Files
AgentCompany/electron.vite.config.ts
T
ZacharyZhang-NY a2de132083 Embed the Composio key in the app bundle instead of shipping cred.txt
Root cause of the recurring 401: a revoked key was hardcoded in
startup-recovery.ts and onboarding-service.ts and reseeded into
composio_settings on every launch, and the interim fix shipped cred.txt
as a visible file under resources/.

- electron.vite.config.ts reads the gitignored cred.txt at build time
  and injects the key into the main-process bundle as
  __COMPOSIO_API_KEY__; no credential file is packaged and the key is
  not user-visible or configurable. The renderer bundle never sees it.
- Delete both hardcoded-key seeders; migration 046 purges stored
  api_key and never-read toolkits rows while keeping entity_id and
  auth_config state.
- Stop shipping composio_settings in the renderer snapshot.
2026-07-07 01:40:19 -04:00

70 lines
2.0 KiB
TypeScript

import { existsSync, readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, resolve } from "node:path";
import { defineConfig, externalizeDepsPlugin } from "electron-vite";
import react from "@vitejs/plugin-react";
const __dirname = dirname(fileURLToPath(import.meta.url));
/**
* The Composio integration key is compiled into the main-process bundle so
* no credential file ever ships with the app. It lives in the gitignored
* cred.txt at the repository root (first line "Composio apikey: ak_...");
* a checkout without the file builds an app whose connector features report
* the integration as unconfigured. Rotation = update cred.txt, rebuild.
*/
function composioApiKeyForBuild(): string {
const credPath = resolve(__dirname, "cred.txt");
if (!existsSync(credPath)) return "";
const firstLine = readFileSync(credPath, "utf8").split("\n")[0] ?? "";
return firstLine.split(":").slice(1).join(":").trim();
}
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()],
define: {
__COMPOSIO_API_KEY__: JSON.stringify(composioApiKeyForBuild()),
},
resolve: {
alias: {
"@shared": resolve(__dirname, "src/shared"),
"@main": resolve(__dirname, "src/main"),
},
},
build: {
rollupOptions: {
input: resolve(__dirname, "src/main/index.ts"),
},
},
},
preload: {
plugins: [externalizeDepsPlugin()],
resolve: {
alias: {
"@shared": resolve(__dirname, "src/shared"),
"@preload": resolve(__dirname, "src/preload"),
},
},
build: {
rollupOptions: {
input: resolve(__dirname, "src/preload/index.ts"),
output: {
format: "cjs",
entryFileNames: "index.js",
},
},
},
},
renderer: {
root: resolve(__dirname, "src/renderer"),
resolve: {
alias: {
"@shared": resolve(__dirname, "src/shared"),
"@renderer": resolve(__dirname, "src/renderer"),
},
},
plugins: [react()],
},
});