Слияние частей A и B этапа 2 (разрешены конфликты: задания, MCP-инструменты, формат ответа категоризации)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import type { FastifyInstance } from "fastify";
|
||||
import { withTx, type Pool } from "khb_common";
|
||||
import { createMcpAuth, McpAuthError, type JwtVerifier } from "./mcp-auth.js";
|
||||
import { REVIEW_UI_HTML, REVIEW_UI_MIME, REVIEW_UI_URI, REVIEW_UI_URI_LEGACY, rowsToMarkdown, toRow } from "./mcp-ui.js";
|
||||
import { allowWithoutReceipt } from "./receipt-search.js";
|
||||
import type { AccountingSettings } from "./settings.js";
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,8 @@ export class McpToolError extends Error {}
|
||||
export interface ReviewDeps {
|
||||
pool: Pool;
|
||||
settings: Pick<AccountingSettings, "reviewers">;
|
||||
/** Лимит расхода без чека (USD), по умолчанию 500. */
|
||||
noReceiptLimitUsd?: number;
|
||||
now?: () => Date;
|
||||
}
|
||||
|
||||
@@ -392,6 +395,26 @@ export class ReviewTools {
|
||||
});
|
||||
}
|
||||
|
||||
/** acc_receipt_allow_without: Анастасия разрешает провести расход без чека (процесс «Поиск чека», шаг 8). */
|
||||
async allowWithoutReceipt(personId: string, a: Json): Promise<Json> {
|
||||
const roles = this.rolesOf(personId);
|
||||
if (!roles.includes("cfo")) throw new McpToolError("Разрешить расход без чека может только роль cfo (Анастасия).");
|
||||
const id = await this.id(a);
|
||||
if (typeof a.reason !== "string" || !a.reason.trim()) throw new McpToolError("reason: нужна причина (почему чек не найден)");
|
||||
const t = (await this.d.pool.query("select * from acc_manual_review where id = $1", [id])).rows[0] as Task | undefined;
|
||||
if (!t) throw new McpToolError("Задача не найдена (возможно, уже завершена и удалена из очереди).");
|
||||
let feed: string | null = null;
|
||||
if (t.ref_table === "acc_categorization_review") feed = t.ref_id;
|
||||
else if (t.ref_table === "acc_receipt_search") feed = ((await this.d.pool.query("select feed_txn_id from acc_receipt_search where id::text = $1", [t.ref_id])).rows[0]?.feed_txn_id as string | undefined) ?? null;
|
||||
if (!feed) throw new McpToolError("Задача не относится к операции банка (нужна задача вида categorization или receipt_search).");
|
||||
try {
|
||||
const r = await allowWithoutReceipt(this.d.pool, personId, feed, a.reason, this.d.noReceiptLimitUsd ?? 500, this.now());
|
||||
return { ok: true, amount: r.amount, message: "Разрешено провести без чека. Проведите операцию в QuickBooks с пометкой «чек не найден, причина» в Private note, затем отметьте задачу выполненной." };
|
||||
} catch (e) {
|
||||
throw new McpToolError(e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
}
|
||||
|
||||
/** Полный uuid или префикс (от 8 символов) id задачи, как в таблице списка. */
|
||||
private async resolveId(v: unknown): Promise<string> {
|
||||
if (typeof v !== "string") throw new McpToolError("нужно поле id: первые 8 символов (или полный uuid) задачи из таблицы acc_review_list");
|
||||
@@ -445,6 +468,7 @@ export class ReviewTools {
|
||||
case "acc_review_snooze": return this.snooze(personId, a);
|
||||
case "acc_invoice_to_approve": return this.invoiceToApprove(personId, a);
|
||||
case "acc_invoice_decide": return this.invoiceDecide(personId, a);
|
||||
case "acc_receipt_allow_without": return this.allowWithoutReceipt(personId, a);
|
||||
default: throw new McpToolError(`Неизвестный инструмент ${name}`);
|
||||
}
|
||||
}
|
||||
@@ -499,6 +523,13 @@ export const TOOLS: { name: string; description: string; inputSchema: Json; anno
|
||||
description: "Вернуть задачу в общую очередь (роль accountant) с причиной; причина записывается в problem_highlight, отложенность снимается.",
|
||||
inputSchema: obj({ id: idP, reason: { type: "string", description: "причина возврата" } }, ["id", "reason"]),
|
||||
},
|
||||
{
|
||||
name: "acc_receipt_allow_without",
|
||||
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
||||
description:
|
||||
"Только роль cfo (Анастасия). Разрешить провести расход без чека, когда чек так и не найден (процесс «Поиск чека», шаг 8): только на сумму до $500 и по каждому расходу отдельно; больше $500 без чека не проводится. id - задача операции (categorization или receipt_search). Дальше проведи операцию в QuickBooks с пометкой «чек не найден, причина» в Private note и отметь задачу выполненной.",
|
||||
inputSchema: obj({ id: idP, reason: { type: "string", description: "почему чек не найден" } }, ["id", "reason"]),
|
||||
},
|
||||
{
|
||||
name: "acc_review_batch",
|
||||
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
|
||||
|
||||
Reference in New Issue
Block a user