diff --git a/api/server/routes/schedules.js b/api/server/routes/schedules.js
index 51b5e23f3d..2c7205d463 100644
--- a/api/server/routes/schedules.js
+++ b/api/server/routes/schedules.js
@@ -84,10 +84,15 @@ const handlers = createSchedulesHandlers({
// Durable account-deletion barrier. A one-shot disable scan cannot close the
// create race, so every scheduling WRITE consults the user-level flag instead.
isUserDeleting,
+ // Where consent is on, a schedule is authorized in the same write that creates it.
+ grant: (identity, choice, options) =>
+ require('~/server/services/Schedules/consent').consent.service.grant(identity, choice, options),
});
const consentHost = require('~/server/services/Schedules/consent').consent;
+/** Before the `/:id` routes: what the owner could allow a schedule of an agent not yet created. */
+router.post('/mcp-consent/offer', checkSchedulesCreate, consentHost.handlers.draft);
router.get('/:id/mcp-consent', consentHost.handlers.get);
router.post('/:id/mcp-consent', checkSchedulesCreate, consentHost.handlers.confirm);
router.delete('/:id/mcp-consent', consentHost.handlers.revoke);
diff --git a/api/server/services/Schedules/consent.spec.js b/api/server/services/Schedules/consent.spec.js
new file mode 100644
index 0000000000..5f0f3b5183
--- /dev/null
+++ b/api/server/services/Schedules/consent.spec.js
@@ -0,0 +1,49 @@
+/**
+ * Loads the real wiring against the real packages. Only the app's own singletons are stood
+ * in for, so something the packages do not provide fails here and not when the router loads.
+ */
+jest.mock('~/models', () => ({
+ findUser: jest.fn(),
+ getRoleByName: jest.fn(),
+ getScheduleById: jest.fn(),
+ getAgentGraphNodes: jest.fn(),
+ resolveAgentGraphAccess: jest.fn(),
+ getScheduleMCPCompletionState: jest.fn(),
+}));
+jest.mock('~/config', () => ({ getMCPServersRegistry: jest.fn() }));
+jest.mock('~/server/services/Config/app', () => ({ getAppConfig: jest.fn() }));
+jest.mock('~/server/controllers/ModelController', () => ({ getModelsConfig: jest.fn() }));
+jest.mock('./access', () => ({ resolveAgentFireAccess: jest.fn() }));
+
+const { findUser, getRoleByName } = require('~/models');
+const { resolveAgentFireAccess } = require('./access');
+
+describe('schedule consent wiring', () => {
+ it('provides the routes and the service the schedule router uses', () => {
+ const { consent } = require('./consent');
+ expect(consent.handlers).toEqual({
+ draft: expect.any(Function),
+ get: expect.any(Function),
+ confirm: expect.any(Function),
+ revoke: expect.any(Function),
+ });
+ expect(consent.service.grant).toEqual(expect.any(Function));
+ });
+
+ it('answers the offer for a schedule not yet created from the caller and the agent it names', async () => {
+ const { consent } = require('./consent');
+ const res = { status: jest.fn().mockReturnThis(), json: jest.fn() };
+ // No agent named: there is nothing to make an offer for.
+ await consent.handlers.draft({ user: { id: 'owner' }, body: {} }, res);
+ expect(res.status).toHaveBeenCalledWith(404);
+
+ findUser.mockResolvedValue({ id: 'owner', role: 'USER' });
+ getRoleByName.mockResolvedValue({ permissions: {} });
+ resolveAgentFireAccess.mockResolvedValue('ok');
+ res.status.mockClear();
+ // An owner whose role may not use schedules is refused, by the same check as a stored one.
+ await consent.handlers.draft({ user: { id: 'owner' }, body: { agent_id: 'agent_a' } }, res);
+ expect(res.status).toHaveBeenCalledWith(403);
+ expect(res.json).toHaveBeenLastCalledWith({ code: 'consent_forbidden' });
+ });
+});
diff --git a/client/src/components/MCP/GrantDialog.tsx b/client/src/components/MCP/GrantDialog.tsx
index c11bf2a162..359e96ce3a 100644
--- a/client/src/components/MCP/GrantDialog.tsx
+++ b/client/src/components/MCP/GrantDialog.tsx
@@ -1,22 +1,10 @@
import { useState, useId } from 'react';
-import { Tools } from 'librechat-data-provider';
-import {
- Button,
- Input,
- Label,
- Spinner,
- Checkbox,
- OGDialog,
- OGDialogTemplate,
-} from '@librechat/client';
-import type {
- ScheduledMCPTarget,
- ScheduleMCPConsentView,
- ConfirmScheduleMCPConsent,
-} from 'librechat-data-provider';
+import { Button, Input, Label, Spinner, OGDialog, OGDialogTemplate } from '@librechat/client';
+import type { ScheduleMCPConsentView, ConfirmScheduleMCPConsent } from 'librechat-data-provider';
import type { UseMutationResult, UseQueryResult } from '@tanstack/react-query';
import type { MutableRefObject, ReactNode } from 'react';
import type { TranslationKeys } from '~/hooks';
+import GrantTools, { useGrantChoice } from './GrantTools';
import { useLocalize } from '~/hooks';
/** Where a grant is read and written: a schedule's, or an API key's for one agent. */
@@ -44,81 +32,12 @@ const statusKeys = {
unsupported: 'com_ui_schedule_consent_unsupported',
} as const;
-/** Built-in tools the owner knows by name. Any other, such as an action, is shown by its key. */
-const toolKeys = new Map([
- [Tools.execute_code, 'com_ui_schedule_consent_tool_code'],
- [Tools.web_search, 'com_ui_schedule_consent_tool_web'],
- [Tools.file_search, 'com_ui_schedule_consent_tool_files'],
-]);
-
const messageKeys = {
error: 'com_ui_schedule_consent_error',
revoked: 'com_ui_schedule_consent_revoked',
success: 'com_ui_schedule_consent_confirmed',
} as const;
-/** Every tool on offer for a server, whichever agents selected it. */
-function offeredTools(target: ScheduledMCPTarget): string[] {
- return [...new Set(target.permittedTools.flatMap((selection) => selection.tools))].sort();
-}
-
-/**
- * The owner's starting point: what the stored grant already allows and is still on offer.
- * A tool whose definition changed starts unticked, so allowing the new one is a decision.
- */
-function initialChoice(data: ScheduleMCPConsentView): Record {
- return Object.fromEntries(
- data.targets.map((target) => {
- const offered = offeredTools(target);
- const allowed = data.allowed[target.resource.serverName] ?? [];
- const changed = data.changed[target.resource.serverName] ?? [];
- return [
- target.resource.serverName,
- offered.filter((tool) => allowed.includes(tool) && !changed.includes(tool)),
- ];
- }),
- );
-}
-
-/**
- * The owner's ticks, with the grant they were made against and the tools it marked as
- * changed at the time. A mark belongs to one grant: the same tool marked again under a later
- * grant is a different change, which the owner has not looked at.
- */
-interface Edited {
- choice: Record;
- revision: string | null;
- changed: Record;
-}
-
-/**
- * The owner's ticks, kept to what is on offer now. The offer is read again while the dialog
- * is open: a server or tool the agents dropped has no box left to untick, and a tool marked
- * as changed since the owner last ticked anything, or marked under another grant, loses its
- * tick, so allowing the new definition is something the owner does with the warning in view.
- */
-function currentChoice(
- data: ScheduleMCPConsentView,
- edited: Edited | null,
-): Record {
- const initial = initialChoice(data);
- if (!edited) return initial;
- return Object.fromEntries(
- data.targets.map((target) => {
- const { serverName } = target.resource;
- const offered = offeredTools(target);
- const marked = data.changed[serverName] ?? [];
- const seen = edited.revision === data.revision ? (edited.changed[serverName] ?? []) : [];
- return [
- serverName,
- (edited.choice[serverName] ?? initial[serverName]).filter(
- (tool) => offered.includes(tool) && (!marked.includes(tool) || seen.includes(tool)),
- ),
- ];
- }),
- );
-}
-
/**
* The owner's view of one grant: which MCP servers and tools a run may use while nobody is
* watching. `children` sits above the grant, for whatever picks its subject; `subjectKey`
@@ -179,102 +98,27 @@ function Grant({
const idle = query.fetchStatus === 'idle' && query.data == null && !query.isError;
const [hours, setHours] = useState(1);
const [message, setMessage] = useState<'success' | 'revoked' | 'error' | null>(null);
- /** Null until the owner changes a box, so a refetch cannot overwrite a choice in progress. */
- const [edited, setEdited] = useState(null);
const busy = confirm.isLoading || revoke.isLoading || query.isFetching;
const data: ScheduleMCPConsentView | undefined = query.data;
const choosing = canConfirm && data?.offer != null;
- const choice = data ? currentChoice(data, edited) : {};
- /** Null until the owner changes an "ask me first" box, with the grant it was changed against. */
- const [editedAsking, setEditedAsking] = useState<{
- revision: string | null;
- tools: Record;
- } | null>(null);
- const canAsk = data?.approval === true;
- /**
- * Kept apart from the ticks. Starts from the stored grant, even where a run cannot pause
- * and for a tool that is not ticked right now: one that changed starts unticked, and
- * ticking it again must not turn a tool the owner approves each time into an unattended one.
- * The owner's edits hold only for the grant they were made against: a question added to a
- * grant confirmed elsewhere is not theirs to drop unseen.
- */
- const asking =
- (editedAsking?.revision === data?.revision ? editedAsking?.tools : undefined) ??
- data?.asking ??
- {};
- const noteId = useId();
- const otherId = useId();
- /** Null until the owner changes one of the other tools, with the grant it was changed against. */
- const [editedOther, setEditedOther] = useState<{
- revision: string | null;
- tools: string[];
- } | null>(null);
- /** The agents' tools that are not MCP tools: each one allowed or left out, like an MCP tool. */
- const offeredOther = data?.tools.offered ?? [];
- const other = (
- (editedOther?.revision === data?.revision ? editedOther?.tools : undefined) ??
- data?.tools.allowed ??
- []
- ).filter((tool) => offeredOther.includes(tool));
- /** A grant allows something: an MCP tool, or one of the other tools. */
- const chosenCount =
- Object.values(choice).reduce((count, tools) => count + tools.length, 0) + other.length;
- const setOther = (tools: string[]) => setEditedOther({ revision: data?.revision ?? null, tools });
- /** One click for an owner who trusts the agent as it is: every server, every tool. */
- const allowEverything = () => {
- if (!data) return;
- setEdited({
- choice: Object.fromEntries(
- data.targets.map((target) => [target.resource.serverName, offeredTools(target)]),
- ),
- revision: data.revision,
- changed: data.changed,
- });
- setOther(offeredOther);
- };
- const toolLabel = (tool: string) => {
- const key = toolKeys.get(tool);
- return key ? localize(key) : tool;
- };
- const setTools = (serverName: string, tools: string[]) =>
- setEdited({
- choice: { ...choice, [serverName]: tools },
- revision: data?.revision ?? null,
- changed: data?.changed ?? {},
- });
- const setAsking = (serverName: string, tools: string[]) =>
- setEditedAsking({
- revision: data?.revision ?? null,
- tools: { ...asking, [serverName]: tools },
- });
- /** Sent with the confirmation: of the tools ticked now, the ones the owner asks about. */
- const ask = Object.fromEntries(
- Object.entries(asking)
- .map(([serverName, tools]): [string, string[]] => [
- serverName,
- tools.filter((tool) => (choice[serverName] ?? []).includes(tool)),
- ])
- .filter(([, tools]) => tools.length > 0),
- );
+ const state = useGrantChoice(data);
const commit = () => {
- if (!data?.offer || chosenCount === 0) return;
+ if (!data?.offer || state.count === 0) return;
setMessage(null);
confirm.mutate(
{
offerDigest: data.offer.digest,
expectedRevision: data.revision,
lifetimeHours: hours,
- allow: choice,
+ allow: state.choice,
// Always sent: left out, the server keeps what the stored grant asks about.
- ask,
+ ask: state.ask,
// Likewise: left out, the server keeps the other tools the stored grant allows.
- tools: other,
+ tools: state.other,
},
{
onSuccess: () => {
- setEdited(null);
- setEditedAsking(null);
- setEditedOther(null);
+ state.reset();
setMessage('success');
},
onError: () => setMessage('error'),
@@ -322,126 +166,7 @@ function Grant({
})}
@@ -490,111 +215,3 @@ function Grant({
>
);
}
-
-/** One server's tools: a box for the whole server and one per tool. Unchecked means refused. */
-function ToolChoice({
- serverName,
- offered,
- chosen,
- changed,
- asking,
- askable,
- askNoteId,
- disabled,
- onChange,
- onAskingChange,
-}: {
- serverName: string;
- offered: string[];
- chosen: string[];
- /** Tools the server changed since they were allowed. Refused until confirmed again. */
- changed: string[];
- /** Allowed tools the owner approves call by call. */
- asking: string[];
- /**
- * Tools that get an "ask me first" box. Where a scheduled run cannot pause, only the ones
- * the stored grant already asks about, so the owner can keep or drop them but add none.
- */
- askable: string[];
- /** The note explaining that a run cannot pause here, when it is shown. */
- askNoteId?: string;
- disabled: boolean;
- onChange: (tools: string[]) => void;
- onAskingChange: (tools: string[]) => void;
-}) {
- const localize = useLocalize();
- const groupId = useId();
- /** Checked only when every tool is: the shared box has no partly-selected appearance. */
- const all = offered.length > 0 && offered.every((tool) => chosen.includes(tool));
- return (
-
- );
-}
diff --git a/client/src/components/MCP/GrantTools.tsx b/client/src/components/MCP/GrantTools.tsx
new file mode 100644
index 0000000000..5198040b1a
--- /dev/null
+++ b/client/src/components/MCP/GrantTools.tsx
@@ -0,0 +1,452 @@
+import { useId, useState } from 'react';
+import { Tools } from 'librechat-data-provider';
+import { Label, Button, Checkbox } from '@librechat/client';
+import type { ScheduledMCPTarget, ScheduleMCPConsentView } from 'librechat-data-provider';
+import type { TranslationKeys } from '~/hooks';
+import { useLocalize } from '~/hooks';
+
+/** Built-in tools the owner knows by name. Any other, such as an action, is shown by its key. */
+const toolKeys = new Map([
+ [Tools.execute_code, 'com_ui_schedule_consent_tool_code'],
+ [Tools.web_search, 'com_ui_schedule_consent_tool_web'],
+ [Tools.file_search, 'com_ui_schedule_consent_tool_files'],
+]);
+
+/** Every tool on offer for a server, whichever agents selected it. */
+function offeredTools(target: ScheduledMCPTarget): string[] {
+ return [...new Set(target.permittedTools.flatMap((selection) => selection.tools))].sort();
+}
+
+/**
+ * The owner's starting point: what the stored grant already allows and is still on offer.
+ * A tool whose definition changed starts unticked, so allowing the new one is a decision.
+ */
+function initialChoice(data: ScheduleMCPConsentView): Record {
+ return Object.fromEntries(
+ data.targets.map((target) => {
+ const offered = offeredTools(target);
+ const allowed = data.allowed[target.resource.serverName] ?? [];
+ const changed = data.changed[target.resource.serverName] ?? [];
+ return [
+ target.resource.serverName,
+ offered.filter((tool) => allowed.includes(tool) && !changed.includes(tool)),
+ ];
+ }),
+ );
+}
+
+/**
+ * The owner's ticks, with the grant they were made against and the tools it marked as
+ * changed at the time. A mark belongs to one grant: the same tool marked again under a later
+ * grant is a different change, which the owner has not looked at.
+ */
+interface Edited {
+ choice: Record;
+ revision: string | null;
+ changed: Record;
+}
+
+/**
+ * The owner's ticks, kept to what is on offer now. The offer is read again while the dialog
+ * is open: a server or tool the agents dropped has no box left to untick, and a tool marked
+ * as changed since the owner last ticked anything, or marked under another grant, loses its
+ * tick, so allowing the new definition is something the owner does with the warning in view.
+ */
+function currentChoice(
+ data: ScheduleMCPConsentView,
+ edited: Edited | null,
+): Record {
+ const initial = initialChoice(data);
+ if (!edited) return initial;
+ return Object.fromEntries(
+ data.targets.map((target) => {
+ const { serverName } = target.resource;
+ const offered = offeredTools(target);
+ const marked = data.changed[serverName] ?? [];
+ const seen = edited.revision === data.revision ? (edited.changed[serverName] ?? []) : [];
+ return [
+ serverName,
+ (edited.choice[serverName] ?? initial[serverName]).filter(
+ (tool) => offered.includes(tool) && (!marked.includes(tool) || seen.includes(tool)),
+ ),
+ ];
+ }),
+ );
+}
+
+/** The owner's choice from one offer, and the ways to change it. */
+export interface GrantChoice {
+ /** The MCP tools ticked, by server. */
+ choice: Record;
+ /** The ticked MCP tools the owner approves call by call, by server: what a confirmation sends. */
+ ask: Record;
+ asking: Record;
+ /** The other tools ticked. */
+ other: string[];
+ offeredOther: string[];
+ canAsk: boolean;
+ /** How many tools of either kind are ticked. A grant allows at least one. */
+ count: number;
+ setTools: (serverName: string, tools: string[]) => void;
+ setAsking: (serverName: string, tools: string[]) => void;
+ setOther: (tools: string[]) => void;
+ allowEverything: () => void;
+ /** Back to what the offer starts from, once a choice has been stored. */
+ reset: () => void;
+}
+
+/** The owner's choice from an offer: what is ticked now, starting from what the offer says. */
+export function useGrantChoice(data: ScheduleMCPConsentView | undefined): GrantChoice {
+ /** Null until the owner changes a box, so a refetch cannot overwrite a choice in progress. */
+ const [edited, setEdited] = useState(null);
+ const choice = data ? currentChoice(data, edited) : {};
+ /** Null until the owner changes an "ask me first" box, with the grant it was changed against. */
+ const [editedAsking, setEditedAsking] = useState<{
+ revision: string | null;
+ tools: Record;
+ } | null>(null);
+ const canAsk = data?.approval === true;
+ /**
+ * Kept apart from the ticks. Starts from the stored grant, even where a run cannot pause
+ * and for a tool that is not ticked right now: one that changed starts unticked, and
+ * ticking it again must not turn a tool the owner approves each time into an unattended one.
+ * The owner's edits hold only for the grant they were made against: a question added to a
+ * grant confirmed elsewhere is not theirs to drop unseen.
+ */
+ const asking =
+ (editedAsking?.revision === data?.revision ? editedAsking?.tools : undefined) ??
+ data?.asking ??
+ {};
+ /** Null until the owner changes one of the other tools, with the grant it was changed against. */
+ const [editedOther, setEditedOther] = useState<{
+ revision: string | null;
+ tools: string[];
+ } | null>(null);
+ /** The agents' tools that are not MCP tools: each one allowed or left out, like an MCP tool. */
+ const offeredOther = data?.tools.offered ?? [];
+ const other = (
+ (editedOther?.revision === data?.revision ? editedOther?.tools : undefined) ??
+ data?.tools.allowed ??
+ []
+ ).filter((tool) => offeredOther.includes(tool));
+ /** A grant allows something: an MCP tool, or one of the other tools. */
+ const chosenCount =
+ Object.values(choice).reduce((count, tools) => count + tools.length, 0) + other.length;
+ const setOther = (tools: string[]) => setEditedOther({ revision: data?.revision ?? null, tools });
+ /** One click for an owner who trusts the agent as it is: every server, every tool. */
+ const allowEverything = () => {
+ if (!data) return;
+ setEdited({
+ choice: Object.fromEntries(
+ data.targets.map((target) => [target.resource.serverName, offeredTools(target)]),
+ ),
+ revision: data.revision,
+ changed: data.changed,
+ });
+ setOther(offeredOther);
+ };
+ const setTools = (serverName: string, tools: string[]) =>
+ setEdited({
+ choice: { ...choice, [serverName]: tools },
+ revision: data?.revision ?? null,
+ changed: data?.changed ?? {},
+ });
+ const setAsking = (serverName: string, tools: string[]) =>
+ setEditedAsking({
+ revision: data?.revision ?? null,
+ tools: { ...asking, [serverName]: tools },
+ });
+ /** Sent with the confirmation: of the tools ticked now, the ones the owner asks about. */
+ const ask = Object.fromEntries(
+ Object.entries(asking)
+ .map(([serverName, tools]): [string, string[]] => [
+ serverName,
+ tools.filter((tool) => (choice[serverName] ?? []).includes(tool)),
+ ])
+ .filter(([, tools]) => tools.length > 0),
+ );
+ return {
+ choice,
+ ask,
+ asking,
+ other,
+ offeredOther,
+ canAsk,
+ count: chosenCount,
+ setTools,
+ setAsking,
+ setOther,
+ allowEverything,
+ reset: () => {
+ setEdited(null);
+ setEditedAsking(null);
+ setEditedOther(null);
+ },
+ };
+}
+
+/**
+ * The servers and tools of one offer. While the owner is choosing, each is a box to tick;
+ * otherwise what the stored grant allows is listed.
+ */
+export default function GrantTools({
+ data,
+ choosing,
+ state,
+ busy,
+}: {
+ data: ScheduleMCPConsentView;
+ choosing: boolean;
+ state: GrantChoice;
+ busy: boolean;
+}) {
+ const localize = useLocalize();
+ const noteId = useId();
+ const otherId = useId();
+ const {
+ choice,
+ ask,
+ asking,
+ other,
+ offeredOther,
+ canAsk,
+ setTools,
+ setAsking,
+ setOther,
+ allowEverything,
+ } = state;
+ const toolLabel = (tool: string) => {
+ const key = toolKeys.get(tool);
+ return key ? localize(key) : tool;
+ };
+ return (
+ <>
+ {choosing && !canAsk && Object.keys(ask).length > 0 && (
+
+ )}
+ >
+ );
+}
+
+/** One server's tools: a box for the whole server and one per tool. Unchecked means refused. */
+function ToolChoice({
+ serverName,
+ offered,
+ chosen,
+ changed,
+ asking,
+ askable,
+ askNoteId,
+ disabled,
+ onChange,
+ onAskingChange,
+}: {
+ serverName: string;
+ offered: string[];
+ chosen: string[];
+ /** Tools the server changed since they were allowed. Refused until confirmed again. */
+ changed: string[];
+ /** Allowed tools the owner approves call by call. */
+ asking: string[];
+ /**
+ * Tools that get an "ask me first" box. Where a scheduled run cannot pause, only the ones
+ * the stored grant already asks about, so the owner can keep or drop them but add none.
+ */
+ askable: string[];
+ /** The note explaining that a run cannot pause here, when it is shown. */
+ askNoteId?: string;
+ disabled: boolean;
+ onChange: (tools: string[]) => void;
+ onAskingChange: (tools: string[]) => void;
+}) {
+ const localize = useLocalize();
+ const groupId = useId();
+ /** Checked only when every tool is: the shared box has no partly-selected appearance. */
+ const all = offered.length > 0 && offered.every((tool) => chosen.includes(tool));
+ return (
+
+ );
+}
diff --git a/client/src/components/SidePanel/Schedules/Authorize.tsx b/client/src/components/SidePanel/Schedules/Authorize.tsx
new file mode 100644
index 0000000000..9446057ba3
--- /dev/null
+++ b/client/src/components/SidePanel/Schedules/Authorize.tsx
@@ -0,0 +1,93 @@
+import { useEffect, useId, useState } from 'react';
+import { Input, Label, Button, Spinner } from '@librechat/client';
+import type { ScheduleAuthorization } from 'librechat-data-provider';
+import GrantTools, { useGrantChoice } from '~/components/MCP/GrantTools';
+import { useScheduleMCPOffer } from '~/data-provider/Schedules/consent';
+import { useLocalize } from '~/hooks';
+
+/** What the form needs to know: the owner's choice, and whether one is owed before creating. */
+export interface Authorization {
+ value: ScheduleAuthorization | null;
+ /** There is something to allow, so the schedule is not created until something is. */
+ owed: boolean;
+}
+
+/**
+ * What a schedule may use while its owner is away, chosen as it is created. Mounted per
+ * agent (`key`), so a choice made for one agent is never carried to the next.
+ */
+export default function Authorize({
+ agentId,
+ onChange,
+}: {
+ agentId: string;
+ onChange: (authorization: Authorization) => void;
+}) {
+ const localize = useLocalize();
+ const inputId = useId();
+ const query = useScheduleMCPOffer(agentId);
+ const state = useGrantChoice(query.data);
+ const [hours, setHours] = useState(1);
+ const offer = query.data?.offer ?? null;
+ /** Not while the offer is being read again: its digest is the one just turned down. */
+ const valid =
+ offer != null &&
+ !query.isFetching &&
+ state.count > 0 &&
+ Number.isInteger(hours) &&
+ hours >= 1 &&
+ hours <= offer.maxLifetimeHours;
+ /** Compared by value: the choice is rebuilt on every render, and the form is told on change. */
+ const chosen = valid
+ ? JSON.stringify({
+ offerDigest: offer.digest,
+ lifetimeHours: hours,
+ allow: state.choice,
+ ask: state.ask,
+ tools: state.other,
+ })
+ : null;
+ const owed = offer != null;
+ useEffect(() => {
+ onChange({ value: chosen ? (JSON.parse(chosen) as ScheduleAuthorization) : null, owed });
+ }, [chosen, owed, onChange]);
+
+ if (query.isLoading && query.fetchStatus !== 'idle') return ;
+ if (query.isError)
+ return (
+