fix(mobile): support Hermes collection sorting

Reuses the focused compatibility approach from closed PR #3923 and covers the remaining hardware-keyboard reverse iteration.

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-08-14 11:23:26 +02:00
1 parent 9c65560b35
commit 32b749d07e
8 files changed
+72 -22

No files matched your search

@@ -55,7 +55,10 @@ export function subscribeToHardwareKeyboardCommandRegistrations(listener: () =>
export function dispatchHardwareKeyboardCommand(command: HardwareKeyboardCommand): boolean {
const commandHandlers = handlers.get(command);
if (!commandHandlers) return false;
for (const handler of [...commandHandlers].toReversed()) {
const handlersInRegistrationOrder = Array.from(commandHandlers);
for (let index = handlersInRegistrationOrder.length - 1; index >= 0; index -= 1) {
const handler = handlersInRegistrationOrder[index];
if (!handler) continue;
if (handler() !== false) return true;
}
return false;
@@ -8,7 +8,8 @@ import {
} from "@t3tools/client-runtime/state/thread-relationships";
import { canDetachThreadProviderSession } from "@t3tools/client-runtime/state/thread-workflows";
import type { EnvironmentId, OrchestrationV2ThreadShell, ThreadId } from "@t3tools/contracts";
import { useRouter } from "expo-router";
import { copySorted } from "@t3tools/shared/Array";
import { useNavigation } from "@react-navigation/native";
import { useMemo, useState } from "react";
import { ActivityIndicator, Modal, Pressable, ScrollView, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -79,7 +80,8 @@ export function ThreadRelationshipsBanner(props: {
const mergeTargetThreadId = resolveMergeBackTargetThreadId(projection);
const rows = useMemo(
() =>
immediateThreadRelationships(graph, props.threadId).toSorted(
copySorted(
immediateThreadRelationships(graph, props.threadId),
(left, right) =>
Number(right.threadId === mergeTargetThreadId) -
Number(left.threadId === mergeTargetThreadId),
+16 -2
View File
@@ -9,6 +9,7 @@ import {
} from "@t3tools/contracts";
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
import * as Option from "effect/Option";
import { copySorted } from "@t3tools/shared/Array";
import { useProject, useThreadShell } from "../state/entities";
import { useEnvironmentThread } from "../state/threads";
@@ -44,8 +45,21 @@ function threadDetailToShell(
environmentId: EnvironmentId,
thread: OrchestrationThread,
): EnvironmentThreadShell {
return {
environmentId,
const thread = projection.thread;
const runsByOrdinal = copySorted(projection.runs, (left, right) => right.ordinal - left.ordinal);
const latestRun = runsByOrdinal[0] ?? null;
const activeRun =
runsByOrdinal.find(
(run) =>
run.status === "preparing" ||
run.status === "queued" ||
run.status === "starting" ||
run.status === "running" ||
run.status === "waiting",
) ?? null;
const pendingRequest =
projection.runtimeRequests.find((request) => request.status === "pending") ?? null;
return presentThreadShell(environmentId, {
id: thread.id,
projectId: thread.projectId,
title: thread.title,
@@ -3,6 +3,7 @@ import type {
OrchestrationV2ProviderCapabilities,
OrchestrationV2ThreadProjection,
} from "@t3tools/contracts";
import { copySorted } from "@t3tools/shared/Array";
type Projection = OrchestrationV2ThreadProjection;
type Run = Projection["runs"][number];
@@ -54,19 +55,17 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu
const activeRun = resolveActiveThreadRun(projection);
const session = resolveThreadProviderSession(projection);
const capabilities = session?.capabilities.turns;
const queuedRuns = projection.runs
.filter((run) => run.status === "queued")
.toSorted(
(left, right) =>
(left.queuePosition ?? left.ordinal) - (right.queuePosition ?? right.ordinal) ||
left.ordinal - right.ordinal,
)
.map((run) => ({
run,
text:
projection.messages.find((message) => message.id === run.userMessageId)?.text ??
"Queued message",
}));
const queuedRuns = copySorted(
projection.runs.filter((run) => run.status === "queued"),
(left, right) =>
(left.queuePosition ?? left.ordinal) - (right.queuePosition ?? right.ordinal) ||
left.ordinal - right.ordinal,
).map((run) => ({
run,
text:
projection.messages.find((message) => message.id === run.userMessageId)?.text ??
"Queued message",
}));
return {
activeRun,
+4
View File
@@ -3,6 +3,10 @@
"private": true,
"type": "module",
"exports": {
"./Array": {
"types": "./src/Array.ts",
"import": "./src/Array.ts"
},
"./projectFavicon": {
"types": "./src/projectFavicon.ts",
"import": "./src/projectFavicon.ts"
+12
View File
@@ -0,0 +1,12 @@
import { describe, expect, it } from "vite-plus/test";
import { copySorted } from "./Array.ts";
describe("array copies", () => {
it("sorts a copy without mutating the source", () => {
const source = [3, 1, 2];
expect(copySorted(source, (left: number, right: number) => left - right)).toEqual([1, 2, 3]);
expect(source).toEqual([3, 1, 2]);
});
});
+6
View File
@@ -0,0 +1,6 @@
export function copySorted<T>(
values: ReadonlyArray<T>,
compareFn?: (left: T, right: T) => number,
): T[] {
return [...values].sort(compareFn);
}
+14 -4
View File
@@ -9,6 +9,7 @@ import {
type ProviderOptionDescriptor,
type ProviderOptionSelection,
} from "@t3tools/contracts";
import { copySorted } from "./Array.ts";
const DEFAULT_PROVIDER_DRIVER_KIND = ProviderDriverKind.make("codex");
@@ -80,12 +81,21 @@ export function getModelSelectionBooleanOptionValue(
function canonicalModelSelectionOptions(
modelSelection: ModelSelection,
): ReadonlyArray<readonly [id: string, value: string | boolean]> {
return (modelSelection.options ?? [])
.map((selection) => [selection.id, selection.value] as const)
.toSorted(([leftId, leftValue], [rightId, rightValue]) => {
return copySorted(
(modelSelection.options ?? []).map(
(selection): readonly [id: string, value: string | boolean] => [
selection.id,
selection.value,
],
),
(
[leftId, leftValue]: readonly [id: string, value: string | boolean],
[rightId, rightValue]: readonly [id: string, value: string | boolean],
) => {
const idOrder = leftId.localeCompare(rightId);
return idOrder !== 0 ? idOrder : String(leftValue).localeCompare(String(rightValue));
});
},
);
}
/**