Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadManagementService.ts

682 lines23.3 KB

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