Files
cobble/src/pages/admin/settings/environment/(sections)/environment-settings-section.tsx
T
tbenandClaude Opus 5.5 69988e08fc Move secrets between users and computers without the model seeing them
A new personal env scope (paradigm user: one user's secret for one bot)
beats every other scope, reaches only that user's runs of that bot, and
is redacted like any secret. Bots take secrets in with request_secret,
which puts a [secret-request:ID] card in the chat: the user types the
value into a masked input there, never into a message, and the bot is
told only the key. Bots show secrets with capture_secret (a task's
computer tool that saves a file or a command's output straight to a
personal env, then redacts it from the rest of the run) and show_secret
(an env by key): both give a [secret:ID] chip whose Reveal and Copy fetch
the value on click, for its own user (personal) or a super admin
(anything else), logged by key. Values never go into messages, page
props, history, Copy chat or logs. Users manage their own secrets on
Settings > Secrets; the Environment page lists everyone's, remove only.
Deleting a bot or user removes its personal secrets, and SecretsNote
tells bots never to ask for or print secrets in chat.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 16:51:32 +01:00

87 lines
3.6 KiB
TypeScript

import { useContext, useState } from "react";
import { AppContext } from "@/src/pages/__root";
import type { EnvsMutationResult, EnvsOverviewPayload } from "@/src/types";
import EnvsGroup from "../../(partials)/envs/envs-group";
import postEnvApi from "../../(functions)/post-env-api";
import PersonalSecretsGroup from "../../(partials)/secrets/personal-secrets-group";
import EnvScopeSelect from "../(partials)/env-scope-select";
import KnownEnvsGroup from "../(partials)/known-envs-group";
import scopeValue, { envInScope } from "../(utils)/scope-value";
/**
* Pick where (general, a workspace, a bot or a computer), then that scope's
* envs. General also lists the app settings. Below, every user's personal
* secrets (set from the chat), which can only be removed here. Every change
* saves at once and refreshes the page data.
*/
export default function EnvironmentSettingsSection() {
const { pageProps } = useContext(AppContext);
const [overview, setOverview] = useState(pageProps?.envs_overview);
const [selected, setSelected] = useState("general");
const [status, setStatus] = useState<{ error?: boolean; success?: boolean; msg?: string }>();
/**
* Remounts the lists when the data changes under them.
*/
const [version, setVersion] = useState(0);
const [removing, setRemoving] = useState<number>();
if (!overview) return null;
const scope =
overview.scopes.find((s) => scopeValue({ scope: s }) == selected) || overview.scopes[0]!;
const changed = (result: EnvsMutationResult, msg: string) => {
if (result.overview) setOverview(result.overview);
setStatus({ success: true, msg });
setVersion((prev) => prev + 1);
};
const failed = (msg: string) => setStatus({ error: true, msg });
return (
<>
<EnvScopeSelect
scopes={overview.scopes}
value={scopeValue({ scope })}
status={status}
onChange={(next) => {
setSelected(next);
setStatus(undefined);
}}
/>
{scope.paradigm == "general" ? (
<KnownEnvsGroup
key={`known-${version}`}
scope={scope}
overview={overview}
onChanged={changed}
onError={failed}
/>
) : null}
<EnvsGroup
key={`${scopeValue({ scope })}-${version}`}
scope={scope}
envs={overview.envs.filter((env) => !env.known && envInScope({ env, scope }))}
onChanged={changed}
onError={failed}
/>
<PersonalSecretsGroup
title="Personal secrets"
description="What users gave their bots from the chat, each for one user's runs of one bot. Only its user can see or replace one; you can remove it."
secrets={overview.personal || []}
show_user
busy_id={removing}
onRemove={async ({ secret }) => {
if (!window.confirm(`Remove ${secret.user_name}'s ${secret.key} for ${secret.bot_name}?`)) return;
setRemoving(secret.id);
const res = await postEnvApi({ path: "delete-env", body: { env_id: secret.id } }).catch(() => null);
setRemoving(undefined);
if (res?.success && res.singleRes) changed(res.singleRes, res.msg || "Removed.");
else failed(res?.msg || "Couldn't remove it.");
}}
/>
</>
);
}