mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-09 18:29:39 +00:00
feat: tf code
This commit is contained in:
@@ -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))) {
|
||||
|
||||
Reference in New Issue
Block a user