repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * Automaton Configuration |
| #3 | * |
| #4 | * Loads and saves the automaton's configuration from ~/.automaton/automaton.json |
| #5 | */ |
| #6 | |
| #7 | import fs from "fs"; |
| #8 | import path from "path"; |
| #9 | import type { AutomatonConfig } from "./types.js"; |
| #10 | import type { Address } from "viem"; |
| #11 | import { DEFAULT_CONFIG } from "./types.js"; |
| #12 | import { getAutomatonDir } from "./identity/wallet.js"; |
| #13 | import { loadApiKeyFromConfig } from "./identity/provision.js"; |
| #14 | |
| #15 | const CONFIG_FILENAME = "automaton.json"; |
| #16 | |
| #17 | export function getConfigPath(): string { |
| #18 | return path.join(getAutomatonDir(), CONFIG_FILENAME); |
| #19 | } |
| #20 | |
| #21 | /** |
| #22 | * Load the automaton config from disk. |
| #23 | * Merges with defaults for any missing fields. |
| #24 | */ |
| #25 | export function loadConfig(): AutomatonConfig | null { |
| #26 | const configPath = getConfigPath(); |
| #27 | if (!fs.existsSync(configPath)) { |
| #28 | return null; |
| #29 | } |
| #30 | |
| #31 | try { |
| #32 | const raw = JSON.parse(fs.readFileSync(configPath, "utf-8")); |
| #33 | const apiKey = raw.conwayApiKey || loadApiKeyFromConfig(); |
| #34 | |
| #35 | return { |
| #36 | ...DEFAULT_CONFIG, |
| #37 | ...raw, |
| #38 | conwayApiKey: apiKey, |
| #39 | } as AutomatonConfig; |
| #40 | } catch { |
| #41 | return null; |
| #42 | } |
| #43 | } |
| #44 | |
| #45 | /** |
| #46 | * Save the automaton config to disk. |
| #47 | */ |
| #48 | export function saveConfig(config: AutomatonConfig): void { |
| #49 | const dir = getAutomatonDir(); |
| #50 | if (!fs.existsSync(dir)) { |
| #51 | fs.mkdirSync(dir, { recursive: true, mode: 0o700 }); |
| #52 | } |
| #53 | |
| #54 | const configPath = getConfigPath(); |
| #55 | fs.writeFileSync(configPath, JSON.stringify(config, null, 2), { |
| #56 | mode: 0o600, |
| #57 | }); |
| #58 | } |
| #59 | |
| #60 | /** |
| #61 | * Resolve ~ paths to absolute paths. |
| #62 | */ |
| #63 | export function resolvePath(p: string): string { |
| #64 | if (p.startsWith("~")) { |
| #65 | return path.join(process.env.HOME || "/root", p.slice(1)); |
| #66 | } |
| #67 | return p; |
| #68 | } |
| #69 | |
| #70 | /** |
| #71 | * Create a fresh config from setup wizard inputs. |
| #72 | */ |
| #73 | export function createConfig(params: { |
| #74 | name: string; |
| #75 | genesisPrompt: string; |
| #76 | creatorMessage?: string; |
| #77 | creatorAddress: Address; |
| #78 | registeredWithConway: boolean; |
| #79 | sandboxId: string; |
| #80 | walletAddress: Address; |
| #81 | apiKey: string; |
| #82 | parentAddress?: Address; |
| #83 | }): AutomatonConfig { |
| #84 | return { |
| #85 | name: params.name, |
| #86 | genesisPrompt: params.genesisPrompt, |
| #87 | creatorMessage: params.creatorMessage, |
| #88 | creatorAddress: params.creatorAddress, |
| #89 | registeredWithConway: params.registeredWithConway, |
| #90 | sandboxId: params.sandboxId, |
| #91 | conwayApiUrl: DEFAULT_CONFIG.conwayApiUrl!, |
| #92 | conwayApiKey: params.apiKey, |
| #93 | inferenceModel: DEFAULT_CONFIG.inferenceModel!, |
| #94 | maxTokensPerTurn: DEFAULT_CONFIG.maxTokensPerTurn!, |
| #95 | heartbeatConfigPath: DEFAULT_CONFIG.heartbeatConfigPath!, |
| #96 | dbPath: DEFAULT_CONFIG.dbPath!, |
| #97 | logLevel: DEFAULT_CONFIG.logLevel as AutomatonConfig["logLevel"], |
| #98 | walletAddress: params.walletAddress, |
| #99 | version: DEFAULT_CONFIG.version!, |
| #100 | skillsDir: DEFAULT_CONFIG.skillsDir!, |
| #101 | maxChildren: DEFAULT_CONFIG.maxChildren!, |
| #102 | parentAddress: params.parentAddress, |
| #103 | }; |
| #104 | } |
| #105 |