@agether/agether 2.6.2 → 2.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +9 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agether/agether",
3
- "version": "2.6.2",
3
+ "version": "2.6.4",
4
4
  "description": "OpenClaw plugin for Agether — onchain credit for AI agents on Ethereum & Base",
5
5
  "main": "src/index.ts",
6
6
  "openclaw": {
package/src/index.ts CHANGED
@@ -158,13 +158,15 @@ function resolvePrivateKey(): string {
158
158
 
159
159
  function getConfig(api: any): PluginConfig {
160
160
  const cfg = api.config?.plugins?.entries?.["agether"]?.config ?? {};
161
- const rawChain = cfg.chain;
161
+ // chainOverride (set by agether_set_chain at runtime) takes priority over
162
+ // api.config which is a stale in-memory snapshot that never refreshes.
163
+ const rawChain = chainOverride ?? cfg.chain;
162
164
  const chainConfigured = rawChain !== undefined && rawChain !== null && rawChain !== "";
163
165
  const chainId = (rawChain as ChainId) || ChainId.Ethereum;
164
166
  activeChainId = chainId; // Update module-level for txLink
165
167
  return {
166
168
  privateKey: resolvePrivateKey(),
167
- agentId: cfg.agentId,
169
+ agentId: cachedAgentIds[chainId] || cfg.agentId,
168
170
  rpcUrl: resolveRpcUrl(chainId),
169
171
  chainId,
170
172
  chainConfigured,
@@ -172,8 +174,9 @@ function getConfig(api: any): PluginConfig {
172
174
  }
173
175
 
174
176
  // Module-level cache
175
- let cachedAgentId: string | undefined;
177
+ const cachedAgentIds: Record<number, string> = {}; // chainId → agentId (chain-specific!)
176
178
  let activeChainId: ChainId = ChainId.Ethereum;
179
+ let chainOverride: ChainId | undefined; // set by agether_set_chain, survives stale api.config
177
180
 
178
181
  /**
179
182
  * Hard guardrail: refuse to proceed if chain was never explicitly configured.
@@ -190,7 +193,7 @@ function requireChain(cfg: PluginConfig): void {
190
193
  }
191
194
 
192
195
  function createClient(cfg: PluginConfig): MorphoClient {
193
- const agentId = cachedAgentId || cfg.agentId;
196
+ const agentId = cachedAgentIds[cfg.chainId] || cfg.agentId;
194
197
  return new MorphoClient({
195
198
  privateKey: cfg.privateKey,
196
199
  rpcUrl: cfg.rpcUrl,
@@ -201,7 +204,7 @@ function createClient(cfg: PluginConfig): MorphoClient {
201
204
 
202
205
  /** Persist agentId to openclaw.json so it survives restarts. */
203
206
  function persistAgentId(agentId: string): string {
204
- cachedAgentId = agentId;
207
+ cachedAgentIds[activeChainId] = agentId;
205
208
  try {
206
209
  const home = process.env.HOME || process.env.USERPROFILE || "/root";
207
210
  const cfgPath = path.join(home, ".openclaw", "openclaw.json");
@@ -225,6 +228,7 @@ function persistAgentId(agentId: string): string {
225
228
  /** Persist chain to openclaw.json so it survives restarts. */
226
229
  function persistChainId(chainId: ChainId): string {
227
230
  activeChainId = chainId;
231
+ chainOverride = chainId; // In-memory override so getConfig() picks it up immediately
228
232
  try {
229
233
  const home = process.env.HOME || process.env.USERPROFILE || "/root";
230
234
  const cfgPath = path.join(home, ".openclaw", "openclaw.json");