From f3c5a527d79941eba7f1b8581bc2b7c6119a9a43 Mon Sep 17 00:00:00 2001 From: murashit Date: Tue, 30 Jun 2026 10:45:57 +0900 Subject: [PATCH] Group chat app-server transports --- .../chat/app-server/session-gateway.ts | 12 +++---- .../thread-reference-resolver.ts | 12 +++---- .../app-server/threads/loading-transport.ts | 27 ---------------- .../client-scope.ts | 0 .../goal-transport.ts} | 4 +-- .../thread-loading-transport.ts} | 31 +++++++++++++++++-- .../thread-mutation-transport.ts} | 4 +-- .../thread-settings-transport.ts | 4 +-- .../turn-transport.ts} | 4 +-- .../chat/app-server/transports.test.ts | 15 +++++---- tests/scripts/grit-policy.test.mjs | 4 +-- 11 files changed, 59 insertions(+), 58 deletions(-) rename src/features/chat/app-server/{references => }/thread-reference-resolver.ts (83%) delete mode 100644 src/features/chat/app-server/threads/loading-transport.ts rename src/features/chat/app-server/{connection => transports}/client-scope.ts (100%) rename src/features/chat/app-server/{goals/transport.ts => transports/goal-transport.ts} (94%) rename src/features/chat/app-server/{threads/projection.ts => transports/thread-loading-transport.ts} (55%) rename src/features/chat/app-server/{threads/transport.ts => transports/thread-mutation-transport.ts} (89%) rename src/features/chat/app-server/{runtime => transports}/thread-settings-transport.ts (81%) rename src/features/chat/app-server/{turns/transport.ts => transports/turn-transport.ts} (89%) diff --git a/src/features/chat/app-server/session-gateway.ts b/src/features/chat/app-server/session-gateway.ts index cdb12cd4..d09b109e 100644 --- a/src/features/chat/app-server/session-gateway.ts +++ b/src/features/chat/app-server/session-gateway.ts @@ -8,12 +8,12 @@ import type { RuntimeSettingsTransport } from "../application/runtime/settings-t import type { ThreadGoalReadTransport, ThreadGoalTransport } from "../application/threads/goal-transport"; import type { ThreadHistoryTransport, ThreadResumeTransport } from "../application/threads/thread-loading-transport"; import type { ThreadMutationTransport } from "../application/threads/thread-mutation-transport"; -import { createChatThreadGoalReadTransport, createChatThreadGoalTransport } from "./goals/transport"; -import { createThreadReferenceResolver, type ThreadReferenceResolver } from "./references/thread-reference-resolver"; -import { createChatRuntimeSettingsTransport } from "./runtime/thread-settings-transport"; -import { createChatThreadHistoryTransport, createChatThreadResumeTransport } from "./threads/loading-transport"; -import { createChatThreadMutationTransport } from "./threads/transport"; -import { createChatTurnTransport } from "./turns/transport"; +import { createThreadReferenceResolver, type ThreadReferenceResolver } from "./thread-reference-resolver"; +import { createChatThreadGoalReadTransport, createChatThreadGoalTransport } from "./transports/goal-transport"; +import { createChatThreadHistoryTransport, createChatThreadResumeTransport } from "./transports/thread-loading-transport"; +import { createChatThreadMutationTransport } from "./transports/thread-mutation-transport"; +import { createChatRuntimeSettingsTransport } from "./transports/thread-settings-transport"; +import { createChatTurnTransport } from "./transports/turn-transport"; export interface ChatAppServerGatewayHost { vaultPath: string; diff --git a/src/features/chat/app-server/references/thread-reference-resolver.ts b/src/features/chat/app-server/thread-reference-resolver.ts similarity index 83% rename from src/features/chat/app-server/references/thread-reference-resolver.ts rename to src/features/chat/app-server/thread-reference-resolver.ts index 8e9dac34..26cf6489 100644 --- a/src/features/chat/app-server/references/thread-reference-resolver.ts +++ b/src/features/chat/app-server/thread-reference-resolver.ts @@ -1,9 +1,9 @@ -import { readReferencedThreadConversationSummaries, type ThreadConversationSummaryClient } from "../../../../app-server/services/threads"; -import { type CodexInput, codexTextInputWithAttachments } from "../../../../domain/chat/input"; -import type { Thread } from "../../../../domain/threads/model"; -import { REFERENCED_THREAD_TURN_LIMIT, referencedThreadPromptBundle } from "../../../../domain/threads/reference"; -import { shortThreadId } from "../../../../shared/id/thread-id"; -import type { ThreadReferenceInput } from "../../application/conversation/slash-command-execution"; +import { readReferencedThreadConversationSummaries, type ThreadConversationSummaryClient } from "../../../app-server/services/threads"; +import { type CodexInput, codexTextInputWithAttachments } from "../../../domain/chat/input"; +import type { Thread } from "../../../domain/threads/model"; +import { REFERENCED_THREAD_TURN_LIMIT, referencedThreadPromptBundle } from "../../../domain/threads/reference"; +import { shortThreadId } from "../../../shared/id/thread-id"; +import type { ThreadReferenceInput } from "../application/conversation/slash-command-execution"; interface ThreadReferenceResolverHost { currentClient(): ThreadConversationSummaryClient | null; diff --git a/src/features/chat/app-server/threads/loading-transport.ts b/src/features/chat/app-server/threads/loading-transport.ts deleted file mode 100644 index 155dcab0..00000000 --- a/src/features/chat/app-server/threads/loading-transport.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { - ThreadHistoryPage, - ThreadHistoryTransport, - ThreadResumeSnapshot, - ThreadResumeTransport, -} from "../../application/threads/thread-loading-transport"; -import type { ConnectedChatAppServerClientHost, CurrentChatAppServerClientHost } from "../connection/client-scope"; -import { withConnectedChatAppServerClient, withCurrentChatAppServerClient } from "../connection/client-scope"; -import { readChatThreadHistoryPage, resumeChatThread } from "./projection"; - -interface ChatThreadResumeTransportHost extends ConnectedChatAppServerClientHost { - vaultPath: string; -} - -export function createChatThreadHistoryTransport(host: CurrentChatAppServerClientHost): ThreadHistoryTransport { - return { - readHistoryPage: (threadId, cursor, limit): Promise => - withCurrentChatAppServerClient(host, (client) => readChatThreadHistoryPage(client, threadId, cursor, limit)), - }; -} - -export function createChatThreadResumeTransport(host: ChatThreadResumeTransportHost): ThreadResumeTransport { - return { - resumeThread: (threadId): Promise => - withConnectedChatAppServerClient(host, (client) => resumeChatThread(client, threadId, host.vaultPath)), - }; -} diff --git a/src/features/chat/app-server/connection/client-scope.ts b/src/features/chat/app-server/transports/client-scope.ts similarity index 100% rename from src/features/chat/app-server/connection/client-scope.ts rename to src/features/chat/app-server/transports/client-scope.ts diff --git a/src/features/chat/app-server/goals/transport.ts b/src/features/chat/app-server/transports/goal-transport.ts similarity index 94% rename from src/features/chat/app-server/goals/transport.ts rename to src/features/chat/app-server/transports/goal-transport.ts index 0dff6efb..beeaede8 100644 --- a/src/features/chat/app-server/goals/transport.ts +++ b/src/features/chat/app-server/transports/goal-transport.ts @@ -1,7 +1,7 @@ import { clearThreadGoal, readThreadGoal, recordThreadGoalUserMessage, setThreadGoal } from "../../../../app-server/services/threads"; import type { ThreadGoalReadTransport, ThreadGoalTransport } from "../../application/threads/goal-transport"; -import type { ConnectedChatAppServerClientHost, CurrentChatAppServerClientHost } from "../connection/client-scope"; -import { chatAppServerClientIsStale, withConnectedChatAppServerClient, withCurrentChatAppServerClient } from "../connection/client-scope"; +import type { ConnectedChatAppServerClientHost, CurrentChatAppServerClientHost } from "./client-scope"; +import { chatAppServerClientIsStale, withConnectedChatAppServerClient, withCurrentChatAppServerClient } from "./client-scope"; export function createChatThreadGoalReadTransport(host: CurrentChatAppServerClientHost): ThreadGoalReadTransport { return { diff --git a/src/features/chat/app-server/threads/projection.ts b/src/features/chat/app-server/transports/thread-loading-transport.ts similarity index 55% rename from src/features/chat/app-server/threads/projection.ts rename to src/features/chat/app-server/transports/thread-loading-transport.ts index 2eceb0bd..337ff0f5 100644 --- a/src/features/chat/app-server/threads/projection.ts +++ b/src/features/chat/app-server/transports/thread-loading-transport.ts @@ -1,8 +1,15 @@ import type { AppServerRequestClient } from "../../../../app-server/services/request-client"; import { listThreadTurns, resumeThread, threadActivationSnapshotFromAppServerResponse } from "../../../../app-server/services/threads"; import type { ThreadTurnsPage } from "../../../../domain/threads/history"; -import type { ThreadHistoryPage, ThreadResumeSnapshot } from "../../application/threads/thread-loading-transport"; +import type { + ThreadHistoryPage, + ThreadHistoryTransport, + ThreadResumeSnapshot, + ThreadResumeTransport, +} from "../../application/threads/thread-loading-transport"; import { messageStreamItemsFromTurns } from "../mappers/message-stream/turn-items"; +import type { ConnectedChatAppServerClientHost, CurrentChatAppServerClientHost } from "./client-scope"; +import { withConnectedChatAppServerClient, withCurrentChatAppServerClient } from "./client-scope"; type ChatThreadHistoryClient = AppServerRequestClient; type ChatThreadResumeClient = AppServerRequestClient; @@ -12,7 +19,25 @@ interface AppServerThreadTurnsPage { readonly nextCursor: string | null; } -export async function readChatThreadHistoryPage( +interface ChatThreadResumeTransportHost extends ConnectedChatAppServerClientHost { + vaultPath: string; +} + +export function createChatThreadHistoryTransport(host: CurrentChatAppServerClientHost): ThreadHistoryTransport { + return { + readHistoryPage: (threadId, cursor, limit): Promise => + withCurrentChatAppServerClient(host, (client) => readChatThreadHistoryPage(client, threadId, cursor, limit)), + }; +} + +export function createChatThreadResumeTransport(host: ChatThreadResumeTransportHost): ThreadResumeTransport { + return { + resumeThread: (threadId): Promise => + withConnectedChatAppServerClient(host, (client) => resumeChatThread(client, threadId, host.vaultPath)), + }; +} + +async function readChatThreadHistoryPage( client: ChatThreadHistoryClient, threadId: string, cursor: string | null, @@ -29,7 +54,7 @@ function chatThreadHistoryPageFromTurnsPage(page: ThreadTurnsPage): ThreadHistor }; } -export async function resumeChatThread(client: ChatThreadResumeClient, threadId: string, cwd: string): Promise { +async function resumeChatThread(client: ChatThreadResumeClient, threadId: string, cwd: string): Promise { const response = await resumeThread(client, threadId, cwd); return { activation: threadActivationSnapshotFromAppServerResponse(response), diff --git a/src/features/chat/app-server/threads/transport.ts b/src/features/chat/app-server/transports/thread-mutation-transport.ts similarity index 89% rename from src/features/chat/app-server/threads/transport.ts rename to src/features/chat/app-server/transports/thread-mutation-transport.ts index 5d34f65d..25e95275 100644 --- a/src/features/chat/app-server/threads/transport.ts +++ b/src/features/chat/app-server/transports/thread-mutation-transport.ts @@ -1,8 +1,8 @@ import { compactThread, forkThread, rollbackThread } from "../../../../app-server/services/threads"; import type { ThreadMutationTransport, ThreadRollbackSnapshot } from "../../application/threads/thread-mutation-transport"; -import type { ConnectedChatAppServerClientHost } from "../connection/client-scope"; -import { withConnectedChatAppServerClient } from "../connection/client-scope"; import { messageStreamItemsFromTurns } from "../mappers/message-stream/turn-items"; +import type { ConnectedChatAppServerClientHost } from "./client-scope"; +import { withConnectedChatAppServerClient } from "./client-scope"; interface ChatThreadMutationTransportHost extends ConnectedChatAppServerClientHost { vaultPath: string; diff --git a/src/features/chat/app-server/runtime/thread-settings-transport.ts b/src/features/chat/app-server/transports/thread-settings-transport.ts similarity index 81% rename from src/features/chat/app-server/runtime/thread-settings-transport.ts rename to src/features/chat/app-server/transports/thread-settings-transport.ts index 115f97a5..1f1066a4 100644 --- a/src/features/chat/app-server/runtime/thread-settings-transport.ts +++ b/src/features/chat/app-server/transports/thread-settings-transport.ts @@ -1,8 +1,8 @@ import { updateThreadSettings } from "../../../../app-server/services/threads"; import type { RuntimeSettingsPatch } from "../../../../domain/runtime/thread-settings"; import type { RuntimeSettingsTransport } from "../../application/runtime/settings-transport"; -import type { CurrentChatAppServerClientHost } from "../connection/client-scope"; -import { withCurrentChatAppServerClient } from "../connection/client-scope"; +import type { CurrentChatAppServerClientHost } from "./client-scope"; +import { withCurrentChatAppServerClient } from "./client-scope"; export function createChatRuntimeSettingsTransport(host: CurrentChatAppServerClientHost): RuntimeSettingsTransport { return { diff --git a/src/features/chat/app-server/turns/transport.ts b/src/features/chat/app-server/transports/turn-transport.ts similarity index 89% rename from src/features/chat/app-server/turns/transport.ts rename to src/features/chat/app-server/transports/turn-transport.ts index e365c052..065cce0a 100644 --- a/src/features/chat/app-server/turns/transport.ts +++ b/src/features/chat/app-server/transports/turn-transport.ts @@ -1,7 +1,7 @@ import { interruptTurn, startTurn, steerTurn } from "../../../../app-server/services/turns"; import type { ChatTurnTransport } from "../../application/conversation/turn-transport"; -import type { ConnectedChatAppServerClientHost } from "../connection/client-scope"; -import { withCurrentChatAppServerClient } from "../connection/client-scope"; +import type { ConnectedChatAppServerClientHost } from "./client-scope"; +import { withCurrentChatAppServerClient } from "./client-scope"; interface ChatTurnTransportHost extends ConnectedChatAppServerClientHost { vaultPath: string; diff --git a/tests/features/chat/app-server/transports.test.ts b/tests/features/chat/app-server/transports.test.ts index 1d429e98..39b85e18 100644 --- a/tests/features/chat/app-server/transports.test.ts +++ b/tests/features/chat/app-server/transports.test.ts @@ -4,15 +4,18 @@ import type { AppServerClient, ClientResponseByMethod } from "../../../../src/ap import type { ThreadRecord } from "../../../../src/app-server/protocol/thread"; import type { TurnItem, TurnRecord } from "../../../../src/app-server/protocol/turn"; import type { CodexInput } from "../../../../src/domain/chat/input"; -import { createChatThreadGoalReadTransport, createChatThreadGoalTransport } from "../../../../src/features/chat/app-server/goals/transport"; -import { createThreadReferenceResolver } from "../../../../src/features/chat/app-server/references/thread-reference-resolver"; -import { createChatRuntimeSettingsTransport } from "../../../../src/features/chat/app-server/runtime/thread-settings-transport"; +import { createThreadReferenceResolver } from "../../../../src/features/chat/app-server/thread-reference-resolver"; +import { + createChatThreadGoalReadTransport, + createChatThreadGoalTransport, +} from "../../../../src/features/chat/app-server/transports/goal-transport"; import { createChatThreadHistoryTransport, createChatThreadResumeTransport, -} from "../../../../src/features/chat/app-server/threads/loading-transport"; -import { createChatThreadMutationTransport } from "../../../../src/features/chat/app-server/threads/transport"; -import { createChatTurnTransport } from "../../../../src/features/chat/app-server/turns/transport"; +} from "../../../../src/features/chat/app-server/transports/thread-loading-transport"; +import { createChatThreadMutationTransport } from "../../../../src/features/chat/app-server/transports/thread-mutation-transport"; +import { createChatRuntimeSettingsTransport } from "../../../../src/features/chat/app-server/transports/thread-settings-transport"; +import { createChatTurnTransport } from "../../../../src/features/chat/app-server/transports/turn-transport"; import { deferred } from "../../../support/async"; const textInput = (text: string): CodexInput => [{ type: "text", text }]; diff --git a/tests/scripts/grit-policy.test.mjs b/tests/scripts/grit-policy.test.mjs index 936d79d1..fc031078 100644 --- a/tests/scripts/grit-policy.test.mjs +++ b/tests/scripts/grit-policy.test.mjs @@ -475,12 +475,12 @@ export function timestamp(): number { path.join(cwd, "src/features/chat/application/outer.ts"), ` import type { Host } from "../host/contracts"; -import type { ChatThreadHistoryPage } from "../app-server/threads/projection"; +import type { ThreadHistoryTransport } from "../app-server/transports/thread-loading-transport"; import type { ToolbarPanelActions } from "../panel/toolbar-actions"; import { statusText } from "../presentation/runtime/status"; import { Toolbar } from "../ui/toolbar"; -export type Escape = ChatThreadHistoryPage | Host | ToolbarPanelActions; +export type Escape = ThreadHistoryTransport | Host | ToolbarPanelActions; export const values = [statusText, Toolbar] satisfies unknown[]; `.trimStart(), );