@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.
- package/assets/connector-icons/README.md +1 -0
- package/assets/connector-icons/fleetio.ico +0 -0
- package/dist/agent/activity-label.d.ts.map +1 -1
- package/dist/agent/background/background-card.d.ts +10 -0
- package/dist/agent/background/background-card.d.ts.map +1 -0
- package/dist/agent/background/background-tool-row.d.ts +9 -0
- package/dist/agent/background/background-tool-row.d.ts.map +1 -0
- package/dist/agent/background/context.d.ts +23 -0
- package/dist/agent/background/context.d.ts.map +1 -0
- package/dist/agent/background/interpret.d.ts +116 -0
- package/dist/agent/background/interpret.d.ts.map +1 -0
- package/dist/agent/bash/bash-tool-view.d.ts.map +1 -1
- package/dist/agent/bash/interpret.d.ts +4 -0
- package/dist/agent/bash/interpret.d.ts.map +1 -1
- package/dist/agent/components/composer-menu.d.ts +3 -1
- package/dist/agent/components/composer-menu.d.ts.map +1 -1
- package/dist/agent/components/composer-place.d.ts +11 -0
- package/dist/agent/components/composer-place.d.ts.map +1 -0
- package/dist/agent/components/composer.d.ts +4 -1
- package/dist/agent/components/composer.d.ts.map +1 -1
- package/dist/agent/components/computer-place.d.ts +3 -1
- package/dist/agent/components/computer-place.d.ts.map +1 -1
- package/dist/agent/components/transcript.d.ts +6 -0
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/components/web-fetch-tool-view.d.ts.map +1 -1
- package/dist/agent/delegation/child-parts.d.ts +2 -0
- package/dist/agent/delegation/child-parts.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/hooks/use-agent-conversation.d.ts +15 -1
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-new-thread-place.d.ts +48 -0
- package/dist/agent/hooks/use-new-thread-place.d.ts.map +1 -0
- package/dist/agent/hooks/use-thread-lists.d.ts +40 -0
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +60 -0
- 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 +106 -0
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/observed-conversation.d.ts.map +1 -1
- package/dist/agent/tool-views/built-in.d.ts.map +1 -1
- package/dist/agent/utils/web-fetch.d.ts +33 -1
- package/dist/agent/utils/web-fetch.d.ts.map +1 -1
- package/dist/agent/utils/web-search.d.ts +14 -2
- package/dist/agent/utils/web-search.d.ts.map +1 -1
- package/dist/{chunk-zxthr2q5.js → chunk-4j3c3p72.js} +1 -1
- package/dist/{chunk-km25essq.js → chunk-7fj9cfkw.js} +1 -1
- package/dist/{chunk-j9653e83.js → chunk-j8g956dt.js} +1 -1
- package/dist/{chunk-fw2bm6dq.js → chunk-ytadd0b5.js} +3095 -1994
- package/dist/{chunk-fw2bm6dq.js.map → chunk-ytadd0b5.js.map} +25 -19
- package/dist/index.js +1 -1
- package/dist/pages/console/data/shared.d.ts.map +1 -1
- package/dist/pages/settings/usage/messages.d.ts +2 -0
- package/dist/pages/settings/usage/messages.d.ts.map +1 -1
- package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
- package/dist/pages.js +13 -6
- package/dist/pages.js.map +6 -6
- package/package.json +3 -3
- package/src/agent/activity-label.ts +6 -2
- package/src/agent/agent.css +18 -0
- package/src/agent/background/background-card.tsx +308 -0
- package/src/agent/background/background-tool-row.tsx +58 -0
- package/src/agent/background/context.ts +26 -0
- package/src/agent/background/interpret.ts +356 -0
- package/src/agent/bash/bash-tool-view.tsx +9 -4
- package/src/agent/bash/interpret.ts +21 -3
- package/src/agent/components/composer-menu.tsx +4 -1
- package/src/agent/components/composer-place.tsx +144 -0
- package/src/agent/components/composer.tsx +13 -0
- package/src/agent/components/computer-place.tsx +18 -1
- package/src/agent/components/transcript.tsx +33 -1
- package/src/agent/components/web-fetch-tool-view.tsx +94 -29
- package/src/agent/delegation/child-parts.tsx +1 -1
- package/src/agent/hooks/use-agent-conversation.ts +68 -6
- package/src/agent/hooks/use-new-thread-place.ts +170 -0
- package/src/agent/i18n/en.ts +56 -3
- package/src/agent/i18n/fr.ts +58 -3
- package/src/agent/observed-conversation.tsx +3 -0
- package/src/agent/tool-views/built-in.tsx +26 -11
- package/src/agent/utils/web-fetch.ts +89 -10
- package/src/agent/utils/web-search.ts +67 -28
- package/src/pages/console/data/shared.tsx +1 -0
- package/src/pages/settings/usage/messages.ts +2 -0
- package/src/pages/settings/usage/spend-model.ts +1 -0
- /package/dist/{chunk-zxthr2q5.js.map → chunk-4j3c3p72.js.map} +0 -0
- /package/dist/{chunk-km25essq.js.map → chunk-7fj9cfkw.js.map} +0 -0
- /package/dist/{chunk-j9653e83.js.map → chunk-j8g956dt.js.map} +0 -0
|
@@ -60,6 +60,8 @@ export interface ComputerOfflineNoticeProps {
|
|
|
60
60
|
/** Why the last move failed: a turn it must wait for, or anything else. */
|
|
61
61
|
readonly error: "busy" | "failed" | null
|
|
62
62
|
readonly onContinueInCloud: () => void
|
|
63
|
+
/** In a desktop app on this conversation's own computer: ask the person to run it here. */
|
|
64
|
+
readonly onRunHere?: () => void
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
/**
|
|
@@ -71,6 +73,7 @@ export function ComputerOfflineNotice({
|
|
|
71
73
|
pending,
|
|
72
74
|
error,
|
|
73
75
|
onContinueInCloud,
|
|
76
|
+
onRunHere,
|
|
74
77
|
}: ComputerOfflineNoticeProps) {
|
|
75
78
|
const messages = useAgentMessages().computer
|
|
76
79
|
return (
|
|
@@ -81,9 +84,23 @@ export function ComputerOfflineNotice({
|
|
|
81
84
|
<Laptop aria-hidden className="size-3.5 shrink-0" />
|
|
82
85
|
<span className="min-w-0 flex-1">
|
|
83
86
|
{computer
|
|
84
|
-
?
|
|
87
|
+
? onRunHere
|
|
88
|
+
? messages.offlineHere(shownFolder(computer.folder))
|
|
89
|
+
: messages.offlineNotice(computer.name, shownFolder(computer.folder))
|
|
85
90
|
: messages.noFolder}
|
|
86
91
|
</span>
|
|
92
|
+
{onRunHere ? (
|
|
93
|
+
<Button
|
|
94
|
+
type="button"
|
|
95
|
+
variant="outline"
|
|
96
|
+
size="sm"
|
|
97
|
+
disabled={pending}
|
|
98
|
+
className="h-7 rounded-full"
|
|
99
|
+
onClick={onRunHere}
|
|
100
|
+
>
|
|
101
|
+
{messages.runHere}
|
|
102
|
+
</Button>
|
|
103
|
+
) : null}
|
|
87
104
|
<AlertDialog>
|
|
88
105
|
<AlertDialogTrigger asChild>
|
|
89
106
|
<Button
|
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
type ReportedApprovalOutcome,
|
|
16
16
|
type TranscriptApprovals,
|
|
17
17
|
} from "../approvals"
|
|
18
|
+
import { BackgroundCardsContext, type TranscriptBackground } from "../background/context"
|
|
19
|
+
import { BACKGROUND_TOOLS, readThreadBackground } from "../background/interpret"
|
|
18
20
|
import type { AgentConversationMessage, AgentConversationTurn } from "../conversation"
|
|
19
21
|
import { DelegationCardsContext, type TranscriptDelegation } from "../delegation/context"
|
|
20
22
|
import {
|
|
@@ -67,10 +69,20 @@ export interface TranscriptProps {
|
|
|
67
69
|
readonly delegation?: TranscriptDelegation
|
|
68
70
|
/** Where the conversation moved, after which saved message: the files from before stayed. */
|
|
69
71
|
readonly moved?: { readonly afterMessageId: string; readonly label: string } | null
|
|
72
|
+
/**
|
|
73
|
+
* Where its background commands run and what is known of them now, each a card under the work
|
|
74
|
+
* that started it. Without it, a command its turn no longer runs reads as last seen running.
|
|
75
|
+
*/
|
|
76
|
+
readonly background?: TranscriptBackground
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
const NO_OUTCOMES: ReadonlyMap<string, ReportedApprovalOutcome> = new Map()
|
|
73
80
|
|
|
81
|
+
/** Nothing said of where the commands run: no card claims how one ended that nobody saw. */
|
|
82
|
+
const UNKNOWN_BACKGROUND: TranscriptBackground = {
|
|
83
|
+
source: { onComputer: true, live: null, online: false },
|
|
84
|
+
}
|
|
85
|
+
|
|
74
86
|
export function Transcript(props: TranscriptProps) {
|
|
75
87
|
const { approvals, approvalOutcomes, messages, turn, threadId, delegation: actions } = props
|
|
76
88
|
const cards = useMemo(
|
|
@@ -91,10 +103,30 @@ export function Transcript(props: TranscriptProps) {
|
|
|
91
103
|
[threadId, delegation, liveRunId, actions]
|
|
92
104
|
)
|
|
93
105
|
|
|
106
|
+
// Its background commands change as their calls do, not with every chunk of the reply.
|
|
107
|
+
const backgroundSignature = JSON.stringify(
|
|
108
|
+
messages.flatMap((message) =>
|
|
109
|
+
message.parts.flatMap((part) =>
|
|
110
|
+
part.type === "tool" && BACKGROUND_TOOLS.has(part.toolName)
|
|
111
|
+
? [[part.toolCallId, part.state]]
|
|
112
|
+
: []
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the signature stands for the calls
|
|
117
|
+
const thread = useMemo(() => readThreadBackground(messages), [backgroundSignature])
|
|
118
|
+
const { background = UNKNOWN_BACKGROUND } = props
|
|
119
|
+
const backgroundCards = useMemo(
|
|
120
|
+
() => ({ ...background, thread, liveRunId }),
|
|
121
|
+
[background, thread, liveRunId]
|
|
122
|
+
)
|
|
123
|
+
|
|
94
124
|
return (
|
|
95
125
|
<ApprovalCardsContext.Provider value={cards}>
|
|
96
126
|
<DelegationCardsContext.Provider value={children}>
|
|
97
|
-
<
|
|
127
|
+
<BackgroundCardsContext.Provider value={backgroundCards}>
|
|
128
|
+
<TranscriptView {...props} threadDelegation={delegation} />
|
|
129
|
+
</BackgroundCardsContext.Provider>
|
|
98
130
|
</DelegationCardsContext.Provider>
|
|
99
131
|
</ApprovalCardsContext.Provider>
|
|
100
132
|
)
|
|
@@ -1,19 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Collapsible,
|
|
3
|
+
CollapsibleContent,
|
|
4
|
+
CollapsibleTrigger,
|
|
5
|
+
Markdown,
|
|
6
|
+
type MarkdownProps,
|
|
7
|
+
} from "@sixb/ui/components"
|
|
8
|
+
import { useLocale } from "@sixb/ui/lib/i18n"
|
|
2
9
|
import { ArrowUpRight, ChevronRight, Globe } from "lucide-react"
|
|
10
|
+
import { formatFileSize } from "../../artifacts/file-size"
|
|
3
11
|
import { useAgentMessages } from "../i18n"
|
|
4
12
|
import type { NormalizedTool } from "../parts"
|
|
5
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
coerceWebFetchOutput,
|
|
15
|
+
type WebFetchPage,
|
|
16
|
+
webFetchQuestion,
|
|
17
|
+
webFetchUrl,
|
|
18
|
+
} from "../utils/web-fetch"
|
|
19
|
+
import { displayDomain } from "../utils/web-search"
|
|
6
20
|
import { ActivityStatusText } from "./activity-status"
|
|
7
21
|
import { SourceFavicon } from "./web-sources"
|
|
8
22
|
|
|
23
|
+
// A page's images, or those its answer quotes, would load from their sites as soon as the row
|
|
24
|
+
// opens: the text is enough.
|
|
25
|
+
const PAGE_COMPONENTS: MarkdownProps["components"] = { img: () => null }
|
|
26
|
+
|
|
9
27
|
export function WebFetchToolView({ tool }: { tool: NormalizedTool }) {
|
|
10
28
|
const messages = useAgentMessages().web
|
|
11
29
|
const running = tool.state === "input-streaming" || tool.state === "input-available"
|
|
12
30
|
const failed = tool.state === "output-error"
|
|
13
|
-
const
|
|
31
|
+
const page = coerceWebFetchOutput(tool.output)
|
|
14
32
|
const url = webFetchUrl(tool.input)
|
|
15
|
-
const
|
|
16
|
-
|
|
33
|
+
const question = page?.question ?? webFetchQuestion(tool.input)
|
|
34
|
+
|
|
35
|
+
const domain = page?.source.domain ?? (url ? displayDomain(url) : messages.webPage)
|
|
36
|
+
const favicon = page?.source.faviconUrl ?? (url ? new URL("/favicon.ico", url.origin).href : null)
|
|
37
|
+
const label = running
|
|
38
|
+
? question
|
|
39
|
+
? messages.asking(domain)
|
|
40
|
+
: messages.reading(domain)
|
|
41
|
+
: failed
|
|
42
|
+
? messages.readFailed(domain)
|
|
43
|
+
: (page?.source.title ?? messages.read(domain))
|
|
17
44
|
|
|
18
45
|
return (
|
|
19
46
|
<Collapsible className="min-w-0 space-y-1 text-[13px] text-muted-foreground">
|
|
@@ -27,17 +54,14 @@ export function WebFetchToolView({ tool }: { tool: NormalizedTool }) {
|
|
|
27
54
|
</span>
|
|
28
55
|
<span className="min-w-0 flex-1">
|
|
29
56
|
{running ? (
|
|
30
|
-
<ActivityStatusText
|
|
31
|
-
label={messages.reading(domain)}
|
|
32
|
-
className="shimmer motion-reduce:animate-none"
|
|
33
|
-
/>
|
|
57
|
+
<ActivityStatusText label={label} className="shimmer motion-reduce:animate-none" />
|
|
34
58
|
) : (
|
|
35
|
-
<span className="line-clamp-2 font-medium break-words">
|
|
36
|
-
{failed ? messages.readFailed(domain) : (source?.title ?? messages.read(domain))}
|
|
37
|
-
</span>
|
|
59
|
+
<span className="line-clamp-2 font-medium break-words">{label}</span>
|
|
38
60
|
)}
|
|
39
|
-
{
|
|
40
|
-
<span className="mt-0.5 block truncate text-xs text-muted-foreground/70">
|
|
61
|
+
{page && !running && !failed ? (
|
|
62
|
+
<span className="mt-0.5 block truncate text-xs text-muted-foreground/70">
|
|
63
|
+
{page.redirect ? messages.redirectedTo(page.redirect.domain) : domain}
|
|
64
|
+
</span>
|
|
41
65
|
) : null}
|
|
42
66
|
</span>
|
|
43
67
|
<ChevronRight className="mt-0.5 size-3.5 shrink-0 opacity-0 transition-all group-hover:opacity-100 group-focus-visible:opacity-100 group-data-[state=open]:rotate-90 group-data-[state=open]:opacity-100 motion-reduce:transition-none" />
|
|
@@ -48,22 +72,63 @@ export function WebFetchToolView({ tool }: { tool: NormalizedTool }) {
|
|
|
48
72
|
</p>
|
|
49
73
|
) : null}
|
|
50
74
|
<CollapsibleContent className="space-y-2 pt-1 pl-[26px]">
|
|
51
|
-
{
|
|
52
|
-
|
|
53
|
-
<p className="leading-relaxed break-words">{source.excerpt || messages.noPageText}</p>
|
|
54
|
-
<a
|
|
55
|
-
href={source.url}
|
|
56
|
-
target="_blank"
|
|
57
|
-
rel="noopener noreferrer"
|
|
58
|
-
className="flex w-fit items-center gap-1 rounded text-xs font-medium underline-offset-4 hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring pointer-coarse:min-h-11"
|
|
59
|
-
>
|
|
60
|
-
{messages.openPage}
|
|
61
|
-
<ArrowUpRight className="size-3.5" aria-hidden="true" />
|
|
62
|
-
<span className="sr-only">{messages.newTab}</span>
|
|
63
|
-
</a>
|
|
64
|
-
</>
|
|
65
|
-
) : null}
|
|
75
|
+
{question ? <p className="font-medium break-words text-foreground/80">{question}</p> : null}
|
|
76
|
+
{page ? <PageContent page={page} /> : null}
|
|
66
77
|
</CollapsibleContent>
|
|
67
78
|
</Collapsible>
|
|
68
79
|
)
|
|
69
80
|
}
|
|
81
|
+
|
|
82
|
+
/** The answer when the agent asked one, else the start of the page; then what the server sent. */
|
|
83
|
+
function PageContent({ page }: { page: WebFetchPage }) {
|
|
84
|
+
const messages = useAgentMessages()
|
|
85
|
+
const locale = useLocale()
|
|
86
|
+
|
|
87
|
+
const served = [
|
|
88
|
+
page.status,
|
|
89
|
+
page.contentType?.split(";")[0],
|
|
90
|
+
page.bytes !== undefined ? formatFileSize(page.bytes, locale, messages.files) : undefined,
|
|
91
|
+
page.truncated ? messages.web.truncated : undefined,
|
|
92
|
+
].filter((value) => value !== undefined)
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<>
|
|
96
|
+
{page.answer ? (
|
|
97
|
+
<>
|
|
98
|
+
<Markdown className="sixb-web-fetch text-foreground" components={PAGE_COMPONENTS}>
|
|
99
|
+
{page.answer}
|
|
100
|
+
</Markdown>
|
|
101
|
+
{page.answerTruncated ? (
|
|
102
|
+
<p className="text-xs text-muted-foreground/70">{messages.web.answerTruncated}</p>
|
|
103
|
+
) : null}
|
|
104
|
+
</>
|
|
105
|
+
) : page.preview ? (
|
|
106
|
+
<>
|
|
107
|
+
{page.answerFailed ? <p>{messages.web.answerFailed}</p> : null}
|
|
108
|
+
<div className="scrollbar-thin max-h-60 overflow-y-auto overscroll-contain rounded bg-muted/50 p-2">
|
|
109
|
+
<Markdown className="sixb-web-fetch sixb-web-fetch-page" components={PAGE_COMPONENTS}>
|
|
110
|
+
{page.preview}
|
|
111
|
+
</Markdown>
|
|
112
|
+
</div>
|
|
113
|
+
</>
|
|
114
|
+
) : page.redirect ? null : (
|
|
115
|
+
<p>{messages.web.noPageText}</p>
|
|
116
|
+
)}
|
|
117
|
+
{served.length > 0 ? (
|
|
118
|
+
<p className="truncate font-mono text-[10px] text-muted-foreground/60">
|
|
119
|
+
{served.join(" · ")}
|
|
120
|
+
</p>
|
|
121
|
+
) : null}
|
|
122
|
+
<a
|
|
123
|
+
href={page.redirect?.url ?? page.source.url}
|
|
124
|
+
target="_blank"
|
|
125
|
+
rel="noopener noreferrer"
|
|
126
|
+
className="flex w-fit items-center gap-1 rounded text-xs font-medium underline-offset-4 hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring pointer-coarse:min-h-11"
|
|
127
|
+
>
|
|
128
|
+
{messages.web.openPage}
|
|
129
|
+
<ArrowUpRight className="size-3.5" aria-hidden="true" />
|
|
130
|
+
<span className="sr-only">{messages.web.newTab}</span>
|
|
131
|
+
</a>
|
|
132
|
+
</>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
@@ -274,7 +274,7 @@ function tierOf(value: string | undefined): "light" | "standard" | "heavy" | und
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
/** Now, every second while `ticking`: an elapsed time that moves. */
|
|
277
|
-
function useNow(ticking: boolean): number {
|
|
277
|
+
export function useNow(ticking: boolean): number {
|
|
278
278
|
const [now, setNow] = useState(() => Date.now())
|
|
279
279
|
useEffect(() => {
|
|
280
280
|
setNow(Date.now())
|
|
@@ -24,8 +24,10 @@ import {
|
|
|
24
24
|
recreateAgentThreadSandboxMutation,
|
|
25
25
|
retryAgentRunMutation,
|
|
26
26
|
setAgentThreadApprovalModeMutation,
|
|
27
|
+
stopAgentBackgroundCommandMutation,
|
|
27
28
|
updateAgentPreferencesMutation,
|
|
28
29
|
useAgentActivityStream,
|
|
30
|
+
useDesktop,
|
|
29
31
|
} from "@sixb/client/hooks"
|
|
30
32
|
import { MODEL_REASONING_LEVELS, type ModelReasoningLevel } from "@sixb/core/models"
|
|
31
33
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
|
|
@@ -42,6 +44,7 @@ import {
|
|
|
42
44
|
reportedApprovalOutcomes,
|
|
43
45
|
type TranscriptApprovals,
|
|
44
46
|
} from "../approvals"
|
|
47
|
+
import type { TranscriptBackground } from "../background/context"
|
|
45
48
|
import type { ComposerProps } from "../components/composer"
|
|
46
49
|
import { type ComputerOfflineNoticeProps, shownFolder } from "../components/computer-place"
|
|
47
50
|
import type { SandboxRecoveryProps } from "../components/sandbox-recovery"
|
|
@@ -81,6 +84,7 @@ import {
|
|
|
81
84
|
userPrincipal,
|
|
82
85
|
} from "../sharing"
|
|
83
86
|
import type { AgentContextEntryInput, AgentFileRef, AgentRun, LanguageModel } from "../types"
|
|
87
|
+
import { ComputerUnavailableError, useNewThreadPlace } from "./use-new-thread-place"
|
|
84
88
|
import { useAgentThreadLists } from "./use-thread-lists"
|
|
85
89
|
import { useThreadStream } from "./use-thread-stream"
|
|
86
90
|
|
|
@@ -116,6 +120,7 @@ export interface UseAgentConversationInput {
|
|
|
116
120
|
export type ConversationComposerProps = Pick<
|
|
117
121
|
ComposerProps,
|
|
118
122
|
| "onSend"
|
|
123
|
+
| "newThreadPlace"
|
|
119
124
|
| "error"
|
|
120
125
|
| "disabled"
|
|
121
126
|
| "pending"
|
|
@@ -153,6 +158,8 @@ export type AgentConversationSendError =
|
|
|
153
158
|
| { readonly code: "busy"; readonly someoneElse: boolean }
|
|
154
159
|
/** The conversation's sandbox must be recovered before another answer. */
|
|
155
160
|
| { readonly code: "sandbox" }
|
|
161
|
+
/** It's to run on this computer, and what runs it there can't start. */
|
|
162
|
+
| { readonly code: "computer" }
|
|
156
163
|
| { readonly code: "send" | "retry" | "stop" | "approvalMode" }
|
|
157
164
|
|
|
158
165
|
/** The conversation's messages could not be read. */
|
|
@@ -172,6 +179,15 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
172
179
|
const agentMessages = useAgentMessages()
|
|
173
180
|
const labels = agentMessages.chat
|
|
174
181
|
const queryClient = useQueryClient()
|
|
182
|
+
const {
|
|
183
|
+
place: newThreadPlace,
|
|
184
|
+
waiting: newThreadPlaceWaiting,
|
|
185
|
+
computerId: desktopComputerId,
|
|
186
|
+
resolveBody: resolvePlaceBody,
|
|
187
|
+
} = useNewThreadPlace()
|
|
188
|
+
const desktopComputer = useDesktop()?.computer
|
|
189
|
+
// Asking for a folder can take as long as the person does: the composer holds meanwhile.
|
|
190
|
+
const [resolvingPlace, setResolvingPlace] = useState(false)
|
|
175
191
|
const user = useCurrentUser()
|
|
176
192
|
const agentQuery = useQuery(getAgentOptions())
|
|
177
193
|
const modelsQuery = useQuery(listModelsOptions())
|
|
@@ -198,12 +214,12 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
198
214
|
// A held call changed: its card, and the thread list's count of what waits for the reader. Its
|
|
199
215
|
// turn's runs follow from their own events.
|
|
200
216
|
onApprovalActivity: (event) => void refreshApprovals(event.threadId),
|
|
201
|
-
// Its owner's sixb opened or closed where the open conversation runs: its badge follows.
|
|
217
|
+
// Its owner's sixb opened or closed where the open conversation runs: its badge follows. So do
|
|
218
|
+
// its background commands, which may run where it ran before it moved.
|
|
202
219
|
onComputerActivity: (event) => {
|
|
203
220
|
const place = thread?.computer
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
221
|
+
const here = place?.id === event.computerId && place.folder === event.folder
|
|
222
|
+
if (threadId && (here || thread?.backgroundCommands)) void refreshThread(threadId)
|
|
207
223
|
},
|
|
208
224
|
// It moved from another tab or from sixb: the badge and notice follow.
|
|
209
225
|
onThreadMoved: (event) => {
|
|
@@ -427,6 +443,7 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
427
443
|
const retryRun = useMutation(retryAgentRunMutation())
|
|
428
444
|
const recreateSandbox = useMutation(recreateAgentThreadSandboxMutation())
|
|
429
445
|
const moveToCloud = useMutation(moveAgentThreadToCloudMutation())
|
|
446
|
+
const stopBackgroundCommand = useMutation(stopAgentBackgroundCommandMutation())
|
|
430
447
|
const decideApproval = useMutation(decideAgentApprovalMutation())
|
|
431
448
|
// Each runs after the one before, so the last choice is the one the server keeps.
|
|
432
449
|
const saveThreadApprovalMode = useMutation({
|
|
@@ -528,9 +545,16 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
528
545
|
}
|
|
529
546
|
|
|
530
547
|
if (!currentAgent) return
|
|
548
|
+
setResolvingPlace(true)
|
|
549
|
+
const place = await resolvePlaceBody().finally(() => setResolvingPlace(false))
|
|
550
|
+
if (!place) {
|
|
551
|
+
// They cancelled choosing a folder: nothing was sent, and their message goes back.
|
|
552
|
+
setDraftReseed((current) => ({ text, attachments, context, nonce: current.nonce + 1 }))
|
|
553
|
+
return
|
|
554
|
+
}
|
|
531
555
|
const title = deriveTitle(text, attachments)
|
|
532
556
|
const created = await createThread.mutateAsync({
|
|
533
|
-
body: title ? { title } : {},
|
|
557
|
+
body: { ...(title ? { title } : {}), ...place },
|
|
534
558
|
})
|
|
535
559
|
createdThreadId = created.thread.id
|
|
536
560
|
setPendingUser({
|
|
@@ -859,7 +883,7 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
859
883
|
const anchorCurrentTurn = Boolean(
|
|
860
884
|
(pendingUser && pendingUser.threadId === threadId) || (pendingRun && pendingSend?.anchor)
|
|
861
885
|
)
|
|
862
|
-
const composerPending = postMessage.isPending || createThread.isPending
|
|
886
|
+
const composerPending = postMessage.isPending || createThread.isPending || resolvingPlace
|
|
863
887
|
const currentSendError: AgentConversationSendError | null =
|
|
864
888
|
sendError && sendError.threadId === threadId
|
|
865
889
|
? sendError.failure === "busy"
|
|
@@ -1018,6 +1042,31 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
1018
1042
|
}
|
|
1019
1043
|
: null
|
|
1020
1044
|
|
|
1045
|
+
// Its background commands: what its owner's sixb reports of them, and their Stop, to its owner
|
|
1046
|
+
// alone, as the computer is theirs. A command started in a folder runs on there once the thread
|
|
1047
|
+
// moved to another, or to the cloud.
|
|
1048
|
+
const computer = thread?.computer
|
|
1049
|
+
const backgroundCommands = thread?.backgroundCommands
|
|
1050
|
+
const runsOnComputer = thread?.runsOn === "computer"
|
|
1051
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: the mutation and the refresh are the conversation's
|
|
1052
|
+
const transcriptBackground = useMemo((): TranscriptBackground => {
|
|
1053
|
+
const live = backgroundCommands ?? (computer ? [] : null)
|
|
1054
|
+
return {
|
|
1055
|
+
source: { onComputer: runsOnComputer, live, online: computer?.online ?? false },
|
|
1056
|
+
...(live !== null && threadId !== null
|
|
1057
|
+
? {
|
|
1058
|
+
stop: async (command) => {
|
|
1059
|
+
await stopBackgroundCommand.mutateAsync({
|
|
1060
|
+
path: { threadId, commandId: command.id },
|
|
1061
|
+
body: { startedAt: command.startedAt },
|
|
1062
|
+
})
|
|
1063
|
+
await refreshThread(threadId)
|
|
1064
|
+
},
|
|
1065
|
+
}
|
|
1066
|
+
: {}),
|
|
1067
|
+
}
|
|
1068
|
+
}, [computer, backgroundCommands, runsOnComputer, threadId])
|
|
1069
|
+
|
|
1021
1070
|
const transcriptProps: TranscriptProps = {
|
|
1022
1071
|
threadId,
|
|
1023
1072
|
messages,
|
|
@@ -1029,6 +1078,7 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
1029
1078
|
approvals: transcriptApprovals,
|
|
1030
1079
|
approvalOutcomes,
|
|
1031
1080
|
delegation: transcriptDelegation,
|
|
1081
|
+
background: transcriptBackground,
|
|
1032
1082
|
}
|
|
1033
1083
|
|
|
1034
1084
|
const modelControlsProps = {
|
|
@@ -1047,6 +1097,9 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
1047
1097
|
|
|
1048
1098
|
const composerProps: ConversationComposerProps = {
|
|
1049
1099
|
onSend: send,
|
|
1100
|
+
...(threadId === null && (newThreadPlace || newThreadPlaceWaiting)
|
|
1101
|
+
? { newThreadPlace: newThreadPlace ?? "waiting" }
|
|
1102
|
+
: {}),
|
|
1050
1103
|
error: currentSendError
|
|
1051
1104
|
? failureMessage(currentSendError, labels, agentMessages.approvalModes.saveFailed)
|
|
1052
1105
|
: undefined,
|
|
@@ -1090,6 +1143,12 @@ export function useAgentConversation({ threadId, onThreadCreated }: UseAgentConv
|
|
|
1090
1143
|
? "busy"
|
|
1091
1144
|
: "failed",
|
|
1092
1145
|
onContinueInCloud: handleContinueInCloud,
|
|
1146
|
+
...(desktopComputer && thread?.computer && thread.computer.id === desktopComputerId
|
|
1147
|
+
? {
|
|
1148
|
+
onRunHere: () =>
|
|
1149
|
+
void desktopComputer.allowFolder(thread.computer?.folder ?? "").catch(() => {}),
|
|
1150
|
+
}
|
|
1151
|
+
: {}),
|
|
1093
1152
|
}
|
|
1094
1153
|
: null
|
|
1095
1154
|
|
|
@@ -1204,6 +1263,7 @@ function decisionFailure(error: unknown): AgentApprovalDecisionFailure {
|
|
|
1204
1263
|
|
|
1205
1264
|
/** A message that did not go out: another answer holds the thread, the sandbox is away, or else. */
|
|
1206
1265
|
function sendFailure(error: unknown): TurnFailure {
|
|
1266
|
+
if (error instanceof ComputerUnavailableError) return "computer"
|
|
1207
1267
|
if (!isSixbApiError(error) || error.status !== 409) return "send"
|
|
1208
1268
|
if (error.code === "active_run_exists") return "busy"
|
|
1209
1269
|
if (error.code === "sandbox_execution_unavailable") return "sandbox"
|
|
@@ -1225,6 +1285,8 @@ function failureMessage(
|
|
|
1225
1285
|
return failure.someoneElse ? labels.busyOther : labels.busy
|
|
1226
1286
|
case "sandbox":
|
|
1227
1287
|
return labels.sandboxUnavailable
|
|
1288
|
+
case "computer":
|
|
1289
|
+
return labels.computerUnavailable
|
|
1228
1290
|
case "retry":
|
|
1229
1291
|
return labels.retryFailed
|
|
1230
1292
|
case "stop":
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { type DesktopComputer, type DesktopComputerAccess, useDesktop } from "@sixb/client/hooks"
|
|
2
|
+
import { useCallback, useEffect, useState } from "react"
|
|
3
|
+
|
|
4
|
+
const STORAGE_KEY = "sixb.agent.new-thread-place"
|
|
5
|
+
|
|
6
|
+
/** The last choice, on this computer: where a new conversation starts. */
|
|
7
|
+
interface StoredPlace {
|
|
8
|
+
readonly cloud: boolean
|
|
9
|
+
readonly folder: string | null
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function readStored(): StoredPlace {
|
|
13
|
+
try {
|
|
14
|
+
const stored = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "null") as Partial<StoredPlace>
|
|
15
|
+
return { cloud: stored?.cloud === true, folder: stored?.folder ?? null }
|
|
16
|
+
} catch {
|
|
17
|
+
return { cloud: false, folder: null }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A message that's to run on this computer, and what runs it there can't start. */
|
|
22
|
+
export class ComputerUnavailableError extends Error {
|
|
23
|
+
constructor(cause: unknown) {
|
|
24
|
+
super("[SixbApp] What runs the agent on this computer couldn't start.", { cause })
|
|
25
|
+
this.name = "ComputerUnavailableError"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** What a new conversation is created with to run on this computer: nothing, for the cloud. */
|
|
30
|
+
export type NewThreadPlaceBody =
|
|
31
|
+
| { readonly runsOn?: undefined }
|
|
32
|
+
| {
|
|
33
|
+
readonly runsOn: "computer"
|
|
34
|
+
readonly computer: DesktopComputer & { readonly folder: string }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The composer's choice of where a new conversation runs. */
|
|
38
|
+
export interface NewThreadPlace {
|
|
39
|
+
/** Null while what runs the agent here can't start: the cloud is still a choice. */
|
|
40
|
+
readonly computerName: string | null
|
|
41
|
+
readonly cloud: boolean
|
|
42
|
+
/** Null before the person has chosen one: the first message asks. */
|
|
43
|
+
readonly folder: string | null
|
|
44
|
+
/** Folders chosen before, to choose from again. */
|
|
45
|
+
readonly folders: readonly string[]
|
|
46
|
+
readonly chooseCloud: () => void
|
|
47
|
+
readonly chooseFolder: (folder: string) => void
|
|
48
|
+
/** Ask the person for a folder, and use it. */
|
|
49
|
+
readonly pickFolder: () => Promise<void>
|
|
50
|
+
readonly forgetFolder: (folder: string) => void
|
|
51
|
+
readonly refreshFolders: () => void
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Where a new conversation runs, in a desktop app that can run the agent here: this computer unless
|
|
56
|
+
* the person chooses the cloud. In a browser there's nothing to choose, and this says so.
|
|
57
|
+
*/
|
|
58
|
+
export function useNewThreadPlace(): {
|
|
59
|
+
/** Null where the only place is the cloud, or until it's known that there's another. */
|
|
60
|
+
readonly place: NewThreadPlace | null
|
|
61
|
+
/** A desktop app that hasn't said yet whether it can run the agent here. */
|
|
62
|
+
readonly waiting: boolean
|
|
63
|
+
/** This computer, once the desktop app has said: what tells a conversation that runs on it. */
|
|
64
|
+
readonly computerId: string | null
|
|
65
|
+
/**
|
|
66
|
+
* What to create the next conversation with, asking for a folder if none is chosen. Null when the
|
|
67
|
+
* person cancels, so that their message stays in the composer.
|
|
68
|
+
*/
|
|
69
|
+
readonly resolveBody: () => Promise<NewThreadPlaceBody | null>
|
|
70
|
+
} {
|
|
71
|
+
const access: DesktopComputerAccess | null = useDesktop()?.computer ?? null
|
|
72
|
+
// Undefined until the desktop app answers; null where it can't run the agent.
|
|
73
|
+
const [computer, setComputer] = useState<DesktopComputer | null | undefined>(undefined)
|
|
74
|
+
const [cannotStart, setCannotStart] = useState(false)
|
|
75
|
+
// Null until the runner has said: a folder chosen before isn't taken as gone meanwhile.
|
|
76
|
+
const [folders, setFolders] = useState<readonly string[] | null>(null)
|
|
77
|
+
const [stored, setStored] = useState(readStored)
|
|
78
|
+
|
|
79
|
+
const remember = useCallback((next: StoredPlace) => {
|
|
80
|
+
setStored(next)
|
|
81
|
+
try {
|
|
82
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(next))
|
|
83
|
+
} catch {
|
|
84
|
+
// Private storage: the choice lasts as long as the page.
|
|
85
|
+
}
|
|
86
|
+
}, [])
|
|
87
|
+
|
|
88
|
+
const refreshFolders = useCallback(() => {
|
|
89
|
+
void access?.folders().then(setFolders, () => {})
|
|
90
|
+
}, [access])
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!access) return
|
|
94
|
+
let current = true
|
|
95
|
+
const refresh = () => {
|
|
96
|
+
void access.about().then(
|
|
97
|
+
(found) => {
|
|
98
|
+
if (!current) return
|
|
99
|
+
setComputer(found)
|
|
100
|
+
setCannotStart(false)
|
|
101
|
+
},
|
|
102
|
+
() => {
|
|
103
|
+
if (current) setCannotStart(true)
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
refreshFolders()
|
|
107
|
+
}
|
|
108
|
+
refresh()
|
|
109
|
+
// A runner that couldn't start when this first asked may have since.
|
|
110
|
+
window.addEventListener("focus", refresh)
|
|
111
|
+
return () => {
|
|
112
|
+
current = false
|
|
113
|
+
window.removeEventListener("focus", refresh)
|
|
114
|
+
}
|
|
115
|
+
}, [access, refreshFolders])
|
|
116
|
+
|
|
117
|
+
if (!access) {
|
|
118
|
+
return { place: null, waiting: false, computerId: null, resolveBody: async () => ({}) }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const pick = async (): Promise<string | null> => {
|
|
122
|
+
const folder = await access.pickFolder()
|
|
123
|
+
if (folder) {
|
|
124
|
+
remember({ cloud: false, folder })
|
|
125
|
+
refreshFolders()
|
|
126
|
+
}
|
|
127
|
+
return folder
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Asks the runner rather than reading what's shown: a message sent before it has answered goes
|
|
131
|
+
// where the person last chose, not to the cloud by default. One it can't start for says so.
|
|
132
|
+
const resolveBody = async (): Promise<NewThreadPlaceBody | null> => {
|
|
133
|
+
if (stored.cloud) return {}
|
|
134
|
+
const found = await access.about().catch((cause: unknown) => {
|
|
135
|
+
throw new ComputerUnavailableError(cause)
|
|
136
|
+
})
|
|
137
|
+
if (!found) return {}
|
|
138
|
+
// A folder that's no longer allowed here, or no longer there, or a sign-in that ended: asking
|
|
139
|
+
// again allows it, and signs in. Anything else would leave the message waiting on nothing.
|
|
140
|
+
const allowed = await access.folders()
|
|
141
|
+
const folder = stored.folder && allowed.includes(stored.folder) ? stored.folder : await pick()
|
|
142
|
+
return folder ? { runsOn: "computer", computer: { ...found, folder } } : null
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (computer === null || (computer === undefined && !cannotStart)) {
|
|
146
|
+
return { place: null, waiting: computer === undefined, computerId: null, resolveBody }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
waiting: false,
|
|
151
|
+
computerId: computer?.id ?? null,
|
|
152
|
+
place: {
|
|
153
|
+
computerName: computer?.name ?? null,
|
|
154
|
+
cloud: stored.cloud,
|
|
155
|
+
folder: stored.folder && (!folders || folders.includes(stored.folder)) ? stored.folder : null,
|
|
156
|
+
folders: folders ?? [],
|
|
157
|
+
chooseCloud: () => remember({ ...stored, cloud: true }),
|
|
158
|
+
chooseFolder: (folder) => remember({ cloud: false, folder }),
|
|
159
|
+
pickFolder: async () => {
|
|
160
|
+
await pick()
|
|
161
|
+
},
|
|
162
|
+
forgetFolder: (folder) => {
|
|
163
|
+
void access.forgetFolder(folder).then(refreshFolders, () => {})
|
|
164
|
+
if (stored.folder === folder) remember({ ...stored, folder: null })
|
|
165
|
+
},
|
|
166
|
+
refreshFolders,
|
|
167
|
+
},
|
|
168
|
+
resolveBody,
|
|
169
|
+
}
|
|
170
|
+
}
|