Skip to content

Commit a052547

Browse files
chore(voice): integrate the language-aware model browser from main
2 parents 37ada6c + 32a0531 commit a052547

36 files changed

Lines changed: 1012 additions & 182 deletions

‎apps/desktop/src/preview/AnnotationStyles.generated.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎apps/desktop/src/preview/PickPreload.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ function startAnnotation(
633633
" h-7 w-7 shrink-0 rounded-full border-primary bg-primary p-0 text-primary-foreground hover:bg-primary/90";
634634
const voiceSkip = createButton("Skip", "Skip transcript cleanup");
635635
voiceSkip.className += " h-7 shrink-0 rounded-full px-2.5";
636+
// createButton's rounded-md sorts after rounded-full in the generated CSS, so it would win.
637+
for (const button of [voiceCancel, voiceFinish, voiceSkip]) button.classList.remove("rounded-md");
636638
const voiceStatus = document.createElement("div");
637639
voiceStatus.className = "flex h-7 min-w-0 flex-1 items-center gap-2";
638640
voiceStatus.setAttribute("role", "status");
@@ -744,16 +746,27 @@ function startAnnotation(
744746
}
745747
const recording = state.phase === "recording";
746748
const active = state.phase !== "idle" && state.phase !== "error";
749+
const wasActive = voicePill.parentElement === composerRow;
747750
voiceButton.hidden = !state.available || active;
748751
voiceButton.disabled = voiceBusy;
749752
const label = voiceSettings ? "Open voice settings" : "Start voice input";
750753
voiceButton.title =
751754
!voiceSettings && state.shortcutLabel ? `${label} (${state.shortcutLabel})` : label;
752755
voiceButton.setAttribute("aria-label", label);
753-
voiceRow.hidden = state.phase === "idle";
756+
// An active dictation takes the textarea's place; it takes focus once (sr-only) so Enter still attaches.
757+
voiceRow.hidden = state.phase === "idle" || active;
758+
comment.classList.toggle("sr-only", active);
759+
if (active && !wasActive) comment.focus({ preventScroll: true });
760+
submit.hidden = active;
761+
// Re-inserting on every level update would blur a focused Finish or Cancel.
762+
if (active && voicePill.parentElement !== composerRow) comment.after(voicePill);
763+
else if (!active && voicePill.parentElement !== voiceRow) voiceRow.appendChild(voicePill);
754764
voicePill.className = active
755-
? "flex h-9 w-64 min-w-0 items-center gap-2 rounded-full border border-border bg-background p-1"
765+
? "flex h-8 min-w-0 flex-1 items-center gap-2"
756766
: "flex min-w-0 items-center gap-1";
767+
// A draft that arrived while the textarea was sr-only was measured at 1px wide.
768+
if (wasActive && !active) resizeComment();
769+
else if (phaseChanged) queueEditorLayout();
757770
voiceCancel.title =
758771
state.phase === "error" ? "Dismiss voice input error" : "Cancel voice input";
759772
voiceCancel.setAttribute("aria-label", voiceCancel.title);

‎apps/mobile/src/features/pull-requests/PullRequestMarkdown.tsx‎

Lines changed: 90 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { splitPullRequestBody } from "@t3tools/client-runtime/pull-request-markdown";
1+
import {
2+
splitPullRequestBody,
3+
type PullRequestBodySegment,
4+
} from "@t3tools/client-runtime/pull-request-markdown";
25
import { markdownTaskMarkerOffset } from "@t3tools/shared/markdownTaskList";
36
import type { ReactNode } from "react";
47
import { View } from "react-native";
@@ -116,49 +119,101 @@ export function PullRequestMarkdown(props: {
116119
readonly checked: boolean;
117120
}) => boolean;
118121
}) {
119-
const { onTaskListChange } = props;
122+
const mediaContext = useContext(PullRequestMediaContext);
123+
const changeRequestUrl = useContext(ChangeRequestUrlContext);
120124
const segments = useMemo(() => splitPullRequestBody(props.markdown), [props.markdown]);
121125
const [undoneTicks, setUndoneTicks] = useState(0);
126+
const gallery: FilePreviewItem[] = markdownImageSources(
127+
props.imageGroupMarkdown ?? props.markdown,
128+
)
129+
.map((href) => (changeRequestUrl ? resolveChangeRequestMediaUrl(href, changeRequestUrl) : href))
130+
.filter(
131+
(uri) =>
132+
/^https?:\/\//i.test(uri) &&
133+
videoMimeType({ name: uri.split(/[?#]/)[0] ?? uri, mimeType: "" }) === null,
134+
)
135+
.map((uri) => pullRequestImageSource(uri, mediaContext));
136+
const segmentProps = {
137+
gallery,
138+
lineBreaks: props.lineBreaks,
139+
undoneTicks,
140+
onTaskListChange: props.onTaskListChange,
141+
onTaskListUndone: () => setUndoneTicks((count) => count + 1),
142+
};
143+
return (
144+
<View style={{ gap: 12 }}>
145+
{segments.map((segment) => (
146+
<PullRequestBodySegmentView key={segment.id} segment={segment} {...segmentProps} />
147+
))}
148+
</View>
149+
);
150+
}
151+
152+
function PullRequestBodySegmentView(props: {
153+
readonly segment: PullRequestBodySegment;
154+
readonly gallery: FilePreviewItem[];
155+
readonly lineBreaks: boolean | undefined;
156+
readonly undoneTicks: number;
157+
readonly onTaskListChange:
158+
| ((input: { readonly markerOffset: number; readonly checked: boolean }) => boolean)
159+
| undefined;
160+
readonly onTaskListUndone: () => void;
161+
}) {
162+
const { segment, onTaskListChange } = props;
163+
if (segment.kind === "markdown") {
164+
return (
165+
<PullRequestMarkdownContent
166+
key={props.undoneTicks}
167+
markdown={segment.text}
168+
gallery={props.gallery}
169+
lineBreaks={props.lineBreaks}
170+
onTaskListItemPress={
171+
onTaskListChange
172+
? (event) => {
173+
const offset = markdownTaskMarkerOffset(
174+
segment.text,
175+
event.index,
176+
event.text,
177+
event.checked,
178+
);
179+
const kept =
180+
offset !== null &&
181+
onTaskListChange({
182+
markerOffset: segment.sourceOffset + offset,
183+
checked: event.checked,
184+
});
185+
if (!kept) props.onTaskListUndone();
186+
}
187+
: undefined
188+
}
189+
/>
190+
);
191+
}
192+
if (segment.kind === "attachment") {
193+
return <PullRequestMedia url={segment.url} kind={segment.media} />;
194+
}
122195
return (
123196
<View style={{ gap: 12 }}>
124-
{segments.map((segment) =>
125-
segment.kind === "markdown" ? (
126-
<PullRequestMarkdownContent
127-
key={`${segment.id}:${undoneTicks}`}
128-
markdown={segment.text}
129-
imageGroupMarkdown={props.imageGroupMarkdown ?? props.markdown}
130-
lineBreaks={props.lineBreaks}
131-
onTaskListItemPress={
132-
onTaskListChange
133-
? (event) => {
134-
const offset = markdownTaskMarkerOffset(
135-
segment.text,
136-
event.index,
137-
event.text,
138-
event.checked,
139-
);
140-
const kept =
141-
offset !== null &&
142-
onTaskListChange({
143-
markerOffset: segment.sourceOffset + offset,
144-
checked: event.checked,
145-
});
146-
if (!kept) setUndoneTicks((count) => count + 1);
147-
}
148-
: undefined
149-
}
150-
/>
151-
) : (
152-
<PullRequestMedia key={segment.id} url={segment.url} kind={segment.media} />
153-
),
154-
)}
197+
{segment.rows.map((cells, rowIndex) => (
198+
// oxlint-disable-next-line react/no-array-index-key -- rows have no identity besides position
199+
<View key={rowIndex} style={{ flexDirection: "row", gap: 12 }}>
200+
{cells.map((cell, cellIndex) => (
201+
// oxlint-disable-next-line react/no-array-index-key -- cells have no identity besides position
202+
<View key={cellIndex} style={{ flex: 1, minWidth: 0, gap: 12 }}>
203+
{cell.segments.map((cellSegment) => (
204+
<PullRequestBodySegmentView key={cellSegment.id} {...props} segment={cellSegment} />
205+
))}
206+
</View>
207+
))}
208+
</View>
209+
))}
155210
</View>
156211
);
157212
}
158213

159214
function PullRequestMarkdownContent(props: {
160215
readonly markdown: string;
161-
readonly imageGroupMarkdown?: string;
216+
readonly gallery: FilePreviewItem[];
162217
readonly lineBreaks: boolean | undefined;
163218
readonly onTaskListItemPress?: SelectableMarkdownTextProps["onTaskListItemPress"];
164219
}) {
@@ -173,23 +228,13 @@ function PullRequestMarkdownContent(props: {
173228
const openLink = (href: string) => {
174229
void openPullRequest(href);
175230
};
176-
const gallery: FilePreviewItem[] = markdownImageSources(
177-
props.imageGroupMarkdown ?? props.markdown,
178-
)
179-
.map(resolveMediaUrl)
180-
.filter(
181-
(uri) =>
182-
/^https?:\/\//i.test(uri) &&
183-
videoMimeType({ name: uri.split(/[?#]/)[0] ?? uri, mimeType: "" }) === null,
184-
)
185-
.map((uri) => pullRequestImageSource(uri, mediaContext));
186231
const [preview, setPreview] = useState<FilePreviewSource | null>(null);
187232
const renderImage: MarkdownImageRenderer = (image) => (
188233
<MarkdownImage href={resolveMediaUrl(image.href)} alt={image.alt} onPreview={setPreview} />
189234
);
190235
const styles = useMarkdownPreviewStyles();
191236
return (
192-
<FilePreviewGallery value={gallery}>
237+
<FilePreviewGallery value={props.gallery}>
193238
<SelectableMarkdownText
194239
markdown={markdown}
195240
preserveSoftBreaks={props.lineBreaks ?? hostLineBreaks}

‎apps/mobile/src/features/pull-requests/pullRequestDescriptionContent.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ describe("PR attachments", () => {
2626
},
2727
]);
2828
});
29+
30+
it("collects videos from a before/after table", () => {
31+
const media = splitPullRequestBody(
32+
"<table>\n<tr><th>Before</th><th>After</th></tr>\n<tr><td>\n\nhttps://drop.example.com/before.mp4\n\n</td><td>\n\nhttps://drop.example.com/after.mp4\n\n</td></tr>\n</table>",
33+
);
34+
expect(
35+
pullRequestDescriptionContent({ type: "root" } as MarkdownNode, media).attachments,
36+
).toEqual([
37+
{ uri: "https://drop.example.com/before.mp4", caption: "Video", kind: "video" },
38+
{ uri: "https://drop.example.com/after.mp4", caption: "Video", kind: "video" },
39+
]);
40+
});
2941
});

‎apps/mobile/src/features/pull-requests/pullRequestDescriptionContent.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export function pullRequestDescriptionContent(
3737
if (node.type === "break") text.push(" ");
3838
};
3939
visit(document);
40-
for (const segment of media) {
40+
const collect = (segment: PullRequestBodySegment) => {
41+
if (segment.kind === "table") {
42+
segment.rows.flat().forEach((cell) => cell.segments.forEach(collect));
43+
return;
44+
}
4145
if (segment.kind === "attachment" && !attachments.has(segment.url)) {
4246
const name = new URL(segment.url).pathname.split("/").pop();
4347
attachments.set(segment.url, {
@@ -46,6 +50,7 @@ export function pullRequestDescriptionContent(
4650
kind: segment.media,
4751
});
4852
}
49-
}
53+
};
54+
media.forEach(collect);
5055
return { preview: text.join("").trim(), attachments: [...attachments.values()] };
5156
}

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11809,9 +11809,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1180911809
}
1181011810
return false;
1181111811
}),
11812-
hasPendingBackgroundWorkForThread: Effect.fn(
11813-
"ClaudeAdapterV2.hasPendingBackgroundWorkForThread",
11814-
)(function* (providerThread, options) {
11812+
// Untraced: the run's event stream calls this once per provider event.
11813+
hasPendingBackgroundWorkForThread: Effect.fnUntraced(function* (providerThread, options) {
1181511814
const nativeThreadId = providerThread.nativeThreadRef?.nativeId;
1181611815
if (nativeThreadId === undefined || nativeThreadId === null) {
1181711816
return false;

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7071,9 +7071,8 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
70717071
}
70727072
return false;
70737073
}),
7074-
hasPendingBackgroundWorkForThread: Effect.fn(
7075-
"CodexAdapterV2.hasPendingBackgroundWorkForThread",
7076-
)(function* (providerThread) {
7074+
// Untraced: the run's event stream calls this once per provider event.
7075+
hasPendingBackgroundWorkForThread: Effect.fnUntraced(function* (providerThread) {
70777076
const contexts = [
70787077
...(yield* Ref.get(activeTurns)).values(),
70797078
...(yield* Ref.get(settledTurns)).values(),

‎apps/server/src/orchestration-v2/ProjectionStore.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,62 @@ it.effect("record reads restrict provider histories to delivery identities", ()
472472
})).providerThreads,
473473
[],
474474
);
475+
const ownerNodeId = NodeId.make("node:delivery-identities:owner");
476+
yield* store.apply({
477+
id: EventId.make("event:delivery-identities:owner-node"),
478+
type: "node.updated",
479+
threadId,
480+
runId: RunId.make("run:delivery-identities:rolled-back"),
481+
nodeId: ownerNodeId,
482+
driver,
483+
occurredAt: now,
484+
payload: {
485+
id: ownerNodeId,
486+
threadId,
487+
runId: RunId.make("run:delivery-identities:rolled-back"),
488+
rootNodeId: NodeId.make("node:delivery-identities:rolled-back"),
489+
parentNodeId: NodeId.make("node:delivery-identities:rolled-back"),
490+
kind: "subagent",
491+
status: "completed",
492+
countsForRun: false,
493+
providerThreadId: null,
494+
providerTurnId: null,
495+
nativeItemRef: null,
496+
runtimeRequestId: null,
497+
checkpointScopeId: null,
498+
startedAt: now,
499+
completedAt: now,
500+
},
501+
});
502+
yield* store.apply({
503+
id: EventId.make("event:delivery-identities:owned"),
504+
type: "provider-thread.updated",
505+
threadId,
506+
occurredAt: now,
507+
payload: {
508+
id: ProviderThreadId.make("provider-thread:owned"),
509+
appThreadId: ThreadId.make("thread:delivery-identities:child"),
510+
driver,
511+
providerInstanceId,
512+
providerSessionId: null,
513+
ownerNodeId,
514+
nativeThreadRef: null,
515+
nativeConversationHeadRef: null,
516+
lastRunOrdinal: null,
517+
handoffIds: [],
518+
forkedFrom: null,
519+
status: "idle",
520+
firstRunOrdinal: 2,
521+
createdAt: now,
522+
updatedAt: now,
523+
},
524+
});
525+
assert.deepEqual(
526+
(yield* store.getThreadRecords(threadId, ["providerThreads"])).providerThreads.map(
527+
(row) => row.id,
528+
),
529+
["provider-thread:history", "provider-thread:selected", "provider-thread:owned"],
530+
);
475531
// Unselected history must not be decoded, even if its payload is unreadable.
476532
yield* sql`UPDATE orchestration_v2_projection_provider_threads SET payload_json = '{}'
477533
WHERE provider_thread_id = 'provider-thread:history'`;

‎apps/server/src/orchestration-v2/ProjectionStore.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,16 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
19791979
OR item.payload_json LIKE '%"viewedImagePath"%'
19801980
OR item.payload_json LIKE '%"toolName":"%delegate_task"%')`;
19811981

1982+
// Start from the few owned provider threads; a thread can have a large settled node history.
1983+
const nodesOwningProviderThreads = (threadId: ThreadId) => sql`
1984+
SELECT owner.node_id
1985+
FROM orchestration_v2_projection_provider_threads AS owned
1986+
INDEXED BY orchestration_v2_projection_provider_threads_owner_idx
1987+
CROSS JOIN orchestration_v2_projection_nodes AS owner
1988+
ON owner.node_id = owned.owner_node_id
1989+
WHERE owned.owner_node_id IS NOT NULL AND owner.thread_id = ${threadId}
1990+
`;
1991+
19821992
const keepRecordedRunField = (payload: Statement.Fragment, path: string) => sql`
19831993
CASE
19841994
WHEN json_type(excluded.payload_json, ${path}) IS NULL
@@ -3500,11 +3510,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
35003510
SELECT payload_json
35013511
FROM orchestration_v2_projection_provider_threads
35023512
WHERE (thread_id = ${threadId}
3503-
OR owner_node_id IN (
3504-
SELECT node_id
3505-
FROM orchestration_v2_projection_nodes
3506-
WHERE thread_id = ${threadId}
3507-
)
3513+
OR owner_node_id IN (${nodesOwningProviderThreads(threadId)})
35083514
OR provider_thread_id IN (
35093515
SELECT provider_thread_id
35103516
FROM orchestration_v2_projection_subagents
@@ -5085,7 +5091,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
50855091
sql<PayloadRow>`SELECT payload_json FROM orchestration_v2_projection_provider_threads
50865092
WHERE provider_thread_id = ${target.providerThreadId} AND (
50875093
thread_id = ${threadId}
5088-
OR owner_node_id IN (SELECT node_id FROM orchestration_v2_projection_nodes WHERE thread_id = ${threadId})
5094+
OR owner_node_id IN (${nodesOwningProviderThreads(threadId)})
50895095
OR provider_thread_id IN (SELECT provider_thread_id FROM orchestration_v2_projection_subagents WHERE thread_id = ${threadId})
50905096
)`,
50915097
sql<PayloadRow>`SELECT payload_json FROM orchestration_v2_projection_provider_turns
@@ -5325,7 +5331,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
53255331
sql<PayloadRow>`SELECT payload_json FROM orchestration_v2_projection_provider_threads
53265332
WHERE provider_thread_id = ${run?.providerThreadId ?? null}
53275333
AND (thread_id = ${threadId}
5328-
OR owner_node_id IN (SELECT node_id FROM orchestration_v2_projection_nodes WHERE thread_id = ${threadId})
5334+
OR owner_node_id IN (${nodesOwningProviderThreads(threadId)})
53295335
OR provider_thread_id IN (SELECT provider_thread_id FROM orchestration_v2_projection_subagents WHERE thread_id = ${threadId}))`,
53305336
sql<{ readonly ordinal: number }>`SELECT ordinal_within_scope AS ordinal
53315337
FROM orchestration_v2_projection_checkpoints
@@ -5364,7 +5370,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
53645370
sql<PayloadRow>`SELECT payload_json FROM orchestration_v2_projection_provider_threads
53655371
WHERE provider_thread_id = ${target.providerThreadId}
53665372
AND (thread_id = ${threadId}
5367-
OR owner_node_id IN (SELECT node_id FROM orchestration_v2_projection_nodes WHERE thread_id = ${threadId})
5373+
OR owner_node_id IN (${nodesOwningProviderThreads(threadId)})
53685374
OR provider_thread_id IN (SELECT provider_thread_id FROM orchestration_v2_projection_subagents WHERE thread_id = ${threadId}))`,
53695375
sql<PayloadRow>`SELECT payload_json FROM orchestration_v2_projection_checkpoints
53705376
WHERE thread_id = ${threadId} AND checkpoint_id = ${target.checkpointId}`,

0 commit comments

Comments
 (0)