Skip to content

Commit 70ce1d5

Browse files
fix(mobile): keep follow-up dispatch helper in lib
The mobile dependency graph forbids state importing from features, so the helper that resolves the outbox dispatch mode moves next to the follow-up behavior preference it reads. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 7d379fd commit 70ce1d5

5 files changed

Lines changed: 61 additions & 60 deletions

File tree

‎apps/mobile/src/features/threads/composerSendPresentation.test.ts‎

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { describe, expect, it } from "vite-plus/test";
22

3-
import {
4-
resolveComposerSendPresentation,
5-
resolveFollowUpDispatchMode,
6-
} from "./composerSendPresentation";
3+
import { resolveComposerSendPresentation } from "./composerSendPresentation";
74

85
const idle = {
96
editingQueuedMessage: false,
@@ -82,30 +79,3 @@ describe("resolveComposerSendPresentation", () => {
8279
expect(presentation.offersFollowUpChoice).toBe(false);
8380
});
8481
});
85-
86-
describe("resolveFollowUpDispatchMode", () => {
87-
const running = {
88-
running: true,
89-
canSteer: true,
90-
isCompacting: false,
91-
followUpBehavior: "steer",
92-
} as const;
93-
94-
it("lets the server decide while the thread is idle", () => {
95-
expect(resolveFollowUpDispatchMode({ ...running, running: false })).toBeNull();
96-
});
97-
98-
it("sends steering as auto and queueing as queue", () => {
99-
expect(resolveFollowUpDispatchMode(running)).toBe("auto");
100-
expect(resolveFollowUpDispatchMode({ ...running, followUpBehavior: "queue" })).toBe("queue");
101-
expect(resolveFollowUpDispatchMode({ ...running, followUpOverride: "queue" })).toBe("queue");
102-
});
103-
104-
it("queues explicitly while compacting, matching the Queue label", () => {
105-
// While /compact is still being dispatched the active run is the ordinary
106-
// one, which an auto send would steer.
107-
expect(resolveFollowUpDispatchMode({ ...running, canSteer: false, isCompacting: true })).toBe(
108-
"queue",
109-
);
110-
});
111-
});

‎apps/mobile/src/features/threads/composerSendPresentation.ts‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
alternateComposerDispatchAction,
3-
resolveComposerDispatchMode,
43
type ActiveTurnComposerAction,
54
} from "@t3tools/client-runtime/state/composer-dispatch";
65

@@ -66,28 +65,3 @@ export function resolveComposerSendPresentation(input: {
6665
offersFollowUpChoice: input.canSteer,
6766
};
6867
}
69-
70-
/**
71-
* The outbox dispatch mode for a send, or null when the thread is idle and the
72-
* server decides. Steering travels as "auto" so a turn that ends before the
73-
* outbox delivers degrades to a queued run instead of failing the delivery and
74-
* bouncing the message back into the draft.
75-
*/
76-
export function resolveFollowUpDispatchMode(input: {
77-
readonly running: boolean;
78-
readonly canSteer: boolean;
79-
readonly isCompacting: boolean;
80-
readonly followUpBehavior: FollowUpBehavior;
81-
readonly followUpOverride?: ActiveTurnComposerAction;
82-
}): "queue" | "auto" | null {
83-
const action = resolveComposerDispatchMode({
84-
// Compaction queues explicitly: while /compact is still being dispatched
85-
// the active run is the ordinary one, which an auto send would steer.
86-
running: input.running && (input.canSteer || input.isCompacting),
87-
alternateModifier:
88-
input.followUpOverride !== undefined && input.followUpOverride !== input.followUpBehavior,
89-
activeTurnDefault: input.followUpBehavior,
90-
activeTurnIsCompaction: input.isCompacting,
91-
});
92-
return action === "auto" ? null : action === "queue" ? "queue" : "auto";
93-
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
3+
import { resolveFollowUpDispatchMode } from "./followUpBehavior";
4+
5+
describe("resolveFollowUpDispatchMode", () => {
6+
const running = {
7+
running: true,
8+
canSteer: true,
9+
isCompacting: false,
10+
followUpBehavior: "steer",
11+
} as const;
12+
13+
it("lets the server decide while the thread is idle", () => {
14+
expect(resolveFollowUpDispatchMode({ ...running, running: false })).toBeNull();
15+
});
16+
17+
it("sends steering as auto and queueing as queue", () => {
18+
expect(resolveFollowUpDispatchMode(running)).toBe("auto");
19+
expect(resolveFollowUpDispatchMode({ ...running, followUpBehavior: "queue" })).toBe("queue");
20+
expect(resolveFollowUpDispatchMode({ ...running, followUpOverride: "queue" })).toBe("queue");
21+
});
22+
23+
it("queues explicitly while compacting, matching the Queue label", () => {
24+
// While /compact is still being dispatched the active run is the ordinary
25+
// one, which an auto send would steer.
26+
expect(resolveFollowUpDispatchMode({ ...running, canSteer: false, isCompacting: true })).toBe(
27+
"queue",
28+
);
29+
});
30+
});

‎apps/mobile/src/lib/followUpBehavior.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { ActiveTurnComposerAction } from "@t3tools/client-runtime/state/composer-dispatch";
1+
import {
2+
resolveComposerDispatchMode,
3+
type ActiveTurnComposerAction,
4+
} from "@t3tools/client-runtime/state/composer-dispatch";
25

36
/**
47
* What the send button does while a turn is already running: `queue` waits for
@@ -11,3 +14,28 @@ import type { ActiveTurnComposerAction } from "@t3tools/client-runtime/state/com
1114
export type FollowUpBehavior = Extract<ActiveTurnComposerAction, "queue" | "steer">;
1215

1316
export const DEFAULT_FOLLOW_UP_BEHAVIOR: FollowUpBehavior = "queue";
17+
18+
/**
19+
* The outbox dispatch mode for a send, or null when the thread is idle and the
20+
* server decides. Steering travels as "auto" so a turn that ends before the
21+
* outbox delivers degrades to a queued run instead of failing the delivery and
22+
* bouncing the message back into the draft.
23+
*/
24+
export function resolveFollowUpDispatchMode(input: {
25+
readonly running: boolean;
26+
readonly canSteer: boolean;
27+
readonly isCompacting: boolean;
28+
readonly followUpBehavior: FollowUpBehavior;
29+
readonly followUpOverride?: ActiveTurnComposerAction;
30+
}): "queue" | "auto" | null {
31+
const action = resolveComposerDispatchMode({
32+
// Compaction queues explicitly: while /compact is still being dispatched
33+
// the active run is the ordinary one, which an auto send would steer.
34+
running: input.running && (input.canSteer || input.isCompacting),
35+
alternateModifier:
36+
input.followUpOverride !== undefined && input.followUpOverride !== input.followUpBehavior,
37+
activeTurnDefault: input.followUpBehavior,
38+
activeTurnIsCompaction: input.isCompacting,
39+
});
40+
return action === "auto" ? null : action === "queue" ? "queue" : "auto";
41+
}

‎apps/mobile/src/state/use-thread-composer-state.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import { scopedThreadKey } from "../lib/scopedEntities";
5252
import { buildThreadFeed } from "../lib/threadActivity";
5353
import { acknowledgedThreadMessagesAtom } from "./acknowledged-thread-messages";
5454
import { appendPendingThreadMessages } from "../features/threads/pending-thread-feed";
55-
import { resolveFollowUpDispatchMode } from "../features/threads/composerSendPresentation";
5655
import { threadAllowsProviderSwitch } from "./thread-provider-switching";
5756
import { appAtomRegistry } from "../state/atom-registry";
5857
import { pendingThreadCreationMessage } from "./pending-thread-creation";
@@ -82,7 +81,7 @@ import { type ActiveTurnComposerAction } from "@t3tools/client-runtime/state/com
8281
import { Atom } from "effect/unstable/reactivity";
8382
import { AsyncResult } from "effect/unstable/reactivity";
8483
import { prepareTurnAttachments } from "../lib/attachmentUpload";
85-
import { DEFAULT_FOLLOW_UP_BEHAVIOR } from "../lib/followUpBehavior";
84+
import { DEFAULT_FOLLOW_UP_BEHAVIOR, resolveFollowUpDispatchMode } from "../lib/followUpBehavior";
8685
import { mobilePreferencesAtom } from "./preferences";
8786
import { environmentThreadDetails } from "./threads";
8887
import {

0 commit comments

Comments
 (0)