mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-11 19:28:33 +00:00
feat: Add ACP (Agent Client Protocol) support (#2947)
Co-authored-by: opencode-bot <devnull@opencode.local> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
53
packages/opencode/src/acp/server.ts
Normal file
53
packages/opencode/src/acp/server.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { AgentSideConnection, ndJsonStream } from "@zed-industries/agent-client-protocol"
|
||||
import { Log } from "../util/log"
|
||||
import { Instance } from "../project/instance"
|
||||
import { OpenCodeAgent } from "./agent"
|
||||
|
||||
export namespace ACPServer {
|
||||
const log = Log.create({ service: "acp-server" })
|
||||
|
||||
export async function start() {
|
||||
await Instance.provide({
|
||||
directory: process.cwd(),
|
||||
fn: async () => {
|
||||
log.info("starting ACP server", { cwd: process.cwd() })
|
||||
|
||||
const stdout = new WritableStream({
|
||||
write(chunk) {
|
||||
process.stdout.write(chunk)
|
||||
},
|
||||
})
|
||||
|
||||
const stdin = new ReadableStream({
|
||||
start(controller) {
|
||||
process.stdin.on("data", (chunk) => {
|
||||
controller.enqueue(new Uint8Array(chunk))
|
||||
})
|
||||
process.stdin.on("end", () => {
|
||||
controller.close()
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
const stream = ndJsonStream(stdout, stdin)
|
||||
|
||||
new AgentSideConnection((conn) => {
|
||||
return new OpenCodeAgent(conn)
|
||||
}, stream)
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
process.on("SIGTERM", () => {
|
||||
log.info("received SIGTERM")
|
||||
resolve()
|
||||
})
|
||||
process.on("SIGINT", () => {
|
||||
log.info("received SIGINT")
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
|
||||
log.info("ACP server stopped")
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user