Files
t3code/apps/server/src/provider/Services/ProviderService.ts
T
Julius Marminge 8572ca2d05 Add plan interaction mode and user-input request handling
- Wire Codex plan mode through turn start, including collaboration settings
- Track and answer pending `requestUserInput` prompts instead of auto-empty responses
- Persist/project thread `interactionMode` (schema, migration, queries) and update tests/contracts
2026-03-05 18:15:55 -08:00

126 lines
3.5 KiB
TypeScript

/**
* ProviderService - Service interface for provider sessions, turns, and checkpoints.
*
* Acts as the cross-provider facade used by transports (WebSocket/RPC). It
* resolves provider adapters through `ProviderAdapterRegistry`, routes
* session-scoped calls via `ProviderSessionDirectory`, and exposes one unified
* provider event stream to callers.
*
* Uses Effect `ServiceMap.Service` for dependency injection and returns typed
* domain errors for validation, session, codex, and checkpoint workflows.
*
* @module ProviderService
*/
import type {
ProviderInterruptTurnInput,
ProviderKind,
ProviderRespondToRequestInput,
ProviderRespondToUserInputInput,
ProviderRuntimeEvent,
ProviderSendTurnInput,
ProviderSession,
ProviderSessionStartInput,
ProviderStopSessionInput,
ThreadId,
ProviderTurnStartResult,
} from "@t3tools/contracts";
import { ServiceMap } from "effect";
import type { Effect, Stream } from "effect";
import type { ProviderServiceError } from "../Errors.ts";
import type { ProviderAdapterCapabilities } from "./ProviderAdapter.ts";
/**
* ProviderServiceShape - Service API for provider session and turn orchestration.
*/
export interface ProviderServiceShape {
/**
* Start a provider session.
*/
readonly startSession: (
threadId: ThreadId,
input: ProviderSessionStartInput,
) => Effect.Effect<ProviderSession, ProviderServiceError>;
/**
* Send a provider turn.
*/
readonly sendTurn: (
input: ProviderSendTurnInput,
) => Effect.Effect<ProviderTurnStartResult, ProviderServiceError>;
/**
* Interrupt a running provider turn.
*/
readonly interruptTurn: (
input: ProviderInterruptTurnInput,
) => Effect.Effect<void, ProviderServiceError>;
/**
* Respond to a provider approval request.
*/
readonly respondToRequest: (
input: ProviderRespondToRequestInput,
) => Effect.Effect<void, ProviderServiceError>;
/**
* Respond to a provider structured user-input request.
*/
readonly respondToUserInput: (
input: ProviderRespondToUserInputInput,
) => Effect.Effect<void, ProviderServiceError>;
/**
* Stop a provider session.
*/
readonly stopSession: (
input: ProviderStopSessionInput,
) => Effect.Effect<void, ProviderServiceError>;
/**
* List active provider sessions.
*
* Aggregates runtime session lists from all registered adapters.
*/
readonly listSessions: () => Effect.Effect<ReadonlyArray<ProviderSession>>;
/**
* Read static capabilities for a provider adapter.
*/
readonly getCapabilities: (
provider: ProviderKind,
) => Effect.Effect<ProviderAdapterCapabilities, ProviderServiceError>;
/**
* Roll back provider conversation state by a number of turns.
*/
readonly rollbackConversation: (input: {
readonly threadId: ThreadId;
readonly numTurns: number;
}) => Effect.Effect<void, ProviderServiceError>;
/**
* Stop all active provider sessions.
*
* Persisted session bindings remain so stale sessions can be resumed after
* process restart.
*
* Runtime alias mappings are cleared as part of shutdown.
*/
readonly stopAll: () => Effect.Effect<void, ProviderServiceError>;
/**
* Canonical provider runtime event stream.
*
* Fan-out is owned by ProviderService (not by a standalone event-bus service).
*/
readonly streamEvents: Stream.Stream<ProviderRuntimeEvent>;
}
/**
* ProviderService - Service tag for provider orchestration.
*/
export class ProviderService extends ServiceMap.Service<ProviderService, ProviderServiceShape>()(
"t3/provider/Services/ProviderService",
) {}