delegate_task takes a task_id to hand over a task already on a list: it moves to the worker (a workspace's task stays on its list), goes to doing, and the job is linked back so its end is noted on the task. hand_over_schedule moves a bot's own routine to another bot, keeping its workspace. Users get Hand over in the Tasks UI and both routine lists. Co-Authored-By: Claude Opus 5.5 <[email protected]>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import AppError from "./app-error";
|
|
|
|
type Params = {
|
|
/**
|
|
* The workspace the task's list or the routine belongs to now; none
|
|
* for a bot's own.
|
|
*/
|
|
workspace_id?: number | string | null;
|
|
/**
|
|
* The workspace asked for, if any.
|
|
*/
|
|
asked_workspace_id?: number | string | null;
|
|
/**
|
|
* What is handed over, for the refusal ("Task #4").
|
|
*/
|
|
label: string;
|
|
};
|
|
|
|
/**
|
|
* Where handed-over work runs from now: a task on a workspace's list or a
|
|
* routine in a workspace stays in that workspace, and asking for another
|
|
* is refused; a bot's own goes to the asked workspace, or the new bot's
|
|
* own chat (null).
|
|
*/
|
|
export default function handOverPlace({ workspace_id, asked_workspace_id, label }: Params): number | null {
|
|
if (workspace_id) {
|
|
if (asked_workspace_id && Number(asked_workspace_id) != Number(workspace_id)) {
|
|
throw new AppError(`${label} belongs to workspace ${workspace_id}, and stays there. Leave workspace_id out.`);
|
|
}
|
|
|
|
return Number(workspace_id);
|
|
}
|
|
|
|
return asked_workspace_id ? Number(asked_workspace_id) : null;
|
|
}
|