Skip to content

Commit be177ec

Browse files
committed
fix(clients): load thread link titles and project icons
1 parent f54e7cf commit be177ec

20 files changed

Lines changed: 345 additions & 100 deletions

‎apps/mobile/src/state/entities.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ const EMPTY_THREAD_LINK_TITLES_ATOM = Atom.make<ReadonlyMap<string, string>>(new
5656
const decodeThreadKey = Schema.decodeUnknownSync(Schema.Tuple([EnvironmentId, ThreadId]));
5757
const threadKey = (ref: ScopedThreadRef) => JSON.stringify([ref.environmentId, ref.threadId]);
5858

59-
// Omitted and archived targets need only a title lookup, not their conversation history.
59+
// Omitted and archived targets need only a metadata lookup, not their conversation history.
6060
const threadTitleAtom = Atom.family((key: string) => {
6161
const ref = scopeThreadRef(...decodeThreadKey(JSON.parse(key)));
6262
return Atom.make((get) => {
6363
const shell = get(environmentThreadShells.threadShellAtom(ref));
6464
if (shell !== null) return shell.title;
6565
const titles = get(
66-
orchestrationEnvironment.threadTitles({
66+
orchestrationEnvironment.threadLinkMetadata({
6767
environmentId: ref.environmentId,
6868
input: { threadIds: [ref.threadId] },
6969
}),
7070
);
7171
return AsyncResult.isSuccess(titles)
72-
? (titles.value[ref.threadId] ?? (titles.waiting ? "Thread" : null))
72+
? (titles.value[ref.threadId]?.title ?? (titles.waiting ? "Thread" : null))
7373
: "Thread";
7474
}).pipe(Atom.withLabel(`mobile-thread-title:${key}`));
7575
});
@@ -103,11 +103,22 @@ const threadProjectChipIconAtom = Atom.family((key: string) => {
103103
const ref = scopeThreadRef(...decodeThreadKey(JSON.parse(key)));
104104
return Atom.make((get): string | null => {
105105
const shell = get(environmentThreadShells.threadShellAtom(ref));
106-
const project = shell
106+
const metadata =
107+
shell ??
108+
AsyncResult.getOrElse(
109+
get(
110+
orchestrationEnvironment.threadLinkMetadata({
111+
environmentId: ref.environmentId,
112+
input: { threadIds: [ref.threadId] },
113+
}),
114+
),
115+
() => null,
116+
)?.[ref.threadId];
117+
const project = metadata?.projectId
107118
? get(
108119
environmentProjects.projectAtom({
109120
environmentId: ref.environmentId,
110-
projectId: shell.projectId,
121+
projectId: metadata.projectId,
111122
}),
112123
)
113124
: null;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { createOrchestrationEnvironmentAtoms } from "@t3tools/client-runtime/state/orchestration";
22

33
import { connectionAtomRuntime } from "../connection/runtime";
4+
import { environmentShell } from "./shell";
45
import { recordReviewTurnDiffAnswer } from "./reviewTurnDiffs";
56

67
export const orchestrationEnvironment = createOrchestrationEnvironmentAtoms(connectionAtomRuntime, {
8+
shellState: environmentShell.stateValueAtom,
79
onCheckpointDiffAnswer: recordReviewTurnDiffAnswer,
810
});

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const RPC_REQUIRED_SCOPES = {
5252
[ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: AuthOrchestrationReadScope,
5353
[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: AuthOrchestrationReadScope,
5454
[ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: AuthOrchestrationReadScope,
55+
[ORCHESTRATION_V2_WS_METHODS.getThreadLinkMetadata]: AuthOrchestrationReadScope,
5556
[ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: AuthOrchestrationReadScope,
5657
[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: AuthOrchestrationReadScope,
5758
[ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: AuthOrchestrationReadScope,

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const RPC_AGGREGATES = {
2525
[ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: "orchestration",
2626
[ORCHESTRATION_V2_WS_METHODS.getThreadFamily]: "orchestration",
2727
[ORCHESTRATION_V2_WS_METHODS.getThreadTitles]: "orchestration",
28+
[ORCHESTRATION_V2_WS_METHODS.getThreadLinkMetadata]: "orchestration",
2829
[ORCHESTRATION_V2_WS_METHODS.getWorktreeThreadIds]: "orchestration",
2930
[ORCHESTRATION_V2_WS_METHODS.getOlderSettledThreads]: "orchestration",
3031
[ORCHESTRATION_V2_WS_METHODS.getThreadProjection]: "orchestrationV2",

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {
2+
OrchestrationV2ThreadLinkMetadata,
23
GuestShareId,
34
OrchestrationV2SearchThreadInput,
45
OrchestrationV2SearchThreadResult,
@@ -479,6 +480,9 @@ export interface OrchestratorV2Shape {
479480
shareId: GuestShareId,
480481
) => Effect.Effect<ThreadId | null, OrchestratorV2Error>;
481482
/** Titles of the given threads that exist, archived ones included. */
483+
readonly getThreadLinkMetadata: (
484+
threadIds: ReadonlyArray<ThreadId>,
485+
) => Effect.Effect<Record<ThreadId, OrchestrationV2ThreadLinkMetadata>, OrchestratorV2Error>;
482486
readonly getThreadTitles: (
483487
threadIds: ReadonlyArray<ThreadId>,
484488
) => Effect.Effect<Record<ThreadId, string>, OrchestratorV2Error>;
@@ -14540,6 +14544,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1454014544
.findGuestShareThreadId(shareId)
1454114545
.pipe(Effect.mapError(shellProjectionError));
1454214546
}),
14547+
getThreadLinkMetadata: Effect.fn("OrchestratorV2.getThreadLinkMetadata")(function (threadIds) {
14548+
return projectionStore
14549+
.getThreadLinkMetadata(threadIds)
14550+
.pipe(Effect.mapError(shellProjectionError));
14551+
}),
1454314552
getThreadTitles: Effect.fn("OrchestratorV2.getThreadTitles")(function (threadIds) {
1454414553
return projectionStore.getThreadTitles(threadIds).pipe(Effect.mapError(shellProjectionError));
1454514554
}),

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,24 @@ const threadWorktreePathsIncludeArchivedOnRequest = Effect.gen(function* () {
13271327
{ threadId: ThreadId.make("thread:active"), worktreePath: "/worktrees/active" },
13281328
{ threadId: ThreadId.make("thread:archived"), worktreePath: "/worktrees/archived" },
13291329
]);
1330+
assert.deepEqual(
1331+
yield* store.getThreadLinkMetadata([
1332+
deleted.id,
1333+
ThreadId.make("thread:active"),
1334+
ThreadId.make("thread:archived"),
1335+
ThreadId.make("unknown"),
1336+
]),
1337+
{
1338+
[ThreadId.make("thread:active")]: {
1339+
title: "Title for thread:active",
1340+
projectId: ProjectId.make("project:worktree-paths"),
1341+
},
1342+
[ThreadId.make("thread:archived")]: {
1343+
title: "Title for thread:archived",
1344+
projectId: ProjectId.make("project:worktree-paths"),
1345+
},
1346+
},
1347+
);
13301348
assert.deepEqual(
13311349
yield* store.getThreadTitles([
13321350
deleted.id,

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Stream from "effect/Stream";
66
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
77
import { makeThreadFind } from "./ThreadFind.ts";
88
import type {
9+
OrchestrationV2ThreadLinkMetadata,
910
OrchestrationV2SearchThreadInput,
1011
OrchestrationV2SearchThreadResult,
1112
OrchestrationV2ThreadHistoryPage,
@@ -562,6 +563,9 @@ export interface ProjectionStoreV2Shape {
562563
threadId?: ThreadId,
563564
) => Effect.Effect<ReadonlyArray<ProjectionThreadPullRequests>, ProjectionStoreV2Error>;
564565
/** Titles of the given threads that exist, archived ones included. */
566+
readonly getThreadLinkMetadata: (
567+
threadIds: ReadonlyArray<ThreadId>,
568+
) => Effect.Effect<Record<ThreadId, OrchestrationV2ThreadLinkMetadata>, ProjectionStoreV2Error>;
565569
readonly getThreadTitles: (
566570
threadIds: ReadonlyArray<ThreadId>,
567571
) => Effect.Effect<Record<ThreadId, string>, ProjectionStoreV2Error>;
@@ -7306,6 +7310,24 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
73067310
}));
73077311
}, Effect.mapError(shellSnapshotReadError));
73087312

7313+
const getThreadLinkMetadata = Effect.fn("ProjectionStore.getThreadLinkMetadata")(function* (
7314+
threadIds: ReadonlyArray<ThreadId>,
7315+
) {
7316+
if (threadIds.length === 0) return {};
7317+
const rows = yield* sql<{
7318+
readonly thread_id: ThreadId;
7319+
readonly title: string;
7320+
readonly project_id: ProjectId;
7321+
}>`
7322+
SELECT thread_id, title, project_id
7323+
FROM orchestration_v2_projection_threads
7324+
WHERE deleted_at IS NULL AND thread_id IN ${sql.in(threadIds)}
7325+
`;
7326+
return Object.fromEntries(
7327+
rows.map((row) => [row.thread_id, { title: row.title, projectId: row.project_id }]),
7328+
);
7329+
}, Effect.mapError(shellSnapshotReadError));
7330+
73097331
const getThreadTitles = Effect.fn("ProjectionStore.getThreadTitles")(function* (
73107332
threadIds: ReadonlyArray<ThreadId>,
73117333
) {
@@ -7485,6 +7507,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
74857507
getSettlementCandidates: readOnReader(getSettlementCandidates),
74867508
getThreadsWithPullRequests: readOnReader(getThreadsWithPullRequests),
74877509
getThreadTitles: readOnReader(getThreadTitles),
7510+
getThreadLinkMetadata: readOnReader(getThreadLinkMetadata),
74887511
getThreadWorktreePaths: readOnReader(getThreadWorktreePaths),
74897512
getOpenRemoteDelegatedTasks: getOpenRemoteDelegatedTasks.pipe(NodeSqliteClient.readOnly),
74907513
getThreadProjection: readOnReader(getThreadProjection),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ it.effect(
221221
readShellSnapshot: () => Effect.die("unused readShellSnapshot"),
222222
getThreadShell: () => Effect.die("unused getThreadShell"),
223223
getThreadTitles: () => Effect.die("unused getThreadTitles"),
224+
getThreadLinkMetadata: () => Effect.die("unused getThreadLinkMetadata"),
224225
findGuestShareThreadId: () => Effect.die("unused findGuestShareThreadId"),
225226
getThread: () => Ref.get(projection).pipe(Effect.map((state) => state.thread)),
226227
getSettlementCandidates: () => Effect.die("unused getSettlementCandidates"),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ export interface ThreadManagementServiceShape {
423423
>;
424424
readonly getThreadShell: Orchestrator.OrchestratorV2["Service"]["getThreadShell"];
425425
readonly listAppOwnedChildThreadIds: Orchestrator.OrchestratorV2["Service"]["listAppOwnedChildThreadIds"];
426+
readonly getThreadLinkMetadata: Orchestrator.OrchestratorV2["Service"]["getThreadLinkMetadata"];
426427
readonly getThreadTitles: Orchestrator.OrchestratorV2["Service"]["getThreadTitles"];
427428
/** Omit `projectId` to list every project's threads. Side chats are never listed. */
428429
readonly listProjectThreads: (input: {
@@ -1609,6 +1610,7 @@ const make = Effect.gen(function* () {
16091610
},
16101611
),
16111612
getThreadTitles: orchestrator.getThreadTitles,
1613+
getThreadLinkMetadata: orchestrator.getThreadLinkMetadata,
16121614
listProjectThreads,
16131615
sendToThread,
16141616
assertProviderInstanceEnabled,

‎apps/server/src/relay/AgentAwarenessRelay.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ const makeTestRelay = Effect.fnUntraced(function* (
204204
listOlderSettledThreads: unused,
205205
readShellSnapshot: unused,
206206
getThreadTitles: unused,
207+
getThreadLinkMetadata: unused,
207208
ensureLegacyTranscript: unused,
208209
dispatch: unused,
209210
searchThread: () => Effect.die("unused"),

0 commit comments

Comments
 (0)