swarm-ui: show and toggle an agent's unrestricted internet flag, add it to the create dialog
This commit is contained in:
parent
24beb167d8
commit
10508895c4
2 changed files with 136 additions and 2 deletions
|
|
@ -49,6 +49,7 @@ import { FormField } from "../ui/form-field/FormField.js";
|
|||
import { MultiselectFilterOptions } from "../ui/multiselect-filter/MultiselectFilter.js";
|
||||
import {
|
||||
initialSelection,
|
||||
requestInternet,
|
||||
requestPermissions,
|
||||
togglePermission,
|
||||
} from "./CreateAgentPermissions.js";
|
||||
|
|
@ -132,6 +133,8 @@ export function CreateAgentForm({
|
|||
null,
|
||||
);
|
||||
const [selected, setSelected] = useState<string[]>([]);
|
||||
// Unticked: the server writes `false`, so the agent starts restricted.
|
||||
const [internet, setInternet] = useState(false);
|
||||
// `null` until `/api/archetypes` answers; `archetype` is the picked one's
|
||||
// `archetypeKey`, `""` for none.
|
||||
const [archetypes, setArchetypes] = useState<ArchetypeList | null>(null);
|
||||
|
|
@ -231,6 +234,7 @@ export function CreateAgentForm({
|
|||
permissions: catalogue
|
||||
? requestPermissions(selected, catalogue.default)
|
||||
: undefined,
|
||||
...requestInternet(internet),
|
||||
archetype: requestArchetype(picked),
|
||||
...agentsMdBody(agentsMd),
|
||||
}),
|
||||
|
|
@ -434,6 +438,14 @@ export function CreateAgentForm({
|
|||
)}
|
||||
</div>
|
||||
</FormField>
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={internet}
|
||||
onChange={() => setInternet((v) => !v)}
|
||||
/>{" "}
|
||||
Unrestricted internet
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
{!done && step === "resources" && (
|
||||
|
|
|
|||
|
|
@ -38,3 +38,13 @@ export function initialSelection(
|
|||
...extra.filter((p) => all.includes(p) && !defaults.includes(p)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The create request's internet field: `unrestricted_internet: true` while
|
||||
* the box is ticked, nothing otherwise, as the server writes `false` for it.
|
||||
*/
|
||||
export function requestInternet(ticked: boolean): {
|
||||
unrestricted_internet?: true;
|
||||
} {
|
||||
return ticked ? { unrestricted_internet: true } : {};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue