Open History to see the last commit
1import {
2 type ChatAttachment,
3 type CommandId,
4 MessageId,
5 type ModelSelection,
6 type OrchestrationV2Actor,
7 type OrchestrationV2Command,
8 type OrchestrationV2ConversationMessage,
9 type OrchestrationV2CreationSource,
10 type OrchestrationV2Run,
11 type OrchestrationV2ThreadShellSnapshot,
12 type OrchestrationV2ThreadProjection,
13 type OrchestrationV2ThreadShell,
14 type OrchestrationV2TurnItem,
15 ProjectId,
16 RunId,
17 ThreadId,
18} from "@t3tools/contracts";
19import * as Context from "effect/Context";
20import * as DateTime from "effect/DateTime";
21import * as Duration from "effect/Duration";
22import * as Effect from "effect/Effect";
23import * as Layer from "effect/Layer";
24import * as Option from "effect/Option";
25import * as Schema from "effect/Schema";
26
27import {
28 OrchestratorDispatchError,
29 OrchestratorProjectionError,
30 OrchestratorV2,
31 type OrchestratorV2DispatchResult,
32 type OrchestratorV2Error,
33} from "./Orchestrator.ts";
34import {
35 LegacyV1ThreadImporter,
36 type LegacyV1ThreadImportError,
37} from "./LegacyV1ThreadImporter.ts";
38
39export type ThreadManagementSendMode = "auto" | "queue" | "steer" | "restart";
40
41export interface ThreadManagementProvenance {
42 readonly createdBy: OrchestrationV2Actor;
43 readonly creationSource: OrchestrationV2CreationSource;
44}
45
46export function withCreationProvenance(
47 command: OrchestrationV2Command,
48 provenance: ThreadManagementProvenance,
49): OrchestrationV2Command {
50 switch (command.type) {
51 case "thread.create":
52 case "message.dispatch":
53 case "thread.fork":
54 case "thread.merge_back":
55 case "delegated_task.request":
56 return { ...command, ...provenance };
57 default:
58 return command;
59 }
60}
61
62export function existingThreadIdsForCommand(
63 command: OrchestrationV2Command,
64): ReadonlyArray<ThreadId> {
65 switch (command.type) {
66 case "thread.create":
67 return [];
68 // Read-state commands only rewrite the thread payload's visited/unread
69 // watermark; they never touch messages, so they do not need the imported
70 // v1 transcript hydrated first. Visits fire on every thread-activity bump
71 // while a thread is open, so keeping them off the import path matters.
72 case "thread.visit":
73 case "thread.mark-unread":
74 return [];
75 case "thread.fork":
76 return [command.sourceThreadId];
77 case "thread.merge_back":
78 return command.sourceThreadId === command.targetThreadId
79 ? [command.sourceThreadId]
80 : [command.sourceThreadId, command.targetThreadId];
81 case "delegated_task.request":
82 case "delegated_task.wake-policy":
83 case "delegated_task.completion-delivery.acknowledge":
84 case "delegated_task.completion-delivery.dispose":
85 return [command.parentThreadId];
86 case "thread.created.record":
87 return command.parentThreadId === command.targetThreadId
88 ? [command.parentThreadId]
89 : [command.parentThreadId, command.targetThreadId];
90 default:
91 return [command.threadId];
92 }
93}
94
95export type ThreadManagementTerminalRunStatus = Extract<
96 OrchestrationV2Run["status"],
97 "completed" | "failed" | "cancelled" | "interrupted" | "rolled_back"
98>;
99
100export interface ThreadManagementSendInput {
101 readonly projectId: ProjectId;
102 readonly commandId: CommandId;
103 readonly threadId: ThreadId;
104 readonly messageId: MessageId;
105 readonly text: string;
106 readonly attachments: ReadonlyArray<ChatAttachment>;
107 readonly modelSelection?: ModelSelection;
108 readonly mode: ThreadManagementSendMode;
109 readonly createdBy: OrchestrationV2Actor;
110 readonly creationSource: OrchestrationV2CreationSource;
111}
112
113export interface ThreadManagementSendResult {
114 readonly dispatch: OrchestratorV2DispatchResult;
115 readonly projection: OrchestrationV2ThreadProjection;
116 readonly message: OrchestrationV2ConversationMessage;
117 readonly run: OrchestrationV2Run;
118 /** Null for queued sends: the user turn item materializes when the queued turn starts. */
119 readonly turnItem: Extract<OrchestrationV2TurnItem, { readonly type: "user_message" }> | null;
120 readonly delivery: "started" | "queued" | "steered" | "restarted";
121}
122
123export interface ThreadManagementWaitInput {
124 readonly projectId: ProjectId;
125 readonly threadId: ThreadId;
126 readonly runId?: RunId;
127 readonly timeoutMs: number;
128 readonly pollIntervalMs?: number;
129}
130
131export interface ThreadManagementWaitResult {
132 readonly threadId: ThreadId;
133 readonly run: OrchestrationV2Run | null;
134 readonly timedOut: boolean;
135}
136
137export interface ThreadManagementInterruptInput {
138 readonly projectId: ProjectId;
139 readonly commandId: CommandId;
140 readonly threadId: ThreadId;
141 readonly runId?: RunId;
142 readonly reason?: string;
143}
144
145export type ThreadManagementInterruptResult =
146 | {
147 readonly type: "interrupt_requested";
148 readonly run: OrchestrationV2Run;
149 readonly dispatch: OrchestratorV2DispatchResult;
150 }
151 | { readonly type: "no_active_run" }
152 | {
153 readonly type: "already_terminal";
154 readonly run: OrchestrationV2Run & { readonly status: ThreadManagementTerminalRunStatus };
155 };
156
157export class ThreadManagementThreadNotFoundError extends Schema.TaggedErrorClass<ThreadManagementThreadNotFoundError>()(
158 "ThreadManagementThreadNotFoundError",
159 {
160 projectId: ProjectId,
161 threadId: ThreadId,
162 },
163) {
164 override get message(): string {
165 return `Thread ${this.threadId} was not found in project ${this.projectId}.`;
166 }
167}
168
169export class ThreadManagementRunNotFoundError extends Schema.TaggedErrorClass<ThreadManagementRunNotFoundError>()(
170 "ThreadManagementRunNotFoundError",
171 {
172 threadId: ThreadId,
173 runId: RunId,
174 },
175) {
176 override get message(): string {
177 return `Run ${this.runId} does not belong to thread ${this.threadId}.`;
178 }
179}
180
181export class ThreadManagementThreadArchivedError extends Schema.TaggedErrorClass<ThreadManagementThreadArchivedError>()(
182 "ThreadManagementThreadArchivedError",
183 {
184 threadId: ThreadId,
185 },
186) {
187 override get message(): string {
188 return `Thread ${this.threadId} is archived and cannot receive messages.`;
189 }
190}
191
192export class ThreadManagementNoSteerableRunError extends Schema.TaggedErrorClass<ThreadManagementNoSteerableRunError>()(
193 "ThreadManagementNoSteerableRunError",
194 {
195 threadId: ThreadId,
196 mode: Schema.Literals(["steer", "restart"]),
197 },
198) {
199 override get message(): string {
200 return `Thread ${this.threadId} has no running turn that can be ${this.mode === "steer" ? "steered" : "restarted"}.`;
201 }
202}
203
204export class ThreadManagementThreadNotInterruptibleError extends Schema.TaggedErrorClass<ThreadManagementThreadNotInterruptibleError>()(
205 "ThreadManagementThreadNotInterruptibleError",
206 {
207 threadId: ThreadId,
208 runId: RunId,
209 },
210) {
211 override get message(): string {
212 return `Run ${this.runId} is not currently interruptible.`;
213 }
214}
215
216export class ThreadManagementProjectionLoadError extends Schema.TaggedErrorClass<ThreadManagementProjectionLoadError>()(
217 "ThreadManagementProjectionLoadError",
218 {
219 projectId: ProjectId,
220 threadId: ThreadId,
221 cause: Schema.Defect(),
222 },
223) {
224 override get message(): string {
225 return `Unable to load thread ${this.threadId} in project ${this.projectId}.`;
226 }
227}
228
229export class ThreadManagementProjectThreadsListError extends Schema.TaggedErrorClass<ThreadManagementProjectThreadsListError>()(
230 "ThreadManagementProjectThreadsListError",
231 {
232 projectId: ProjectId,
233 cause: Schema.Defect(),
234 },
235) {
236 override get message(): string {
237 return `Unable to list threads in project ${this.projectId}.`;
238 }
239}
240
241export class ThreadManagementDurableRunProjectionError extends Schema.TaggedErrorClass<ThreadManagementDurableRunProjectionError>()(
242 "ThreadManagementDurableRunProjectionError",
243 {
244 threadId: ThreadId,
245 messageId: MessageId,
246 },
247) {
248 override get message(): string {
249 return `Message ${this.messageId} was accepted on thread ${this.threadId} without a durable run projection.`;
250 }
251}
252
253export const ThreadManagementError = Schema.Union([
254 ThreadManagementThreadNotFoundError,
255 ThreadManagementRunNotFoundError,
256 ThreadManagementThreadArchivedError,
257 ThreadManagementNoSteerableRunError,
258 ThreadManagementThreadNotInterruptibleError,
259 ThreadManagementProjectionLoadError,
260 ThreadManagementProjectThreadsListError,
261 ThreadManagementDurableRunProjectionError,
262]);
263export type ThreadManagementError = typeof ThreadManagementError.Type;
264
265type ThreadManagementFailure = ThreadManagementError | OrchestratorV2Error;
266
267export interface ThreadManagementServiceShape {
268 readonly ensureLegacyTranscript: (
269 threadId: ThreadId,
270 ) => Effect.Effect<void, LegacyV1ThreadImportError>;
271 readonly dispatch: (
272 command: OrchestrationV2Command,
273 ) => Effect.Effect<OrchestratorV2DispatchResult, OrchestratorV2Error>;
274 readonly getThreadProjection: (
275 threadId: ThreadId,
276 ) => Effect.Effect<OrchestrationV2ThreadProjection, OrchestratorV2Error>;
277 readonly getThreadSnapshot: OrchestratorV2["Service"]["getThreadSnapshot"];
278 readonly getProjectThread: (input: {
279 readonly projectId: ProjectId;
280 readonly threadId: ThreadId;
281 }) => Effect.Effect<OrchestrationV2ThreadProjection, ThreadManagementError>;
282 readonly getShellSnapshot: () => Effect.Effect<
283 OrchestrationV2ThreadShellSnapshot,
284 OrchestratorV2Error
285 >;
286 readonly getThreadShell: OrchestratorV2["Service"]["getThreadShell"];
287 readonly listProjectThreads: (input: {
288 readonly projectId: ProjectId;
289 readonly includeSubagents: boolean;
290 }) => Effect.Effect<ReadonlyArray<OrchestrationV2ThreadShell>, ThreadManagementError>;
291 readonly sendToThread: (
292 input: ThreadManagementSendInput,
293 ) => Effect.Effect<ThreadManagementSendResult, ThreadManagementFailure>;
294 readonly waitForThread: (
295 input: ThreadManagementWaitInput,
296 ) => Effect.Effect<ThreadManagementWaitResult, ThreadManagementError>;
297 readonly interruptThread: (
298 input: ThreadManagementInterruptInput,
299 ) => Effect.Effect<ThreadManagementInterruptResult, ThreadManagementFailure>;
300 readonly getThreadEventSequence: OrchestratorV2["Service"]["getThreadEventSequence"];
301 readonly streamStoredEvents: OrchestratorV2["Service"]["streamStoredEvents"];
302 readonly streamStoredEventsFrom: OrchestratorV2["Service"]["streamStoredEventsFrom"];
303 readonly streamDomainEvents: OrchestratorV2["Service"]["streamDomainEvents"];
304}
305
306export class ThreadManagementService extends Context.Service<
307 ThreadManagementService,
308 ThreadManagementServiceShape
309>()("t3/orchestration-v2/ThreadManagementService") {}
310
311export function isActiveRun(run: OrchestrationV2Run): boolean {
312 return (
313 run.status === "preparing" ||
314 run.status === "starting" ||
315 run.status === "running" ||
316 run.status === "waiting"
317 );
318}
319
320export function isTerminalRunStatus(
321 status: OrchestrationV2Run["status"],
322): status is ThreadManagementTerminalRunStatus {
323 return (
324 status === "completed" ||
325 status === "failed" ||
326 status === "cancelled" ||
327 status === "interrupted" ||
328 status === "rolled_back"
329 );
330}
331
332export function latestRun(
333 projection: OrchestrationV2ThreadProjection,
334): OrchestrationV2Run | undefined {
335 return projection.runs.toSorted((left, right) => right.ordinal - left.ordinal)[0];
336}
337
338export function latestActiveRun(
339 projection: OrchestrationV2ThreadProjection,
340): OrchestrationV2Run | undefined {
341 return projection.runs
342 .filter(isActiveRun)
343 .toSorted((left, right) => right.ordinal - left.ordinal)[0];
344}
345
346export function latestSteerableRun(
347 projection: OrchestrationV2ThreadProjection,
348): OrchestrationV2Run | undefined {
349 return projection.runs
350 .filter(
351 (run) =>
352 run.status === "running" &&
353 run.activeAttemptId !== null &&
354 projection.providerTurns.some(
355 (turn) => turn.runAttemptId === run.activeAttemptId && turn.status === "running",
356 ),
357 )
358 .toSorted((left, right) => right.ordinal - left.ordinal)[0];
359}
360
361const make = Effect.gen(function* () {
362 const orchestrator = yield* OrchestratorV2;
363 const legacyImporter = yield* LegacyV1ThreadImporter;
364
365 const ensureLegacyTranscript = Effect.fn(
366 "orchestrationV2.threadManagement.ensureLegacyTranscript",
367 )(function* (threadId: ThreadId) {
368 yield* legacyImporter.ensureTranscript(threadId).pipe(
369 Effect.tapError((cause) =>
370 Effect.logWarning("Unable to hydrate migrated v1 thread transcript", {
371 threadId,
372 cause,
373 }),
374 ),
375 );
376 });
377
378 const ensureProjectionTranscript = (threadId: ThreadId) =>
379 ensureLegacyTranscript(threadId).pipe(
380 Effect.mapError(
381 (cause) =>
382 new OrchestratorProjectionError({
383 threadId,
384 cause,
385 }),
386 ),
387 );
388
389 const ensureCommandTranscripts = Effect.fn(
390 "orchestrationV2.threadManagement.ensureCommandTranscripts",
391 )(function* (command: OrchestrationV2Command) {
392 yield* Effect.forEach(
393 existingThreadIdsForCommand(command),
394 (threadId) => ensureLegacyTranscript(threadId),
395 { discard: true },
396 ).pipe(
397 Effect.mapError(
398 (cause) =>
399 new OrchestratorDispatchError({
400 commandId: command.commandId,
401 commandType: command.type,
402 cause,
403 }),
404 ),
405 );
406 });
407
408 const getThreadProjection: ThreadManagementServiceShape["getThreadProjection"] = (threadId) =>
409 ensureProjectionTranscript(threadId).pipe(
410 Effect.andThen(orchestrator.getThreadProjection(threadId)),
411 );
412
413 const getThreadSnapshot: ThreadManagementServiceShape["getThreadSnapshot"] = (threadId) =>
414 ensureProjectionTranscript(threadId).pipe(
415 Effect.andThen(orchestrator.getThreadSnapshot(threadId)),
416 );
417
418 const dispatch: ThreadManagementServiceShape["dispatch"] = (command) =>
419 ensureCommandTranscripts(command).pipe(Effect.andThen(orchestrator.dispatch(command)));
420
421 const getProjectThread: ThreadManagementServiceShape["getProjectThread"] = (input) =>
422 getThreadProjection(input.threadId).pipe(
423 Effect.mapError(
424 (cause) =>
425 new ThreadManagementProjectionLoadError({
426 projectId: input.projectId,
427 threadId: input.threadId,
428 cause,
429 }),
430 ),
431 Effect.flatMap((projection) =>
432 projection.thread.projectId === input.projectId && projection.thread.deletedAt === null
433 ? Effect.succeed(projection)
434 : Effect.fail(
435 new ThreadManagementThreadNotFoundError({
436 projectId: input.projectId,
437 threadId: input.threadId,
438 }),
439 ),
440 ),
441 );
442
443 const listProjectThreads: ThreadManagementServiceShape["listProjectThreads"] = (input) =>
444 orchestrator.getShellSnapshot().pipe(
445 Effect.mapError(
446 (cause) =>
447 new ThreadManagementProjectThreadsListError({
448 projectId: input.projectId,
449 cause,
450 }),
451 ),
452 Effect.map((snapshot) =>
453 snapshot.threads
454 .filter((thread) => thread.projectId === input.projectId)
455 .filter(
456 (thread) =>
457 input.includeSubagents || thread.lineage.relationshipToParent !== "subagent",
458 )
459 .toSorted(
460 (left, right) =>
461 DateTime.toEpochMillis(right.updatedAt) - DateTime.toEpochMillis(left.updatedAt) ||
462 right.id.localeCompare(left.id),
463 ),
464 ),
465 );
466
467 const sendToThread: ThreadManagementServiceShape["sendToThread"] = (input) =>
468 Effect.gen(function* () {
469 const target = yield* getProjectThread(input);
470 if (target.thread.archivedAt !== null) {
471 return yield* new ThreadManagementThreadArchivedError({
472 threadId: input.threadId,
473 });
474 }
475
476 const steerableRun = latestSteerableRun(target);
477 let dispatchMode: Extract<
478 OrchestrationV2Command,
479 { readonly type: "message.dispatch" }
480 >["dispatchMode"];
481 if (input.mode === "steer" || input.mode === "restart") {
482 if (steerableRun === undefined) {
483 return yield* new ThreadManagementNoSteerableRunError({
484 threadId: input.threadId,
485 mode: input.mode,
486 });
487 }
488 dispatchMode = {
489 type: input.mode === "steer" ? "steer_active" : "restart_active",
490 targetRunId: steerableRun.id,
491 };
492 } else if (input.mode === "auto" && steerableRun !== undefined) {
493 dispatchMode = { type: "steer_active", targetRunId: steerableRun.id };
494 } else {
495 dispatchMode = {
496 type: input.mode === "queue" ? "queue_after_active" : "start_immediately",
497 };
498 }
499
500 const dispatch = yield* orchestrator.dispatch({
501 type: "message.dispatch",
502 commandId: input.commandId,
503 threadId: input.threadId,
504 messageId: input.messageId,
505 text: input.text,
506 attachments: input.attachments,
507 ...(input.modelSelection === undefined ? {} : { modelSelection: input.modelSelection }),
508 dispatchMode,
509 createdBy: input.createdBy,
510 creationSource: input.creationSource,
511 });
512 const projection = yield* getProjectThread(input);
513 const message = projection.messages.find((candidate) => candidate.id === input.messageId);
514 const run =
515 message?.runId === null || message?.runId === undefined
516 ? undefined
517 : projection.runs.find((candidate) => candidate.id === message.runId);
518 const turnItem =
519 projection.turnItems.find(
520 (
521 candidate,
522 ): candidate is Extract<OrchestrationV2TurnItem, { readonly type: "user_message" }> =>
523 candidate.type === "user_message" && candidate.messageId === input.messageId,
524 ) ?? null;
525 // A queued message's user turn item is deliberately not emitted at
526 // dispatch time — it materializes when the queued turn actually starts,
527 // so it can map onto the provider turn. Every other dispatch mode still
528 // produces its turn item transactionally with the run.
529 if (
530 message === undefined ||
531 run === undefined ||
532 (turnItem === null && run.status !== "queued")
533 ) {
534 return yield* new ThreadManagementDurableRunProjectionError({
535 threadId: input.threadId,
536 messageId: input.messageId,
537 });
538 }
539 const delivery: ThreadManagementSendResult["delivery"] =
540 turnItem === null || turnItem.inputIntent === "queued_turn"
541 ? "queued"
542 : turnItem.inputIntent === "turn_start"
543 ? "started"
544 : input.mode === "restart"
545 ? "restarted"
546 : "steered";
547 return { dispatch, projection, message, run, turnItem, delivery };
548 });
549
550 const waitForThread: ThreadManagementServiceShape["waitForThread"] = (input) =>
551 Effect.gen(function* () {
552 const target = yield* getProjectThread(input);
553 const selectedRun =
554 input.runId === undefined
555 ? latestRun(target)
556 : target.runs.find((candidate) => candidate.id === input.runId);
557 if (input.runId !== undefined && selectedRun === undefined) {
558 return yield* new ThreadManagementRunNotFoundError({
559 threadId: input.threadId,
560 runId: input.runId,
561 });
562 }
563 if (selectedRun === undefined) {
564 return { threadId: input.threadId, run: null, timedOut: false };
565 }
566 if (isTerminalRunStatus(selectedRun.status)) {
567 return { threadId: input.threadId, run: selectedRun, timedOut: false };
568 }
569
570 const wait = Effect.gen(function* () {
571 while (true) {
572 const current = yield* getProjectThread(input);
573 const run = current.runs.find((candidate) => candidate.id === selectedRun.id);
574 if (run === undefined) {
575 return yield* new ThreadManagementRunNotFoundError({
576 threadId: input.threadId,
577 runId: selectedRun.id,
578 });
579 }
580 if (isTerminalRunStatus(run.status)) return run;
581 yield* Effect.sleep(Duration.millis(Math.max(1, input.pollIntervalMs ?? 250)));
582 }
583 }).pipe(Effect.timeoutOption(Duration.millis(Math.max(1, input.timeoutMs))));
584 const waited = yield* wait;
585 if (Option.isSome(waited)) {
586 return { threadId: input.threadId, run: waited.value, timedOut: false };
587 }
588 const current = yield* getProjectThread(input);
589 const run = current.runs.find((candidate) => candidate.id === selectedRun.id);
590 if (run === undefined) {
591 return yield* new ThreadManagementRunNotFoundError({
592 threadId: input.threadId,
593 runId: selectedRun.id,
594 });
595 }
596 return { threadId: input.threadId, run, timedOut: true };
597 });
598
599 const interruptThread: ThreadManagementServiceShape["interruptThread"] = (input) =>
600 Effect.gen(function* () {
601 const target = yield* getProjectThread(input);
602 const explicitRun =
603 input.runId === undefined
604 ? undefined
605 : target.runs.find((candidate) => candidate.id === input.runId);
606 if (input.runId !== undefined && explicitRun === undefined) {
607 return yield* new ThreadManagementRunNotFoundError({
608 threadId: input.threadId,
609 runId: input.runId,
610 });
611 }
612 if (explicitRun !== undefined && isTerminalRunStatus(explicitRun.status)) {
613 return {
614 type: "already_terminal",
615 run: explicitRun as OrchestrationV2Run & {
616 readonly status: ThreadManagementTerminalRunStatus;
617 },
618 } as const;
619 }
620 const interruptibleRun = latestActiveRun(target);
621 if (interruptibleRun === undefined) {
622 if (input.runId === undefined) {
623 return { type: "no_active_run" } as const;
624 }
625 return yield* new ThreadManagementThreadNotInterruptibleError({
626 threadId: input.threadId,
627 runId: input.runId,
628 });
629 }
630 if (input.runId !== undefined && interruptibleRun.id !== input.runId) {
631 return yield* new ThreadManagementThreadNotInterruptibleError({
632 threadId: input.threadId,
633 runId: input.runId,
634 });
635 }
636 const dispatch = yield* orchestrator.dispatch({
637 type: "run.interrupt",
638 commandId: input.commandId,
639 threadId: input.threadId,
640 runId: interruptibleRun.id,
641 ...(input.reason === undefined ? {} : { reason: input.reason }),
642 });
643 return { type: "interrupt_requested", run: interruptibleRun, dispatch } as const;
644 });
645
646 return ThreadManagementService.of({
647 ensureLegacyTranscript,
648 dispatch,
649 getThreadProjection,
650 getThreadSnapshot,
651 getProjectThread,
652 getShellSnapshot: orchestrator.getShellSnapshot,
653 getThreadShell: orchestrator.getThreadShell,
654 listProjectThreads,
655 sendToThread,
656 waitForThread,
657 interruptThread,
658 getThreadEventSequence: orchestrator.getThreadEventSequence,
659 streamStoredEvents: orchestrator.streamStoredEvents,
660 streamStoredEventsFrom: orchestrator.streamStoredEventsFrom,
661 streamDomainEvents: orchestrator.streamDomainEvents,
662 });
663});
664
665const legacyV1ThreadImporterNoopLayer = Layer.succeed(
666 LegacyV1ThreadImporter,
667 LegacyV1ThreadImporter.of({
668 pendingThreadCount: Effect.succeed(0),
669 reconcileShells: Effect.succeed({ importedThreadCount: 0, importedMessageCount: 0 }),
670 ensureTranscript: () => Effect.succeed({ importedThreadCount: 0, importedMessageCount: 0 }),
671 importPendingTranscripts: Effect.succeed({ importedThreadCount: 0, importedMessageCount: 0 }),
672 }),
673);
674
675export const layer: Layer.Layer<ThreadManagementService, never, OrchestratorV2> = Layer.effect(
676 ThreadManagementService,
677 make,
678).pipe(Layer.provide(legacyV1ThreadImporterNoopLayer));
679
680export const layerWithLegacyImporter: Layer.Layer<
681 ThreadManagementService,
682 never,
683 LegacyV1ThreadImporter | OrchestratorV2
684> = Layer.effect(ThreadManagementService, make);