openclaw-abacusai-auth 1.2.3 → 1.2.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.
- package/index.ts +53 -4
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync, readdirSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
@@ -720,6 +720,48 @@ function buildModelDefinition(modelId: string) {
|
|
|
720
720
|
};
|
|
721
721
|
}
|
|
722
722
|
|
|
723
|
+
// ---------------------------------------------------------------------------
|
|
724
|
+
// Dynamic baseUrl updater — keep config in sync with current proxy port
|
|
725
|
+
// ---------------------------------------------------------------------------
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Update the `models.providers.abacusai.baseUrl` in openclaw.json to match
|
|
729
|
+
* the current proxy port. This is necessary because the proxy uses port 0
|
|
730
|
+
* (OS-assigned random port) and gets a new port every time the gateway starts,
|
|
731
|
+
* but the config still stores the port from when `openclaw models auth login`
|
|
732
|
+
* was first run.
|
|
733
|
+
*/
|
|
734
|
+
function updateBaseUrlInConfig(): void {
|
|
735
|
+
if (!proxyPort) return;
|
|
736
|
+
const newBaseUrl = `http://${PROXY_HOST}:${proxyPort}`;
|
|
737
|
+
try {
|
|
738
|
+
const stateDir =
|
|
739
|
+
process.env.OPENCLAW_STATE_DIR ||
|
|
740
|
+
process.env.CLAWDBOT_STATE_DIR ||
|
|
741
|
+
join(homedir(), ".openclaw");
|
|
742
|
+
const configPath = join(stateDir, "openclaw.json");
|
|
743
|
+
if (!existsSync(configPath)) return;
|
|
744
|
+
|
|
745
|
+
const raw = readFileSync(configPath, "utf-8");
|
|
746
|
+
const config = JSON.parse(raw);
|
|
747
|
+
const currentUrl = config?.models?.providers?.abacusai?.baseUrl;
|
|
748
|
+
|
|
749
|
+
if (currentUrl === newBaseUrl) {
|
|
750
|
+
// Already up to date
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// Update the baseUrl
|
|
755
|
+
if (config.models?.providers?.abacusai) {
|
|
756
|
+
config.models.providers.abacusai.baseUrl = newBaseUrl;
|
|
757
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
758
|
+
console.log(`[abacusai] Updated config baseUrl: ${currentUrl} → ${newBaseUrl}`);
|
|
759
|
+
}
|
|
760
|
+
} catch (err) {
|
|
761
|
+
console.error("[abacusai] Failed to update baseUrl in config:", err);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
723
765
|
// ---------------------------------------------------------------------------
|
|
724
766
|
// Plugin
|
|
725
767
|
// ---------------------------------------------------------------------------
|
|
@@ -760,9 +802,16 @@ const abacusaiPlugin = {
|
|
|
760
802
|
// Auto-start proxy if we have a saved API key
|
|
761
803
|
const savedKey = tryRecoverApiKey();
|
|
762
804
|
if (savedKey) {
|
|
763
|
-
startProxy(savedKey)
|
|
764
|
-
|
|
765
|
-
|
|
805
|
+
startProxy(savedKey)
|
|
806
|
+
.then(() => {
|
|
807
|
+
// Update baseUrl in config to match the new proxy port
|
|
808
|
+
// (The proxy gets a new random port each time the gateway starts,
|
|
809
|
+
// but the config still has the port from when auth was first run)
|
|
810
|
+
updateBaseUrlInConfig();
|
|
811
|
+
})
|
|
812
|
+
.catch((err) => {
|
|
813
|
+
console.error("[abacusai] Failed to auto-start proxy:", err);
|
|
814
|
+
});
|
|
766
815
|
}
|
|
767
816
|
|
|
768
817
|
pluginApi.registerProvider({
|