@sixb/app 0.2.3 → 0.2.4

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 (133) hide show
  1. package/dist/agent/activity-label.d.ts.map +1 -1
  2. package/dist/agent/agent-chat.d.ts.map +1 -1
  3. package/dist/agent/background/background-tool-row.d.ts.map +1 -1
  4. package/dist/agent/background/interpret.d.ts +1 -1
  5. package/dist/agent/background/interpret.d.ts.map +1 -1
  6. package/dist/agent/components/conversation-panel.d.ts +4 -1
  7. package/dist/agent/components/conversation-panel.d.ts.map +1 -1
  8. package/dist/agent/components/message-parts.d.ts.map +1 -1
  9. package/dist/agent/components/transcript.d.ts +5 -0
  10. package/dist/agent/components/transcript.d.ts.map +1 -1
  11. package/dist/agent/delegation/agent-exchange.d.ts +16 -0
  12. package/dist/agent/delegation/agent-exchange.d.ts.map +1 -0
  13. package/dist/agent/delegation/child-card.d.ts +3 -3
  14. package/dist/agent/delegation/child-card.d.ts.map +1 -1
  15. package/dist/agent/delegation/child-parts.d.ts +1 -10
  16. package/dist/agent/delegation/child-parts.d.ts.map +1 -1
  17. package/dist/agent/delegation/child-work.d.ts.map +1 -1
  18. package/dist/agent/delegation/interpret.d.ts +4 -10
  19. package/dist/agent/delegation/interpret.d.ts.map +1 -1
  20. package/dist/agent/file-edits/file-edit-tool-view.d.ts +10 -0
  21. package/dist/agent/file-edits/file-edit-tool-view.d.ts.map +1 -0
  22. package/dist/agent/file-edits/interpret.d.ts +25 -0
  23. package/dist/agent/file-edits/interpret.d.ts.map +1 -0
  24. package/dist/agent/hooks/use-agent-conversation.d.ts +6 -0
  25. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  26. package/dist/agent/i18n/en.d.ts +46 -5
  27. package/dist/agent/i18n/en.d.ts.map +1 -1
  28. package/dist/agent/i18n/fr.d.ts.map +1 -1
  29. package/dist/agent/i18n/index.d.ts +76 -8
  30. package/dist/agent/i18n/index.d.ts.map +1 -1
  31. package/dist/agent/message-agent/interpret.d.ts +2 -2
  32. package/dist/agent/message-agent/interpret.d.ts.map +1 -1
  33. package/dist/agent/publish-artifact/interpret.d.ts +1 -1
  34. package/dist/agent/publish-artifact/interpret.d.ts.map +1 -1
  35. package/dist/agent/questions/interpret.d.ts +31 -0
  36. package/dist/agent/questions/interpret.d.ts.map +1 -0
  37. package/dist/agent/questions/question-card.d.ts +16 -0
  38. package/dist/agent/questions/question-card.d.ts.map +1 -0
  39. package/dist/agent/questions/question-composer.d.ts +15 -0
  40. package/dist/agent/questions/question-composer.d.ts.map +1 -0
  41. package/dist/agent/read/interpret.d.ts +8 -1
  42. package/dist/agent/read/interpret.d.ts.map +1 -1
  43. package/dist/agent/read/read-tool-view.d.ts.map +1 -1
  44. package/dist/agent/tool-views/built-in.d.ts.map +1 -1
  45. package/dist/agent/waits.d.ts +14 -0
  46. package/dist/agent/waits.d.ts.map +1 -0
  47. package/dist/artifacts/edit-session.d.ts +11 -1
  48. package/dist/artifacts/edit-session.d.ts.map +1 -1
  49. package/dist/artifacts/frame.d.ts.map +1 -1
  50. package/dist/artifacts/messages.d.ts +52 -0
  51. package/dist/artifacts/messages.d.ts.map +1 -1
  52. package/dist/artifacts/renderers/canvas/board-editor.d.ts +11 -4
  53. package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
  54. package/dist/artifacts/renderers/canvas/board.d.ts +14 -2
  55. package/dist/artifacts/renderers/canvas/board.d.ts.map +1 -1
  56. package/dist/artifacts/renderers/canvas/canvas.d.ts +4 -3
  57. package/dist/artifacts/renderers/canvas/canvas.d.ts.map +1 -1
  58. package/dist/artifacts/renderers/canvas/controls.d.ts +15 -4
  59. package/dist/artifacts/renderers/canvas/controls.d.ts.map +1 -1
  60. package/dist/artifacts/renderers/canvas/focus.d.ts +19 -5
  61. package/dist/artifacts/renderers/canvas/focus.d.ts.map +1 -1
  62. package/dist/artifacts/renderers/canvas/gestures.d.ts +46 -0
  63. package/dist/artifacts/renderers/canvas/gestures.d.ts.map +1 -0
  64. package/dist/artifacts/renderers/canvas/page-resize.d.ts +21 -0
  65. package/dist/artifacts/renderers/canvas/page-resize.d.ts.map +1 -0
  66. package/dist/artifacts/renderers/canvas/page-size-controls.d.ts +21 -0
  67. package/dist/artifacts/renderers/canvas/page-size-controls.d.ts.map +1 -0
  68. package/dist/artifacts/renderers/canvas/page-size.d.ts +93 -0
  69. package/dist/artifacts/renderers/canvas/page-size.d.ts.map +1 -0
  70. package/dist/artifacts/renderers/canvas/page-zoom.d.ts +64 -0
  71. package/dist/artifacts/renderers/canvas/page-zoom.d.ts.map +1 -0
  72. package/dist/artifacts/renderers/canvas/shown-size.d.ts +26 -0
  73. package/dist/artifacts/renderers/canvas/shown-size.d.ts.map +1 -0
  74. package/dist/{chunk-kes4ygmz.js → chunk-970s5nkn.js} +1 -1
  75. package/dist/{chunk-001c4gnk.js → chunk-kymx9y5e.js} +3117 -2363
  76. package/dist/{chunk-001c4gnk.js.map → chunk-kymx9y5e.js.map} +36 -29
  77. package/dist/{chunk-fwb9mxwm.js → chunk-pxd07kvx.js} +1 -1
  78. package/dist/{chunk-5crvhjp2.js → chunk-yrcm1pbg.js} +1504 -233
  79. package/dist/chunk-yrcm1pbg.js.map +34 -0
  80. package/dist/index.d.ts +2 -0
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +4 -2
  83. package/dist/index.js.map +3 -3
  84. package/dist/pages.js +2 -2
  85. package/package.json +2 -2
  86. package/src/agent/activity-label.ts +6 -1
  87. package/src/agent/agent-chat.tsx +1 -0
  88. package/src/agent/background/background-tool-row.tsx +24 -10
  89. package/src/agent/background/interpret.ts +60 -51
  90. package/src/agent/components/conversation-panel.tsx +27 -8
  91. package/src/agent/components/message-parts.tsx +23 -5
  92. package/src/agent/components/transcript.tsx +45 -27
  93. package/src/agent/delegation/agent-exchange.tsx +53 -0
  94. package/src/agent/delegation/child-card.tsx +6 -40
  95. package/src/agent/delegation/child-parts.tsx +1 -84
  96. package/src/agent/delegation/child-work.tsx +19 -5
  97. package/src/agent/delegation/interpret.ts +33 -54
  98. package/src/agent/delegation/model.ts +1 -1
  99. package/src/agent/file-edits/file-edit-tool-view.tsx +126 -0
  100. package/src/agent/file-edits/interpret.ts +120 -0
  101. package/src/agent/hooks/use-agent-conversation.ts +20 -0
  102. package/src/agent/i18n/en.ts +47 -5
  103. package/src/agent/i18n/fr.ts +39 -4
  104. package/src/agent/message-agent/interpret.ts +4 -3
  105. package/src/agent/publish-artifact/interpret.ts +14 -5
  106. package/src/agent/publish-artifact/publish-artifact-tool-view.tsx +2 -2
  107. package/src/agent/questions/interpret.ts +90 -0
  108. package/src/agent/questions/question-card.tsx +57 -0
  109. package/src/agent/questions/question-composer.tsx +257 -0
  110. package/src/agent/read/interpret.ts +34 -1
  111. package/src/agent/read/read-tool-view.tsx +20 -4
  112. package/src/agent/tool-views/built-in.tsx +19 -8
  113. package/src/agent/waits.ts +50 -0
  114. package/src/artifacts/artifacts.css +36 -0
  115. package/src/artifacts/edit-session.tsx +15 -1
  116. package/src/artifacts/frame.tsx +3 -2
  117. package/src/artifacts/messages.ts +54 -0
  118. package/src/artifacts/renderers/canvas/board-editor.tsx +37 -15
  119. package/src/artifacts/renderers/canvas/board.tsx +70 -8
  120. package/src/artifacts/renderers/canvas/canvas.tsx +66 -15
  121. package/src/artifacts/renderers/canvas/controls.tsx +64 -30
  122. package/src/artifacts/renderers/canvas/focus.tsx +200 -56
  123. package/src/artifacts/renderers/canvas/gestures.ts +265 -0
  124. package/src/artifacts/renderers/canvas/page-resize.tsx +542 -0
  125. package/src/artifacts/renderers/canvas/page-size-controls.tsx +193 -0
  126. package/src/artifacts/renderers/canvas/page-size.ts +218 -0
  127. package/src/artifacts/renderers/canvas/page-zoom.ts +280 -0
  128. package/src/artifacts/renderers/canvas/shown-size.ts +105 -0
  129. package/src/artifacts/viewer.tsx +15 -1
  130. package/src/index.ts +2 -0
  131. package/dist/chunk-5crvhjp2.js.map +0 -28
  132. /package/dist/{chunk-kes4ygmz.js.map → chunk-970s5nkn.js.map} +0 -0
  133. /package/dist/{chunk-fwb9mxwm.js.map → chunk-pxd07kvx.js.map} +0 -0
@@ -3,8 +3,9 @@ import type { ArtifactKindName } from "../../artifacts/kind-icon"
3
3
  import type { NormalizedPart, NormalizedTool } from "../parts"
4
4
 
5
5
  /**
6
- * Creating an artifact, and changing one: `update_artifact` writes its current version, and
7
- * `publish_artifact_version`, in threads from before, published the next version.
6
+ * Creating an artifact, and changing one: `publish_artifact` with an id writes its current version.
7
+ * Threads from before hold `update_artifact`, which did that, and `publish_artifact_version`,
8
+ * which published the next version.
8
9
  */
9
10
  const PUBLISH_TOOLS = new Set(["publish_artifact", "update_artifact", "publish_artifact_version"])
10
11
 
@@ -13,8 +14,16 @@ export function isPublishTool(toolName: string): boolean {
13
14
  }
14
15
 
15
16
  /** Whether a publish call changed an artifact that was there before, rather than created one. */
16
- export function isUpdateTool(toolName: string): boolean {
17
- return toolName === "update_artifact" || toolName === "publish_artifact_version"
17
+ export function isUpdate(tool: Pick<NormalizedTool, "toolName" | "input">): boolean {
18
+ if (tool.toolName !== "publish_artifact") return isPublishTool(tool.toolName)
19
+ const input = tool.input
20
+ return (
21
+ typeof input === "object" &&
22
+ input !== null &&
23
+ "id" in input &&
24
+ typeof input.id === "string" &&
25
+ input.id.trim().startsWith("art_")
26
+ )
18
27
  }
19
28
 
20
29
  /** What one publish call published, read from its result. */
@@ -86,7 +95,7 @@ export function turnArtifacts(parts: readonly NormalizedPart[]): TurnArtifact[]
86
95
  const published = publishedArtifact(part.tool)
87
96
  if (!published) continue
88
97
  const earlier = byId.get(published.artifactId)
89
- const created = earlier?.created === true || part.tool.toolName === "publish_artifact"
98
+ const created = earlier?.created === true || !isUpdate(part.tool)
90
99
  if (!earlier || writtenAfter(published, earlier)) {
91
100
  byId.set(published.artifactId, { ...published, created })
92
101
  } else if (created !== earlier.created) {
@@ -3,7 +3,7 @@ import { useArtifactMessages } from "../../artifacts/messages"
3
3
  import { ActivityStatusText } from "../components/activity-status"
4
4
  import { useAgentMessages } from "../i18n"
5
5
  import type { NormalizedTool } from "../parts"
6
- import { isUpdateTool, publishedArtifact, publishTitle } from "./interpret"
6
+ import { isUpdate, publishedArtifact, publishTitle } from "./interpret"
7
7
 
8
8
  /**
9
9
  * A publish in the work trace: what it published, with any warnings, or why it was refused. The
@@ -18,7 +18,7 @@ export function PublishArtifactToolView({ tool }: { tool: NormalizedTool }) {
18
18
  const published = publishedArtifact(tool)
19
19
  const running = tool.state === "input-streaming" || tool.state === "input-available"
20
20
  const failed = tool.state === "output-error"
21
- const update = isUpdateTool(tool.toolName)
21
+ const update = isUpdate(tool)
22
22
  const label = failed
23
23
  ? (update ? messages.updateFailed : messages.publishFailed)(title)
24
24
  : running
@@ -0,0 +1,90 @@
1
+ import type { AgentConversationMessage, AgentConversationTurn } from "../conversation"
2
+
3
+ /** One question of an `ask` call, as the card shows it. */
4
+ export interface AskedQuestion {
5
+ readonly question: string
6
+ readonly choices: readonly string[]
7
+ /** Several of the choices may be picked. */
8
+ readonly multiple: boolean
9
+ }
10
+
11
+ /** The tools an agent asks with: `ask`, and a sub-agent's `ask_parent` in earlier threads. */
12
+ export function isAskTool(toolName: string): boolean {
13
+ return toolName === "ask" || toolName === "ask_parent"
14
+ }
15
+
16
+ /** The questions of an `ask` call's input, or of an `ask_parent` call's `{ question }`. */
17
+ export function askedQuestions(input: unknown): readonly AskedQuestion[] {
18
+ if (!isRecord(input)) return []
19
+ if (typeof input.question === "string" && input.question.trim()) {
20
+ return [{ question: input.question.trim(), choices: [], multiple: false }]
21
+ }
22
+ if (!Array.isArray(input.questions)) return []
23
+ return input.questions.flatMap((value): AskedQuestion[] => {
24
+ if (!isRecord(value) || typeof value.question !== "string" || !value.question.trim()) return []
25
+ const choices = Array.isArray(value.choices)
26
+ ? value.choices.filter((choice): choice is string => typeof choice === "string" && !!choice)
27
+ : []
28
+ return [
29
+ {
30
+ question: value.question.trim(),
31
+ choices,
32
+ multiple: value.multiple === true && choices.length > 0,
33
+ },
34
+ ]
35
+ })
36
+ }
37
+
38
+ /** The questions as one line, for a row that names them: `Which year? · Which regions?`. */
39
+ export function askedText(input: unknown): string {
40
+ return askedQuestions(input)
41
+ .map((question) => question.question)
42
+ .join(" · ")
43
+ }
44
+
45
+ /**
46
+ * The user's answer as the message the card sends: the picked choices or the typed text, and with
47
+ * several questions each answer after its question. Unanswered questions are left out; empty when
48
+ * nothing was answered.
49
+ */
50
+ export function answerText(
51
+ questions: readonly AskedQuestion[],
52
+ answers: readonly (readonly string[])[]
53
+ ): string {
54
+ const answered = questions.flatMap((question, index) => {
55
+ const picked = (answers[index] ?? []).map((answer) => answer.trim()).filter(Boolean)
56
+ return picked.length > 0 ? [{ question: question.question, answer: picked.join(", ") }] : []
57
+ })
58
+ if (questions.length === 1) return answered[0]?.answer ?? ""
59
+ return answered.map(({ question, answer }) => `${question} ${answer}`).join("\n")
60
+ }
61
+
62
+ /** The questions the conversation's last word asks the user, and the reply that asked them. */
63
+ export interface OpenQuestion {
64
+ readonly messageKey: string
65
+ readonly questions: readonly AskedQuestion[]
66
+ }
67
+
68
+ /**
69
+ * What still waits for the user: the questions of the conversation's last message, a reply that
70
+ * asked, once its turn ended. A later message answers it, and a running turn has not asked yet.
71
+ */
72
+ export function openQuestion(
73
+ messages: readonly AgentConversationMessage[],
74
+ turn: AgentConversationTurn
75
+ ): OpenQuestion | null {
76
+ if (turn.kind === "responding") return null
77
+ const last = messages.at(-1)
78
+ if (last?.role !== "assistant") return null
79
+ const asked = last.parts.filter(
80
+ (part) => part.type === "tool" && part.toolName === "ask" && part.state === "output-available"
81
+ )
82
+ const questions = asked.flatMap((part) =>
83
+ part.type === "tool" ? askedQuestions(part.input) : []
84
+ )
85
+ return questions.length > 0 ? { messageKey: last.key, questions } : null
86
+ }
87
+
88
+ function isRecord(value: unknown): value is Record<string, unknown> {
89
+ return typeof value === "object" && value !== null && !Array.isArray(value)
90
+ }
@@ -0,0 +1,57 @@
1
+ import { MessageCircleQuestion } from "lucide-react"
2
+ import { createContext, useContext } from "react"
3
+ import { ACTIVITY_STATUS_ROW_CLASS_NAME } from "../components/activity-status"
4
+ import { useAgentMessages } from "../i18n"
5
+ import type { NormalizedTool } from "../parts"
6
+ import { askedQuestions } from "./interpret"
7
+
8
+ /**
9
+ * Whether the reply a line is in asks the reader now: its question is the conversation's last word,
10
+ * answered in the composer, which becomes the question (`QuestionComposer`). `answering` when the
11
+ * reader may answer there; otherwise, as for an observer, someone else's answer is awaited.
12
+ */
13
+ export interface QuestionTurn {
14
+ readonly open: boolean
15
+ readonly answering?: boolean
16
+ }
17
+
18
+ export const QuestionTurnContext = createContext<QuestionTurn>({ open: false })
19
+
20
+ /** The Agent's questions in its reply: a quiet line each, the composer asks them. */
21
+ export function QuestionCards({ tools }: { readonly tools: readonly NormalizedTool[] }) {
22
+ if (tools.length === 0) return null
23
+ return (
24
+ <div className="flex flex-col gap-3">
25
+ {tools.map((tool, index) => (
26
+ // A reply's calls never reorder: their order is their identity.
27
+ <QuestionLine key={index} tool={tool} />
28
+ ))}
29
+ </div>
30
+ )
31
+ }
32
+
33
+ function QuestionLine({ tool }: { readonly tool: NormalizedTool }) {
34
+ const turn = useContext(QuestionTurnContext)
35
+ const messages = useAgentMessages().questions
36
+ const questions = askedQuestions(tool.input)
37
+ if (questions.length === 0) return null
38
+
39
+ // While the reader may answer, the composer is the question: the reply leaves it to the composer.
40
+ if (turn.open && turn.answering) return null
41
+ const label = turn.open ? messages.waiting : messages.asked
42
+ return (
43
+ <div className="min-w-0">
44
+ <p className={ACTIVITY_STATUS_ROW_CLASS_NAME}>
45
+ <MessageCircleQuestion className="size-3.5 shrink-0" />
46
+ <span className="min-w-0 truncate font-medium">{label}</span>
47
+ </p>
48
+ <ul className="mt-1 space-y-0.5 pl-5 text-[13px] text-muted-foreground">
49
+ {questions.map((question) => (
50
+ <li key={question.question} className="break-words">
51
+ {question.question}
52
+ </li>
53
+ ))}
54
+ </ul>
55
+ </div>
56
+ )
57
+ }
@@ -0,0 +1,257 @@
1
+ import { cn } from "@sixb/ui/lib/utils"
2
+ import { ArrowUp, Check, ChevronLeft, X } from "lucide-react"
3
+ import { useEffect, useRef, useState } from "react"
4
+ import { useAgentMessages } from "../i18n"
5
+ import { type AskedQuestion, answerText } from "./interpret"
6
+
7
+ export interface QuestionComposerProps {
8
+ readonly questions: readonly AskedQuestion[]
9
+ readonly onAnswer: (text: string) => void
10
+ /** Back to the composer, to reply in words of one's own. */
11
+ readonly onDismiss: () => void
12
+ readonly className?: string
13
+ }
14
+
15
+ /**
16
+ * The composer, become the Agent's question: the same surface in the same place, its questions one
17
+ * at a time, each choice a row to pick and a last row to write something else. Picking the one
18
+ * answer of the last question sends; several questions send together from the last.
19
+ */
20
+ export function QuestionComposer({
21
+ questions,
22
+ onAnswer,
23
+ onDismiss,
24
+ className,
25
+ }: QuestionComposerProps) {
26
+ const messages = useAgentMessages().questions
27
+ const [step, setStep] = useState(0)
28
+ const [answers, setAnswers] = useState<readonly (readonly string[])[]>(() =>
29
+ questions.map(() => [])
30
+ )
31
+ const [other, setOther] = useState("")
32
+ const [sent, setSent] = useState(false)
33
+ const rows = useRef<HTMLDivElement>(null)
34
+
35
+ const question = questions[step]
36
+ const last = step === questions.length - 1
37
+ const picked = answers[step] ?? []
38
+
39
+ // Each question starts on its first choice, ready for the keyboard.
40
+ // biome-ignore lint/correctness/useExhaustiveDependencies: a new step moves the focus
41
+ useEffect(() => {
42
+ rows.current?.querySelector<HTMLButtonElement>("[data-choice]")?.focus({ preventScroll: true })
43
+ }, [step])
44
+
45
+ if (!question) return null
46
+
47
+ const finish = (next: readonly (readonly string[])[]) => {
48
+ const text = answerText(questions, next)
49
+ if (!text || sent) return
50
+ setSent(true)
51
+ onAnswer(text)
52
+ }
53
+
54
+ const commit = (answer: readonly string[]) => {
55
+ const next = answers.map((entry, index) => (index === step ? answer : entry))
56
+ setAnswers(next)
57
+ setOther("")
58
+ if (last) finish(next)
59
+ else setStep(step + 1)
60
+ }
61
+
62
+ const choose = (choice: string) => {
63
+ if (!question.multiple) return commit([choice])
64
+ setAnswers((current) =>
65
+ current.map((entry, index) =>
66
+ index !== step
67
+ ? entry
68
+ : entry.includes(choice)
69
+ ? entry.filter((value) => value !== choice)
70
+ : [...entry, choice]
71
+ )
72
+ )
73
+ }
74
+
75
+ const writeOther = () => {
76
+ const text = other.trim()
77
+ if (!text) return
78
+ commit(question.multiple ? [...picked, text] : [text])
79
+ }
80
+
81
+ return (
82
+ <div className={cn("relative bg-background px-4 pt-2 pb-3", className)}>
83
+ <div className="mx-auto w-full max-w-[46rem]">
84
+ <section
85
+ aria-label={messages.card(questions.length)}
86
+ aria-busy={sent}
87
+ onKeyDown={(event) => {
88
+ if (event.key === "Escape") {
89
+ event.preventDefault()
90
+ onDismiss()
91
+ return
92
+ }
93
+ if (event.target instanceof HTMLInputElement) return
94
+ const number = Number(event.key)
95
+ const choice = Number.isInteger(number) ? question.choices[number - 1] : undefined
96
+ if (choice !== undefined) {
97
+ event.preventDefault()
98
+ choose(choice)
99
+ return
100
+ }
101
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
102
+ event.preventDefault()
103
+ const all = [...(rows.current?.querySelectorAll<HTMLElement>("[data-row]") ?? [])]
104
+ const at = all.indexOf(document.activeElement as HTMLElement)
105
+ const to =
106
+ event.key === "ArrowDown" ? Math.min(all.length - 1, at + 1) : Math.max(0, at - 1)
107
+ all[to]?.focus()
108
+ }
109
+ }}
110
+ className={cn(
111
+ "sixb-composer-surface relative rounded-[26px] p-2",
112
+ "motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-bottom-3 motion-safe:duration-300 motion-safe:ease-out"
113
+ )}
114
+ >
115
+ {/* The question, where it stands among the others, and the way back to the composer. */}
116
+ <div className="flex items-start gap-2 px-3 pt-2.5 pb-2">
117
+ {step > 0 ? (
118
+ <button
119
+ type="button"
120
+ onClick={() => setStep(step - 1)}
121
+ aria-label={messages.back}
122
+ className="-ml-1.5 flex size-7 shrink-0 items-center justify-center rounded-full text-muted-foreground outline-none transition-colors hover:bg-black/[0.05] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 dark:hover:bg-white/[0.08]"
123
+ >
124
+ <ChevronLeft className="size-4" />
125
+ </button>
126
+ ) : null}
127
+ <div className="min-w-0 flex-1">
128
+ <h3
129
+ key={step}
130
+ className="text-[15px] leading-snug font-medium tracking-[-0.01em] text-foreground motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-200"
131
+ >
132
+ {question.question}
133
+ </h3>
134
+ {question.multiple ? (
135
+ <p className="mt-0.5 text-xs text-muted-foreground">{messages.pickAny}</p>
136
+ ) : null}
137
+ </div>
138
+ {questions.length > 1 ? (
139
+ <span
140
+ className="mt-1.5 flex shrink-0 items-center gap-1"
141
+ aria-label={messages.step(step + 1, questions.length)}
142
+ >
143
+ {questions.map((entry, index) => (
144
+ <span
145
+ key={entry.question}
146
+ className={cn(
147
+ "size-1.5 rounded-full transition-colors duration-200",
148
+ index === step
149
+ ? "bg-foreground"
150
+ : index < step
151
+ ? "bg-foreground/40"
152
+ : "bg-foreground/15"
153
+ )}
154
+ />
155
+ ))}
156
+ </span>
157
+ ) : null}
158
+ <button
159
+ type="button"
160
+ onClick={onDismiss}
161
+ aria-label={messages.dismiss}
162
+ title={messages.dismiss}
163
+ className="-mt-0.5 -mr-1 flex size-7 shrink-0 items-center justify-center rounded-full text-muted-foreground outline-none transition-colors hover:bg-black/[0.05] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 dark:hover:bg-white/[0.08]"
164
+ >
165
+ <X className="size-4" />
166
+ </button>
167
+ </div>
168
+
169
+ <div
170
+ ref={rows}
171
+ key={step}
172
+ className="flex flex-col gap-0.5 motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-200"
173
+ >
174
+ {question.choices.map((choice, index) => {
175
+ const selected = picked.includes(choice)
176
+ return (
177
+ <button
178
+ key={choice}
179
+ type="button"
180
+ data-row=""
181
+ data-choice=""
182
+ aria-pressed={question.multiple ? selected : undefined}
183
+ disabled={sent}
184
+ onClick={() => choose(choice)}
185
+ className={cn(
186
+ "group/choice flex min-h-11 w-full items-center gap-3 rounded-[18px] px-3 text-left text-[15px] text-foreground outline-none transition-colors",
187
+ "hover:bg-black/[0.04] focus-visible:bg-black/[0.05] dark:hover:bg-white/[0.06] dark:focus-visible:bg-white/[0.08]",
188
+ selected && "bg-black/[0.05] dark:bg-white/[0.08]"
189
+ )}
190
+ >
191
+ <span
192
+ aria-hidden="true"
193
+ className={cn(
194
+ "flex size-6 shrink-0 items-center justify-center rounded-[7px] text-xs font-medium tabular-nums transition-colors",
195
+ selected
196
+ ? "bg-foreground text-background"
197
+ : "bg-black/[0.05] text-muted-foreground group-hover/choice:text-foreground dark:bg-white/[0.08]"
198
+ )}
199
+ >
200
+ {selected ? <Check className="size-3.5" strokeWidth={2.5} /> : index + 1}
201
+ </span>
202
+ <span className="min-w-0 flex-1 break-words">{choice}</span>
203
+ </button>
204
+ )
205
+ })}
206
+
207
+ {/* Something else, in words: the composer's own field and send button, in a row. */}
208
+ <div
209
+ className={cn(
210
+ "flex min-h-11 items-center gap-3 rounded-[18px] pr-1 pl-3",
211
+ question.choices.length > 0 && "mt-0.5"
212
+ )}
213
+ >
214
+ {question.choices.length > 0 ? (
215
+ <span aria-hidden="true" className="size-6 shrink-0" />
216
+ ) : null}
217
+ <input
218
+ data-row=""
219
+ type="text"
220
+ value={other}
221
+ disabled={sent}
222
+ aria-label={messages.typeAnswer}
223
+ placeholder={
224
+ question.choices.length > 0 ? messages.somethingElse : messages.typeAnswer
225
+ }
226
+ onChange={(event) => setOther(event.target.value)}
227
+ onKeyDown={(event) => {
228
+ if (event.key === "Enter" && !event.nativeEvent.isComposing) {
229
+ event.preventDefault()
230
+ if (other.trim()) writeOther()
231
+ else if (question.multiple && picked.length > 0) commit(picked)
232
+ }
233
+ }}
234
+ className="h-10 min-w-0 flex-1 bg-transparent text-[15px] text-foreground outline-none placeholder:text-muted-foreground/70"
235
+ />
236
+ {question.multiple || other.trim() || question.choices.length === 0 ? (
237
+ <button
238
+ type="button"
239
+ disabled={sent || (!other.trim() && picked.length === 0)}
240
+ onClick={() => (other.trim() ? writeOther() : commit(picked))}
241
+ aria-label={last ? messages.send : messages.next}
242
+ className={cn(
243
+ "sixb-composer-send flex size-9 shrink-0 items-center justify-center rounded-full outline-none transition-colors",
244
+ "bg-foreground text-background hover:bg-foreground/85 focus-visible:ring-2 focus-visible:ring-ring/50",
245
+ "disabled:bg-foreground/25 dark:disabled:bg-white/20 dark:disabled:text-white/70"
246
+ )}
247
+ >
248
+ <ArrowUp className={cn("size-4", !last && "rotate-90")} strokeWidth={2.25} />
249
+ </button>
250
+ ) : null}
251
+ </div>
252
+ </div>
253
+ </section>
254
+ </div>
255
+ </div>
256
+ )
257
+ }
@@ -15,6 +15,13 @@ export interface ReadOutput {
15
15
  readonly nextOffset?: number
16
16
  }
17
17
 
18
+ /** A folder `read` listed: its entries, folders ending in `/`. */
19
+ export interface ReadDirectory {
20
+ readonly path: string
21
+ readonly entries: readonly string[]
22
+ readonly truncated: boolean
23
+ }
24
+
18
25
  export interface ReadDescription {
19
26
  readonly path: string
20
27
  readonly title: string
@@ -55,12 +62,38 @@ export function coerceReadOutput(value: unknown): ReadOutput | null {
55
62
  }
56
63
  }
57
64
 
65
+ export function coerceReadDirectory(value: unknown): ReadDirectory | null {
66
+ if (
67
+ !isRecord(value) ||
68
+ typeof value.path !== "string" ||
69
+ !Array.isArray(value.entries) ||
70
+ !value.entries.every((entry) => typeof entry === "string")
71
+ ) {
72
+ return null
73
+ }
74
+ return { path: value.path, entries: value.entries, truncated: value.truncated === true }
75
+ }
76
+
58
77
  export function describeRead(
59
78
  input: ReadInput | null,
60
79
  output: ReadOutput | null,
61
- messages: AgentMessages = en
80
+ messages: AgentMessages = en,
81
+ directory: ReadDirectory | null = null
62
82
  ): ReadDescription {
63
83
  const m = messages.read
84
+ if (directory) {
85
+ const name = fileName(directory.path)
86
+ const entries = m.entries(directory.entries.length)
87
+ return {
88
+ path: directory.path,
89
+ title: m.directory.title(name),
90
+ runningTitle: m.directory.running(name),
91
+ failedTitle: m.directory.failed(name),
92
+ detail: directory.truncated ? m.moreAvailable(entries) : entries,
93
+ skill: false,
94
+ memory: false,
95
+ }
96
+ }
64
97
  const path = output?.path ?? input?.path ?? ""
65
98
  const memory = memoryFile(path)
66
99
  if (memory !== null) {
@@ -1,18 +1,32 @@
1
1
  import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@sixb/ui/components"
2
- import { Bookmark, BookOpen, ChevronRight, FileText, type LucideIcon } from "lucide-react"
2
+ import {
3
+ Bookmark,
4
+ BookOpen,
5
+ ChevronRight,
6
+ FileText,
7
+ FolderOpen,
8
+ type LucideIcon,
9
+ } from "lucide-react"
3
10
  import { ActivityStatusText } from "../components/activity-status"
4
11
  import { useAgentMessages } from "../i18n"
5
12
  import type { NormalizedTool } from "../parts"
6
- import { coerceReadInput, coerceReadOutput, describeRead } from "./interpret"
13
+ import { coerceReadDirectory, coerceReadInput, coerceReadOutput, describeRead } from "./interpret"
7
14
 
8
15
  export function ReadToolView({ tool }: { tool: NormalizedTool }) {
9
16
  const messages = useAgentMessages()
10
17
  const input = coerceReadInput(tool.input)
11
18
  const output = coerceReadOutput(tool.output)
12
- const description = describeRead(input, output, messages)
19
+ const directory = coerceReadDirectory(tool.output)
20
+ const description = describeRead(input, output, messages, directory)
13
21
  const running = tool.state === "input-streaming" || tool.state === "input-available"
14
22
  const error = tool.state === "output-error"
15
- const Icon = description.memory ? Bookmark : description.skill ? BookOpen : FileText
23
+ const Icon = directory
24
+ ? FolderOpen
25
+ : description.memory
26
+ ? Bookmark
27
+ : description.skill
28
+ ? BookOpen
29
+ : FileText
16
30
  const label = error
17
31
  ? description.failedTitle
18
32
  : running
@@ -44,6 +58,8 @@ export function ReadToolView({ tool }: { tool: NormalizedTool }) {
44
58
  ) : null}
45
59
  {error ? (
46
60
  <ReadBlock value={tool.errorText?.trim() || messages.read.error} />
61
+ ) : directory ? (
62
+ <ReadBlock value={directory.entries.join("\n")} />
47
63
  ) : output?.content ? (
48
64
  <ReadBlock value={output.content} />
49
65
  ) : output ? (
@@ -5,13 +5,16 @@ import { isBackgroundStart } from "../background/interpret"
5
5
  import { BashToolView } from "../bash/bash-tool-view"
6
6
  import { WebFetchToolView } from "../components/web-fetch-tool-view"
7
7
  import { WebSearchToolView } from "../components/web-search-tool-view"
8
+ import { EditToolView, WriteToolView } from "../file-edits/file-edit-tool-view"
8
9
  import type { NormalizedTool } from "../parts"
9
10
  import { OpenArtifactToolView } from "../publish-artifact/open-artifact-tool-view"
10
11
  import { PublishArtifactToolView } from "../publish-artifact/publish-artifact-tool-view"
11
12
  import { ReadToolView } from "../read/read-tool-view"
12
13
  import { coerceWebFetchOutput } from "../utils/web-fetch"
13
14
  import { coerceWebSearchOutput } from "../utils/web-search"
15
+ import { describeViewFile } from "../view-file/interpret"
14
16
  import { ViewFileToolView } from "../view-file/view-file-tool-view"
17
+ import { waitsForCommandsOnly } from "../waits"
15
18
 
16
19
  type BuiltInToolView = (tool: NormalizedTool) => ReactNode
17
20
 
@@ -37,16 +40,24 @@ const BUILT_IN_TOOL_VIEWS: ReadonlyMap<string, BuiltInToolView> = new Map([
37
40
  />
38
41
  ),
39
42
  ],
40
- // A failed read or stop keeps the inspector, which says why.
41
- [
42
- "bash_output",
43
- (tool) => (tool.state === "output-error" ? null : <BackgroundToolRow tool={tool} />),
44
- ],
43
+ // A wait or a stop for commands alone is their row; one for a sub-agent is the sub-agent's. A
44
+ // failed one keeps the inspector, which says why. Earlier threads hold bash_output and bash_stop.
45
+ ...["wait", "stop", "bash_output", "bash_stop"].map((name): [string, BuiltInToolView] => [
46
+ name,
47
+ (tool) =>
48
+ tool.state === "output-error" || !waitsForCommandsOnly(tool) ? null : (
49
+ <BackgroundToolRow tool={tool} />
50
+ ),
51
+ ]),
52
+ // A file read shows as itself, an image or a PDF, keeps the view view_file had.
45
53
  [
46
- "bash_stop",
47
- (tool) => (tool.state === "output-error" ? null : <BackgroundToolRow tool={tool} />),
54
+ "read",
55
+ (tool) =>
56
+ describeViewFile(tool).file ? <ViewFileToolView tool={tool} /> : <ReadToolView tool={tool} />,
48
57
  ],
49
- ["read", (tool) => <ReadToolView tool={tool} />],
58
+ ["edit", (tool) => <EditToolView tool={tool} />],
59
+ ["write", (tool) => <WriteToolView tool={tool} />],
60
+ // Earlier threads hold calls to it.
50
61
  ["view_file", (tool) => <ViewFileToolView tool={tool} />],
51
62
  ["publish_artifact", publishArtifact],
52
63
  ["update_artifact", publishArtifact],
@@ -0,0 +1,50 @@
1
+ import type { NormalizedTool } from "./parts"
2
+
3
+ // `wait` and `stop` name background commands, by the `bg_` id `bash` returned, and sub-agents, by
4
+ // their key. Earlier threads hold the tools before them: `bash_output` and `bash_stop` for a
5
+ // command, `wait_agent` for sub-agents, by run id.
6
+
7
+ /** The tools that read or stop a background command, today's and earlier threads'. */
8
+ export const COMMAND_TOOLS: ReadonlySet<string> = new Set([
9
+ "wait",
10
+ "stop",
11
+ "bash_output",
12
+ "bash_stop",
13
+ ])
14
+
15
+ /** What a `wait` or a `stop` names: the ids it was called with, as the model wrote them. */
16
+ export function namedIds(tool: Pick<NormalizedTool, "toolName" | "input">): readonly string[] {
17
+ const input = isRecord(tool.input) ? tool.input : {}
18
+ const ids = Array.isArray(input.ids)
19
+ ? input.ids
20
+ : Array.isArray(input.runIds)
21
+ ? input.runIds
22
+ : [input.id]
23
+ return ids.flatMap((id) => (typeof id === "string" && id.trim() ? [id.trim()] : []))
24
+ }
25
+
26
+ /** Whether an id names a background command rather than a sub-agent. */
27
+ export function isCommandId(id: string): boolean {
28
+ return id.startsWith("bg_")
29
+ }
30
+
31
+ /** Whether a call waits for, or stops, one of the Agent's sub-agents: its row stands for it. */
32
+ export function waitsForChildren(tool: Pick<NormalizedTool, "toolName" | "input">): boolean {
33
+ if (tool.toolName === "wait_agent") return true
34
+ if (tool.toolName !== "wait" && tool.toolName !== "stop") return false
35
+ return namedIds(tool).some((id) => !isCommandId(id))
36
+ }
37
+
38
+ /** Whether a call reads, waits for, or stops background commands alone. */
39
+ export function waitsForCommandsOnly(tool: Pick<NormalizedTool, "toolName" | "input">): boolean {
40
+ return COMMAND_TOOLS.has(tool.toolName) && !waitsForChildren(tool)
41
+ }
42
+
43
+ /** Whether a call stops what it names. */
44
+ export function isStop(tool: Pick<NormalizedTool, "toolName">): boolean {
45
+ return tool.toolName === "stop" || tool.toolName === "bash_stop"
46
+ }
47
+
48
+ function isRecord(value: unknown): value is Record<string, unknown> {
49
+ return typeof value === "object" && value !== null && !Array.isArray(value)
50
+ }