mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-01 14:52:25 +00:00
mcp support
This commit is contained in:
@@ -1,43 +1,23 @@
|
||||
import path from "path"
|
||||
import { Log } from "../util/log"
|
||||
import { z } from "zod"
|
||||
import { App } from "../app/app"
|
||||
import { Provider } from "../provider/provider"
|
||||
import { Filesystem } from "../util/filesystem"
|
||||
|
||||
export namespace Config {
|
||||
const log = Log.create({ service: "config" })
|
||||
|
||||
export const state = App.state("config", async (app) => {
|
||||
const result = await load(app.path.root)
|
||||
return result
|
||||
})
|
||||
|
||||
export const Info = z
|
||||
.object({
|
||||
provider: z.lazy(() => Provider.Info.array().optional()),
|
||||
tool: z
|
||||
.object({
|
||||
provider: z.record(z.string(), z.string().array()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.strict()
|
||||
|
||||
export type Info = z.output<typeof Info>
|
||||
|
||||
export function get() {
|
||||
return state()
|
||||
}
|
||||
|
||||
async function load(directory: string) {
|
||||
let result: Info = {}
|
||||
for (const file of ["opencode.jsonc", "opencode.json"]) {
|
||||
const resolved = path.join(directory, file)
|
||||
log.info("searching", { path: resolved })
|
||||
const resolved = await Filesystem.findUp(
|
||||
file,
|
||||
app.path.cwd,
|
||||
app.path.root,
|
||||
)
|
||||
if (!resolved) continue
|
||||
try {
|
||||
result = await import(path.join(directory, file)).then((mod) =>
|
||||
Info.parse(mod.default),
|
||||
)
|
||||
result = await import(resolved).then((mod) => Info.parse(mod.default))
|
||||
log.info("found", { path: resolved })
|
||||
break
|
||||
} catch (e) {
|
||||
@@ -52,5 +32,37 @@ export namespace Config {
|
||||
}
|
||||
log.info("loaded", result)
|
||||
return result
|
||||
})
|
||||
|
||||
export const McpLocal = z.object({
|
||||
type: z.literal("local"),
|
||||
command: z.string().array(),
|
||||
environment: z.record(z.string(), z.string()).optional(),
|
||||
})
|
||||
|
||||
export const McpRemote = z.object({
|
||||
type: z.literal("remote"),
|
||||
url: z.string(),
|
||||
})
|
||||
|
||||
export const Mcp = z.discriminatedUnion("type", [McpLocal, McpRemote])
|
||||
export type Mcp = z.infer<typeof Mcp>
|
||||
|
||||
export const Info = z
|
||||
.object({
|
||||
provider: z.lazy(() => Provider.Info.array().optional()),
|
||||
tool: z
|
||||
.object({
|
||||
provider: z.record(z.string(), z.string().array()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
mcp: z.record(z.string(), Mcp).optional(),
|
||||
})
|
||||
.strict()
|
||||
|
||||
export type Info = z.output<typeof Info>
|
||||
|
||||
export function get() {
|
||||
return state()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user