@sixb/app 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent-chat.d.ts +8 -1
- package/dist/agent/agent-chat.d.ts.map +1 -1
- package/dist/agent/agent-panel.d.ts +8 -1
- package/dist/agent/agent-panel.d.ts.map +1 -1
- package/dist/agent/agent-surface.d.ts +8 -1
- package/dist/agent/agent-surface.d.ts.map +1 -1
- package/dist/agent/approvals.d.ts +1 -4
- package/dist/agent/approvals.d.ts.map +1 -1
- package/dist/agent/artifact-panel.d.ts +21 -2
- package/dist/agent/artifact-panel.d.ts.map +1 -1
- package/dist/agent/components/activity-status.d.ts +1 -1
- package/dist/agent/components/activity-status.d.ts.map +1 -1
- package/dist/agent/components/agent-threads.d.ts +15 -0
- package/dist/agent/components/agent-threads.d.ts.map +1 -0
- package/dist/agent/components/approval-card.d.ts +4 -4
- package/dist/agent/components/approval-card.d.ts.map +1 -1
- package/dist/agent/components/approval-mode-chip.d.ts +4 -6
- package/dist/agent/components/approval-mode-chip.d.ts.map +1 -1
- package/dist/agent/components/auto-model-chip.d.ts +2 -3
- package/dist/agent/components/auto-model-chip.d.ts.map +1 -1
- package/dist/agent/components/composer-menu.d.ts +42 -0
- package/dist/agent/components/composer-menu.d.ts.map +1 -0
- package/dist/agent/components/composer.d.ts +8 -5
- package/dist/agent/components/composer.d.ts.map +1 -1
- package/dist/agent/components/conversation-panel.d.ts +3 -12
- package/dist/agent/components/conversation-panel.d.ts.map +1 -1
- package/dist/agent/components/dictation-bar.d.ts +13 -0
- package/dist/agent/components/dictation-bar.d.ts.map +1 -0
- package/dist/agent/components/message-parts.d.ts.map +1 -1
- package/dist/agent/components/message-view.d.ts +3 -1
- package/dist/agent/components/message-view.d.ts.map +1 -1
- package/dist/agent/components/model-controls.d.ts +15 -0
- package/dist/agent/components/model-controls.d.ts.map +1 -1
- package/dist/agent/components/model-picker-row.d.ts +9 -2
- package/dist/agent/components/model-picker-row.d.ts.map +1 -1
- package/dist/agent/components/participant-input.d.ts +7 -6
- package/dist/agent/components/participant-input.d.ts.map +1 -1
- package/dist/agent/components/thread-people.d.ts +4 -4
- package/dist/agent/components/thread-people.d.ts.map +1 -1
- package/dist/agent/components/threads-button.d.ts +14 -0
- package/dist/agent/components/threads-button.d.ts.map +1 -0
- package/dist/agent/conversation.d.ts +3 -1
- package/dist/agent/conversation.d.ts.map +1 -1
- package/dist/agent/delegation/child-card.d.ts +24 -11
- package/dist/agent/delegation/child-card.d.ts.map +1 -1
- package/dist/agent/delegation/child-cards.d.ts +2 -2
- package/dist/agent/delegation/child-cards.d.ts.map +1 -1
- package/dist/agent/delegation/child-group.d.ts +5 -4
- package/dist/agent/delegation/child-group.d.ts.map +1 -1
- package/dist/agent/delegation/child-parts.d.ts +17 -18
- package/dist/agent/delegation/child-parts.d.ts.map +1 -1
- package/dist/agent/delegation/child-work.d.ts +0 -13
- package/dist/agent/delegation/child-work.d.ts.map +1 -1
- package/dist/agent/delegation/interpret.d.ts +0 -5
- package/dist/agent/delegation/interpret.d.ts.map +1 -1
- package/dist/agent/delegation/model.d.ts +12 -6
- package/dist/agent/delegation/model.d.ts.map +1 -1
- package/dist/agent/dictation.d.ts +16 -0
- package/dist/agent/dictation.d.ts.map +1 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts +3 -270
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-people-suggestions.d.ts +21 -0
- package/dist/agent/hooks/use-people-suggestions.d.ts.map +1 -0
- package/dist/agent/hooks/use-thread-lists.d.ts +220 -0
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -0
- package/dist/agent/i18n/en.d.ts +47 -36
- package/dist/agent/i18n/en.d.ts.map +1 -1
- package/dist/agent/i18n/fr.d.ts.map +1 -1
- package/dist/agent/i18n/index.d.ts +84 -72
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/react-router.d.ts +9 -0
- package/dist/agent/react-router.d.ts.map +1 -1
- package/dist/agent/run-presentation.d.ts +4 -1
- package/dist/agent/run-presentation.d.ts.map +1 -1
- package/dist/agent/thread-navigation.d.ts +8 -0
- package/dist/agent/thread-navigation.d.ts.map +1 -1
- package/dist/agent/thread-pages.d.ts +11 -0
- package/dist/agent/thread-pages.d.ts.map +1 -0
- package/dist/artifacts/person-avatar.d.ts +2 -2
- package/dist/{chunk-aes17xmx.js → chunk-12v6y89k.js} +4180 -3793
- package/dist/{chunk-aes17xmx.js.map → chunk-12v6y89k.js.map} +48 -42
- package/dist/{chunk-0yb22w6m.js → chunk-2a69ge8h.js} +1 -1
- package/dist/{chunk-vtp6nk44.js → chunk-bpj9mg5c.js} +1 -1
- package/dist/{chunk-1rhht9y0.js → chunk-hzy2g13h.js} +1 -1
- package/dist/createCustomApp.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -6
- package/dist/index.js.map +6 -6
- package/dist/pages/home.d.ts.map +1 -1
- package/dist/pages/observability/ai-usage/calls.d.ts.map +1 -1
- package/dist/pages/settings/memory-history.d.ts.map +1 -1
- package/dist/pages/settings/messages.d.ts.map +1 -1
- package/dist/pages/values.d.ts +5 -0
- package/dist/pages/values.d.ts.map +1 -1
- package/dist/pages.d.ts +1 -1
- package/dist/pages.d.ts.map +1 -1
- package/dist/pages.js +60 -44
- package/dist/pages.js.map +8 -8
- package/dist/server.js +12 -6
- package/dist/server.js.map +3 -3
- package/dist/shell/agent-dock.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/agent/agent-chat.tsx +15 -23
- package/src/agent/agent-panel.tsx +11 -0
- package/src/agent/agent-surface.tsx +11 -0
- package/src/agent/agent.css +33 -3
- package/src/agent/approvals.ts +4 -5
- package/src/agent/artifact-panel.tsx +113 -37
- package/src/agent/components/activity-status.tsx +1 -1
- package/src/agent/components/agent-threads.tsx +377 -0
- package/src/agent/components/approval-card.tsx +336 -327
- package/src/agent/components/approval-mode-chip.tsx +38 -145
- package/src/agent/components/auto-model-chip.tsx +103 -167
- package/src/agent/components/composer-menu.tsx +185 -0
- package/src/agent/components/composer.tsx +168 -103
- package/src/agent/components/context-chips.tsx +1 -1
- package/src/agent/components/conversation-panel.tsx +16 -36
- package/src/agent/components/dictation-bar.tsx +110 -0
- package/src/agent/components/file-attachment-card.tsx +5 -2
- package/src/agent/components/message-parts.tsx +27 -11
- package/src/agent/components/message-view.tsx +182 -68
- package/src/agent/components/model-controls.tsx +133 -125
- package/src/agent/components/model-picker-row.tsx +38 -17
- package/src/agent/components/participant-input.tsx +159 -31
- package/src/agent/components/reasoning-effort-slider.tsx +27 -27
- package/src/agent/components/shared-thread-notice.tsx +1 -1
- package/src/agent/components/thread-people.tsx +45 -15
- package/src/agent/components/threads-button.tsx +70 -0
- package/src/agent/components/transcript.tsx +30 -1
- package/src/agent/conversation.ts +25 -1
- package/src/agent/delegation/child-card.tsx +187 -247
- package/src/agent/delegation/child-cards.tsx +4 -7
- package/src/agent/delegation/child-group.tsx +179 -98
- package/src/agent/delegation/child-parts.tsx +71 -106
- package/src/agent/delegation/child-work.tsx +6 -52
- package/src/agent/delegation/interpret.ts +0 -28
- package/src/agent/delegation/model.ts +115 -39
- package/src/agent/dictation.ts +48 -0
- package/src/agent/hooks/use-agent-conversation.ts +10 -92
- package/src/agent/hooks/use-people-suggestions.ts +90 -0
- package/src/agent/hooks/use-thread-lists.ts +77 -0
- package/src/agent/i18n/en.ts +100 -83
- package/src/agent/i18n/fr.ts +109 -100
- package/src/agent/react-router.tsx +48 -5
- package/src/agent/run-presentation.ts +6 -2
- package/src/agent/thread-navigation.ts +16 -0
- package/src/agent/thread-pages.ts +24 -0
- package/src/artifacts/person-avatar.tsx +1 -1
- package/src/createCustomApp.ts +13 -6
- package/src/index.ts +7 -3
- package/src/pages/home.tsx +3 -1
- package/src/pages/observability/ai-usage/calls.tsx +2 -1
- package/src/pages/settings/memory-history.tsx +2 -1
- package/src/pages/settings/messages.ts +2 -3
- package/src/pages/values.tsx +23 -1
- package/src/pages.ts +5 -1
- package/src/shell/agent-dock.tsx +4 -2
- package/dist/agent/agents-page.d.ts +0 -4
- package/dist/agent/agents-page.d.ts.map +0 -1
- package/dist/agent/components/agent-thread-switcher.d.ts +0 -37
- package/dist/agent/components/agent-thread-switcher.d.ts.map +0 -1
- package/src/agent/agents-page.ts +0 -7
- package/src/agent/components/agent-thread-switcher.tsx +0 -519
- /package/dist/{chunk-0yb22w6m.js.map → chunk-2a69ge8h.js.map} +0 -0
- /package/dist/{chunk-vtp6nk44.js.map → chunk-bpj9mg5c.js.map} +0 -0
- /package/dist/{chunk-1rhht9y0.js.map → chunk-hzy2g13h.js.map} +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Spinner } from "@sixb/ui/components"
|
|
2
|
-
import {
|
|
3
|
-
import { Fragment, memo, type ReactNode, useEffect, useLayoutEffect, useMemo, useRef } from "react"
|
|
2
|
+
import { Fragment, memo, type ReactNode, useEffect, useMemo, useRef } from "react"
|
|
4
3
|
import { childFileSource, messageFileSource } from "../../artifacts/file-source"
|
|
5
4
|
import { FileAttachmentCard } from "../components/file-attachment-card"
|
|
6
5
|
import { AssistantBody } from "../components/message-parts"
|
|
@@ -116,16 +115,11 @@ export function ChildWork({
|
|
|
116
115
|
} else if (atWork && live?.runId === run.id && live.parts.length > 0) {
|
|
117
116
|
body = <AssistantBody parts={live.parts} live={live.active} nested />
|
|
118
117
|
} else if (atWork) {
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
: run.status === "queued"
|
|
125
|
-
? labels.states.starting
|
|
126
|
-
: labels.states.working}
|
|
127
|
-
</p>
|
|
128
|
-
)
|
|
118
|
+
// Its status says it works; until its first step, nothing more to say. An observer reads
|
|
119
|
+
// no stream: a run's steps come once it ended.
|
|
120
|
+
body = observed ? (
|
|
121
|
+
<p className="text-[13px] text-muted-foreground">{labels.stepsLater}</p>
|
|
122
|
+
) : null
|
|
129
123
|
} else if (messages.isError) {
|
|
130
124
|
body = <p className="text-[13px] text-muted-foreground">{labels.loadFailed}</p>
|
|
131
125
|
} else if (messages.isLoading || messages.isFetching) {
|
|
@@ -202,43 +196,3 @@ const RunWork = memo(function RunWork({
|
|
|
202
196
|
</>
|
|
203
197
|
)
|
|
204
198
|
})
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* A scrolling box that follows new content while its reader is at its end, and stays where they
|
|
208
|
-
* scrolled otherwise.
|
|
209
|
-
*/
|
|
210
|
-
export function FollowingScroll({
|
|
211
|
-
follow,
|
|
212
|
-
live,
|
|
213
|
-
className,
|
|
214
|
-
children,
|
|
215
|
-
}: {
|
|
216
|
-
/** Changes when the content grows. */
|
|
217
|
-
readonly follow: string
|
|
218
|
-
/** The content is still growing: it opens at its end. Otherwise at its start. */
|
|
219
|
-
readonly live: boolean
|
|
220
|
-
readonly className?: string
|
|
221
|
-
readonly children: ReactNode
|
|
222
|
-
}) {
|
|
223
|
-
const box = useRef<HTMLDivElement>(null)
|
|
224
|
-
const atEnd = useRef(live)
|
|
225
|
-
|
|
226
|
-
// biome-ignore lint/correctness/useExhaustiveDependencies: `follow` is the trigger
|
|
227
|
-
useLayoutEffect(() => {
|
|
228
|
-
const element = box.current
|
|
229
|
-
if (element && atEnd.current) element.scrollTop = element.scrollHeight
|
|
230
|
-
}, [follow])
|
|
231
|
-
|
|
232
|
-
return (
|
|
233
|
-
<div
|
|
234
|
-
ref={box}
|
|
235
|
-
onScroll={(event) => {
|
|
236
|
-
const element = event.currentTarget
|
|
237
|
-
atEnd.current = element.scrollHeight - element.scrollTop - element.clientHeight < 48
|
|
238
|
-
}}
|
|
239
|
-
className={cn("scrollbar-thin overflow-y-auto overscroll-contain", className)}
|
|
240
|
-
>
|
|
241
|
-
{children}
|
|
242
|
-
</div>
|
|
243
|
-
)
|
|
244
|
-
}
|
|
@@ -260,34 +260,6 @@ export function workedMs(view: AgentChild, now: number): number {
|
|
|
260
260
|
}, 0)
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
/**
|
|
264
|
-
* What children spent together, in the currency the first of them was priced in; nothing until a
|
|
265
|
-
* call was priced.
|
|
266
|
-
*/
|
|
267
|
-
export function childrenCost(
|
|
268
|
-
views: readonly (AgentChild | undefined)[],
|
|
269
|
-
locale: string
|
|
270
|
-
): string | null {
|
|
271
|
-
const amounts = views.flatMap((view) => view?.cost?.amounts ?? [])
|
|
272
|
-
const currency = amounts[0]?.currency
|
|
273
|
-
if (!currency) return null
|
|
274
|
-
|
|
275
|
-
const nanos = amounts
|
|
276
|
-
.filter((amount) => amount.currency === currency)
|
|
277
|
-
.reduce((total, amount) => total + BigInt(amount.amountNanos), 0n)
|
|
278
|
-
const value = Number(nanos) / 1_000_000_000
|
|
279
|
-
const format = (figure: number) =>
|
|
280
|
-
new Intl.NumberFormat(locale, {
|
|
281
|
-
style: "currency",
|
|
282
|
-
currency,
|
|
283
|
-
minimumFractionDigits: 2,
|
|
284
|
-
maximumFractionDigits: 2,
|
|
285
|
-
}).format(figure)
|
|
286
|
-
|
|
287
|
-
if (value > 0 && value < 0.01) return `< ${format(0.01)}`
|
|
288
|
-
return format(value)
|
|
289
|
-
}
|
|
290
|
-
|
|
291
263
|
/**
|
|
292
264
|
* A child's name, from the key the Agent spawned it with: "supplier-terms" reads "Supplier terms",
|
|
293
265
|
* "checkINV4490" reads "Check INV4490". The key's own capitals stay.
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type AgentChild,
|
|
6
6
|
type ChildState,
|
|
7
7
|
childState,
|
|
8
|
+
childTitle,
|
|
8
9
|
isActive,
|
|
9
10
|
liveQuestion,
|
|
10
11
|
type SpawnedChild,
|
|
@@ -101,51 +102,126 @@ export function isSettled(state: ChildState): boolean {
|
|
|
101
102
|
)
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
/** One
|
|
105
|
-
export interface
|
|
106
|
-
readonly
|
|
107
|
-
readonly
|
|
105
|
+
/** One clause of a reply's line: some sub-agents by name, and how they stand. */
|
|
106
|
+
export interface LineClause {
|
|
107
|
+
readonly names: string
|
|
108
|
+
readonly verb: string
|
|
109
|
+
/** `urgent`: the reader is the one to act. `live`: still at work. */
|
|
110
|
+
readonly tone: "urgent" | "live" | "quiet"
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
/**
|
|
111
|
-
|
|
113
|
+
/**
|
|
114
|
+
* A reply's sub-agents as a sentence, its clauses in the order a reader cares about: what waits
|
|
115
|
+
* on them, what is at work, then how the rest ended. "Terms needs your approval · History is
|
|
116
|
+
* working", "Terms, History and Disputes finished".
|
|
117
|
+
*/
|
|
118
|
+
export function lineClauses(
|
|
112
119
|
models: readonly ChildModel[],
|
|
113
120
|
messages: AgentMessages
|
|
114
|
-
):
|
|
115
|
-
const labels = messages.delegation
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
)
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
): readonly LineClause[] {
|
|
122
|
+
const labels = messages.delegation.line
|
|
123
|
+
const clause = (
|
|
124
|
+
test: (model: ChildModel) => boolean,
|
|
125
|
+
verb: (agents: number) => string,
|
|
126
|
+
tone: LineClause["tone"]
|
|
127
|
+
): LineClause | null => {
|
|
128
|
+
const named = models.filter(test).map((model) => shortName(childTitle(model.child.key)))
|
|
129
|
+
return named.length > 0 ? { names: labels.names(named), verb: verb(named.length), tone } : null
|
|
130
|
+
}
|
|
131
|
+
const person = personWaitedOn(models)
|
|
132
|
+
const urgent = [
|
|
133
|
+
clause((model) => model.needsReader && model.state === "approval", labels.approval, "urgent"),
|
|
134
|
+
clause((model) => model.needsReader && model.state === "answer", labels.answer, "urgent"),
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
// Many, or long-named, read as a count: names would turn the line into a paragraph. Whoever
|
|
138
|
+
// waits on the reader is still named.
|
|
139
|
+
// A lone agent is always named, its name shortened if it must be.
|
|
140
|
+
if (
|
|
141
|
+
models.length > NAMED_AGENTS ||
|
|
142
|
+
(models.length > 1 && models.some((model) => !named(model)))
|
|
143
|
+
) {
|
|
144
|
+
const counts = messages.delegation
|
|
145
|
+
const counted = (
|
|
146
|
+
test: (model: ChildModel) => boolean,
|
|
147
|
+
verb: (agents: number) => string,
|
|
148
|
+
tone: LineClause["tone"]
|
|
149
|
+
): LineClause | null => {
|
|
150
|
+
const agents = models.filter(test).length
|
|
151
|
+
return agents > 0 ? { names: "", verb: verb(agents), tone } : null
|
|
152
|
+
}
|
|
153
|
+
return [
|
|
154
|
+
{ names: counts.count(models.length), verb: "", tone: "quiet" as const },
|
|
155
|
+
...urgent,
|
|
156
|
+
counted(
|
|
157
|
+
waitingOther,
|
|
158
|
+
person ? (agents) => counts.waitingOn(agents, person) : counts.waitingOthers,
|
|
159
|
+
"quiet"
|
|
160
|
+
),
|
|
161
|
+
counted((model) => isActive(model.state), counts.working, "live"),
|
|
162
|
+
counted((model) => model.state === "resume", counts.later, "quiet"),
|
|
163
|
+
counted((model) => model.state === "done", counts.done, "quiet"),
|
|
164
|
+
counted((model) => model.state === "failed", counts.failed, "quiet"),
|
|
165
|
+
counted(
|
|
166
|
+
(model) => model.state === "stopped" || model.state === "ended",
|
|
167
|
+
counts.stopped,
|
|
168
|
+
"quiet"
|
|
169
|
+
),
|
|
170
|
+
].filter((part): part is LineClause => part !== null)
|
|
171
|
+
}
|
|
131
172
|
|
|
132
173
|
return [
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
174
|
+
...urgent,
|
|
175
|
+
clause(
|
|
176
|
+
waitingOther,
|
|
177
|
+
person ? (agents) => labels.waitingOn(agents, person) : labels.waiting,
|
|
178
|
+
"quiet"
|
|
179
|
+
),
|
|
180
|
+
clause((model) => model.state === "asking", labels.asking, "live"),
|
|
181
|
+
clause((model) => model.state === "working", labels.working, "live"),
|
|
182
|
+
clause((model) => model.state === "starting", labels.starting, "live"),
|
|
183
|
+
clause((model) => model.state === "resume", labels.later, "quiet"),
|
|
184
|
+
clause((model) => model.state === "done", labels.done, "quiet"),
|
|
185
|
+
clause((model) => model.state === "failed", labels.failed, "quiet"),
|
|
186
|
+
clause(
|
|
187
|
+
(model) => model.state === "stopped" || model.state === "ended",
|
|
188
|
+
labels.stopped,
|
|
189
|
+
"quiet"
|
|
190
|
+
),
|
|
191
|
+
].filter((part): part is LineClause => part !== null)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Waiting on someone, but not on the reader: their approval or their answer. */
|
|
195
|
+
function waitingOther(model: ChildModel): boolean {
|
|
196
|
+
return (model.state === "approval" || model.state === "answer") && !model.needsReader
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The one person the others wait on, when it is one person. */
|
|
200
|
+
function personWaitedOn(models: readonly ChildModel[]): string | null {
|
|
201
|
+
const people = new Set(
|
|
202
|
+
models
|
|
203
|
+
.filter(waitingOther)
|
|
204
|
+
.map((model) => (model.waitingOn.kind === "person" ? model.waitingOn.name : ""))
|
|
205
|
+
)
|
|
206
|
+
const [person] = people
|
|
207
|
+
return people.size === 1 && person ? person : null
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** The longest a name reads in the line before it is cut at a word; its thread shows it whole. */
|
|
211
|
+
const LINE_NAME_LENGTH = 28
|
|
212
|
+
|
|
213
|
+
/** Up to this many sub-agents, with short names, the line names each; past it, it counts them. */
|
|
214
|
+
const NAMED_AGENTS = 3
|
|
215
|
+
|
|
216
|
+
function named(model: ChildModel): boolean {
|
|
217
|
+
return childTitle(model.child.key).length <= 20
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function shortName(name: string): string {
|
|
221
|
+
if (name.length <= LINE_NAME_LENGTH) return name
|
|
222
|
+
const cut = name.slice(0, LINE_NAME_LENGTH)
|
|
223
|
+
const word = cut.lastIndexOf(" ")
|
|
224
|
+
return `${(word > LINE_NAME_LENGTH / 2 ? cut.slice(0, word) : cut).replace(/[\s,.:;-]+$/, "")}…`
|
|
149
225
|
}
|
|
150
226
|
|
|
151
227
|
/** What `wait_agent` last said of any of the child's runs. */
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ListModelsResponse, transcribeAudio } from "@sixb/client"
|
|
2
|
+
import { createRecordingSpeechRecognizer, type SpeechRecognizer } from "@sixb/ui/lib/speech"
|
|
3
|
+
|
|
4
|
+
// btoa takes a string of byte characters; spreading the whole recording would overflow the stack.
|
|
5
|
+
const BASE64_CHUNK_BYTES = 0x8000
|
|
6
|
+
|
|
7
|
+
const projectRecognizer = createRecordingSpeechRecognizer({
|
|
8
|
+
id: "sixb-transcription",
|
|
9
|
+
transcribe: transcribeDictation,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The recognizer behind the chat's microphone, when the project declares a transcription model
|
|
14
|
+
* and the reader may call it; otherwise none, and the chat shows no microphone. Never the
|
|
15
|
+
* browser's own recognition, which sends the audio to Google or Apple.
|
|
16
|
+
*/
|
|
17
|
+
export function projectDictation(
|
|
18
|
+
catalog: ListModelsResponse | undefined
|
|
19
|
+
): SpeechRecognizer | undefined {
|
|
20
|
+
if (!catalog?.capabilities.run || catalog.audio.transcription.length === 0) return undefined
|
|
21
|
+
return projectRecognizer
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Transcribes a recording with the project's default transcription model. The audio travels
|
|
26
|
+
* inline in the request: it reaches the model without ever being stored.
|
|
27
|
+
*/
|
|
28
|
+
export async function transcribeDictation(
|
|
29
|
+
audio: Blob,
|
|
30
|
+
{ signal }: { readonly signal: AbortSignal }
|
|
31
|
+
): Promise<string> {
|
|
32
|
+
const { data } = await transcribeAudio({
|
|
33
|
+
body: { audio: { data: await toBase64(audio), mediaType: audio.type } },
|
|
34
|
+
signal,
|
|
35
|
+
throwOnError: true,
|
|
36
|
+
})
|
|
37
|
+
return data.text
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function toBase64(audio: Blob): Promise<string> {
|
|
41
|
+
const bytes = new Uint8Array(await audio.arrayBuffer())
|
|
42
|
+
let binary = ""
|
|
43
|
+
for (let offset = 0; offset < bytes.length; offset += BASE64_CHUNK_BYTES) {
|
|
44
|
+
binary += String.fromCharCode(...bytes.subarray(offset, offset + BASE64_CHUNK_BYTES))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return btoa(binary)
|
|
48
|
+
}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
getAgentPreferencesQueryKey,
|
|
9
9
|
getAgentThreadOptions,
|
|
10
10
|
getAgentThreadQueryKey,
|
|
11
|
-
listAgentApprovalsOptions,
|
|
12
11
|
listAgentApprovalsQueryKey,
|
|
13
12
|
listAgentThreadApprovalsOptions,
|
|
14
13
|
listAgentThreadApprovalsQueryKey,
|
|
@@ -16,7 +15,6 @@ import {
|
|
|
16
15
|
listAgentThreadMessagesQueryKey,
|
|
17
16
|
listAgentThreadRunsOptions,
|
|
18
17
|
listAgentThreadRunsQueryKey,
|
|
19
|
-
listAgentThreadsInfiniteOptions,
|
|
20
18
|
listAgentThreadsQueryKey,
|
|
21
19
|
listModelsOptions,
|
|
22
20
|
postAgentThreadMessageMutation,
|
|
@@ -27,7 +25,7 @@ import {
|
|
|
27
25
|
useAgentActivityStream,
|
|
28
26
|
} from "@sixb/client/hooks"
|
|
29
27
|
import { MODEL_REASONING_LEVELS, type ModelReasoningLevel } from "@sixb/core/models"
|
|
30
|
-
import {
|
|
28
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
|
|
31
29
|
import { useEffect, useMemo, useRef, useState } from "react"
|
|
32
30
|
import { useCurrentUser } from "../../session"
|
|
33
31
|
import {
|
|
@@ -46,6 +44,7 @@ import type { SandboxRecoveryProps } from "../components/sandbox-recovery"
|
|
|
46
44
|
import type { TranscriptProps } from "../components/transcript"
|
|
47
45
|
import { conversationMessages, conversationTurn, type PendingUserMessage } from "../conversation"
|
|
48
46
|
import type { TranscriptDelegation } from "../delegation/context"
|
|
47
|
+
import { projectDictation } from "../dictation"
|
|
49
48
|
import { useAgentMessages } from "../i18n"
|
|
50
49
|
import { knownName } from "../message-authors"
|
|
51
50
|
import {
|
|
@@ -75,8 +74,8 @@ import {
|
|
|
75
74
|
threadOwner,
|
|
76
75
|
userPrincipal,
|
|
77
76
|
} from "../sharing"
|
|
78
|
-
import { THREAD_PAGE_SIZE } from "../thread-navigation"
|
|
79
77
|
import type { AgentContextEntryInput, AgentFileRef, AgentRun, LanguageModel } from "../types"
|
|
78
|
+
import { useAgentThreadLists } from "./use-thread-lists"
|
|
80
79
|
import { useThreadStream } from "./use-thread-stream"
|
|
81
80
|
|
|
82
81
|
interface PendingSend {
|
|
@@ -91,24 +90,9 @@ interface PendingSend {
|
|
|
91
90
|
/** Keys of the messages the reader sends, so each keeps its key once it is saved. */
|
|
92
91
|
let sentMessageCount = 0
|
|
93
92
|
|
|
94
|
-
const THREAD_LIST_QUERY = {
|
|
95
|
-
limit: String(THREAD_PAGE_SIZE),
|
|
96
|
-
order: "desc" as const,
|
|
97
|
-
}
|
|
98
|
-
|
|
99
93
|
/** Enough of a thread's held calls for every card: a turn holds a few, and a thread few turns. */
|
|
100
94
|
const THREAD_APPROVALS_QUERY = { limit: "200" }
|
|
101
95
|
|
|
102
|
-
/** The calls waiting for the reader across threads, for the thread list. */
|
|
103
|
-
const PENDING_APPROVALS_QUERY = { status: "pending" as const, limit: "200" }
|
|
104
|
-
|
|
105
|
-
/** The conversations others shared with the reader: one page, newest first. */
|
|
106
|
-
const SHARED_THREAD_LIST_QUERY = {
|
|
107
|
-
sharedWithMe: "true" as const,
|
|
108
|
-
limit: String(THREAD_PAGE_SIZE),
|
|
109
|
-
order: "desc" as const,
|
|
110
|
-
}
|
|
111
|
-
|
|
112
96
|
const MODEL_PREFERENCE_KEY = "sixb.agent-ui.model-preference"
|
|
113
97
|
const MODEL_PINS_KEY = "sixb.agent-ui.model-pins"
|
|
114
98
|
/** Pins kept per browser, the most recently chosen last; older ones fall back to Auto. */
|
|
@@ -149,10 +133,9 @@ export type ConversationComposerProps = Pick<
|
|
|
149
133
|
| "draftContext"
|
|
150
134
|
| "draftNonce"
|
|
151
135
|
| "approvalMode"
|
|
152
|
-
| "defaultApprovalMode"
|
|
153
136
|
| "onApprovalModeChange"
|
|
154
|
-
| "onMakeApprovalModeDefault"
|
|
155
137
|
| "awaitingApproval"
|
|
138
|
+
| "dictation"
|
|
156
139
|
>
|
|
157
140
|
|
|
158
141
|
export type AgentConversation = ReturnType<typeof useAgentConversation>
|
|
@@ -218,37 +201,8 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
218
201
|
// The project activity feed is primary. Poll only as a focus-aware recovery path while the
|
|
219
202
|
// socket is unavailable, rather than opening one connection per background thread.
|
|
220
203
|
const recoveryPollMs = !activityStream.connected || activityStream.error ? 10_000 : false
|
|
221
|
-
const
|
|
222
|
-
...listAgentThreadsInfiniteOptions({ query: THREAD_LIST_QUERY }),
|
|
223
|
-
initialPageParam: { query: THREAD_LIST_QUERY },
|
|
224
|
-
getNextPageParam: (lastPage, pages) => {
|
|
225
|
-
if (!lastPage.hasMore) return undefined
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
query: {
|
|
229
|
-
...THREAD_LIST_QUERY,
|
|
230
|
-
offset: String(pages.length * THREAD_PAGE_SIZE),
|
|
231
|
-
},
|
|
232
|
-
}
|
|
233
|
-
},
|
|
234
|
-
refetchInterval: recoveryPollMs,
|
|
235
|
-
})
|
|
236
|
-
// Nothing announces a new share or a removal: read the list again when the reader comes back.
|
|
237
|
-
const sharedThreadsQuery = useInfiniteQuery({
|
|
238
|
-
...listAgentThreadsInfiniteOptions({ query: SHARED_THREAD_LIST_QUERY }),
|
|
239
|
-
initialPageParam: { query: SHARED_THREAD_LIST_QUERY },
|
|
240
|
-
getNextPageParam: (lastPage, pages) => {
|
|
241
|
-
if (!lastPage.hasMore) return undefined
|
|
242
|
-
|
|
243
|
-
return {
|
|
244
|
-
query: {
|
|
245
|
-
...SHARED_THREAD_LIST_QUERY,
|
|
246
|
-
offset: String(pages.length * THREAD_PAGE_SIZE),
|
|
247
|
-
},
|
|
248
|
-
}
|
|
249
|
-
},
|
|
204
|
+
const { threads, sharedThreads, waitingThreadIds } = useAgentThreadLists({
|
|
250
205
|
refetchInterval: recoveryPollMs,
|
|
251
|
-
refetchOnWindowFocus: true,
|
|
252
206
|
})
|
|
253
207
|
const currentAgent = agentQuery.data
|
|
254
208
|
const models = useMemo(() => modelsQuery.data?.language ?? [], [modelsQuery.data])
|
|
@@ -265,16 +219,6 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
265
219
|
)
|
|
266
220
|
const selectedModel = modelSelection.model
|
|
267
221
|
const selectedReasoning = modelSelection.reasoning
|
|
268
|
-
const threads = useMemo(
|
|
269
|
-
() => threadsQuery.data?.pages.flatMap((page) => page.threads) ?? [],
|
|
270
|
-
[threadsQuery.data]
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
const sharedThreads = useMemo(
|
|
274
|
-
() => sharedThreadsQuery.data?.pages.flatMap((page) => page.threads) ?? [],
|
|
275
|
-
[sharedThreadsQuery.data]
|
|
276
|
-
)
|
|
277
|
-
|
|
278
222
|
const threadQuery = useQuery({
|
|
279
223
|
...getAgentThreadOptions({ path: { threadId: threadId ?? "" } }),
|
|
280
224
|
enabled: threadId !== null,
|
|
@@ -346,19 +290,6 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
346
290
|
)
|
|
347
291
|
return pending.length === 0 ? read : [...read, ...pending]
|
|
348
292
|
}, [threadId, approvalsQuery.data, pendingHereQuery.data])
|
|
349
|
-
const pendingApprovalsQuery = useQuery({
|
|
350
|
-
...listAgentApprovalsOptions({ query: PENDING_APPROVALS_QUERY }),
|
|
351
|
-
refetchInterval: recoveryPollMs,
|
|
352
|
-
retry: false,
|
|
353
|
-
})
|
|
354
|
-
/** The threads where a call waits for the reader. */
|
|
355
|
-
const waitingThreadIds = useMemo(
|
|
356
|
-
() =>
|
|
357
|
-
new Set(
|
|
358
|
-
(pendingApprovalsQuery.data?.approvals ?? []).map((approval) => approval.threadId)
|
|
359
|
-
) as ReadonlySet<string>,
|
|
360
|
-
[pendingApprovalsQuery.data]
|
|
361
|
-
)
|
|
362
293
|
|
|
363
294
|
const [pendingSend, setPendingSend] = useState<PendingSend | null>(null)
|
|
364
295
|
const [pendingUser, setPendingUser] = useState<PendingUserMessage | null>(null)
|
|
@@ -668,9 +599,11 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
668
599
|
/**
|
|
669
600
|
* What the reader's next turns here may change without asking. In a thread it is kept as their
|
|
670
601
|
* own choice there, on every device; in a new conversation, until its first message makes one.
|
|
602
|
+
* Either way it becomes their default too, so the next conversation starts where they left off.
|
|
671
603
|
*/
|
|
672
604
|
const setApprovalMode = (mode: AgentApprovalMode) => {
|
|
673
605
|
setChosenApprovalMode({ threadId, mode })
|
|
606
|
+
if (mode !== defaultApprovalMode) setDefaultApprovalMode(mode)
|
|
674
607
|
if (threadId === null) return
|
|
675
608
|
|
|
676
609
|
// Saves run one after the other: until the last choice is saved, the chip keeps showing it.
|
|
@@ -831,8 +764,6 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
831
764
|
return () => window.removeEventListener("storage", follow)
|
|
832
765
|
}, [])
|
|
833
766
|
|
|
834
|
-
const agentThreads = threads.filter((entry) => entry.id !== threadId)
|
|
835
|
-
|
|
836
767
|
const sandboxRecovery =
|
|
837
768
|
thread?.sandboxState &&
|
|
838
769
|
!isRunning &&
|
|
@@ -881,6 +812,7 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
881
812
|
isRunning,
|
|
882
813
|
sandboxRecovery: Boolean(sandboxRecovery),
|
|
883
814
|
messages: savedMessages,
|
|
815
|
+
latestRun,
|
|
884
816
|
})
|
|
885
817
|
|
|
886
818
|
const reader = user
|
|
@@ -893,6 +825,7 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
893
825
|
reader,
|
|
894
826
|
pending: pendingUser && pendingUser.threadId === threadId ? pendingUser : null,
|
|
895
827
|
sentKeys,
|
|
828
|
+
runs,
|
|
896
829
|
live,
|
|
897
830
|
presentation,
|
|
898
831
|
})
|
|
@@ -1030,10 +963,9 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
1030
963
|
draftContext: draftReseed.context,
|
|
1031
964
|
draftNonce: draftReseed.nonce,
|
|
1032
965
|
approvalMode,
|
|
1033
|
-
defaultApprovalMode,
|
|
1034
966
|
onApprovalModeChange: setApprovalMode,
|
|
1035
|
-
onMakeApprovalModeDefault: setDefaultApprovalMode,
|
|
1036
967
|
awaitingApproval,
|
|
968
|
+
dictation: projectDictation(modelsQuery.data),
|
|
1037
969
|
}
|
|
1038
970
|
|
|
1039
971
|
const sandboxRecoveryProps: SandboxRecoveryProps | null = sandboxRecovery
|
|
@@ -1067,25 +999,11 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
1067
999
|
selectReasoning,
|
|
1068
1000
|
resetReasoning,
|
|
1069
1001
|
resetModelSelection,
|
|
1070
|
-
threads,
|
|
1071
1002
|
/** Threads with a run in progress, counting this one while its run starts. */
|
|
1072
1003
|
runningThreadCount,
|
|
1073
|
-
threadsError: threadsQuery.isError,
|
|
1074
|
-
threadsHasMore: threadsQuery.hasNextPage,
|
|
1075
|
-
threadsLoadingMore: threadsQuery.isFetchingNextPage,
|
|
1076
|
-
threadsLoadMoreError: threadsQuery.isFetchNextPageError,
|
|
1077
|
-
loadMoreThreads: () => threadsQuery.fetchNextPage(),
|
|
1078
1004
|
threadUnavailable,
|
|
1079
1005
|
currentAgent,
|
|
1080
1006
|
currentThread: thread,
|
|
1081
|
-
agentThreads,
|
|
1082
|
-
sharedThreads,
|
|
1083
|
-
sharedThreadsTotal: sharedThreadsQuery.data?.pages[0]?.total ?? 0,
|
|
1084
|
-
sharedThreadsError: sharedThreadsQuery.isError,
|
|
1085
|
-
sharedThreadsHasMore: sharedThreadsQuery.hasNextPage,
|
|
1086
|
-
sharedThreadsLoadingMore: sharedThreadsQuery.isFetchingNextPage,
|
|
1087
|
-
sharedThreadsLoadMoreError: sharedThreadsQuery.isFetchNextPageError,
|
|
1088
|
-
loadMoreSharedThreads: () => sharedThreadsQuery.fetchNextPage(),
|
|
1089
1007
|
access,
|
|
1090
1008
|
user,
|
|
1091
1009
|
removedFromThread,
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { listUsersOptions } from "@sixb/client/hooks"
|
|
2
|
+
import { keepPreviousData, useQuery } from "@tanstack/react-query"
|
|
3
|
+
import { useMemo } from "react"
|
|
4
|
+
import { useAgentThreadLists } from "./use-thread-lists"
|
|
5
|
+
|
|
6
|
+
/** Someone the share field can suggest: a member, with their email when the directory gave it. */
|
|
7
|
+
export interface PersonSuggestion {
|
|
8
|
+
readonly id: string
|
|
9
|
+
readonly name: string
|
|
10
|
+
readonly email?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The most the field lists at once. */
|
|
14
|
+
const SUGGESTIONS = 6
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Who the share field suggests for what the owner typed. The people they already share threads
|
|
18
|
+
* with come first: they reveal no one new. With `can.view(project.users)`, any member whose name
|
|
19
|
+
* or email matches follows; without it, the directory is skipped and a typed email still works.
|
|
20
|
+
* Before anything is typed, only those people show.
|
|
21
|
+
*/
|
|
22
|
+
export function usePeopleSuggestions(input: {
|
|
23
|
+
readonly text: string
|
|
24
|
+
/** User ids not to suggest: the reader, whoever is in the thread, and whoever is picked. */
|
|
25
|
+
readonly exclude: ReadonlySet<string>
|
|
26
|
+
}) {
|
|
27
|
+
const query = input.text.trim().toLowerCase()
|
|
28
|
+
|
|
29
|
+
// Whether the reader may read the directory, asked once: the field's wording follows it.
|
|
30
|
+
const directory = useQuery({
|
|
31
|
+
...listUsersOptions({ query: { limit: 1 } }),
|
|
32
|
+
retry: false,
|
|
33
|
+
staleTime: 5 * 60_000,
|
|
34
|
+
})
|
|
35
|
+
const canSearch = directory.isSuccess
|
|
36
|
+
const matches = useQuery({
|
|
37
|
+
...listUsersOptions({ query: { search: query, limit: SUGGESTIONS } }),
|
|
38
|
+
enabled: canSearch && query.length > 0,
|
|
39
|
+
placeholderData: keepPreviousData,
|
|
40
|
+
staleTime: 30_000,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const { threads, sharedThreads } = useAgentThreadLists({})
|
|
44
|
+
const known = useMemo(() => {
|
|
45
|
+
const people = new Map<string, PersonSuggestion>()
|
|
46
|
+
const add = (principal: { readonly type: string; readonly id: string }, name?: string) => {
|
|
47
|
+
if (principal.type !== "user" || people.has(principal.id)) return
|
|
48
|
+
people.set(principal.id, { id: principal.id, name: name ?? principal.id })
|
|
49
|
+
}
|
|
50
|
+
// Newest first, as the lists come: whoever the reader worked with lately leads.
|
|
51
|
+
for (const thread of [...sharedThreads, ...threads].sort(byRecency)) {
|
|
52
|
+
add(thread.ownerPrincipal, thread.owner.displayName)
|
|
53
|
+
for (const participant of thread.participants) {
|
|
54
|
+
add(participant.principal, participant.principal.displayName)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return [...people.values()]
|
|
58
|
+
}, [threads, sharedThreads])
|
|
59
|
+
|
|
60
|
+
const suggestions = useMemo(() => {
|
|
61
|
+
const picked = new Map<string, PersonSuggestion>()
|
|
62
|
+
const offer = (person: PersonSuggestion) => {
|
|
63
|
+
if (input.exclude.has(person.id) || picked.has(person.id)) return
|
|
64
|
+
picked.set(person.id, person)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (const person of known) {
|
|
68
|
+
if (!query || person.name.toLowerCase().includes(query)) offer(person)
|
|
69
|
+
}
|
|
70
|
+
if (query && canSearch) {
|
|
71
|
+
for (const user of matches.data?.users ?? []) {
|
|
72
|
+
if (user.status !== "active") continue
|
|
73
|
+
const earlier = picked.get(user.id)
|
|
74
|
+
// Someone from a thread keeps their place, and gains the email the directory knows.
|
|
75
|
+
if (earlier) picked.set(user.id, { ...earlier, email: user.email })
|
|
76
|
+
else offer({ id: user.id, name: user.displayName ?? user.email, email: user.email })
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return [...picked.values()].slice(0, SUGGESTIONS)
|
|
80
|
+
}, [known, matches.data, query, canSearch, input.exclude])
|
|
81
|
+
|
|
82
|
+
return { suggestions, canSearch }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function byRecency(
|
|
86
|
+
a: { readonly lastMessageAt?: string | null; readonly updatedAt: string },
|
|
87
|
+
b: { readonly lastMessageAt?: string | null; readonly updatedAt: string }
|
|
88
|
+
): number {
|
|
89
|
+
return (b.lastMessageAt ?? b.updatedAt).localeCompare(a.lastMessageAt ?? a.updatedAt)
|
|
90
|
+
}
|