@talonic/mcp 0.1.74 → 0.1.76

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
@@ -1832,6 +1832,321 @@ function registerGrowthTools(server, getToken, baseUrl) {
1832
1832
  async (args) => handleGrowthToolsUsage(getToken, baseUrl, args)
1833
1833
  );
1834
1834
  }
1835
+ var DEFAULT_BASE2 = "https://api.talonic.com";
1836
+ var TASK_STATUSES = ["available", "claimed", "submitted", "timed_out", "cancelled"];
1837
+ var taskId = z.string().uuid().describe("Agent task UUID.");
1838
+ var executionEpoch = z.number().int().min(1).max(2147483647).describe("Execution epoch returned by the successful claim. Stale epochs are rejected.");
1839
+ var status = z.enum(TASK_STATUSES).optional().describe("Optional task-status filter.");
1840
+ var limit = z.number().int().min(1).max(100).optional().describe("Page size (default 50).");
1841
+ var cursor = z.string().min(1).optional().describe("Opaque cursor from pagination.next_cursor.");
1842
+ var outputValue = z.object({
1843
+ value: z.json().describe("JSON value matching the field's declared data type."),
1844
+ confidence: z.number().min(0).max(1).optional().describe("Optional confidence from 0 to 1."),
1845
+ reasoning: z.string().max(4e3).optional().describe("Optional concise reasoning for this field, up to 4,000 characters.")
1846
+ });
1847
+ var outputs = z.record(z.string().min(1), outputValue).describe("Output field key to { value, confidence?, reasoning? }. Use only declared fields.");
1848
+ var listInput = { status, limit, cursor };
1849
+ var idInput = { task_id: taskId };
1850
+ var heartbeatInput = { task_id: taskId, execution_epoch: executionEpoch };
1851
+ var submitInput = {
1852
+ task_id: taskId,
1853
+ execution_epoch: executionEpoch,
1854
+ outputs,
1855
+ summary: z.string().max(4e3).optional().describe("Optional result summary, up to 4,000 characters.")
1856
+ };
1857
+ var adminCustomerId = z.string().uuid().describe("Explicit customer/workspace UUID. Payload calls never accept 'all'.");
1858
+ var adminReason = z.string().min(1).max(1e3).describe("Human-readable reason recorded with the cross-tenant access.");
1859
+ var adminTotp = z.string().regex(/^\d{6}$/, "TOTP code must contain exactly 6 digits").describe("Fresh 6-digit TOTP code for step-up authorization.");
1860
+ var adminPayloadAccessInput = {
1861
+ customer_id: adminCustomerId,
1862
+ reason: adminReason,
1863
+ totp_code: adminTotp
1864
+ };
1865
+ function apiUrl(baseUrl, path, query) {
1866
+ const base = (baseUrl ?? DEFAULT_BASE2).replace(/\/$/, "");
1867
+ const url = new URL(`${base}${path}`);
1868
+ for (const [key, value] of Object.entries(query ?? {})) {
1869
+ if (value !== void 0 && value !== "") url.searchParams.set(key, String(value));
1870
+ }
1871
+ return url.toString();
1872
+ }
1873
+ async function agentTaskRequest(getToken, baseUrl, request) {
1874
+ try {
1875
+ const response = await fetch(apiUrl(baseUrl, request.path, request.query), {
1876
+ method: request.method ?? "GET",
1877
+ headers: {
1878
+ Authorization: `Bearer ${getToken()}`,
1879
+ Accept: "application/json",
1880
+ ...request.body === void 0 ? {} : { "Content-Type": "application/json" },
1881
+ ...request.headers
1882
+ },
1883
+ ...request.body === void 0 ? {} : { body: JSON.stringify(request.body) }
1884
+ });
1885
+ if (!response.ok) {
1886
+ const body = await response.text().catch(() => "");
1887
+ return toolError(
1888
+ new Error(`Talonic API error: HTTP ${response.status}${body ? ` \u2014 ${body}` : ""}`)
1889
+ );
1890
+ }
1891
+ return jsonOk(await response.json());
1892
+ } catch (error) {
1893
+ return toolError(error);
1894
+ }
1895
+ }
1896
+ function listQuery(args) {
1897
+ return { status: args.status, limit: args.limit, cursor: args.cursor };
1898
+ }
1899
+ function adminHeaders(args) {
1900
+ return {
1901
+ "x-talonic-reason": args.reason,
1902
+ "x-step-up-code": args.totp_code
1903
+ };
1904
+ }
1905
+ function handleListAgentTasks(getToken, baseUrl, args) {
1906
+ return agentTaskRequest(getToken, baseUrl, {
1907
+ path: "/v1/agent-tasks",
1908
+ query: listQuery(args)
1909
+ });
1910
+ }
1911
+ function handleGetAgentTask(getToken, baseUrl, args) {
1912
+ return agentTaskRequest(getToken, baseUrl, {
1913
+ path: `/v1/agent-tasks/${encodeURIComponent(args.task_id)}`
1914
+ });
1915
+ }
1916
+ function handleClaimAgentTask(getToken, baseUrl, args) {
1917
+ return agentTaskRequest(getToken, baseUrl, {
1918
+ method: "POST",
1919
+ path: `/v1/agent-tasks/${encodeURIComponent(args.task_id)}/claim`
1920
+ });
1921
+ }
1922
+ function handleHeartbeatAgentTask(getToken, baseUrl, args) {
1923
+ return agentTaskRequest(getToken, baseUrl, {
1924
+ method: "POST",
1925
+ path: `/v1/agent-tasks/${encodeURIComponent(args.task_id)}/heartbeat`,
1926
+ body: { execution_epoch: args.execution_epoch }
1927
+ });
1928
+ }
1929
+ function handleSubmitAgentTask(getToken, baseUrl, args) {
1930
+ return agentTaskRequest(getToken, baseUrl, {
1931
+ method: "POST",
1932
+ path: `/v1/agent-tasks/${encodeURIComponent(args.task_id)}/submit`,
1933
+ body: {
1934
+ execution_epoch: args.execution_epoch,
1935
+ outputs: args.outputs,
1936
+ ...args.summary === void 0 ? {} : { summary: args.summary }
1937
+ }
1938
+ });
1939
+ }
1940
+ function handleAdminListAgentTasks(getToken, baseUrl, args) {
1941
+ return agentTaskRequest(getToken, baseUrl, {
1942
+ path: "/v1/agent-tasks/admin/tasks",
1943
+ query: { customerId: args.customer_id ?? "all", ...listQuery(args) }
1944
+ });
1945
+ }
1946
+ function handleAdminGetAgentTask(getToken, baseUrl, args) {
1947
+ return agentTaskRequest(getToken, baseUrl, {
1948
+ path: `/v1/agent-tasks/admin/tasks/${encodeURIComponent(args.task_id)}`,
1949
+ query: { customerId: args.customer_id },
1950
+ headers: adminHeaders(args)
1951
+ });
1952
+ }
1953
+ function handleAdminClaimAgentTask(getToken, baseUrl, args) {
1954
+ return agentTaskRequest(getToken, baseUrl, {
1955
+ method: "POST",
1956
+ path: `/v1/agent-tasks/admin/tasks/${encodeURIComponent(args.task_id)}/claim`,
1957
+ query: { customerId: args.customer_id },
1958
+ headers: adminHeaders(args)
1959
+ });
1960
+ }
1961
+ function handleAdminHeartbeatAgentTask(getToken, baseUrl, args) {
1962
+ return agentTaskRequest(getToken, baseUrl, {
1963
+ method: "POST",
1964
+ path: `/v1/agent-tasks/admin/tasks/${encodeURIComponent(args.task_id)}/heartbeat`,
1965
+ query: { customerId: args.customer_id },
1966
+ headers: adminHeaders(args),
1967
+ body: { execution_epoch: args.execution_epoch }
1968
+ });
1969
+ }
1970
+ function handleAdminSubmitAgentTask(getToken, baseUrl, args) {
1971
+ return agentTaskRequest(getToken, baseUrl, {
1972
+ method: "POST",
1973
+ path: `/v1/agent-tasks/admin/tasks/${encodeURIComponent(args.task_id)}/submit`,
1974
+ query: { customerId: args.customer_id },
1975
+ headers: adminHeaders(args),
1976
+ body: {
1977
+ execution_epoch: args.execution_epoch,
1978
+ outputs: args.outputs,
1979
+ ...args.summary === void 0 ? {} : { summary: args.summary }
1980
+ }
1981
+ });
1982
+ }
1983
+ var READ_ONLY2 = {
1984
+ readOnlyHint: true,
1985
+ destructiveHint: false,
1986
+ openWorldHint: false
1987
+ };
1988
+ var MUTATING = {
1989
+ readOnlyHint: false,
1990
+ destructiveHint: false,
1991
+ openWorldHint: false
1992
+ };
1993
+ var DESCRIPTIONS = {
1994
+ list: [
1995
+ "List Agent-stage tasks visible to this Talonic workspace credential.",
1996
+ "",
1997
+ "USE WHEN: looking for external-agent work to process; begin with status 'available'.",
1998
+ "NOT FOR: reading the immutable task payload (use talonic_get_agent_task) or taking a lease (use talonic_claim_agent_task).",
1999
+ "ARGS: optional status, limit, and cursor. RETURNS: metadata only plus pagination.next_cursor."
2000
+ ].join("\n"),
2001
+ get: [
2002
+ "Fetch one Agent-stage task's immutable input snapshot, instructions, and declared output contract. This disclosure is audited.",
2003
+ "",
2004
+ "USE WHEN: inspecting a listed task before deciding whether to process it.",
2005
+ "NOT FOR: acquiring the task (use talonic_claim_agent_task) or returning results (use talonic_submit_agent_task).",
2006
+ "ARGS: task_id. RETURNS: metadata, input_snapshot, output_contract, instructions, and timeout_fallthrough."
2007
+ ].join("\n"),
2008
+ claim: [
2009
+ "Claim an available Agent-stage task, or reclaim it after its lease expires.",
2010
+ "",
2011
+ "USE WHEN: ready to process a task. Save the returned execution_epoch and lease_expires_at.",
2012
+ "NOT FOR: merely inspecting work (use talonic_get_agent_task) or extending an active lease (use talonic_heartbeat_agent_task).",
2013
+ "A conflicting live claim returns HTTP 409. A successful claim returns the task payload."
2014
+ ].join("\n"),
2015
+ heartbeat: [
2016
+ "Extend the lease on a claimed Agent-stage task.",
2017
+ "",
2018
+ "USE WHEN: processing may continue past lease_expires_at; heartbeat before expiry using the epoch from claim.",
2019
+ "NOT FOR: acquiring a task (use talonic_claim_agent_task) or submitting finished outputs (use talonic_submit_agent_task).",
2020
+ "ARGS: task_id and execution_epoch. Stale or foreign claims return HTTP 409."
2021
+ ].join("\n"),
2022
+ submit: [
2023
+ "Submit declared output fields for a claimed Agent-stage task and resume the parked document.",
2024
+ "",
2025
+ "USE WHEN: processing is complete and every required output in output_contract is ready.",
2026
+ "NOT FOR: undeclared fields or partial lease maintenance (use talonic_heartbeat_agent_task).",
2027
+ "ARGS: task_id, execution_epoch, outputs keyed exactly by declared field key, and optional summary. The platform validates all fields and types transactionally before writing anything."
2028
+ ].join("\n")
2029
+ };
2030
+ function registerAgentTaskTools(server, getToken, baseUrl) {
2031
+ server.registerTool(
2032
+ "talonic_list_agent_tasks",
2033
+ {
2034
+ title: "List Agent Tasks",
2035
+ description: DESCRIPTIONS.list,
2036
+ inputSchema: listInput,
2037
+ annotations: { title: "List Agent Tasks", ...READ_ONLY2 }
2038
+ },
2039
+ async (args) => handleListAgentTasks(getToken, baseUrl, args)
2040
+ );
2041
+ server.registerTool(
2042
+ "talonic_get_agent_task",
2043
+ {
2044
+ title: "Get Agent Task",
2045
+ description: DESCRIPTIONS.get,
2046
+ inputSchema: idInput,
2047
+ annotations: { title: "Get Agent Task", ...READ_ONLY2 }
2048
+ },
2049
+ async (args) => handleGetAgentTask(getToken, baseUrl, args)
2050
+ );
2051
+ server.registerTool(
2052
+ "talonic_claim_agent_task",
2053
+ {
2054
+ title: "Claim Agent Task",
2055
+ description: DESCRIPTIONS.claim,
2056
+ inputSchema: idInput,
2057
+ annotations: { title: "Claim Agent Task", ...MUTATING }
2058
+ },
2059
+ async (args) => handleClaimAgentTask(getToken, baseUrl, args)
2060
+ );
2061
+ server.registerTool(
2062
+ "talonic_heartbeat_agent_task",
2063
+ {
2064
+ title: "Heartbeat Agent Task",
2065
+ description: DESCRIPTIONS.heartbeat,
2066
+ inputSchema: heartbeatInput,
2067
+ annotations: { title: "Heartbeat Agent Task", ...MUTATING }
2068
+ },
2069
+ async (args) => handleHeartbeatAgentTask(getToken, baseUrl, args)
2070
+ );
2071
+ server.registerTool(
2072
+ "talonic_submit_agent_task",
2073
+ {
2074
+ title: "Submit Agent Task",
2075
+ description: DESCRIPTIONS.submit,
2076
+ inputSchema: submitInput,
2077
+ annotations: { title: "Submit Agent Task", ...MUTATING }
2078
+ },
2079
+ async (args) => handleSubmitAgentTask(getToken, baseUrl, args)
2080
+ );
2081
+ }
2082
+ var adminIdInput = { task_id: taskId, ...adminPayloadAccessInput };
2083
+ var adminHeartbeatInput = {
2084
+ task_id: taskId,
2085
+ execution_epoch: executionEpoch,
2086
+ ...adminPayloadAccessInput
2087
+ };
2088
+ var adminSubmitInput = {
2089
+ task_id: taskId,
2090
+ execution_epoch: executionEpoch,
2091
+ outputs,
2092
+ summary: z.string().max(4e3).optional(),
2093
+ ...adminPayloadAccessInput
2094
+ };
2095
+ function registerAdminAgentTaskTools(server, getToken, baseUrl) {
2096
+ server.registerTool(
2097
+ "talonic_admin_list_agent_tasks",
2098
+ {
2099
+ title: "Admin: List Agent Tasks",
2100
+ description: "INTERNAL: list Agent-task metadata across all tenants or one named tenant. NOT FOR payload data; use talonic_admin_get_agent_task with an explicit tenant, reason, and TOTP code.",
2101
+ inputSchema: {
2102
+ customer_id: z.union([z.string().uuid(), z.literal("all")]).optional().describe("Tenant UUID, or 'all' (default) for cross-tenant metadata."),
2103
+ ...listInput
2104
+ },
2105
+ annotations: { title: "Admin: List Agent Tasks", ...READ_ONLY2 }
2106
+ },
2107
+ async (args) => handleAdminListAgentTasks(getToken, baseUrl, args)
2108
+ );
2109
+ server.registerTool(
2110
+ "talonic_admin_get_agent_task",
2111
+ {
2112
+ title: "Admin: Get Agent Task",
2113
+ description: "INTERNAL: fetch one Agent-task payload for an explicit tenant. This audited disclosure requires interactive OAuth, a reason, and fresh TOTP. NOT FOR cross-tenant metadata listing.",
2114
+ inputSchema: adminIdInput,
2115
+ annotations: { title: "Admin: Get Agent Task", ...READ_ONLY2 }
2116
+ },
2117
+ async (args) => handleAdminGetAgentTask(getToken, baseUrl, args)
2118
+ );
2119
+ server.registerTool(
2120
+ "talonic_admin_claim_agent_task",
2121
+ {
2122
+ title: "Admin: Claim Agent Task",
2123
+ description: "INTERNAL: claim or reclaim one Agent task in an explicit tenant. Requires interactive OAuth, reason, and fresh TOTP. NOT FOR metadata-only access.",
2124
+ inputSchema: adminIdInput,
2125
+ annotations: { title: "Admin: Claim Agent Task", ...MUTATING }
2126
+ },
2127
+ async (args) => handleAdminClaimAgentTask(getToken, baseUrl, args)
2128
+ );
2129
+ server.registerTool(
2130
+ "talonic_admin_heartbeat_agent_task",
2131
+ {
2132
+ title: "Admin: Heartbeat Agent Task",
2133
+ description: "INTERNAL: extend one claimed Agent-task lease in an explicit tenant. Requires interactive OAuth, reason, and fresh TOTP. NOT FOR acquiring a task.",
2134
+ inputSchema: adminHeartbeatInput,
2135
+ annotations: { title: "Admin: Heartbeat Agent Task", ...MUTATING }
2136
+ },
2137
+ async (args) => handleAdminHeartbeatAgentTask(getToken, baseUrl, args)
2138
+ );
2139
+ server.registerTool(
2140
+ "talonic_admin_submit_agent_task",
2141
+ {
2142
+ title: "Admin: Submit Agent Task",
2143
+ description: "INTERNAL: submit declared outputs for one claimed Agent task in an explicit tenant. Requires interactive OAuth, reason, and fresh TOTP. NOT FOR undeclared fields.",
2144
+ inputSchema: adminSubmitInput,
2145
+ annotations: { title: "Admin: Submit Agent Task", ...MUTATING }
2146
+ },
2147
+ async (args) => handleAdminSubmitAgentTask(getToken, baseUrl, args)
2148
+ );
2149
+ }
1835
2150
  var DESCRIPTION11 = [
1836
2151
  "Get the OCR-converted markdown text of a document.",
1837
2152
  "",
@@ -1937,9 +2252,384 @@ function registerToMarkdown(server, getTalonic) {
1937
2252
  );
1938
2253
  }
1939
2254
 
2255
+ // src/tools/_http.ts
2256
+ var DEFAULT_BASE3 = "https://api.talonic.com";
2257
+ function buildUrl(baseUrl, path, params = {}) {
2258
+ const qs = new URLSearchParams();
2259
+ for (const [k, v] of Object.entries(params)) {
2260
+ if (v === void 0 || v === "") continue;
2261
+ qs.set(k, String(v));
2262
+ }
2263
+ return `${baseUrl ?? DEFAULT_BASE3}${path}${qs.size ? `?${qs}` : ""}`;
2264
+ }
2265
+ async function apiJson(getToken, baseUrl, method, path, opts = {}) {
2266
+ const url = buildUrl(baseUrl, path, opts.params);
2267
+ const res = await fetch(url, {
2268
+ method,
2269
+ headers: {
2270
+ Authorization: `Bearer ${getToken()}`,
2271
+ Accept: "application/json",
2272
+ ...opts.body !== void 0 ? { "Content-Type": "application/json" } : {}
2273
+ },
2274
+ ...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {}
2275
+ });
2276
+ if (!res.ok) {
2277
+ const text = await res.text().catch(() => "");
2278
+ throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
2279
+ }
2280
+ return await res.json();
2281
+ }
2282
+ async function runTool(fn) {
2283
+ try {
2284
+ return jsonOk(await fn());
2285
+ } catch (err) {
2286
+ return toolError(err);
2287
+ }
2288
+ }
2289
+
2290
+ // src/tools/fields.ts
2291
+ var MATURITIES = ["core", "proven", "candidate"];
2292
+ var maturityArg = z.enum(MATURITIES).optional().describe(
2293
+ "Filter by maturity: `core` (universal, fully trusted \u2014 safe to build on), `proven` (recurring, stable id), `candidate` (newly discovered, may still be merged or renamed)."
2294
+ );
2295
+ var fieldIdArg = z.string().uuid().optional().describe("Field UUID (from talonic_list_fields / talonic_search).");
2296
+ var fieldNameArg = z.string().min(1).optional().describe(
2297
+ "Field NAME instead of an id \u2014 resolved through canonical name, synonyms, merge aliases and the registry's spelling fold, then followed to the live concept. Use the user's wording ('Invoice No', 'Vertragsnummer')."
2298
+ );
2299
+ async function resolveFieldId(getToken, baseUrl, args) {
2300
+ if (args.field_id) return { id: args.field_id };
2301
+ const resolved = await apiJson(getToken, baseUrl, "GET", "/v1/fields/resolve", {
2302
+ params: { name: args.name, follow_redirects: true }
2303
+ });
2304
+ return {
2305
+ id: resolved.field.id,
2306
+ resolution: { matched_by: resolved.matched_by, redirected_from: resolved.redirected_from }
2307
+ };
2308
+ }
2309
+ var LIST_DESCRIPTION = [
2310
+ "List the workspace's Field Registry \u2014 the canonical concepts Talonic has discovered across every ingested document, each with a stable id, maturity level, data type, synonyms and occurrence count.",
2311
+ "",
2312
+ "USE WHEN: you need to know WHAT data exists before querying it, want to pick the right concept for a question, or need the exact field id for talonic_get_field / talonic_field_values.",
2313
+ "NOT FOR: locating a specific document (talonic_search) or filtering documents by a value (talonic_filter).",
2314
+ "",
2315
+ "ARGS: `search` (case-insensitive contains on name), `maturity` (core | proven | candidate \u2014 prefer `core`/`proven` for anything you will build on), `include_superseded` (default false: rows merged into another concept are hidden so you never see two ids for one concept), `limit`, `cursor`.",
2316
+ "RETURNS: data[] of { id, canonical_name, display_name, data_type, maturity, tier, synonyms, description, occurrence_count, superseded_by, links } plus cursor pagination."
2317
+ ].join("\n");
2318
+ var listFieldsInputSchema = {
2319
+ search: z.string().optional().describe("Case-insensitive contains match on canonical_name / display_name."),
2320
+ maturity: maturityArg,
2321
+ include_superseded: z.boolean().optional().describe("Include rows merged into a survivor (they carry `superseded_by`). Default false."),
2322
+ limit: z.number().int().min(1).max(100).optional().describe("Page size (default 20, max 100)."),
2323
+ cursor: z.string().optional().describe("Opaque cursor from pagination.next_cursor.")
2324
+ };
2325
+ async function handleListFields(getToken, baseUrl, args) {
2326
+ return runTool(
2327
+ () => apiJson(getToken, baseUrl, "GET", "/v1/fields", {
2328
+ params: {
2329
+ search: args.search,
2330
+ maturity: args.maturity,
2331
+ include_superseded: args.include_superseded,
2332
+ limit: args.limit,
2333
+ cursor: args.cursor
2334
+ }
2335
+ })
2336
+ );
2337
+ }
2338
+ var GET_DESCRIPTION = [
2339
+ "Get the CONCEPT CARD for one Field Registry field: what it means (curated description + extraction instruction), its synonyms and aliases, maturity, where it occurs (document/occurrence counts, first/last seen, document-type spread), its value distribution (top values with counts, distinct count, examples), schema usage, and identity links (superseded_by, absorbed concepts).",
2340
+ "",
2341
+ "USE WHEN: you must decide whether a field is the right concept for a question, need example values or the value shape before writing a filter, or hold a field NAME from the user and need the live concept behind it.",
2342
+ "NOT FOR: listing many fields (talonic_list_fields) or reading every value (talonic_field_values).",
2343
+ "",
2344
+ "ARGS: exactly one of `field_id` or `name`. Names are resolved through canonical name \u2192 spelling fold \u2192 merge aliases \u2192 synonyms (then case-insensitive fallbacks) and followed to the live concept; the response says which arm matched. `include_history: true` appends the curation trail (merges, renames, maturity moves).",
2345
+ "RETURNS: the card { id, canonical_name, maturity, data_type, definition, identity, occurrence, values, usage, links } plus `resolution` when a name was given and `history` when requested."
2346
+ ].join("\n");
2347
+ var getFieldInputSchema = {
2348
+ field_id: fieldIdArg,
2349
+ name: fieldNameArg,
2350
+ include_history: z.boolean().optional().describe(
2351
+ "Append the concept's curation history (tier changes, merges, renames), newest first."
2352
+ )
2353
+ };
2354
+ async function handleGetField(getToken, baseUrl, args) {
2355
+ if (!args.field_id && !args.name) return validationError("Provide `field_id` or `name`.");
2356
+ if (args.field_id && args.name)
2357
+ return validationError("Provide either `field_id` or `name`, not both.");
2358
+ return runTool(async () => {
2359
+ const { id, resolution } = await resolveFieldId(getToken, baseUrl, args);
2360
+ const card = await apiJson(
2361
+ getToken,
2362
+ baseUrl,
2363
+ "GET",
2364
+ `/v1/fields/${id}/card`,
2365
+ {
2366
+ params: { follow_redirects: true }
2367
+ }
2368
+ );
2369
+ const out = { ...card };
2370
+ if (resolution) out["resolution"] = resolution;
2371
+ if (args.include_history) {
2372
+ out["history"] = await apiJson(getToken, baseUrl, "GET", `/v1/fields/${id}/history`, {
2373
+ params: { limit: 50 }
2374
+ });
2375
+ }
2376
+ return out;
2377
+ });
2378
+ }
2379
+ var VALUES_DESCRIPTION = [
2380
+ "Read a field's CURRENT VALUES across documents, with provenance \u2014 one row per bound occurrence: document id + filename + type, the value, confidence, the raw name it was captured under, the verbatim source text, and the resolution band that bound it.",
2381
+ "",
2382
+ "USE WHEN: the user asks 'what are all the X across my documents', you need to tabulate or aggregate one concept across the corpus, or you want the evidence (source text + document) behind a value.",
2383
+ "NOT FOR: multi-field row-shaped queries over documents (talonic_filter) or one document's full field set (talonic_get_document).",
2384
+ "",
2385
+ "ARGS: exactly one of `field_id` or `name`; optional `document_id` (one document), `value` (case-insensitive contains filter), `limit` (max 100), `cursor`.",
2386
+ "RETURNS: { field_id, canonical_name, concept_ids, data[] of { occurrence_id, document_id, document_filename, value, confidence, provenance{ raw_field_name, source_text, resolved_by, needs_confirmation, via_redirect }, links }, pagination }. Rows are Sources-IAM filtered for the caller."
2387
+ ].join("\n");
2388
+ var fieldValuesInputSchema = {
2389
+ field_id: fieldIdArg,
2390
+ name: fieldNameArg,
2391
+ document_id: z.string().uuid().optional().describe("Only occurrences on this document."),
2392
+ value: z.string().optional().describe("Case-insensitive contains filter on the value text."),
2393
+ limit: z.number().int().min(1).max(100).optional().describe("Page size (default 20, max 100)."),
2394
+ cursor: z.string().optional().describe("Opaque cursor from pagination.next_cursor.")
2395
+ };
2396
+ async function handleFieldValues(getToken, baseUrl, args) {
2397
+ if (!args.field_id && !args.name) return validationError("Provide `field_id` or `name`.");
2398
+ if (args.field_id && args.name)
2399
+ return validationError("Provide either `field_id` or `name`, not both.");
2400
+ return runTool(async () => {
2401
+ const { id, resolution } = await resolveFieldId(getToken, baseUrl, args);
2402
+ const params = {
2403
+ document_id: args.document_id,
2404
+ value: args.value,
2405
+ limit: args.limit,
2406
+ cursor: args.cursor
2407
+ };
2408
+ const page = await apiJson(
2409
+ getToken,
2410
+ baseUrl,
2411
+ "GET",
2412
+ `/v1/fields/${id}/values`,
2413
+ { params }
2414
+ );
2415
+ return resolution ? { ...page, resolution } : page;
2416
+ });
2417
+ }
2418
+ function registerFieldTools(server, getToken, baseUrl) {
2419
+ server.registerTool(
2420
+ "talonic_list_fields",
2421
+ {
2422
+ title: "List registry fields",
2423
+ description: LIST_DESCRIPTION,
2424
+ inputSchema: listFieldsInputSchema,
2425
+ annotations: {
2426
+ readOnlyHint: true,
2427
+ destructiveHint: false,
2428
+ idempotentHint: true,
2429
+ openWorldHint: false
2430
+ }
2431
+ },
2432
+ async (args) => handleListFields(getToken, baseUrl, args)
2433
+ );
2434
+ server.registerTool(
2435
+ "talonic_get_field",
2436
+ {
2437
+ title: "Get a field's concept card",
2438
+ description: GET_DESCRIPTION,
2439
+ inputSchema: getFieldInputSchema,
2440
+ annotations: {
2441
+ readOnlyHint: true,
2442
+ destructiveHint: false,
2443
+ idempotentHint: true,
2444
+ openWorldHint: false
2445
+ }
2446
+ },
2447
+ async (args) => handleGetField(getToken, baseUrl, args)
2448
+ );
2449
+ server.registerTool(
2450
+ "talonic_field_values",
2451
+ {
2452
+ title: "Read a field's values across documents",
2453
+ description: VALUES_DESCRIPTION,
2454
+ inputSchema: fieldValuesInputSchema,
2455
+ annotations: {
2456
+ readOnlyHint: true,
2457
+ destructiveHint: false,
2458
+ idempotentHint: true,
2459
+ openWorldHint: false
2460
+ }
2461
+ },
2462
+ async (args) => handleFieldValues(getToken, baseUrl, args)
2463
+ );
2464
+ }
2465
+ function unwrap(res) {
2466
+ let result = res.content;
2467
+ if (typeof res.content === "string") {
2468
+ try {
2469
+ result = JSON.parse(res.content);
2470
+ } catch {
2471
+ result = res.content;
2472
+ }
2473
+ }
2474
+ const out = { tool: res.tool, result };
2475
+ if (res.citations?.length) out["citations"] = res.citations;
2476
+ if (res.artifacts?.length) out["artifacts"] = res.artifacts;
2477
+ if (res.cards?.length) out["cards"] = res.cards;
2478
+ return out;
2479
+ }
2480
+ var documentIdsArg = z.array(z.string().uuid()).max(1e3).optional().describe("Restrict to these document ids (hard filter, enforced server-side).");
2481
+ var FIND_DESCRIPTION = [
2482
+ "Locate the REAL data behind a natural-language concept before querying anything: semantic + lexical retrieval that resolves a phrase ('payment volume per transaction', 'counterparty', 'Vertragslaufzeit') to the registry fields, values, documents and text passages that carry it \u2014 even when the field is captured under a different name.",
2483
+ "",
2484
+ "USE WHEN: the user asks about a concept and you are not sure which field holds it, when talonic_list_fields / talonic_search came back empty or ambiguous, or when the answer may live in document prose rather than a captured cell.",
2485
+ "NOT FOR: reading a known field's values (talonic_field_values) or filtering by a known field (talonic_filter).",
2486
+ "",
2487
+ "ARGS: `query` (the concept, in the user's words), optional `top_k` (1\u201325, default 10), `document_ids` (hard scope).",
2488
+ "RETURNS: ranked planes \u2014 FIELDS (canonical_name, field ids/keys, maturity/tier, occurrence_count, sample values with their documents), VALUES, DOCUMENTS and PASSAGES \u2014 every item a ready handle for the next call. Read-only, no LLM cost."
2489
+ ].join("\n");
2490
+ var findDataInputSchema = {
2491
+ query: z.string().min(1).describe("The natural-language concept to locate."),
2492
+ top_k: z.number().int().min(1).max(25).optional().describe("Max results per plane (default 10)."),
2493
+ document_ids: documentIdsArg
2494
+ };
2495
+ async function handleFindData(getToken, baseUrl, args) {
2496
+ return runTool(async () => {
2497
+ const res = await apiJson(
2498
+ getToken,
2499
+ baseUrl,
2500
+ "POST",
2501
+ "/v1/agent/tools/find_data/invoke",
2502
+ {
2503
+ body: {
2504
+ args: {
2505
+ query: args.query,
2506
+ ...args.top_k !== void 0 ? { top_k: args.top_k } : {},
2507
+ ...args.document_ids?.length ? { document_scope: args.document_ids } : {}
2508
+ }
2509
+ }
2510
+ }
2511
+ );
2512
+ return unwrap(res);
2513
+ });
2514
+ }
2515
+ var LIST_TOOLS_DESCRIPTION = [
2516
+ "List the platform's agent tool registry \u2014 every retrieval, provenance and analysis primitive the in-product Talonic agent runs on (find_data, describe_data, query_data for read-only SQL over the extracted data, get_document_markdown, workspace_overview, \u2026) with its input schema and whether THIS credential may invoke it.",
2517
+ "",
2518
+ "USE WHEN: you want a capability talonic_* tools do not cover directly (e.g. SQL over the structured data, a workspace overview, cohort discovery) \u2014 list here, then call talonic_invoke_agent_tool with the tool name and its args.",
2519
+ "NOT FOR: discovering fields (talonic_list_fields / talonic_find_data) or documents (talonic_search) \u2014 those are shaped for you.",
2520
+ "",
2521
+ "ARGS: `only_invocable` (default true \u2014 hide tools this key cannot run), `include_schemas` (default true \u2014 include each tool's JSON input schema).",
2522
+ "RETURNS: { tools[] of { name, description, impact, capability, can_invoke, input_schema? }, invocable_count, totalCount }."
2523
+ ].join("\n");
2524
+ var listAgentToolsInputSchema = {
2525
+ only_invocable: z.boolean().optional().describe("Hide tools this credential cannot invoke. Default true."),
2526
+ include_schemas: z.boolean().optional().describe("Include each tool's JSON input schema. Default true.")
2527
+ };
2528
+ async function handleListAgentTools(getToken, baseUrl, args) {
2529
+ return runTool(async () => {
2530
+ const res = await apiJson(getToken, baseUrl, "GET", "/v1/agent/tools");
2531
+ const onlyInvocable = args.only_invocable ?? true;
2532
+ const includeSchemas = args.include_schemas ?? true;
2533
+ const tools = (res.tools ?? []).filter((t) => !onlyInvocable || t.can_invoke).map((t) => {
2534
+ const item = {
2535
+ name: t.name,
2536
+ description: t.description,
2537
+ impact: t.impact,
2538
+ capability: t.capability,
2539
+ can_invoke: t.can_invoke
2540
+ };
2541
+ if (includeSchemas) item["input_schema"] = t.input_schema;
2542
+ return item;
2543
+ });
2544
+ return {
2545
+ tools,
2546
+ invocable_count: res.invocable_count ?? tools.length,
2547
+ totalCount: res.totalCount ?? res.tools?.length ?? 0
2548
+ };
2549
+ });
2550
+ }
2551
+ var INVOKE_DESCRIPTION = [
2552
+ "Invoke ONE named tool from the platform's agent tool registry directly, with no model in the loop \u2014 you choose the arguments. This is how an external agent uses Talonic's retrieval and provenance while driving control flow itself (e.g. `query_data` for a read-only SQL SELECT over the extracted data, `describe_data` for the queryable field list, `get_document_markdown` to read a document's text).",
2553
+ "",
2554
+ "USE WHEN: talonic_list_agent_tools showed a tool with can_invoke: true that does what you need. Pass exactly the `args` its input_schema declares.",
2555
+ "NOT FOR: anything a dedicated talonic_* tool already does (prefer those \u2014 they are shaped for you).",
2556
+ "",
2557
+ "ARGS: `name` (tool name), `args` (object matching the tool's input_schema), optional `document_ids` (hard scope for scope-aware tools).",
2558
+ "RETURNS: { tool, result (the tool's parsed output), citations?, artifacts?, cards? }. Denied capabilities come back as an error naming the capability required; the platform re-checks every call."
2559
+ ].join("\n");
2560
+ var invokeAgentToolInputSchema = {
2561
+ name: z.string().min(1).describe("Tool name from talonic_list_agent_tools, e.g. `query_data`."),
2562
+ args: z.record(z.string(), z.unknown()).optional().describe("Arguments matching the tool's input_schema."),
2563
+ document_ids: documentIdsArg
2564
+ };
2565
+ async function handleInvokeAgentTool(getToken, baseUrl, args) {
2566
+ return runTool(async () => {
2567
+ const res = await apiJson(
2568
+ getToken,
2569
+ baseUrl,
2570
+ "POST",
2571
+ `/v1/agent/tools/${encodeURIComponent(args.name)}/invoke`,
2572
+ {
2573
+ body: {
2574
+ args: args.args ?? {},
2575
+ ...args.document_ids?.length ? { scope: { document_ids: args.document_ids } } : {}
2576
+ }
2577
+ }
2578
+ );
2579
+ return unwrap(res);
2580
+ });
2581
+ }
2582
+ function registerAgentRegistryTools(server, getToken, baseUrl) {
2583
+ server.registerTool(
2584
+ "talonic_find_data",
2585
+ {
2586
+ title: "Find the data behind a concept",
2587
+ description: FIND_DESCRIPTION,
2588
+ inputSchema: findDataInputSchema,
2589
+ annotations: {
2590
+ readOnlyHint: true,
2591
+ destructiveHint: false,
2592
+ idempotentHint: true,
2593
+ openWorldHint: false
2594
+ }
2595
+ },
2596
+ async (args) => handleFindData(getToken, baseUrl, args)
2597
+ );
2598
+ server.registerTool(
2599
+ "talonic_list_agent_tools",
2600
+ {
2601
+ title: "List the platform agent tools",
2602
+ description: LIST_TOOLS_DESCRIPTION,
2603
+ inputSchema: listAgentToolsInputSchema,
2604
+ annotations: {
2605
+ readOnlyHint: true,
2606
+ destructiveHint: false,
2607
+ idempotentHint: true,
2608
+ openWorldHint: false
2609
+ }
2610
+ },
2611
+ async (args) => handleListAgentTools(getToken, baseUrl, args)
2612
+ );
2613
+ server.registerTool(
2614
+ "talonic_invoke_agent_tool",
2615
+ {
2616
+ title: "Invoke a platform agent tool",
2617
+ description: INVOKE_DESCRIPTION,
2618
+ inputSchema: invokeAgentToolInputSchema,
2619
+ annotations: {
2620
+ readOnlyHint: true,
2621
+ destructiveHint: false,
2622
+ idempotentHint: false,
2623
+ openWorldHint: false
2624
+ }
2625
+ },
2626
+ async (args) => handleInvokeAgentTool(getToken, baseUrl, args)
2627
+ );
2628
+ }
2629
+
1940
2630
  // package.json
1941
2631
  var package_default = {
1942
- version: "0.1.74"};
2632
+ version: "0.1.76"};
1943
2633
 
1944
2634
  // src/version.ts
1945
2635
  var VERSION = package_default.version;
@@ -2031,6 +2721,15 @@ function createServer(options) {
2031
2721
  "with that id \u2014 do not ask the user for an id.",
2032
2722
  "talonic_search matches LITERAL keywords: query with one short singular term or an",
2033
2723
  "exact filename, never a sentence; on an empty result retry with a shorter keyword.",
2724
+ "The Field Registry is the source of truth for WHAT data exists: talonic_find_data",
2725
+ "resolves a concept in the user's words to the fields/documents that carry it,",
2726
+ "talonic_list_fields / talonic_get_field describe concepts (prefer maturity core or",
2727
+ "proven for anything you build on), talonic_field_values reads one concept across all",
2728
+ "documents with provenance. Anything else the in-product agent can do is reachable via",
2729
+ "talonic_list_agent_tools + talonic_invoke_agent_tool (e.g. query_data for SQL).",
2730
+ "For Agent-stage work, follow list -> get -> claim -> heartbeat while needed ->",
2731
+ "submit. Preserve the execution_epoch from claim and return only fields declared",
2732
+ "in the task output_contract; never continue after a lease or epoch conflict.",
2034
2733
  "Prefer acting over explaining."
2035
2734
  ].join(" ")
2036
2735
  }
@@ -2054,9 +2753,15 @@ function createServer(options) {
2054
2753
  registerGetPricing(server, getTalonic);
2055
2754
  registerGetUsage(server, getTalonic);
2056
2755
  registerRequestUpload(server, getToken, baseUrl);
2756
+ registerFieldTools(server, getToken, baseUrl);
2757
+ registerAgentRegistryTools(server, getToken, baseUrl);
2758
+ registerAgentTaskTools(server, getToken, baseUrl);
2057
2759
  if (options.includeGrowthTools) {
2058
2760
  registerGrowthTools(server, getToken, baseUrl);
2059
2761
  }
2762
+ if (options.includeAdminAgentTaskTools) {
2763
+ registerAdminAgentTaskTools(server, getToken, baseUrl);
2764
+ }
2060
2765
  registerSchemasResource(server, getTalonic);
2061
2766
  registerWebhooksResource(server, getToken, baseUrl);
2062
2767
  registerWidgets(server);