2026-04-25 18:00:30 +00:00
|
|
|
import { Agent } from "@/agent/agent"
|
|
|
|
|
import { Command } from "@/command"
|
|
|
|
|
import { Format } from "@/format"
|
2026-04-27 18:33:33 +00:00
|
|
|
import { LSP } from "@/lsp/lsp"
|
|
|
|
|
import { Vcs } from "@/project/vcs"
|
2026-04-25 18:00:30 +00:00
|
|
|
import { Skill } from "@/skill"
|
2026-04-29 13:34:50 +00:00
|
|
|
import { Schema } from "effect"
|
|
|
|
|
import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
|
2026-04-29 20:50:54 +00:00
|
|
|
import { Authorization } from "../middleware/authorization"
|
|
|
|
|
import { InstanceContextMiddleware } from "../middleware/instance-context"
|
|
|
|
|
import { WorkspaceRoutingMiddleware } from "../middleware/workspace-routing"
|
2026-04-29 13:34:50 +00:00
|
|
|
import { described } from "./metadata"
|
2026-04-25 14:42:31 +00:00
|
|
|
|
|
|
|
|
const PathInfo = Schema.Struct({
|
|
|
|
|
home: Schema.String,
|
|
|
|
|
state: Schema.String,
|
|
|
|
|
config: Schema.String,
|
|
|
|
|
worktree: Schema.String,
|
|
|
|
|
directory: Schema.String,
|
|
|
|
|
}).annotate({ identifier: "Path" })
|
|
|
|
|
|
2026-04-29 13:34:50 +00:00
|
|
|
export const VcsDiffQuery = Schema.Struct({
|
2026-04-25 14:42:31 +00:00
|
|
|
mode: Vcs.Mode,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const InstancePaths = {
|
2026-04-25 19:24:07 +00:00
|
|
|
dispose: "/instance/dispose",
|
2026-04-25 14:42:31 +00:00
|
|
|
path: "/path",
|
|
|
|
|
vcs: "/vcs",
|
|
|
|
|
vcsDiff: "/vcs/diff",
|
2026-04-25 18:00:30 +00:00
|
|
|
command: "/command",
|
|
|
|
|
agent: "/agent",
|
|
|
|
|
skill: "/skill",
|
|
|
|
|
lsp: "/lsp",
|
|
|
|
|
formatter: "/formatter",
|
2026-04-25 14:42:31 +00:00
|
|
|
} as const
|
|
|
|
|
|
|
|
|
|
export const InstanceApi = HttpApi.make("instance")
|
|
|
|
|
.add(
|
|
|
|
|
HttpApiGroup.make("instance")
|
|
|
|
|
.add(
|
2026-04-25 19:24:07 +00:00
|
|
|
HttpApiEndpoint.post("dispose", InstancePaths.dispose, {
|
2026-04-29 13:34:50 +00:00
|
|
|
success: described(Schema.Boolean, "Instance disposed"),
|
2026-04-25 19:24:07 +00:00
|
|
|
}).annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
identifier: "instance.dispose",
|
|
|
|
|
summary: "Dispose instance",
|
|
|
|
|
description: "Clean up and dispose the current OpenCode instance, releasing all resources.",
|
|
|
|
|
}),
|
|
|
|
|
),
|
2026-04-25 14:42:31 +00:00
|
|
|
HttpApiEndpoint.get("path", InstancePaths.path, {
|
|
|
|
|
success: PathInfo,
|
|
|
|
|
}).annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
identifier: "path.get",
|
|
|
|
|
summary: "Get paths",
|
2026-04-25 14:43:27 +00:00
|
|
|
description:
|
|
|
|
|
"Retrieve the current working directory and related path information for the OpenCode instance.",
|
2026-04-25 14:42:31 +00:00
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
HttpApiEndpoint.get("vcs", InstancePaths.vcs, {
|
2026-04-29 13:34:50 +00:00
|
|
|
success: described(Vcs.Info, "VCS info"),
|
2026-04-25 14:42:31 +00:00
|
|
|
}).annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
identifier: "vcs.get",
|
|
|
|
|
summary: "Get VCS info",
|
2026-04-25 14:43:27 +00:00
|
|
|
description:
|
|
|
|
|
"Retrieve version control system (VCS) information for the current project, such as git branch.",
|
2026-04-25 14:42:31 +00:00
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
HttpApiEndpoint.get("vcsDiff", InstancePaths.vcsDiff, {
|
|
|
|
|
query: VcsDiffQuery,
|
2026-04-29 13:34:50 +00:00
|
|
|
success: described(Schema.Array(Vcs.FileDiff), "VCS diff"),
|
2026-04-25 14:42:31 +00:00
|
|
|
}).annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
identifier: "vcs.diff",
|
|
|
|
|
summary: "Get VCS diff",
|
|
|
|
|
description: "Retrieve the current git diff for the working tree or against the default branch.",
|
|
|
|
|
}),
|
|
|
|
|
),
|
2026-04-25 18:00:30 +00:00
|
|
|
HttpApiEndpoint.get("command", InstancePaths.command, {
|
2026-04-29 13:34:50 +00:00
|
|
|
success: described(Schema.Array(Command.Info), "List of commands"),
|
2026-04-25 18:00:30 +00:00
|
|
|
}).annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
identifier: "command.list",
|
|
|
|
|
summary: "List commands",
|
|
|
|
|
description: "Get a list of all available commands in the OpenCode system.",
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
HttpApiEndpoint.get("agent", InstancePaths.agent, {
|
2026-04-29 13:34:50 +00:00
|
|
|
success: described(Schema.Array(Agent.Info), "List of agents"),
|
2026-04-25 18:00:30 +00:00
|
|
|
}).annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
identifier: "app.agents",
|
|
|
|
|
summary: "List agents",
|
|
|
|
|
description: "Get a list of all available AI agents in the OpenCode system.",
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
HttpApiEndpoint.get("skill", InstancePaths.skill, {
|
2026-04-29 13:34:50 +00:00
|
|
|
success: described(Schema.Array(Skill.Info), "List of skills"),
|
2026-04-25 18:00:30 +00:00
|
|
|
}).annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
identifier: "app.skills",
|
|
|
|
|
summary: "List skills",
|
|
|
|
|
description: "Get a list of all available skills in the OpenCode system.",
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
HttpApiEndpoint.get("lsp", InstancePaths.lsp, {
|
2026-04-29 13:34:50 +00:00
|
|
|
success: described(Schema.Array(LSP.Status), "LSP server status"),
|
2026-04-25 18:00:30 +00:00
|
|
|
}).annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
identifier: "lsp.status",
|
|
|
|
|
summary: "Get LSP status",
|
|
|
|
|
description: "Get LSP server status",
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
HttpApiEndpoint.get("formatter", InstancePaths.formatter, {
|
2026-04-29 13:34:50 +00:00
|
|
|
success: described(Schema.Array(Format.Status), "Formatter status"),
|
2026-04-25 18:00:30 +00:00
|
|
|
}).annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
identifier: "formatter.status",
|
|
|
|
|
summary: "Get formatter status",
|
|
|
|
|
description: "Get formatter status",
|
|
|
|
|
}),
|
|
|
|
|
),
|
2026-04-25 14:42:31 +00:00
|
|
|
)
|
|
|
|
|
.annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
title: "instance",
|
|
|
|
|
description: "Experimental HttpApi instance read routes.",
|
|
|
|
|
}),
|
|
|
|
|
)
|
2026-04-29 13:34:50 +00:00
|
|
|
.middleware(InstanceContextMiddleware)
|
2026-04-29 20:50:54 +00:00
|
|
|
.middleware(WorkspaceRoutingMiddleware)
|
2026-04-25 14:42:31 +00:00
|
|
|
.middleware(Authorization),
|
|
|
|
|
)
|
|
|
|
|
.annotateMerge(
|
|
|
|
|
OpenApi.annotations({
|
|
|
|
|
title: "opencode experimental HttpApi",
|
|
|
|
|
version: "0.0.1",
|
|
|
|
|
description: "Experimental HttpApi surface for selected instance routes.",
|
|
|
|
|
}),
|
|
|
|
|
)
|