refactor: unwrap McpAuth namespace + self-reexport (#22942)
This commit is contained in:
@@ -4,35 +4,34 @@ import { Global } from "../global"
|
|||||||
import { Effect, Layer, Context } from "effect"
|
import { Effect, Layer, Context } from "effect"
|
||||||
import { AppFileSystem } from "@opencode-ai/shared/filesystem"
|
import { AppFileSystem } from "@opencode-ai/shared/filesystem"
|
||||||
|
|
||||||
export namespace McpAuth {
|
export const Tokens = z.object({
|
||||||
export const Tokens = z.object({
|
|
||||||
accessToken: z.string(),
|
accessToken: z.string(),
|
||||||
refreshToken: z.string().optional(),
|
refreshToken: z.string().optional(),
|
||||||
expiresAt: z.number().optional(),
|
expiresAt: z.number().optional(),
|
||||||
scope: z.string().optional(),
|
scope: z.string().optional(),
|
||||||
})
|
})
|
||||||
export type Tokens = z.infer<typeof Tokens>
|
export type Tokens = z.infer<typeof Tokens>
|
||||||
|
|
||||||
export const ClientInfo = z.object({
|
export const ClientInfo = z.object({
|
||||||
clientId: z.string(),
|
clientId: z.string(),
|
||||||
clientSecret: z.string().optional(),
|
clientSecret: z.string().optional(),
|
||||||
clientIdIssuedAt: z.number().optional(),
|
clientIdIssuedAt: z.number().optional(),
|
||||||
clientSecretExpiresAt: z.number().optional(),
|
clientSecretExpiresAt: z.number().optional(),
|
||||||
})
|
})
|
||||||
export type ClientInfo = z.infer<typeof ClientInfo>
|
export type ClientInfo = z.infer<typeof ClientInfo>
|
||||||
|
|
||||||
export const Entry = z.object({
|
export const Entry = z.object({
|
||||||
tokens: Tokens.optional(),
|
tokens: Tokens.optional(),
|
||||||
clientInfo: ClientInfo.optional(),
|
clientInfo: ClientInfo.optional(),
|
||||||
codeVerifier: z.string().optional(),
|
codeVerifier: z.string().optional(),
|
||||||
oauthState: z.string().optional(),
|
oauthState: z.string().optional(),
|
||||||
serverUrl: z.string().optional(),
|
serverUrl: z.string().optional(),
|
||||||
})
|
})
|
||||||
export type Entry = z.infer<typeof Entry>
|
export type Entry = z.infer<typeof Entry>
|
||||||
|
|
||||||
const filepath = path.join(Global.Path.data, "mcp-auth.json")
|
const filepath = path.join(Global.Path.data, "mcp-auth.json")
|
||||||
|
|
||||||
export interface Interface {
|
export interface Interface {
|
||||||
readonly all: () => Effect.Effect<Record<string, Entry>>
|
readonly all: () => Effect.Effect<Record<string, Entry>>
|
||||||
readonly get: (mcpName: string) => Effect.Effect<Entry | undefined>
|
readonly get: (mcpName: string) => Effect.Effect<Entry | undefined>
|
||||||
readonly getForUrl: (mcpName: string, serverUrl: string) => Effect.Effect<Entry | undefined>
|
readonly getForUrl: (mcpName: string, serverUrl: string) => Effect.Effect<Entry | undefined>
|
||||||
@@ -46,11 +45,11 @@ export namespace McpAuth {
|
|||||||
readonly getOAuthState: (mcpName: string) => Effect.Effect<string | undefined>
|
readonly getOAuthState: (mcpName: string) => Effect.Effect<string | undefined>
|
||||||
readonly clearOAuthState: (mcpName: string) => Effect.Effect<void>
|
readonly clearOAuthState: (mcpName: string) => Effect.Effect<void>
|
||||||
readonly isTokenExpired: (mcpName: string) => Effect.Effect<boolean | null>
|
readonly isTokenExpired: (mcpName: string) => Effect.Effect<boolean | null>
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Service extends Context.Service<Service, Interface>()("@opencode/McpAuth") {}
|
export class Service extends Context.Service<Service, Interface>()("@opencode/McpAuth") {}
|
||||||
|
|
||||||
export const layer = Layer.effect(
|
export const layer = Layer.effect(
|
||||||
Service,
|
Service,
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const fs = yield* AppFileSystem.Service
|
const fs = yield* AppFileSystem.Service
|
||||||
@@ -138,7 +137,8 @@ export namespace McpAuth {
|
|||||||
isTokenExpired,
|
isTokenExpired,
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
export const defaultLayer = layer.pipe(Layer.provide(AppFileSystem.defaultLayer))
|
export const defaultLayer = layer.pipe(Layer.provide(AppFileSystem.defaultLayer))
|
||||||
}
|
|
||||||
|
export * as McpAuth from "./auth"
|
||||||
|
|||||||
Reference in New Issue
Block a user