From b81785d8e269a893cc14b3cf419354fb5d6d3715 Mon Sep 17 00:00:00 2001 From: Shannon Code Date: Mon, 18 Nov 2024 20:55:49 -0500 Subject: [PATCH 1/4] ignore local lock --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ad4176f7b..bdd4993bc 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ characters/ packages/core/src/providers/cache packages/core/src/providers/cache/* cache/* + +pnpm-lock.yaml From 8afd007c61a4e2849c6bba103a203edd5758ed75 Mon Sep 17 00:00:00 2001 From: Shannon Code Date: Mon, 18 Nov 2024 20:56:39 -0500 Subject: [PATCH 2/4] now with env scoping --- docs/docs/guides/secrets-management.md | 5 ++++- docs/docs/packages/agent.md | 14 ++++++++++++ packages/agent/src/index.ts | 26 ++++++++++++++++----- packages/core/src/settings.ts | 31 ++++++++++++++++++++++++++ pnpm-lock.yaml | 2 +- 5 files changed, 70 insertions(+), 8 deletions(-) diff --git a/docs/docs/guides/secrets-management.md b/docs/docs/guides/secrets-management.md index c35c65345..636f783c0 100644 --- a/docs/docs/guides/secrets-management.md +++ b/docs/docs/guides/secrets-management.md @@ -12,7 +12,8 @@ A comprehensive guide for managing secrets, API keys, and sensitive configuratio Eliza uses a hierarchical environment variable system: -1. Character-specific secrets (highest priority) +1. Character-specific namespaced environment variables (highest priority) +1. Character-specific secrets 2. Environment variables 3. Default values (lowest priority) @@ -89,6 +90,8 @@ Define secrets in character files: } ``` +Alternatively, you can use the `CHARACTER.YOUR_CHARACTER_NAME.SECRET_NAME` format inside your `.env` file. + Access secrets in code: ```typescript diff --git a/docs/docs/packages/agent.md b/docs/docs/packages/agent.md index 87108048b..2f16b8587 100644 --- a/docs/docs/packages/agent.md +++ b/docs/docs/packages/agent.md @@ -159,6 +159,15 @@ export async function initializeClients( ### Token Management +Tokens can be configured in two ways: + +1. Using namespaced environment variables: +```env +CHARACTER.YOUR_CHARACTER_NAME.OPENAI_API_KEY=sk-... +CHARACTER.YOUR_CHARACTER_NAME.ANTHROPIC_API_KEY=sk-... +``` + +2. Using character settings: ```typescript export function getTokenForProvider( provider: ModelProviderName, @@ -179,6 +188,11 @@ export function getTokenForProvider( } ``` +The system will check for tokens in the following order: +1. Character-specific namespaced env variables +2. Character settings from JSON +3. Global environment variables + ### Database Selection ```typescript diff --git a/packages/agent/src/index.ts b/packages/agent/src/index.ts index 725a65cfc..34ac2bc92 100644 --- a/packages/agent/src/index.ts +++ b/packages/agent/src/index.ts @@ -76,8 +76,25 @@ export async function loadCharacters( for (const path of characterPaths) { try { const character = JSON.parse(fs.readFileSync(path, "utf8")); + + const characterId = character.id || character.name; + const characterPrefix = `CHARACTER.${characterId.toUpperCase().replace(/ /g, '_')}.`; + + const characterSettings = Object.entries(process.env) + .filter(([key]) => key.startsWith(characterPrefix)) + .reduce((settings, [key, value]) => { + const settingKey = key.slice(characterPrefix.length); + return { ...settings, [settingKey]: value }; + }, {}); + + if (Object.keys(characterSettings).length > 0) { + character.settings = character.settings || {}; + character.settings.secrets = { + ...characterSettings, + ...character.settings.secrets + }; + } - // is there a "plugins" field? if (character.plugins) { console.log("Plugins are: ", character.plugins); @@ -99,13 +116,10 @@ export async function loadCharacters( } } } - - if (loadedCharacters.length === 0) { + loadedCharacters.length === 0 && console.log("No characters found, using default character"); - loadedCharacters.push(defaultCharacter); - } - return loadedCharacters; + return loadedCharacters.length > 0 ? loadedCharacters : [defaultCharacter]; } export function getTokenForProvider( diff --git a/packages/core/src/settings.ts b/packages/core/src/settings.ts index 9de8564cb..2d51b0c76 100644 --- a/packages/core/src/settings.ts +++ b/packages/core/src/settings.ts @@ -6,6 +6,10 @@ interface Settings { [key: string]: string | undefined; } +interface NamespacedSettings { + [namespace: string]: Settings; +} + let environmentSettings: Settings = {}; /** @@ -81,6 +85,15 @@ export function loadEnvConfig(): Settings { } console.log(`Loaded .env file from: ${envPath}`); + + // Parse namespaced settings + const namespacedSettings = parseNamespacedSettings(process.env as Settings); + + // Attach to process.env for backward compatibility + Object.entries(namespacedSettings).forEach(([namespace, settings]) => { + process.env[`__namespaced_${namespace}`] = JSON.stringify(settings); + }); + return process.env as Settings; } @@ -115,3 +128,21 @@ export function hasEnvVariable(key: string): boolean { // Initialize settings based on environment export const settings = isBrowser() ? environmentSettings : loadEnvConfig(); export default settings; + +// Add this function to parse namespaced settings +function parseNamespacedSettings(env: Settings): NamespacedSettings { + const namespaced: NamespacedSettings = {}; + + for (const [key, value] of Object.entries(env)) { + if (!value) continue; + + const [namespace, ...rest] = key.split('.'); + if (!namespace || rest.length === 0) continue; + + const settingKey = rest.join('.'); + namespaced[namespace] = namespaced[namespace] || {}; + namespaced[namespace][settingKey] = value; + } + + return namespaced; +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a97848a2e..7fd37dabc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22169,7 +22169,7 @@ snapshots: log-symbols@4.1.0: dependencies: - chalk: 4.1.0 + chalk: 4.1.2 is-unicode-supported: 0.1.0 log-symbols@6.0.0: From 93f3a54983c0c65742a486dbbae74197fa7dbfb6 Mon Sep 17 00:00:00 2001 From: Shannon Code Date: Tue, 19 Nov 2024 02:35:39 -0500 Subject: [PATCH 3/4] re number list --- docs/docs/guides/secrets-management.md | 6 +- packages/client-ui/static/index.html | 701 +++++++++++++++++++++++++ scripts/devall.sh | 12 + 3 files changed, 716 insertions(+), 3 deletions(-) create mode 100644 packages/client-ui/static/index.html create mode 100644 scripts/devall.sh diff --git a/docs/docs/guides/secrets-management.md b/docs/docs/guides/secrets-management.md index 636f783c0..9dc86f895 100644 --- a/docs/docs/guides/secrets-management.md +++ b/docs/docs/guides/secrets-management.md @@ -13,9 +13,9 @@ A comprehensive guide for managing secrets, API keys, and sensitive configuratio Eliza uses a hierarchical environment variable system: 1. Character-specific namespaced environment variables (highest priority) -1. Character-specific secrets -2. Environment variables -3. Default values (lowest priority) +2. Character-specific secrets +3. Environment variables +4. Default values (lowest priority) ### Secret Types diff --git a/packages/client-ui/static/index.html b/packages/client-ui/static/index.html new file mode 100644 index 000000000..bbff5d786 --- /dev/null +++ b/packages/client-ui/static/index.html @@ -0,0 +1,701 @@ + + + + Eliza Admin Panel + + + + + +
+ + +
+ +
+
+ + +
+
+ + +
+ +
+
+
+ + +
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/scripts/devall.sh b/scripts/devall.sh new file mode 100644 index 000000000..7fb48f7d1 --- /dev/null +++ b/scripts/devall.sh @@ -0,0 +1,12 @@ +echo "Passing arguments: $* --character=\"characters/fusion.character.json\"" +npx concurrently --raw \ + "pnpm --dir packages/core dev -- $* --character=\"characters/fusion.character.json\"" \ + "pnpm --dir packages/client-telegram dev -- $* --character=\"characters/fusion.character.json\"" \ + "pnpm --dir packages/client-discord dev -- $* --character=\"characters/fusion.character.json\"" \ + "pnpm --dir packages/client-twitter dev -- $* --character=\"characters/fusion.character.json\"" \ + "pnpm --dir packages/client-ui dev -- $* --character=\"characters/fusion.character.json\"" \ + "pnpm --dir packages/plugin-bootstrap dev -- $* --character=\"characters/fusion.character.json\"" \ + "pnpm --dir packages/plugin-node dev -- $* --character=\"characters/fusion.character.json\"" \ + "pnpm --dir packages/adapter-sqlite dev -- $* --character=\"characters/fusion.character.json\"" \ + "pnpm --dir packages/adapter-postgres dev -- $* --character=\"characters/fusion.character.json\"" \ + "node -e \"setTimeout(() => process.exit(0), 5000)\" && pnpm --dir packages/agent dev -- $* --characters=\"characters/fusion.character.json,characters/shannonai.character.json\"" \ No newline at end of file From 40bdb8fabb7ac7582b17b9956cf701156427eba5 Mon Sep 17 00:00:00 2001 From: Shannon Code Date: Tue, 19 Nov 2024 07:35:28 -0500 Subject: [PATCH 4/4] those don't belong here --- packages/client-ui/static/index.html | 701 --------------------------- scripts/devall.sh | 12 - 2 files changed, 713 deletions(-) delete mode 100644 packages/client-ui/static/index.html delete mode 100644 scripts/devall.sh diff --git a/packages/client-ui/static/index.html b/packages/client-ui/static/index.html deleted file mode 100644 index bbff5d786..000000000 --- a/packages/client-ui/static/index.html +++ /dev/null @@ -1,701 +0,0 @@ - - - - Eliza Admin Panel - - - - - -
- - -
- -
-
- - -
-
- - -
- -
-
-
- - -
-
-
-
-
-
- - - - \ No newline at end of file diff --git a/scripts/devall.sh b/scripts/devall.sh deleted file mode 100644 index 7fb48f7d1..000000000 --- a/scripts/devall.sh +++ /dev/null @@ -1,12 +0,0 @@ -echo "Passing arguments: $* --character=\"characters/fusion.character.json\"" -npx concurrently --raw \ - "pnpm --dir packages/core dev -- $* --character=\"characters/fusion.character.json\"" \ - "pnpm --dir packages/client-telegram dev -- $* --character=\"characters/fusion.character.json\"" \ - "pnpm --dir packages/client-discord dev -- $* --character=\"characters/fusion.character.json\"" \ - "pnpm --dir packages/client-twitter dev -- $* --character=\"characters/fusion.character.json\"" \ - "pnpm --dir packages/client-ui dev -- $* --character=\"characters/fusion.character.json\"" \ - "pnpm --dir packages/plugin-bootstrap dev -- $* --character=\"characters/fusion.character.json\"" \ - "pnpm --dir packages/plugin-node dev -- $* --character=\"characters/fusion.character.json\"" \ - "pnpm --dir packages/adapter-sqlite dev -- $* --character=\"characters/fusion.character.json\"" \ - "pnpm --dir packages/adapter-postgres dev -- $* --character=\"characters/fusion.character.json\"" \ - "node -e \"setTimeout(() => process.exit(0), 5000)\" && pnpm --dir packages/agent dev -- $* --characters=\"characters/fusion.character.json,characters/shannonai.character.json\"" \ No newline at end of file