@talonic/mcp 0.1.91 → 0.1.92

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/dist/server.js CHANGED
@@ -3120,6 +3120,56 @@ function handleUpcoming(getToken, baseUrl, args) {
3120
3120
  () => apiJson(getToken, baseUrl, "GET", "/v1/contracts/upcoming", { params: { days: args.days } })
3121
3121
  );
3122
3122
  }
3123
+ var PROCESSES_DESCRIPTION = [
3124
+ "Open processes the contract data starts for people across contracts, from the captured Spec fields, the ERP contract register (Dynamics ku_* columns), document types and Money Found: sales (price fixing 3 months before commissioning, the notice window as the ERP keeps it, missing sales opportunity, tacit renewals to reprice, lost to competition), billing (billing held until commissioning, ERP record after signing, run-out phase, CPI adjustment, rent due), legal (land-register entry, termination received, breach, change of control, consumer law), operations (overdue supply start, missing commissioning protocol, SLAs, fuels, warranties), property (the easement DBK chain, security rights target vs actual), contract_management (signing workflow backlog: drafts, originals, documents, owner missing), procurement (subcontracts, purchase-side notice, upstream supplier), controlling (severance, asset transfer, tax and levy clauses, intercompany). Each item names its department, phase, kind (deadline / event / ingest / backlog), due date (null when the data names none yet), days_left (negative = overdue) and the fields it rests on. Items marked handled are left out.",
3125
+ "USE WHEN: what a department has to start now; preparing a sales, billing, legal or operations worklist from contract data; a digest or ticket export.",
3126
+ "NOT FOR: dates only (talonic_contracts_upcoming); one contract's processes (talonic_contracts_contract, `processes[]`).",
3127
+ "",
3128
+ "ARGS: `department` (sales | billing | legal | operations | property | contract_management | procurement | controlling), `days` (horizon for dated items, default the workspace's process horizon, 180), `contract_id`.",
3129
+ "RETURNS: data[] { id, contract_id, contract_key, title, counterparty, rule_id, department, phase, kind, due_date, days_left, evidence[] { field, value, document_id } }."
3130
+ ].join("\n");
3131
+ var DEPARTMENTS = [
3132
+ "sales",
3133
+ "billing",
3134
+ "legal",
3135
+ "operations",
3136
+ "property",
3137
+ "contract_management",
3138
+ "procurement",
3139
+ "controlling"
3140
+ ];
3141
+ var processesInputSchema = {
3142
+ department: z.enum(DEPARTMENTS).optional().describe("Only this department's items."),
3143
+ days: z.number().int().min(1).max(3650).optional().describe("Days ahead for dated items."),
3144
+ contract_id: z.string().uuid().optional().describe("Only this contract's items.")
3145
+ };
3146
+ function handleProcesses(getToken, baseUrl, args) {
3147
+ return runTool(
3148
+ () => apiJson(getToken, baseUrl, "GET", "/v1/contracts/processes", {
3149
+ params: { department: args.department, days: args.days, contract_id: args.contract_id }
3150
+ })
3151
+ );
3152
+ }
3153
+ var PROCESS_DESCRIPTION = [
3154
+ "Mark a process item handled (it ran: the price was agreed, the invoice went out, the entry was filed) or open again. A decision, recorded with who made it; it survives every rebuild. A moved deadline opens the process again.",
3155
+ "USE WHEN: a process from talonic_contracts_processes was done, or was marked by mistake.",
3156
+ "NOT FOR: key dates (talonic_contracts_key_date).",
3157
+ "",
3158
+ "ARGS: `process_id`, `handled` (true / false), `note` (what was done).",
3159
+ "RETURNS: { id, handled }."
3160
+ ].join("\n");
3161
+ var processInputSchema = {
3162
+ process_id: z.string().uuid(),
3163
+ handled: z.boolean(),
3164
+ note: z.string().max(2e3).optional()
3165
+ };
3166
+ function handleProcess(getToken, baseUrl, args) {
3167
+ return runTool(
3168
+ () => apiJson(getToken, baseUrl, "POST", `/v1/contracts/processes/${args.process_id}`, {
3169
+ body: { handled: args.handled, note: args.note }
3170
+ })
3171
+ );
3172
+ }
3123
3173
  var CANDIDATES_DESCRIPTION = [
3124
3174
  "Contract documents whose terms have not been read yet, grouped by the contract key in their filename; keys Contract Pricing already models first.",
3125
3175
  "USE WHEN: choosing what to read, or checking how the documents will group before importing.",
@@ -3429,6 +3479,22 @@ function registerContractsTools(server, getToken, baseUrl) {
3429
3479
  write(true),
3430
3480
  (a) => handleKeyDate(getToken, baseUrl, a)
3431
3481
  ],
3482
+ [
3483
+ "talonic_contracts_processes",
3484
+ "Processes the contract data starts",
3485
+ PROCESSES_DESCRIPTION,
3486
+ processesInputSchema,
3487
+ readOnly,
3488
+ (a) => handleProcesses(getToken, baseUrl, a)
3489
+ ],
3490
+ [
3491
+ "talonic_contracts_process",
3492
+ "Mark a process handled",
3493
+ PROCESS_DESCRIPTION,
3494
+ processInputSchema,
3495
+ write(true),
3496
+ (a) => handleProcess(getToken, baseUrl, a)
3497
+ ],
3432
3498
  [
3433
3499
  "talonic_contracts_set_term",
3434
3500
  "Set a contract term with its quote",
@@ -5249,7 +5315,7 @@ function handleIssues5(getToken, baseUrl, args) {
5249
5315
  () => apiJson(getToken, baseUrl, "GET", "/v1/submissions/issues", { params: args })
5250
5316
  );
5251
5317
  }
5252
- var PROCESS_DESCRIPTION = [
5318
+ var PROCESS_DESCRIPTION2 = [
5253
5319
  "Capture new workbooks and map submissions into a target structure, in bulk. Capturing is deterministic (no model); mapping classifies only labels the workspace has not seen, and reuses every earlier and every human decision. Run with dry_run first.",
5254
5320
  "USE WHEN: new submissions arrived (only: not_captured), or a target structure changed and submissions need re-mapping (only: not_mapped or all).",
5255
5321
  "NOT FOR: reading results (talonic_submissions_list, talonic_submissions_issues).",
@@ -5257,7 +5323,7 @@ var PROCESS_DESCRIPTION = [
5257
5323
  "ARGS: `spec_id` (map into this structure), `document_ids` (restrict), `only` not_captured|not_mapped|all (default all), `recapture` (capture again even when captured; replaces earlier facts), `limit` (default 50, max 200), `dry_run`.",
5258
5324
  "RETURNS: dry_run \u2192 { plan[] { document_id, filename, capture, map } }; otherwise { results[] { document_id, ok, facts?, checks_failed?, error? } }."
5259
5325
  ].join("\n");
5260
- var processInputSchema = {
5326
+ var processInputSchema2 = {
5261
5327
  spec_id: specId.optional(),
5262
5328
  document_ids: z.array(z.string().uuid()).max(200).optional(),
5263
5329
  only: z.enum(["not_captured", "not_mapped", "all"]).optional(),
@@ -5265,7 +5331,7 @@ var processInputSchema = {
5265
5331
  limit: z.number().int().min(1).max(200).optional(),
5266
5332
  dry_run: z.boolean().optional().describe("List what would run; nothing runs.")
5267
5333
  };
5268
- function handleProcess(getToken, baseUrl, args) {
5334
+ function handleProcess2(getToken, baseUrl, args) {
5269
5335
  return runTool(
5270
5336
  () => apiJson(getToken, baseUrl, "POST", "/v1/submissions/process", { body: args })
5271
5337
  );
@@ -5387,6 +5453,56 @@ function handleChecks(getToken, baseUrl, args) {
5387
5453
  )
5388
5454
  );
5389
5455
  }
5456
+ var REVIEW_DESCRIPTION = [
5457
+ "Agentic review of a target structure's label mappings (how each spreadsheet label maps onto the client's metrics and fields). Without `start`: the review's progress and the decisions stored (confirmed, corrected, best guesses, answered by experts, still proposed, open questions). With `start: true`: rule-made mappings are confirmed, the review agent decides the rest, the few only the client can answer become questions, and every mapped submission is re-mapped; runs in the background, poll without `start`.",
5458
+ "USE WHEN: labels are waiting for review (talonic_submissions_specs shows labels_to_review) and nobody will check them one by one.",
5459
+ "NOT FOR: the questions themselves (talonic_submissions_questions).",
5460
+ "",
5461
+ "ARGS: `spec_id`, `start` (true to start a review).",
5462
+ "RETURNS: { run: { phase, done, total, stats } | null, decisions: { total, proposed, questions, confirmed, fixed, best_guess, answered } }."
5463
+ ].join("\n");
5464
+ var reviewInputSchema = {
5465
+ spec_id: z.string().uuid().describe("Target structure id (talonic_submissions_specs)."),
5466
+ start: z.boolean().optional().describe("Start a review instead of reading its status.")
5467
+ };
5468
+ function handleReview(getToken, baseUrl, args) {
5469
+ return runTool(
5470
+ () => args.start ? apiJson(getToken, baseUrl, "POST", "/v1/submissions/review", {
5471
+ body: { spec_id: args.spec_id }
5472
+ }) : apiJson(getToken, baseUrl, "GET", "/v1/submissions/review", {
5473
+ params: { spec_id: args.spec_id }
5474
+ })
5475
+ );
5476
+ }
5477
+ var QUESTIONS_DESCRIPTION = [
5478
+ "The open questions the label review left for the client's experts, one per group, heaviest first. Without `group`: the questions with their options and the labels each settles. With `group` and `option`: record the expert's answer; every label of the group takes the mapping that answer means, and the submissions are re-mapped.",
5479
+ "USE WHEN: walking the client's experts through the few questions only they can answer, or recording their answers.",
5480
+ "NOT FOR: starting a review (talonic_submissions_review).",
5481
+ "",
5482
+ "ARGS: `spec_id`; to answer: `group` (from the list) and `option` (0-based index into its options).",
5483
+ "RETURNS: list: data[] { group, question, options[], labels[] { label_key, text, where, samples[] } }; answer: { settled }."
5484
+ ].join("\n");
5485
+ var questionsInputSchema = {
5486
+ spec_id: z.string().uuid().describe("Target structure id (talonic_submissions_specs)."),
5487
+ group: z.string().max(400).optional().describe("The question group to answer (from the list)."),
5488
+ option: z.number().int().min(0).max(5).optional().describe("0-based index of the chosen option.")
5489
+ };
5490
+ function handleQuestions(getToken, baseUrl, args) {
5491
+ if (args.group === void 0 !== (args.option === void 0)) {
5492
+ return Promise.resolve(
5493
+ validationError(
5494
+ "Give both `group` and `option` to answer, or neither to list the questions."
5495
+ )
5496
+ );
5497
+ }
5498
+ return runTool(
5499
+ () => args.group !== void 0 ? apiJson(getToken, baseUrl, "POST", "/v1/submissions/questions/answer", {
5500
+ body: { spec_id: args.spec_id, group: args.group, option: args.option }
5501
+ }) : apiJson(getToken, baseUrl, "GET", "/v1/submissions/questions", {
5502
+ params: { spec_id: args.spec_id }
5503
+ })
5504
+ );
5505
+ }
5390
5506
  async function probeSubmissionsAccess(token, baseUrl) {
5391
5507
  try {
5392
5508
  const res = await fetch(buildUrl(baseUrl, "/v1/submissions/specs"), {
@@ -5427,10 +5543,10 @@ function registerSubmissionsTools(server, getToken, baseUrl) {
5427
5543
  [
5428
5544
  "talonic_submissions_process",
5429
5545
  "Capture and map submissions",
5430
- PROCESS_DESCRIPTION,
5431
- processInputSchema,
5546
+ PROCESS_DESCRIPTION2,
5547
+ processInputSchema2,
5432
5548
  write6(true),
5433
- (a) => handleProcess(getToken, baseUrl, a)
5549
+ (a) => handleProcess2(getToken, baseUrl, a)
5434
5550
  ],
5435
5551
  [
5436
5552
  "talonic_submissions_completeness",
@@ -5464,6 +5580,22 @@ function registerSubmissionsTools(server, getToken, baseUrl) {
5464
5580
  readOnly6,
5465
5581
  (a) => handleChecks(getToken, baseUrl, a)
5466
5582
  ],
5583
+ [
5584
+ "talonic_submissions_review",
5585
+ "Review label mappings",
5586
+ REVIEW_DESCRIPTION,
5587
+ reviewInputSchema,
5588
+ write6(true),
5589
+ (a) => handleReview(getToken, baseUrl, a)
5590
+ ],
5591
+ [
5592
+ "talonic_submissions_questions",
5593
+ "Questions for the client's experts",
5594
+ QUESTIONS_DESCRIPTION,
5595
+ questionsInputSchema,
5596
+ write6(true),
5597
+ (a) => handleQuestions(getToken, baseUrl, a)
5598
+ ],
5467
5599
  [
5468
5600
  "talonic_submissions_export",
5469
5601
  "Export submission facts",
@@ -5481,6 +5613,819 @@ function registerSubmissionsTools(server, getToken, baseUrl) {
5481
5613
  );
5482
5614
  }
5483
5615
  }
5616
+ var MONTH_RE = /^\d{4}-\d{2}$/;
5617
+ var INDEX_PERIOD_RE = /^\d{4}(-\d{2}|-Q[1-4]|-H[12])?$/;
5618
+ var modelIdArg = z.string().uuid().describe("Price model id (from talonic_price_baseline_models).");
5619
+ var fromArg = z.string().regex(MONTH_RE).describe("First month of the evaluation window, `YYYY-MM`.");
5620
+ var toArg = z.string().regex(MONTH_RE).describe("Last month of the evaluation window, `YYYY-MM`.");
5621
+ var readOnly7 = {
5622
+ readOnlyHint: true,
5623
+ destructiveHint: false,
5624
+ idempotentHint: true,
5625
+ openWorldHint: false
5626
+ };
5627
+ var DOCUMENTS_DESCRIPTION = [
5628
+ "Find contracts and invoices in the workspace to build a price baseline from.",
5629
+ "USE WHEN: picking the contract for talonic_price_baseline_extract or the invoice for talonic_price_baseline_compare.",
5630
+ "NOT FOR: general document search across all content (talonic_search).",
5631
+ "",
5632
+ "ARGS: `query` (filename contains, optional).",
5633
+ "RETURNS: data[] { id, filename, created_at }. Which contracts already have a model: talonic_price_baseline_models."
5634
+ ].join("\n");
5635
+ var documentsInputSchema = {
5636
+ query: z.string().optional().describe("Filename contains match (e.g. 'W\xE4rmeliefervertrag').")
5637
+ };
5638
+ function handleDocuments(getToken, baseUrl, args) {
5639
+ return runTool(
5640
+ () => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/documents", {
5641
+ params: { q: args.query }
5642
+ })
5643
+ );
5644
+ }
5645
+ var EXTRACT_DESCRIPTION = [
5646
+ "Read a contract's price clause into a standard price model: components (Arbeitspreis, Grundpreis, CO2, ...), their formulas, the named indices with base year and reference months, and every stated number with its verified contract quote. With `model_id` instead, read only the contract's identity (contract number, customer, site) and agreed quantities into that existing model, keeping its formulas and values.",
5647
+ "USE WHEN: a contract has no price model yet (`document_id`), or a model lacks its contract number or agreed quantities, e.g. the contract workbook asks for a quantity (`model_id`). Many contracts at once: talonic_price_baseline_import.",
5648
+ "NOT FOR: generic field extraction (talonic_extract); editing an existing model (talonic_price_baseline_update_model).",
5649
+ "",
5650
+ "ARGS: `document_id` (contract UUID) or `model_id` (enrich), `use_opus` (slower, for long or unusual clauses; document_id only).",
5651
+ "RETURNS: the stored model { id, document_id, contract_key, contract_label, status, model }. Costs one LLM call. A value whose quote does not verify carries `evidence.verified: false` and counts as missing. Enrich keys the model by its contract number when it has no key yet."
5652
+ ].join("\n");
5653
+ var extractInputSchema = {
5654
+ document_id: z.string().uuid().optional().describe("Contract document UUID (new model)."),
5655
+ model_id: modelIdArg.optional().describe(
5656
+ "Existing model to enrich with contract number, customer, site and agreed quantities."
5657
+ ),
5658
+ use_opus: z.boolean().optional().describe("Use the larger model for long or unusual price clauses.")
5659
+ };
5660
+ function handleExtract2(getToken, baseUrl, args) {
5661
+ if (!!args.document_id === !!args.model_id) {
5662
+ return Promise.resolve(
5663
+ validationError("provide either `document_id` (new model) or `model_id` (enrich), not both")
5664
+ );
5665
+ }
5666
+ if (args.model_id) {
5667
+ return runTool(
5668
+ () => apiJson(
5669
+ getToken,
5670
+ baseUrl,
5671
+ "POST",
5672
+ `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}/enrich`
5673
+ )
5674
+ );
5675
+ }
5676
+ return runTool(
5677
+ () => apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/models", {
5678
+ body: { document_id: args.document_id, use_opus: args.use_opus }
5679
+ })
5680
+ );
5681
+ }
5682
+ var MODELS_DESCRIPTION = [
5683
+ "List the workspace's price models, or read one in full when `model_id` is given.",
5684
+ "USE WHEN: finding a model id, or reviewing a model's components, formulas, indices and quotes before confirming it.",
5685
+ "NOT FOR: computed prices (talonic_price_baseline_prices); invoice checks (talonic_price_baseline_compare).",
5686
+ "",
5687
+ "ARGS: `model_id` (optional UUID).",
5688
+ "RETURNS: without id, data[] { id, document_id, contract_label, status, components, unverified_values, index_series, updated_at }; with id, the stored model with its full `model`."
5689
+ ].join("\n");
5690
+ var modelsInputSchema = {
5691
+ model_id: modelIdArg.optional()
5692
+ };
5693
+ function handleModels(getToken, baseUrl, args) {
5694
+ const path = args.model_id ? `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}` : "/v1/price-baseline/models";
5695
+ return runTool(() => apiJson(getToken, baseUrl, "GET", path));
5696
+ }
5697
+ var UPDATE_DESCRIPTION = [
5698
+ "Edit a price model after review: replace its model, confirm it, place it in a contract, or exclude it.",
5699
+ "USE WHEN: a formula, index or reference month was read wrong; the reviewer confirms the model; a document belongs to another contract (`contract_key`); a document of the contract sets no price, e.g. a withdrawn letter or cover mail (`status: excluded`).",
5700
+ "NOT FOR: first extraction (talonic_price_baseline_extract); entering one missing contract value (talonic_price_baseline_answer).",
5701
+ "",
5702
+ "ARGS: `model_id`, and at least one of `model` (the full model object from talonic_price_baseline_models, edited), `status` (draft | confirmed | excluded), `contract_key` (the contract number every version of the contract shares; null clears a hand-set key), `superseded_by` (model of a later amendment that replaces this one from its valid_from; null unlinks).",
5703
+ "RETURNS: the stored model. The platform re-verifies every quote: an edited number only counts when its quote occurs in the contract and prints that number. Models with the same `contract_key` are versions of one contract, ordered by valid_from."
5704
+ ].join("\n");
5705
+ var updateInputSchema = {
5706
+ model_id: modelIdArg,
5707
+ model: z.record(z.string(), z.unknown()).optional().describe("The full edited model object (the `model` field of the stored model)."),
5708
+ status: z.enum(["draft", "confirmed", "excluded"]).optional().describe(
5709
+ "`confirmed` once a reviewer accepts the model; `excluded` for a document of the contract that sets no price."
5710
+ ),
5711
+ contract_key: z.string().max(64).nullable().optional().describe(
5712
+ "Contract this document belongs to (its contract number); null clears a hand-set key."
5713
+ ),
5714
+ superseded_by: z.string().uuid().nullable().optional().describe("Model of the amendment or price sheet that replaces this one; null unlinks.")
5715
+ };
5716
+ function handleUpdate(getToken, baseUrl, args) {
5717
+ const { model_id, ...patch } = args;
5718
+ if (Object.values(patch).every((v) => v === void 0)) {
5719
+ return Promise.resolve(
5720
+ validationError("provide at least one of `model`, `status`, `contract_key`, `superseded_by`")
5721
+ );
5722
+ }
5723
+ return runTool(
5724
+ () => apiJson(getToken, baseUrl, "PUT", `/v1/price-baseline/models/${encodeURIComponent(model_id)}`, {
5725
+ body: patch
5726
+ })
5727
+ );
5728
+ }
5729
+ var PRICES_DESCRIPTION = [
5730
+ "Recompute every price of a model for each price period in a window, from the index values on file.",
5731
+ "USE WHEN: you need the contract's own price per period, independent of the biller's price sheet.",
5732
+ "NOT FOR: checking a specific invoice (talonic_price_baseline_compare); the Excel file (talonic_price_baseline_workbook).",
5733
+ "",
5734
+ "ARGS: `model_id`, `from`, `to` (YYYY-MM).",
5735
+ "RETURNS: prices[] { component, period { label, from, to }, price, unit, status, detail, indices[] { variable, series, months, value, sources, independent } } and the index values used. `status` other than ok (missing_index, missing_value, rebase_mismatch, custom_reference, formula_error) means `price` is null; nothing is estimated. Fetch missing public indices with talonic_price_baseline_refresh_indices."
5736
+ ].join("\n");
5737
+ var pricesInputSchema = { model_id: modelIdArg, from: fromArg, to: toArg };
5738
+ function handlePrices(getToken, baseUrl, args) {
5739
+ return runTool(
5740
+ () => apiJson(
5741
+ getToken,
5742
+ baseUrl,
5743
+ "GET",
5744
+ `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}/prices`,
5745
+ {
5746
+ params: { from: args.from, to: args.to }
5747
+ }
5748
+ )
5749
+ );
5750
+ }
5751
+ var WORKBOOK_DESCRIPTION = [
5752
+ "Download the standard Excel workbook for a model: Variablen, Preise (live formulas), Indizes, Rechnungspr\xFCfung, Hinweise, Quellen. Every contract comes out in the same layout.",
5753
+ "USE WHEN: the user wants the baseline as a spreadsheet, or to hand over an invoice check.",
5754
+ "NOT FOR: reading prices as data (talonic_price_baseline_prices).",
5755
+ "",
5756
+ "ARGS: `model_id`, `from`, `to` (YYYY-MM), `comparison_id` (optional, fills the Rechnungspr\xFCfung sheet).",
5757
+ "RETURNS: the .xlsx as an embedded resource (base64) plus its filename and size."
5758
+ ].join("\n");
5759
+ var workbookInputSchema = {
5760
+ model_id: modelIdArg,
5761
+ from: fromArg,
5762
+ to: toArg,
5763
+ comparison_id: z.string().uuid().optional().describe("Invoice comparison to include (from talonic_price_baseline_compare).")
5764
+ };
5765
+ var XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
5766
+ async function handleWorkbook(getToken, baseUrl, args) {
5767
+ try {
5768
+ const url = buildUrl(
5769
+ baseUrl,
5770
+ `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}/workbook.xlsx`,
5771
+ {
5772
+ from: args.from,
5773
+ to: args.to,
5774
+ comparison_id: args.comparison_id
5775
+ }
5776
+ );
5777
+ const res = await resolveFetch(getToken)(url, {
5778
+ headers: { Authorization: `Bearer ${getToken()}`, Accept: XLSX_MIME }
5779
+ });
5780
+ if (!res.ok) {
5781
+ const text = await res.text().catch(() => "");
5782
+ throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
5783
+ }
5784
+ const buf = Buffer.from(await res.arrayBuffer());
5785
+ const filename = /filename="([^"]+)"/.exec(res.headers.get("content-disposition") ?? "")?.[1] ?? `price-baseline-${args.model_id}.xlsx`;
5786
+ return {
5787
+ content: [
5788
+ { type: "text", text: JSON.stringify({ filename, bytes: buf.length }, null, 2) },
5789
+ {
5790
+ type: "resource",
5791
+ resource: {
5792
+ uri: `talonic://price-baseline/${args.model_id}/${filename}`,
5793
+ mimeType: XLSX_MIME,
5794
+ blob: buf.toString("base64")
5795
+ }
5796
+ }
5797
+ ]
5798
+ };
5799
+ } catch (err) {
5800
+ return toolError(err);
5801
+ }
5802
+ }
5803
+ var COMPARE_DESCRIPTION = [
5804
+ "Check an invoice against a model: read the invoice's billed prices and quantities, recompute each price from the contract, and report the difference per line.",
5805
+ "USE WHEN: establishing Money Found for an invoice, or listing past checks (`list: true`).",
5806
+ "NOT FOR: prices without an invoice (talonic_price_baseline_prices).",
5807
+ "",
5808
+ "ARGS: `model_id`, `invoice_document_id` (invoice UUID, to run a new check) or `list: true` (past checks).",
5809
+ "RETURNS: { id, invoice, prices, comparison { lines[] { line, baseline_price, billed_price, unit, effect_eur, verdict, reason, independent }, totals { underbilled_eur, overbilled_eur, compared_lines, not_comparable_lines }, amendment_suspects[] } }. Suspected amendments are held out of totals. A baseline built on an index printed only on the invoice is `independent: false`. Costs one LLM call."
5810
+ ].join("\n");
5811
+ var compareInputSchema = {
5812
+ model_id: modelIdArg,
5813
+ invoice_document_id: z.string().uuid().optional().describe("Invoice document UUID to check."),
5814
+ list: z.boolean().optional().describe("List this model's past comparisons instead of running one.")
5815
+ };
5816
+ function handleCompare(getToken, baseUrl, args) {
5817
+ const base = `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}`;
5818
+ if (args.list) return runTool(() => apiJson(getToken, baseUrl, "GET", `${base}/comparisons`));
5819
+ if (!args.invoice_document_id) {
5820
+ return Promise.resolve(
5821
+ validationError("provide `invoice_document_id`, or `list: true` for past comparisons")
5822
+ );
5823
+ }
5824
+ return runTool(
5825
+ () => apiJson(getToken, baseUrl, "POST", `${base}/compare`, {
5826
+ body: { invoice_document_id: args.invoice_document_id }
5827
+ })
5828
+ );
5829
+ }
5830
+ var PROOF_INVOICE_DESCRIPTION = [
5831
+ "Restate a checked invoice as the audit-proof invoice the contract supports: every line restated at the contract price, every input (base value, weight, index value, quantity) listed with its source (contract quote, publisher URL and line, the biller's invoice, or a marked assumption), and eight checks that say whether the restatement holds up without anyone's word for it.",
5832
+ "USE WHEN: an invoice was already checked (a comparison exists) and the user needs the corrected invoice to send, file or audit, or wants to know what still keeps it from being audit-proof.",
5833
+ "NOT FOR: running a new check or listing past checks (talonic_price_baseline_compare); prices without an invoice (talonic_price_baseline_prices).",
5834
+ "",
5835
+ "ARGS: `comparison_id` (from talonic_price_baseline_compare), `format` (json, default | html).",
5836
+ "RETURNS (json): { lines[] { label, quantity, unit_price, amount, billed_amount, delta, inputs[] { symbol, value, period, source }, verdict, independent }, totals { net, billed_net, delta, tax_rate, tax, gross }, checks[8] { key, label, passed, detail }, audit_proof, hash, sources[], restates, currency, pdf_url }. delta > 0 = billed too little. html: { html (self-contained page), pdf_url }. pdf_url needs the same bearer; this tool does not download it."
5837
+ ].join("\n");
5838
+ var proofInvoiceInputSchema = {
5839
+ comparison_id: z.string().uuid().describe("Comparison UUID (talonic_price_baseline_compare)."),
5840
+ format: z.enum(["json", "html"]).optional().describe("json (default): the restated invoice; html: the self-contained page.")
5841
+ };
5842
+ function handleProofInvoice(getToken, baseUrl, args) {
5843
+ const path = `/v1/price-baseline/comparisons/${encodeURIComponent(args.comparison_id)}/proof-invoice`;
5844
+ return runTool(async () => {
5845
+ const { invoice, html } = await apiJson(
5846
+ getToken,
5847
+ baseUrl,
5848
+ "GET",
5849
+ path
5850
+ );
5851
+ const pdf_url = buildUrl(baseUrl, `${path}.pdf`);
5852
+ return args.format === "html" ? { html, pdf_url } : { ...invoice, pdf_url };
5853
+ });
5854
+ }
5855
+ var INDICES_DESCRIPTION = [
5856
+ "Show the index catalog (series the platform can fetch or accept manually), the sync state of the workspace's external series, or the stored values of given series.",
5857
+ "USE WHEN: a price period reports a missing index, to see which source a value came from, or to see which series are stale or failing (`view: sync`).",
5858
+ "NOT FOR: fetching new values (talonic_price_baseline_sync_series, talonic_price_baseline_refresh_indices) or entering them (talonic_price_baseline_add_index_values).",
5859
+ "",
5860
+ "ARGS: `series` (optional list of series keys, e.g. ['destatis.vpi', 'behg.co2']) for values; else `view` (catalog, default | sync).",
5861
+ "RETURNS: values data[] { series, period, value, unit, base_year, source, source_url, quote, document_id }; catalog data[] { key, label, provider, unit, base_year, note, stored { count, first, last } }; sync data[] { key, label, provider, connector (catalog | manual), shared, sync_hours, active, last_synced_at, last_status, last_error, due, stored, contracts (how many contracts read it) }."
5862
+ ].join("\n");
5863
+ var indicesInputSchema = {
5864
+ series: z.array(z.string().min(1)).max(50).optional().describe("Series keys to read values for."),
5865
+ view: z.enum(["catalog", "sync"]).optional().describe("Without `series`: the catalog (default) or each series' sync state.")
5866
+ };
5867
+ function handleIndices(getToken, baseUrl, args) {
5868
+ if (args.series?.length) {
5869
+ return runTool(
5870
+ () => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/indices/values", {
5871
+ params: { series: args.series?.join(",") }
5872
+ })
5873
+ );
5874
+ }
5875
+ if (args.view === "sync") {
5876
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/data/series"));
5877
+ }
5878
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/indices"));
5879
+ }
5880
+ var REFRESH_DESCRIPTION = [
5881
+ "Fetch index values from their publishers: BEHG CO2 price (\xA710 law text), Bundesbank VPI and Erzeugerpreise, Destatis GENESIS tables (needs the platform's GENESIS token).",
5882
+ "USE WHEN: talonic_price_baseline_prices reports a missing public index for a specific year range (backfill).",
5883
+ "NOT FOR: routine sync of every due series (talonic_price_baseline_sync_series); THE levies or grid tariffs, which have no free feed (talonic_price_baseline_add_index_values).",
5884
+ "",
5885
+ "ARGS: `series` (catalog keys), `from_year`, `to_year`.",
5886
+ "RETURNS: data[] { series, stored, error }. A failed series reports its error; it never succeeds empty."
5887
+ ].join("\n");
5888
+ var refreshInputSchema = {
5889
+ series: z.array(z.string().min(1)).min(1).max(20).describe("Catalog series keys to fetch."),
5890
+ from_year: z.number().int().min(2e3).max(2100).describe("First year to fetch."),
5891
+ to_year: z.number().int().min(2e3).max(2100).describe("Last year to fetch.")
5892
+ };
5893
+ function handleRefresh(getToken, baseUrl, args) {
5894
+ if (args.to_year < args.from_year)
5895
+ return Promise.resolve(validationError("`to_year` is before `from_year`"));
5896
+ return runTool(
5897
+ () => apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/indices/refresh", { body: args })
5898
+ );
5899
+ }
5900
+ var MANUAL_DESCRIPTION = [
5901
+ "Enter index values that have no free feed (EEX, THE levies, grid tariffs) for this workspace, each with its source.",
5902
+ "USE WHEN: a price needs an index talonic_price_baseline_refresh_indices cannot fetch.",
5903
+ "NOT FOR: public series with a feed (talonic_price_baseline_refresh_indices).",
5904
+ "",
5905
+ "ARGS: `values[]` { series, period (YYYY, YYYY-MM, YYYY-Qn, YYYY-Hn), value, unit?, base_year?, quote, source_url | document_id }. `quote` is the publisher's own line printing the value; a document-backed quote must verify in that document.",
5906
+ "RETURNS: { stored }. A value without a quote and a URL or document is rejected. Never enter a value you did not read from its publication."
5907
+ ].join("\n");
5908
+ var manualInputSchema = {
5909
+ values: z.array(
5910
+ z.object({
5911
+ series: z.string().min(1),
5912
+ period: z.string().regex(INDEX_PERIOD_RE),
5913
+ value: z.number(),
5914
+ unit: z.string().optional(),
5915
+ base_year: z.number().int().optional(),
5916
+ quote: z.string().min(1).describe("The publisher's line that prints this value."),
5917
+ source_url: z.string().url().optional(),
5918
+ document_id: z.string().uuid().optional()
5919
+ })
5920
+ ).min(1).max(500).describe("Index values, each with its source.")
5921
+ };
5922
+ function handleManual(getToken, baseUrl, args) {
5923
+ const unsourced = args.values.findIndex((v) => !v.source_url && !v.document_id);
5924
+ if (unsourced >= 0) {
5925
+ return Promise.resolve(
5926
+ validationError(`values[${unsourced}] needs a \`source_url\` or \`document_id\``)
5927
+ );
5928
+ }
5929
+ return runTool(
5930
+ () => apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/indices/manual", { body: args })
5931
+ );
5932
+ }
5933
+ var RULES = "RULES: every number needs a source: a verbatim contract quote that prints it, or a publisher URL plus the publisher's line. Nothing is estimated. An assumption is marked on every number built on it, is never independent, and is replaced by a real value automatically.";
5934
+ var REGISTER_DESCRIPTION2 = [
5935
+ "The contract register: one row per contract (all its documents as versions), with the expected invoice for a year and what is still open.",
5936
+ "USE WHEN: seeing what every contract should bill for a year, which contracts still have open inputs, or finding a contract's `id` and `contract_key`.",
5937
+ "NOT FOR: one contract's open inputs in detail (talonic_price_baseline_contract); single model documents (talonic_price_baseline_models).",
5938
+ "",
5939
+ "ARGS: `year` (optional; default the last full calendar year).",
5940
+ "RETURNS: data[] { id (latest version's model id), contract_key, contract_number, customer, customer_number, site, contract_label, valid_from, versions, amended, priced, expected { basis (invoice | plan), net, vat, gross, currency, complete, assumed_net }, invoice { comparison_id, invoice_number, period_from, period_to } | null, open { price (unanswered), waiting (source chosen), assumed, invoice (still missing), period } }. `complete: false` means the totals cover only what could be computed; `assumed_net` is the part resting on assumptions."
5941
+ ].join("\n");
5942
+ var registerInputSchema2 = {
5943
+ year: z.number().int().min(2e3).max(2100).optional().describe("Calendar year the expected invoice is computed for.")
5944
+ };
5945
+ function handleRegister2(getToken, baseUrl, args) {
5946
+ return runTool(async () => ({
5947
+ data: await apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/register", {
5948
+ params: { year: args.year }
5949
+ })
5950
+ }));
5951
+ }
5952
+ var CONTRACT_DESCRIPTION3 = [
5953
+ "One contract's workbook: what it should bill for a period, every open input as a question with the ways to answer it, and the assumptions its numbers rest on.",
5954
+ "USE WHEN: finding what is missing for a contract before answering it, or checking the expected invoice after an answer.",
5955
+ "NOT FOR: the Excel file (talonic_price_baseline_workbook); all contracts at once (talonic_price_baseline_register).",
5956
+ "",
5957
+ "ARGS: `model_id` (any version), one period: `year`, `comparison_id` (an invoice check) or `from`+`to` (YYYY-MM); default the newest invoice check, else the last full year. `include_grid` adds all cells.",
5958
+ "RETURNS: { contract_key, period, expected { basis, net, vat, gross, complete, assumed_net }, open[] { key, kind, model_id, variable, series, periods, question, options, decision, assumption, assume_target }, assumptions[], gaps[], sources[], sheets[] }.",
5959
+ "ANSWER by the input's options: enter_contract_value, from_invoice, request \u2192 talonic_price_baseline_answer (with the input's `model_id`); enter_published \u2192 talonic_price_baseline_add_index_values; assume \u2192 talonic_price_baseline_assume (`assume_target`); upload_invoice \u2192 talonic_price_baseline_compare.",
5960
+ RULES
5961
+ ].join("\n");
5962
+ var contractInputSchema3 = {
5963
+ model_id: modelIdArg,
5964
+ year: z.number().int().min(2e3).max(2100).optional().describe("Calendar year to prepare."),
5965
+ comparison_id: z.string().uuid().optional().describe("Invoice check whose period and quantities to use."),
5966
+ from: fromArg.optional(),
5967
+ to: toArg.optional(),
5968
+ include_grid: z.boolean().optional().describe("Include every sheet's cell rows (large). Default: sheet names and row counts only.")
5969
+ };
5970
+ function handleContract3(getToken, baseUrl, args) {
5971
+ if (!!args.from !== !!args.to) {
5972
+ return Promise.resolve(validationError("give `from` and `to` together"));
5973
+ }
5974
+ const periods = [args.year !== void 0, !!args.comparison_id, !!args.from].filter(Boolean);
5975
+ if (periods.length > 1) {
5976
+ return Promise.resolve(
5977
+ validationError("choose one period: `year`, `comparison_id`, or `from`+`to`")
5978
+ );
5979
+ }
5980
+ if (args.from && args.to && args.from > args.to) {
5981
+ return Promise.resolve(validationError("`to` is before `from`"));
5982
+ }
5983
+ return runTool(async () => {
5984
+ const book = await apiJson(
5985
+ getToken,
5986
+ baseUrl,
5987
+ "GET",
5988
+ `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}/sheets`,
5989
+ {
5990
+ params: {
5991
+ year: args.year,
5992
+ comparison_id: args.comparison_id,
5993
+ from: args.from,
5994
+ to: args.to
5995
+ }
5996
+ }
5997
+ );
5998
+ if (args.include_grid || !Array.isArray(book?.sheets)) return book;
5999
+ return {
6000
+ ...book,
6001
+ sheets: book.sheets.map((s) => ({ name: s.name, rows: s.rows?.length ?? 0 }))
6002
+ };
6003
+ });
6004
+ }
6005
+ var ANSWER_DESCRIPTION = [
6006
+ "Answer an open input of a contract workbook: enter a contract value with its verbatim quote, or record where the value will come from.",
6007
+ "USE WHEN: talonic_price_baseline_contract lists an open input whose options include enter_contract_value, from_invoice or request.",
6008
+ "NOT FOR: published index values (talonic_price_baseline_add_index_values); stand-in values (talonic_price_baseline_assume); editing formulas (talonic_price_baseline_update_model).",
6009
+ "",
6010
+ "ARGS: `model_id` (the open input's own `model_id`: the version that states the value), `action`:",
6011
+ "- enter_contract_value: `variable` (the input's `variable`), `value`, `quote` (the contract's passage, copied verbatim, that prints the value).",
6012
+ "- choose_source: `key` (the input's `key`), `choice` (from_invoice | request; null clears), `note`.",
6013
+ "RETURNS: enter_contract_value, the stored model; choose_source, { key, decision }. A quote that does not occur in the contract or does not print the value is rejected and nothing is saved. A choice records a plan; it never fills a number.",
6014
+ RULES
6015
+ ].join("\n");
6016
+ var answerInputSchema = {
6017
+ model_id: modelIdArg,
6018
+ action: z.enum(["enter_contract_value", "choose_source"]),
6019
+ variable: z.string().min(1).max(64).optional().describe("Model variable name (enter_contract_value)."),
6020
+ value: z.number().optional().describe("The number the contract states (enter_contract_value)."),
6021
+ quote: z.string().min(1).max(2e3).optional().describe("Verbatim contract passage that prints the value (enter_contract_value)."),
6022
+ key: z.string().min(1).max(300).optional().describe("Open input key (choose_source)."),
6023
+ choice: z.enum(["from_invoice", "request"]).nullable().optional().describe("Where the value will come from; null clears the choice (choose_source)."),
6024
+ note: z.string().max(2e3).optional().describe("Why, or whom to ask (choose_source).")
6025
+ };
6026
+ function handleAnswer(getToken, baseUrl, args) {
6027
+ const base = `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}`;
6028
+ if (args.action === "enter_contract_value") {
6029
+ if (!args.variable || args.value === void 0 || !args.quote?.trim()) {
6030
+ return Promise.resolve(
6031
+ validationError(
6032
+ "enter_contract_value needs `variable`, `value` and `quote` (the verbatim contract passage printing the value)"
6033
+ )
6034
+ );
6035
+ }
6036
+ return runTool(
6037
+ () => apiJson(getToken, baseUrl, "POST", `${base}/values`, {
6038
+ body: { variable: args.variable, value: args.value, quote: args.quote }
6039
+ })
6040
+ );
6041
+ }
6042
+ if (!args.key || args.choice === void 0) {
6043
+ return Promise.resolve(
6044
+ validationError("choose_source needs `key` and `choice` (from_invoice | request | null)")
6045
+ );
6046
+ }
6047
+ return runTool(
6048
+ () => apiJson(getToken, baseUrl, "POST", `${base}/decide`, {
6049
+ body: { key: args.key, choice: args.choice, note: args.note ?? null }
6050
+ })
6051
+ );
6052
+ }
6053
+ var ASSUMPTIONS_DESCRIPTION = [
6054
+ "List the active assumptions: stand-in values used where no real value exists yet.",
6055
+ "USE WHEN: reviewing what the numbers rest on, or finding an assumption's id to replace or withdraw it.",
6056
+ "NOT FOR: making or changing one (talonic_price_baseline_assume).",
6057
+ "",
6058
+ "ARGS: `contract_key` (optional; the assumptions that apply to that contract, its own and the workspace's). Without it, every active assumption of the workspace.",
6059
+ "RETURNS: data[] { id, contract_key (null = workspace), target_kind, target, period_from, period_to, rule, value, unit, params { series, factor }, note, created_by }."
6060
+ ].join("\n");
6061
+ var assumptionsInputSchema = {
6062
+ contract_key: z.string().min(1).max(64).optional().describe("Contract key (from the register) to list the assumptions applying to it.")
6063
+ };
6064
+ function handleAssumptions(getToken, baseUrl, args) {
6065
+ return runTool(
6066
+ () => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/assumptions", {
6067
+ params: { contract_key: args.contract_key }
6068
+ })
6069
+ );
6070
+ }
6071
+ var ASSUME_DESCRIPTION = [
6072
+ "Make, replace or withdraw an assumption: a marked stand-in for a value nobody has yet, for one contract or the whole workspace.",
6073
+ "USE WHEN: an open input offers `assume` and the real value cannot be had now (e.g. a levy not yet published, a quantity the customer has not sent). Use the input's `assume_target` as `target_kind` + `target`.",
6074
+ "NOT FOR: a value you can source: enter it (talonic_price_baseline_answer, talonic_price_baseline_add_index_values). Never assume a number you could read.",
6075
+ "",
6076
+ "ARGS: `action` (create | replace | withdraw), `assumption_id` (replace, withdraw). create/replace (full assumption): `scope` (contract + `contract_key` | workspace), `target_kind` (series | variable | quantity | profile), `target` (series key or variable; `*` = every series, carry_forward only), `rule`, `value`, `unit`, `params { series, factor }`, `period_from`/`period_to` (YYYY[-MM|-Qn|-Hn]; omit = open-ended), `note` (required: why).",
6077
+ "Rule value = this number; carry_forward = the series' last real value; proxy = `params.series` \xD7 `params.factor`. A contract assumption wins over a workspace one. Withdraw reopens the gap.",
6078
+ "RETURNS: the stored assumption, or { id, active: false }.",
6079
+ RULES
6080
+ ].join("\n");
6081
+ var assumeInputSchema = {
6082
+ action: z.enum(["create", "replace", "withdraw"]),
6083
+ assumption_id: z.string().uuid().optional().describe("Assumption to replace or withdraw."),
6084
+ scope: z.enum(["contract", "workspace"]).optional().describe("One contract (needs `contract_key`) or every contract of the workspace."),
6085
+ contract_key: z.string().min(1).max(64).optional().describe("Contract key (scope: contract)."),
6086
+ target_kind: z.enum(["series", "variable", "quantity", "profile"]).optional(),
6087
+ target: z.string().min(1).max(120).optional().describe("Series key or variable name; `*` = every series."),
6088
+ rule: z.enum(["value", "carry_forward", "proxy"]).optional(),
6089
+ value: z.number().optional().describe("The assumed number (rule: value)."),
6090
+ unit: z.string().max(40).optional(),
6091
+ params: z.object({
6092
+ series: z.string().min(1).max(120).optional().describe("Source series (proxy, profile)."),
6093
+ factor: z.number().optional().describe("Multiplier on the source series (proxy).")
6094
+ }).optional(),
6095
+ period_from: z.string().regex(INDEX_PERIOD_RE).optional(),
6096
+ period_to: z.string().regex(INDEX_PERIOD_RE).optional(),
6097
+ note: z.string().min(1).max(2e3).optional().describe("Why this assumption is made (required).")
6098
+ };
6099
+ function assumptionProblem(a) {
6100
+ if (!a.scope) return "`scope` is required: contract (with `contract_key`) or workspace";
6101
+ if (a.scope === "contract" && !a.contract_key?.trim())
6102
+ return "scope contract needs `contract_key`";
6103
+ if (a.scope === "workspace" && a.contract_key) return "scope workspace takes no `contract_key`";
6104
+ if (!a.target_kind || !a.target?.trim() || !a.rule)
6105
+ return "`target_kind`, `target` and `rule` are required";
6106
+ if (!a.note?.trim()) return "`note` is required: say why the value is assumed";
6107
+ if (a.rule === "value" && a.target_kind !== "profile" && a.value === void 0)
6108
+ return "rule value needs `value`";
6109
+ if (a.rule === "carry_forward" && a.target_kind !== "series")
6110
+ return "only a series value can be carried forward";
6111
+ if ((a.rule === "proxy" || a.target_kind === "profile") && !a.params?.series)
6112
+ return "name the series it is derived from in `params.series`";
6113
+ if (a.target === "*" && (a.target_kind !== "series" || a.rule !== "carry_forward"))
6114
+ return "a default for every series (*) can only carry the last value forward";
6115
+ return null;
6116
+ }
6117
+ function handleAssume(getToken, baseUrl, args) {
6118
+ const path = (id) => `/v1/price-baseline/assumptions/${encodeURIComponent(id)}`;
6119
+ if (args.action !== "create" && !args.assumption_id) {
6120
+ return Promise.resolve(validationError(`${args.action} needs \`assumption_id\``));
6121
+ }
6122
+ if (args.action === "withdraw") {
6123
+ return runTool(() => apiJson(getToken, baseUrl, "DELETE", path(args.assumption_id)));
6124
+ }
6125
+ const problem = assumptionProblem(args);
6126
+ if (problem) return Promise.resolve(validationError(problem));
6127
+ const body = {
6128
+ contract_key: args.scope === "contract" ? args.contract_key?.trim() : null,
6129
+ target_kind: args.target_kind,
6130
+ target: args.target?.trim(),
6131
+ rule: args.rule,
6132
+ value: args.rule === "value" ? args.value ?? null : null,
6133
+ unit: args.unit ?? null,
6134
+ params: args.params,
6135
+ period_from: args.period_from ?? null,
6136
+ period_to: args.period_to ?? null,
6137
+ note: args.note?.trim()
6138
+ };
6139
+ return args.action === "create" ? runTool(() => apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/assumptions", { body })) : runTool(() => apiJson(getToken, baseUrl, "PUT", path(args.assumption_id), { body }));
6140
+ }
6141
+ var SYNC_DESCRIPTION = [
6142
+ "Sync external price data now (BEHG, Bundesbank, Destatis, EEX via Energy-Charts, DWD degree days), or change how often a series syncs.",
6143
+ "USE WHEN: talonic_price_baseline_indices `view: sync` shows a series as due, failed or stale, or a contract waits on a published value that should be out by now.",
6144
+ "NOT FOR: series with no feed, e.g. THE levies and grid tariffs (talonic_price_baseline_add_index_values); a backfill for a specific year range (talonic_price_baseline_refresh_indices).",
6145
+ "",
6146
+ "ARGS: sync: `keys` (series keys; omit to sync every shared series whose interval has passed). Schedule: `key` with `sync_hours` (1\u20132160) and/or `active` (false pauses; a shared series changes for everyone).",
6147
+ "RETURNS: sync data[] { series, stored, error } (a failed series reports its error, never an empty success); schedule, the series definition. Values arriving replace any assumption standing in for them."
6148
+ ].join("\n");
6149
+ var syncInputSchema = {
6150
+ keys: z.array(z.string().min(1)).max(50).optional().describe("Series keys to fetch now."),
6151
+ key: z.string().min(1).max(120).optional().describe("Series whose schedule to change."),
6152
+ sync_hours: z.number().int().min(1).max(2160).optional().describe("Sync interval in hours."),
6153
+ active: z.boolean().optional().describe("false pauses syncing.")
6154
+ };
6155
+ function handleSync(getToken, baseUrl, args) {
6156
+ const schedule = args.key !== void 0 || args.sync_hours !== void 0 || args.active !== void 0;
6157
+ if (schedule) {
6158
+ if (args.keys?.length) {
6159
+ return Promise.resolve(
6160
+ validationError("either sync (`keys`) or change a schedule (`key`), not both")
6161
+ );
6162
+ }
6163
+ if (!args.key || args.sync_hours === void 0 && args.active === void 0) {
6164
+ return Promise.resolve(
6165
+ validationError("a schedule change needs `key` and `sync_hours` or `active`")
6166
+ );
6167
+ }
6168
+ return runTool(
6169
+ () => apiJson(getToken, baseUrl, "PUT", "/v1/price-baseline/data/series", {
6170
+ body: { key: args.key, sync_hours: args.sync_hours, active: args.active }
6171
+ })
6172
+ );
6173
+ }
6174
+ return runTool(async () => ({
6175
+ data: await apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/data/series/sync", {
6176
+ body: args.keys?.length ? { keys: args.keys } : {}
6177
+ })
6178
+ }));
6179
+ }
6180
+ var IMPORTS_DESCRIPTION = [
6181
+ "Contract documents in data capture that have no price model yet, grouped by contract number, or the state of the import queue.",
6182
+ "USE WHEN: bringing a workspace's contracts into Price Baseline: pick candidates, queue them with talonic_price_baseline_import, then poll `view: status`.",
6183
+ "NOT FOR: documents that already have a model (talonic_price_baseline_register); invoices (talonic_price_baseline_documents).",
6184
+ "",
6185
+ "ARGS: `view` (candidates, default | status), `query` (filename contains; candidates only).",
6186
+ "RETURNS: candidates data[] { contract_key, documents[] { document_id, filename, kind (contract | amendment | price_sheet), created_at, import { status, error } | null } }; status { counts { pending, processing, done, failed }, failed[] { document_id, filename, error, attempts } }."
6187
+ ].join("\n");
6188
+ var importsInputSchema = {
6189
+ view: z.enum(["candidates", "status"]).optional(),
6190
+ query: z.string().optional().describe("Filename contains match (candidates).")
6191
+ };
6192
+ function handleImports(getToken, baseUrl, args) {
6193
+ if (args.view === "status") {
6194
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/import/status"));
6195
+ }
6196
+ return runTool(
6197
+ () => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/import/candidates", {
6198
+ params: { q: args.query }
6199
+ })
6200
+ );
6201
+ }
6202
+ var IMPORT_DESCRIPTION2 = [
6203
+ "Queue contract documents for import: each one's price model is read in the background, and documents sharing a contract number become versions of one contract.",
6204
+ "USE WHEN: importing several contracts at once from talonic_price_baseline_imports candidates, or retrying failed imports (a failed document is queued again).",
6205
+ "NOT FOR: one contract you want to read now and inspect (talonic_price_baseline_extract).",
6206
+ "",
6207
+ "ARGS: `document_ids` (1\u2013500 document UUIDs).",
6208
+ "RETURNS: { queued, skipped } (a document already queued or done is skipped). Each document costs one LLM call. Poll talonic_price_baseline_imports `view: status`; finished contracts appear in talonic_price_baseline_register."
6209
+ ].join("\n");
6210
+ var importInputSchema2 = {
6211
+ document_ids: z.array(z.string().uuid()).min(1).max(500).describe("Contract document UUIDs (from talonic_price_baseline_imports).")
6212
+ };
6213
+ function handleImport2(getToken, baseUrl, args) {
6214
+ return runTool(
6215
+ () => apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/import", {
6216
+ body: { document_ids: [...new Set(args.document_ids)] }
6217
+ })
6218
+ );
6219
+ }
6220
+ async function probePriceBaselineAccess(token, baseUrl) {
6221
+ try {
6222
+ const res = await fetch(buildUrl(baseUrl, "/v1/price-baseline/indices"), {
6223
+ headers: { Authorization: `Bearer ${token}`, Accept: "application/json" },
6224
+ signal: AbortSignal.timeout(5e3)
6225
+ });
6226
+ return res.ok;
6227
+ } catch {
6228
+ return false;
6229
+ }
6230
+ }
6231
+ function registerPriceBaselineTools(server, getToken, baseUrl) {
6232
+ const write7 = (idempotent) => ({
6233
+ readOnlyHint: false,
6234
+ destructiveHint: false,
6235
+ idempotentHint: idempotent,
6236
+ openWorldHint: false
6237
+ });
6238
+ server.registerTool(
6239
+ "talonic_price_baseline_documents",
6240
+ {
6241
+ title: "Find contracts and invoices",
6242
+ description: DOCUMENTS_DESCRIPTION,
6243
+ inputSchema: documentsInputSchema,
6244
+ annotations: readOnly7
6245
+ },
6246
+ async (args) => handleDocuments(getToken, baseUrl, args)
6247
+ );
6248
+ server.registerTool(
6249
+ "talonic_price_baseline_extract",
6250
+ {
6251
+ title: "Build or enrich a price model from a contract",
6252
+ description: EXTRACT_DESCRIPTION,
6253
+ inputSchema: extractInputSchema,
6254
+ annotations: write7(false)
6255
+ },
6256
+ async (args) => handleExtract2(getToken, baseUrl, args)
6257
+ );
6258
+ server.registerTool(
6259
+ "talonic_price_baseline_models",
6260
+ {
6261
+ title: "List or read price models",
6262
+ description: MODELS_DESCRIPTION,
6263
+ inputSchema: modelsInputSchema,
6264
+ annotations: readOnly7
6265
+ },
6266
+ async (args) => handleModels(getToken, baseUrl, args)
6267
+ );
6268
+ server.registerTool(
6269
+ "talonic_price_baseline_update_model",
6270
+ {
6271
+ title: "Edit or confirm a price model",
6272
+ description: UPDATE_DESCRIPTION,
6273
+ inputSchema: updateInputSchema,
6274
+ annotations: write7(true)
6275
+ },
6276
+ async (args) => handleUpdate(getToken, baseUrl, args)
6277
+ );
6278
+ server.registerTool(
6279
+ "talonic_price_baseline_prices",
6280
+ {
6281
+ title: "Recompute contract prices",
6282
+ description: PRICES_DESCRIPTION,
6283
+ inputSchema: pricesInputSchema,
6284
+ annotations: readOnly7
6285
+ },
6286
+ async (args) => handlePrices(getToken, baseUrl, args)
6287
+ );
6288
+ server.registerTool(
6289
+ "talonic_price_baseline_workbook",
6290
+ {
6291
+ title: "Download the price baseline workbook",
6292
+ description: WORKBOOK_DESCRIPTION,
6293
+ inputSchema: workbookInputSchema,
6294
+ annotations: readOnly7
6295
+ },
6296
+ async (args) => handleWorkbook(getToken, baseUrl, args)
6297
+ );
6298
+ server.registerTool(
6299
+ "talonic_price_baseline_compare",
6300
+ {
6301
+ title: "Check an invoice against the contract",
6302
+ description: COMPARE_DESCRIPTION,
6303
+ inputSchema: compareInputSchema,
6304
+ annotations: write7(false)
6305
+ },
6306
+ async (args) => handleCompare(getToken, baseUrl, args)
6307
+ );
6308
+ server.registerTool(
6309
+ "talonic_price_baseline_proof_invoice",
6310
+ {
6311
+ title: "Audit-proof invoice",
6312
+ description: PROOF_INVOICE_DESCRIPTION,
6313
+ inputSchema: proofInvoiceInputSchema,
6314
+ annotations: readOnly7
6315
+ },
6316
+ async (args) => handleProofInvoice(getToken, baseUrl, args)
6317
+ );
6318
+ server.registerTool(
6319
+ "talonic_price_baseline_indices",
6320
+ {
6321
+ title: "Index catalog and values",
6322
+ description: INDICES_DESCRIPTION,
6323
+ inputSchema: indicesInputSchema,
6324
+ annotations: readOnly7
6325
+ },
6326
+ async (args) => handleIndices(getToken, baseUrl, args)
6327
+ );
6328
+ server.registerTool(
6329
+ "talonic_price_baseline_refresh_indices",
6330
+ {
6331
+ title: "Fetch public index values",
6332
+ description: REFRESH_DESCRIPTION,
6333
+ inputSchema: refreshInputSchema,
6334
+ annotations: { ...write7(true), openWorldHint: true }
6335
+ },
6336
+ async (args) => handleRefresh(getToken, baseUrl, args)
6337
+ );
6338
+ server.registerTool(
6339
+ "talonic_price_baseline_add_index_values",
6340
+ {
6341
+ title: "Enter sourced index values",
6342
+ description: MANUAL_DESCRIPTION,
6343
+ inputSchema: manualInputSchema,
6344
+ annotations: write7(true)
6345
+ },
6346
+ async (args) => handleManual(getToken, baseUrl, args)
6347
+ );
6348
+ server.registerTool(
6349
+ "talonic_price_baseline_register",
6350
+ {
6351
+ title: "Contract register and expected invoices",
6352
+ description: REGISTER_DESCRIPTION2,
6353
+ inputSchema: registerInputSchema2,
6354
+ annotations: readOnly7
6355
+ },
6356
+ async (args) => handleRegister2(getToken, baseUrl, args)
6357
+ );
6358
+ server.registerTool(
6359
+ "talonic_price_baseline_contract",
6360
+ {
6361
+ title: "Contract workbook and open inputs",
6362
+ description: CONTRACT_DESCRIPTION3,
6363
+ inputSchema: contractInputSchema3,
6364
+ annotations: readOnly7
6365
+ },
6366
+ async (args) => handleContract3(getToken, baseUrl, args)
6367
+ );
6368
+ server.registerTool(
6369
+ "talonic_price_baseline_answer",
6370
+ {
6371
+ title: "Answer an open contract input",
6372
+ description: ANSWER_DESCRIPTION,
6373
+ inputSchema: answerInputSchema,
6374
+ annotations: write7(true)
6375
+ },
6376
+ async (args) => handleAnswer(getToken, baseUrl, args)
6377
+ );
6378
+ server.registerTool(
6379
+ "talonic_price_baseline_assumptions",
6380
+ {
6381
+ title: "List assumptions",
6382
+ description: ASSUMPTIONS_DESCRIPTION,
6383
+ inputSchema: assumptionsInputSchema,
6384
+ annotations: readOnly7
6385
+ },
6386
+ async (args) => handleAssumptions(getToken, baseUrl, args)
6387
+ );
6388
+ server.registerTool(
6389
+ "talonic_price_baseline_assume",
6390
+ {
6391
+ title: "Make, replace or withdraw an assumption",
6392
+ description: ASSUME_DESCRIPTION,
6393
+ inputSchema: assumeInputSchema,
6394
+ annotations: { ...write7(false), destructiveHint: true }
6395
+ },
6396
+ async (args) => handleAssume(getToken, baseUrl, args)
6397
+ );
6398
+ server.registerTool(
6399
+ "talonic_price_baseline_sync_series",
6400
+ {
6401
+ title: "Sync external price data",
6402
+ description: SYNC_DESCRIPTION,
6403
+ inputSchema: syncInputSchema,
6404
+ annotations: { ...write7(true), openWorldHint: true }
6405
+ },
6406
+ async (args) => handleSync(getToken, baseUrl, args)
6407
+ );
6408
+ server.registerTool(
6409
+ "talonic_price_baseline_imports",
6410
+ {
6411
+ title: "Import candidates and status",
6412
+ description: IMPORTS_DESCRIPTION,
6413
+ inputSchema: importsInputSchema,
6414
+ annotations: readOnly7
6415
+ },
6416
+ async (args) => handleImports(getToken, baseUrl, args)
6417
+ );
6418
+ server.registerTool(
6419
+ "talonic_price_baseline_import",
6420
+ {
6421
+ title: "Import contracts from data capture",
6422
+ description: IMPORT_DESCRIPTION2,
6423
+ inputSchema: importInputSchema2,
6424
+ annotations: write7(true)
6425
+ },
6426
+ async (args) => handleImport2(getToken, baseUrl, args)
6427
+ );
6428
+ }
5484
6429
  var DEFAULT_BASE3 = "https://api.talonic.com";
5485
6430
  var TASK_STATUSES = ["available", "claimed", "submitted", "timed_out", "cancelled"];
5486
6431
  var taskId = z.string().uuid().describe("Agent task UUID.");
@@ -7027,7 +7972,7 @@ function registerAskTools(server, getToken, baseUrl) {
7027
7972
 
7028
7973
  // package.json
7029
7974
  var package_default = {
7030
- version: "0.1.91"};
7975
+ version: "0.1.92"};
7031
7976
 
7032
7977
  // src/version.ts
7033
7978
  var VERSION = package_default.version;
@@ -7196,6 +8141,9 @@ function createServer(options) {
7196
8141
  if (options.includeSubmissionsTools) {
7197
8142
  registerSubmissionsTools(server, rawToken, baseUrl);
7198
8143
  }
8144
+ if (options.includePriceBaselineTools) {
8145
+ registerPriceBaselineTools(server, rawToken, baseUrl);
8146
+ }
7199
8147
  registerSchemasResource(server, getTalonic);
7200
8148
  registerWebhooksResource(server, rawToken, baseUrl);
7201
8149
  registerWidgets(server);
@@ -7256,7 +8204,8 @@ async function main(argv = process.argv.slice(2), env = process.env, out = (line
7256
8204
  includeDocGenTools,
7257
8205
  includePartiesTools,
7258
8206
  includeMasterRecordsTools,
7259
- includeSubmissionsTools
8207
+ includeSubmissionsTools,
8208
+ includePriceBaselineTools
7260
8209
  ] = await Promise.all([
7261
8210
  probeGrowthAccess(apiKey, baseUrl),
7262
8211
  probeAgentTaskAdminAccess(apiKey, baseUrl),
@@ -7265,7 +8214,8 @@ async function main(argv = process.argv.slice(2), env = process.env, out = (line
7265
8214
  probeDocGenAccess(apiKey, baseUrl),
7266
8215
  probePartiesAccess(apiKey, baseUrl),
7267
8216
  probeMasterRecordsAccess(apiKey, baseUrl),
7268
- probeSubmissionsAccess(apiKey, baseUrl)
8217
+ probeSubmissionsAccess(apiKey, baseUrl),
8218
+ probePriceBaselineAccess(apiKey, baseUrl)
7269
8219
  ]);
7270
8220
  const server = createServer({
7271
8221
  apiKey,
@@ -7277,7 +8227,8 @@ async function main(argv = process.argv.slice(2), env = process.env, out = (line
7277
8227
  includeDocGenTools,
7278
8228
  includePartiesTools,
7279
8229
  includeMasterRecordsTools,
7280
- includeSubmissionsTools
8230
+ includeSubmissionsTools,
8231
+ includePriceBaselineTools
7281
8232
  });
7282
8233
  const transport = new StdioServerTransport();
7283
8234
  await server.connect(transport);