fix(webui): keep automation creation intent in runtime context

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-13 05:43:05 +08:00
1 parent 037438e7d1
commit 458b925f86
21 files changed
+149 -20

No files matched your search

@@ -176,13 +176,9 @@ export function AutomationsSettings({
images?: SendAttachment[],
options?: SendOptions,
) => onStartChat?.(
tx(
"settings.automations.createRequest",
"Create an automation for this request:\n\n{{request}}",
{ request: content.trim() },
),
content.trim(),
images,
options,
{ ...options, intent: "create_automation" },
activeModelPreset,
);
const filterLabel = filter === "all" ? tx("settings.automations.filter", "Filter") : tx("settings.automations.filteredBy", "Filter: {{status}}", {
+1
View File
@@ -176,6 +176,7 @@ export interface SendAttachment {
}
export interface SendOptions {
intent?: "create_automation";
cliApps?: OutboundCliAppMention[];
mcpPresets?: OutboundMcpPresetMention[];
sessionMentions?: SessionMention[];
-1
View File
@@ -1101,7 +1101,6 @@
"create": "Create automation",
"createPrompt": "What would you like nanobot to automate?",
"createInput": "Describe an automation",
"createRequest": "Create an automation for this request:\n\n{{request}}",
"errors": {
"legacyMissingDestination": "This older automation is missing its delivery destination. Recreate it from the linked chat to continue."
},
-1
View File
@@ -902,7 +902,6 @@
"create": "Crear automatización",
"createPrompt": "¿Qué te gustaría automatizar con nanobot?",
"createInput": "Describe una automatización",
"createRequest": "Crea una automatización para esta solicitud:\n\n{{request}}",
"errors": {
"legacyMissingDestination": "Esta automatización antigua no tiene un destino de entrega. Vuelve a crearla desde el chat vinculado para continuar."
},
-1
View File
@@ -901,7 +901,6 @@
"create": "Créer une automatisation",
"createPrompt": "Que voulez-vous automatiser avec nanobot ?",
"createInput": "Décrire une automatisation",
"createRequest": "Crée une automatisation pour cette demande :\n\n{{request}}",
"errors": {
"legacyMissingDestination": "Cette ancienne automatisation n’a plus de destination. Recréez-la depuis la discussion liée pour continuer."
},
-1
View File
@@ -901,7 +901,6 @@
"create": "Buat otomatisasi",
"createPrompt": "Apa yang ingin kamu otomatisasi dengan nanobot?",
"createInput": "Jelaskan otomatisasi",
"createRequest": "Buat otomatisasi untuk permintaan ini:\n\n{{request}}",
"errors": {
"legacyMissingDestination": "Otomatisasi lama ini tidak memiliki tujuan pengiriman. Buat ulang dari chat terkait untuk melanjutkan."
},
-1
View File
@@ -901,7 +901,6 @@
"create": "自動タスクを作成",
"createPrompt": "nanobot に何を自動化してほしいですか?",
"createInput": "自動タスクを説明",
"createRequest": "次の依頼に対する自動タスクを作成してください:\n\n{{request}}",
"errors": {
"legacyMissingDestination": "この旧形式の自動タスクには送信先がありません。続行するには、関連チャットから作り直してください。"
},
-1
View File
@@ -901,7 +901,6 @@
"create": "자동화 만들기",
"createPrompt": "nanobot이 무엇을 자동으로 해주면 좋을까요?",
"createInput": "자동화 설명",
"createRequest": "다음 요청에 맞는 자동화를 만들어 주세요:\n\n{{request}}",
"errors": {
"legacyMissingDestination": "이전 형식의 자동화에 전송 대상이 없습니다. 계속하려면 연결된 채팅에서 다시 만들어 주세요."
},
-1
View File
@@ -915,7 +915,6 @@
"create": "Criar automação",
"createPrompt": "O que você gostaria de automatizar com o nanobot?",
"createInput": "Descreva uma automação",
"createRequest": "Crie uma automação para esta solicitação:\n\n{{request}}",
"errors": {
"legacyMissingDestination": "Esta automação antiga não tem um destino de entrega. Recrie-a na conversa vinculada para continuar."
},
-1
View File
@@ -901,7 +901,6 @@
"create": "Tạo tự động hóa",
"createPrompt": "Bạn muốn nanobot tự động làm gì?",
"createInput": "Mô tả tác vụ tự động",
"createRequest": "Tạo một tác vụ tự động cho yêu cầu này:\n\n{{request}}",
"errors": {
"legacyMissingDestination": "Tác vụ tự động cũ này thiếu nơi nhận. Hãy tạo lại từ cuộc trò chuyện liên kết để tiếp tục."
},
-1
View File
@@ -1101,7 +1101,6 @@
"create": "创建自动任务",
"createPrompt": "想让 nanobot 自动帮你做什么?",
"createInput": "描述一个自动任务",
"createRequest": "请为以下需求创建自动任务:\n\n{{request}}",
"errors": {
"legacyMissingDestination": "这个旧版自动任务缺少发送目标,无法继续运行。请从关联会话中重新创建该任务。"
},
-1
View File
@@ -901,7 +901,6 @@
"create": "建立自動任務",
"createPrompt": "想讓 nanobot 自動幫你做什麼?",
"createInput": "描述自動任務",
"createRequest": "請為以下需求建立自動任務:\n\n{{request}}",
"errors": {
"legacyMissingDestination": "這個舊版自動任務缺少傳送目標,無法繼續執行。請從關聯對話中重新建立該任務。"
},
+2
View File
@@ -976,6 +976,7 @@ export class NanobotClient {
mcpPresets?: OutboundMcpPresetMention[];
sessionMentions?: SessionMention[];
quotedContext?: string;
intent?: "create_automation";
workspaceScope?: WorkspaceScopePayload | null;
turnId?: string;
/** False for side-channel or injected messages that do not own a lifecycle. */
@@ -995,6 +996,7 @@ export class NanobotClient {
? { session_mentions: options.sessionMentions }
: {}),
...(options?.quotedContext?.trim() ? { quoted_context: options.quotedContext.trim() } : {}),
...(options?.intent === "create_automation" ? { intent: options.intent } : {}),
...(options?.workspaceScope ? { workspace_scope: options.workspaceScope } : {}),
...(options?.turnId ? { turn_id: options.turnId } : {}),
webui: true,
+1
View File
@@ -1602,6 +1602,7 @@ export type Outbound =
mcp_presets?: OutboundMcpPresetMention[];
session_mentions?: SessionMention[];
quoted_context?: string;
intent?: "create_automation";
workspace_scope?: WorkspaceScopePayload;
turn_id?: string;
/** Marks messages sent by the embedded WebUI, without changing the
@@ -490,9 +490,9 @@ describe("Automation task list and detail sheet", () => {
await user.click(screen.getByRole("button", { name: "Send message" }));
expect(onStartChat).toHaveBeenCalledWith(
"Create an automation for this request:\n\nEvery weekday at 9, summarize my open pull requests",
undefined,
"Every weekday at 9, summarize my open pull requests",
undefined,
{ intent: "create_automation" },
"fast",
);
await waitFor(() => expect(composer).toHaveValue(""));
@@ -512,9 +512,9 @@ describe("Automation task list and detail sheet", () => {
await user.type(composer, "Run a deep weekly review");
await user.click(screen.getByRole("button", { name: "Send message" }));
expect(onStartChat).toHaveBeenCalledWith(
"Create an automation for this request:\n\nRun a deep weekly review",
undefined,
"Run a deep weekly review",
undefined,
{ intent: "create_automation" },
"deep",
);
});
+24
View File
@@ -1974,6 +1974,30 @@ describe("NanobotClient", () => {
});
});
it("sends automation intent separately from the user's text", () => {
const client = new NanobotClient({
url: "ws://test",
reconnect: false,
socketFactory: (url) => new FakeSocket(url) as unknown as WebSocket,
});
client.connect();
lastSocket().fakeOpen();
client.sendMessage("chat-x", "每天八点提醒我喝水", undefined, {
intent: "create_automation",
});
expect(JSON.parse(lastSocket().sent.at(-1) as string)).toEqual({
type: "message",
chat_id: "chat-x",
content: "每天八点提醒我喝水",
intent: "create_automation",
webui: true,
});
client.sendMessage("chat-x", "Thanks");
expect(JSON.parse(lastSocket().sent.at(-1) as string)).not.toHaveProperty("intent");
});
it("includes CLI app attachments in outbound messages", () => {
const client = new NanobotClient({
url: "ws://test",
+7
View File
@@ -1608,6 +1608,7 @@ describe("ThreadShell", () => {
id: "automation-first-message",
chatId: "chat-new",
content: "Every weekday at 9, summarize open pull requests",
options: { intent: "create_automation" as const },
};
render(
@@ -1633,6 +1634,12 @@ describe("ThreadShell", () => {
expect(client.sendMessage).toHaveBeenCalledTimes(1);
expect(consumed).toHaveBeenCalledOnce();
expect(consumed).toHaveBeenCalledWith(pendingFirstMessage.id);
expect(client.sendMessage).toHaveBeenCalledWith(
"chat-new",
pendingFirstMessage.content,
undefined,
expect.objectContaining({ intent: "create_automation" }),
);
});
it("keeps the first landing message when new chat history is still empty", async () => {
+18
View File
@@ -2711,6 +2711,24 @@ describe("useNanobotStream", () => {
expect(outbound[3]).not.toHaveProperty("quotedContext");
});
it("keeps automation intent out of the optimistic user message", () => {
const fake = fakeClient();
const { result } = renderHook(() => useNanobotStream("chat-automation", EMPTY_MESSAGES), {
wrapper: wrap(fake.client),
});
act(() => {
result.current.send("每天八点提醒我喝水", undefined, { intent: "create_automation" });
});
expect(result.current.messages[0].content).toBe("每天八点提醒我喝水");
expect(result.current.messages[0]).not.toHaveProperty("intent");
expect(fake.client.sendMessage).toHaveBeenCalledWith(
"chat-automation",
"每天八点提醒我喝水",
undefined,
expect.objectContaining({ intent: "create_automation", turnId: expect.any(String) }),
);
});
it("attaches assistant media_urls to complete messages", () => {
const fake = fakeClient();
const { result } = renderHook(() => useNanobotStream("chat-m", EMPTY_MESSAGES), {