feat: tf code

This commit is contained in:
Gab
2026-03-24 15:40:48 +11:00
parent 1539afc803
commit 1c0c0e6a50
5 changed files with 105 additions and 4 deletions

View File

@@ -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))) {