@talonic/mcp 0.1.88 → 0.1.89

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
@@ -3708,7 +3708,7 @@ var templateIdArg = z.string().uuid().describe("Template id (from talonic_doc_ge
3708
3708
  var productIdArg = z.string().uuid().describe("Data product id (from talonic_doc_gen_products).");
3709
3709
  var jobIdArg = z.string().uuid().describe("Batch id (from talonic_doc_gen_jobs or _generate).");
3710
3710
  var valuesArg = z.record(z.string(), z.string()).describe(
3711
- "Values by field key (or case key). A field whose source type is `case` (entered per document) takes the value as entered; a value for any other field is an edit over the fill, recorded in the document history."
3711
+ 'Values by field key (or case key). A field whose source type is `case` (entered per document) takes the value as entered; a passage decided per document (condition `ask`) takes "yes" or "no" (include or leave out; it stays missing until decided); a value for any other field is an edit over the fill, recorded in the document history.'
3712
3712
  );
3713
3713
  var ENTERED_RULE = "Fields whose source type is `case` are entered per document: the data does not hold them (e.g. the new owner), so pass them in `values` by field key (or case key). A value for any other field overrides the fill and is recorded as an edit in the document history.";
3714
3714
  function waitSeconds(requested, max) {
@@ -3783,10 +3783,11 @@ var UPDATE_TEMPLATE_DESCRIPTION = [
3783
3783
  "Change a template's metadata (name, group, kind, companion template, version) and its fields by key: a field's label, source, confirmed flag or reason. Fields not named stay as they are; an unknown key is refused. Run with dry_run first to see the sheet as it would be.",
3784
3784
  "USE WHEN: fixing a field the proposal got wrong (e.g. pointing it at another column or making it entered per document with source { type: 'case', caseKey }), or pairing a letter with its agreement.",
3785
3785
  "Setting `confirmed: true` is a person's decision: only do it when the user asked (see talonic_doc_gen_confirm_fields).",
3786
+ "Red passages (fields with `spot.original`, red text in the Word file): set a `variant` for grammar that depends on the party, a `condition` for text printed only sometimes, any value source, or `fixed` to keep the words (in black). `rescan: true` first adds the red passages of a template whose sheet predates them.",
3786
3787
  "NOT FOR: confirming many fields at once (talonic_doc_gen_confirm_fields).",
3787
3788
  "",
3788
- "ARGS: `template_id`; optional `name`, `group`, `kind` letter|agreement, `pair_template_id`, `version` (null clears group/kind/pair/version); `fields[] { key, label?, source?, confirmed?, reason? }`; `dry_run`.",
3789
- "RETURNS: { dry_run, template } with the field sheet."
3789
+ "ARGS: `template_id`; optional `name`, `group`, `kind` letter|agreement, `pair_template_id`, `version` (null clears group/kind/pair/version); `fields[] { key, label?, source?, confirmed?, reason? }`; `rescan` (add the fields the file has and the sheet lacks; alone or before the changes); `dry_run`.",
3790
+ "RETURNS: { dry_run, template } with the field sheet; with `rescan` alone { template, added[] } (keys added)."
3790
3791
  ].join("\n");
3791
3792
  var updateTemplateInputSchema = {
3792
3793
  template_id: templateIdArg,
@@ -3800,29 +3801,39 @@ var updateTemplateInputSchema = {
3800
3801
  key: z.string().min(1).max(200).describe("Field key from the field sheet."),
3801
3802
  label: z.string().max(120).optional(),
3802
3803
  source: z.record(z.string(), z.unknown()).optional().describe(
3803
- "Field source as the sheet stores it, e.g. { type: 'product', field }, { type: 'reference', column }, { type: 'case', caseKey }, { type: 'user', profile }, { type: 'rule', rule }, { type: 'today' }."
3804
+ "Field source as the sheet stores it, e.g. { type: 'product', field }, { type: 'reference', column }, { type: 'case', caseKey }, { type: 'user', profile }, { type: 'rule', rule }, { type: 'today' }, { type: 'party', role: addressee|owner_addressee|effective_partner|partner|manager|tenant|previous_owner|new_owner, attribute: name|salutation|greeting|street|postcode_town|address|address_block|email|kind|channel }, { type: 'variant', by: <party role>, map: { herr, frau, eheleute, person, company, association }, fallback } (grammar such as 'der/von'), { type: 'condition', when: { kind: 'party', role, present } | { kind: 'document', pattern, present } | { kind: 'field', field, present?, equals? } | { kind: 'ask' }, text? } (printed only when the condition holds; `ask`: the person generating decides per document, e.g. case variants), { type: 'fixed', text }."
3804
3805
  ),
3805
3806
  confirmed: z.boolean().optional().describe("Only when the user asked to confirm."),
3806
3807
  reason: z.string().max(400).nullable().optional()
3807
3808
  })
3808
3809
  ).max(500).optional().describe("Field changes by key."),
3810
+ rescan: z.boolean().optional().describe(
3811
+ "Read the Word file again and add the fields the sheet lacks (red passages); existing fields stay."
3812
+ ),
3809
3813
  dry_run: z.boolean().optional().describe("Return the sheet as it would be; nothing is saved.")
3810
3814
  };
3811
3815
  function handleUpdateTemplate(getToken, baseUrl, args) {
3812
- const { template_id, dry_run, ...changes } = args;
3816
+ const { template_id, dry_run, rescan, ...changes } = args;
3813
3817
  const body = Object.fromEntries(Object.entries(changes).filter(([, v]) => v !== void 0));
3814
- if (Object.keys(body).length === 0) {
3818
+ if (Object.keys(body).length === 0 && !rescan) {
3815
3819
  return Promise.resolve(
3816
3820
  validationError(
3817
- "name nothing to change: pass name, group, kind, pair_template_id, version or fields."
3821
+ "name nothing to change: pass name, group, kind, pair_template_id, version, fields or rescan."
3818
3822
  )
3819
3823
  );
3820
3824
  }
3821
- return runTool(
3822
- () => apiJson(getToken, baseUrl, "PATCH", `/v1/doc-gen/templates/${template_id}`, {
3825
+ if (rescan && dry_run) {
3826
+ return Promise.resolve(
3827
+ validationError("rescan saves the added fields; it cannot run as a dry run.")
3828
+ );
3829
+ }
3830
+ return runTool(async () => {
3831
+ const scanned = rescan ? await apiJson(getToken, baseUrl, "POST", `/v1/doc-gen/templates/${template_id}/rescan`) : null;
3832
+ if (Object.keys(body).length === 0) return scanned;
3833
+ return apiJson(getToken, baseUrl, "PATCH", `/v1/doc-gen/templates/${template_id}`, {
3823
3834
  body: { ...body, dry_run: dry_run ?? false }
3824
- })
3825
- );
3835
+ });
3836
+ });
3826
3837
  }
3827
3838
  var CONFIRM_DESCRIPTION = [
3828
3839
  "Confirm fields of a template's field sheet: the named keys, or every unconfirmed field (with include_entered false, leaving the fields entered per document unconfirmed). Confirming says a person checked the field's source; it is the user's decision, so only call this when the user asked to confirm. Run with dry_run first to list what would be confirmed.",
@@ -4383,6 +4394,565 @@ function registerDocGenTools(server, getToken, baseUrl, opts = {}) {
4383
4394
  );
4384
4395
  }
4385
4396
  }
4397
+ var readOnly4 = {
4398
+ readOnlyHint: true,
4399
+ destructiveHint: false,
4400
+ idempotentHint: true,
4401
+ openWorldHint: false
4402
+ };
4403
+ var write4 = (idempotent, destructive = false) => ({
4404
+ readOnlyHint: false,
4405
+ destructiveHint: destructive,
4406
+ idempotentHint: idempotent,
4407
+ openWorldHint: false
4408
+ });
4409
+ var PARTIES_POLL_INTERVAL_MS = 5e3;
4410
+ var READ_MAX_WAIT_S = 600;
4411
+ var ROLES2 = [
4412
+ "partner",
4413
+ "manager",
4414
+ "tenant",
4415
+ "previous_owner",
4416
+ "new_owner",
4417
+ "contact",
4418
+ "invoice_recipient"
4419
+ ];
4420
+ var KINDS = ["person", "company", "owners_association", "unknown"];
4421
+ var SALUTATIONS = ["herr", "frau", "eheleute", "firma", "weg"];
4422
+ var ROLE_STATES = ["suggested", "confirmed", "rejected"];
4423
+ var ISSUE_CODES = [
4424
+ "no_partner",
4425
+ "several_partners",
4426
+ "reference_disagrees",
4427
+ "kind_unknown",
4428
+ "address_missing",
4429
+ "manager_without_party",
4430
+ "tenant_without_period",
4431
+ "owner_change_open",
4432
+ "cost_unit_disagrees",
4433
+ "cost_unit_missing",
4434
+ "not_read",
4435
+ "read_failed",
4436
+ "possible_duplicate"
4437
+ ];
4438
+ var ROLES_EXPLAINED = "Roles: partner (the contract partner), manager (Verwalter: acts for a company or an owners' association and is written to on its behalf; represents_id names the role it acts for), tenant (with enters_contract: true the tenant is the temporary partner for the lease period valid_from..valid_to), previous_owner / new_owner (an owner change: the new owner holds from the transfer date valid_from), contact, invoice_recipient.";
4439
+ var COMPUTED_RULE = "The effective partner (the tenant entering the contract during its lease, else the partner) and the addressee (the effective partner's Verwalter when it has one, else the effective partner) are computed by the platform from the roles in force on the day; never set them yourself, fix the roles.";
4440
+ var DECISION_RULE = "A read only makes suggestions and never overwrites a person's decision (a confirmed role stays, a rejected one never comes back). Confirming, rejecting and merging are a person's decisions: only do them when the user asked.";
4441
+ var dateArg = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "a date YYYY-MM-DD").describe("ISO date YYYY-MM-DD.");
4442
+ var contractIdArg2 = z.string().uuid().describe("Contract id (from talonic_parties_contracts or talonic_parties_issues).");
4443
+ var partyIdArg = z.string().uuid().describe("Party id (from talonic_parties_search, _contract or _issues).");
4444
+ function waitSeconds2(requested, max) {
4445
+ const n = Number.isFinite(requested) ? requested : 0;
4446
+ return Math.max(0, Math.min(max, Math.floor(n)));
4447
+ }
4448
+ function defined(obj) {
4449
+ return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
4450
+ }
4451
+ var STATUS_DESCRIPTION3 = [
4452
+ "Contract Party Management at a glance: how many contracts, how many have confirmed parties, only suggestions, or no partner; active parties; open suggestions; and the parties-read queue.",
4453
+ "USE WHEN: starting any parties work, or to report where things stand. The loop: talonic_parties_status \u2192 talonic_parties_read (dry_run first, then with wait_seconds) \u2192 talonic_parties_issues \u2192 talonic_parties_contract per flagged contract \u2192 talonic_parties_set_role / talonic_parties_confirm \u2192 talonic_parties_merge duplicates \u2192 talonic_parties_issues again.",
4454
+ "NOT FOR: what to fix (talonic_parties_issues); one contract (talonic_parties_contract).",
4455
+ "",
4456
+ "ARGS: none.",
4457
+ "RETURNS: { contracts, contracts_confirmed, contracts_suggested, contracts_without_partner, parties, suggestions, reads { counts { pending, running, done, failed }, unread, failed } }."
4458
+ ].join("\n");
4459
+ function handleStatus2(getToken, baseUrl) {
4460
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/parties/status"));
4461
+ }
4462
+ var ISSUES_DESCRIPTION4 = [
4463
+ "The parties worklist: per contract what looks wrong today (no partner, several partners, the reference table names another partner, person-or-company unknown, no postal address, a Verwalter for a party no longer on the contract, a tenant entering the contract without a lease period, an owner change without a transfer date, cost unit disagreeing or missing, not read, read failed), plus parties that look like duplicates (same name, and postcode when both have one).",
4464
+ "USE WHEN: after talonic_parties_read, deciding what to fix; open each flagged contract with talonic_parties_contract. Duplicates are merge candidates: never merged on their own (talonic_parties_merge, only when the user asked).",
4465
+ "NOT FOR: the headline counts (talonic_parties_status); all contracts (talonic_parties_contracts).",
4466
+ "",
4467
+ `ARGS: \`code\` (only this issue; one of ${ISSUE_CODES.join(", ")}).`,
4468
+ "RETURNS: { contracts[] { contract_id, contract_key, title, issues[] { code, detail, role_ids[], party_ids[] } }, duplicates[] { name_key, party_ids[], names[] } }."
4469
+ ].join("\n");
4470
+ var issuesInputSchema2 = {
4471
+ code: z.enum(ISSUE_CODES).optional().describe("Only this issue code.")
4472
+ };
4473
+ function handleIssues4(getToken, baseUrl, args) {
4474
+ return runTool(
4475
+ () => apiJson(getToken, baseUrl, "GET", "/v1/parties/issues", { params: { code: args.code } })
4476
+ );
4477
+ }
4478
+ var CONTRACTS_DESCRIPTION = [
4479
+ "List the workspace's contracts with their parties today: effective partner, addressee and Verwalter by name, the parties' state (confirmed: every role counted is confirmed; suggested: any is a suggestion; none: no partner), open suggestions and the read state.",
4480
+ "USE WHEN: getting an overview, finding a contract by key, title or party name, or listing contracts still on suggestions (state: suggested) or without a partner (state: none).",
4481
+ "NOT FOR: one contract's roles and evidence (talonic_parties_contract); what needs fixing (talonic_parties_issues).",
4482
+ "",
4483
+ "ARGS: `query` (contract key, title, counterparty, partner or Verwalter contains), `state` confirmed|suggested|none, `limit` (1-5000, default 500).",
4484
+ "RETURNS: { total, data[] { id, contract_key, title, counterparty, status, partner, addressee, manager, state, suggestions, read } }."
4485
+ ].join("\n");
4486
+ var contractsInputSchema = {
4487
+ query: z.string().optional().describe("Key, title, counterparty, partner or Verwalter contains."),
4488
+ state: z.enum(["confirmed", "suggested", "none"]).optional().describe("Only contracts whose parties are in this state."),
4489
+ limit: z.number().int().min(1).max(5e3).optional().describe("At most this many (default 500).")
4490
+ };
4491
+ function handleContracts(getToken, baseUrl, args) {
4492
+ return runTool(
4493
+ () => apiJson(getToken, baseUrl, "GET", "/v1/parties/contracts", {
4494
+ params: { q: args.query, state: args.state, limit: args.limit }
4495
+ })
4496
+ );
4497
+ }
4498
+ var CONTRACT_DESCRIPTION2 = [
4499
+ "One contract's parties on a day: the computed view (partner, manager, tenant, previous and new owner, effective partner, addressee with its postal address lines, contacts, state), every role row with its party, state (suggested|confirmed|rejected), confidence and evidence (document quotes, reference table rows, a person's word), the issues, the cost unit (documents vs. contract register) and the read state.",
4500
+ "USE WHEN: checking or fixing a flagged contract; you need role ids (roles[].id) for talonic_parties_set_role, or to answer who the partner is and where a letter goes.",
4501
+ ROLES_EXPLAINED,
4502
+ COMPUTED_RULE,
4503
+ "NOT FOR: the list of contracts (talonic_parties_contracts); one party across contracts (talonic_parties_party).",
4504
+ "",
4505
+ "ARGS: `contract_id`, `on` (YYYY-MM-DD; default today: the roles in force on that day).",
4506
+ "RETURNS: { contract { id, contract_key, title, counterparty, status }, on, view { partner, manager, tenant, previous_owner, new_owner, effective_partner, addressee { ...party, role_id, role, state, valid_from, valid_to, address_lines[] }, contacts[], state }, roles[] { id, party_id, role, represents_id, valid_from, valid_to, enters_contract, state, confidence, evidence[], origin, decided_by, decided_at, note, party }, issues[], cost_unit { documents, quote, register[] }, reference_names[], read { status, read_at, error, notes, read_with } | null }."
4507
+ ].join("\n");
4508
+ var contractInputSchema2 = {
4509
+ contract_id: contractIdArg2,
4510
+ on: dateArg.optional().describe("The day to read the parties for (YYYY-MM-DD; default today).")
4511
+ };
4512
+ function handleContract2(getToken, baseUrl, args) {
4513
+ return runTool(
4514
+ () => apiJson(getToken, baseUrl, "GET", `/v1/parties/contracts/${args.contract_id}`, {
4515
+ params: { on: args.on }
4516
+ })
4517
+ );
4518
+ }
4519
+ var SEARCH_DESCRIPTION = [
4520
+ "Search the party register (people, companies, owners' associations): name, street, postcode, town, email or an external reference contains the query; each with how many contracts it holds a role on.",
4521
+ "USE WHEN: finding a party to add to a contract (its id for talonic_parties_set_role), checking whether a party already exists before creating one, or finding duplicates by name.",
4522
+ "NOT FOR: one party with its roles (talonic_parties_party); a contract's parties (talonic_parties_contract).",
4523
+ "",
4524
+ "ARGS: `query`, `kind` person|company|owners_association|unknown, `limit` (1-1000, default 200).",
4525
+ "RETURNS: { total, data[] { id, kind, display_name, salutation, title, first_name, last_name, company_name, legal_form, street, postcode, town, country, email, phone, preferred_channel, external_refs, status, contracts } }."
4526
+ ].join("\n");
4527
+ var searchInputSchema = {
4528
+ query: z.string().optional().describe("Name, address, email or external reference contains."),
4529
+ kind: z.enum(KINDS).optional().describe("Only parties of this kind."),
4530
+ limit: z.number().int().min(1).max(1e3).optional().describe("At most this many (default 200).")
4531
+ };
4532
+ function handleSearch2(getToken, baseUrl, args) {
4533
+ return runTool(
4534
+ () => apiJson(getToken, baseUrl, "GET", "/v1/parties", {
4535
+ params: { q: args.query, kind: args.kind, limit: args.limit }
4536
+ })
4537
+ );
4538
+ }
4539
+ var PARTY_FIELD_KEYS = [
4540
+ "kind",
4541
+ "display_name",
4542
+ "salutation",
4543
+ "title",
4544
+ "first_name",
4545
+ "last_name",
4546
+ "company_name",
4547
+ "legal_form",
4548
+ "street",
4549
+ "postcode",
4550
+ "town",
4551
+ "country",
4552
+ "email",
4553
+ "phone",
4554
+ "preferred_channel",
4555
+ "external_refs"
4556
+ ];
4557
+ var PARTY_DESCRIPTION = [
4558
+ "Read, change or create one party. With `party_id` alone: the party with its roles on every contract, its contacts (members), the companies it is a contact of and the documents it appears in (with quotes). With `party_id` and fields: changes those fields (the rest stay). Without `party_id`: creates a party; `display_name` is required (kind and salutation are inferred from it when not given).",
4559
+ "USE WHEN: checking a party; fixing its name, kind (person or company decides a letter's wording), salutation or postal address (issues kind_unknown, address_missing); creating a party the documents miss before adding it to a contract with talonic_parties_set_role. Search first (talonic_parties_search) so you do not create a duplicate.",
4560
+ "NOT FOR: its role on a contract (talonic_parties_set_role); combining duplicates (talonic_parties_merge).",
4561
+ "",
4562
+ "ARGS: `party_id` (omit to create); fields `kind` person|company|owners_association|unknown, `display_name`, `salutation` herr|frau|eheleute|firma|weg, `title`, `first_name`, `last_name`, `company_name`, `legal_form`, `street`, `postcode`, `town`, `country`, `email`, `phone`, `preferred_channel` post|email, `external_refs` { name: value } (null clears a text field).",
4563
+ "RETURNS: read { party, merged_into, roles[] { ...role, contract }, members[] { id, function, party }, member_of[], documents[] { document_id, filename, quotes[] } }; change or create: the party."
4564
+ ].join("\n");
4565
+ var nullableText = (max) => z.string().max(max).nullable().optional();
4566
+ var partyInputSchema = {
4567
+ party_id: partyIdArg.optional().describe("The party to read or change; omit to create one."),
4568
+ kind: z.enum(KINDS).optional().describe("Person, company, owners' association or unknown."),
4569
+ display_name: z.string().min(1).max(300).optional().describe("Name as printed; required to create."),
4570
+ salutation: z.enum(SALUTATIONS).nullable().optional().describe("Salutation; null clears it."),
4571
+ title: nullableText(60).describe("Academic title, e.g. 'Dr.'."),
4572
+ first_name: nullableText(120),
4573
+ last_name: nullableText(120),
4574
+ company_name: nullableText(300),
4575
+ legal_form: nullableText(60).describe("e.g. GmbH, AG, KG."),
4576
+ street: nullableText(200).describe("Street and house number."),
4577
+ postcode: nullableText(12),
4578
+ town: nullableText(120),
4579
+ country: nullableText(60),
4580
+ email: z.string().email().nullable().optional(),
4581
+ phone: nullableText(60),
4582
+ preferred_channel: z.enum(["post", "email"]).nullable().optional(),
4583
+ external_refs: z.record(z.string(), z.string()).optional().describe("References in other systems by name, e.g. { debitor: '10042' }.")
4584
+ };
4585
+ function handleParty(getToken, baseUrl, args) {
4586
+ const fields = defined(Object.fromEntries(PARTY_FIELD_KEYS.map((k) => [k, args[k]])));
4587
+ const changing = Object.keys(fields).length > 0;
4588
+ if (args.party_id) {
4589
+ const path = `/v1/parties/${args.party_id}`;
4590
+ return runTool(
4591
+ () => changing ? apiJson(getToken, baseUrl, "PATCH", path, { body: fields }) : apiJson(getToken, baseUrl, "GET", path)
4592
+ );
4593
+ }
4594
+ if (typeof args.display_name !== "string" || !args.display_name.trim()) {
4595
+ return Promise.resolve(
4596
+ validationError("pass party_id to read or change a party, or display_name to create one.")
4597
+ );
4598
+ }
4599
+ return runTool(() => apiJson(getToken, baseUrl, "POST", "/v1/parties", { body: fields }));
4600
+ }
4601
+ var SET_ROLE_DESCRIPTION = [
4602
+ "Add a role to a contract, or change one role row. With `contract_id`, `party_id` and `role`: adds the party in that role (confirmed unless `state` says suggested; a party already holding that role on the contract has that row updated). With `role_id`: changes that row: confirm or reject it (`state`), move it to another role or party, set the period, the Verwalter link or enters_contract. Any change by a person is a decision: an edited suggestion becomes confirmed unless `state` says otherwise.",
4603
+ "USE WHEN: fixing a contract's parties after reading talonic_parties_contract: a partner missing (no_partner), two partners at once (reject the wrong one, or give the old one valid_to), a Verwalter for the right party (represents_id), a tenant entering the contract (enters_contract with valid_from / valid_to), an owner change (previous_owner, new_owner with valid_from = transfer date).",
4604
+ ROLES_EXPLAINED,
4605
+ COMPUTED_RULE,
4606
+ DECISION_RULE,
4607
+ "NOT FOR: confirming many suggestions at once (talonic_parties_confirm); the party's own details (talonic_parties_party).",
4608
+ "",
4609
+ "ARGS: add: `contract_id`, `party_id`, `role`; change: `role_id` (roles[].id from talonic_parties_contract) and optional `party_id`, `role`. Both: `state` suggested|confirmed|rejected, `represents_id` (another role id on the same contract; null clears), `valid_from`, `valid_to` (YYYY-MM-DD; null clears), `enters_contract` (tenant only), `note` (say where the decision comes from).",
4610
+ "RETURNS: the role row { id, contract_id, party_id, role, represents_id, valid_from, valid_to, enters_contract, state, confidence, evidence[], origin, decided_by, decided_at, note }."
4611
+ ].join("\n");
4612
+ var setRoleInputSchema = {
4613
+ contract_id: contractIdArg2.optional().describe("Add: the contract to add the role to."),
4614
+ role_id: z.string().uuid().optional().describe("Change: the role row (roles[].id from talonic_parties_contract)."),
4615
+ party_id: partyIdArg.optional().describe("Add: the party; change: move the row to this party."),
4616
+ role: z.enum(ROLES2).optional().describe("The role."),
4617
+ state: z.enum(ROLE_STATES).optional().describe("confirmed or rejected (a person's decision); suggested keeps it open."),
4618
+ represents_id: z.string().uuid().nullable().optional().describe("Manager / contact: the role id it acts for on the same contract; null clears."),
4619
+ valid_from: dateArg.nullable().optional().describe("From this day (YYYY-MM-DD); null clears."),
4620
+ valid_to: dateArg.nullable().optional().describe("Until this day (YYYY-MM-DD); null clears."),
4621
+ enters_contract: z.boolean().optional().describe("Tenant: enters the contract (temporary partner for the lease period)."),
4622
+ note: z.string().max(1e3).nullable().optional().describe("Why; where the decision comes from.")
4623
+ };
4624
+ function handleSetRole(getToken, baseUrl, args) {
4625
+ const { contract_id, role_id, ...rest } = args;
4626
+ const body = defined(rest);
4627
+ if (!!contract_id === !!role_id) {
4628
+ return Promise.resolve(
4629
+ validationError("pass contract_id (with party_id and role) to add, or role_id to change.")
4630
+ );
4631
+ }
4632
+ if (contract_id) {
4633
+ if (!args.party_id || !args.role) {
4634
+ return Promise.resolve(validationError("adding a role needs party_id and role."));
4635
+ }
4636
+ return runTool(
4637
+ () => apiJson(getToken, baseUrl, "POST", `/v1/parties/contracts/${contract_id}/roles`, { body })
4638
+ );
4639
+ }
4640
+ if (Object.keys(body).length === 0) {
4641
+ return Promise.resolve(
4642
+ validationError(
4643
+ "name something to change: state, role, party_id, represents_id, valid_from, valid_to, enters_contract or note."
4644
+ )
4645
+ );
4646
+ }
4647
+ return runTool(
4648
+ () => apiJson(getToken, baseUrl, "PATCH", `/v1/parties/roles/${role_id}`, { body })
4649
+ );
4650
+ }
4651
+ var CONFIRM_DESCRIPTION2 = [
4652
+ "Confirm suggested roles in bulk: by default only high-confidence suggestions (a verified quote the contract register agrees with), optionally only of named contracts or roles. Confirming says a person checked them; it is the user's decision, so only call this when the user asked. Run with dry_run first and say how many it would confirm.",
4653
+ "USE WHEN: the user asks to accept the suggestions (all, or of some contracts / roles).",
4654
+ DECISION_RULE,
4655
+ "NOT FOR: rejecting or fixing one role (talonic_parties_set_role).",
4656
+ "",
4657
+ "ARGS: `contract_ids[]` (omit for all), `roles[]` (e.g. ['partner']), `min_confidence` high|medium|low (default high), `limit` (1-5000, default 500), `dry_run`.",
4658
+ "RETURNS: { dry_run, confirmed, rows[] { id, contract_id, party_id, role, confidence } } (rows: the first 100)."
4659
+ ].join("\n");
4660
+ var confirmInputSchema2 = {
4661
+ contract_ids: z.array(z.string().uuid()).max(1e3).optional().describe("Only these contracts."),
4662
+ roles: z.array(z.enum(ROLES2)).max(ROLES2.length).optional().describe("Only these roles."),
4663
+ min_confidence: z.enum(["high", "medium", "low"]).optional().describe("Lowest confidence confirmed (default high)."),
4664
+ limit: z.number().int().min(1).max(5e3).optional().describe("At most this many (default 500)."),
4665
+ dry_run: z.boolean().optional().describe("Count only; nothing is confirmed.")
4666
+ };
4667
+ function handleConfirm2(getToken, baseUrl, args) {
4668
+ return runTool(
4669
+ () => apiJson(getToken, baseUrl, "POST", "/v1/parties/roles/confirm", {
4670
+ body: {
4671
+ ...args.contract_ids ? { contract_ids: args.contract_ids } : {},
4672
+ ...args.roles ? { roles: args.roles } : {},
4673
+ min_confidence: args.min_confidence ?? "high",
4674
+ ...args.limit ? { limit: args.limit } : {},
4675
+ dry_run: args.dry_run ?? false
4676
+ }
4677
+ })
4678
+ );
4679
+ }
4680
+ var MERGE_DESCRIPTION2 = [
4681
+ "Merge one party into another: every role and contact link moves to the survivor (`into`); a role the survivor already holds on the same contract keeps the survivor's row and takes the merged one's evidence. The merged party stays only as a pointer to the survivor. Cannot be undone; a person's decision, so only when the user asked. Run with dry_run first.",
4682
+ "USE WHEN: talonic_parties_issues lists duplicates (same name and postcode) and the user confirms they are the same party.",
4683
+ "NOT FOR: two different parties with similar names; moving one role to another party (talonic_parties_set_role with role_id and party_id).",
4684
+ "",
4685
+ "ARGS: `party_id` (the one that goes), `into` (the survivor), `dry_run`.",
4686
+ "RETURNS: { dry_run, moves, combined, party } (party: the survivor, after a real merge)."
4687
+ ].join("\n");
4688
+ var mergeInputSchema2 = {
4689
+ party_id: partyIdArg.describe("The party merged away."),
4690
+ into: z.string().uuid().describe("The party that survives."),
4691
+ dry_run: z.boolean().optional().describe("Count the moves; nothing changes.")
4692
+ };
4693
+ function handleMerge2(getToken, baseUrl, args) {
4694
+ if (args.party_id === args.into) {
4695
+ return Promise.resolve(validationError("a party cannot be merged into itself."));
4696
+ }
4697
+ return runTool(
4698
+ () => apiJson(getToken, baseUrl, "POST", `/v1/parties/${args.party_id}/merge`, {
4699
+ body: { into: args.into, dry_run: args.dry_run ?? false }
4700
+ })
4701
+ );
4702
+ }
4703
+ var READ_DESCRIPTION = [
4704
+ "Read the parties from contract documents: queues contracts for the platform to read in the background (one model call per contract) and store every party and role it finds as a suggestion, with quotes. By default every contract not read yet (only_unread); `contract_ids` reads exactly those again. With `status: true` only reports the queue. Pass `wait_seconds` to wait until the queue is empty (polls the queue every 5 s).",
4705
+ "USE WHEN: filling the app or after new contract documents arrived: run with dry_run first and say how many contracts it will read, then without dry_run and with wait_seconds; then talonic_parties_issues.",
4706
+ DECISION_RULE,
4707
+ "NOT FOR: one contract's parties (talonic_parties_contract).",
4708
+ "",
4709
+ "ARGS: `status` (only the queue); or `contract_ids[]` (omit for all), `only_unread` (default true), `force` (read again although read), `limit` (1-5000, default 500), `dry_run`; `wait_seconds` (0-600, default 0; not with dry_run).",
4710
+ "RETURNS: dry_run { dry_run, would_queue, skipped, contracts[] (first 50) }; queued { dry_run, queued, skipped }; status { contracts, counts { pending, running, done, failed }, unread, failed[] { contract_id, contract_key, error, attempts } }. After a wait also { status, waited_ms, still_running }."
4711
+ ].join("\n");
4712
+ var readInputSchema = {
4713
+ status: z.boolean().optional().describe("Only report the read queue; nothing is queued."),
4714
+ contract_ids: z.array(z.string().uuid()).max(5e3).optional().describe("Only these contracts (read again when already read)."),
4715
+ only_unread: z.boolean().optional().describe("All contracts: only those not read yet (default true)."),
4716
+ force: z.boolean().optional().describe("Read again although already read."),
4717
+ limit: z.number().int().min(1).max(5e3).optional().describe("Queue at most this many."),
4718
+ dry_run: z.boolean().optional().describe("Count and list what would be read; nothing is queued."),
4719
+ wait_seconds: z.number().min(0).max(READ_MAX_WAIT_S).optional().describe(`Seconds to wait for the queue to empty (0-${READ_MAX_WAIT_S}).`)
4720
+ };
4721
+ var busy = (s) => (s.counts?.["pending"] ?? 0) + (s.counts?.["running"] ?? 0) > 0;
4722
+ function handleRead(getToken, baseUrl, args, deps = {}) {
4723
+ const waitS = waitSeconds2(args.wait_seconds, READ_MAX_WAIT_S);
4724
+ const readStatus = () => apiJson(getToken, baseUrl, "GET", "/v1/parties/read/status");
4725
+ return runTool(async () => {
4726
+ let started = null;
4727
+ if (!args.status) {
4728
+ started = await apiJson(
4729
+ getToken,
4730
+ baseUrl,
4731
+ "POST",
4732
+ "/v1/parties/read",
4733
+ {
4734
+ body: {
4735
+ ...args.contract_ids ? { contract_ids: args.contract_ids } : {},
4736
+ ...args.only_unread !== void 0 ? { only_unread: args.only_unread } : {},
4737
+ ...args.force !== void 0 ? { force: args.force } : {},
4738
+ ...args.limit ? { limit: args.limit } : {},
4739
+ dry_run: args.dry_run ?? false
4740
+ }
4741
+ }
4742
+ );
4743
+ if (waitS === 0 || args.dry_run) return started;
4744
+ }
4745
+ const first = await readStatus();
4746
+ if (waitS === 0) return first;
4747
+ const sleep2 = deps.sleep ?? sleep;
4748
+ const now = deps.now ?? Date.now;
4749
+ const start = now();
4750
+ const deadline = start + waitS * 1e3;
4751
+ let status3 = first;
4752
+ let pollError;
4753
+ while (busy(status3) && now() < deadline) {
4754
+ await sleep2(Math.min(PARTIES_POLL_INTERVAL_MS, deadline - now()));
4755
+ try {
4756
+ status3 = await readStatus();
4757
+ } catch (err) {
4758
+ pollError = err instanceof Error ? err.message : String(err);
4759
+ break;
4760
+ }
4761
+ }
4762
+ const stillRunning = pollError !== void 0 || busy(status3);
4763
+ return {
4764
+ ...started ?? {},
4765
+ status: status3,
4766
+ waited_ms: now() - start,
4767
+ still_running: stillRunning,
4768
+ ...pollError ? { poll_error: pollError } : {},
4769
+ next: stillRunning ? "Still reading: call talonic_parties_read with status: true (and wait_seconds) later." : "Read done: open the worklist with talonic_parties_issues."
4770
+ };
4771
+ });
4772
+ }
4773
+ var MEMBERS_DESCRIPTION = [
4774
+ "Add a contact person to a company or an owners' association (with their function), or remove a contact link. A contact is always a person; the company is a company or an owners' association. Adding the same person again updates the function.",
4775
+ "USE WHEN: the user names the person to write to at a company (e.g. the WEG's Verwalter contact), or a contact left.",
4776
+ "NOT FOR: a contact role on one contract (talonic_parties_set_role with role contact).",
4777
+ "",
4778
+ "ARGS: add: `party_id` (the company), `person_id`, `function` (e.g. 'Gesch\xE4ftsf\xFChrer'); remove: `member_id` (members[].id from talonic_parties_party) alone.",
4779
+ "RETURNS: add: the link { id, company_party_id, person_party_id, function }; remove: { ok: true }."
4780
+ ].join("\n");
4781
+ var membersInputSchema = {
4782
+ party_id: partyIdArg.optional().describe("Add: the company or owners' association."),
4783
+ person_id: z.string().uuid().optional().describe("Add: the person (a party of kind person)."),
4784
+ function: z.string().max(200).nullable().optional().describe("Add: their function."),
4785
+ member_id: z.string().uuid().optional().describe("Remove: the link (members[].id from talonic_parties_party).")
4786
+ };
4787
+ function handleMembers(getToken, baseUrl, args) {
4788
+ if (args.member_id) {
4789
+ if (args.party_id || args.person_id || args.function !== void 0) {
4790
+ return Promise.resolve(validationError("member_id (remove) goes alone."));
4791
+ }
4792
+ return runTool(
4793
+ () => apiJson(getToken, baseUrl, "DELETE", `/v1/parties/members/${args.member_id}`)
4794
+ );
4795
+ }
4796
+ if (!args.party_id || !args.person_id) {
4797
+ return Promise.resolve(
4798
+ validationError("pass party_id and person_id to add a contact, or member_id to remove one.")
4799
+ );
4800
+ }
4801
+ return runTool(
4802
+ () => apiJson(getToken, baseUrl, "POST", `/v1/parties/${args.party_id}/members`, {
4803
+ body: {
4804
+ person_id: args.person_id,
4805
+ ...args.function !== void 0 ? { function: args.function } : {}
4806
+ }
4807
+ })
4808
+ );
4809
+ }
4810
+ var GROUP_COMPANIES_DESCRIPTION = [
4811
+ "Read the workspace's own companies (the group: lead company, subsidiaries, sisters), or replace them all with `companies`. The read uses them to tell our side from the contract partner. Replacing deletes every company not in the new list: read first, change, send the whole list, and only when the user asked.",
4812
+ "USE WHEN: a read takes one of our own companies for the partner, or setting up the workspace.",
4813
+ "NOT FOR: contract partners (talonic_parties_party).",
4814
+ "",
4815
+ "ARGS: none to read; `companies[] { name, parent? (another name in the list), relation? subsidiary|sister|parent }` to replace.",
4816
+ "RETURNS: { data[] { id, name, parent_id, relation } } (after a replace: the stored list)."
4817
+ ].join("\n");
4818
+ var groupCompaniesInputSchema = {
4819
+ companies: z.array(
4820
+ z.object({
4821
+ name: z.string().min(1).max(300),
4822
+ parent: z.string().max(300).nullable().optional().describe("Another name in the list."),
4823
+ relation: z.enum(["subsidiary", "sister", "parent"]).nullable().optional()
4824
+ })
4825
+ ).max(1e3).optional().describe("The complete new list; omit to read.")
4826
+ };
4827
+ function handleGroupCompanies(getToken, baseUrl, args) {
4828
+ return runTool(
4829
+ () => args.companies ? apiJson(getToken, baseUrl, "PUT", "/v1/parties/group-companies", {
4830
+ body: { companies: args.companies }
4831
+ }) : apiJson(getToken, baseUrl, "GET", "/v1/parties/group-companies")
4832
+ );
4833
+ }
4834
+ async function probePartiesAccess(token, baseUrl) {
4835
+ try {
4836
+ const res = await fetch(buildUrl(baseUrl, "/v1/parties/status"), {
4837
+ headers: { Authorization: `Bearer ${token}`, Accept: "application/json" },
4838
+ signal: AbortSignal.timeout(5e3)
4839
+ });
4840
+ return res.ok;
4841
+ } catch {
4842
+ return false;
4843
+ }
4844
+ }
4845
+ function registerPartiesTools(server, getToken, baseUrl) {
4846
+ const tools = [
4847
+ [
4848
+ "talonic_parties_status",
4849
+ "Contract parties status",
4850
+ STATUS_DESCRIPTION3,
4851
+ {},
4852
+ readOnly4,
4853
+ () => handleStatus2(getToken, baseUrl)
4854
+ ],
4855
+ [
4856
+ "talonic_parties_issues",
4857
+ "Contract parties worklist",
4858
+ ISSUES_DESCRIPTION4,
4859
+ issuesInputSchema2,
4860
+ readOnly4,
4861
+ (a) => handleIssues4(getToken, baseUrl, a)
4862
+ ],
4863
+ [
4864
+ "talonic_parties_contracts",
4865
+ "Contracts with their parties",
4866
+ CONTRACTS_DESCRIPTION,
4867
+ contractsInputSchema,
4868
+ readOnly4,
4869
+ (a) => handleContracts(getToken, baseUrl, a)
4870
+ ],
4871
+ [
4872
+ "talonic_parties_contract",
4873
+ "One contract's parties",
4874
+ CONTRACT_DESCRIPTION2,
4875
+ contractInputSchema2,
4876
+ readOnly4,
4877
+ (a) => handleContract2(getToken, baseUrl, a)
4878
+ ],
4879
+ [
4880
+ "talonic_parties_search",
4881
+ "Search parties",
4882
+ SEARCH_DESCRIPTION,
4883
+ searchInputSchema,
4884
+ readOnly4,
4885
+ (a) => handleSearch2(getToken, baseUrl, a)
4886
+ ],
4887
+ [
4888
+ "talonic_parties_party",
4889
+ "Read, change or create a party",
4890
+ PARTY_DESCRIPTION,
4891
+ partyInputSchema,
4892
+ // With fields it overwrites the party's details: destructive per OpenAI's annotation rules.
4893
+ write4(false, true),
4894
+ (a) => handleParty(getToken, baseUrl, a)
4895
+ ],
4896
+ [
4897
+ "talonic_parties_set_role",
4898
+ "Add or change a contract role",
4899
+ SET_ROLE_DESCRIPTION,
4900
+ setRoleInputSchema,
4901
+ // Overwrites or rejects a role row: destructive.
4902
+ write4(true, true),
4903
+ (a) => handleSetRole(getToken, baseUrl, a)
4904
+ ],
4905
+ [
4906
+ "talonic_parties_confirm",
4907
+ "Confirm suggested roles",
4908
+ CONFIRM_DESCRIPTION2,
4909
+ confirmInputSchema2,
4910
+ write4(true),
4911
+ (a) => handleConfirm2(getToken, baseUrl, a)
4912
+ ],
4913
+ [
4914
+ "talonic_parties_merge",
4915
+ "Merge duplicate parties",
4916
+ MERGE_DESCRIPTION2,
4917
+ mergeInputSchema2,
4918
+ write4(true, true),
4919
+ (a) => handleMerge2(getToken, baseUrl, a)
4920
+ ],
4921
+ [
4922
+ "talonic_parties_read",
4923
+ "Read parties from contracts",
4924
+ READ_DESCRIPTION,
4925
+ readInputSchema,
4926
+ write4(true),
4927
+ (a) => handleRead(getToken, baseUrl, a)
4928
+ ],
4929
+ [
4930
+ "talonic_parties_members",
4931
+ "Company contacts",
4932
+ MEMBERS_DESCRIPTION,
4933
+ membersInputSchema,
4934
+ // Removing a contact link deletes it: destructive.
4935
+ write4(true, true),
4936
+ (a) => handleMembers(getToken, baseUrl, a)
4937
+ ],
4938
+ [
4939
+ "talonic_parties_group_companies",
4940
+ "Our group companies",
4941
+ GROUP_COMPANIES_DESCRIPTION,
4942
+ groupCompaniesInputSchema,
4943
+ // With `companies` it replaces the whole list: destructive.
4944
+ write4(true, true),
4945
+ (a) => handleGroupCompanies(getToken, baseUrl, a)
4946
+ ]
4947
+ ];
4948
+ for (const [name, title, description, inputSchema11, annotations, handler] of tools) {
4949
+ server.registerTool(
4950
+ name,
4951
+ { title, description, inputSchema: inputSchema11, annotations: { title, ...annotations } },
4952
+ async (args) => handler(args)
4953
+ );
4954
+ }
4955
+ }
4386
4956
  var DEFAULT_BASE3 = "https://api.talonic.com";
4387
4957
  var TASK_STATUSES = ["available", "claimed", "submitted", "timed_out", "cancelled"];
4388
4958
  var taskId = z.string().uuid().describe("Agent task UUID.");
@@ -5929,7 +6499,7 @@ function registerAskTools(server, getToken, baseUrl) {
5929
6499
 
5930
6500
  // package.json
5931
6501
  var package_default = {
5932
- version: "0.1.88"};
6502
+ version: "0.1.89"};
5933
6503
 
5934
6504
  // src/version.ts
5935
6505
  var VERSION = package_default.version;
@@ -6089,6 +6659,9 @@ function createServer(options) {
6089
6659
  if (options.includeDocGenTools) {
6090
6660
  registerDocGenTools(server, rawToken, baseUrl, { localFiles: !options.tokenProvider });
6091
6661
  }
6662
+ if (options.includePartiesTools) {
6663
+ registerPartiesTools(server, rawToken, baseUrl);
6664
+ }
6092
6665
  registerSchemasResource(server, getTalonic);
6093
6666
  registerWebhooksResource(server, rawToken, baseUrl);
6094
6667
  registerWidgets(server);
@@ -6146,13 +6719,15 @@ async function main(argv = process.argv.slice(2), env = process.env, out = (line
6146
6719
  includeAdminAgentTaskTools,
6147
6720
  includeContractsTools,
6148
6721
  includeApTools,
6149
- includeDocGenTools
6722
+ includeDocGenTools,
6723
+ includePartiesTools
6150
6724
  ] = await Promise.all([
6151
6725
  probeGrowthAccess(apiKey, baseUrl),
6152
6726
  probeAgentTaskAdminAccess(apiKey, baseUrl),
6153
6727
  probeContractsAccess(apiKey, baseUrl),
6154
6728
  probeApAccess(apiKey, baseUrl),
6155
- probeDocGenAccess(apiKey, baseUrl)
6729
+ probeDocGenAccess(apiKey, baseUrl),
6730
+ probePartiesAccess(apiKey, baseUrl)
6156
6731
  ]);
6157
6732
  const server = createServer({
6158
6733
  apiKey,
@@ -6161,7 +6736,8 @@ async function main(argv = process.argv.slice(2), env = process.env, out = (line
6161
6736
  includeAdminAgentTaskTools,
6162
6737
  includeContractsTools,
6163
6738
  includeApTools,
6164
- includeDocGenTools
6739
+ includeDocGenTools,
6740
+ includePartiesTools
6165
6741
  });
6166
6742
  const transport = new StdioServerTransport();
6167
6743
  await server.connect(transport);