Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b155dbec8 | ||
|
|
3b01bbe18f | ||
|
|
823d69f621 | ||
|
|
4963fccb05 | ||
|
|
dd89d5ce1a |
No files matched your search
@@ -626,20 +626,25 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
|
||||
const existingMessage = yield* projectionThreadMessageRepository.getByMessageId({
|
||||
messageId: event.payload.messageId,
|
||||
});
|
||||
const nextText =
|
||||
Option.isSome(existingMessage) && event.payload.streaming
|
||||
? `${existingMessage.value.text}${event.payload.text}`
|
||||
: Option.isSome(existingMessage) && event.payload.text.length === 0
|
||||
? existingMessage.value.text
|
||||
: event.payload.text;
|
||||
const previousMessage = Option.getOrUndefined(existingMessage);
|
||||
const nextText = Option.match(existingMessage, {
|
||||
onNone: () => event.payload.text,
|
||||
onSome: (message) => {
|
||||
if (event.payload.streaming) {
|
||||
return `${message.text}${event.payload.text}`;
|
||||
}
|
||||
if (event.payload.text.length === 0) {
|
||||
return message.text;
|
||||
}
|
||||
return event.payload.text;
|
||||
},
|
||||
});
|
||||
const nextAttachments =
|
||||
event.payload.attachments !== undefined
|
||||
? yield* materializeAttachmentsForProjection({
|
||||
attachments: event.payload.attachments,
|
||||
})
|
||||
: Option.isSome(existingMessage)
|
||||
? existingMessage.value.attachments
|
||||
: undefined;
|
||||
: previousMessage?.attachments;
|
||||
yield* projectionThreadMessageRepository.upsert({
|
||||
messageId: event.payload.messageId,
|
||||
threadId: event.payload.threadId,
|
||||
@@ -648,9 +653,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
|
||||
text: nextText,
|
||||
...(nextAttachments !== undefined ? { attachments: [...nextAttachments] } : {}),
|
||||
isStreaming: event.payload.streaming,
|
||||
createdAt: Option.isSome(existingMessage)
|
||||
? existingMessage.value.createdAt
|
||||
: event.payload.createdAt,
|
||||
createdAt: previousMessage?.createdAt ?? event.payload.createdAt,
|
||||
updatedAt: event.payload.updatedAt,
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -1145,11 +1145,6 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
});
|
||||
|
||||
const wsUrl = yield* getWsServerUrl("/ws");
|
||||
const snapshotResult = yield* Effect.scoped(
|
||||
withWsRpcClient(wsUrl, (client) => client[ORCHESTRATION_WS_METHODS.getSnapshot]({})),
|
||||
);
|
||||
assert.equal(snapshotResult.snapshotSequence, 1);
|
||||
|
||||
const activeSnapshotResult = yield* Effect.scoped(
|
||||
withWsRpcClient(wsUrl, (client) => client[ORCHESTRATION_WS_METHODS.getActiveSnapshot]({})),
|
||||
);
|
||||
@@ -1266,15 +1261,15 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
it.effect("routes websocket rpc orchestration.getSnapshot errors", () =>
|
||||
it.effect("routes websocket rpc orchestration.getActiveSnapshot errors", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* buildAppUnderTest({
|
||||
layers: {
|
||||
projectionSnapshotQuery: {
|
||||
getSnapshot: () =>
|
||||
getActiveSnapshot: () =>
|
||||
Effect.fail(
|
||||
new PersistenceSqlError({
|
||||
operation: "ProjectionSnapshotQuery.getSnapshot",
|
||||
operation: "ProjectionSnapshotQuery.getActiveSnapshot",
|
||||
detail: "projection unavailable",
|
||||
}),
|
||||
),
|
||||
@@ -1284,14 +1279,14 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
|
||||
const wsUrl = yield* getWsServerUrl("/ws");
|
||||
const result = yield* Effect.scoped(
|
||||
withWsRpcClient(wsUrl, (client) => client[ORCHESTRATION_WS_METHODS.getSnapshot]({})).pipe(
|
||||
Effect.result,
|
||||
),
|
||||
withWsRpcClient(wsUrl, (client) =>
|
||||
client[ORCHESTRATION_WS_METHODS.getActiveSnapshot]({}),
|
||||
).pipe(Effect.result),
|
||||
);
|
||||
|
||||
assertTrue(result._tag === "Failure");
|
||||
assertTrue(result.failure._tag === "OrchestrationGetSnapshotError");
|
||||
assertInclude(result.failure.message, "Failed to load orchestration snapshot");
|
||||
assertTrue(result.failure._tag === "OrchestrationGetActiveSnapshotError");
|
||||
assertInclude(result.failure.message, "Failed to load active orchestration snapshot");
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
|
||||
@@ -99,12 +99,24 @@ const ReactorLayerLive = Layer.empty.pipe(
|
||||
Layer.provideMerge(RuntimeReceiptBusLive),
|
||||
);
|
||||
|
||||
const OrchestrationLayerLive = Layer.empty.pipe(
|
||||
Layer.provideMerge(OrchestrationProjectionSnapshotQueryLive),
|
||||
Layer.provideMerge(OrchestrationEngineLive),
|
||||
Layer.provideMerge(OrchestrationProjectionPipelineLive),
|
||||
Layer.provideMerge(OrchestrationEventStoreLive),
|
||||
Layer.provideMerge(OrchestrationCommandReceiptRepositoryLive),
|
||||
const OrchestrationEventInfrastructureLayerLive = Layer.mergeAll(
|
||||
OrchestrationEventStoreLive,
|
||||
OrchestrationCommandReceiptRepositoryLive,
|
||||
);
|
||||
|
||||
const OrchestrationProjectionPipelineLayerLive = OrchestrationProjectionPipelineLive.pipe(
|
||||
Layer.provide(OrchestrationEventStoreLive),
|
||||
);
|
||||
|
||||
const OrchestrationInfrastructureLayerLive = Layer.mergeAll(
|
||||
OrchestrationProjectionSnapshotQueryLive,
|
||||
OrchestrationEventInfrastructureLayerLive,
|
||||
OrchestrationProjectionPipelineLayerLive,
|
||||
);
|
||||
|
||||
const OrchestrationLayerLive = Layer.mergeAll(
|
||||
OrchestrationInfrastructureLayerLive,
|
||||
OrchestrationEngineLive.pipe(Layer.provide(OrchestrationInfrastructureLayerLive)),
|
||||
);
|
||||
|
||||
const CheckpointingLayerLive = Layer.empty.pipe(
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
OrchestrationGetActiveSnapshotError,
|
||||
OrchestrationGetFullThreadDiffError,
|
||||
OrchestrationListArchivedThreadsError,
|
||||
OrchestrationGetSnapshotError,
|
||||
OrchestrationGetTurnDiffError,
|
||||
ORCHESTRATION_WS_METHODS,
|
||||
ProjectSearchEntriesError,
|
||||
@@ -74,16 +73,6 @@ const WsRpcLayer = WsRpcGroup.toLayer(
|
||||
});
|
||||
|
||||
return WsRpcGroup.of({
|
||||
[ORCHESTRATION_WS_METHODS.getSnapshot]: (_input) =>
|
||||
projectionSnapshotQuery.getSnapshot().pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new OrchestrationGetSnapshotError({
|
||||
message: "Failed to load orchestration snapshot",
|
||||
cause,
|
||||
}),
|
||||
),
|
||||
),
|
||||
[ORCHESTRATION_WS_METHODS.getActiveSnapshot]: (_input) =>
|
||||
projectionSnapshotQuery.getActiveSnapshot().pipe(
|
||||
Effect.mapError(
|
||||
|
||||
@@ -622,10 +622,7 @@ function resolveWsRpc(body: NormalizedWsRpcRequestBody): unknown {
|
||||
return customResult;
|
||||
}
|
||||
const tag = body._tag;
|
||||
if (
|
||||
tag === ORCHESTRATION_WS_METHODS.getSnapshot ||
|
||||
tag === ORCHESTRATION_WS_METHODS.getActiveSnapshot
|
||||
) {
|
||||
if (tag === ORCHESTRATION_WS_METHODS.getActiveSnapshot) {
|
||||
return fixture.snapshot;
|
||||
}
|
||||
if (tag === WS_METHODS.serverGetConfig) {
|
||||
|
||||
@@ -147,10 +147,7 @@ function buildFixture(): TestFixture {
|
||||
}
|
||||
|
||||
function resolveWsRpc(tag: string): unknown {
|
||||
if (
|
||||
tag === ORCHESTRATION_WS_METHODS.getSnapshot ||
|
||||
tag === ORCHESTRATION_WS_METHODS.getActiveSnapshot
|
||||
) {
|
||||
if (tag === ORCHESTRATION_WS_METHODS.getActiveSnapshot) {
|
||||
return fixture.snapshot;
|
||||
}
|
||||
if (tag === WS_METHODS.serverGetConfig) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import { useSettings } from "./useSettings";
|
||||
|
||||
export function useThreadActions() {
|
||||
const appSettings = useSettings();
|
||||
const syncServerReadModel = useStore((store) => store.syncServerReadModel);
|
||||
const clearComposerDraftForThread = useComposerDraftStore((store) => store.clearDraftThread);
|
||||
const clearProjectDraftThreadById = useComposerDraftStore(
|
||||
(store) => store.clearProjectDraftThreadById,
|
||||
@@ -32,6 +33,13 @@ export function useThreadActions() {
|
||||
const queryClient = useQueryClient();
|
||||
const removeWorktreeMutation = useMutation(gitRemoveWorktreeMutationOptions({ queryClient }));
|
||||
|
||||
const refreshActiveSnapshot = useCallback(async () => {
|
||||
const api = readNativeApi();
|
||||
if (!api) return;
|
||||
const snapshot = await api.orchestration.getActiveSnapshot();
|
||||
syncServerReadModel(snapshot);
|
||||
}, [syncServerReadModel]);
|
||||
|
||||
const archiveThread = useCallback(
|
||||
async (threadId: ThreadId) => {
|
||||
const api = readNativeApi();
|
||||
@@ -65,9 +73,10 @@ export function useThreadActions() {
|
||||
commandId: newCommandId(),
|
||||
threadId,
|
||||
});
|
||||
await refreshActiveSnapshot();
|
||||
void queryClient.invalidateQueries({ queryKey: orchestrationQueryKeys.archivedThreads() });
|
||||
},
|
||||
[queryClient],
|
||||
[queryClient, refreshActiveSnapshot],
|
||||
);
|
||||
|
||||
const deleteThread = useCallback(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { OrchestrationListArchivedThreadsResult } from "@t3tools/contracts";
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
import { ensureNativeApi } from "~/nativeApi";
|
||||
|
||||
@@ -7,6 +8,7 @@ export const orchestrationQueryKeys = {
|
||||
};
|
||||
|
||||
const DEFAULT_ARCHIVED_THREADS_STALE_TIME = 15_000;
|
||||
const EMPTY_ARCHIVED_THREADS: OrchestrationListArchivedThreadsResult = [];
|
||||
|
||||
export function archivedThreadsQueryOptions() {
|
||||
return queryOptions({
|
||||
@@ -16,6 +18,6 @@ export function archivedThreadsQueryOptions() {
|
||||
return api.orchestration.listArchivedThreads();
|
||||
},
|
||||
staleTime: DEFAULT_ARCHIVED_THREADS_STALE_TIME,
|
||||
placeholderData: (previous) => previous,
|
||||
placeholderData: (previous) => previous ?? EMPTY_ARCHIVED_THREADS,
|
||||
});
|
||||
}
|
||||
@@ -75,7 +75,6 @@ const rpcClientMock = {
|
||||
subscribeLifecycle: vi.fn(),
|
||||
},
|
||||
orchestration: {
|
||||
getSnapshot: vi.fn(),
|
||||
getActiveSnapshot: vi.fn(),
|
||||
listArchivedThreads: vi.fn(),
|
||||
dispatchCommand: vi.fn(),
|
||||
|
||||
@@ -90,7 +90,6 @@ export function createWsNativeApi(): NativeApi {
|
||||
updateSettings: rpcClient.server.updateSettings,
|
||||
},
|
||||
orchestration: {
|
||||
getSnapshot: rpcClient.orchestration.getSnapshot,
|
||||
getActiveSnapshot: rpcClient.orchestration.getActiveSnapshot,
|
||||
listArchivedThreads: rpcClient.orchestration.listArchivedThreads,
|
||||
dispatchCommand: rpcClient.orchestration.dispatchCommand,
|
||||
|
||||
@@ -86,7 +86,6 @@ export interface WsRpcClient {
|
||||
readonly subscribeLifecycle: RpcStreamMethod<typeof WS_METHODS.subscribeServerLifecycle>;
|
||||
};
|
||||
readonly orchestration: {
|
||||
readonly getSnapshot: RpcUnaryNoArgMethod<typeof ORCHESTRATION_WS_METHODS.getSnapshot>;
|
||||
readonly getActiveSnapshot: RpcUnaryNoArgMethod<
|
||||
typeof ORCHESTRATION_WS_METHODS.getActiveSnapshot
|
||||
>;
|
||||
@@ -191,8 +190,6 @@ export function createWsRpcClient(transport = new WsTransport()): WsRpcClient {
|
||||
transport.subscribe((client) => client[WS_METHODS.subscribeServerLifecycle]({}), listener),
|
||||
},
|
||||
orchestration: {
|
||||
getSnapshot: () =>
|
||||
transport.request((client) => client[ORCHESTRATION_WS_METHODS.getSnapshot]({})),
|
||||
getActiveSnapshot: () =>
|
||||
transport.request((client) => client[ORCHESTRATION_WS_METHODS.getActiveSnapshot]({})),
|
||||
dispatchCommand: (input) =>
|
||||
|
||||
@@ -174,7 +174,6 @@ export interface NativeApi {
|
||||
updateSettings: (patch: ServerSettingsPatch) => Promise<ServerSettings>;
|
||||
};
|
||||
orchestration: {
|
||||
getSnapshot: () => Promise<OrchestrationReadModel>;
|
||||
getActiveSnapshot: () => Promise<OrchestrationReadModel>;
|
||||
listArchivedThreads: () => Promise<OrchestrationListArchivedThreadsResult>;
|
||||
dispatchCommand: (command: ClientOrchestrationCommand) => Promise<{ sequence: number }>;
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
} from "./baseSchemas";
|
||||
|
||||
export const ORCHESTRATION_WS_METHODS = {
|
||||
getSnapshot: "orchestration.getSnapshot",
|
||||
getActiveSnapshot: "orchestration.getActiveSnapshot",
|
||||
dispatchCommand: "orchestration.dispatchCommand",
|
||||
getTurnDiff: "orchestration.getTurnDiff",
|
||||
@@ -982,11 +981,6 @@ export const DispatchResult = Schema.Struct({
|
||||
});
|
||||
export type DispatchResult = typeof DispatchResult.Type;
|
||||
|
||||
export const OrchestrationGetSnapshotInput = Schema.Struct({});
|
||||
export type OrchestrationGetSnapshotInput = typeof OrchestrationGetSnapshotInput.Type;
|
||||
const OrchestrationGetSnapshotResult = OrchestrationReadModel;
|
||||
export type OrchestrationGetSnapshotResult = typeof OrchestrationGetSnapshotResult.Type;
|
||||
|
||||
export const OrchestrationGetActiveSnapshotInput = Schema.Struct({});
|
||||
export type OrchestrationGetActiveSnapshotInput = typeof OrchestrationGetActiveSnapshotInput.Type;
|
||||
const OrchestrationGetActiveSnapshotResult = OrchestrationReadModel;
|
||||
@@ -1039,10 +1033,6 @@ const OrchestrationReplayEventsResult = Schema.Array(OrchestrationEvent);
|
||||
export type OrchestrationReplayEventsResult = typeof OrchestrationReplayEventsResult.Type;
|
||||
|
||||
export const OrchestrationRpcSchemas = {
|
||||
getSnapshot: {
|
||||
input: OrchestrationGetSnapshotInput,
|
||||
output: OrchestrationGetSnapshotResult,
|
||||
},
|
||||
getActiveSnapshot: {
|
||||
input: OrchestrationGetActiveSnapshotInput,
|
||||
output: OrchestrationGetActiveSnapshotResult,
|
||||
@@ -1069,14 +1059,6 @@ export const OrchestrationRpcSchemas = {
|
||||
},
|
||||
} as const;
|
||||
|
||||
export class OrchestrationGetSnapshotError extends Schema.TaggedErrorClass<OrchestrationGetSnapshotError>()(
|
||||
"OrchestrationGetSnapshotError",
|
||||
{
|
||||
message: TrimmedNonEmptyString,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
|
||||
export class OrchestrationGetActiveSnapshotError extends Schema.TaggedErrorClass<OrchestrationGetActiveSnapshotError>()(
|
||||
"OrchestrationGetActiveSnapshotError",
|
||||
{
|
||||
|
||||
@@ -35,8 +35,6 @@ import {
|
||||
OrchestrationGetActiveSnapshotInput,
|
||||
OrchestrationGetFullThreadDiffError,
|
||||
OrchestrationGetFullThreadDiffInput,
|
||||
OrchestrationGetSnapshotError,
|
||||
OrchestrationGetSnapshotInput,
|
||||
OrchestrationGetTurnDiffError,
|
||||
OrchestrationGetTurnDiffInput,
|
||||
OrchestrationListArchivedThreadsError,
|
||||
@@ -261,12 +259,6 @@ export const WsTerminalCloseRpc = Rpc.make(WS_METHODS.terminalClose, {
|
||||
error: TerminalError,
|
||||
});
|
||||
|
||||
export const WsOrchestrationGetSnapshotRpc = Rpc.make(ORCHESTRATION_WS_METHODS.getSnapshot, {
|
||||
payload: OrchestrationGetSnapshotInput,
|
||||
success: OrchestrationRpcSchemas.getSnapshot.output,
|
||||
error: OrchestrationGetSnapshotError,
|
||||
});
|
||||
|
||||
export const WsOrchestrationGetActiveSnapshotRpc = Rpc.make(
|
||||
ORCHESTRATION_WS_METHODS.getActiveSnapshot,
|
||||
{
|
||||
@@ -369,15 +361,14 @@ export const WsRpcGroup = RpcGroup.make(
|
||||
WsTerminalClearRpc,
|
||||
WsTerminalRestartRpc,
|
||||
WsTerminalCloseRpc,
|
||||
WsSubscribeOrchestrationDomainEventsRpc,
|
||||
WsSubscribeTerminalEventsRpc,
|
||||
WsSubscribeServerConfigRpc,
|
||||
WsSubscribeServerLifecycleRpc,
|
||||
WsOrchestrationGetSnapshotRpc,
|
||||
WsOrchestrationGetActiveSnapshotRpc,
|
||||
WsOrchestrationDispatchCommandRpc,
|
||||
WsOrchestrationGetTurnDiffRpc,
|
||||
WsOrchestrationGetFullThreadDiffRpc,
|
||||
WsOrchestrationListArchivedThreadsRpc,
|
||||
WsOrchestrationReplayEventsRpc,
|
||||
WsSubscribeOrchestrationDomainEventsRpc,
|
||||
WsSubscribeTerminalEventsRpc,
|
||||
WsSubscribeServerConfigRpc,
|
||||
WsSubscribeServerLifecycleRpc,
|
||||
);
|
||||
Reference in new issue
Block a user