Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/src/components/approvals/bot-rules.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { IconChecklist } from "@/components/icons";
import { useMutation, useQuery } from "@tanstack/react-query";
import { Link } from "@tanstack/react-router";
import { Fragment } from "react";
import { IconChecklist } from "@/components/icons";
import {
PageEmpty,
PageRows,
PageSection,
} from "@/components/layout/page-shell";
import { Separator } from "@/components/ui/separator";
import {
approvalInboxOptions,
approvalSettingsOptions,
createApprovalRuleMutationOptions,
revokeApprovalRuleMutationOptions,
ruleCoversBot,
Expand All @@ -25,7 +25,7 @@ import { RuleForm, RuleRow } from "./rules";
* `botId` is the Bot's id, or a pattern covering it.
*/
export function BotApprovalRules({ agentId }: { agentId: string }) {
const inbox = useQuery(approvalInboxOptions());
const inbox = useQuery(approvalSettingsOptions());
const addRule = useMutation(createApprovalRuleMutationOptions(queryClient));
const changeRule = useMutation(
updateApprovalRuleMutationOptions(queryClient),
Expand Down
10 changes: 5 additions & 5 deletions app/src/components/approvals/conversation-allowances.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { approvalPhrase } from "@openbot/shared/tool-name";
import { IconCircleCheck } from "@/components/icons";
import { useMutation, useQuery } from "@tanstack/react-query";
import { IconCircleCheck } from "@/components/icons";
import { Button } from "@/components/ui/button";
import {
type ActionKind,
approvalInboxOptions,
type ConversationGrant,
conversationGrantsOptions,
revokeConversationGrantMutationOptions,
} from "@/lib/approvals";
import { queryClient } from "@/query-client";
import { failureSaid } from "@/lib/load-failure";
import { queryClient } from "@/query-client";

/** A kind of action, as the start of a sentence about where it is allowed. */
const KIND_WORDS: Record<ActionKind, string> = {
Expand Down Expand Up @@ -44,11 +44,11 @@ function allowedWords(grant: ConversationGrant): string {
* allowed here.
*/
export function ConversationAllowances({ threadId }: { threadId: string }) {
const inbox = useQuery(approvalInboxOptions());
const inbox = useQuery(conversationGrantsOptions());
const revoke = useMutation(
revokeConversationGrantMutationOptions(queryClient),
);
const grants = (inbox.data?.conversationGrants ?? []).filter(
const grants = (inbox.data ?? []).filter(
(grant) => grant.threadId === threadId,
);
if (grants.length === 0) return null;
Expand Down
10 changes: 5 additions & 5 deletions app/src/components/approvals/inline-approval.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { settingsApprovalBodyFor } from "@/components/settings-tools/settings-to
import {
type ApprovalDecision,
type ApprovalRequest,
approvalInboxOptions,
approvalQueueOptions,
conversationApprovalsQueryOptions,
decideApproval,
} from "@/lib/approvals";
Expand Down Expand Up @@ -79,13 +79,13 @@ const CHOICE_WORDS: Record<
* The requests a conversation's cards and answered lines are drawn from: the inbox, and the
* conversation's own list.
*
* The inbox is read again every few seconds, so a decision made on the Approvals page shows here
* too, but it keeps only the person's last hundred, across every conversation. In an older
* The inbox is read again when the server says it changed, so a decision made on the Approvals page
* shows here too, but it keeps only the person's last hundred, across every conversation. In an older
* conversation those were all elsewhere and its answered lines never showed. The conversation's own
* list reaches back past them. Where both hold a request, the inbox's copy is the newer.
*/
function useRequestsHere(): ApprovalRequest[] {
const inbox = useQuery(approvalInboxOptions());
const inbox = useQuery(approvalQueueOptions());
// The conversation this is drawn in, where it is drawn in one.
const threadId = useCopilotChatConfiguration()?.threadId;
const here = useQuery({
Expand Down Expand Up @@ -270,7 +270,7 @@ export function InlineApproval({
* the sheet draws them too. The same card, from the same inbox, so answering either answers both.
*/
export function ConversationApprovals({ threadId }: { threadId: string }) {
const inbox = useQuery(approvalInboxOptions());
const inbox = useQuery(approvalQueueOptions());
const ids = (inbox.data?.requests ?? []).flatMap((request) =>
request.status === "pending" &&
request.action.threadId === threadId &&
Expand Down
12 changes: 6 additions & 6 deletions app/src/components/approvals/question-notice.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Message } from "@ag-ui/core";
import { IconX } from "@/components/icons";
import { useMutation, useQuery } from "@tanstack/react-query";
import { useState } from "react";
import { BotOrb } from "@/components/agents/bot-orb";
import { IconX } from "@/components/icons";
import { Button } from "@/components/ui/button";
import {
Questionnaire,
Expand All @@ -19,15 +19,15 @@ import {
QuestionnaireTitle,
} from "@/components/ui/questionnaire";
import {
type ApprovalInboxData,
approvalInboxOptions,
type ApprovalQueueData,
approvalQueueOptions,
dismissPersonQuestionMutationOptions,
} from "@/lib/approvals";
import { type Failure, failureSaid } from "@/lib/load-failure";
import { ANSWER_PREFIX } from "@/lib/question-answer";
import { queryClient } from "@/query-client";

export type WaitingQuestion = ApprovalInboxData["questions"][number];
export type WaitingQuestion = ApprovalQueueData["questions"][number];

/**
* The question this conversation's Bot is waiting on, if one is: the newest open question asked in
Expand All @@ -37,13 +37,13 @@ export function useConversationQuestion(
channelId: string,
threadId: string,
): WaitingQuestion | undefined {
const inbox = useQuery(approvalInboxOptions());
const inbox = useQuery(approvalQueueOptions());
return conversationQuestion(inbox.data, channelId, threadId);
}

/** The newest open question asked in this conversation, from an inbox read. */
export function conversationQuestion(
inbox: ApprovalInboxData | undefined,
inbox: ApprovalQueueData | undefined,
channelId: string,
threadId: string,
): WaitingQuestion | undefined {
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/approvals/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { Separator } from "@/components/ui/separator";
import { Switch } from "@/components/ui/switch";
import { agentListQueryOptions } from "@/lib/agents/queries";
import {
approvalInboxOptions,
approvalPreferencesMutationOptions,
approvalSettingsOptions,
createApprovalRuleMutationOptions,
revokeApprovalRuleMutationOptions,
ruleCoversBot,
Expand All @@ -46,7 +46,7 @@ import { HOST_LABELS, LabelSelect, RuleForm, RuleRow } from "./rules";
* administrators change them in Admin → Approvals. Rules for a single Bot are on that Bot's page.
*/
export function ApprovalSettings() {
const inbox = useQuery(approvalInboxOptions());
const inbox = useQuery(approvalSettingsOptions());
const me = useQuery(currentUserQueryOptions()).data;
// The personal edition has no team for team settings to govern, so no team rules to point at.
const personal =
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/approvals/team-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Switch } from "@/components/ui/switch";
import {
type ActionKind,
type ActionKindPolicy,
approvalInboxOptions,
approvalSettingsOptions,
createTeamApprovalRuleMutationOptions,
revokeTeamApprovalRuleMutationOptions,
teamApprovalSettingsMutationOptions,
Expand Down Expand Up @@ -81,7 +81,7 @@ const ACTION_KIND_LABELS: Record<ActionKindPolicy, string> = {
* Settings → Approvals.
*/
export function TeamApprovalSettings() {
const inbox = useQuery(approvalInboxOptions());
const inbox = useQuery(approvalSettingsOptions());
const guidance = useQuery(reviewerGuidanceQueryOptions());
const team = useMutation(teamApprovalSettingsMutationOptions(queryClient));
const addTeamRule = useMutation(
Expand Down
10 changes: 5 additions & 5 deletions app/src/components/approvals/waiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ import { useBotNames } from "@/lib/agents/bot-names";
import { agentListQueryOptions } from "@/lib/agents/queries";
import {
type ApprovalDecision,
type ApprovalInboxData,
type ApprovalQueueData,
answerPersonQuestionMutationOptions,
approvalInboxOptions,
approvalQueueOptions,
decideApprovalMutationOptions,
dismissPersonQuestionMutationOptions,
} from "@/lib/approvals";
Expand All @@ -70,16 +70,16 @@ import type { WaitingWhere } from "@/lib/tasks/groups";
import { cn } from "@/lib/utils";
import { queryClient } from "@/query-client";

type WaitingQuestion = ApprovalInboxData["questions"][number];
type WaitingRequest = ApprovalInboxData["requests"][number];
type WaitingQuestion = ApprovalQueueData["questions"][number];
type WaitingRequest = ApprovalQueueData["requests"][number];

/**
* What waits on the person in the approval inbox, for one Bot or for all of them: the questions its
* Bots asked, and the actions waiting on a decision. A question asked during a hand-off belongs to
* the Bot whose conversation it is.
*/
function useWaiting(agentId: string | undefined) {
const inbox = useQuery(approvalInboxOptions());
const inbox = useQuery(approvalQueueOptions());
const ours = (botId: string) => agentId === undefined || botId === agentId;
return {
error: inbox.error,
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/bot-profile/settings-rows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
sharingSummary,
} from "@/lib/agents/bot-summaries";
import type { AgentProfile } from "@/lib/agents/queries";
import { approvalInboxOptions, ruleCoversBot } from "@/lib/approvals";
import { approvalSettingsOptions, ruleCoversBot } from "@/lib/approvals";
import { currentUserQueryOptions } from "@/lib/auth/queries";
import { isOrganizationAdmin } from "@/lib/auth/roles";
import { destinationsQueryOptions } from "@/lib/delivery";
Expand Down Expand Up @@ -80,7 +80,7 @@ export function BotSettingsRows({ agent }: { agent: AgentProfile }) {
const checkIns = useQuery(proactiveSettingsQueryOptions());
const sources = useQuery({ ...memorySourcesQueryOptions(), enabled: memory });
const plugins = useBotPlugins(agent.id);
const approvals = useQuery(approvalInboxOptions());
const approvals = useQuery(approvalSettingsOptions());
const teamBots = useQuery({ ...teamBotsQueryOptions(), enabled: !personal });
const reach = useQuery({
...destinationsQueryOptions(),
Expand Down
32 changes: 14 additions & 18 deletions app/src/components/channels/channel-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ import { BOT_KEY_REFUSED } from "@/lib/agents/key-link";
import { agentListQueryOptions } from "@/lib/agents/queries";
import {
answerPersonQuestionMutationOptions,
approvalInboxOptions,
carryingOnAfterApproval,
approvalQueueOptions,
approvalsWaiting,
type LeftCall,
leftAnswers,
leftInConversation,
stoppedOnLeft,
useCarryingOnAfterApproval,
withLeftAnswers,
} from "@/lib/approvals";
import { useBotTakesModelChoice } from "@/lib/bot-agents/queries";
Expand Down Expand Up @@ -1832,18 +1833,12 @@ export function ChannelChat({
* the Bot went on working: found on the Mac, after Allow once on a Google Maps step.
*
* Read from the approval itself, which the server marks `completed` only once that turn has ended,
* so it is the same record whichever tab or device decided it. Polled faster while it is going, so
* the conversation stops saying it is working soon after it is done.
* so it is the same record whichever tab or device decided it. Not polled: the server announces the
* decision and the end (its `approvals` hint), and the queue is read again on each. The
* conversation's work (`carriedByServer` below) does not list this turn: the server lists only a
* turn it carries on its own queue, which an approval's carry-on joins only when handed on.
*/
const carryingOn =
useQuery({
...approvalInboxOptions(),
select: (inbox) => carryingOnAfterApproval(inbox, channel.threadId),
refetchInterval: (query) =>
carryingOnAfterApproval(query.state.data, channel.threadId)
? 2_000
: 10_000,
}).data === true;
const carryingOn = useCarryingOnAfterApproval(channel.threadId);
/*
* When the server's turn ends, what it wrote is read, whether or not the roster says the Bot
* replied. A turn the person stopped has no reply to announce, and what it said before the Stop
Expand All @@ -1863,8 +1858,8 @@ export function ChannelChat({
*/
const leftCalls =
useQuery({
...approvalInboxOptions(),
select: (inbox) => leftInConversation(inbox, channel.threadId),
...approvalQueueOptions(),
select: (queue) => leftInConversation(queue, channel.threadId),
}).data ?? NO_CALLS;

/*
Expand Down Expand Up @@ -2134,7 +2129,7 @@ export function ChannelChat({
const repaired = repairUnansweredToolCalls(
target.messages,
undefined,
leftAnswers(queryClient.getQueryData(approvalInboxOptions().queryKey)),
leftAnswers(queryClient.getQueryData(approvalQueueOptions().queryKey)),
);
if (repaired !== target.messages) {
target.setMessages(repaired as typeof target.messages);
Expand Down Expand Up @@ -2807,7 +2802,8 @@ export function ChannelChat({
// And a run that ended on a question to the person, the same way.
askedSinceLastMessage(agent.messages)
)
void queryClient.invalidateQueries({ queryKey: ["approvals"] });
// What waits on the person; their settings did not move.
void queryClient.invalidateQueries(approvalsWaiting);
const wasOurs = awaitingReply.current;
awaitingReply.current = false;
/*
Expand Down Expand Up @@ -2862,7 +2858,7 @@ export function ChannelChat({
if (question || !askedSinceLastMessage(agentRef.current.messages))
return question;
const inbox = await queryClient
.fetchQuery({ ...approvalInboxOptions(), staleTime: 0 })
.fetchQuery({ ...approvalQueueOptions(), staleTime: 0 })
.catch(() => undefined);
return conversationQuestion(inbox, channel.id, channel.threadId);
};
Expand Down
15 changes: 8 additions & 7 deletions app/src/components/channels/group-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
} from "@/components/ui/message";
import { agentListQueryOptions } from "@/lib/agents/queries";
import {
type ApprovalInboxData,
type ApprovalQueueData,
answerPersonQuestionMutationOptions,
approvalInboxOptions,
approvalQueueOptions,
} from "@/lib/approvals";
import { currentUserQueryOptions } from "@/lib/auth/queries";
import {
Expand Down Expand Up @@ -78,7 +78,7 @@ export function GroupChat({ channelId }: { channelId: string }) {
(message) => message.status === "running" || message.status === "queued",
);

const inbox = useQuery(approvalInboxOptions());
const inbox = useQuery(approvalQueueOptions());
const question = groupQuestion(inbox.data, channelId);
// The Bot whose conversation it is: for a hand-off, the one that handed the work on.
const askerId = question?.conversationBotId ?? question?.botId;
Expand All @@ -94,14 +94,15 @@ export function GroupChat({ channelId }: { channelId: string }) {
});
};
/*
* The inbox is read every 10 s, and a Bot that asks ends its turn on the question. Read again the
* moment the Bots stop, so the question is above the composer when the reply that asks it is.
* The inbox is read again on the server's word that it changed, and a Bot that asks ends its turn
* on the question. Read again the moment the Bots stop too, so the question is above the composer
* when the reply that asks it is, whichever arrives first.
*/
const wasWorking = useRef(working);
useEffect(() => {
if (wasWorking.current && !working)
void queryClient.invalidateQueries({
queryKey: approvalInboxOptions().queryKey,
queryKey: approvalQueueOptions().queryKey,
});
wasWorking.current = working;
}, [working, queryClient]);
Expand Down Expand Up @@ -292,7 +293,7 @@ export function GroupChat({ channelId }: { channelId: string }) {
* thread of its own, so it is found by the conversation, not by a thread.
*/
export function groupQuestion(
inbox: ApprovalInboxData | undefined,
inbox: ApprovalQueueData | undefined,
channelId: string,
): WaitingQuestion | undefined {
return inbox?.questions.find((question) => question.channelId === channelId);
Expand Down
4 changes: 2 additions & 2 deletions app/src/components/computer/use-cards-first.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import { useEffect, useRef } from "react";
import { approvalInboxOptions } from "@/lib/approvals";
import { approvalQueueOptions } from "@/lib/approvals";
import { useComputerControl } from "@/lib/computers/use-control";
import {
FINAL_SIGN_IN,
Expand Down Expand Up @@ -48,7 +48,7 @@ export function useCardsFirst({
botId ?? "",
Boolean(botId) && computers,
);
const inbox = useQuery(approvalInboxOptions());
const inbox = useQuery(approvalQueueOptions());
const signIns = useQuery({
...pendingSignInRequestsQueryOptions(),
enabled: covers && Boolean(threadId),
Expand Down
Loading
Loading