@talonic/mcp 0.1.81 → 0.1.83

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
@@ -2959,6 +2959,696 @@ function registerGrowthTools(server, getToken, baseUrl) {
2959
2959
  async (args) => handleGrowthToolsUsage(getToken, baseUrl, args)
2960
2960
  );
2961
2961
  }
2962
+ var contractIdArg = z.string().uuid().describe("Contract id (from talonic_contracts_register or talonic_contracts_issues).");
2963
+ var rowIdArg = z.string().uuid().describe(
2964
+ "Document row id on the contract: `documents[].id` from talonic_contracts_contract (not the workspace document id)."
2965
+ );
2966
+ var readOnly = {
2967
+ readOnlyHint: true,
2968
+ destructiveHint: false,
2969
+ idempotentHint: true,
2970
+ openWorldHint: false
2971
+ };
2972
+ var write = (idempotent, destructive = false) => ({
2973
+ readOnlyHint: false,
2974
+ destructiveHint: destructive,
2975
+ idempotentHint: idempotent,
2976
+ openWorldHint: false
2977
+ });
2978
+ var ROLES = ["master", "amendment", "renewal", "termination", "price_sheet", "other"];
2979
+ var STATUSES = ["draft", "active", "expired", "terminated", "unknown"];
2980
+ var DECISIONS = ["terminated", "notice_sent", "renewal_declined", "active"];
2981
+ var TERMS = [
2982
+ "title",
2983
+ "counterparty",
2984
+ "our_party",
2985
+ "family",
2986
+ "site",
2987
+ "signed_date",
2988
+ "effective_date",
2989
+ "expiry_date",
2990
+ "initial_term_months",
2991
+ "auto_renewal",
2992
+ "renewal_term_months",
2993
+ "notice_days",
2994
+ "notice_months",
2995
+ "terminated_on",
2996
+ "annual_value",
2997
+ "currency",
2998
+ "escalation_pct",
2999
+ "escalation_date",
3000
+ "min_commitment",
3001
+ "cap_amount",
3002
+ "payment_terms_days",
3003
+ "governing_law",
3004
+ "is_draft"
3005
+ ];
3006
+ var REGISTER_DESCRIPTION = [
3007
+ "List the workspace's contracts: key, title, counterparty, status, start, end in force, notice deadline, document count, next open date, and what Contract Pricing and Money Found report per contract.",
3008
+ "USE WHEN: getting an overview, finding a contract by key/name, or counting by status.",
3009
+ "NOT FOR: one contract's terms and documents (talonic_contracts_contract); what needs cleaning (talonic_contracts_issues).",
3010
+ "",
3011
+ "ARGS: `query` (key, title or counterparty contains), `status`, `key` (exact).",
3012
+ "RETURNS: data[] { id, contract_key, title, counterparty, status, effective_date, expiry_date, notice_deadline, documents, next_date, links }."
3013
+ ].join("\n");
3014
+ var registerInputSchema = {
3015
+ query: z.string().optional().describe("Key, title or counterparty contains."),
3016
+ status: z.enum(STATUSES).optional().describe("Only contracts in this status."),
3017
+ key: z.string().optional().describe("Exact contract key, e.g. '1042460' or '3042-WLV'.")
3018
+ };
3019
+ function handleRegister(getToken, baseUrl, args) {
3020
+ return runTool(
3021
+ () => apiJson(getToken, baseUrl, "GET", "/v1/contracts", {
3022
+ params: { q: args.query, status: args.status, key: args.key }
3023
+ })
3024
+ );
3025
+ }
3026
+ var CONTRACT_DESCRIPTION = [
3027
+ "Read one contract in full: terms in force (each with the document and verbatim quote it rests on), documents in fold order with what each states (unverified values carry their `problem`), key dates, decisions and links to the other apps.",
3028
+ "USE WHEN: checking or cleaning a contract; you need document row ids for talonic_contracts_update_document.",
3029
+ "NOT FOR: the list of contracts (talonic_contracts_register).",
3030
+ "",
3031
+ "ARGS: `contract_id`.",
3032
+ "RETURNS: { contract, documents[] { id, document_id, filename, role, excluded, extract }, key_dates[], links, decision, history }."
3033
+ ].join("\n");
3034
+ var contractInputSchema = { contract_id: contractIdArg };
3035
+ function handleContract(getToken, baseUrl, args) {
3036
+ return runTool(() => apiJson(getToken, baseUrl, "GET", `/v1/contracts/${args.contract_id}`));
3037
+ }
3038
+ var ISSUES_DESCRIPTION = [
3039
+ "The cleaning worklist: contracts that look wrong and why. Codes: several_base_contracts (one key holds several contracts), printed_number_differs, several_counterparties, several_sites, ended_by_message (an email read as the termination), unread_documents, no_dates, unverified_terms.",
3040
+ "USE WHEN: after an import, to decide what to fix; again after fixing, to confirm it is clean.",
3041
+ "NOT FOR: contracts that are fine (talonic_contracts_register).",
3042
+ "",
3043
+ "ARGS: `code` (only contracts with this issue, optional).",
3044
+ "RETURNS: data[] { contract_id, contract_key, title, status, issues[] { code, detail, document_ids } }. document_ids are workspace document ids; match them to documents[].document_id in talonic_contracts_contract."
3045
+ ].join("\n");
3046
+ var issuesInputSchema = {
3047
+ code: z.enum([
3048
+ "several_base_contracts",
3049
+ "printed_number_differs",
3050
+ "several_counterparties",
3051
+ "several_sites",
3052
+ "ended_by_message",
3053
+ "unread_documents",
3054
+ "no_dates",
3055
+ "unverified_terms"
3056
+ ]).optional().describe("Only contracts with this issue.")
3057
+ };
3058
+ async function handleIssues(getToken, baseUrl, args) {
3059
+ return runTool(async () => {
3060
+ const res = await apiJson(
3061
+ getToken,
3062
+ baseUrl,
3063
+ "GET",
3064
+ "/v1/contracts/issues"
3065
+ );
3066
+ return args.code ? { data: res.data.filter((c) => c.issues.some((i) => i.code === args.code)) } : res;
3067
+ });
3068
+ }
3069
+ var UPCOMING_DESCRIPTION = [
3070
+ "Open key dates across all contracts, soonest first: notice deadlines, ends of term, renewals, price changes, terminations, dated obligations. Dates marked handled are left out.",
3071
+ "USE WHEN: what needs someone soon; preparing a renewal or notice decision.",
3072
+ "NOT FOR: one contract's dates (talonic_contracts_contract).",
3073
+ "",
3074
+ "ARGS: `days` (horizon, default the workspace's alert horizon, 90).",
3075
+ "RETURNS: data[] { id, contract_id, contract_key, title, kind, due_date, days_left, label, quote }."
3076
+ ].join("\n");
3077
+ var upcomingInputSchema = {
3078
+ days: z.number().int().min(1).max(3650).optional().describe("Days ahead.")
3079
+ };
3080
+ function handleUpcoming(getToken, baseUrl, args) {
3081
+ return runTool(
3082
+ () => apiJson(getToken, baseUrl, "GET", "/v1/contracts/upcoming", { params: { days: args.days } })
3083
+ );
3084
+ }
3085
+ var CANDIDATES_DESCRIPTION = [
3086
+ "Contract documents whose terms have not been read yet, grouped by the contract key in their filename; keys Contract Pricing already models first.",
3087
+ "USE WHEN: choosing what to read, or checking how the documents will group before importing.",
3088
+ "NOT FOR: reading them (talonic_contracts_import).",
3089
+ "",
3090
+ "ARGS: `query` (filename contains).",
3091
+ "RETURNS: data[] { contract_key, in_price_baseline, documents[] { document_id, filename, import } }."
3092
+ ].join("\n");
3093
+ var candidatesInputSchema = { query: z.string().optional().describe("Filename contains.") };
3094
+ function handleCandidates(getToken, baseUrl, args) {
3095
+ return runTool(
3096
+ () => apiJson(getToken, baseUrl, "GET", "/v1/contracts/import/candidates", {
3097
+ params: { q: args.query }
3098
+ })
3099
+ );
3100
+ }
3101
+ var STATUS_DESCRIPTION = [
3102
+ "Where the read queue stands: counts by status (pending, running, done, failed) and the latest failures with their error.",
3103
+ "USE WHEN: after talonic_contracts_import, poll until pending and running are 0.",
3104
+ "NOT FOR: the contracts themselves (talonic_contracts_register).",
3105
+ "",
3106
+ "ARGS: none.",
3107
+ "RETURNS: { counts, failed[] { document_id, filename, error, attempts } }."
3108
+ ].join("\n");
3109
+ function handleImportStatus(getToken, baseUrl) {
3110
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/contracts/import/status"));
3111
+ }
3112
+ var IMPORT_DESCRIPTION = [
3113
+ "Queue contract documents to be read; the platform reads them in the background (one model call each) and files each under its contract.",
3114
+ "USE WHEN: filling the app. `all: true` queues every unread candidate (narrow with query, contract_keys, only_priced; `limit` for a first batch); `document_ids` queues exactly those. Always run `all` with `dry_run: true` first and say how many documents it will read.",
3115
+ "NOT FOR: reading a contract again after cleaning (talonic_contracts_reread).",
3116
+ "",
3117
+ "ARGS: `all` or `document_ids`; with all: `query`, `contract_keys`, `only_priced`, `limit`, `dry_run`; with document_ids: `force` (read again even if read).",
3118
+ "RETURNS: all \u2192 { dry_run, contracts, documents, queued, skipped }; document_ids \u2192 { queued, skipped }. Then poll talonic_contracts_import_status."
3119
+ ].join("\n");
3120
+ var importInputSchema = {
3121
+ all: z.boolean().optional().describe("Queue every unread candidate (with the filters below)."),
3122
+ document_ids: z.array(z.string().uuid()).min(1).max(500).optional().describe("Workspace document ids to read."),
3123
+ query: z.string().optional().describe("all: only filenames containing this."),
3124
+ contract_keys: z.array(z.string()).max(2e3).optional().describe("all: only these contract keys."),
3125
+ only_priced: z.boolean().optional().describe("all: only keys Contract Pricing already models."),
3126
+ limit: z.number().int().min(1).max(2e4).optional().describe("all: queue at most this many documents."),
3127
+ dry_run: z.boolean().optional().describe("all: count only, queue nothing."),
3128
+ force: z.boolean().optional().describe("document_ids: read again even when already read.")
3129
+ };
3130
+ function handleImport(getToken, baseUrl, args) {
3131
+ if (!!args.all === !!args.document_ids?.length)
3132
+ return Promise.resolve(validationError("Pass either `all: true` or `document_ids`, not both."));
3133
+ if (args.all) {
3134
+ const { query, contract_keys, only_priced, limit: limit2, dry_run } = args;
3135
+ return runTool(
3136
+ () => apiJson(getToken, baseUrl, "POST", "/v1/contracts/import/all", {
3137
+ body: { query, contract_keys, only_priced, limit: limit2, dry_run }
3138
+ })
3139
+ );
3140
+ }
3141
+ return runTool(
3142
+ () => apiJson(getToken, baseUrl, "POST", "/v1/contracts/import", {
3143
+ body: { document_ids: args.document_ids, force: args.force }
3144
+ })
3145
+ );
3146
+ }
3147
+ var UPDATE_DOCUMENT_DESCRIPTION = [
3148
+ "Fix one document of a contract: set what it is (`role`), leave it out of the fold (`excluded`), file it under another contract key (`contract_key`; a new key creates that contract, null returns it to its derived key), or take it off the contract (`remove`).",
3149
+ "USE WHEN: cleaning \u2014 a key holds several contracts (move each set to its own key, e.g. '1042460-WLV / An der Walze 12'), an email is read as a termination (exclude it), an amendment is read as a base contract (role).",
3150
+ "NOT FOR: moving all documents of a contract at once (talonic_contracts_merge).",
3151
+ "",
3152
+ "ARGS: `contract_id`, `document_row_id`, and one or more of `role`, `excluded`, `contract_key`; or `remove: true` alone.",
3153
+ "RETURNS: the contract the document ends up in, recomputed. A hand-set key and role survive re-reading."
3154
+ ].join("\n");
3155
+ var updateDocumentInputSchema = {
3156
+ contract_id: contractIdArg,
3157
+ document_row_id: rowIdArg,
3158
+ role: z.enum(ROLES).optional().describe("What the document is."),
3159
+ excluded: z.boolean().optional().describe("true = leave it out of the contract's terms."),
3160
+ contract_key: z.string().max(64).nullable().optional().describe("File under this key; null = back to the derived key."),
3161
+ remove: z.boolean().optional().describe("Take the document off the contract (the document stays in the workspace).")
3162
+ };
3163
+ function handleUpdateDocument(getToken, baseUrl, args) {
3164
+ const path = `/v1/contracts/${args.contract_id}/documents/${args.document_row_id}`;
3165
+ if (args.remove) {
3166
+ if (args.role !== void 0 || args.excluded !== void 0 || args.contract_key !== void 0)
3167
+ return Promise.resolve(validationError("`remove` goes alone."));
3168
+ return runTool(() => apiJson(getToken, baseUrl, "DELETE", path));
3169
+ }
3170
+ if (args.role === void 0 && args.excluded === void 0 && args.contract_key === void 0)
3171
+ return Promise.resolve(
3172
+ validationError("Nothing to change: pass role, excluded, contract_key or remove.")
3173
+ );
3174
+ return runTool(
3175
+ () => apiJson(getToken, baseUrl, "PUT", path, {
3176
+ body: { role: args.role, excluded: args.excluded, contract_key: args.contract_key }
3177
+ })
3178
+ );
3179
+ }
3180
+ var MERGE_DESCRIPTION = [
3181
+ "Move every document of one contract under another key (the same contract read under two keys, e.g. '1042460' and '1042460-WLV'). The emptied contract disappears.",
3182
+ "USE WHEN: two register rows are the same contract.",
3183
+ "NOT FOR: moving single documents (talonic_contracts_update_document).",
3184
+ "",
3185
+ "ARGS: `contract_id` (the one to empty), `into_key`.",
3186
+ "RETURNS: { moved, contract } \u2014 the contract under into_key, recomputed."
3187
+ ].join("\n");
3188
+ var mergeInputSchema = {
3189
+ contract_id: contractIdArg,
3190
+ into_key: z.string().min(1).max(64).describe("The key to move everything under.")
3191
+ };
3192
+ function handleMerge(getToken, baseUrl, args) {
3193
+ return runTool(
3194
+ () => apiJson(getToken, baseUrl, "POST", `/v1/contracts/${args.contract_id}/merge`, {
3195
+ body: { into_key: args.into_key }
3196
+ })
3197
+ );
3198
+ }
3199
+ var REREAD_DESCRIPTION = [
3200
+ "Read a contract's documents again (or one of them), e.g. after cleaning or when values did not verify. One model call per document; hand-set values and roles are kept.",
3201
+ "USE WHEN: a contract's terms look wrong and the documents are right.",
3202
+ "NOT FOR: documents never read (talonic_contracts_import).",
3203
+ "",
3204
+ "ARGS: `contract_id`, `document_row_id` (optional, all when omitted).",
3205
+ "RETURNS: { queued, skipped }. Then poll talonic_contracts_import_status."
3206
+ ].join("\n");
3207
+ var rereadInputSchema = {
3208
+ contract_id: contractIdArg,
3209
+ document_row_id: rowIdArg.optional()
3210
+ };
3211
+ function handleReread(getToken, baseUrl, args) {
3212
+ return runTool(
3213
+ () => apiJson(getToken, baseUrl, "POST", `/v1/contracts/${args.contract_id}/reread`, {
3214
+ body: args.document_row_id ? { document_row_id: args.document_row_id } : {}
3215
+ })
3216
+ );
3217
+ }
3218
+ var DECIDE_DESCRIPTION = [
3219
+ "Record a decision on a contract: terminated, notice_sent, renewal_declined, or active (withdraws the earlier one). Recorded as made through the API key, with your note; the contract's status, end and key dates follow.",
3220
+ "USE WHEN: the user states the decision or it is confirmed by a document they point to. Never infer a termination on your own.",
3221
+ "NOT FOR: a termination letter already in the documents (it is read as a fact; check talonic_contracts_contract).",
3222
+ "",
3223
+ "ARGS: `contract_id`, `state`, `note` (say where the decision comes from).",
3224
+ "RETURNS: the contract, recomputed."
3225
+ ].join("\n");
3226
+ var decideInputSchema = {
3227
+ contract_id: contractIdArg,
3228
+ state: z.enum(DECISIONS),
3229
+ note: z.string().max(2e3).optional().describe("Source of the decision, e.g. 'K\xFCndigungsschreiben vom 12.01.2026'.")
3230
+ };
3231
+ function handleDecide(getToken, baseUrl, args) {
3232
+ return runTool(
3233
+ () => apiJson(getToken, baseUrl, "POST", `/v1/contracts/${args.contract_id}/decision`, {
3234
+ body: { state: args.state, note: args.note }
3235
+ })
3236
+ );
3237
+ }
3238
+ var KEY_DATE_DESCRIPTION = [
3239
+ "Mark a key date handled (or open again), e.g. a notice deadline someone has dealt with. Handled dates leave the upcoming list and raise no alert.",
3240
+ "USE WHEN: the user confirms a date is taken care of.",
3241
+ "NOT FOR: changing the date itself (it follows the documents).",
3242
+ "",
3243
+ "ARGS: `key_date_id` (key_dates[].id from talonic_contracts_contract or id from talonic_contracts_upcoming), `handled`, `note`.",
3244
+ "RETURNS: { id, handled }."
3245
+ ].join("\n");
3246
+ var keyDateInputSchema = {
3247
+ key_date_id: z.string().uuid(),
3248
+ handled: z.boolean(),
3249
+ note: z.string().max(2e3).optional()
3250
+ };
3251
+ function handleKeyDate(getToken, baseUrl, args) {
3252
+ return runTool(
3253
+ () => apiJson(getToken, baseUrl, "POST", `/v1/contracts/key-dates/${args.key_date_id}`, {
3254
+ body: { handled: args.handled, note: args.note }
3255
+ })
3256
+ );
3257
+ }
3258
+ var SET_TERM_DESCRIPTION = [
3259
+ "Set one term on one document by hand, with the passage that states it copied verbatim from that document. The platform saves it only when the quote occurs in the document and prints the value.",
3260
+ "USE WHEN: a term was missed or read wrong and you have the exact passage (talonic_get_document or talonic_search to find it).",
3261
+ "NOT FOR: guessing a value; decisions (talonic_contracts_decide).",
3262
+ "",
3263
+ "ARGS: `contract_id`, `document_row_id`, `field`, `value` (ISO date for dates; fraction for escalation_pct; months for *_months), `quote`.",
3264
+ "RETURNS: the contract, recomputed; an error naming the problem when the quote does not verify."
3265
+ ].join("\n");
3266
+ var setTermInputSchema = {
3267
+ contract_id: contractIdArg,
3268
+ document_row_id: rowIdArg,
3269
+ field: z.enum(TERMS),
3270
+ value: z.union([z.string(), z.number(), z.boolean()]),
3271
+ quote: z.string().min(3).max(2e3).describe("Copied character for character from the document.")
3272
+ };
3273
+ function handleSetTerm(getToken, baseUrl, args) {
3274
+ const { field, value, quote } = args;
3275
+ return runTool(
3276
+ () => apiJson(
3277
+ getToken,
3278
+ baseUrl,
3279
+ "POST",
3280
+ `/v1/contracts/${args.contract_id}/documents/${args.document_row_id}/terms`,
3281
+ { body: { field, value, quote } }
3282
+ )
3283
+ );
3284
+ }
3285
+ async function probeContractsAccess(token, baseUrl) {
3286
+ try {
3287
+ const res = await fetch(buildUrl(baseUrl, "/v1/contracts/import/status"), {
3288
+ headers: { Authorization: `Bearer ${token}`, Accept: "application/json" },
3289
+ signal: AbortSignal.timeout(5e3)
3290
+ });
3291
+ return res.ok;
3292
+ } catch {
3293
+ return false;
3294
+ }
3295
+ }
3296
+ function registerContractsTools(server, getToken, baseUrl) {
3297
+ const tools = [
3298
+ [
3299
+ "talonic_contracts_register",
3300
+ "List contracts",
3301
+ REGISTER_DESCRIPTION,
3302
+ registerInputSchema,
3303
+ readOnly,
3304
+ (a) => handleRegister(getToken, baseUrl, a)
3305
+ ],
3306
+ [
3307
+ "talonic_contracts_contract",
3308
+ "Read one contract",
3309
+ CONTRACT_DESCRIPTION,
3310
+ contractInputSchema,
3311
+ readOnly,
3312
+ (a) => handleContract(getToken, baseUrl, a)
3313
+ ],
3314
+ [
3315
+ "talonic_contracts_issues",
3316
+ "Contracts to clean",
3317
+ ISSUES_DESCRIPTION,
3318
+ issuesInputSchema,
3319
+ readOnly,
3320
+ (a) => handleIssues(getToken, baseUrl, a)
3321
+ ],
3322
+ [
3323
+ "talonic_contracts_upcoming",
3324
+ "Upcoming contract dates",
3325
+ UPCOMING_DESCRIPTION,
3326
+ upcomingInputSchema,
3327
+ readOnly,
3328
+ (a) => handleUpcoming(getToken, baseUrl, a)
3329
+ ],
3330
+ [
3331
+ "talonic_contracts_import_candidates",
3332
+ "Unread contract documents",
3333
+ CANDIDATES_DESCRIPTION,
3334
+ candidatesInputSchema,
3335
+ readOnly,
3336
+ (a) => handleCandidates(getToken, baseUrl, a)
3337
+ ],
3338
+ [
3339
+ "talonic_contracts_import_status",
3340
+ "Contract read queue",
3341
+ STATUS_DESCRIPTION,
3342
+ {},
3343
+ readOnly,
3344
+ () => handleImportStatus(getToken, baseUrl)
3345
+ ],
3346
+ [
3347
+ "talonic_contracts_import",
3348
+ "Read contract documents",
3349
+ IMPORT_DESCRIPTION,
3350
+ importInputSchema,
3351
+ write(true),
3352
+ (a) => handleImport(getToken, baseUrl, a)
3353
+ ],
3354
+ [
3355
+ "talonic_contracts_update_document",
3356
+ "Fix a contract document",
3357
+ UPDATE_DOCUMENT_DESCRIPTION,
3358
+ updateDocumentInputSchema,
3359
+ write(false, true),
3360
+ (a) => handleUpdateDocument(getToken, baseUrl, a)
3361
+ ],
3362
+ [
3363
+ "talonic_contracts_merge",
3364
+ "Merge two contracts",
3365
+ MERGE_DESCRIPTION,
3366
+ mergeInputSchema,
3367
+ write(true, true),
3368
+ (a) => handleMerge(getToken, baseUrl, a)
3369
+ ],
3370
+ [
3371
+ "talonic_contracts_reread",
3372
+ "Read a contract again",
3373
+ REREAD_DESCRIPTION,
3374
+ rereadInputSchema,
3375
+ write(true),
3376
+ (a) => handleReread(getToken, baseUrl, a)
3377
+ ],
3378
+ [
3379
+ "talonic_contracts_decide",
3380
+ "Record a contract decision",
3381
+ DECIDE_DESCRIPTION,
3382
+ decideInputSchema,
3383
+ write(true),
3384
+ (a) => handleDecide(getToken, baseUrl, a)
3385
+ ],
3386
+ [
3387
+ "talonic_contracts_key_date",
3388
+ "Mark a key date handled",
3389
+ KEY_DATE_DESCRIPTION,
3390
+ keyDateInputSchema,
3391
+ write(true),
3392
+ (a) => handleKeyDate(getToken, baseUrl, a)
3393
+ ],
3394
+ [
3395
+ "talonic_contracts_set_term",
3396
+ "Set a contract term with its quote",
3397
+ SET_TERM_DESCRIPTION,
3398
+ setTermInputSchema,
3399
+ write(true),
3400
+ (a) => handleSetTerm(getToken, baseUrl, a)
3401
+ ]
3402
+ ];
3403
+ for (const [name, title, description, inputSchema11, annotations, handler] of tools) {
3404
+ server.registerTool(
3405
+ name,
3406
+ { title, description, inputSchema: inputSchema11, annotations: { title, ...annotations } },
3407
+ async (args) => handler(args)
3408
+ );
3409
+ }
3410
+ }
3411
+ var readOnly2 = {
3412
+ readOnlyHint: true,
3413
+ destructiveHint: false,
3414
+ idempotentHint: true,
3415
+ openWorldHint: false
3416
+ };
3417
+ var write2 = (idempotent, destructive = false) => ({
3418
+ readOnlyHint: false,
3419
+ destructiveHint: destructive,
3420
+ idempotentHint: idempotent,
3421
+ openWorldHint: false
3422
+ });
3423
+ var OVERVIEW_DESCRIPTION = [
3424
+ "AP totals for the workspace: invoices ready to post and held (count and dollars), dollars at stake above contract, duplicates, missing PO, per entity with its system of record, and the last simulated NetSuite run.",
3425
+ 'USE WHEN: the headline ("how much is ready to post, how much is held and why").',
3426
+ "NOT FOR: the invoices themselves (talonic_ap_bills); the held worklist (talonic_ap_issues).",
3427
+ "",
3428
+ "ARGS: none.",
3429
+ "RETURNS: { as_of, currency, configured, gaps[], totals { bills, ready, held { at_stake, above_contract, duplicates, missing_po, vendor_unknown } }, entities[], sources[], last_run }."
3430
+ ].join("\n");
3431
+ function handleOverview(getToken, baseUrl) {
3432
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/ap/overview"));
3433
+ }
3434
+ var BILLS_DESCRIPTION = [
3435
+ "List AP invoices as posting-ready vendor bills, each with vendor, invoice number, dates, amount (as invoiced and in the ledger currency), entity, status, holds with dollars and evidence, NetSuite mapping and lines.",
3436
+ "USE WHEN: looking up invoices by vendor or number, or listing the ready or held ones.",
3437
+ "NOT FOR: totals (talonic_ap_overview).",
3438
+ "",
3439
+ "ARGS: `status` ready|held, `entity` (entity code), `reason` above_contract|duplicate|missing_po|vendor_unknown, `query` (vendor, number, filename or contract contains), `limit` (default 500).",
3440
+ "RETURNS: { currency, total, data[] }."
3441
+ ].join("\n");
3442
+ var billsInputSchema = {
3443
+ status: z.enum(["ready", "held"]).optional().describe("Only ready or only held invoices."),
3444
+ entity: z.string().optional().describe("Entity code, e.g. 'HRL'."),
3445
+ reason: z.enum(["above_contract", "duplicate", "missing_po", "vendor_unknown"]).optional().describe("Only invoices held for this reason."),
3446
+ query: z.string().optional().describe("Vendor, invoice number, filename or contract contains."),
3447
+ limit: z.number().int().min(1).max(5e3).optional().describe("Maximum invoices returned.")
3448
+ };
3449
+ function handleBills(getToken, baseUrl, args) {
3450
+ return runTool(
3451
+ () => apiJson(getToken, baseUrl, "GET", "/v1/ap/bills", {
3452
+ params: {
3453
+ status: args.status,
3454
+ entity: args.entity,
3455
+ reason: args.reason,
3456
+ q: args.query,
3457
+ limit: args.limit
3458
+ }
3459
+ })
3460
+ );
3461
+ }
3462
+ var ISSUES_DESCRIPTION2 = [
3463
+ "The AP worklist: every held invoice, why (each hold with its reason, finding, explanation and dollars), and the dollars at stake.",
3464
+ "USE WHEN: deciding what to dispute or fix before posting.",
3465
+ "NOT FOR: invoices ready to post (talonic_ap_bills with status=ready).",
3466
+ "",
3467
+ "ARGS: none.",
3468
+ "RETURNS: { currency, data[] { key, vendor, invoice_number, entity, document_id, filename, amount, at_stake, holds[] } }."
3469
+ ].join("\n");
3470
+ function handleIssues2(getToken, baseUrl) {
3471
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/ap/issues"));
3472
+ }
3473
+ var CONFIG_DESCRIPTION = [
3474
+ "Read the AP configuration: which captured document kinds are bills, the contract register used for entity and cost centre, entities with their system and NetSuite subsidiary, the NetSuite mapping (accounts, departments, terms, currencies, vendors).",
3475
+ "USE WHEN: before changing the configuration, or to explain why an invoice maps the way it does.",
3476
+ "NOT FOR: invoices (talonic_ap_bills).",
3477
+ "",
3478
+ "ARGS: none.",
3479
+ "RETURNS: { config, saved, updated_at }."
3480
+ ].join("\n");
3481
+ function handleConfig(getToken, baseUrl) {
3482
+ return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/ap/config"));
3483
+ }
3484
+ var SAVE_CONFIG_DESCRIPTION = [
3485
+ "Replace the AP configuration with a complete new one (validated by the platform). Run with dry_run first.",
3486
+ "USE WHEN: setting up AP for a workspace or changing the NetSuite mapping.",
3487
+ "NOT FOR: partial edits; read talonic_ap_config, change it, and send the whole object.",
3488
+ "",
3489
+ "ARGS: `config` (the whole configuration object), `dry_run` (validate only).",
3490
+ "RETURNS: { config, saved }. A broken config returns the list of problems."
3491
+ ].join("\n");
3492
+ var saveConfigInputSchema = {
3493
+ config: z.record(z.string(), z.unknown()).describe("The whole AP configuration object (see talonic_ap_config)."),
3494
+ dry_run: z.boolean().optional().describe("Validate only; nothing is saved.")
3495
+ };
3496
+ function handleSaveConfig(getToken, baseUrl, args) {
3497
+ return runTool(
3498
+ () => apiJson(getToken, baseUrl, "PUT", "/v1/ap/config", {
3499
+ body: { config: args.config, dry_run: args.dry_run ?? false }
3500
+ })
3501
+ );
3502
+ }
3503
+ var PREVIEW_DESCRIPTION = [
3504
+ "The exact NetSuite vendor bill records a posting would send (REST Record API `vendorBill` bodies: entity, subsidiary, tranId, tranDate, dueDate, terms, currency, expense / item sublists, memo naming the source document and page), and the invoices left out with the reason. The NetSuite target is a simulated sandbox.",
3505
+ "USE WHEN: showing or checking what would be exported to NetSuite.",
3506
+ "NOT FOR: posting (talonic_ap_netsuite_post).",
3507
+ "",
3508
+ "ARGS: `include_held` (also send held invoices, on payment hold; duplicates are never sent).",
3509
+ "RETURNS: { adapter { mode: 'simulated_sandbox' }, records[] { bill_key, method, path, body }, skipped[], totals }."
3510
+ ].join("\n");
3511
+ var previewInputSchema = {
3512
+ include_held: z.boolean().optional().describe("Send held invoices too, with paymentHold true.")
3513
+ };
3514
+ function handlePreview(getToken, baseUrl, args) {
3515
+ return runTool(
3516
+ () => apiJson(getToken, baseUrl, "GET", "/v1/ap/netsuite/preview", {
3517
+ params: { include_held: args.include_held ? 1 : 0 }
3518
+ })
3519
+ );
3520
+ }
3521
+ var POST_DESCRIPTION = [
3522
+ "Post the vendor bills to the SIMULATED NetSuite sandbox: each record is answered as NetSuite's REST API answers a created record (204 with the new internal id), and the run's posting log is kept. Nothing is sent to any NetSuite account; say so when reporting the result.",
3523
+ "USE WHEN: the user asks to run the NetSuite export or a shadow posting.",
3524
+ "NOT FOR: looking at the payload (talonic_ap_netsuite_preview).",
3525
+ "",
3526
+ "ARGS: `include_held` (held invoices on payment hold), `dry_run` (answer without keeping the run), `limit`.",
3527
+ "RETURNS: { id, records, amount, results[] { bill_key, external_id, internal_id, status, location, payment_hold }, skipped[], log[] }."
3528
+ ].join("\n");
3529
+ var postInputSchema = {
3530
+ include_held: z.boolean().optional().describe("Send held invoices too, with paymentHold true."),
3531
+ dry_run: z.boolean().optional().describe("Do not keep the run."),
3532
+ limit: z.number().int().min(1).max(5e3).optional().describe("At most this many records.")
3533
+ };
3534
+ function handlePost(getToken, baseUrl, args) {
3535
+ return runTool(
3536
+ () => apiJson(getToken, baseUrl, "POST", "/v1/ap/netsuite/post", {
3537
+ body: {
3538
+ include_held: args.include_held ?? false,
3539
+ dry_run: args.dry_run ?? false,
3540
+ ...args.limit ? { limit: args.limit } : {}
3541
+ }
3542
+ })
3543
+ );
3544
+ }
3545
+ var RUNS_DESCRIPTION = [
3546
+ "Simulated NetSuite posting runs: the list, or one run with its internal ids and posting log.",
3547
+ "USE WHEN: checking what an earlier export posted.",
3548
+ "NOT FOR: posting (talonic_ap_netsuite_post).",
3549
+ "",
3550
+ "ARGS: `run_id` (one run; omit for the list).",
3551
+ "RETURNS: { data[] } or one run { results[], skipped[], log[] }."
3552
+ ].join("\n");
3553
+ var runsInputSchema = {
3554
+ run_id: z.string().uuid().optional().describe("One run (from the list).")
3555
+ };
3556
+ function handleRuns(getToken, baseUrl, args) {
3557
+ return runTool(
3558
+ () => apiJson(
3559
+ getToken,
3560
+ baseUrl,
3561
+ "GET",
3562
+ args.run_id ? `/v1/ap/netsuite/runs/${args.run_id}` : "/v1/ap/netsuite/runs"
3563
+ )
3564
+ );
3565
+ }
3566
+ async function probeApAccess(token, baseUrl) {
3567
+ try {
3568
+ const res = await fetch(buildUrl(baseUrl, "/v1/ap/config"), {
3569
+ headers: { Authorization: `Bearer ${token}`, Accept: "application/json" },
3570
+ signal: AbortSignal.timeout(5e3)
3571
+ });
3572
+ return res.ok;
3573
+ } catch {
3574
+ return false;
3575
+ }
3576
+ }
3577
+ function registerApTools(server, getToken, baseUrl) {
3578
+ const tools = [
3579
+ [
3580
+ "talonic_ap_overview",
3581
+ "AP totals",
3582
+ OVERVIEW_DESCRIPTION,
3583
+ {},
3584
+ readOnly2,
3585
+ () => handleOverview(getToken, baseUrl)
3586
+ ],
3587
+ [
3588
+ "talonic_ap_bills",
3589
+ "List AP invoices",
3590
+ BILLS_DESCRIPTION,
3591
+ billsInputSchema,
3592
+ readOnly2,
3593
+ (a) => handleBills(getToken, baseUrl, a)
3594
+ ],
3595
+ [
3596
+ "talonic_ap_issues",
3597
+ "Held AP invoices",
3598
+ ISSUES_DESCRIPTION2,
3599
+ {},
3600
+ readOnly2,
3601
+ () => handleIssues2(getToken, baseUrl)
3602
+ ],
3603
+ [
3604
+ "talonic_ap_config",
3605
+ "Read the AP configuration",
3606
+ CONFIG_DESCRIPTION,
3607
+ {},
3608
+ readOnly2,
3609
+ () => handleConfig(getToken, baseUrl)
3610
+ ],
3611
+ [
3612
+ "talonic_ap_save_config",
3613
+ "Save the AP configuration",
3614
+ SAVE_CONFIG_DESCRIPTION,
3615
+ saveConfigInputSchema,
3616
+ write2(true, true),
3617
+ (a) => handleSaveConfig(getToken, baseUrl, a)
3618
+ ],
3619
+ [
3620
+ "talonic_ap_netsuite_preview",
3621
+ "NetSuite vendor bill payload",
3622
+ PREVIEW_DESCRIPTION,
3623
+ previewInputSchema,
3624
+ readOnly2,
3625
+ (a) => handlePreview(getToken, baseUrl, a)
3626
+ ],
3627
+ [
3628
+ "talonic_ap_netsuite_post",
3629
+ "Post to the simulated NetSuite sandbox",
3630
+ POST_DESCRIPTION,
3631
+ postInputSchema,
3632
+ write2(true),
3633
+ (a) => handlePost(getToken, baseUrl, a)
3634
+ ],
3635
+ [
3636
+ "talonic_ap_netsuite_runs",
3637
+ "NetSuite posting runs",
3638
+ RUNS_DESCRIPTION,
3639
+ runsInputSchema,
3640
+ readOnly2,
3641
+ (a) => handleRuns(getToken, baseUrl, a)
3642
+ ]
3643
+ ];
3644
+ for (const [name, title, description, inputSchema11, annotations, handler] of tools) {
3645
+ server.registerTool(
3646
+ name,
3647
+ { title, description, inputSchema: inputSchema11, annotations: { title, ...annotations } },
3648
+ async (args) => handler(args)
3649
+ );
3650
+ }
3651
+ }
2962
3652
  var DEFAULT_BASE3 = "https://api.talonic.com";
2963
3653
  var TASK_STATUSES = ["available", "claimed", "submitted", "timed_out", "cancelled"];
2964
3654
  var taskId = z.string().uuid().describe("Agent task UUID.");
@@ -4484,7 +5174,7 @@ function registerAskTools(server, getToken, baseUrl) {
4484
5174
 
4485
5175
  // package.json
4486
5176
  var package_default = {
4487
- version: "0.1.81"};
5177
+ version: "0.1.83"};
4488
5178
 
4489
5179
  // src/version.ts
4490
5180
  var VERSION = package_default.version;
@@ -4637,6 +5327,12 @@ function createServer(options) {
4637
5327
  if (options.includeAdminAgentTaskTools) {
4638
5328
  registerAdminAgentTaskTools(server, rawToken, baseUrl);
4639
5329
  }
5330
+ if (options.includeContractsTools) {
5331
+ registerContractsTools(server, rawToken, baseUrl);
5332
+ }
5333
+ if (options.includeApTools) {
5334
+ registerApTools(server, rawToken, baseUrl);
5335
+ }
4640
5336
  registerSchemasResource(server, getTalonic);
4641
5337
  registerWebhooksResource(server, rawToken, baseUrl);
4642
5338
  registerWidgets(server);
@@ -4689,15 +5385,19 @@ async function main(argv = process.argv.slice(2), env = process.env, out = (line
4689
5385
  return 1;
4690
5386
  }
4691
5387
  const baseUrl = env["TALONIC_BASE_URL"];
4692
- const [includeGrowthTools, includeAdminAgentTaskTools] = await Promise.all([
5388
+ const [includeGrowthTools, includeAdminAgentTaskTools, includeContractsTools, includeApTools] = await Promise.all([
4693
5389
  probeGrowthAccess(apiKey, baseUrl),
4694
- probeAgentTaskAdminAccess(apiKey, baseUrl)
5390
+ probeAgentTaskAdminAccess(apiKey, baseUrl),
5391
+ probeContractsAccess(apiKey, baseUrl),
5392
+ probeApAccess(apiKey, baseUrl)
4695
5393
  ]);
4696
5394
  const server = createServer({
4697
5395
  apiKey,
4698
5396
  ...baseUrl ? { baseUrl } : {},
4699
5397
  includeGrowthTools,
4700
- includeAdminAgentTaskTools
5398
+ includeAdminAgentTaskTools,
5399
+ includeContractsTools,
5400
+ includeApTools
4701
5401
  });
4702
5402
  const transport = new StdioServerTransport();
4703
5403
  await server.connect(transport);