@@ -3,12 +3,21 @@ import type {
33 CloudTaskQueuedMessage ,
44 CloudTaskQueueMoveDirection ,
55} from "@posthog/core/sessions/cloudTaskQueue" ;
6+ import { DEFAULT_CLAUDE_EXECUTION_MODE } from "@posthog/core/sessions/executionModes" ;
67import {
78 countUserMessages ,
89 getSessionActivityPhase ,
910} from "@posthog/core/sessions/sessionActivity" ;
1011import { isTaskRunning } from "@posthog/core/tasks/taskArchive" ;
11- import type { Task } from "@posthog/shared" ;
12+ import {
13+ DEFAULT_GATEWAY_MODEL ,
14+ DEFAULT_REASONING_EFFORT ,
15+ type ExecutionMode ,
16+ getReasoningEffortOptions ,
17+ type SupportedReasoningEffort ,
18+ serializeCloudPrompt ,
19+ type Task ,
20+ } from "@posthog/shared" ;
1221import { useQueryClient } from "@tanstack/react-query" ;
1322import * as Haptics from "expo-haptics" ;
1423import { useLocalSearchParams , useRouter } from "expo-router" ;
@@ -24,24 +33,14 @@ import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller
2433import Animated , { useAnimatedStyle } from "react-native-reanimated" ;
2534import { FloatingBackButton } from "@/components/FloatingBackButton" ;
2635import { usePreferencesStore } from "@/features/preferences/stores/preferencesStore" ;
27- import { runTaskInCloud } from "@/features/tasks/api" ;
2836import { CustomImageBadge } from "@/features/tasks/components/CustomImageBadge" ;
2937import { FloatingTaskHeader } from "@/features/tasks/components/FloatingTaskHeader" ;
3038import { PrDiffStatsBadge } from "@/features/tasks/components/PrDiffStatsBadge" ;
3139import { PrStatusBadge } from "@/features/tasks/components/PrStatusBadge" ;
3240import { StopRunButton } from "@/features/tasks/components/StopRunButton" ;
3341import { TaskSessionView } from "@/features/tasks/components/TaskSessionView" ;
3442import { buildCloudPromptBlocks } from "@/features/tasks/composer/attachments/buildCloudPrompt" ;
35- import { serializeCloudPrompt } from "@/features/tasks/composer/attachments/cloudPrompt" ;
3643import type { PendingAttachment } from "@/features/tasks/composer/attachments/types" ;
37- import {
38- DEFAULT_EXECUTION_MODE ,
39- DEFAULT_MODEL ,
40- DEFAULT_REASONING ,
41- type ExecutionMode ,
42- modelSupportsReasoning ,
43- type ReasoningEffort ,
44- } from "@/features/tasks/composer/options" ;
4544import { QueuedMessagesDock } from "@/features/tasks/composer/QueuedMessagesDock" ;
4645import { TaskChatComposer } from "@/features/tasks/composer/TaskChatComposer" ;
4746import {
@@ -134,7 +133,13 @@ export default function TaskDetailScreen() {
134133 // Cleared when the screen unmounts. Matches the desktop super-property.
135134 useActiveTaskAnalyticsContext ( task ?. signal_report ?? null ) ;
136135
137- const session = taskId ? getTaskSession ( taskId ) : undefined ;
136+ const session = useTaskSessionStore ( ( state ) =>
137+ taskId
138+ ? Object . values ( state . sessions ) . find (
139+ ( candidate ) => candidate . taskId === taskId ,
140+ )
141+ : undefined ,
142+ ) ;
138143
139144 // Optimistic echo set by the new-task screen (or the terminal-resume path
140145 // below) so the user's prompt appears in the thread immediately, before
@@ -176,14 +181,14 @@ export default function TaskDetailScreen() {
176181 string | undefined
177182 > ( ) ;
178183 const composerMode : ExecutionMode =
179- composerConfig ?. mode ?? DEFAULT_EXECUTION_MODE ;
180- const composerModel = composerConfig ?. model ?? DEFAULT_MODEL ;
181- const composerReasoning : ReasoningEffort =
182- composerConfig ?. reasoning ?? DEFAULT_REASONING ;
184+ composerConfig ?. mode ?? DEFAULT_CLAUDE_EXECUTION_MODE ;
185+ const composerModel = composerConfig ?. model ?? DEFAULT_GATEWAY_MODEL ;
186+ const composerReasoning : SupportedReasoningEffort =
187+ composerConfig ?. reasoning ?? DEFAULT_REASONING_EFFORT ;
183188
184189 const messagingMode = useMessagingMode ( taskId ) ;
185190 const queuedCount = useQueuedCount ( taskId ) ;
186- const { editingId : editingQueuedId } = useTaskMessageQueue ( taskId ) ;
191+ const editingQueuedId = useTaskMessageQueue ( taskId ?? "" ) . editingId ;
187192 const toggleMessagingMode = useToggleMessagingMode ( taskId ) ;
188193 const analytics = useAnalytics ( ) ;
189194
@@ -317,16 +322,21 @@ export default function TaskDetailScreen() {
317322 )
318323 : text ;
319324
320- const supportsReasoning = modelSupportsReasoning ( composerModel ) ;
321- const updatedTask = await runTaskInCloud ( taskId , {
322- resumeFromRunId : task . latest_run ?. id ,
323- pendingUserMessage,
324- runtimeAdapter : "claude" ,
325- model : composerModel ,
326- reasoningEffort : supportsReasoning ? composerReasoning : undefined ,
327- initialPermissionMode : composerMode ,
328- rtkEnabled : usePreferencesStore . getState ( ) . rtkEnabledCloud ,
329- } ) ;
325+ const supportsReasoning =
326+ getReasoningEffortOptions ( "claude" , composerModel ) !== null ;
327+ const updatedTask = await getPostHogApiClient ( ) . runTaskInCloud (
328+ taskId ,
329+ undefined ,
330+ {
331+ resumeFromRunId : task . latest_run ?. id ,
332+ pendingUserMessage,
333+ adapter : "claude" ,
334+ model : composerModel ,
335+ reasoningLevel : supportsReasoning ? composerReasoning : undefined ,
336+ initialPermissionMode : composerMode ,
337+ rtkEnabled : usePreferencesStore . getState ( ) . rtkEnabledCloud ,
338+ } ,
339+ ) ;
330340 setTask ( updatedTask ) ;
331341 await connectToTask ( updatedTask ) ;
332342 updateTaskInCache ( updatedTask ) ;
@@ -513,7 +523,7 @@ export default function TaskDetailScreen() {
513523 ) ;
514524
515525 const handleReasoningChange = useCallback (
516- ( value : ReasoningEffort ) => {
526+ ( value : SupportedReasoningEffort ) => {
517527 if ( ! taskId ) return ;
518528 setComposerConfig ( taskId , { reasoning : value } ) ;
519529 setConfigOption ( taskId , "effort" , value ) . catch ( ( ) => { } ) ;
@@ -566,10 +576,14 @@ export default function TaskDetailScreen() {
566576 setRetrying ( true ) ;
567577 disconnectFromTask ( taskId ) ;
568578
569- const updatedTask = await runTaskInCloud ( taskId , {
570- resumeFromRunId : task . latest_run ?. id ,
571- rtkEnabled : usePreferencesStore . getState ( ) . rtkEnabledCloud ,
572- } ) ;
579+ const updatedTask = await getPostHogApiClient ( ) . runTaskInCloud (
580+ taskId ,
581+ undefined ,
582+ {
583+ resumeFromRunId : task . latest_run ?. id ,
584+ rtkEnabled : usePreferencesStore . getState ( ) . rtkEnabledCloud ,
585+ } ,
586+ ) ;
573587 setTask ( updatedTask ) ;
574588 await connectToTask ( updatedTask ) ;
575589 updateTaskInCache ( updatedTask ) ;
0 commit comments