1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
import { Agent } from "@/agent/agent"
import { Command } from "@/command"
import { Format } from "@/format"
import { LSP } from "@/lsp/lsp"
import { Vcs } from "@/project/vcs"
import { Skill } from "@/skill"
import { Schema } from "effect"
import { HttpApi, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
import { Authorization } from "../middleware/authorization"
import { InstanceContextMiddleware } from "../middleware/instance-context"
import { WorkspaceRoutingMiddleware } from "../middleware/workspace-routing"
import { described } from "./metadata"
const PathInfo = Schema.Struct({
home: Schema.String,
state: Schema.String,
config: Schema.String,
worktree: Schema.String,
directory: Schema.String,
}).annotate({ identifier: "Path" })
export const VcsDiffQuery = Schema.Struct({
mode: Vcs.Mode,
})
export const InstancePaths = {
dispose: "/instance/dispose",
path: "/path",
vcs: "/vcs",
vcsDiff: "/vcs/diff",
command: "/command",
agent: "/agent",
skill: "/skill",
lsp: "/lsp",
formatter: "/formatter",
} as const
export const InstanceApi = HttpApi.make("instance")
.add(
HttpApiGroup.make("instance")
.add(
HttpApiEndpoint.post("dispose", InstancePaths.dispose, {
success: described(Schema.Boolean, "Instance disposed"),
}).annotateMerge(
OpenApi.annotations({
identifier: "instance.dispose",
summary: "Dispose instance",
description: "Clean up and dispose the current OpenCode instance, releasing all resources.",
}),
),
HttpApiEndpoint.get("path", InstancePaths.path, {
success: PathInfo,
}).annotateMerge(
OpenApi.annotations({
identifier: "path.get",
summary: "Get paths",
description:
"Retrieve the current working directory and related path information for the OpenCode instance.",
}),
),
HttpApiEndpoint.get("vcs", InstancePaths.vcs, {
success: described(Vcs.Info, "VCS info"),
}).annotateMerge(
OpenApi.annotations({
identifier: "vcs.get",
summary: "Get VCS info",
description:
"Retrieve version control system (VCS) information for the current project, such as git branch.",
}),
),
HttpApiEndpoint.get("vcsDiff", InstancePaths.vcsDiff, {
query: VcsDiffQuery,
success: described(Schema.Array(Vcs.FileDiff), "VCS diff"),
}).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.",
}),
),
HttpApiEndpoint.get("command", InstancePaths.command, {
success: described(Schema.Array(Command.Info), "List of commands"),
}).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, {
success: described(Schema.Array(Agent.Info), "List of agents"),
}).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, {
success: described(Schema.Array(Skill.Info), "List of skills"),
}).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, {
success: described(Schema.Array(LSP.Status), "LSP server status"),
}).annotateMerge(
OpenApi.annotations({
identifier: "lsp.status",
summary: "Get LSP status",
description: "Get LSP server status",
}),
),
HttpApiEndpoint.get("formatter", InstancePaths.formatter, {
success: described(Schema.Array(Format.Status), "Formatter status"),
}).annotateMerge(
OpenApi.annotations({
identifier: "formatter.status",
summary: "Get formatter status",
description: "Get formatter status",
}),
),
)
.annotateMerge(
OpenApi.annotations({
title: "instance",
description: "Experimental HttpApi instance read routes.",
}),
)
.middleware(InstanceContextMiddleware)
.middleware(WorkspaceRoutingMiddleware)
.middleware(Authorization),
)
.annotateMerge(
OpenApi.annotations({
title: "opencode experimental HttpApi",
version: "0.0.1",
description: "Experimental HttpApi surface for selected instance routes.",
}),
)
|