The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | alternateComposerDispatchAction, |
| 3 | type ActiveTurnComposerAction, |
| 4 | } from "@t3tools/client-runtime/state/composer-dispatch"; |
| 5 | import { msg } from "gt-react-native"; |
| 6 | |
| 7 | import { m, type MessageResolver } from "../../i18n/messages"; |
| 8 | |
| 9 | import type { FollowUpBehavior } from "../../lib/followUpBehavior"; |
| 10 | |
| 11 | export interface ComposerSendPresentation { |
| 12 | readonly label: string; |
| 13 | readonly icon: |
| 14 | | "arrow.up" |
| 15 | | "tray.and.arrow.up" |
| 16 | | "checkmark" |
| 17 | | "list.number" |
| 18 | | "arrow.turn.left.up"; |
| 19 | readonly action: ActiveTurnComposerAction | null; |
| 20 | readonly alternate: ActiveTurnComposerAction | null; |
| 21 | readonly offersFollowUpChoice: boolean; |
| 22 | } |
| 23 | |
| 24 | const ACTION_LABEL: Record<ActiveTurnComposerAction, string> = { |
| 25 | queue: msg("Queue", { $context: "verb, sends the message after the current turn" }), |
| 26 | steer: msg("Steer", { $context: "verb, sends the message into the running turn" }), |
| 27 | restart: msg("Restart", { $context: "verb, restarts the turn with the message" }), |
| 28 | }; |
| 29 | |
| 30 | export function resolveComposerSendPresentation( |
| 31 | input: { |
| 32 | readonly editingQueuedMessage: boolean; |
| 33 | readonly running: boolean; |
| 34 | readonly canSteer: boolean; |
| 35 | readonly followUpBehavior: FollowUpBehavior; |
| 36 | readonly deliveryDeferred: boolean; |
| 37 | }, |
| 38 | resolve: MessageResolver = m, |
| 39 | ): ComposerSendPresentation { |
| 40 | if (input.editingQueuedMessage) { |
| 41 | return { |
| 42 | label: resolve(msg("Update queued message")), |
| 43 | icon: "checkmark", |
| 44 | action: null, |
| 45 | alternate: null, |
| 46 | offersFollowUpChoice: false, |
| 47 | }; |
| 48 | } |
| 49 | if (!input.running) { |
| 50 | return { |
| 51 | label: input.deliveryDeferred |
| 52 | ? resolve(ACTION_LABEL.queue) |
| 53 | : resolve(msg("Send", { $context: "verb, sends the message" })), |
| 54 | icon: input.deliveryDeferred ? "tray.and.arrow.up" : "arrow.up", |
| 55 | action: null, |
| 56 | alternate: null, |
| 57 | offersFollowUpChoice: false, |
| 58 | }; |
| 59 | } |
| 60 | const action: ActiveTurnComposerAction = input.canSteer ? input.followUpBehavior : "queue"; |
| 61 | const alternate = alternateComposerDispatchAction(action); |
| 62 | return { |
| 63 | label: resolve(ACTION_LABEL[action]), |
| 64 | icon: action === "steer" ? "arrow.turn.left.up" : "list.number", |
| 65 | action, |
| 66 | alternate: input.canSteer ? alternate : null, |
| 67 | offersFollowUpChoice: input.canSteer, |
| 68 | }; |
| 69 | } |