accounting_automation: этап 1 бухгалтерской автоматизации (инвойсы из почты, категоризация, ручной разбор, MCP), интервальные задания scheduler, миграции 033/034/038
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
34
packages/accounting_automation/src/prompt-loader.ts
Normal file
34
packages/accounting_automation/src/prompt-loader.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
export interface PromptSourceDeps {
|
||||
/** Текст Google Docs (экспорт text/plain); не задан или упал - берётся копия из файла. */
|
||||
exportDocText?: (docId: string) => Promise<string>;
|
||||
docId: string;
|
||||
fallbackFile: string;
|
||||
/** Корень репозитория для относительного fallbackFile. */
|
||||
rootDir?: string;
|
||||
log?: (msg: string, extra?: Record<string, unknown>) => void;
|
||||
}
|
||||
|
||||
/** Служебные разделы файла-копии (`## Описание`) агенту не нужны. */
|
||||
export function stripPromptFile(text: string): string {
|
||||
const noDescription = text.split(/\n## Описание/)[0] ?? text;
|
||||
return noDescription.replace(/^# [^\n]*\n+/, "").trim();
|
||||
}
|
||||
|
||||
/** Промпт категоризации: Google Docs (правит Анастасия) с запасной копией из репозитория. */
|
||||
export function makePromptLoader(d: PromptSourceDeps): () => Promise<string> {
|
||||
return async () => {
|
||||
if (d.exportDocText) {
|
||||
try {
|
||||
const t = (await d.exportDocText(d.docId)).trim();
|
||||
if (t.length > 200) return t;
|
||||
d.log?.("промпт из Google Docs слишком короткий, берётся копия из файла", { length: t.length });
|
||||
} catch (e) {
|
||||
d.log?.("промпт из Google Docs недоступен, берётся копия из файла", { err: String(e) });
|
||||
}
|
||||
}
|
||||
const path = d.rootDir && !/^([a-zA-Z]:|\/)/.test(d.fallbackFile) ? `${d.rootDir}/${d.fallbackFile}` : d.fallbackFile;
|
||||
return stripPromptFile(await readFile(path, "utf8"));
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user