Files
web_app/src/core/ChatClientMock.js
2026-02-23 09:08:15 +03:00

36 lines
1.3 KiB
JavaScript

export class ChatClientMock {
async sendMessage(payload) {
const taskId = `task-${Date.now()}`;
await new Promise((resolve) => setTimeout(resolve, 400));
const text = payload.message.trim();
if (text.startsWith("/changeset")) {
const raw = text.slice("/changeset".length).trim();
const parsed = JSON.parse(raw);
return { task_id: taskId, status: "done", result_type: "changeset", changeset: parsed.changeset || [] };
}
if (text.startsWith("/demo-update ")) {
const path = text.replace("/demo-update ", "").trim();
const file = payload.files.find((f) => f.path === path);
if (!file) {
return { task_id: taskId, status: "done", result_type: "answer", answer: `Файл ${path} не найден.` };
}
const proposed = `${file.content}\n// demo update from mock agent\n`;
return {
task_id: taskId,
status: "done",
result_type: "changeset",
changeset: [{ op: "update", path, base_hash: file.content_hash, proposed_content: proposed, reason: "Demo change" }]
};
}
return {
task_id: taskId,
status: "done",
result_type: "answer",
answer: "Mock-агент активен. Используйте /changeset {json} или /demo-update <path>."
};
}
}