@openclawcity/become 1.0.24 → 1.0.26

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/dist/cli.js CHANGED
@@ -107,10 +107,30 @@ function patchOpenClaw(config) {
107
107
  `Provider "${providerName}" not found in models.json or openclaw.json. Your model is "${primaryModel}" which needs a "${providerName}" provider.`
108
108
  );
109
109
  }
110
- const originalUrl = provider.baseUrl;
110
+ let originalUrl = provider.baseUrl;
111
111
  if (!originalUrl) {
112
112
  throw new Error(`Provider "${providerName}" has no baseUrl`);
113
113
  }
114
+ if (originalUrl.includes("127.0.0.1") || originalUrl.includes("localhost")) {
115
+ if (existsSync2(BACKUP_PATH)) {
116
+ try {
117
+ const backupRaw = readFileSync2(BACKUP_PATH, "utf-8");
118
+ } catch {
119
+ }
120
+ }
121
+ const savedUrl = readSafe(ORIGINAL_URL_PATH);
122
+ if (savedUrl && !savedUrl.includes("127.0.0.1")) {
123
+ originalUrl = savedUrl;
124
+ console.log(` recovered original URL from state: ${originalUrl}`);
125
+ } else {
126
+ throw new Error(
127
+ `Provider "${providerName}" baseUrl is already pointing to localhost (${originalUrl}).
128
+ This means become was previously connected but not properly restored.
129
+ Fix manually: set the baseUrl back to the real provider URL in:
130
+ ${modelsSource === "models.json" ? getModelsJsonPath(clawConfig) : OPENCLAW_CONFIG}`
131
+ );
132
+ }
133
+ }
114
134
  writeFileSync2(BACKUP_PATH, raw, "utf-8");
115
135
  writeFileSync2(ORIGINAL_URL_PATH, originalUrl, "utf-8");
116
136
  writeFileSync2(PATCHED_PROVIDER_PATH, `${providerName}:${modelsSource}`, "utf-8");
@@ -803,6 +823,14 @@ function createProxyServer(config, analyzer, overrideUpstreamUrl) {
803
823
  const rawBody = await readBody(req);
804
824
  const body = JSON.parse(rawBody);
805
825
  const messages = body.messages;
826
+ if (Array.isArray(messages)) {
827
+ for (const m of messages) {
828
+ if (m.role === "user" || m.role === "system") {
829
+ const preview = typeof m.content === "string" ? m.content.slice(0, 200) : "(non-string)";
830
+ console.log(`[become] msg ${m.role}${m.name ? ` name=${m.name}` : ""}: ${preview.replace(/\n/g, "\\n")}`);
831
+ }
832
+ }
833
+ }
806
834
  if (Array.isArray(messages)) {
807
835
  const skills = getSkills().slice(0, config.max_skills_per_call);
808
836
  if (skills.length > 0) {
@@ -1864,21 +1892,30 @@ async function start() {
1864
1892
  max_skills_per_call: config.max_skills_per_call,
1865
1893
  auto_extract: config.auto_extract
1866
1894
  };
1867
- if (config.state !== "on") {
1868
- try {
1869
- turnOn();
1870
- } catch (e) {
1871
- console.error("Warning: could not auto-connect agent:", e instanceof Error ? e.message : e);
1872
- }
1895
+ try {
1896
+ turnOn();
1897
+ } catch (e) {
1898
+ console.error("Warning: could not connect agent:", e instanceof Error ? e.message : e);
1873
1899
  }
1874
1900
  const originalUrlPath = join7(homedir5(), ".become", "state", "original_base_url.txt");
1875
- let originalUpstreamUrl;
1901
+ let upstreamUrl = config.llm_base_url;
1876
1902
  if (existsSync7(originalUrlPath)) {
1877
1903
  const saved = readFileSync7(originalUrlPath, "utf-8").trim();
1878
- if (saved) originalUpstreamUrl = saved;
1904
+ if (saved) upstreamUrl = saved;
1905
+ }
1906
+ if (upstreamUrl.includes("127.0.0.1") || upstreamUrl.includes("localhost")) {
1907
+ const port = config.proxy_port.toString();
1908
+ if (upstreamUrl.includes(`:${port}`)) {
1909
+ console.error(`
1910
+ FATAL: upstream URL ${upstreamUrl} points to the become proxy itself.`);
1911
+ console.error("This would cause an infinite loop. Aborting.");
1912
+ console.error("Run `become off` to restore your config, then `become start` again.\n");
1913
+ process.exit(1);
1914
+ }
1879
1915
  }
1916
+ console.log(`[become] upstream: ${upstreamUrl}`);
1880
1917
  const analyzer = createAnalyzer(config);
1881
- const proxy = createProxyServer(proxyConfig, analyzer, originalUpstreamUrl);
1918
+ const proxy = createProxyServer(proxyConfig, analyzer, upstreamUrl);
1882
1919
  await proxy.listen();
1883
1920
  const dashboard = createDashboardServer({
1884
1921
  store: proxy.store,