Add Start and Discuss buttons to lead suggestions
This commit is contained in:
+5
-1
@@ -218,7 +218,7 @@ export interface paths {
|
||||
};
|
||||
get: operations["listTasks"];
|
||||
put?: never;
|
||||
/** @description Creates the task's branch and worktree from the project's default branch, or with workflow, starts a run of that workflow from it. */
|
||||
/** @description Creates the task's branch and worktree from the project's default branch, and with prompt starts its agent, or with workflow, starts a run of that workflow from it. */
|
||||
post: operations["createTask"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
@@ -1097,6 +1097,10 @@ export interface components {
|
||||
};
|
||||
TaskCreate: {
|
||||
title: string;
|
||||
/** @description Starts the task's agent with this as its first message, in the same request. Not with workflow. */
|
||||
prompt?: string;
|
||||
/** @description The agent's model when prompt is given. */
|
||||
model?: string;
|
||||
/** @description The name of a saved workflow to run instead of creating one task with no agent: each stage with no after stages becomes its own task, titled "<title>: <stage>", with the title as the run's brief. The response is the first of those tasks. */
|
||||
workflow?: string;
|
||||
};
|
||||
|
||||
@@ -339,6 +339,14 @@ function link(href: string, children: Node[]): Node {
|
||||
return h("span", {}, ...children);
|
||||
}
|
||||
}
|
||||
const suggest = /^#\/suggest\/(\w+)\/([^/]+)\/(.+)$/.exec(href);
|
||||
if (suggest) {
|
||||
try {
|
||||
return todoLink(suggest[1]!, decodeURIComponent(suggest[2]!), children, decodeURIComponent(suggest[3]!));
|
||||
} catch {
|
||||
return h("span", {}, ...children);
|
||||
}
|
||||
}
|
||||
if (href.startsWith("#/")) {
|
||||
return h("a", { href }, ...children);
|
||||
}
|
||||
|
||||
+36
-14
@@ -1,12 +1,16 @@
|
||||
import { post } from "./api.js";
|
||||
import { errorText, h, replace, showAlert } from "./dom.js";
|
||||
import { currentSession, focusTask, state } from "./state.js";
|
||||
import { currentLead, currentSession, focusTask, state } from "./state.js";
|
||||
import { taskStyle } from "./taskcolor.js";
|
||||
|
||||
const starting = new Set<string>();
|
||||
const busy = new Map<string, string>();
|
||||
|
||||
export function todoLink(projectId: string, title: string, children: Node[]): HTMLElement {
|
||||
return h("span", { class: "todo-link", data: { project: projectId, title } }, h("span", { class: "todo-title" }, ...children), " ", h("span", { class: "todo-action" }));
|
||||
export function todoLink(projectId: string, title: string, children: Node[], brief?: string): HTMLElement {
|
||||
const data: Record<string, string> = { project: projectId, title };
|
||||
if (brief !== undefined) {
|
||||
data["brief"] = brief;
|
||||
}
|
||||
return h("span", { class: "todo-link", data }, h("span", { class: "todo-title" }, ...children), " ", h("span", { class: "todo-action" }));
|
||||
}
|
||||
|
||||
export function fillTodoLinks(root: ParentNode, model: string): void {
|
||||
@@ -18,9 +22,10 @@ export function fillTodoLinks(root: ParentNode, model: string): void {
|
||||
function fill(el: HTMLElement, model: string): void {
|
||||
const projectId = el.dataset["project"]!;
|
||||
const title = el.dataset["title"]!;
|
||||
const brief = el.dataset["brief"];
|
||||
const action = el.querySelector<HTMLElement>(".todo-action")!;
|
||||
const titleEl = el.querySelector<HTMLElement>(".todo-title")!;
|
||||
const task = (state.tasks.get(projectId) ?? []).find((t) => t.status === "active" && t.todo_item === title);
|
||||
const task = (state.tasks.get(projectId) ?? []).find((t) => t.status === "active" && (brief === undefined ? t.todo_item === title : t.title === title));
|
||||
|
||||
if (task) {
|
||||
const sess = currentSession(task.id);
|
||||
@@ -48,21 +53,38 @@ function fill(el: HTMLElement, model: string): void {
|
||||
el.removeAttribute("style");
|
||||
titleEl.classList.remove("task-name");
|
||||
const key = `${projectId}\n${title}`;
|
||||
const busy = starting.has(key);
|
||||
const start = async (discuss: boolean) => {
|
||||
starting.add(key);
|
||||
const label = busy.get(key);
|
||||
const run = async (busyLabel: string, act: () => Promise<unknown>) => {
|
||||
busy.set(key, busyLabel);
|
||||
fill(el, model);
|
||||
try {
|
||||
await post("/api/projects/{projectId}/todo/tasks", { path: { projectId }, body: { title, model, discuss } });
|
||||
await act();
|
||||
} catch (err) {
|
||||
void showAlert(errorText(err));
|
||||
}
|
||||
starting.delete(key);
|
||||
busy.delete(key);
|
||||
fill(el, model);
|
||||
};
|
||||
const startButton = h("button", { disabled: busy, title: "Start a task that gets straight to work" }, busy ? "starting…" : "start");
|
||||
startButton.onclick = () => void start(false);
|
||||
const discussButton = h("button", { disabled: busy, title: "Start a task that discusses it with you in chat before building anything" }, "discuss");
|
||||
discussButton.onclick = () => void start(true);
|
||||
|
||||
if (brief === undefined) {
|
||||
const start = (discuss: boolean) => run(discuss ? "discuss" : "start", () => post("/api/projects/{projectId}/todo/tasks", { path: { projectId }, body: { title, model, discuss } }));
|
||||
const startButton = h("button", { disabled: !!label, title: "Start a task that gets straight to work" }, label === "start" ? "starting…" : "start");
|
||||
startButton.onclick = () => void start(false);
|
||||
const discussButton = h("button", { disabled: !!label, title: "Start a task that discusses it with you in chat before building anything" }, label === "discuss" ? "starting…" : "discuss");
|
||||
discussButton.onclick = () => void start(true);
|
||||
replace(action, startButton, discussButton);
|
||||
return;
|
||||
}
|
||||
|
||||
const startButton = h("button", { disabled: !!label, title: "Start a task with the lead's brief" }, label === "start" ? "starting…" : "start");
|
||||
startButton.onclick = () =>
|
||||
void run("start", () => post("/api/projects/{projectId}/tasks", { path: { projectId }, body: { title, prompt: brief, model } }));
|
||||
const discussButton = h("button", { disabled: !!label, title: "Ask your lead to talk it over in chat" }, label === "discuss" ? "sending…" : "discuss");
|
||||
discussButton.onclick = () =>
|
||||
void run("discuss", () => {
|
||||
const lead = currentLead();
|
||||
const live = lead !== undefined && lead.state !== "completed";
|
||||
return post("/api/me/lead/messages", { body: { text: `Let's discuss your suggestion "${title}" before starting it:\n\n${brief}`, model: live ? undefined : model } });
|
||||
});
|
||||
replace(action, startButton, discussButton);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user