1import type {
2 ChatGptReconnectProfile,
3 ChatGptTransferredProfile,
4 ProviderAuthRespondInput,
5 ProviderAuthState,
6 ProviderSetupError,
7} from "@t3tools/contracts";
8import type * as Effect from "effect/Effect";
9import type * as Scope from "effect/Scope";
10import type * as Stream from "effect/Stream";
11
12export interface ProviderAuthController {
13 /** Equal keys mean these instances share credentials on this environment. */
14 readonly credentialBinding?: { readonly owner: "provider" | "t3"; readonly key: string };
15 readonly reconnectProfile?: (
16 methodId: string,
17 ) => Effect.Effect<ChatGptReconnectProfile | null, ProviderSetupError>;
18 readonly importProfile?: (
19 profile: ChatGptTransferredProfile,
20 stopSessions: Effect.Effect<void, ProviderSetupError>,
21 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
22 readonly adoptCredentials?: (
23 update: Effect.Effect<void, ProviderSetupError>,
24 stopSessions: Effect.Effect<void, ProviderSetupError>,
25 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
26 readonly isChangingCredentials?: Effect.Effect<boolean>;
27 readonly invalidate?: Effect.Effect<void>;
28 readonly refreshMethods?: Effect.Effect<void>;
29 readonly withAccess?: <A, E, R>(
30 task: Effect.Effect<A, E, R>,
31 ) => Effect.Effect<A, E | ProviderSetupError, R | Scope.Scope>;
32 readonly start: (
33 ownerSessionId: string,
34 stopSessions?: Effect.Effect<void, ProviderSetupError>,
35 methodId?: string,
36 returnUrl?: string,
37 callbackMode?: "server" | "client",
38 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
39 readonly complete: (
40 ownerSessionId: string,
41 input: { readonly flowId: string; readonly callbackUrl: string },
42 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
43 readonly cancel: (
44 ownerSessionId: string,
45 flowId: string,
46 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
47 readonly respond?: (
48 ownerSessionId: string,
49 input: ProviderAuthRespondInput,
50 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
51 /** The controller closes process admission before it stops routed sessions. */
52 readonly logout: (
53 stopSessions: Effect.Effect<void, ProviderSetupError>,
54 ) => Effect.Effect<ProviderAuthState, ProviderSetupError>;
55 readonly subscribe: (ownerSessionId: string) => Stream.Stream<ProviderAuthState>;
56 readonly isLogoutPrompt?: (text: string, hasAttachments: boolean) => boolean;
57}