@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/index.js CHANGED
@@ -3106,6 +3106,56 @@ function handleUpcoming(getToken, baseUrl, args) {
3106
3106
  () => apiJson(getToken, baseUrl, "GET", "/v1/contracts/upcoming", { params: { days: args.days } })
3107
3107
  );
3108
3108
  }
3109
+ var PROCESSES_DESCRIPTION = [
3110
+ "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.",
3111
+ "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.",
3112
+ "NOT FOR: dates only (talonic_contracts_upcoming); one contract's processes (talonic_contracts_contract, `processes[]`).",
3113
+ "",
3114
+ "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`.",
3115
+ "RETURNS: data[] { id, contract_id, contract_key, title, counterparty, rule_id, department, phase, kind, due_date, days_left, evidence[] { field, value, document_id } }."
3116
+ ].join("\n");
3117
+ var DEPARTMENTS = [
3118
+ "sales",
3119
+ "billing",
3120
+ "legal",
3121
+ "operations",
3122
+ "property",
3123
+ "contract_management",
3124
+ "procurement",
3125
+ "controlling"
3126
+ ];
3127
+ var processesInputSchema = {
3128
+ department: z.enum(DEPARTMENTS).optional().describe("Only this department's items."),
3129
+ days: z.number().int().min(1).max(3650).optional().describe("Days ahead for dated items."),
3130
+ contract_id: z.string().uuid().optional().describe("Only this contract's items.")
3131
+ };
3132
+ function handleProcesses(getToken, baseUrl, args) {
3133
+ return runTool(
3134
+ () => apiJson(getToken, baseUrl, "GET", "/v1/contracts/processes", {
3135
+ params: { department: args.department, days: args.days, contract_id: args.contract_id }
3136
+ })
3137
+ );
3138
+ }
3139
+ var PROCESS_DESCRIPTION = [
3140
+ "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.",
3141
+ "USE WHEN: a process from talonic_contracts_processes was done, or was marked by mistake.",
3142
+ "NOT FOR: key dates (talonic_contracts_key_date).",
3143
+ "",
3144
+ "ARGS: `process_id`, `handled` (true / false), `note` (what was done).",
3145
+ "RETURNS: { id, handled }."
3146
+ ].join("\n");
3147
+ var processInputSchema = {
3148
+ process_id: z.string().uuid(),
3149
+ handled: z.boolean(),
3150
+ note: z.string().max(2e3).optional()
3151
+ };
3152
+ function handleProcess(getToken, baseUrl, args) {
3153
+ return runTool(
3154
+ () => apiJson(getToken, baseUrl, "POST", `/v1/contracts/processes/${args.process_id}`, {
3155
+ body: { handled: args.handled, note: args.note }
3156
+ })
3157
+ );
3158
+ }
3109
3159
  var CANDIDATES_DESCRIPTION = [
3110
3160
  "Contract documents whose terms have not been read yet, grouped by the contract key in their filename; keys Contract Pricing already models first.",
3111
3161
  "USE WHEN: choosing what to read, or checking how the documents will group before importing.",
@@ -3404,6 +3454,22 @@ function registerContractsTools(server, getToken, baseUrl) {
3404
3454
  write(true),
3405
3455
  (a) => handleKeyDate(getToken, baseUrl, a)
3406
3456
  ],
3457
+ [
3458
+ "talonic_contracts_processes",
3459
+ "Processes the contract data starts",
3460
+ PROCESSES_DESCRIPTION,
3461
+ processesInputSchema,
3462
+ readOnly,
3463
+ (a) => handleProcesses(getToken, baseUrl, a)
3464
+ ],
3465
+ [
3466
+ "talonic_contracts_process",
3467
+ "Mark a process handled",
3468
+ PROCESS_DESCRIPTION,
3469
+ processInputSchema,
3470
+ write(true),
3471
+ (a) => handleProcess(getToken, baseUrl, a)
3472
+ ],
3407
3473
  [
3408
3474
  "talonic_contracts_set_term",
3409
3475
  "Set a contract term with its quote",
@@ -5180,7 +5246,7 @@ function handleIssues5(getToken, baseUrl, args) {
5180
5246
  () => apiJson(getToken, baseUrl, "GET", "/v1/submissions/issues", { params: args })
5181
5247
  );
5182
5248
  }
5183
- var PROCESS_DESCRIPTION = [
5249
+ var PROCESS_DESCRIPTION2 = [
5184
5250
  "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.",
5185
5251
  "USE WHEN: new submissions arrived (only: not_captured), or a target structure changed and submissions need re-mapping (only: not_mapped or all).",
5186
5252
  "NOT FOR: reading results (talonic_submissions_list, talonic_submissions_issues).",
@@ -5188,7 +5254,7 @@ var PROCESS_DESCRIPTION = [
5188
5254
  "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`.",
5189
5255
  "RETURNS: dry_run \u2192 { plan[] { document_id, filename, capture, map } }; otherwise { results[] { document_id, ok, facts?, checks_failed?, error? } }."
5190
5256
  ].join("\n");
5191
- var processInputSchema = {
5257
+ var processInputSchema2 = {
5192
5258
  spec_id: specId.optional(),
5193
5259
  document_ids: z.array(z.string().uuid()).max(200).optional(),
5194
5260
  only: z.enum(["not_captured", "not_mapped", "all"]).optional(),
@@ -5196,7 +5262,7 @@ var processInputSchema = {
5196
5262
  limit: z.number().int().min(1).max(200).optional(),
5197
5263
  dry_run: z.boolean().optional().describe("List what would run; nothing runs.")
5198
5264
  };
5199
- function handleProcess(getToken, baseUrl, args) {
5265
+ function handleProcess2(getToken, baseUrl, args) {
5200
5266
  return runTool(
5201
5267
  () => apiJson(getToken, baseUrl, "POST", "/v1/submissions/process", { body: args })
5202
5268
  );
@@ -5318,6 +5384,56 @@ function handleChecks(getToken, baseUrl, args) {
5318
5384
  )
5319
5385
  );
5320
5386
  }
5387
+ var REVIEW_DESCRIPTION = [
5388
+ "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`.",
5389
+ "USE WHEN: labels are waiting for review (talonic_submissions_specs shows labels_to_review) and nobody will check them one by one.",
5390
+ "NOT FOR: the questions themselves (talonic_submissions_questions).",
5391
+ "",
5392
+ "ARGS: `spec_id`, `start` (true to start a review).",
5393
+ "RETURNS: { run: { phase, done, total, stats } | null, decisions: { total, proposed, questions, confirmed, fixed, best_guess, answered } }."
5394
+ ].join("\n");
5395
+ var reviewInputSchema = {
5396
+ spec_id: z.string().uuid().describe("Target structure id (talonic_submissions_specs)."),
5397
+ start: z.boolean().optional().describe("Start a review instead of reading its status.")
5398
+ };
5399
+ function handleReview(getToken, baseUrl, args) {
5400
+ return runTool(
5401
+ () => args.start ? apiJson(getToken, baseUrl, "POST", "/v1/submissions/review", {
5402
+ body: { spec_id: args.spec_id }
5403
+ }) : apiJson(getToken, baseUrl, "GET", "/v1/submissions/review", {
5404
+ params: { spec_id: args.spec_id }
5405
+ })
5406
+ );
5407
+ }
5408
+ var QUESTIONS_DESCRIPTION = [
5409
+ "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.",
5410
+ "USE WHEN: walking the client's experts through the few questions only they can answer, or recording their answers.",
5411
+ "NOT FOR: starting a review (talonic_submissions_review).",
5412
+ "",
5413
+ "ARGS: `spec_id`; to answer: `group` (from the list) and `option` (0-based index into its options).",
5414
+ "RETURNS: list: data[] { group, question, options[], labels[] { label_key, text, where, samples[] } }; answer: { settled }."
5415
+ ].join("\n");
5416
+ var questionsInputSchema = {
5417
+ spec_id: z.string().uuid().describe("Target structure id (talonic_submissions_specs)."),
5418
+ group: z.string().max(400).optional().describe("The question group to answer (from the list)."),
5419
+ option: z.number().int().min(0).max(5).optional().describe("0-based index of the chosen option.")
5420
+ };
5421
+ function handleQuestions(getToken, baseUrl, args) {
5422
+ if (args.group === void 0 !== (args.option === void 0)) {
5423
+ return Promise.resolve(
5424
+ validationError(
5425
+ "Give both `group` and `option` to answer, or neither to list the questions."
5426
+ )
5427
+ );
5428
+ }
5429
+ return runTool(
5430
+ () => args.group !== void 0 ? apiJson(getToken, baseUrl, "POST", "/v1/submissions/questions/answer", {
5431
+ body: { spec_id: args.spec_id, group: args.group, option: args.option }
5432
+ }) : apiJson(getToken, baseUrl, "GET", "/v1/submissions/questions", {
5433
+ params: { spec_id: args.spec_id }
5434
+ })
5435
+ );
5436
+ }
5321
5437
  function registerSubmissionsTools(server, getToken, baseUrl) {
5322
5438
  const tools = [
5323
5439
  [
@@ -5347,10 +5463,10 @@ function registerSubmissionsTools(server, getToken, baseUrl) {
5347
5463
  [
5348
5464
  "talonic_submissions_process",
5349
5465
  "Capture and map submissions",
5350
- PROCESS_DESCRIPTION,
5351
- processInputSchema,
5466
+ PROCESS_DESCRIPTION2,
5467
+ processInputSchema2,
5352
5468
  write6(true),
5353
- (a) => handleProcess(getToken, baseUrl, a)
5469
+ (a) => handleProcess2(getToken, baseUrl, a)
5354
5470
  ],
5355
5471
  [
5356
5472
  "talonic_submissions_completeness",
@@ -5384,6 +5500,22 @@ function registerSubmissionsTools(server, getToken, baseUrl) {
5384
5500
  readOnly6,
5385
5501
  (a) => handleChecks(getToken, baseUrl, a)
5386
5502
  ],
5503
+ [
5504
+ "talonic_submissions_review",
5505
+ "Review label mappings",
5506
+ REVIEW_DESCRIPTION,
5507
+ reviewInputSchema,
5508
+ write6(true),
5509
+ (a) => handleReview(getToken, baseUrl, a)
5510
+ ],
5511
+ [
5512
+ "talonic_submissions_questions",
5513
+ "Questions for the client's experts",
5514
+ QUESTIONS_DESCRIPTION,
5515
+ questionsInputSchema,
5516
+ write6(true),
5517
+ (a) => handleQuestions(getToken, baseUrl, a)
5518
+ ],
5387
5519
  [
5388
5520
  "talonic_submissions_export",
5389
5521
  "Export submission facts",
@@ -5401,6 +5533,808 @@ function registerSubmissionsTools(server, getToken, baseUrl) {
5401
5533
  );
5402
5534
  }
5403
5535
  }
5536
+ var MONTH_RE = /^\d{4}-\d{2}$/;
5537
+ var INDEX_PERIOD_RE = /^\d{4}(-\d{2}|-Q[1-4]|-H[12])?$/;
5538
+ var modelIdArg = z.string().uuid().describe("Price model id (from talonic_price_baseline_models).");
5539
+ var fromArg = z.string().regex(MONTH_RE).describe("First month of the evaluation window, `YYYY-MM`.");
5540
+ var toArg = z.string().regex(MONTH_RE).describe("Last month of the evaluation window, `YYYY-MM`.");
5541
+ var readOnly7 = {
5542
+ readOnlyHint: true,
5543
+ destructiveHint: false,
5544
+ idempotentHint: true,
5545
+ openWorldHint: false
5546
+ };
5547
+ var DOCUMENTS_DESCRIPTION = [
5548
+ "Find contracts and invoices in the workspace to build a price baseline from.",
5549
+ "USE WHEN: picking the contract for talonic_price_baseline_extract or the invoice for talonic_price_baseline_compare.",
5550
+ "NOT FOR: general document search across all content (talonic_search).",
5551
+ "",
5552
+ "ARGS: `query` (filename contains, optional).",
5553
+ "RETURNS: data[] { id, filename, created_at }. Which contracts already have a model: talonic_price_baseline_models."
5554
+ ].join("\n");
5555
+ var documentsInputSchema = {
5556
+ query: z.string().optional().describe("Filename contains match (e.g. 'W\xE4rmeliefervertrag').")
5557
+ };
5558
+ function handleDocuments(getToken, baseUrl, args) {
5559
+ return runTool(
5560
+ () => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/documents", {
5561
+ params: { q: args.query }
5562
+ })
5563
+ );
5564
+ }
5565
+ var EXTRACT_DESCRIPTION = [
5566
+ "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.",
5567
+ "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.",
5568
+ "NOT FOR: generic field extraction (talonic_extract); editing an existing model (talonic_price_baseline_update_model).",
5569
+ "",
5570
+ "ARGS: `document_id` (contract UUID) or `model_id` (enrich), `use_opus` (slower, for long or unusual clauses; document_id only).",
5571
+ "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."
5572
+ ].join("\n");
5573
+ var extractInputSchema = {
5574
+ document_id: z.string().uuid().optional().describe("Contract document UUID (new model)."),
5575
+ model_id: modelIdArg.optional().describe(
5576
+ "Existing model to enrich with contract number, customer, site and agreed quantities."
5577
+ ),
5578
+ use_opus: z.boolean().optional().describe("Use the larger model for long or unusual price clauses.")
5579
+ };
5580
+ function handleExtract2(getToken, baseUrl, args) {
5581
+ if (!!args.document_id === !!args.model_id) {
5582
+ return Promise.resolve(
5583
+ validationError("provide either `document_id` (new model) or `model_id` (enrich), not both")
5584
+ );
5585
+ }
5586
+ if (args.model_id) {
5587
+ return runTool(
5588
+ () => apiJson(
5589
+ getToken,
5590
+ baseUrl,
5591
+ "POST",
5592
+ `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}/enrich`
5593
+ )
5594
+ );
5595
+ }
5596
+ return runTool(
5597
+ () => apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/models", {
5598
+ body: { document_id: args.document_id, use_opus: args.use_opus }
5599
+ })
5600
+ );
5601
+ }
5602
+ var MODELS_DESCRIPTION = [
5603
+ "List the workspace's price models, or read one in full when `model_id` is given.",
5604
+ "USE WHEN: finding a model id, or reviewing a model's components, formulas, indices and quotes before confirming it.",
5605
+ "NOT FOR: computed prices (talonic_price_baseline_prices); invoice checks (talonic_price_baseline_compare).",
5606
+ "",
5607
+ "ARGS: `model_id` (optional UUID).",
5608
+ "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`."
5609
+ ].join("\n");
5610
+ var modelsInputSchema = {
5611
+ model_id: modelIdArg.optional()
5612
+ };
5613
+ function handleModels(getToken, baseUrl, args) {
5614
+ const path = args.model_id ? `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}` : "/v1/price-baseline/models";
5615
+ return runTool(() => apiJson(getToken, baseUrl, "GET", path));
5616
+ }
5617
+ var UPDATE_DESCRIPTION = [
5618
+ "Edit a price model after review: replace its model, confirm it, place it in a contract, or exclude it.",
5619
+ "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`).",
5620
+ "NOT FOR: first extraction (talonic_price_baseline_extract); entering one missing contract value (talonic_price_baseline_answer).",
5621
+ "",
5622
+ "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).",
5623
+ "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."
5624
+ ].join("\n");
5625
+ var updateInputSchema = {
5626
+ model_id: modelIdArg,
5627
+ model: z.record(z.string(), z.unknown()).optional().describe("The full edited model object (the `model` field of the stored model)."),
5628
+ status: z.enum(["draft", "confirmed", "excluded"]).optional().describe(
5629
+ "`confirmed` once a reviewer accepts the model; `excluded` for a document of the contract that sets no price."
5630
+ ),
5631
+ contract_key: z.string().max(64).nullable().optional().describe(
5632
+ "Contract this document belongs to (its contract number); null clears a hand-set key."
5633
+ ),
5634
+ superseded_by: z.string().uuid().nullable().optional().describe("Model of the amendment or price sheet that replaces this one; null unlinks.")
5635
+ };
5636
+ function handleUpdate(getToken, baseUrl, args) {
5637
+ const { model_id, ...patch } = args;
5638
+ if (Object.values(patch).every((v) => v === void 0)) {
5639
+ return Promise.resolve(
5640
+ validationError("provide at least one of `model`, `status`, `contract_key`, `superseded_by`")
5641
+ );
5642
+ }
5643
+ return runTool(
5644
+ () => apiJson(getToken, baseUrl, "PUT", `/v1/price-baseline/models/${encodeURIComponent(model_id)}`, {
5645
+ body: patch
5646
+ })
5647
+ );
5648
+ }
5649
+ var PRICES_DESCRIPTION = [
5650
+ "Recompute every price of a model for each price period in a window, from the index values on file.",
5651
+ "USE WHEN: you need the contract's own price per period, independent of the biller's price sheet.",
5652
+ "NOT FOR: checking a specific invoice (talonic_price_baseline_compare); the Excel file (talonic_price_baseline_workbook).",
5653
+ "",
5654
+ "ARGS: `model_id`, `from`, `to` (YYYY-MM).",
5655
+ "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."
5656
+ ].join("\n");
5657
+ var pricesInputSchema = { model_id: modelIdArg, from: fromArg, to: toArg };
5658
+ function handlePrices(getToken, baseUrl, args) {
5659
+ return runTool(
5660
+ () => apiJson(
5661
+ getToken,
5662
+ baseUrl,
5663
+ "GET",
5664
+ `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}/prices`,
5665
+ {
5666
+ params: { from: args.from, to: args.to }
5667
+ }
5668
+ )
5669
+ );
5670
+ }
5671
+ var WORKBOOK_DESCRIPTION = [
5672
+ "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.",
5673
+ "USE WHEN: the user wants the baseline as a spreadsheet, or to hand over an invoice check.",
5674
+ "NOT FOR: reading prices as data (talonic_price_baseline_prices).",
5675
+ "",
5676
+ "ARGS: `model_id`, `from`, `to` (YYYY-MM), `comparison_id` (optional, fills the Rechnungspr\xFCfung sheet).",
5677
+ "RETURNS: the .xlsx as an embedded resource (base64) plus its filename and size."
5678
+ ].join("\n");
5679
+ var workbookInputSchema = {
5680
+ model_id: modelIdArg,
5681
+ from: fromArg,
5682
+ to: toArg,
5683
+ comparison_id: z.string().uuid().optional().describe("Invoice comparison to include (from talonic_price_baseline_compare).")
5684
+ };
5685
+ var XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
5686
+ async function handleWorkbook(getToken, baseUrl, args) {
5687
+ try {
5688
+ const url = buildUrl(
5689
+ baseUrl,
5690
+ `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}/workbook.xlsx`,
5691
+ {
5692
+ from: args.from,
5693
+ to: args.to,
5694
+ comparison_id: args.comparison_id
5695
+ }
5696
+ );
5697
+ const res = await resolveFetch(getToken)(url, {
5698
+ headers: { Authorization: `Bearer ${getToken()}`, Accept: XLSX_MIME }
5699
+ });
5700
+ if (!res.ok) {
5701
+ const text = await res.text().catch(() => "");
5702
+ throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
5703
+ }
5704
+ const buf = Buffer.from(await res.arrayBuffer());
5705
+ const filename = /filename="([^"]+)"/.exec(res.headers.get("content-disposition") ?? "")?.[1] ?? `price-baseline-${args.model_id}.xlsx`;
5706
+ return {
5707
+ content: [
5708
+ { type: "text", text: JSON.stringify({ filename, bytes: buf.length }, null, 2) },
5709
+ {
5710
+ type: "resource",
5711
+ resource: {
5712
+ uri: `talonic://price-baseline/${args.model_id}/${filename}`,
5713
+ mimeType: XLSX_MIME,
5714
+ blob: buf.toString("base64")
5715
+ }
5716
+ }
5717
+ ]
5718
+ };
5719
+ } catch (err) {
5720
+ return toolError(err);
5721
+ }
5722
+ }
5723
+ var COMPARE_DESCRIPTION = [
5724
+ "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.",
5725
+ "USE WHEN: establishing Money Found for an invoice, or listing past checks (`list: true`).",
5726
+ "NOT FOR: prices without an invoice (talonic_price_baseline_prices).",
5727
+ "",
5728
+ "ARGS: `model_id`, `invoice_document_id` (invoice UUID, to run a new check) or `list: true` (past checks).",
5729
+ "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."
5730
+ ].join("\n");
5731
+ var compareInputSchema = {
5732
+ model_id: modelIdArg,
5733
+ invoice_document_id: z.string().uuid().optional().describe("Invoice document UUID to check."),
5734
+ list: z.boolean().optional().describe("List this model's past comparisons instead of running one.")
5735
+ };
5736
+ function handleCompare(getToken, baseUrl, args) {
5737
+ const base = `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}`;
5738
+ if (args.list) return runTool(() => apiJson(getToken, baseUrl, "GET", `${base}/comparisons`));
5739
+ if (!args.invoice_document_id) {
5740
+ return Promise.resolve(
5741
+ validationError("provide `invoice_document_id`, or `list: true` for past comparisons")
5742
+ );
5743
+ }
5744
+ return runTool(
5745
+ () => apiJson(getToken, baseUrl, "POST", `${base}/compare`, {
5746
+ body: { invoice_document_id: args.invoice_document_id }
5747
+ })
5748
+ );
5749
+ }
5750
+ var PROOF_INVOICE_DESCRIPTION = [
5751
+ "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.",
5752
+ "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.",
5753
+ "NOT FOR: running a new check or listing past checks (talonic_price_baseline_compare); prices without an invoice (talonic_price_baseline_prices).",
5754
+ "",
5755
+ "ARGS: `comparison_id` (from talonic_price_baseline_compare), `format` (json, default | html).",
5756
+ "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."
5757
+ ].join("\n");
5758
+ var proofInvoiceInputSchema = {
5759
+ comparison_id: z.string().uuid().describe("Comparison UUID (talonic_price_baseline_compare)."),
5760
+ format: z.enum(["json", "html"]).optional().describe("json (default): the restated invoice; html: the self-contained page.")
5761
+ };
5762
+ function handleProofInvoice(getToken, baseUrl, args) {
5763
+ const path = `/v1/price-baseline/comparisons/${encodeURIComponent(args.comparison_id)}/proof-invoice`;
5764
+ return runTool(async () => {
5765
+ const { invoice, html } = await apiJson(
5766
+ getToken,
5767
+ baseUrl,
5768
+ "GET",
5769
+ path
5770
+ );
5771
+ const pdf_url = buildUrl(baseUrl, `${path}.pdf`);
5772
+ return args.format === "html" ? { html, pdf_url } : { ...invoice, pdf_url };
5773
+ });
5774
+ }
5775
+ var INDICES_DESCRIPTION = [
5776
+ "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.",
5777
+ "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`).",
5778
+ "NOT FOR: fetching new values (talonic_price_baseline_sync_series, talonic_price_baseline_refresh_indices) or entering them (talonic_price_baseline_add_index_values).",
5779
+ "",
5780
+ "ARGS: `series` (optional list of series keys, e.g. ['destatis.vpi', 'behg.co2']) for values; else `view` (catalog, default | sync).",
5781
+ "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) }."
5782
+ ].join("\n");
5783
+ var indicesInputSchema = {
5784
+ series: z.array(z.string().min(1)).max(50).optional().describe("Series keys to read values for."),
5785
+ view: z.enum(["catalog", "sync"]).optional().describe("Without `series`: the catalog (default) or each series' sync state.")
5786
+ };
5787
+ function handleIndices(getToken, baseUrl, args) {
5788
+ if (args.series?.length) {
5789
+ return runTool(
5790
+ () => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/indices/values", {
5791
+ params: { series: args.series?.join(",") }
5792
+ })
5793
+ );
5794
+ }
5795
+ if (args.view === "sync") {
5796
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/data/series"));
5797
+ }
5798
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/indices"));
5799
+ }
5800
+ var REFRESH_DESCRIPTION = [
5801
+ "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).",
5802
+ "USE WHEN: talonic_price_baseline_prices reports a missing public index for a specific year range (backfill).",
5803
+ "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).",
5804
+ "",
5805
+ "ARGS: `series` (catalog keys), `from_year`, `to_year`.",
5806
+ "RETURNS: data[] { series, stored, error }. A failed series reports its error; it never succeeds empty."
5807
+ ].join("\n");
5808
+ var refreshInputSchema = {
5809
+ series: z.array(z.string().min(1)).min(1).max(20).describe("Catalog series keys to fetch."),
5810
+ from_year: z.number().int().min(2e3).max(2100).describe("First year to fetch."),
5811
+ to_year: z.number().int().min(2e3).max(2100).describe("Last year to fetch.")
5812
+ };
5813
+ function handleRefresh(getToken, baseUrl, args) {
5814
+ if (args.to_year < args.from_year)
5815
+ return Promise.resolve(validationError("`to_year` is before `from_year`"));
5816
+ return runTool(
5817
+ () => apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/indices/refresh", { body: args })
5818
+ );
5819
+ }
5820
+ var MANUAL_DESCRIPTION = [
5821
+ "Enter index values that have no free feed (EEX, THE levies, grid tariffs) for this workspace, each with its source.",
5822
+ "USE WHEN: a price needs an index talonic_price_baseline_refresh_indices cannot fetch.",
5823
+ "NOT FOR: public series with a feed (talonic_price_baseline_refresh_indices).",
5824
+ "",
5825
+ "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.",
5826
+ "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."
5827
+ ].join("\n");
5828
+ var manualInputSchema = {
5829
+ values: z.array(
5830
+ z.object({
5831
+ series: z.string().min(1),
5832
+ period: z.string().regex(INDEX_PERIOD_RE),
5833
+ value: z.number(),
5834
+ unit: z.string().optional(),
5835
+ base_year: z.number().int().optional(),
5836
+ quote: z.string().min(1).describe("The publisher's line that prints this value."),
5837
+ source_url: z.string().url().optional(),
5838
+ document_id: z.string().uuid().optional()
5839
+ })
5840
+ ).min(1).max(500).describe("Index values, each with its source.")
5841
+ };
5842
+ function handleManual(getToken, baseUrl, args) {
5843
+ const unsourced = args.values.findIndex((v) => !v.source_url && !v.document_id);
5844
+ if (unsourced >= 0) {
5845
+ return Promise.resolve(
5846
+ validationError(`values[${unsourced}] needs a \`source_url\` or \`document_id\``)
5847
+ );
5848
+ }
5849
+ return runTool(
5850
+ () => apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/indices/manual", { body: args })
5851
+ );
5852
+ }
5853
+ 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.";
5854
+ var REGISTER_DESCRIPTION2 = [
5855
+ "The contract register: one row per contract (all its documents as versions), with the expected invoice for a year and what is still open.",
5856
+ "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`.",
5857
+ "NOT FOR: one contract's open inputs in detail (talonic_price_baseline_contract); single model documents (talonic_price_baseline_models).",
5858
+ "",
5859
+ "ARGS: `year` (optional; default the last full calendar year).",
5860
+ "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."
5861
+ ].join("\n");
5862
+ var registerInputSchema2 = {
5863
+ year: z.number().int().min(2e3).max(2100).optional().describe("Calendar year the expected invoice is computed for.")
5864
+ };
5865
+ function handleRegister2(getToken, baseUrl, args) {
5866
+ return runTool(async () => ({
5867
+ data: await apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/register", {
5868
+ params: { year: args.year }
5869
+ })
5870
+ }));
5871
+ }
5872
+ var CONTRACT_DESCRIPTION3 = [
5873
+ "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.",
5874
+ "USE WHEN: finding what is missing for a contract before answering it, or checking the expected invoice after an answer.",
5875
+ "NOT FOR: the Excel file (talonic_price_baseline_workbook); all contracts at once (talonic_price_baseline_register).",
5876
+ "",
5877
+ "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.",
5878
+ "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[] }.",
5879
+ "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.",
5880
+ RULES
5881
+ ].join("\n");
5882
+ var contractInputSchema3 = {
5883
+ model_id: modelIdArg,
5884
+ year: z.number().int().min(2e3).max(2100).optional().describe("Calendar year to prepare."),
5885
+ comparison_id: z.string().uuid().optional().describe("Invoice check whose period and quantities to use."),
5886
+ from: fromArg.optional(),
5887
+ to: toArg.optional(),
5888
+ include_grid: z.boolean().optional().describe("Include every sheet's cell rows (large). Default: sheet names and row counts only.")
5889
+ };
5890
+ function handleContract3(getToken, baseUrl, args) {
5891
+ if (!!args.from !== !!args.to) {
5892
+ return Promise.resolve(validationError("give `from` and `to` together"));
5893
+ }
5894
+ const periods = [args.year !== void 0, !!args.comparison_id, !!args.from].filter(Boolean);
5895
+ if (periods.length > 1) {
5896
+ return Promise.resolve(
5897
+ validationError("choose one period: `year`, `comparison_id`, or `from`+`to`")
5898
+ );
5899
+ }
5900
+ if (args.from && args.to && args.from > args.to) {
5901
+ return Promise.resolve(validationError("`to` is before `from`"));
5902
+ }
5903
+ return runTool(async () => {
5904
+ const book = await apiJson(
5905
+ getToken,
5906
+ baseUrl,
5907
+ "GET",
5908
+ `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}/sheets`,
5909
+ {
5910
+ params: {
5911
+ year: args.year,
5912
+ comparison_id: args.comparison_id,
5913
+ from: args.from,
5914
+ to: args.to
5915
+ }
5916
+ }
5917
+ );
5918
+ if (args.include_grid || !Array.isArray(book?.sheets)) return book;
5919
+ return {
5920
+ ...book,
5921
+ sheets: book.sheets.map((s) => ({ name: s.name, rows: s.rows?.length ?? 0 }))
5922
+ };
5923
+ });
5924
+ }
5925
+ var ANSWER_DESCRIPTION = [
5926
+ "Answer an open input of a contract workbook: enter a contract value with its verbatim quote, or record where the value will come from.",
5927
+ "USE WHEN: talonic_price_baseline_contract lists an open input whose options include enter_contract_value, from_invoice or request.",
5928
+ "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).",
5929
+ "",
5930
+ "ARGS: `model_id` (the open input's own `model_id`: the version that states the value), `action`:",
5931
+ "- enter_contract_value: `variable` (the input's `variable`), `value`, `quote` (the contract's passage, copied verbatim, that prints the value).",
5932
+ "- choose_source: `key` (the input's `key`), `choice` (from_invoice | request; null clears), `note`.",
5933
+ "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.",
5934
+ RULES
5935
+ ].join("\n");
5936
+ var answerInputSchema = {
5937
+ model_id: modelIdArg,
5938
+ action: z.enum(["enter_contract_value", "choose_source"]),
5939
+ variable: z.string().min(1).max(64).optional().describe("Model variable name (enter_contract_value)."),
5940
+ value: z.number().optional().describe("The number the contract states (enter_contract_value)."),
5941
+ quote: z.string().min(1).max(2e3).optional().describe("Verbatim contract passage that prints the value (enter_contract_value)."),
5942
+ key: z.string().min(1).max(300).optional().describe("Open input key (choose_source)."),
5943
+ choice: z.enum(["from_invoice", "request"]).nullable().optional().describe("Where the value will come from; null clears the choice (choose_source)."),
5944
+ note: z.string().max(2e3).optional().describe("Why, or whom to ask (choose_source).")
5945
+ };
5946
+ function handleAnswer(getToken, baseUrl, args) {
5947
+ const base = `/v1/price-baseline/models/${encodeURIComponent(args.model_id)}`;
5948
+ if (args.action === "enter_contract_value") {
5949
+ if (!args.variable || args.value === void 0 || !args.quote?.trim()) {
5950
+ return Promise.resolve(
5951
+ validationError(
5952
+ "enter_contract_value needs `variable`, `value` and `quote` (the verbatim contract passage printing the value)"
5953
+ )
5954
+ );
5955
+ }
5956
+ return runTool(
5957
+ () => apiJson(getToken, baseUrl, "POST", `${base}/values`, {
5958
+ body: { variable: args.variable, value: args.value, quote: args.quote }
5959
+ })
5960
+ );
5961
+ }
5962
+ if (!args.key || args.choice === void 0) {
5963
+ return Promise.resolve(
5964
+ validationError("choose_source needs `key` and `choice` (from_invoice | request | null)")
5965
+ );
5966
+ }
5967
+ return runTool(
5968
+ () => apiJson(getToken, baseUrl, "POST", `${base}/decide`, {
5969
+ body: { key: args.key, choice: args.choice, note: args.note ?? null }
5970
+ })
5971
+ );
5972
+ }
5973
+ var ASSUMPTIONS_DESCRIPTION = [
5974
+ "List the active assumptions: stand-in values used where no real value exists yet.",
5975
+ "USE WHEN: reviewing what the numbers rest on, or finding an assumption's id to replace or withdraw it.",
5976
+ "NOT FOR: making or changing one (talonic_price_baseline_assume).",
5977
+ "",
5978
+ "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.",
5979
+ "RETURNS: data[] { id, contract_key (null = workspace), target_kind, target, period_from, period_to, rule, value, unit, params { series, factor }, note, created_by }."
5980
+ ].join("\n");
5981
+ var assumptionsInputSchema = {
5982
+ contract_key: z.string().min(1).max(64).optional().describe("Contract key (from the register) to list the assumptions applying to it.")
5983
+ };
5984
+ function handleAssumptions(getToken, baseUrl, args) {
5985
+ return runTool(
5986
+ () => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/assumptions", {
5987
+ params: { contract_key: args.contract_key }
5988
+ })
5989
+ );
5990
+ }
5991
+ var ASSUME_DESCRIPTION = [
5992
+ "Make, replace or withdraw an assumption: a marked stand-in for a value nobody has yet, for one contract or the whole workspace.",
5993
+ "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`.",
5994
+ "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.",
5995
+ "",
5996
+ "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).",
5997
+ "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.",
5998
+ "RETURNS: the stored assumption, or { id, active: false }.",
5999
+ RULES
6000
+ ].join("\n");
6001
+ var assumeInputSchema = {
6002
+ action: z.enum(["create", "replace", "withdraw"]),
6003
+ assumption_id: z.string().uuid().optional().describe("Assumption to replace or withdraw."),
6004
+ scope: z.enum(["contract", "workspace"]).optional().describe("One contract (needs `contract_key`) or every contract of the workspace."),
6005
+ contract_key: z.string().min(1).max(64).optional().describe("Contract key (scope: contract)."),
6006
+ target_kind: z.enum(["series", "variable", "quantity", "profile"]).optional(),
6007
+ target: z.string().min(1).max(120).optional().describe("Series key or variable name; `*` = every series."),
6008
+ rule: z.enum(["value", "carry_forward", "proxy"]).optional(),
6009
+ value: z.number().optional().describe("The assumed number (rule: value)."),
6010
+ unit: z.string().max(40).optional(),
6011
+ params: z.object({
6012
+ series: z.string().min(1).max(120).optional().describe("Source series (proxy, profile)."),
6013
+ factor: z.number().optional().describe("Multiplier on the source series (proxy).")
6014
+ }).optional(),
6015
+ period_from: z.string().regex(INDEX_PERIOD_RE).optional(),
6016
+ period_to: z.string().regex(INDEX_PERIOD_RE).optional(),
6017
+ note: z.string().min(1).max(2e3).optional().describe("Why this assumption is made (required).")
6018
+ };
6019
+ function assumptionProblem(a) {
6020
+ if (!a.scope) return "`scope` is required: contract (with `contract_key`) or workspace";
6021
+ if (a.scope === "contract" && !a.contract_key?.trim())
6022
+ return "scope contract needs `contract_key`";
6023
+ if (a.scope === "workspace" && a.contract_key) return "scope workspace takes no `contract_key`";
6024
+ if (!a.target_kind || !a.target?.trim() || !a.rule)
6025
+ return "`target_kind`, `target` and `rule` are required";
6026
+ if (!a.note?.trim()) return "`note` is required: say why the value is assumed";
6027
+ if (a.rule === "value" && a.target_kind !== "profile" && a.value === void 0)
6028
+ return "rule value needs `value`";
6029
+ if (a.rule === "carry_forward" && a.target_kind !== "series")
6030
+ return "only a series value can be carried forward";
6031
+ if ((a.rule === "proxy" || a.target_kind === "profile") && !a.params?.series)
6032
+ return "name the series it is derived from in `params.series`";
6033
+ if (a.target === "*" && (a.target_kind !== "series" || a.rule !== "carry_forward"))
6034
+ return "a default for every series (*) can only carry the last value forward";
6035
+ return null;
6036
+ }
6037
+ function handleAssume(getToken, baseUrl, args) {
6038
+ const path = (id) => `/v1/price-baseline/assumptions/${encodeURIComponent(id)}`;
6039
+ if (args.action !== "create" && !args.assumption_id) {
6040
+ return Promise.resolve(validationError(`${args.action} needs \`assumption_id\``));
6041
+ }
6042
+ if (args.action === "withdraw") {
6043
+ return runTool(() => apiJson(getToken, baseUrl, "DELETE", path(args.assumption_id)));
6044
+ }
6045
+ const problem = assumptionProblem(args);
6046
+ if (problem) return Promise.resolve(validationError(problem));
6047
+ const body = {
6048
+ contract_key: args.scope === "contract" ? args.contract_key?.trim() : null,
6049
+ target_kind: args.target_kind,
6050
+ target: args.target?.trim(),
6051
+ rule: args.rule,
6052
+ value: args.rule === "value" ? args.value ?? null : null,
6053
+ unit: args.unit ?? null,
6054
+ params: args.params,
6055
+ period_from: args.period_from ?? null,
6056
+ period_to: args.period_to ?? null,
6057
+ note: args.note?.trim()
6058
+ };
6059
+ return args.action === "create" ? runTool(() => apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/assumptions", { body })) : runTool(() => apiJson(getToken, baseUrl, "PUT", path(args.assumption_id), { body }));
6060
+ }
6061
+ var SYNC_DESCRIPTION = [
6062
+ "Sync external price data now (BEHG, Bundesbank, Destatis, EEX via Energy-Charts, DWD degree days), or change how often a series syncs.",
6063
+ "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.",
6064
+ "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).",
6065
+ "",
6066
+ "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).",
6067
+ "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."
6068
+ ].join("\n");
6069
+ var syncInputSchema = {
6070
+ keys: z.array(z.string().min(1)).max(50).optional().describe("Series keys to fetch now."),
6071
+ key: z.string().min(1).max(120).optional().describe("Series whose schedule to change."),
6072
+ sync_hours: z.number().int().min(1).max(2160).optional().describe("Sync interval in hours."),
6073
+ active: z.boolean().optional().describe("false pauses syncing.")
6074
+ };
6075
+ function handleSync(getToken, baseUrl, args) {
6076
+ const schedule = args.key !== void 0 || args.sync_hours !== void 0 || args.active !== void 0;
6077
+ if (schedule) {
6078
+ if (args.keys?.length) {
6079
+ return Promise.resolve(
6080
+ validationError("either sync (`keys`) or change a schedule (`key`), not both")
6081
+ );
6082
+ }
6083
+ if (!args.key || args.sync_hours === void 0 && args.active === void 0) {
6084
+ return Promise.resolve(
6085
+ validationError("a schedule change needs `key` and `sync_hours` or `active`")
6086
+ );
6087
+ }
6088
+ return runTool(
6089
+ () => apiJson(getToken, baseUrl, "PUT", "/v1/price-baseline/data/series", {
6090
+ body: { key: args.key, sync_hours: args.sync_hours, active: args.active }
6091
+ })
6092
+ );
6093
+ }
6094
+ return runTool(async () => ({
6095
+ data: await apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/data/series/sync", {
6096
+ body: args.keys?.length ? { keys: args.keys } : {}
6097
+ })
6098
+ }));
6099
+ }
6100
+ var IMPORTS_DESCRIPTION = [
6101
+ "Contract documents in data capture that have no price model yet, grouped by contract number, or the state of the import queue.",
6102
+ "USE WHEN: bringing a workspace's contracts into Price Baseline: pick candidates, queue them with talonic_price_baseline_import, then poll `view: status`.",
6103
+ "NOT FOR: documents that already have a model (talonic_price_baseline_register); invoices (talonic_price_baseline_documents).",
6104
+ "",
6105
+ "ARGS: `view` (candidates, default | status), `query` (filename contains; candidates only).",
6106
+ "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 } }."
6107
+ ].join("\n");
6108
+ var importsInputSchema = {
6109
+ view: z.enum(["candidates", "status"]).optional(),
6110
+ query: z.string().optional().describe("Filename contains match (candidates).")
6111
+ };
6112
+ function handleImports(getToken, baseUrl, args) {
6113
+ if (args.view === "status") {
6114
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/import/status"));
6115
+ }
6116
+ return runTool(
6117
+ () => apiJson(getToken, baseUrl, "GET", "/v1/price-baseline/import/candidates", {
6118
+ params: { q: args.query }
6119
+ })
6120
+ );
6121
+ }
6122
+ var IMPORT_DESCRIPTION2 = [
6123
+ "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.",
6124
+ "USE WHEN: importing several contracts at once from talonic_price_baseline_imports candidates, or retrying failed imports (a failed document is queued again).",
6125
+ "NOT FOR: one contract you want to read now and inspect (talonic_price_baseline_extract).",
6126
+ "",
6127
+ "ARGS: `document_ids` (1\u2013500 document UUIDs).",
6128
+ "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."
6129
+ ].join("\n");
6130
+ var importInputSchema2 = {
6131
+ document_ids: z.array(z.string().uuid()).min(1).max(500).describe("Contract document UUIDs (from talonic_price_baseline_imports).")
6132
+ };
6133
+ function handleImport2(getToken, baseUrl, args) {
6134
+ return runTool(
6135
+ () => apiJson(getToken, baseUrl, "POST", "/v1/price-baseline/import", {
6136
+ body: { document_ids: [...new Set(args.document_ids)] }
6137
+ })
6138
+ );
6139
+ }
6140
+ function registerPriceBaselineTools(server, getToken, baseUrl) {
6141
+ const write7 = (idempotent) => ({
6142
+ readOnlyHint: false,
6143
+ destructiveHint: false,
6144
+ idempotentHint: idempotent,
6145
+ openWorldHint: false
6146
+ });
6147
+ server.registerTool(
6148
+ "talonic_price_baseline_documents",
6149
+ {
6150
+ title: "Find contracts and invoices",
6151
+ description: DOCUMENTS_DESCRIPTION,
6152
+ inputSchema: documentsInputSchema,
6153
+ annotations: readOnly7
6154
+ },
6155
+ async (args) => handleDocuments(getToken, baseUrl, args)
6156
+ );
6157
+ server.registerTool(
6158
+ "talonic_price_baseline_extract",
6159
+ {
6160
+ title: "Build or enrich a price model from a contract",
6161
+ description: EXTRACT_DESCRIPTION,
6162
+ inputSchema: extractInputSchema,
6163
+ annotations: write7(false)
6164
+ },
6165
+ async (args) => handleExtract2(getToken, baseUrl, args)
6166
+ );
6167
+ server.registerTool(
6168
+ "talonic_price_baseline_models",
6169
+ {
6170
+ title: "List or read price models",
6171
+ description: MODELS_DESCRIPTION,
6172
+ inputSchema: modelsInputSchema,
6173
+ annotations: readOnly7
6174
+ },
6175
+ async (args) => handleModels(getToken, baseUrl, args)
6176
+ );
6177
+ server.registerTool(
6178
+ "talonic_price_baseline_update_model",
6179
+ {
6180
+ title: "Edit or confirm a price model",
6181
+ description: UPDATE_DESCRIPTION,
6182
+ inputSchema: updateInputSchema,
6183
+ annotations: write7(true)
6184
+ },
6185
+ async (args) => handleUpdate(getToken, baseUrl, args)
6186
+ );
6187
+ server.registerTool(
6188
+ "talonic_price_baseline_prices",
6189
+ {
6190
+ title: "Recompute contract prices",
6191
+ description: PRICES_DESCRIPTION,
6192
+ inputSchema: pricesInputSchema,
6193
+ annotations: readOnly7
6194
+ },
6195
+ async (args) => handlePrices(getToken, baseUrl, args)
6196
+ );
6197
+ server.registerTool(
6198
+ "talonic_price_baseline_workbook",
6199
+ {
6200
+ title: "Download the price baseline workbook",
6201
+ description: WORKBOOK_DESCRIPTION,
6202
+ inputSchema: workbookInputSchema,
6203
+ annotations: readOnly7
6204
+ },
6205
+ async (args) => handleWorkbook(getToken, baseUrl, args)
6206
+ );
6207
+ server.registerTool(
6208
+ "talonic_price_baseline_compare",
6209
+ {
6210
+ title: "Check an invoice against the contract",
6211
+ description: COMPARE_DESCRIPTION,
6212
+ inputSchema: compareInputSchema,
6213
+ annotations: write7(false)
6214
+ },
6215
+ async (args) => handleCompare(getToken, baseUrl, args)
6216
+ );
6217
+ server.registerTool(
6218
+ "talonic_price_baseline_proof_invoice",
6219
+ {
6220
+ title: "Audit-proof invoice",
6221
+ description: PROOF_INVOICE_DESCRIPTION,
6222
+ inputSchema: proofInvoiceInputSchema,
6223
+ annotations: readOnly7
6224
+ },
6225
+ async (args) => handleProofInvoice(getToken, baseUrl, args)
6226
+ );
6227
+ server.registerTool(
6228
+ "talonic_price_baseline_indices",
6229
+ {
6230
+ title: "Index catalog and values",
6231
+ description: INDICES_DESCRIPTION,
6232
+ inputSchema: indicesInputSchema,
6233
+ annotations: readOnly7
6234
+ },
6235
+ async (args) => handleIndices(getToken, baseUrl, args)
6236
+ );
6237
+ server.registerTool(
6238
+ "talonic_price_baseline_refresh_indices",
6239
+ {
6240
+ title: "Fetch public index values",
6241
+ description: REFRESH_DESCRIPTION,
6242
+ inputSchema: refreshInputSchema,
6243
+ annotations: { ...write7(true), openWorldHint: true }
6244
+ },
6245
+ async (args) => handleRefresh(getToken, baseUrl, args)
6246
+ );
6247
+ server.registerTool(
6248
+ "talonic_price_baseline_add_index_values",
6249
+ {
6250
+ title: "Enter sourced index values",
6251
+ description: MANUAL_DESCRIPTION,
6252
+ inputSchema: manualInputSchema,
6253
+ annotations: write7(true)
6254
+ },
6255
+ async (args) => handleManual(getToken, baseUrl, args)
6256
+ );
6257
+ server.registerTool(
6258
+ "talonic_price_baseline_register",
6259
+ {
6260
+ title: "Contract register and expected invoices",
6261
+ description: REGISTER_DESCRIPTION2,
6262
+ inputSchema: registerInputSchema2,
6263
+ annotations: readOnly7
6264
+ },
6265
+ async (args) => handleRegister2(getToken, baseUrl, args)
6266
+ );
6267
+ server.registerTool(
6268
+ "talonic_price_baseline_contract",
6269
+ {
6270
+ title: "Contract workbook and open inputs",
6271
+ description: CONTRACT_DESCRIPTION3,
6272
+ inputSchema: contractInputSchema3,
6273
+ annotations: readOnly7
6274
+ },
6275
+ async (args) => handleContract3(getToken, baseUrl, args)
6276
+ );
6277
+ server.registerTool(
6278
+ "talonic_price_baseline_answer",
6279
+ {
6280
+ title: "Answer an open contract input",
6281
+ description: ANSWER_DESCRIPTION,
6282
+ inputSchema: answerInputSchema,
6283
+ annotations: write7(true)
6284
+ },
6285
+ async (args) => handleAnswer(getToken, baseUrl, args)
6286
+ );
6287
+ server.registerTool(
6288
+ "talonic_price_baseline_assumptions",
6289
+ {
6290
+ title: "List assumptions",
6291
+ description: ASSUMPTIONS_DESCRIPTION,
6292
+ inputSchema: assumptionsInputSchema,
6293
+ annotations: readOnly7
6294
+ },
6295
+ async (args) => handleAssumptions(getToken, baseUrl, args)
6296
+ );
6297
+ server.registerTool(
6298
+ "talonic_price_baseline_assume",
6299
+ {
6300
+ title: "Make, replace or withdraw an assumption",
6301
+ description: ASSUME_DESCRIPTION,
6302
+ inputSchema: assumeInputSchema,
6303
+ annotations: { ...write7(false), destructiveHint: true }
6304
+ },
6305
+ async (args) => handleAssume(getToken, baseUrl, args)
6306
+ );
6307
+ server.registerTool(
6308
+ "talonic_price_baseline_sync_series",
6309
+ {
6310
+ title: "Sync external price data",
6311
+ description: SYNC_DESCRIPTION,
6312
+ inputSchema: syncInputSchema,
6313
+ annotations: { ...write7(true), openWorldHint: true }
6314
+ },
6315
+ async (args) => handleSync(getToken, baseUrl, args)
6316
+ );
6317
+ server.registerTool(
6318
+ "talonic_price_baseline_imports",
6319
+ {
6320
+ title: "Import candidates and status",
6321
+ description: IMPORTS_DESCRIPTION,
6322
+ inputSchema: importsInputSchema,
6323
+ annotations: readOnly7
6324
+ },
6325
+ async (args) => handleImports(getToken, baseUrl, args)
6326
+ );
6327
+ server.registerTool(
6328
+ "talonic_price_baseline_import",
6329
+ {
6330
+ title: "Import contracts from data capture",
6331
+ description: IMPORT_DESCRIPTION2,
6332
+ inputSchema: importInputSchema2,
6333
+ annotations: write7(true)
6334
+ },
6335
+ async (args) => handleImport2(getToken, baseUrl, args)
6336
+ );
6337
+ }
5404
6338
  var DEFAULT_BASE3 = "https://api.talonic.com";
5405
6339
  var TASK_STATUSES = ["available", "claimed", "submitted", "timed_out", "cancelled"];
5406
6340
  var taskId = z.string().uuid().describe("Agent task UUID.");
@@ -6936,7 +7870,7 @@ function registerAskTools(server, getToken, baseUrl) {
6936
7870
 
6937
7871
  // package.json
6938
7872
  var package_default = {
6939
- version: "0.1.91"};
7873
+ version: "0.1.92"};
6940
7874
 
6941
7875
  // src/version.ts
6942
7876
  var VERSION = package_default.version;
@@ -7105,6 +8039,9 @@ function createServer(options) {
7105
8039
  if (options.includeSubmissionsTools) {
7106
8040
  registerSubmissionsTools(server, rawToken, baseUrl);
7107
8041
  }
8042
+ if (options.includePriceBaselineTools) {
8043
+ registerPriceBaselineTools(server, rawToken, baseUrl);
8044
+ }
7108
8045
  registerSchemasResource(server, getTalonic);
7109
8046
  registerWebhooksResource(server, rawToken, baseUrl);
7110
8047
  registerWidgets(server);