比较提交
3 提交
779ffc3d55
...
06316a3240
| 作者 | SHA1 | 提交日期 | |
|---|---|---|---|
| 06316a3240 | |||
| 79dbb40a25 | |||
| ef8bc430d9 |
共有 5 个文件被更改,包括 811 次插入 和 640 次删除
|
|
@ -36,6 +36,14 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- Adding a connection now asks for four things — server address, adapter id, API key, and slot —
|
||||||
|
with the rest behind a collapsed advanced section. The SSE URL and certificate fingerprint fields
|
||||||
|
were removed because nothing reads them, and the role field was removed because it follows the
|
||||||
|
chosen slot. The display name is derived from the identity and host unless set explicitly, and the
|
||||||
|
insecure-HTTP approval appears only for an `http://` address, where it is required.
|
||||||
|
- Choosing a slot in the connection form now assigns the slot and points startup auto-connect at it,
|
||||||
|
replacing a separate slot card interaction and a separate dropdown that could disagree.
|
||||||
|
- The API key is enrolled as part of saving a new connection instead of as a second step.
|
||||||
- Synchronized the 13-item roadmap status with the actual P02 implementation state.
|
- Synchronized the 13-item roadmap status with the actual P02 implementation state.
|
||||||
- Documented external prerequisites for HTTPS certificate pinning, signed updates, and dual-server soak testing.
|
- Documented external prerequisites for HTTPS certificate pinning, signed updates, and dual-server soak testing.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -650,3 +650,51 @@ Rust 107 passed / 2 ignored. Frontend 24 passed / 5 files. Playwright 5 passed.
|
||||||
|
|
||||||
Next: capture the frames, then batch R3.6 (message identity, pulling F-34 forward) and R3.7
|
Next: capture the frames, then batch R3.6 (message identity, pulling F-34 forward) and R3.7
|
||||||
(attachment chain, pulling F-33 forward).
|
(attachment chain, pulling F-33 forward).
|
||||||
|
|
||||||
|
## 2026-07-27: window controls and connection form
|
||||||
|
|
||||||
|
### Window controls (P0)
|
||||||
|
|
||||||
|
The minimize, maximize and close buttons did nothing. The handlers were correct; the ACL rejected
|
||||||
|
them. `core:default` resolves to `core:window:default`, which grants only read-only queries —
|
||||||
|
`allow-is-maximized` is in it, which is why the maximize icon tracked state, but `allow-minimize`,
|
||||||
|
`allow-toggle-maximize`, `allow-close` and `allow-start-dragging` are not. Both windows are
|
||||||
|
`decorations: false`, so with close denied the main window could not be closed except through the
|
||||||
|
tray.
|
||||||
|
|
||||||
|
Added `main-window-controls` and `pet-window-drag` capabilities rather than widening the shared one,
|
||||||
|
so the pet gains dragging alone. Routed the calls through a helper that reports failures in the
|
||||||
|
shell error banner; they were bare `void` expressions, which is why the rejection was
|
||||||
|
indistinguishable from an unwired button.
|
||||||
|
|
||||||
|
This is the second time a missing capability surfaced as a silent no-op, after the pet window
|
||||||
|
(F-03). `src-tauri/tests/capabilities.rs` now reads the shipped capability files and asserts each
|
||||||
|
permission the UI calls is granted to the window that calls it.
|
||||||
|
|
||||||
|
### Connection form
|
||||||
|
|
||||||
|
Adding a connection asked for eleven fields. Three reached nothing: the SSE URL has no consumer in
|
||||||
|
`networking/`, the certificate fingerprint is stored but TLS pinning is unimplemented, and the role
|
||||||
|
only chose a word in the profile list. The form is now server address, adapter id, API key and slot,
|
||||||
|
with the rest behind a collapsed advanced section.
|
||||||
|
|
||||||
|
The adapter id is the remote username, previously entered twice — once in the profile form, once in
|
||||||
|
the credential card. Display name, role, and the insecure-HTTP approval are now derived rather than
|
||||||
|
asked for; the approval appears only for an `http://` address and is required there, since
|
||||||
|
`normalize_url` rejects such an address without it.
|
||||||
|
|
||||||
|
Choosing a slot assigns the slot and points auto-connect at it, replacing two controls that could
|
||||||
|
disagree. The API key is enrolled in the same submit; both follow-up steps need the profile to
|
||||||
|
exist, so they report their own failures rather than failing the save.
|
||||||
|
|
||||||
|
`ProfileManager.tsx` was normalized to LF in a separate commit first. It held 603 CRLF and 85 LF
|
||||||
|
lines against an `.editorconfig` that pins LF, which is why the fix queue carried a standing warning
|
||||||
|
about editing it.
|
||||||
|
|
||||||
|
### Test status
|
||||||
|
|
||||||
|
Rust 112 passed / 2 ignored. Frontend 29 passed / 6 files. Playwright 5 passed. Build passes.
|
||||||
|
|
||||||
|
Verified in a browser against the real stylesheet rather than by inspection: four visible fields
|
||||||
|
plus a collapsed advanced section, the insecure checkbox appearing only for `http://` and carrying
|
||||||
|
`required`, and the display name resolving to identity@host.
|
||||||
|
|
|
||||||
|
|
@ -227,15 +227,16 @@ describe("App", () => {
|
||||||
await openConnectionsPage();
|
await openConnectionsPage();
|
||||||
expect(await screen.findByText("尚未保存 Profile。")).toBeInTheDocument();
|
expect(await screen.findByText("尚未保存 Profile。")).toBeInTheDocument();
|
||||||
|
|
||||||
|
fireEvent.change(screen.getByLabelText("服务器地址"), {
|
||||||
|
target: { value: "https://ops.example.test" },
|
||||||
|
});
|
||||||
|
fireEvent.change(screen.getByLabelText("适配器 ID"), {
|
||||||
|
target: { value: "opsbot" },
|
||||||
|
});
|
||||||
|
// Lives under 高级设置; the disclosure only hides it visually.
|
||||||
fireEvent.change(screen.getByLabelText("显示名称"), {
|
fireEvent.change(screen.getByLabelText("显示名称"), {
|
||||||
target: { value: "家庭运维" },
|
target: { value: "家庭运维" },
|
||||||
});
|
});
|
||||||
fireEvent.change(screen.getByLabelText("角色"), {
|
|
||||||
target: { value: "operations" },
|
|
||||||
});
|
|
||||||
fireEvent.change(screen.getByLabelText("REST 基础 URL"), {
|
|
||||||
target: { value: "https://ops.example.test" },
|
|
||||||
});
|
|
||||||
fireEvent.click(screen.getByRole("button", { name: "保存 Profile" }));
|
fireEvent.click(screen.getByRole("button", { name: "保存 Profile" }));
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
|
|
@ -354,13 +355,24 @@ describe("App", () => {
|
||||||
const created: ConnectionProfile = {
|
const created: ConnectionProfile = {
|
||||||
id: "2bdedc10-d804-4da5-8e92-39dd7f175d7a",
|
id: "2bdedc10-d804-4da5-8e92-39dd7f175d7a",
|
||||||
...request,
|
...request,
|
||||||
transportKind: "desktop-v1",
|
transportKind: request.transportKind ?? "astr-bot-open-api",
|
||||||
createdAt: "2026-07-19T03:00:00Z",
|
createdAt: "2026-07-19T03:00:00Z",
|
||||||
updatedAt: "2026-07-19T03:00:00Z",
|
updatedAt: "2026-07-19T03:00:00Z",
|
||||||
};
|
};
|
||||||
profiles = [created];
|
profiles = [created];
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
if (command === "assign_connection_slot") {
|
||||||
|
const { request } = args as {
|
||||||
|
request: { slot: ActiveSlotKind; profileId: string };
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
slot: request.slot,
|
||||||
|
profileId: request.profileId,
|
||||||
|
state: "disconnected",
|
||||||
|
unreadCount: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
throw new Error(`Unexpected command: ${command}`);
|
throw new Error(`Unexpected command: ${command}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -368,19 +380,18 @@ describe("App", () => {
|
||||||
await openConnectionsPage();
|
await openConnectionsPage();
|
||||||
expect(await screen.findByText("尚未保存 Profile。")).toBeInTheDocument();
|
expect(await screen.findByText("尚未保存 Profile。")).toBeInTheDocument();
|
||||||
|
|
||||||
|
fireEvent.change(screen.getByLabelText("服务器地址"), {
|
||||||
|
target: { value: "https://companion.example.test" },
|
||||||
|
});
|
||||||
|
fireEvent.change(screen.getByLabelText("适配器 ID"), {
|
||||||
|
target: { value: "companionbot" },
|
||||||
|
});
|
||||||
fireEvent.change(screen.getByLabelText("显示名称"), {
|
fireEvent.change(screen.getByLabelText("显示名称"), {
|
||||||
target: { value: "自动陪伴" },
|
target: { value: "自动陪伴" },
|
||||||
});
|
});
|
||||||
fireEvent.change(screen.getByLabelText("角色"), {
|
// Choosing a slot is now the single control: it assigns the slot, sets the
|
||||||
target: { value: "companion" },
|
// role, and points startup auto-connect at it.
|
||||||
});
|
fireEvent.change(screen.getByLabelText("槽位"), {
|
||||||
fireEvent.change(screen.getByLabelText("REST 基础 URL"), {
|
|
||||||
target: { value: "https://companion.example.test" },
|
|
||||||
});
|
|
||||||
fireEvent.click(
|
|
||||||
screen.getByLabelText("启动时自动连接(不会在本阶段真正建立网络会话)"),
|
|
||||||
);
|
|
||||||
fireEvent.change(screen.getByLabelText("自动连接槽位"), {
|
|
||||||
target: { value: "companion" },
|
target: { value: "companion" },
|
||||||
});
|
});
|
||||||
fireEvent.click(screen.getByRole("button", { name: "保存 Profile" }));
|
fireEvent.click(screen.getByRole("button", { name: "保存 Profile" }));
|
||||||
|
|
@ -388,19 +399,25 @@ describe("App", () => {
|
||||||
expect(
|
expect(
|
||||||
await screen.findByText("已创建 Profile:自动陪伴"),
|
await screen.findByText("已创建 Profile:自动陪伴"),
|
||||||
).toBeInTheDocument();
|
).toBeInTheDocument();
|
||||||
expect(screen.getByText("自动连接:陪伴")).toBeInTheDocument();
|
|
||||||
expect(invoke).toHaveBeenCalledWith("create_connection_profile", {
|
expect(invoke).toHaveBeenCalledWith("create_connection_profile", {
|
||||||
request: {
|
request: {
|
||||||
displayName: "自动陪伴",
|
displayName: "自动陪伴",
|
||||||
role: "companion",
|
role: "companion",
|
||||||
baseUrl: "https://companion.example.test",
|
baseUrl: "https://companion.example.test",
|
||||||
authenticationType: "device-token",
|
authenticationType: "api-key",
|
||||||
transportKind: "desktop-v1",
|
transportKind: "astr-bot-open-api",
|
||||||
|
remoteUsername: "companionbot",
|
||||||
allowInsecureHttp: false,
|
allowInsecureHttp: false,
|
||||||
autoConnect: true,
|
autoConnect: true,
|
||||||
autoConnectSlot: "companion",
|
autoConnectSlot: "companion",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
expect(invoke).toHaveBeenCalledWith("assign_connection_slot", {
|
||||||
|
request: {
|
||||||
|
slot: "companion",
|
||||||
|
profileId: "2bdedc10-d804-4da5-8e92-39dd7f175d7a",
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shows duplicate server-instance warnings and locks the operations slot", async () => {
|
it("shows duplicate server-instance warnings and locks the operations slot", async () => {
|
||||||
|
|
|
||||||
|
|
@ -25,35 +25,68 @@ import { errorMessage } from "../../lib/errorMessage";
|
||||||
import { CredentialEnrollmentCard } from "./CredentialEnrollmentCard";
|
import { CredentialEnrollmentCard } from "./CredentialEnrollmentCard";
|
||||||
|
|
||||||
interface ProfileFormState {
|
interface ProfileFormState {
|
||||||
displayName: string;
|
|
||||||
role: ProfileRole;
|
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
eventStreamUrl: string;
|
apiKey: string;
|
||||||
|
remoteUsername: string;
|
||||||
|
slot: "" | ActiveSlotKind;
|
||||||
|
displayName: string;
|
||||||
|
remoteDisplayName: string;
|
||||||
authenticationType: AuthenticationType;
|
authenticationType: AuthenticationType;
|
||||||
transportKind: TransportKind;
|
transportKind: TransportKind;
|
||||||
remoteUsername: string;
|
|
||||||
remoteDisplayName: string;
|
|
||||||
allowInsecureHttp: boolean;
|
allowInsecureHttp: boolean;
|
||||||
pinnedCertificateFingerprint: string;
|
|
||||||
autoConnect: boolean;
|
autoConnect: boolean;
|
||||||
autoConnectSlot: "" | ActiveSlotKind;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const emptyForm: ProfileFormState = {
|
const emptyForm: ProfileFormState = {
|
||||||
displayName: "",
|
baseUrl: "http://",
|
||||||
role: "general",
|
apiKey: "",
|
||||||
baseUrl: "https://",
|
|
||||||
eventStreamUrl: "",
|
|
||||||
authenticationType: "device-token",
|
|
||||||
transportKind: "desktop-v1",
|
|
||||||
remoteUsername: "",
|
remoteUsername: "",
|
||||||
|
slot: "",
|
||||||
|
displayName: "",
|
||||||
remoteDisplayName: "",
|
remoteDisplayName: "",
|
||||||
|
authenticationType: "api-key",
|
||||||
|
transportKind: "astr-bot-open-api",
|
||||||
allowInsecureHttp: false,
|
allowInsecureHttp: false,
|
||||||
pinnedCertificateFingerprint: "",
|
autoConnect: true,
|
||||||
autoConnect: false,
|
|
||||||
autoConnectSlot: "",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Names the connection after the server and identity when the user did not.
|
||||||
|
///
|
||||||
|
/// The display name is `NOT NULL` in the database and is what the profile list
|
||||||
|
/// and the slot cards show, but asking for it adds a field that carries no
|
||||||
|
/// information the other three do not already provide.
|
||||||
|
function derivedDisplayName(form: ProfileFormState): string {
|
||||||
|
const explicit = form.displayName.trim();
|
||||||
|
if (explicit) return explicit;
|
||||||
|
const username = form.remoteUsername.trim();
|
||||||
|
const host = hostOf(form.baseUrl);
|
||||||
|
if (host && username) return `${username}@${host}`;
|
||||||
|
return username || host || "AstrBot 连接";
|
||||||
|
}
|
||||||
|
|
||||||
|
function hostOf(value: string): string {
|
||||||
|
try {
|
||||||
|
return new URL(value.trim()).host;
|
||||||
|
} catch {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The slot a profile serves is the only meaningful reading of its role.
|
||||||
|
function roleForSlot(slot: "" | ActiveSlotKind): ProfileRole {
|
||||||
|
return slot === "" ? "general" : slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// True when the address needs the explicit insecure-transport approval.
|
||||||
|
///
|
||||||
|
/// `normalize_url` in `profiles.rs` rejects an `http://` base URL unless the
|
||||||
|
/// profile carries that approval, so the checkbox has to appear before the user
|
||||||
|
/// can save a LAN address — but showing it unconditionally invites turning it on
|
||||||
|
/// for an `https://` endpoint that never needed it.
|
||||||
|
function needsInsecureApproval(baseUrl: string): boolean {
|
||||||
|
return baseUrl.trim().toLowerCase().startsWith("http://");
|
||||||
|
}
|
||||||
|
|
||||||
const emptyPolicy: ConnectionPolicyStatus = {
|
const emptyPolicy: ConnectionPolicyStatus = {
|
||||||
operationsSwitchLocked: false,
|
operationsSwitchLocked: false,
|
||||||
activeOperationsTaskCount: 0,
|
activeOperationsTaskCount: 0,
|
||||||
|
|
@ -103,7 +136,10 @@ export function ProfileManager() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void loadProfiles();
|
void loadProfiles();
|
||||||
const refreshTimer = window.setInterval(() => void refreshRuntimeStatus(), 2000);
|
const refreshTimer = window.setInterval(
|
||||||
|
() => void refreshRuntimeStatus(),
|
||||||
|
2000,
|
||||||
|
);
|
||||||
return () => window.clearInterval(refreshTimer);
|
return () => window.clearInterval(refreshTimer);
|
||||||
}, [loadProfiles, refreshRuntimeStatus]);
|
}, [loadProfiles, refreshRuntimeStatus]);
|
||||||
|
|
||||||
|
|
@ -132,15 +168,65 @@ export function ProfileManager() {
|
||||||
saved,
|
saved,
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// The remaining steps each need the profile to exist, so they cannot be
|
||||||
|
// folded into the create call. A failure in either leaves a usable
|
||||||
|
// profile, so report it rather than treating the save as failed.
|
||||||
|
const followUp: string[] = [];
|
||||||
|
|
||||||
|
if (form.slot) {
|
||||||
|
try {
|
||||||
|
const assigned = connectionSlotSchema.parse(
|
||||||
|
await invoke<unknown>("assign_connection_slot", {
|
||||||
|
request: {
|
||||||
|
slot: form.slot,
|
||||||
|
profileId: saved.id,
|
||||||
|
} satisfies AssignConnectionSlotRequest,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
setSlots((current) =>
|
||||||
|
current.map((item) =>
|
||||||
|
item.slot === assigned.slot ? assigned : item,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} catch (reason) {
|
||||||
|
followUp.push(`槽位指派失败:${errorMessage(reason)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const secret = form.apiKey.trim();
|
||||||
|
if (secret) {
|
||||||
|
try {
|
||||||
|
await invoke("enroll_profile_credential", {
|
||||||
|
request: {
|
||||||
|
profileId: saved.id,
|
||||||
|
authenticationType: saved.authenticationType,
|
||||||
|
secret,
|
||||||
|
username: saved.remoteUsername ?? undefined,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (reason) {
|
||||||
|
followUp.push(
|
||||||
|
`凭据登记失败:${errorMessage(reason)}。Profile 已保存,可在下方凭据卡片重试。`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await loadProfiles();
|
||||||
await refreshPolicy();
|
await refreshPolicy();
|
||||||
setNotice(
|
if (followUp.length > 0) {
|
||||||
editingId
|
setError(followUp.join(" "));
|
||||||
? `已更新 Profile:${saved.displayName}`
|
setNotice(`已保存 Profile:${saved.displayName}`);
|
||||||
: `已创建 Profile:${saved.displayName}`,
|
} else {
|
||||||
);
|
setNotice(
|
||||||
|
editingId
|
||||||
|
? `已更新 Profile:${saved.displayName}`
|
||||||
|
: `已创建 Profile:${saved.displayName}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
resetForm();
|
resetForm();
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
setError(`Profile save failed: ${errorMessage(reason)}`);
|
setError(`Profile 保存失败:${errorMessage(reason)}`);
|
||||||
} finally {
|
} finally {
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
|
|
@ -148,19 +234,25 @@ export function ProfileManager() {
|
||||||
|
|
||||||
function editProfile(profile: ConnectionProfile) {
|
function editProfile(profile: ConnectionProfile) {
|
||||||
setEditingId(profile.id);
|
setEditingId(profile.id);
|
||||||
|
// The persisted slot assignment is authoritative for which slot a profile
|
||||||
|
// serves; `autoConnectSlot` only says where startup connection should go.
|
||||||
|
const assignedSlot = slots.find(
|
||||||
|
(slot) => slot.profileId === profile.id,
|
||||||
|
)?.slot;
|
||||||
setForm({
|
setForm({
|
||||||
displayName: profile.displayName,
|
|
||||||
role: profile.role,
|
|
||||||
baseUrl: profile.baseUrl,
|
baseUrl: profile.baseUrl,
|
||||||
eventStreamUrl: profile.eventStreamUrl ?? "",
|
// Never populated from a stored profile: the secret lives in Windows
|
||||||
authenticationType: profile.authenticationType,
|
// Credential Manager and never crosses IPC. Rotation goes through the
|
||||||
transportKind: profile.transportKind ?? "desktop-v1",
|
// credential card.
|
||||||
|
apiKey: "",
|
||||||
remoteUsername: profile.remoteUsername ?? "",
|
remoteUsername: profile.remoteUsername ?? "",
|
||||||
|
slot: assignedSlot ?? profile.autoConnectSlot ?? "",
|
||||||
|
displayName: profile.displayName,
|
||||||
remoteDisplayName: profile.remoteDisplayName ?? "",
|
remoteDisplayName: profile.remoteDisplayName ?? "",
|
||||||
|
authenticationType: profile.authenticationType,
|
||||||
|
transportKind: profile.transportKind ?? "astr-bot-open-api",
|
||||||
allowInsecureHttp: profile.allowInsecureHttp,
|
allowInsecureHttp: profile.allowInsecureHttp,
|
||||||
pinnedCertificateFingerprint: profile.pinnedCertificateFingerprint ?? "",
|
|
||||||
autoConnect: profile.autoConnect,
|
autoConnect: profile.autoConnect,
|
||||||
autoConnectSlot: profile.autoConnectSlot ?? "",
|
|
||||||
});
|
});
|
||||||
setError(null);
|
setError(null);
|
||||||
setNotice(null);
|
setNotice(null);
|
||||||
|
|
@ -335,45 +427,12 @@ export function ProfileManager() {
|
||||||
<h3>{editingId ? "编辑 Profile" : "新建 Profile"}</h3>
|
<h3>{editingId ? "编辑 Profile" : "新建 Profile"}</h3>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<span>显示名称</span>
|
<span>服务器地址</span>
|
||||||
<input
|
|
||||||
name="displayName"
|
|
||||||
required
|
|
||||||
maxLength={80}
|
|
||||||
value={form.displayName}
|
|
||||||
onChange={(event) =>
|
|
||||||
setForm((current) => ({
|
|
||||||
...current,
|
|
||||||
displayName: event.target.value,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label>
|
|
||||||
<span>角色</span>
|
|
||||||
<select
|
|
||||||
name="role"
|
|
||||||
value={form.role}
|
|
||||||
onChange={(event) =>
|
|
||||||
setForm((current) => ({
|
|
||||||
...current,
|
|
||||||
role: event.target.value as ProfileRole,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<option value="general">通用</option>
|
|
||||||
<option value="companion">陪伴</option>
|
|
||||||
<option value="operations">运维</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label>
|
|
||||||
<span>REST 基础 URL</span>
|
|
||||||
<input
|
<input
|
||||||
name="baseUrl"
|
name="baseUrl"
|
||||||
type="url"
|
type="url"
|
||||||
required
|
required
|
||||||
|
placeholder="http://192.168.1.10:6185"
|
||||||
value={form.baseUrl}
|
value={form.baseUrl}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
setForm((current) => ({
|
setForm((current) => ({
|
||||||
|
|
@ -385,90 +444,12 @@ export function ProfileManager() {
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<span>SSE URL(可选)</span>
|
<span>适配器 ID</span>
|
||||||
<input
|
|
||||||
name="eventStreamUrl"
|
|
||||||
type="url"
|
|
||||||
value={form.eventStreamUrl}
|
|
||||||
onChange={(event) =>
|
|
||||||
setForm((current) => ({
|
|
||||||
...current,
|
|
||||||
eventStreamUrl: event.target.value,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label>
|
|
||||||
<span>认证类型</span>
|
|
||||||
<select
|
|
||||||
name="authenticationType"
|
|
||||||
value={form.authenticationType}
|
|
||||||
onChange={(event) =>
|
|
||||||
setForm((current) => ({
|
|
||||||
...current,
|
|
||||||
authenticationType: event.target.value as AuthenticationType,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<option value="device-token">设备 Token</option>
|
|
||||||
<option value="api-key">API Key</option>
|
|
||||||
<option value="jwt">AstrBot JWT</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label>
|
|
||||||
<span>证书 SHA-256 指纹(可选)</span>
|
|
||||||
<input
|
|
||||||
name="pinnedCertificateFingerprint"
|
|
||||||
inputMode="text"
|
|
||||||
placeholder="64 位十六进制"
|
|
||||||
value={form.pinnedCertificateFingerprint}
|
|
||||||
onChange={(event) =>
|
|
||||||
setForm((current) => ({
|
|
||||||
...current,
|
|
||||||
pinnedCertificateFingerprint: event.target.value,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label className="checkbox-field">
|
|
||||||
<input
|
|
||||||
name="allowInsecureHttp"
|
|
||||||
type="checkbox"
|
|
||||||
checked={form.allowInsecureHttp}
|
|
||||||
onChange={(event) =>
|
|
||||||
setForm((current) => ({
|
|
||||||
...current,
|
|
||||||
allowInsecureHttp: event.target.checked,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<span>明确允许不安全 HTTP(仅限受信任网络)</span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
|
|
||||||
<label>
|
|
||||||
传输协议
|
|
||||||
<select
|
|
||||||
value={form.transportKind}
|
|
||||||
onChange={(event) =>
|
|
||||||
setForm((current) => ({
|
|
||||||
...current,
|
|
||||||
transportKind: event.target.value as TransportKind,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<option value="desktop-v1">Desktop Mock/Gateway</option>
|
|
||||||
<option value="astr-bot-open-api">AstrBot OpenAPI</option>
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
{form.transportKind === "astr-bot-open-api" ? (
|
|
||||||
<>
|
|
||||||
<label>
|
|
||||||
AstrBot 用户名
|
|
||||||
<input
|
<input
|
||||||
|
name="remoteUsername"
|
||||||
|
required={form.transportKind === "astr-bot-open-api"}
|
||||||
|
pattern="[A-Za-z0-9]{3,32}"
|
||||||
|
placeholder="yoki"
|
||||||
value={form.remoteUsername}
|
value={form.remoteUsername}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
setForm((current) => ({
|
setForm((current) => ({
|
||||||
|
|
@ -476,67 +457,159 @@ export function ProfileManager() {
|
||||||
remoteUsername: event.target.value,
|
remoteUsername: event.target.value,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
placeholder="desktop-companion"
|
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<p className="form-note">
|
||||||
BOT 称呼昵称
|
AstrBot 的会话身份,3–32 位英文或数字。两个槽位必须使用不同的
|
||||||
<input
|
ID,否则会共用同一段对话。
|
||||||
value={form.remoteDisplayName}
|
</p>
|
||||||
maxLength={80}
|
|
||||||
onChange={(event) =>
|
{editingId ? null : (
|
||||||
setForm((current) => ({
|
<>
|
||||||
...current,
|
<label>
|
||||||
remoteDisplayName: event.target.value,
|
<span>API Key</span>
|
||||||
}))
|
<input
|
||||||
}
|
name="apiKey"
|
||||||
placeholder="小明"
|
type="password"
|
||||||
/>
|
autoComplete="off"
|
||||||
</label>
|
value={form.apiKey}
|
||||||
</>
|
onChange={(event) =>
|
||||||
) : null}
|
setForm((current) => ({
|
||||||
<label className="checkbox-field">
|
...current,
|
||||||
<input
|
apiKey: event.target.value,
|
||||||
name="autoConnect"
|
}))
|
||||||
type="checkbox"
|
}
|
||||||
checked={form.autoConnect}
|
/>
|
||||||
onChange={(event) =>
|
</label>
|
||||||
setForm((current) => ({
|
<p className="form-note">
|
||||||
...current,
|
保存时一次性写入 Windows
|
||||||
autoConnect: event.target.checked,
|
凭据管理器,不会进入本地数据库或前端状态。
|
||||||
autoConnectSlot: event.target.checked
|
</p>
|
||||||
? current.autoConnectSlot || "companion"
|
</>
|
||||||
: "",
|
)}
|
||||||
}))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<span>启动时自动连接(不会在本阶段真正建立网络会话)</span>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
<span>自动连接槽位</span>
|
<span>槽位</span>
|
||||||
<select
|
<select
|
||||||
name="autoConnectSlot"
|
name="slot"
|
||||||
aria-label="自动连接槽位"
|
value={form.slot}
|
||||||
disabled={!form.autoConnect}
|
|
||||||
value={form.autoConnectSlot}
|
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
setForm((current) => ({
|
setForm((current) => ({
|
||||||
...current,
|
...current,
|
||||||
autoConnectSlot: event.target.value as "" | ActiveSlotKind,
|
slot: event.target.value as "" | ActiveSlotKind,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<option value="">不自动连接</option>
|
<option value="">暂不指派</option>
|
||||||
<option value="companion">陪伴槽位</option>
|
<option value="companion">陪伴</option>
|
||||||
<option value="operations">运维槽位</option>
|
<option value="operations">运维</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<p className="form-note">
|
{needsInsecureApproval(form.baseUrl) ? (
|
||||||
自动连接配置最多两个 Profile,且槽位不可重复;真正的 REST/SSE
|
<label className="checkbox-field">
|
||||||
激活仍需等待协议与凭据边界确认。
|
<input
|
||||||
</p>
|
name="allowInsecureHttp"
|
||||||
|
type="checkbox"
|
||||||
|
required
|
||||||
|
checked={form.allowInsecureHttp}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm((current) => ({
|
||||||
|
...current,
|
||||||
|
allowInsecureHttp: event.target.checked,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span>这是明文 HTTP 地址,确认仅在受信任的局域网内使用</span>
|
||||||
|
</label>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<details className="profile-advanced">
|
||||||
|
<summary>高级设置</summary>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<span>显示名称</span>
|
||||||
|
<input
|
||||||
|
name="displayName"
|
||||||
|
maxLength={80}
|
||||||
|
placeholder={derivedDisplayName(form)}
|
||||||
|
value={form.displayName}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm((current) => ({
|
||||||
|
...current,
|
||||||
|
displayName: event.target.value,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<span>传输协议</span>
|
||||||
|
<select
|
||||||
|
name="transportKind"
|
||||||
|
value={form.transportKind}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm((current) => ({
|
||||||
|
...current,
|
||||||
|
transportKind: event.target.value as TransportKind,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="astr-bot-open-api">AstrBot OpenAPI</option>
|
||||||
|
<option value="desktop-v1">Desktop Mock/Gateway</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<span>认证类型</span>
|
||||||
|
<select
|
||||||
|
name="authenticationType"
|
||||||
|
value={form.authenticationType}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm((current) => ({
|
||||||
|
...current,
|
||||||
|
authenticationType: event.target
|
||||||
|
.value as AuthenticationType,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<option value="api-key">API Key</option>
|
||||||
|
<option value="jwt">AstrBot JWT</option>
|
||||||
|
<option value="device-token">设备 Token</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<span>BOT 称呼昵称</span>
|
||||||
|
<input
|
||||||
|
name="remoteDisplayName"
|
||||||
|
maxLength={80}
|
||||||
|
placeholder="小明"
|
||||||
|
value={form.remoteDisplayName}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm((current) => ({
|
||||||
|
...current,
|
||||||
|
remoteDisplayName: event.target.value,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label className="checkbox-field">
|
||||||
|
<input
|
||||||
|
name="autoConnect"
|
||||||
|
type="checkbox"
|
||||||
|
checked={form.autoConnect}
|
||||||
|
onChange={(event) =>
|
||||||
|
setForm((current) => ({
|
||||||
|
...current,
|
||||||
|
autoConnect: event.target.checked,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span>启动时自动连接所选槽位</span>
|
||||||
|
</label>
|
||||||
|
</details>
|
||||||
|
|
||||||
<div className="button-row">
|
<div className="button-row">
|
||||||
<button type="submit" disabled={busy}>
|
<button type="submit" disabled={busy}>
|
||||||
|
|
@ -607,7 +680,7 @@ export function ProfileManager() {
|
||||||
profile={profile}
|
profile={profile}
|
||||||
onChanged={loadProfiles}
|
onChanged={loadProfiles}
|
||||||
/>
|
/>
|
||||||
</article>
|
</article>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -628,23 +701,22 @@ export function ProfileManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function toProfileInput(form: ProfileFormState): ConnectionProfileInput {
|
function toProfileInput(form: ProfileFormState): ConnectionProfileInput {
|
||||||
const eventStreamUrl = form.eventStreamUrl.trim();
|
const slot = form.slot || undefined;
|
||||||
const fingerprint = form.pinnedCertificateFingerprint.trim();
|
|
||||||
return {
|
return {
|
||||||
displayName: form.displayName.trim(),
|
displayName: derivedDisplayName(form),
|
||||||
role: form.role,
|
role: roleForSlot(form.slot),
|
||||||
baseUrl: form.baseUrl.trim(),
|
baseUrl: form.baseUrl.trim(),
|
||||||
eventStreamUrl: eventStreamUrl || undefined,
|
|
||||||
authenticationType: form.authenticationType,
|
authenticationType: form.authenticationType,
|
||||||
transportKind: form.transportKind,
|
transportKind: form.transportKind,
|
||||||
remoteUsername: form.remoteUsername.trim() || undefined,
|
remoteUsername: form.remoteUsername.trim() || undefined,
|
||||||
remoteDisplayName: form.remoteDisplayName.trim() || undefined,
|
remoteDisplayName: form.remoteDisplayName.trim() || undefined,
|
||||||
allowInsecureHttp: form.allowInsecureHttp,
|
// `normalize_url` only consults this for an `http://` address, and leaving a
|
||||||
pinnedCertificateFingerprint: fingerprint || undefined,
|
// stale approval on an `https://` profile would silently permit a later
|
||||||
autoConnect: form.autoConnect,
|
// downgrade of that address.
|
||||||
autoConnectSlot: form.autoConnect
|
allowInsecureHttp:
|
||||||
? form.autoConnectSlot || undefined
|
needsInsecureApproval(form.baseUrl) && form.allowInsecureHttp,
|
||||||
: undefined,
|
autoConnect: form.autoConnect && Boolean(slot),
|
||||||
|
autoConnectSlot: form.autoConnect ? slot : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,32 @@ select:focus {
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Everything the AstrBot connection does not need in order to work. Collapsed
|
||||||
|
by default so the common path is four fields. */
|
||||||
|
.profile-advanced {
|
||||||
|
padding: 0.75rem 0.9rem;
|
||||||
|
border: 1px solid var(--ui-line, rgb(137 175 232 / 26%));
|
||||||
|
border-radius: 0.65rem;
|
||||||
|
background: var(--ui-surface-soft, rgb(11 27 49 / 45%));
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-advanced > summary {
|
||||||
|
color: var(--ui-subtle, #9fb4d4);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
font-weight: 650;
|
||||||
|
cursor: pointer;
|
||||||
|
list-style-position: inside;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-advanced[open] > summary {
|
||||||
|
margin-bottom: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-advanced > label:not(:last-child),
|
||||||
|
.profile-advanced > .checkbox-field:not(:last-child) {
|
||||||
|
margin-bottom: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
.button-row {
|
.button-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
|
|
||||||
正在加载…
添加表格
在新工单中引用