openclaw-abacusai-auth 1.2.2 → 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 +68 -5
- 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";
|
|
@@ -421,7 +421,10 @@ function cleanSchema(schema: unknown): unknown {
|
|
|
421
421
|
}
|
|
422
422
|
|
|
423
423
|
/**
|
|
424
|
-
* Strip `strict` field from tools
|
|
424
|
+
* Strip `strict` field from tools, clean schemas, and promote name/parameters
|
|
425
|
+
* to the top level of each tool object for RouteLLM compatibility.
|
|
426
|
+
* RouteLLM expects `name` and `parameters` accessible at the tool level,
|
|
427
|
+
* not only nested under `function`.
|
|
425
428
|
*/
|
|
426
429
|
function normalizeToolsForRouteLLM(tools: unknown[]): unknown[] {
|
|
427
430
|
return tools.map((t) => {
|
|
@@ -441,6 +444,17 @@ function normalizeToolsForRouteLLM(tools: unknown[]): unknown[] {
|
|
|
441
444
|
}
|
|
442
445
|
|
|
443
446
|
copy.function = fn;
|
|
447
|
+
|
|
448
|
+
// Promote name and parameters to top level for RouteLLM
|
|
449
|
+
if (fn.name && !copy.name) {
|
|
450
|
+
copy.name = fn.name;
|
|
451
|
+
}
|
|
452
|
+
if (fn.parameters !== undefined && copy.parameters === undefined) {
|
|
453
|
+
copy.parameters = fn.parameters;
|
|
454
|
+
}
|
|
455
|
+
if (fn.description && !copy.description) {
|
|
456
|
+
copy.description = fn.description;
|
|
457
|
+
}
|
|
444
458
|
}
|
|
445
459
|
|
|
446
460
|
return copy;
|
|
@@ -706,6 +720,48 @@ function buildModelDefinition(modelId: string) {
|
|
|
706
720
|
};
|
|
707
721
|
}
|
|
708
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
|
+
|
|
709
765
|
// ---------------------------------------------------------------------------
|
|
710
766
|
// Plugin
|
|
711
767
|
// ---------------------------------------------------------------------------
|
|
@@ -746,9 +802,16 @@ const abacusaiPlugin = {
|
|
|
746
802
|
// Auto-start proxy if we have a saved API key
|
|
747
803
|
const savedKey = tryRecoverApiKey();
|
|
748
804
|
if (savedKey) {
|
|
749
|
-
startProxy(savedKey)
|
|
750
|
-
|
|
751
|
-
|
|
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
|
+
});
|
|
752
815
|
}
|
|
753
816
|
|
|
754
817
|
pluginApi.registerProvider({
|