an archetype flow can be customized for one agent
This commit is contained in:
parent
f2e735a98f
commit
5443c1c9ba
1 changed files with 153 additions and 34 deletions
|
|
@ -43,6 +43,7 @@ import {
|
|||
saveOutcome,
|
||||
previewRequest,
|
||||
saveRequest,
|
||||
disabledOnSave,
|
||||
seedFlow,
|
||||
parentOf,
|
||||
withFlow,
|
||||
|
|
@ -70,7 +71,10 @@ export function FlowEditorPage({
|
|||
isNew?: boolean;
|
||||
}) {
|
||||
const flowId = decodeURIComponent(params.flowId);
|
||||
const from = new URLSearchParams(useSearch()).get("from");
|
||||
const search = new URLSearchParams(useSearch());
|
||||
const from = search.get("from");
|
||||
// With `from` an archetype flow: the one agent this copy is for.
|
||||
const agent = search.get("agent");
|
||||
const [, navigate] = useLocation();
|
||||
const [view, setView] = useState<FlowsView | null>(null);
|
||||
const [draft, setDraft] = useState<Flow | null>(null);
|
||||
|
|
@ -108,7 +112,7 @@ export function FlowEditorPage({
|
|||
setSaveError(null);
|
||||
if (!keepDraft) {
|
||||
const flow = isNew
|
||||
? seedFlow(next, from)
|
||||
? seedFlow(next, from, agent)
|
||||
: next.flows.find((f) => f.id === flowId);
|
||||
setSeed(isNew && flow ? structuredClone(flow) : null);
|
||||
setDraft(flow ? structuredClone(flow) : null);
|
||||
|
|
@ -120,7 +124,7 @@ export function FlowEditorPage({
|
|||
);
|
||||
}
|
||||
},
|
||||
[flowId, isNew, from],
|
||||
[flowId, isNew, from, agent],
|
||||
);
|
||||
useEffect(() => {
|
||||
void load(false);
|
||||
|
|
@ -150,16 +154,16 @@ export function FlowEditorPage({
|
|||
// tab, following a link or pressing back.
|
||||
const leaving = useLeaveGuard(dirty);
|
||||
|
||||
// Send `flows` as the document; true when the controller took it.
|
||||
async function put(flows: Flow[]): Promise<boolean> {
|
||||
// Send `flows` and `disabled` as the document; true when the controller took it.
|
||||
async function put(
|
||||
flows: Flow[],
|
||||
disabled: string[] = view?.disabled_builtins ?? [],
|
||||
): Promise<boolean> {
|
||||
if (!view) return false;
|
||||
setBusy(true);
|
||||
setSaveError(null);
|
||||
try {
|
||||
const r = await fetch(
|
||||
FLOWS_URL,
|
||||
saveRequest(view, flows, view.disabled_builtins),
|
||||
);
|
||||
const r = await fetch(FLOWS_URL, saveRequest(view, flows, disabled));
|
||||
const outcome = saveOutcome(r.status);
|
||||
if (outcome === "saved") {
|
||||
const next = (await r.json()) as FlowsView;
|
||||
|
|
@ -220,7 +224,12 @@ export function FlowEditorPage({
|
|||
async function save() {
|
||||
if (!view || !draft) return;
|
||||
const flow = isNew ? savedAs(view, draft) : draft;
|
||||
if (!(await put(withFlow(view.flows, flow))) || !isNew) return;
|
||||
// The first save of a copy made for one agent also switches the
|
||||
// archetype's flow off for it, in the same write.
|
||||
const disabled = isNew
|
||||
? disabledOnSave(view.disabled_builtins, from, agent)
|
||||
: view.disabled_builtins;
|
||||
if (!(await put(withFlow(view.flows, flow), disabled)) || !isNew) return;
|
||||
leaving.release();
|
||||
navigate(`/notifications/${encodeURIComponent(flow.id)}`, {
|
||||
replace: true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue