@sixb/app 0.2.4 → 0.2.6
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/ctm.png +0 -0
- package/dist/agent/activity-label.d.ts.map +1 -1
- package/dist/agent/agent-chat.d.ts +3 -1
- package/dist/agent/agent-chat.d.ts.map +1 -1
- package/dist/agent/agent-panel.d.ts.map +1 -1
- package/dist/agent/artifact-panel.d.ts +3 -1
- package/dist/agent/artifact-panel.d.ts.map +1 -1
- package/dist/agent/components/agent-threads.d.ts.map +1 -1
- package/dist/agent/components/composer-place.d.ts.map +1 -1
- package/dist/agent/components/composer-settings.d.ts +1 -1
- package/dist/agent/components/composer-settings.d.ts.map +1 -1
- package/dist/agent/components/composer.d.ts +22 -5
- package/dist/agent/components/composer.d.ts.map +1 -1
- package/dist/agent/components/computer-place.d.ts +24 -6
- package/dist/agent/components/computer-place.d.ts.map +1 -1
- package/dist/agent/components/context-meter.d.ts +1 -1
- package/dist/agent/components/context-meter.d.ts.map +1 -1
- package/dist/agent/components/conversation-panel.d.ts +5 -2
- package/dist/agent/components/conversation-panel.d.ts.map +1 -1
- package/dist/agent/components/message-parts.d.ts +2 -1
- package/dist/agent/components/message-parts.d.ts.map +1 -1
- package/dist/agent/components/message-view.d.ts +13 -3
- package/dist/agent/components/message-view.d.ts.map +1 -1
- package/dist/agent/components/pending-messages.d.ts +20 -0
- package/dist/agent/components/pending-messages.d.ts.map +1 -0
- package/dist/agent/components/sandbox-recovery.d.ts +11 -2
- package/dist/agent/components/sandbox-recovery.d.ts.map +1 -1
- package/dist/agent/components/threads-button.d.ts +1 -1
- package/dist/agent/components/threads-button.d.ts.map +1 -1
- package/dist/agent/components/transcript.d.ts +13 -0
- package/dist/agent/components/transcript.d.ts.map +1 -1
- package/dist/agent/conversation.d.ts +7 -6
- package/dist/agent/conversation.d.ts.map +1 -1
- package/dist/agent/delegation/interpret.d.ts +5 -0
- package/dist/agent/delegation/interpret.d.ts.map +1 -1
- package/dist/agent/delegation/use-children.d.ts.map +1 -1
- package/dist/agent/format.d.ts +7 -0
- package/dist/agent/format.d.ts.map +1 -1
- package/dist/agent/hooks/thread-queries.d.ts +1548 -0
- package/dist/agent/hooks/thread-queries.d.ts.map +1 -0
- package/dist/agent/hooks/use-agent-conversation.d.ts +51 -6
- package/dist/agent/hooks/use-agent-conversation.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-lists.d.ts +80 -3
- package/dist/agent/hooks/use-thread-lists.d.ts.map +1 -1
- package/dist/agent/hooks/use-thread-place.d.ts +49 -0
- package/dist/agent/hooks/use-thread-place.d.ts.map +1 -0
- package/dist/agent/hooks/use-thread-stream.d.ts.map +1 -1
- package/dist/agent/i18n/en.d.ts +107 -6
- 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 +180 -12
- package/dist/agent/i18n/index.d.ts.map +1 -1
- package/dist/agent/inbox-handoff.d.ts +10 -0
- package/dist/agent/inbox-handoff.d.ts.map +1 -0
- package/dist/agent/live-run.d.ts +8 -1
- package/dist/agent/live-run.d.ts.map +1 -1
- package/dist/agent/model-selection.d.ts +3 -2
- package/dist/agent/model-selection.d.ts.map +1 -1
- package/dist/agent/moves.d.ts +40 -0
- package/dist/agent/moves.d.ts.map +1 -0
- package/dist/agent/search/interpret.d.ts +101 -0
- package/dist/agent/search/interpret.d.ts.map +1 -0
- package/dist/agent/search/search-tool-view.d.ts +10 -0
- package/dist/agent/search/search-tool-view.d.ts.map +1 -0
- package/dist/agent/thread-reader-state.d.ts +30 -0
- package/dist/agent/thread-reader-state.d.ts.map +1 -0
- package/dist/agent/thread-state.d.ts +26 -0
- package/dist/agent/thread-state.d.ts.map +1 -0
- package/dist/agent/tool-views/built-in.d.ts.map +1 -1
- package/dist/agent/tool-views/registry.d.ts +5 -6
- package/dist/agent/tool-views/registry.d.ts.map +1 -1
- package/dist/agent/types.d.ts +9 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts +2 -1
- package/dist/agent/view-file/view-file-tool-view.d.ts.map +1 -1
- package/dist/artifacts/card-preview.d.ts.map +1 -1
- package/dist/artifacts/editor/block-handle.d.ts +20 -0
- package/dist/artifacts/editor/block-handle.d.ts.map +1 -0
- package/dist/artifacts/editor/blocks.d.ts +34 -0
- package/dist/artifacts/editor/blocks.d.ts.map +1 -0
- package/dist/artifacts/editor/callout-view.d.ts +7 -0
- package/dist/artifacts/editor/callout-view.d.ts.map +1 -0
- package/dist/artifacts/editor/document-editor.d.ts +30 -0
- package/dist/artifacts/editor/document-editor.d.ts.map +1 -0
- package/dist/artifacts/editor/figure-view.d.ts +12 -0
- package/dist/artifacts/editor/figure-view.d.ts.map +1 -0
- package/dist/artifacts/editor/find-blocks.d.ts +6 -0
- package/dist/artifacts/editor/find-blocks.d.ts.map +1 -0
- package/dist/artifacts/editor/markdown-document.d.ts +12 -0
- package/dist/artifacts/editor/markdown-document.d.ts.map +1 -0
- package/dist/artifacts/editor/messages.d.ts +4 -0
- package/dist/artifacts/editor/messages.d.ts.map +1 -0
- package/dist/artifacts/editor/schema.d.ts +21 -0
- package/dist/artifacts/editor/schema.d.ts.map +1 -0
- package/dist/artifacts/editor/selection-toolbar.d.ts +35 -0
- package/dist/artifacts/editor/selection-toolbar.d.ts.map +1 -0
- package/dist/artifacts/editor/slash-menu.d.ts +43 -0
- package/dist/artifacts/editor/slash-menu.d.ts.map +1 -0
- package/dist/artifacts/editor/upload.d.ts +12 -0
- package/dist/artifacts/editor/upload.d.ts.map +1 -0
- package/dist/artifacts/file-source.d.ts +5 -0
- package/dist/artifacts/file-source.d.ts.map +1 -1
- package/dist/artifacts/frame-editor/bundle.d.ts +7 -0
- package/dist/artifacts/frame-editor/bundle.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/commands.d.ts +93 -0
- package/dist/artifacts/frame-editor/commands.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/entry.d.ts +2 -0
- package/dist/artifacts/frame-editor/entry.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/frame.d.ts +5 -0
- package/dist/artifacts/frame-editor/frame.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/keys.d.ts +8 -0
- package/dist/artifacts/frame-editor/keys.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/protocol.d.ts +186 -0
- package/dist/artifacts/frame-editor/protocol.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/schema.d.ts +34 -0
- package/dist/artifacts/frame-editor/schema.d.ts.map +1 -0
- package/dist/artifacts/frame-editor/style.d.ts +2 -0
- package/dist/artifacts/frame-editor/style.d.ts.map +1 -0
- package/dist/artifacts/frame.d.ts +2 -2
- package/dist/artifacts/frame.d.ts.map +1 -1
- package/dist/artifacts/live/boards.d.ts +2 -0
- package/dist/artifacts/live/boards.d.ts.map +1 -1
- package/dist/artifacts/live/document.d.ts +32 -0
- package/dist/artifacts/live/document.d.ts.map +1 -0
- package/dist/artifacts/live/header.d.ts +4 -4
- package/dist/artifacts/live/header.d.ts.map +1 -1
- package/dist/artifacts/live/presence.d.ts.map +1 -1
- package/dist/artifacts/live/session.d.ts +2 -0
- package/dist/artifacts/live/session.d.ts.map +1 -1
- package/dist/artifacts/live/view.d.ts +4 -3
- package/dist/artifacts/live/view.d.ts.map +1 -1
- package/dist/artifacts/messages.d.ts +226 -2
- package/dist/artifacts/messages.d.ts.map +1 -1
- package/dist/artifacts/pdf.d.ts +8 -0
- package/dist/artifacts/pdf.d.ts.map +1 -0
- package/dist/artifacts/queries.d.ts +80 -0
- package/dist/artifacts/queries.d.ts.map +1 -1
- package/dist/artifacts/references/references.d.ts +3 -3
- package/dist/artifacts/references/references.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/board-editor.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comment-pins.d.ts +4 -2
- package/dist/artifacts/renderers/canvas/comment-pins.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comments-panel.d.ts.map +1 -1
- package/dist/artifacts/renderers/canvas/comments.d.ts +2 -1
- package/dist/artifacts/renderers/canvas/comments.d.ts.map +1 -1
- package/dist/artifacts/renderers/designed-document.d.ts +28 -0
- package/dist/artifacts/renderers/designed-document.d.ts.map +1 -0
- package/dist/artifacts/renderers/document-tree.d.ts +2 -0
- package/dist/artifacts/renderers/document-tree.d.ts.map +1 -1
- package/dist/artifacts/renderers/document.d.ts +9 -1
- package/dist/artifacts/renderers/document.d.ts.map +1 -1
- package/dist/artifacts/renderers/live-frame.d.ts +145 -0
- package/dist/artifacts/renderers/live-frame.d.ts.map +1 -0
- package/dist/artifacts/renderers/page-editor.d.ts +16 -0
- package/dist/artifacts/renderers/page-editor.d.ts.map +1 -0
- package/dist/artifacts/renderers/page.d.ts +10 -1
- package/dist/artifacts/renderers/page.d.ts.map +1 -1
- package/dist/artifacts/viewer.d.ts.map +1 -1
- package/dist/{chunk-pxd07kvx.js → chunk-096d52h2.js} +1 -1
- package/dist/{chunk-yrcm1pbg.js → chunk-94d7enwc.js} +491 -2128
- package/dist/chunk-94d7enwc.js.map +27 -0
- package/dist/{chunk-970s5nkn.js → chunk-ezntd3yy.js} +1 -1
- package/dist/{chunk-kymx9y5e.js → chunk-qjw5r2vk.js} +12729 -5044
- package/dist/chunk-qjw5r2vk.js.map +242 -0
- package/dist/chunk-y51c4tsz.js +11 -0
- package/dist/chunk-y51c4tsz.js.map +10 -0
- package/dist/createCustomApp.d.ts +8 -1
- package/dist/createCustomApp.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +5 -5
- package/dist/pages/console/data/accounts.d.ts +94 -0
- package/dist/pages/console/data/accounts.d.ts.map +1 -0
- package/dist/pages/console/data/connectors.d.ts.map +1 -1
- package/dist/pages/console/data/live-updates.d.ts.map +1 -1
- package/dist/pages/console/data/messages.d.ts +52 -0
- package/dist/pages/console/data/messages.d.ts.map +1 -1
- package/dist/pages/console/data/shared.d.ts.map +1 -1
- package/dist/pages/console/data/sync-button.d.ts.map +1 -1
- package/dist/pages/console/data/syncs.d.ts.map +1 -1
- package/dist/pages/settings/usage/breakdown.d.ts.map +1 -1
- package/dist/pages/settings/usage/page.d.ts +4 -1
- package/dist/pages/settings/usage/page.d.ts.map +1 -1
- package/dist/pages/settings/usage/spend-model.d.ts +43 -19
- package/dist/pages/settings/usage/spend-model.d.ts.map +1 -1
- package/dist/pages.js +23044 -22570
- package/dist/pages.js.map +17 -16
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +40 -3
- package/dist/server.js.map +3 -3
- package/dist/shell/search-command.d.ts.map +1 -1
- package/package.json +22 -5
- package/src/agent/activity-label.ts +3 -0
- package/src/agent/agent-chat.tsx +58 -39
- package/src/agent/agent-execution-trace.tsx +2 -2
- package/src/agent/agent-panel.tsx +6 -4
- package/src/agent/agent.css +254 -0
- package/src/agent/artifact-panel.tsx +77 -22
- package/src/agent/components/agent-threads.tsx +42 -2
- package/src/agent/components/composer-place.tsx +2 -7
- package/src/agent/components/composer-settings.tsx +20 -10
- package/src/agent/components/composer.tsx +342 -104
- package/src/agent/components/computer-place.tsx +415 -70
- package/src/agent/components/context-meter.tsx +7 -3
- package/src/agent/components/conversation-panel.tsx +99 -54
- package/src/agent/components/message-parts.tsx +367 -59
- package/src/agent/components/message-view.tsx +428 -9
- package/src/agent/components/pending-messages.tsx +342 -0
- package/src/agent/components/sandbox-recovery.tsx +36 -17
- package/src/agent/components/threads-button.tsx +3 -2
- package/src/agent/components/transcript.tsx +198 -38
- package/src/agent/conversation.ts +219 -55
- package/src/agent/delegation/interpret.ts +31 -7
- package/src/agent/format.ts +52 -0
- package/src/agent/hooks/thread-queries.ts +75 -0
- package/src/agent/hooks/use-agent-conversation.ts +801 -211
- package/src/agent/hooks/use-thread-lists.ts +72 -7
- package/src/agent/hooks/use-thread-place.ts +239 -0
- package/src/agent/hooks/use-thread-stream.ts +10 -0
- package/src/agent/i18n/en.ts +150 -27
- package/src/agent/i18n/fr.ts +148 -31
- package/src/agent/inbox-handoff.ts +47 -0
- package/src/agent/live-run.ts +61 -2
- package/src/agent/model-selection.ts +3 -2
- package/src/agent/moves.ts +174 -0
- package/src/agent/react-router.tsx +2 -2
- package/src/agent/search/interpret.ts +367 -0
- package/src/agent/search/search-tool-view.tsx +235 -0
- package/src/agent/thread-reader-state.ts +75 -0
- package/src/agent/thread-state.ts +114 -0
- package/src/agent/tool-views/built-in.tsx +16 -0
- package/src/agent/tool-views/registry.tsx +28 -2
- package/src/agent/types.ts +13 -0
- package/src/agent/view-file/view-file-tool-view.tsx +33 -19
- package/src/artifacts/artifacts.css +398 -0
- package/src/artifacts/card-preview.tsx +6 -1
- package/src/artifacts/editor/block-handle.tsx +278 -0
- package/src/artifacts/editor/blocks.ts +216 -0
- package/src/artifacts/editor/callout-view.tsx +31 -0
- package/src/artifacts/editor/document-editor.tsx +484 -0
- package/src/artifacts/editor/figure-view.tsx +66 -0
- package/src/artifacts/editor/find-blocks.ts +19 -0
- package/src/artifacts/editor/markdown-document.tsx +72 -0
- package/src/artifacts/editor/messages.ts +4 -0
- package/src/artifacts/editor/schema.ts +159 -0
- package/src/artifacts/editor/selection-toolbar.tsx +364 -0
- package/src/artifacts/editor/slash-menu.tsx +251 -0
- package/src/artifacts/editor/upload.ts +40 -0
- package/src/artifacts/file-source.ts +11 -0
- package/src/artifacts/frame-editor/bundle.ts +8 -0
- package/src/artifacts/frame-editor/commands.ts +565 -0
- package/src/artifacts/frame-editor/entry.ts +6 -0
- package/src/artifacts/frame-editor/frame.ts +847 -0
- package/src/artifacts/frame-editor/generated/editor.txt +149 -0
- package/src/artifacts/frame-editor/generated.d.ts +5 -0
- package/src/artifacts/frame-editor/keys.ts +323 -0
- package/src/artifacts/frame-editor/protocol.ts +151 -0
- package/src/artifacts/frame-editor/schema.ts +293 -0
- package/src/artifacts/frame-editor/style.ts +58 -0
- package/src/artifacts/frame.tsx +11 -3
- package/src/artifacts/live/boards.ts +46 -3
- package/src/artifacts/live/document.ts +89 -0
- package/src/artifacts/live/header.tsx +9 -14
- package/src/artifacts/live/presence.ts +5 -1
- package/src/artifacts/live/session.ts +9 -2
- package/src/artifacts/live/view.ts +14 -8
- package/src/artifacts/messages.ts +138 -2
- package/src/artifacts/pdf.ts +50 -0
- package/src/artifacts/references/references.tsx +46 -11
- package/src/artifacts/renderers/canvas/board-editor.tsx +11 -144
- package/src/artifacts/renderers/canvas/comment-pins.tsx +5 -0
- package/src/artifacts/renderers/canvas/comments-panel.tsx +58 -1
- package/src/artifacts/renderers/canvas/comments.ts +8 -4
- package/src/artifacts/renderers/designed-document.tsx +277 -0
- package/src/artifacts/renderers/document-tree.ts +9 -0
- package/src/artifacts/renderers/document.tsx +13 -102
- package/src/artifacts/renderers/live-frame.ts +163 -0
- package/src/artifacts/renderers/page-editor.tsx +613 -0
- package/src/artifacts/renderers/page.tsx +21 -4
- package/src/artifacts/viewer.tsx +87 -41
- package/src/createCustomApp.ts +57 -3
- package/src/index.ts +10 -0
- package/src/pages/console/data/accounts.tsx +509 -0
- package/src/pages/console/data/connectors.tsx +7 -15
- package/src/pages/console/data/live-updates.ts +2 -0
- package/src/pages/console/data/messages.ts +79 -0
- package/src/pages/console/data/projections.tsx +4 -0
- package/src/pages/console/data/shared.tsx +1 -0
- package/src/pages/console/data/sync-button.tsx +56 -16
- package/src/pages/console/data/syncs.tsx +66 -41
- package/src/pages/console/ontology/lineage/trail.tsx +3 -0
- package/src/pages/section-ui.tsx +1 -1
- package/src/pages/settings/usage/breakdown.tsx +5 -2
- package/src/pages/settings/usage/filter-menu.tsx +1 -1
- package/src/pages/settings/usage/page.tsx +32 -13
- package/src/pages/settings/usage/spend-chart.tsx +2 -2
- package/src/pages/settings/usage/spend-model.ts +118 -50
- package/src/server.ts +1 -0
- package/src/shell/search-command.tsx +2 -0
- package/dist/chunk-kymx9y5e.js.map +0 -211
- package/dist/chunk-yrcm1pbg.js.map +0 -34
- /package/dist/{chunk-pxd07kvx.js.map → chunk-096d52h2.js.map} +0 -0
- /package/dist/{chunk-970s5nkn.js.map → chunk-ezntd3yy.js.map} +0 -0
|
@@ -3,36 +3,38 @@ import {
|
|
|
3
3
|
cancelAgentRunMutation,
|
|
4
4
|
createAgentThreadMutation,
|
|
5
5
|
decideAgentApprovalMutation,
|
|
6
|
+
editAgentThreadMessageMutation,
|
|
6
7
|
getAgentOptions,
|
|
7
8
|
getAgentPreferencesOptions,
|
|
8
9
|
getAgentPreferencesQueryKey,
|
|
9
10
|
getAgentThreadContextOptions,
|
|
10
11
|
getAgentThreadContextQueryKey,
|
|
11
|
-
getAgentThreadOptions,
|
|
12
12
|
getAgentThreadQueryKey,
|
|
13
13
|
listAgentApprovalsQueryKey,
|
|
14
|
+
listAgentComputersOptions,
|
|
14
15
|
listAgentComputersQueryKey,
|
|
15
16
|
listAgentThreadApprovalsOptions,
|
|
16
17
|
listAgentThreadApprovalsQueryKey,
|
|
17
|
-
|
|
18
|
+
listAgentThreadInboxOptions,
|
|
19
|
+
listAgentThreadInboxQueryKey,
|
|
18
20
|
listAgentThreadMessagesQueryKey,
|
|
19
|
-
listAgentThreadRunsOptions,
|
|
20
21
|
listAgentThreadRunsQueryKey,
|
|
21
22
|
listAgentThreadsQueryKey,
|
|
22
23
|
listModelsOptions,
|
|
23
|
-
moveAgentThreadToCloudMutation,
|
|
24
24
|
postAgentThreadMessageMutation,
|
|
25
25
|
recreateAgentThreadSandboxMutation,
|
|
26
|
+
restoreAgentThreadSandboxMutation,
|
|
26
27
|
retryAgentRunMutation,
|
|
27
28
|
setAgentThreadApprovalModeMutation,
|
|
28
29
|
stopAgentBackgroundCommandMutation,
|
|
29
30
|
updateAgentPreferencesMutation,
|
|
30
31
|
useAgentActivityStream,
|
|
31
32
|
useDesktop,
|
|
33
|
+
withdrawAgentThreadInboxItemMutation,
|
|
32
34
|
} from "@sixb/client/hooks"
|
|
33
35
|
import { MODEL_REASONING_LEVELS, type ModelReasoningLevel } from "@sixb/core/models"
|
|
34
36
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
|
|
35
|
-
import { useEffect, useMemo, useRef, useState } from "react"
|
|
37
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
|
36
38
|
import { useCurrentUser } from "../../session"
|
|
37
39
|
import {
|
|
38
40
|
type AgentApproval,
|
|
@@ -47,10 +49,16 @@ import {
|
|
|
47
49
|
} from "../approvals"
|
|
48
50
|
import type { TranscriptBackground } from "../background/context"
|
|
49
51
|
import type { ComposerProps } from "../components/composer"
|
|
50
|
-
import { type ComputerOfflineNoticeProps,
|
|
52
|
+
import { type ComputerOfflineNoticeProps, folderName } from "../components/computer-place"
|
|
53
|
+
import type { PendingMessagesProps } from "../components/pending-messages"
|
|
51
54
|
import type { SandboxRecoveryProps } from "../components/sandbox-recovery"
|
|
52
55
|
import type { TranscriptProps } from "../components/transcript"
|
|
53
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
type AgentConversationTurn,
|
|
58
|
+
conversationMessages,
|
|
59
|
+
conversationTurn,
|
|
60
|
+
type PendingUserMessage,
|
|
61
|
+
} from "../conversation"
|
|
54
62
|
import type { TranscriptDelegation } from "../delegation/context"
|
|
55
63
|
import { projectDictation } from "../dictation"
|
|
56
64
|
import { useAgentMessages } from "../i18n"
|
|
@@ -62,6 +70,7 @@ import {
|
|
|
62
70
|
preferenceWithReasoning,
|
|
63
71
|
resolveModelSelection,
|
|
64
72
|
} from "../model-selection"
|
|
73
|
+
import { transcriptMoves } from "../moves"
|
|
65
74
|
import { openQuestion } from "../questions/interpret"
|
|
66
75
|
import type { QuestionComposerProps } from "../questions/question-composer"
|
|
67
76
|
import { type RequesterSettings, sendWithRequesterSettings } from "../requester-settings"
|
|
@@ -88,17 +97,22 @@ import {
|
|
|
88
97
|
} from "../sharing"
|
|
89
98
|
import type {
|
|
90
99
|
AgentContextEntryInput,
|
|
100
|
+
AgentContextInput,
|
|
91
101
|
AgentFileRef,
|
|
102
|
+
AgentInboxItem,
|
|
103
|
+
AgentMessageDelivery,
|
|
92
104
|
AgentRun,
|
|
93
105
|
AgentThreadSandboxParams,
|
|
94
106
|
LanguageModel,
|
|
95
107
|
} from "../types"
|
|
108
|
+
import { markThreadReadsStale, threadQueryOptions } from "./thread-queries"
|
|
96
109
|
import {
|
|
97
110
|
ComputerUnavailableError,
|
|
98
111
|
type NewThreadPlaceBody,
|
|
99
112
|
useNewThreadPlace,
|
|
100
113
|
} from "./use-new-thread-place"
|
|
101
114
|
import { useAgentThreadLists } from "./use-thread-lists"
|
|
115
|
+
import { useThreadPlace } from "./use-thread-place"
|
|
102
116
|
import { useThreadStream } from "./use-thread-stream"
|
|
103
117
|
|
|
104
118
|
interface PendingSend {
|
|
@@ -144,6 +158,7 @@ export type ConversationComposerProps = Pick<
|
|
|
144
158
|
| "disabled"
|
|
145
159
|
| "pending"
|
|
146
160
|
| "running"
|
|
161
|
+
| "steerable"
|
|
147
162
|
| "stopping"
|
|
148
163
|
| "onStop"
|
|
149
164
|
| "hint"
|
|
@@ -158,10 +173,12 @@ export type ConversationComposerProps = Pick<
|
|
|
158
173
|
| "usingDefaultModel"
|
|
159
174
|
| "onResetModelSelection"
|
|
160
175
|
| "modelRouting"
|
|
176
|
+
| "draftKey"
|
|
161
177
|
| "draft"
|
|
162
178
|
| "draftAttachments"
|
|
163
179
|
| "draftContext"
|
|
164
180
|
| "draftNonce"
|
|
181
|
+
| "draftReseedKey"
|
|
165
182
|
| "insertion"
|
|
166
183
|
| "onInserted"
|
|
167
184
|
| "approvalMode"
|
|
@@ -171,9 +188,21 @@ export type ConversationComposerProps = Pick<
|
|
|
171
188
|
| "contextMeter"
|
|
172
189
|
>
|
|
173
190
|
|
|
191
|
+
/** Draft state for an earlier user message open in the inline editor. */
|
|
192
|
+
export interface AgentMessageEditDraft {
|
|
193
|
+
readonly messageId: string
|
|
194
|
+
readonly text: string
|
|
195
|
+
readonly attachments: readonly AgentFileRef[]
|
|
196
|
+
readonly context: readonly AgentContextEntryInput[]
|
|
197
|
+
/** Incremented when a failed edit restores this draft, so the editor reseeds. */
|
|
198
|
+
readonly nonce: number
|
|
199
|
+
/** Why the last save did not go through, said under the editor. */
|
|
200
|
+
readonly error?: string
|
|
201
|
+
}
|
|
202
|
+
|
|
174
203
|
export type AgentConversation = ReturnType<typeof useAgentConversation>
|
|
175
204
|
|
|
176
|
-
/** Why a message, a retry or a stop did not go through, or the approval mode did not change. */
|
|
205
|
+
/** Why a message, an edit, a retry or a stop did not go through, or the approval mode did not change. */
|
|
177
206
|
export type AgentConversationSendError =
|
|
178
207
|
/** Another answer holds the conversation; `someoneElse` when another person asked for it. */
|
|
179
208
|
| { readonly code: "busy"; readonly someoneElse: boolean }
|
|
@@ -181,7 +210,7 @@ export type AgentConversationSendError =
|
|
|
181
210
|
| { readonly code: "sandbox" }
|
|
182
211
|
/** It's to run on this computer, and what runs it there can't start. */
|
|
183
212
|
| { readonly code: "computer" }
|
|
184
|
-
| { readonly code: "send" | "retry" | "stop" | "approvalMode" }
|
|
213
|
+
| { readonly code: "send" | "edit" | "retry" | "stop" | "approvalMode" }
|
|
185
214
|
|
|
186
215
|
/** The conversation's messages could not be read. */
|
|
187
216
|
export interface AgentConversationMessagesError {
|
|
@@ -190,6 +219,9 @@ export interface AgentConversationMessagesError {
|
|
|
190
219
|
|
|
191
220
|
const MESSAGES_LOAD_ERROR: AgentConversationMessagesError = { code: "load" }
|
|
192
221
|
|
|
222
|
+
/** How often an open thread's messages are read again while the activity feed is away. */
|
|
223
|
+
const MESSAGES_RECOVERY_POLL_MS = 30_000
|
|
224
|
+
|
|
193
225
|
/**
|
|
194
226
|
* Everything one conversation with the project's agent needs: its threads, messages, turn and
|
|
195
227
|
* model choice, and the actions on them. Route-independent; the built-in chat and custom chats
|
|
@@ -234,6 +266,8 @@ export function useAgentConversation({
|
|
|
234
266
|
return
|
|
235
267
|
}
|
|
236
268
|
|
|
269
|
+
// Another thread may hold reads a prefetch or an earlier visit left: opening it reads again.
|
|
270
|
+
if (event.threadId !== threadId) markThreadReadsStale(queryClient, event.threadId)
|
|
237
271
|
void refreshThreads()
|
|
238
272
|
},
|
|
239
273
|
// A held call changed: its card, and the thread list's count of what waits for the reader. Its
|
|
@@ -254,6 +288,7 @@ export function useAgentConversation({
|
|
|
254
288
|
},
|
|
255
289
|
// On every (re)subscription: catch up with what changed while the socket was away.
|
|
256
290
|
onSubscribed: () => {
|
|
291
|
+
markThreadReadsStale(queryClient)
|
|
257
292
|
void queryClient.invalidateQueries({ queryKey: listAgentApprovalsQueryKey() })
|
|
258
293
|
void queryClient.invalidateQueries({ queryKey: listAgentComputersQueryKey() })
|
|
259
294
|
void (threadId === null ? refreshThreads() : refreshThread(threadId))
|
|
@@ -263,32 +298,37 @@ export function useAgentConversation({
|
|
|
263
298
|
// The project activity feed is primary. Poll only as a focus-aware recovery path while the
|
|
264
299
|
// socket is unavailable, rather than opening one connection per background thread.
|
|
265
300
|
const recoveryPollMs = !activityStream.connected || activityStream.error ? 10_000 : false
|
|
301
|
+
// A thread's messages are its heaviest read, so they follow less often while the feed is away;
|
|
302
|
+
// its runs and the thread still poll at the faster rate.
|
|
303
|
+
const messagesRecoveryPollMs = recoveryPollMs === false ? false : MESSAGES_RECOVERY_POLL_MS
|
|
266
304
|
const { threads, sharedThreads, waitingThreadIds } = useAgentThreadLists({
|
|
267
305
|
refetchInterval: recoveryPollMs,
|
|
268
306
|
})
|
|
269
307
|
const currentAgent = agentQuery.data
|
|
270
308
|
const models = useMemo(() => modelsQuery.data?.language ?? [], [modelsQuery.data])
|
|
271
|
-
//
|
|
272
|
-
// conversation
|
|
273
|
-
//
|
|
309
|
+
// The browser remembers one choice: a new conversation starts on it, and with tiers each
|
|
310
|
+
// conversation keeps the model pinned in it. Without tiers, that one choice serves every
|
|
311
|
+
// conversation.
|
|
274
312
|
const tiered = hasTiers(models)
|
|
275
313
|
const [modelPreference, setModelPreference] = useState(readModelPreference)
|
|
276
314
|
const [modelPins, setModelPins] = useState(() => readModelPins() ?? {})
|
|
277
|
-
const [newThreadPin, setNewThreadPin] = useState<ModelPreference | null>(null)
|
|
278
315
|
const modelSelection = resolveModelSelection(
|
|
279
316
|
models,
|
|
280
|
-
tiered ? (threadId === null ?
|
|
317
|
+
tiered ? (threadId === null ? modelPreference : (modelPins[threadId] ?? null)) : modelPreference
|
|
281
318
|
)
|
|
282
319
|
const selectedModel = modelSelection.model
|
|
283
320
|
const selectedReasoning = modelSelection.reasoning
|
|
321
|
+
const reads = threadQueryOptions(threadId ?? "")
|
|
284
322
|
const threadQuery = useQuery({
|
|
285
|
-
...
|
|
323
|
+
...reads.thread,
|
|
286
324
|
enabled: threadId !== null,
|
|
287
325
|
refetchInterval: recoveryPollMs,
|
|
288
326
|
// A shared thread can lose its reader without an event, and a computer's sixb can stop
|
|
289
|
-
// without saying so: read it again when they come back.
|
|
327
|
+
// without saying so: read it again when they come back, however recent the last read.
|
|
290
328
|
refetchOnWindowFocus: (query) =>
|
|
291
|
-
isShared(query.state.data ?? null) || query.state.data?.computer !== undefined
|
|
329
|
+
isShared(query.state.data ?? null) || query.state.data?.computer !== undefined
|
|
330
|
+
? "always"
|
|
331
|
+
: false,
|
|
292
332
|
})
|
|
293
333
|
// A 404 after a read means the reader no longer reads it, such as a participant someone removed:
|
|
294
334
|
// the last copy the query keeps must not stand in for it.
|
|
@@ -310,27 +350,39 @@ export function useAgentConversation({
|
|
|
310
350
|
access === "owner" && thread?.runsOn === "computer" && thread.computer?.online !== true
|
|
311
351
|
|
|
312
352
|
const messagesQuery = useQuery({
|
|
313
|
-
...
|
|
314
|
-
path: { threadId: threadId ?? "" },
|
|
315
|
-
query: { order: "asc" },
|
|
316
|
-
}),
|
|
353
|
+
...reads.messages,
|
|
317
354
|
enabled: threadId !== null,
|
|
318
|
-
refetchInterval:
|
|
355
|
+
refetchInterval: messagesRecoveryPollMs,
|
|
319
356
|
})
|
|
320
357
|
const savedMessages = useMemo(() => messagesQuery.data?.messages ?? [], [messagesQuery.data])
|
|
321
358
|
const approvalOutcomes = useMemo(() => reportedApprovalOutcomes(savedMessages), [savedMessages])
|
|
322
359
|
const authors = messagesQuery.data?.authors
|
|
360
|
+
// Every run, as every message is read: the transcript marks each move from the runs either side.
|
|
323
361
|
const runsQuery = useQuery({
|
|
324
|
-
...
|
|
325
|
-
path: { threadId: threadId ?? "" },
|
|
326
|
-
query: { limit: "50", order: "desc" },
|
|
327
|
-
}),
|
|
362
|
+
...reads.runs,
|
|
328
363
|
enabled: threadId !== null,
|
|
329
364
|
refetchInterval: recoveryPollMs,
|
|
330
365
|
})
|
|
331
366
|
const runs = useMemo(() => runsQuery.data?.runs ?? [], [runsQuery.data])
|
|
332
367
|
const latestRun = runs[0] ?? null
|
|
333
368
|
|
|
369
|
+
// An edit the reader saved while a turn answered waits in the thread's inbox until that turn
|
|
370
|
+
// ends: read from there, it stands in place after a reload, and on another device.
|
|
371
|
+
const inboxQuery = useQuery({
|
|
372
|
+
...listAgentThreadInboxOptions({ path: { threadId: threadId ?? "" } }),
|
|
373
|
+
enabled: threadId !== null,
|
|
374
|
+
refetchInterval: (query) => ((query.state.data?.items.length ?? 0) > 0 ? 5_000 : false),
|
|
375
|
+
})
|
|
376
|
+
const waitingEdit = useMemo(
|
|
377
|
+
() =>
|
|
378
|
+
inboxQuery.data?.items.find(
|
|
379
|
+
(item) =>
|
|
380
|
+
item.replacesMessageId !== undefined &&
|
|
381
|
+
(!user || (item.authorPrincipal.type === "user" && item.authorPrincipal.id === user.id))
|
|
382
|
+
) ?? null,
|
|
383
|
+
[inboxQuery.data, user]
|
|
384
|
+
)
|
|
385
|
+
|
|
334
386
|
// Measured against the model the next message goes to; on Auto, the latest turn's.
|
|
335
387
|
const meteredModel = modelSelection.auto ? undefined : selectedModel
|
|
336
388
|
const contextQuery = useQuery({
|
|
@@ -378,6 +430,7 @@ export function useAgentConversation({
|
|
|
378
430
|
|
|
379
431
|
const [pendingSend, setPendingSend] = useState<PendingSend | null>(null)
|
|
380
432
|
const [pendingUser, setPendingUser] = useState<PendingUserMessage | null>(null)
|
|
433
|
+
const [editingMessage, setEditingMessage] = useState<AgentMessageEditDraft | null>(null)
|
|
381
434
|
const [sentKeys, setSentKeys] = useState<ReadonlyMap<string, string>>(() => new Map())
|
|
382
435
|
const [sendError, setSendError] = useState<{
|
|
383
436
|
threadId: string | null
|
|
@@ -388,7 +441,9 @@ export function useAgentConversation({
|
|
|
388
441
|
attachments: readonly AgentFileRef[]
|
|
389
442
|
context: readonly AgentContextEntryInput[]
|
|
390
443
|
nonce: number
|
|
391
|
-
|
|
444
|
+
/** The conversation the message was for, whichever one is open when it comes back. */
|
|
445
|
+
draftKey: string
|
|
446
|
+
}>({ text: "", attachments: [], context: [], nonce: 0, draftKey: "draft" })
|
|
392
447
|
const [stoppingRunId, setStoppingRunId] = useState<string | null>(null)
|
|
393
448
|
const stopRef = useRef<(approval: AgentApproval) => Promise<void>>(async () => {})
|
|
394
449
|
const decideRef = useRef<NonNullable<TranscriptApprovals["decide"]>>(async () => {
|
|
@@ -402,6 +457,8 @@ export function useAgentConversation({
|
|
|
402
457
|
} | null>(null)
|
|
403
458
|
/** The thread whose answer Continue is asking for, until the API accepts or refuses it. */
|
|
404
459
|
const [continuingThreadId, setContinuingThreadId] = useState<string | null>(null)
|
|
460
|
+
/** The thread whose sandbox its owner just resumed, until its cut-short turn runs again. */
|
|
461
|
+
const [resumedThreadId, setResumedThreadId] = useState<string | null>(null)
|
|
405
462
|
|
|
406
463
|
const pendingRun =
|
|
407
464
|
pendingSend && threadId !== null && pendingSend.run.threadId === threadId
|
|
@@ -412,6 +469,11 @@ export function useAgentConversation({
|
|
|
412
469
|
? selectActiveRunId({ pendingRun, threadActiveRunId: thread?.activeRunId ?? null, latestRun })
|
|
413
470
|
: null
|
|
414
471
|
const { live, run: streamRun, reconnecting } = useThreadStream({ threadId, runId: activeRunId })
|
|
472
|
+
// What the turn read as it answered leaves the tray: the transcript shows it where it was read.
|
|
473
|
+
const readMessageIds = useMemo(
|
|
474
|
+
() => new Set(live.inboxReads.flatMap((read) => read.messages.map((message) => message.id))),
|
|
475
|
+
[live.inboxReads]
|
|
476
|
+
)
|
|
415
477
|
// A compaction that ended changed what the conversation weighs: measure it again.
|
|
416
478
|
const wasCompactingRef = useRef(false)
|
|
417
479
|
useEffect(() => {
|
|
@@ -453,24 +515,60 @@ export function useAgentConversation({
|
|
|
453
515
|
setPendingUser(null)
|
|
454
516
|
return
|
|
455
517
|
}
|
|
518
|
+
const replacedGone =
|
|
519
|
+
pendingUser.replacesMessageId === undefined ||
|
|
520
|
+
!savedMessages.some((message) => message.id === pendingUser.replacesMessageId)
|
|
456
521
|
if (
|
|
457
522
|
pendingUser.messageId &&
|
|
523
|
+
replacedGone &&
|
|
458
524
|
savedMessages.some((message) => message.id === pendingUser.messageId)
|
|
459
525
|
) {
|
|
460
526
|
setPendingUser(null)
|
|
461
527
|
}
|
|
462
528
|
}, [pendingUser, threadId, savedMessages])
|
|
463
529
|
|
|
530
|
+
useEffect(() => {
|
|
531
|
+
if (threadId === null || !waitingEdit) return
|
|
532
|
+
setPendingUser((current) =>
|
|
533
|
+
current?.threadId === threadId ? current : waitingEditPending(threadId, waitingEdit)
|
|
534
|
+
)
|
|
535
|
+
}, [threadId, waitingEdit])
|
|
536
|
+
|
|
537
|
+
// An edit that waited and never became a message was set aside: withdrawn, or dropped once the
|
|
538
|
+
// message it replaced was gone. The conversation shows what the thread holds again.
|
|
539
|
+
useEffect(() => {
|
|
540
|
+
if (!pendingUser?.replacesMessageId || pendingUser.messageId === null) return
|
|
541
|
+
if (pendingUser.threadId !== threadId || pendingSend !== null) return
|
|
542
|
+
if (!inboxQuery.isSuccess || inboxQuery.isFetching || messagesQuery.isFetching) return
|
|
543
|
+
|
|
544
|
+
const waiting = inboxQuery.data.items.some((item) => item.messageId === pendingUser.messageId)
|
|
545
|
+
const saved = savedMessages.some((message) => message.id === pendingUser.messageId)
|
|
546
|
+
if (!waiting && !saved && activeRunId === null) setPendingUser(null)
|
|
547
|
+
}, [
|
|
548
|
+
pendingUser,
|
|
549
|
+
threadId,
|
|
550
|
+
pendingSend,
|
|
551
|
+
inboxQuery.isSuccess,
|
|
552
|
+
inboxQuery.isFetching,
|
|
553
|
+
inboxQuery.data,
|
|
554
|
+
messagesQuery.isFetching,
|
|
555
|
+
savedMessages,
|
|
556
|
+
activeRunId,
|
|
557
|
+
])
|
|
558
|
+
|
|
464
559
|
useEffect(() => {
|
|
465
560
|
setSendError((current) => (current && current.threadId === threadId ? current : null))
|
|
561
|
+
setEditingMessage(null)
|
|
466
562
|
}, [threadId])
|
|
467
563
|
|
|
468
564
|
const createThread = useMutation(createAgentThreadMutation())
|
|
469
565
|
const postMessage = useMutation(postAgentThreadMessageMutation())
|
|
566
|
+
const editThreadMessage = useMutation(editAgentThreadMessageMutation())
|
|
567
|
+
const withdrawInboxItem = useMutation(withdrawAgentThreadInboxItemMutation())
|
|
470
568
|
const cancelRun = useMutation(cancelAgentRunMutation())
|
|
471
569
|
const retryRun = useMutation(retryAgentRunMutation())
|
|
472
570
|
const recreateSandbox = useMutation(recreateAgentThreadSandboxMutation())
|
|
473
|
-
const
|
|
571
|
+
const restoreSandbox = useMutation(restoreAgentThreadSandboxMutation())
|
|
474
572
|
const stopBackgroundCommand = useMutation(stopAgentBackgroundCommandMutation())
|
|
475
573
|
const decideApproval = useMutation(decideAgentApprovalMutation())
|
|
476
574
|
// Each runs after the one before, so the last choice is the one the server keeps.
|
|
@@ -493,15 +591,28 @@ export function useAgentConversation({
|
|
|
493
591
|
const approvalMode: AgentApprovalMode | undefined =
|
|
494
592
|
chosenHere ?? (threadId !== null ? threadQuery.data?.approvalMode : defaultApprovalMode)
|
|
495
593
|
|
|
496
|
-
const
|
|
497
|
-
|
|
594
|
+
const activePending = pendingUser && pendingUser.threadId === threadId ? pendingUser : null
|
|
595
|
+
const visibleSavedMessages = useMemo(() => {
|
|
596
|
+
if (!activePending?.replacesMessageId) return savedMessages
|
|
597
|
+
const cut = savedMessages.findIndex((entry) => entry.id === activePending.replacesMessageId)
|
|
598
|
+
return cut === -1 ? savedMessages : savedMessages.slice(0, cut)
|
|
599
|
+
}, [activePending?.replacesMessageId, savedMessages])
|
|
600
|
+
|
|
601
|
+
// From Save until the thread holds the edited message: the turns it replaces, and any turn it
|
|
602
|
+
// stopped, are gone from the transcript.
|
|
603
|
+
const editInFlight = activePending?.replacesMessageId !== undefined
|
|
604
|
+
const basePresentation = presentActiveTurn({
|
|
605
|
+
activeRunId: editInFlight ? null : activeRunId,
|
|
498
606
|
pendingRun,
|
|
499
|
-
streamRun,
|
|
607
|
+
streamRun: editInFlight ? null : streamRun,
|
|
500
608
|
live,
|
|
501
609
|
runs,
|
|
502
|
-
messages:
|
|
610
|
+
messages: visibleSavedMessages,
|
|
503
611
|
messagesLoading: messagesQuery.isFetching,
|
|
504
612
|
})
|
|
613
|
+
const presentation = editInFlight
|
|
614
|
+
? ({ kind: "responding", queuedRun: null } as const)
|
|
615
|
+
: basePresentation
|
|
505
616
|
const isRunning = presentation.kind === "responding"
|
|
506
617
|
const waitingLonger = useExtendedWaitingStatus(
|
|
507
618
|
presentation.kind === "responding" ? presentation.queuedRun : null
|
|
@@ -516,7 +627,13 @@ export function useAgentConversation({
|
|
|
516
627
|
[pendingRun, streamRun, ...runs].find((run) => run !== null && run.id === activeRunId) ?? null
|
|
517
628
|
|
|
518
629
|
const stop = () => {
|
|
519
|
-
if (threadId === null
|
|
630
|
+
if (threadId === null) return
|
|
631
|
+
// While an edit waits for the turn it stopped, Stop takes the edit back, to the editor.
|
|
632
|
+
if (waitingEdit && pendingUser?.messageId === waitingEdit.messageId) {
|
|
633
|
+
withdrawEdit(threadId, waitingEdit)
|
|
634
|
+
return
|
|
635
|
+
}
|
|
636
|
+
if (activeRunId === null || !canStop) return
|
|
520
637
|
setStoppingRunId(activeRunId)
|
|
521
638
|
cancelRun.mutate(
|
|
522
639
|
{ path: { threadId }, body: { runId: activeRunId } },
|
|
@@ -530,44 +647,91 @@ export function useAgentConversation({
|
|
|
530
647
|
)
|
|
531
648
|
}
|
|
532
649
|
|
|
650
|
+
const withdrawEdit = (targetThreadId: string, item: AgentInboxItem) => {
|
|
651
|
+
const edit = pendingUser
|
|
652
|
+
withdrawInboxItem.mutate(
|
|
653
|
+
{ path: { threadId: targetThreadId, itemId: item.id } },
|
|
654
|
+
{
|
|
655
|
+
onSuccess: () => {
|
|
656
|
+
setPendingUser(null)
|
|
657
|
+
// The turn the edit stopped is still winding down: it shows as stopping.
|
|
658
|
+
if (activeRunId !== null) setStoppingRunId(activeRunId)
|
|
659
|
+
if (edit?.replacesMessageId) {
|
|
660
|
+
setEditingMessage((current) => ({
|
|
661
|
+
messageId: edit.replacesMessageId as string,
|
|
662
|
+
text: edit.text,
|
|
663
|
+
attachments: edit.attachments,
|
|
664
|
+
context: edit.context,
|
|
665
|
+
nonce: (current?.nonce ?? 0) + 1,
|
|
666
|
+
}))
|
|
667
|
+
}
|
|
668
|
+
},
|
|
669
|
+
// A turn already started from it: Stop again stops that turn.
|
|
670
|
+
onSettled: () => void refreshThread(targetThreadId),
|
|
671
|
+
}
|
|
672
|
+
)
|
|
673
|
+
}
|
|
674
|
+
|
|
533
675
|
// The turn runs in the mode the chip shows, whatever another device chose since.
|
|
534
676
|
const turnApprovalMode = approvalMode === undefined ? {} : { approvalMode }
|
|
535
677
|
|
|
536
678
|
const send = async (
|
|
537
679
|
text: string,
|
|
538
680
|
attachments: readonly AgentFileRef[],
|
|
539
|
-
context: readonly AgentContextEntryInput[]
|
|
681
|
+
context: readonly AgentContextEntryInput[],
|
|
682
|
+
delivery: AgentMessageDelivery = "auto"
|
|
540
683
|
) => {
|
|
541
|
-
|
|
684
|
+
// A running turn takes the message as a steer, a queued turn, or one that stops it. A chat that
|
|
685
|
+
// does not say where it goes sends it where Enter would: into the reader's own answer, or after
|
|
686
|
+
// the answer in flight when it is someone else's or carries a file, which no step reads.
|
|
687
|
+
// The thread that a message starts is always a turn, whatever the composer said.
|
|
688
|
+
const where: AgentMessageDelivery =
|
|
689
|
+
isRunning && delivery === "auto"
|
|
690
|
+
? attachments.length === 0 && !requestedBySomeoneElse(activeRun, user)
|
|
691
|
+
? "steer"
|
|
692
|
+
: "queue"
|
|
693
|
+
: delivery
|
|
542
694
|
setSendError(null)
|
|
543
695
|
const targetThreadId = threadId
|
|
696
|
+
// What this message asks for, and what the thread it creates keeps pinned.
|
|
697
|
+
const selection = modelSelection.request
|
|
544
698
|
const key = `sent:${++sentMessageCount}`
|
|
545
699
|
let createdThreadId: string | null = null
|
|
546
700
|
try {
|
|
547
701
|
if (targetThreadId !== null) {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
702
|
+
// A message for the running turn waits in the inbox, which the tray shows: only one that
|
|
703
|
+
// starts a turn is the transcript's next message.
|
|
704
|
+
if (where === "auto") {
|
|
705
|
+
setPendingUser({
|
|
706
|
+
key,
|
|
707
|
+
threadId: targetThreadId,
|
|
708
|
+
text,
|
|
709
|
+
attachments,
|
|
710
|
+
context,
|
|
711
|
+
messageId: null,
|
|
712
|
+
})
|
|
713
|
+
}
|
|
556
714
|
const response = await sendWithRequesterSettings((settings) =>
|
|
557
715
|
postMessage.mutateAsync({
|
|
558
716
|
path: { threadId: targetThreadId },
|
|
559
717
|
body: {
|
|
560
|
-
...messageBody(text, attachments, context,
|
|
718
|
+
...messageBody(text, attachments, context, selection, settings),
|
|
561
719
|
...turnApprovalMode,
|
|
720
|
+
...(where === "auto" ? {} : { delivery: where }),
|
|
562
721
|
},
|
|
563
722
|
})
|
|
564
723
|
)
|
|
565
|
-
recordAcceptedSend(response.run, key)
|
|
724
|
+
if (response.run) recordAcceptedSend(response.run, key)
|
|
566
725
|
await Promise.all([
|
|
567
726
|
queryClient.invalidateQueries({
|
|
568
727
|
queryKey: listAgentThreadMessagesQueryKey({ path: { threadId: targetThreadId } }),
|
|
569
728
|
}),
|
|
570
729
|
queryClient.invalidateQueries({ queryKey: listAgentThreadsQueryKey() }),
|
|
730
|
+
// A message that waits beside the running turn is in the thread's inbox, not its
|
|
731
|
+
// transcript: the tray reads it from there.
|
|
732
|
+
queryClient.invalidateQueries({
|
|
733
|
+
queryKey: listAgentThreadInboxQueryKey({ path: { threadId: targetThreadId } }),
|
|
734
|
+
}),
|
|
571
735
|
])
|
|
572
736
|
return
|
|
573
737
|
}
|
|
@@ -582,7 +746,13 @@ export function useAgentConversation({
|
|
|
582
746
|
}
|
|
583
747
|
if (!place) {
|
|
584
748
|
// They cancelled choosing a folder: nothing was sent, and their message goes back.
|
|
585
|
-
setDraftReseed((current) => ({
|
|
749
|
+
setDraftReseed((current) => ({
|
|
750
|
+
text,
|
|
751
|
+
attachments,
|
|
752
|
+
context,
|
|
753
|
+
nonce: current.nonce + 1,
|
|
754
|
+
draftKey: "draft",
|
|
755
|
+
}))
|
|
586
756
|
return
|
|
587
757
|
}
|
|
588
758
|
const title = deriveTitle(text, attachments)
|
|
@@ -609,16 +779,16 @@ export function useAgentConversation({
|
|
|
609
779
|
postMessage.mutateAsync({
|
|
610
780
|
path: { threadId: newThreadId },
|
|
611
781
|
body: {
|
|
612
|
-
...messageBody(text, attachments, context,
|
|
782
|
+
...messageBody(text, attachments, context, selection, settings),
|
|
613
783
|
...turnApprovalMode,
|
|
614
784
|
},
|
|
615
785
|
})
|
|
616
786
|
)
|
|
617
|
-
recordAcceptedSend(response.run, key)
|
|
787
|
+
if (response.run) recordAcceptedSend(response.run, key)
|
|
618
788
|
// The next new conversation starts from the default again.
|
|
619
789
|
setChosenApprovalMode((current) => (current?.threadId === null ? null : current))
|
|
620
790
|
await queryClient.invalidateQueries({ queryKey: listAgentThreadsQueryKey() })
|
|
621
|
-
showCreatedThread(createdThreadId)
|
|
791
|
+
showCreatedThread(createdThreadId, selection)
|
|
622
792
|
} catch (error) {
|
|
623
793
|
// Restore the exact submitted snapshot. In particular, do not re-read ambient page context:
|
|
624
794
|
// navigation may have changed it while the request was in flight.
|
|
@@ -628,12 +798,13 @@ export function useAgentConversation({
|
|
|
628
798
|
attachments,
|
|
629
799
|
context,
|
|
630
800
|
nonce: current.nonce + 1,
|
|
801
|
+
draftKey: createdThreadId ?? targetThreadId ?? "draft",
|
|
631
802
|
}))
|
|
632
803
|
setSendError({
|
|
633
804
|
threadId: createdThreadId ?? targetThreadId,
|
|
634
805
|
failure: sendFailure(error),
|
|
635
806
|
})
|
|
636
|
-
if (createdThreadId) showCreatedThread(createdThreadId)
|
|
807
|
+
if (createdThreadId) showCreatedThread(createdThreadId, selection)
|
|
637
808
|
|
|
638
809
|
// A refusal can mean another turn holds the thread: read who asked for it, too.
|
|
639
810
|
if (targetThreadId !== null) void refreshThread(targetThreadId)
|
|
@@ -641,9 +812,9 @@ export function useAgentConversation({
|
|
|
641
812
|
}
|
|
642
813
|
}
|
|
643
814
|
|
|
644
|
-
//
|
|
645
|
-
const showCreatedThread = (createdThreadId: string) => {
|
|
646
|
-
if (tiered &&
|
|
815
|
+
// The model the first message ran on is pinned in the thread it created, from the moment it shows.
|
|
816
|
+
const showCreatedThread = (createdThreadId: string, pin: ModelPreference | undefined) => {
|
|
817
|
+
if (tiered && pin) pinModel(createdThreadId, pin)
|
|
647
818
|
onThreadCreated(createdThreadId)
|
|
648
819
|
}
|
|
649
820
|
|
|
@@ -702,6 +873,10 @@ export function useAgentConversation({
|
|
|
702
873
|
queryClient.invalidateQueries({
|
|
703
874
|
queryKey: getAgentThreadContextQueryKey({ path: { threadId } }),
|
|
704
875
|
}),
|
|
876
|
+
// A turn that ended read its steers, or started what was queued behind it.
|
|
877
|
+
queryClient.invalidateQueries({
|
|
878
|
+
queryKey: listAgentThreadInboxQueryKey({ path: { threadId } }),
|
|
879
|
+
}),
|
|
705
880
|
])
|
|
706
881
|
|
|
707
882
|
const keepThreadApprovalMode = async (threadId: string, mode: AgentApprovalMode) => {
|
|
@@ -807,8 +982,10 @@ export function useAgentConversation({
|
|
|
807
982
|
postMessage.mutateAsync({ path: { threadId }, body: { continue: true, ...settings } })
|
|
808
983
|
)
|
|
809
984
|
setContinuingThreadId(null)
|
|
810
|
-
|
|
811
|
-
|
|
985
|
+
if (response.run) {
|
|
986
|
+
watchRun(response.run)
|
|
987
|
+
setPendingSend({ run: response.run, anchor: true })
|
|
988
|
+
}
|
|
812
989
|
await refreshThread(threadId)
|
|
813
990
|
} catch (error) {
|
|
814
991
|
setContinuingThreadId(null)
|
|
@@ -817,31 +994,18 @@ export function useAgentConversation({
|
|
|
817
994
|
}
|
|
818
995
|
}
|
|
819
996
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
moveToCloud.mutate(
|
|
823
|
-
{ path: { threadId: thread.id } },
|
|
824
|
-
{
|
|
825
|
-
onSuccess: (moved) => {
|
|
826
|
-
queryClient.setQueryData(getAgentThreadQueryKey({ path: { threadId: moved.id } }), moved)
|
|
827
|
-
void queryClient.invalidateQueries({
|
|
828
|
-
queryKey: listAgentThreadRunsQueryKey({ path: { threadId: moved.id } }),
|
|
829
|
-
})
|
|
830
|
-
void refreshThreads()
|
|
831
|
-
},
|
|
832
|
-
}
|
|
833
|
-
)
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
const handleRecreateSandbox = () => {
|
|
997
|
+
/** Recover the thread's sandbox as its owner chose: fresh, or as the failed save left it. */
|
|
998
|
+
const recoverSandbox = (recovery: typeof recreateSandbox | typeof restoreSandbox) => {
|
|
837
999
|
if (!thread?.sandboxState || isRunning || access !== "owner") return
|
|
838
|
-
|
|
1000
|
+
recovery.mutate(
|
|
839
1001
|
{
|
|
840
1002
|
path: { threadId: thread.id },
|
|
841
1003
|
body: { expectedSandboxName: thread.sandboxState.name },
|
|
842
1004
|
},
|
|
843
1005
|
{
|
|
844
1006
|
onSuccess: () => {
|
|
1007
|
+
if (recovery === restoreSandbox) setResumedThreadId(thread.id)
|
|
1008
|
+
|
|
845
1009
|
void queryClient.invalidateQueries({
|
|
846
1010
|
queryKey: getAgentThreadQueryKey({ path: { threadId: thread.id } }),
|
|
847
1011
|
})
|
|
@@ -866,15 +1030,11 @@ export function useAgentConversation({
|
|
|
866
1030
|
/** Follow the project defaults again, including later changes to them; with tiers, Auto. */
|
|
867
1031
|
const resetModelSelection = () => updateModelPreference(null)
|
|
868
1032
|
|
|
1033
|
+
/** The reader's choice: what a new conversation starts on, and the model pinned in this thread. */
|
|
869
1034
|
const updateModelPreference = (preference: ModelPreference | null) => {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
return
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
if (threadId === null) setNewThreadPin(preference)
|
|
877
|
-
else pinModel(threadId, preference)
|
|
1035
|
+
setModelPreference(preference)
|
|
1036
|
+
writeModelPreference(preference)
|
|
1037
|
+
if (tiered && threadId !== null) pinModel(threadId, preference)
|
|
878
1038
|
}
|
|
879
1039
|
|
|
880
1040
|
// Start from the stored pins, so the ones another tab wrote since are kept.
|
|
@@ -884,21 +1044,18 @@ export function useAgentConversation({
|
|
|
884
1044
|
writeModelPins(pins)
|
|
885
1045
|
}
|
|
886
1046
|
|
|
887
|
-
//
|
|
888
|
-
useEffect(() => {
|
|
889
|
-
if (threadId !== null) setNewThreadPin(null)
|
|
890
|
-
}, [threadId])
|
|
891
|
-
|
|
892
|
-
// Another tab pinned a model, or went back to Auto.
|
|
1047
|
+
// Another tab chose a model, pinned one, or went back to Auto.
|
|
893
1048
|
useEffect(() => {
|
|
894
1049
|
const follow = (event: StorageEvent) => {
|
|
895
1050
|
if (event.key === MODEL_PINS_KEY) setModelPins(readModelPins() ?? {})
|
|
1051
|
+
if (event.key === MODEL_PREFERENCE_KEY) setModelPreference(readModelPreference())
|
|
896
1052
|
}
|
|
897
1053
|
window.addEventListener("storage", follow)
|
|
898
1054
|
return () => window.removeEventListener("storage", follow)
|
|
899
1055
|
}, [])
|
|
900
1056
|
|
|
901
1057
|
const sandboxRecovery =
|
|
1058
|
+
thread?.runsOn !== "computer" &&
|
|
902
1059
|
thread?.sandboxState &&
|
|
903
1060
|
!isRunning &&
|
|
904
1061
|
["busy", "blocked", "unavailable"].includes(thread.sandboxState.status)
|
|
@@ -916,7 +1073,8 @@ export function useAgentConversation({
|
|
|
916
1073
|
const anchorCurrentTurn = Boolean(
|
|
917
1074
|
(pendingUser && pendingUser.threadId === threadId) || (pendingRun && pendingSend?.anchor)
|
|
918
1075
|
)
|
|
919
|
-
const composerPending =
|
|
1076
|
+
const composerPending =
|
|
1077
|
+
postMessage.isPending || editThreadMessage.isPending || createThread.isPending || resolvingPlace
|
|
920
1078
|
const currentSendError: AgentConversationSendError | null =
|
|
921
1079
|
sendError && sendError.threadId === threadId
|
|
922
1080
|
? sendError.failure === "busy"
|
|
@@ -937,6 +1095,7 @@ export function useAgentConversation({
|
|
|
937
1095
|
// A turn that never answered can run again, by whoever asked for it, once the sandbox works,
|
|
938
1096
|
// unless it would fail the same way: a conversation too long for its model.
|
|
939
1097
|
const canRetry =
|
|
1098
|
+
!(access === "participant" && thread?.runsOn === "computer") &&
|
|
940
1099
|
!sandboxRecovery &&
|
|
941
1100
|
((presentation.kind === "failed" && presentation.run.error?.code !== CONTEXT_LIMIT_EXCEEDED) ||
|
|
942
1101
|
((presentation.kind === "timeout" || presentation.kind === "interrupted") &&
|
|
@@ -950,6 +1109,22 @@ export function useAgentConversation({
|
|
|
950
1109
|
latestRun,
|
|
951
1110
|
})
|
|
952
1111
|
|
|
1112
|
+
// Resuming the sandbox picks the cut-short turn up again, once the thread reads ready: it goes
|
|
1113
|
+
// on where it stopped, or runs again when it had not got anywhere.
|
|
1114
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: Continue and Retry check their own state
|
|
1115
|
+
useEffect(() => {
|
|
1116
|
+
if (resumedThreadId === null) return
|
|
1117
|
+
if (resumedThreadId !== threadId) {
|
|
1118
|
+
setResumedThreadId(null)
|
|
1119
|
+
return
|
|
1120
|
+
}
|
|
1121
|
+
if (sandboxRecovery) return
|
|
1122
|
+
|
|
1123
|
+
setResumedThreadId(null)
|
|
1124
|
+
if (canContinue) void continueTurn()
|
|
1125
|
+
else if (canRetry) retry()
|
|
1126
|
+
}, [resumedThreadId, threadId, sandboxRecovery, canContinue, canRetry])
|
|
1127
|
+
|
|
953
1128
|
const reader = user
|
|
954
1129
|
? { type: "user" as const, id: user.id, displayName: user.displayName }
|
|
955
1130
|
: undefined
|
|
@@ -958,14 +1133,181 @@ export function useAgentConversation({
|
|
|
958
1133
|
authors,
|
|
959
1134
|
thread,
|
|
960
1135
|
reader,
|
|
961
|
-
pending:
|
|
1136
|
+
pending: activePending,
|
|
962
1137
|
sentKeys,
|
|
963
1138
|
runs,
|
|
964
1139
|
live,
|
|
965
1140
|
presentation,
|
|
966
1141
|
})
|
|
967
1142
|
|
|
968
|
-
const
|
|
1143
|
+
const editableMessageIds = useMemo((): ReadonlySet<string> => {
|
|
1144
|
+
if (
|
|
1145
|
+
threadId === null ||
|
|
1146
|
+
sandboxRecovery ||
|
|
1147
|
+
editInFlight ||
|
|
1148
|
+
(thread?.runsOn === "computer" && access !== "owner") ||
|
|
1149
|
+
(isRunning && !canStop)
|
|
1150
|
+
) {
|
|
1151
|
+
return new Set()
|
|
1152
|
+
}
|
|
1153
|
+
// An edit takes back whole turns: a message a turn read while it answered, as a steer, sits
|
|
1154
|
+
// inside that turn, which started at an earlier message.
|
|
1155
|
+
const indexOf = new Map(messages.map((entry, index) => [entry.id, index]))
|
|
1156
|
+
const turnStart = new Map(runs.map((run) => [run.id, indexOf.get(run.triggerMessageId)]))
|
|
1157
|
+
let earliestTurnAfter = Number.POSITIVE_INFINITY
|
|
1158
|
+
|
|
1159
|
+
const allowed = new Set<string>()
|
|
1160
|
+
let seenOtherUser = false
|
|
1161
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
1162
|
+
const entry = messages[index]
|
|
1163
|
+
if (!entry) continue
|
|
1164
|
+
|
|
1165
|
+
if (entry.role === "assistant" && entry.runId !== null) {
|
|
1166
|
+
const start = turnStart.get(entry.runId)
|
|
1167
|
+
if (start !== undefined) earliestTurnAfter = Math.min(earliestTurnAfter, start)
|
|
1168
|
+
}
|
|
1169
|
+
if (entry.role !== "user") continue
|
|
1170
|
+
|
|
1171
|
+
const ownMessage = !user || !entry.author || entry.author.isReader
|
|
1172
|
+
const insideTurn = earliestTurnAfter < index
|
|
1173
|
+
if (
|
|
1174
|
+
entry.id !== null &&
|
|
1175
|
+
entry.status === "complete" &&
|
|
1176
|
+
ownMessage &&
|
|
1177
|
+
!insideTurn &&
|
|
1178
|
+
(access === "owner" || !seenOtherUser)
|
|
1179
|
+
) {
|
|
1180
|
+
allowed.add(entry.id)
|
|
1181
|
+
}
|
|
1182
|
+
if (!ownMessage) seenOtherUser = true
|
|
1183
|
+
}
|
|
1184
|
+
return allowed
|
|
1185
|
+
}, [
|
|
1186
|
+
threadId,
|
|
1187
|
+
sandboxRecovery,
|
|
1188
|
+
editInFlight,
|
|
1189
|
+
thread?.runsOn,
|
|
1190
|
+
access,
|
|
1191
|
+
isRunning,
|
|
1192
|
+
canStop,
|
|
1193
|
+
messages,
|
|
1194
|
+
runs,
|
|
1195
|
+
user,
|
|
1196
|
+
])
|
|
1197
|
+
|
|
1198
|
+
const startEditMessage = useCallback(
|
|
1199
|
+
(messageId: string) => {
|
|
1200
|
+
if (!editableMessageIds.has(messageId)) return
|
|
1201
|
+
const target = messages.find((entry) => entry.id === messageId && entry.role === "user")
|
|
1202
|
+
if (!target) return
|
|
1203
|
+
const text = target.parts
|
|
1204
|
+
.map((part) => (part.type === "text" ? part.text : ""))
|
|
1205
|
+
.join("")
|
|
1206
|
+
.trim()
|
|
1207
|
+
const attachments = target.parts.flatMap((part) =>
|
|
1208
|
+
part.type === "file" ? [part.fileRef] : []
|
|
1209
|
+
)
|
|
1210
|
+
setEditingMessage((current) => ({
|
|
1211
|
+
messageId,
|
|
1212
|
+
text,
|
|
1213
|
+
attachments,
|
|
1214
|
+
context: target.context,
|
|
1215
|
+
nonce: (current?.nonce ?? 0) + 1,
|
|
1216
|
+
}))
|
|
1217
|
+
},
|
|
1218
|
+
[editableMessageIds, messages]
|
|
1219
|
+
)
|
|
1220
|
+
|
|
1221
|
+
const cancelEditMessage = useCallback(() => {
|
|
1222
|
+
setEditingMessage(null)
|
|
1223
|
+
}, [])
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* Replace an earlier message and take the conversation back to it. A turn still answering stops
|
|
1227
|
+
* first: the server holds the edit until that turn ends, then rewinds. Meanwhile the transcript
|
|
1228
|
+
* shows the edit in place of the message, with the turns after it gone.
|
|
1229
|
+
*/
|
|
1230
|
+
const editMessage = async (
|
|
1231
|
+
messageId: string,
|
|
1232
|
+
text: string,
|
|
1233
|
+
attachments: readonly AgentFileRef[],
|
|
1234
|
+
context: readonly AgentContextEntryInput[]
|
|
1235
|
+
) => {
|
|
1236
|
+
const targetThreadId = threadId
|
|
1237
|
+
if (targetThreadId === null || !editableMessageIds.has(messageId)) return
|
|
1238
|
+
|
|
1239
|
+
setSendError(null)
|
|
1240
|
+
setEditingMessage(null)
|
|
1241
|
+
const key =
|
|
1242
|
+
messages.find((entry) => entry.id === messageId)?.key ?? `sent:${++sentMessageCount}`
|
|
1243
|
+
setPendingUser({
|
|
1244
|
+
key,
|
|
1245
|
+
threadId: targetThreadId,
|
|
1246
|
+
text,
|
|
1247
|
+
attachments,
|
|
1248
|
+
context,
|
|
1249
|
+
messageId: null,
|
|
1250
|
+
replacesMessageId: messageId,
|
|
1251
|
+
})
|
|
1252
|
+
|
|
1253
|
+
try {
|
|
1254
|
+
const response = await sendWithRequesterSettings((settings) =>
|
|
1255
|
+
editThreadMessage.mutateAsync({
|
|
1256
|
+
path: { threadId: targetThreadId, messageId },
|
|
1257
|
+
body: {
|
|
1258
|
+
...messageBody(text, attachments, context, modelSelection.request, settings),
|
|
1259
|
+
...turnApprovalMode,
|
|
1260
|
+
},
|
|
1261
|
+
})
|
|
1262
|
+
)
|
|
1263
|
+
|
|
1264
|
+
if (response.run) {
|
|
1265
|
+
recordAcceptedSend(response.run, key)
|
|
1266
|
+
} else if (response.item) {
|
|
1267
|
+
// It waits for the turn it stopped: its message takes this id once that turn ends.
|
|
1268
|
+
const waitingId = response.item.messageId
|
|
1269
|
+
setPendingUser((current) =>
|
|
1270
|
+
current && current.key === key ? { ...current, messageId: waitingId } : current
|
|
1271
|
+
)
|
|
1272
|
+
}
|
|
1273
|
+
await refreshThread(targetThreadId)
|
|
1274
|
+
} catch (error) {
|
|
1275
|
+
setPendingUser(null)
|
|
1276
|
+
setEditingMessage((current) => ({
|
|
1277
|
+
messageId,
|
|
1278
|
+
text,
|
|
1279
|
+
attachments,
|
|
1280
|
+
context,
|
|
1281
|
+
nonce: (current?.nonce ?? 0) + 1,
|
|
1282
|
+
error: editFailureMessage(
|
|
1283
|
+
editFailure(error),
|
|
1284
|
+
requestedBySomeoneElse(activeRun, user),
|
|
1285
|
+
labels
|
|
1286
|
+
),
|
|
1287
|
+
}))
|
|
1288
|
+
void refreshThread(targetThreadId)
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
const answeringAuthor = useMemo(
|
|
1293
|
+
() =>
|
|
1294
|
+
answeringFor
|
|
1295
|
+
? {
|
|
1296
|
+
type: answeringFor.type,
|
|
1297
|
+
id: answeringFor.id,
|
|
1298
|
+
...(answeringForName === undefined ? {} : { displayName: answeringForName }),
|
|
1299
|
+
isReader: false,
|
|
1300
|
+
}
|
|
1301
|
+
: null,
|
|
1302
|
+
[answeringFor, answeringForName]
|
|
1303
|
+
)
|
|
1304
|
+
const continuingHere = continuingThreadId !== null && continuingThreadId === threadId
|
|
1305
|
+
const waitingForComputer =
|
|
1306
|
+
computerOffline && thread?.computer
|
|
1307
|
+
? agentMessages.computer.placeOn(folderName(thread.computer.folder), thread.computer.name)
|
|
1308
|
+
: null
|
|
1309
|
+
const streamReconnecting = live.active && reconnecting
|
|
1310
|
+
const nextTurn = conversationTurn({
|
|
969
1311
|
presentation,
|
|
970
1312
|
activeRunId,
|
|
971
1313
|
canStop,
|
|
@@ -973,21 +1315,17 @@ export function useAgentConversation({
|
|
|
973
1315
|
canContinue,
|
|
974
1316
|
stopping,
|
|
975
1317
|
retrying: retryRun.isPending,
|
|
976
|
-
continuing:
|
|
1318
|
+
continuing: continuingHere,
|
|
977
1319
|
waitingLonger,
|
|
978
|
-
waitingFor:
|
|
1320
|
+
waitingFor: waitingForComputer,
|
|
979
1321
|
compacting: live.compacting,
|
|
980
1322
|
contextFull: live.contextFull,
|
|
981
|
-
reconnecting:
|
|
982
|
-
answeringFor:
|
|
983
|
-
? {
|
|
984
|
-
type: answeringFor.type,
|
|
985
|
-
id: answeringFor.id,
|
|
986
|
-
...(answeringForName === undefined ? {} : { displayName: answeringForName }),
|
|
987
|
-
isReader: false,
|
|
988
|
-
}
|
|
989
|
-
: null,
|
|
1323
|
+
reconnecting: streamReconnecting,
|
|
1324
|
+
answeringFor: answeringAuthor,
|
|
990
1325
|
})
|
|
1326
|
+
const prevTurnRef = useRef(nextTurn)
|
|
1327
|
+
if (!sameTurn(prevTurnRef.current, nextTurn)) prevTurnRef.current = nextTurn
|
|
1328
|
+
const turn = prevTurnRef.current
|
|
991
1329
|
|
|
992
1330
|
/**
|
|
993
1331
|
* Stop a turn paused on held calls, as Stop does a running one: its waiting calls are set aside,
|
|
@@ -1053,27 +1391,40 @@ export function useAgentConversation({
|
|
|
1053
1391
|
[runs, access, user]
|
|
1054
1392
|
)
|
|
1055
1393
|
|
|
1056
|
-
//
|
|
1057
|
-
|
|
1058
|
-
const
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1394
|
+
// The names of the reader's computers, where they're already known: a run keeps only the id.
|
|
1395
|
+
const listedComputers = useQuery({ ...listAgentComputersOptions(), enabled: false }).data
|
|
1396
|
+
const computerNames = useMemo(() => {
|
|
1397
|
+
const names = new Map(
|
|
1398
|
+
(listedComputers?.computers ?? []).map((computer) => [computer.id, computer.name])
|
|
1399
|
+
)
|
|
1400
|
+
if (thread?.computer) names.set(thread.computer.id, thread.computer.name)
|
|
1401
|
+
return names
|
|
1402
|
+
}, [listedComputers, thread?.computer])
|
|
1403
|
+
|
|
1404
|
+
// Where the conversation moved, at every turn that ran elsewhere than the one before and where it
|
|
1405
|
+
// runs now: the files earlier turns worked on stayed behind.
|
|
1406
|
+
const { moved, moves } = useMemo(
|
|
1407
|
+
() =>
|
|
1408
|
+
transcriptMoves({
|
|
1409
|
+
thread,
|
|
1410
|
+
savedMessages,
|
|
1411
|
+
shownIds: new Set(messages.flatMap((message) => (message.id !== null ? [message.id] : []))),
|
|
1412
|
+
runs,
|
|
1413
|
+
messages: agentMessages.computer,
|
|
1414
|
+
computerNames,
|
|
1415
|
+
ownerName: thread && access === "participant" ? personName(threadOwner(thread)) : null,
|
|
1416
|
+
}),
|
|
1417
|
+
[access, agentMessages.computer, computerNames, messages, runs, savedMessages, thread]
|
|
1418
|
+
)
|
|
1419
|
+
|
|
1420
|
+
const hasPendingApprovals =
|
|
1421
|
+
isAwaitingApproval(latestRun) &&
|
|
1422
|
+
approvals.some((approval) => approval.status === "pending" && approval.runId === latestRun?.id)
|
|
1423
|
+
// A computer's conversation moves with a turn still queued for it; the cloud's, once none is.
|
|
1424
|
+
const replyRunning = thread?.runsOn === "computer" ? activeRun?.status === "running" : isRunning
|
|
1425
|
+
const placeBusy = hasPendingApprovals ? "approval" : replyRunning ? "running" : null
|
|
1426
|
+
const messageWaiting = thread?.runsOn === "computer" && activeRun?.status === "queued"
|
|
1427
|
+
const place = useThreadPlace({ thread, access, busy: placeBusy, waiting: messageWaiting })
|
|
1077
1428
|
|
|
1078
1429
|
// Its background commands: what its owner's sixb reports of them, and their Stop, to its owner
|
|
1079
1430
|
// alone, as the computer is theirs. A command started in a folder runs on there once the thread
|
|
@@ -1105,104 +1456,272 @@ export function useAgentConversation({
|
|
|
1105
1456
|
const [questionSetAside, setQuestionSetAside] = useState<string | null>(null)
|
|
1106
1457
|
const asked = threadId !== null ? openQuestion(messages, turn) : null
|
|
1107
1458
|
const asking = asked !== null && questionSetAside !== asked.messageKey ? asked : null
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1459
|
+
// Stable callbacks so streaming chunks never invalidate memoized Composer or Transcript controls.
|
|
1460
|
+
const actionsRef = useRef({
|
|
1461
|
+
send,
|
|
1462
|
+
stop,
|
|
1463
|
+
retry,
|
|
1464
|
+
continueTurn,
|
|
1465
|
+
selectModel,
|
|
1466
|
+
selectReasoning,
|
|
1467
|
+
resetReasoning,
|
|
1468
|
+
resetModelSelection,
|
|
1469
|
+
setApprovalMode,
|
|
1470
|
+
editMessage,
|
|
1471
|
+
})
|
|
1472
|
+
actionsRef.current = {
|
|
1473
|
+
send,
|
|
1474
|
+
stop,
|
|
1475
|
+
retry,
|
|
1476
|
+
continueTurn,
|
|
1477
|
+
selectModel,
|
|
1478
|
+
selectReasoning,
|
|
1479
|
+
resetReasoning,
|
|
1480
|
+
resetModelSelection,
|
|
1481
|
+
setApprovalMode,
|
|
1482
|
+
editMessage,
|
|
1128
1483
|
}
|
|
1484
|
+
const stableSend = useCallback<ComposerProps["onSend"]>(
|
|
1485
|
+
(text, attachments, context, delivery) =>
|
|
1486
|
+
void actionsRef.current.send(text, attachments, context, delivery),
|
|
1487
|
+
[]
|
|
1488
|
+
)
|
|
1489
|
+
const stableStop = useCallback(() => actionsRef.current.stop(), [])
|
|
1490
|
+
const stableRetry = useCallback(() => actionsRef.current.retry(), [])
|
|
1491
|
+
const stableContinue = useCallback(() => void actionsRef.current.continueTurn(), [])
|
|
1492
|
+
const stableSelectModel = useCallback(
|
|
1493
|
+
(model: LanguageModel) => actionsRef.current.selectModel(model),
|
|
1494
|
+
[]
|
|
1495
|
+
)
|
|
1496
|
+
const stableSelectReasoning = useCallback(
|
|
1497
|
+
(reasoning: ModelReasoningLevel) => actionsRef.current.selectReasoning(reasoning),
|
|
1498
|
+
[]
|
|
1499
|
+
)
|
|
1500
|
+
const stableResetReasoning = useCallback(() => actionsRef.current.resetReasoning(), [])
|
|
1501
|
+
const stableResetModelSelection = useCallback(() => actionsRef.current.resetModelSelection(), [])
|
|
1502
|
+
const stableSetApprovalMode = useCallback(
|
|
1503
|
+
(mode: AgentApprovalMode) => actionsRef.current.setApprovalMode(mode),
|
|
1504
|
+
[]
|
|
1505
|
+
)
|
|
1506
|
+
const stableSubmitEdit = useCallback<NonNullable<TranscriptProps["onSubmitEditMessage"]>>(
|
|
1507
|
+
(messageId, text, attachments, context) =>
|
|
1508
|
+
void actionsRef.current.editMessage(messageId, text, attachments, context),
|
|
1509
|
+
[]
|
|
1510
|
+
)
|
|
1511
|
+
const stableAnswerQuestion = useCallback(
|
|
1512
|
+
(text: string) => void actionsRef.current.send(text, [], []),
|
|
1513
|
+
[]
|
|
1514
|
+
)
|
|
1129
1515
|
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
modelsLoading: modelsQuery.isLoading,
|
|
1135
|
-
modelsError: modelsQuery.isError,
|
|
1136
|
-
onSelectModel: selectModel,
|
|
1137
|
-
onSelectReasoning: selectReasoning,
|
|
1138
|
-
onResetReasoning: resetReasoning,
|
|
1139
|
-
usingDefaultModel: modelSelection.request === undefined,
|
|
1140
|
-
onResetModelSelection: resetModelSelection,
|
|
1141
|
-
modelRouting: modelsQuery.data?.languageRouting,
|
|
1142
|
-
}
|
|
1516
|
+
const askingKey = asking?.messageKey ?? null
|
|
1517
|
+
const dismissQuestion = useCallback(() => {
|
|
1518
|
+
if (askingKey) setQuestionSetAside(askingKey)
|
|
1519
|
+
}, [askingKey])
|
|
1143
1520
|
|
|
1144
|
-
const
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1521
|
+
const questionProps: QuestionComposerProps | null = useMemo(
|
|
1522
|
+
() =>
|
|
1523
|
+
asking
|
|
1524
|
+
? {
|
|
1525
|
+
questions: asking.questions,
|
|
1526
|
+
onAnswer: stableAnswerQuestion,
|
|
1527
|
+
onDismiss: dismissQuestion,
|
|
1528
|
+
}
|
|
1529
|
+
: null,
|
|
1530
|
+
[asking, stableAnswerQuestion, dismissQuestion]
|
|
1531
|
+
)
|
|
1532
|
+
|
|
1533
|
+
const movedAfterMessageId = moved?.afterMessageId ?? null
|
|
1534
|
+
const movedLabel = moved?.label ?? null
|
|
1535
|
+
const stableMoved = useMemo(
|
|
1536
|
+
() =>
|
|
1537
|
+
movedAfterMessageId && movedLabel
|
|
1538
|
+
? { afterMessageId: movedAfterMessageId, label: movedLabel }
|
|
1539
|
+
: null,
|
|
1540
|
+
[movedAfterMessageId, movedLabel]
|
|
1541
|
+
)
|
|
1542
|
+
|
|
1543
|
+
const transcriptProps: TranscriptProps = useMemo(
|
|
1544
|
+
() => ({
|
|
1545
|
+
threadId,
|
|
1546
|
+
messages,
|
|
1547
|
+
moved: stableMoved,
|
|
1548
|
+
moves,
|
|
1549
|
+
turn,
|
|
1550
|
+
anchorCurrentTurn,
|
|
1551
|
+
onRetry: canRetry ? stableRetry : undefined,
|
|
1552
|
+
onContinue: canContinue ? stableContinue : undefined,
|
|
1553
|
+
editableMessageIds,
|
|
1554
|
+
editingMessage,
|
|
1555
|
+
onStartEditMessage: startEditMessage,
|
|
1556
|
+
onCancelEditMessage: cancelEditMessage,
|
|
1557
|
+
onSubmitEditMessage: stableSubmitEdit,
|
|
1558
|
+
approvals: transcriptApprovals,
|
|
1559
|
+
approvalOutcomes,
|
|
1560
|
+
delegation: transcriptDelegation,
|
|
1561
|
+
background: transcriptBackground,
|
|
1562
|
+
}),
|
|
1563
|
+
[
|
|
1564
|
+
threadId,
|
|
1565
|
+
messages,
|
|
1566
|
+
stableMoved,
|
|
1567
|
+
moves,
|
|
1568
|
+
turn,
|
|
1569
|
+
anchorCurrentTurn,
|
|
1570
|
+
canRetry,
|
|
1571
|
+
stableRetry,
|
|
1572
|
+
canContinue,
|
|
1573
|
+
stableContinue,
|
|
1574
|
+
editableMessageIds,
|
|
1575
|
+
editingMessage,
|
|
1576
|
+
startEditMessage,
|
|
1577
|
+
cancelEditMessage,
|
|
1578
|
+
stableSubmitEdit,
|
|
1579
|
+
transcriptApprovals,
|
|
1580
|
+
approvalOutcomes,
|
|
1581
|
+
transcriptDelegation,
|
|
1582
|
+
transcriptBackground,
|
|
1583
|
+
]
|
|
1584
|
+
)
|
|
1585
|
+
|
|
1586
|
+
const meterContext = threadId !== null ? contextQuery.data : undefined
|
|
1587
|
+
const meterModelName = meteredModelName(models, contextQuery.data?.model)
|
|
1588
|
+
const contextMeter = useMemo(
|
|
1589
|
+
() => ({
|
|
1590
|
+
context: meterContext,
|
|
1591
|
+
modelName: meterModelName,
|
|
1175
1592
|
condensing: live.compacting,
|
|
1176
|
-
},
|
|
1177
|
-
|
|
1593
|
+
}),
|
|
1594
|
+
[meterContext, meterModelName, live.compacting]
|
|
1595
|
+
)
|
|
1178
1596
|
|
|
1179
|
-
const
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1597
|
+
const composerError = currentSendError
|
|
1598
|
+
? failureMessage(currentSendError, labels, agentMessages.approvalModes.saveFailed)
|
|
1599
|
+
: undefined
|
|
1600
|
+
const composerHint = answeringName
|
|
1601
|
+
? agentMessages.sharing.answering(answeringName)
|
|
1602
|
+
: othersWaiting
|
|
1603
|
+
? agentMessages.approvals.setsAside(transcriptApprovals.requesterName(othersWaiting))
|
|
1604
|
+
: undefined
|
|
1605
|
+
const resolvedNewThreadPlace =
|
|
1606
|
+
threadId === null && !newThreadSandbox && (newThreadPlace || newThreadPlaceWaiting)
|
|
1607
|
+
? (newThreadPlace ?? "waiting")
|
|
1608
|
+
: undefined
|
|
1609
|
+
const usingDefaultModel = modelSelection.request === undefined
|
|
1610
|
+
const modelRouting = modelsQuery.data?.languageRouting
|
|
1611
|
+
const dictationRecognizer = projectDictation(modelsQuery.data)
|
|
1612
|
+
const composerDisabled = Boolean(sandboxRecovery)
|
|
1613
|
+
const steerable = !requestedBySomeoneElse(activeRun, user)
|
|
1614
|
+
|
|
1615
|
+
const composerProps: ConversationComposerProps = useMemo(
|
|
1616
|
+
() => ({
|
|
1617
|
+
onSend: stableSend,
|
|
1618
|
+
...(resolvedNewThreadPlace ? { newThreadPlace: resolvedNewThreadPlace } : {}),
|
|
1619
|
+
error: composerError,
|
|
1620
|
+
// Whoever's answer is in flight, the reader writes the next message.
|
|
1621
|
+
disabled: composerDisabled,
|
|
1622
|
+
hint: composerHint,
|
|
1623
|
+
pending: composerPending,
|
|
1624
|
+
running: isRunning,
|
|
1625
|
+
// Only the turn the reader asked for takes a steer; another person's takes a queued message.
|
|
1626
|
+
steerable,
|
|
1627
|
+
stopping,
|
|
1628
|
+
onStop: canStop ? stableStop : undefined,
|
|
1629
|
+
models,
|
|
1630
|
+
selectedModel,
|
|
1631
|
+
selectedReasoning,
|
|
1632
|
+
modelsLoading: modelsQuery.isLoading,
|
|
1633
|
+
modelsError: modelsQuery.isError,
|
|
1634
|
+
onSelectModel: stableSelectModel,
|
|
1635
|
+
onSelectReasoning: stableSelectReasoning,
|
|
1636
|
+
onResetReasoning: stableResetReasoning,
|
|
1637
|
+
usingDefaultModel,
|
|
1638
|
+
onResetModelSelection: stableResetModelSelection,
|
|
1639
|
+
modelRouting,
|
|
1640
|
+
draftKey: threadId ?? "draft",
|
|
1641
|
+
draft: draftReseed.text,
|
|
1642
|
+
draftAttachments: draftReseed.attachments,
|
|
1643
|
+
draftContext: draftReseed.context,
|
|
1644
|
+
draftNonce: draftReseed.nonce,
|
|
1645
|
+
draftReseedKey: draftReseed.draftKey,
|
|
1646
|
+
approvalMode,
|
|
1647
|
+
onApprovalModeChange: stableSetApprovalMode,
|
|
1648
|
+
awaitingApproval,
|
|
1649
|
+
dictation: dictationRecognizer,
|
|
1650
|
+
contextMeter,
|
|
1651
|
+
}),
|
|
1652
|
+
[
|
|
1653
|
+
stableSend,
|
|
1654
|
+
resolvedNewThreadPlace,
|
|
1655
|
+
composerError,
|
|
1656
|
+
composerDisabled,
|
|
1657
|
+
composerHint,
|
|
1658
|
+
composerPending,
|
|
1659
|
+
isRunning,
|
|
1660
|
+
steerable,
|
|
1661
|
+
stopping,
|
|
1662
|
+
canStop,
|
|
1663
|
+
stableStop,
|
|
1664
|
+
models,
|
|
1665
|
+
selectedModel,
|
|
1666
|
+
selectedReasoning,
|
|
1667
|
+
modelsQuery.isLoading,
|
|
1668
|
+
modelsQuery.isError,
|
|
1669
|
+
stableSelectModel,
|
|
1670
|
+
stableSelectReasoning,
|
|
1671
|
+
stableResetReasoning,
|
|
1672
|
+
usingDefaultModel,
|
|
1673
|
+
stableResetModelSelection,
|
|
1674
|
+
modelRouting,
|
|
1675
|
+
threadId,
|
|
1676
|
+
draftReseed,
|
|
1677
|
+
approvalMode,
|
|
1678
|
+
stableSetApprovalMode,
|
|
1679
|
+
awaitingApproval,
|
|
1680
|
+
dictationRecognizer,
|
|
1681
|
+
contextMeter,
|
|
1682
|
+
]
|
|
1683
|
+
)
|
|
1684
|
+
|
|
1685
|
+
const pendingProps: PendingMessagesProps = useMemo(
|
|
1686
|
+
() => ({ threadId, steerable, read: readMessageIds }),
|
|
1687
|
+
[threadId, steerable, readMessageIds]
|
|
1688
|
+
)
|
|
1689
|
+
|
|
1690
|
+
// The header's move to the cloud, from the notice: one move, one state, wherever it's asked.
|
|
1691
|
+
const computerNoticeProps: ComputerOfflineNoticeProps | null =
|
|
1692
|
+
computerOffline && place
|
|
1693
|
+
? {
|
|
1694
|
+
computer: thread?.computer ?? null,
|
|
1695
|
+
waiting: messageWaiting,
|
|
1696
|
+
pending: place.movingTo === "cloud",
|
|
1697
|
+
moving: place.pending,
|
|
1698
|
+
busy: place.busy,
|
|
1699
|
+
error: place.cloudError,
|
|
1700
|
+
onContinueInCloud: place.moveToCloud,
|
|
1701
|
+
...(desktopComputer && thread?.computer && thread.computer.id === desktopComputerId
|
|
1702
|
+
? {
|
|
1703
|
+
onRunHere: () =>
|
|
1704
|
+
void desktopComputer.allowFolder(thread.computer?.folder ?? "").catch(() => {}),
|
|
1705
|
+
}
|
|
1706
|
+
: {}),
|
|
1707
|
+
}
|
|
1708
|
+
: null
|
|
1200
1709
|
|
|
1201
1710
|
const sandboxRecoveryProps: SandboxRecoveryProps | null = sandboxRecovery
|
|
1202
1711
|
? {
|
|
1203
|
-
pending: recreateSandbox.isPending,
|
|
1712
|
+
pending: recreateSandbox.isPending || restoreSandbox.isPending,
|
|
1204
1713
|
error: recreateSandbox.isError,
|
|
1205
|
-
onRecreate:
|
|
1714
|
+
onRecreate: () => recoverSandbox(recreateSandbox),
|
|
1715
|
+
// Only a workspace its run finished preparing has files to go on from.
|
|
1716
|
+
...(sandboxRecovery.status !== "unavailable" && sandboxRecovery.initialized
|
|
1717
|
+
? {
|
|
1718
|
+
restore: {
|
|
1719
|
+
pending: restoreSandbox.isPending,
|
|
1720
|
+
error: restoreSandbox.isError,
|
|
1721
|
+
onRestore: () => recoverSandbox(restoreSandbox),
|
|
1722
|
+
},
|
|
1723
|
+
}
|
|
1724
|
+
: {}),
|
|
1206
1725
|
canRecreate: access === "owner",
|
|
1207
1726
|
owner: thread ? personName(threadOwner(thread)) : "",
|
|
1208
1727
|
}
|
|
@@ -1252,6 +1771,14 @@ export function useAgentConversation({
|
|
|
1252
1771
|
draftReseed,
|
|
1253
1772
|
composerPending,
|
|
1254
1773
|
send,
|
|
1774
|
+
/** Saved user message ids the reader may edit in place. */
|
|
1775
|
+
editableMessageIds,
|
|
1776
|
+
/** The message currently open in the inline editor, or null. */
|
|
1777
|
+
editingMessage,
|
|
1778
|
+
startEditMessage,
|
|
1779
|
+
cancelEditMessage,
|
|
1780
|
+
/** Edit an earlier user message in place and restart the thread from there. */
|
|
1781
|
+
editMessage,
|
|
1255
1782
|
/** Stop the answer in flight, when `turn.canStop`. */
|
|
1256
1783
|
stop,
|
|
1257
1784
|
/** Run again the turn that never answered, when `turn.canRetry`. */
|
|
@@ -1281,8 +1808,12 @@ export function useAgentConversation({
|
|
|
1281
1808
|
* until the reader answers it or sets it aside.
|
|
1282
1809
|
*/
|
|
1283
1810
|
questionProps,
|
|
1811
|
+
/** Spread into `<PendingMessages>`, above the composer: what waits beside the running turn. */
|
|
1812
|
+
pendingProps,
|
|
1284
1813
|
/** Spread into `<SandboxRecovery>` while set: the composer stays disabled until it is resolved. */
|
|
1285
1814
|
sandboxRecoveryProps,
|
|
1815
|
+
/** Where the reader's own conversation runs, and how to switch it between cloud and computer. */
|
|
1816
|
+
place,
|
|
1286
1817
|
/** Where the reader's own conversation runs on their computer, for its badge. */
|
|
1287
1818
|
computer: access === "owner" ? (thread?.computer ?? null) : null,
|
|
1288
1819
|
/** Spread into `<ComputerOfflineNotice>` while its computer is offline. */
|
|
@@ -1322,6 +1853,53 @@ function sendFailure(error: unknown): TurnFailure {
|
|
|
1322
1853
|
return "send"
|
|
1323
1854
|
}
|
|
1324
1855
|
|
|
1856
|
+
function editFailure(error: unknown): TurnFailure {
|
|
1857
|
+
if (error instanceof ComputerUnavailableError) return "computer"
|
|
1858
|
+
if (!isSixbApiError(error)) return "edit"
|
|
1859
|
+
// Someone else's answer runs, which only they or the thread's owner may stop.
|
|
1860
|
+
if (error.status === 403 && error.code === "not_run_requester") return "busy"
|
|
1861
|
+
if (error.status !== 409) return "edit"
|
|
1862
|
+
if (error.code === "active_run_exists") return "busy"
|
|
1863
|
+
if (error.code === "sandbox_execution_unavailable") return "sandbox"
|
|
1864
|
+
|
|
1865
|
+
return "edit"
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
/** Why an edit did not go through, in words about the edit, said under the editor. */
|
|
1869
|
+
function editFailureMessage(
|
|
1870
|
+
failure: TurnFailure,
|
|
1871
|
+
someoneElse: boolean,
|
|
1872
|
+
labels: ReturnType<typeof useAgentMessages>["chat"]
|
|
1873
|
+
): string {
|
|
1874
|
+
switch (failure) {
|
|
1875
|
+
case "busy":
|
|
1876
|
+
return someoneElse ? labels.editBusyOther : labels.editBusy
|
|
1877
|
+
case "sandbox":
|
|
1878
|
+
return labels.sandboxUnavailable
|
|
1879
|
+
case "computer":
|
|
1880
|
+
return labels.computerUnavailable
|
|
1881
|
+
default:
|
|
1882
|
+
return labels.editFailed
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
/** The edit a waiting inbox item holds, as the transcript shows one just saved. */
|
|
1887
|
+
function waitingEditPending(threadId: string, item: AgentInboxItem): PendingUserMessage {
|
|
1888
|
+
return {
|
|
1889
|
+
key: `edit:${item.id}`,
|
|
1890
|
+
threadId,
|
|
1891
|
+
text: item.parts.map((part) => (part.type === "text" ? part.text : "")).join(""),
|
|
1892
|
+
attachments: item.parts.flatMap((part) => (part.type === "file" ? [part.fileRef] : [])),
|
|
1893
|
+
context: item.parts.flatMap((part) =>
|
|
1894
|
+
part.type === "context"
|
|
1895
|
+
? [{ context: part.context as AgentContextInput, origin: part.origin }]
|
|
1896
|
+
: []
|
|
1897
|
+
),
|
|
1898
|
+
messageId: item.messageId,
|
|
1899
|
+
...(item.replacesMessageId === undefined ? {} : { replacesMessageId: item.replacesMessageId }),
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1325
1903
|
/**
|
|
1326
1904
|
* Said once the thread is read again, so a busy thread names whose answer holds it when the reader
|
|
1327
1905
|
* can tell.
|
|
@@ -1338,6 +1916,8 @@ function failureMessage(
|
|
|
1338
1916
|
return labels.sandboxUnavailable
|
|
1339
1917
|
case "computer":
|
|
1340
1918
|
return labels.computerUnavailable
|
|
1919
|
+
case "edit":
|
|
1920
|
+
return labels.editFailed
|
|
1341
1921
|
case "retry":
|
|
1342
1922
|
return labels.retryFailed
|
|
1343
1923
|
case "stop":
|
|
@@ -1472,3 +2052,13 @@ function useExtendedWaitingStatus(run: Pick<AgentRun, "status" | "createdAt"> |
|
|
|
1472
2052
|
|
|
1473
2053
|
return visible
|
|
1474
2054
|
}
|
|
2055
|
+
|
|
2056
|
+
function sameTurn(a: AgentConversationTurn, b: AgentConversationTurn): boolean {
|
|
2057
|
+
const keysA = Object.keys(a)
|
|
2058
|
+
const keysB = Object.keys(b)
|
|
2059
|
+
if (keysA.length !== keysB.length) return false
|
|
2060
|
+
for (const key of keysA) {
|
|
2061
|
+
if (!Object.is(Reflect.get(a, key), Reflect.get(b, key))) return false
|
|
2062
|
+
}
|
|
2063
|
+
return true
|
|
2064
|
+
}
|