Skip to content

Commit 431749d

Browse files
refactor(mobile): keep composer controls local
Generated-By: PostHog Code Task-Id: c1bbe3cf-742b-4b24-bf96-d11a18b4cf22
1 parent 65fe2d0 commit 431749d

8 files changed

Lines changed: 92 additions & 57 deletions

File tree

apps/mobile/src/app/task/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import {
33
DEFAULT_CLAUDE_EXECUTION_MODE,
44
getAvailableModes,
55
} from "@posthog/core/sessions/executionModes";
6-
import {
7-
getComposerModelOptions,
8-
getConfigOptionLabel,
9-
getModelConfigOption,
10-
resolveComposerModelChange,
11-
} from "@posthog/core/task-detail/composerControls";
126
import {
137
DEFAULT_GATEWAY_MODEL,
148
DEFAULT_REASONING_EFFORT,
@@ -61,6 +55,12 @@ import {
6155
} from "@/features/tasks/composer/attachments/pickers";
6256
import type { PendingAttachment } from "@/features/tasks/composer/attachments/types";
6357
import { DotBackground } from "@/features/tasks/composer/DotBackground";
58+
import {
59+
getComposerModelOptions,
60+
getConfigOptionLabel,
61+
getModelConfigOption,
62+
resolveComposerModelChange,
63+
} from "@/features/tasks/composer/options";
6464
import { Pill } from "@/features/tasks/composer/Pill";
6565
import { RepositoryPickerInline } from "@/features/tasks/composer/RepositoryPickerInline";
6666
import { SelectSheet } from "@/features/tasks/composer/SelectSheet";

apps/mobile/src/features/inbox/components/TinderView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
formatSignalReportSummaryMarkdown,
44
inboxStatusLabel,
55
} from "@posthog/core/inbox/reportPresentation";
6-
import { getModelConfigOption } from "@posthog/core/task-detail/composerControls";
76
import type {
87
SignalReport,
98
SignalReportPriority,
@@ -27,6 +26,7 @@ import {
2726
} from "react-native-safe-area-context";
2827
import { MarkdownText } from "@/features/chat/components/MarkdownText";
2928
import { usePreferencesStore } from "@/features/preferences/stores/preferencesStore";
29+
import { getModelConfigOption } from "@/features/tasks/composer/options";
3030
import { useCloudTaskConfigOptions } from "@/features/tasks/hooks/useCloudTaskConfigOptions";
3131
import type {
3232
CreateTaskOptions,

apps/mobile/src/features/tasks/composer/TaskChatComposer.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ import {
33
DEFAULT_CLAUDE_EXECUTION_MODE,
44
getAvailableModes,
55
} from "@posthog/core/sessions/executionModes";
6-
import {
7-
getComposerModelOptions,
8-
getConfigOptionLabel,
9-
getModelConfigOption,
10-
resolveComposerModelChange,
11-
resolveComposerPrimaryAction,
12-
} from "@posthog/core/task-detail/composerControls";
136
import {
147
DEFAULT_GATEWAY_MODEL,
158
DEFAULT_REASONING_EFFORT,
@@ -62,6 +55,13 @@ import {
6255
pickPhotoFromLibrary,
6356
} from "./attachments/pickers";
6457
import type { PendingAttachment } from "./attachments/types";
58+
import {
59+
getComposerModelOptions,
60+
getConfigOptionLabel,
61+
getModelConfigOption,
62+
resolveComposerModelChange,
63+
resolveComposerPrimaryAction,
64+
} from "./options";
6565
import { Pill } from "./Pill";
6666
import { SelectSheet } from "./SelectSheet";
6767

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import {
2+
type CloudTaskConfigOption,
3+
DEFAULT_GATEWAY_MODEL,
4+
restrictedModelMeta,
5+
} from "@posthog/shared";
6+
import { describe, expect, it } from "vitest";
7+
import {
8+
getComposerModelOptions,
9+
resolveComposerPrimaryAction,
10+
} from "./options";
11+
12+
const modelOption: CloudTaskConfigOption = {
13+
id: "model",
14+
name: "Model",
15+
type: "select",
16+
currentValue: DEFAULT_GATEWAY_MODEL,
17+
options: [
18+
{ value: DEFAULT_GATEWAY_MODEL, name: "Claude Opus 4.8" },
19+
{
20+
value: "claude-fable-5",
21+
name: "Claude Fable 5",
22+
_meta: restrictedModelMeta(),
23+
},
24+
],
25+
category: "model",
26+
description: "Choose a model",
27+
};
28+
29+
describe("mobile composer options", () => {
30+
it("adapts live model options for the mobile picker", () => {
31+
expect(getComposerModelOptions(modelOption)).toEqual([
32+
{
33+
value: DEFAULT_GATEWAY_MODEL,
34+
label: "Claude Opus 4.8",
35+
description: undefined,
36+
disabled: false,
37+
},
38+
{
39+
value: "claude-fable-5",
40+
label: "Claude Fable 5",
41+
description: undefined,
42+
disabled: true,
43+
},
44+
]);
45+
});
46+
47+
it.each([
48+
[{ hasContent: true }, "send"],
49+
[{ canStop: true }, "stop"],
50+
[{ isRecording: true }, "mic-stop"],
51+
[{}, "mic"],
52+
])("derives the mobile primary action", (overrides, expected) => {
53+
expect(
54+
resolveComposerPrimaryAction({
55+
hasContent: false,
56+
disabled: false,
57+
isRecording: false,
58+
isTranscribing: false,
59+
canStop: false,
60+
allowSendWhileRunning: true,
61+
...overrides,
62+
}),
63+
).toBe(expected);
64+
});
65+
});

packages/core/src/task-detail/composerControls.ts renamed to apps/mobile/src/features/tasks/composer/options.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
type SupportedReasoningEffort,
88
} from "@posthog/shared";
99

10-
export interface ComposerModelOption {
10+
export interface MobileModelOption {
1111
value: string;
1212
label: string;
1313
description?: string;
@@ -24,7 +24,7 @@ export function getModelConfigOption(
2424

2525
export function getComposerModelOptions(
2626
modelOption: CloudTaskConfigOption,
27-
): ComposerModelOption[] {
27+
): MobileModelOption[] {
2828
return modelOption.options.map((option) => ({
2929
value: option.value,
3030
label: option.name,
@@ -40,16 +40,6 @@ export function getConfigOptionLabel(
4040
return options.find((option) => option.value === value)?.name ?? value;
4141
}
4242

43-
export function resolveAvailableModel(
44-
modelOption: CloudTaskConfigOption,
45-
value: string,
46-
): string {
47-
const selected = modelOption.options.find((option) => option.value === value);
48-
return selected && !isRestrictedModelOption(selected._meta)
49-
? value
50-
: modelOption.currentValue;
51-
}
52-
5343
export function resolveComposerModelChange({
5444
adapter,
5545
modelOption,
@@ -61,7 +51,13 @@ export function resolveComposerModelChange({
6151
requestedModel: string;
6252
reasoning: SupportedReasoningEffort;
6353
}): { model: string; reasoning: SupportedReasoningEffort } {
64-
const model = resolveAvailableModel(modelOption, requestedModel);
54+
const selected = modelOption.options.find(
55+
(option) => option.value === requestedModel,
56+
);
57+
const model =
58+
selected && !isRestrictedModelOption(selected._meta)
59+
? requestedModel
60+
: modelOption.currentValue;
6561
return {
6662
model,
6763
reasoning: isSupportedReasoningEffort(adapter, model, reasoning)

apps/mobile/src/features/tasks/hooks/useCloudTaskConfigOptions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ vi.mock("@/lib/posthogApiClient", () => ({
2626
}),
2727
}));
2828

29-
import { getModelConfigOption } from "@posthog/core/task-detail/composerControls";
29+
import { getModelConfigOption } from "../composer/options";
3030
import { useCloudTaskConfigOptions } from "./useCloudTaskConfigOptions";
3131

3232
function createWrapper(queryClient: QueryClient) {

packages/core/src/task-detail/composerControls.test.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/ui/src/features/sessions/components/UnifiedModelSelector.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
Robot,
1010
Spinner,
1111
} from "@phosphor-icons/react";
12-
import { getConfigOptionLabel } from "@posthog/core/task-detail/composerControls";
1312
import {
1413
Button,
1514
DropdownMenu,
@@ -79,7 +78,9 @@ export function UnifiedModelSelector({
7978
}, [selectOption]);
8079

8180
const currentValue = selectOption?.currentValue;
82-
const currentLabel = getConfigOptionLabel(options, currentValue);
81+
const currentLabel =
82+
options.find((option) => option.value === currentValue)?.name ??
83+
currentValue;
8384

8485
const otherAdapter = getOtherAdapter(adapter);
8586

0 commit comments

Comments
 (0)