Слияние частей A и B этапа 2 (разрешены конфликты: задания, MCP-инструменты, формат ответа категоризации)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -14,8 +14,11 @@ import { instructionsFromFile } from "./mcp.js";
|
||||
import { runInvoiceIngest } from "./invoices-mail.js";
|
||||
import { makePromptLoader } from "./prompt-loader.js";
|
||||
import { accountingSchema } from "./settings.js";
|
||||
import { createSlackPoster } from "./slack.js";
|
||||
import { createSlackClient } from "./slack.js";
|
||||
import { postDailySummary } from "./summary.js";
|
||||
import { runReceiptSearch, runReceiptWeeklyReport } from "./receipt-search.js";
|
||||
import { runReceiptsSlack } from "./receipts.js";
|
||||
import { loadNonWorkdays } from "./workdays.js";
|
||||
|
||||
const { common, service: s } = loadServiceSettings("accounting_automation", accountingSchema);
|
||||
const log = createLogger("accounting_automation", common.logLevel);
|
||||
@@ -30,7 +33,7 @@ const claude = makeClaudeRunner({
|
||||
});
|
||||
const auth = s.google ? new GoogleAuth({ client_email: s.google.client_email, private_key: s.google.private_key }) : null;
|
||||
const drive = auth && s.google?.rootFolderId ? new DriveClient({ auth, rootFolderId: s.google.rootFolderId }) : null;
|
||||
const slack = s.slack ? createSlackPoster({ botToken: s.slack.botToken }) : null;
|
||||
const slack = s.slack ? createSlackClient({ botToken: s.slack.botToken }) : null;
|
||||
|
||||
const notify = async (text: string): Promise<void> => {
|
||||
if (slack && s.slack) await slack.post(s.slack.accountingChannelId, text).catch((e) => log.error({ err: String(e) }, "slack"));
|
||||
@@ -45,10 +48,7 @@ async function realmId(): Promise<string> {
|
||||
return rows[0].realm_id as string;
|
||||
}
|
||||
|
||||
async function nonWorkdays(): Promise<ReadonlySet<string>> {
|
||||
const { rows } = await pool.query("select to_char(day, 'YYYY-MM-DD') as d from calendar_day where not is_workday");
|
||||
return new Set(rows.map((r) => r.d as string));
|
||||
}
|
||||
const nonWorkdays = (): Promise<ReadonlySet<string>> => loadNonWorkdays(pool);
|
||||
|
||||
let mcpInstructions: string | undefined;
|
||||
try {
|
||||
@@ -76,7 +76,7 @@ const app = buildApi({
|
||||
});
|
||||
return runInvoiceIngest({ pool, mail, drive, claude, now: () => new Date(), log });
|
||||
},
|
||||
finalize: () => runFinalize({ pool, delaySeconds: s.finalizeDelaySeconds, notify }),
|
||||
finalize: () => runFinalize({ pool, delaySeconds: s.finalizeDelaySeconds, noReceiptLimitUsd: s.receipts.noReceiptLimitUsd, notify }),
|
||||
categorize: async () =>
|
||||
runCategorization({
|
||||
pool,
|
||||
@@ -101,6 +101,25 @@ const app = buildApi({
|
||||
const text = await postDailySummary({ pool, slack, channelId: s.slack.accountingChannelId, tz: "Asia/Nicosia", options: { nonWorkdays: await nonWorkdays() } });
|
||||
return { sent: true, length: text.length };
|
||||
},
|
||||
"receipts-slack": async () => {
|
||||
if (!slack || !drive) throw new Error("не настроены slack (botToken) и google (ключ сервисного аккаунта, rootFolderId)");
|
||||
return runReceiptsSlack({
|
||||
pool, slack, drive, claude, now: () => new Date(), log,
|
||||
options: { lookbackHours: s.receipts.lookbackHours, senderPersonIds: s.receipts.senderPersonIds },
|
||||
});
|
||||
},
|
||||
"receipt-search": async () => {
|
||||
if (!slack) throw new Error("не настроен slack (botToken, accountingChannelId)");
|
||||
const r = s.receipts;
|
||||
return runReceiptSearch({
|
||||
pool, slack, now: () => new Date(), log, nonWorkdays,
|
||||
options: { tz: r.tz, graceWorkdays: r.graceWorkdays, escalationWorkdays: r.escalationWorkdays, subscriptionVendors: r.subscriptionVendors, qboBankingUrl: r.qboBankingUrl },
|
||||
});
|
||||
},
|
||||
"receipt-weekly-report": async () => {
|
||||
if (!slack || !s.slack) throw new Error("не настроен slack (botToken, accountingChannelId)");
|
||||
return runReceiptWeeklyReport({ pool, slack, now: () => new Date(), fallbackChannelId: s.slack.accountingChannelId });
|
||||
},
|
||||
},
|
||||
});
|
||||
await app.listen({ host: s.http.host, port: s.http.port });
|
||||
|
||||
Reference in New Issue
Block a user