authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-10-08 18:05:10-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-10-09 01:05:10+00:00
log2c7a446e657e705c257db28540819f4c0115b2fc
tree36f0376370207f6a7fbca2c57098834b064614a0
parentb0ee7dd48f868c5c02884345f723bebaf616b13d
signature Signed by PGP key B5690EEEBB952194

refactor(providers): namespace-import service modules in core, Muse, Pi, and testing (#17375)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

14 files changed, 112 insertions(+), 117 deletions(-)

packages/provider-core/src/server/adapterDriver.ts+6-2
......@@ -7,7 +7,7 @@ import * as Schema from "effect/Schema";
77import type * as Effect from "effect/Effect";
88import type * as Scope from "effect/Scope";
99
10import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter";
10import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
1111
1212export class ProviderAdapterDriverCreateError extends Schema.TaggedError<ProviderAdapterDriverCreateError>()(
1313 "ProviderAdapterDriverCreateError",
......@@ -38,7 +38,11 @@ export interface ProviderAdapterDriver<Config, R = never> {
3838 readonly defaultConfig: () => Config;
3939 readonly create: (
4040 input: ProviderAdapterDriverCreateInput<Config>,
41 ) => Effect.Effect<ProviderAdapterV2Shape, ProviderAdapterDriverCreateError, R | Scope.Scope>;
41 ) => Effect.Effect<
42 ProviderAdapter.ProviderAdapterV2Shape,
43 ProviderAdapterDriverCreateError,
44 R | Scope.Scope
45 >;
4246}
4347
4448export type AnyProviderAdapterDriver<R = never> = ProviderAdapterDriver<any, R>;
packages/provider-core/src/server/driver.ts+2-2
......@@ -37,7 +37,7 @@ import type * as Effect from "effect/Effect";
3737import type * as Schema from "effect/Schema";
3838import type * as Scope from "effect/Scope";
3939
40import type { ProviderAdapterV2Shape } from "./ProviderAdapter.ts";
40import type * as ProviderAdapter from "./ProviderAdapter.ts";
4141import type { ProviderAuthController } from "./auth.ts";
4242import type { ProviderDriverError } from "./errors.ts";
4343import type { ServerProviderShape } from "./snapshot.ts";
......@@ -101,7 +101,7 @@ export interface ProviderInstance {
101101 ProviderConsumeResetCreditOutcome,
102102 ProviderDriverError
103103 >;
104 readonly orchestrationAdapter: ProviderAdapterV2Shape;
104 readonly orchestrationAdapter: ProviderAdapter.ProviderAdapterV2Shape;
105105 readonly textGeneration: ProviderTextGeneration;
106106 readonly auth?: ProviderAuthController;
107107 readonly acpSessionManagement?: {
packages/provider-core/src/server/failure.test.ts+2-2
......@@ -19,7 +19,7 @@ import {
1919 ContextHandoffBudgetError,
2020} from "./failure.ts";
2121import * as IdAllocator from "./IdAllocator.ts";
22import { ProviderAdapterTurnStartError } from "@t3tools/provider-core/server/ProviderAdapter";
22import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
2323
2424it("redacts credentials and URL secrets from provider failures", () => {
2525 const failure = makeProviderFailure({
......@@ -88,7 +88,7 @@ it("does not expose arbitrary cause messages and preserves explicit messages", (
8888});
8989
9090it("preserves actionable handoff errors wrapped by turn startup", () => {
91 const cause = new ProviderAdapterTurnStartError({
91 const cause = new ProviderAdapter.ProviderAdapterTurnStartError({
9292 driver: ProviderDriverKind.make("codex"),
9393 threadId: ThreadId.make("thread:handoff-error"),
9494 providerThreadId: ProviderThreadId.make("provider-thread:handoff-error"),
packages/provider-core/src/server/failure.ts+3-3
......@@ -13,7 +13,7 @@ import type {
1313import * as DateTime from "effect/DateTime";
1414import * as Cause from "effect/Cause";
1515
16import type { IdAllocatorV2Shape } from "./IdAllocator.ts";
16import type * as IdAllocator from "./IdAllocator.ts";
1717import * as Schema from "effect/Schema";
1818
1919/** Raised when portable history does not fit the target provider's context window. */
......@@ -172,7 +172,7 @@ export function makeProviderFailure(input: {
172172}
173173
174174export function makeProviderFailureTurnItem(input: {
175 readonly idAllocator: IdAllocatorV2Shape;
175 readonly idAllocator: IdAllocator.IdAllocatorV2Shape;
176176 readonly driver: ProviderDriverKind;
177177 readonly threadId: ThreadId;
178178 readonly runId: RunId | null;
......@@ -210,7 +210,7 @@ export function makeProviderFailureTurnItem(input: {
210210}
211211
212212export function makeProviderRetryTurnItem(input: {
213 readonly idAllocator: IdAllocatorV2Shape;
213 readonly idAllocator: IdAllocator.IdAllocatorV2Shape;
214214 readonly driver: ProviderDriverKind;
215215 readonly threadId: ThreadId;
216216 readonly runId: RunId | null;
packages/provider-core/src/server/managedProvider.test.ts+5-5
......@@ -16,7 +16,7 @@ import * as Ref from "effect/Ref";
1616import * as Stream from "effect/Stream";
1717import { TestClock } from "effect/testing";
1818
19import { ProviderHost, type ProviderHostShape } from "./ProviderHost.ts";
19import * as ProviderHost from "./ProviderHost.ts";
2020import { makeManagedServerProvider } from "./managedProvider.ts";
2121
2222const emptyCapabilities = createModelCapabilities({ optionDescriptors: [] });
......@@ -99,11 +99,11 @@ const refreshedSnapshotSecond: ServerProvider = {
9999/** A host whose settings never change and whose background demand is fixed. */
100100function layerProviderHost(input: {
101101 readonly runBackgroundWork: boolean;
102 readonly settings?: Pick<ProviderHostShape, "settings">["settings"];
102 readonly settings?: Pick<ProviderHost.ProviderHostShape, "settings">["settings"];
103103}) {
104104 return Layer.succeed(
105 ProviderHost,
106 ProviderHost.of({
105 ProviderHost.ProviderHost,
106 ProviderHost.ProviderHost.of({
107107 paths: {
108108 cwd: process.cwd(),
109109 baseDir: "/t3",
......@@ -281,7 +281,7 @@ describe("makeManagedServerProvider", () => {
281281 };
282282 const serverSettingsRef = yield* Ref.make(initialServerSettings);
283283 const serverSettingsChanges = yield* PubSub.unbounded<typeof initialServerSettings>();
284 const hostSettings: ProviderHostShape["settings"] = {
284 const hostSettings: ProviderHost.ProviderHostShape["settings"] = {
285285 get: Ref.get(serverSettingsRef),
286286 changes: Stream.empty,
287287 subscribe: PubSub.subscribe(serverSettingsChanges).pipe(
packages/provider-core/src/server/managedProvider.ts+7-3
......@@ -15,7 +15,7 @@ import * as Scope from "effect/Scope";
1515import * as Stream from "effect/Stream";
1616import * as Semaphore from "effect/Semaphore";
1717
18import { ProviderHost } from "./ProviderHost.ts";
18import * as ProviderHost from "./ProviderHost.ts";
1919import { applyUsageLimitsUpdate, resolveUsageLimitsAfterProbe } from "./usageLimits.ts";
2020import type { ServerProviderShape } from "./snapshot.ts";
2121
......@@ -53,8 +53,12 @@ export const makeManagedServerProvider = Effect.fn("makeManagedServerProvider")(
5353 readonly refreshInterval?: Duration.Input;
5454 readonly refreshOnInterval?: boolean;
5555 readonly checkProviderOnSettingsChange?: (previous: Settings, next: Settings) => boolean;
56}): Effect.fn.Return<ServerProviderShape, ServerSettingsError, Scope.Scope | ProviderHost> {
57 const host = yield* ProviderHost;
56}): Effect.fn.Return<
57 ServerProviderShape,
58 ServerSettingsError,
59 Scope.Scope | ProviderHost.ProviderHost
60> {
61 const host = yield* ProviderHost.ProviderHost;
5862 const refreshSemaphore = yield* Semaphore.make(1);
5963 const changesPubSub = yield* Effect.acquireRelease(
6064 PubSub.unbounded<ServerProvider>(),
packages/provider-core/src/server/snapshotSettings.ts+2-2
......@@ -3,7 +3,7 @@ import * as Effect from "effect/Effect";
33import * as Equal from "effect/Equal";
44import * as Stream from "effect/Stream";
55
6import type { ProviderHostShape } from "./ProviderHost.ts";
6import type * as ProviderHost from "./ProviderHost.ts";
77
88export interface ProviderSnapshotSettings<Settings> {
99 readonly provider: Settings;
......@@ -29,7 +29,7 @@ export function haveProviderSnapshotSettingsChanged<Settings>(
2929
3030export function makeProviderSnapshotSettingsSource<Settings>(
3131 provider: Settings,
32 settings: ProviderHostShape["settings"],
32 settings: ProviderHost.ProviderHostShape["settings"],
3333): {
3434 readonly getSettings: Effect.Effect<ProviderSnapshotSettings<Settings>, ServerSettingsError>;
3535 readonly streamSettings: Stream.Stream<ProviderSnapshotSettings<Settings>>;
packages/provider-muse/src/server/adapter.test.ts+20-17
......@@ -31,17 +31,13 @@ import * as Queue from "effect/Queue";
3131import * as Schema from "effect/Schema";
3232import * as Stream from "effect/Stream";
3333
34import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost";
34import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
3535import { layerTestProviderHost } from "@t3tools/provider-testing/host";
3636import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
3737import type { MuseItem } from "./protocol.ts";
3838import type { MuseSdkHost } from "./sdk.ts";
3939import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
40import {
41 ProviderAdapterV2RuntimePolicy,
42 type ProviderAdapterV2Event,
43 type ProviderAdapterV2TurnInput,
44} from "@t3tools/provider-core/server/ProviderAdapter";
40import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
4541import type { ProviderContinuationRequest } from "@t3tools/provider-core/server/continuationRequests";
4642import { makeMuseAdapterV2, type MuseAdapterV2Options } from "./adapter.ts";
4743
......@@ -55,7 +51,7 @@ const INSTANCE_ID = ProviderInstanceId.make("muse_work");
5551const THREAD_ID = ThreadId.make("thread-muse-test");
5652const MODEL = "muse-spark-1.3-contributor";
5753const museSettings = Schema.decodeSync(MuseSettings)({ enabled: true });
58const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({
54const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
5955 runtimeMode: "full-access",
6056 interactionMode: "default",
6157 cwd: null,
......@@ -204,7 +200,7 @@ const makeHarness = Effect.fnUntraced(function* (
204200 settings: museSettings,
205201 environment: { PATH: "/fake/bin" },
206202 idAllocator: yield* IdAllocator.IdAllocatorV2,
207 host: yield* ProviderHost,
203 host: yield* ProviderHost.ProviderHost,
208204 fileSystem: yield* FileSystem.FileSystem,
209205 createHost: async () => (hostCount++ === 0 ? fake.host : (replacement ?? fake).host),
210206 ...overrides,
......@@ -216,8 +212,8 @@ const makeHarness = Effect.fnUntraced(function* (
216212 runtimePolicy: policy,
217213 ...(initialNativeThreadId ? { initialNativeThreadId } : {}),
218214 });
219 const emitted = yield* Queue.unbounded<ProviderAdapterV2Event>();
220 const allEvents: ProviderAdapterV2Event[] = [];
215 const emitted = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
216 const allEvents: ProviderAdapter.ProviderAdapterV2Event[] = [];
221217 const eventsEnded = yield* Deferred.make<Exit.Exit<void, Stream.Error<typeof runtime.events>>>();
222218 yield* runtime.events.pipe(
223219 Stream.runForEach((event) =>
......@@ -236,14 +232,21 @@ const makeHarness = Effect.fnUntraced(function* (
236232 runtimePolicy: policy,
237233 ...(existingProviderThread ? { existingProviderThread } : {}),
238234 });
239 const takeEvent = Effect.fnUntraced(function* <T extends ProviderAdapterV2Event["type"]>(
235 const takeEvent = Effect.fnUntraced(function* <
236 T extends ProviderAdapter.ProviderAdapterV2Event["type"],
237 >(
240238 type: T,
241 predicate: (event: Extract<ProviderAdapterV2Event, { type: T }>) => boolean = () => true,
239 predicate: (
240 event: Extract<ProviderAdapter.ProviderAdapterV2Event, { type: T }>,
241 ) => boolean = () => true,
242242 ) {
243243 while (true) {
244244 const event = yield* Queue.take(emitted);
245 if (event.type === type && predicate(event as Extract<ProviderAdapterV2Event, { type: T }>)) {
246 return event as Extract<ProviderAdapterV2Event, { type: T }>;
245 if (
246 event.type === type &&
247 predicate(event as Extract<ProviderAdapter.ProviderAdapterV2Event, { type: T }>)
248 ) {
249 return event as Extract<ProviderAdapter.ProviderAdapterV2Event, { type: T }>;
247250 }
248251 }
249252 });
......@@ -275,7 +278,7 @@ const turnInput = Effect.fnUntraced(function* (
275278 providerThread: OrchestrationV2ProviderThread,
276279 runOrdinal = 1,
277280 policy = runtimePolicy,
278): Effect.fn.Return<ProviderAdapterV2TurnInput> {
281): Effect.fn.Return<ProviderAdapter.ProviderAdapterV2TurnInput> {
279282 const now = yield* DateTime.now;
280283 const threadId = providerThread.appThreadId ?? THREAD_ID;
281284 const selection = modelSelection(providerThread.providerInstanceId);
......@@ -436,7 +439,7 @@ describe("MuseAdapterV2", () => {
436439 settings: museSettings,
437440 environment: { PATH: "/fake/bin" },
438441 idAllocator: yield* IdAllocator.IdAllocatorV2,
439 host: yield* ProviderHost,
442 host: yield* ProviderHost.ProviderHost,
440443 fileSystem: yield* FileSystem.FileSystem,
441444 createHost: async () => fake.host,
442445 });
......@@ -833,7 +836,7 @@ describe("MuseAdapterV2", () => {
833836 it.effect("keeps a workflow child's approval pending for the user past the turn's end", () =>
834837 Effect.gen(function* () {
835838 const fake = yield* makeFakeMuse();
836 const policy = ProviderAdapterV2RuntimePolicy.make({
839 const policy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
837840 ...runtimePolicy,
838841 runtimeMode: "approval-required",
839842 });
packages/provider-muse/src/server/adapter.ts+39-52
......@@ -35,7 +35,7 @@ import * as Semaphore from "effect/Semaphore";
3535import * as Scope from "effect/Scope";
3636import * as Stream from "effect/Stream";
3737
38import type { ProviderHostShape } from "@t3tools/provider-core/server/ProviderHost";
38import type * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
3939import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
4040import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions";
4141import { museModelCapabilities, resolveMuseReasoningEffort } from "./modelCatalog.ts";
......@@ -63,35 +63,13 @@ import {
6363 type createMuseSdkHost,
6464 type MuseSdkHost,
6565} from "./sdk.ts";
66import type { EventNdjsonLogger } from "@t3tools/provider-core/server/ProviderEventLoggers";
66import type * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers";
6767import {
6868 providerMessageTextWithAttachmentPaths,
6969 isProviderNativeImageAttachment,
7070} from "@t3tools/provider-core/server/attachmentPrompt";
7171import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
72import {
73 ProviderAdapterEnsureThreadError,
74 ProviderAdapterForkThreadError,
75 ProviderAdapterInterruptError,
76 ProviderAdapterOpenSessionError,
77 ProviderAdapterProtocolError,
78 ProviderAdapterReadThreadSnapshotError,
79 ProviderAdapterResumeThreadError,
80 ProviderAdapterRollbackThreadError,
81 ProviderAdapterRuntimeRequestResponseError,
82 ProviderAdapterSteerRunError,
83 ProviderAdapterTurnStartError,
84 ProviderAdapterV2,
85 type ProviderAdapterV2Error,
86 type ProviderAdapterV2Event,
87 type ProviderAdapterV2EnsureThreadInput,
88 type ProviderAdapterV2OpenSessionInput,
89 type ProviderAdapterV2SessionRuntime,
90 type ProviderAdapterV2Shape,
91 type ProviderAdapterV2ThreadSnapshot,
92 type ProviderAdapterV2TurnInput,
93 type ProviderAdapterV2TurnMessage,
94} from "@t3tools/provider-core/server/ProviderAdapter";
72import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
9573import {
9674 backgroundWorkNotification,
9775 type BackgroundWorkReport,
......@@ -102,8 +80,8 @@ import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/sel
10280import { museItemStatus, museToolPresentation } from "./itemPresentation.ts";
10381
10482const MUSE_PROVIDER = ProviderDriverKind.make("muse");
105const isOpenSessionError = Schema.is(ProviderAdapterOpenSessionError);
106const isProtocolError = Schema.is(ProviderAdapterProtocolError);
83const isOpenSessionError = Schema.is(ProviderAdapter.ProviderAdapterOpenSessionError);
84const isProtocolError = Schema.is(ProviderAdapter.ProviderAdapterProtocolError);
10785
10886const MuseProviderCapabilitiesV2 = {
10987 runtimePolicy: { enforcement: "native" },
......@@ -204,12 +182,12 @@ export interface MuseAdapterV2Options {
204182 readonly settings: MuseSettings;
205183 readonly environment: NodeJS.ProcessEnv;
206184 readonly idAllocator: IdAllocator.IdAllocatorV2["Service"];
207 readonly host: ProviderHostShape;
185 readonly host: ProviderHost.ProviderHostShape;
208186 readonly fileSystem: FileSystem.FileSystem;
209187 readonly modelCatalog?: Effect.Effect<ReadonlyArray<ServerProviderModel>>;
210188 readonly createHost?: typeof createMuseSdkHost;
211189 readonly requestTimeoutMs?: number;
212 readonly nativeEventLogger?: EventNdjsonLogger;
190 readonly nativeEventLogger?: ProviderEventLoggers.EventNdjsonLogger;
213191 /** Where a turn Muse starts on its own (a finished workflow's report) asks for its run. */
214192 readonly continuationRequests?: {
215193 readonly offer: (
......@@ -219,7 +197,7 @@ export interface MuseAdapterV2Options {
219197}
220198
221199interface ActiveTurn {
222 readonly input: ProviderAdapterV2TurnInput;
200 readonly input: ProviderAdapter.ProviderAdapterV2TurnInput;
223201 providerTurn: OrchestrationV2ProviderTurn;
224202 readonly nativeId: string;
225203 /** Turns Muse started on its own while this run was active, which this run shows. */
......@@ -267,21 +245,23 @@ const TOOLS_WITH_NATIVE_ROWS = new Set(["write_todos", "request_user_input", "wo
267245const responseAnswerSchema = Schema.Union([Schema.String, Schema.Array(Schema.String)]);
268246
269247/** One scoped Muse host owns one native session; the orchestrator owns app runs and queuing. */
270export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapterV2Shape {
248export function makeMuseAdapterV2(
249 options: MuseAdapterV2Options,
250): ProviderAdapter.ProviderAdapterV2Shape {
271251 const { idAllocator } = options;
272252 const protocolError = (detail: string, payload?: unknown) =>
273 new ProviderAdapterProtocolError({
253 new ProviderAdapter.ProviderAdapterProtocolError({
274254 driver: MUSE_PROVIDER,
275255 detail,
276256 ...(payload === undefined ? {} : { payload }),
277257 });
278 return ProviderAdapterV2.of({
258 return ProviderAdapter.ProviderAdapterV2.of({
279259 instanceId: options.instanceId,
280260 driver: MUSE_PROVIDER,
281261 getCapabilities: () => Effect.succeed(MuseProviderCapabilitiesV2),
282262 planSelectionTransition: () => Effect.succeed(turnScopedSelectionTransition()),
283263 openSession: Effect.fn("MuseAdapterV2.openSession")(function* (
284 input: ProviderAdapterV2OpenSessionInput,
264 input: ProviderAdapter.ProviderAdapterV2OpenSessionInput,
285265 ) {
286266 if (!options.settings.enabled) return yield* protocolError("Muse Code is disabled");
287267 if (input.runtimePolicy.interactionMode === "plan")
......@@ -307,8 +287,8 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
307287 lastError: null,
308288 };
309289 const events = yield* Queue.unbounded<
310 ProviderAdapterV2Event,
311 ProviderAdapterV2Error | Cause.Done
290 ProviderAdapter.ProviderAdapterV2Event,
291 ProviderAdapter.ProviderAdapterV2Error | Cause.Done
312292 >();
313293 type Inbox =
314294 | { type: "notification"; method: string; params: unknown; epoch: number }
......@@ -344,7 +324,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
344324 let wake:
345325 | { readonly nativeId: string; readonly events: Array<[string, unknown]> }
346326 | undefined;
347 const emit = (event: ProviderAdapterV2Event) =>
327 const emit = (event: ProviderAdapter.ProviderAdapterV2Event) =>
348328 Queue.offer(events, event).pipe(Effect.asVoid);
349329 const decode = <A, I>(schema: Schema.Codec<A, I>, data: unknown) =>
350330 Schema.decodeUnknownEffect(schema)(data).pipe(
......@@ -1400,7 +1380,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
14001380 ).pipe(
14011381 Effect.mapError(
14021382 (error) =>
1403 new ProviderAdapterOpenSessionError({
1383 new ProviderAdapter.ProviderAdapterOpenSessionError({
14041384 driver: MUSE_PROVIDER,
14051385 providerSessionId: input.providerSessionId,
14061386 cause: error.cause,
......@@ -1472,7 +1452,9 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
14721452 );
14731453 yield* launchHost();
14741454
1475 const register = Effect.fnUntraced(function* (args: ProviderAdapterV2EnsureThreadInput) {
1455 const register = Effect.fnUntraced(function* (
1456 args: ProviderAdapter.ProviderAdapterV2EnsureThreadInput,
1457 ) {
14761458 if (broken || closed)
14771459 return yield* protocolError("Muse host is unavailable; reopen the session");
14781460 if (active)
......@@ -1592,7 +1574,9 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
15921574 ),
15931575 );
15941576 });
1595 const prompt = Effect.fnUntraced(function* (message: ProviderAdapterV2TurnMessage) {
1577 const prompt = Effect.fnUntraced(function* (
1578 message: ProviderAdapter.ProviderAdapterV2TurnMessage,
1579 ) {
15961580 const parts: SendUserTurnOptions<unknown>["input"] = [];
15971581 const text = providerMessageTextWithAttachmentPaths({
15981582 text: message.text,
......@@ -1635,7 +1619,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
16351619 );
16361620 });
16371621 const start = Effect.fnUntraced(function* (
1638 turnInput: ProviderAdapterV2TurnInput,
1622 turnInput: ProviderAdapter.ProviderAdapterV2TurnInput,
16391623 compact = false,
16401624 ) {
16411625 if (!validateThread(turnInput.providerThread) || broken || closed)
......@@ -1783,7 +1767,10 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
17831767 // Only messages are read back; T3 owns turn and item history.
17841768 const snapshot = Effect.fnUntraced(function* (
17851769 current: OrchestrationV2ProviderThread,
1786 ): Effect.fn.Return<ProviderAdapterV2ThreadSnapshot, ProviderAdapterV2Error> {
1770 ): Effect.fn.Return<
1771 ProviderAdapter.ProviderAdapterV2ThreadSnapshot,
1772 ProviderAdapter.ProviderAdapterV2Error
1773 > {
17871774 const result = yield* request("session/read", { excludeItems: false }, false).pipe(
17881775 Effect.flatMap((value) => decode(MuseSessionResult, value)),
17891776 );
......@@ -1821,7 +1808,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
18211808 providerPayload: items,
18221809 };
18231810 });
1824 const runtime: ProviderAdapterV2SessionRuntime = {
1811 const runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime = {
18251812 instanceId: options.instanceId,
18261813 driver: MUSE_PROVIDER,
18271814 providerSessionId: input.providerSessionId,
......@@ -1836,7 +1823,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
18361823 commands.withPermits(1),
18371824 Effect.mapError(
18381825 (cause) =>
1839 new ProviderAdapterEnsureThreadError({
1826 new ProviderAdapter.ProviderAdapterEnsureThreadError({
18401827 driver: MUSE_PROVIDER,
18411828 threadId: args.threadId,
18421829 cause,
......@@ -1853,7 +1840,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
18531840 commands.withPermits(1),
18541841 Effect.mapError(
18551842 (cause) =>
1856 new ProviderAdapterResumeThreadError({
1843 new ProviderAdapter.ProviderAdapterResumeThreadError({
18571844 driver: MUSE_PROVIDER,
18581845 providerSessionId: input.providerSessionId,
18591846 providerThreadId: args.providerThread.id,
......@@ -1866,7 +1853,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
18661853 commands.withPermits(1),
18671854 Effect.mapError(
18681855 (cause) =>
1869 new ProviderAdapterTurnStartError({
1856 new ProviderAdapter.ProviderAdapterTurnStartError({
18701857 driver: MUSE_PROVIDER,
18711858 threadId: args.threadId,
18721859 providerThreadId: args.providerThread.id,
......@@ -1897,7 +1884,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
18971884 commands.withPermits(1),
18981885 Effect.mapError(
18991886 (cause) =>
1900 new ProviderAdapterSteerRunError({
1887 new ProviderAdapter.ProviderAdapterSteerRunError({
19011888 driver: MUSE_PROVIDER,
19021889 providerThreadId: args.providerThread.id,
19031890 providerTurnId: args.providerTurnId,
......@@ -1946,7 +1933,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
19461933 commands.withPermits(1),
19471934 Effect.mapError(
19481935 (cause) =>
1949 new ProviderAdapterInterruptError({
1936 new ProviderAdapter.ProviderAdapterInterruptError({
19501937 driver: MUSE_PROVIDER,
19511938 providerThreadId: args.providerThread.id,
19521939 providerTurnId: args.providerTurnId,
......@@ -1999,7 +1986,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
19991986 }).pipe(
20001987 Effect.mapError(
20011988 (cause) =>
2002 new ProviderAdapterRuntimeRequestResponseError({
1989 new ProviderAdapter.ProviderAdapterRuntimeRequestResponseError({
20031990 driver: MUSE_PROVIDER,
20041991 requestId: args.requestId,
20051992 cause,
......@@ -2014,7 +2001,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
20142001 commands.withPermits(1),
20152002 Effect.mapError(
20162003 (cause) =>
2017 new ProviderAdapterReadThreadSnapshotError({
2004 new ProviderAdapter.ProviderAdapterReadThreadSnapshotError({
20182005 driver: MUSE_PROVIDER,
20192006 providerThreadId: args.providerThread.id,
20202007 cause,
......@@ -2025,7 +2012,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
20252012 // portable context handoff for forks and does not rewind Muse conversations.
20262013 rollbackThread: (args) =>
20272014 Effect.fail(
2028 new ProviderAdapterRollbackThreadError({
2015 new ProviderAdapter.ProviderAdapterRollbackThreadError({
20292016 driver: MUSE_PROVIDER,
20302017 providerThreadId: args.providerThread.id,
20312018 checkpointId: args.target.checkpointId,
......@@ -2034,7 +2021,7 @@ export function makeMuseAdapterV2(options: MuseAdapterV2Options): ProviderAdapte
20342021 ),
20352022 forkThread: (args) =>
20362023 Effect.fail(
2037 new ProviderAdapterForkThreadError({
2024 new ProviderAdapter.ProviderAdapterForkThreadError({
20382025 driver: MUSE_PROVIDER,
20392026 providerThreadId: args.sourceProviderThread.id,
20402027 cause: "Muse Code does not support native forks in T3 Code.",
packages/provider-muse/src/server/driver.ts+3-3
......@@ -8,7 +8,7 @@ import * as Schema from "effect/Schema";
88import { HttpClient } from "effect/http";
99import { ChildProcessSpawner } from "effect/process";
1010
11import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost";
11import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
1212import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
1313import { makeMuseTextGeneration } from "./textGeneration.ts";
1414import { ProviderDriverError } from "@t3tools/provider-core/server/errors";
......@@ -42,7 +42,7 @@ const decodeMuseSettings = Schema.decodeSync(MuseSettings);
4242
4343export type MuseDriverEnv =
4444 | IdAllocator.IdAllocatorV2
45 | ProviderHost
45 | ProviderHost.ProviderHost
4646 | ChildProcessSpawner.ChildProcessSpawner
4747 | FileSystem.FileSystem
4848 | HttpClient.HttpClient
......@@ -60,7 +60,7 @@ export const MuseDriver: ProviderDriver<MuseSettings, MuseDriverEnv> = {
6060 const fileSystem = yield* FileSystem.FileSystem;
6161 const path = yield* Path.Path;
6262 const httpClient = yield* HttpClient.HttpClient;
63 const host = yield* ProviderHost;
63 const host = yield* ProviderHost.ProviderHost;
6464 const eventLoggers = yield* ProviderEventLoggers.ProviderEventLoggers;
6565 const { cwd } = host.paths;
6666 const idAllocator = yield* IdAllocator.IdAllocatorV2;
packages/provider-pi/src/server/adapter.test.ts+10-13
......@@ -33,16 +33,12 @@ import * as TestClock from "effect/testing/TestClock";
3333import { ChildProcess, ChildProcessSpawner } from "effect/process";
3434import { HostProcessEnvironment } from "@t3tools/shared/hostProcess";
3535
36import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost";
36import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
3737import { layerTestProviderHost } from "@t3tools/provider-testing/host";
3838import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests";
3939import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
4040import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
41import {
42 ProviderAdapterV2RuntimePolicy,
43 type ProviderAdapterV2Event,
44 type ProviderAdapterV2SessionRuntime,
45} from "@t3tools/provider-core/server/ProviderAdapter";
41import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
4642import { handoffBudget } from "@t3tools/provider-core/server/handoffBudget";
4743import {
4844 makePiAdapterV2,
......@@ -68,7 +64,7 @@ const FAKE_SESSION_FILE = "/fake/.pi/agent/sessions/--workspace--/0001_abc.jsonl
6864/** Deliberately outside the valid pid range so a group-kill can never land. */
6965const FAKE_PID = 999_999_999;
7066
71const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({
67const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
7268 runtimeMode: "full-access",
7369 interactionMode: "default",
7470 cwd: null,
......@@ -331,7 +327,7 @@ const makeAdapter = Effect.fnUntraced(function* (
331327 continuationRequests?: PiAdapterV2Options["continuationRequests"],
332328) {
333329 const idAllocator = yield* IdAllocator.IdAllocatorV2;
334 const host = yield* ProviderHost;
330 const host = yield* ProviderHost.ProviderHost;
335331 const fileSystem = yield* FileSystem.FileSystem;
336332 const spawner =
337333 forkFake === undefined
......@@ -383,12 +379,12 @@ const openRuntime = Effect.fnUntraced(function* (
383379 modelSelection: modelSelection(model),
384380 runtimePolicy,
385381 });
386 const emitted = yield* Queue.unbounded<ProviderAdapterV2Event>();
382 const emitted = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
387383 yield* runtime.events.pipe(
388384 Stream.runForEach((event) => Queue.offer(emitted, event)),
389385 Effect.forkScoped,
390386 );
391 const takeEvent = (predicate: (event: ProviderAdapterV2Event) => boolean) =>
387 const takeEvent = (predicate: (event: ProviderAdapter.ProviderAdapterV2Event) => boolean) =>
392388 Effect.gen(function* () {
393389 while (true) {
394390 const event = yield* Queue.take(emitted);
......@@ -426,7 +422,7 @@ const makeAppThread = Effect.fnUntraced(function* (model: string, threadId = THR
426422});
427423
428424const startTurn = Effect.fnUntraced(function* (
429 runtime: ProviderAdapterV2SessionRuntime,
425 runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime,
430426 providerThread: OrchestrationV2ProviderThread,
431427 model = "default",
432428 attachments: ReadonlyArray<ChatAttachment> = [],
......@@ -832,8 +828,9 @@ describe("PiAdapterV2", () => {
832828 });
833829 yield* fake.emit({ type: "agent_start" });
834830 yield* Queue.take(offers);
835 const requests: Array<Extract<ProviderAdapterV2Event, { type: "runtime_request.updated" }>> =
836 [];
831 const requests: Array<
832 Extract<ProviderAdapter.ProviderAdapterV2Event, { type: "runtime_request.updated" }>
833 > = [];
837834 fake.deferNextModelSelection();
838835 const starting = yield* startTurn(
839836 runtime,
packages/provider-pi/src/server/adapter.ts+5-5
......@@ -60,7 +60,7 @@ import * as Semaphore from "effect/Semaphore";
6060import * as Stream from "effect/Stream";
6161import { ChildProcessSpawner } from "effect/process";
6262
63import { ProviderHost, type ProviderHostShape } from "@t3tools/provider-core/server/ProviderHost";
63import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
6464import { mcpToolPresentation } from "@t3tools/provider-core/server/mcpToolPresentation";
6565import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession";
6666import {
......@@ -231,7 +231,7 @@ export interface PiAdapterV2Options {
231231 readonly spawner: ChildProcessSpawner.ChildProcessSpawner["Service"];
232232 readonly fileSystem: FileSystem.FileSystem;
233233 readonly idAllocator: IdAllocator.IdAllocatorV2["Service"];
234 readonly host: ProviderHostShape;
234 readonly host: ProviderHost.ProviderHostShape;
235235 readonly continuationRequests?: {
236236 readonly offer: (
237237 request: ProviderContinuationRequests.ProviderContinuationRequest,
......@@ -3201,7 +3201,7 @@ export type PiAdapterV2DriverEnv =
32013201 | ChildProcessSpawner.ChildProcessSpawner
32023202 | FileSystem.FileSystem
32033203 | IdAllocator.IdAllocatorV2
3204 | ProviderHost;
3204 | ProviderHost.ProviderHost;
32053205
32063206export const PiAdapterV2Driver: ProviderAdapterDriver<PiSettings, PiAdapterV2DriverEnv> = {
32073207 driverKind: PI_DRIVER_KIND,
......@@ -3213,7 +3213,7 @@ export const PiAdapterV2Driver: ProviderAdapterDriver<PiSettings, PiAdapterV2Dri
32133213 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
32143214 const fileSystem = yield* FileSystem.FileSystem;
32153215 const idAllocator = yield* IdAllocator.IdAllocatorV2;
3216 const host = yield* ProviderHost;
3216 const host = yield* ProviderHost.ProviderHost;
32173217 const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
32183218 return makePiAdapterV2({
32193219 instanceId: input.instanceId,
......@@ -3249,7 +3249,7 @@ const layer: Layer.Layer<ProviderAdapter.ProviderAdapterV2, never, PiAdapterV2Dr
32493249 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
32503250 const fileSystem = yield* FileSystem.FileSystem;
32513251 const idAllocator = yield* IdAllocator.IdAllocatorV2;
3252 const host = yield* ProviderHost;
3252 const host = yield* ProviderHost.ProviderHost;
32533253 const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
32543254 return makePiAdapterV2({
32553255 instanceId: PI_DEFAULT_INSTANCE_ID,
packages/provider-pi/src/server/driver.ts+3-3
......@@ -15,7 +15,7 @@ import * as Schema from "effect/Schema";
1515import { HttpClient } from "effect/http";
1616import { ChildProcessSpawner } from "effect/process";
1717
18import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost";
18import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
1919import { makePiTextGeneration } from "./textGeneration.ts";
2020import { PiAdapterV2Driver, type PiAdapterV2DriverEnv } from "./adapter.ts";
2121import { ProviderDriverError } from "@t3tools/provider-core/server/errors";
......@@ -56,7 +56,7 @@ const UPDATE = makePackageManagedProviderMaintenanceResolver({
5656
5757export type PiDriverEnv =
5858 | PiAdapterV2DriverEnv
59 | ProviderHost
59 | ProviderHost.ProviderHost
6060 | ChildProcessSpawner.ChildProcessSpawner
6161 | FileSystem.FileSystem
6262 | HttpClient.HttpClient
......@@ -92,7 +92,7 @@ export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv> = {
9292 const fileSystem = yield* FileSystem.FileSystem;
9393 const pathService = yield* Path.Path;
9494 const httpClient = yield* HttpClient.HttpClient;
95 const host = yield* ProviderHost;
95 const host = yield* ProviderHost.ProviderHost;
9696 const { cwd } = host.paths;
9797 const processEnv = mergeProviderInstanceEnvironment(environment);
9898 const continuationIdentity = defaultProviderContinuationIdentity({
packages/provider-testing/src/host.ts+5-5
......@@ -1,12 +1,12 @@
11/**
2 * A `ProviderHost` for driver and adapter tests. Its directories live in a
2 * A `ProviderHost.ProviderHost` for driver and adapter tests. Its directories live in a
33 * scoped temp directory, settings are fixed, and background work always runs
44 * unless the test says otherwise.
55 *
66 * @module provider-testing/host
77 */
88import { DEFAULT_SERVER_SETTINGS, type ServerSettings } from "@t3tools/contracts";
9import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost";
9import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
1010import * as Effect from "effect/Effect";
1111import * as FileSystem from "effect/FileSystem";
1212import * as Layer from "effect/Layer";
......@@ -23,9 +23,9 @@ export interface TestProviderHostOptions {
2323
2424export const layerTestProviderHost = (
2525 options: TestProviderHostOptions = {},
26): Layer.Layer<ProviderHost, never, FileSystem.FileSystem | Path.Path> =>
26): Layer.Layer<ProviderHost.ProviderHost, never, FileSystem.FileSystem | Path.Path> =>
2727 Layer.effect(
28 ProviderHost,
28 ProviderHost.ProviderHost,
2929 Effect.gen(function* () {
3030 const fileSystem = yield* FileSystem.FileSystem;
3131 const path = yield* Path.Path;
......@@ -39,7 +39,7 @@ export const layerTestProviderHost = (
3939 yield* fileSystem.makeDirectory(directory, { recursive: true }).pipe(Effect.orDie);
4040 }
4141 const settings = options.settings ?? DEFAULT_SERVER_SETTINGS;
42 return ProviderHost.of({
42 return ProviderHost.ProviderHost.of({
4343 paths: { cwd: options.cwd ?? process.cwd(), baseDir, stateDir, providerStatusCacheDir },
4444 settings: {
4545 get: Effect.succeed(settings),