mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-11-16 09:21:50 +00:00
fix(dsh): gate the LLM test on every unsaved probe setting
- compare the model, the base URL and a typed key against the saved .env, so the test never runs against a configuration the user did not put on disk - resolve an empty backend to the default on both sides, so picking the default in the form is not treated as a change - broaden the probe guard against a rewritten base URL
This commit is contained in:
parent
76d27bdea5
commit
c499cc0eae
8 changed files with 139 additions and 17 deletions
|
|
@ -114,8 +114,8 @@ DSH settings.
|
|||
reported as broken. The base URL is used as the provider's own SDK builds it, so a base that already carries the
|
||||
version suffix fails in the probe exactly as it fails in the service.
|
||||
- ReMe reaches xAI through its gRPC SDK, so the xAI probe is a REST-level approximation of that channel.
|
||||
- The probe reads the `.env` on disk, so a backend that is only picked in the form is not tested before the file is
|
||||
saved; the button says so while it waits.
|
||||
- The probe reads the `.env` on disk, so a configuration that is only picked in the form is not tested before the
|
||||
file is saved; the button says so while it waits.
|
||||
- Drafts are bound to the workspace they were typed in: switching the workspace drops them, so a key typed for
|
||||
one workspace cannot be saved into another.
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ ReMe 在服务启动时读取 workspace 目录下的 `.env`;标签页从不把
|
|||
配置也不会被报成故障。Base URL 的拼接方式与服务商 SDK 完全一致,因此已经带版本后缀的地址在探测与服务中都会
|
||||
同样失败。
|
||||
- ReMe 通过 gRPC SDK 连接 xAI,因此 xAI 的探测只是该通道在 REST 层面的近似。
|
||||
- 探测读取的是磁盘上的 `.env`,所以只在表单里切换后端而未保存时不会发起测试;等待期间按钮会给出提示。
|
||||
- 探测读取的是磁盘上的 `.env`,所以只在表单里改过配置而未保存时不会发起测试;等待期间按钮会给出提示。
|
||||
- 草稿与输入它的 workspace 绑定:切换 workspace 会丢弃草稿,因此为某个 workspace 输入的密钥不会被保存到另一个。
|
||||
|
||||
## 连接测试
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ export const envEn = {
|
|||
testLlmButton: "Test LLM connection",
|
||||
testingLlm: "Testing…",
|
||||
testLlmSaveFirst:
|
||||
"Save the .env first: the test uses the backend that is saved on disk.",
|
||||
"Save the .env first: the test uses the configuration that is saved on disk.",
|
||||
llmOk: "LLM reachable ({ms} ms)",
|
||||
llmFailed: "LLM test failed",
|
||||
serviceHint:
|
||||
|
|
@ -293,7 +293,7 @@ export const envZh: typeof envEn = {
|
|||
saveEnvFailed: "保存失败",
|
||||
testLlmButton: "测试 LLM 连接",
|
||||
testingLlm: "正在测试…",
|
||||
testLlmSaveFirst: "请先保存 .env:测试使用的是磁盘上已保存的后端。",
|
||||
testLlmSaveFirst: "请先保存 .env:测试使用的是磁盘上已保存的配置。",
|
||||
llmOk: "LLM 连接正常({ms} ms)",
|
||||
llmFailed: "LLM 测试失败",
|
||||
serviceHint: "启动或停止本地 ReMe 服务;DSH 关闭后服务仍会保持运行。",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { StatusRpc } from "../../client/status-page.js";
|
||||
import { safeError } from "../../endpoint.js";
|
||||
import { llmBackendOf } from "../llm-backend.js";
|
||||
import type { EnvEntry, EnvSummary, LlmTestResult } from "../types.js";
|
||||
import { fill, type EnvKey, type EnvTranslator } from "./locales.js";
|
||||
import { EnvField } from "./presentation.js";
|
||||
|
|
@ -415,13 +416,26 @@ export function WorkspaceSection({
|
|||
}): JSX.Element {
|
||||
const [open, setOpen] = useState(false);
|
||||
const { env, llmTest, result } = workspace;
|
||||
// The probe reads the saved .env, so a backend that is only picked in the
|
||||
// form would be tested against the one still on disk. The button says so
|
||||
// instead of quietly testing the old backend.
|
||||
const savedBackend =
|
||||
env.data?.entries.find((entry) => entry.key === "LLM_BACKEND")?.value ?? "";
|
||||
// The probe reads the saved .env, so a configuration that is only picked in
|
||||
// the form would be tested against the one still on disk. The button waits
|
||||
// instead of quietly testing the old configuration.
|
||||
const savedValue = (key: string): string =>
|
||||
env.data?.entries.find((entry) => entry.key === key)?.value ?? "";
|
||||
// The backend falls back to the default on both sides, so picking the
|
||||
// default in the form is not a change at all.
|
||||
const backendChanged =
|
||||
workspace.value("LLM_BACKEND").trim() !== savedBackend.trim();
|
||||
llmBackendOf(workspace.value("LLM_BACKEND")) !==
|
||||
llmBackendOf(savedValue("LLM_BACKEND"));
|
||||
// The model and the base URL travel as plain text, so they compare by
|
||||
// value. The key is write-only: a typed one is the only sign that it
|
||||
// differs from the file, which still holds the stored key.
|
||||
const configChanged =
|
||||
backendChanged ||
|
||||
workspace.value("LLM_MODEL_NAME").trim() !==
|
||||
savedValue("LLM_MODEL_NAME").trim() ||
|
||||
workspace.value("LLM_BASE_URL").trim() !==
|
||||
savedValue("LLM_BASE_URL").trim() ||
|
||||
workspace.value("LLM_API_KEY") !== "";
|
||||
|
||||
return (
|
||||
<section className={`reme-env-card${open ? "" : " collapsed"}`}>
|
||||
|
|
@ -515,7 +529,7 @@ export function WorkspaceSection({
|
|||
type="button"
|
||||
className="reme-settings-button"
|
||||
disabled={
|
||||
!pythonPath || llmTest.phase === "running" || backendChanged
|
||||
!pythonPath || llmTest.phase === "running" || configChanged
|
||||
}
|
||||
onClick={() => void workspace.testLlm(pythonPath)}
|
||||
>
|
||||
|
|
@ -525,7 +539,7 @@ export function WorkspaceSection({
|
|||
: "testLlmButton",
|
||||
)}
|
||||
</button>
|
||||
{backendChanged ? (
|
||||
{configChanged ? (
|
||||
<span className="reme-settings-muted">
|
||||
{t("testLlmSaveFirst")}
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {
|
|||
import { dirname, isAbsolute, join, resolve } from "node:path";
|
||||
|
||||
import { safeError } from "../../endpoint.js";
|
||||
import { DEFAULT_LLM_BACKEND, llmBackendOf } from "../llm-backend.js";
|
||||
import type { EnvSummary, LlmTestResult } from "../types.js";
|
||||
import type { RunCommand } from "./runner.js";
|
||||
|
||||
|
|
@ -285,12 +286,11 @@ export const LLM_PROTOCOLS: Record<string, LlmProtocol> = {
|
|||
};
|
||||
|
||||
/** The backend ReMe itself falls back to when `.env` names none. */
|
||||
export const DEFAULT_LLM_BACKEND = "openai";
|
||||
export { DEFAULT_LLM_BACKEND };
|
||||
|
||||
/** The protocol a backend speaks; unknown backends use ReMe's default. */
|
||||
export function llmProtocolFor(backend: string): LlmProtocol {
|
||||
const name = (backend ?? "").trim().toLowerCase();
|
||||
return LLM_PROTOCOLS[name] ?? OPENAI_PROTOCOL;
|
||||
return LLM_PROTOCOLS[llmBackendOf(backend)] ?? OPENAI_PROTOCOL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
17
integrations/dsh/src/environment/llm-backend.ts
Normal file
17
integrations/dsh/src/environment/llm-backend.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* The LLM backend the workspace `.env` selects.
|
||||
*
|
||||
* ReMe's own configuration resolves an empty value to `openai`
|
||||
* (`${LLM_BACKEND:-openai}`), and the Host's probe resolves it the same way.
|
||||
* The tab has to agree: a backend that is only picked in the form and equals
|
||||
* the default is not a change to the configuration.
|
||||
*
|
||||
* This module stays browser-safe: no Node built-ins, because the client
|
||||
* imports it too.
|
||||
*/
|
||||
export const DEFAULT_LLM_BACKEND = "openai";
|
||||
|
||||
/** The backend a value means, with the default the configuration applies. */
|
||||
export function llmBackendOf(value: string): string {
|
||||
return (value ?? "").trim().toLowerCase() || DEFAULT_LLM_BACKEND;
|
||||
}
|
||||
|
|
@ -1539,6 +1539,97 @@ test("the LLM test waits for the backend that is saved on disk", async (t) => {
|
|||
);
|
||||
});
|
||||
|
||||
test("the LLM test waits for every unsaved probe setting", async (t) => {
|
||||
// The probe reads the whole .env from disk, so a changed model or key is
|
||||
// just as untested as a changed backend.
|
||||
const { renderer, restore } = await mount();
|
||||
t.after(restore);
|
||||
await act(async () => {
|
||||
buttonByText(renderer, envZh.expand).props.onClick();
|
||||
});
|
||||
const model = renderer.root.findAll(
|
||||
(node) => node.type === "input" && node.props.value === "qwen3.7-plus",
|
||||
);
|
||||
assert.ok(model.length > 0, "the model field");
|
||||
await act(async () => {
|
||||
model[0].props.onChange({ target: { value: "another-model" } });
|
||||
});
|
||||
assert.equal(
|
||||
buttonByText(renderer, envZh.testLlmButton).props.disabled,
|
||||
true,
|
||||
"an unsaved model is not the model the probe would use",
|
||||
);
|
||||
|
||||
// A typed key is not on disk either.
|
||||
const fresh = await mount();
|
||||
try {
|
||||
await act(async () => {
|
||||
buttonByText(fresh.renderer, envZh.expand).props.onClick();
|
||||
});
|
||||
const key = fresh.renderer.root.findAll(
|
||||
(node) => node.type === "input" && node.props.type === "password",
|
||||
)[0];
|
||||
await act(async () => {
|
||||
key.props.onChange({ target: { value: "sk-typed" } });
|
||||
});
|
||||
assert.equal(
|
||||
buttonByText(fresh.renderer, envZh.testLlmButton).props.disabled,
|
||||
true,
|
||||
"an unsaved key is not the key the probe would use",
|
||||
);
|
||||
} finally {
|
||||
fresh.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test("picking the default backend is not treated as a change", async (t) => {
|
||||
// The .env names no backend, so ReMe and the probe both use the default;
|
||||
// choosing it in the form changes nothing.
|
||||
const { renderer, restore } = await mount(
|
||||
{},
|
||||
{
|
||||
responses: {
|
||||
"remeEnv/readEnv": {
|
||||
workspaceDir: "C:\\Users\\test\\.reme",
|
||||
exists: true,
|
||||
envPath: "C:\\Users\\test\\.reme\\.env",
|
||||
entries: [
|
||||
{
|
||||
key: "LLM_MODEL_NAME",
|
||||
value: "qwen3.7-plus",
|
||||
masked: "qwen3.7-plus",
|
||||
secret: false,
|
||||
set: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
t.after(restore);
|
||||
await act(async () => {
|
||||
buttonByText(renderer, envZh.expand).props.onClick();
|
||||
});
|
||||
const backend = renderer.root
|
||||
.findAll((node) => node.type === "select")
|
||||
// The LLM backend is the only select that offers the native providers;
|
||||
// the mirror and the embedding backend have their own options.
|
||||
.find((node) =>
|
||||
node.props.children
|
||||
.flat(Infinity)
|
||||
.some((option) => option?.props?.value === "anthropic"),
|
||||
);
|
||||
assert.ok(backend, "the LLM backend select");
|
||||
await act(async () => {
|
||||
backend.props.onChange({ target: { value: "openai" } });
|
||||
});
|
||||
assert.equal(
|
||||
buttonByText(renderer, envZh.testLlmButton).props.disabled,
|
||||
false,
|
||||
"the default backend is what the probe already uses",
|
||||
);
|
||||
});
|
||||
|
||||
test("a restored job is matched by the interpreter's own path semantics", async (t) => {
|
||||
// The Host reports the interpreter with its own spelling; a Windows path
|
||||
// folds case and separators, so the job is still the one on screen.
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ test("the probe builds a valid request for every backend", async (t) => {
|
|||
const snippet = llmProbeSnippet(protocol);
|
||||
assert.doesNotMatch(
|
||||
snippet,
|
||||
/base\[:|endswith/,
|
||||
/base\s*\[|base\.endswith\(|base\.removesuffix\(/,
|
||||
`${backend} does not rewrite the configured base`,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue