@sixb/app 0.2.0 → 0.2.1

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 (87) hide show
  1. package/assets/connector-icons/README.md +1 -0
  2. package/assets/connector-icons/fleetio.ico +0 -0
  3. package/dist/agent/activity-label.d.ts.map +1 -1
  4. package/dist/agent/background/background-card.d.ts +10 -0
  5. package/dist/agent/background/background-card.d.ts.map +1 -0
  6. package/dist/agent/background/background-tool-row.d.ts +9 -0
  7. package/dist/agent/background/background-tool-row.d.ts.map +1 -0
  8. package/dist/agent/background/context.d.ts +23 -0
  9. package/dist/agent/background/context.d.ts.map +1 -0
  10. package/dist/agent/background/interpret.d.ts +116 -0
  11. package/dist/agent/background/interpret.d.ts.map +1 -0
  12. package/dist/agent/bash/bash-tool-view.d.ts.map +1 -1
  13. package/dist/agent/bash/interpret.d.ts +4 -0
  14. package/dist/agent/bash/interpret.d.ts.map +1 -1
  15. package/dist/agent/components/composer-menu.d.ts +3 -1
  16. package/dist/agent/components/composer-menu.d.ts.map +1 -1
  17. package/dist/agent/components/composer-place.d.ts +11 -0
  18. package/dist/agent/components/composer-place.d.ts.map +1 -0
  19. package/dist/agent/components/composer.d.ts +4 -1
  20. package/dist/agent/components/composer.d.ts.map +1 -1
  21. package/dist/agent/components/computer-place.d.ts +3 -1
  22. package/dist/agent/components/computer-place.d.ts.map +1 -1
  23. package/dist/agent/components/transcript.d.ts +6 -0
  24. package/dist/agent/components/transcript.d.ts.map +1 -1
  25. package/dist/agent/components/web-fetch-tool-view.d.ts.map +1 -1
  26. package/dist/agent/delegation/child-parts.d.ts +2 -0
  27. package/dist/agent/delegation/child-parts.d.ts.map +1 -1
  28. package/dist/agent/delegation/use-children.d.ts.map +1 -1
  29. package/dist/agent/hooks/use-agent-conversation.d.ts +15 -1
  30. package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
  31. package/dist/agent/hooks/use-new-thread-place.d.ts +48 -0
  32. package/dist/agent/hooks/use-new-thread-place.d.ts.map +1 -0
  33. package/dist/agent/hooks/use-thread-lists.d.ts +40 -0
  34. package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
  35. package/dist/agent/i18n/en.d.ts +60 -0
  36. package/dist/agent/i18n/en.d.ts.map +1 -1
  37. package/dist/agent/i18n/fr.d.ts.map +1 -1
  38. package/dist/agent/i18n/index.d.ts +106 -0
  39. package/dist/agent/i18n/index.d.ts.map +1 -1
  40. package/dist/agent/observed-conversation.d.ts.map +1 -1
  41. package/dist/agent/tool-views/built-in.d.ts.map +1 -1
  42. package/dist/agent/utils/web-fetch.d.ts +33 -1
  43. package/dist/agent/utils/web-fetch.d.ts.map +1 -1
  44. package/dist/agent/utils/web-search.d.ts +14 -2
  45. package/dist/agent/utils/web-search.d.ts.map +1 -1
  46. package/dist/{chunk-zxthr2q5.js → chunk-4j3c3p72.js} +1 -1
  47. package/dist/{chunk-km25essq.js → chunk-7fj9cfkw.js} +1 -1
  48. package/dist/{chunk-j9653e83.js → chunk-j8g956dt.js} +1 -1
  49. package/dist/{chunk-fw2bm6dq.js → chunk-ytadd0b5.js} +3095 -1994
  50. package/dist/{chunk-fw2bm6dq.js.map → chunk-ytadd0b5.js.map} +25 -19
  51. package/dist/index.js +1 -1
  52. package/dist/pages/console/data/shared.d.ts.map +1 -1
  53. package/dist/pages/settings/usage/messages.d.ts +2 -0
  54. package/dist/pages/settings/usage/messages.d.ts.map +1 -1
  55. package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
  56. package/dist/pages.js +13 -6
  57. package/dist/pages.js.map +6 -6
  58. package/package.json +3 -3
  59. package/src/agent/activity-label.ts +6 -2
  60. package/src/agent/agent.css +18 -0
  61. package/src/agent/background/background-card.tsx +308 -0
  62. package/src/agent/background/background-tool-row.tsx +58 -0
  63. package/src/agent/background/context.ts +26 -0
  64. package/src/agent/background/interpret.ts +356 -0
  65. package/src/agent/bash/bash-tool-view.tsx +9 -4
  66. package/src/agent/bash/interpret.ts +21 -3
  67. package/src/agent/components/composer-menu.tsx +4 -1
  68. package/src/agent/components/composer-place.tsx +144 -0
  69. package/src/agent/components/composer.tsx +13 -0
  70. package/src/agent/components/computer-place.tsx +18 -1
  71. package/src/agent/components/transcript.tsx +33 -1
  72. package/src/agent/components/web-fetch-tool-view.tsx +94 -29
  73. package/src/agent/delegation/child-parts.tsx +1 -1
  74. package/src/agent/hooks/use-agent-conversation.ts +68 -6
  75. package/src/agent/hooks/use-new-thread-place.ts +170 -0
  76. package/src/agent/i18n/en.ts +56 -3
  77. package/src/agent/i18n/fr.ts +58 -3
  78. package/src/agent/observed-conversation.tsx +3 -0
  79. package/src/agent/tool-views/built-in.tsx +26 -11
  80. package/src/agent/utils/web-fetch.ts +89 -10
  81. package/src/agent/utils/web-search.ts +67 -28
  82. package/src/pages/console/data/shared.tsx +1 -0
  83. package/src/pages/settings/usage/messages.ts +2 -0
  84. package/src/pages/settings/usage/spend-model.ts +1 -0
  85. /package/dist/{chunk-zxthr2q5.js.map → chunk-4j3c3p72.js.map} +0 -0
  86. /package/dist/{chunk-km25essq.js.map → chunk-7fj9cfkw.js.map} +0 -0
  87. /package/dist/{chunk-j9653e83.js.map → chunk-j8g956dt.js.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sixb/app",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Custom app toolkit for Sixb projects — route scanning, dev serving, and production builds",
5
5
  "keywords": [
6
6
  "sixb",
@@ -54,8 +54,8 @@
54
54
  "prepack": "bun run build"
55
55
  },
56
56
  "dependencies": {
57
- "@sixb/client": "^0.2.0",
58
- "@sixb/core": "^0.2.0",
57
+ "@sixb/client": "^0.2.1",
58
+ "@sixb/core": "^0.2.2",
59
59
  "@sixb/ui": "^0.2.0",
60
60
  "@tailwindcss/cli": "^4.2.2",
61
61
  "@xyflow/react": "^12.10.2",
@@ -1,4 +1,5 @@
1
1
  import { heldCallsInOutput } from "./approvals"
2
+ import { backgroundRowLabel, isBackgroundStart } from "./background/interpret"
2
3
  import {
3
4
  classifyCommand,
4
5
  coerceBashInput,
@@ -12,7 +13,7 @@ import { childQuestions, describeMessageAgent } from "./message-agent/interpret"
12
13
  import type { NormalizedPart, NormalizedTool } from "./parts"
13
14
  import { isPublishTool, publishTitle } from "./publish-artifact/interpret"
14
15
  import { coerceReadInput, coerceReadOutput, describeRead } from "./read/interpret"
15
- import { webFetchUrl } from "./utils/web-fetch"
16
+ import { webFetchQuestion, webFetchUrl } from "./utils/web-fetch"
16
17
  import { describeViewFile } from "./view-file/interpret"
17
18
 
18
19
  /** A short, present-tense label for the newest visible step in a live work group. */
@@ -39,13 +40,16 @@ function toolProgressLabel(
39
40
  const domain = webFetchUrl(tool.input)?.hostname.replace(/^www\./, "") ?? messages.web.webPage
40
41
  if (tool.state === "output-error") return messages.web.readFailed(domain)
41
42
  if (tool.state === "output-available") return messages.web.reviewing(domain)
42
- return messages.web.reading(domain)
43
+ return webFetchQuestion(tool.input) ? messages.web.asking(domain) : messages.web.reading(domain)
43
44
  }
44
45
  if (tool.toolName === "web_search") {
45
46
  if (tool.state === "output-error") return messages.web.continuingAfterFailure
46
47
  if (tool.state === "output-available") return messages.web.reviewingResults
47
48
  return messages.web.searching
48
49
  }
50
+ if (tool.toolName === "bash_output" || tool.toolName === "bash_stop" || isBackgroundStart(tool)) {
51
+ return backgroundRowLabel(tool, messages)
52
+ }
49
53
  if (tool.toolName === "bash") {
50
54
  if (tool.state === "input-streaming") return messages.bash.preparing
51
55
  if (tool.state === "output-available" && heldCallsInOutput(tool.output).length > 0) {
@@ -35,6 +35,24 @@
35
35
  }
36
36
  }
37
37
 
38
+ /* What a fetched page said, inside its row: one reading size, headings marked by weight alone. */
39
+ .prose.sixb-web-fetch {
40
+ font-size: 13px;
41
+ line-height: 1.6;
42
+ }
43
+
44
+ .prose.sixb-web-fetch-page {
45
+ font-size: 12px;
46
+ color: var(--muted-foreground);
47
+ }
48
+
49
+ .prose.sixb-web-fetch :is(h1, h2, h3, h4, h5, h6) {
50
+ margin: 0.75em 0 0.25em;
51
+ font-size: inherit;
52
+ font-weight: 600;
53
+ color: inherit;
54
+ }
55
+
38
56
  @keyframes sixb-reasoning-max {
39
57
  0%,
40
58
  100% {
@@ -0,0 +1,308 @@
1
+ import { Button, Collapsible, CollapsibleContent, CollapsibleTrigger } from "@sixb/ui/components"
2
+ import { cn } from "@sixb/ui/lib/utils"
3
+ import { ChevronRight, CircleCheck, CircleStop, CircleX, Square } from "lucide-react"
4
+ import { useEffect, useRef, useState } from "react"
5
+ import { useNow } from "../delegation/child-parts"
6
+ import { formatWorked } from "../delegation/interpret"
7
+ import { useAgentMessages } from "../i18n"
8
+ import type { AgentMessages } from "../i18n/en"
9
+ import type { NormalizedTool } from "../parts"
10
+ import { BackgroundToolRow } from "./background-tool-row"
11
+ import { useBackgroundCards } from "./context"
12
+ import {
13
+ type BackgroundCardState,
14
+ type BackgroundStart,
15
+ backgroundCardState,
16
+ backgroundStartOf,
17
+ } from "./interpret"
18
+
19
+ /** How many lines of what the agent read the card shows: the newest. */
20
+ const OUTPUT_LINES = 60
21
+
22
+ /**
23
+ * A command the agent started in the background, as its step in the work: the card that says how
24
+ * it stands, which only a reader who opens the steps sees. On its way, or outside a transcript, it
25
+ * is a quiet line like any other step.
26
+ */
27
+ export function BackgroundCommandStep({ tool }: { readonly tool: NormalizedTool }) {
28
+ const context = useBackgroundCards()
29
+ const start = backgroundStartOf(tool)
30
+ if (!context || start?.kind !== "started") return <BackgroundToolRow tool={tool} />
31
+
32
+ return (
33
+ // The steps scroll past their height: the card keeps its own rather than shrink with them.
34
+ <div className="min-w-0 shrink-0 overflow-hidden rounded-lg border border-border/70 bg-card text-card-foreground">
35
+ <BackgroundCommandCard start={start} />
36
+ </div>
37
+ )
38
+ }
39
+
40
+ /**
41
+ * One background command as it stands now: what runs, for how long or how it ended, the newest of
42
+ * what the agent read of its output, and, for its owner while it runs on their computer, Stop. Its
43
+ * calls, its `sixb`'s reports and its turn make one state (see `backgroundCardState`).
44
+ */
45
+ function BackgroundCommandCard({ start }: { readonly start: BackgroundStart }) {
46
+ const context = useBackgroundCards()
47
+ const messages = useAgentMessages()
48
+ const labels = messages.background
49
+ const [stopAsked, setStopAsked] = useState(false)
50
+ const [stopFailed, setStopFailed] = useState(false)
51
+ const [open, setOpen] = useState(false)
52
+
53
+ const calls = start.kind === "started" ? context?.thread.commands.get(start.key) : undefined
54
+ const state = context
55
+ ? backgroundCardState({
56
+ start,
57
+ ...(calls ? { calls } : {}),
58
+ source: context.source,
59
+ liveRunId: context.liveRunId,
60
+ stopAsked,
61
+ })
62
+ : null
63
+ const now = useNow(state?.status === "running")
64
+ if (!context || !state) return null
65
+
66
+ const stop = context.stop
67
+ const canStop = state.canStop && stop !== undefined && start.kind === "started"
68
+ const askStop = () => {
69
+ if (!canStop || start.kind !== "started") return
70
+ setStopAsked(true)
71
+ setStopFailed(false)
72
+ stop({ id: start.id, startedAt: start.startedAt }).catch(() => {
73
+ setStopAsked(false)
74
+ setStopFailed(true)
75
+ })
76
+ }
77
+
78
+ const command = firstLine(state.command)
79
+ const output = tail(state.output)
80
+
81
+ return (
82
+ <Collapsible
83
+ open={open}
84
+ onOpenChange={setOpen}
85
+ role="region"
86
+ aria-label={labels.card(command)}
87
+ data-background-status={state.status}
88
+ className="min-w-0"
89
+ >
90
+ {/* Said once per change of how it stands, never per tick of its clock. */}
91
+ <span className="sr-only" aria-live="polite">
92
+ {statusWords(state, labels)}
93
+ </span>
94
+
95
+ <div className="flex min-w-0 items-center gap-3 px-3 py-2.5 sm:px-3.5">
96
+ <StatusMark state={state} />
97
+ <div className="min-w-0 flex-1">
98
+ <p
99
+ className="truncate font-mono text-[12.5px] leading-5 text-foreground"
100
+ title={state.command}
101
+ >
102
+ {command}
103
+ </p>
104
+ <p className="truncate text-xs leading-5 text-muted-foreground tabular-nums">
105
+ <StatusLine state={state} now={now} messages={messages} />
106
+ </p>
107
+ </div>
108
+ <div className="flex shrink-0 items-center gap-1">
109
+ {output.lines.length > 0 ? (
110
+ <CollapsibleTrigger
111
+ aria-label={labels.output}
112
+ title={labels.lines(output.count)}
113
+ className="group flex h-6 items-center gap-0.5 rounded-md px-1.5 text-xs text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 data-[state=open]:text-foreground"
114
+ >
115
+ {/* A phone keeps the room for the command: the chevron says it opens. */}
116
+ <span className="hidden sm:inline">{labels.output}</span>
117
+ <ChevronRight
118
+ className="size-3.5 shrink-0 transition-transform group-data-[state=open]:rotate-90 motion-reduce:transition-none"
119
+ aria-hidden="true"
120
+ />
121
+ </CollapsibleTrigger>
122
+ ) : null}
123
+ {canStop ? (
124
+ <Button
125
+ type="button"
126
+ variant="outline"
127
+ size="xs"
128
+ onClick={askStop}
129
+ title={labels.stopHint}
130
+ className="rounded-full px-2.5 text-muted-foreground hover:text-foreground"
131
+ >
132
+ <Square className="size-2 fill-current" aria-hidden="true" />
133
+ {labels.stop}
134
+ </Button>
135
+ ) : null}
136
+ </div>
137
+ </div>
138
+
139
+ {stopFailed ? (
140
+ <p
141
+ role="alert"
142
+ className="-mt-1 px-3 pb-2.5 pl-10 text-xs text-destructive sm:pl-[2.875rem]"
143
+ >
144
+ {labels.stopFailed}
145
+ </p>
146
+ ) : null}
147
+
148
+ {output.lines.length > 0 ? (
149
+ <CollapsibleContent>
150
+ <OutputTail lines={output.lines} />
151
+ {(state.truncated || output.cut) && state.outputPath ? (
152
+ <p className="-mt-1 truncate px-3 pb-2.5 font-mono text-[11px] text-muted-foreground/70 sm:px-3.5">
153
+ {labels.earlierOutput(state.outputPath)}
154
+ </p>
155
+ ) : null}
156
+ </CollapsibleContent>
157
+ ) : null}
158
+ </Collapsible>
159
+ )
160
+ }
161
+
162
+ /** The newest output, scrolled to its end as it opens: a tail reads from the bottom. */
163
+ function OutputTail({ lines }: { readonly lines: readonly string[] }) {
164
+ const ref = useRef<HTMLPreElement>(null)
165
+ const text = lines.join("\n")
166
+ // biome-ignore lint/correctness/useExhaustiveDependencies: new output scrolls it again
167
+ useEffect(() => {
168
+ const pre = ref.current
169
+ if (pre) pre.scrollTop = pre.scrollHeight
170
+ }, [text])
171
+
172
+ return (
173
+ <pre
174
+ ref={ref}
175
+ className="scrollbar-thin mx-3 mb-3 max-h-56 overflow-auto overscroll-contain rounded-lg bg-muted/50 p-2.5 font-mono text-[11px] leading-relaxed whitespace-pre-wrap break-words text-foreground/90 sm:mx-3.5"
176
+ >
177
+ {text}
178
+ </pre>
179
+ )
180
+ }
181
+
182
+ /** Running pulses; an end reads at a glance: done, failed, stopped. */
183
+ function StatusMark({ state }: { readonly state: BackgroundCardState }) {
184
+ const box = "flex size-4 shrink-0 items-center justify-center"
185
+
186
+ if (state.status === "running" || state.status === "starting") {
187
+ const live = state.status === "running" && !state.stopping
188
+ return (
189
+ <span className={box} aria-hidden="true">
190
+ <span className="relative flex size-2">
191
+ {live ? (
192
+ <span className="absolute inline-flex size-full animate-ping rounded-full bg-emerald-500/50 motion-reduce:hidden" />
193
+ ) : null}
194
+ <span
195
+ className={cn(
196
+ "relative inline-flex size-2 rounded-full",
197
+ live ? "bg-emerald-500" : "animate-pulse bg-muted-foreground/40"
198
+ )}
199
+ />
200
+ </span>
201
+ </span>
202
+ )
203
+ }
204
+ if (state.status === "exited") {
205
+ return state.exitCode === 0 || state.exitCode === undefined ? (
206
+ <CircleCheck
207
+ className="size-4 shrink-0 text-emerald-600 dark:text-emerald-400"
208
+ aria-hidden="true"
209
+ />
210
+ ) : (
211
+ <CircleX className="size-4 shrink-0 text-red-600/85 dark:text-red-400" aria-hidden="true" />
212
+ )
213
+ }
214
+ if (state.status === "stopped") {
215
+ return <CircleStop className="size-4 shrink-0 text-muted-foreground" aria-hidden="true" />
216
+ }
217
+ return (
218
+ <span className={box} aria-hidden="true">
219
+ <span className="size-2 rounded-full bg-muted-foreground/35" />
220
+ </span>
221
+ )
222
+ }
223
+
224
+ /** How it stands, then for how long: `Running · 2m 14s`, `Failed · exit code 1 · 12s`. */
225
+ function StatusLine({
226
+ state,
227
+ now,
228
+ messages,
229
+ }: {
230
+ readonly state: BackgroundCardState
231
+ readonly now: number
232
+ readonly messages: AgentMessages
233
+ }) {
234
+ const labels = messages.background
235
+ const started = state.startedAt ? Date.parse(state.startedAt) : undefined
236
+ const ended = state.endedAt ? Date.parse(state.endedAt) : undefined
237
+ const ran =
238
+ started === undefined
239
+ ? undefined
240
+ : state.status === "running"
241
+ ? now - started
242
+ : ended === undefined
243
+ ? undefined
244
+ : ended - started
245
+ const time = ran === undefined ? null : formatWorked(ran, messages.delegation)
246
+
247
+ const clauses: { readonly text: string; readonly tone?: "live" | "quiet" }[] = []
248
+ const words = statusWords(state, labels)
249
+ clauses.push({
250
+ text: words,
251
+ ...(state.stopping || state.status === "starting" ? { tone: "live" as const } : {}),
252
+ })
253
+ if (time && !state.endedWith) clauses.push({ text: time })
254
+ if (state.status === "running" && !state.stopping && state.pending) {
255
+ clauses.push({ text: labels[state.pending], tone: "quiet" })
256
+ }
257
+
258
+ return clauses.map((clause, index) => (
259
+ <span key={clause.text}>
260
+ {index > 0 ? <span className="text-muted-foreground/50"> · </span> : null}
261
+ <span
262
+ className={cn(
263
+ clause.tone === "live" && "shimmer motion-reduce:animate-none",
264
+ clause.tone === "quiet" && "text-muted-foreground/70"
265
+ )}
266
+ >
267
+ {clause.text}
268
+ </span>
269
+ </span>
270
+ ))
271
+ }
272
+
273
+ function statusWords(state: BackgroundCardState, labels: AgentMessages["background"]): string {
274
+ if (state.stopping) return labels.stopping
275
+ switch (state.status) {
276
+ case "starting":
277
+ return labels.starting
278
+ case "running":
279
+ return labels.running
280
+ case "exited":
281
+ return labels.exited(state.exitCode ?? 0)
282
+ case "stopped":
283
+ return state.endedWith === "turn"
284
+ ? labels.stoppedWithTurn
285
+ : state.endedWith === "sixb"
286
+ ? labels.stoppedWithSixb
287
+ : labels.stopped
288
+ case "unknown":
289
+ return state.unreachable ? labels.unreachable : labels.unknown
290
+ }
291
+ }
292
+
293
+ /** The output's newest lines, and how many it has in all. */
294
+ function tail(output: string): {
295
+ readonly lines: readonly string[]
296
+ readonly count: number
297
+ readonly cut: boolean
298
+ } {
299
+ const trimmed = output.replace(/\s+$/, "")
300
+ if (!trimmed) return { lines: [], count: 0, cut: false }
301
+ const all = trimmed.split("\n")
302
+ return { lines: all.slice(-OUTPUT_LINES), count: all.length, cut: all.length > OUTPUT_LINES }
303
+ }
304
+
305
+ function firstLine(command: string): string {
306
+ const lines = command.trim().split("\n")
307
+ return (lines[0] ?? "") + (lines.length > 1 ? " …" : "")
308
+ }
@@ -0,0 +1,58 @@
1
+ import { Terminal } from "lucide-react"
2
+ import { ActivityStatusText } from "../components/activity-status"
3
+ import { useAgentMessages } from "../i18n"
4
+ import type { NormalizedTool } from "../parts"
5
+ import { toolResultValue } from "../parts"
6
+ import { useBackgroundCards } from "./context"
7
+ import { backgroundRowLabel } from "./interpret"
8
+
9
+ /**
10
+ * A call that starts, reads or stops a background command, as one quiet line of the work: the
11
+ * card under the work is where the command stands, so the line only says what the agent did.
12
+ */
13
+ export function BackgroundToolRow({ tool }: { readonly tool: NormalizedTool }) {
14
+ const messages = useAgentMessages()
15
+ const context = useBackgroundCards()
16
+ const running = tool.state === "input-streaming" || tool.state === "input-available"
17
+ const label = backgroundRowLabel(tool, messages)
18
+ const detail = commandNamed(tool, context?.thread.commands)
19
+
20
+ return (
21
+ <div className="flex w-fit max-w-full items-center gap-1.5 text-[13px] leading-normal text-muted-foreground">
22
+ <Terminal className="size-3.5 shrink-0" />
23
+ {running ? (
24
+ <ActivityStatusText label={label} className="font-medium shimmer" />
25
+ ) : (
26
+ <span className="min-w-0 truncate font-medium">{label}</span>
27
+ )}
28
+ {detail ? (
29
+ // A phone keeps the line for what the agent did.
30
+ <span className="hidden min-w-0 shrink truncate font-mono text-xs text-muted-foreground/60 sm:inline">
31
+ {detail}
32
+ </span>
33
+ ) : null}
34
+ </div>
35
+ )
36
+ }
37
+
38
+ /** The command a call names: its own input, what it returned, or the start of that id. */
39
+ function commandNamed(
40
+ tool: NormalizedTool,
41
+ commands: ReadonlyMap<string, { readonly id: string; readonly command: string }> | undefined
42
+ ): string {
43
+ const input = isRecord(tool.input) ? tool.input : {}
44
+ const output = toolResultValue(tool.output)
45
+ const named =
46
+ typeof input.command === "string"
47
+ ? input.command
48
+ : isRecord(output) && typeof output.command === "string"
49
+ ? output.command
50
+ : [...(commands?.values() ?? [])].reverse().find((command) => command.id === input.id)
51
+ ?.command
52
+ const line = named?.trim().split("\n")[0] ?? ""
53
+ return line || (typeof input.id === "string" ? input.id : "")
54
+ }
55
+
56
+ function isRecord(value: unknown): value is Record<string, unknown> {
57
+ return typeof value === "object" && value !== null && !Array.isArray(value)
58
+ }
@@ -0,0 +1,26 @@
1
+ import { createContext, useContext } from "react"
2
+ import type { BackgroundSource, ThreadBackground } from "./interpret"
3
+
4
+ /** What a conversation knows of its background commands, and lets its reader do with them. */
5
+ export interface TranscriptBackground {
6
+ readonly source: BackgroundSource
7
+ /**
8
+ * Ask its computer to stop a command, which it does at once: its owner's, while their `sixb`
9
+ * runs it. Absent for anyone else.
10
+ */
11
+ readonly stop?: (command: { readonly id: string; readonly startedAt: string }) => Promise<void>
12
+ }
13
+
14
+ /** What the background command cards of a transcript read. */
15
+ export interface BackgroundCardsContext extends TranscriptBackground {
16
+ readonly thread: ThreadBackground
17
+ /** The turn streaming now, which runs the commands it started. */
18
+ readonly liveRunId: string | null
19
+ }
20
+
21
+ /** Null outside a transcript, such as in a workflow's agent trace: no card is shown there. */
22
+ export const BackgroundCardsContext = createContext<BackgroundCardsContext | null>(null)
23
+
24
+ export function useBackgroundCards(): BackgroundCardsContext | null {
25
+ return useContext(BackgroundCardsContext)
26
+ }