From b66dd402e86899c3fb4341d46c32d0d69df1eefc Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 9 Oct 2026 09:15:21 -0700 Subject: [PATCH] refactor(provider-core): follow the Effect service conventions throughout (#17427) Co-authored-by: Claude Opus 5.5 --- .../record-claude-agent-sdk-replay-fixture.ts | 9 +- .../scripts/record-grok-acp-replay-fixture.ts | 6 +- .../server/src/mcp/McpToolAccess.race.test.ts | 4 +- .../src/mcp/OrchestratorMcpService.test.ts | 6 +- ...OrchestratorMcpToolkit.integration.test.ts | 27 +- .../server/src/mcpApps/McpAppRequests.test.ts | 13 +- apps/server/src/mcpApps/McpAppRequests.ts | 11 +- .../AcpRegistryOrchestratorV2.live.test.ts | 2 +- .../Adapters/AcpAdapterV2.test.ts | 360 +++++++++--------- .../Adapters/AcpRegistryAdapterV2.test.ts | 8 +- .../Adapters/AntigravityAdapterV2.test.ts | 10 +- .../Adapters/ClaudeAdapterV2.test.ts | 168 ++++---- .../Adapters/ClaudeAdapterV2.ts | 18 +- .../Adapters/CodexAdapterV2.test.ts | 165 +++++--- .../Adapters/CodexAdapterV2.testkit.ts | 4 +- .../Adapters/CodexAdapterV2.ts | 208 +++++----- .../Adapters/CursorAdapterV2.testkit.ts | 4 +- .../Adapters/GrokAdapterV2.test.ts | 10 +- .../Adapters/GrokAdapterV2.testkit.ts | 2 +- .../Adapters/MuseAdapterV2.testkit.ts | 2 +- .../Adapters/OpenCode2AdapterV2.test.ts | 60 +-- .../Adapters/OpenCodeAdapterV2.testkit.ts | 2 +- .../BackgroundWorkStop.integration.test.ts | 15 +- .../CheckpointCaptureService.ts | 2 +- .../CheckpointRollbackService.test.ts | 4 +- .../CheckpointRollbackService.ts | 10 +- .../src/orchestration-v2/CheckpointService.ts | 4 +- .../ContextHandoffBudget.test.ts | 6 +- .../ContextHandoffDelivery.ts | 4 +- .../CursorOrchestratorV2.live.test.ts | 2 +- .../DelegatedCompletionDelivery.test.ts | 4 +- .../DispatchModeLimit.test.ts | 4 +- .../GrokOrchestratorV2.live.test.ts | 2 +- .../OpenCode2OrchestratorV2.live.test.ts | 4 +- .../Orchestrator.control-reads.test.ts | 4 +- .../src/orchestration-v2/Orchestrator.ts | 14 +- .../ProviderAdapterRegistry.test.ts | 25 +- .../ProviderAdapterRegistry.ts | 16 +- .../ProviderContinuationService.test.ts | 2 +- .../ProviderContinuationService.ts | 2 +- .../orchestration-v2/ProviderEventIngestor.ts | 9 +- .../ProviderSessionManager.test.ts | 34 +- .../ProviderSessionManager.ts | 68 ++-- .../ProviderSwitchService.test.ts | 8 +- .../ProviderTurnControlService.test.ts | 4 +- .../ProviderTurnStartService.test.ts | 6 +- .../ProviderTurnStartService.ts | 23 +- .../RunExecutionService.test.ts | 143 ++++--- .../orchestration-v2/RunExecutionService.ts | 31 +- .../src/orchestration-v2/RuntimePolicy.ts | 11 +- .../RuntimeRequestService.test.ts | 6 +- .../SelectionRestart.integration.test.ts | 23 +- .../SteeringCompletion.integration.test.ts | 21 +- .../src/orchestration-v2/ThreadDeletion.ts | 6 +- .../ThreadFork.execution.test.ts | 4 +- .../ThreadLaunchService.test.ts | 4 +- .../src/orchestration-v2/ThreadStop.test.ts | 4 +- .../ThreadTitleRegenerationService.test.ts | 4 +- .../assistantStreaming.test.ts | 8 +- .../orchestration-v2/assistantStreaming.ts | 7 +- .../LegacyV1Cutover.integration.test.ts | 14 +- .../src/orchestration-v2/runtimeLayer.test.ts | 11 +- .../src/orchestration-v2/runtimeLayer.ts | 2 +- .../testkit/ProviderReplayHarness.ts | 2 +- .../ProviderSwitch.integration.test.ts | 25 +- apps/server/src/provider/CodexChatGptAuth.ts | 4 +- .../Drivers/AntigravityDriver.test.ts | 2 +- .../src/provider/Drivers/AntigravityDriver.ts | 10 +- .../src/provider/Drivers/ClaudeDriver.ts | 9 +- .../src/provider/Drivers/CodexDriver.test.ts | 6 +- .../src/provider/Drivers/CodexDriver.ts | 9 +- .../provider/Drivers/CodexManagedProvider.ts | 4 +- apps/server/src/provider/EventNdjsonLogger.ts | 24 +- .../src/provider/ProviderEventLoggers.ts | 71 ---- apps/server/src/provider/ProviderHostLive.ts | 8 +- .../provider/ProviderInstanceRegistry.test.ts | 2 +- .../ProviderInstanceRegistryHydration.ts | 6 +- ...viderOrchestrationAdapterInfrastructure.ts | 2 +- .../src/provider/ProviderRegistry.test.ts | 2 +- apps/server/src/server.ts | 36 +- .../provider-acp-registry/src/server/auth.ts | 2 +- .../src/server/driver.ts | 8 +- packages/provider-acp/src/server/adapter.ts | 9 +- packages/provider-core/package.json | 14 +- .../provider-core/src/server/IdAllocator.ts | 108 +++--- .../src/server/ProviderAdapter.ts | 35 +- ...sts.ts => ProviderContinuationRequests.ts} | 2 +- .../provider-core/src/server/ProviderHost.ts | 59 ++- .../provider-core/src/server/adapterDriver.ts | 2 +- packages/provider-core/src/server/driver.ts | 2 +- packages/provider-core/src/server/failure.ts | 8 +- ...hFlow.test.ts => providerAuthFlow.test.ts} | 2 +- ...roviderAuthFlow.ts => providerAuthFlow.ts} | 0 .../src/server/snapshotSettings.ts | 34 +- .../provider-cursor/src/server/adapter.ts | 2 +- packages/provider-cursor/src/server/driver.ts | 2 +- packages/provider-grok/src/server/adapter.ts | 2 +- packages/provider-grok/src/server/driver.ts | 2 +- .../provider-muse/src/server/adapter.test.ts | 4 +- packages/provider-muse/src/server/adapter.ts | 2 +- packages/provider-muse/src/server/driver.ts | 4 +- .../provider-opencode/src/server/adapter.ts | 4 +- .../provider-opencode/src/server/driver.ts | 8 +- .../src/server/v2/adapter.ts | 4 +- .../provider-pi/src/server/adapter.test.ts | 2 +- packages/provider-pi/src/server/adapter.ts | 3 +- packages/provider-pi/src/server/driver.ts | 2 +- 107 files changed, 1123 insertions(+), 1099 deletions(-) delete mode 100644 apps/server/src/provider/ProviderEventLoggers.ts rename packages/provider-core/src/server/{continuationRequests.ts => ProviderContinuationRequests.ts} (97%) rename packages/provider-core/src/server/{ProviderAuthFlow.test.ts => providerAuthFlow.test.ts} (99%) rename packages/provider-core/src/server/{ProviderAuthFlow.ts => providerAuthFlow.ts} (100%) diff --git a/apps/server/scripts/record-claude-agent-sdk-replay-fixture.ts b/apps/server/scripts/record-claude-agent-sdk-replay-fixture.ts index 970c1faf1e14d7e7092cacc3e1e733c55cb58115..a509ed8c88dee38e0a3d64c1aa8f6c1480b9b761 100644 --- a/apps/server/scripts/record-claude-agent-sdk-replay-fixture.ts +++ b/apps/server/scripts/record-claude-agent-sdk-replay-fixture.ts @@ -10,10 +10,7 @@ import { CLAUDE_AGENT_SDK_REPLAY_PROTOCOL, } from "../src/orchestration-v2/Adapters/ClaudeAdapterV2.testkit.ts"; import { claudeRuntimeQueryPolicyForRuntimePolicy } from "../src/orchestration-v2/Adapters/ClaudeAdapterV2.ts"; -import { - ProviderAdapterV2RuntimePolicy, - type ProviderAdapterV2RuntimePolicy as ProviderAdapterV2RuntimePolicyType, -} from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import type { RuntimePolicyV2Override } from "../src/orchestration-v2/RuntimePolicy.ts"; import { makeCheckpointWorkspace } from "@t3tools/provider-testing/replayWorkspace"; import { CLAUDE_MODEL_SELECTION } from "../src/orchestration-v2/testkit/fixtures/shared.ts"; @@ -440,8 +437,8 @@ validateClaudeReplayRecordingSelection({ function runtimePolicyForRecording(input: { readonly cwd: string; readonly override?: RuntimePolicyV2Override; -}): ProviderAdapterV2RuntimePolicyType { - return ProviderAdapterV2RuntimePolicy.make({ +}): ProviderAdapter.ProviderAdapterV2RuntimePolicy { + return ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: input.override?.cwd ?? input.cwd, diff --git a/apps/server/scripts/record-grok-acp-replay-fixture.ts b/apps/server/scripts/record-grok-acp-replay-fixture.ts index fbf381f50537e0184ba3d689d8aacf3a0ca01b89..da8b17fec5672b4f33943b8e013ad92161329ab6 100644 --- a/apps/server/scripts/record-grok-acp-replay-fixture.ts +++ b/apps/server/scripts/record-grok-acp-replay-fixture.ts @@ -33,8 +33,8 @@ import { } from "@t3tools/provider-grok/testing"; import { ACP_PROTOCOL } from "@t3tools/provider-acp/server/adapter"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import type { ProviderAdapterV2SessionRuntime } from "@t3tools/provider-core/server/ProviderAdapter"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import * as ProviderAdapterRegistry from "../src/orchestration-v2/ProviderAdapterRegistry.ts"; import { provideDeterministicTestRuntime } from "../src/orchestration-v2/testkit/DeterministicRuntime.ts"; import { ORCHESTRATOR_REPLAY_FIXTURES } from "../src/orchestration-v2/testkit/fixtures/index.ts"; @@ -474,7 +474,7 @@ const recordScenario = Effect.fn("recordGrokScenario")(function* (fixtureName: s ...adapter, openSession: (input) => adapter.openSession(input).pipe( - Effect.map((session): ProviderAdapterV2SessionRuntime => ({ + Effect.map((session): ProviderAdapter.ProviderAdapterV2SessionRuntime => ({ ...session, startTurn: (turnInput) => onWallClock(session.startTurn(turnInput)), steerTurn: (turnInput) => onWallClock(session.steerTurn(turnInput)), diff --git a/apps/server/src/mcp/McpToolAccess.race.test.ts b/apps/server/src/mcp/McpToolAccess.race.test.ts index 52458c8401e89f697e0359113be559f259b52ab9..46522810f707cadb95494d457f09276978fea819 100644 --- a/apps/server/src/mcp/McpToolAccess.race.test.ts +++ b/apps/server/src/mcp/McpToolAccess.race.test.ts @@ -19,13 +19,13 @@ import { DispatchModeLimit } from "../orchestration-v2/DispatchModeLimit.ts"; import { CodexProviderCapabilitiesV2 } from "../orchestration-v2/Adapters/CodexAdapterV2.ts"; import * as Orchestrator from "../orchestration-v2/Orchestrator.ts"; import * as ProjectionStore from "../orchestration-v2/ProjectionStore.ts"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "../orchestration-v2/ProviderAdapterRegistry.ts"; import * as ThreadManagement from "../orchestration-v2/ThreadManagementService.ts"; import * as ProviderReplayHarness from "../orchestration-v2/testkit/ProviderReplayHarness.ts"; import * as McpHttpServer from "./McpHttpServer.ts"; import * as McpInvocationContext from "./McpInvocationContext.ts"; import * as McpToolAccess from "./McpToolAccess.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; // A Supervised outside agent renames a thread through a `writesThreads` tool. // The thread's user raises it to full access after the tool's check but @@ -38,7 +38,7 @@ const adapter = { getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2), planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" as const }), openSession: () => Effect.die("No provider process needed for metadata commands"), -} as ProviderAdapterV2Shape; +} as ProviderAdapter.ProviderAdapterV2["Service"]; const layerDatabase = SqlitePersistence.layerMemory; const layerOrchestrator = Layer.mergeAll( layerDatabase, diff --git a/apps/server/src/mcp/OrchestratorMcpService.test.ts b/apps/server/src/mcp/OrchestratorMcpService.test.ts index eaa776173af33c462e2f4727852c4cdbe0d2fee2..2b2033779f210aa70c354cecfdf90f8e1b060906 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.test.ts @@ -28,7 +28,6 @@ import { OrchestratorProjectionError, OrchestratorThreadAboveModeLimitError, } from "../orchestration-v2/Orchestrator.ts"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "../orchestration-v2/ProviderAdapterRegistry.ts"; import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts"; import * as ProviderRegistry from "../provider/ProviderRegistry.ts"; @@ -39,6 +38,7 @@ import * as SecretRequests from "../secrets/SecretRequests.ts"; import type { McpInvocationScope } from "./McpInvocationContext.ts"; import { idleThreadProjection, liveThreadShell } from "./McpToolAccess.testkit.ts"; import * as OrchestratorMcpService from "./OrchestratorMcpService.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; describe("OrchestratorMcpService", () => { it.effect("retries terminal acknowledgement with a fresh command id", () => @@ -810,7 +810,9 @@ describe("OrchestratorMcpService provider resolution", () => { list: () => Effect.succeed(instanceIds), get: (instanceId) => instanceIds.includes(instanceId) - ? Effect.succeed({ instanceId } as unknown as ProviderAdapterV2Shape) + ? Effect.succeed({ + instanceId, + } as unknown as ProviderAdapter.ProviderAdapterV2["Service"]) : Effect.fail( new ProviderAdapterRegistry.ProviderAdapterRegistryLookupError({ instanceId }), ), diff --git a/apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts b/apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts index f4aa8bafbe6666905f5e63355ad871edd73745fd..02c780b35946eeb49d25f4be6976a67b7d046ab2 100644 --- a/apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts @@ -57,14 +57,8 @@ import { threadShellFromProjection } from "../orchestration-v2/ProjectionStore.t import * as EventSink from "../orchestration-v2/EventSink.ts"; import * as Orchestrator from "../orchestration-v2/Orchestrator.ts"; import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts"; -import { - type ProviderAdapterV2Event, - ProviderAdapterProtocolError, - type ProviderAdapterV2Shape, - type ProviderAdapterV2TurnInput, -} from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "../orchestration-v2/ProviderAdapterRegistry.ts"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace"; import * as ProviderReplayHarness from "../orchestration-v2/testkit/ProviderReplayHarness.ts"; import { @@ -79,6 +73,7 @@ import * as ServerSecretStore from "../auth/ServerSecretStore.ts"; import * as McpHttpServer from "./McpHttpServer.ts"; import * as McpInvocationContext from "./McpInvocationContext.ts"; import { delegatedTaskRun, hasPendingChildRuns } from "./OrchestratorMcpService.ts"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; // Effect returns a declared tool failure as `isError` with its encoded payload // as JSON text, never as `structuredContent`. @@ -146,7 +141,7 @@ interface CapturedTurn { } function unsupported(driver: ProviderDriverKind, detail: string) { - return Effect.fail(new ProviderAdapterProtocolError({ driver, detail })); + return Effect.fail(new ProviderAdapter.ProviderAdapterProtocolError({ driver, detail })); } function makeProviderSnapshot(input: { @@ -185,10 +180,12 @@ function makeDeterministicAdapter(input: { readonly driver: ProviderDriverKind; readonly capabilities: OrchestrationV2ProviderCapabilities; readonly capturedTurns: Ref.Ref>; - readonly shouldComplete: (turn: ProviderAdapterV2TurnInput) => boolean; - readonly terminalGate?: (turn: ProviderAdapterV2TurnInput) => Deferred.Deferred | undefined; - readonly response: (turn: ProviderAdapterV2TurnInput) => string; -}): ProviderAdapterV2Shape { + readonly shouldComplete: (turn: ProviderAdapter.ProviderAdapterV2TurnInput) => boolean; + readonly terminalGate?: ( + turn: ProviderAdapter.ProviderAdapterV2TurnInput, + ) => Deferred.Deferred | undefined; + readonly response: (turn: ProviderAdapter.ProviderAdapterV2TurnInput) => string; +}): ProviderAdapter.ProviderAdapterV2["Service"] { return { instanceId: input.instanceId, driver: input.driver, @@ -196,7 +193,7 @@ function makeDeterministicAdapter(input: { planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" }), openSession: (sessionInput) => Effect.gen(function* () { - const events = yield* PubSub.unbounded(); + const events = yield* PubSub.unbounded(); const now = yield* DateTime.now; const providerSession: OrchestrationV2ProviderSession = { id: sessionInput.providerSessionId, @@ -211,12 +208,12 @@ function makeDeterministicAdapter(input: { lastError: null, }; - const publish = (providerEvents: ReadonlyArray) => + const publish = (providerEvents: ReadonlyArray) => Effect.forEach(providerEvents, (event) => PubSub.publish(events, event), { discard: true, }); const runOrdinals = new Map(); - const turnInputs = new Map(); + const turnInputs = new Map(); return { instanceId: input.instanceId, diff --git a/apps/server/src/mcpApps/McpAppRequests.test.ts b/apps/server/src/mcpApps/McpAppRequests.test.ts index ce2d6428091c0e251e55ea8d16f81c4847246c73..dfd01ad27daa8d396d8048bfff66c5a3b1291477 100644 --- a/apps/server/src/mcpApps/McpAppRequests.test.ts +++ b/apps/server/src/mcpApps/McpAppRequests.test.ts @@ -14,10 +14,7 @@ import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; import * as Orchestrator from "../orchestration-v2/Orchestrator.ts"; -import type { - ProviderAdapterV2McpApps, - ProviderAdapterV2SessionRuntime, -} from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderSessionManager from "../orchestration-v2/ProviderSessionManager.ts"; import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts"; import * as McpAppModelContext from "./McpAppModelContext.ts"; @@ -71,7 +68,7 @@ const storedContext = new Map(); function makeLayer(input: { readonly item: OrchestrationV2TurnItem | null; - readonly mcpApps?: ProviderAdapterV2McpApps; + readonly mcpApps?: ProviderAdapter.ProviderAdapterV2McpApps; readonly live?: boolean; }) { return McpAppRequests.layer.pipe( @@ -121,7 +118,9 @@ function makeLayer(input: { : Option.some( (input.mcpApps === undefined ? {} - : { mcpApps: input.mcpApps }) as ProviderAdapterV2SessionRuntime, + : { + mcpApps: input.mcpApps, + }) as ProviderAdapter.ProviderAdapterV2SessionRuntime, ), ), }), @@ -138,7 +137,7 @@ const reason = (effect: Effect.Effect) => describe("McpAppRequests", () => { const calls: Array<{ server: string; tool: string }> = []; - const mcpApps: ProviderAdapterV2McpApps = { + const mcpApps: ProviderAdapter.ProviderAdapterV2McpApps = { listTools: () => Effect.succeed([ { name: "refresh", annotations: { readOnlyHint: true } }, diff --git a/apps/server/src/mcpApps/McpAppRequests.ts b/apps/server/src/mcpApps/McpAppRequests.ts index 41902c528aebcac8a502ab30cf70353bcb401a21..ee8f6d521324d04b9bd783e456930e297537070c 100644 --- a/apps/server/src/mcpApps/McpAppRequests.ts +++ b/apps/server/src/mcpApps/McpAppRequests.ts @@ -21,10 +21,7 @@ import * as Predicate from "effect/Predicate"; import * as Schema from "effect/Schema"; import * as Orchestrator from "../orchestration-v2/Orchestrator.ts"; -import type { - ProviderAdapterV2McpApps, - ProviderAdapterV2McpTool, -} from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderSessionManager from "../orchestration-v2/ProviderSessionManager.ts"; import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts"; import * as McpAppModelContext from "./McpAppModelContext.ts"; @@ -57,10 +54,10 @@ export class McpAppRequests extends Context.Service< const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown)); const utf8 = new TextEncoder(); -const readOnlyHint = (tool: ProviderAdapterV2McpTool) => +const readOnlyHint = (tool: ProviderAdapter.ProviderAdapterV2McpTool) => Predicate.isObject(tool.annotations) && tool.annotations.readOnlyHint === true; -const toolTitle = (tool: ProviderAdapterV2McpTool) => +const toolTitle = (tool: ProviderAdapter.ProviderAdapterV2McpTool) => Predicate.isObject(tool.annotations) && typeof tool.annotations.title === "string" ? tool.annotations.title : undefined; @@ -112,7 +109,7 @@ const make = Effect.gen(function* () { .pipe(Effect.mapError((cause) => fail(input.threadId, "request-failed", cause))), ); if (runtime === undefined) return yield* fail(input.threadId, "session-stopped"); - const mcpApps: ProviderAdapterV2McpApps | undefined = runtime.mcpApps; + const mcpApps: ProviderAdapter.ProviderAdapterV2McpApps | undefined = runtime.mcpApps; if (mcpApps === undefined) return yield* fail(input.threadId, "provider-unsupported"); return { app, providerThread, mcpApps }; }); diff --git a/apps/server/src/orchestration-v2/AcpRegistryOrchestratorV2.live.test.ts b/apps/server/src/orchestration-v2/AcpRegistryOrchestratorV2.live.test.ts index 4f2ea3e2f3d61e0d6d9c52b0a8c55058e4094690..f39c1c2115328574a1c09d5c0dc12988c9e90b98 100644 --- a/apps/server/src/orchestration-v2/AcpRegistryOrchestratorV2.live.test.ts +++ b/apps/server/src/orchestration-v2/AcpRegistryOrchestratorV2.live.test.ts @@ -29,7 +29,7 @@ import * as CodexInstallation from "../provider/CodexInstallation.ts"; import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; import * as ModelManifest from "../provider/ModelManifest.ts"; import * as ProviderInstanceRegistryHydration from "../provider/ProviderInstanceRegistryHydration.ts"; -import * as ProviderEventLoggers from "../provider/ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as OpenCodeRuntime from "@t3tools/provider-opencode/server/OpenCodeRuntime"; import * as OpenCodeServerLedger from "@t3tools/provider-opencode/server/OpenCodeServerLedger"; import * as ServerSettings from "../serverSettings.ts"; diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index bda7b91e735a57b65ee8c80e6dffde200ad1282e..f1f33d43233f3285fdedad0d783fe4ef0a2b3806 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -64,13 +64,8 @@ import { registerXAiBackgroundTaskTracking, } from "@t3tools/provider-grok/testing"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import { - ProviderAdapterProtocolError, - ProviderAdapterV2RuntimePolicy, - type ProviderAdapterV2Event, - type ProviderAdapterV2TurnInput, -} from "@t3tools/provider-core/server/ProviderAdapter"; -import type { ProviderContinuationRequest } from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { AcpProviderCapabilitiesV2, acpProviderItemNativeId, @@ -540,7 +535,7 @@ function makeTurnInput(input: { readonly threadId: ThreadId; readonly providerThread: OrchestrationV2ProviderThread; readonly instanceId: ProviderInstanceId; - readonly runtimePolicy: ProviderAdapterV2RuntimePolicy; + readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy; readonly now: DateTime.Utc; readonly ordinal?: number; readonly modelSelection?: ModelSelection; @@ -548,7 +543,7 @@ function makeTurnInput(input: { readonly messageCreatedBy?: "user" | "agent"; readonly messageCreationSource?: "web" | "mobile" | "mcp" | "provider" | "server"; readonly messageText?: string; -}): ProviderAdapterV2TurnInput { +}): ProviderAdapter.ProviderAdapterV2TurnInput { const ordinal = input.ordinal ?? 1; const suffix = `${input.threadId}:${ordinal}`; const modelSelection = @@ -625,7 +620,7 @@ describe("AcpAdapterV2", () => { }), }, }); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -742,7 +737,7 @@ describe("AcpAdapterV2", () => { }, selfInvocation, }); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -799,7 +794,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const policy = (interactionMode: "default" | "plan") => - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode, cwd: process.cwd(), @@ -820,7 +815,7 @@ describe("AcpAdapterV2", () => { const now = yield* DateTime.now; const runTurn = Effect.fnUntraced(function* ( ordinal: number, - runtimePolicy: ProviderAdapterV2RuntimePolicy, + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy, messageText: string, ) { yield* runtime.startTurn( @@ -917,7 +912,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-v2-plan-replay-boundary"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -1091,7 +1086,7 @@ describe("AcpAdapterV2", () => { }); const threadId = ThreadId.make("devin-streamed-write"); const modelSelection = { instanceId, model: "default" }; - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -1342,7 +1337,7 @@ describe("AcpAdapterV2", () => { }); const threadId = ThreadId.make("devin-replay-parent"); const modelSelection = { instanceId, model: "default" }; - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -1504,7 +1499,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-v2-fidelity"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -1684,7 +1679,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-eager-resume"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -1765,7 +1760,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-stale-eager-resume"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -1910,7 +1905,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-unexpected-termination"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -1993,7 +1988,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-provider-exit-running-command"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -2065,7 +2060,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-cgroup-unavailable"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -2130,7 +2125,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-cgroup-join-failure"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -2226,7 +2221,7 @@ describe("AcpAdapterV2", () => { McpProviderSession.clearMcpProviderSession(targetThreadId); }), ); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -2392,7 +2387,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-no-client-fs"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: workspace, @@ -2493,7 +2488,7 @@ describe("AcpAdapterV2", () => { clientTerminals: { childProcessSpawner }, }); const threadId = ThreadId.make("thread-acp-unknown-permission-grant"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: process.cwd(), @@ -2598,7 +2593,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-missing-native-thread"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -2629,7 +2624,7 @@ describe("AcpAdapterV2", () => { .pipe(Effect.flip); assert.equal(error._tag, "ProviderAdapterTurnStartError"); - assert.instanceOf(error.cause, ProviderAdapterProtocolError); + assert.instanceOf(error.cause, ProviderAdapter.ProviderAdapterProtocolError); assert.include(String(error.cause), "missing its ACP session id"); }).pipe(Effect.provide(layerTest), Effect.scoped), ); @@ -2676,7 +2671,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-rollback-session"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -2689,7 +2684,7 @@ describe("AcpAdapterV2", () => { runtimePolicy, }); assert.isTrue(runtime.providerSession.capabilities.threads.canRollbackThread); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -2883,7 +2878,7 @@ describe("AcpAdapterV2", () => { continuationRequests: { offer: () => Effect.void }, }); const threadId = ThreadId.make("thread-acp-rollback-retry-generation"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -2899,7 +2894,7 @@ describe("AcpAdapterV2", () => { return yield* Effect.die("ACP runtime must expose background work state"); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -2995,7 +2990,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-rollback-failure-compensation"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -3009,7 +3004,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -3079,7 +3074,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-idle-finalizer"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -3129,7 +3124,7 @@ describe("AcpAdapterV2", () => { threadId: ThreadId.make(`grok-model-${model}`), providerSessionId: ProviderSessionId.make(`grok-model-${model}`), modelSelection: { instanceId, model }, - runtimePolicy: ProviderAdapterV2RuntimePolicy.make({ + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -3173,7 +3168,7 @@ describe("AcpAdapterV2", () => { ), }); const threadId = ThreadId.make("grok-model-switch-back"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -3242,7 +3237,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-unsupported-option"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -3286,7 +3281,7 @@ describe("AcpAdapterV2", () => { }); const firstThreadId = ThreadId.make("thread-acp-active-setup:first"); const secondThreadId = ThreadId.make("thread-acp-active-setup:second"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -3400,7 +3395,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-empty-successful-bash"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -3412,7 +3407,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -3540,7 +3535,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-native-cancel"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -3642,7 +3637,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-cancel-permission"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: process.cwd(), @@ -3741,7 +3736,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-response-wins-permission"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: process.cwd(), @@ -3833,7 +3828,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-reordered-elicitation"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: process.cwd(), @@ -3908,7 +3903,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-mcp-approval-elicitation"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -3983,7 +3978,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-normal-close-held-response"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: process.cwd(), @@ -4089,7 +4084,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-close-wins-registration"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: process.cwd(), @@ -4208,7 +4203,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-pending-response-timeout"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: process.cwd(), @@ -4333,7 +4328,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-pending-response-cancel"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: process.cwd(), @@ -4442,7 +4437,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make(`thread-acp-immediate-permission-${name}`); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", approvalPolicy: "never", @@ -4535,7 +4530,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-immediate-url-elicitation"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -4626,7 +4621,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-missing-response-ack"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", approvalPolicy: "never", @@ -4708,7 +4703,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-teardown-wins-elicitation"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: process.cwd(), @@ -4802,7 +4797,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-cancel-timeout"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -4903,7 +4898,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-double-stop"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -4915,7 +4910,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -5007,7 +5002,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-interrupt-background-hold"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -5019,7 +5014,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -5111,7 +5106,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-subagent-carryover"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -5123,7 +5118,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -5252,7 +5247,7 @@ describe("AcpAdapterV2", () => { continuationRequests: { offer: () => Effect.void }, }); const threadId = ThreadId.make("thread-acp-carryover-pending-pin"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -5270,7 +5265,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -5416,7 +5411,7 @@ describe("AcpAdapterV2", () => { continuationRequests: { offer: () => Effect.void }, }); const threadId = ThreadId.make("thread-acp-active-carryover-pending-pin"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -5436,7 +5431,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -5661,7 +5656,7 @@ describe("AcpAdapterV2", () => { continuationRequests: { offer: () => Effect.void }, }); const threadId = ThreadId.make("thread-acp-subagent-finalize-window"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -5681,7 +5676,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -5796,7 +5791,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const promptSettled = yield* Deferred.make(); const instanceId = ProviderInstanceId.make("acp-test"); const childSessionId = "mock-child-session-post-settle"; @@ -5859,7 +5855,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-carryover-child-session-post-settle"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -5879,7 +5875,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -6046,7 +6042,7 @@ describe("AcpAdapterV2", () => { continuationRequests: { offer: () => Effect.void }, }); const threadId = ThreadId.make("thread-acp-carryover-subagent-finished"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -6062,7 +6058,7 @@ describe("AcpAdapterV2", () => { return yield* Effect.die("post-settle continuation must expose hasPendingBackgroundWork"); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -6151,7 +6147,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const instanceId = ProviderInstanceId.make("acp-test"); const childSessionId = "019f44a6-4820-7402-925d-bc862ee711dd"; let subagentPhase: "spawn" | "complete" = "spawn"; @@ -6210,7 +6207,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-completed-root-eager-carryover"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -6230,7 +6227,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -6396,7 +6393,8 @@ describe("AcpAdapterV2", () => { const mockAgentPath = yield* path.fromFileUrl( new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const bufferedAssistantText = "BUFFERED_WAKE_AFTER_USER_ATTACH"; const instanceId = ProviderInstanceId.make("acp-test"); let subagentPhase: "spawn" | "complete" = "spawn"; @@ -6458,7 +6456,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-carryover-root-session-continuation"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -6478,7 +6476,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -6678,7 +6676,8 @@ describe("AcpAdapterV2", () => { const mockAgentPath = yield* path.fromFileUrl( new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const promptWireReturned = yield* Deferred.make(); const releasePromptCompletion = yield* Deferred.make(); const instanceId = ProviderInstanceId.make("acp-test"); @@ -6750,7 +6749,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-carryover-already-handled-re-report"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -6770,7 +6769,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -6914,7 +6913,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const promptSettled = yield* Deferred.make(); const instanceId = ProviderInstanceId.make("acp-test"); const childSessionId = "019f5470-bf92-7a90-afb3-5a6cea5b34a3"; @@ -6988,7 +6988,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-carryover-root-end-notice"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -7006,7 +7006,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -7136,7 +7136,8 @@ describe("AcpAdapterV2", () => { const mockAgentPath = yield* path.fromFileUrl( new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const instanceId = ProviderInstanceId.make("acp-test"); const childSessionId = "mock-child-session-pending-continuation"; const bufferedAssistantText = "POST_SETTLE_BUFFERED_ASSISTANT_TEXT"; @@ -7199,7 +7200,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-carryover-child-pending-continuation"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -7219,7 +7220,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -7401,7 +7402,8 @@ describe("AcpAdapterV2", () => { const mockAgentPath = yield* path.fromFileUrl( new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const instanceId = ProviderInstanceId.make("acp-test"); const childSessionId = "mock-child-session-root-then-child"; let subagentPhase: "spawn" | "complete" = "spawn"; @@ -7463,7 +7465,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-carryover-root-then-child"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -7483,7 +7485,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -7701,7 +7703,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-settled-soft-steer"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -7713,7 +7715,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -7834,7 +7836,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-unsettled-steer-stays-hard"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -7892,7 +7894,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const instanceId = ProviderInstanceId.make("acp-test"); let cancelCalled = false; let runtimeOrdinalSeen = 0; @@ -7940,7 +7943,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-soft-mid-prompt-steer"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -7958,7 +7961,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -8115,7 +8118,7 @@ describe("AcpAdapterV2", () => { continuationRequests: { offer: () => Effect.void }, }); const threadId = ThreadId.make("thread-acp-stop-quarantine-late-task"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -8133,7 +8136,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -8255,7 +8258,7 @@ describe("AcpAdapterV2", () => { continuationRequests: { offer: () => Effect.void }, }); const threadId = ThreadId.make("thread-acp-production-stop-hard-kill"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -8267,7 +8270,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -8417,7 +8420,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-stop-after-soft-steer-orphan"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -8431,7 +8434,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -8700,7 +8703,7 @@ describe("AcpAdapterV2", () => { continuationRequests: { offer: () => Effect.void }, }); const threadId = ThreadId.make("thread-acp-direct-stop-deferred-terminal"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -8720,7 +8723,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -8904,7 +8907,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-settled-soft-admission-race"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -8918,7 +8921,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -8999,7 +9002,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const instanceId = ProviderInstanceId.make("acp-test"); const adapter = yield* makeAcpAdapterV2({ instanceId, @@ -9037,7 +9041,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-already-handled-wake-pin"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -9057,7 +9061,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -9123,7 +9127,8 @@ describe("AcpAdapterV2", () => { const mockAgentPath = yield* path.fromFileUrl( new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; let sessionUpdateHandler: Parameters[0] | undefined; const instanceId = ProviderInstanceId.make("acp-test"); @@ -9154,7 +9159,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-sticky-continuation-dispatch"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -9168,7 +9173,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -9237,7 +9242,8 @@ describe("AcpAdapterV2", () => { const mockAgentPath = yield* path.fromFileUrl( new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const userPromptStarted = yield* Deferred.make(); const releaseUserPrompt = yield* Deferred.make(); const bufferedAssistantText = "BUFFERED_WAKE_QUEUED_AFTER_USER"; @@ -9284,7 +9290,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-buffered-continuation-user-race"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -9304,7 +9310,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -9480,7 +9486,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-injected-report-hold"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -9492,7 +9498,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -9515,7 +9521,7 @@ describe("AcpAdapterV2", () => { // hydration are ingested: the hydrated monitor card carries the // fetched listing. let reportSeen = false; - const trackReport = (event: ProviderAdapterV2Event): void => { + const trackReport = (event: ProviderAdapter.ProviderAdapterV2Event): void => { if ( event.type === "turn_item.updated" && event.turnItem.type === "assistant_message" && @@ -9605,7 +9611,8 @@ describe("AcpAdapterV2", () => { const triggerDir = yield* fileSystem.makeTempDirectoryScoped(); const triggerPath = path.join(triggerDir, "report-trigger"); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const capturedMutation: { current: | ((mutation: { @@ -9662,7 +9669,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-settle-hold-ext-complete-no-wake"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -9676,7 +9683,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -9696,7 +9703,7 @@ describe("AcpAdapterV2", () => { }); let reportSeen = false; - const trackReport = (event: ProviderAdapterV2Event): void => { + const trackReport = (event: ProviderAdapter.ProviderAdapterV2Event): void => { if ( event.type === "turn_item.updated" && event.turnItem.type === "assistant_message" && @@ -9799,7 +9806,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; let sessionUpdateHandler: Parameters[0] | undefined; const promptGate = yield* Deferred.make(); @@ -9854,7 +9862,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-pre-settle-arm-cleared-by-report"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -9868,7 +9876,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -9965,7 +9973,7 @@ describe("AcpAdapterV2", () => { yield* Effect.yieldNow; let reportSeen = false; - const trackReport = (event: ProviderAdapterV2Event): void => { + const trackReport = (event: ProviderAdapter.ProviderAdapterV2Event): void => { if ( event.type === "turn_item.updated" && event.turnItem.type === "assistant_message" && @@ -10033,7 +10041,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; let sessionUpdateHandler: Parameters[0] | undefined; const promptGate = yield* Deferred.make(); @@ -10095,7 +10104,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-staggered-midturn-keep-until-last"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -10109,7 +10118,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -10246,7 +10255,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; let sessionUpdateHandler: Parameters[0] | undefined; const promptGate = yield* Deferred.make(); @@ -10312,7 +10322,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-staggered-midturn-clear-on-interrupt"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -10326,7 +10336,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -10455,7 +10465,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; let sessionUpdateHandler: Parameters[0] | undefined; const promptGates: Array> = []; @@ -10543,7 +10554,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-multiturn-in-turn-monitor-no-wake"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -10563,7 +10574,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -10820,7 +10831,8 @@ describe("AcpAdapterV2", () => { const mockAgentPath = yield* path.fromFileUrl( new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; let sessionUpdateHandler: Parameters[0] | undefined; let applyMutation: AcpAdapterV2ExtensionContext["applyBackgroundTaskMutation"] | undefined; @@ -10860,7 +10872,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-wake-report-while-queued"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -10872,7 +10884,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -10969,7 +10981,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; let sessionUpdateHandler: Parameters[0] | undefined; const promptGates: Array> = []; @@ -11038,7 +11051,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-mid-turn-dirty-wake-buffer"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -11058,7 +11071,7 @@ describe("AcpAdapterV2", () => { ); } const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -11294,7 +11307,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; let sessionUpdateHandler: Parameters[0] | undefined; const promptGate = yield* Deferred.make(); @@ -11344,7 +11358,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-mid-turn-unhandled-offers-after-finalize"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -11358,7 +11372,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -11446,7 +11460,7 @@ describe("AcpAdapterV2", () => { content: { type: "text", text: " \n\t " }, }, }); - const lateEvents: Array = []; + const lateEvents: Array = []; let lateEvent = yield* Queue.poll(events); while (Option.isSome(lateEvent)) { lateEvents.push(lateEvent.value); @@ -11475,7 +11489,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; let sessionUpdateHandler: Parameters[0] | undefined; const promptGate = yield* Deferred.make(); @@ -11529,7 +11544,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-empty-drain-continuation-quiet"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -11543,7 +11558,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -11713,7 +11728,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; let sessionUpdateHandler: Parameters[0] | undefined; const promptGate = yield* Deferred.make(); @@ -11765,7 +11781,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-empty-drain-continuation-no-wedge"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -11779,7 +11795,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -11913,7 +11929,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-restart-after-interrupt"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -12144,7 +12160,8 @@ describe("AcpAdapterV2", () => { const residualCallbackResponseLogPath = path.join(residualCallbackDir, "responses.log"); const residualCallbackTriggerPath = path.join(residualCallbackDir, "trigger"); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const teardownStarted = yield* Deferred.make(); const releaseTeardown = yield* Deferred.make(); let terminatorCallCount = 0; @@ -12187,7 +12204,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-failed-hard-teardown"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -12202,7 +12219,7 @@ describe("AcpAdapterV2", () => { runtimePolicy, }) .pipe(Effect.provideService(Scope.Scope, sessionScope)); - const adapterEvents = yield* Queue.unbounded(); + const adapterEvents = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(adapterEvents, event)), Effect.forkIn(sessionScope), @@ -12368,7 +12385,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-missing-hard-teardown"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -12464,7 +12481,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-concurrent-hard-teardown"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -12540,7 +12557,8 @@ describe("AcpAdapterV2", () => { new URL("../../../scripts/acp-mock-agent.ts", import.meta.url), ); const protocolEvents = yield* Queue.bounded(256); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const responseLifecycle: Array = []; type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"]; type HandlerRecord = { @@ -12633,7 +12651,7 @@ describe("AcpAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-successful-teardown-callback-quarantine"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -12647,7 +12665,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const adapterEvents = yield* Queue.unbounded(); + const adapterEvents = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(adapterEvents, event)), Effect.forkScoped, @@ -12849,7 +12867,7 @@ describe("AcpAdapterV2", () => { method: "_x.ai/ask_user_question", }, ).pipe(Effect.forkScoped); - let replacementRequest: ProviderAdapterV2Event | undefined; + let replacementRequest: ProviderAdapter.ProviderAdapterV2Event | undefined; while (replacementRequest === undefined) { const event = yield* Queue.take(adapterEvents); if (event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending") { @@ -12916,7 +12934,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-stale-deferred-cleanup"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: process.cwd(), @@ -12928,7 +12946,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -12975,7 +12993,7 @@ describe("AcpAdapterV2", () => { yield* runtime.startTurn( makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now, ordinal: 2 }), ); - let replacementPending: ProviderAdapterV2Event | undefined; + let replacementPending: ProviderAdapter.ProviderAdapterV2Event | undefined; while (replacementPending === undefined) { const event = yield* Queue.take(events); if (event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending") { @@ -13045,7 +13063,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-concurrent-resume-teardown"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -13192,7 +13210,7 @@ describe("AcpAdapterV2", () => { continuationRequests: { offer: () => Effect.void }, }); const threadId = ThreadId.make("thread-acp-direct-stop-running-command"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -13206,7 +13224,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -13458,7 +13476,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-direct-stop-subagent-hold"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -13472,7 +13490,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, @@ -13602,7 +13620,7 @@ describe("AcpAdapterV2", () => { selfInvocation, }); const threadId = ThreadId.make("thread-acp-restart-active-in-process"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -13614,7 +13632,7 @@ describe("AcpAdapterV2", () => { modelSelection, runtimePolicy, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); yield* runtime.events.pipe( Stream.runForEach((event) => Queue.offer(events, event)), Effect.forkScoped, diff --git a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts index 728e8bc4c91dae55164d095175633363c5234a41..c640ae35491938277a6455f382aca85766fb4b58 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts @@ -29,7 +29,7 @@ import { makeAcpReplayCompletenessAssertion, makeAcpReplayRuntime, } from "./AcpAdapterV2.testkit.ts"; -import { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import { BUILT_IN_PROVIDER_ADAPTER_DRIVER_KINDS_V2 } from "../builtInProviderAdapterDrivers.ts"; import { AcpRegistryAdapterV2Driver } from "@t3tools/provider-acp-registry/server"; import { @@ -216,7 +216,7 @@ describe("AcpRegistryAdapterV2", () => { model: "default", options: [{ id: ACP_SESSION_MODE_OPTION_ID, value: input.storedModePick }], }, - runtimePolicy: ProviderAdapterV2RuntimePolicy.make({ + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: replayDir, @@ -304,7 +304,7 @@ describe("AcpRegistryAdapterV2", () => { ); }), }); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), @@ -413,7 +413,7 @@ describe("AcpRegistryAdapterV2", () => { }, }); const threadId = ThreadId.make("thread-acp-registry-fixture"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), diff --git a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts index f997751f2fdd54f9ca1d6651ea0e602320fd33f0..9579da1fa91c3a24ae958c69882589ccdc17a4d8 100644 --- a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts @@ -27,7 +27,7 @@ import { layerTestProviderHost } from "@t3tools/provider-testing/host"; import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime"; import { makeAntigravityAcpRuntime } from "../../provider/acp/AntigravityAcpSupport.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import { makeAntigravityAcpAdapterFlavor, makeAntigravityAdapterV2, @@ -74,7 +74,7 @@ describe("AntigravityAdapterV2 flavor", () => { it("maps runtime modes to the agent's native permission modes", () => { const mode = (runtimeMode: "approval-required" | "auto-accept-edits" | "full-access") => flavor.sessionModeForPolicy?.( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode, interactionMode: "default", cwd: "/workspace", @@ -190,7 +190,7 @@ describe("AntigravityAdapterV2 client file system", () => { yield* fileSystem.writeFileString(attachment, "pasted"); const threadId = ThreadId.make("thread-antigravity-containment"); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: workspace, @@ -325,7 +325,7 @@ describe("AntigravityAdapterV2 workspace changes", () => { yield* fileSystem.writeFileString(path.join(workspaceA, "a.txt"), "from a"); yield* fileSystem.writeFileString(path.join(workspaceB, "b.txt"), "from b"); const policyFor = (cwd: string) => - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd, @@ -476,7 +476,7 @@ describe("AntigravityAdapterV2 client file system under restrictive policies", ( }); yield* fileSystem.writeFileString(path.join(workspace, "existing.ts"), "existing"); const threadId = ThreadId.make(`thread-antigravity-restrictive-${policy.runtimeMode}`); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ ...policy, interactionMode: "default", cwd: workspace, diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index bfef7f9e9a10475f389431145916700b6cd359de..eed58e1aa416e6de398fd4d7e871ec6abddc3c90 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -61,13 +61,9 @@ import { WorktreeToolkit } from "../../mcp/toolkits/worktree/tools.ts"; import { ThreadToolkit } from "../../mcp/toolkits/thread/tools.ts"; import { OrchestratorToolkit } from "../../mcp/toolkits/orchestrator/tools.ts"; import { ClaudeExecutableFileCheck } from "../../provider/Drivers/ClaudeExecutable.ts"; -import type { EventNdjsonLogger } from "../../provider/EventNdjsonLogger.ts"; -import { - ProviderAdapterV2RuntimePolicy, - type ProviderAdapterV2Event, - type ProviderAdapterV2TurnInput, -} from "@t3tools/provider-core/server/ProviderAdapter"; -import type { ProviderContinuationRequest } from "@t3tools/provider-core/server/continuationRequests"; +import type * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { makeProviderFailure } from "@t3tools/provider-core/server/failure"; import * as ClaudeAdapterV2 from "./ClaudeAdapterV2.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; @@ -81,7 +77,7 @@ const CLAUDE_TEST_MODEL_SELECTION = { model: "claude-sonnet-4-6", options: [{ id: "effort", value: "ultrathink" }], } satisfies ModelSelection; -const CLAUDE_TEST_RUNTIME_POLICY = ProviderAdapterV2RuntimePolicy.make({ +const CLAUDE_TEST_RUNTIME_POLICY = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -127,14 +123,14 @@ function makeClaudeTestTurnInput(input: { readonly now: DateTime.Utc; readonly attemptId: RunAttemptId; readonly text: string; - readonly attachments: ProviderAdapterV2TurnInput["message"]["attachments"]; + readonly attachments: ProviderAdapter.ProviderAdapterV2TurnInput["message"]["attachments"]; readonly providerTurnOrdinal?: number; readonly nativeThreadHasTurns?: boolean; - readonly messageCreatedBy?: ProviderAdapterV2TurnInput["message"]["createdBy"]; - readonly messageCreationSource?: ProviderAdapterV2TurnInput["message"]["creationSource"]; + readonly messageCreatedBy?: ProviderAdapter.ProviderAdapterV2TurnInput["message"]["createdBy"]; + readonly messageCreationSource?: ProviderAdapter.ProviderAdapterV2TurnInput["message"]["creationSource"]; readonly modelSelection?: ModelSelection; - readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy; -}): ProviderAdapterV2TurnInput { + readonly runtimePolicy?: ProviderAdapter.ProviderAdapterV2RuntimePolicy; +}): ProviderAdapter.ProviderAdapterV2TurnInput { return { appThread: makeClaudeTestAppThread(input), threadId: input.threadId, @@ -298,7 +294,7 @@ describe("ClaudeAdapterV2 runtime query policy", () => { it("maps canonical read-only never policy to Claude dontAsk with read-only tools", () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -321,7 +317,7 @@ describe("ClaudeAdapterV2 runtime query policy", () => { it("maps canonical read-only on-request policy to Claude default with callbacks", () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -344,7 +340,7 @@ describe("ClaudeAdapterV2 runtime query policy", () => { it("does not auto-allow reads for canonical restricted read-only never policy", () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -370,7 +366,7 @@ describe("ClaudeAdapterV2 runtime query policy", () => { it("maps default full-access policy to Claude bypass permissions", () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -386,7 +382,7 @@ describe("ClaudeAdapterV2 runtime query policy", () => { it("maps Auto runtime mode to Claude's AI-reviewed permission mode", () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "auto", interactionMode: "default", cwd: "/workspace", @@ -401,7 +397,7 @@ describe("ClaudeAdapterV2 runtime query policy", () => { it("keeps approval-required mode interactive with danger-full-access sandboxing", () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: "/workspace", @@ -419,7 +415,7 @@ describe("ClaudeAdapterV2 runtime query policy", () => { it("installs the permission callback for approval-required plan mode", () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "plan", cwd: "/workspace", @@ -434,7 +430,7 @@ describe("ClaudeAdapterV2 runtime query policy", () => { it("honors never approvals for approval-required workspace-write policy", () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: "/workspace", @@ -453,7 +449,7 @@ describe("ClaudeAdapterV2 runtime query policy", () => { it("honors never approvals for externally sandboxed policy", () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: "/workspace", @@ -595,7 +591,7 @@ describe("ClaudeAdapterV2 MCP query overrides", () => { const threadId = ThreadId.make("thread-claude-mcp-query-key"); withMcpSession(threadId, () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -627,7 +623,7 @@ describe("ClaudeAdapterV2 MCP query overrides", () => { const threadId = ThreadId.make("thread-claude-mcp-credential-rotation"); withMcpSession(threadId, () => { const queryPolicy = ClaudeAdapterV2.claudeRuntimeQueryPolicyForRuntimePolicy( - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: "/workspace", @@ -750,7 +746,7 @@ describe("ClaudeAdapterV2 native protocol logging", () => { readonly event: unknown; readonly threadId: ThreadId | null; }> = []; - const logger: EventNdjsonLogger = { + const logger: ProviderEventLoggers.EventNdjsonLogger = { filePath: "/tmp/events.log", write: (event, threadId) => Effect.sync(() => { @@ -993,7 +989,7 @@ describe("ClaudeAdapterV2 Auto-accept edits", () => { assertComplete: Effect.void, }, }); - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "auto-accept-edits", interactionMode: "default", cwd: "/workspace", @@ -1701,7 +1697,7 @@ describe("ClaudeAdapterV2 native fork", () => { instanceId: ProviderInstanceId.make(ClaudeAdapterV2.CLAUDE_PROVIDER), model: "claude-sonnet-4-6", }, - runtimePolicy: ProviderAdapterV2RuntimePolicy.make({ + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -1713,7 +1709,7 @@ describe("ClaudeAdapterV2 native fork", () => { instanceId: ProviderInstanceId.make(ClaudeAdapterV2.CLAUDE_PROVIDER), model: "claude-sonnet-4-6", }, - runtimePolicy: ProviderAdapterV2RuntimePolicy.make({ + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -1808,7 +1804,7 @@ describe("ClaudeAdapterV2 native fork", () => { instanceId: ProviderInstanceId.make(ClaudeAdapterV2.CLAUDE_PROVIDER), model: "claude-sonnet-4-6", }, - runtimePolicy: ProviderAdapterV2RuntimePolicy.make({ + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -2120,11 +2116,16 @@ describe("ClaudeAdapterV2 background wake turns", () => { }); const offeredMessages: Array = []; const permissionModeChanges: Array = []; - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const terminalReceipts = - yield* Queue.unbounded>(); + yield* Queue.unbounded< + Extract + >(); const systemNoticeReceipts = - yield* Queue.unbounded>(); + yield* Queue.unbounded< + Extract + >(); let openedOptions: ClaudeAdapterV2.ClaudeAgentSdkQueryOptions | undefined; const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, @@ -2210,7 +2211,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { modelSelection: CLAUDE_TEST_MODEL_SELECTION, runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY, }); - const events: Array = []; + const events: Array = []; yield* runtime.events.pipe( Stream.runForEach((event) => Effect.gen(function* () { @@ -2231,7 +2232,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; const terminalEvents = () => events.filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "turn.terminal", ); return { @@ -2817,7 +2820,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { attemptId: RunAttemptId.make("attempt-claude-auth-failure"), text: "Continue.", attachments: [], - runtimePolicy: ProviderAdapterV2RuntimePolicy.make({ + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd, @@ -3633,10 +3636,16 @@ describe("ClaudeAdapterV2 background wake turns", () => { ), ); - const providerThreadRosterEvents = (events: ReadonlyArray) => + const providerThreadRosterEvents = ( + events: ReadonlyArray, + ) => events.filter( - (event): event is Extract => - event.type === "provider_thread.updated", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "provider_thread.updated" } + > => event.type === "provider_thread.updated", ); it.effect( @@ -3932,8 +3941,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { }); const processQueues: Array> = []; const firstCloseRequested = yield* Deferred.make(); - const events: Array = []; - const continuationRequests: Array = []; + const events: Array = []; + const continuationRequests: Array = + []; const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, settings: DEFAULT_CLAUDE_SETTINGS, @@ -4179,7 +4189,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { readonly nativeThreadId: string; readonly queue: Queue.Queue; }> = []; - const events: Array = []; + const events: Array = []; const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, settings: DEFAULT_CLAUDE_SETTINGS, @@ -4430,7 +4440,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { Effect.gen(function* () { const harness = yield* makeWakeHarness; const now = yield* DateTime.now; - const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({ + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode, interactionMode: "default", cwd: "/workspace", @@ -4731,7 +4741,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { Effect.gen(function* () { const harness = yield* makeWakeHarness; const now = yield* DateTime.now; - const approvalPolicy = ProviderAdapterV2RuntimePolicy.make({ + const approvalPolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "approval-required", interactionMode: "default", cwd: "/workspace", @@ -5972,7 +5982,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { session_id: WAKE_NATIVE_SESSION, }); const subagentRouting = ( - events: ReadonlyArray, + events: ReadonlyArray, nativeToolIds: ReadonlyArray, ) => { const childThreadId = @@ -6090,7 +6100,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { const userTurn = ( attempt: string, providerTurnOrdinal: number, - attachments: ProviderAdapterV2TurnInput["message"]["attachments"] = [], + attachments: ProviderAdapter.ProviderAdapterV2TurnInput["message"]["attachments"] = [], ) => harness.runtime.startTurn( makeClaudeTestTurnInput({ @@ -7838,8 +7848,12 @@ describe("ClaudeAdapterV2 background wake turns", () => { const now = yield* DateTime.now; const subagentEvents = () => harness.events.filter( - (event): event is Extract => - event.type === "subagent.updated", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "subagent.updated" } + > => event.type === "subagent.updated", ); yield* harness.runtime.startTurn( @@ -7942,8 +7956,12 @@ describe("ClaudeAdapterV2 background wake turns", () => { const now = yield* DateTime.now; const subagentEvents = () => harness.events.filter( - (event): event is Extract => - event.type === "subagent.updated", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "subagent.updated" } + > => event.type === "subagent.updated", ); yield* harness.runtime.startTurn( @@ -8059,8 +8077,12 @@ describe("ClaudeAdapterV2 background wake turns", () => { const now = yield* DateTime.now; const subagentEvents = () => harness.events.filter( - (event): event is Extract => - event.type === "subagent.updated", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "subagent.updated" } + > => event.type === "subagent.updated", ); yield* harness.runtime.startTurn( @@ -8249,7 +8271,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { // already pre-opened by the wake buffer before the drain replay. const nodeStatuses = harness.events .filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "node.updated" && event.node.kind === "subagent" && event.node.nativeItemRef?.nativeId === SUBAGENT_TASK_ID, @@ -8288,8 +8312,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { prefix: "t3-claude-v2-process-reset-", }); const processQueues: Array> = []; - const events: Array = []; - const continuationRequests: Array = []; + const events: Array = []; + const continuationRequests: Array = + []; const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, settings: DEFAULT_CLAUDE_SETTINGS, @@ -8472,8 +8497,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { prefix: "t3-claude-v2-buffer-replace-", }); const processQueues: Array> = []; - const events: Array = []; - const continuationRequests: Array = []; + const events: Array = []; + const continuationRequests: Array = + []; const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, settings: DEFAULT_CLAUDE_SETTINGS, @@ -8708,8 +8734,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { prefix: "t3-claude-v2-subagent-buffer-replace-", }); const processQueues: Array> = []; - const events: Array = []; - const continuationRequests: Array = []; + const events: Array = []; + const continuationRequests: Array = + []; const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, settings: DEFAULT_CLAUDE_SETTINGS, @@ -8775,8 +8802,12 @@ describe("ClaudeAdapterV2 background wake turns", () => { const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; const subagentEvents = () => events.filter( - (event): event is Extract => - event.type === "subagent.updated", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "subagent.updated" } + > => event.type === "subagent.updated", ); const now = yield* DateTime.now; @@ -8880,7 +8911,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { assert.equal(finalSubagent?.result, SUBAGENT_SUMMARY); assert.equal(finalSubagent?.runId, subagentEvents()[0]?.subagent.runId); const subagentNodeEvents = events.filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "node.updated" && event.node.kind === "subagent" && event.node.nativeItemRef?.nativeId === SUBAGENT_TASK_ID, @@ -8902,7 +8935,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { prefix: "t3-claude-v2-model-change-running-subagent-", }); const processQueues: Array> = []; - const events: Array = []; + const events: Array = []; const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, settings: DEFAULT_CLAUDE_SETTINGS, @@ -9069,7 +9102,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { }); let openCount = 0; const processQueues: Array> = []; - const events: Array = []; + const events: Array = []; const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, settings: DEFAULT_CLAUDE_SETTINGS, @@ -9198,8 +9231,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { }); let openCount = 0; const processQueues: Array> = []; - const events: Array = []; - const continuationRequests: Array = []; + const events: Array = []; + const continuationRequests: Array = + []; const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, settings: DEFAULT_CLAUDE_SETTINGS, @@ -9394,7 +9428,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { const attachmentsDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-v2-first-open-fail-", }); - const events: Array = []; + const events: Array = []; const adapter = ClaudeAdapterV2.makeClaudeAdapterV2({ instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID, settings: DEFAULT_CLAUDE_SETTINGS, @@ -9496,7 +9530,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { uuid, session_id: WAKE_NATIVE_SESSION, }); - const goalStatuses = (events: ReadonlyArray) => + const goalStatuses = (events: ReadonlyArray) => events.flatMap((event) => event.type === "provider_thread.updated" && event.providerThread.goal != null ? [event.providerThread.goal] diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index de747802d3490e702cf9b772154ddfab1d1f2efc..0eb2dff9bfe3b992d958d867be6822a78effb532 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -101,10 +101,9 @@ import { } from "../../provider/ClaudeModelCatalog.ts"; import { boundProviderEventForLogging, - type EventNdjsonLogger, shouldPersistProviderEvent, } from "../../provider/EventNdjsonLogger.ts"; -import * as ProviderEventLoggers from "../../provider/ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import { claudeRateLimitEventToUpdate, type ClaudeScopedLimitNames, @@ -135,7 +134,7 @@ import { type BackgroundWorkReport, backgroundWorkNotification, } from "@t3tools/provider-core/server/notification"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { makeSubagentChildThread, makeSubagentConversationArtifacts, @@ -570,7 +569,7 @@ export function loggedClaudeQueryOptions( } export function makeClaudeAgentSdkProtocolLogger(input: { - readonly nativeEventLogger: EventNdjsonLogger | undefined; + readonly nativeEventLogger: ProviderEventLoggers.EventNdjsonLogger | undefined; readonly threadId: ThreadId; readonly providerSessionId: OrchestrationV2ProviderSession["id"]; }): ClaudeAgentSdkProtocolLogger | undefined { @@ -1118,7 +1117,7 @@ function resultTextFromSdkMessage( } function makeProviderThread(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly providerInstanceId: ProviderInstanceId; readonly appThreadId: OrchestrationV2ProviderThread["appThreadId"]; readonly ownerNodeId?: OrchestrationV2ProviderThread["ownerNodeId"]; @@ -2581,7 +2580,7 @@ function providerFailureFromApiRetry(message: SDKAPIRetryMessage): Orchestration } function buildAssistantArtifacts(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly turnInput: ProviderAdapter.ProviderAdapterV2TurnInput; readonly providerTurnId: OrchestrationV2ProviderTurn["id"]; readonly nativeItemId: string; @@ -3015,7 +3014,7 @@ export interface ClaudeAdapterV2Options { readonly fileSystem: FileSystem.FileSystem; readonly path: Path.Path; readonly crypto: Crypto.Crypto; - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly queryRunner: ClaudeAgentSdkQueryRunnerShape; readonly scopedLimitNames?: Ref.Ref; readonly onUsageLimits?: ServerProviderShape["applyUsageLimits"]; @@ -3029,7 +3028,7 @@ export interface ClaudeAdapterV2Options { export function makeClaudeAdapterV2( adapterOptions: ClaudeAdapterV2Options, -): ProviderAdapter.ProviderAdapterV2Shape { +): ProviderAdapter.ProviderAdapterV2["Service"] { const { attachmentsDir, fileSystem, path, crypto, idAllocator, queryRunner } = adapterOptions; const continuationRequests = adapterOptions.continuationRequests ?? { offer: () => Effect.void, @@ -3356,7 +3355,6 @@ export function makeClaudeAdapterV2( type: "turn_item.updated", driver: CLAUDE_PROVIDER, turnItem: makeProviderRetryTurnItem({ - idAllocator, driver: CLAUDE_PROVIDER, threadId: context.input.threadId, runId: context.input.runId, @@ -5083,7 +5081,6 @@ export function makeClaudeAdapterV2( type: "turn_item.updated", driver: CLAUDE_PROVIDER, turnItem: makeProviderRetryTurnItem({ - idAllocator, driver: CLAUDE_PROVIDER, threadId: input.context.input.threadId, runId: input.context.input.runId, @@ -6089,7 +6086,6 @@ export function makeClaudeAdapterV2( type: "turn_item.updated", driver: CLAUDE_PROVIDER, turnItem: makeProviderRetryTurnItem({ - idAllocator, driver: CLAUDE_PROVIDER, threadId: context.input.threadId, runId: context.input.runId, diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts index 4188c3248a5fdcefd280b5ace74a060939b2f478..ef884b9c3abcbbccff3bfe5f3bd57f2c21e9f2a9 100644 --- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts @@ -1,7 +1,6 @@ import * as NodeOS from "node:os"; import { historyResponseItems } from "@t3tools/provider-core/server/handoffBudget"; -import type { ProviderAdapterV2HistoricalContext } from "@t3tools/provider-core/server/ProviderAdapter"; import { makeProviderTextDeltaCoalescer, type ProviderTextDeltaUpdate, @@ -56,21 +55,13 @@ import { ChildProcess, ChildProcessSpawner } from "effect/process"; import packageJson from "../../../package.json" with { type: "json" }; import * as ServerConfig from "../../config.ts"; import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession"; -import type { EventNdjsonLogger } from "../../provider/EventNdjsonLogger.ts"; -import * as ProviderEventLoggers from "../../provider/ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as EffectWorker from "../EffectWorker.ts"; import * as Orchestrator from "../Orchestrator.ts"; import * as ProviderReplayHarness from "../testkit/ProviderReplayHarness.ts"; -import { - ProviderAdapterForkThreadError, - ProviderAdapterOpenSessionError, - ProviderAdapterRollbackThreadError, - ProviderAdapterV2RuntimePolicy, - type ProviderAdapterV2Event, - type ProviderAdapterV2TurnInput, -} from "@t3tools/provider-core/server/ProviderAdapter"; -import type { ProviderContinuationRequest } from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import * as CodexAdapterV2 from "./CodexAdapterV2.ts"; import { makeReplayServerConfig, withCodexReplayChildMetadata } from "./CodexAdapterV2.testkit.ts"; import * as CodexAdapterV2Testkit from "./CodexAdapterV2.testkit.ts"; @@ -767,7 +758,7 @@ describe("CodexAdapterV2 process spawning", () => { instanceId: CodexAdapterV2.CODEX_DEFAULT_INSTANCE_ID, threadId: ThreadId.make("thread-launch-args"), providerSessionId: ProviderSessionId.make("provider-session-launch-args"), - runtimePolicy: ProviderAdapterV2RuntimePolicy.make({ + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -1036,7 +1027,7 @@ describe("CodexAdapterV2 native protocol logging", () => { readonly event: unknown; readonly threadId: ThreadId | null; }> = []; - const logger: EventNdjsonLogger = { + const logger: ProviderEventLoggers.EventNdjsonLogger = { filePath: "/tmp/events.log", write: (event, threadId) => Effect.sync(() => { @@ -1410,7 +1401,7 @@ describe("CodexAdapterV2 fork boundary", () => { }), ); - assert.instanceOf(error, ProviderAdapterForkThreadError); + assert.instanceOf(error, ProviderAdapter.ProviderAdapterForkThreadError); assert.include(String(error.cause), "provider-turn-missing"); }), ); @@ -1478,7 +1469,7 @@ const CODEX_TEST_MODEL_SELECTION = { instanceId: CodexAdapterV2.CODEX_DEFAULT_INSTANCE_ID, model: "gpt-5.4", } satisfies ModelSelection; -const CODEX_TEST_RUNTIME_POLICY = ProviderAdapterV2RuntimePolicy.make({ +const CODEX_TEST_RUNTIME_POLICY = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: "/workspace", @@ -1524,7 +1515,7 @@ function makeCodexTestTurnInput(input: { readonly now: DateTime.Utc; readonly attemptId: RunAttemptId; readonly text: string; -}): ProviderAdapterV2TurnInput { +}): ProviderAdapter.ProviderAdapterV2TurnInput { return { appThread: makeCodexTestAppThread(input), threadId: input.threadId, @@ -1747,7 +1738,7 @@ describe("CodexAdapterV2 session initialize", () => { ), Effect.mapError( (cause) => - new ProviderAdapterOpenSessionError({ + new ProviderAdapter.ProviderAdapterOpenSessionError({ driver: CodexAdapterV2.CODEX_DRIVER_KIND, providerSessionId: openInput.providerSessionId, cause, @@ -1907,7 +1898,8 @@ describe("CodexAdapterV2 post-settle continuation", () => { const makeCodexReplayHarness = ( transcript: CodexReplay.CodexAppServerReplayTranscript, - onEvent: (event: ProviderAdapterV2Event) => Effect.Effect = () => Effect.void, + onEvent: (event: ProviderAdapter.ProviderAdapterV2Event) => Effect.Effect = () => + Effect.void, onRequest: (method: string, params: unknown) => Effect.Effect = () => Effect.void, readChildMetadata?: Parameters[2], ) => @@ -1915,13 +1907,14 @@ describe("CodexAdapterV2 post-settle continuation", () => { const fileSystem = yield* FileSystem.FileSystem; const idAllocator = yield* IdAllocator.IdAllocatorV2; const serverConfig = yield* makeReplayServerConfig(transcript.scenario).pipe(Effect.orDie); - const continuationRequests: Array = []; + const continuationRequests: Array = + []; const clientFactory: CodexAdapterV2.CodexAppServerClientFactoryShape = { open: (openInput) => Layer.build(CodexReplay.layerReplay(transcript)).pipe( Effect.mapError( (cause) => - new ProviderAdapterOpenSessionError({ + new ProviderAdapter.ProviderAdapterOpenSessionError({ driver: CodexAdapterV2.CODEX_DRIVER_KIND, providerSessionId: openInput.providerSessionId, cause, @@ -1975,7 +1968,7 @@ describe("CodexAdapterV2 post-settle continuation", () => { modelSelection: CODEX_TEST_MODEL_SELECTION, runtimePolicy: CODEX_TEST_RUNTIME_POLICY, }); - const events: Array = []; + const events: Array = []; const firstTerminal = yield* Deferred.make(); yield* runtime.events.pipe( Stream.runForEach((event) => @@ -1998,13 +1991,19 @@ describe("CodexAdapterV2 post-settle continuation", () => { const hasPendingBackgroundWork = runtime.hasPendingBackgroundWork; const terminalEvents = () => events.filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "turn.terminal", ); const subagentUpdates = () => events.filter( - (event): event is Extract => - event.type === "subagent.updated", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "subagent.updated" } + > => event.type === "subagent.updated", ); return { runtime, @@ -2026,7 +2025,7 @@ describe("CodexAdapterV2 post-settle continuation", () => { Effect.gen(function* () { const nativeThreadId = `inject-${response}`; const prompt = "Only the current request"; - const history: ProviderAdapterV2HistoricalContext = { + const history: ProviderAdapter.ProviderAdapterV2HistoricalContext = { context: "Historical conversation", messages: (["user", "assistant"] as const).map((role) => ({ role, @@ -2528,12 +2527,14 @@ describe("CodexAdapterV2 post-settle continuation", () => { }).pipe(Effect.scoped, Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))), ); - const assistantMessages = (events: ReadonlyArray) => + const assistantMessages = (events: ReadonlyArray) => events.filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "message.updated" && event.message.role === "assistant", ); - const assistantTurnItems = (events: ReadonlyArray) => + const assistantTurnItems = (events: ReadonlyArray) => events.flatMap((event) => event.type === "turn_item.updated" && event.turnItem.type === "assistant_message" ? [event.turnItem] @@ -4914,8 +4915,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { ); const providerTurnId = harness.events.find( - (event): event is Extract => - event.type === "provider_turn.updated", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "provider_turn.updated" } + > => event.type === "provider_turn.updated", )?.providerTurn.id; assert.isDefined(providerTurnId); @@ -4931,7 +4936,7 @@ describe("CodexAdapterV2 post-settle continuation", () => { assert.isAtLeast(terminalIndex, 0); let lastCommandBeforeTerminal: - | Extract + | Extract | undefined; for (let index = 0; index < terminalIndex; index++) { const event = harness.events[index]; @@ -4997,8 +5002,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { ); const commandUpdates = harness.events.filter( - (event): event is Extract => - event.type === "turn_item.updated" && event.turnItem.type === "command_execution", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "turn_item.updated" } + > => event.type === "turn_item.updated" && event.turnItem.type === "command_execution", ); assert.isAtLeast(commandUpdates.length, 2, "start + interrupt terminalization"); assert.equal(commandUpdates[commandUpdates.length - 1]?.turnItem.status, "interrupted"); @@ -5142,7 +5151,7 @@ describe("CodexAdapterV2 post-settle continuation", () => { }); const assertChildProviderTerminalBeforeRoot = ( - events: ReadonlyArray, + events: ReadonlyArray, rootThreadId: ThreadId, ) => { const terminalIndex = events.findIndex((event) => event.type === "turn.terminal"); @@ -5199,8 +5208,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { "running child command item", ); const providerTurnId = harness.events.find( - (event): event is Extract => - event.type === "provider_turn.updated" && event.threadId === harness.threadId, + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "provider_turn.updated" } + > => event.type === "provider_turn.updated" && event.threadId === harness.threadId, )?.providerTurn.id; assert.isDefined(providerTurnId); @@ -5212,7 +5225,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { yield* awaitUntil(() => harness.terminalEvents().length === 1, "interrupted root terminal"); assert.equal(harness.terminalEvents()[0]?.status, "interrupted"); const childCommandUpdates = harness.events.filter( - (event): event is Extract => + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "turn_item.updated" } + > => event.type === "turn_item.updated" && event.turnItem.type === "command_execution" && event.turnItem.nativeItemRef?.nativeId === INTERRUPT_CHILD_COMMAND_ITEM, @@ -5289,8 +5307,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { "running child command item", ); const providerTurnId = harness.events.find( - (event): event is Extract => - event.type === "provider_turn.updated" && event.threadId === harness.threadId, + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "provider_turn.updated" } + > => event.type === "provider_turn.updated" && event.threadId === harness.threadId, )?.providerTurn.id; assert.isDefined(providerTurnId); @@ -5361,8 +5383,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { "running child command item", ); const providerTurnId = harness.events.find( - (event): event is Extract => - event.type === "provider_turn.updated" && event.threadId === harness.threadId, + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "provider_turn.updated" } + > => event.type === "provider_turn.updated" && event.threadId === harness.threadId, )?.providerTurn.id; assert.isDefined(providerTurnId); @@ -5460,8 +5486,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { "running child command item", ); const providerTurnId = harness.events.find( - (event): event is Extract => - event.type === "provider_turn.updated" && event.threadId === harness.threadId, + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "provider_turn.updated" } + > => event.type === "provider_turn.updated" && event.threadId === harness.threadId, )?.providerTurn.id; assert.isDefined(providerTurnId); @@ -5481,7 +5511,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { yield* awaitUntil(() => harness.terminalEvents().length === 1, "interrupted root terminal"); const lateChildUpdates = harness.events.filter( - (event): event is Extract => + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "provider_turn.updated" } + > => event.type === "provider_turn.updated" && event.providerTurn.nativeTurnRef?.nativeId === INTERRUPT_LATE_CHILD_NATIVE_TURN, ); @@ -5589,8 +5624,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { "running child command item", ); const providerTurnId = harness.events.find( - (event): event is Extract => - event.type === "provider_turn.updated" && event.threadId === harness.threadId, + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "provider_turn.updated" } + > => event.type === "provider_turn.updated" && event.threadId === harness.threadId, )?.providerTurn.id; assert.isDefined(providerTurnId); @@ -5835,8 +5874,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { "running command item", ); const providerTurnId = harness.events.find( - (event): event is Extract => - event.type === "provider_turn.updated", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "provider_turn.updated" } + > => event.type === "provider_turn.updated", )?.providerTurn.id; assert.isDefined(providerTurnId); @@ -5868,8 +5911,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { assert.lengthOf(terminalProviderTurnsBeforeLateEvents, 1); const commandUpdatesBeforeLateEvents = harness.events.filter( - (event): event is Extract => - event.type === "turn_item.updated" && event.turnItem.type === "command_execution", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "turn_item.updated" } + > => event.type === "turn_item.updated" && event.turnItem.type === "command_execution", ); const terminalCommands = commandUpdatesBeforeLateEvents.filter( (event) => @@ -5993,8 +6040,12 @@ describe("CodexAdapterV2 post-settle continuation", () => { "running command item", ); const providerTurnId = harness.events.find( - (event): event is Extract => - event.type === "provider_turn.updated", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "provider_turn.updated" } + > => event.type === "provider_turn.updated", )?.providerTurn.id; assert.isDefined(providerTurnId); @@ -7663,7 +7714,7 @@ describe("CodexAdapterV2 post-settle continuation", () => { }), ); - assert.instanceOf(error, ProviderAdapterRollbackThreadError); + assert.instanceOf(error, ProviderAdapter.ProviderAdapterRollbackThreadError); assert.include( errorCauseChainText(error), "legacy", @@ -7904,7 +7955,7 @@ describe("CodexAdapterV2 post-settle continuation", () => { }), ); - assert.instanceOf(error, ProviderAdapterForkThreadError); + assert.instanceOf(error, ProviderAdapter.ProviderAdapterForkThreadError); assert.include( errorCauseChainText(error), "legacy", @@ -7969,7 +8020,7 @@ describe("CodexAdapterV2 post-settle continuation", () => { }), ); - assert.instanceOf(error, ProviderAdapterForkThreadError); + assert.instanceOf(error, ProviderAdapter.ProviderAdapterForkThreadError); assert.include(errorCauseChainText(error), "fork exploded"); }).pipe(Effect.scoped, Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))), ); @@ -8033,7 +8084,7 @@ describe("CodexAdapterV2 post-settle continuation", () => { }), ), ); - const providerGoals = (events: ReadonlyArray) => + const providerGoals = (events: ReadonlyArray) => events.flatMap((event) => event.type === "provider_thread.updated" ? [event.providerThread.goal?.status ?? null] : [], ); diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.testkit.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.testkit.ts index 0941a1f88e3adeaa88ff8447ef04aecc7f13f915..ea949828076da2c0c129b4d8a8f2debd4bd7453f 100644 --- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.testkit.ts +++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.testkit.ts @@ -15,7 +15,7 @@ import * as Schema from "effect/Schema"; import * as ServerConfig from "../../config.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import { ProviderAdapterOpenSessionError } from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import { ProviderAdapterDriverCreateError } from "@t3tools/provider-core/server/adapterDriver"; import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts"; import type { OrchestratorV2ProviderReplayHarness } from "../testkit/ProviderReplayHarness.ts"; @@ -195,7 +195,7 @@ export function layer(input: { const context = yield* Layer.build(layerReplay).pipe( Effect.mapError( (cause) => - new ProviderAdapterOpenSessionError({ + new ProviderAdapter.ProviderAdapterOpenSessionError({ driver: CodexAdapterV2.CODEX_DRIVER_KIND, providerSessionId: openInput.providerSessionId, cause, diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts index c8b98828939027d814389dc068db5b48b8b687fa..6ae159b2cc339ec98730117778b9d25306c98acf 100644 --- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts @@ -102,10 +102,9 @@ import { } from "../../provider/Drivers/CodexHomeLayout.ts"; import { boundProviderEventForLogging, - type EventNdjsonLogger, shouldPersistProviderEvent, } from "../../provider/EventNdjsonLogger.ts"; -import { ProviderEventLoggers } from "../../provider/ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import { codexAppServerArgs, resolveCodexLaunchArgs } from "../../provider/codexLaunchArgs.ts"; import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment"; import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession"; @@ -121,11 +120,7 @@ import { type ProviderAdapterDriver, type ProviderAdapterDriverCreateInput, } from "@t3tools/provider-core/server/adapterDriver"; -import { IdAllocatorV2, type IdAllocatorV2Shape } from "@t3tools/provider-core/server/IdAllocator"; -import { - type ProviderContinuationRequest, - ProviderContinuationRequests, -} from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { backgroundWorkNotification } from "@t3tools/provider-core/server/notification"; import { makeProviderFailure, @@ -137,35 +132,13 @@ import { isProviderNativeImageAttachment, providerMessageTextWithAttachmentPaths, } from "@t3tools/provider-core/server/attachmentPrompt"; -import { - ProviderAdapterEnsureThreadError, - ProviderAdapterForkThreadError, - ProviderAdapterInterruptError, - ProviderAdapterOpenSessionError, - ProviderAdapterProtocolError, - ProviderAdapterReadThreadSnapshotError, - ProviderAdapterResumeThreadError, - ProviderAdapterRollbackThreadError, - ProviderAdapterRuntimeRequestResponseError, - ProviderAdapterSteerRunError, - ProviderAdapterTurnStartError, - ProviderAdapterV2, - type ProviderAdapterV2Shape, - type ProviderAdapterV2Event, - type ProviderAdapterV2ForkThreadInput, - type ProviderAdapterV2RollbackThreadInput, - type ProviderAdapterV2RuntimePolicy, - type ProviderAdapterV2McpApps, - type ProviderAdapterV2SessionRuntime, - type ProviderAdapterV2InterruptInput, - type ProviderAdapterV2SteerInput, - type ProviderAdapterV2TurnInput, -} from "@t3tools/provider-core/server/ProviderAdapter"; import { makeSubagentChildThread, makeSubagentConversationArtifacts, subagentThreadTitle, } from "@t3tools/provider-core/server/subagentProjection"; +import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const CODEX_PROVIDER = ProviderDriverKind.make("codex"); export const CODEX_DRIVER_KIND = CODEX_PROVIDER; @@ -341,8 +314,11 @@ export const CodexProviderCapabilitiesV2 = { }, } satisfies OrchestrationV2ProviderCapabilities; -function toProtocolError(detail: string, payload?: unknown): ProviderAdapterProtocolError { - return new ProviderAdapterProtocolError({ +function toProtocolError( + detail: string, + payload?: unknown, +): ProviderAdapter.ProviderAdapterProtocolError { + return new ProviderAdapter.ProviderAdapterProtocolError({ driver: CODEX_PROVIDER, detail, ...(payload === undefined ? {} : { payload }), @@ -385,7 +361,7 @@ function mapCodexTurnStatus( function providerTurnStatusToTerminal( status: OrchestrationV2ProviderTurn["status"], -): Extract["status"] { +): Extract["status"] { switch (status) { case "completed": return "completed"; @@ -677,7 +653,7 @@ const decodeCodexTurnStartParamsWithCollaborationMode = Schema.decodeUnknownEffe CodexTurnStartParamsWithCollaborationMode, ); const isProviderAdapterRuntimeRequestResponseError = Schema.is( - ProviderAdapterRuntimeRequestResponseError, + ProviderAdapter.ProviderAdapterRuntimeRequestResponseError, ); function codexRuntimeModeTurnDefaults(runtimeMode: RuntimeMode): { @@ -724,7 +700,7 @@ function codexRuntimeModeTurnDefaults(runtimeMode: RuntimeMode): { export function buildCodexTurnStartParams(input: { readonly nativeThreadId: string; readonly codexInput: ReadonlyArray; - readonly runtimePolicy: ProviderAdapterV2RuntimePolicy; + readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy; readonly modelSelection: ModelSelection; readonly hasT3Mcp?: boolean; readonly browserToolsAvailable?: boolean; @@ -732,7 +708,7 @@ export function buildCodexTurnStartParams(input: { /** ChatGPT token sharing does not accept service tiers. */ readonly omitServiceTier?: boolean; /** What the thread's MCP Apps want the agent to know (`ui/update-model-context`). */ - readonly appContext?: ProviderAdapterV2TurnInput["appContext"]; + readonly appContext?: ProviderAdapter.ProviderAdapterV2TurnInput["appContext"]; }) { return Effect.gen(function* () { const runtimeModeDefaults = codexRuntimeModeTurnDefaults(input.runtimePolicy.runtimeMode); @@ -851,7 +827,7 @@ function getNativeThreadId(providerThread: OrchestrationV2ProviderThread) { function providerThreadFromCodexThread(input: { readonly appThreadId: ThreadId | null; - readonly idAllocator: IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly ownerNodeId: OrchestrationV2ProviderThread["ownerNodeId"]; readonly providerSessionId: OrchestrationV2ProviderThread["providerSessionId"]; readonly providerInstanceId: ProviderInstanceId; @@ -983,7 +959,7 @@ const countTerminalTurnsAfterBoundary = ( }; const resolveCodexForkRollbackTurnCount = Effect.fn("CodexAdapterV2.resolveForkRollbackTurnCount")( - function* (input: ProviderAdapterV2ForkThreadInput) { + function* (input: ProviderAdapter.ProviderAdapterV2ForkThreadInput) { if (input.providerTurnId === undefined || input.sourceProviderTurns === undefined) { return 0; } @@ -993,7 +969,7 @@ const resolveCodexForkRollbackTurnCount = Effect.fn("CodexAdapterV2.resolveForkR input.providerTurnId, ); if (rollbackTurnCount === null) { - return yield* new ProviderAdapterForkThreadError({ + return yield* new ProviderAdapter.ProviderAdapterForkThreadError({ driver: CODEX_PROVIDER, providerThreadId: input.sourceProviderThread.id, cause: `Cannot fork Codex thread from provider turn ${input.providerTurnId}: source turn was not found in provider thread ${input.sourceProviderThread.id}.`, @@ -1012,7 +988,7 @@ const resolveCodexForkRollbackTurnCount = Effect.fn("CodexAdapterV2.resolveForkR * only for source turns that predate native turn references. */ export const resolveCodexForkBoundary = Effect.fn("CodexAdapterV2.resolveForkBoundary")(function* ( - input: ProviderAdapterV2ForkThreadInput, + input: ProviderAdapter.ProviderAdapterV2ForkThreadInput, ) { const rollbackTurnCount = yield* resolveCodexForkRollbackTurnCount(input); if (input.providerTurnId === undefined || input.sourceProviderTurns === undefined) { @@ -1066,14 +1042,14 @@ const readCodexThreadHistoryMetadata = Effect.fn("CodexAdapterV2.readThreadHisto ); export const resolveCodexRollbackTurnCount = Effect.fn("CodexAdapterV2.resolveRollbackTurnCount")( - function* (input: ProviderAdapterV2RollbackThreadInput) { + function* (input: ProviderAdapter.ProviderAdapterV2RollbackThreadInput) { const providerTurns = input.providerThreadTurns; switch (input.target.type) { case "thread_start": return providerTurns.filter(isTerminalProviderTurn).length; case "provider_turn": { if (input.target.providerTurn.providerThreadId !== input.providerThread.id) { - return yield* new ProviderAdapterRollbackThreadError({ + return yield* new ProviderAdapter.ProviderAdapterRollbackThreadError({ driver: CODEX_PROVIDER, providerThreadId: input.providerThread.id, cause: `Cannot roll back Codex thread ${input.providerThread.id} to provider turn ${input.target.providerTurn.id}: target turn belongs to provider thread ${input.target.providerTurn.providerThreadId}.`, @@ -1085,7 +1061,7 @@ export const resolveCodexRollbackTurnCount = Effect.fn("CodexAdapterV2.resolveRo input.target.providerTurn.id, ); if (rollbackTurnCount === null) { - return yield* new ProviderAdapterRollbackThreadError({ + return yield* new ProviderAdapter.ProviderAdapterRollbackThreadError({ driver: CODEX_PROVIDER, providerThreadId: input.providerThread.id, cause: `Cannot roll back Codex thread ${input.providerThread.id} to provider turn ${input.target.providerTurn.id}: target turn was not found in durable provider turn history.`, @@ -1129,10 +1105,10 @@ interface ActiveCodexTurnContext { readonly failure: OrchestrationV2ProviderFailure; }; readonly nativeStartReady?: Deferred.Deferred; - readonly input: ProviderAdapterV2TurnInput; + readonly input: ProviderAdapter.ProviderAdapterV2TurnInput; readonly projectionAppThread: OrchestrationV2AppThread; readonly projectionThreadId: ThreadId; - readonly projectionRunId: ProviderAdapterV2TurnInput["runId"] | null; + readonly projectionRunId: ProviderAdapter.ProviderAdapterV2TurnInput["runId"] | null; readonly nativeTurnId: string; readonly providerThread: OrchestrationV2ProviderThread; readonly providerTurnId: ProviderTurnId; @@ -1177,7 +1153,10 @@ function isPersistentCodexDynamicTool(item: CodexDynamicToolItem): boolean { return Reflect.get(input, "persistent") === true; } -type CodexRootTerminalEvent = Extract; +type CodexRootTerminalEvent = Extract< + ProviderAdapter.ProviderAdapterV2Event, + { readonly type: "turn.terminal" } +>; /** A completed root turn whose run stays open for the goal turn Codex starts next. */ interface CodexGoalHold { @@ -1294,12 +1273,12 @@ export interface CodexAppServerClientFactoryShape { readonly instanceId: ProviderInstanceId; readonly threadId: ThreadId; readonly providerSessionId: OrchestrationV2ProviderSession["id"]; - readonly runtimePolicy: ProviderAdapterV2RuntimePolicy; + readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy; readonly settings: CodexSettings; readonly environment: NodeJS.ProcessEnv; }) => Effect.Effect< CodexClient.CodexAppServerClient["Service"], - ProviderAdapterOpenSessionError, + ProviderAdapter.ProviderAdapterOpenSessionError, Scope.Scope >; } @@ -1319,7 +1298,7 @@ export const CODEX_THREAD_CONFIG = { "tools.update_plan.enabled": true } as cons export function codexThreadRuntimeParams(input: { readonly threadId: ThreadId | null; readonly modelSelection?: { readonly model: string }; - readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy; + readonly runtimePolicy?: ProviderAdapter.ProviderAdapterV2RuntimePolicy; }): { readonly cwd?: string; readonly model?: string; @@ -1417,7 +1396,7 @@ const layerCodexAppServerClientFactoryCommand = ( Effect.provideService(Scope.Scope, scope), Effect.mapError( (cause) => - new ProviderAdapterOpenSessionError({ + new ProviderAdapter.ProviderAdapterOpenSessionError({ driver: CODEX_PROVIDER, providerSessionId: input.providerSessionId, cause, @@ -1434,7 +1413,7 @@ const layerCodexAppServerClientFactoryCommand = ( ); export function makeCodexAppServerProtocolLogger(input: { - readonly nativeEventLogger: EventNdjsonLogger | undefined; + readonly nativeEventLogger: ProviderEventLoggers.EventNdjsonLogger | undefined; readonly threadId: ThreadId; readonly providerSessionId: OrchestrationV2ProviderSession["id"]; }): CodexClient.CodexAppServerClientOptions["logger"] | undefined { @@ -1510,12 +1489,12 @@ function isSensitiveCodexProtocolKey(key: string): boolean { export const layerAppServerClientFactory: Layer.Layer< CodexAppServerClientFactory, never, - ChildProcessSpawner.ChildProcessSpawner | ProviderEventLoggers + ChildProcessSpawner.ChildProcessSpawner | ProviderEventLoggers.ProviderEventLoggers > = Layer.effect( CodexAppServerClientFactory, Effect.gen(function* () { const spawner = yield* ChildProcessSpawner.ChildProcessSpawner; - const { native: nativeEventLogger } = yield* ProviderEventLoggers; + const { native: nativeEventLogger } = yield* ProviderEventLoggers.ProviderEventLoggers; return CodexAppServerClientFactory.of({ open: (input) => @@ -1536,7 +1515,7 @@ export const layerAppServerClientFactory: Layer.Layer< Effect.provideService(Scope.Scope, scope), Effect.mapError( (cause) => - new ProviderAdapterOpenSessionError({ + new ProviderAdapter.ProviderAdapterOpenSessionError({ driver: CODEX_PROVIDER, providerSessionId: input.providerSessionId, cause, @@ -1569,7 +1548,7 @@ export type CodexAdapterV2DriverEnv = | CodexAppServerClientFactory | Crypto.Crypto | FileSystem.FileSystem - | IdAllocatorV2 + | IdAllocator.IdAllocatorV2 | Path.Path | ServerConfig; @@ -1579,11 +1558,11 @@ export const createCodexAdapterV2 = ( ) => Effect.gen(function* () { const clientFactory = yield* CodexAppServerClientFactory; - const continuationRequests = yield* ProviderContinuationRequests; + const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests; const crypto = yield* Crypto.Crypto; const fileSystem = yield* FileSystem.FileSystem; const hostEnvironment = yield* HostProcessEnvironment; - const idAllocator = yield* IdAllocatorV2; + const idAllocator = yield* IdAllocator.IdAllocatorV2; const serverConfig = yield* ServerConfig; const homeLayout = yield* resolveCodexHomeLayout(config); @@ -1628,18 +1607,22 @@ export const CodexAdapterV2Driver: ProviderAdapterDriver = Layer.effect( - ProviderAdapterV2, + ProviderAdapter.ProviderAdapterV2, Effect.gen(function* () { const clientFactory = yield* CodexAppServerClientFactory; - const continuationRequests = yield* ProviderContinuationRequests; + const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests; const crypto = yield* Crypto.Crypto; const fileSystem = yield* FileSystem.FileSystem; const hostEnvironment = yield* HostProcessEnvironment; - const idAllocator = yield* IdAllocatorV2; + const idAllocator = yield* IdAllocator.IdAllocatorV2; const serverConfig = yield* ServerConfig; return makeCodexAdapterV2({ @@ -1670,7 +1653,7 @@ export interface CodexAdapterV2Options { readonly resolveRuntime?: Effect.Effect; readonly crypto: Crypto.Crypto; readonly fileSystem: FileSystem.FileSystem; - readonly idAllocator: IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly serverConfig: ServerConfig["Service"]; /** * Sink for post-settle background command completions so the orchestrator @@ -1678,15 +1661,19 @@ export interface CodexAdapterV2Options { * projection-only handling for late item completions. */ readonly continuationRequests?: { - readonly offer: (request: ProviderContinuationRequest) => Effect.Effect; + readonly offer: ( + request: ProviderContinuationRequests.ProviderContinuationRequest, + ) => Effect.Effect; }; } -export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): ProviderAdapterV2Shape { +export function makeCodexAdapterV2( + adapterOptions: CodexAdapterV2Options, +): ProviderAdapter.ProviderAdapterV2["Service"] { const { clientFactory, crypto, fileSystem, idAllocator, serverConfig } = adapterOptions; const continuationRequests = adapterOptions.continuationRequests; - return ProviderAdapterV2.of({ + return ProviderAdapter.ProviderAdapterV2.of({ instanceId: adapterOptions.instanceId, driver: CODEX_PROVIDER, getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2), @@ -1700,7 +1687,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi : yield* adapterOptions.resolveRuntime.pipe( Effect.mapError( (cause) => - new ProviderAdapterOpenSessionError({ + new ProviderAdapter.ProviderAdapterOpenSessionError({ driver: CODEX_PROVIDER, providerSessionId: input.providerSessionId, cause, @@ -1800,7 +1787,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi model: input.modelSelection.model, now, }); - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); const rateLimitSnapshot = yield* Ref.make(undefined); const limitedTurnItems = yield* Ref.make( new Map>(), @@ -1833,7 +1820,9 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi context.nativeTurnId, ).hasSubagents = true; }; - const pendingRootTurns = yield* Ref.make(new Map()); + const pendingRootTurns = yield* Ref.make( + new Map(), + ); const turnWaiters = yield* Ref.make(new Map>()); const subagentThreads = yield* Ref.make(new Map()); const subagentSelections = new Map>(); @@ -1893,7 +1882,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi const latestGoalTurnId = (providerTurnId: ProviderTurnId) => goalRuns.get(providerTurnId)?.at(-1)?.providerTurnId ?? providerTurnId; - const emitProviderEvent = (event: ProviderAdapterV2Event) => + const emitProviderEvent = (event: ProviderAdapter.ProviderAdapterV2Event) => Queue.offer(events, event).pipe(Effect.asVoid); /** Writes the thread's current native goal onto its root provider thread. */ @@ -1942,7 +1931,6 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi type: "turn_item.updated", driver: CODEX_PROVIDER, turnItem: makeProviderRetryTurnItem({ - idAllocator, driver: CODEX_PROVIDER, threadId: context.projectionThreadId, runId: context.projectionRunId, @@ -1960,7 +1948,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }); const registerRootTurn = (input: { - readonly turnInput: ProviderAdapterV2TurnInput; + readonly turnInput: ProviderAdapter.ProviderAdapterV2TurnInput; readonly nativeTurnId: string; readonly startedAt: DateTime.Utc; readonly waitForNativeStart?: boolean; @@ -3143,7 +3131,11 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }); const toCodexInput = ( - turnInput: Pick, + turnInput: Pick< + | ProviderAdapter.ProviderAdapterV2TurnInput + | ProviderAdapter.ProviderAdapterV2SteerInput, + "message" + >, ) => Effect.gen(function* () { const inputItems: Array = []; @@ -4539,7 +4531,6 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi type: "turn_item.updated", driver: CODEX_PROVIDER, turnItem: makeProviderRetryTurnItem({ - idAllocator, driver: CODEX_PROVIDER, threadId: context.projectionThreadId, runId: context.projectionRunId, @@ -5584,7 +5575,6 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi } if (current.status === "failed" && current.failure.class === "usage_limit") { const item = makeProviderFailureTurnItem({ - idAllocator, driver: CODEX_PROVIDER, threadId: context.input.threadId, runId: context.input.runId, @@ -5735,7 +5725,6 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi type: "turn_item.updated", driver: CODEX_PROVIDER, turnItem: makeProviderRetryTurnItem({ - idAllocator, driver: CODEX_PROVIDER, threadId: input.context.projectionThreadId, runId: input.context.projectionRunId, @@ -6000,7 +5989,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi * assistant text, as Claude's own `/goal` output is. */ const completeGoalCommandTurn = Effect.fnUntraced(function* ( - turnInput: ProviderAdapterV2TurnInput, + turnInput: ProviderAdapter.ProviderAdapterV2TurnInput, reply: string, ) { const now = yield* DateTime.now; @@ -6104,7 +6093,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi * Stop also reaches. */ const resolveGoalStopTarget = Effect.fnUntraced(function* ( - turnInput: ProviderAdapterV2InterruptInput, + turnInput: ProviderAdapter.ProviderAdapterV2InterruptInput, ) { const goalThreadId = turnInput.providerThread.nativeThreadRef?.nativeId; if (goalThreadId == null) { @@ -6172,7 +6161,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi /** Starts a native turn with this run's full turn configuration. */ const startNativeTurn = ( - turnInput: ProviderAdapterV2TurnInput, + turnInput: ProviderAdapter.ProviderAdapterV2TurnInput, codexInput: ReadonlyArray, ) => Effect.gen(function* () { @@ -6227,7 +6216,10 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi * turn Codex starts on its own reuses the last turn's settings. Codex * continues later goal turns itself. Other commands settle with a reply. */ - const runGoalCommand = (turnInput: ProviderAdapterV2TurnInput, command: CodexGoalCommand) => + const runGoalCommand = ( + turnInput: ProviderAdapter.ProviderAdapterV2TurnInput, + command: CodexGoalCommand, + ) => Effect.gen(function* () { const threadId = yield* getNativeThreadId(turnInput.providerThread); // Goal notifications during the command belong to this run's snapshot. @@ -6326,7 +6318,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterTurnStartError({ + new ProviderAdapter.ProviderAdapterTurnStartError({ driver: CODEX_PROVIDER, threadId: turnInput.threadId, providerThreadId: turnInput.providerThread.id, @@ -6339,8 +6331,12 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi // MCP Apps reach their server through Codex's own MCP client, so any // server the user configured for Codex works without T3 connecting to it. const mcpAppsError = (detail: string) => (cause: unknown) => - new ProviderAdapterProtocolError({ driver: CODEX_PROVIDER, detail, payload: cause }); - const mcpApps: ProviderAdapterV2McpApps = { + new ProviderAdapter.ProviderAdapterProtocolError({ + driver: CODEX_PROVIDER, + detail, + payload: cause, + }); + const mcpApps: ProviderAdapter.ProviderAdapterV2McpApps = { listTools: (toolsInput) => Effect.gen(function* () { const threadId = yield* getNativeThreadId(toolsInput.providerThread); @@ -6394,7 +6390,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe(Effect.mapError(mcpAppsError("Codex MCP resource read failed."))), }; - const runtime: ProviderAdapterV2SessionRuntime = { + const runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime = { instanceId: adapterOptions.instanceId, driver: CODEX_PROVIDER, providerSessionId: input.providerSessionId, @@ -6471,7 +6467,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi ), Effect.mapError( (cause) => - new ProviderAdapterEnsureThreadError({ + new ProviderAdapter.ProviderAdapterEnsureThreadError({ driver: CODEX_PROVIDER, threadId: threadInput.threadId, cause: normalizeCodexCause(cause), @@ -6535,7 +6531,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterResumeThreadError({ + new ProviderAdapter.ProviderAdapterResumeThreadError({ driver: CODEX_PROVIDER, providerSessionId: input.providerSessionId, providerThreadId: threadInput.providerThread.id, @@ -6563,7 +6559,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterTurnStartError({ + new ProviderAdapter.ProviderAdapterTurnStartError({ driver: CODEX_PROVIDER, threadId: turnInput.threadId, providerThreadId: turnInput.providerThread.id, @@ -6593,7 +6589,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterProtocolError({ + new ProviderAdapter.ProviderAdapterProtocolError({ driver: CODEX_PROVIDER, detail: "Failed to inject historical context", cause, @@ -6617,7 +6613,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterTurnStartError({ + new ProviderAdapter.ProviderAdapterTurnStartError({ driver: CODEX_PROVIDER, threadId: turnInput.threadId, providerThreadId: turnInput.providerThread.id, @@ -6655,7 +6651,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterSteerRunError({ + new ProviderAdapter.ProviderAdapterSteerRunError({ driver: CODEX_PROVIDER, providerThreadId: turnInput.providerThread.id, providerTurnId: turnInput.providerTurnId, @@ -6674,7 +6670,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi Effect.mapError((cause) => cause._tag === "ProviderAdapterProtocolError" ? cause - : new ProviderAdapterProtocolError({ + : new ProviderAdapter.ProviderAdapterProtocolError({ driver: CODEX_PROVIDER, detail: `Failed to unload Codex thread for provider thread ${unloadInput.providerThread.id}`, cause: normalizeCodexCause(cause), @@ -7061,7 +7057,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterInterruptError({ + new ProviderAdapter.ProviderAdapterInterruptError({ driver: CODEX_PROVIDER, providerThreadId: requestedInput.providerThread.id, providerTurnId: requestedInput.providerTurnId, @@ -7075,7 +7071,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi String(requestInput.requestId), ); if (pending === undefined) { - return yield* new ProviderAdapterRuntimeRequestResponseError({ + return yield* new ProviderAdapter.ProviderAdapterRuntimeRequestResponseError({ driver: CODEX_PROVIDER, requestId: requestInput.requestId, cause: toProtocolError( @@ -7085,7 +7081,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi } if (pending.type === "user_input") { if (requestInput.answers === undefined) { - return yield* new ProviderAdapterRuntimeRequestResponseError({ + return yield* new ProviderAdapter.ProviderAdapterRuntimeRequestResponseError({ driver: CODEX_PROVIDER, requestId: requestInput.requestId, cause: toProtocolError( @@ -7097,7 +7093,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi return; } if (requestInput.decision === undefined) { - return yield* new ProviderAdapterRuntimeRequestResponseError({ + return yield* new ProviderAdapter.ProviderAdapterRuntimeRequestResponseError({ driver: CODEX_PROVIDER, requestId: requestInput.requestId, cause: toProtocolError( @@ -7110,7 +7106,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi Effect.mapError((cause) => isProviderAdapterRuntimeRequestResponseError(cause) ? cause - : new ProviderAdapterRuntimeRequestResponseError({ + : new ProviderAdapter.ProviderAdapterRuntimeRequestResponseError({ driver: CODEX_PROVIDER, requestId: requestInput.requestId, cause, @@ -7134,7 +7130,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterProtocolError({ + new ProviderAdapter.ProviderAdapterProtocolError({ driver: CODEX_PROVIDER, detail: "Failed to upload Codex thread feedback.", payload: cause, @@ -7167,7 +7163,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterReadThreadSnapshotError({ + new ProviderAdapter.ProviderAdapterReadThreadSnapshotError({ driver: CODEX_PROVIDER, providerThreadId: threadInput.providerThread.id, cause, @@ -7200,7 +7196,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi Effect.andThen(readCodexThreadHistoryMetadata(client.raw, threadId)), ); if (historyMode !== "paginated") { - return yield* new ProviderAdapterRollbackThreadError({ + return yield* new ProviderAdapter.ProviderAdapterRollbackThreadError({ driver: CODEX_PROVIDER, providerThreadId: threadInput.providerThread.id, cause: `Cannot roll back Codex thread ${threadId}: the thread uses legacy history, which Codex 0.156 cannot revert.`, @@ -7244,7 +7240,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterRollbackThreadError({ + new ProviderAdapter.ProviderAdapterRollbackThreadError({ driver: CODEX_PROVIDER, providerThreadId: threadInput.providerThread.id, cause: normalizeCodexCause(cause), @@ -7275,7 +7271,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi ), Effect.mapError( (cause) => - new ProviderAdapterForkThreadError({ + new ProviderAdapter.ProviderAdapterForkThreadError({ driver: CODEX_PROVIDER, providerThreadId: threadInput.sourceProviderThread.id, cause: normalizeCodexCause(cause), @@ -7291,7 +7287,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi Effect.andThen(readCodexThreadHistoryMetadata(client.raw, response.thread.id)), ); if (historyMode !== "paginated") { - return yield* new ProviderAdapterForkThreadError({ + return yield* new ProviderAdapter.ProviderAdapterForkThreadError({ driver: CODEX_PROVIDER, providerThreadId: threadInput.sourceProviderThread.id, cause: `Cannot fork Codex thread ${threadId} at provider turn ${threadInput.providerTurnId}: the source turn has no native Codex turn reference, and the forked thread uses legacy history which Codex 0.156 cannot revert.`, @@ -7303,7 +7299,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi ), Effect.mapError( (cause) => - new ProviderAdapterForkThreadError({ + new ProviderAdapter.ProviderAdapterForkThreadError({ driver: CODEX_PROVIDER, providerThreadId: threadInput.sourceProviderThread.id, cause: normalizeCodexCause(cause), @@ -7328,7 +7324,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterForkThreadError({ + new ProviderAdapter.ProviderAdapterForkThreadError({ driver: CODEX_PROVIDER, providerThreadId: threadInput.sourceProviderThread.id, cause: normalizeCodexCause(cause), @@ -7340,7 +7336,7 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi }).pipe( Effect.mapError( (cause) => - new ProviderAdapterOpenSessionError({ + new ProviderAdapter.ProviderAdapterOpenSessionError({ driver: CODEX_PROVIDER, providerSessionId: input.providerSessionId, cause, diff --git a/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.ts b/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.ts index 3f2f6581f90d4af73b1471166b85ef07eef59115..fa347db3478dfa92f95591514ec4b1cc2f8c6466 100644 --- a/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.ts +++ b/apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.ts @@ -28,7 +28,7 @@ import { cursorSdkModelSelection, makeCursorAgentOptions, } from "@t3tools/provider-cursor/testing"; -import type { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import type { RuntimePolicyV2Override } from "../RuntimePolicy.ts"; const CursorAgentSdkReplayTranscript = Schema.Struct({ @@ -625,7 +625,7 @@ function recordingRuntimePolicy(input: { readonly cwd: string; readonly interactionMode: "default" | "plan"; readonly override?: Pick; -}): ProviderAdapterV2RuntimePolicy { +}): ProviderAdapter.ProviderAdapterV2RuntimePolicy { return { runtimeMode: "full-access", interactionMode: input.interactionMode, diff --git a/apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.test.ts index a21f16853b9bf5e7b46b263132cb7db582dfdd56..960d29beb4e73fb8a48304c5175fe35a0c565fb4 100644 --- a/apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.test.ts @@ -26,7 +26,7 @@ import { buildInitialGrokProviderSnapshot } from "@t3tools/provider-grok/testing import type { ProviderInstance } from "@t3tools/provider-core/server/driver"; import * as ProviderInstanceRegistry from "../../provider/ProviderInstanceRegistry.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as RuntimePolicy from "../RuntimePolicy.ts"; import { acpPermissionDisposition } from "@t3tools/provider-acp/server/clientPolicy"; import { @@ -68,7 +68,7 @@ function runtimePolicy(input: { readonly approvalPolicy?: unknown; readonly sandboxPolicy?: unknown; }) { - return ProviderAdapterV2RuntimePolicy.make({ + return ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: input.runtimeMode, interactionMode: "default", cwd: "/workspace", @@ -314,7 +314,7 @@ describe("Grok launch permission mode", () => { // Opens a session through the adapter's own Grok runtime factory and returns // the argv it tried to launch. The spawn fails after recording, so no // process starts. - const launchArgs = (runtimePolicy: ProviderAdapterV2RuntimePolicy) => + const launchArgs = (runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy) => Effect.gen(function* () { const launches: Array> = []; const childProcessSpawner = ChildProcessSpawner.make((command) => { @@ -352,9 +352,9 @@ describe("Grok launch permission mode", () => { const policy = ( runtimeMode: RuntimeMode, - override: Partial = {}, + override: Partial = {}, ) => - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode, interactionMode: "default", cwd: process.cwd(), diff --git a/apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.testkit.ts b/apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.testkit.ts index 37de61f072ce4b8d6e1cc587418734ec1e490ead..467ad620d534ea542d492ca9ade634b72550b0ac 100644 --- a/apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.testkit.ts +++ b/apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.testkit.ts @@ -13,7 +13,7 @@ import { layerTestProviderHost } from "@t3tools/provider-testing/host"; import { GROK_ACP_CANCEL_META, GROK_ACP_INITIALIZE_META } from "@t3tools/provider-grok/testing"; import { makeXAiPromptCompletionRuntime } from "@t3tools/provider-grok/testing"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts"; import type { ProviderReplayGate } from "@t3tools/provider-testing/replayGate"; import type { OrchestratorV2ProviderReplayHarness } from "../testkit/ProviderReplayHarness.ts"; diff --git a/apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.testkit.ts b/apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.testkit.ts index 1d10bb8e50e150cbe0ba0db9b8c86a4b7cb602b3..b695b39fa8d0249af05b3447c9f94616c6df62b9 100644 --- a/apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.testkit.ts +++ b/apps/server/src/orchestration-v2/Adapters/MuseAdapterV2.testkit.ts @@ -36,7 +36,7 @@ import { } from "@t3tools/provider-muse/testing"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import type { OrchestratorV2ProviderReplayHarness } from "../testkit/ProviderReplayHarness.ts"; import { makeMuseAdapterV2 } from "@t3tools/provider-muse/server"; diff --git a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts index ff87c347641e5f6be84e47ac57330fddaecf7d5a..789ed7e778595faf7436e5fee2a7ab721e7efb04 100644 --- a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts @@ -38,14 +38,10 @@ import * as Exit from "effect/Exit"; import { TestClock } from "effect/testing"; import { describe } from "vite-plus/test"; -import type { - ProviderAdapterV2Event, - ProviderAdapterV2SessionRuntime, -} from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import type { ProviderContinuationRequest } from "@t3tools/provider-core/server/continuationRequests"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { OPENCODE_2_STILL_STOPPING, OPENCODE_PROVIDER, @@ -347,21 +343,27 @@ const resumed = ( return { runtime, thread }; }); -const requestOf = (runtime: ProviderAdapterV2SessionRuntime) => +const requestOf = (runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime) => runtime.events.pipe( Stream.filter( - (event): event is Extract => - event.type === "runtime_request.updated", + ( + event, + ): event is Extract< + ProviderAdapter.ProviderAdapterV2Event, + { type: "runtime_request.updated" } + > => event.type === "runtime_request.updated", ), Stream.map((event) => event.runtimeRequest), Stream.runHead, Effect.map(Option.getOrUndefined), ); -const terminalOf = (runtime: ProviderAdapterV2SessionRuntime) => +const terminalOf = (runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime) => runtime.events.pipe( Stream.filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "turn.terminal", ), Stream.runHead, @@ -637,7 +639,7 @@ describe("OpenCode2 adapter", () => { * The single reader of the runtime's events: resolves `attached` once the * running background child has its thread, then returns the turn's terminal. */ - const watchBackgroundTurn = (runtime: ProviderAdapterV2SessionRuntime) => + const watchBackgroundTurn = (runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime) => Effect.gen(function* () { const attached = yield* Deferred.make(); const terminal = yield* runtime.events.pipe( @@ -647,7 +649,9 @@ describe("OpenCode2 adapter", () => { : Effect.void, ), Stream.filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "turn.terminal", ), Stream.runHead, @@ -767,7 +771,9 @@ describe("OpenCode2 adapter", () => { : Effect.void, ), Stream.filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "turn.terminal", ), Stream.runHead, @@ -809,7 +815,9 @@ describe("OpenCode2 adapter", () => { const firstEnded = yield* Deferred.make(); const ended = yield* runtime.events.pipe( Stream.filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "turn.terminal", ), Stream.tap(() => Deferred.succeed(firstEnded, undefined)), @@ -1110,7 +1118,7 @@ describe("OpenCode2 adapter", () => { event("session.execution.succeeded", { sessionID: SESSION }), ]; /** The runtime's events, with the background subagent's statuses and the middle session's turns. */ - const watchNested = (runtime: ProviderAdapterV2SessionRuntime) => + const watchNested = (runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime) => Effect.gen(function* () { const deep: Array = []; const middleTurns = new Map(); @@ -1325,7 +1333,7 @@ describe("OpenCode2 adapter", () => { attemptId: RunAttemptId.make("attempt:opencode2-adapter:2"), }); const stopFirstTurn = ( - runtime: ProviderAdapterV2SessionRuntime, + runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime, thread: OrchestrationV2ProviderThread, ) => Effect.gen(function* () { @@ -1336,10 +1344,12 @@ describe("OpenCode2 adapter", () => { yield* TestClock.adjust("11 seconds"); yield* Fiber.join(interrupt); }); - const terminals = (runtime: ProviderAdapterV2SessionRuntime, count: number) => + const terminals = (runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime, count: number) => runtime.events.pipe( Stream.filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "turn.terminal", ), Stream.take(count), @@ -2113,7 +2123,9 @@ describe("OpenCode2 adapter", () => { }), ), Stream.filter( - (event): event is Extract => + ( + event, + ): event is Extract => event.type === "turn.terminal", ), Stream.tap(() => Deferred.succeed(firstEnded, undefined)), @@ -2331,7 +2343,7 @@ describe("OpenCode2 adapter", () => { replyData("session.form.list", forms), ]; - const turnItems = (collected: ReadonlyArray) => + const turnItems = (collected: ReadonlyArray) => collected.flatMap((event) => event.type === "turn_item.updated" ? [`${event.turnItem.type}:${event.turnItem.status}`] : [], ); @@ -3043,7 +3055,7 @@ describe("OpenCode2 adapter", () => { Effect.gen(function* () { const kept = "msg_t3_turn_run-attempt:kept:1"; const dropped = "msg_t3_turn_run-attempt:dropped:1"; - const offers: Array = []; + const offers: Array = []; const { runtime, thread } = yield* resumed([ out("message.list", ""), reply("message.list", { @@ -3727,7 +3739,7 @@ describe("OpenCode2 adapter", () => { */ const continued = (after: ReadonlyArray) => Effect.gen(function* () { - const offers: Array = []; + const offers: Array = []; const { runtime, thread } = yield* resumed([ ...backgroundLaunch(CHILD), event("session.execution.succeeded", { sessionID: SESSION }), @@ -3867,7 +3879,7 @@ describe("OpenCode2 adapter", () => { Effect.gen(function* () { const reportText = `\nCHILD_OK\n`; const steerId = `msg_t3_steer_${SESSION}:message:opencode2-adapter:steer`; - const offers: Array = []; + const offers: Array = []; const { runtime, thread } = yield* resumed([ ...backgroundLaunch(CHILD), event("session.execution.succeeded", { sessionID: SESSION }), diff --git a/apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.testkit.ts b/apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.testkit.ts index 36d0e35ddcede3f369e2167c06f8e99e0ad48043..5c982997a92f07b69fec0c6c2fb2972507e3bfd6 100644 --- a/apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.testkit.ts +++ b/apps/server/src/orchestration-v2/Adapters/OpenCodeAdapterV2.testkit.ts @@ -9,7 +9,7 @@ import * as Schema from "effect/Schema"; import { OpenCodeAdapterV2Driver } from "@t3tools/provider-opencode/server"; import * as OpenCodeRuntime from "@t3tools/provider-opencode/server/OpenCodeRuntime"; import { layerTestProviderHost } from "@t3tools/provider-testing/host"; -import * as ProviderEventLoggers from "../../provider/ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import { ProviderAdapterDriverCreateError } from "@t3tools/provider-core/server/adapterDriver"; import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts"; diff --git a/apps/server/src/orchestration-v2/BackgroundWorkStop.integration.test.ts b/apps/server/src/orchestration-v2/BackgroundWorkStop.integration.test.ts index 4d4950bcb4b7e6959e8375fff36674507c11cd88..6d5e0b92d87f8b6315cec15f09a581ba10ccbb4f 100644 --- a/apps/server/src/orchestration-v2/BackgroundWorkStop.integration.test.ts +++ b/apps/server/src/orchestration-v2/BackgroundWorkStop.integration.test.ts @@ -24,16 +24,11 @@ import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import * as EffectWorker from "./EffectWorker.ts"; import * as EventSink from "./EventSink.ts"; import * as Orchestrator from "./Orchestrator.ts"; -import type { - ProviderAdapterV2Event, - ProviderAdapterV2InterruptInput, - ProviderAdapterV2Shape, - ProviderAdapterV2TurnInput, -} from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ProviderSessionManager from "./ProviderSessionManager.ts"; import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts"; import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const driver = ProviderDriverKind.make("codex"); const instanceId = ProviderInstanceId.make("codex"); @@ -61,10 +56,10 @@ const stopEarlierBackgroundWork = ({ Effect.scoped( Effect.gen(function* () { const cwd = yield* checkpointWorkspace("background-work-stop"); - const events = yield* Queue.unbounded(); - const started: ProviderAdapterV2TurnInput[] = []; - const interrupts: ProviderAdapterV2InterruptInput[] = []; - const adapter: ProviderAdapterV2Shape = { + const events = yield* Queue.unbounded(); + const started: ProviderAdapter.ProviderAdapterV2TurnInput[] = []; + const interrupts: ProviderAdapter.ProviderAdapterV2InterruptInput[] = []; + const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = { instanceId, driver, getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2), diff --git a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts index 6be935c9c23bbbdaae8c23757c01cacb16662b0a..45bf03610316d6f51ddf885a7ea03f7c0c74cf3a 100644 --- a/apps/server/src/orchestration-v2/CheckpointCaptureService.ts +++ b/apps/server/src/orchestration-v2/CheckpointCaptureService.ts @@ -252,7 +252,7 @@ export const layer: Layer.Layer< ); function makeCheckpointTurnItem(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly run: OrchestrationV2Run; readonly rootNode: OrchestrationV2ExecutionNode; readonly providerThread: OrchestrationV2ProviderThread; diff --git a/apps/server/src/orchestration-v2/CheckpointRollbackService.test.ts b/apps/server/src/orchestration-v2/CheckpointRollbackService.test.ts index 217a73697133e077d1f0d1ce27d9313412206153..018b4f8f49b14871d591cca4ef5ac0b37fc8a5ee 100644 --- a/apps/server/src/orchestration-v2/CheckpointRollbackService.test.ts +++ b/apps/server/src/orchestration-v2/CheckpointRollbackService.test.ts @@ -26,7 +26,7 @@ import * as EventSink from "./EventSink.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as ProjectionStore from "./ProjectionStore.ts"; import * as ProjectStore from "./ProjectStore.ts"; -import type { ProviderAdapterV2RollbackThreadInput } from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderSessionManager from "./ProviderSessionManager.ts"; import * as RuntimePolicy from "./RuntimePolicy.ts"; @@ -457,7 +457,7 @@ it.effect.each([ Layer.mock(ProviderSessionManager.ProviderSessionManagerV2)({ open: () => Effect.succeed({ - rollbackThread: (input: ProviderAdapterV2RollbackThreadInput) => + rollbackThread: (input: ProviderAdapter.ProviderAdapterV2RollbackThreadInput) => Effect.gen(function* () { const count = yield* resolveCodexRollbackTurnCount(input); assert.equal(count, 2 - targetOrdinal); diff --git a/apps/server/src/orchestration-v2/CheckpointRollbackService.ts b/apps/server/src/orchestration-v2/CheckpointRollbackService.ts index f9747abe2093dc04d92da0985d23e2eb5717142b..acacfed521c6f641fe808cb96934e2bb59cfe7a4 100644 --- a/apps/server/src/orchestration-v2/CheckpointRollbackService.ts +++ b/apps/server/src/orchestration-v2/CheckpointRollbackService.ts @@ -20,10 +20,10 @@ import { } from "./CheckpointRestoreSafety.ts"; import { CheckpointServiceV2 } from "./CheckpointService.ts"; import { EventSinkV2 } from "./EventSink.ts"; -import { IdAllocatorV2 } from "@t3tools/provider-core/server/IdAllocator"; +import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import { ProjectionStoreV2 } from "./ProjectionStore.ts"; import * as ProjectStore from "./ProjectStore.ts"; -import type { ProviderAdapterV2RollbackTarget } from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import { ProviderSessionManagerV2 } from "./ProviderSessionManager.ts"; import { RuntimePolicyV2 } from "./RuntimePolicy.ts"; import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts"; @@ -85,7 +85,7 @@ export const layer: Layer.Layer< never, | CheckpointServiceV2 | EventSinkV2 - | IdAllocatorV2 + | IdAllocator.IdAllocatorV2 | ProjectionStoreV2 | ProviderSessionManagerV2 | RuntimePolicyV2 @@ -98,7 +98,7 @@ export const layer: Layer.Layer< Effect.gen(function* () { const checkpoints = yield* CheckpointServiceV2; const eventSink = yield* EventSinkV2; - const ids = yield* IdAllocatorV2; + const ids = yield* IdAllocator.IdAllocatorV2; const projections = yield* ProjectionStoreV2; const sessions = yield* ProviderSessionManagerV2; const runtimePolicy = yield* RuntimePolicyV2; @@ -225,7 +225,7 @@ export const layer: Layer.Layer< turn.providerThreadId === providerThread.id && (turn.runAttemptId === null || !rolledBackAttemptIds.has(turn.runAttemptId)), ); - const rollbackTarget: ProviderAdapterV2RollbackTarget = + const rollbackTarget: ProviderAdapter.ProviderAdapterV2RollbackTarget = targetOrdinal === 0 ? { type: "thread_start", diff --git a/apps/server/src/orchestration-v2/CheckpointService.ts b/apps/server/src/orchestration-v2/CheckpointService.ts index c0bf30311a248a795c0cf1a6ae93004110b4fa74..913e53658e2c48a2b58d575185db68e9c6a5a606 100644 --- a/apps/server/src/orchestration-v2/CheckpointService.ts +++ b/apps/server/src/orchestration-v2/CheckpointService.ts @@ -172,7 +172,7 @@ export const checkpointRefForScopeOrdinal = Effect.fn("checkpointRefForScopeOrdi ); function checkpointIdForScopeOrdinal( - idAllocator: IdAllocator.IdAllocatorV2Shape, + idAllocator: IdAllocator.IdAllocatorV2["Service"], input: { readonly scopeId: CheckpointScopeId; readonly ordinalWithinScope: number; @@ -185,7 +185,7 @@ function checkpointIdForScopeOrdinal( } function makeRootRunScope(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly threadId: ThreadId; readonly runId: RunId; readonly rootNodeId: NodeId; diff --git a/apps/server/src/orchestration-v2/ContextHandoffBudget.test.ts b/apps/server/src/orchestration-v2/ContextHandoffBudget.test.ts index 0335d921da3e91a8a1e55337a9db939ac8edd5f9..bbab4b5fd4527911433f84f64b82916662a00fc0 100644 --- a/apps/server/src/orchestration-v2/ContextHandoffBudget.test.ts +++ b/apps/server/src/orchestration-v2/ContextHandoffBudget.test.ts @@ -1,4 +1,4 @@ -import type { ProviderAdapterV2HistoricalContext } from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import { assert, describe, it } from "@effect/vitest"; import { ContextHandoffId, @@ -501,7 +501,7 @@ describe("handoff delivery", () => { providerThread, budget: 16_000, alreadyDeliveredItemIds: new Set(), - inject: (value: ProviderAdapterV2HistoricalContext) => + inject: (value: ProviderAdapter.ProviderAdapterV2HistoricalContext) => Effect.sync(() => { history.push(...historyResponseItems(value.messages, value.context)); return true; @@ -588,7 +588,7 @@ describe("handoff delivery", () => { ...handoff, id: ContextHandoffId.make(`handoff:retry:${index}`), })); - let captured: ProviderAdapterV2HistoricalContext | undefined; + let captured: ProviderAdapter.ProviderAdapterV2HistoricalContext | undefined; const result = yield* deliverContextHandoffs({ handoffs: many, providerThread, diff --git a/apps/server/src/orchestration-v2/ContextHandoffDelivery.ts b/apps/server/src/orchestration-v2/ContextHandoffDelivery.ts index 534217a58a202a04f45989147657c224b5cff1d1..30f5873b9cf0bc9215aa3abf8a9373153f00d4fc 100644 --- a/apps/server/src/orchestration-v2/ContextHandoffDelivery.ts +++ b/apps/server/src/orchestration-v2/ContextHandoffDelivery.ts @@ -2,7 +2,7 @@ import type { OrchestrationV2ContextHandoff, OrchestrationV2ProviderThread, } from "@t3tools/contracts"; -import type { ProviderAdapterV2HistoricalContext } from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import { ContextHandoffBudgetError } from "@t3tools/provider-core/server/failure"; import * as Effect from "effect/Effect"; import * as Schema from "effect/Schema"; @@ -25,7 +25,7 @@ export const deliverContextHandoffs = Effect.fn("orchestrationV2.deliverContextH readonly deferInline?: boolean; readonly alreadyDeliveredItemIds: ReadonlySet; readonly inject?: ( - history: ProviderAdapterV2HistoricalContext, + history: ProviderAdapter.ProviderAdapterV2HistoricalContext, ) => Effect.Effect; readonly persist: (handoff: OrchestrationV2ContextHandoff) => Effect.Effect; }) { diff --git a/apps/server/src/orchestration-v2/CursorOrchestratorV2.live.test.ts b/apps/server/src/orchestration-v2/CursorOrchestratorV2.live.test.ts index 1c74ee18d7a925016f9d1f436449d7d55936c08e..044f3fd8da9fb3a5bbfd2358c05f9bed13832965 100644 --- a/apps/server/src/orchestration-v2/CursorOrchestratorV2.live.test.ts +++ b/apps/server/src/orchestration-v2/CursorOrchestratorV2.live.test.ts @@ -29,7 +29,7 @@ import * as CodexInstallation from "../provider/CodexInstallation.ts"; import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; import * as ModelManifest from "../provider/ModelManifest.ts"; import * as ProviderInstanceRegistryHydration from "../provider/ProviderInstanceRegistryHydration.ts"; -import * as ProviderEventLoggers from "../provider/ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as OpenCodeRuntime from "@t3tools/provider-opencode/server/OpenCodeRuntime"; import * as OpenCodeServerLedger from "@t3tools/provider-opencode/server/OpenCodeServerLedger"; import * as ServerSettings from "../serverSettings.ts"; diff --git a/apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts b/apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts index ed2ae984501e6fa5ab67ce385421ce2ecf7c2c1d..3f93674cd5d9e354ff6eb6a697c2d92816d9051e 100644 --- a/apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts +++ b/apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts @@ -36,10 +36,10 @@ import * as WorkspacePaths from "../workspace/WorkspacePaths.ts"; import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import * as EventSink from "./EventSink.ts"; import * as Orchestrator from "./Orchestrator.ts"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import { continueRestartedRun } from "./RestartContinuation.ts"; import * as RuntimeLayer from "./runtimeLayer.ts"; import * as ProviderTurnStartServiceTestkit from "./ProviderTurnStartService.testkit.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const layerPlatformTest = Layer.merge( NodeServices.layer, @@ -74,7 +74,7 @@ const orchestrationAdapter = { getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2), planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" }), openSession: () => Effect.die("sessions are not used by delegated completion tests"), -} as ProviderAdapterV2Shape; +} as ProviderAdapter.ProviderAdapterV2["Service"]; const providerInstance = { instanceId: modelSelection.instanceId, driverKind: driver, diff --git a/apps/server/src/orchestration-v2/DispatchModeLimit.test.ts b/apps/server/src/orchestration-v2/DispatchModeLimit.test.ts index 044b1b66bcdc7c5491addaff86a4beb964291079..8e2fd54f06ff665fd15f7824a4545e1a7e8895bc 100644 --- a/apps/server/src/orchestration-v2/DispatchModeLimit.test.ts +++ b/apps/server/src/orchestration-v2/DispatchModeLimit.test.ts @@ -13,9 +13,9 @@ import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import { DispatchModeLimit } from "./DispatchModeLimit.ts"; import * as Orchestrator from "./Orchestrator.ts"; import * as ProjectionStore from "./ProjectionStore.ts"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const instanceId = ProviderInstanceId.make("codex"); const adapter = { @@ -24,7 +24,7 @@ const adapter = { getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2), planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" as const }), openSession: () => Effect.die("No provider process needed for metadata commands"), -} as ProviderAdapterV2Shape; +} as ProviderAdapter.ProviderAdapterV2["Service"]; const layerDatabase = SqlitePersistence.layerMemory; const layerTest = Layer.mergeAll( layerDatabase, diff --git a/apps/server/src/orchestration-v2/GrokOrchestratorV2.live.test.ts b/apps/server/src/orchestration-v2/GrokOrchestratorV2.live.test.ts index 15d29d30f8acd5eee121103d8f1aed08c6cbbd72..abdf28155a06b6aff631ccab596ed2d959672e9a 100644 --- a/apps/server/src/orchestration-v2/GrokOrchestratorV2.live.test.ts +++ b/apps/server/src/orchestration-v2/GrokOrchestratorV2.live.test.ts @@ -29,7 +29,7 @@ import * as CodexInstallation from "../provider/CodexInstallation.ts"; import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; import * as ModelManifest from "../provider/ModelManifest.ts"; import * as ProviderInstanceRegistryHydration from "../provider/ProviderInstanceRegistryHydration.ts"; -import * as ProviderEventLoggers from "../provider/ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as OpenCodeRuntime from "@t3tools/provider-opencode/server/OpenCodeRuntime"; import * as OpenCodeServerLedger from "@t3tools/provider-opencode/server/OpenCodeServerLedger"; import * as ServerSettings from "../serverSettings.ts"; diff --git a/apps/server/src/orchestration-v2/OpenCode2OrchestratorV2.live.test.ts b/apps/server/src/orchestration-v2/OpenCode2OrchestratorV2.live.test.ts index 55d93ded6e6e74a6d90171b836cdc3825efb9f4e..b3d025ed0bdab4ed418a88118076b013722ee15f 100644 --- a/apps/server/src/orchestration-v2/OpenCode2OrchestratorV2.live.test.ts +++ b/apps/server/src/orchestration-v2/OpenCode2OrchestratorV2.live.test.ts @@ -54,7 +54,7 @@ import * as CodexInstallation from "../provider/CodexInstallation.ts"; import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; import * as ModelManifest from "../provider/ModelManifest.ts"; import * as ProviderInstanceRegistryHydration from "../provider/ProviderInstanceRegistryHydration.ts"; -import * as ProviderEventLoggers from "../provider/ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as OpenCode2Client from "@t3tools/provider-opencode/server/v2/OpenCode2Client"; import * as OpenCodeRuntime from "@t3tools/provider-opencode/server/OpenCodeRuntime"; import * as OpenCodeServerLedger from "@t3tools/provider-opencode/server/OpenCodeServerLedger"; @@ -67,7 +67,7 @@ import * as ProviderInstanceRegistry from "../provider/ProviderInstanceRegistry. import * as ProviderTurnStartServiceTestkit from "./ProviderTurnStartService.testkit.ts"; import * as RuntimeLayer from "./runtimeLayer.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import * as ProviderContinuationService from "./ProviderContinuationService.ts"; import * as ThreadManagementService from "./ThreadManagementService.ts"; import * as McpSessionRegistry from "../mcp/McpSessionRegistry.ts"; diff --git a/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts b/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts index 76a4bd8c1beced3e59e10a62bb23027f9f2b8e68..8e5fca79cf5534da2b7d6b5845477d195e4fd366 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts @@ -25,9 +25,9 @@ import * as SqlitePersistence from "../persistence/Sqlite.ts"; import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import * as Orchestrator from "./Orchestrator.ts"; import * as ProjectionStore from "./ProjectionStore.ts"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const instanceId = ProviderInstanceId.make("codex"); const modelSelection = { instanceId, model: "gpt-5.1-codex" }; @@ -37,7 +37,7 @@ const adapter = { getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2), planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" as const }), openSession: () => Effect.die("No provider process needed for metadata controls"), -} as ProviderAdapterV2Shape; +} as ProviderAdapter.ProviderAdapterV2["Service"]; const layerDatabase = SqlitePersistence.layerMemory; const layerTest = Layer.mergeAll( layerDatabase, diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index c85f11c568350e52a261804c45703fb49e03c3ee..4f870a606e00e4e8901d6371254f4770ad2893bd 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -91,7 +91,7 @@ import { isUndeliveredMailboxSteer } from "./NotificationMailbox.ts"; import { EventSinkV2 } from "./EventSink.ts"; import * as EffectOutbox from "./EffectOutbox.ts"; import type { OrchestrationEffectRequestV2, PendingOrchestrationEffectV2 } from "./EffectOutbox.ts"; -import { IdAllocatorV2 } from "@t3tools/provider-core/server/IdAllocator"; +import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts"; import { DispatchModeLimit, exceededDispatchModeLimit } from "./DispatchModeLimit.ts"; import { @@ -107,9 +107,8 @@ import { type ProjectionCheckpointContext, type ShellSnapshotOptions, } from "./ProjectionStore.ts"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import { ProviderAdapterRegistryV2 } from "./ProviderAdapterRegistry.ts"; -import { ProviderContinuationRequests } from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { makeProviderFailure } from "@t3tools/provider-core/server/failure"; import * as RunExecutionService from "./RunExecutionService.ts"; import { ProviderSessionManagerV2 } from "./ProviderSessionManager.ts"; @@ -128,6 +127,7 @@ import { ThreadForkServiceV2, } from "./ThreadForkService.ts"; import { planThreadDeletion } from "./ThreadDeletion.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; export class OrchestratorDispatchError extends Schema.TaggedError()( "OrchestratorDispatchError", @@ -800,7 +800,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio const contextHandoffService = yield* ContextHandoffServiceV2; const eventSink = yield* EventSinkV2; const commandReceipts = yield* CommandReceiptStoreV2; - const idAllocator = yield* IdAllocatorV2; + const idAllocator = yield* IdAllocator.IdAllocatorV2; const projects = yield* ProjectStore.ProjectStoreV2; const projectionStore = yield* ProjectionStoreV2; const effectOutbox = yield* EffectOutbox.EffectOutboxV2; @@ -823,7 +823,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; const providerAdapters = yield* ProviderAdapterRegistryV2; - const continuationRequests = yield* ProviderContinuationRequests; + const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests; const providerSessions = yield* ProviderSessionManagerV2; const providerSwitchService = yield* ProviderSwitchServiceV2; const runtimePolicy = yield* RuntimePolicyV2; @@ -857,7 +857,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio ); const providerSessionIdFor = (input: { - readonly adapter: ProviderAdapterV2Shape; + readonly adapter: ProviderAdapter.ProviderAdapterV2["Service"]; readonly providerInstanceId: ProviderInstanceId; readonly threadId: ThreadId; }) => @@ -10955,7 +10955,7 @@ export const layer: Layer.Layer< | ContextHandoffServiceV2 | EffectOutbox.EffectOutboxV2 | EventSinkV2 - | IdAllocatorV2 + | IdAllocator.IdAllocatorV2 | ProjectStore.ProjectStoreV2 | ProviderAdapterRegistryV2 | ProviderSessionManagerV2 diff --git a/apps/server/src/orchestration-v2/ProviderAdapterRegistry.test.ts b/apps/server/src/orchestration-v2/ProviderAdapterRegistry.test.ts index 3e8f6dfa297bb79f4b5f5225cc476616868c2479..2f2c545377eb73333f519f88a3456d605fe6e5f1 100644 --- a/apps/server/src/orchestration-v2/ProviderAdapterRegistry.test.ts +++ b/apps/server/src/orchestration-v2/ProviderAdapterRegistry.test.ts @@ -18,36 +18,35 @@ import * as Schema from "effect/Schema"; import type * as Scope from "effect/Scope"; import * as Stream from "effect/Stream"; -import * as ProviderAuthFlow from "@t3tools/provider-core/server/ProviderAuthFlow"; +import * as ProviderAuthFlow from "@t3tools/provider-core/server/providerAuthFlow"; import type { ProviderAuthController } from "../provider/ProviderAuthService.ts"; import type { ProviderInstance } from "@t3tools/provider-core/server/driver"; import * as ProviderInstanceRegistry from "../provider/ProviderInstanceRegistry.ts"; -import { - ProviderAdapterOpenSessionError, - type ProviderAdapterV2Shape, -} from "@t3tools/provider-core/server/ProviderAdapter"; import { ProviderAdapterDriverCreateError, type ProviderAdapterDriver, } from "@t3tools/provider-core/server/adapterDriver"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const driver = ProviderDriverKind.make("codex"); const personalId = ProviderInstanceId.make("codex_personal"); const workId = ProviderInstanceId.make("codex_work"); -const makeAdapter = (instanceId: ProviderInstanceId): ProviderAdapterV2Shape => +const makeAdapter = ( + instanceId: ProviderInstanceId, +): ProviderAdapter.ProviderAdapterV2["Service"] => ({ instanceId, driver, getCapabilities: () => Effect.die("capabilities are not used by this registry test"), planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" }), openSession: () => Effect.die("sessions are not used by this registry test"), - }) as ProviderAdapterV2Shape; + }) as ProviderAdapter.ProviderAdapterV2["Service"]; const makeInstance = ( instanceId: ProviderInstanceId, - orchestrationAdapter: ProviderAdapterV2Shape, + orchestrationAdapter: ProviderAdapter.ProviderAdapterV2["Service"], ): ProviderInstance => ({ instanceId, driverKind: driver, @@ -101,7 +100,11 @@ const lifecycleConfigMap: ProviderInstanceConfigMap = { const lifecycleAdapter = makeAdapter(lifecycleInstanceId); const makeLifecycleDriver = ( - create: Effect.Effect, + create: Effect.Effect< + ProviderAdapter.ProviderAdapterV2["Service"], + ProviderAdapterDriverCreateError, + Scope.Scope + >, ): ProviderAdapterDriver> => ({ driverKind: lifecycleDriver, configSchema: Schema.Struct({}), @@ -263,7 +266,7 @@ it.effect( }, }) .pipe(Effect.flip); - assert.instanceOf(error, ProviderAdapterOpenSessionError); + assert.instanceOf(error, ProviderAdapter.ProviderAdapterOpenSessionError); assert.instanceOf(error.cause, ProviderSetupError); }), ); @@ -287,7 +290,7 @@ it.effect("interrupts admitted session startup when a shared peer signs out", () authenticate: () => Effect.void, logout: Effect.void, }); - const adapter: ProviderAdapterV2Shape = { + const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = { ...workAdapter, openSession: () => Effect.gen(function* () { diff --git a/apps/server/src/orchestration-v2/ProviderAdapterRegistry.ts b/apps/server/src/orchestration-v2/ProviderAdapterRegistry.ts index 984fd586e5ea54d4da4c247f6f97059b2b46b9c2..9811907f250230eecfe6510f4b517e16851c04a9 100644 --- a/apps/server/src/orchestration-v2/ProviderAdapterRegistry.ts +++ b/apps/server/src/orchestration-v2/ProviderAdapterRegistry.ts @@ -48,11 +48,11 @@ export type ProviderAdapterRegistryV2Error = typeof ProviderAdapterRegistryV2Err export interface ProviderAdapterRegistryV2Shape { readonly get: ( instanceId: ProviderInstanceId, - ) => Effect.Effect; + ) => Effect.Effect; readonly list: () => Effect.Effect>; readonly getMetadata?: (instanceId: ProviderInstanceId) => Effect.Effect< { - readonly driver: ProviderAdapter.ProviderAdapterV2Shape["driver"]; + readonly driver: ProviderAdapter.ProviderAdapterV2["Service"]["driver"]; readonly continuationKey: string; readonly enabled: boolean; readonly capabilities: OrchestrationV2ProviderCapabilities; @@ -134,7 +134,7 @@ export const layerFromProviderInstanceRegistry: Layer.Layer< ), ); }, - } satisfies ProviderAdapter.ProviderAdapterV2Shape); + } satisfies ProviderAdapter.ProviderAdapterV2["Service"]); }), ), list: () => @@ -169,7 +169,7 @@ export const ProviderAdapterRegistryBuildError = Schema.Union([ProviderAdapterDr export type ProviderAdapterRegistryBuildError = typeof ProviderAdapterRegistryBuildError.Type; function makeRegistry( - adapters: ReadonlyArray, + adapters: ReadonlyArray, ): ProviderAdapterRegistryV2Shape { return { get: (instanceId) => @@ -185,7 +185,7 @@ function makeRegistry( } export function layerFromAdapters( - adapters: ReadonlyArray, + adapters: ReadonlyArray, ): Layer.Layer { return Layer.succeed( ProviderAdapterRegistryV2, @@ -194,7 +194,7 @@ export function layerFromAdapters( } export function layerFromAdaptersEffect( - adapters: Effect.Effect, E, R>, + adapters: Effect.Effect, E, R>, ): Layer.Layer { return Layer.effect( ProviderAdapterRegistryV2, @@ -203,7 +203,7 @@ export function layerFromAdaptersEffect( } export function layerSingle( - adapter: ProviderAdapter.ProviderAdapterV2Shape, + adapter: ProviderAdapter.ProviderAdapterV2["Service"], ): Layer.Layer { return layerFromAdapters([adapter]); } @@ -217,7 +217,7 @@ const decodedConfigEnabled = (config: unknown): boolean | undefined => { }; interface LiveAdapterEntry { - readonly adapter: ProviderAdapter.ProviderAdapterV2Shape; + readonly adapter: ProviderAdapter.ProviderAdapterV2["Service"]; readonly scope: Scope.Closeable; readonly entry: ProviderInstanceConfig; } diff --git a/apps/server/src/orchestration-v2/ProviderContinuationService.test.ts b/apps/server/src/orchestration-v2/ProviderContinuationService.test.ts index 6e99d80a30e44f23d95c5a49f39e16779a77f819..a6afc4a4b2ffd5e2cba327f6d2069617aade3b4f 100644 --- a/apps/server/src/orchestration-v2/ProviderContinuationService.test.ts +++ b/apps/server/src/orchestration-v2/ProviderContinuationService.test.ts @@ -19,7 +19,7 @@ import * as Semaphore from "effect/Semaphore"; import * as TestClock from "effect/testing/TestClock"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import * as ProviderContinuationService from "./ProviderContinuationService.ts"; import * as ThreadManagementService from "./ThreadManagementService.ts"; diff --git a/apps/server/src/orchestration-v2/ProviderContinuationService.ts b/apps/server/src/orchestration-v2/ProviderContinuationService.ts index 928a5c9095240d20a27c343ff693b887e21fcd39..b8a57a88937f2e3060f444272c144f708bfc6659 100644 --- a/apps/server/src/orchestration-v2/ProviderContinuationService.ts +++ b/apps/server/src/orchestration-v2/ProviderContinuationService.ts @@ -4,7 +4,7 @@ import * as Layer from "effect/Layer"; import * as Ref from "effect/Ref"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import * as ThreadManagementService from "./ThreadManagementService.ts"; import { isUndeliveredMailboxSteer } from "./NotificationMailbox.ts"; diff --git a/apps/server/src/orchestration-v2/ProviderEventIngestor.ts b/apps/server/src/orchestration-v2/ProviderEventIngestor.ts index 355a73e2199c575deca0c80848c6606c2e117905..02acf9b51da1abff3160da6929e964e43056a036 100644 --- a/apps/server/src/orchestration-v2/ProviderEventIngestor.ts +++ b/apps/server/src/orchestration-v2/ProviderEventIngestor.ts @@ -31,7 +31,7 @@ import * as AnalyticsService from "../telemetry/AnalyticsService.ts"; import * as EventSink from "./EventSink.ts"; import * as ProjectionStore from "./ProjectionStore.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import { ProviderAdapterV2Event } from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import { makeProviderFailureTurnItem } from "@t3tools/provider-core/server/failure"; import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts"; import { stripUnservedToolOutputImageBytes } from "./toolOutputImageBytes.ts"; @@ -41,7 +41,7 @@ export class ProviderEventNormalizeError extends Schema.TaggedError> { @@ -257,7 +257,7 @@ export interface ProviderEventIngestInput { readonly runId?: RunId; readonly nodeId?: NodeId; readonly rawEventId?: RawEventId; - readonly event: ProviderAdapterV2Event; + readonly event: ProviderAdapter.ProviderAdapterV2Event; readonly analyticsContext?: ProviderTurnAnalyticsContext; } @@ -657,7 +657,6 @@ export const layer: Layer.Layer< yield* makeDomainEvent(input, { type: "turn-item.updated", payload: makeProviderFailureTurnItem({ - idAllocator, driver: input.event.driver, threadId: input.threadId, runId: input.runId ?? null, diff --git a/apps/server/src/orchestration-v2/ProviderSessionManager.test.ts b/apps/server/src/orchestration-v2/ProviderSessionManager.test.ts index bb994377f4bf624e69f0f5a3dc2c2b8ec9a0e9dd..7f5d935771b051e52e347650bf44d7f344c756e4 100644 --- a/apps/server/src/orchestration-v2/ProviderSessionManager.test.ts +++ b/apps/server/src/orchestration-v2/ProviderSessionManager.test.ts @@ -44,18 +44,11 @@ import * as EventSink from "./EventSink.ts"; import * as EventStore from "./EventStore.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as ProjectionStore from "./ProjectionStore.ts"; -import { - ProviderAdapterEventStreamError, - type ProviderAdapterV2Event, - ProviderAdapterProtocolError, - type ProviderAdapterV2RuntimePolicy, - type ProviderAdapterV2SessionRuntime, - type ProviderAdapterV2Shape, -} from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ProviderEventIngestor from "./ProviderEventIngestor.ts"; import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts"; import * as ProviderSessionManager from "./ProviderSessionManager.ts"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const layerTestDatabase = SqlitePersistence.layerMemory; const layerTestStores = Layer.merge(EventStore.layer, ProjectionStore.layer).pipe( @@ -167,7 +160,10 @@ interface TestProviderRuntimeState { readonly interruptCount: number; readonly resumeCount: number; readonly unloadedNativeThreadIds: ReadonlyArray; - readonly eventQueues: ReadonlyMap>; + readonly eventQueues: ReadonlyMap< + string, + Queue.Queue + >; } const emptyState: TestProviderRuntimeState = { @@ -189,7 +185,7 @@ const runtimePolicy = { runtimeMode: "full-access", interactionMode: "default", cwd: process.cwd(), -} satisfies ProviderAdapterV2RuntimePolicy; +} satisfies ProviderAdapter.ProviderAdapterV2RuntimePolicy; function makeProviderSession(input: { readonly providerSessionId: ProviderSessionId; @@ -211,7 +207,7 @@ function makeProviderSession(input: { } function makeThreadCreatedEvent(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly threadId: ThreadId; readonly now: DateTime.Utc; readonly projectId?: ProjectId; @@ -264,7 +260,7 @@ function makeThreadCreatedEvent(input: { } function makeProviderThread(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly threadId: ThreadId; readonly providerSessionId: ProviderSessionId; readonly now: DateTime.Utc; @@ -299,7 +295,7 @@ function makeProviderThread(input: { function unimplemented(detail: string) { return Effect.fail( - new ProviderAdapterProtocolError({ + new ProviderAdapter.ProviderAdapterProtocolError({ driver: CODEX_DRIVER, detail, }), @@ -328,7 +324,7 @@ function makeProviderAdapter( /** Completed when a hanging scope close reaches its wedged finalizer. */ readonly scopeCloseReached?: Deferred.Deferred; } = {}, -): ProviderAdapterV2Shape { +): ProviderAdapter.ProviderAdapterV2["Service"] { const countClose = Effect.addFinalizer(() => Ref.update(state, (current) => ({ ...current, @@ -371,7 +367,7 @@ function makeProviderAdapter( ]); } const now = yield* DateTime.now; - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); const session = makeProviderSession({ providerSessionId: input.providerSessionId, now, @@ -398,7 +394,7 @@ function makeProviderAdapter( providerSession: session, events: options.failEventStream ? Stream.fail( - new ProviderAdapterEventStreamError({ + new ProviderAdapter.ProviderAdapterEventStreamError({ driver: CODEX_DRIVER, providerSessionId: input.providerSessionId, cause: "process exited", @@ -442,7 +438,7 @@ function makeProviderAdapter( readThreadSnapshot: () => unimplemented("readThreadSnapshot unused in test"), rollbackThread: () => unimplemented("rollbackThread unused in test"), forkThread: () => unimplemented("forkThread unused in test"), - } satisfies ProviderAdapterV2SessionRuntime; + } satisfies ProviderAdapter.ProviderAdapterV2SessionRuntime; }), }; } @@ -674,7 +670,7 @@ function runBrowserAccessScenario(input: { } function makePendingRuntimeRequestEvents(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly threadId: ThreadId; readonly providerSessionId: ProviderSessionId; readonly providerThread: OrchestrationV2ProviderThread; @@ -795,7 +791,7 @@ function makePendingRuntimeRequestEvents(input: { driver: CODEX_DRIVER, turnItem, }, - ] satisfies ReadonlyArray; + ] satisfies ReadonlyArray; return { events, providerEvents, requestId, nodeId }; }); } diff --git a/apps/server/src/orchestration-v2/ProviderSessionManager.ts b/apps/server/src/orchestration-v2/ProviderSessionManager.ts index f467b8527e89297454b82a98cf1d4998f4fdf913..705bd4ec27e2ad1a63b4137819aedd5c60a09c06 100644 --- a/apps/server/src/orchestration-v2/ProviderSessionManager.ts +++ b/apps/server/src/orchestration-v2/ProviderSessionManager.ts @@ -46,14 +46,7 @@ import * as McpSessionRegistry from "../mcp/McpSessionRegistry.ts"; import * as EventSink from "./EventSink.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as ProviderEventIngestor from "./ProviderEventIngestor.ts"; -import { - ProviderAdapterEventStreamError, - ProviderAdapterV2RuntimePolicy, - type ProviderAdapterV2Error, - type ProviderAdapterV2Event, - type ProviderAdapterV2EventSubscription, - type ProviderAdapterV2SessionRuntime, -} from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ProjectionStore from "./ProjectionStore.ts"; @@ -161,14 +154,20 @@ export interface ProviderSessionManagerV2Shape { readonly threadId: ThreadId; readonly providerSessionId: ProviderSessionId; readonly modelSelection: ModelSelection; - readonly runtimePolicy: ProviderAdapterV2RuntimePolicy; + readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy; readonly resumeFromSession?: OrchestrationV2ProviderSession; readonly initialNativeThreadId?: string; readonly initialProviderItemIdentityVersion?: 2; - }) => Effect.Effect; + }) => Effect.Effect< + ProviderAdapter.ProviderAdapterV2SessionRuntime, + ProviderSessionManagerV2Error + >; readonly get: ( providerSessionId: ProviderSessionId, - ) => Effect.Effect, ProviderSessionManagerV2Error>; + ) => Effect.Effect< + Option.Option, + ProviderSessionManagerV2Error + >; readonly close: ( providerSessionId: ProviderSessionId, ) => Effect.Effect; @@ -211,8 +210,8 @@ interface LiveSessionEntry { */ readonly mcpCredentialIdByThread: ReadonlyMap; readonly supportsMultipleProviderThreads: boolean; - readonly runtime: ProviderAdapterV2SessionRuntime; - readonly exposedRuntime: ProviderAdapterV2SessionRuntime; + readonly runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime; + readonly exposedRuntime: ProviderAdapter.ProviderAdapterV2SessionRuntime; readonly eventSubscribers: Ref.Ref< ReadonlyMap> >; @@ -244,10 +243,10 @@ interface IdleThreadUnload { } type ProviderSessionEventSignal = - | { readonly type: "event"; readonly event: ProviderAdapterV2Event } + | { readonly type: "event"; readonly event: ProviderAdapter.ProviderAdapterV2Event } | { readonly type: "failure"; - readonly cause: Cause.Cause; + readonly cause: Cause.Cause; }; export interface ProviderSessionManagerV2LayerOptions { @@ -279,7 +278,9 @@ function sessionKey(providerSessionId: ProviderSessionId): string { * Their node and transcript item are runless too, so they bypass the normal * per-run subscriber and are persisted by the session event pump. */ -function sessionScopedRuntimeRequestThreadId(event: ProviderAdapterV2Event): ThreadId | undefined { +function sessionScopedRuntimeRequestThreadId( + event: ProviderAdapter.ProviderAdapterV2Event, +): ThreadId | undefined { switch (event.type) { case "runtime_request.updated": return event.runtimeRequest.providerTurnId === null ? event.threadId : undefined; @@ -298,7 +299,9 @@ function sessionScopedRuntimeRequestThreadId(event: ProviderAdapterV2Event): Thr } function providerThreadRuntimeKey( - providerThread: Parameters[0]["providerThread"], + providerThread: Parameters< + ProviderAdapter.ProviderAdapterV2SessionRuntime["resumeThread"] + >[0]["providerThread"], ): string { const nativeThreadRef = providerThread.nativeThreadRef; return nativeThreadRef === null @@ -308,10 +311,10 @@ function providerThreadRuntimeKey( function providerThreadLoadKey(input: { readonly providerThread: Parameters< - ProviderAdapterV2SessionRuntime["resumeThread"] + ProviderAdapter.ProviderAdapterV2SessionRuntime["resumeThread"] >[0]["providerThread"]; readonly modelSelection?: ModelSelection; - readonly runtimePolicy?: ProviderAdapterV2RuntimePolicy; + readonly runtimePolicy?: ProviderAdapter.ProviderAdapterV2RuntimePolicy; }): string { return JSON.stringify({ providerThread: providerThreadRuntimeKey(input.providerThread), @@ -575,7 +578,7 @@ export const layerWithOptions = ( const failSubscribers = (entry: LiveSessionEntry, detail: string) => Effect.gen(function* () { - const error = new ProviderAdapterEventStreamError({ + const error = new ProviderAdapter.ProviderAdapterEventStreamError({ driver: entry.runtime.driver, providerSessionId: entry.runtime.providerSessionId, cause: detail, @@ -617,7 +620,7 @@ export const layerWithOptions = ( fiber === null ? Effect.void : Fiber.interrupt(fiber).pipe(Effect.ignore); const writeProviderSessionEvents = (input: { - readonly runtime: ProviderAdapterV2SessionRuntime; + readonly runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime; readonly threadIds: Iterable; readonly type: "provider-session.attached" | "provider-session.updated"; readonly payload: OrchestrationV2ProviderSession; @@ -1226,7 +1229,7 @@ export const layerWithOptions = ( const removeThreadAttachment = (input: { readonly providerSessionId: ProviderSessionId; readonly threadId: ThreadId; - readonly runtime: ProviderAdapterV2SessionRuntime; + readonly runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime; }) => Ref.update(sessions, (current) => { const key = sessionKey(input.providerSessionId); @@ -1289,7 +1292,7 @@ export const layerWithOptions = ( readonly providerInstanceId: ProviderInstanceId; }) => Effect.suspend(() => { - let attachedTo: ProviderAdapterV2SessionRuntime | undefined; + let attachedTo: ProviderAdapter.ProviderAdapterV2SessionRuntime | undefined; let preparedForCleanup: PreparedMcpCredential | undefined; let reservationDropped = false; const dropReservation = () => { @@ -1631,7 +1634,7 @@ export const layerWithOptions = ( subscribers: Ref.Ref< ReadonlyMap> >, - ): Effect.Effect => + ): Effect.Effect => Effect.gen(function* () { const queue = yield* Queue.unbounded(); const subscriberId = yield* Ref.getAndUpdate(nextSubscriberId, (value) => value + 1); @@ -1662,15 +1665,15 @@ export const layerWithOptions = ( ), Stream.ensuring(close), ); - return { events, close } satisfies ProviderAdapterV2EventSubscription; + return { events, close } satisfies ProviderAdapter.ProviderAdapterV2EventSubscription; }); const decorateRuntime = ( - runtime: ProviderAdapterV2SessionRuntime, + runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime, eventSubscribers: Ref.Ref< ReadonlyMap> >, - ): ProviderAdapterV2SessionRuntime => { + ): ProviderAdapter.ProviderAdapterV2SessionRuntime => { const providerSessionId = runtime.providerSessionId; const subscribeEvents = makeEventSubscription(eventSubscribers); // Every provider's turn operations pass through here, so this is where they are @@ -1852,7 +1855,10 @@ export const layerWithOptions = ( const persistProviderSessionUpdate = ( entry: LiveSessionEntry, - event: Extract, + event: Extract< + ProviderAdapter.ProviderAdapterV2Event, + { readonly type: "provider_session.updated" } + >, ) => Effect.gen(function* () { const current = (yield* Ref.get(sessions)).get( @@ -1925,7 +1931,7 @@ export const layerWithOptions = ( .pipe( Effect.mapError( (cause) => - new ProviderAdapterEventStreamError({ + new ProviderAdapter.ProviderAdapterEventStreamError({ driver: entry.runtime.driver, providerSessionId: entry.runtime.providerSessionId, cause, @@ -1962,7 +1968,7 @@ export const layerWithOptions = ( const cause = Exit.isFailure(exit) ? exit.cause : Cause.fail( - new ProviderAdapterEventStreamError({ + new ProviderAdapter.ProviderAdapterEventStreamError({ driver: entry.runtime.driver, providerSessionId: entry.runtime.providerSessionId, cause: "Provider event stream ended unexpectedly.", @@ -2212,7 +2218,7 @@ export const layerWithOptions = ( Effect.gen(function* () { const entry = (yield* Ref.get(sessions)).get(sessionKey(providerSessionId)); if (entry === undefined) { - return Option.none(); + return Option.none(); } yield* touchActivity(providerSessionId); return Option.some(entry.exposedRuntime); diff --git a/apps/server/src/orchestration-v2/ProviderSwitchService.test.ts b/apps/server/src/orchestration-v2/ProviderSwitchService.test.ts index 712b9e6e10f35905491899bd7ead731a7af0ebfe..d36721bbd6a1cd1b49451d42619ef9c3e3ac387c 100644 --- a/apps/server/src/orchestration-v2/ProviderSwitchService.test.ts +++ b/apps/server/src/orchestration-v2/ProviderSwitchService.test.ts @@ -12,10 +12,10 @@ import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import { acpSelectionTransition } from "@t3tools/provider-core/server/selectionTransition"; import * as ProviderSwitch from "./ProviderSwitchService.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const driver = ProviderDriverKind.make("codex"); const currentInstanceId = ProviderInstanceId.make("codex_primary"); @@ -67,10 +67,12 @@ function deadSessionRecord( function layerTest( metadata: Readonly>, - planSelectionTransition: ProviderAdapterV2Shape["planSelectionTransition"] = () => + planSelectionTransition: ProviderAdapter.ProviderAdapterV2["Service"]["planSelectionTransition"] = () => Effect.succeed({ type: "restart_session" }), ) { - const adapter = (instanceId: ProviderInstanceId): ProviderAdapterV2Shape => ({ + const adapter = ( + instanceId: ProviderInstanceId, + ): ProviderAdapter.ProviderAdapterV2["Service"] => ({ instanceId, driver, getCapabilities: () => Effect.succeed(capabilitiesWithoutModelSwitch), diff --git a/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts b/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts index 42b3943e71d0cae880c0142b8c96a111d7278ed2..2ac00838018b4844a38c00bd795f62d750557673 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts @@ -24,7 +24,7 @@ import * as Stream from "effect/Stream"; import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import * as ProjectionStore from "./ProjectionStore.ts"; -import type { ProviderAdapterV2SessionRuntime } from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderSessionManager from "./ProviderSessionManager.ts"; import * as ProviderTurnControlService from "./ProviderTurnControlService.ts"; @@ -177,7 +177,7 @@ it.effect( updatedAt: now, lastError: null, }; - const runtime: ProviderAdapterV2SessionRuntime = { + const runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime = { instanceId: providerInstanceId, driver, providerSessionId: oldSessionId, diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts index 54e55c40a3ccfcc7132fea4d487f71d5917795b4..d6c12fab7ee15eedabf45632b887e836d677294e 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts @@ -32,7 +32,7 @@ import * as EventSink from "./EventSink.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import * as ProjectionStore from "./ProjectionStore.ts"; -import { ProviderAdapterEventStreamError } from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderSessionManager from "./ProviderSessionManager.ts"; import * as ProviderTurnStart from "./ProviderTurnStartService.ts"; import * as RunExecutionService from "./RunExecutionService.ts"; @@ -372,7 +372,7 @@ function makeLocalCommandHarness(input: { }).pipe( Effect.andThen( Effect.fail( - new ProviderAdapterEventStreamError({ + new ProviderAdapter.ProviderAdapterEventStreamError({ driver: providerThread.driver, providerSessionId, cause: input.ensureThreadFailure, @@ -385,7 +385,7 @@ function makeLocalCommandHarness(input: { driver: providerThread.driver, resumeThread: () => Effect.fail( - new ProviderAdapterEventStreamError({ + new ProviderAdapter.ProviderAdapterEventStreamError({ driver: providerThread.driver, providerSessionId, cause: "native thread is gone", diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index a928680b240245ed6ab2c8adaf488d1a52108aa5..e2c905b1e17a970053449f497c3ea58abe84433f 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -37,12 +37,7 @@ import { latestNativeContextUsage, } from "@t3tools/provider-core/server/handoffBudget"; import { deliverContextHandoffs } from "./ContextHandoffDelivery.ts"; -import { - ProviderAdapterTurnStartError, - type ProviderAdapterV2Error, - type ProviderAdapterV2HistoricalContext, - type ProviderAdapterV2SessionRuntime, -} from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as ProjectionStore from "./ProjectionStore.ts"; import * as ProviderSessionManager from "./ProviderSessionManager.ts"; @@ -184,15 +179,15 @@ export const layer: Layer.Layer< }; const makeDeliverySession = ( - session: ProviderAdapterV2SessionRuntime, + session: ProviderAdapter.ProviderAdapterV2SessionRuntime, startWithHandoffs: ( - input: Parameters[0], + input: Parameters[0], compact?: boolean, - ) => ReturnType, + ) => ReturnType, ) => { let deliver: typeof startWithHandoffs | undefined = startWithHandoffs; const start = ( - input: Parameters[0], + input: Parameters[0], compact = false, ) => Effect.suspend(() => { @@ -595,7 +590,7 @@ export const layer: Layer.Layer< // Only the provider's own thread load fails the run on the last attempt; // store, id and handoff failures around it keep their typed errors. const loadFromProvider = ( - load: Effect.Effect, + load: Effect.Effect, ) => Effect.gen(function* () { const loaded = yield* Effect.result(load); @@ -672,7 +667,7 @@ export const layer: Layer.Layer< const resumed = yield* Effect.result( uncertainDelivery ? Effect.fail( - new ProviderAdapterTurnStartError({ + new ProviderAdapter.ProviderAdapterTurnStartError({ driver: session.driver, threadId: projection.thread.id, providerThreadId: providerThread.id, @@ -1143,7 +1138,7 @@ export const layer: Layer.Layer< ...(session.injectHistory === undefined ? {} : { - inject: (history: ProviderAdapterV2HistoricalContext) => + inject: (history: ProviderAdapter.ProviderAdapterV2HistoricalContext) => session.injectHistory!({ providerThread: runningProviderThread, ...history, @@ -1211,7 +1206,7 @@ export const layer: Layer.Layer< Effect.mapError((cause) => cause._tag === "ProviderAdapterTurnStartError" ? cause - : new ProviderAdapterTurnStartError({ + : new ProviderAdapter.ProviderAdapterTurnStartError({ driver: session.driver, threadId: projection.thread.id, providerThreadId: providerThread.id, diff --git a/apps/server/src/orchestration-v2/RunExecutionService.test.ts b/apps/server/src/orchestration-v2/RunExecutionService.test.ts index c7434605807740977ba041115ef47a9866e06272..70820566378718117c0d981d51495ea848ca9f91 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.test.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.test.ts @@ -43,14 +43,7 @@ import * as CheckpointService from "./CheckpointService.ts"; import type { PendingOrchestrationEffectV2 } from "./EffectOutbox.ts"; import * as EventSink from "./EventSink.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import { - ProviderAdapterEventStreamError, - ProviderAdapterTurnStartError, - type ProviderAdapterV2Error, - type ProviderAdapterV2Event, - type ProviderAdapterV2SessionRuntime, - type ProviderAdapterV2TurnInput, -} from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProjectionStore from "./ProjectionStore.ts"; import * as ProviderEventIngestor from "./ProviderEventIngestor.ts"; import * as McpAppModelContext from "../mcpApps/McpAppModelContext.ts"; @@ -95,7 +88,7 @@ it.effect("routes shared-runtime events only to their owning root run", () => providerThreadId: ProviderThreadId.make("provider-thread:shared-runtime:second"), }; const firstTurnId = ProviderTurnId.make("provider-turn:shared-runtime:first"); - const turnEvent: ProviderAdapterV2Event = { + const turnEvent: ProviderAdapter.ProviderAdapterV2Event = { type: "provider_turn.updated", driver, threadId: first.threadId, @@ -111,7 +104,7 @@ it.effect("routes shared-runtime events only to their owning root run", () => completedAt: null, }, }; - const messageEvent: ProviderAdapterV2Event = { + const messageEvent: ProviderAdapter.ProviderAdapterV2Event = { type: "message.updated", driver, message: { @@ -129,7 +122,7 @@ it.effect("routes shared-runtime events only to their owning root run", () => updatedAt: now, }, }; - const terminalEvent: ProviderAdapterV2Event = { + const terminalEvent: ProviderAdapter.ProviderAdapterV2Event = { type: "turn.terminal", driver, providerThreadId: first.providerThreadId, @@ -181,7 +174,7 @@ it("leaves a child thread created after the root turn ended to the run that is l attemptId: RunAttemptId.make("attempt:late-child"), providerThreadId: ProviderThreadId.make("provider-thread:late-child"), }; - const childCreated = (childThreadId: ThreadId): ProviderAdapterV2Event => + const childCreated = (childThreadId: ThreadId): ProviderAdapter.ProviderAdapterV2Event => ({ type: "app_thread.created", driver, @@ -193,7 +186,7 @@ it("leaves a child thread created after the root turn ended to the run that is l rootThreadId: threadId, }, }, - }) as ProviderAdapterV2Event; + }) as ProviderAdapter.ProviderAdapterV2Event; const earlyChild = ThreadId.make("thread:late-child:early"); const lateChild = ThreadId.make("thread:late-child:late"); @@ -246,7 +239,7 @@ it("does not route a superseded attempt through a reused provider thread", () => ...oldAttempt, attemptId: RunAttemptId.make("attempt:shared-runtime:restart:new"), }; - const oldTurnEvent: ProviderAdapterV2Event = { + const oldTurnEvent: ProviderAdapter.ProviderAdapterV2Event = { type: "provider_turn.updated", driver, threadId, @@ -299,33 +292,33 @@ it("routes only exact same-thread background items inherited from settled runs", type: "subagent", status: "running", }, - } as Extract; + } as Extract; const unrelatedRunItem = { ...inheritedRunning, turnItem: { ...inheritedRunning.turnItem, runId: RunId.make("run:inherited-background-routing:unrelated"), }, - } as ProviderAdapterV2Event; + } as ProviderAdapter.ProviderAdapterV2Event; const unlistedPriorItem = { ...inheritedRunning, turnItem: { ...inheritedRunning.turnItem, id: TurnItemId.make("turn-item:inherited-background-routing:unrelated"), }, - } as ProviderAdapterV2Event; + } as ProviderAdapter.ProviderAdapterV2Event; const unrelatedThreadItem = { ...inheritedRunning, turnItem: { ...inheritedRunning.turnItem, threadId: otherThreadId }, - } as ProviderAdapterV2Event; + } as ProviderAdapter.ProviderAdapterV2Event; const ordinaryItem = { ...inheritedRunning, turnItem: { ...inheritedRunning.turnItem, type: "reasoning" as const }, - } as ProviderAdapterV2Event; + } as ProviderAdapter.ProviderAdapterV2Event; const inheritedTerminal = { ...inheritedRunning, turnItem: { ...inheritedRunning.turnItem, status: "completed" as const }, - } as ProviderAdapterV2Event; + } as ProviderAdapter.ProviderAdapterV2Event; const [runningAccepted, afterRunning] = RunExecutionService.routeProviderEvent( inheritedRunning, @@ -515,7 +508,7 @@ it("does not carry interrupted or still-running child ownership into later attem startedAt: null, completedAt: null, }, - } satisfies ProviderAdapterV2Event; + } satisfies ProviderAdapter.ProviderAdapterV2Event; assert.isFalse(RunExecutionService.routeProviderEvent(lateChildNode, identity, state)[0]); }); @@ -550,7 +543,7 @@ it.effect("rechecks run ownership immediately before calling the provider", () = const session = { events: Stream.never, startTurn: () => Ref.update(providerStarts, (count) => count + 1), - } as unknown as ProviderAdapterV2SessionRuntime; + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime; yield* runExecution.startRootRun({ commandId: CommandId.make("command:run-execution-start-guard"), @@ -597,14 +590,15 @@ it.effect("rechecks run ownership immediately before calling the provider", () = it.effect("passes the thread's MCP app context to the provider under a safe key", () => Effect.gen(function* () { const runExecution = yield* RunExecutionService.RunExecutionServiceV2; - const started = yield* Deferred.make(); + const started = yield* Deferred.make(); const threadId = ThreadId.make("thread:run-execution-app-context"); const providerInstanceId = ProviderInstanceId.make("codex"); const attemptId = RunAttemptId.make("attempt:run-execution-app-context"); const session = { events: Stream.never, - startTurn: (input: ProviderAdapterV2TurnInput) => Deferred.succeed(started, input), - } as unknown as ProviderAdapterV2SessionRuntime; + startTurn: (input: ProviderAdapter.ProviderAdapterV2TurnInput) => + Deferred.succeed(started, input), + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime; yield* runExecution.startRootRun({ commandId: CommandId.make("command:run-execution-app-context"), @@ -716,7 +710,7 @@ it.effect("fails the run when its ownership check cannot be read before calling session: { events: Stream.never, startTurn: () => Ref.update(providerStarts, (count) => count + 1), - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: runId, threadId, ordinal: 1, providerInstanceId } as OrchestrationV2Run, rootNode: { id: NodeId.make("node:run-execution-start-guard-read"), @@ -821,7 +815,7 @@ it.effect( Effect.sync(() => { calls.push("compact"); }), - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: RunId.make(`run:compact-routing:${index}`), threadId, @@ -888,7 +882,7 @@ it.effect("refreshes MCP credential liveness before calling the provider", () => session: { events: Stream.never, startTurn: () => Ref.update(order, (entries) => [...entries, "start-turn"]), - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: RunId.make("run:run-execution-mcp-liveness"), threadId, @@ -1000,7 +994,7 @@ it.effect("starts the provider when checkpoint baseline capture fails", () => session: { events: Stream.never, startTurn: () => Ref.update(providerStarts, (count) => count + 1), - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: runId, threadId, @@ -1137,7 +1131,7 @@ it.effect.each(["failure", "interruption", "stale-attempt", "start-guard"] as co session: { events: Stream.never, startTurn: () => Ref.update(providerStarts, (count) => count + 1), - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: runId, threadId, @@ -1288,7 +1282,7 @@ it.effect("keeps ingesting owned child events after the root turn terminalizes", ), ), ); - const events: ReadonlyArray = [ + const events: ReadonlyArray = [ { type: "app_thread.created", driver, @@ -1300,7 +1294,7 @@ it.effect("keeps ingesting owned child events after the root turn terminalizes", rootThreadId: threadId, }, }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, { type: "provider_thread.updated", driver, @@ -1308,7 +1302,7 @@ it.effect("keeps ingesting owned child events after the root turn terminalizes", id: childProviderThreadId, appThreadId: childThreadId, }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, { type: "subagent.updated", driver, @@ -1318,7 +1312,7 @@ it.effect("keeps ingesting owned child events after the root turn terminalizes", runId, status: "running", }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, { type: "provider_turn.updated", driver, @@ -1330,7 +1324,7 @@ it.effect("keeps ingesting owned child events after the root turn terminalizes", runAttemptId: null, status: "running", }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, { type: "turn.terminal", driver, @@ -1353,7 +1347,7 @@ it.effect("keeps ingesting owned child events after the root turn terminalizes", text: "Hello.", streaming: false, }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, { type: "provider_turn.updated", driver, @@ -1365,7 +1359,7 @@ it.effect("keeps ingesting owned child events after the root turn terminalizes", runAttemptId: null, status: "completed", }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, { type: "subagent.updated", driver, @@ -1375,7 +1369,7 @@ it.effect("keeps ingesting owned child events after the root turn terminalizes", runId, status: "completed", }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, ]; yield* Effect.gen(function* () { @@ -1387,7 +1381,7 @@ it.effect("keeps ingesting owned child events after the root turn terminalizes", session: { events: Stream.fromIterable(events), startTurn: () => Effect.void, - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: runId, threadId, @@ -1788,7 +1782,7 @@ it.effect( ], updatedAt: now, }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, rootTerminalEvent(ids, "completed"), { type: "provider_thread.updated", @@ -1799,12 +1793,12 @@ it.effect( pendingBackgroundTasks: [], updatedAt: now, }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, ]), close: Deferred.succeed(ingestionDone, undefined), }), startTurn: () => Effect.void, - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: ids.runId, threadId: ids.threadId, @@ -2000,7 +1994,7 @@ it.effect("drops late root provider-thread writes from a superseded attempt", () ], updatedAt: now, }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, rootTerminalEvent(ids, "completed"), // Late snapshot after a replacement attempt claimed the same // run ordinal. Without attempt gating this would clobber it. @@ -2016,12 +2010,12 @@ it.effect("drops late root provider-thread writes from a superseded attempt", () ], updatedAt: now, }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, ]), close: Deferred.succeed(ingestionDone, undefined), }), startTurn: () => Effect.void, - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: ids.runId, threadId: ids.threadId, @@ -2197,7 +2191,7 @@ it.effect( ], updatedAt: now, }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, // Late completion still writable (turn_item writes are not // ownership-gated); stream must stay open for it. backgroundTurnItemEvent(ids, "command_execution", "completed", 2), @@ -2205,7 +2199,7 @@ it.effect( close: Deferred.succeed(ingestionDone, undefined), }), startTurn: () => Effect.void, - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: ids.runId, threadId: ids.threadId, @@ -2371,12 +2365,12 @@ it.effect( ], updatedAt: now, }, - } as ProviderAdapterV2Event, + } as ProviderAdapter.ProviderAdapterV2Event, ]), close: Deferred.succeed(ingestionDone, undefined), }), startTurn: () => Effect.void, - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: ids.runId, threadId: ids.threadId, @@ -2439,7 +2433,7 @@ it.effect( ); const providerInstanceId = ProviderInstanceId.make("codex"); const written = yield* Ref.make>([]); - const ingested = yield* Ref.make>([]); + const ingested = yield* Ref.make>([]); const ingestionDone = yield* Deferred.make(); const layerTest = RunExecutionService.layer.pipe( Layer.provide( @@ -2609,11 +2603,11 @@ it.effect( completedAt: runningChildNode.startedAt, }, }, - ] satisfies ReadonlyArray), + ] satisfies ReadonlyArray), close: Deferred.succeed(ingestionDone, undefined), }), startTurn: () => Effect.void, - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: ids.runId, threadId: ids.threadId, @@ -2940,11 +2934,11 @@ it.effect( }, }, rootTerminalEvent(ids, "interrupted"), - ] satisfies ReadonlyArray), + ] satisfies ReadonlyArray), close: Deferred.succeed(ingestionDone, undefined), }), startTurn: () => Effect.void, - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: ids.runId, threadId: ids.threadId, @@ -3439,7 +3433,7 @@ it.effect("refreshes pull requests after a provider stream exits with an error", shouldFinalizeRun: () => Effect.succeed(true), events: () => Stream.fail( - new ProviderAdapterEventStreamError({ + new ProviderAdapter.ProviderAdapterEventStreamError({ driver, providerSessionId: ProviderSessionId.make("session:exited"), cause: "provider process exited", @@ -3468,7 +3462,7 @@ it.effect("refreshes pull requests only once when startup failure closes its eve Deferred.await(ingestionStarted).pipe( Effect.andThen( Effect.fail( - new ProviderAdapterTurnStartError({ + new ProviderAdapter.ProviderAdapterTurnStartError({ driver, threadId: input.threadId, providerThreadId: input.providerThread.id, @@ -3506,8 +3500,11 @@ function captureRootRunTermination(input: { readonly seedOpenSubagent?: boolean; readonly events?: ( ids: BackgroundScenarioIds, - ) => Stream.Stream; - readonly startTurn?: ProviderAdapterV2SessionRuntime["startTurn"]; + ) => Stream.Stream< + ProviderAdapter.ProviderAdapterV2Event, + ProviderAdapter.ProviderAdapterV2Error + >; + readonly startTurn?: ProviderAdapter.ProviderAdapterV2SessionRuntime["startTurn"]; readonly refreshAfterTurn?: Effect.Effect; }) { return Effect.gen(function* () { @@ -3622,11 +3619,11 @@ function captureRootRunTermination(input: { ] : []), rootTerminalEvent(ids, "interrupted"), - ] satisfies ReadonlyArray), + ] satisfies ReadonlyArray), close: Deferred.succeed(ingestionDone, undefined), }), startTurn: input.startTurn ?? (() => Effect.void), - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: ids.runId, threadId: ids.threadId, @@ -3716,7 +3713,9 @@ function backgroundScenarioIds(key: string): BackgroundScenarioIds { }; } -function childThreadCreatedEvent(ids: BackgroundScenarioIds): ProviderAdapterV2Event { +function childThreadCreatedEvent( + ids: BackgroundScenarioIds, +): ProviderAdapter.ProviderAdapterV2Event { return { type: "app_thread.created", driver, @@ -3728,14 +3727,14 @@ function childThreadCreatedEvent(ids: BackgroundScenarioIds): ProviderAdapterV2E rootThreadId: ids.threadId, }, }, - } as ProviderAdapterV2Event; + } as ProviderAdapter.ProviderAdapterV2Event; } function childBackgroundTurnItemEvent( ids: BackgroundScenarioIds, status: "running" | "completed" | "idle", ordinal: number, -): ProviderAdapterV2Event { +): ProviderAdapter.ProviderAdapterV2Event { return { type: "turn_item.updated", driver, @@ -3748,7 +3747,7 @@ function childBackgroundTurnItemEvent( type: "command_execution", status, }, - } as ProviderAdapterV2Event; + } as ProviderAdapter.ProviderAdapterV2Event; } function backgroundTurnItemEvent( @@ -3757,7 +3756,7 @@ function backgroundTurnItemEvent( status: "running" | "completed" | "idle", ordinal: number, itemId?: TurnItemId, -): ProviderAdapterV2Event { +): ProviderAdapter.ProviderAdapterV2Event { return { type: "turn_item.updated", driver, @@ -3770,7 +3769,7 @@ function backgroundTurnItemEvent( type, status, }, - } as ProviderAdapterV2Event; + } as ProviderAdapter.ProviderAdapterV2Event; } function backgroundTurnItemEventForRun( @@ -3779,7 +3778,7 @@ function backgroundTurnItemEventForRun( type: "command_execution" | "dynamic_tool" | "subagent", status: "running" | "completed" | "idle", ordinal: number, -): ProviderAdapterV2Event { +): ProviderAdapter.ProviderAdapterV2Event { const event = backgroundTurnItemEvent(ids, type, status, ordinal); if (event.type !== "turn_item.updated") { return event; @@ -3790,7 +3789,7 @@ function backgroundTurnItemEventForRun( function subagentEvent( ids: BackgroundScenarioIds, status: "running" | "completed" | "idle", -): ProviderAdapterV2Event { +): ProviderAdapter.ProviderAdapterV2Event { return { type: "subagent.updated", driver, @@ -3800,7 +3799,7 @@ function subagentEvent( runId: ids.runId, status, }, - } as ProviderAdapterV2Event; + } as ProviderAdapter.ProviderAdapterV2Event; } function makeRunOwnedSubagentFixture(input: { @@ -3977,7 +3976,7 @@ function makeRunOwnedSubagentChildNodeFixture(input: { function rootTerminalEvent( ids: BackgroundScenarioIds, status: "completed" | "interrupted" | "cancelled" | "failed", -): ProviderAdapterV2Event { +): ProviderAdapter.ProviderAdapterV2Event { const common = { type: "turn.terminal" as const, driver, @@ -4003,7 +4002,7 @@ function rootTerminalEvent( function runBackgroundItemScenario( key: string, - makeEvents: (ids: BackgroundScenarioIds) => ReadonlyArray, + makeEvents: (ids: BackgroundScenarioIds) => ReadonlyArray, options?: { readonly keepEventStreamOpen?: boolean; readonly loadInheritedBackgroundTurnItems?: () => Effect.Effect< @@ -4082,7 +4081,7 @@ function runBackgroundItemScenario( }; }), startTurn: () => Effect.void, - } as unknown as ProviderAdapterV2SessionRuntime, + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, run: { id: ids.runId, threadId: ids.threadId, diff --git a/apps/server/src/orchestration-v2/RunExecutionService.ts b/apps/server/src/orchestration-v2/RunExecutionService.ts index 111aced2865e3abc00ab9d30e372ab4f5dd2083d..a316ce0ccd6212fa90f2bca7df1274ab8cee5f42 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.ts @@ -41,13 +41,7 @@ import * as ServerSettings from "../serverSettings.ts"; import * as CheckpointService from "./CheckpointService.ts"; import * as EventSink from "./EventSink.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import type { - ProviderAdapterV2Event, - ProviderAdapterV2RuntimePolicy, - ProviderAdapterV2SessionRuntime, - ProviderAdapterV2TurnMessage, -} from "@t3tools/provider-core/server/ProviderAdapter"; -import { ProviderAdapterTurnStartError } from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderEventIngestor from "./ProviderEventIngestor.ts"; import type { ProjectionStoreV2Error } from "./ProjectionStore.ts"; import { @@ -79,7 +73,10 @@ export interface InheritedBackgroundTurnItemRoute { readonly runId: OrchestrationV2Run["id"]; } -type ProviderTerminalEvent = Extract; +type ProviderTerminalEvent = Extract< + ProviderAdapter.ProviderAdapterV2Event, + { readonly type: "turn.terminal" } +>; function isTerminalProviderTurnStatus(status: OrchestrationV2ProviderTurn["status"]): boolean { return ( @@ -351,7 +348,7 @@ export function makeProviderEventRoutingState(input: { } export function routeProviderEvent( - event: ProviderAdapterV2Event, + event: ProviderAdapter.ProviderAdapterV2Event, input: ProviderEventRouteIdentity, state: ProviderEventRoutingState, ): readonly [boolean, ProviderEventRoutingState] { @@ -503,7 +500,7 @@ export interface RunExecutionServiceV2StartRootRunInput { readonly commandId: CommandId; readonly appThread: OrchestrationV2AppThread; readonly providerSessionId: ProviderSessionId; - readonly session: ProviderAdapterV2SessionRuntime; + readonly session: ProviderAdapter.ProviderAdapterV2SessionRuntime; readonly run: OrchestrationV2Run; readonly rootNode: OrchestrationV2ExecutionNode; readonly checkpointScope: OrchestrationV2CheckpointScope; @@ -521,9 +518,9 @@ export interface RunExecutionServiceV2StartRootRunInput { readonly shouldStartProviderTurn?: () => Effect.Effect; readonly shouldFinalizeRun?: () => Effect.Effect; readonly hasUnpairedRunInterruptRequest?: () => Effect.Effect; - readonly message: ProviderAdapterV2TurnMessage; + readonly message: ProviderAdapter.ProviderAdapterV2TurnMessage; readonly modelSelection: ModelSelection; - readonly runtimePolicy: ProviderAdapterV2RuntimePolicy; + readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy; } export interface RunExecutionServiceV2Shape { @@ -738,7 +735,6 @@ export const layer: Layer.Layer< providerInstanceId: input.run.providerInstanceId, occurredAt: completedAt, payload: makeProviderFailureTurnItem({ - idAllocator, driver: input.terminal.driver, threadId: input.run.threadId, runId: input.run.id, @@ -1006,7 +1002,10 @@ export const layer: Layer.Layer< } yield* Ref.set(rootRunFinalized, true); }); - const trackChildLifecycle = (event: ProviderAdapterV2Event, deliverable: boolean) => + const trackChildLifecycle = ( + event: ProviderAdapter.ProviderAdapterV2Event, + deliverable: boolean, + ) => Effect.gen(function* () { const routing = yield* Ref.get(eventRouting); if (event.type === "provider_turn.updated") { @@ -1403,7 +1402,7 @@ export const layer: Layer.Layer< const startTurn = compact ? (input.session.compactThread?.(turnInput) ?? Effect.fail( - new ProviderAdapterTurnStartError({ + new ProviderAdapter.ProviderAdapterTurnStartError({ driver: input.session.driver, threadId: input.run.threadId, providerThreadId: input.providerThread.id, @@ -1471,7 +1470,7 @@ export const layer: Layer.Layer< ); export function makeInterruptResultTurnItem(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly run: OrchestrationV2Run; readonly rootNode: OrchestrationV2ExecutionNode; readonly providerThread: OrchestrationV2ProviderThread; diff --git a/apps/server/src/orchestration-v2/RuntimePolicy.ts b/apps/server/src/orchestration-v2/RuntimePolicy.ts index a512b7dcabe95cc4ecdbd57a86ff2cf0b2d0e785..6d6fcf82d64dbde112117d7e7dbeb8005b7b070d 100644 --- a/apps/server/src/orchestration-v2/RuntimePolicy.ts +++ b/apps/server/src/orchestration-v2/RuntimePolicy.ts @@ -12,10 +12,7 @@ import * as Option from "effect/Option"; import * as Schema from "effect/Schema"; import * as ProviderInstanceRegistry from "../provider/ProviderInstanceRegistry.ts"; -import { - ProviderAdapterV2RuntimePolicy, - type ProviderAdapterV2RuntimePolicy as ProviderAdapterV2RuntimePolicyType, -} from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProjectStore from "./ProjectStore.ts"; /** @@ -52,7 +49,7 @@ export interface RuntimePolicyV2Shape { readonly resolve: (input: { readonly thread: OrchestrationV2AppThread; readonly modelSelection: ModelSelection; - }) => Effect.Effect; + }) => Effect.Effect; } export class RuntimePolicyV2 extends Context.Service()( @@ -128,7 +125,7 @@ export const layerFromProjectStore: Layer.Layer< }), ), )); - return ProviderAdapterV2RuntimePolicy.make({ + return ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: providerRuntimeMode(input.thread.runtimeMode, supportedRuntimeModes), interactionMode: input.thread.interactionMode, cwd, @@ -149,7 +146,7 @@ export function layerWithOverride( resolve: (input) => base.resolve(input).pipe( Effect.map((policy) => - ProviderAdapterV2RuntimePolicy.make({ + ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ ...policy, ...(override.cwd === undefined ? {} : { cwd: override.cwd }), ...(override.approvalPolicy === undefined diff --git a/apps/server/src/orchestration-v2/RuntimeRequestService.test.ts b/apps/server/src/orchestration-v2/RuntimeRequestService.test.ts index eb4670258101a09b26516414112e662818e39625..11dedc6ab47416a6d941e2396378111d5d4beac2 100644 --- a/apps/server/src/orchestration-v2/RuntimeRequestService.test.ts +++ b/apps/server/src/orchestration-v2/RuntimeRequestService.test.ts @@ -12,7 +12,7 @@ import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; -import type { ProviderAdapterV2RuntimeRequestResponseInput } from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProjectionStore from "./ProjectionStore.ts"; import * as ProviderSessionManager from "./ProviderSessionManager.ts"; import * as RuntimeRequestService from "./RuntimeRequestService.ts"; @@ -69,7 +69,7 @@ it.effect("forwards orchestrator-resolved runtime requests to the live adapter", const providerSessionId = ProviderSessionId.make("provider-session-runtime-request-resolved"); const requestId = RuntimeRequestId.make("request-resolved"); const respondToRuntimeRequest = vi.fn( - (_input: ProviderAdapterV2RuntimeRequestResponseInput) => Effect.void, + (_input: ProviderAdapter.ProviderAdapterV2RuntimeRequestResponseInput) => Effect.void, ); const getSession = vi.fn(() => Effect.succeed( @@ -133,7 +133,7 @@ it.effect("rejects expired runtime requests before invoking the live adapter", ( const providerSessionId = ProviderSessionId.make("provider-session-runtime-request-expired"); const requestId = RuntimeRequestId.make("request-expired"); const respondToRuntimeRequest = vi.fn( - (_input: ProviderAdapterV2RuntimeRequestResponseInput) => Effect.void, + (_input: ProviderAdapter.ProviderAdapterV2RuntimeRequestResponseInput) => Effect.void, ); const getSession = vi.fn(() => Effect.succeed( diff --git a/apps/server/src/orchestration-v2/SelectionRestart.integration.test.ts b/apps/server/src/orchestration-v2/SelectionRestart.integration.test.ts index 425336ac29e00530d80ff4200c144cdf563e7cc1..958fb89cc8e461733ebf54c4408794c2a6af9a92 100644 --- a/apps/server/src/orchestration-v2/SelectionRestart.integration.test.ts +++ b/apps/server/src/orchestration-v2/SelectionRestart.integration.test.ts @@ -28,15 +28,10 @@ import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import * as EffectWorker from "./EffectWorker.ts"; import * as EventSink from "./EventSink.ts"; import * as Orchestrator from "./Orchestrator.ts"; -import { - ProviderAdapterOpenSessionError, - type ProviderAdapterV2Event, - type ProviderAdapterV2Shape, - type ProviderAdapterV2TurnInput, -} from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts"; import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const driver = ProviderDriverKind.make("codex"); const providerInstanceId = ProviderInstanceId.make("codex-restart-test"); @@ -69,7 +64,7 @@ const exclusiveCapabilities: OrchestrationV2ProviderCapabilities = { }; interface ActiveTurn { - readonly input: ProviderAdapterV2TurnInput; + readonly input: ProviderAdapter.ProviderAdapterV2TurnInput; readonly providerTurnId: ProviderTurnId; } @@ -92,7 +87,7 @@ function makeRestartAdapter( state: Ref.Ref, sessionCapabilities: OrchestrationV2ProviderCapabilities = pooledCapabilities, providerInstanceId = initialSelection.instanceId, -): ProviderAdapterV2Shape { +): ProviderAdapter.ProviderAdapterV2["Service"] { return { instanceId: providerInstanceId, driver, @@ -125,14 +120,14 @@ function makeRestartAdapter( ] as const; }); if (failThisOpen) { - return yield* new ProviderAdapterOpenSessionError({ + return yield* new ProviderAdapter.ProviderAdapterOpenSessionError({ driver, providerSessionId: sessionInput.providerSessionId, cause: "simulated replacement open failure", }); } - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); const now = yield* DateTime.now; const providerSession: OrchestrationV2ProviderSession = { id: sessionInput.providerSessionId, @@ -290,7 +285,9 @@ function makeRestartAdapter( }; } -function makeCompletingHandoffAdapter(startCount: Ref.Ref): ProviderAdapterV2Shape { +function makeCompletingHandoffAdapter( + startCount: Ref.Ref, +): ProviderAdapter.ProviderAdapterV2["Service"] { return { instanceId: handoffProviderInstanceId, driver: handoffDriver, @@ -298,7 +295,7 @@ function makeCompletingHandoffAdapter(startCount: Ref.Ref): ProviderAdap planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" }), openSession: (sessionInput) => Effect.gen(function* () { - const events = yield* Queue.unbounded(); + const events = yield* Queue.unbounded(); const now = yield* DateTime.now; return { instanceId: handoffProviderInstanceId, @@ -865,7 +862,7 @@ it.live.each(["active", "idle", "selection-command", "pooled", "separate-home"] }), })), ), - } satisfies ProviderAdapterV2Shape; + } satisfies ProviderAdapter.ProviderAdapterV2["Service"]; }); const layerRegistry = Layer.succeed(ProviderAdapterRegistry.ProviderAdapterRegistryV2, { get: (instanceId) => diff --git a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts index 8c28cbc03ce906b3077a613c27a8500bee76ef8d..730b72feea6b32910cf63a6d306bc47e5fbc931d 100644 --- a/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts +++ b/apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts @@ -23,15 +23,10 @@ import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import * as EffectWorker from "./EffectWorker.ts"; import * as EventSink from "./EventSink.ts"; import * as Orchestrator from "./Orchestrator.ts"; -import { - ProviderAdapterSteerRunError, - type ProviderAdapterV2Event, - type ProviderAdapterV2Shape, - type ProviderAdapterV2TurnInput, -} from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts"; import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const driver = ProviderDriverKind.make("codex"); const instanceId = ProviderInstanceId.make("codex"); @@ -67,8 +62,8 @@ it.effect.each( Effect.scoped( Effect.gen(function* () { const cwd = yield* checkpointWorkspace(`steering-completion-${timing.replaceAll(" ", "-")}`); - const events = yield* Queue.unbounded(); - const started: ProviderAdapterV2TurnInput[] = []; + const events = yield* Queue.unbounded(); + const started: ProviderAdapter.ProviderAdapterV2TurnInput[] = []; const steerEntered = yield* Deferred.make(); const rejectSteer = yield* Deferred.make(); let steerCalls = 0; @@ -80,7 +75,7 @@ it.effect.each( activeSteeringInterruptsTools: timing === "with interrupting native steering", }, }; - const adapter: ProviderAdapterV2Shape = { + const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = { instanceId, driver, getCapabilities: () => Effect.succeed(capabilities), @@ -153,7 +148,7 @@ it.effect.each( if (timing === "after delivery") return; yield* Deferred.succeed(steerEntered, undefined); yield* Deferred.await(rejectSteer); - return yield* new ProviderAdapterSteerRunError({ + return yield* new ProviderAdapter.ProviderAdapterSteerRunError({ driver, providerThreadId: turn.providerThread.id, providerTurnId: turn.providerTurnId, @@ -424,8 +419,8 @@ const composerSelection = { const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function* (name: string) { const cwd = yield* checkpointWorkspace(name); - const events = yield* Queue.unbounded(); - const started: ProviderAdapterV2TurnInput[] = []; + const events = yield* Queue.unbounded(); + const started: ProviderAdapter.ProviderAdapterV2TurnInput[] = []; const steered: string[] = []; const capabilities = { ...CodexProviderCapabilitiesV2, @@ -435,7 +430,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function* supportsSteeringByInterruptRestart: false, }, }; - const adapter: ProviderAdapterV2Shape = { + const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = { instanceId, driver, getCapabilities: () => Effect.succeed(capabilities), diff --git a/apps/server/src/orchestration-v2/ThreadDeletion.ts b/apps/server/src/orchestration-v2/ThreadDeletion.ts index fca9c05ae3e7c8b426145e3415f3fcb53ef64dc9..1b326cc21c44c2ef44e90a909d9a92876cd2b5c5 100644 --- a/apps/server/src/orchestration-v2/ThreadDeletion.ts +++ b/apps/server/src/orchestration-v2/ThreadDeletion.ts @@ -7,7 +7,7 @@ import type * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; import type { PendingOrchestrationEffectV2 } from "./EffectOutbox.ts"; -import type { IdAllocatorV2, IdAllocatorV2Error } from "@t3tools/provider-core/server/IdAllocator"; +import type * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; export interface ThreadDeletionPlan { readonly events: ReadonlyArray; @@ -23,8 +23,8 @@ export const planThreadDeletion = Effect.fn("ThreadDeletion.planThreadDeletion") >; readonly attachmentIds: ReadonlyArray; readonly now: DateTime.Utc; - readonly idAllocator: IdAllocatorV2["Service"]; -}): Effect.fn.Return { + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; +}): Effect.fn.Return { const { command, projection, now, idAllocator } = input; const events: Array = []; const effects: Array = []; diff --git a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts index 77e95378c8bcd406ea8702257bf91c4ffc0a734b..a13277418550ecd80a2db5f0406e2bd55cd16ef7 100644 --- a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts +++ b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts @@ -21,15 +21,15 @@ import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import { ClaudeProviderCapabilitiesV2 } from "./Adapters/ClaudeAdapterV2.ts"; import * as EventSink from "./EventSink.ts"; import * as Orchestrator from "./Orchestrator.ts"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const forkCases = (["codex", "claudeAgent"] as const).flatMap((driverName) => { const driver = ProviderDriverKind.make(driverName); const instanceId = ProviderInstanceId.make(driver); const modelSelection = { instanceId, model: "test-model" }; - const adapter: ProviderAdapterV2Shape = { + const adapter: ProviderAdapter.ProviderAdapterV2["Service"] = { instanceId, driver, getCapabilities: () => diff --git a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts index bfbd078e00c5d0d63075ac237af47e7bf4f0f741..dfa02f4f514bf254f48917161d2e1e62d808078c 100644 --- a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts @@ -54,12 +54,12 @@ import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import * as CommandReceiptStore from "./CommandReceiptStore.ts"; import * as EffectOutbox from "./EffectOutbox.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ThreadLaunch from "./ThreadLaunchService.ts"; import * as ThreadManagement from "./ThreadManagementService.ts"; import * as ThreadTitleRegeneration from "./ThreadTitleRegenerationService.ts"; import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const projectId = ProjectId.make("project:launch-test"); const otherProjectId = ProjectId.make("project:launch-other"); @@ -94,7 +94,7 @@ const adapter = { getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2), planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" as const }), openSession: () => Effect.die("provider execution is disabled in launch tests"), -} as ProviderAdapterV2Shape; +} as ProviderAdapter.ProviderAdapterV2["Service"]; interface HarnessOptions { readonly managedFolders?: Layer.Layer; diff --git a/apps/server/src/orchestration-v2/ThreadStop.test.ts b/apps/server/src/orchestration-v2/ThreadStop.test.ts index 43a77a50e75c0b927a2f4ae232ad671e16ea46d6..6c5874cb75f2c1cedbad47a8a276e3f4a11d06bd 100644 --- a/apps/server/src/orchestration-v2/ThreadStop.test.ts +++ b/apps/server/src/orchestration-v2/ThreadStop.test.ts @@ -24,10 +24,10 @@ import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import { OrchestrationEffectRequestV2 } from "./EffectOutbox.ts"; import * as Orchestrator from "./Orchestrator.ts"; import * as ProjectionStore from "./ProjectionStore.ts"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ThreadManagementService from "./ThreadManagementService.ts"; import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const instanceId = ProviderInstanceId.make("codex"); const modelSelection = { instanceId, model: "gpt-5.1-codex" }; @@ -37,7 +37,7 @@ const adapter = { getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2), planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" as const }), openSession: () => Effect.die("Runs here never reach a provider"), -} as ProviderAdapterV2Shape; +} as ProviderAdapter.ProviderAdapterV2["Service"]; const layerDatabase = SqlitePersistence.layerMemory; // No effect worker: runs stay unstarted, so Stop ends them without a provider. const layerTest = ThreadManagementService.layer.pipe( diff --git a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts index 392dc3fdaee75b981ce762c53cb0bce39dc09711..06f7aa2488c80a24947b07afd05154e7af1d57cc 100644 --- a/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts @@ -22,11 +22,11 @@ import * as ServerSettings from "../serverSettings.ts"; import * as TextGeneration from "../textGeneration/TextGeneration.ts"; import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import * as EffectOutbox from "./EffectOutbox.ts"; -import type { ProviderAdapterV2Shape } from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; import * as ThreadManagement from "./ThreadManagementService.ts"; import * as ThreadTitleRegeneration from "./ThreadTitleRegenerationService.ts"; import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const projectId = ProjectId.make("project:title-regeneration"); const modelSelection = { @@ -40,7 +40,7 @@ const adapter = { getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2), planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" as const }), openSession: () => Effect.die("provider execution is disabled in title regeneration tests"), -} as ProviderAdapterV2Shape; +} as ProviderAdapter.ProviderAdapterV2["Service"]; function makeHarness( options: { diff --git a/apps/server/src/orchestration-v2/assistantStreaming.test.ts b/apps/server/src/orchestration-v2/assistantStreaming.test.ts index 2580936b0dfb1f6cf3b0b2e5351898033113f024..8e36a5abd75eb89625d38029fdc87f3f8a33aaba 100644 --- a/apps/server/src/orchestration-v2/assistantStreaming.test.ts +++ b/apps/server/src/orchestration-v2/assistantStreaming.test.ts @@ -2,9 +2,9 @@ import { describe, expect, it } from "vite-plus/test"; import { MessageId, NodeId, ProviderDriverKind, ThreadId, TurnItemId } from "@t3tools/contracts"; import * as DateTime from "effect/DateTime"; import { makeAssistantStreamingFilter, splitBufferedAssistantText } from "./assistantStreaming.ts"; -import type { ProviderAdapterV2Event } from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; -const message = (text: string, streaming = true): ProviderAdapterV2Event => ({ +const message = (text: string, streaming = true): ProviderAdapter.ProviderAdapterV2Event => ({ type: "message.updated", driver: ProviderDriverKind.make("codex"), message: { @@ -27,7 +27,7 @@ const turnItem = ( text: string, streaming = true, type: "assistant_message" | "reasoning" = "assistant_message", -): ProviderAdapterV2Event => ({ +): ProviderAdapter.ProviderAdapterV2Event => ({ type: "turn_item.updated", driver: ProviderDriverKind.make("codex"), turnItem: { @@ -108,7 +108,7 @@ describe("V2 assistant streaming", () => { "suppresses running assistant nodes in %s mode while delivering tool and completed nodes", (mode) => { const filter = makeAssistantStreamingFilter(mode); - const running: Extract = { + const running: Extract = { type: "node.updated", driver: ProviderDriverKind.make("codex"), node: { diff --git a/apps/server/src/orchestration-v2/assistantStreaming.ts b/apps/server/src/orchestration-v2/assistantStreaming.ts index 4c70dbbfc35e3b84ba6be3a3a8d4a39b1116614e..d17b73daebfdf66d965bd05503635bfe12e6c12d 100644 --- a/apps/server/src/orchestration-v2/assistantStreaming.ts +++ b/apps/server/src/orchestration-v2/assistantStreaming.ts @@ -1,5 +1,5 @@ import type { ResponseStreamingMode } from "@t3tools/contracts"; -import type { ProviderAdapterV2Event } from "@t3tools/provider-core/server/ProviderAdapter"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; // An opening fence may sit at any indentation, since fences inside list // items are indented past the marker. A closing fence may be indented at most @@ -91,7 +91,10 @@ export function splitBufferedAssistantText(text: string): { ready: string; rest: /** Buffer assistant messages and reasoning alike, keeping unfinished markdown out of the read model. */ export function makeAssistantStreamingFilter(mode: ResponseStreamingMode) { const delivered = new Map(); - return (event: ProviderAdapterV2Event, now: number): ProviderAdapterV2Event | null => { + return ( + event: ProviderAdapter.ProviderAdapterV2Event, + now: number, + ): ProviderAdapter.ProviderAdapterV2Event | null => { if ( event.type === "node.updated" && event.node.kind === "assistant_message" && diff --git a/apps/server/src/orchestration-v2/legacy/LegacyV1Cutover.integration.test.ts b/apps/server/src/orchestration-v2/legacy/LegacyV1Cutover.integration.test.ts index 803bc7ce09029e9caf0ea1a75b8ddf05a55afaaa..9ae1e74b9410f1d6cdf35777bc7edfcd908b2286 100644 --- a/apps/server/src/orchestration-v2/legacy/LegacyV1Cutover.integration.test.ts +++ b/apps/server/src/orchestration-v2/legacy/LegacyV1Cutover.integration.test.ts @@ -44,14 +44,10 @@ import * as LegacyV1ThreadImporter from "./LegacyV1ThreadImporter.ts"; import * as Orchestrator from "../Orchestrator.ts"; import * as ProjectionMaintenance from "../ProjectionMaintenance.ts"; import * as ProjectionStore from "../ProjectionStore.ts"; -import { - ProviderAdapterProtocolError, - type ProviderAdapterV2Event, - type ProviderAdapterV2Shape, -} from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts"; import * as ProviderReplayHarness from "../testkit/ProviderReplayHarness.ts"; import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const PROJECT_ID = "project:cutover"; const ACTIVE_THREAD = "thread:cutover:active"; @@ -422,7 +418,7 @@ interface CapturedTurn { } const unimplemented = (detail: string) => - Effect.fail(new ProviderAdapterProtocolError({ driver, detail })); + Effect.fail(new ProviderAdapter.ProviderAdapterProtocolError({ driver, detail })); const makeCodexAdapter = (capturedTurns: Ref.Ref>) => ({ @@ -432,7 +428,7 @@ const makeCodexAdapter = (capturedTurns: Ref.Ref>) = planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" }), openSession: (sessionInput) => Effect.gen(function* () { - const events = yield* PubSub.unbounded(); + const events = yield* PubSub.unbounded(); const now = yield* DateTime.now; const providerSession: OrchestrationV2ProviderSession = { id: sessionInput.providerSessionId, @@ -551,7 +547,7 @@ const makeCodexAdapter = (capturedTurns: Ref.Ref>) = failure: null, threadDisposition: "reusable", }, - ] satisfies ReadonlyArray); + ] satisfies ReadonlyArray); }), steerTurn: () => Effect.void, interruptTurn: () => Effect.void, @@ -561,7 +557,7 @@ const makeCodexAdapter = (capturedTurns: Ref.Ref>) = forkThread: () => unimplemented("forkThread unused in cutover test"), }; }), - }) satisfies ProviderAdapterV2Shape; + }) satisfies ProviderAdapter.ProviderAdapterV2["Service"]; const waitForIdle = Effect.fn("LegacyV1Cutover.waitForIdle")(function* (threadId: ThreadId) { const orchestrator = yield* Orchestrator.OrchestratorV2; diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index aed7f73e6c0f705ed96923be5be33976dd7f5d2b..f28cbae65970710a0a1224336230b5c0cd455107 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -67,16 +67,13 @@ import * as PullRequestWatchReactor from "./PullRequestWatchReactor.ts"; import { PullRequestProviderError } from "../pullRequest/PullRequestProvider.ts"; import * as PullRequestService from "../pullRequest/PullRequestService.ts"; import * as ProjectStore from "./ProjectStore.ts"; -import type { - ProviderAdapterV2SessionRuntime, - ProviderAdapterV2Shape, -} from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderSessionManager from "./ProviderSessionManager.ts"; import * as RuntimeLayer from "./runtimeLayer.ts"; import { shellStreamItemFromThreadShell } from "./ShellStream.ts"; import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts"; import * as ThreadManagementService from "./ThreadManagementService.ts"; import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts"; +import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const layerPlatformTest = Layer.merge( NodeServices.layer, @@ -119,7 +116,7 @@ const orchestrationAdapter = { getCapabilities: () => Effect.succeed(CodexProviderCapabilitiesV2), planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" }), openSession: () => Effect.die("sessions are not used by lifecycle tests"), -} as ProviderAdapterV2Shape; +} as ProviderAdapter.ProviderAdapterV2["Service"]; const providerInstance = { instanceId: modelSelection.instanceId, driverKind: driver, @@ -928,7 +925,9 @@ it.layer(layerTest)("OrchestrationV2LayerLive", (it) => { const sessionSpy = vi .spyOn(sessions, "get") .mockReturnValue( - Effect.succeed(Option.some({ providerSession } as ProviderAdapterV2SessionRuntime)), + Effect.succeed( + Option.some({ providerSession } as ProviderAdapter.ProviderAdapterV2SessionRuntime), + ), ); yield* Effect.addFinalizer(() => Effect.sync(() => sessionSpy.mockRestore())); diff --git a/apps/server/src/orchestration-v2/runtimeLayer.ts b/apps/server/src/orchestration-v2/runtimeLayer.ts index 5d736f1564bebfc166994f17437200b0b86db8db..2442a4fa010c8edb043d7d5f9fb3f9951fe3e6b4 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.ts @@ -30,7 +30,7 @@ import * as ProjectionStore from "./ProjectionStore.ts"; import * as ProjectionMaintenance from "./ProjectionMaintenance.ts"; import * as ProjectStore from "./ProjectStore.ts"; import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import * as ProviderContinuationService from "./ProviderContinuationService.ts"; import * as ThreadTitleRegenerationService from "./ThreadTitleRegenerationService.ts"; import * as ProviderEventIngestor from "./ProviderEventIngestor.ts"; diff --git a/apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts b/apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts index d24ae5b624d90feb53838732b1a2bec19b0336e8..318bd28dd9bd5855ab719dbffcf11d3774ad9905 100644 --- a/apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts +++ b/apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts @@ -35,7 +35,7 @@ import * as ProjectionStore from "../ProjectionStore.ts"; import * as ProjectStore from "../ProjectStore.ts"; import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts"; import * as ProviderAuthService from "../../provider/ProviderAuthService.ts"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import * as ProviderContinuationService from "../ProviderContinuationService.ts"; import * as ProviderEventIngestor from "../ProviderEventIngestor.ts"; import * as ProviderRuntimeRecoveryService from "../ProviderRuntimeRecoveryService.ts"; diff --git a/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts b/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts index e7633781036bf9735d2ec174a1a75f9767f90527..9bde775d0d4e2658242a54defb919635057254d3 100644 --- a/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts +++ b/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts @@ -52,14 +52,6 @@ import * as EffectWorker from "../EffectWorker.ts"; import * as EffectOutbox from "../EffectOutbox.ts"; import * as ProjectionMaintenance from "../ProjectionMaintenance.ts"; import * as ProjectionStore from "../ProjectionStore.ts"; -import { - type ProviderAdapterV2Event, - type ProviderAdapterV2HistoricalContext, - ProviderAdapterProtocolError, - ProviderAdapterTurnStartError, - type ProviderAdapterV2Shape, - type ProviderAdapterV2SessionRuntime, -} from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts"; import { makeProviderFailure } from "@t3tools/provider-core/server/failure"; import { @@ -70,6 +62,7 @@ import { } from "./fixtures/shared.ts"; import * as ProviderReplayHarness from "./ProviderReplayHarness.ts"; import { checkpointWorkspace } from "@t3tools/provider-testing/replayWorkspace"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; const encodeJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown)); @@ -95,7 +88,7 @@ interface CapturedTurn { } function unimplemented(driver: ProviderDriverKind, detail: string) { - return Effect.fail(new ProviderAdapterProtocolError({ driver, detail })); + return Effect.fail(new ProviderAdapter.ProviderAdapterProtocolError({ driver, detail })); } function makeTestAdapter(input: { @@ -116,7 +109,7 @@ function makeTestAdapter(input: { readonly failResumeOnce?: Ref.Ref; readonly initialContextUsage?: OrchestrationV2ProviderThread["contextUsage"]; readonly getModelContextWindow?: (selection: ModelSelection) => number | undefined; - readonly canReuseContextUsage?: ProviderAdapterV2SessionRuntime["canReuseContextUsage"]; + readonly canReuseContextUsage?: ProviderAdapter.ProviderAdapterV2SessionRuntime["canReuseContextUsage"]; readonly tokenUsageByRunOrdinal?: Readonly< Record> >; @@ -125,7 +118,7 @@ function makeTestAdapter(input: { readonly holdRunOrdinal?: number; readonly holdFirstTurn?: Deferred.Deferred; readonly releaseFirstTurn?: Deferred.Deferred; -}): ProviderAdapterV2Shape { +}): ProviderAdapter.ProviderAdapterV2["Service"] { return { instanceId: input.instanceId, driver: input.driver, @@ -133,7 +126,7 @@ function makeTestAdapter(input: { planSelectionTransition: () => Effect.succeed({ type: "apply_on_next_turn" }), openSession: (sessionInput) => Effect.gen(function* () { - const events = yield* PubSub.unbounded(); + const events = yield* PubSub.unbounded(); const now = yield* DateTime.now; const providerSession: OrchestrationV2ProviderSession = { id: sessionInput.providerSessionId, @@ -148,7 +141,7 @@ function makeTestAdapter(input: { lastError: null, }; - const runtime: ProviderAdapterV2SessionRuntime = { + const runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime = { instanceId: input.instanceId, driver: input.driver, providerSessionId: sessionInput.providerSessionId, @@ -204,7 +197,7 @@ function makeTestAdapter(input: { ...(input.injectedHistory === undefined ? {} : { - injectHistory: (history: ProviderAdapterV2HistoricalContext) => + injectHistory: (history: ProviderAdapter.ProviderAdapterV2HistoricalContext) => Ref.update(input.injectedHistory!, (current) => [ ...current, ...historyResponseItems(history.messages, history.context), @@ -236,7 +229,7 @@ function makeTestAdapter(input: { input.refuseStarts !== undefined && (yield* Ref.getAndUpdate(input.refuseStarts, (left) => Math.max(0, left - 1))) > 0 ) - return yield* new ProviderAdapterTurnStartError({ + return yield* new ProviderAdapter.ProviderAdapterTurnStartError({ driver: input.driver, threadId: turnInput.threadId, providerThreadId: turnInput.providerThread.id, @@ -280,7 +273,7 @@ function makeTestAdapter(input: { input.responseByThreadId?.[turnInput.threadId]?.[turnInput.runOrdinal] ?? input.responseByRunOrdinal[turnInput.runOrdinal] ?? `${input.driver} response for run ${turnInput.runOrdinal}`; - const providerEvents: ReadonlyArray = [ + const providerEvents: ReadonlyArray = [ { type: "provider_turn.updated", driver: input.driver, diff --git a/apps/server/src/provider/CodexChatGptAuth.ts b/apps/server/src/provider/CodexChatGptAuth.ts index b6845a02972115b4f94bb9855e38162e14bb9748..2eda1e31533dedc320fc5c623b17d13d8bab21d5 100644 --- a/apps/server/src/provider/CodexChatGptAuth.ts +++ b/apps/server/src/provider/CodexChatGptAuth.ts @@ -19,8 +19,8 @@ import * as Effect from "effect/Effect"; import * as Option from "effect/Option"; import * as Schema from "effect/Schema"; import * as Semaphore from "effect/Semaphore"; -import * as ProviderAuthFlow from "@t3tools/provider-core/server/ProviderAuthFlow"; -import type { ProviderAuthFlowContext } from "@t3tools/provider-core/server/ProviderAuthFlow"; +import * as ProviderAuthFlow from "@t3tools/provider-core/server/providerAuthFlow"; +import type { ProviderAuthFlowContext } from "@t3tools/provider-core/server/providerAuthFlow"; import { HttpClient, HttpClientRequest } from "effect/http"; import * as ProviderCredentialStore from "./ProviderCredentialStore.ts"; import { withChatGptSessionLock } from "./CodexChatGptSessionLock.ts"; diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.test.ts b/apps/server/src/provider/Drivers/AntigravityDriver.test.ts index 33aa39f5598b081c3b5ae3017cfc0195e3f6453a..7ae333fd1e450ee86144d662b02329d2e2e131fc 100644 --- a/apps/server/src/provider/Drivers/AntigravityDriver.test.ts +++ b/apps/server/src/provider/Drivers/AntigravityDriver.test.ts @@ -29,7 +29,7 @@ import { ANTIGRAVITY_AUTH_STDOUT_PREFIX, resolveAntigravityInstanceDirectories, } from "../antigravityAuthSupport.ts"; -import * as ProviderEventLoggers from "../ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as ModelManifest from "../ModelManifest.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import { AntigravityDriver } from "./AntigravityDriver.ts"; diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.ts b/apps/server/src/provider/Drivers/AntigravityDriver.ts index d8710e901a4d0596c101d1ac85d903c3cc2f7a2b..3bac2a48953e58597a5fd331bc43d7db27cda2d8 100644 --- a/apps/server/src/provider/Drivers/AntigravityDriver.ts +++ b/apps/server/src/provider/Drivers/AntigravityDriver.ts @@ -18,7 +18,7 @@ import * as Stream from "effect/Stream"; import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner"; import type { AcpError } from "effect-acp/errors"; -import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost"; +import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost"; import { isAntigravityTextGenerationAvailable, makeAntigravityTextGeneration, @@ -46,12 +46,12 @@ import { removeAntigravitySessionFiles, } from "../acp/AntigravitySessionFiles.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { makeAntigravityAdapterV2 } from "../../orchestration-v2/Adapters/AntigravityAdapterV2.ts"; import { makeAcpNativeLoggerFactory } from "@t3tools/provider-acp/server/nativeLogging"; import { ProviderDriverError } from "../Errors.ts"; import { makeAntigravityProvider } from "../AntigravityProvider.ts"; -import * as ProviderEventLoggers from "../ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as ModelCatalog from "@t3tools/provider-core/server/ModelCatalog"; import { defaultProviderContinuationIdentity, @@ -68,7 +68,7 @@ const isNodeRuntimeUnavailableError = Schema.is(NodeRuntimeUnavailableError); export type AntigravityDriverEnv = | AntigravityInstallation.AntigravityInstallation - | ProviderHost + | ProviderHost.ProviderHost | ChildProcessSpawner.ChildProcessSpawner | Crypto.Crypto | FileSystem.FileSystem @@ -89,7 +89,7 @@ export const AntigravityDriver: ProviderDriver = { const { cwd } = yield* ServerConfig.ServerConfig; const httpClient = yield* HttpClient.HttpClient; const resetCreditCoordinator = yield* ResetCreditCoordinator.ResetCreditCoordinator; - const host = yield* ProviderHost; const catalogService = yield* ModelCatalog.ModelCatalog; const modelCatalog = catalogService .current(DRIVER_KIND) @@ -237,7 +236,7 @@ export const ClaudeDriver: ProviderDriver = { Effect.provideService(Path.Path, path), ); - const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, host.settings); + const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig); const snapshot = yield* makeManagedServerProvider>({ resolveMaintenance, getSettings: snapshotSettings.getSettings, diff --git a/apps/server/src/provider/Drivers/CodexDriver.test.ts b/apps/server/src/provider/Drivers/CodexDriver.test.ts index 72340b7471cf08f3d327aa23d8bce79f710ad6c4..296cc27eb605dab9f3a5532db0d309bda09c618e 100644 --- a/apps/server/src/provider/Drivers/CodexDriver.test.ts +++ b/apps/server/src/provider/Drivers/CodexDriver.test.ts @@ -26,7 +26,7 @@ import * as BackgroundPolicy from "../../background/BackgroundPolicy.ts"; import * as ServerConfig from "../../config.ts"; import * as ServerSettings from "../../serverSettings.ts"; import * as ResetCreditCoordinator from "../resetCreditCoordinator.ts"; -import * as ProviderEventLoggers from "../ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as ModelManifest from "../ModelManifest.ts"; import { createProviderVersionAdvisory, @@ -36,7 +36,7 @@ import { import { CodexDriver } from "./CodexDriver.ts"; import * as CodexAdapterV2 from "../../orchestration-v2/Adapters/CodexAdapterV2.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import { ProviderAdapterV2RuntimePolicy } from "@t3tools/provider-core/server/ProviderAdapter"; +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ProviderCredentialStore from "../ProviderCredentialStore.ts"; import * as ProviderHostLive from "../ProviderHostLive.ts"; @@ -214,7 +214,7 @@ it.layer(layerTest)("CodexDriver", (it) => { threadId, providerSessionId: ProviderSessionId.make("managed-account-session"), modelSelection: { instanceId, model: "gpt-5.4" }, - runtimePolicy: ProviderAdapterV2RuntimePolicy.make({ + runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ runtimeMode: "full-access", interactionMode: "default", cwd: serverConfig.stateDir, diff --git a/apps/server/src/provider/Drivers/CodexDriver.ts b/apps/server/src/provider/Drivers/CodexDriver.ts index a2e580330c3c421d645b0658141a1665d607492e..0759be9b868d22fb43fb757e93ab122150313bae 100644 --- a/apps/server/src/provider/Drivers/CodexDriver.ts +++ b/apps/server/src/provider/Drivers/CodexDriver.ts @@ -31,10 +31,10 @@ import { HttpClient } from "effect/http"; import { ChildProcessSpawner } from "effect/process"; import { makeCodexTextGeneration } from "../../textGeneration/CodexTextGeneration.ts"; -import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost"; +import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost"; import * as ServerConfig from "../../config.ts"; import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion"; -import * as ProviderEventLoggers from "../ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import { createCodexAdapterV2, type CodexAdapterV2DriverEnv, @@ -109,7 +109,7 @@ function makeCodexMaintenanceResolver(sharedHomePath: string) { */ export type CodexDriverEnv = | CodexAdapterV2DriverEnv - | ProviderHost + | ProviderHost.ProviderHost | ChildProcessSpawner.ChildProcessSpawner | ResetCreditCoordinator.ResetCreditCoordinator | Crypto.Crypto @@ -147,7 +147,6 @@ export const CodexDriver: ProviderDriver = { const fileSystem = yield* FileSystem.FileSystem; const pathService = yield* Path.Path; const httpClient = yield* HttpClient.HttpClient; - const host = yield* ProviderHost; const modelCatalog = yield* ModelCatalog.ModelCatalog; const currentCatalog = modelCatalog.current(DRIVER_KIND); const processEnv = mergeProviderInstanceEnvironment(environment); @@ -231,7 +230,7 @@ export const CodexDriver: ProviderDriver = { ), Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner), ); - const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, host.settings); + const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig); const snapshot = yield* makeManagedServerProvider>({ resolveMaintenance, getSettings: snapshotSettings.getSettings, diff --git a/apps/server/src/provider/Drivers/CodexManagedProvider.ts b/apps/server/src/provider/Drivers/CodexManagedProvider.ts index 32d88e64487932d14ecdf29639de0cddb62ce819..a7181352b2889f1efdad52f8b25996d6165d7b5f 100644 --- a/apps/server/src/provider/Drivers/CodexManagedProvider.ts +++ b/apps/server/src/provider/Drivers/CodexManagedProvider.ts @@ -4,7 +4,7 @@ import * as Stream from "effect/Stream"; import * as Option from "effect/Option"; import { ChildProcessSpawner } from "effect/process"; import { makeCodexTextGeneration } from "../../textGeneration/CodexTextGeneration.ts"; -import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost"; +import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost"; import { chatGptModels } from "../CodexChatGptModels.ts"; import { makeCodexManagedRuntime } from "../CodexManagedRuntime.ts"; import { ProviderDriverError } from "../Errors.ts"; @@ -31,7 +31,7 @@ export const makeManagedCodexProvider = Effect.fn("makeManagedCodexProvider")(fu const { instanceId, enabled, displayName, accentColor, config } = input; const http = yield* HttpClient.HttpClient; const spawner = yield* ChildProcessSpawner.ChildProcessSpawner; - const host = yield* ProviderHost; + const host = yield* ProviderHost.ProviderHost; const runtime = yield* makeCodexManagedRuntime({ instanceId, enabled, diff --git a/apps/server/src/provider/EventNdjsonLogger.ts b/apps/server/src/provider/EventNdjsonLogger.ts index 1ec5c46d9324e4e38373f7900ab482477eaf8fc4..f8cbca0c1316a6cd5460dea7cfed241ba28152a1 100644 --- a/apps/server/src/provider/EventNdjsonLogger.ts +++ b/apps/server/src/provider/EventNdjsonLogger.ts @@ -9,7 +9,7 @@ import * as NodeFS from "node:fs"; import * as NodePath from "node:path"; import type { ThreadId } from "@t3tools/contracts"; -import type { EventNdjsonLogger } from "@t3tools/provider-core/server/ProviderEventLoggers"; +import type * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import { RotatingFileSink } from "@t3tools/shared/logging"; import { errorTag } from "@t3tools/shared/observability"; import * as Clock from "effect/Clock"; @@ -21,7 +21,7 @@ import * as Scope from "effect/Scope"; import * as SynchronizedRef from "effect/SynchronizedRef"; import { toSafeThreadAttachmentSegment } from "../attachmentStore.ts"; -import type { ResourceAttribution } from "../resourceTelemetry/ResourceAttribution.ts"; +import type * as ResourceAttribution from "../resourceTelemetry/ResourceAttribution.ts"; const MEBIBYTE = 1024 * 1024; const DAY_MS = 24 * 60 * 60 * 1_000; @@ -64,11 +64,9 @@ const transientAcpUpdates = new Set(["agent_message_chunk", "agent_thought_chunk export type EventNdjsonStream = "native" | "canonical" | "orchestration"; -export type { EventNdjsonLogger }; - export interface EventNdjsonLogStore { readonly filePath: string; - readonly logger: (stream: EventNdjsonStream) => EventNdjsonLogger; + readonly logger: (stream: EventNdjsonStream) => ProviderEventLoggers.EventNdjsonLogger; readonly close: () => Effect.Effect; } @@ -81,7 +79,7 @@ export interface EventNdjsonLogStoreOptions { readonly retentionCheckIntervalMs?: number; readonly maxBufferedBytes?: number; readonly maxBufferedRecords?: number; - readonly attribution?: ResourceAttribution["Service"]; + readonly attribution?: ResourceAttribution.ResourceAttribution["Service"]; } export interface EventNdjsonLoggerOptions extends EventNdjsonLogStoreOptions { @@ -127,7 +125,7 @@ interface ResolvedOptions { readonly retentionCheckIntervalMs: number; readonly maxBufferedBytes: number; readonly maxBufferedRecords: number; - readonly attribution: ResourceAttribution["Service"] | undefined; + readonly attribution: ResourceAttribution.ResourceAttribution["Service"] | undefined; } export interface PendingRecord { @@ -731,8 +729,8 @@ export const makeEventNdjsonLogStore = Effect.fnUntraced(function* ( yield* Scope.close(timerScope, Exit.void); }); - const loggerViews = new Map(); - const logger = (stream: EventNdjsonStream): EventNdjsonLogger => { + const loggerViews = new Map(); + const logger = (stream: EventNdjsonStream): ProviderEventLoggers.EventNdjsonLogger => { const existing = loggerViews.get(stream); if (existing) return existing; @@ -778,7 +776,11 @@ export const makeEventNdjsonLogStore = Effect.fnUntraced(function* ( } }); - const view = { filePath, write, close: () => Effect.void } satisfies EventNdjsonLogger; + const view = { + filePath, + write, + close: () => Effect.void, + } satisfies ProviderEventLoggers.EventNdjsonLogger; loggerViews.set(stream, view); return view; }; @@ -789,7 +791,7 @@ export const makeEventNdjsonLogStore = Effect.fnUntraced(function* ( export const makeEventNdjsonLogger = Effect.fnUntraced(function* ( filePath: string, options: EventNdjsonLoggerOptions, -): Effect.fn.Return { +): Effect.fn.Return { const store = yield* makeEventNdjsonLogStore(filePath, options).pipe( Effect.catch((error) => logWarning(error.message, { error }).pipe( diff --git a/apps/server/src/provider/ProviderEventLoggers.ts b/apps/server/src/provider/ProviderEventLoggers.ts deleted file mode 100644 index b31acbef952bd932866031bba131ce6ebf16326d..0000000000000000000000000000000000000000 --- a/apps/server/src/provider/ProviderEventLoggers.ts +++ /dev/null @@ -1,71 +0,0 @@ -/** - * ProviderEventLoggers — single observability service that owns the shared - * provider event log store and exposes its two runtime views: - * - * - `native` — provider-protocol events as the SDK emits them, written - * from inside each `Adapter` factory. - * - `canonical` — runtime events after `ProviderService` has normalized - * them onto `ProviderRuntimeEvent`. - * - * Why a service tag and not constructor options? - * - * - Adapters are now constructed *inside* drivers (`Driver.create()`), - * not at the boot Layer. There is no longer a single `makeAdapterLive(options)` - * call site where we can hand an `EventNdjsonLogger` in by hand. - * - Multiple driver instances per kind (`codex_personal`, `codex_work`) - * must share one underlying log store — opening N writers against the - * same rotating file would race the rotation logic. Owning the loggers on - * a single tag keeps that invariant intact. - * - Tests can swap one (or both) loggers with in-memory recorders by - * `Layer.succeed(ProviderEventLoggers, { native, canonical })` instead of - * juggling per-Layer option threading. - * - * Both fields are optional because observability must not prevent startup. - * - * @module provider/ProviderEventLoggers - */ -import * as Effect from "effect/Effect"; -import * as Layer from "effect/Layer"; - -import * as ServerConfig from "../config.ts"; -import * as ResourceAttribution from "../resourceTelemetry/ResourceAttribution.ts"; -import { - NoOpProviderEventLoggers, - ProviderEventLoggers, -} from "@t3tools/provider-core/server/ProviderEventLoggers"; -import * as EventNdjsonLogger from "./EventNdjsonLogger.ts"; - -export { NoOpProviderEventLoggers, ProviderEventLoggers }; - -/** - * Builds both stream views over one shared store. Setup failures are logged - * and downgraded to the no-op service so diagnostics never block startup. - * - * @public Service construction is part of the canonical Effect module API. - */ -export const make = Effect.gen(function* () { - const { providerEventLogPath } = yield* ServerConfig.ServerConfig; - const attribution = yield* ResourceAttribution.ResourceAttribution; - const store = yield* EventNdjsonLogger.makeEventNdjsonLogStore(providerEventLogPath, { - attribution, - }).pipe( - Effect.catch((error) => - Effect.logWarning(error.message, { error }).pipe( - Effect.annotateLogs({ scope: "provider-observability" }), - Effect.as(undefined), - ), - ), - ); - - if (!store) { - return ProviderEventLoggers.of(NoOpProviderEventLoggers); - } - - yield* Effect.addFinalizer(() => store.close()); - return ProviderEventLoggers.of({ - native: store.logger("native"), - canonical: store.logger("canonical"), - }); -}); - -export const layer = Layer.effect(ProviderEventLoggers, make); diff --git a/apps/server/src/provider/ProviderHostLive.ts b/apps/server/src/provider/ProviderHostLive.ts index 3a924b39bd664b381c09a9841346757e86282f87..14d08de50ee9776d954f041aa759b640f9c203dd 100644 --- a/apps/server/src/provider/ProviderHostLive.ts +++ b/apps/server/src/provider/ProviderHostLive.ts @@ -1,10 +1,10 @@ /** - * The server's implementation of `ProviderHost`, the only server surface + * The server's implementation of `ProviderHost.ProviderHost`, the only server surface * provider drivers and adapters may use. * * @module provider/ProviderHostLive */ -import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost"; +import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost"; import { ProviderCredentialError } from "@t3tools/provider-core/server/errors"; import * as Crypto from "effect/Crypto"; import * as Effect from "effect/Effect"; @@ -18,14 +18,14 @@ import * as ServerSettings from "../serverSettings.ts"; import * as ProviderCredentialStore from "./ProviderCredentialStore.ts"; export const layer = Layer.effect( - ProviderHost, + ProviderHost.ProviderHost, Effect.gen(function* () { const config = yield* ServerConfig.ServerConfig; const serverSettings = yield* ServerSettings.ServerSettingsService; const backgroundPolicy = yield* BackgroundPolicy.BackgroundPolicy; const secrets = yield* ServerSecretStore.ServerSecretStore; const crypto = yield* Crypto.Crypto; - return ProviderHost.of({ + return ProviderHost.ProviderHost.of({ paths: { cwd: config.cwd, baseDir: config.baseDir, diff --git a/apps/server/src/provider/ProviderInstanceRegistry.test.ts b/apps/server/src/provider/ProviderInstanceRegistry.test.ts index 933751bdd39b73da00f56970e83c301915c032eb..81208e54091e80069fae3a716f33111d933211cc 100644 --- a/apps/server/src/provider/ProviderInstanceRegistry.test.ts +++ b/apps/server/src/provider/ProviderInstanceRegistry.test.ts @@ -61,7 +61,7 @@ import * as ModelManifest from "./ModelManifest.ts"; import * as OpenCodeRuntime from "@t3tools/provider-opencode/server/OpenCodeRuntime"; import * as OpenCodeServerLedger from "@t3tools/provider-opencode/server/OpenCodeServerLedger"; import * as ResetCreditCoordinator from "./resetCreditCoordinator.ts"; -import * as ProviderEventLoggers from "./ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import { makeProviderInstanceRegistry } from "./ProviderInstanceRegistry.ts"; import * as ProviderOrchestrationAdapterInfrastructure from "./ProviderOrchestrationAdapterInfrastructure.ts"; import * as ProviderHostLive from "./ProviderHostLive.ts"; diff --git a/apps/server/src/provider/ProviderInstanceRegistryHydration.ts b/apps/server/src/provider/ProviderInstanceRegistryHydration.ts index 6048f48636ea2b00e6740b1f5cacc6ce1bb93c55..822b69bcb8176134f9373dba61bb7931952634ad 100644 --- a/apps/server/src/provider/ProviderInstanceRegistryHydration.ts +++ b/apps/server/src/provider/ProviderInstanceRegistryHydration.ts @@ -40,7 +40,7 @@ import * as ProviderInstanceRegistryMutator from "./ProviderInstanceRegistryMuta import * as ProviderOrchestrationAdapterInfrastructure from "./ProviderOrchestrationAdapterInfrastructure.ts"; import * as AcpRegistrySupport from "@t3tools/provider-acp-registry/server/AcpRegistrySupport"; import * as ProviderHostLive from "./ProviderHostLive.ts"; -import type { ProviderHost } from "@t3tools/provider-core/server/ProviderHost"; +import type * as ProviderHost from "@t3tools/provider-core/server/ProviderHost"; import type * as BackgroundPolicy from "../background/BackgroundPolicy.ts"; import type * as ServerConfig from "../config.ts"; @@ -49,10 +49,10 @@ type ProviderInstanceRegistryHydrationEnv = BuiltInDriversEnv, | ProviderOrchestrationAdapterInfrastructure.ProviderOrchestrationAdapterInfrastructure | AcpRegistrySupport.AcpRegistryCatalog - | ProviderHost + | ProviderHost.ProviderHost > | Settings.ServerSettingsService - // Requirements of the `ProviderHost` the drivers receive. + // Requirements of the `ProviderHost.ProviderHost` the drivers receive. | BackgroundPolicy.BackgroundPolicy | ServerConfig.ServerConfig; diff --git a/apps/server/src/provider/ProviderOrchestrationAdapterInfrastructure.ts b/apps/server/src/provider/ProviderOrchestrationAdapterInfrastructure.ts index 2cbb70fbbdeccd37f7e99f1b757ccf7e1034d03f..3dea8ca677ed247279e4be300db29a8c6b19be88 100644 --- a/apps/server/src/provider/ProviderOrchestrationAdapterInfrastructure.ts +++ b/apps/server/src/provider/ProviderOrchestrationAdapterInfrastructure.ts @@ -4,7 +4,7 @@ import * as ClaudeAdapterV2 from "../orchestration-v2/Adapters/ClaudeAdapterV2.t import * as CodexAdapterV2 from "../orchestration-v2/Adapters/CodexAdapterV2.ts"; import * as CursorAgentSdk from "@t3tools/provider-cursor/server/CursorAgentSdk"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; export type ProviderOrchestrationAdapterInfrastructure = | ClaudeAdapterV2.ClaudeAgentSdkQueryRunner diff --git a/apps/server/src/provider/ProviderRegistry.test.ts b/apps/server/src/provider/ProviderRegistry.test.ts index 8653bd32ebd2188d9de76b6389e3f54125aa8796..f0ed962544143b3b8f4f5851575765081318d17d 100644 --- a/apps/server/src/provider/ProviderRegistry.test.ts +++ b/apps/server/src/provider/ProviderRegistry.test.ts @@ -47,7 +47,7 @@ import { applyProviderCompatibility } from "./providerCompatibility.ts"; import * as ResetCreditCoordinator from "./resetCreditCoordinator.ts"; import * as OpenCodeRuntime from "@t3tools/provider-opencode/server/OpenCodeRuntime"; import * as OpenCodeServerLedger from "@t3tools/provider-opencode/server/OpenCodeServerLedger"; -import * as ProviderEventLoggers from "./ProviderEventLoggers.ts"; +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as ProviderInstanceRegistryHydration from "./ProviderInstanceRegistryHydration.ts"; import * as ServerConfig from "../config.ts"; import * as ServerSettingsModule from "../serverSettings.ts"; diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts index 79fb63afb64fe9c0f35a5843661c2c5d5385b39a..ab93e814e7009fadc37cc3325b68ea504c9ef34f 100644 --- a/apps/server/src/server.ts +++ b/apps/server/src/server.ts @@ -1,3 +1,4 @@ +import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import type { RelayManagedEndpointRuntimeConfig } from "@t3tools/contracts/relay"; import * as Clock from "effect/Clock"; import * as Random from "effect/Random"; @@ -42,7 +43,7 @@ import * as AnalyticsService from "./telemetry/AnalyticsService.ts"; import * as ProviderEventIngestor from "./orchestration-v2/ProviderEventIngestor.ts"; import * as ModelManifest from "./provider/ModelManifest.ts"; import * as ResetCreditCoordinator from "./provider/resetCreditCoordinator.ts"; -import * as ProviderEventLoggers from "./provider/ProviderEventLoggers.ts"; +import * as EventNdjsonLogger from "./provider/EventNdjsonLogger.ts"; import * as OpenCodeRuntime from "@t3tools/provider-opencode/server/OpenCodeRuntime"; import * as OpenCodeServerLedger from "@t3tools/provider-opencode/server/OpenCodeServerLedger"; import * as ProviderHostLive from "./provider/ProviderHostLive.ts"; @@ -193,6 +194,30 @@ const layerApplicationObservability = EventLoopMonitor.layer.pipe( Layer.provideMerge(layerResourceAttribution), ); +// One rotating store behind both logger views, so driver instances never race +// its rotation. Diagnostics must not block startup: a store that cannot open +// degrades to the no-op loggers. +const layerProviderEventLoggers = Layer.effect( + ProviderEventLoggers.ProviderEventLoggers, + Effect.gen(function* () { + const { providerEventLogPath } = yield* ServerConfig.ServerConfig; + const attribution = yield* ResourceAttribution.ResourceAttribution; + const store = yield* EventNdjsonLogger.makeEventNdjsonLogStore(providerEventLogPath, { + attribution, + }).pipe( + Effect.catch((error) => + Effect.logWarning(error.message, { error }).pipe( + Effect.annotateLogs({ scope: "provider-observability" }), + Effect.as(undefined), + ), + ), + ); + if (!store) return ProviderEventLoggers.NoOpProviderEventLoggers; + yield* Effect.addFinalizer(() => store.close()); + return { native: store.logger("native"), canonical: store.logger("canonical") }; + }), +); + const layerPtyAdapter = NodePtyAdapter.layer; const layerServerSettings = ServerSettings.layer.pipe( @@ -599,17 +624,14 @@ const layerRuntimeCoreDependencies = layerRuntimeCoreDependenciesBase.pipe( // Search, prepare, status inspection, and turn launch share one registry // cache so every client and provider instance sees the same prepared agents. Layer.provideMerge(AcpRegistrySupport.layerFromHost.pipe(Layer.provide(ProviderHostLive.layer))), - // Shared native/canonical NDJSON writers used by both the per-instance - // V2 drivers and the orchestration runtime. Provide resource attribution so - // the rewritten telemetry pipeline can account for logical NDJSON writes. - // Provided once at the runtime level so every consumer sees the same - // logger instances. + // Provider event loggers are shared by every driver instance and the + // orchestration runtime, so they are provided once here. // `ModelManifest.layer` is the model manifest, refreshed from the repo's // `model-manifest.json` on `main`. Drivers read their entry through the // `ModelCatalog` port it provides. Layer.provideMerge( Layer.mergeAll( - ProviderEventLoggers.layer, + layerProviderEventLoggers, ModelManifest.layerModelCatalog.pipe(Layer.provideMerge(ModelManifest.layer)), ResetCreditCoordinator.layer, ), diff --git a/packages/provider-acp-registry/src/server/auth.ts b/packages/provider-acp-registry/src/server/auth.ts index 7189d5a4fdec6e17d64b858bcda94fa5fc0e8e2a..72993a7a5f896977b5eb5ccce612b94984b25743 100644 --- a/packages/provider-acp-registry/src/server/auth.ts +++ b/packages/provider-acp-registry/src/server/auth.ts @@ -16,7 +16,7 @@ import { ChildProcessSpawner } from "effect/process"; import type * as AcpSchema from "effect-acp/compat"; import * as PtyAdapter from "@t3tools/shared/PtyAdapter"; -import * as ProviderAuthFlow from "@t3tools/provider-core/server/ProviderAuthFlow"; +import * as ProviderAuthFlow from "@t3tools/provider-core/server/providerAuthFlow"; import { normalizeAcpRegistryAuthMethods, normalizeAcpRegistryWebUrl } from "./probe.ts"; import * as AcpRegistrySupport from "./AcpRegistrySupport.ts"; import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts"; diff --git a/packages/provider-acp-registry/src/server/driver.ts b/packages/provider-acp-registry/src/server/driver.ts index 17ca9ea3ddcbb073577d3639f3b4c35de0606b91..0e699bee5bf8a07913a1369a236e6bafe46a7a3c 100644 --- a/packages/provider-acp-registry/src/server/driver.ts +++ b/packages/provider-acp-registry/src/server/driver.ts @@ -21,7 +21,7 @@ import * as Schema from "effect/Schema"; import * as Semaphore from "effect/Semaphore"; import { ChildProcessSpawner } from "effect/process"; -import { ProviderHost } from "@t3tools/provider-core/server/ProviderHost"; +import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost"; import { AcpRegistryAdapterV2Driver, type AcpRegistryAdapterV2DriverEnv } from "./adapter.ts"; import type { ProviderTextGeneration } from "@t3tools/provider-core/server/textGeneration"; import { ProviderDriverError } from "@t3tools/provider-core/server/errors"; @@ -455,7 +455,7 @@ export const checkAcpRegistryProviderReadiness = Effect.fn( : snapshot; }); -export type AcpRegistryDriverEnv = AcpRegistryAdapterV2DriverEnv | ProviderHost; +export type AcpRegistryDriverEnv = AcpRegistryAdapterV2DriverEnv | ProviderHost.ProviderHost; /** Canonical provider-instance wrapper for ACP Registry orchestration adapters. */ export const AcpRegistryDriver: ProviderDriver = { @@ -485,7 +485,7 @@ export const AcpRegistryDriver: ProviderDriver >({ diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 65c168314fd16ce5cb1bdf90e01eaaf83a04d399..220521019818bf290329742d7d42c61372bfa5e4 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -95,7 +95,7 @@ import { } from "@t3tools/provider-core/server/orchestrationInstructions"; import { buildRuntimeInstructions } from "@t3tools/provider-core/server/runtimeInstructions"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import { type ProviderContinuationRequest } from "@t3tools/provider-core/server/continuationRequests"; +import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { type BackgroundWork, type BackgroundWorkReport, @@ -499,7 +499,9 @@ export interface AcpAdapterV2Options { * / history-only behavior for null-activeTurn updates. */ readonly continuationRequests?: { - readonly offer: (request: ProviderContinuationRequest) => Effect.Effect; + readonly offer: ( + request: ProviderContinuationRequests.ProviderContinuationRequest, + ) => Effect.Effect; }; readonly testHooks?: { /** @@ -743,7 +745,7 @@ function nativeThreadId( function makeProviderThread(input: { readonly driver: ProviderDriverKind; readonly providerInstanceId: ProviderInstanceId; - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly appThreadId: OrchestrationV2ProviderThread["appThreadId"]; readonly providerSessionId: OrchestrationV2ProviderThread["providerSessionId"]; readonly nativeThreadId: string; @@ -2226,7 +2228,6 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( type: "turn_item.updated", driver, turnItem: makeProviderRetryTurnItem({ - idAllocator, driver, threadId: context.input.threadId, runId: context.input.runId, diff --git a/packages/provider-core/package.json b/packages/provider-core/package.json index fe4b25b981bcc44f75121bda3924559405e0da6d..2b7b653b6baa06a95d421a3ab6ee81374768150f 100644 --- a/packages/provider-core/package.json +++ b/packages/provider-core/package.json @@ -23,10 +23,6 @@ "types": "./src/server/collectStreamText.ts", "import": "./src/server/collectStreamText.ts" }, - "./server/continuationRequests": { - "types": "./src/server/continuationRequests.ts", - "import": "./src/server/continuationRequests.ts" - }, "./server/driver": { "types": "./src/server/driver.ts", "import": "./src/server/driver.ts" @@ -103,9 +99,13 @@ "types": "./src/server/ProviderAdapter.ts", "import": "./src/server/ProviderAdapter.ts" }, - "./server/ProviderAuthFlow": { - "types": "./src/server/ProviderAuthFlow.ts", - "import": "./src/server/ProviderAuthFlow.ts" + "./server/providerAuthFlow": { + "types": "./src/server/providerAuthFlow.ts", + "import": "./src/server/providerAuthFlow.ts" + }, + "./server/ProviderContinuationRequests": { + "types": "./src/server/ProviderContinuationRequests.ts", + "import": "./src/server/ProviderContinuationRequests.ts" }, "./server/ProviderEventLoggers": { "types": "./src/server/ProviderEventLoggers.ts", diff --git a/packages/provider-core/src/server/IdAllocator.ts b/packages/provider-core/src/server/IdAllocator.ts index cb31cfb5895f7ff0e509bacca4c6e4e610dc42d1..3382ca49a236ee85fe9e32ba66e7ac91252ab16a 100644 --- a/packages/provider-core/src/server/IdAllocator.ts +++ b/packages/provider-core/src/server/IdAllocator.ts @@ -67,7 +67,7 @@ export class IdAllocatorV2AllocationError extends Schema.TaggedError Effect.Effect; } -export interface IdAllocatorV2DeriveShape { +export interface IdAllocatorV2Derive { readonly providerSession: (input: { readonly providerInstanceId: ProviderInstanceId; }) => ProviderSessionId; @@ -180,14 +180,13 @@ export interface IdAllocatorV2DeriveShape { readonly approvalTurnItem: (input: { readonly requestId: RuntimeRequestId }) => TurnItemId; } -export interface IdAllocatorV2Shape { - readonly allocate: IdAllocatorV2AllocateShape; - readonly derive: IdAllocatorV2DeriveShape; -} - -export class IdAllocatorV2 extends Context.Service()( - "@t3tools/provider-core/server/IdAllocator/IdAllocatorV2", -) {} +export class IdAllocatorV2 extends Context.Service< + IdAllocatorV2, + { + readonly allocate: IdAllocatorV2Allocate; + readonly derive: IdAllocatorV2Derive; + } +>()("@t3tools/provider-core/server/IdAllocator/IdAllocatorV2") {} const encodePart = (part: string | number): string => encodeURIComponent(String(part)); @@ -252,6 +251,49 @@ const randomId = ), ); +/** Deterministic id derivations; pure, so callers that only derive need no allocator. */ +export const derive: IdAllocatorV2Derive = { + providerSession: (input) => + ProviderSessionId.make( + joinId("provider-session", "provider-instance", input.providerInstanceId, "shared"), + ), + delegatedTaskNode: (input) => NodeId.make(joinId("node", "delegated-task", input.commandId)), + delegatedTaskThread: (input) => + ThreadId.make(joinId("thread", "delegated-task", input.commandId)), + delegatedTaskMessage: (input) => + MessageId.make(joinId("message", "delegated-task", input.commandId)), + delegatedTaskTurnItem: (input) => + TurnItemId.make(joinId("turn-item", "delegated-task", input.commandId)), + createdThreadTurnItem: (input) => + TurnItemId.make(joinId("turn-item", "created-thread", input.commandId)), + threadFromProviderThread: deriveThreadFromProviderThread, + run: (input) => RunId.make(joinId("run", "thread", input.threadId, "ordinal", input.ordinal)), + runAttempt: (input) => + RunAttemptId.make(joinId("run-attempt", "run", input.runId, "attempt", input.attemptOrdinal)), + rootNode: (input) => NodeId.make(joinId("node", "run", input.runId, "root")), + rootNodeAttempt: (input) => + NodeId.make(joinId("node", "run", input.runId, "attempt", input.attemptOrdinal, "root")), + userTurnItem: (input) => TurnItemId.make(joinId("turn-item", "message", input.messageId)), + runSignalTurnItem: (input) => + TurnItemId.make(joinId("turn-item", "run", input.runId, "signal", input.signal)), + providerThread: deriveProviderThread, + providerTurn: (input) => + ProviderTurnId.make( + joinId("provider-turn", "provider", input.driver, "native-turn", input.nativeTurnId), + ), + nodeFromProviderItem: (input) => + NodeId.make(joinId("node", "provider", input.driver, "native-item", input.nativeItemId)), + messageFromProviderItem: (input) => + MessageId.make(joinId("message", "provider", input.driver, "native-item", input.nativeItemId)), + turnItemFromProviderItem: (input) => + TurnItemId.make( + joinId("turn-item", "provider", input.driver, "native-item", input.nativeItemId), + ), + approvalNode: (input) => NodeId.make(joinId("node", "runtime-request", input.requestId)), + approvalTurnItem: (input) => + TurnItemId.make(joinId("turn-item", "runtime-request", input.requestId)), +}; + export const layer: Layer.Layer = Layer.succeed( IdAllocatorV2, IdAllocatorV2.of({ @@ -386,50 +428,6 @@ export const layer: Layer.Layer = Layer.succeed( make: PlanId.make, })(input), }, - derive: { - providerSession: (input) => - ProviderSessionId.make( - joinId("provider-session", "provider-instance", input.providerInstanceId, "shared"), - ), - delegatedTaskNode: (input) => NodeId.make(joinId("node", "delegated-task", input.commandId)), - delegatedTaskThread: (input) => - ThreadId.make(joinId("thread", "delegated-task", input.commandId)), - delegatedTaskMessage: (input) => - MessageId.make(joinId("message", "delegated-task", input.commandId)), - delegatedTaskTurnItem: (input) => - TurnItemId.make(joinId("turn-item", "delegated-task", input.commandId)), - createdThreadTurnItem: (input) => - TurnItemId.make(joinId("turn-item", "created-thread", input.commandId)), - threadFromProviderThread: deriveThreadFromProviderThread, - run: (input) => RunId.make(joinId("run", "thread", input.threadId, "ordinal", input.ordinal)), - runAttempt: (input) => - RunAttemptId.make( - joinId("run-attempt", "run", input.runId, "attempt", input.attemptOrdinal), - ), - rootNode: (input) => NodeId.make(joinId("node", "run", input.runId, "root")), - rootNodeAttempt: (input) => - NodeId.make(joinId("node", "run", input.runId, "attempt", input.attemptOrdinal, "root")), - userTurnItem: (input) => TurnItemId.make(joinId("turn-item", "message", input.messageId)), - runSignalTurnItem: (input) => - TurnItemId.make(joinId("turn-item", "run", input.runId, "signal", input.signal)), - providerThread: deriveProviderThread, - providerTurn: (input) => - ProviderTurnId.make( - joinId("provider-turn", "provider", input.driver, "native-turn", input.nativeTurnId), - ), - nodeFromProviderItem: (input) => - NodeId.make(joinId("node", "provider", input.driver, "native-item", input.nativeItemId)), - messageFromProviderItem: (input) => - MessageId.make( - joinId("message", "provider", input.driver, "native-item", input.nativeItemId), - ), - turnItemFromProviderItem: (input) => - TurnItemId.make( - joinId("turn-item", "provider", input.driver, "native-item", input.nativeItemId), - ), - approvalNode: (input) => NodeId.make(joinId("node", "runtime-request", input.requestId)), - approvalTurnItem: (input) => - TurnItemId.make(joinId("turn-item", "runtime-request", input.requestId)), - }, + derive, }), ); diff --git a/packages/provider-core/src/server/ProviderAdapter.ts b/packages/provider-core/src/server/ProviderAdapter.ts index c6e6ef48627556f77466ce1c8acba3f769d781ce..086300e21878eac4471d4b18f435aae853b587d7 100644 --- a/packages/provider-core/src/server/ProviderAdapter.ts +++ b/packages/provider-core/src/server/ProviderAdapter.ts @@ -632,21 +632,20 @@ export interface ProviderAdapterV2SessionRuntime { ) => Effect.Effect; } -export interface ProviderAdapterV2Shape { - readonly instanceId: ProviderInstanceId; - readonly driver: ProviderDriverKind; - readonly getCapabilities: () => Effect.Effect< - OrchestrationV2ProviderCapabilities, - ProviderAdapterV2Error - >; - readonly planSelectionTransition: ( - input: ProviderSelectionTransitionInput, - ) => Effect.Effect; - readonly openSession: ( - input: ProviderAdapterV2OpenSessionInput, - ) => Effect.Effect; -} - -export class ProviderAdapterV2 extends Context.Service()( - "@t3tools/provider-core/server/ProviderAdapter/ProviderAdapterV2", -) {} +export class ProviderAdapterV2 extends Context.Service< + ProviderAdapterV2, + { + readonly instanceId: ProviderInstanceId; + readonly driver: ProviderDriverKind; + readonly getCapabilities: () => Effect.Effect< + OrchestrationV2ProviderCapabilities, + ProviderAdapterV2Error + >; + readonly planSelectionTransition: ( + input: ProviderSelectionTransitionInput, + ) => Effect.Effect; + readonly openSession: ( + input: ProviderAdapterV2OpenSessionInput, + ) => Effect.Effect; + } +>()("@t3tools/provider-core/server/ProviderAdapter/ProviderAdapterV2") {} diff --git a/packages/provider-core/src/server/continuationRequests.ts b/packages/provider-core/src/server/ProviderContinuationRequests.ts similarity index 97% rename from packages/provider-core/src/server/continuationRequests.ts rename to packages/provider-core/src/server/ProviderContinuationRequests.ts index f7c8606ace14e925d827b466a8c639e9a98d5eea..638068eb621fdcc5702ee0ba05edc6dc7fd3a903 100644 --- a/packages/provider-core/src/server/continuationRequests.ts +++ b/packages/provider-core/src/server/ProviderContinuationRequests.ts @@ -59,7 +59,7 @@ export interface ProviderContinuationRequest { export class ProviderContinuationRequests extends Context.Reference<{ readonly offer: (request: ProviderContinuationRequest) => Effect.Effect; readonly take: Effect.Effect; -}>("@t3tools/provider-core/server/continuationRequests/ProviderContinuationRequests", { +}>("@t3tools/provider-core/server/ProviderContinuationRequests", { defaultValue: () => ({ offer: () => Effect.void, take: Effect.never }), }) {} diff --git a/packages/provider-core/src/server/ProviderHost.ts b/packages/provider-core/src/server/ProviderHost.ts index 050ad0882fd96a8a123976679ef393a35f89044c..858a7c1e22d1a8a386b66662580dbb2bff0219c4 100644 --- a/packages/provider-core/src/server/ProviderHost.ts +++ b/packages/provider-core/src/server/ProviderHost.ts @@ -45,33 +45,32 @@ export interface ProviderCredentials { readonly remove: Effect.Effect; } -interface ProviderHostService { - readonly paths: ProviderHostPaths; - readonly settings: { - readonly get: Effect.Effect; - /** Runs `use` on a settings snapshot that no settings write can change until it finishes. */ - readonly withSnapshot: ( - use: (settings: ServerSettings) => Effect.Effect, - ) => Effect.Effect; - /** Every settings change after subscription, starting with the next one. */ - readonly changes: Stream.Stream; - /** Changes buffered from the moment the scoped subscription is acquired. */ - readonly subscribe: Effect.Effect, never, Scope.Scope>; - }; - /** Whether background work for `scope` should run now (client demand and host power). */ - readonly shouldRunBackgroundWork: (scope: BackgroundScope) => Effect.Effect; - /** - * Absolute path of a stored chat attachment, or `null` when its id does not - * resolve inside the attachments directory. - */ - readonly resolveAttachmentPath: (attachment: ChatAttachment) => string | null; - /** The credentials stored for `bindingId`, usually an instance id, under a provider-chosen namespace. */ - readonly credentials: ( - namespace: string, - bindingId: string, - ) => Effect.Effect; -} - -export class ProviderHost extends Context.Service()( - "@t3tools/provider-core/server/ProviderHost", -) {} +export class ProviderHost extends Context.Service< + ProviderHost, + { + readonly paths: ProviderHostPaths; + readonly settings: { + readonly get: Effect.Effect; + /** Runs `use` on a settings snapshot that no settings write can change until it finishes. */ + readonly withSnapshot: ( + use: (settings: ServerSettings) => Effect.Effect, + ) => Effect.Effect; + /** Every settings change after subscription, starting with the next one. */ + readonly changes: Stream.Stream; + /** Changes buffered from the moment the scoped subscription is acquired. */ + readonly subscribe: Effect.Effect, never, Scope.Scope>; + }; + /** Whether background work for `scope` should run now (client demand and host power). */ + readonly shouldRunBackgroundWork: (scope: BackgroundScope) => Effect.Effect; + /** + * Absolute path of a stored chat attachment, or `null` when its id does not + * resolve inside the attachments directory. + */ + readonly resolveAttachmentPath: (attachment: ChatAttachment) => string | null; + /** The credentials stored for `bindingId`, usually an instance id, under a provider-chosen namespace. */ + readonly credentials: ( + namespace: string, + bindingId: string, + ) => Effect.Effect; + } +>()("@t3tools/provider-core/server/ProviderHost") {} diff --git a/packages/provider-core/src/server/adapterDriver.ts b/packages/provider-core/src/server/adapterDriver.ts index 7445dc7ed016228f6d1a1dcf47943e97bf16da0b..27f1432394730093005b38b2922f89d3bf5744c7 100644 --- a/packages/provider-core/src/server/adapterDriver.ts +++ b/packages/provider-core/src/server/adapterDriver.ts @@ -39,7 +39,7 @@ export interface ProviderAdapterDriver { readonly create: ( input: ProviderAdapterDriverCreateInput, ) => Effect.Effect< - ProviderAdapter.ProviderAdapterV2Shape, + ProviderAdapter.ProviderAdapterV2["Service"], ProviderAdapterDriverCreateError, R | Scope.Scope >; diff --git a/packages/provider-core/src/server/driver.ts b/packages/provider-core/src/server/driver.ts index b177ba926ba4636274413187a4008e02542dd1b0..df215d3197429059b5a4040472d57fb3ea979d02 100644 --- a/packages/provider-core/src/server/driver.ts +++ b/packages/provider-core/src/server/driver.ts @@ -101,7 +101,7 @@ export interface ProviderInstance { ProviderConsumeResetCreditOutcome, ProviderDriverError >; - readonly orchestrationAdapter: ProviderAdapter.ProviderAdapterV2Shape; + readonly orchestrationAdapter: ProviderAdapter.ProviderAdapterV2["Service"]; readonly textGeneration: ProviderTextGeneration; readonly auth?: ProviderAuthController; readonly acpSessionManagement?: { diff --git a/packages/provider-core/src/server/failure.ts b/packages/provider-core/src/server/failure.ts index 8a745f83aaac20bccf3af1ba127082488154edf7..45c90822aaf3fb3cea8a1426397497c2ee64c826 100644 --- a/packages/provider-core/src/server/failure.ts +++ b/packages/provider-core/src/server/failure.ts @@ -13,7 +13,7 @@ import type { import * as DateTime from "effect/DateTime"; import * as Cause from "effect/Cause"; -import type * as IdAllocator from "./IdAllocator.ts"; +import * as IdAllocator from "./IdAllocator.ts"; import * as Schema from "effect/Schema"; /** Raised when portable history does not fit the target provider's context window. */ @@ -172,7 +172,6 @@ export function makeProviderFailure(input: { } export function makeProviderFailureTurnItem(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; readonly driver: ProviderDriverKind; readonly threadId: ThreadId; readonly runId: RunId | null; @@ -186,7 +185,7 @@ export function makeProviderFailureTurnItem(input: { readonly occurredAt: DateTime.Utc; }): Extract { return { - id: input.idAllocator.derive.turnItemFromProviderItem({ + id: IdAllocator.derive.turnItemFromProviderItem({ driver: input.driver, nativeItemId: `terminal-failure:${input.providerTurnId}`, }), @@ -210,7 +209,6 @@ export function makeProviderFailureTurnItem(input: { } export function makeProviderRetryTurnItem(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; readonly driver: ProviderDriverKind; readonly threadId: ThreadId; readonly runId: RunId | null; @@ -237,7 +235,7 @@ export function makeProviderRetryTurnItem(input: { title = "Provider retry stopped"; } return { - id: input.idAllocator.derive.turnItemFromProviderItem({ + id: IdAllocator.derive.turnItemFromProviderItem({ driver: input.driver, nativeItemId: `terminal-failure:${input.providerTurnId}`, }), diff --git a/packages/provider-core/src/server/ProviderAuthFlow.test.ts b/packages/provider-core/src/server/providerAuthFlow.test.ts similarity index 99% rename from packages/provider-core/src/server/ProviderAuthFlow.test.ts rename to packages/provider-core/src/server/providerAuthFlow.test.ts index 5ea9a0fc2f3b0c3b43d157bc4243d826c6600320..2351243f1e0ef629f49d28ddf4c8313bbbe08dad 100644 --- a/packages/provider-core/src/server/ProviderAuthFlow.test.ts +++ b/packages/provider-core/src/server/providerAuthFlow.test.ts @@ -16,7 +16,7 @@ import * as Option from "effect/Option"; import * as Stream from "effect/Stream"; import * as TestClock from "effect/testing/TestClock"; -import * as ProviderAuthFlow from "./ProviderAuthFlow.ts"; +import * as ProviderAuthFlow from "./providerAuthFlow.ts"; const instanceId = ProviderInstanceId.make("auth-flow-test"); const method = { id: "browser", name: "Browser", description: null, type: "agent" as const }; diff --git a/packages/provider-core/src/server/ProviderAuthFlow.ts b/packages/provider-core/src/server/providerAuthFlow.ts similarity index 100% rename from packages/provider-core/src/server/ProviderAuthFlow.ts rename to packages/provider-core/src/server/providerAuthFlow.ts diff --git a/packages/provider-core/src/server/snapshotSettings.ts b/packages/provider-core/src/server/snapshotSettings.ts index f434d35b967e3121dabe79e3cbb680722a42134c..bf0996d0a15abff963686106ad99737ffab28de9 100644 --- a/packages/provider-core/src/server/snapshotSettings.ts +++ b/packages/provider-core/src/server/snapshotSettings.ts @@ -3,7 +3,7 @@ import * as Effect from "effect/Effect"; import * as Equal from "effect/Equal"; import * as Stream from "effect/Stream"; -import type * as ProviderHost from "./ProviderHost.ts"; +import * as ProviderHost from "./ProviderHost.ts"; export interface ProviderSnapshotSettings { readonly provider: Settings; @@ -27,17 +27,23 @@ export function haveProviderSnapshotSettingsChanged( return !Equal.equals(previous, next); } -export function makeProviderSnapshotSettingsSource( +/** The instance's settings paired with the host's server settings, as snapshots read them. */ +export const makeProviderSnapshotSettingsSource = ( provider: Settings, - settings: ProviderHost.ProviderHost["Service"]["settings"], -): { - readonly getSettings: Effect.Effect, ServerSettingsError>; - readonly streamSettings: Stream.Stream>; -} { - const mapSettings = (settings: ServerSettings) => - makeProviderSnapshotSettings(provider, settings); - return { - getSettings: settings.get.pipe(Effect.map(mapSettings)), - streamSettings: settings.changes.pipe(Stream.map(mapSettings)), - }; -} +): Effect.Effect< + { + readonly getSettings: Effect.Effect, ServerSettingsError>; + readonly streamSettings: Stream.Stream>; + }, + never, + ProviderHost.ProviderHost +> => + Effect.gen(function* () { + const { settings } = yield* ProviderHost.ProviderHost; + const mapSettings = (current: ServerSettings) => + makeProviderSnapshotSettings(provider, current); + return { + getSettings: settings.get.pipe(Effect.map(mapSettings)), + streamSettings: settings.changes.pipe(Stream.map(mapSettings)), + }; + }); diff --git a/packages/provider-cursor/src/server/adapter.ts b/packages/provider-cursor/src/server/adapter.ts index 5aa9e836bd73fc481a1ee37cb90730059734a8f9..8ebf8ea9a44879ee0a0d8944abbe48d9f2f70973 100644 --- a/packages/provider-cursor/src/server/adapter.ts +++ b/packages/provider-cursor/src/server/adapter.ts @@ -239,7 +239,7 @@ function providerSession(input: { } function makeProviderThread(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly providerInstanceId: ProviderInstanceId; readonly appThreadId: OrchestrationV2ProviderThread["appThreadId"]; readonly providerSessionId: OrchestrationV2ProviderThread["providerSessionId"]; diff --git a/packages/provider-cursor/src/server/driver.ts b/packages/provider-cursor/src/server/driver.ts index 157b7dca5c1e12e0ad953b7bb29b33f8986f45e1..e007e8b6fda6b57fd9a59674b4101651044746ce 100644 --- a/packages/provider-cursor/src/server/driver.ts +++ b/packages/provider-cursor/src/server/driver.ts @@ -223,7 +223,7 @@ export const CursorDriver: ProviderDriver = { Effect.provide(CursorSdkCatalog.layer), ); - const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, host.settings); + const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig); const snapshot = yield* makeManagedServerProvider>({ resolveMaintenance: () => Effect.succeed(MAINTENANCE_CAPABILITIES), getSettings: snapshotSettings.getSettings, diff --git a/packages/provider-grok/src/server/adapter.ts b/packages/provider-grok/src/server/adapter.ts index b25faa9db4e73623536eed768fb7f390546d59be..e8332425201b63cd3c612d1b4c8938404ee3ac0c 100644 --- a/packages/provider-grok/src/server/adapter.ts +++ b/packages/provider-grok/src/server/adapter.ts @@ -58,7 +58,7 @@ import { acpPermissionDisposition } from "@t3tools/provider-acp/server/clientPol import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime"; import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import { ProviderAdapterDriverCreateError, diff --git a/packages/provider-grok/src/server/driver.ts b/packages/provider-grok/src/server/driver.ts index e3201d0f03c306669968c7ba2b89b5715af0a0b9..a2ce6ce4a41ee795b5f028060cb1bd1219e4ec00 100644 --- a/packages/provider-grok/src/server/driver.ts +++ b/packages/provider-grok/src/server/driver.ts @@ -160,7 +160,7 @@ export const GrokDriver: ProviderDriver = { Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner), ); - const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, host.settings); + const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig); const snapshot = yield* makeManagedServerProvider>({ resolveMaintenance, getSettings: snapshotSettings.getSettings, diff --git a/packages/provider-muse/src/server/adapter.test.ts b/packages/provider-muse/src/server/adapter.test.ts index 33191bb8e46e8aac19f93fdd5f60bcf1a5134d00..90071af22ed63a819c09104bc2920a0082f6354e 100644 --- a/packages/provider-muse/src/server/adapter.test.ts +++ b/packages/provider-muse/src/server/adapter.test.ts @@ -36,7 +36,7 @@ import type { MuseItem } from "./protocol.ts"; import type { MuseSdkHost } from "./sdk.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; -import type { ProviderContinuationRequest } from "@t3tools/provider-core/server/continuationRequests"; +import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { makeMuseAdapterV2, type MuseAdapterV2Options } from "./adapter.ts"; const testLayer = Layer.mergeAll( @@ -766,7 +766,7 @@ describe("MuseAdapterV2", () => { it.effect("lets a user turn take a held Muse report turn, approvals included", () => Effect.gen(function* () { const fake = yield* makeFakeMuse(); - const offers: Array = []; + const offers: Array = []; const harness = yield* makeHarness( fake, INSTANCE_ID, diff --git a/packages/provider-muse/src/server/adapter.ts b/packages/provider-muse/src/server/adapter.ts index c834e1370ebefad8fa40d75f050dad84b1178fd5..558a50960f840d2e695cafff24b6b1012bb5302b 100644 --- a/packages/provider-muse/src/server/adapter.ts +++ b/packages/provider-muse/src/server/adapter.ts @@ -74,7 +74,7 @@ import { backgroundWorkNotification, type BackgroundWorkReport, } from "@t3tools/provider-core/server/notification"; -import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { makeProviderFailure } from "@t3tools/provider-core/server/failure"; import { turnScopedSelectionTransition } from "@t3tools/provider-core/server/selectionTransition"; import { museItemStatus, museToolPresentation } from "./itemPresentation.ts"; diff --git a/packages/provider-muse/src/server/driver.ts b/packages/provider-muse/src/server/driver.ts index 805749f7ef8c4026afcd21abc5c14b36d7ddad46..2b35db227ff260dc89ddeb6d53acc97ee792be0a 100644 --- a/packages/provider-muse/src/server/driver.ts +++ b/packages/provider-muse/src/server/driver.ts @@ -14,7 +14,7 @@ import { makeMuseTextGeneration } from "./textGeneration.ts"; import { ProviderDriverError } from "@t3tools/provider-core/server/errors"; import { makeMuseAdapterV2 } from "./adapter.ts"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { checkMuseProviderStatus, makePendingMuseProvider } from "./status.ts"; import * as ProviderEventLoggers from "@t3tools/provider-core/server/ProviderEventLoggers"; import { makeManagedServerProvider } from "@t3tools/provider-core/server/managedProvider"; @@ -86,7 +86,7 @@ export const MuseDriver: ProviderDriver = { accentColor, continuationGroupKey: continuationIdentity.continuationKey, }); - const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, host.settings); + const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig); const resolveInstallation = yield* makeCachedProviderMaintenanceResolution( resolveProviderMaintenanceCapabilitiesEffect(museMaintenance, { binaryPath: effectiveConfig.binaryPath, diff --git a/packages/provider-opencode/src/server/adapter.ts b/packages/provider-opencode/src/server/adapter.ts index 8c9f5e83ae6c7e4e0e4ee94c3a19450968407737..0beb1c2147e67790a2640275a151e541648a3b35 100644 --- a/packages/provider-opencode/src/server/adapter.ts +++ b/packages/provider-opencode/src/server/adapter.ts @@ -459,7 +459,7 @@ function formatOpenCodeProtocolLogPayload(event: OpenCodeProtocolLogEvent) { export function makeOpenCodeProtocolLogger(input: { readonly nativeEventLogger: ProviderEventLoggers.EventNdjsonLogger | undefined; - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly providerInstanceId: ProviderInstanceId; readonly providerSessionId: ProviderSessionId; readonly threadId: ThreadId; @@ -830,7 +830,7 @@ function taskSessionId(part: ToolPart): string | null { } function makeProviderThread(input: { - readonly idAllocator: IdAllocator.IdAllocatorV2Shape; + readonly idAllocator: IdAllocator.IdAllocatorV2["Service"]; readonly providerInstanceId: ProviderInstanceId; readonly providerSessionId: OrchestrationV2ProviderThread["providerSessionId"]; readonly appThreadId: OrchestrationV2ProviderThread["appThreadId"]; diff --git a/packages/provider-opencode/src/server/driver.ts b/packages/provider-opencode/src/server/driver.ts index 9c37ab2abd48a0d0e1d18bbd2e4abbfbefe768f7..fba3465980606adfbfcd722971bbc360f4bdb708 100644 --- a/packages/provider-opencode/src/server/driver.ts +++ b/packages/provider-opencode/src/server/driver.ts @@ -123,9 +123,9 @@ function byOpenCodeRuntime( */ function selectOpenCodeRuntimeAdapter(input: { readonly probe: OpenCodeRuntimeProbe; - readonly v1: ProviderAdapter.ProviderAdapterV2Shape; - readonly v2: ProviderAdapter.ProviderAdapterV2Shape; -}): ProviderAdapter.ProviderAdapterV2Shape { + readonly v1: ProviderAdapter.ProviderAdapterV2["Service"]; + readonly v2: ProviderAdapter.ProviderAdapterV2["Service"]; +}): ProviderAdapter.ProviderAdapterV2["Service"] { const pick = (probed: Effect.Effect) => byOpenCodeRuntime(probed, { v1: Effect.succeed(input.v1), v2: Effect.succeed(input.v2) }); const hot = pick(Effect.map(input.probe.lastSuccess, Option.getOrUndefined)); @@ -445,7 +445,7 @@ export const OpenCodeDriver: ProviderDriver ), ); - const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, host.settings); + const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig); const snapshot = yield* makeManagedServerProvider>( { resolveMaintenance, diff --git a/packages/provider-opencode/src/server/v2/adapter.ts b/packages/provider-opencode/src/server/v2/adapter.ts index 97429ddfde8581dc9587ab2b4eae8b73f44dc0c2..89fb482100333779bcf7d26b7a256f9bace65854 100644 --- a/packages/provider-opencode/src/server/v2/adapter.ts +++ b/packages/provider-opencode/src/server/v2/adapter.ts @@ -88,7 +88,7 @@ import { backgroundWorkNotification, type BackgroundWorkReport, } from "@t3tools/provider-core/server/notification"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { makeProviderFailure } from "@t3tools/provider-core/server/failure"; import { makeSubagentChildThread, @@ -858,7 +858,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr }); const openSession = Effect.fn("OpenCode2Adapter.openSession")(function* ( - input: Parameters[0], + input: Parameters[0], initial: { readonly connection: OpenCode2Server.OpenCode2Connection; readonly scope: Scope.Closeable; diff --git a/packages/provider-pi/src/server/adapter.test.ts b/packages/provider-pi/src/server/adapter.test.ts index ed3236d763c7e2526cdfcf9b1bf1b4c9a43c1d37..b6942a4d529eec766b8297fd36fc0ab323793874 100644 --- a/packages/provider-pi/src/server/adapter.test.ts +++ b/packages/provider-pi/src/server/adapter.test.ts @@ -32,7 +32,7 @@ import * as TestClock from "effect/testing/TestClock"; import { ChildProcess, ChildProcessSpawner } from "effect/process"; import { layerTestProviderHost } from "@t3tools/provider-testing/host"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; diff --git a/packages/provider-pi/src/server/adapter.ts b/packages/provider-pi/src/server/adapter.ts index e0d93d51a0103950b7083c2af064cfa9d59e9736..d2709307c985188afbcdd23d4548f90ce82ce593 100644 --- a/packages/provider-pi/src/server/adapter.ts +++ b/packages/provider-pi/src/server/adapter.ts @@ -67,7 +67,7 @@ import { parsePiCompactCommand, type PiCompactCommand } from "./commands.ts"; import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment"; import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; -import * as ProviderContinuationRequests from "@t3tools/provider-core/server/continuationRequests"; +import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; import { ProviderAdapterDriverCreateError, type ProviderAdapterDriver, @@ -775,7 +775,6 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* ( type: "turn_item.updated", driver: PI_PROVIDER, turnItem: makeProviderRetryTurnItem({ - idAllocator, driver: PI_PROVIDER, threadId: turn.turnInput.threadId, runId: turn.turnInput.runId, diff --git a/packages/provider-pi/src/server/driver.ts b/packages/provider-pi/src/server/driver.ts index 25d39091178146c0acccca9885d3101ae69632c0..c1507b861ca5c09331ece0a584a8c04cbc4fb5db 100644 --- a/packages/provider-pi/src/server/driver.ts +++ b/packages/provider-pi/src/server/driver.ts @@ -142,7 +142,7 @@ export const PiDriver: ProviderDriver = { Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner), ); - const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, host.settings); + const snapshotSettings = yield* makeProviderSnapshotSettingsSource(effectiveConfig); const snapshot = yield* makeManagedServerProvider>({ resolveMaintenance, getSettings: snapshotSettings.getSettings, -- 2.54.0