mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-03 15:43:45 +00:00
feat: tf code
This commit is contained in:
@@ -255,10 +255,50 @@ export namespace Agent {
|
||||
return state().then((x) => x[agent])
|
||||
}
|
||||
|
||||
async function loadTFCoderAgents(): Promise<Info[]> {
|
||||
const toolsPath = path.join(Global.Path.data, ".tfcode", "tools.json")
|
||||
console.log("[TF Agents] Loading from:", toolsPath)
|
||||
try {
|
||||
const content = await Bun.file(toolsPath).text()
|
||||
const data = JSON.parse(content)
|
||||
console.log("[TF Agents] File loaded, success:", data.success, "tools:", data.tools?.length)
|
||||
if (!data.success || !data.tools) {
|
||||
console.log("[TF Agents] No tools data, returning []")
|
||||
return []
|
||||
}
|
||||
|
||||
const tfAgents = data.tools
|
||||
.filter((t: any) => t.tool_type === "agent_skill")
|
||||
|
||||
console.log("[TF Agents] Found agent_skill items:", tfAgents.length)
|
||||
console.log("[TF Agents] Names:", tfAgents.map((t: any) => t.name))
|
||||
|
||||
return tfAgents.map((t: any): Info => ({
|
||||
name: t.name,
|
||||
description: t.description,
|
||||
mode: "subagent" as const,
|
||||
permission: Permission.fromConfig({ "*": "allow" }),
|
||||
native: false,
|
||||
options: {
|
||||
tf_agent_id: t.id,
|
||||
tf_auth_via: t.auth_via,
|
||||
},
|
||||
}))
|
||||
} catch (e) {
|
||||
console.log("[TF Agents] Error:", e)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export async function list() {
|
||||
const cfg = await Config.get()
|
||||
const localAgents = await state()
|
||||
const tfAgents = await loadTFCoderAgents()
|
||||
|
||||
console.log("[TF Agents] list() - local:", Object.keys(localAgents).length, "tf:", tfAgents.length)
|
||||
|
||||
return pipe(
|
||||
await state(),
|
||||
{ ...localAgents, ...Object.fromEntries(tfAgents.map(a => [a.name, a])) },
|
||||
values(),
|
||||
sortBy(
|
||||
[(x) => (cfg.default_agent ? x.name === cfg.default_agent : x.name === "build"), "desc"],
|
||||
|
||||
@@ -62,6 +62,8 @@ async function runPythonSync(
|
||||
method: string,
|
||||
args: Record<string, unknown> = {},
|
||||
): Promise<unknown> {
|
||||
const credentials = await loadCredentials()
|
||||
|
||||
const pythonCode = `
|
||||
import json
|
||||
import sys
|
||||
@@ -162,6 +164,9 @@ sys.exit(0)
|
||||
env: {
|
||||
...process.env,
|
||||
PYTHONPATH: getPythonSyncPath(),
|
||||
TF_WORKSPACE_ID: credentials?.workspace_id || "",
|
||||
TF_API_KEY: credentials?.api_key || "",
|
||||
TF_REGION: credentials?.region || "au",
|
||||
},
|
||||
})
|
||||
|
||||
@@ -204,6 +209,23 @@ function getToolsFilePath(): string {
|
||||
return path.join(getConfigPath(), TFCODE_TOOLS_FILE)
|
||||
}
|
||||
|
||||
function getCredentialsFilePath(): string {
|
||||
return path.join(getConfigPath(), "credentials.json")
|
||||
}
|
||||
|
||||
async function loadCredentials(): Promise<{ workspace_id: string; api_key: string; region: string } | null> {
|
||||
const credFile = getCredentialsFilePath()
|
||||
if (!(await Filesystem.exists(credFile))) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
const content = await Bun.file(credFile).text()
|
||||
return JSON.parse(content)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function loadCachedTools(): Promise<ToolSyncResult | null> {
|
||||
const toolsFile = getToolsFilePath()
|
||||
if (!(await Filesystem.exists(toolsFile))) {
|
||||
|
||||
@@ -44,7 +44,7 @@ export namespace UI {
|
||||
const result: string[] = []
|
||||
const reset = "\x1b[0m"
|
||||
const left = {
|
||||
fg: Bun.color("gray", "ansi") ?? "",
|
||||
fg: "\x1b[38;2;29;184;198m",
|
||||
shadow: "\x1b[38;5;235m",
|
||||
bg: "\x1b[48;5;235m",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user