91 lines
3.3 KiB
TypeScript
91 lines
3.3 KiB
TypeScript
import type {
|
|
ConnectionInfo,
|
|
CredentialOAuth,
|
|
CredentialValue,
|
|
IntegrationEnvMethod,
|
|
IntegrationInputs,
|
|
IntegrationKeyMethod,
|
|
IntegrationMethod,
|
|
IntegrationOAuthMethod,
|
|
IntegrationRef,
|
|
} from "@opencode-ai/sdk/v2/types"
|
|
import type { IntegrationApi } from "@opencode-ai/client/effect/api"
|
|
import type { WebSearch } from "@opencode-ai/schema/websearch"
|
|
import type { Effect, Scope } from "effect"
|
|
import type { Registration, Transform } from "./registration.js"
|
|
|
|
export type IntegrationOAuthAuthorization = {
|
|
readonly url: string
|
|
readonly instructions: string
|
|
} & (
|
|
| {
|
|
readonly mode: "auto"
|
|
readonly callback: Effect.Effect<CredentialOAuth, unknown>
|
|
}
|
|
| {
|
|
readonly mode: "code"
|
|
readonly callback: (code: string) => Effect.Effect<CredentialOAuth, unknown>
|
|
}
|
|
)
|
|
export type IntegrationOAuthMethodRegistration = {
|
|
readonly integrationID: string
|
|
readonly method: IntegrationOAuthMethod
|
|
readonly authorize: (inputs: IntegrationInputs) => Effect.Effect<IntegrationOAuthAuthorization, unknown, Scope.Scope>
|
|
readonly refresh?: (credential: CredentialOAuth) => Effect.Effect<CredentialOAuth, unknown>
|
|
readonly label?: (credential: CredentialOAuth) => string | undefined
|
|
}
|
|
export type IntegrationMethodRegistration =
|
|
| IntegrationOAuthMethodRegistration
|
|
| {
|
|
readonly integrationID: string
|
|
readonly method: IntegrationKeyMethod
|
|
}
|
|
| {
|
|
readonly integrationID: string
|
|
readonly method: IntegrationEnvMethod
|
|
}
|
|
|
|
export type IntegrationOAuthMethodDefinition = IntegrationOAuthMethod & {
|
|
readonly authorize: (inputs: IntegrationInputs) => Effect.Effect<IntegrationOAuthAuthorization, unknown, Scope.Scope>
|
|
readonly refresh?: (credential: CredentialOAuth) => Effect.Effect<CredentialOAuth, unknown>
|
|
readonly credentialLabel?: (credential: CredentialOAuth) => string | undefined
|
|
}
|
|
|
|
export type IntegrationMethodDefinition = IntegrationOAuthMethodDefinition | IntegrationKeyMethod | IntegrationEnvMethod
|
|
|
|
export interface IntegrationWebSearchDefinition {
|
|
readonly connection: "optional" | "required"
|
|
readonly execute: (
|
|
input: WebSearch.Input,
|
|
context: { readonly credential?: CredentialValue; readonly sessionID?: string },
|
|
) => Effect.Effect<WebSearch.ProviderOutput, unknown>
|
|
}
|
|
|
|
export interface IntegrationDefinition {
|
|
readonly id: string
|
|
readonly name: string
|
|
readonly methods?: readonly IntegrationMethodDefinition[]
|
|
readonly websearch?: IntegrationWebSearchDefinition
|
|
}
|
|
|
|
export interface IntegrationDraft {
|
|
list(): readonly IntegrationRef[]
|
|
get(id: string): IntegrationRef | undefined
|
|
update(id: string, update: (integration: IntegrationRef) => void): void
|
|
remove(id: string): void
|
|
readonly method: {
|
|
list(integrationID: string): readonly IntegrationMethod[]
|
|
update(input: IntegrationMethodRegistration): void
|
|
remove(integrationID: string, method: IntegrationMethod): void
|
|
}
|
|
}
|
|
|
|
export interface IntegrationDomain extends IntegrationApi<unknown> {
|
|
readonly register: (definition: IntegrationDefinition) => Effect.Effect<Registration, never, Scope.Scope>
|
|
readonly transform: Transform<IntegrationDraft>
|
|
readonly reload: () => Effect.Effect<void>
|
|
readonly connection: {
|
|
readonly active: (integrationID: string) => Effect.Effect<ConnectionInfo | undefined>
|
|
readonly resolve: (connection: ConnectionInfo) => Effect.Effect<CredentialValue | undefined, unknown>
|
|
}
|
|
}
|