@diy-accounting-uk/diya-submit 0.1.3 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -7
- package/lib/accounts-tools.js +1 -1
- package/lib/book-read-tools.js +134 -0
- package/lib/book-tools.js +155 -43
- package/lib/client-kind.js +44 -0
- package/lib/finance/bank-lines.js +4 -2
- package/lib/finance/paypal-statement-lines.js +117 -37
- package/lib/handoff-tools.js +135 -23
- package/lib/help-index.json +2959 -0
- package/lib/help-tools.js +111 -0
- package/lib/hosted-register-book.js +128 -0
- package/lib/hosted-tools.js +116 -16
- package/lib/hosted-write-tools.js +313 -0
- package/lib/http.js +3 -3
- package/lib/rules-data.json +1821 -0
- package/lib/rules-tools.js +165 -0
- package/lib/server.js +316 -63
- package/lib/submit-tools.js +200 -13
- package/lib/tool-annotations.js +4 -1
- package/lib/vat-tools.js +16 -2
- package/lib/vendored/app/services/ct600Figures.js +15 -19
- package/lib/vendored/app/services/microEntityAccounts.js +8 -6
- package/package.json +2 -2
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LicenseRef-PolyForm-Internal-Use-1.0.0
|
|
2
|
+
// Copyright (C) 2006-2026 DIY Accounting Limited
|
|
3
|
+
|
|
4
|
+
// @capability MCP-29 Answer help questions and the DIYA-GL book format from the hosted connector
|
|
5
|
+
// - **Use when:** an assistant needs Submit's own help on a step, a diya-gl knowledge base article, the shape of a DIYA-GL book, or a CT600 box.
|
|
6
|
+
// - **Does:** findHelp in mcp/lib/help-tools.js scores the Submit guide's journeys, the MCP, rates and MTD calendar pages' sections and the diya-gl knowledge base's articles against a question and answers each match's title, a two-line summary and its public address. bookFormat answers the DIYA-GL book's two files and their fields, or the CT600 box map. Both read mcp/lib/help-index.json, which scripts/build-mcp-help-index.mjs builds; it calls no service.
|
|
7
|
+
// - **Run:** `npm run build:mcp-help-index` (rebuild the index); `npm run build:mcp-help-index -- --fetch` (read the published knowledge base again)
|
|
8
|
+
// - **Entry:** `mcp/lib/help-tools.js:findHelp`; `mcp/lib/help-tools.js:bookFormat`; `scripts/build-mcp-help-index.mjs:buildHelpIndex`
|
|
9
|
+
// - **Files:** mcp/lib/help-tools.js, mcp/lib/help-index.json, scripts/build-mcp-help-index.mjs, mcp/test/help-tools.test.js, app/unit-tests/scripts/buildMcpHelpIndex.test.js
|
|
10
|
+
// - **Keywords:** find_help, book_format, guide search, knowledge base, book format, ct600 box map, help index
|
|
11
|
+
// - **Related:** MCP-01
|
|
12
|
+
// @end-capability
|
|
13
|
+
|
|
14
|
+
// help-tools.js -- find_help and book_format: read-only answers from the help index.
|
|
15
|
+
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
17
|
+
|
|
18
|
+
const INDEX_URL = new URL("./help-index.json", import.meta.url);
|
|
19
|
+
export const GUIDE_URL = "https://submit.diyaccounting.co.uk/guide.html";
|
|
20
|
+
export const KNOWLEDGE_BASE_PAGE_URL = "https://spreadsheets.diyaccounting.co.uk/knowledge-base.html";
|
|
21
|
+
export const HELP_SOURCES = { "guide": "Submit guide", "knowledge-base": "diya-gl knowledge base" };
|
|
22
|
+
export const DEFAULT_MATCHES = 5;
|
|
23
|
+
export const MAX_MATCHES = 10;
|
|
24
|
+
|
|
25
|
+
const STOP_WORDS = new Set(
|
|
26
|
+
"a an and are as at be by can do does for from get how i in is it me my of on or the to what when where which who why will with you your".split(
|
|
27
|
+
" ",
|
|
28
|
+
),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
let index;
|
|
32
|
+
function helpIndex() {
|
|
33
|
+
index ??= JSON.parse(readFileSync(INDEX_URL, "utf8"));
|
|
34
|
+
return index;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const wordsOf = (text) =>
|
|
38
|
+
(text ?? "")
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.split(/[^a-z0-9£%]+/)
|
|
41
|
+
.filter(Boolean);
|
|
42
|
+
|
|
43
|
+
/** The words of a question that carry its meaning. */
|
|
44
|
+
export function queryTerms(query) {
|
|
45
|
+
return [...new Set(wordsOf(query).filter((word) => !STOP_WORDS.has(word)))];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// A term matches a word it begins, so "allowance" finds "allowances".
|
|
49
|
+
function hits(term, words) {
|
|
50
|
+
return words.some((word) => word.startsWith(term));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** How well an entry answers the terms: a term in the title counts most, then the summary, then the rest. */
|
|
54
|
+
export function scoreOf(entry, terms, phrase) {
|
|
55
|
+
const title = wordsOf(entry.title);
|
|
56
|
+
const summary = wordsOf(`${entry.section} ${entry.summary}`);
|
|
57
|
+
const text = wordsOf(entry.text);
|
|
58
|
+
let score = 0;
|
|
59
|
+
for (const term of terms) {
|
|
60
|
+
if (hits(term, title)) score += 3;
|
|
61
|
+
else if (hits(term, summary)) score += 2;
|
|
62
|
+
else if (hits(term, text)) score += 1;
|
|
63
|
+
}
|
|
64
|
+
if (phrase && entry.title.toLowerCase().includes(phrase)) score += 5;
|
|
65
|
+
return score;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The guide sections and knowledge base articles that answer a question, best first.
|
|
70
|
+
* @param {Object} _session - unused: the help index is the same for every caller
|
|
71
|
+
* @param {{query: string, source?: "guide"|"knowledge-base", limit?: number}} args
|
|
72
|
+
*/
|
|
73
|
+
export function findHelp(_session, { query, source, limit = DEFAULT_MATCHES } = {}) {
|
|
74
|
+
const terms = queryTerms(query);
|
|
75
|
+
if (terms.length === 0) throw new Error("find_help needs a question or some words to search for");
|
|
76
|
+
const phrase = (query ?? "").trim().toLowerCase();
|
|
77
|
+
const wanted = source ? HELP_SOURCES[source] : undefined;
|
|
78
|
+
if (source && !wanted) throw new Error(`find_help source must be one of ${Object.keys(HELP_SOURCES).join(", ")}`);
|
|
79
|
+
const count = Math.min(Math.max(Math.trunc(limit) || DEFAULT_MATCHES, 1), MAX_MATCHES);
|
|
80
|
+
const matches = helpIndex()
|
|
81
|
+
.entries.filter((entry) => !wanted || entry.source === wanted)
|
|
82
|
+
.map((entry, order) => ({ entry, order, score: scoreOf(entry, terms, phrase) }))
|
|
83
|
+
.filter((candidate) => candidate.score > 0)
|
|
84
|
+
.sort((a, b) => b.score - a.score || a.order - b.order)
|
|
85
|
+
.slice(0, count)
|
|
86
|
+
.map(({ entry }) => ({ source: entry.source, title: entry.title, summary: entry.summary, url: entry.url }));
|
|
87
|
+
if (matches.length > 0) return { query, matches };
|
|
88
|
+
return {
|
|
89
|
+
query,
|
|
90
|
+
matches,
|
|
91
|
+
note: `Nothing in the Submit guide or the diya-gl knowledge base matches. The guide is ${GUIDE_URL} and the knowledge base is ${KNOWLEDGE_BASE_PAGE_URL}.`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The DIYA-GL book format (part "book", the default) or the CT600 box map (part "ct600"), whose boxes a
|
|
97
|
+
* section narrows.
|
|
98
|
+
* @param {Object} _session - unused: the format is the same for every caller
|
|
99
|
+
* @param {{part?: "book"|"ct600", section?: string}} args
|
|
100
|
+
*/
|
|
101
|
+
export function bookFormat(_session, { part = "book", section } = {}) {
|
|
102
|
+
const { bookFormat: format, ct600 } = helpIndex();
|
|
103
|
+
if (part === "book") return format;
|
|
104
|
+
if (part !== "ct600") throw new Error('book_format part must be "book" or "ct600"');
|
|
105
|
+
const sections = [...new Set(ct600.boxes.map((box) => box.section))];
|
|
106
|
+
if (!section) return { version: ct600.version, source: ct600.source, sections, boxes: ct600.boxes };
|
|
107
|
+
const wanted = section.trim().toLowerCase();
|
|
108
|
+
const boxes = ct600.boxes.filter((box) => box.section.toLowerCase().includes(wanted));
|
|
109
|
+
if (boxes.length === 0) throw new Error(`No CT600 section matches "${section}"; the sections are: ${sections.join("; ")}`);
|
|
110
|
+
return { version: ct600.version, source: ct600.source, sections, boxes };
|
|
111
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LicenseRef-PolyForm-Internal-Use-1.0.0
|
|
2
|
+
// Copyright (C) 2006-2026 DIY Accounting Limited
|
|
3
|
+
|
|
4
|
+
// hosted-register-book.js -- new_book_from_register on the hosted connector: a limited company's
|
|
5
|
+
// next DIYA-GL book from what Companies House holds, read through DIY Accounting Submit's own
|
|
6
|
+
// register reads, built by the published diya-gl tool's own handler, and saved to the person's
|
|
7
|
+
// account as a new book. The company profile, the current officers and the last filed iXBRL accounts
|
|
8
|
+
// come from the public register read; the statement of capital and the shareholdings come from the
|
|
9
|
+
// confirmation statement data read, which takes the company authentication code, so only when the
|
|
10
|
+
// person gives a codesEntryId from request_companies_house_codes.
|
|
11
|
+
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
import { readBookSource } from "@diy-accounting-uk/diya-gl/dist/app/lib/diya-gl-interchange.js";
|
|
15
|
+
import { TOOLS as DIYA_GL_TOOLS } from "@diy-accounting-uk/diya-gl/dist/app/lib/mcp/diya-gl-tools.js";
|
|
16
|
+
import { PRODUCTS } from "@diy-accounting-uk/diya-gl/dist/app/lib/products.js";
|
|
17
|
+
|
|
18
|
+
import { callSubmitApi, getConfirmationStatementData } from "./submit-tools.js";
|
|
19
|
+
import { saveNewBook } from "./hosted-write-tools.js";
|
|
20
|
+
import { ADDS_OUTSIDE } from "./tool-annotations.js";
|
|
21
|
+
|
|
22
|
+
const pick = (object, names) =>
|
|
23
|
+
Object.fromEntries(names.filter((name) => object?.[name] !== undefined && object[name] !== null).map((name) => [name, object[name]]));
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The builder's input from the register reads: the profile and officer fields it takes, the
|
|
27
|
+
* statement of capital and the holders' names only, never a date of birth, a nationality or an
|
|
28
|
+
* address of a person.
|
|
29
|
+
* @param {{profile: Object, officers?: Object[]}} register - the public register read's answer
|
|
30
|
+
* @param {Object|null} filingData - the confirmation statement data read's answer
|
|
31
|
+
*/
|
|
32
|
+
export function registerInput(register, filingData) {
|
|
33
|
+
const input = {
|
|
34
|
+
profile: {
|
|
35
|
+
...pick(register.profile, [
|
|
36
|
+
"companyNumber",
|
|
37
|
+
"companyName",
|
|
38
|
+
"dateOfCreation",
|
|
39
|
+
"accountsNextPeriodStart",
|
|
40
|
+
"accountsNextPeriodEnd",
|
|
41
|
+
"accountsLastPeriodEnd",
|
|
42
|
+
]),
|
|
43
|
+
registeredOffice: pick(register.profile?.registeredOffice, [
|
|
44
|
+
"addressLine1",
|
|
45
|
+
"addressLine2",
|
|
46
|
+
"addressLine3",
|
|
47
|
+
"cityOrTown",
|
|
48
|
+
"postalCode",
|
|
49
|
+
]),
|
|
50
|
+
},
|
|
51
|
+
officers: (register.officers ?? []).map((officer) => pick(officer, ["name", "officerRole", "appointedOn", "resignedOn"])),
|
|
52
|
+
};
|
|
53
|
+
const statement = filingData?.statementOfCapital;
|
|
54
|
+
if (statement) {
|
|
55
|
+
input.capital = {
|
|
56
|
+
...pick(statement, ["shareCurrency", "totalAggregateNominalValue"]),
|
|
57
|
+
shares: (statement.shares ?? []).map((share) => pick(share, ["shareClass", "numShares", "aggregateNominalValue"])),
|
|
58
|
+
};
|
|
59
|
+
input.shareholdings = (filingData.shareholdings ?? []).map((holding) => ({
|
|
60
|
+
...pick(holding, ["shareClass", "numberHeld"]),
|
|
61
|
+
shareholders: (holding.shareholders ?? []).map((holder) => pick(holder, ["forename", "surname", "amalgamatedName"])),
|
|
62
|
+
}));
|
|
63
|
+
if (filingData.madeUpDate) input.capitalDate = filingData.madeUpDate;
|
|
64
|
+
}
|
|
65
|
+
return input;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// The last filed accounts as the builder takes them, or the reason they could not be read.
|
|
69
|
+
async function lastAccountsOf(filedAccounts) {
|
|
70
|
+
if (filedAccounts?.status !== "ixbrl" || !filedAccounts.ixbrl) return { lastAccounts: null, unread: filedAccounts?.status ?? "none" };
|
|
71
|
+
try {
|
|
72
|
+
const read = await readBookSource(new TextEncoder().encode(filedAccounts.ixbrl), "accounts.xhtml", { products: PRODUCTS });
|
|
73
|
+
return { lastAccounts: read.accounts ?? null, unread: read.accounts ? null : "unreadable" };
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return { lastAccounts: null, unread: error.message };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function newBookFromRegister(session, { companyNumber, periodEnd, codesEntryId, madeUpDate, clientId } = {}) {
|
|
80
|
+
if (!companyNumber) throw new Error("new_book_from_register requires companyNumber");
|
|
81
|
+
const number = String(companyNumber).trim().toUpperCase();
|
|
82
|
+
const register = await callSubmitApi(session, `/api/v1/public/company-register?number=${encodeURIComponent(number)}`);
|
|
83
|
+
const filingData = codesEntryId
|
|
84
|
+
? await getConfirmationStatementData(session, {
|
|
85
|
+
companyNumber: number,
|
|
86
|
+
codesEntryId,
|
|
87
|
+
madeUpDate: madeUpDate ?? new Date().toISOString().slice(0, 10),
|
|
88
|
+
})
|
|
89
|
+
: null;
|
|
90
|
+
const { lastAccounts, unread } = await lastAccountsOf(register.filedAccounts);
|
|
91
|
+
const input = { ...registerInput(register, filingData), ...(lastAccounts ? { lastAccounts } : {}), ...(periodEnd ? { periodEnd } : {}) };
|
|
92
|
+
const built = await DIYA_GL_TOOLS.new_book_from_register.handler({ book: null, lines: null }, input);
|
|
93
|
+
const summary = await saveNewBook(session, built.book, built.lines, { clientId, change: { tool: "new_book_from_register" } });
|
|
94
|
+
return {
|
|
95
|
+
...summary,
|
|
96
|
+
fromFiledAccounts: Boolean(lastAccounts),
|
|
97
|
+
...(lastAccounts ? {} : { filedAccountsNotRead: unread }),
|
|
98
|
+
withCapital: Boolean(input.capital),
|
|
99
|
+
differences: built.differences,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const HOSTED_REGISTER_BOOK_OVERRIDES = {
|
|
104
|
+
new_book_from_register: {
|
|
105
|
+
title: "Start a company's DIYA-GL book from Companies House",
|
|
106
|
+
annotations: ADDS_OUTSIDE,
|
|
107
|
+
description:
|
|
108
|
+
"Starts the DIYA-GL book of a limited company's next accounting period from the Companies House register: the " +
|
|
109
|
+
"company, its registered office, its current directors and secretaries, and the roll forward of its last filed " +
|
|
110
|
+
"accounts when the register holds them as iXBRL, so the opening balance sheet equals the filed closing one. With " +
|
|
111
|
+
"a codesEntryId it also writes in the statement of capital and the shareholders. Saves it in the person's DIY " +
|
|
112
|
+
"Accounting Submit account as a new book, which becomes the open one. Use this when the person starts a company's " +
|
|
113
|
+
"records for its next year from what Companies House holds. It does not change another DIYA-GL book or file anything.",
|
|
114
|
+
inputSchema: {
|
|
115
|
+
companyNumber: z.string().describe("The company's registration number"),
|
|
116
|
+
periodEnd: z.string().optional().describe("The year end chosen, YYYY-MM-DD, on or after the register's next period end"),
|
|
117
|
+
codesEntryId: z
|
|
118
|
+
.string()
|
|
119
|
+
.optional()
|
|
120
|
+
.describe(
|
|
121
|
+
"An entry request_companies_house_codes answered (kind confirmation-statement-data), to add the capital and the shareholders",
|
|
122
|
+
),
|
|
123
|
+
madeUpDate: z.string().optional().describe("The date the shareholdings are read as at, YYYY-MM-DD; today by default"),
|
|
124
|
+
clientId: z.string().optional().describe("A practice client's id, to keep the DIYA-GL book in that client's set"),
|
|
125
|
+
},
|
|
126
|
+
handler: newBookFromRegister,
|
|
127
|
+
},
|
|
128
|
+
};
|
package/lib/hosted-tools.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
// Copyright (C) 2006-2026 DIY Accounting Limited
|
|
3
3
|
|
|
4
4
|
// hosted-tools.js -- the tools the hosted MCP endpoint registers, and the four
|
|
5
|
-
// that change shape there: open_book reads the
|
|
5
|
+
// that change shape there: open_book reads the DIY Accounting Submit account only,
|
|
6
6
|
// derive_itsa_annual_submission and derive_company_tax_return answer without
|
|
7
7
|
// writing a file, and run_for_clients cannot run the book tools. The tools
|
|
8
8
|
// left out are the sign-in pair (the connector owns sign-in) and the filesystem
|
|
9
|
-
// tools. The
|
|
10
|
-
//
|
|
9
|
+
// tools. The DIYA-GL book's write tools (hosted-write-tools.js) save each change
|
|
10
|
+
// to the person's account, because the hosted server keeps no book between calls.
|
|
11
|
+
// The practice tools (invite_client, client_authorisation_status, run_for_clients)
|
|
12
|
+
// read the session's HMRC grant and take no token argument.
|
|
11
13
|
|
|
12
14
|
import { z } from "zod";
|
|
13
15
|
|
|
@@ -16,6 +18,9 @@ import { openBook } from "./book-tools.js";
|
|
|
16
18
|
import { deriveItsaAnnualSubmission } from "./itsa-tools.js";
|
|
17
19
|
import { CHANGES_OUTSIDE, READS } from "./tool-annotations.js";
|
|
18
20
|
import { runForClients, RUN_FOR_CLIENTS_TOOLS } from "./batch-tools.js";
|
|
21
|
+
import { ACCOUNTS_FILING_SENTENCE, COMPANY_TAX_RETURN_FILING_SENTENCE, VAT_FILING_SENTENCE } from "./handoff-tools.js";
|
|
22
|
+
import { HOSTED_WRITE_OVERRIDES } from "./hosted-write-tools.js";
|
|
23
|
+
import { HOSTED_REGISTER_BOOK_OVERRIDES } from "./hosted-register-book.js";
|
|
19
24
|
|
|
20
25
|
// The book tools read and write the server's filesystem, which a hosted caller never reaches.
|
|
21
26
|
const HOSTED_RUN_FOR_CLIENTS_TOOLS = RUN_FOR_CLIENTS_TOOLS.filter((tool) => tool !== "open_book" && tool !== "save_book");
|
|
@@ -34,6 +39,7 @@ export const HOSTED_TOOL_NAMES = [
|
|
|
34
39
|
"derive_uk_property_period",
|
|
35
40
|
"derive_uk_property_annual",
|
|
36
41
|
"derive_company_tax_return",
|
|
42
|
+
"company_filing_deadlines",
|
|
37
43
|
"request_hmrc_authorisation",
|
|
38
44
|
"list_vat_obligations",
|
|
39
45
|
"list_vat_liabilities",
|
|
@@ -43,6 +49,7 @@ export const HOSTED_TOOL_NAMES = [
|
|
|
43
49
|
"submit_vat_return",
|
|
44
50
|
"get_vat_receipt",
|
|
45
51
|
"list_vat_receipts",
|
|
52
|
+
"list_accounts_receipts",
|
|
46
53
|
"render_micro_entity_accounts_sandbox",
|
|
47
54
|
"render_small_company_accounts_sandbox",
|
|
48
55
|
"request_companies_house_codes",
|
|
@@ -58,12 +65,33 @@ export const HOSTED_TOOL_NAMES = [
|
|
|
58
65
|
"invite_client",
|
|
59
66
|
"client_authorisation_status",
|
|
60
67
|
"run_for_clients",
|
|
68
|
+
"report",
|
|
69
|
+
"trial_balance",
|
|
70
|
+
"checks",
|
|
71
|
+
"lines",
|
|
72
|
+
"chart",
|
|
73
|
+
"book",
|
|
74
|
+
"look_up_rule",
|
|
75
|
+
"prepare_micro_entity_accounts",
|
|
76
|
+
"prepare_small_company_accounts",
|
|
77
|
+
"prepare_company_tax_return",
|
|
78
|
+
"edit_lines",
|
|
79
|
+
"new_book",
|
|
80
|
+
"roll_forward",
|
|
81
|
+
"undo_book_change",
|
|
82
|
+
"extract_book",
|
|
83
|
+
"save_workbook",
|
|
84
|
+
"new_book_from_register",
|
|
85
|
+
"find_help",
|
|
86
|
+
"book_format",
|
|
61
87
|
];
|
|
62
88
|
|
|
63
|
-
// Prod offers the
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
89
|
+
// Prod offers the DIYA-GL book tools (reading a book, changing it with an undo, starting new ones), the
|
|
90
|
+
// VAT, accounts and Company Tax Return derivations, the links that open the VAT, accounts and CT600 forms
|
|
91
|
+
// with the figures filled in, the rules and rates with their sources, the site's help, a company's filing
|
|
92
|
+
// deadlines from the public register, and the stored receipts. No hosted tool on prod files or reaches
|
|
93
|
+
// HMRC, because an AI client cannot give the fraud prevention headers a call needs. The HMRC tools, the
|
|
94
|
+
// sandbox filing tools and the practice tools register in every other environment.
|
|
67
95
|
const PROD_HOSTED_TOOL_NAMES = [
|
|
68
96
|
"list_books",
|
|
69
97
|
"open_book",
|
|
@@ -71,6 +99,30 @@ const PROD_HOSTED_TOOL_NAMES = [
|
|
|
71
99
|
"prepare_vat_return",
|
|
72
100
|
"get_vat_receipt",
|
|
73
101
|
"list_vat_receipts",
|
|
102
|
+
"company_filing_deadlines",
|
|
103
|
+
"derive_micro_entity_accounts",
|
|
104
|
+
"derive_small_company_accounts",
|
|
105
|
+
"derive_company_tax_return",
|
|
106
|
+
"list_accounts_receipts",
|
|
107
|
+
"report",
|
|
108
|
+
"trial_balance",
|
|
109
|
+
"checks",
|
|
110
|
+
"lines",
|
|
111
|
+
"chart",
|
|
112
|
+
"book",
|
|
113
|
+
"look_up_rule",
|
|
114
|
+
"prepare_micro_entity_accounts",
|
|
115
|
+
"prepare_small_company_accounts",
|
|
116
|
+
"prepare_company_tax_return",
|
|
117
|
+
"edit_lines",
|
|
118
|
+
"new_book",
|
|
119
|
+
"roll_forward",
|
|
120
|
+
"undo_book_change",
|
|
121
|
+
"extract_book",
|
|
122
|
+
"save_workbook",
|
|
123
|
+
"new_book_from_register",
|
|
124
|
+
"find_help",
|
|
125
|
+
"book_format",
|
|
74
126
|
];
|
|
75
127
|
|
|
76
128
|
// The demo user that directory reviewers sign in as belongs to this Cognito group. Its token sees
|
|
@@ -88,14 +140,59 @@ export function hostedToolNames(environmentName, groups = []) {
|
|
|
88
140
|
return prod || groups.includes(REVIEWER_GROUP) ? PROD_HOSTED_TOOL_NAMES : HOSTED_TOOL_NAMES;
|
|
89
141
|
}
|
|
90
142
|
|
|
143
|
+
// What an assistant connected to prod's tool set needs to know beyond each tool's description: what
|
|
144
|
+
// the connector cannot do, how a return gets filed, and what to show from a derived return.
|
|
145
|
+
const PROD_HOSTED_INSTRUCTIONS =
|
|
146
|
+
"A book is one DIYA-GL file: one business's sales, purchases and bank lines for a year. " +
|
|
147
|
+
'Say "your DIYA-GL book" or "your records" to the person, never "your books". ' +
|
|
148
|
+
"This connector keeps and reads the person's records and works out figures: it opens a DIYA-GL book and derives " +
|
|
149
|
+
"from it a VAT return, a company's micro-entity or small company accounts and a Company Tax Return; it prepares the " +
|
|
150
|
+
"links that open the VAT return, accounts and Company Tax Return forms with the figures filled in; it looks up a " +
|
|
151
|
+
"company's filing deadlines on the Companies House register; and it reads stored VAT receipts and accounts filings. " +
|
|
152
|
+
"No tool files a return or accounts, or pays HMRC or anyone else. When asked to pay, say that this connector cannot " +
|
|
153
|
+
"do it. To file a VAT return, call prepare_vat_return, give the person its link and " +
|
|
154
|
+
`tell them: "${VAT_FILING_SENTENCE}" After derive_vat_return, show the nine boxes and the largest lines behind ` +
|
|
155
|
+
"boxes 1 and 4. When list_books answers no DIYA-GL book, say that no DIYA-GL book is saved in the account and give " +
|
|
156
|
+
"the link https://submit.diyaccounting.co.uk/mcp.html#what-you-need. " +
|
|
157
|
+
"report gives the book's profit and loss account, balance sheet, tax and VAT figures, each with the label the " +
|
|
158
|
+
"spreadsheet prints. trial_balance gives a company's trial balance for the year, a month, a VAT quarter or a date " +
|
|
159
|
+
"range. checks gives every book check with its verdict and the lines that fail it. lines reads the book's lines, " +
|
|
160
|
+
"filtered and grouped, to answer who the best customer is or what was spent on something. chart gives the chart of " +
|
|
161
|
+
"accounts and where each account lands in the accounts. book gives the book's period, business, tax settings and " +
|
|
162
|
+
"registers. edit_lines records or corrects sales, purchases and bank lines and saves the book as its next version; " +
|
|
163
|
+
"say what changed, and use undo_book_change when the person says a change was wrong. new_book starts an empty " +
|
|
164
|
+
"DIYA-GL book for a new business. roll_forward starts next year's DIYA-GL book from the open one. " +
|
|
165
|
+
"new_book_from_register starts a company's next DIYA-GL book from the Companies House register and its last filed " +
|
|
166
|
+
"accounts. extract_book gives the link where the person uploads a spreadsheet or package zip as a DIYA-GL book. " +
|
|
167
|
+
"save_workbook gives the link that downloads the open book as a spreadsheet or a file. look_up_rule answers a tax " +
|
|
168
|
+
"rule, rate or deadline with its gov.uk source; quote the source and send the person to HMRC or Companies House for " +
|
|
169
|
+
"a ruling. find_help finds the Submit guide, the MCP page or the knowledge base article that answers a question; " +
|
|
170
|
+
"give its link. book_format describes the DIYA-GL book's files and fields, or the CT600 box map. " +
|
|
171
|
+
"prepare_micro_entity_accounts and prepare_small_company_accounts give the link to the accounts form with the " +
|
|
172
|
+
`figures filled in; tell the person: "${ACCOUNTS_FILING_SENTENCE}" prepare_company_tax_return gives the link to the ` +
|
|
173
|
+
`Company Tax Return form with the figures filled in; tell the person: "${COMPANY_TAX_RETURN_FILING_SENTENCE}"`;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The server instructions the hosted endpoint sends in an environment, for a caller in these groups:
|
|
177
|
+
* prod's tool set carries them, the wider tool set carries none.
|
|
178
|
+
* @param {string|undefined} environmentName
|
|
179
|
+
* @param {string[]} [groups] - the token's `cognito:groups`
|
|
180
|
+
* @returns {string|undefined}
|
|
181
|
+
*/
|
|
182
|
+
export function hostedInstructions(environmentName, groups = []) {
|
|
183
|
+
return hostedToolNames(environmentName, groups) === PROD_HOSTED_TOOL_NAMES ? PROD_HOSTED_INSTRUCTIONS : undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
91
186
|
export const HOSTED_OVERRIDES = {
|
|
92
187
|
open_book: {
|
|
93
|
-
title: "Open a book",
|
|
188
|
+
title: "Open a DIYA-GL book",
|
|
94
189
|
annotations: READS,
|
|
95
190
|
description:
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
191
|
+
"Opens a DIYA-GL book saved in the person's DIY Accounting Submit account by its bookId, which list_books gives " +
|
|
192
|
+
"(a practice client's own DIYA-GL book with clientId). Answers the product, the business, the period covered, the " +
|
|
193
|
+
"line count and the book's checks, and replaces any DIYA-GL book already open in this conversation. Use this when " +
|
|
194
|
+
"the person picks a saved DIYA-GL book, or before working out or preparing a VAT return from their records. It " +
|
|
195
|
+
"does not change the book, file anything or contact HMRC.",
|
|
99
196
|
inputSchema: {
|
|
100
197
|
bookId: z.string().describe("The cloud book's id"),
|
|
101
198
|
clientId: z.string().optional().describe("A practice client's id, to open that client's book instead of the practice's own"),
|
|
@@ -110,7 +207,7 @@ export const HOSTED_OVERRIDES = {
|
|
|
110
207
|
annotations: READS,
|
|
111
208
|
description:
|
|
112
209
|
"The year's allowances and adjustments for HMRC's Self Employment Business API annual submission from the loaded " +
|
|
113
|
-
"self-employed book, restricted to the fields HMRC accepts for that tax year.",
|
|
210
|
+
"self-employed DIYA-GL book, restricted to the fields HMRC accepts for that tax year.",
|
|
114
211
|
inputSchema: {
|
|
115
212
|
taxYear: z.string().optional().describe("Override the tax year the book's dates imply, as 2025-26"),
|
|
116
213
|
},
|
|
@@ -143,11 +240,14 @@ export const HOSTED_OVERRIDES = {
|
|
|
143
240
|
title: "Derive a Company Tax Return",
|
|
144
241
|
annotations: READS,
|
|
145
242
|
description:
|
|
146
|
-
"
|
|
147
|
-
"computation figures, the profit and loss account
|
|
148
|
-
"
|
|
149
|
-
"makes a trading loss or carries net
|
|
243
|
+
"Works out the figures a Company Tax Return (CT600) takes, from the open DIYA-GL book of a company: the accounting " +
|
|
244
|
+
"period, the computation figures, the profit and loss account, and the book's own trading profit and Corporation " +
|
|
245
|
+
"Tax as a check. Use this when the person asks what their Corporation Tax will be, for their CT600 figures, or how " +
|
|
246
|
+
"their taxable profit is worked out. It refuses a book that is not a company's, makes a trading loss or carries net " +
|
|
247
|
+
"non-trading loan relationship debits, and it does not file the return or contact HMRC.",
|
|
150
248
|
inputSchema: {},
|
|
151
249
|
handler: (session) => deriveCompanyTaxReturn(session, {}),
|
|
152
250
|
},
|
|
251
|
+
...HOSTED_WRITE_OVERRIDES,
|
|
252
|
+
...HOSTED_REGISTER_BOOK_OVERRIDES,
|
|
153
253
|
};
|