refactor(core): simplify integration credentials (#31968)

This commit is contained in:
Dax 2026-06-12 02:15:25 -04:00 committed by GitHub
commit 30aec297d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
112 changed files with 2467 additions and 47728 deletions

View file

@ -0,0 +1,30 @@
import { Credential } from "@opencode-ai/core/credential"
import { Schema } from "effect"
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi"
export const CredentialGroup = HttpApiGroup.make("server.credential")
.add(
HttpApiEndpoint.patch("credential.update", "/api/credential/:credentialID", {
params: { credentialID: Credential.ID },
payload: Schema.Struct({ label: Schema.String }),
success: HttpApiSchema.NoContent,
}).annotateMerge(
OpenApi.annotations({
identifier: "v2.credential.update",
summary: "Update credential",
description: "Update a stored credential label.",
}),
),
)
.add(
HttpApiEndpoint.delete("credential.remove", "/api/credential/:credentialID", {
params: { credentialID: Credential.ID },
success: HttpApiSchema.NoContent,
}).annotateMerge(
OpenApi.annotations({
identifier: "v2.credential.remove",
summary: "Remove credential",
description: "Remove a stored integration credential.",
}),
),
)

View file

@ -1,4 +1,4 @@
import { Connector } from "@opencode-ai/core/connector"
import { Integration } from "@opencode-ai/core/integration"
import { Location } from "@opencode-ai/core/location"
import { Schema } from "effect"
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi"
@ -7,44 +7,42 @@ import { LocationMiddleware, LocationQuery, locationQueryOpenApi } from "./locat
const Inputs = Schema.Record(Schema.String, Schema.String)
export const ConnectorGroup = HttpApiGroup.make("server.connector")
export const IntegrationGroup = HttpApiGroup.make("server.integration")
.add(
HttpApiEndpoint.get("connector.list", "/api/connector", {
HttpApiEndpoint.get("integration.list", "/api/integration", {
query: LocationQuery,
success: Location.response(Schema.Array(Connector.Info)),
success: Location.response(Schema.Array(Integration.Info)),
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.connector.list",
summary: "List connectors",
description: "Retrieve available connectors and their authentication methods.",
identifier: "v2.integration.list",
summary: "List integrations",
description: "Retrieve available integrations and their authentication methods.",
}),
),
)
.add(
HttpApiEndpoint.get("connector.get", "/api/connector/:connectorID", {
params: { connectorID: Connector.ID },
HttpApiEndpoint.get("integration.get", "/api/integration/:integrationID", {
params: { integrationID: Integration.ID },
query: LocationQuery,
success: Location.response(Schema.UndefinedOr(Connector.Info)),
success: Location.response(Schema.UndefinedOr(Integration.Info)),
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.connector.get",
summary: "Get connector",
description: "Retrieve one connector and its authentication methods.",
identifier: "v2.integration.get",
summary: "Get integration",
description: "Retrieve one integration and its authentication methods.",
}),
),
)
.add(
HttpApiEndpoint.post("connector.connect.key", "/api/connector/:connectorID/connect/key", {
params: { connectorID: Connector.ID },
HttpApiEndpoint.post("integration.connect.key", "/api/integration/:integrationID/connect/key", {
params: { integrationID: Integration.ID },
query: LocationQuery,
payload: Schema.Struct({
methodID: Connector.MethodID,
key: Schema.String,
inputs: Inputs,
label: Schema.optional(Schema.String),
}),
success: HttpApiSchema.NoContent,
@ -53,51 +51,51 @@ export const ConnectorGroup = HttpApiGroup.make("server.connector")
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.connector.connect.key",
identifier: "v2.integration.connect.key",
summary: "Connect with key",
description: "Run a key authentication method and store the resulting credential.",
}),
),
)
.add(
HttpApiEndpoint.post("connector.connect.oauth.begin", "/api/connector/:connectorID/connect/oauth", {
params: { connectorID: Connector.ID },
HttpApiEndpoint.post("integration.connect.oauth", "/api/integration/:integrationID/connect/oauth", {
params: { integrationID: Integration.ID },
query: LocationQuery,
payload: Schema.Struct({
methodID: Connector.MethodID,
methodID: Integration.MethodID,
inputs: Inputs,
label: Schema.optional(Schema.String),
}),
success: Location.response(Connector.Attempt),
success: Location.response(Integration.Attempt),
error: InvalidRequestError,
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.connector.connect.oauth.begin",
identifier: "v2.integration.connect.oauth",
summary: "Begin OAuth connection",
description: "Start an OAuth attempt and return the authorization details.",
}),
),
)
.add(
HttpApiEndpoint.get("connector.connect.oauth.status", "/api/connector/oauth/:attemptID", {
params: { attemptID: Connector.AttemptID },
HttpApiEndpoint.get("integration.attempt.status", "/api/integration/attempt/:attemptID", {
params: { attemptID: Integration.AttemptID },
query: LocationQuery,
success: Location.response(Connector.AttemptStatus),
success: Location.response(Integration.AttemptStatus),
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.connector.connect.oauth.status",
identifier: "v2.integration.attempt.status",
summary: "Get OAuth attempt status",
description: "Poll the current status of an OAuth attempt.",
}),
),
)
.add(
HttpApiEndpoint.post("connector.connect.oauth.complete", "/api/connector/oauth/:attemptID/complete", {
params: { attemptID: Connector.AttemptID },
HttpApiEndpoint.post("integration.attempt.complete", "/api/integration/attempt/:attemptID/complete", {
params: { attemptID: Integration.AttemptID },
query: LocationQuery,
payload: Schema.Struct({ code: Schema.optional(Schema.String) }),
success: HttpApiSchema.NoContent,
@ -106,28 +104,28 @@ export const ConnectorGroup = HttpApiGroup.make("server.connector")
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.connector.connect.oauth.complete",
identifier: "v2.integration.attempt.complete",
summary: "Complete OAuth connection",
description: "Complete a code-based OAuth attempt and store the resulting credential.",
}),
),
)
.add(
HttpApiEndpoint.delete("connector.connect.oauth.cancel", "/api/connector/oauth/:attemptID", {
params: { attemptID: Connector.AttemptID },
HttpApiEndpoint.delete("integration.attempt.cancel", "/api/integration/attempt/:attemptID", {
params: { attemptID: Integration.AttemptID },
query: LocationQuery,
success: HttpApiSchema.NoContent,
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.connector.connect.oauth.cancel",
identifier: "v2.integration.attempt.cancel",
summary: "Cancel OAuth connection",
description: "Cancel an OAuth attempt and release its resources.",
}),
),
)
.annotateMerge(
OpenApi.annotations({ title: "connectors", description: "Connector discovery and authentication routes." }),
OpenApi.annotations({ title: "integrations", description: "Integration discovery and authentication routes." }),
)
.middleware(LocationMiddleware)