@talonic/mcp 0.1.85 → 0.1.87
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/CHANGELOG.md +18 -0
- package/dist/content.js +1 -1
- package/dist/content.js.map +1 -1
- package/dist/http-server.js +785 -7
- package/dist/http-server.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +737 -3
- package/dist/index.js.map +1 -1
- package/dist/server.js +759 -6
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Talonic, TalonicError } from '@talonic/node';
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { readFile } from 'fs/promises';
|
|
5
|
+
import { basename } from 'path';
|
|
4
6
|
|
|
5
7
|
// src/server-factory.ts
|
|
6
8
|
function jsonOk(value) {
|
|
@@ -101,6 +103,42 @@ async function apiForm(getToken, baseUrl, path, fields) {
|
|
|
101
103
|
}
|
|
102
104
|
return await res.json();
|
|
103
105
|
}
|
|
106
|
+
async function apiBinary(getToken, baseUrl, path, opts) {
|
|
107
|
+
const res = await resolveFetch(getToken)(buildUrl(baseUrl, path, opts.params), {
|
|
108
|
+
method: "GET",
|
|
109
|
+
headers: { Authorization: `Bearer ${getToken()}`, Accept: "*/*" }
|
|
110
|
+
});
|
|
111
|
+
if (!res.ok) {
|
|
112
|
+
const text = await res.text().catch(() => "");
|
|
113
|
+
throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
|
|
114
|
+
}
|
|
115
|
+
const tooLarge = (n) => new Error(`File is ${n} bytes, over the ${opts.maxBytes}-byte limit for a tool result.`);
|
|
116
|
+
const declared = Number(res.headers.get("content-length"));
|
|
117
|
+
if (Number.isFinite(declared) && declared > opts.maxBytes) {
|
|
118
|
+
await res.body?.cancel().catch(() => {
|
|
119
|
+
});
|
|
120
|
+
throw tooLarge(declared);
|
|
121
|
+
}
|
|
122
|
+
const bytes = Buffer.from(await res.arrayBuffer());
|
|
123
|
+
if (bytes.length > opts.maxBytes) throw tooLarge(bytes.length);
|
|
124
|
+
return {
|
|
125
|
+
bytes,
|
|
126
|
+
filename: filenameFromDisposition(res.headers.get("content-disposition")),
|
|
127
|
+
mimeType: (res.headers.get("content-type") ?? "application/octet-stream").split(";")[0].trim()
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function filenameFromDisposition(header) {
|
|
131
|
+
if (!header) return null;
|
|
132
|
+
const star = /filename\*\s*=\s*(?:UTF-8'[^']*')?([^;]+)/i.exec(header);
|
|
133
|
+
const plain = /filename\s*=\s*"([^"]*)"|filename\s*=\s*([^;]+)/i.exec(header);
|
|
134
|
+
const raw = star?.[1] ?? plain?.[1] ?? plain?.[2];
|
|
135
|
+
if (!raw) return null;
|
|
136
|
+
try {
|
|
137
|
+
return decodeURIComponent(raw.trim());
|
|
138
|
+
} catch {
|
|
139
|
+
return raw.trim();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
104
142
|
function sleep(ms) {
|
|
105
143
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
106
144
|
}
|
|
@@ -3614,6 +3652,690 @@ function registerApTools(server, getToken, baseUrl) {
|
|
|
3614
3652
|
);
|
|
3615
3653
|
}
|
|
3616
3654
|
}
|
|
3655
|
+
var readOnly3 = {
|
|
3656
|
+
readOnlyHint: true,
|
|
3657
|
+
destructiveHint: false,
|
|
3658
|
+
idempotentHint: true,
|
|
3659
|
+
openWorldHint: false
|
|
3660
|
+
};
|
|
3661
|
+
var write3 = (idempotent, destructive = false) => ({
|
|
3662
|
+
readOnlyHint: false,
|
|
3663
|
+
destructiveHint: destructive,
|
|
3664
|
+
idempotentHint: idempotent,
|
|
3665
|
+
openWorldHint: false
|
|
3666
|
+
});
|
|
3667
|
+
var DOC_GEN_POLL_INTERVAL_MS = 3e3;
|
|
3668
|
+
var PROPOSE_MAX_WAIT_S = 120;
|
|
3669
|
+
var GENERATE_MAX_WAIT_S = 300;
|
|
3670
|
+
var DOC_GEN_MAX_FILE_BYTES = 8 * 1024 * 1024;
|
|
3671
|
+
var templateIdArg = z.string().uuid().describe("Template id (from talonic_doc_gen_templates or talonic_doc_gen_issues).");
|
|
3672
|
+
var productIdArg = z.string().uuid().describe("Data product id (from talonic_doc_gen_products).");
|
|
3673
|
+
var jobIdArg = z.string().uuid().describe("Batch id (from talonic_doc_gen_jobs or _generate).");
|
|
3674
|
+
var valuesArg = z.record(z.string(), z.string()).describe(
|
|
3675
|
+
"Values by field key (or case key). A field whose source type is `case` (entered per document) takes the value as entered; a value for any other field is an edit over the fill, recorded in the document history."
|
|
3676
|
+
);
|
|
3677
|
+
var ENTERED_RULE = "Fields whose source type is `case` are entered per document: the data does not hold them (e.g. the new owner), so pass them in `values` by field key (or case key). A value for any other field overrides the fill and is recorded as an edit in the document history.";
|
|
3678
|
+
function waitSeconds(requested, max) {
|
|
3679
|
+
const n = Number.isFinite(requested) ? requested : 0;
|
|
3680
|
+
return Math.max(0, Math.min(max, Math.floor(n)));
|
|
3681
|
+
}
|
|
3682
|
+
async function pollUntilDone(first, read, isRunning, waitS, deps) {
|
|
3683
|
+
const sleep2 = deps.sleep ?? sleep;
|
|
3684
|
+
const now = deps.now ?? Date.now;
|
|
3685
|
+
const start = now();
|
|
3686
|
+
const deadline = start + waitS * 1e3;
|
|
3687
|
+
let value = first;
|
|
3688
|
+
while (isRunning(value) && now() < deadline) {
|
|
3689
|
+
await sleep2(Math.min(DOC_GEN_POLL_INTERVAL_MS, deadline - now()));
|
|
3690
|
+
try {
|
|
3691
|
+
value = await read();
|
|
3692
|
+
} catch (err) {
|
|
3693
|
+
return {
|
|
3694
|
+
value,
|
|
3695
|
+
waited_ms: now() - start,
|
|
3696
|
+
still_running: true,
|
|
3697
|
+
poll_error: err instanceof Error ? err.message : String(err)
|
|
3698
|
+
};
|
|
3699
|
+
}
|
|
3700
|
+
}
|
|
3701
|
+
return { value, waited_ms: now() - start, still_running: isRunning(value) };
|
|
3702
|
+
}
|
|
3703
|
+
var STATUS_DESCRIPTION2 = [
|
|
3704
|
+
"Document Generation at a glance: how many templates, field-sheet fields (confirmed, unconfirmed, entered per document), proposals running / failed / never run, and batches of the last 30 days with the latest one.",
|
|
3705
|
+
"USE WHEN: starting any Doc Gen work, or to report where things stand.",
|
|
3706
|
+
"NOT FOR: what to fix (talonic_doc_gen_issues); one template (talonic_doc_gen_templates).",
|
|
3707
|
+
"",
|
|
3708
|
+
"ARGS: none.",
|
|
3709
|
+
"RETURNS: { templates, fields { total, confirmed, unconfirmed, entered_per_document }, proposals { running, failed, never_proposed }, jobs { last_30_days, documents_last_30_days, failed_last_30_days, last } }."
|
|
3710
|
+
].join("\n");
|
|
3711
|
+
function handleStatus(getToken, baseUrl) {
|
|
3712
|
+
return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/doc-gen/status"));
|
|
3713
|
+
}
|
|
3714
|
+
var ISSUES_DESCRIPTION3 = [
|
|
3715
|
+
"The Doc Gen worklist: templates never proposed, proposals failed or with fields left without a suggestion, fields nobody confirmed, and batches of the last 30 days that failed, have failed documents or miss PDFs.",
|
|
3716
|
+
"USE WHEN: deciding what to fix before generating, or after a batch.",
|
|
3717
|
+
"NOT FOR: the headline counts (talonic_doc_gen_status).",
|
|
3718
|
+
"",
|
|
3719
|
+
"ARGS: none.",
|
|
3720
|
+
"RETURNS: { data[] { code (never_proposed|proposal_failed|proposal_pending|fields_unconfirmed|job_failed|documents_failed|pdf_missing), template_id?, template_name?, job_id?, detail, fields?[] } }."
|
|
3721
|
+
].join("\n");
|
|
3722
|
+
function handleIssues3(getToken, baseUrl) {
|
|
3723
|
+
return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/doc-gen/issues"));
|
|
3724
|
+
}
|
|
3725
|
+
var TEMPLATES_DESCRIPTION = [
|
|
3726
|
+
"List the Word templates, or read one template with its field sheet and proposal state.",
|
|
3727
|
+
"USE WHEN: finding a template, or before proposing, fixing or generating: the field sheet names every field's key, label, source ({ type: product|reference|extract|first|case|user|rule|today, ... }) and whether a person confirmed it.",
|
|
3728
|
+
`${ENTERED_RULE}`,
|
|
3729
|
+
"NOT FOR: changing a template (talonic_doc_gen_update_template).",
|
|
3730
|
+
"",
|
|
3731
|
+
"ARGS: `template_id` (one template; omit for the list), `query` (name, group or file contains), `group` (exact group).",
|
|
3732
|
+
"RETURNS: list { data[] { id, name, file, group, kind, pairId, version, dataProductId, field_count, unconfirmed, entered_per_document, generated, lastUsedAt } } or one template { ...template, fields[] { key, label, kind, options, source, confirmed, reason }, proposal { status running|done|failed, productId, startedAt, finishedAt, error, summary } }."
|
|
3733
|
+
].join("\n");
|
|
3734
|
+
var templatesInputSchema = {
|
|
3735
|
+
template_id: templateIdArg.optional(),
|
|
3736
|
+
query: z.string().optional().describe("Name, group or filename contains (list only)."),
|
|
3737
|
+
group: z.string().optional().describe("Only templates of this group (list only).")
|
|
3738
|
+
};
|
|
3739
|
+
function handleTemplates(getToken, baseUrl, args) {
|
|
3740
|
+
return runTool(
|
|
3741
|
+
() => args.template_id ? apiJson(getToken, baseUrl, "GET", `/v1/doc-gen/templates/${args.template_id}`) : apiJson(getToken, baseUrl, "GET", "/v1/doc-gen/templates", {
|
|
3742
|
+
params: { q: args.query, group: args.group }
|
|
3743
|
+
})
|
|
3744
|
+
);
|
|
3745
|
+
}
|
|
3746
|
+
var UPDATE_TEMPLATE_DESCRIPTION = [
|
|
3747
|
+
"Change a template's metadata (name, group, kind, companion template, version) and its fields by key: a field's label, source, confirmed flag or reason. Fields not named stay as they are; an unknown key is refused. Run with dry_run first to see the sheet as it would be.",
|
|
3748
|
+
"USE WHEN: fixing a field the proposal got wrong (e.g. pointing it at another column or making it entered per document with source { type: 'case', caseKey }), or pairing a letter with its agreement.",
|
|
3749
|
+
"Setting `confirmed: true` is a person's decision: only do it when the user asked (see talonic_doc_gen_confirm_fields).",
|
|
3750
|
+
"NOT FOR: confirming many fields at once (talonic_doc_gen_confirm_fields).",
|
|
3751
|
+
"",
|
|
3752
|
+
"ARGS: `template_id`; optional `name`, `group`, `kind` letter|agreement, `pair_template_id`, `version` (null clears group/kind/pair/version); `fields[] { key, label?, source?, confirmed?, reason? }`; `dry_run`.",
|
|
3753
|
+
"RETURNS: { dry_run, template } with the field sheet."
|
|
3754
|
+
].join("\n");
|
|
3755
|
+
var updateTemplateInputSchema = {
|
|
3756
|
+
template_id: templateIdArg,
|
|
3757
|
+
name: z.string().min(1).max(300).optional().describe("New template name."),
|
|
3758
|
+
group: z.string().max(200).nullable().optional().describe("Group; null clears it."),
|
|
3759
|
+
kind: z.enum(["letter", "agreement"]).nullable().optional().describe("Letter or agreement."),
|
|
3760
|
+
pair_template_id: z.string().uuid().nullable().optional().describe("The companion template generated with this one (with_pair); null unpairs."),
|
|
3761
|
+
version: z.string().max(60).nullable().optional().describe("Version label; null clears it."),
|
|
3762
|
+
fields: z.array(
|
|
3763
|
+
z.object({
|
|
3764
|
+
key: z.string().min(1).max(200).describe("Field key from the field sheet."),
|
|
3765
|
+
label: z.string().max(120).optional(),
|
|
3766
|
+
source: z.record(z.string(), z.unknown()).optional().describe(
|
|
3767
|
+
"Field source as the sheet stores it, e.g. { type: 'product', field }, { type: 'reference', column }, { type: 'case', caseKey }, { type: 'user', profile }, { type: 'rule', rule }, { type: 'today' }."
|
|
3768
|
+
),
|
|
3769
|
+
confirmed: z.boolean().optional().describe("Only when the user asked to confirm."),
|
|
3770
|
+
reason: z.string().max(400).nullable().optional()
|
|
3771
|
+
})
|
|
3772
|
+
).max(500).optional().describe("Field changes by key."),
|
|
3773
|
+
dry_run: z.boolean().optional().describe("Return the sheet as it would be; nothing is saved.")
|
|
3774
|
+
};
|
|
3775
|
+
function handleUpdateTemplate(getToken, baseUrl, args) {
|
|
3776
|
+
const { template_id, dry_run, ...changes } = args;
|
|
3777
|
+
const body = Object.fromEntries(Object.entries(changes).filter(([, v]) => v !== void 0));
|
|
3778
|
+
if (Object.keys(body).length === 0) {
|
|
3779
|
+
return Promise.resolve(
|
|
3780
|
+
validationError(
|
|
3781
|
+
"name nothing to change: pass name, group, kind, pair_template_id, version or fields."
|
|
3782
|
+
)
|
|
3783
|
+
);
|
|
3784
|
+
}
|
|
3785
|
+
return runTool(
|
|
3786
|
+
() => apiJson(getToken, baseUrl, "PATCH", `/v1/doc-gen/templates/${template_id}`, {
|
|
3787
|
+
body: { ...body, dry_run: dry_run ?? false }
|
|
3788
|
+
})
|
|
3789
|
+
);
|
|
3790
|
+
}
|
|
3791
|
+
var CONFIRM_DESCRIPTION = [
|
|
3792
|
+
"Confirm fields of a template's field sheet: the named keys, or every unconfirmed field (with include_entered false, leaving the fields entered per document unconfirmed). Confirming says a person checked the field's source; it is the user's decision, so only call this when the user asked to confirm. Run with dry_run first to list what would be confirmed.",
|
|
3793
|
+
"USE WHEN: the user reviewed the sheet and asks to confirm it (or some fields).",
|
|
3794
|
+
"NOT FOR: changing a field's source (talonic_doc_gen_update_template).",
|
|
3795
|
+
"",
|
|
3796
|
+
"ARGS: `template_id`, `keys[]` (omit for every unconfirmed field), `include_entered` (default true; only without keys), `dry_run`.",
|
|
3797
|
+
"RETURNS: { dry_run, confirmed[] { key, label, source } }."
|
|
3798
|
+
].join("\n");
|
|
3799
|
+
var confirmInputSchema = {
|
|
3800
|
+
template_id: templateIdArg,
|
|
3801
|
+
keys: z.array(z.string()).max(500).optional().describe("Field keys to confirm."),
|
|
3802
|
+
include_entered: z.boolean().optional().describe("Without keys: also confirm the fields entered per document (default true)."),
|
|
3803
|
+
dry_run: z.boolean().optional().describe("List what would be confirmed; nothing is saved.")
|
|
3804
|
+
};
|
|
3805
|
+
function handleConfirm(getToken, baseUrl, args) {
|
|
3806
|
+
return runTool(
|
|
3807
|
+
() => apiJson(getToken, baseUrl, "POST", `/v1/doc-gen/templates/${args.template_id}/confirm`, {
|
|
3808
|
+
body: {
|
|
3809
|
+
...args.keys ? { keys: args.keys } : {},
|
|
3810
|
+
...args.include_entered !== void 0 ? { include_entered: args.include_entered } : {},
|
|
3811
|
+
dry_run: args.dry_run ?? false
|
|
3812
|
+
}
|
|
3813
|
+
})
|
|
3814
|
+
);
|
|
3815
|
+
}
|
|
3816
|
+
var PROPOSE_DESCRIPTION = [
|
|
3817
|
+
"Propose a template's field sheet from a data product: the platform reads the product's columns (and its reference table) and suggests a source for every field; suggestions stay unconfirmed. One template runs in the background: pass `wait_seconds` to wait for it (polls every 3 s). Without template_id, starts proposals for several templates (bulk; dry_run first).",
|
|
3818
|
+
"USE WHEN: a template is new, never proposed, or should be mapped to another product. Then read the sheet with talonic_doc_gen_templates and fix fields by key.",
|
|
3819
|
+
"NOT FOR: setting one field (talonic_doc_gen_update_template).",
|
|
3820
|
+
"",
|
|
3821
|
+
"ARGS: `data_product_id`; one template: `template_id`, `force` (propose again although the sheet was proposed for this product), `wait_seconds` (0-120, default 0). Bulk: `template_ids[]` (omit for all), `only_unproposed` (default true), `force`, `limit` (1-50, default 10), `dry_run`.",
|
|
3822
|
+
"RETURNS: one template: { proposal { status running|done|failed, summary { fields, proposed, kept, fromData, derived, entered, profile, pending[] }, error }, template } or after a wait { template_id, proposal, waited_ms, still_running }. Bulk: { dry_run, started[] | would_start[], skipped }; poll each with talonic_doc_gen_templates."
|
|
3823
|
+
].join("\n");
|
|
3824
|
+
var proposeInputSchema = {
|
|
3825
|
+
data_product_id: productIdArg,
|
|
3826
|
+
template_id: templateIdArg.optional().describe("One template; omit for a bulk proposal."),
|
|
3827
|
+
force: z.boolean().optional().describe("Propose again although already proposed."),
|
|
3828
|
+
wait_seconds: z.number().min(0).max(PROPOSE_MAX_WAIT_S).optional().describe(`One template: seconds to wait for the proposal (0-${PROPOSE_MAX_WAIT_S}).`),
|
|
3829
|
+
template_ids: z.array(z.string().uuid()).max(200).optional().describe("Bulk: only these templates."),
|
|
3830
|
+
only_unproposed: z.boolean().optional().describe("Bulk: only templates not yet proposed for this product (default true)."),
|
|
3831
|
+
limit: z.number().int().min(1).max(50).optional().describe("Bulk: at most this many."),
|
|
3832
|
+
dry_run: z.boolean().optional().describe("Bulk: list what would start.")
|
|
3833
|
+
};
|
|
3834
|
+
function handlePropose(getToken, baseUrl, args, deps = {}) {
|
|
3835
|
+
if (!args.template_id) {
|
|
3836
|
+
return runTool(
|
|
3837
|
+
() => apiJson(getToken, baseUrl, "POST", "/v1/doc-gen/templates/propose", {
|
|
3838
|
+
body: {
|
|
3839
|
+
data_product_id: args.data_product_id,
|
|
3840
|
+
...args.template_ids ? { template_ids: args.template_ids } : {},
|
|
3841
|
+
...args.only_unproposed !== void 0 ? { only_unproposed: args.only_unproposed } : {},
|
|
3842
|
+
force: args.force ?? false,
|
|
3843
|
+
...args.limit ? { limit: args.limit } : {},
|
|
3844
|
+
dry_run: args.dry_run ?? false
|
|
3845
|
+
}
|
|
3846
|
+
})
|
|
3847
|
+
);
|
|
3848
|
+
}
|
|
3849
|
+
const id = args.template_id;
|
|
3850
|
+
const waitS = waitSeconds(args.wait_seconds, PROPOSE_MAX_WAIT_S);
|
|
3851
|
+
return runTool(async () => {
|
|
3852
|
+
const started = await apiJson(
|
|
3853
|
+
getToken,
|
|
3854
|
+
baseUrl,
|
|
3855
|
+
"POST",
|
|
3856
|
+
`/v1/doc-gen/templates/${id}/propose`,
|
|
3857
|
+
{ body: { data_product_id: args.data_product_id, force: args.force ?? false } }
|
|
3858
|
+
);
|
|
3859
|
+
if (waitS === 0) return started;
|
|
3860
|
+
const polled = await pollUntilDone(
|
|
3861
|
+
started,
|
|
3862
|
+
() => apiJson(getToken, baseUrl, "GET", `/v1/doc-gen/templates/${id}/proposal`),
|
|
3863
|
+
(r) => r.proposal?.status === "running",
|
|
3864
|
+
waitS,
|
|
3865
|
+
deps
|
|
3866
|
+
);
|
|
3867
|
+
return {
|
|
3868
|
+
template_id: id,
|
|
3869
|
+
proposal: polled.value.proposal ?? null,
|
|
3870
|
+
waited_ms: polled.waited_ms,
|
|
3871
|
+
still_running: polled.still_running,
|
|
3872
|
+
...polled.poll_error ? { poll_error: polled.poll_error } : {},
|
|
3873
|
+
next: polled.still_running ? "Still running: call talonic_doc_gen_templates with this template_id later." : "Read the field sheet with talonic_doc_gen_templates and fix fields by key."
|
|
3874
|
+
};
|
|
3875
|
+
});
|
|
3876
|
+
}
|
|
3877
|
+
var UPLOAD_DESCRIPTION = [
|
|
3878
|
+
"Upload a Word template (.docx or .dotx) to Document Generation. Its placeholders become the field sheet; propose it against a data product next.",
|
|
3879
|
+
"USE WHEN: the user gives a new letter or agreement template.",
|
|
3880
|
+
"NOT FOR: documents to read data from (talonic_request_upload / talonic_extract).",
|
|
3881
|
+
"",
|
|
3882
|
+
"ARGS: `filename` (with extension) and `content_base64` (the file bytes); in a local install `file_path` instead (the server reads the file). Optional `name`, `group`, `kind` letter|agreement, `version`.",
|
|
3883
|
+
"RETURNS: the new template with its fields."
|
|
3884
|
+
].join("\n");
|
|
3885
|
+
var uploadBaseSchema = {
|
|
3886
|
+
filename: z.string().min(1).max(300).optional().describe("File name with extension, e.g. 'Kuendigung.docx'."),
|
|
3887
|
+
content_base64: z.string().min(1).optional().describe("The .docx / .dotx bytes, base64."),
|
|
3888
|
+
name: z.string().max(300).optional().describe("Template name (default: from the file)."),
|
|
3889
|
+
group: z.string().max(200).optional().describe("Group the template belongs to."),
|
|
3890
|
+
kind: z.enum(["letter", "agreement"]).optional().describe("Letter or agreement."),
|
|
3891
|
+
version: z.string().max(60).optional().describe("Version label.")
|
|
3892
|
+
};
|
|
3893
|
+
var uploadInputSchema = uploadBaseSchema;
|
|
3894
|
+
var uploadLocalInputSchema = {
|
|
3895
|
+
...uploadBaseSchema,
|
|
3896
|
+
file_path: z.string().min(1).optional().describe("Local path to the .docx / .dotx (local installs only); replaces content_base64.")
|
|
3897
|
+
};
|
|
3898
|
+
async function handleUpload(getToken, baseUrl, args, opts = {}) {
|
|
3899
|
+
if (args.file_path !== void 0 && !opts.localFiles) {
|
|
3900
|
+
return validationError("file_path works only in a local install; send content_base64.");
|
|
3901
|
+
}
|
|
3902
|
+
if (args.file_path === void 0 === (args.content_base64 === void 0)) {
|
|
3903
|
+
return validationError(
|
|
3904
|
+
opts.localFiles ? "pass exactly one of content_base64 (with filename) or file_path." : "content_base64 (with filename) is required."
|
|
3905
|
+
);
|
|
3906
|
+
}
|
|
3907
|
+
let content = args.content_base64;
|
|
3908
|
+
let filename = args.filename;
|
|
3909
|
+
if (args.file_path !== void 0) {
|
|
3910
|
+
try {
|
|
3911
|
+
content = (await readFile(args.file_path)).toString("base64");
|
|
3912
|
+
} catch (err) {
|
|
3913
|
+
return toolError(err);
|
|
3914
|
+
}
|
|
3915
|
+
filename = filename ?? basename(args.file_path);
|
|
3916
|
+
}
|
|
3917
|
+
if (!filename) return validationError("filename is required with content_base64.");
|
|
3918
|
+
return runTool(
|
|
3919
|
+
() => apiJson(getToken, baseUrl, "POST", "/v1/doc-gen/templates", {
|
|
3920
|
+
body: {
|
|
3921
|
+
filename,
|
|
3922
|
+
content_base64: content,
|
|
3923
|
+
...args.name ? { name: args.name } : {},
|
|
3924
|
+
...args.group ? { group: args.group } : {},
|
|
3925
|
+
...args.kind ? { kind: args.kind } : {},
|
|
3926
|
+
...args.version ? { version: args.version } : {}
|
|
3927
|
+
}
|
|
3928
|
+
})
|
|
3929
|
+
);
|
|
3930
|
+
}
|
|
3931
|
+
var DELETE_DESCRIPTION = [
|
|
3932
|
+
"Delete a template and its field sheet for good. Generated batches keep their documents. Cannot be undone; only when the user asked.",
|
|
3933
|
+
"USE WHEN: the user asks to remove a template.",
|
|
3934
|
+
"NOT FOR: replacing the Word file (upload the new one, then delete the old one if asked).",
|
|
3935
|
+
"",
|
|
3936
|
+
"ARGS: `template_id`.",
|
|
3937
|
+
"RETURNS: { ok: true }."
|
|
3938
|
+
].join("\n");
|
|
3939
|
+
var deleteInputSchema = { template_id: templateIdArg };
|
|
3940
|
+
function handleDelete(getToken, baseUrl, args) {
|
|
3941
|
+
return runTool(
|
|
3942
|
+
() => apiJson(getToken, baseUrl, "DELETE", `/v1/doc-gen/templates/${args.template_id}`)
|
|
3943
|
+
);
|
|
3944
|
+
}
|
|
3945
|
+
var PRODUCTS_DESCRIPTION = [
|
|
3946
|
+
"The data products a template is filled from: the list, one product with its columns and reference table, or its rows (one document per row).",
|
|
3947
|
+
"USE WHEN: choosing the product to propose or generate against, or picking the rows (record ids) to generate for.",
|
|
3948
|
+
"NOT FOR: the template's fields (talonic_doc_gen_templates).",
|
|
3949
|
+
"",
|
|
3950
|
+
"ARGS: `product_id` (one product; omit for the list); with `records: true` its rows, filtered by `query` (label or any value contains) and `limit` (1-500, default 50).",
|
|
3951
|
+
"RETURNS: list { data[] }, one product { id, name, columns[], reference }, or rows { total, data[] { id, label, values, documents } }."
|
|
3952
|
+
].join("\n");
|
|
3953
|
+
var productsInputSchema = {
|
|
3954
|
+
product_id: productIdArg.optional(),
|
|
3955
|
+
records: z.boolean().optional().describe("List the product's rows (needs product_id)."),
|
|
3956
|
+
query: z.string().optional().describe("Rows whose label or any value contains this."),
|
|
3957
|
+
limit: z.number().int().min(1).max(500).optional().describe("Rows returned (default 50).")
|
|
3958
|
+
};
|
|
3959
|
+
function handleProducts(getToken, baseUrl, args) {
|
|
3960
|
+
if (args.records && !args.product_id) {
|
|
3961
|
+
return Promise.resolve(validationError("records needs a product_id."));
|
|
3962
|
+
}
|
|
3963
|
+
return runTool(() => {
|
|
3964
|
+
if (!args.product_id) return apiJson(getToken, baseUrl, "GET", "/v1/doc-gen/products");
|
|
3965
|
+
if (!args.records) {
|
|
3966
|
+
return apiJson(getToken, baseUrl, "GET", `/v1/doc-gen/products/${args.product_id}`);
|
|
3967
|
+
}
|
|
3968
|
+
return apiJson(getToken, baseUrl, "GET", `/v1/doc-gen/products/${args.product_id}/records`, {
|
|
3969
|
+
params: { q: args.query, limit: args.limit ?? 50 }
|
|
3970
|
+
});
|
|
3971
|
+
});
|
|
3972
|
+
}
|
|
3973
|
+
var RULES_DESCRIPTION = [
|
|
3974
|
+
"Read the workspace's rules (named derivations a field with source { type: 'rule', rule } uses, e.g. a salutation from a gender column), or replace them all with `rules`. Replacing deletes every rule not in the new list: read first, change, send the whole list, and only when the user asked.",
|
|
3975
|
+
"USE WHEN: explaining a rule-sourced value, or setting up the workspace's rules.",
|
|
3976
|
+
"NOT FOR: one field's source (talonic_doc_gen_update_template).",
|
|
3977
|
+
"",
|
|
3978
|
+
"ARGS: none to read; `rules[] { name, description?, definition }` to replace.",
|
|
3979
|
+
"RETURNS: { data[] { name, description, definition } } (after a replace: the stored list)."
|
|
3980
|
+
].join("\n");
|
|
3981
|
+
var rulesInputSchema = {
|
|
3982
|
+
rules: z.array(
|
|
3983
|
+
z.object({
|
|
3984
|
+
name: z.string().min(1).max(120),
|
|
3985
|
+
description: z.string().max(500).optional(),
|
|
3986
|
+
definition: z.record(z.string(), z.unknown()).describe("The rule's definition object.")
|
|
3987
|
+
})
|
|
3988
|
+
).max(500).optional().describe("The complete new list; omit to read.")
|
|
3989
|
+
};
|
|
3990
|
+
function handleRules(getToken, baseUrl, args) {
|
|
3991
|
+
return runTool(
|
|
3992
|
+
() => args.rules ? apiJson(getToken, baseUrl, "PUT", "/v1/doc-gen/rules", { body: { rules: args.rules } }) : apiJson(getToken, baseUrl, "GET", "/v1/doc-gen/rules")
|
|
3993
|
+
);
|
|
3994
|
+
}
|
|
3995
|
+
var PROFILE_KEYS = ["name", "kuerzel", "titel", "bereich", "unterschrift"];
|
|
3996
|
+
var PROFILE_DESCRIPTION = [
|
|
3997
|
+
"Read or change the writer's details a fill reads for fields with source { type: 'user' }: name, kuerzel (initials), titel, bereich (department), unterschrift (signature line). They belong to the person who owns the key or signed in. Changing merges the given details into the saved ones; only when the user asked.",
|
|
3998
|
+
"USE WHEN: a draft is missing a profile field, or the user asks to set their details. For one batch only, pass `profile` to talonic_doc_gen_draft / _generate instead.",
|
|
3999
|
+
"NOT FOR: per-document values (`values` on talonic_doc_gen_generate).",
|
|
4000
|
+
"",
|
|
4001
|
+
"ARGS: none to read; any of `name`, `kuerzel`, `titel`, `bereich`, `unterschrift` to save.",
|
|
4002
|
+
"RETURNS: { name, kuerzel, titel, bereich, unterschrift }."
|
|
4003
|
+
].join("\n");
|
|
4004
|
+
var profileInputSchema = Object.fromEntries(
|
|
4005
|
+
PROFILE_KEYS.map((k) => [k, z.string().max(200).optional()])
|
|
4006
|
+
);
|
|
4007
|
+
function handleProfile(getToken, baseUrl, args) {
|
|
4008
|
+
const given = PROFILE_KEYS.filter((k) => typeof args[k] === "string");
|
|
4009
|
+
return runTool(async () => {
|
|
4010
|
+
const current = await apiJson(
|
|
4011
|
+
getToken,
|
|
4012
|
+
baseUrl,
|
|
4013
|
+
"GET",
|
|
4014
|
+
"/v1/doc-gen/profile"
|
|
4015
|
+
);
|
|
4016
|
+
if (!given.length) return current;
|
|
4017
|
+
const body = {};
|
|
4018
|
+
for (const k of PROFILE_KEYS) {
|
|
4019
|
+
const v = typeof args[k] === "string" ? args[k] : current[k];
|
|
4020
|
+
if (typeof v === "string") body[k] = v;
|
|
4021
|
+
}
|
|
4022
|
+
return apiJson(getToken, baseUrl, "PUT", "/v1/doc-gen/profile", { body });
|
|
4023
|
+
});
|
|
4024
|
+
}
|
|
4025
|
+
var batchSchema = {
|
|
4026
|
+
template_id: templateIdArg.optional().describe("The template to fill (with_pair adds its companion). Or template_ids."),
|
|
4027
|
+
template_ids: z.array(z.string().uuid()).min(1).max(10).optional().describe("An explicit set of templates instead of template_id."),
|
|
4028
|
+
with_pair: z.boolean().optional().describe("Also fill template_id's companion template."),
|
|
4029
|
+
data_product_id: productIdArg,
|
|
4030
|
+
record_ids: z.array(z.string().min(1).max(200)).min(1).max(500).describe("Row ids from talonic_doc_gen_products (records: true): one document per row."),
|
|
4031
|
+
values: valuesArg.optional().describe(`Values for every document of the batch. ${ENTERED_RULE}`),
|
|
4032
|
+
documents: z.array(
|
|
4033
|
+
z.object({
|
|
4034
|
+
record_id: z.string().min(1).max(200),
|
|
4035
|
+
template_id: z.string().uuid().optional().describe("Only this template's document."),
|
|
4036
|
+
values: valuesArg
|
|
4037
|
+
})
|
|
4038
|
+
).max(5e3).optional().describe("Values for single documents (over `values`)."),
|
|
4039
|
+
profile: z.record(z.string(), z.string()).optional().describe(
|
|
4040
|
+
"Writer details for this batch only (name, kuerzel, titel, bereich, unterschrift); the saved profile is unchanged."
|
|
4041
|
+
)
|
|
4042
|
+
};
|
|
4043
|
+
function batchBody(args) {
|
|
4044
|
+
return {
|
|
4045
|
+
...args.template_id ? { template_id: args.template_id } : {},
|
|
4046
|
+
...args.template_ids ? { template_ids: args.template_ids } : {},
|
|
4047
|
+
...args.with_pair !== void 0 ? { with_pair: args.with_pair } : {},
|
|
4048
|
+
data_product_id: args.data_product_id,
|
|
4049
|
+
record_ids: args.record_ids,
|
|
4050
|
+
...args.values ? { values: args.values } : {},
|
|
4051
|
+
...args.documents ? { documents: args.documents } : {},
|
|
4052
|
+
...args.profile ? { profile: args.profile } : {}
|
|
4053
|
+
};
|
|
4054
|
+
}
|
|
4055
|
+
function needsTemplate(args) {
|
|
4056
|
+
if (!args.template_id && !args.template_ids?.length) {
|
|
4057
|
+
return validationError("name a template_id (or template_ids).");
|
|
4058
|
+
}
|
|
4059
|
+
return null;
|
|
4060
|
+
}
|
|
4061
|
+
var DRAFT_DESCRIPTION = [
|
|
4062
|
+
"Fill documents without generating them: for each row and template, every field's value with its origin, and what is still missing. Nothing is stored.",
|
|
4063
|
+
"USE WHEN: before talonic_doc_gen_generate, to check `missing` and the values the data gives.",
|
|
4064
|
+
ENTERED_RULE,
|
|
4065
|
+
"NOT FOR: making the files (talonic_doc_gen_generate).",
|
|
4066
|
+
"",
|
|
4067
|
+
"ARGS: `template_id` (+ `with_pair`) or `template_ids`, `data_product_id`, `record_ids[]`, optional `values`, `documents[] { record_id, template_id?, values }`, `profile`.",
|
|
4068
|
+
"RETURNS: { templates[] { id, name }, documents[] { template_id, template_name, record_id, record_label, filled, total, missing[] { key, label, source }, values } }."
|
|
4069
|
+
].join("\n");
|
|
4070
|
+
var draftInputSchema = batchSchema;
|
|
4071
|
+
function handleDraft(getToken, baseUrl, args) {
|
|
4072
|
+
const invalid = needsTemplate(args);
|
|
4073
|
+
if (invalid) return Promise.resolve(invalid);
|
|
4074
|
+
return runTool(
|
|
4075
|
+
() => apiJson(getToken, baseUrl, "POST", "/v1/doc-gen/drafts", { body: batchBody(args) })
|
|
4076
|
+
);
|
|
4077
|
+
}
|
|
4078
|
+
var GENERATE_DESCRIPTION = [
|
|
4079
|
+
"Fill and generate the documents: one Word file (and PDF) per row and template, every value's origin kept in the document history. Refused while documents leave fields empty unless `allow_missing` (the empty fields are left out). The batch runs in the background: pass `wait_seconds` to wait for it (polls every 3 s). Run talonic_doc_gen_draft (or dry_run) first.",
|
|
4080
|
+
"USE WHEN: the user asks to generate letters or agreements for rows of a product.",
|
|
4081
|
+
ENTERED_RULE,
|
|
4082
|
+
"NOT FOR: checking values (talonic_doc_gen_draft).",
|
|
4083
|
+
"",
|
|
4084
|
+
"ARGS: as talonic_doc_gen_draft, plus `save_to_workspace` (default true; false deletes the files after 24 hours), `allow_missing`, `dry_run` (the drafts only), `wait_seconds` (0-300, default 0).",
|
|
4085
|
+
"RETURNS: { dry_run, documents[] (as draft), job { id, status running|completed|failed, documents[] { id, status, files[] { kind, name, size }, error, pdfError } } } and after a wait also { waited_ms, still_running }. Download with talonic_doc_gen_file."
|
|
4086
|
+
].join("\n");
|
|
4087
|
+
var generateInputSchema = {
|
|
4088
|
+
...batchSchema,
|
|
4089
|
+
save_to_workspace: z.boolean().optional().describe("Keep the files in the workspace (default true); false deletes them after 24 h."),
|
|
4090
|
+
allow_missing: z.boolean().optional().describe("Generate although fields are empty (they are left out of the documents)."),
|
|
4091
|
+
dry_run: z.boolean().optional().describe("Return the drafts only; no batch is made."),
|
|
4092
|
+
wait_seconds: z.number().min(0).max(GENERATE_MAX_WAIT_S).optional().describe(`Seconds to wait for the batch to finish (0-${GENERATE_MAX_WAIT_S}).`)
|
|
4093
|
+
};
|
|
4094
|
+
function handleGenerate(getToken, baseUrl, args, deps = {}) {
|
|
4095
|
+
const invalid = needsTemplate(args);
|
|
4096
|
+
if (invalid) return Promise.resolve(invalid);
|
|
4097
|
+
const waitS = waitSeconds(args.wait_seconds, GENERATE_MAX_WAIT_S);
|
|
4098
|
+
return runTool(async () => {
|
|
4099
|
+
const created = await apiJson(getToken, baseUrl, "POST", "/v1/doc-gen/jobs", {
|
|
4100
|
+
body: {
|
|
4101
|
+
...batchBody(args),
|
|
4102
|
+
...args.save_to_workspace !== void 0 ? { save_to_workspace: args.save_to_workspace } : {},
|
|
4103
|
+
allow_missing: args.allow_missing ?? false,
|
|
4104
|
+
dry_run: args.dry_run ?? false
|
|
4105
|
+
}
|
|
4106
|
+
});
|
|
4107
|
+
const jobId = created.job?.id;
|
|
4108
|
+
if (waitS === 0 || !jobId || created.job?.status !== "running") return created;
|
|
4109
|
+
const polled = await pollUntilDone(
|
|
4110
|
+
created.job,
|
|
4111
|
+
() => apiJson(
|
|
4112
|
+
getToken,
|
|
4113
|
+
baseUrl,
|
|
4114
|
+
"GET",
|
|
4115
|
+
`/v1/doc-gen/jobs/${jobId}`
|
|
4116
|
+
),
|
|
4117
|
+
(job) => job?.status === "running",
|
|
4118
|
+
waitS,
|
|
4119
|
+
deps
|
|
4120
|
+
);
|
|
4121
|
+
return {
|
|
4122
|
+
...created,
|
|
4123
|
+
job: polled.value,
|
|
4124
|
+
waited_ms: polled.waited_ms,
|
|
4125
|
+
still_running: polled.still_running,
|
|
4126
|
+
...polled.poll_error ? { poll_error: polled.poll_error } : {}
|
|
4127
|
+
};
|
|
4128
|
+
});
|
|
4129
|
+
}
|
|
4130
|
+
var JOBS_DESCRIPTION = [
|
|
4131
|
+
"Generated batches: the history (newest first, with document, failed and PDF-missing counts), or one batch with its documents, their files and errors.",
|
|
4132
|
+
"USE WHEN: checking a batch started by talonic_doc_gen_generate, or finding the document ids to download.",
|
|
4133
|
+
"NOT FOR: the file itself (talonic_doc_gen_file).",
|
|
4134
|
+
"",
|
|
4135
|
+
"ARGS: `job_id` (one batch; omit for the history), `limit` (1-50, history only).",
|
|
4136
|
+
"RETURNS: { data[] } or one batch { id, status, templateNames, savedToWorkspace, filesExpireAt, filesExpired, documents[] { id, recordLabel, status, files[] { kind, name, size }, error, pdfError } }."
|
|
4137
|
+
].join("\n");
|
|
4138
|
+
var jobsInputSchema = {
|
|
4139
|
+
job_id: jobIdArg.optional(),
|
|
4140
|
+
limit: z.number().int().min(1).max(50).optional().describe("History entries (default 50).")
|
|
4141
|
+
};
|
|
4142
|
+
function handleJobs(getToken, baseUrl, args) {
|
|
4143
|
+
return runTool(
|
|
4144
|
+
() => args.job_id ? apiJson(getToken, baseUrl, "GET", `/v1/doc-gen/jobs/${args.job_id}`) : apiJson(getToken, baseUrl, "GET", "/v1/doc-gen/jobs", { params: { limit: args.limit } })
|
|
4145
|
+
);
|
|
4146
|
+
}
|
|
4147
|
+
var RETRY_PDF_DESCRIPTION = [
|
|
4148
|
+
"Make a batch's missing PDFs again (documents whose Word file was made but the PDF conversion failed).",
|
|
4149
|
+
"USE WHEN: talonic_doc_gen_issues reports pdf_missing, or a batch's documents carry pdfError.",
|
|
4150
|
+
"NOT FOR: failed documents (fix the data or values and generate again).",
|
|
4151
|
+
"",
|
|
4152
|
+
"ARGS: `job_id`.",
|
|
4153
|
+
"RETURNS: the batch as talonic_doc_gen_jobs returns it."
|
|
4154
|
+
].join("\n");
|
|
4155
|
+
var retryPdfInputSchema = { job_id: jobIdArg };
|
|
4156
|
+
function handleRetryPdf(getToken, baseUrl, args) {
|
|
4157
|
+
return runTool(() => apiJson(getToken, baseUrl, "POST", `/v1/doc-gen/jobs/${args.job_id}/pdf`));
|
|
4158
|
+
}
|
|
4159
|
+
var FILE_DESCRIPTION = [
|
|
4160
|
+
`Download one generated document as an embedded file (base64 blob with its media type and filename), up to ${DOC_GEN_MAX_FILE_BYTES / (1024 * 1024)} MB.`,
|
|
4161
|
+
"USE WHEN: the user wants the generated Word file or PDF of a document.",
|
|
4162
|
+
"NOT FOR: the batch's state (talonic_doc_gen_jobs).",
|
|
4163
|
+
"",
|
|
4164
|
+
"ARGS: `job_id`, `document_id` (documents[].id of the batch), `kind` docx|pdf (default docx).",
|
|
4165
|
+
"RETURNS: a text item { filename, mime_type, size } and a resource item { uri, mimeType, blob }. Files of a batch not kept in the workspace are gone after 24 hours."
|
|
4166
|
+
].join("\n");
|
|
4167
|
+
var fileInputSchema = {
|
|
4168
|
+
job_id: jobIdArg,
|
|
4169
|
+
document_id: z.string().uuid().describe("documents[].id of the batch (talonic_doc_gen_jobs)."),
|
|
4170
|
+
kind: z.enum(["docx", "pdf"]).optional().describe("Word file or PDF (default docx).")
|
|
4171
|
+
};
|
|
4172
|
+
async function handleFile(getToken, baseUrl, args, maxBytes = DOC_GEN_MAX_FILE_BYTES) {
|
|
4173
|
+
const kind = args.kind ?? "docx";
|
|
4174
|
+
const path = `/v1/doc-gen/jobs/${args.job_id}/documents/${args.document_id}/file`;
|
|
4175
|
+
try {
|
|
4176
|
+
const file = await apiBinary(getToken, baseUrl, path, { params: { kind }, maxBytes });
|
|
4177
|
+
const filename = file.filename ?? `${args.document_id}.${kind}`;
|
|
4178
|
+
const meta = { filename, mime_type: file.mimeType, size: file.bytes.length, kind };
|
|
4179
|
+
return {
|
|
4180
|
+
content: [
|
|
4181
|
+
{ type: "text", text: JSON.stringify(meta, null, 2) },
|
|
4182
|
+
{
|
|
4183
|
+
type: "resource",
|
|
4184
|
+
resource: {
|
|
4185
|
+
uri: buildUrl(baseUrl, path, { kind }),
|
|
4186
|
+
mimeType: file.mimeType,
|
|
4187
|
+
blob: file.bytes.toString("base64")
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
],
|
|
4191
|
+
structuredContent: meta
|
|
4192
|
+
};
|
|
4193
|
+
} catch (err) {
|
|
4194
|
+
return toolError(err);
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4197
|
+
function registerDocGenTools(server, getToken, baseUrl, opts = {}) {
|
|
4198
|
+
const tools = [
|
|
4199
|
+
[
|
|
4200
|
+
"talonic_doc_gen_status",
|
|
4201
|
+
"Document Generation status",
|
|
4202
|
+
STATUS_DESCRIPTION2,
|
|
4203
|
+
{},
|
|
4204
|
+
readOnly3,
|
|
4205
|
+
() => handleStatus(getToken, baseUrl)
|
|
4206
|
+
],
|
|
4207
|
+
[
|
|
4208
|
+
"talonic_doc_gen_issues",
|
|
4209
|
+
"Document Generation worklist",
|
|
4210
|
+
ISSUES_DESCRIPTION3,
|
|
4211
|
+
{},
|
|
4212
|
+
readOnly3,
|
|
4213
|
+
() => handleIssues3(getToken, baseUrl)
|
|
4214
|
+
],
|
|
4215
|
+
[
|
|
4216
|
+
"talonic_doc_gen_templates",
|
|
4217
|
+
"Word templates and field sheets",
|
|
4218
|
+
TEMPLATES_DESCRIPTION,
|
|
4219
|
+
templatesInputSchema,
|
|
4220
|
+
readOnly3,
|
|
4221
|
+
(a) => handleTemplates(getToken, baseUrl, a)
|
|
4222
|
+
],
|
|
4223
|
+
[
|
|
4224
|
+
"talonic_doc_gen_update_template",
|
|
4225
|
+
"Change a template and its fields",
|
|
4226
|
+
UPDATE_TEMPLATE_DESCRIPTION,
|
|
4227
|
+
updateTemplateInputSchema,
|
|
4228
|
+
// Overwrites field sources and metadata: destructive per OpenAI's annotation rules.
|
|
4229
|
+
write3(true, true),
|
|
4230
|
+
(a) => handleUpdateTemplate(getToken, baseUrl, a)
|
|
4231
|
+
],
|
|
4232
|
+
[
|
|
4233
|
+
"talonic_doc_gen_confirm_fields",
|
|
4234
|
+
"Confirm template fields",
|
|
4235
|
+
CONFIRM_DESCRIPTION,
|
|
4236
|
+
confirmInputSchema,
|
|
4237
|
+
write3(true),
|
|
4238
|
+
(a) => handleConfirm(getToken, baseUrl, a)
|
|
4239
|
+
],
|
|
4240
|
+
[
|
|
4241
|
+
"talonic_doc_gen_propose",
|
|
4242
|
+
"Propose a field sheet from a product",
|
|
4243
|
+
PROPOSE_DESCRIPTION,
|
|
4244
|
+
proposeInputSchema,
|
|
4245
|
+
write3(false),
|
|
4246
|
+
(a) => handlePropose(getToken, baseUrl, a)
|
|
4247
|
+
],
|
|
4248
|
+
[
|
|
4249
|
+
"talonic_doc_gen_upload_template",
|
|
4250
|
+
"Upload a Word template",
|
|
4251
|
+
UPLOAD_DESCRIPTION,
|
|
4252
|
+
opts.localFiles ? uploadLocalInputSchema : uploadInputSchema,
|
|
4253
|
+
write3(false),
|
|
4254
|
+
(a) => handleUpload(getToken, baseUrl, a, { localFiles: opts.localFiles === true })
|
|
4255
|
+
],
|
|
4256
|
+
[
|
|
4257
|
+
"talonic_doc_gen_delete_template",
|
|
4258
|
+
"Delete a template",
|
|
4259
|
+
DELETE_DESCRIPTION,
|
|
4260
|
+
deleteInputSchema,
|
|
4261
|
+
write3(true, true),
|
|
4262
|
+
(a) => handleDelete(getToken, baseUrl, a)
|
|
4263
|
+
],
|
|
4264
|
+
[
|
|
4265
|
+
"talonic_doc_gen_products",
|
|
4266
|
+
"Data products and rows",
|
|
4267
|
+
PRODUCTS_DESCRIPTION,
|
|
4268
|
+
productsInputSchema,
|
|
4269
|
+
readOnly3,
|
|
4270
|
+
(a) => handleProducts(getToken, baseUrl, a)
|
|
4271
|
+
],
|
|
4272
|
+
[
|
|
4273
|
+
"talonic_doc_gen_rules",
|
|
4274
|
+
"Workspace rules",
|
|
4275
|
+
RULES_DESCRIPTION,
|
|
4276
|
+
rulesInputSchema,
|
|
4277
|
+
// With `rules` it replaces the whole list: destructive.
|
|
4278
|
+
write3(true, true),
|
|
4279
|
+
(a) => handleRules(getToken, baseUrl, a)
|
|
4280
|
+
],
|
|
4281
|
+
[
|
|
4282
|
+
"talonic_doc_gen_profile",
|
|
4283
|
+
"Writer profile",
|
|
4284
|
+
PROFILE_DESCRIPTION,
|
|
4285
|
+
profileInputSchema,
|
|
4286
|
+
// With details it overwrites the saved ones: destructive per OpenAI's annotation rules.
|
|
4287
|
+
write3(true, true),
|
|
4288
|
+
(a) => handleProfile(getToken, baseUrl, a)
|
|
4289
|
+
],
|
|
4290
|
+
[
|
|
4291
|
+
"talonic_doc_gen_draft",
|
|
4292
|
+
"Fill documents without generating",
|
|
4293
|
+
DRAFT_DESCRIPTION,
|
|
4294
|
+
draftInputSchema,
|
|
4295
|
+
readOnly3,
|
|
4296
|
+
(a) => handleDraft(getToken, baseUrl, a)
|
|
4297
|
+
],
|
|
4298
|
+
[
|
|
4299
|
+
"talonic_doc_gen_generate",
|
|
4300
|
+
"Generate documents",
|
|
4301
|
+
GENERATE_DESCRIPTION,
|
|
4302
|
+
generateInputSchema,
|
|
4303
|
+
write3(false),
|
|
4304
|
+
(a) => handleGenerate(getToken, baseUrl, a)
|
|
4305
|
+
],
|
|
4306
|
+
[
|
|
4307
|
+
"talonic_doc_gen_jobs",
|
|
4308
|
+
"Generated batches",
|
|
4309
|
+
JOBS_DESCRIPTION,
|
|
4310
|
+
jobsInputSchema,
|
|
4311
|
+
readOnly3,
|
|
4312
|
+
(a) => handleJobs(getToken, baseUrl, a)
|
|
4313
|
+
],
|
|
4314
|
+
[
|
|
4315
|
+
"talonic_doc_gen_retry_pdf",
|
|
4316
|
+
"Make missing PDFs again",
|
|
4317
|
+
RETRY_PDF_DESCRIPTION,
|
|
4318
|
+
retryPdfInputSchema,
|
|
4319
|
+
write3(true),
|
|
4320
|
+
(a) => handleRetryPdf(getToken, baseUrl, a)
|
|
4321
|
+
],
|
|
4322
|
+
[
|
|
4323
|
+
"talonic_doc_gen_file",
|
|
4324
|
+
"Download a generated document",
|
|
4325
|
+
FILE_DESCRIPTION,
|
|
4326
|
+
fileInputSchema,
|
|
4327
|
+
readOnly3,
|
|
4328
|
+
(a) => handleFile(getToken, baseUrl, a)
|
|
4329
|
+
]
|
|
4330
|
+
];
|
|
4331
|
+
for (const [name, title, description, inputSchema11, annotations, handler] of tools) {
|
|
4332
|
+
server.registerTool(
|
|
4333
|
+
name,
|
|
4334
|
+
{ title, description, inputSchema: inputSchema11, annotations: { title, ...annotations } },
|
|
4335
|
+
async (args) => handler(args)
|
|
4336
|
+
);
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
3617
4339
|
var DEFAULT_BASE3 = "https://api.talonic.com";
|
|
3618
4340
|
var TASK_STATUSES = ["available", "claimed", "submitted", "timed_out", "cancelled"];
|
|
3619
4341
|
var taskId = z.string().uuid().describe("Agent task UUID.");
|
|
@@ -3624,9 +4346,18 @@ var cursor = z.string().min(1).optional().describe("Opaque cursor from paginatio
|
|
|
3624
4346
|
var outputValue = z.object({
|
|
3625
4347
|
value: z.json().describe("JSON value matching the field's declared data type."),
|
|
3626
4348
|
confidence: z.number().min(0).max(1).optional().describe("Optional confidence from 0 to 1."),
|
|
3627
|
-
reasoning: z.string().max(4e3).optional().describe("Optional concise reasoning for this field, up to 4,000 characters.")
|
|
4349
|
+
reasoning: z.string().max(4e3).optional().describe("Optional concise reasoning for this field, up to 4,000 characters."),
|
|
4350
|
+
escalate: z.boolean().optional().describe(
|
|
4351
|
+
"Agentic Review (product) tasks only: hand this field to a human instead of writing it. value is shown as the proposal, reasoning as the reason."
|
|
4352
|
+
),
|
|
4353
|
+
quote: z.string().max(4e3).optional().describe(
|
|
4354
|
+
"Verbatim evidence for a changed value, copied from document_id. Required when the task's autonomy sets requireQuote; an unverified change is escalated, not written."
|
|
4355
|
+
),
|
|
4356
|
+
document_id: z.string().uuid().optional().describe("The contract document (anchor or candidate supplier) the quote comes from.")
|
|
3628
4357
|
});
|
|
3629
|
-
var outputs = z.record(z.string().min(1), outputValue).describe(
|
|
4358
|
+
var outputs = z.record(z.string().min(1), outputValue).describe(
|
|
4359
|
+
"Output field key to { value, confidence?, reasoning?, escalate?, quote?, document_id? }. Use only declared fields."
|
|
4360
|
+
);
|
|
3630
4361
|
var listInput = { status, limit, cursor };
|
|
3631
4362
|
var idInput = { task_id: taskId };
|
|
3632
4363
|
var heartbeatInput = { task_id: taskId, execution_epoch: executionEpoch };
|
|
@@ -5134,7 +5865,7 @@ function registerAskTools(server, getToken, baseUrl) {
|
|
|
5134
5865
|
|
|
5135
5866
|
// package.json
|
|
5136
5867
|
var package_default = {
|
|
5137
|
-
version: "0.1.
|
|
5868
|
+
version: "0.1.87"};
|
|
5138
5869
|
|
|
5139
5870
|
// src/version.ts
|
|
5140
5871
|
var VERSION = package_default.version;
|
|
@@ -5291,6 +6022,9 @@ function createServer(options) {
|
|
|
5291
6022
|
if (options.includeApTools) {
|
|
5292
6023
|
registerApTools(server, rawToken, baseUrl);
|
|
5293
6024
|
}
|
|
6025
|
+
if (options.includeDocGenTools) {
|
|
6026
|
+
registerDocGenTools(server, rawToken, baseUrl, { localFiles: !options.tokenProvider });
|
|
6027
|
+
}
|
|
5294
6028
|
registerSchemasResource(server, getTalonic);
|
|
5295
6029
|
registerWebhooksResource(server, rawToken, baseUrl);
|
|
5296
6030
|
registerWidgets(server);
|