@talonic/mcp 0.1.77 → 0.1.79
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/CHANGELOG.md +199 -15
- package/README.md +15 -8
- package/dist/content.js +812 -2
- package/dist/content.js.map +1 -1
- package/dist/http-server.js +1824 -251
- package/dist/http-server.js.map +1 -1
- package/dist/index.js +1805 -234
- package/dist/index.js.map +1 -1
- package/dist/server.js +1807 -235
- package/dist/server.js.map +1 -1
- package/package.json +4 -1
package/dist/server.js
CHANGED
|
@@ -6,6 +6,115 @@ import { Talonic, TalonicError } from '@talonic/node';
|
|
|
6
6
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
|
+
function jsonOk(value) {
|
|
10
|
+
const result = {
|
|
11
|
+
content: [
|
|
12
|
+
{
|
|
13
|
+
type: "text",
|
|
14
|
+
text: JSON.stringify(value, null, 2)
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
};
|
|
18
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
19
|
+
result["structuredContent"] = value;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function validationError(message) {
|
|
24
|
+
return {
|
|
25
|
+
isError: true,
|
|
26
|
+
content: [{ type: "text", text: `Validation error: ${message}` }]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function toolError(err) {
|
|
30
|
+
if (err instanceof TalonicError) {
|
|
31
|
+
const lines = [
|
|
32
|
+
`Talonic API error: ${err.message}`,
|
|
33
|
+
`code: ${err.code}`,
|
|
34
|
+
`status: ${err.status}`
|
|
35
|
+
];
|
|
36
|
+
if (err.requestId) lines.push(`request_id: ${err.requestId}`);
|
|
37
|
+
return {
|
|
38
|
+
isError: true,
|
|
39
|
+
content: [{ type: "text", text: lines.join("\n") }]
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
isError: true,
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: "text",
|
|
47
|
+
text: `Unexpected error: ${err instanceof Error ? err.message : String(err)}`
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/tools/_http.ts
|
|
54
|
+
var DEFAULT_BASE = "https://api.talonic.com";
|
|
55
|
+
function withFetch(getToken, fetchImpl) {
|
|
56
|
+
const source = (() => getToken());
|
|
57
|
+
source.fetch = fetchImpl;
|
|
58
|
+
return source;
|
|
59
|
+
}
|
|
60
|
+
function resolveFetch(getToken) {
|
|
61
|
+
return getToken.fetch ?? fetch;
|
|
62
|
+
}
|
|
63
|
+
function buildUrl(baseUrl, path, params = {}) {
|
|
64
|
+
const qs = new URLSearchParams();
|
|
65
|
+
for (const [k, v] of Object.entries(params)) {
|
|
66
|
+
if (v === void 0 || v === "") continue;
|
|
67
|
+
qs.set(k, String(v));
|
|
68
|
+
}
|
|
69
|
+
return `${baseUrl ?? DEFAULT_BASE}${path}${qs.size ? `?${qs}` : ""}`;
|
|
70
|
+
}
|
|
71
|
+
async function apiJson(getToken, baseUrl, method, path, opts = {}) {
|
|
72
|
+
const url = buildUrl(baseUrl, path, opts.params);
|
|
73
|
+
const res = await resolveFetch(getToken)(url, {
|
|
74
|
+
method,
|
|
75
|
+
headers: {
|
|
76
|
+
Authorization: `Bearer ${getToken()}`,
|
|
77
|
+
Accept: "application/json",
|
|
78
|
+
...opts.body !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
79
|
+
},
|
|
80
|
+
...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {},
|
|
81
|
+
...opts.signal ? { signal: opts.signal } : {}
|
|
82
|
+
});
|
|
83
|
+
if (!res.ok) {
|
|
84
|
+
const text = await res.text().catch(() => "");
|
|
85
|
+
throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
|
|
86
|
+
}
|
|
87
|
+
return await res.json();
|
|
88
|
+
}
|
|
89
|
+
async function apiForm(getToken, baseUrl, path, fields) {
|
|
90
|
+
const form = new FormData();
|
|
91
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
92
|
+
if (value === void 0) continue;
|
|
93
|
+
if (Array.isArray(value)) for (const item of value) form.append(key, item);
|
|
94
|
+
else form.append(key, value);
|
|
95
|
+
}
|
|
96
|
+
const res = await resolveFetch(getToken)(buildUrl(baseUrl, path), {
|
|
97
|
+
method: "POST",
|
|
98
|
+
headers: { Authorization: `Bearer ${getToken()}`, Accept: "application/json" },
|
|
99
|
+
body: form
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
const text = await res.text().catch(() => "");
|
|
103
|
+
throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
|
|
104
|
+
}
|
|
105
|
+
return await res.json();
|
|
106
|
+
}
|
|
107
|
+
function sleep(ms) {
|
|
108
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
109
|
+
}
|
|
110
|
+
async function runTool(fn) {
|
|
111
|
+
try {
|
|
112
|
+
return jsonOk(await fn());
|
|
113
|
+
} catch (err) {
|
|
114
|
+
return toolError(err);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
9
118
|
// src/resources/schemas-resource.ts
|
|
10
119
|
function registerSchemasResource(server, getTalonic) {
|
|
11
120
|
server.registerResource(
|
|
@@ -66,7 +175,7 @@ function registerWebhooksResource(server, getToken, baseUrl) {
|
|
|
66
175
|
await Promise.all(
|
|
67
176
|
WEBHOOK_INFO_ENDPOINTS.map(async ({ path, key }) => {
|
|
68
177
|
try {
|
|
69
|
-
const res = await
|
|
178
|
+
const res = await resolveFetch(getToken)(`${base}${path}`, {
|
|
70
179
|
headers: {
|
|
71
180
|
Authorization: `Bearer ${token}`,
|
|
72
181
|
Accept: "application/json"
|
|
@@ -114,14 +223,131 @@ var WIDGET_URIS = {
|
|
|
114
223
|
getBalance: "ui://widget/balance.html",
|
|
115
224
|
getPricing: "ui://widget/pricing.html",
|
|
116
225
|
getUsage: "ui://widget/usage.html",
|
|
117
|
-
requestUpload: "ui://widget/upload-link.html"
|
|
226
|
+
requestUpload: "ui://widget/upload-link.html",
|
|
227
|
+
listFields: "ui://widget/field-list.html",
|
|
228
|
+
getField: "ui://widget/field-card.html",
|
|
229
|
+
fieldValues: "ui://widget/field-values.html",
|
|
230
|
+
findData: "ui://widget/find-data.html",
|
|
231
|
+
listAgentTools: "ui://widget/agent-tools.html",
|
|
232
|
+
invokeAgentTool: "ui://widget/agent-tool-result.html",
|
|
233
|
+
listAgentTasks: "ui://widget/agent-task-list.html",
|
|
234
|
+
getAgentTask: "ui://widget/agent-task.html",
|
|
235
|
+
claimAgentTask: "ui://widget/agent-task-claim.html",
|
|
236
|
+
heartbeatAgentTask: "ui://widget/agent-task-heartbeat.html",
|
|
237
|
+
submitAgentTask: "ui://widget/agent-task-submitted.html",
|
|
238
|
+
listSpecs: "ui://widget/spec-list.html",
|
|
239
|
+
getSpec: "ui://widget/spec-card.html",
|
|
240
|
+
runSpec: "ui://widget/run-started.html",
|
|
241
|
+
getRun: "ui://widget/run-status.html",
|
|
242
|
+
getRunResults: "ui://widget/run-results.html",
|
|
243
|
+
ask: "ui://widget/answer.html",
|
|
244
|
+
getAnswer: "ui://widget/answer-polled.html",
|
|
245
|
+
listDecisionTasks: "ui://widget/decision-task-list.html",
|
|
246
|
+
claimDecisionTask: "ui://widget/decision-bundle.html",
|
|
247
|
+
readDecisionPackage: "ui://widget/decision-package.html",
|
|
248
|
+
heartbeatDecisionTask: "ui://widget/decision-task-heartbeat.html",
|
|
249
|
+
submitDecisionTask: "ui://widget/decision-task-submitted.html",
|
|
250
|
+
releaseDecisionTask: "ui://widget/decision-task-released.html",
|
|
251
|
+
failDecisionTask: "ui://widget/decision-task-failed.html"
|
|
252
|
+
};
|
|
253
|
+
WIDGET_URIS.extract;
|
|
254
|
+
var TOOL_INVOCATION_STATUS = {
|
|
255
|
+
extract: { invoking: "Extracting structured data\u2026", invoked: "Extraction complete" },
|
|
256
|
+
search: { invoking: "Searching the workspace\u2026", invoked: "Search results ready" },
|
|
257
|
+
filter: { invoking: "Filtering documents by field values\u2026", invoked: "Filter results ready" },
|
|
258
|
+
getDocument: { invoking: "Fetching document details\u2026", invoked: "Document details ready" },
|
|
259
|
+
toMarkdown: { invoking: "Converting document to markdown\u2026", invoked: "Markdown ready" },
|
|
260
|
+
listSchemas: { invoking: "Loading saved schemas\u2026", invoked: "Schemas listed" },
|
|
261
|
+
saveSchema: { invoking: "Saving schema\u2026", invoked: "Schema saved" },
|
|
262
|
+
getBalance: { invoking: "Checking credit balance\u2026", invoked: "Balance ready" },
|
|
263
|
+
getPricing: { invoking: "Loading pricing catalog\u2026", invoked: "Pricing ready" },
|
|
264
|
+
getUsage: { invoking: "Loading usage breakdown\u2026", invoked: "Usage ready" },
|
|
265
|
+
requestUpload: { invoking: "Preparing upload link\u2026", invoked: "Upload link ready" },
|
|
266
|
+
listFields: { invoking: "Loading the Field Registry\u2026", invoked: "Fields listed" },
|
|
267
|
+
getField: { invoking: "Loading field concept card\u2026", invoked: "Field card ready" },
|
|
268
|
+
fieldValues: {
|
|
269
|
+
invoking: "Reading field values across documents\u2026",
|
|
270
|
+
invoked: "Field values ready"
|
|
271
|
+
},
|
|
272
|
+
findData: { invoking: "Locating data behind the concept\u2026", invoked: "Matching data found" },
|
|
273
|
+
listAgentTools: { invoking: "Listing platform agent tools\u2026", invoked: "Agent tools listed" },
|
|
274
|
+
invokeAgentTool: { invoking: "Running platform agent tool\u2026", invoked: "Agent tool result ready" },
|
|
275
|
+
listAgentTasks: { invoking: "Loading agent task worklist\u2026", invoked: "Agent tasks listed" },
|
|
276
|
+
getAgentTask: { invoking: "Loading agent task\u2026", invoked: "Agent task ready" },
|
|
277
|
+
claimAgentTask: { invoking: "Claiming agent task\u2026", invoked: "Agent task claimed" },
|
|
278
|
+
heartbeatAgentTask: { invoking: "Extending task lease\u2026", invoked: "Lease extended" },
|
|
279
|
+
submitAgentTask: { invoking: "Submitting task outputs\u2026", invoked: "Task submitted" },
|
|
280
|
+
listSpecs: { invoking: "Loading Specs\u2026", invoked: "Specs listed" },
|
|
281
|
+
getSpec: { invoking: "Loading Spec structure\u2026", invoked: "Spec structure ready" },
|
|
282
|
+
runSpec: { invoking: "Starting the Spec run\u2026", invoked: "Run started" },
|
|
283
|
+
getRun: { invoking: "Checking run progress\u2026", invoked: "Run progress ready" },
|
|
284
|
+
getRunResults: { invoking: "Loading run results\u2026", invoked: "Run results ready" },
|
|
285
|
+
ask: { invoking: "Asking Talonic over your documents\u2026", invoked: "Answer ready" },
|
|
286
|
+
getAnswer: { invoking: "Checking for the answer\u2026", invoked: "Answer status ready" },
|
|
287
|
+
listDecisionTasks: { invoking: "Loading decision tasks\u2026", invoked: "Decision tasks listed" },
|
|
288
|
+
claimDecisionTask: { invoking: "Claiming decision task\u2026", invoked: "Decision task claimed" },
|
|
289
|
+
readDecisionPackage: { invoking: "Reading the decision package\u2026", invoked: "Package page ready" },
|
|
290
|
+
heartbeatDecisionTask: { invoking: "Extending the decision lease\u2026", invoked: "Lease extended" },
|
|
291
|
+
submitDecisionTask: { invoking: "Submitting the decision\u2026", invoked: "Decision submitted" },
|
|
292
|
+
releaseDecisionTask: { invoking: "Releasing the decision task\u2026", invoked: "Task released" },
|
|
293
|
+
failDecisionTask: {
|
|
294
|
+
invoking: "Reporting the task as undecidable\u2026",
|
|
295
|
+
invoked: "Task failed"
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
var WIDGET_DESCRIPTIONS = {
|
|
299
|
+
extract: "Card showing the extracted fields with per-field confidence, the source document, and the credit cost of the extraction.",
|
|
300
|
+
search: "Card listing the documents, fields, schemas and sources that matched the query, grouped by type.",
|
|
301
|
+
filter: "Table of documents whose extracted field values matched the filter, plus any API warnings about field types.",
|
|
302
|
+
getDocument: "Card with one document's metadata, processing status, and triage flags.",
|
|
303
|
+
toMarkdown: "Scrollable view of a document's OCR-converted markdown text.",
|
|
304
|
+
listSchemas: "Table of the workspace's saved extraction schemas with their field counts.",
|
|
305
|
+
saveSchema: "Confirmation card for a newly saved reusable schema.",
|
|
306
|
+
getBalance: "Card with the workspace credit balance, EUR value, tier, 30-day burn and projected runway.",
|
|
307
|
+
getPricing: "Table of Talonic's per-unit credit pricing with EUR values, free-tier badges and multipliers.",
|
|
308
|
+
getUsage: "Breakdown of credits consumed per function over the trailing window, with proportion bars.",
|
|
309
|
+
requestUpload: "Card with the browser upload link the user must open to add their file, plus the document id and expiry.",
|
|
310
|
+
listFields: "Table of Field Registry concepts with data type, maturity (core, proven, candidate) and occurrence counts.",
|
|
311
|
+
getField: "Concept card for one registry field: definition, synonyms, occurrence statistics, top values and schema usage.",
|
|
312
|
+
fieldValues: "Table of one field's current values across documents with confidence and source-text provenance.",
|
|
313
|
+
findData: "Ranked matches for a natural-language concept across four planes: fields, values, documents and passages.",
|
|
314
|
+
listAgentTools: "Table of the platform agent tool registry with each tool's impact, capability and whether this key may invoke it.",
|
|
315
|
+
invokeAgentTool: "Result of one platform agent tool call, rendered as a table, key-value tiles or a JSON tree, with citations.",
|
|
316
|
+
listAgentTasks: "Worklist of Agent-stage tasks with status, document, lease expiry, timeout and execution epoch.",
|
|
317
|
+
getAgentTask: "Card for one Agent-stage task: status, timing, instructions, declared output contract and the input snapshot.",
|
|
318
|
+
claimAgentTask: "Lease card confirming the claim: execution epoch to keep, lease expiry, and the task's instructions and contract.",
|
|
319
|
+
heartbeatAgentTask: "Lease card confirming the lease was extended, with the new expiry and execution epoch.",
|
|
320
|
+
submitAgentTask: "Confirmation that the declared outputs were submitted and the parked document resumed its pipeline.",
|
|
321
|
+
listSpecs: "Table of the workspace's Specs (configured pipelines) with version state, field and stage counts, and last update.",
|
|
322
|
+
getSpec: "Card for one Spec: version state, the schema it materializes onto, the rail's stages in order, the compiled phases, and its fields.",
|
|
323
|
+
runSpec: "Confirmation that a Spec run started: run kind, input count, spec/pipeline/run ids, status, and how to poll it.",
|
|
324
|
+
getRun: "Progress card for a Spec run: normalised status, documents completed / total / errors, and per-phase progress when available.",
|
|
325
|
+
getRunResults: "Table of a Spec run's structured rows \u2014 one row per document with the Spec's fields \u2014 plus review holds and pagination.",
|
|
326
|
+
ask: "Cited answer card: the answer text, verification verdict, source citations, artifacts and credit usage.",
|
|
327
|
+
getAnswer: "Polled answer card: the same cited answer with verification and citations, or a still-processing notice.",
|
|
328
|
+
listDecisionTasks: "Worklist of an External-mode app's decision tasks with status, run, epoch, lease expiry and SLA deadline.",
|
|
329
|
+
claimDecisionTask: "Claim bundle: the task's lease and epoch, the output contract to satisfy, precedents, and the input-package descriptor with its source documents.",
|
|
330
|
+
readDecisionPackage: "One page of a claimed task's frozen input package: the records to decide from, page position, and the source documents on the first page.",
|
|
331
|
+
heartbeatDecisionTask: "Lease card confirming the decision task's lease was extended, with the new expiry and SLA deadline.",
|
|
332
|
+
submitDecisionTask: "Confirmation that the decision was submitted and verified; the run resumes.",
|
|
333
|
+
releaseDecisionTask: "Confirmation that the decision task was released back to available for another claimant.",
|
|
334
|
+
failDecisionTask: "Confirmation that the task was reported undecidable: a Human Review is raised and the app's fallback applies."
|
|
118
335
|
};
|
|
119
|
-
|
|
336
|
+
function widgetToolMeta(key) {
|
|
337
|
+
const uri = WIDGET_URIS[key];
|
|
338
|
+
const status3 = TOOL_INVOCATION_STATUS[key];
|
|
339
|
+
return {
|
|
340
|
+
ui: { resourceUri: uri },
|
|
341
|
+
"openai/outputTemplate": uri,
|
|
342
|
+
"openai/toolInvocation/invoking": status3.invoking,
|
|
343
|
+
"openai/toolInvocation/invoked": status3.invoked
|
|
344
|
+
};
|
|
345
|
+
}
|
|
120
346
|
|
|
121
347
|
// src/widgets/shared.ts
|
|
122
348
|
var WIDGET_DOMAIN = "https://talonic.com";
|
|
123
|
-
function widgetMeta() {
|
|
124
|
-
|
|
349
|
+
function widgetMeta(description) {
|
|
350
|
+
const meta = {
|
|
125
351
|
ui: {
|
|
126
352
|
domain: WIDGET_DOMAIN,
|
|
127
353
|
csp: {
|
|
@@ -135,8 +361,11 @@ function widgetMeta() {
|
|
|
135
361
|
connect_domains: [],
|
|
136
362
|
resource_domains: [],
|
|
137
363
|
redirect_domains: []
|
|
138
|
-
}
|
|
364
|
+
},
|
|
365
|
+
"openai/widgetPrefersBorder": true
|
|
139
366
|
};
|
|
367
|
+
if (description) meta["openai/widgetDescription"] = description;
|
|
368
|
+
return meta;
|
|
140
369
|
}
|
|
141
370
|
var BASE_CSS = `
|
|
142
371
|
:root {
|
|
@@ -196,6 +425,20 @@ var BASE_CSS = `
|
|
|
196
425
|
padding: 12px; max-height: 360px; overflow: auto; white-space: pre-wrap;
|
|
197
426
|
word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
198
427
|
font-size: 12px; }
|
|
428
|
+
.chip.good { background: rgba(22,163,74,.12); color: var(--good); }
|
|
429
|
+
.chip.warn { background: rgba(217,119,6,.14); color: var(--warn); }
|
|
430
|
+
.chip.bad { background: rgba(220,38,38,.12); color: var(--bad); }
|
|
431
|
+
.chip.info { background: rgba(79,70,229,.12); color: var(--accent); }
|
|
432
|
+
.plane { margin-top: 14px; }
|
|
433
|
+
.plane .subtitle { margin-bottom: 4px; }
|
|
434
|
+
.num { text-align: right; }
|
|
435
|
+
.tree-body { padding-left: 12px; border-left: 1px solid var(--border); margin: 2px 0 2px 2px; }
|
|
436
|
+
.node { padding: 2px 0; font-size: 13px; word-break: break-word; }
|
|
437
|
+
.node .k, .tree-body summary .k { color: var(--muted); }
|
|
438
|
+
details.tree { margin: 2px 0; }
|
|
439
|
+
details.tree > summary { cursor: pointer; font-size: 13px; list-style: none; }
|
|
440
|
+
details.tree > summary::before { content: "\u25B8 "; color: var(--muted); }
|
|
441
|
+
details.tree[open] > summary::before { content: "\u25BE "; }
|
|
199
442
|
`;
|
|
200
443
|
var HELPERS_JS = `
|
|
201
444
|
var root = document.getElementById("root");
|
|
@@ -226,6 +469,102 @@ var HELPERS_JS = `
|
|
|
226
469
|
if (navigator.clipboard) navigator.clipboard.writeText(text);
|
|
227
470
|
});
|
|
228
471
|
}
|
|
472
|
+
function chip(text, tone) {
|
|
473
|
+
if (text == null || text === "") return "";
|
|
474
|
+
return '<span class="chip' + (tone ? " " + tone : "") + '">' + esc(text) + '</span>';
|
|
475
|
+
}
|
|
476
|
+
function clamp(s, n) {
|
|
477
|
+
var t = String(s == null ? "" : s);
|
|
478
|
+
return t.length > n ? t.slice(0, n - 1) + "\u2026" : t;
|
|
479
|
+
}
|
|
480
|
+
function shortId(id) {
|
|
481
|
+
var s = String(id == null ? "" : id);
|
|
482
|
+
if (!s) return "\u2014";
|
|
483
|
+
return s.length > 8 ? s.slice(0, 8) : s;
|
|
484
|
+
}
|
|
485
|
+
function idChip(id) {
|
|
486
|
+
var s = String(id == null ? "" : id);
|
|
487
|
+
if (!s) return '<span class="muted">\u2014</span>';
|
|
488
|
+
return '<span class="mono" title="' + esc(s) + '">' + esc(shortId(s)) + '</span>';
|
|
489
|
+
}
|
|
490
|
+
function relTime(iso) {
|
|
491
|
+
if (!iso) return "\u2014";
|
|
492
|
+
var t = Date.parse(iso);
|
|
493
|
+
if (isNaN(t)) return String(iso);
|
|
494
|
+
var d = Math.round((t - Date.now()) / 1000);
|
|
495
|
+
var a = Math.abs(d);
|
|
496
|
+
var n, u;
|
|
497
|
+
if (a < 60) { n = a; u = "s"; }
|
|
498
|
+
else if (a < 3600) { n = Math.round(a / 60); u = "m"; }
|
|
499
|
+
else if (a < 86400) { n = Math.round(a / 3600); u = "h"; }
|
|
500
|
+
else { n = Math.round(a / 86400); u = "d"; }
|
|
501
|
+
return d >= 0 ? "in " + n + u : n + u + " ago";
|
|
502
|
+
}
|
|
503
|
+
function isFlat(obj) {
|
|
504
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return false;
|
|
505
|
+
return Object.keys(obj).every(function (k) { var v = obj[k]; return v == null || typeof v !== "object"; });
|
|
506
|
+
}
|
|
507
|
+
function isRowArray(v) {
|
|
508
|
+
return Array.isArray(v) && v.length > 0 && v.every(function (r) { return !!r && typeof r === "object" && !Array.isArray(r); });
|
|
509
|
+
}
|
|
510
|
+
function dataTable(rows, columns) {
|
|
511
|
+
if (!Array.isArray(rows) || !rows.length) return "";
|
|
512
|
+
var cols = columns ? columns.slice() : [];
|
|
513
|
+
if (!columns) {
|
|
514
|
+
rows.forEach(function (r) {
|
|
515
|
+
if (r && typeof r === "object" && !Array.isArray(r)) {
|
|
516
|
+
Object.keys(r).forEach(function (k) { if (cols.indexOf(k) < 0) cols.push(k); });
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
var extraCols = cols.length > 12 ? cols.length - 12 : 0;
|
|
521
|
+
cols = cols.slice(0, 12);
|
|
522
|
+
var shown = rows.slice(0, 50);
|
|
523
|
+
var html = '<table><thead><tr>' + cols.map(function (c) { return '<th>' + esc(c) + '</th>'; }).join("") + '</tr></thead><tbody>';
|
|
524
|
+
shown.forEach(function (r) {
|
|
525
|
+
html += '<tr>' + cols.map(function (c) {
|
|
526
|
+
var v = r && typeof r === "object" && !Array.isArray(r) ? r[c] : r;
|
|
527
|
+
var cell = v != null && typeof v === "object" ? clamp(JSON.stringify(v), 80) : fmt(v);
|
|
528
|
+
return '<td class="val">' + esc(cell) + '</td>';
|
|
529
|
+
}).join("") + '</tr>';
|
|
530
|
+
});
|
|
531
|
+
html += '</tbody></table>';
|
|
532
|
+
var more = [];
|
|
533
|
+
if (rows.length > shown.length) more.push("+" + (rows.length - shown.length) + " more rows");
|
|
534
|
+
if (extraCols) more.push("+" + extraCols + " more columns");
|
|
535
|
+
if (more.length) html += '<div class="muted small" style="margin-top:6px">' + esc(more.join(" \xB7 ")) + '</div>';
|
|
536
|
+
return html;
|
|
537
|
+
}
|
|
538
|
+
function kvTiles(obj) {
|
|
539
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return "";
|
|
540
|
+
var keys = Object.keys(obj);
|
|
541
|
+
if (!keys.length) return "";
|
|
542
|
+
return '<div class="grid">' + keys.map(function (k) {
|
|
543
|
+
var v = obj[k];
|
|
544
|
+
var text = v != null && typeof v === "object" ? clamp(JSON.stringify(v), 120) : fmt(v);
|
|
545
|
+
return '<div class="kv"><span class="k">' + esc(k) + '</span><span class="val">' + esc(text === "" ? "\u2014" : text) + '</span></div>';
|
|
546
|
+
}).join("") + '</div>';
|
|
547
|
+
}
|
|
548
|
+
function jsonTree(value, depth, budget) {
|
|
549
|
+
depth = depth || 0;
|
|
550
|
+
budget = budget || { n: 400 };
|
|
551
|
+
if (budget.n-- <= 0) return '<span class="muted">\u2026</span>';
|
|
552
|
+
if (value == null || typeof value !== "object") return '<span class="val mono">' + esc(fmt(value)) + '</span>';
|
|
553
|
+
if (depth >= 6) return '<span class="muted">' + esc(clamp(JSON.stringify(value), 80)) + '</span>';
|
|
554
|
+
var isArr = Array.isArray(value);
|
|
555
|
+
var keys = isArr ? value.map(function (_, i) { return String(i); }) : Object.keys(value);
|
|
556
|
+
if (!keys.length) return '<span class="muted">' + (isArr ? "[]" : "{}") + '</span>';
|
|
557
|
+
var inner = keys.map(function (k) {
|
|
558
|
+
var v = value[k];
|
|
559
|
+
var label = '<span class="k mono">' + esc(k) + '</span>';
|
|
560
|
+
if (v == null || typeof v !== "object") {
|
|
561
|
+
return '<div class="node">' + label + ' <span class="val mono">' + esc(fmt(v)) + '</span></div>';
|
|
562
|
+
}
|
|
563
|
+
var size = Array.isArray(v) ? "[" + v.length + "]" : "{" + Object.keys(v).length + "}";
|
|
564
|
+
return '<details class="tree"' + (depth < 1 ? " open" : "") + '><summary>' + label + ' <span class="muted small">' + size + '</span></summary>' + jsonTree(v, depth + 1, budget) + '</details>';
|
|
565
|
+
}).join("");
|
|
566
|
+
return '<div class="tree-body">' + inner + '</div>';
|
|
567
|
+
}
|
|
229
568
|
`;
|
|
230
569
|
var BOOTSTRAP_JS = `
|
|
231
570
|
function payloadFromHost() {
|
|
@@ -289,7 +628,7 @@ function registerWidget(server, opts) {
|
|
|
289
628
|
uri: opts.uri,
|
|
290
629
|
mimeType: WIDGET_MIME,
|
|
291
630
|
text: opts.html,
|
|
292
|
-
_meta: widgetMeta()
|
|
631
|
+
_meta: widgetMeta(opts.description)
|
|
293
632
|
}
|
|
294
633
|
]
|
|
295
634
|
})
|
|
@@ -688,134 +1027,939 @@ var WIDGET_HTML11 = buildWidgetHtml({
|
|
|
688
1027
|
renderBody: RENDER_BODY11
|
|
689
1028
|
});
|
|
690
1029
|
|
|
1030
|
+
// src/widgets/field-list.ts
|
|
1031
|
+
function getFieldListWidgetHtml() {
|
|
1032
|
+
return WIDGET_HTML12;
|
|
1033
|
+
}
|
|
1034
|
+
var RENDER_BODY12 = `
|
|
1035
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1036
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1037
|
+
if (!rows.length) { empty("No fields match."); return; }
|
|
1038
|
+
function maturityTone(m) { return m === "core" ? "good" : m === "proven" ? "info" : m === "candidate" ? "warn" : ""; }
|
|
1039
|
+
var body = rows.map(function (f) {
|
|
1040
|
+
f = f && typeof f === "object" ? f : {};
|
|
1041
|
+
var name = f.display_name || f.canonical_name || f.id || "(field)";
|
|
1042
|
+
var sup = f.superseded_by ? ' <span class="chip bad" title="' + esc(f.superseded_by) + '">superseded</span>' : "";
|
|
1043
|
+
var canon = f.canonical_name && f.canonical_name !== name ? '<div class="muted small mono">' + esc(f.canonical_name) + '</div>' : "";
|
|
1044
|
+
return '<tr>'
|
|
1045
|
+
+ '<td><div class="val">' + esc(name) + sup + '</div>' + canon + '</td>'
|
|
1046
|
+
+ '<td>' + chip(f.data_type, "") + '</td>'
|
|
1047
|
+
+ '<td>' + chip(f.maturity, maturityTone(f.maturity)) + (f.tier != null ? ' <span class="muted small">tier ' + esc(f.tier) + '</span>' : "") + '</td>'
|
|
1048
|
+
+ '<td class="val num">' + esc(f.occurrence_count != null ? f.occurrence_count : "\u2014") + '</td>'
|
|
1049
|
+
+ '</tr>';
|
|
1050
|
+
}).join("");
|
|
1051
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1052
|
+
root.innerHTML = ''
|
|
1053
|
+
+ '<div class="header"><div><div class="title">Field Registry</div><div class="subtitle">' + rows.length + ' of ' + total + ' fields</div></div>'
|
|
1054
|
+
+ (pg.has_more ? '<span class="chip">more available</span>' : "") + '</div>'
|
|
1055
|
+
+ '<table><thead><tr><th>Field</th><th>Type</th><th>Maturity</th><th class="num">Occurrences</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1056
|
+
`;
|
|
1057
|
+
var WIDGET_HTML12 = buildWidgetHtml({
|
|
1058
|
+
title: "Talonic \u2014 Field Registry",
|
|
1059
|
+
renderBody: RENDER_BODY12
|
|
1060
|
+
});
|
|
1061
|
+
|
|
1062
|
+
// src/widgets/field-card.ts
|
|
1063
|
+
function getFieldCardWidgetHtml() {
|
|
1064
|
+
return WIDGET_HTML13;
|
|
1065
|
+
}
|
|
1066
|
+
var RENDER_BODY13 = `
|
|
1067
|
+
if (!payload || (!payload.canonical_name && !payload.id)) { empty("No field card."); return; }
|
|
1068
|
+
var def = payload.definition && typeof payload.definition === "object" ? payload.definition : {};
|
|
1069
|
+
var occ = payload.occurrence && typeof payload.occurrence === "object" ? payload.occurrence : {};
|
|
1070
|
+
var vals = payload.values && typeof payload.values === "object" ? payload.values : {};
|
|
1071
|
+
var usage = payload.usage && typeof payload.usage === "object" ? payload.usage : {};
|
|
1072
|
+
var ident = payload.identity && typeof payload.identity === "object" ? payload.identity : {};
|
|
1073
|
+
var res = payload.resolution && typeof payload.resolution === "object" ? payload.resolution : null;
|
|
1074
|
+
function maturityTone(m) { return m === "core" ? "good" : m === "proven" ? "info" : m === "candidate" ? "warn" : ""; }
|
|
1075
|
+
var name = payload.display_name || payload.canonical_name || payload.id;
|
|
1076
|
+
var definition = def.description || payload.description || def.instruction || payload.master_instruction || "";
|
|
1077
|
+
var synonymList = Array.isArray(def.synonyms) ? def.synonyms : Array.isArray(payload.synonyms) ? payload.synonyms : [];
|
|
1078
|
+
var synonyms = synonymList.slice(0, 12).map(function (s) { return chip(s, ""); }).join("");
|
|
1079
|
+
var top = Array.isArray(vals.top) ? vals.top.slice(0, 8) : [];
|
|
1080
|
+
var topHtml = top.map(function (t) {
|
|
1081
|
+
t = t && typeof t === "object" ? t : {};
|
|
1082
|
+
var share = typeof t.share === "number" ? Math.max(0, Math.min(100, Math.round(t.share * 100))) : null;
|
|
1083
|
+
return '<tr><td class="val mono">' + esc(clamp(fmt(t.value), 60)) + '</td><td class="val num">' + esc(t.count != null ? t.count : "") + '</td><td>'
|
|
1084
|
+
+ (share == null ? "" : '<span class="bar"><span style="width:' + share + '%"></span></span> <span class="muted small">' + share + '%</span>') + '</td></tr>';
|
|
1085
|
+
}).join("");
|
|
1086
|
+
var rate = typeof occ.occurrence_rate === "number" ? (Math.round(occ.occurrence_rate * 1000) / 10) + "%" : "\u2014";
|
|
1087
|
+
var redirected = res && Array.isArray(res.redirected_from) && res.redirected_from.length ? res.redirected_from.join(", ") : "";
|
|
1088
|
+
var occCount = occ.occurrence_count != null ? occ.occurrence_count : payload.occurrence_count != null ? payload.occurrence_count : "\u2014";
|
|
1089
|
+
root.innerHTML = ''
|
|
1090
|
+
+ '<div class="header"><div><div class="title">' + esc(name) + '</div>'
|
|
1091
|
+
+ (payload.canonical_name && payload.canonical_name !== name ? '<div class="subtitle mono">' + esc(payload.canonical_name) + '</div>' : "") + '</div>'
|
|
1092
|
+
+ '<div>' + chip(payload.data_type, "") + chip(payload.maturity, maturityTone(payload.maturity))
|
|
1093
|
+
+ (payload.tier != null ? chip("tier " + payload.tier, "") : "")
|
|
1094
|
+
+ (ident.superseded_by || payload.superseded_by ? chip("superseded", "bad") : "")
|
|
1095
|
+
+ (ident.link_key ? chip("link key", "info") : "") + '</div></div>'
|
|
1096
|
+
+ (definition ? '<div class="small" style="white-space:pre-wrap">' + esc(clamp(definition, 600)) + '</div>' : '<div class="muted small">No definition recorded.</div>')
|
|
1097
|
+
+ (synonyms ? '<div style="margin-top:8px"><div class="muted small">Also known as</div><div>' + synonyms + '</div></div>' : "")
|
|
1098
|
+
+ '<div class="grid">'
|
|
1099
|
+
+ '<div class="kv"><span class="k">Occurrences</span><span class="val">' + esc(occCount) + '</span></div>'
|
|
1100
|
+
+ '<div class="kv"><span class="k">Documents</span><span class="val">' + esc(occ.document_count != null ? occ.document_count : "\u2014") + '</span></div>'
|
|
1101
|
+
+ '<div class="kv"><span class="k">Occurrence rate</span><span class="val">' + esc(rate) + '</span></div>'
|
|
1102
|
+
+ '<div class="kv"><span class="k">Distinct values</span><span class="val">' + esc(vals.distinct_count != null ? vals.distinct_count : "\u2014") + '</span></div>'
|
|
1103
|
+
+ '<div class="kv"><span class="k">Used in schemas</span><span class="val">' + esc(usage.schema_count != null ? usage.schema_count : "\u2014") + '</span></div>'
|
|
1104
|
+
+ '<div class="kv"><span class="k">Last seen</span><span class="val">' + esc(occ.last_seen_at ? relTime(occ.last_seen_at) : "\u2014") + '</span></div>'
|
|
1105
|
+
+ '</div>'
|
|
1106
|
+
+ (topHtml ? '<div class="plane"><div class="subtitle">Top values</div><table><thead><tr><th>Value</th><th class="num">Count</th><th>Share</th></tr></thead><tbody>' + topHtml + '</tbody></table></div>' : "")
|
|
1107
|
+
+ (res ? '<div class="muted small" style="margin-top:10px">Resolved by ' + esc(res.matched_by || "id") + (redirected ? ' \xB7 redirected from ' + esc(redirected) : "") + '</div>' : "");
|
|
1108
|
+
`;
|
|
1109
|
+
var WIDGET_HTML13 = buildWidgetHtml({
|
|
1110
|
+
title: "Talonic \u2014 Field Card",
|
|
1111
|
+
renderBody: RENDER_BODY13
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
// src/widgets/field-values.ts
|
|
1115
|
+
function getFieldValuesWidgetHtml() {
|
|
1116
|
+
return WIDGET_HTML14;
|
|
1117
|
+
}
|
|
1118
|
+
var RENDER_BODY14 = `
|
|
1119
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1120
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1121
|
+
var name = payload.canonical_name || payload.field_id || "field";
|
|
1122
|
+
if (!rows.length) { empty("No values recorded for " + name + "."); return; }
|
|
1123
|
+
var body = rows.map(function (r) {
|
|
1124
|
+
r = r && typeof r === "object" ? r : { value: r };
|
|
1125
|
+
var prov = r.provenance && typeof r.provenance === "object" ? r.provenance : {};
|
|
1126
|
+
var flags = (prov.needs_confirmation ? chip("needs confirmation", "warn") : "") + (prov.via_redirect ? chip("via redirect", "info") : "");
|
|
1127
|
+
return '<tr>'
|
|
1128
|
+
+ '<td class="val mono">' + esc(clamp(fmt(r.value), 80)) + '</td>'
|
|
1129
|
+
+ '<td><div class="val">' + esc(r.document_filename || shortId(r.document_id)) + '</div>' + (r.document_type ? '<div class="muted small">' + esc(r.document_type) + '</div>' : "") + '</td>'
|
|
1130
|
+
+ '<td>' + confBar(r.confidence) + '</td>'
|
|
1131
|
+
+ '<td class="small">' + (prov.raw_field_name ? '<div class="mono">' + esc(prov.raw_field_name) + '</div>' : "")
|
|
1132
|
+
+ (prov.source_text ? '<div class="muted">\u201C' + esc(clamp(prov.source_text, 90)) + '\u201D</div>' : "") + flags + '</td>'
|
|
1133
|
+
+ '</tr>';
|
|
1134
|
+
}).join("");
|
|
1135
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1136
|
+
root.innerHTML = ''
|
|
1137
|
+
+ '<div class="header"><div><div class="title">' + esc(name) + '</div><div class="subtitle">' + rows.length + ' of ' + total + ' values</div></div>'
|
|
1138
|
+
+ (pg.has_more ? '<span class="chip">more available</span>' : "") + '</div>'
|
|
1139
|
+
+ '<table><thead><tr><th>Value</th><th>Document</th><th>Confidence</th><th>Provenance</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1140
|
+
`;
|
|
1141
|
+
var WIDGET_HTML14 = buildWidgetHtml({
|
|
1142
|
+
title: "Talonic \u2014 Field Values",
|
|
1143
|
+
renderBody: RENDER_BODY14
|
|
1144
|
+
});
|
|
1145
|
+
|
|
1146
|
+
// src/widgets/find-data.ts
|
|
1147
|
+
function getFindDataWidgetHtml() {
|
|
1148
|
+
return WIDGET_HTML15;
|
|
1149
|
+
}
|
|
1150
|
+
var RENDER_BODY15 = `
|
|
1151
|
+
var res = payload && payload.result && typeof payload.result === "object" ? payload.result : (payload && typeof payload === "object" ? payload : {});
|
|
1152
|
+
var fields = Array.isArray(res.fields) ? res.fields : [];
|
|
1153
|
+
var values = Array.isArray(res.values) ? res.values : [];
|
|
1154
|
+
var docs = Array.isArray(res.documents) ? res.documents : [];
|
|
1155
|
+
var passages = Array.isArray(res.passages) ? res.passages : [];
|
|
1156
|
+
var total = fields.length + values.length + docs.length + passages.length;
|
|
1157
|
+
var query = typeof res.query === "string" ? res.query : "";
|
|
1158
|
+
if (!total) { empty("Nothing in the workspace matches" + (query ? " \u201C" + query + "\u201D" : "") + "."); return; }
|
|
1159
|
+
function scoreBar(s) {
|
|
1160
|
+
if (typeof s !== "number") return "";
|
|
1161
|
+
var p = Math.max(0, Math.min(100, Math.round(s * 100)));
|
|
1162
|
+
return '<span class="bar"><span style="width:' + p + '%"></span></span> <span class="muted small">' + p + '%</span>';
|
|
1163
|
+
}
|
|
1164
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1165
|
+
function plane(label, items, renderItem) {
|
|
1166
|
+
if (!items.length) return "";
|
|
1167
|
+
return '<div class="plane"><div class="subtitle">' + esc(label) + ' (' + items.length + ')</div>' + items.map(function (i) { return renderItem(obj(i)); }).join("") + '</div>';
|
|
1168
|
+
}
|
|
1169
|
+
var fieldsHtml = plane("Fields", fields, function (f) {
|
|
1170
|
+
var samples = Array.isArray(f.samples) ? f.samples.slice(0, 3).map(function (s) {
|
|
1171
|
+
var v = s && typeof s === "object" && "value" in s ? s.value : s;
|
|
1172
|
+
return chip(clamp(fmt(v), 40), "");
|
|
1173
|
+
}).join("") : "";
|
|
1174
|
+
return '<div class="kv"><div><span class="val">' + esc(f.display_name || f.canonical_name || "(field)") + '</span> ' + chip(f.data_type, "")
|
|
1175
|
+
+ (f.tier != null ? chip("tier " + f.tier, "") : "") + (f.match ? chip(f.match, "info") : "") + '</div>'
|
|
1176
|
+
+ '<div class="small muted">' + (f.occurrence_count != null ? esc(f.occurrence_count) + ' occurrences \xB7 ' : "") + scoreBar(f.score) + '</div>'
|
|
1177
|
+
+ (samples ? '<div>' + samples + '</div>' : "") + '</div>';
|
|
1178
|
+
});
|
|
1179
|
+
var valuesHtml = plane("Values", values, function (v) {
|
|
1180
|
+
return '<div class="kv"><span class="val mono">' + esc(clamp(fmt(v.value), 80)) + '</span><span class="small muted">' + esc(v.canonical_name || v.field_key || "")
|
|
1181
|
+
+ (v.filename ? ' \xB7 ' + esc(v.filename) : "") + ' ' + scoreBar(v.score) + '</span></div>';
|
|
1182
|
+
});
|
|
1183
|
+
var docsHtml = plane("Documents", docs, function (d) {
|
|
1184
|
+
return '<div class="kv"><span class="val">' + esc(d.filename || shortId(d.document_id)) + '</span><span class="small muted">' + scoreBar(d.score) + '</span>'
|
|
1185
|
+
+ (d.best_passage ? '<span class="small">' + esc(clamp(d.best_passage, 160)) + '</span>' : "") + '</div>';
|
|
1186
|
+
});
|
|
1187
|
+
var passagesHtml = plane("Passages", passages, function (p) {
|
|
1188
|
+
return '<div class="kv"><span class="small muted">' + esc(p.filename || shortId(p.document_id)) + ' ' + scoreBar(p.score) + '</span><span class="small">' + esc(clamp(p.text, 220)) + '</span></div>';
|
|
1189
|
+
});
|
|
1190
|
+
root.innerHTML = ''
|
|
1191
|
+
+ '<div class="header"><div><div class="title">Data behind \u201C' + esc(query || "your concept") + '\u201D</div><div class="subtitle">' + total + (total === 1 ? ' match' : ' matches') + (res.semantic ? " \xB7 semantic + lexical" : "") + '</div></div></div>'
|
|
1192
|
+
+ fieldsHtml + valuesHtml + docsHtml + passagesHtml;
|
|
1193
|
+
`;
|
|
1194
|
+
var WIDGET_HTML15 = buildWidgetHtml({
|
|
1195
|
+
title: "Talonic \u2014 Find Data",
|
|
1196
|
+
renderBody: RENDER_BODY15
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
// src/widgets/agent-tools.ts
|
|
1200
|
+
function getAgentToolsWidgetHtml() {
|
|
1201
|
+
return WIDGET_HTML16;
|
|
1202
|
+
}
|
|
1203
|
+
var RENDER_BODY16 = `
|
|
1204
|
+
var tools = Array.isArray(payload.tools) ? payload.tools : [];
|
|
1205
|
+
if (!tools.length) { empty("No agent tools are visible to this credential."); return; }
|
|
1206
|
+
function impactTone(i) { return i === "read" ? "good" : i === "draft_mutation" ? "warn" : i === "live_mutation" ? "bad" : ""; }
|
|
1207
|
+
var body = tools.map(function (t) {
|
|
1208
|
+
t = t && typeof t === "object" ? t : {};
|
|
1209
|
+
return '<tr>'
|
|
1210
|
+
+ '<td><div class="val mono">' + esc(t.name || "(tool)") + '</div><div class="muted small">' + esc(clamp(t.description, 140)) + '</div></td>'
|
|
1211
|
+
+ '<td>' + chip(t.impact, impactTone(t.impact)) + '</td>'
|
|
1212
|
+
+ '<td>' + chip(t.capability, "") + '</td>'
|
|
1213
|
+
+ '<td>' + (t.can_invoke ? '<span class="chip good">\u2713 invocable</span>' : '<span class="muted small">\u2014</span>') + '</td>'
|
|
1214
|
+
+ '</tr>';
|
|
1215
|
+
}).join("");
|
|
1216
|
+
var inv = typeof payload.invocable_count === "number" ? payload.invocable_count : tools.filter(function (t) { return t && t.can_invoke; }).length;
|
|
1217
|
+
var total = typeof payload.totalCount === "number" ? payload.totalCount : tools.length;
|
|
1218
|
+
root.innerHTML = ''
|
|
1219
|
+
+ '<div class="header"><div><div class="title">Platform agent tools</div><div class="subtitle">' + inv + ' invocable with this key \xB7 ' + total + ' in the registry</div></div></div>'
|
|
1220
|
+
+ '<table><thead><tr><th>Tool</th><th>Impact</th><th>Capability</th><th>Access</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1221
|
+
`;
|
|
1222
|
+
var WIDGET_HTML16 = buildWidgetHtml({
|
|
1223
|
+
title: "Talonic \u2014 Agent Tools",
|
|
1224
|
+
renderBody: RENDER_BODY16
|
|
1225
|
+
});
|
|
1226
|
+
|
|
1227
|
+
// src/widgets/agent-tool-result.ts
|
|
1228
|
+
function getAgentToolResultWidgetHtml() {
|
|
1229
|
+
return WIDGET_HTML17;
|
|
1230
|
+
}
|
|
1231
|
+
var RENDER_BODY17 = `
|
|
1232
|
+
var result = payload && typeof payload === "object" ? payload.result : undefined;
|
|
1233
|
+
var toolName = (payload && payload.tool) || "agent tool";
|
|
1234
|
+
var isEmptyResult = result == null || result === ""
|
|
1235
|
+
|| (Array.isArray(result) && result.length === 0)
|
|
1236
|
+
|| (typeof result === "object" && !Array.isArray(result) && Object.keys(result).length === 0);
|
|
1237
|
+
var body;
|
|
1238
|
+
if (isEmptyResult) body = '<div class="empty">The tool returned no data.</div>';
|
|
1239
|
+
else if (isRowArray(result)) body = dataTable(result);
|
|
1240
|
+
else if (isFlat(result)) body = kvTiles(result);
|
|
1241
|
+
else if (typeof result === "object") body = jsonTree(result);
|
|
1242
|
+
else body = '<pre class="md">' + esc(fmt(result)) + '</pre>';
|
|
1243
|
+
var cites = Array.isArray(payload.citations) ? payload.citations : [];
|
|
1244
|
+
var arts = Array.isArray(payload.artifacts) ? payload.artifacts : [];
|
|
1245
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1246
|
+
var citeHtml = cites.length ? '<div class="plane"><div class="subtitle">Citations (' + cites.length + ')</div>' + cites.slice(0, 20).map(function (c) {
|
|
1247
|
+
c = obj(c);
|
|
1248
|
+
return '<div class="kv"><span class="small">\u201C' + esc(clamp(c.quote || c.text || fmt(c), 160)) + '\u201D</span><span class="muted small">' + esc(c.filename || shortId(c.document_id)) + '</span></div>';
|
|
1249
|
+
}).join("") + '</div>' : "";
|
|
1250
|
+
var artHtml = arts.length ? '<div class="plane"><div class="subtitle">Artifacts (' + arts.length + ')</div>' + arts.slice(0, 20).map(function (a) {
|
|
1251
|
+
a = obj(a);
|
|
1252
|
+
var link = typeof a.link === "string" && /^https:\\/\\//.test(a.link) ? a.link : "";
|
|
1253
|
+
return '<div class="kv"><span class="val">' + esc(a.label || a.type || a.id || "artifact") + '</span>'
|
|
1254
|
+
+ (link ? '<a class="btn small" href="' + esc(link) + '" target="_blank" rel="noopener noreferrer">Open</a>' : "") + '</div>';
|
|
1255
|
+
}).join("") + '</div>' : "";
|
|
1256
|
+
var count = "";
|
|
1257
|
+
if (!isEmptyResult) {
|
|
1258
|
+
if (isRowArray(result)) count = result.length + (result.length === 1 ? " row" : " rows");
|
|
1259
|
+
else if (result && typeof result === "object" && !Array.isArray(result)) {
|
|
1260
|
+
var keyCount = Object.keys(result).length;
|
|
1261
|
+
count = keyCount + (keyCount === 1 ? " key" : " keys");
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
root.innerHTML = ''
|
|
1265
|
+
+ '<div class="header"><div><div class="title mono">' + esc(toolName) + '</div>' + (count ? '<div class="subtitle">' + esc(count) + '</div>' : "") + '</div></div>'
|
|
1266
|
+
+ body + citeHtml + artHtml;
|
|
1267
|
+
`;
|
|
1268
|
+
var WIDGET_HTML17 = buildWidgetHtml({
|
|
1269
|
+
title: "Talonic \u2014 Agent Tool Result",
|
|
1270
|
+
renderBody: RENDER_BODY17
|
|
1271
|
+
});
|
|
1272
|
+
|
|
1273
|
+
// src/widgets/agent-task-shared.ts
|
|
1274
|
+
var TASK_JS = `
|
|
1275
|
+
function statusTone(s) {
|
|
1276
|
+
return s === "available" ? "info" : s === "claimed" || s === "submitted" ? "good" : s === "timed_out" ? "bad" : s === "cancelled" ? "warn" : "";
|
|
1277
|
+
}
|
|
1278
|
+
function taskTiming(p) {
|
|
1279
|
+
return '<div class="grid">'
|
|
1280
|
+
+ '<div class="kv"><span class="k">Document</span> <span class="val">' + idChip(p.document_id) + '</span></div>'
|
|
1281
|
+
+ '<div class="kv"><span class="k">Pipeline</span> <span class="val">' + idChip(p.pipeline_id) + '</span></div>'
|
|
1282
|
+
+ '<div class="kv"><span class="k">Phase</span> <span class="val">' + esc(p.phase_index != null ? p.phase_index : "\u2014") + '</span></div>'
|
|
1283
|
+
+ '<div class="kv"><span class="k">Execution epoch</span> <span class="val">' + esc(p.execution_epoch != null ? p.execution_epoch : "\u2014") + '</span></div>'
|
|
1284
|
+
+ '<div class="kv"><span class="k">Lease expires</span> <span class="val">' + esc(p.lease_expires_at ? relTime(p.lease_expires_at) : "\u2014") + '</span></div>'
|
|
1285
|
+
+ '<div class="kv"><span class="k">Times out</span> <span class="val">' + esc(p.timeout_at ? relTime(p.timeout_at) : "\u2014") + '</span></div>'
|
|
1286
|
+
+ '</div>';
|
|
1287
|
+
}
|
|
1288
|
+
function taskSections(p) {
|
|
1289
|
+
var html = "";
|
|
1290
|
+
if (typeof p.instructions === "string" && p.instructions) {
|
|
1291
|
+
html += '<div class="plane"><div class="subtitle">Instructions</div><div class="small" style="white-space:pre-wrap">' + esc(clamp(p.instructions, 1200)) + '</div></div>';
|
|
1292
|
+
}
|
|
1293
|
+
if (Array.isArray(p.output_contract) && p.output_contract.length) {
|
|
1294
|
+
html += '<div class="plane"><div class="subtitle">Output contract (' + p.output_contract.length + ')</div>'
|
|
1295
|
+
+ '<table><thead><tr><th>Field</th><th>Type</th><th>Required</th></tr></thead><tbody>'
|
|
1296
|
+
+ p.output_contract.map(function (f) {
|
|
1297
|
+
f = f && typeof f === "object" ? f : {};
|
|
1298
|
+
return '<tr><td class="val mono">' + esc(f.key || "") + '</td><td>' + chip(f.dataType, "") + '</td><td>'
|
|
1299
|
+
+ (f.required ? chip("required", "warn") : '<span class="muted small">optional</span>') + '</td></tr>';
|
|
1300
|
+
}).join("")
|
|
1301
|
+
+ '</tbody></table></div>';
|
|
1302
|
+
}
|
|
1303
|
+
var snap = p.input_snapshot;
|
|
1304
|
+
if (snap && typeof snap === "object" && !Array.isArray(snap) && Object.keys(snap).length) {
|
|
1305
|
+
html += '<div class="plane"><div class="subtitle">Input snapshot</div>' + (isFlat(snap) ? kvTiles(snap) : jsonTree(snap)) + '</div>';
|
|
1306
|
+
}
|
|
1307
|
+
if (p.timeout_fallthrough) {
|
|
1308
|
+
html += '<div class="muted small" style="margin-top:10px">On timeout: ' + esc(String(p.timeout_fallthrough).replace(/_/g, " ")) + '</div>';
|
|
1309
|
+
}
|
|
1310
|
+
return html;
|
|
1311
|
+
}
|
|
1312
|
+
`;
|
|
1313
|
+
|
|
1314
|
+
// src/widgets/agent-task-list.ts
|
|
1315
|
+
function getAgentTaskListWidgetHtml() {
|
|
1316
|
+
return WIDGET_HTML18;
|
|
1317
|
+
}
|
|
1318
|
+
var RENDER_BODY18 = TASK_JS + `
|
|
1319
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1320
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1321
|
+
if (!rows.length) { empty("No agent tasks in this worklist."); return; }
|
|
1322
|
+
var body = rows.map(function (t) {
|
|
1323
|
+
t = t && typeof t === "object" ? t : {};
|
|
1324
|
+
return '<tr>'
|
|
1325
|
+
+ '<td>' + idChip(t.id) + '</td>'
|
|
1326
|
+
+ '<td>' + chip(t.status, statusTone(t.status)) + '</td>'
|
|
1327
|
+
+ '<td>' + idChip(t.document_id) + '</td>'
|
|
1328
|
+
+ '<td class="val num">' + esc(t.phase_index != null ? t.phase_index : "\u2014") + '</td>'
|
|
1329
|
+
+ '<td class="val">' + esc(t.lease_expires_at ? relTime(t.lease_expires_at) : "\u2014") + '</td>'
|
|
1330
|
+
+ '<td class="val">' + esc(t.timeout_at ? relTime(t.timeout_at) : "\u2014") + '</td>'
|
|
1331
|
+
+ '<td class="val num">' + esc(t.execution_epoch != null ? t.execution_epoch : "\u2014") + '</td>'
|
|
1332
|
+
+ '</tr>';
|
|
1333
|
+
}).join("");
|
|
1334
|
+
var counts = {};
|
|
1335
|
+
rows.forEach(function (t) { var s = t && typeof t === "object" && t.status ? t.status : "unknown"; counts[s] = (counts[s] || 0) + 1; });
|
|
1336
|
+
var summary = Object.keys(counts).map(function (s) { return chip(counts[s] + " " + s, statusTone(s)); }).join("");
|
|
1337
|
+
root.innerHTML = ''
|
|
1338
|
+
+ '<div class="header"><div><div class="title">Agent task worklist</div><div class="subtitle">' + rows.length + ' task' + (rows.length === 1 ? "" : "s") + (pg.has_more ? " \xB7 more available" : "") + '</div></div><div>' + summary + '</div></div>'
|
|
1339
|
+
+ '<table><thead><tr><th>Task</th><th>Status</th><th>Document</th><th class="num">Phase</th><th>Lease</th><th>Timeout</th><th class="num">Epoch</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1340
|
+
`;
|
|
1341
|
+
var WIDGET_HTML18 = buildWidgetHtml({
|
|
1342
|
+
title: "Talonic \u2014 Agent Tasks",
|
|
1343
|
+
renderBody: RENDER_BODY18
|
|
1344
|
+
});
|
|
1345
|
+
|
|
1346
|
+
// src/widgets/agent-task.ts
|
|
1347
|
+
function getAgentTaskWidgetHtml() {
|
|
1348
|
+
return WIDGET_HTML19;
|
|
1349
|
+
}
|
|
1350
|
+
var RENDER_BODY19 = TASK_JS + `
|
|
1351
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No agent task."); return; }
|
|
1352
|
+
root.innerHTML = ''
|
|
1353
|
+
+ '<div class="header"><div><div class="title">Agent task ' + idChip(payload.id) + '</div>'
|
|
1354
|
+
+ '<div class="subtitle">' + esc(payload.created_at ? "created " + relTime(payload.created_at) : "") + '</div></div>'
|
|
1355
|
+
+ '<div>' + chip(payload.status, statusTone(payload.status)) + '</div></div>'
|
|
1356
|
+
+ taskTiming(payload) + taskSections(payload);
|
|
1357
|
+
`;
|
|
1358
|
+
var WIDGET_HTML19 = buildWidgetHtml({
|
|
1359
|
+
title: "Talonic \u2014 Agent Task",
|
|
1360
|
+
renderBody: RENDER_BODY19
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
// src/widgets/agent-task-lease.ts
|
|
1364
|
+
function getAgentTaskClaimWidgetHtml() {
|
|
1365
|
+
return CLAIM_HTML;
|
|
1366
|
+
}
|
|
1367
|
+
function getAgentTaskHeartbeatWidgetHtml() {
|
|
1368
|
+
return HEARTBEAT_HTML;
|
|
1369
|
+
}
|
|
1370
|
+
var LEASE_BODY = `
|
|
1371
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No lease information."); return; }
|
|
1372
|
+
root.innerHTML = ''
|
|
1373
|
+
+ '<div class="header"><div><div class="title">' + HEADLINE + '</div><div class="subtitle">Task ' + idChip(payload.id) + '</div></div>'
|
|
1374
|
+
+ '<div>' + chip(payload.status, statusTone(payload.status)) + '</div></div>'
|
|
1375
|
+
+ '<div class="big">' + esc(payload.execution_epoch != null ? payload.execution_epoch : "\u2014") + ' <span class="muted small">execution epoch</span></div>'
|
|
1376
|
+
+ '<div class="muted small">Keep this epoch for heartbeat and submit.' + (payload.lease_expires_at ? ' Lease expires ' + esc(relTime(payload.lease_expires_at)) + '.' : "") + '</div>'
|
|
1377
|
+
+ taskTiming(payload) + taskSections(payload);
|
|
1378
|
+
`;
|
|
1379
|
+
function leaseWidget(headline, title) {
|
|
1380
|
+
return buildWidgetHtml({
|
|
1381
|
+
title,
|
|
1382
|
+
renderBody: TASK_JS + " var HEADLINE = " + JSON.stringify(headline) + ";\n" + LEASE_BODY
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
var CLAIM_HTML = leaseWidget("Task claimed", "Talonic \u2014 Agent Task Claimed");
|
|
1386
|
+
var HEARTBEAT_HTML = leaseWidget("Lease extended", "Talonic \u2014 Agent Task Lease");
|
|
1387
|
+
|
|
1388
|
+
// src/widgets/agent-task-submitted.ts
|
|
1389
|
+
function getAgentTaskSubmittedWidgetHtml() {
|
|
1390
|
+
return WIDGET_HTML20;
|
|
1391
|
+
}
|
|
1392
|
+
var RENDER_BODY20 = TASK_JS + `
|
|
1393
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No submission recorded."); return; }
|
|
1394
|
+
root.innerHTML = ''
|
|
1395
|
+
+ '<div class="header"><div><div class="title">Outputs submitted</div><div class="subtitle">Task ' + idChip(payload.id)
|
|
1396
|
+
+ (payload.submitted_at ? ' \xB7 ' + esc(relTime(payload.submitted_at)) : "") + '</div></div>'
|
|
1397
|
+
+ '<div>' + chip(payload.status, statusTone(payload.status)) + '</div></div>'
|
|
1398
|
+
+ '<div class="small">The parked document resumes its pipeline from this stage.</div>'
|
|
1399
|
+
+ taskTiming(payload);
|
|
1400
|
+
`;
|
|
1401
|
+
var WIDGET_HTML20 = buildWidgetHtml({
|
|
1402
|
+
title: "Talonic \u2014 Agent Task Submitted",
|
|
1403
|
+
renderBody: RENDER_BODY20
|
|
1404
|
+
});
|
|
1405
|
+
|
|
1406
|
+
// src/widgets/spec-list.ts
|
|
1407
|
+
function getSpecListWidgetHtml() {
|
|
1408
|
+
return WIDGET_HTML21;
|
|
1409
|
+
}
|
|
1410
|
+
var RENDER_BODY21 = `
|
|
1411
|
+
if (!payload || typeof payload !== "object") { empty("No Specs in this workspace."); return; }
|
|
1412
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1413
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1414
|
+
if (!rows.length) { empty("No Specs in this workspace."); return; }
|
|
1415
|
+
function versionChip(s) {
|
|
1416
|
+
if (s.version == null) return chip("unpublished", "bad");
|
|
1417
|
+
if (s.materialized_version != null && s.materialized_version === s.version) return chip("v" + s.version + " live", "good");
|
|
1418
|
+
return chip("v" + s.version + " not live", "warn");
|
|
1419
|
+
}
|
|
1420
|
+
var body = rows.map(function (s) {
|
|
1421
|
+
s = s && typeof s === "object" ? s : {};
|
|
1422
|
+
return '<tr>'
|
|
1423
|
+
+ '<td><div class="val">' + esc(s.name || s.id || "(spec)") + '</div>' + (s.description ? '<div class="muted small">' + esc(clamp(s.description, 100)) + '</div>' : "") + '</td>'
|
|
1424
|
+
+ '<td>' + versionChip(s) + '</td>'
|
|
1425
|
+
+ '<td class="val num">' + esc(s.field_count != null ? s.field_count : "\u2014") + '</td>'
|
|
1426
|
+
+ '<td class="val num">' + esc(s.node_count != null ? s.node_count : "\u2014") + '</td>'
|
|
1427
|
+
+ '<td class="val">' + esc(s.updated_at ? relTime(s.updated_at) : "\u2014") + '</td>'
|
|
1428
|
+
+ '</tr>';
|
|
1429
|
+
}).join("");
|
|
1430
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1431
|
+
root.innerHTML = ''
|
|
1432
|
+
+ '<div class="header"><div><div class="title">Specs</div><div class="subtitle">' + rows.length + ' of ' + total + ' Specs</div></div>'
|
|
1433
|
+
+ (pg.has_more ? '<span class="chip">more available</span>' : "") + '</div>'
|
|
1434
|
+
+ '<table><thead><tr><th>Spec</th><th>Version</th><th class="num">Fields</th><th class="num">Stages</th><th>Updated</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1435
|
+
`;
|
|
1436
|
+
var WIDGET_HTML21 = buildWidgetHtml({ title: "Talonic \u2014 Specs", renderBody: RENDER_BODY21 });
|
|
1437
|
+
|
|
1438
|
+
// src/widgets/spec-card.ts
|
|
1439
|
+
function getSpecCardWidgetHtml() {
|
|
1440
|
+
return WIDGET_HTML22;
|
|
1441
|
+
}
|
|
1442
|
+
var CSS = `
|
|
1443
|
+
.rail { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 6px; }
|
|
1444
|
+
.rail .arrow { color: var(--muted); font-size: 12px; }
|
|
1445
|
+
`;
|
|
1446
|
+
var RENDER_BODY22 = `
|
|
1447
|
+
if (!payload || typeof payload !== "object" || (!payload.id && !payload.name)) { empty("No Spec."); return; }
|
|
1448
|
+
var nodes = Array.isArray(payload.nodes) ? payload.nodes : [];
|
|
1449
|
+
var phases = Array.isArray(payload.phases) ? payload.phases : [];
|
|
1450
|
+
var fields = Array.isArray(payload.fields) ? payload.fields : [];
|
|
1451
|
+
var versions = Array.isArray(payload.versions) ? payload.versions : [];
|
|
1452
|
+
var schema = payload.schema && typeof payload.schema === "object" ? payload.schema : null;
|
|
1453
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1454
|
+
var versionChip = payload.version == null ? chip("unpublished", "bad")
|
|
1455
|
+
: (payload.materialized_version != null && payload.materialized_version === payload.version ? chip("v" + payload.version + " live", "good") : chip("v" + payload.version + " not live", "warn"));
|
|
1456
|
+
var fieldCount = typeof payload.field_count === "number" ? payload.field_count : fields.length;
|
|
1457
|
+
var railHtml = nodes.length ? '<div class="plane"><div class="subtitle">Rail (' + nodes.length + ' stages)</div><div class="rail">'
|
|
1458
|
+
+ nodes.map(function (n, i) { n = obj(n); return (i ? '<span class="arrow">\u2192</span>' : "") + '<span class="chip" title="' + esc(n.name || "") + '">' + esc(n.type || "stage") + (n.name ? ' \xB7 ' + esc(clamp(n.name, 28)) : "") + '</span>'; }).join("")
|
|
1459
|
+
+ '</div></div>' : "";
|
|
1460
|
+
var phaseHtml = phases.length ? '<div class="plane"><div class="subtitle">Compiled plan (' + phases.length + ' phases)</div><table><thead><tr><th class="num">#</th><th>Type</th><th>Phase</th></tr></thead><tbody>'
|
|
1461
|
+
+ phases.map(function (p, i) { p = obj(p); return '<tr><td class="val num">' + esc(p.number != null ? p.number : i + 1) + '</td><td>' + chip(p.type, "") + '</td><td class="val">' + esc(p.name || "\u2014") + '</td></tr>'; }).join("")
|
|
1462
|
+
+ '</tbody></table></div>' : "";
|
|
1463
|
+
var fieldHtml = fields.length ? '<div class="plane"><div class="subtitle">Fields (' + fields.length + ')</div><div>'
|
|
1464
|
+
+ fields.slice(0, 12).map(function (f) { f = obj(f); return chip(f.name || f.field_id || "field", ""); }).join("") + (fields.length > 12 ? '<span class="muted small"> +' + (fields.length - 12) + ' more</span>' : "") + '</div></div>' : "";
|
|
1465
|
+
var versionHtml = versions.length ? '<div class="plane"><div class="subtitle">Versions</div><table><thead><tr><th class="num">Version</th><th>Published</th><th>Hash</th><th></th></tr></thead><tbody>'
|
|
1466
|
+
+ versions.slice(0, 8).map(function (v) { v = obj(v); return '<tr><td class="val num">' + esc(v.version != null ? v.version : "\u2014") + '</td><td class="val">' + esc(v.created_at ? relTime(v.created_at) : "\u2014") + '</td><td class="mono small">' + esc(clamp(fmt(v.content_hash), 18)) + '</td><td>' + (v.is_materialized ? chip("live", "good") : "") + '</td></tr>'; }).join("")
|
|
1467
|
+
+ '</tbody></table></div>' : "";
|
|
1468
|
+
root.innerHTML = ''
|
|
1469
|
+
+ '<div class="header"><div><div class="title">' + esc(payload.name || payload.id) + '</div>'
|
|
1470
|
+
+ (payload.description ? '<div class="subtitle">' + esc(clamp(payload.description, 140)) + '</div>' : "") + '</div>'
|
|
1471
|
+
+ '<div>' + versionChip + chip(fieldCount + " fields", "") + '</div></div>'
|
|
1472
|
+
+ '<div class="grid">'
|
|
1473
|
+
+ '<div class="kv"><span class="k">Spec id</span> <span class="val">' + idChip(payload.id) + '</span></div>'
|
|
1474
|
+
+ '<div class="kv"><span class="k">Schema</span> <span class="val">' + (schema ? esc(schema.name || "") + " " + idChip(schema.id) : idChip(payload.schema_id)) + '</span></div>'
|
|
1475
|
+
+ '<div class="kv"><span class="k">Materialized</span> <span class="val">' + esc(payload.materialized_at ? relTime(payload.materialized_at) : "\u2014") + '</span></div>'
|
|
1476
|
+
+ '<div class="kv"><span class="k">Updated</span> <span class="val">' + esc(payload.updated_at ? relTime(payload.updated_at) : "\u2014") + '</span></div>'
|
|
1477
|
+
+ '</div>'
|
|
1478
|
+
+ railHtml + phaseHtml + fieldHtml + versionHtml;
|
|
1479
|
+
`;
|
|
1480
|
+
var WIDGET_HTML22 = buildWidgetHtml({ title: "Talonic \u2014 Spec", css: CSS, renderBody: RENDER_BODY22 });
|
|
1481
|
+
|
|
1482
|
+
// src/widgets/run-started.ts
|
|
1483
|
+
function getRunStartedWidgetHtml() {
|
|
1484
|
+
return WIDGET_HTML23;
|
|
1485
|
+
}
|
|
1486
|
+
var RENDER_BODY23 = `
|
|
1487
|
+
if (!payload || typeof payload !== "object" || (!payload.pipeline_id && !payload.run_id)) { empty("No run was started."); return; }
|
|
1488
|
+
function kb(n) { return typeof n === "number" ? (n >= 1048576 ? (n / 1048576).toFixed(1) + " MB" : Math.max(1, Math.round(n / 1024)) + " KB") : "\u2014"; }
|
|
1489
|
+
var kind = payload.run_kind === "run" ? "run" : "pipeline";
|
|
1490
|
+
var docs = Array.isArray(payload.documents) ? payload.documents : [];
|
|
1491
|
+
var pollArg = kind === "pipeline" && payload.pipeline_id ? "pipeline_id " + shortId(payload.pipeline_id) : "run_id " + shortId(payload.run_id);
|
|
1492
|
+
var docHtml = docs.length ? '<div class="plane"><div class="subtitle">Documents (' + docs.length + ')</div><table><thead><tr><th>File</th><th>Size</th><th></th></tr></thead><tbody>'
|
|
1493
|
+
+ docs.slice(0, 20).map(function (d) { d = d && typeof d === "object" ? d : {}; return '<tr><td class="val">' + esc(d.filename || shortId(d.document_id)) + '</td><td class="val">' + esc(kb(d.size_bytes)) + '</td><td>' + (d.deduplicated ? chip("deduplicated", "info") : "") + '</td></tr>'; }).join("")
|
|
1494
|
+
+ '</tbody></table>' + (docs.length > 20 ? '<div class="muted small">+' + (docs.length - 20) + ' more</div>' : "") + '</div>' : "";
|
|
1495
|
+
root.innerHTML = ''
|
|
1496
|
+
+ '<div class="header"><div><div class="title">' + (payload.appended ? "Documents appended" : "Run started") + '</div><div class="subtitle">' + esc(payload.spec_name || shortId(payload.spec_id)) + '</div></div>'
|
|
1497
|
+
+ '<div>' + chip(kind, "info") + chip(payload.status, payload.status === "failed" ? "bad" : payload.status === "completed" ? "good" : "") + '</div></div>'
|
|
1498
|
+
+ '<div class="big">' + esc(typeof payload.input_count === "number" ? payload.input_count : docs.length || "\u2014") + ' <span class="muted small">documents</span></div>'
|
|
1499
|
+
+ '<div class="grid">'
|
|
1500
|
+
+ '<div class="kv"><span class="k">Spec</span> <span class="val">' + idChip(payload.spec_id) + '</span></div>'
|
|
1501
|
+
+ '<div class="kv"><span class="k">Pipeline</span> <span class="val">' + idChip(payload.pipeline_id) + '</span></div>'
|
|
1502
|
+
+ '<div class="kv"><span class="k">Run</span> <span class="val">' + idChip(payload.run_id) + '</span></div>'
|
|
1503
|
+
+ '<div class="kv"><span class="k">Enqueued</span> <span class="val">' + esc(payload.enqueued_documents != null ? payload.enqueued_documents : "\u2014") + '</span></div>'
|
|
1504
|
+
+ '</div>'
|
|
1505
|
+
+ (payload.message ? '<div class="muted small" style="margin-top:8px">' + esc(payload.message) + '</div>' : "")
|
|
1506
|
+
+ '<div class="small" style="margin-top:8px">Poll with talonic_get_run (' + esc(pollArg) + ') every 5\u201310 s, then talonic_get_run_results.</div>'
|
|
1507
|
+
+ docHtml;
|
|
1508
|
+
`;
|
|
1509
|
+
var WIDGET_HTML23 = buildWidgetHtml({ title: "Talonic \u2014 Run Started", renderBody: RENDER_BODY23 });
|
|
1510
|
+
|
|
1511
|
+
// src/widgets/run-status.ts
|
|
1512
|
+
function getRunStatusWidgetHtml() {
|
|
1513
|
+
return WIDGET_HTML24;
|
|
1514
|
+
}
|
|
1515
|
+
var CSS2 = `
|
|
1516
|
+
.progress { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
|
|
1517
|
+
.progress .bar { width: 160px; height: 8px; }
|
|
1518
|
+
`;
|
|
1519
|
+
var RENDER_BODY24 = `
|
|
1520
|
+
if (!payload || typeof payload !== "object" || (!payload.pipeline_id && !payload.run_id)) { empty("No run to show."); return; }
|
|
1521
|
+
function tone(s) { return s === "completed" ? "good" : s === "failed" ? "bad" : "info"; }
|
|
1522
|
+
var status = typeof payload.status === "string" ? payload.status : "processing";
|
|
1523
|
+
var pr = payload.progress && typeof payload.progress === "object" ? payload.progress : {};
|
|
1524
|
+
var total = typeof pr.total_documents === "number" ? pr.total_documents : null;
|
|
1525
|
+
var done = typeof pr.completed_documents === "number" ? pr.completed_documents : null;
|
|
1526
|
+
var errs = typeof pr.error_documents === "number" ? pr.error_documents : null;
|
|
1527
|
+
var pct = total == null ? 0 : (total > 0 ? Math.max(0, Math.min(100, Math.round(((done || 0) / total) * 100))) : (status === "completed" ? 100 : 0));
|
|
1528
|
+
var totalText = total == null ? "\u2014" : String(total);
|
|
1529
|
+
var doneText = done == null ? "\u2014" : String(done);
|
|
1530
|
+
var phases = Array.isArray(pr.phases) ? pr.phases : [];
|
|
1531
|
+
var docs = Array.isArray(payload.documents) ? payload.documents : [];
|
|
1532
|
+
var pending = Array.isArray(pr.finalization_pending) ? pr.finalization_pending : [];
|
|
1533
|
+
var phaseHtml = phases.length ? '<div class="plane"><div class="subtitle">Phases</div><table><thead><tr><th>Phase</th><th>Type</th><th class="num">Done</th><th class="num">Running</th><th class="num">Errors</th></tr></thead><tbody>'
|
|
1534
|
+
+ phases.map(function (p) { p = p && typeof p === "object" ? p : {}; return '<tr><td class="val">' + esc(p.name || p.phase_id || "\u2014") + '</td><td>' + chip(p.type, "") + '</td><td class="val num">' + esc(p.completed != null ? p.completed : 0) + '</td><td class="val num">' + esc(p.running != null ? p.running : 0) + '</td><td class="val num">' + esc(p.errors != null ? p.errors : 0) + '</td></tr>'; }).join("")
|
|
1535
|
+
+ '</tbody></table></div>' : "";
|
|
1536
|
+
var docHtml = docs.length ? '<div class="plane"><div class="subtitle">Documents (' + docs.length + ')</div><table><thead><tr><th>File</th><th>Status</th></tr></thead><tbody>'
|
|
1537
|
+
+ docs.slice(0, 50).map(function (d) { d = d && typeof d === "object" ? d : {}; return '<tr><td class="val">' + esc(d.filename || shortId(d.document_id)) + '</td><td>' + chip(d.status, tone(d.status)) + '</td></tr>'; }).join("")
|
|
1538
|
+
+ '</tbody></table></div>' : "";
|
|
1539
|
+
root.innerHTML = ''
|
|
1540
|
+
+ '<div class="header"><div><div class="title">' + esc(payload.name || "Spec run") + '</div><div class="subtitle">' + esc(payload.run_kind === "run" ? "run " + shortId(payload.run_id) : "pipeline " + shortId(payload.pipeline_id)) + (payload.raw_status && payload.raw_status !== status ? ' \xB7 ' + esc(payload.raw_status) : "") + '</div></div>'
|
|
1541
|
+
+ '<div>' + chip(status, tone(status)) + '</div></div>'
|
|
1542
|
+
+ '<div class="progress"><span class="bar ' + (errs ? "warn" : "") + '"><span style="width:' + pct + '%"></span></span><span class="val">' + doneText + ' of ' + totalText + ' documents</span>' + (errs ? '<span class="muted small">\xB7 ' + errs + ' error' + (errs === 1 ? "" : "s") + '</span>' : "") + '</div>'
|
|
1543
|
+
+ (pending.length ? '<div class="muted small" style="margin-top:6px">Finalizing: ' + esc(pending.join(", ")) + '</div>' : "")
|
|
1544
|
+
+ (payload.error_message ? '<div class="small" style="margin-top:8px;color:var(--bad)">' + esc(payload.error_message) + '</div>' : "")
|
|
1545
|
+
+ phaseHtml + docHtml;
|
|
1546
|
+
`;
|
|
1547
|
+
var WIDGET_HTML24 = buildWidgetHtml({
|
|
1548
|
+
title: "Talonic \u2014 Run Progress",
|
|
1549
|
+
css: CSS2,
|
|
1550
|
+
renderBody: RENDER_BODY24
|
|
1551
|
+
});
|
|
1552
|
+
|
|
1553
|
+
// src/widgets/run-results.ts
|
|
1554
|
+
function getRunResultsWidgetHtml() {
|
|
1555
|
+
return WIDGET_HTML25;
|
|
1556
|
+
}
|
|
1557
|
+
var RENDER_BODY25 = `
|
|
1558
|
+
if (!payload || typeof payload !== "object") { empty("No result rows yet."); return; }
|
|
1559
|
+
var cols = Array.isArray(payload.columns) ? payload.columns.filter(function (c) { return c && typeof c === "object"; }) : [];
|
|
1560
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1561
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1562
|
+
if (!rows.length) { empty("No result rows yet."); return; }
|
|
1563
|
+
function tone(s) { return s === "complete" || s === "completed" ? "good" : s === "error" ? "bad" : s === "partial" ? "warn" : "info"; }
|
|
1564
|
+
var shownCols = cols.slice(0, 10);
|
|
1565
|
+
var head = '<tr><th>Document</th><th>Status</th>' + shownCols.map(function (c) { return '<th>' + esc(c.display_name || c.field_key || "") + '</th>'; }).join("") + '</tr>';
|
|
1566
|
+
var body = rows.slice(0, 50).map(function (r) {
|
|
1567
|
+
r = r && typeof r === "object" ? r : {};
|
|
1568
|
+
var f = r.fields && typeof r.fields === "object" ? r.fields : {};
|
|
1569
|
+
return '<tr><td class="val">' + esc(r.filename || shortId(r.document_id)) + '</td><td>' + chip(r.status, tone(r.status)) + '</td>'
|
|
1570
|
+
+ shownCols.map(function (c) { var v = f[c.field_key]; var text = v == null ? "\u2014" : (typeof v === "object" ? clamp(JSON.stringify(v), 60) : fmt(v)); return '<td class="val">' + esc(text) + '</td>'; }).join("") + '</tr>';
|
|
1571
|
+
}).join("");
|
|
1572
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1573
|
+
var held = typeof payload.pending_review_count === "number" ? payload.pending_review_count : 0;
|
|
1574
|
+
var more = [];
|
|
1575
|
+
if (rows.length > 50) more.push("+" + (rows.length - 50) + " more rows");
|
|
1576
|
+
if (cols.length > 10) more.push("+" + (cols.length - 10) + " more columns");
|
|
1577
|
+
root.innerHTML = ''
|
|
1578
|
+
+ '<div class="header"><div><div class="title">Run results</div><div class="subtitle">' + Math.min(rows.length, 50) + ' of ' + total + ' rows' + (pg.has_more ? " \xB7 more available" : "") + '</div></div>'
|
|
1579
|
+
+ '<div>' + chip(payload.status, payload.status === "completed" ? "good" : payload.status === "failed" ? "bad" : "info") + (held ? chip(held + " held for review", "warn") : "") + '</div></div>'
|
|
1580
|
+
+ '<table><thead>' + head + '</thead><tbody>' + body + '</tbody></table>'
|
|
1581
|
+
+ (more.length ? '<div class="muted small" style="margin-top:6px">' + esc(more.join(" \xB7 ")) + '</div>' : "");
|
|
1582
|
+
`;
|
|
1583
|
+
var WIDGET_HTML25 = buildWidgetHtml({ title: "Talonic \u2014 Run Results", renderBody: RENDER_BODY25 });
|
|
1584
|
+
|
|
1585
|
+
// src/widgets/answer.ts
|
|
1586
|
+
function getAnswerWidgetHtml() {
|
|
1587
|
+
return ANSWER_HTML;
|
|
1588
|
+
}
|
|
1589
|
+
function getAnswerPolledWidgetHtml() {
|
|
1590
|
+
return POLLED_HTML;
|
|
1591
|
+
}
|
|
1592
|
+
var CSS3 = `
|
|
1593
|
+
.cite { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--border); }
|
|
1594
|
+
.cite:last-child { border-bottom: none; }
|
|
1595
|
+
pre.md.answer { max-height: 480px; font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, sans-serif; }
|
|
1596
|
+
`;
|
|
1597
|
+
var ANSWER_BODY = `
|
|
1598
|
+
if (!payload || typeof payload !== "object" || !payload.ask_id) { empty("No answer."); return; }
|
|
1599
|
+
var status = typeof payload.status === "string" ? payload.status : "processing";
|
|
1600
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1601
|
+
var ver = obj(payload.verification);
|
|
1602
|
+
var usage = obj(payload.usage);
|
|
1603
|
+
var cites = Array.isArray(payload.citations) ? payload.citations : [];
|
|
1604
|
+
var arts = Array.isArray(payload.artifacts) ? payload.artifacts : [];
|
|
1605
|
+
var verdictTone = ver.verdict === "supported" ? "good" : ver.verdict === "issues" ? "warn" : ver.verdict === "unverifiable" ? "bad" : "";
|
|
1606
|
+
var head = '<div class="header"><div><div class="title">' + HEADLINE + '</div><div class="subtitle">ask ' + idChip(payload.ask_id) + (payload.conversation_id ? ' \xB7 conversation ' + idChip(payload.conversation_id) : "") + '</div></div>'
|
|
1607
|
+
+ '<div>' + (status === "completed" ? chip(ver.verdict, verdictTone) : chip(status, status === "error" ? "bad" : "info")) + '</div></div>';
|
|
1608
|
+
if (status === "processing") {
|
|
1609
|
+
root.innerHTML = head + '<div class="small">Still thinking\u2026 call talonic_get_answer with ask_id ' + idChip(payload.ask_id) + ' in a few seconds.</div>';
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
var answer = typeof payload.answer === "string" ? payload.answer : (payload.answer == null ? "" : fmt(payload.answer));
|
|
1613
|
+
var citeHtml = cites.length ? '<div class="plane"><div class="subtitle">Citations (' + cites.length + ')</div>' + cites.slice(0, 20).map(function (c, i) {
|
|
1614
|
+
c = obj(c);
|
|
1615
|
+
return '<div class="cite"><span class="small">[' + (i + 1) + '] \u201C' + esc(clamp(c.quote || fmt(c), 200)) + '\u201D</span><span class="muted small">' + chip(c.kind, c.kind === "field" ? "info" : "") + esc(c.filename || shortId(c.document_id)) + (c.reference ? ' \xB7 ' + esc(c.reference) : "") + '</span></div>';
|
|
1616
|
+
}).join("") + '</div>' : "";
|
|
1617
|
+
var artHtml = arts.length ? '<div class="plane"><div class="subtitle">Artifacts (' + arts.length + ')</div>' + arts.slice(0, 10).map(function (a) {
|
|
1618
|
+
a = obj(a);
|
|
1619
|
+
var link = typeof a.link === "string" && /^https:\\/\\//.test(a.link) ? a.link : "";
|
|
1620
|
+
return '<div class="kv"><span class="val">' + esc(a.label || a.type || a.id || "artifact") + '</span>' + (link ? '<a class="btn small" href="' + esc(link) + '" target="_blank" rel="noopener noreferrer">Open</a>' : "") + '</div>';
|
|
1621
|
+
}).join("") + '</div>' : "";
|
|
1622
|
+
var tiles = [];
|
|
1623
|
+
if (typeof usage.credits_charged === "number") tiles.push(usage.credits_charged + " credits");
|
|
1624
|
+
if (typeof usage.tokens === "number") tiles.push(usage.tokens + " tokens");
|
|
1625
|
+
if (typeof payload.tool_calls === "number") tiles.push(payload.tool_calls + " tool call" + (payload.tool_calls === 1 ? "" : "s"));
|
|
1626
|
+
if (typeof payload.waited_ms === "number") tiles.push((payload.waited_ms / 1000).toFixed(1) + " s");
|
|
1627
|
+
if (typeof ver.checks_total === "number") tiles.push(ver.checks_total + " checks, " + (ver.checks_unsupported || 0) + " unsupported");
|
|
1628
|
+
root.innerHTML = head
|
|
1629
|
+
+ (answer ? '<pre class="md answer">' + esc(answer) + '</pre>' : '<div class="muted small">The agent returned no answer text.</div>')
|
|
1630
|
+
+ (ver.correction ? '<div class="small" style="margin-top:6px"><span class="muted">Correction:</span> ' + esc(ver.correction) + '</div>' : "")
|
|
1631
|
+
+ citeHtml + artHtml
|
|
1632
|
+
+ (tiles.length ? '<div class="muted small" style="margin-top:10px">' + esc(tiles.join(" \xB7 ")) + '</div>' : "");
|
|
1633
|
+
`;
|
|
1634
|
+
function answerWidget(headline, title) {
|
|
1635
|
+
return buildWidgetHtml({
|
|
1636
|
+
title,
|
|
1637
|
+
css: CSS3,
|
|
1638
|
+
renderBody: " var HEADLINE = " + JSON.stringify(headline) + ";\n" + ANSWER_BODY
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
var ANSWER_HTML = answerWidget("Answer", "Talonic \u2014 Answer");
|
|
1642
|
+
var POLLED_HTML = answerWidget("Answer (polled)", "Talonic \u2014 Answer (polled)");
|
|
1643
|
+
|
|
1644
|
+
// src/widgets/decision-task-shared.ts
|
|
1645
|
+
var DECISION_JS = `
|
|
1646
|
+
function decisionTone(s) {
|
|
1647
|
+
return s === "available" ? "info" : s === "claimed" || s === "submitted" ? "good" : s === "failed" || s === "timed_out" ? "bad" : s === "released" || s === "cancelled" ? "warn" : "";
|
|
1648
|
+
}
|
|
1649
|
+
function decisionMeta(p) {
|
|
1650
|
+
return '<div class="grid">'
|
|
1651
|
+
+ '<div class="kv"><span class="k">Run</span> <span class="val">' + idChip(p.run_id) + '</span></div>'
|
|
1652
|
+
+ '<div class="kv"><span class="k">App</span> <span class="val">' + idChip(p.app_id) + '</span></div>'
|
|
1653
|
+
+ '<div class="kv"><span class="k">Execution epoch</span> <span class="val">' + esc(p.execution_epoch != null ? p.execution_epoch : "\u2014") + '</span></div>'
|
|
1654
|
+
+ '<div class="kv"><span class="k">Claimed by</span> <span class="val">' + esc(p.claimed_by || "\u2014") + '</span></div>'
|
|
1655
|
+
+ '<div class="kv"><span class="k">Lease expires</span> <span class="val">' + esc(p.lease_expires_at ? relTime(p.lease_expires_at) : "\u2014") + '</span></div>'
|
|
1656
|
+
+ '<div class="kv"><span class="k">SLA deadline</span> <span class="val">' + esc(p.sla_deadline_at ? relTime(p.sla_deadline_at) : "\u2014") + '</span></div>'
|
|
1657
|
+
+ '</div>';
|
|
1658
|
+
}
|
|
1659
|
+
`;
|
|
1660
|
+
|
|
1661
|
+
// src/widgets/decision-task-list.ts
|
|
1662
|
+
function getDecisionTaskListWidgetHtml() {
|
|
1663
|
+
return WIDGET_HTML26;
|
|
1664
|
+
}
|
|
1665
|
+
var RENDER_BODY26 = DECISION_JS + `
|
|
1666
|
+
if (!payload || typeof payload !== "object") { empty("No decision tasks for this app."); return; }
|
|
1667
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1668
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1669
|
+
if (!rows.length) { empty("No decision tasks for this app."); return; }
|
|
1670
|
+
var body = rows.map(function (t) {
|
|
1671
|
+
t = t && typeof t === "object" ? t : {};
|
|
1672
|
+
return '<tr><td>' + idChip(t.id) + '</td><td>' + chip(t.status, decisionTone(t.status)) + '</td><td>' + idChip(t.run_id) + '</td>'
|
|
1673
|
+
+ '<td class="val num">' + esc(t.execution_epoch != null ? t.execution_epoch : "\u2014") + '</td>'
|
|
1674
|
+
+ '<td class="val">' + esc(t.lease_expires_at ? relTime(t.lease_expires_at) : "\u2014") + '</td>'
|
|
1675
|
+
+ '<td class="val">' + esc(t.sla_deadline_at ? relTime(t.sla_deadline_at) : "\u2014") + '</td></tr>';
|
|
1676
|
+
}).join("");
|
|
1677
|
+
var counts = Object.create(null);
|
|
1678
|
+
rows.forEach(function (t) { var s = t && typeof t === "object" && t.status ? t.status : "unknown"; counts[s] = (counts[s] || 0) + 1; });
|
|
1679
|
+
var summary = Object.keys(counts).map(function (s) { return chip(counts[s] + " " + s, decisionTone(s)); }).join("");
|
|
1680
|
+
var app = rows[0] && typeof rows[0] === "object" ? rows[0].app_id : null;
|
|
1681
|
+
root.innerHTML = ''
|
|
1682
|
+
+ '<div class="header"><div><div class="title">Decision tasks</div><div class="subtitle">' + rows.length + ' task' + (rows.length === 1 ? "" : "s") + (app ? ' \xB7 app ' + idChip(app) : "") + (pg.has_more ? " \xB7 more available" : "") + '</div></div><div>' + summary + '</div></div>'
|
|
1683
|
+
+ '<table><thead><tr><th>Task</th><th>Status</th><th>Run</th><th class="num">Epoch</th><th>Lease</th><th>SLA</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1684
|
+
`;
|
|
1685
|
+
var WIDGET_HTML26 = buildWidgetHtml({ title: "Talonic \u2014 Decision Tasks", renderBody: RENDER_BODY26 });
|
|
1686
|
+
|
|
1687
|
+
// src/widgets/decision-bundle.ts
|
|
1688
|
+
function getDecisionBundleWidgetHtml() {
|
|
1689
|
+
return WIDGET_HTML27;
|
|
1690
|
+
}
|
|
1691
|
+
var RENDER_BODY27 = DECISION_JS + `
|
|
1692
|
+
var task = payload && payload.task && typeof payload.task === "object" ? payload.task : null;
|
|
1693
|
+
if (!task || !task.id) { empty("No decision task was claimed."); return; }
|
|
1694
|
+
var contract = payload.output_contract;
|
|
1695
|
+
var precedents = Array.isArray(payload.precedents) ? payload.precedents : [];
|
|
1696
|
+
var pkg = payload.package && typeof payload.package === "object" ? payload.package : {};
|
|
1697
|
+
var docs = Array.isArray(pkg.documents) ? pkg.documents : [];
|
|
1698
|
+
var contractHtml = contract && typeof contract === "object" ? (isFlat(contract) ? kvTiles(contract) : jsonTree(contract)) : '<div class="muted small">No output contract on this task.</div>';
|
|
1699
|
+
var precHtml = precedents.length ? '<div class="plane"><div class="subtitle">Precedents (' + precedents.length + ')</div>' + precedents.slice(0, 5).map(function (p) {
|
|
1700
|
+
p = p && typeof p === "object" ? p : {};
|
|
1701
|
+
return '<div class="kv"><span class="val mono">' + esc(clamp(fmt(p.outcome), 100)) + '</span><span class="muted small">' + esc(clamp(p.rationale || "", 160)) + (p.task_id ? ' \xB7 task ' + esc(shortId(p.task_id)) : "") + '</span></div>';
|
|
1702
|
+
}).join("") + '</div>' : "";
|
|
1703
|
+
var docHtml = docs.length ? '<div class="plane"><div class="subtitle">Source documents (' + docs.length + ')</div>' + docs.slice(0, 20).map(function (d) { d = d && typeof d === "object" ? d : {}; return chip(d.filename || shortId(d.document_id), ""); }).join("") + '</div>' : "";
|
|
1704
|
+
root.innerHTML = ''
|
|
1705
|
+
+ '<div class="header"><div><div class="title">Decision task claimed</div><div class="subtitle">task ' + idChip(task.id) + '</div></div><div>' + chip(task.status, decisionTone(task.status)) + '</div></div>'
|
|
1706
|
+
+ '<div class="big">' + esc(task.execution_epoch != null ? task.execution_epoch : "\u2014") + ' <span class="muted small">execution epoch</span></div>'
|
|
1707
|
+
+ '<div class="muted small">Keep this epoch for heartbeat, submit, release or fail.' + (task.lease_expires_at ? ' Lease expires ' + esc(relTime(task.lease_expires_at)) + '.' : "") + '</div>'
|
|
1708
|
+
+ decisionMeta(task)
|
|
1709
|
+
+ '<div class="plane"><div class="subtitle">Output contract</div>' + contractHtml + '</div>'
|
|
1710
|
+
+ '<div class="plane"><div class="subtitle">Input package</div><div class="grid">'
|
|
1711
|
+
+ '<div class="kv"><span class="k">Kind</span> <span class="val">' + esc(pkg.package_kind || "\u2014") + '</span></div>'
|
|
1712
|
+
+ '<div class="kv"><span class="k">Records</span> <span class="val">' + esc(pkg.record_count != null ? pkg.record_count : "\u2014") + '</span></div>'
|
|
1713
|
+
+ '<div class="kv"><span class="k">Page size</span> <span class="val">' + esc(pkg.page_size != null ? pkg.page_size : "\u2014") + '</span></div>'
|
|
1714
|
+
+ '<div class="kv"><span class="k">First cursor</span> <span class="val mono">' + esc(pkg.first_cursor ? clamp(pkg.first_cursor, 24) : "\u2014") + '</span></div>'
|
|
1715
|
+
+ '</div>' + (pkg.first_cursor ? '<div class="small" style="margin-top:6px">Read the records with talonic_read_decision_package starting at first_cursor.</div>' : "") + '</div>'
|
|
1716
|
+
+ precHtml + docHtml;
|
|
1717
|
+
`;
|
|
1718
|
+
var WIDGET_HTML27 = buildWidgetHtml({
|
|
1719
|
+
title: "Talonic \u2014 Decision Task Claimed",
|
|
1720
|
+
renderBody: RENDER_BODY27
|
|
1721
|
+
});
|
|
1722
|
+
|
|
1723
|
+
// src/widgets/decision-package.ts
|
|
1724
|
+
function getDecisionPackageWidgetHtml() {
|
|
1725
|
+
return WIDGET_HTML28;
|
|
1726
|
+
}
|
|
1727
|
+
var RENDER_BODY28 = `
|
|
1728
|
+
if (!payload || typeof payload !== "object" || !payload.task_id) { empty("No package page."); return; }
|
|
1729
|
+
var records = Array.isArray(payload.data) ? payload.data : [];
|
|
1730
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1731
|
+
var docs = Array.isArray(payload.documents) ? payload.documents : [];
|
|
1732
|
+
var body = !records.length ? '<div class="empty">This page has no records.</div>' : (isRowArray(records) ? dataTable(records) : jsonTree(records));
|
|
1733
|
+
var docHtml = docs.length ? '<div class="plane"><div class="subtitle">Source documents (' + docs.length + ')</div>' + docs.slice(0, 20).map(function (d) { d = d && typeof d === "object" ? d : {}; return chip(d.filename || shortId(d.document_id), ""); }).join("") + '</div>' : "";
|
|
1734
|
+
root.innerHTML = ''
|
|
1735
|
+
+ '<div class="header"><div><div class="title">Decision package</div><div class="subtitle">task ' + idChip(payload.task_id) + ' \xB7 run ' + idChip(payload.run_id) + '</div></div>'
|
|
1736
|
+
+ '<div>' + chip(records.length + ' of ' + (payload.record_count != null ? payload.record_count : "?") + ' records', "") + (pg.has_more ? chip("more pages", "info") : chip("last page", "good")) + '</div></div>'
|
|
1737
|
+
+ body
|
|
1738
|
+
+ (pg.next_cursor ? '<div class="muted small" style="margin-top:6px">Next page cursor: <span class="mono">' + esc(clamp(pg.next_cursor, 32)) + '</span></div>' : "")
|
|
1739
|
+
+ '<div class="small" style="margin-top:8px">Copy evidence locators verbatim from these records into talonic_submit_decision_task.</div>'
|
|
1740
|
+
+ docHtml;
|
|
1741
|
+
`;
|
|
1742
|
+
var WIDGET_HTML28 = buildWidgetHtml({
|
|
1743
|
+
title: "Talonic \u2014 Decision Package",
|
|
1744
|
+
renderBody: RENDER_BODY28
|
|
1745
|
+
});
|
|
1746
|
+
|
|
1747
|
+
// src/widgets/decision-task-card.ts
|
|
1748
|
+
function getDecisionHeartbeatWidgetHtml() {
|
|
1749
|
+
return HEARTBEAT_HTML2;
|
|
1750
|
+
}
|
|
1751
|
+
function getDecisionSubmittedWidgetHtml() {
|
|
1752
|
+
return SUBMITTED_HTML;
|
|
1753
|
+
}
|
|
1754
|
+
function getDecisionReleasedWidgetHtml() {
|
|
1755
|
+
return RELEASED_HTML;
|
|
1756
|
+
}
|
|
1757
|
+
function getDecisionFailedWidgetHtml() {
|
|
1758
|
+
return FAILED_HTML;
|
|
1759
|
+
}
|
|
1760
|
+
var CARD_BODY = `
|
|
1761
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No decision task."); return; }
|
|
1762
|
+
root.innerHTML = ''
|
|
1763
|
+
+ '<div class="header"><div><div class="title">' + HEADLINE + '</div><div class="subtitle">task ' + idChip(payload.id) + (payload.submitted_at ? ' \xB7 ' + esc(relTime(payload.submitted_at)) : "") + '</div></div>'
|
|
1764
|
+
+ '<div>' + chip(payload.status, decisionTone(payload.status)) + '</div></div>'
|
|
1765
|
+
+ '<div class="small">' + NOTE + '</div>'
|
|
1766
|
+
+ decisionMeta(payload);
|
|
1767
|
+
`;
|
|
1768
|
+
function card(headline, note, title) {
|
|
1769
|
+
return buildWidgetHtml({
|
|
1770
|
+
title,
|
|
1771
|
+
renderBody: DECISION_JS + " var HEADLINE = " + JSON.stringify(headline) + ";\n var NOTE = " + JSON.stringify(note) + ";\n" + CARD_BODY
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
var HEARTBEAT_HTML2 = card(
|
|
1775
|
+
"Lease extended",
|
|
1776
|
+
"Keep heartbeating before the lease expires; the SLA deadline is the hard stop.",
|
|
1777
|
+
"Talonic \u2014 Decision Task Lease"
|
|
1778
|
+
);
|
|
1779
|
+
var SUBMITTED_HTML = card(
|
|
1780
|
+
"Decision submitted",
|
|
1781
|
+
"The platform verified the decision and resumes the run.",
|
|
1782
|
+
"Talonic \u2014 Decision Submitted"
|
|
1783
|
+
);
|
|
1784
|
+
var RELEASED_HTML = card(
|
|
1785
|
+
"Task released",
|
|
1786
|
+
"The task is available again for another claimant; the next claim bumps the epoch.",
|
|
1787
|
+
"Talonic \u2014 Decision Task Released"
|
|
1788
|
+
);
|
|
1789
|
+
var FAILED_HTML = card(
|
|
1790
|
+
"Task failed",
|
|
1791
|
+
"A Human Review was raised with your reason and the app's fallback policy applies.",
|
|
1792
|
+
"Talonic \u2014 Decision Task Failed"
|
|
1793
|
+
);
|
|
1794
|
+
|
|
691
1795
|
// src/widgets/register.ts
|
|
692
|
-
|
|
693
|
-
|
|
1796
|
+
var WIDGET_REGISTRY = {
|
|
1797
|
+
extract: {
|
|
694
1798
|
name: "extraction-result-widget",
|
|
695
|
-
uri: WIDGET_URIS.extract,
|
|
696
1799
|
title: "Talonic Extraction Result",
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
}
|
|
701
|
-
function registerWidgets(server) {
|
|
702
|
-
registerExtractionResultWidget(server);
|
|
703
|
-
registerWidget(server, {
|
|
1800
|
+
html: getExtractionResultWidgetHtml
|
|
1801
|
+
},
|
|
1802
|
+
search: {
|
|
704
1803
|
name: "search-results-widget",
|
|
705
|
-
uri: WIDGET_URIS.search,
|
|
706
1804
|
title: "Talonic Search Results",
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
registerWidget(server, {
|
|
1805
|
+
html: getSearchResultsWidgetHtml
|
|
1806
|
+
},
|
|
1807
|
+
filter: {
|
|
711
1808
|
name: "filter-results-widget",
|
|
712
|
-
uri: WIDGET_URIS.filter,
|
|
713
1809
|
title: "Talonic Filter Results",
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
registerWidget(server, {
|
|
1810
|
+
html: getFilterResultsWidgetHtml
|
|
1811
|
+
},
|
|
1812
|
+
getDocument: {
|
|
718
1813
|
name: "document-meta-widget",
|
|
719
|
-
uri: WIDGET_URIS.getDocument,
|
|
720
1814
|
title: "Talonic Document",
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
registerWidget(server, {
|
|
1815
|
+
html: getDocumentMetaWidgetHtml
|
|
1816
|
+
},
|
|
1817
|
+
toMarkdown: {
|
|
725
1818
|
name: "markdown-view-widget",
|
|
726
|
-
uri: WIDGET_URIS.toMarkdown,
|
|
727
1819
|
title: "Talonic Markdown",
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
registerWidget(server, {
|
|
1820
|
+
html: getMarkdownViewWidgetHtml
|
|
1821
|
+
},
|
|
1822
|
+
listSchemas: {
|
|
732
1823
|
name: "schema-list-widget",
|
|
733
|
-
uri: WIDGET_URIS.listSchemas,
|
|
734
1824
|
title: "Talonic Schemas",
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
registerWidget(server, {
|
|
1825
|
+
html: getSchemaListWidgetHtml
|
|
1826
|
+
},
|
|
1827
|
+
saveSchema: {
|
|
739
1828
|
name: "schema-saved-widget",
|
|
740
|
-
uri: WIDGET_URIS.saveSchema,
|
|
741
1829
|
title: "Talonic Schema Saved",
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
html:
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
name: "
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
1830
|
+
html: getSchemaSavedWidgetHtml
|
|
1831
|
+
},
|
|
1832
|
+
getBalance: { name: "balance-widget", title: "Talonic Balance", html: getBalanceWidgetHtml },
|
|
1833
|
+
getPricing: { name: "pricing-widget", title: "Talonic Pricing", html: getPricingWidgetHtml },
|
|
1834
|
+
getUsage: { name: "usage-widget", title: "Talonic Usage", html: getUsageWidgetHtml },
|
|
1835
|
+
requestUpload: {
|
|
1836
|
+
name: "upload-link-widget",
|
|
1837
|
+
title: "Talonic Upload Link",
|
|
1838
|
+
html: getUploadLinkWidgetHtml
|
|
1839
|
+
},
|
|
1840
|
+
listFields: {
|
|
1841
|
+
name: "field-list-widget",
|
|
1842
|
+
title: "Talonic Field Registry",
|
|
1843
|
+
html: getFieldListWidgetHtml
|
|
1844
|
+
},
|
|
1845
|
+
getField: {
|
|
1846
|
+
name: "field-card-widget",
|
|
1847
|
+
title: "Talonic Field Card",
|
|
1848
|
+
html: getFieldCardWidgetHtml
|
|
1849
|
+
},
|
|
1850
|
+
fieldValues: {
|
|
1851
|
+
name: "field-values-widget",
|
|
1852
|
+
title: "Talonic Field Values",
|
|
1853
|
+
html: getFieldValuesWidgetHtml
|
|
1854
|
+
},
|
|
1855
|
+
findData: { name: "find-data-widget", title: "Talonic Find Data", html: getFindDataWidgetHtml },
|
|
1856
|
+
listAgentTools: {
|
|
1857
|
+
name: "agent-tools-widget",
|
|
1858
|
+
title: "Talonic Agent Tools",
|
|
1859
|
+
html: getAgentToolsWidgetHtml
|
|
1860
|
+
},
|
|
1861
|
+
invokeAgentTool: {
|
|
1862
|
+
name: "agent-tool-result-widget",
|
|
1863
|
+
title: "Talonic Agent Tool Result",
|
|
1864
|
+
html: getAgentToolResultWidgetHtml
|
|
1865
|
+
},
|
|
1866
|
+
listAgentTasks: {
|
|
1867
|
+
name: "agent-task-list-widget",
|
|
1868
|
+
title: "Talonic Agent Tasks",
|
|
1869
|
+
html: getAgentTaskListWidgetHtml
|
|
1870
|
+
},
|
|
1871
|
+
getAgentTask: {
|
|
1872
|
+
name: "agent-task-widget",
|
|
1873
|
+
title: "Talonic Agent Task",
|
|
1874
|
+
html: getAgentTaskWidgetHtml
|
|
1875
|
+
},
|
|
1876
|
+
claimAgentTask: {
|
|
1877
|
+
name: "agent-task-claim-widget",
|
|
1878
|
+
title: "Talonic Agent Task Claimed",
|
|
1879
|
+
html: getAgentTaskClaimWidgetHtml
|
|
1880
|
+
},
|
|
1881
|
+
heartbeatAgentTask: {
|
|
1882
|
+
name: "agent-task-heartbeat-widget",
|
|
1883
|
+
title: "Talonic Agent Task Lease",
|
|
1884
|
+
html: getAgentTaskHeartbeatWidgetHtml
|
|
1885
|
+
},
|
|
1886
|
+
submitAgentTask: {
|
|
1887
|
+
name: "agent-task-submitted-widget",
|
|
1888
|
+
title: "Talonic Agent Task Submitted",
|
|
1889
|
+
html: getAgentTaskSubmittedWidgetHtml
|
|
1890
|
+
},
|
|
1891
|
+
listSpecs: { name: "spec-list-widget", title: "Talonic Specs", html: getSpecListWidgetHtml },
|
|
1892
|
+
getSpec: { name: "spec-card-widget", title: "Talonic Spec", html: getSpecCardWidgetHtml },
|
|
1893
|
+
runSpec: {
|
|
1894
|
+
name: "run-started-widget",
|
|
1895
|
+
title: "Talonic Run Started",
|
|
1896
|
+
html: getRunStartedWidgetHtml
|
|
1897
|
+
},
|
|
1898
|
+
getRun: {
|
|
1899
|
+
name: "run-status-widget",
|
|
1900
|
+
title: "Talonic Run Progress",
|
|
1901
|
+
html: getRunStatusWidgetHtml
|
|
1902
|
+
},
|
|
1903
|
+
getRunResults: {
|
|
1904
|
+
name: "run-results-widget",
|
|
1905
|
+
title: "Talonic Run Results",
|
|
1906
|
+
html: getRunResultsWidgetHtml
|
|
1907
|
+
},
|
|
1908
|
+
ask: { name: "answer-widget", title: "Talonic Answer", html: getAnswerWidgetHtml },
|
|
1909
|
+
getAnswer: {
|
|
1910
|
+
name: "answer-polled-widget",
|
|
1911
|
+
title: "Talonic Answer (polled)",
|
|
1912
|
+
html: getAnswerPolledWidgetHtml
|
|
1913
|
+
},
|
|
1914
|
+
listDecisionTasks: {
|
|
1915
|
+
name: "decision-task-list-widget",
|
|
1916
|
+
title: "Talonic Decision Tasks",
|
|
1917
|
+
html: getDecisionTaskListWidgetHtml
|
|
1918
|
+
},
|
|
1919
|
+
claimDecisionTask: {
|
|
1920
|
+
name: "decision-bundle-widget",
|
|
1921
|
+
title: "Talonic Decision Task Claimed",
|
|
1922
|
+
html: getDecisionBundleWidgetHtml
|
|
1923
|
+
},
|
|
1924
|
+
readDecisionPackage: {
|
|
1925
|
+
name: "decision-package-widget",
|
|
1926
|
+
title: "Talonic Decision Package",
|
|
1927
|
+
html: getDecisionPackageWidgetHtml
|
|
1928
|
+
},
|
|
1929
|
+
heartbeatDecisionTask: {
|
|
1930
|
+
name: "decision-task-heartbeat-widget",
|
|
1931
|
+
title: "Talonic Decision Task Lease",
|
|
1932
|
+
html: getDecisionHeartbeatWidgetHtml
|
|
1933
|
+
},
|
|
1934
|
+
submitDecisionTask: {
|
|
1935
|
+
name: "decision-task-submitted-widget",
|
|
1936
|
+
title: "Talonic Decision Submitted",
|
|
1937
|
+
html: getDecisionSubmittedWidgetHtml
|
|
1938
|
+
},
|
|
1939
|
+
releaseDecisionTask: {
|
|
1940
|
+
name: "decision-task-released-widget",
|
|
1941
|
+
title: "Talonic Decision Task Released",
|
|
1942
|
+
html: getDecisionReleasedWidgetHtml
|
|
1943
|
+
},
|
|
1944
|
+
failDecisionTask: {
|
|
1945
|
+
name: "decision-task-failed-widget",
|
|
1946
|
+
title: "Talonic Decision Task Failed",
|
|
1947
|
+
html: getDecisionFailedWidgetHtml
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
function registerOne(server, key) {
|
|
1951
|
+
const entry = WIDGET_REGISTRY[key];
|
|
766
1952
|
registerWidget(server, {
|
|
767
|
-
name:
|
|
768
|
-
uri: WIDGET_URIS
|
|
769
|
-
title:
|
|
770
|
-
description:
|
|
771
|
-
html:
|
|
1953
|
+
name: entry.name,
|
|
1954
|
+
uri: WIDGET_URIS[key],
|
|
1955
|
+
title: entry.title,
|
|
1956
|
+
description: WIDGET_DESCRIPTIONS[key],
|
|
1957
|
+
html: entry.html()
|
|
772
1958
|
});
|
|
773
1959
|
}
|
|
774
|
-
function
|
|
775
|
-
const
|
|
776
|
-
content: [
|
|
777
|
-
{
|
|
778
|
-
type: "text",
|
|
779
|
-
text: JSON.stringify(value, null, 2)
|
|
780
|
-
}
|
|
781
|
-
]
|
|
782
|
-
};
|
|
783
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
784
|
-
result["structuredContent"] = value;
|
|
785
|
-
}
|
|
786
|
-
return result;
|
|
787
|
-
}
|
|
788
|
-
function validationError(message) {
|
|
789
|
-
return {
|
|
790
|
-
isError: true,
|
|
791
|
-
content: [{ type: "text", text: `Validation error: ${message}` }]
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
function toolError(err) {
|
|
795
|
-
if (err instanceof TalonicError) {
|
|
796
|
-
const lines = [
|
|
797
|
-
`Talonic API error: ${err.message}`,
|
|
798
|
-
`code: ${err.code}`,
|
|
799
|
-
`status: ${err.status}`
|
|
800
|
-
];
|
|
801
|
-
if (err.requestId) lines.push(`request_id: ${err.requestId}`);
|
|
802
|
-
return {
|
|
803
|
-
isError: true,
|
|
804
|
-
content: [{ type: "text", text: lines.join("\n") }]
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
return {
|
|
808
|
-
isError: true,
|
|
809
|
-
content: [
|
|
810
|
-
{
|
|
811
|
-
type: "text",
|
|
812
|
-
text: `Unexpected error: ${err instanceof Error ? err.message : String(err)}`
|
|
813
|
-
}
|
|
814
|
-
]
|
|
815
|
-
};
|
|
1960
|
+
function registerWidgets(server) {
|
|
1961
|
+
for (const key of Object.keys(WIDGET_REGISTRY)) registerOne(server, key);
|
|
816
1962
|
}
|
|
817
|
-
|
|
818
|
-
// src/tools/extract.ts
|
|
819
1963
|
var DESCRIPTION = [
|
|
820
1964
|
"Turn ANY document into structured, schema-validated JSON. The default tool whenever you need to get data OUT of an unstructured file: PDF, scan, image, DOCX, email, or photo. Returns the requested fields with per-field confidence scores.",
|
|
821
1965
|
"",
|
|
@@ -990,10 +2134,7 @@ function registerExtract(server, getTalonic) {
|
|
|
990
2134
|
destructiveHint: false,
|
|
991
2135
|
openWorldHint: true
|
|
992
2136
|
},
|
|
993
|
-
_meta:
|
|
994
|
-
ui: { resourceUri: EXTRACTION_RESULT_WIDGET_URI },
|
|
995
|
-
"openai/outputTemplate": EXTRACTION_RESULT_WIDGET_URI
|
|
996
|
-
}
|
|
2137
|
+
_meta: widgetToolMeta("extract")
|
|
997
2138
|
},
|
|
998
2139
|
async (args) => handleExtract(getTalonic(), args)
|
|
999
2140
|
);
|
|
@@ -1122,10 +2263,7 @@ function registerFilter(server, getTalonic) {
|
|
|
1122
2263
|
destructiveHint: false,
|
|
1123
2264
|
openWorldHint: false
|
|
1124
2265
|
},
|
|
1125
|
-
_meta:
|
|
1126
|
-
ui: { resourceUri: WIDGET_URIS.filter },
|
|
1127
|
-
"openai/outputTemplate": WIDGET_URIS.filter
|
|
1128
|
-
}
|
|
2266
|
+
_meta: widgetToolMeta("filter")
|
|
1129
2267
|
},
|
|
1130
2268
|
async (args) => handleFilter(getTalonic(), args)
|
|
1131
2269
|
);
|
|
@@ -1171,10 +2309,7 @@ function registerGetBalance(server, getTalonic) {
|
|
|
1171
2309
|
destructiveHint: false,
|
|
1172
2310
|
openWorldHint: false
|
|
1173
2311
|
},
|
|
1174
|
-
_meta:
|
|
1175
|
-
ui: { resourceUri: WIDGET_URIS.getBalance },
|
|
1176
|
-
"openai/outputTemplate": WIDGET_URIS.getBalance
|
|
1177
|
-
}
|
|
2312
|
+
_meta: widgetToolMeta("getBalance")
|
|
1178
2313
|
},
|
|
1179
2314
|
async () => handleGetBalance(getTalonic())
|
|
1180
2315
|
);
|
|
@@ -1226,10 +2361,7 @@ function registerGetPricing(server, getTalonic) {
|
|
|
1226
2361
|
destructiveHint: false,
|
|
1227
2362
|
openWorldHint: false
|
|
1228
2363
|
},
|
|
1229
|
-
_meta:
|
|
1230
|
-
ui: { resourceUri: WIDGET_URIS.getPricing },
|
|
1231
|
-
"openai/outputTemplate": WIDGET_URIS.getPricing
|
|
1232
|
-
}
|
|
2364
|
+
_meta: widgetToolMeta("getPricing")
|
|
1233
2365
|
},
|
|
1234
2366
|
async () => handleGetPricing(getTalonic())
|
|
1235
2367
|
);
|
|
@@ -1278,10 +2410,7 @@ function registerGetUsage(server, getTalonic) {
|
|
|
1278
2410
|
destructiveHint: false,
|
|
1279
2411
|
openWorldHint: false
|
|
1280
2412
|
},
|
|
1281
|
-
_meta:
|
|
1282
|
-
ui: { resourceUri: WIDGET_URIS.getUsage },
|
|
1283
|
-
"openai/outputTemplate": WIDGET_URIS.getUsage
|
|
1284
|
-
}
|
|
2413
|
+
_meta: widgetToolMeta("getUsage")
|
|
1285
2414
|
},
|
|
1286
2415
|
async (args) => handleGetUsage(getTalonic(), args.days)
|
|
1287
2416
|
);
|
|
@@ -1372,10 +2501,7 @@ function registerGetDocument(server, getTalonic) {
|
|
|
1372
2501
|
destructiveHint: false,
|
|
1373
2502
|
openWorldHint: false
|
|
1374
2503
|
},
|
|
1375
|
-
_meta:
|
|
1376
|
-
ui: { resourceUri: WIDGET_URIS.getDocument },
|
|
1377
|
-
"openai/outputTemplate": WIDGET_URIS.getDocument
|
|
1378
|
-
}
|
|
2504
|
+
_meta: widgetToolMeta("getDocument")
|
|
1379
2505
|
},
|
|
1380
2506
|
async (args) => handleGetDocument(getTalonic(), args)
|
|
1381
2507
|
);
|
|
@@ -1445,10 +2571,7 @@ function registerListSchemas(server, getTalonic) {
|
|
|
1445
2571
|
destructiveHint: false,
|
|
1446
2572
|
openWorldHint: false
|
|
1447
2573
|
},
|
|
1448
|
-
_meta:
|
|
1449
|
-
ui: { resourceUri: WIDGET_URIS.listSchemas },
|
|
1450
|
-
"openai/outputTemplate": WIDGET_URIS.listSchemas
|
|
1451
|
-
}
|
|
2574
|
+
_meta: widgetToolMeta("listSchemas")
|
|
1452
2575
|
},
|
|
1453
2576
|
async () => handleListSchemas(getTalonic())
|
|
1454
2577
|
);
|
|
@@ -1512,10 +2635,7 @@ function registerSaveSchema(server, getTalonic) {
|
|
|
1512
2635
|
destructiveHint: false,
|
|
1513
2636
|
openWorldHint: false
|
|
1514
2637
|
},
|
|
1515
|
-
_meta:
|
|
1516
|
-
ui: { resourceUri: WIDGET_URIS.saveSchema },
|
|
1517
|
-
"openai/outputTemplate": WIDGET_URIS.saveSchema
|
|
1518
|
-
}
|
|
2638
|
+
_meta: widgetToolMeta("saveSchema")
|
|
1519
2639
|
},
|
|
1520
2640
|
async (args) => handleSaveSchema(getTalonic(), args)
|
|
1521
2641
|
);
|
|
@@ -1613,10 +2733,7 @@ function registerSearch(server, getTalonic) {
|
|
|
1613
2733
|
destructiveHint: false,
|
|
1614
2734
|
openWorldHint: false
|
|
1615
2735
|
},
|
|
1616
|
-
_meta:
|
|
1617
|
-
ui: { resourceUri: WIDGET_URIS.search },
|
|
1618
|
-
"openai/outputTemplate": WIDGET_URIS.search
|
|
1619
|
-
}
|
|
2736
|
+
_meta: widgetToolMeta("search")
|
|
1620
2737
|
},
|
|
1621
2738
|
async (args) => handleSearch(getTalonic(), args)
|
|
1622
2739
|
);
|
|
@@ -1645,7 +2762,7 @@ async function handleRequestUpload(getToken, baseUrl, args) {
|
|
|
1645
2762
|
try {
|
|
1646
2763
|
const base = baseUrl ?? "https://api.talonic.com";
|
|
1647
2764
|
const token = getToken();
|
|
1648
|
-
const res = await
|
|
2765
|
+
const res = await resolveFetch(getToken)(`${base}/v1/documents/upload-session`, {
|
|
1649
2766
|
method: "POST",
|
|
1650
2767
|
headers: {
|
|
1651
2768
|
Authorization: `Bearer ${token}`,
|
|
@@ -1684,22 +2801,19 @@ function registerRequestUpload(server, getToken, baseUrl) {
|
|
|
1684
2801
|
destructiveHint: false,
|
|
1685
2802
|
openWorldHint: false
|
|
1686
2803
|
},
|
|
1687
|
-
_meta:
|
|
1688
|
-
ui: { resourceUri: WIDGET_URIS.requestUpload },
|
|
1689
|
-
"openai/outputTemplate": WIDGET_URIS.requestUpload
|
|
1690
|
-
}
|
|
2804
|
+
_meta: widgetToolMeta("requestUpload")
|
|
1691
2805
|
},
|
|
1692
2806
|
async (args) => handleRequestUpload(getToken, baseUrl, args)
|
|
1693
2807
|
);
|
|
1694
2808
|
}
|
|
1695
|
-
var
|
|
2809
|
+
var DEFAULT_BASE2 = "https://api.talonic.com";
|
|
1696
2810
|
var RANGES = ["7d", "30d", "90d"];
|
|
1697
2811
|
async function growthGet(getToken, baseUrl, path, params) {
|
|
1698
2812
|
try {
|
|
1699
2813
|
const qs = new URLSearchParams();
|
|
1700
2814
|
for (const [k, v] of Object.entries(params)) if (v !== void 0 && v !== "") qs.set(k, v);
|
|
1701
|
-
const url = `${baseUrl ??
|
|
1702
|
-
const res = await
|
|
2815
|
+
const url = `${baseUrl ?? DEFAULT_BASE2}/v1/growth/${path}${qs.size ? `?${qs}` : ""}`;
|
|
2816
|
+
const res = await resolveFetch(getToken)(url, {
|
|
1703
2817
|
headers: { Authorization: `Bearer ${getToken()}`, Accept: "application/json" }
|
|
1704
2818
|
});
|
|
1705
2819
|
if (res.status === 403) {
|
|
@@ -1722,7 +2836,7 @@ async function growthGet(getToken, baseUrl, path, params) {
|
|
|
1722
2836
|
}
|
|
1723
2837
|
async function probeGrowthAccess(token, baseUrl) {
|
|
1724
2838
|
try {
|
|
1725
|
-
const res = await fetch(`${baseUrl ??
|
|
2839
|
+
const res = await fetch(`${baseUrl ?? DEFAULT_BASE2}/v1/growth/access`, {
|
|
1726
2840
|
headers: { Authorization: `Bearer ${token}`, Accept: "application/json" },
|
|
1727
2841
|
signal: AbortSignal.timeout(5e3)
|
|
1728
2842
|
});
|
|
@@ -1845,7 +2959,7 @@ function registerGrowthTools(server, getToken, baseUrl) {
|
|
|
1845
2959
|
async (args) => handleGrowthToolsUsage(getToken, baseUrl, args)
|
|
1846
2960
|
);
|
|
1847
2961
|
}
|
|
1848
|
-
var
|
|
2962
|
+
var DEFAULT_BASE3 = "https://api.talonic.com";
|
|
1849
2963
|
var TASK_STATUSES = ["available", "claimed", "submitted", "timed_out", "cancelled"];
|
|
1850
2964
|
var taskId = z.string().uuid().describe("Agent task UUID.");
|
|
1851
2965
|
var executionEpoch = z.number().int().min(1).max(2147483647).describe("Execution epoch returned by the successful claim. Stale epochs are rejected.");
|
|
@@ -1876,7 +2990,7 @@ var adminPayloadAccessInput = {
|
|
|
1876
2990
|
totp_code: adminTotp
|
|
1877
2991
|
};
|
|
1878
2992
|
function apiUrl(baseUrl, path, query) {
|
|
1879
|
-
const base = (baseUrl ??
|
|
2993
|
+
const base = (baseUrl ?? DEFAULT_BASE3).replace(/\/$/, "");
|
|
1880
2994
|
const url = new URL(`${base}${path}`);
|
|
1881
2995
|
for (const [key, value] of Object.entries(query ?? {})) {
|
|
1882
2996
|
if (value !== void 0 && value !== "") url.searchParams.set(key, String(value));
|
|
@@ -1885,7 +2999,7 @@ function apiUrl(baseUrl, path, query) {
|
|
|
1885
2999
|
}
|
|
1886
3000
|
async function agentTaskRequest(getToken, baseUrl, request) {
|
|
1887
3001
|
try {
|
|
1888
|
-
const response = await
|
|
3002
|
+
const response = await resolveFetch(getToken)(apiUrl(baseUrl, request.path, request.query), {
|
|
1889
3003
|
method: request.method ?? "GET",
|
|
1890
3004
|
headers: {
|
|
1891
3005
|
Authorization: `Bearer ${getToken()}`,
|
|
@@ -2058,7 +3172,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2058
3172
|
title: "List Agent Tasks",
|
|
2059
3173
|
description: DESCRIPTIONS.list,
|
|
2060
3174
|
inputSchema: listInput,
|
|
2061
|
-
annotations: { title: "List Agent Tasks", ...READ_ONLY2 }
|
|
3175
|
+
annotations: { title: "List Agent Tasks", ...READ_ONLY2 },
|
|
3176
|
+
_meta: widgetToolMeta("listAgentTasks")
|
|
2062
3177
|
},
|
|
2063
3178
|
async (args) => handleListAgentTasks(getToken, baseUrl, args)
|
|
2064
3179
|
);
|
|
@@ -2068,7 +3183,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2068
3183
|
title: "Get Agent Task",
|
|
2069
3184
|
description: DESCRIPTIONS.get,
|
|
2070
3185
|
inputSchema: idInput,
|
|
2071
|
-
annotations: { title: "Get Agent Task", ...READ_ONLY2 }
|
|
3186
|
+
annotations: { title: "Get Agent Task", ...READ_ONLY2 },
|
|
3187
|
+
_meta: widgetToolMeta("getAgentTask")
|
|
2072
3188
|
},
|
|
2073
3189
|
async (args) => handleGetAgentTask(getToken, baseUrl, args)
|
|
2074
3190
|
);
|
|
@@ -2078,7 +3194,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2078
3194
|
title: "Claim Agent Task",
|
|
2079
3195
|
description: DESCRIPTIONS.claim,
|
|
2080
3196
|
inputSchema: idInput,
|
|
2081
|
-
annotations: { title: "Claim Agent Task", ...MUTATING }
|
|
3197
|
+
annotations: { title: "Claim Agent Task", ...MUTATING },
|
|
3198
|
+
_meta: widgetToolMeta("claimAgentTask")
|
|
2082
3199
|
},
|
|
2083
3200
|
async (args) => handleClaimAgentTask(getToken, baseUrl, args)
|
|
2084
3201
|
);
|
|
@@ -2088,7 +3205,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2088
3205
|
title: "Heartbeat Agent Task",
|
|
2089
3206
|
description: DESCRIPTIONS.heartbeat,
|
|
2090
3207
|
inputSchema: heartbeatInput,
|
|
2091
|
-
annotations: { title: "Heartbeat Agent Task", ...MUTATING }
|
|
3208
|
+
annotations: { title: "Heartbeat Agent Task", ...MUTATING },
|
|
3209
|
+
_meta: widgetToolMeta("heartbeatAgentTask")
|
|
2092
3210
|
},
|
|
2093
3211
|
async (args) => handleHeartbeatAgentTask(getToken, baseUrl, args)
|
|
2094
3212
|
);
|
|
@@ -2098,7 +3216,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2098
3216
|
title: "Submit Agent Task",
|
|
2099
3217
|
description: DESCRIPTIONS.submit,
|
|
2100
3218
|
inputSchema: submitInput,
|
|
2101
|
-
annotations: { title: "Submit Agent Task", ...MUTATING }
|
|
3219
|
+
annotations: { title: "Submit Agent Task", ...MUTATING },
|
|
3220
|
+
_meta: widgetToolMeta("submitAgentTask")
|
|
2102
3221
|
},
|
|
2103
3222
|
async (args) => handleSubmitAgentTask(getToken, baseUrl, args)
|
|
2104
3223
|
);
|
|
@@ -2171,43 +3290,6 @@ function registerAdminAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2171
3290
|
async (args) => handleAdminSubmitAgentTask(getToken, baseUrl, args)
|
|
2172
3291
|
);
|
|
2173
3292
|
}
|
|
2174
|
-
|
|
2175
|
-
// src/tools/_http.ts
|
|
2176
|
-
var DEFAULT_BASE3 = "https://api.talonic.com";
|
|
2177
|
-
function buildUrl(baseUrl, path, params = {}) {
|
|
2178
|
-
const qs = new URLSearchParams();
|
|
2179
|
-
for (const [k, v] of Object.entries(params)) {
|
|
2180
|
-
if (v === void 0 || v === "") continue;
|
|
2181
|
-
qs.set(k, String(v));
|
|
2182
|
-
}
|
|
2183
|
-
return `${baseUrl ?? DEFAULT_BASE3}${path}${qs.size ? `?${qs}` : ""}`;
|
|
2184
|
-
}
|
|
2185
|
-
async function apiJson(getToken, baseUrl, method, path, opts = {}) {
|
|
2186
|
-
const url = buildUrl(baseUrl, path, opts.params);
|
|
2187
|
-
const res = await fetch(url, {
|
|
2188
|
-
method,
|
|
2189
|
-
headers: {
|
|
2190
|
-
Authorization: `Bearer ${getToken()}`,
|
|
2191
|
-
Accept: "application/json",
|
|
2192
|
-
...opts.body !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
2193
|
-
},
|
|
2194
|
-
...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {}
|
|
2195
|
-
});
|
|
2196
|
-
if (!res.ok) {
|
|
2197
|
-
const text = await res.text().catch(() => "");
|
|
2198
|
-
throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
|
|
2199
|
-
}
|
|
2200
|
-
return await res.json();
|
|
2201
|
-
}
|
|
2202
|
-
async function runTool(fn) {
|
|
2203
|
-
try {
|
|
2204
|
-
return jsonOk(await fn());
|
|
2205
|
-
} catch (err) {
|
|
2206
|
-
return toolError(err);
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2210
|
-
// src/tools/decision-tasks.ts
|
|
2211
3293
|
var DECIDE_SCOPE = "apps:decide";
|
|
2212
3294
|
var TASK_STATUSES2 = [
|
|
2213
3295
|
"available",
|
|
@@ -2392,7 +3474,12 @@ var DESCRIPTIONS2 = {
|
|
|
2392
3474
|
function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
2393
3475
|
const invocable = options.invocable !== false;
|
|
2394
3476
|
const describe = (text) => invocable ? text : NOT_INVOCABLE_PREFIX + text;
|
|
2395
|
-
const
|
|
3477
|
+
const metaFor = (key) => ({
|
|
3478
|
+
_meta: {
|
|
3479
|
+
...widgetToolMeta(key),
|
|
3480
|
+
...invocable ? {} : { "talonic/can_invoke": false, "talonic/required_scope": DECIDE_SCOPE }
|
|
3481
|
+
}
|
|
3482
|
+
});
|
|
2396
3483
|
server.registerTool(
|
|
2397
3484
|
"talonic_list_decision_tasks",
|
|
2398
3485
|
{
|
|
@@ -2400,7 +3487,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2400
3487
|
description: describe(DESCRIPTIONS2.list),
|
|
2401
3488
|
inputSchema: listInput2,
|
|
2402
3489
|
annotations: { title: "List Decision Tasks", ...READ_ONLY3 },
|
|
2403
|
-
...
|
|
3490
|
+
...metaFor("listDecisionTasks")
|
|
2404
3491
|
},
|
|
2405
3492
|
async (args) => handleListDecisionTasks(getToken, baseUrl, args)
|
|
2406
3493
|
);
|
|
@@ -2411,7 +3498,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2411
3498
|
description: describe(DESCRIPTIONS2.claim),
|
|
2412
3499
|
inputSchema: idInput2,
|
|
2413
3500
|
annotations: { title: "Claim Decision Task", ...MUTATING2 },
|
|
2414
|
-
...
|
|
3501
|
+
...metaFor("claimDecisionTask")
|
|
2415
3502
|
},
|
|
2416
3503
|
async (args) => handleClaimDecisionTask(getToken, baseUrl, args)
|
|
2417
3504
|
);
|
|
@@ -2422,7 +3509,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2422
3509
|
description: describe(DESCRIPTIONS2.package),
|
|
2423
3510
|
inputSchema: packageInput,
|
|
2424
3511
|
annotations: { title: "Read Decision Package", ...READ_ONLY3 },
|
|
2425
|
-
...
|
|
3512
|
+
...metaFor("readDecisionPackage")
|
|
2426
3513
|
},
|
|
2427
3514
|
async (args) => handleReadDecisionPackage(getToken, baseUrl, args)
|
|
2428
3515
|
);
|
|
@@ -2433,7 +3520,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2433
3520
|
description: describe(DESCRIPTIONS2.heartbeat),
|
|
2434
3521
|
inputSchema: epochInput,
|
|
2435
3522
|
annotations: { title: "Heartbeat Decision Task", ...MUTATING2 },
|
|
2436
|
-
...
|
|
3523
|
+
...metaFor("heartbeatDecisionTask")
|
|
2437
3524
|
},
|
|
2438
3525
|
async (args) => handleHeartbeatDecisionTask(getToken, baseUrl, args)
|
|
2439
3526
|
);
|
|
@@ -2444,7 +3531,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2444
3531
|
description: describe(DESCRIPTIONS2.submit),
|
|
2445
3532
|
inputSchema: submitInput2,
|
|
2446
3533
|
annotations: { title: "Submit Decision Task", ...MUTATING2 },
|
|
2447
|
-
...
|
|
3534
|
+
...metaFor("submitDecisionTask")
|
|
2448
3535
|
},
|
|
2449
3536
|
async (args) => handleSubmitDecisionTask(getToken, baseUrl, args)
|
|
2450
3537
|
);
|
|
@@ -2455,7 +3542,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2455
3542
|
description: describe(DESCRIPTIONS2.release),
|
|
2456
3543
|
inputSchema: epochInput,
|
|
2457
3544
|
annotations: { title: "Release Decision Task", ...MUTATING2 },
|
|
2458
|
-
...
|
|
3545
|
+
...metaFor("releaseDecisionTask")
|
|
2459
3546
|
},
|
|
2460
3547
|
async (args) => handleReleaseDecisionTask(getToken, baseUrl, args)
|
|
2461
3548
|
);
|
|
@@ -2466,7 +3553,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2466
3553
|
description: describe(DESCRIPTIONS2.fail),
|
|
2467
3554
|
inputSchema: failInput,
|
|
2468
3555
|
annotations: { title: "Fail Decision Task", ...MUTATING2 },
|
|
2469
|
-
...
|
|
3556
|
+
...metaFor("failDecisionTask")
|
|
2470
3557
|
},
|
|
2471
3558
|
async (args) => handleFailDecisionTask(getToken, baseUrl, args)
|
|
2472
3559
|
);
|
|
@@ -2567,10 +3654,7 @@ function registerToMarkdown(server, getTalonic) {
|
|
|
2567
3654
|
destructiveHint: false,
|
|
2568
3655
|
openWorldHint: true
|
|
2569
3656
|
},
|
|
2570
|
-
_meta:
|
|
2571
|
-
ui: { resourceUri: WIDGET_URIS.toMarkdown },
|
|
2572
|
-
"openai/outputTemplate": WIDGET_URIS.toMarkdown
|
|
2573
|
-
}
|
|
3657
|
+
_meta: widgetToolMeta("toMarkdown")
|
|
2574
3658
|
},
|
|
2575
3659
|
async (args) => handleToMarkdown(getTalonic(), args)
|
|
2576
3660
|
);
|
|
@@ -2644,7 +3728,7 @@ async function handleGetField(getToken, baseUrl, args) {
|
|
|
2644
3728
|
return validationError("Provide either `field_id` or `name`, not both.");
|
|
2645
3729
|
return runTool(async () => {
|
|
2646
3730
|
const { id, resolution } = await resolveFieldId(getToken, baseUrl, args);
|
|
2647
|
-
const
|
|
3731
|
+
const card2 = await apiJson(
|
|
2648
3732
|
getToken,
|
|
2649
3733
|
baseUrl,
|
|
2650
3734
|
"GET",
|
|
@@ -2653,7 +3737,7 @@ async function handleGetField(getToken, baseUrl, args) {
|
|
|
2653
3737
|
params: { follow_redirects: true }
|
|
2654
3738
|
}
|
|
2655
3739
|
);
|
|
2656
|
-
const out = { ...
|
|
3740
|
+
const out = { ...card2 };
|
|
2657
3741
|
if (resolution) out["resolution"] = resolution;
|
|
2658
3742
|
if (args.include_history) {
|
|
2659
3743
|
out["history"] = await apiJson(getToken, baseUrl, "GET", `/v1/fields/${id}/history`, {
|
|
@@ -2714,7 +3798,8 @@ function registerFieldTools(server, getToken, baseUrl) {
|
|
|
2714
3798
|
destructiveHint: false,
|
|
2715
3799
|
idempotentHint: true,
|
|
2716
3800
|
openWorldHint: false
|
|
2717
|
-
}
|
|
3801
|
+
},
|
|
3802
|
+
_meta: widgetToolMeta("listFields")
|
|
2718
3803
|
},
|
|
2719
3804
|
async (args) => handleListFields(getToken, baseUrl, args)
|
|
2720
3805
|
);
|
|
@@ -2729,7 +3814,8 @@ function registerFieldTools(server, getToken, baseUrl) {
|
|
|
2729
3814
|
destructiveHint: false,
|
|
2730
3815
|
idempotentHint: true,
|
|
2731
3816
|
openWorldHint: false
|
|
2732
|
-
}
|
|
3817
|
+
},
|
|
3818
|
+
_meta: widgetToolMeta("getField")
|
|
2733
3819
|
},
|
|
2734
3820
|
async (args) => handleGetField(getToken, baseUrl, args)
|
|
2735
3821
|
);
|
|
@@ -2744,7 +3830,8 @@ function registerFieldTools(server, getToken, baseUrl) {
|
|
|
2744
3830
|
destructiveHint: false,
|
|
2745
3831
|
idempotentHint: true,
|
|
2746
3832
|
openWorldHint: false
|
|
2747
|
-
}
|
|
3833
|
+
},
|
|
3834
|
+
_meta: widgetToolMeta("fieldValues")
|
|
2748
3835
|
},
|
|
2749
3836
|
async (args) => handleFieldValues(getToken, baseUrl, args)
|
|
2750
3837
|
);
|
|
@@ -2801,6 +3888,7 @@ async function handleFindData(getToken, baseUrl, args) {
|
|
|
2801
3888
|
}
|
|
2802
3889
|
var LIST_TOOLS_DESCRIPTION = [
|
|
2803
3890
|
"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.",
|
|
3891
|
+
"Target API: https://talonic.com/docs/api (GET /v1/agent/tools).",
|
|
2804
3892
|
"",
|
|
2805
3893
|
"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.",
|
|
2806
3894
|
"NOT FOR: discovering fields (talonic_list_fields / talonic_find_data) or documents (talonic_search) \u2014 those are shaped for you.",
|
|
@@ -2837,6 +3925,8 @@ async function handleListAgentTools(getToken, baseUrl, args) {
|
|
|
2837
3925
|
}
|
|
2838
3926
|
var INVOKE_DESCRIPTION = [
|
|
2839
3927
|
"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).",
|
|
3928
|
+
"READ-ONLY BY CONSTRUCTION: API-key credentials are restricted by the platform to the registry's read-only tools (capability `data.read`); write-capable registry tools are never invocable through this credential, so through an API-key credential this tool reads and never mutates workspace data.",
|
|
3929
|
+
"Target API: Talonic agent tool registry \u2014 https://talonic.com/docs/api (POST /v1/agent/tools/{name}/invoke; input schemas from talonic_list_agent_tools).",
|
|
2840
3930
|
"",
|
|
2841
3931
|
"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.",
|
|
2842
3932
|
"NOT FOR: anything a dedicated talonic_* tool already does (prefer those \u2014 they are shaped for you).",
|
|
@@ -2878,7 +3968,8 @@ function registerAgentRegistryTools(server, getToken, baseUrl) {
|
|
|
2878
3968
|
destructiveHint: false,
|
|
2879
3969
|
idempotentHint: true,
|
|
2880
3970
|
openWorldHint: false
|
|
2881
|
-
}
|
|
3971
|
+
},
|
|
3972
|
+
_meta: widgetToolMeta("findData")
|
|
2882
3973
|
},
|
|
2883
3974
|
async (args) => handleFindData(getToken, baseUrl, args)
|
|
2884
3975
|
);
|
|
@@ -2893,7 +3984,8 @@ function registerAgentRegistryTools(server, getToken, baseUrl) {
|
|
|
2893
3984
|
destructiveHint: false,
|
|
2894
3985
|
idempotentHint: true,
|
|
2895
3986
|
openWorldHint: false
|
|
2896
|
-
}
|
|
3987
|
+
},
|
|
3988
|
+
_meta: widgetToolMeta("listAgentTools")
|
|
2897
3989
|
},
|
|
2898
3990
|
async (args) => handleListAgentTools(getToken, baseUrl, args)
|
|
2899
3991
|
);
|
|
@@ -2908,15 +4000,487 @@ function registerAgentRegistryTools(server, getToken, baseUrl) {
|
|
|
2908
4000
|
destructiveHint: false,
|
|
2909
4001
|
idempotentHint: false,
|
|
2910
4002
|
openWorldHint: false
|
|
2911
|
-
}
|
|
4003
|
+
},
|
|
4004
|
+
_meta: widgetToolMeta("invokeAgentTool")
|
|
2912
4005
|
},
|
|
2913
4006
|
async (args) => handleInvokeAgentTool(getToken, baseUrl, args)
|
|
2914
4007
|
);
|
|
2915
4008
|
}
|
|
4009
|
+
var LIST_DESCRIPTION2 = [
|
|
4010
|
+
"List the workspace's Specs \u2014 the configured pipelines (rail + fields) that talonic_run_spec executes. Each row: id, name, description, schema_id (the schema a run materializes onto \u2014 a DIFFERENT id from the Spec's), version / materialized_version (null = never published), field_count, node_count, timestamps.",
|
|
4011
|
+
"",
|
|
4012
|
+
"USE WHEN: the user wants to run 'their pipeline' / 'the invoice Spec', or you need a spec_id for talonic_run_spec / talonic_get_spec.",
|
|
4013
|
+
"NOT FOR: ad-hoc extraction schemas (talonic_list_schemas) or discovering fields (talonic_list_fields).",
|
|
4014
|
+
"ARGS: optional `search` (name contains, case-insensitive), `limit` (1\u2013100, default 20), `cursor` (from pagination.next_cursor), `order` (asc|desc by updated_at).",
|
|
4015
|
+
"RETURNS: { data[] of { id, name, description, schema_id, version, materialized_version, materialized_at, field_count, node_count, created_at, updated_at, links }, pagination { total, limit, has_more, next_cursor } }."
|
|
4016
|
+
].join("\n");
|
|
4017
|
+
var GET_DESCRIPTION2 = [
|
|
4018
|
+
"Get one Spec's structure: identity and version state, the schema it materializes onto, `nodes[]` (the rail as authored, in editing order) and `phases[]` (the compiled execution plan, in run order \u2014 a validation checkpoint expands to one phase per gate, so the two lists differ on purpose), and `fields[]` (Spec field \u2194 schema field).",
|
|
4019
|
+
"",
|
|
4020
|
+
"USE WHEN: you need to explain what a run will do, confirm a Spec is published (`version` non-null) before talonic_run_spec, or map field names to keys.",
|
|
4021
|
+
"NOT FOR: listing Specs (talonic_list_specs) or starting a run (talonic_run_spec).",
|
|
4022
|
+
"ARGS: `spec_id` (UUID from talonic_list_specs); optional `include_versions` (adds `versions[]` \u2014 published versions newest first, each { version, content_hash, created_at, is_materialized }).",
|
|
4023
|
+
"RETURNS: the Spec object { id, name, description, schema_id, version, materialized_version, materialized_at, field_count, node_count, schema, nodes[], phases[], fields[], links } plus optional versions[]."
|
|
4024
|
+
].join("\n");
|
|
4025
|
+
var listSpecsInputSchema = {
|
|
4026
|
+
search: z.string().min(1).optional().describe("Case-insensitive contains match on the Spec name."),
|
|
4027
|
+
limit: z.number().int().min(1).max(100).optional().describe("Page size (default 20)."),
|
|
4028
|
+
cursor: z.string().min(1).optional().describe("Opaque cursor from pagination.next_cursor."),
|
|
4029
|
+
order: z.enum(["asc", "desc"]).optional().describe("Sort by updated_at (default desc).")
|
|
4030
|
+
};
|
|
4031
|
+
var getSpecInputSchema = {
|
|
4032
|
+
spec_id: z.string().uuid().describe("Spec UUID (from talonic_list_specs)."),
|
|
4033
|
+
include_versions: z.boolean().optional().describe("Also fetch the published versions list (adds `versions[]`).")
|
|
4034
|
+
};
|
|
4035
|
+
async function handleListSpecs(getToken, baseUrl, args) {
|
|
4036
|
+
const params = {
|
|
4037
|
+
search: args.search,
|
|
4038
|
+
limit: args.limit,
|
|
4039
|
+
cursor: args.cursor,
|
|
4040
|
+
order: args.order
|
|
4041
|
+
};
|
|
4042
|
+
return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/specs", { params }));
|
|
4043
|
+
}
|
|
4044
|
+
async function handleGetSpec(getToken, baseUrl, args) {
|
|
4045
|
+
return runTool(async () => {
|
|
4046
|
+
const path = `/v1/specs/${encodeURIComponent(args.spec_id)}`;
|
|
4047
|
+
const spec = await apiJson(getToken, baseUrl, "GET", path);
|
|
4048
|
+
if (!args.include_versions) return spec;
|
|
4049
|
+
const versions = await apiJson(
|
|
4050
|
+
getToken,
|
|
4051
|
+
baseUrl,
|
|
4052
|
+
"GET",
|
|
4053
|
+
`${path}/versions`
|
|
4054
|
+
);
|
|
4055
|
+
return { ...spec, versions: versions.data ?? [] };
|
|
4056
|
+
});
|
|
4057
|
+
}
|
|
4058
|
+
var READ_ONLY4 = {
|
|
4059
|
+
readOnlyHint: true,
|
|
4060
|
+
destructiveHint: false,
|
|
4061
|
+
idempotentHint: true,
|
|
4062
|
+
openWorldHint: false
|
|
4063
|
+
};
|
|
4064
|
+
function registerSpecTools(server, getToken, baseUrl) {
|
|
4065
|
+
server.registerTool(
|
|
4066
|
+
"talonic_list_specs",
|
|
4067
|
+
{
|
|
4068
|
+
title: "List Specs",
|
|
4069
|
+
description: LIST_DESCRIPTION2,
|
|
4070
|
+
inputSchema: listSpecsInputSchema,
|
|
4071
|
+
annotations: { title: "List Specs", ...READ_ONLY4 },
|
|
4072
|
+
_meta: widgetToolMeta("listSpecs")
|
|
4073
|
+
},
|
|
4074
|
+
async (args) => handleListSpecs(getToken, baseUrl, args)
|
|
4075
|
+
);
|
|
4076
|
+
server.registerTool(
|
|
4077
|
+
"talonic_get_spec",
|
|
4078
|
+
{
|
|
4079
|
+
title: "Get a Spec's structure",
|
|
4080
|
+
description: GET_DESCRIPTION2,
|
|
4081
|
+
inputSchema: getSpecInputSchema,
|
|
4082
|
+
annotations: { title: "Get a Spec's structure", ...READ_ONLY4 },
|
|
4083
|
+
_meta: widgetToolMeta("getSpec")
|
|
4084
|
+
},
|
|
4085
|
+
async (args) => handleGetSpec(getToken, baseUrl, args)
|
|
4086
|
+
);
|
|
4087
|
+
}
|
|
4088
|
+
function mapRunStatus(raw) {
|
|
4089
|
+
if (raw === "completed") return "completed";
|
|
4090
|
+
if (raw === "failed" || raw === "error" || raw === "cancelled" || raw === "canceled")
|
|
4091
|
+
return "failed";
|
|
4092
|
+
return "processing";
|
|
4093
|
+
}
|
|
4094
|
+
var RUN_DESCRIPTION = [
|
|
4095
|
+
"Run a Spec \u2014 the customer's configured pipeline \u2014 over documents, in one call. Two inputs: `document_ids` (documents already in the workspace; for a new file, first talonic_request_upload \u2192 poll talonic_get_document until completed) OR `file_urls` (public https files, max 20; Talonic ingests them first). Consumes credits.",
|
|
4096
|
+
"",
|
|
4097
|
+
"USE WHEN: the user wants to 'run the invoice pipeline on these documents', process files through their Spec, or produce the Spec's structured rows.",
|
|
4098
|
+
"NOT FOR: one-off extraction with an ad-hoc schema (talonic_extract), or checking progress (talonic_get_run) / reading rows (talonic_get_run_results).",
|
|
4099
|
+
"ARGS: `spec_id` (talonic_list_specs); exactly one of `document_ids[]` (1\u2013500) or `file_urls[]` (1\u201320, https); optional `name`, `pipeline_mode` (`new` default | `append` to the Spec's existing pipeline); `batch_id` and flat `metadata` only with file_urls.",
|
|
4100
|
+
"RETURNS: RunEnvelope { run_kind ('pipeline'|'run'), run_id, pipeline_id, spec_id, status ('processing'|'completed'|'failed'), raw_status, input_count, documents?, message?, links }. Then poll talonic_get_run with the `pipeline_id` when run_kind is 'pipeline', or with the `run_id` when it is 'run', every 5\u201310 s until status is completed/failed, then talonic_get_run_results."
|
|
4101
|
+
].join("\n");
|
|
4102
|
+
var GET_RUN_DESCRIPTION = [
|
|
4103
|
+
"Poll a Spec run started by talonic_run_spec: normalised status plus document-level progress and, for pipelines, per-phase progress.",
|
|
4104
|
+
"",
|
|
4105
|
+
"USE WHEN: waiting for a run to finish \u2014 poll every 5\u201310 s; stop on `completed` or `failed`.",
|
|
4106
|
+
"NOT FOR: reading the structured rows (talonic_get_run_results) or starting a run (talonic_run_spec).",
|
|
4107
|
+
"ARGS: exactly one of `pipeline_id` (run_kind 'pipeline') or `run_id` (run_kind 'run'), from the RunEnvelope.",
|
|
4108
|
+
"RETURNS: { run_kind, run_id, pipeline_id, spec_id, status, raw_status, input_count?, progress { total_documents, completed_documents, error_documents, phases?[] }, documents?[], error_message?, created_at, updated_at }."
|
|
4109
|
+
].join("\n");
|
|
4110
|
+
var RESULTS_DESCRIPTION = [
|
|
4111
|
+
"Read a Spec run's structured rows \u2014 one row per document with the Spec's fields as clean values (held/pending-review cells serialize null), plus the column definitions.",
|
|
4112
|
+
"",
|
|
4113
|
+
"USE WHEN: talonic_get_run reports `completed` (partial rows are also readable while `processing`).",
|
|
4114
|
+
"NOT FOR: progress (talonic_get_run) or per-field provenance of a single value (include: ['provenance'] here, or talonic_field_values).",
|
|
4115
|
+
"ARGS: exactly one of `pipeline_id` (run_kind 'pipeline', optionally with the envelope's `run_id` to scope to that submission) or `run_id` alone (run_kind 'run'); optional `document_id` (one document), `include` (['cells','provenance'] \u2014 heavier payload), `limit` (1\u2013200, default 50), `cursor`.",
|
|
4116
|
+
"RETURNS: { run_kind, status, columns[] of { field_key, display_name, data_type }, data[] of { document_id, filename, record_id, status ('complete'|'partial'|'error'|'processing'), completed_at, fields { field_key: value }, cells?, provenance? }, pagination, pending_review_count, links }."
|
|
4117
|
+
].join("\n");
|
|
4118
|
+
var uuid = z.string().uuid();
|
|
4119
|
+
var documentIdsArg2 = z.array(uuid).min(1).max(500).optional().describe("Workspace document ids (1\u2013500). Mutually exclusive with file_urls.");
|
|
4120
|
+
var fileUrlsArg = z.array(z.string().url()).min(1).max(20).optional().describe("Public https file URLs (1\u201320). Mutually exclusive with document_ids.");
|
|
4121
|
+
var metadataArg = z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.null()])).optional().describe("Flat caller tags stamped on every ingested document (file_urls path only).");
|
|
4122
|
+
var runSpecInputSchema = {
|
|
4123
|
+
spec_id: uuid.describe("Spec UUID (talonic_list_specs)."),
|
|
4124
|
+
document_ids: documentIdsArg2,
|
|
4125
|
+
file_urls: fileUrlsArg,
|
|
4126
|
+
name: z.string().min(1).max(200).optional().describe("Display name for the run."),
|
|
4127
|
+
pipeline_mode: z.enum(["new", "append"]).optional().describe("`new` (default) or `append` to the Spec's existing pipeline."),
|
|
4128
|
+
batch_id: z.string().min(1).max(200).optional().describe("Caller grouping key (file_urls path only)."),
|
|
4129
|
+
metadata: metadataArg
|
|
4130
|
+
};
|
|
4131
|
+
var runRefInputSchema = {
|
|
4132
|
+
run_id: uuid.optional().describe("From a run_kind 'run' envelope (/v1/run)."),
|
|
4133
|
+
pipeline_id: uuid.optional().describe("From a run_kind 'pipeline' envelope (/v1/pipelines).")
|
|
4134
|
+
};
|
|
4135
|
+
var resultsInputSchema = {
|
|
4136
|
+
run_id: uuid.optional().describe(
|
|
4137
|
+
"The RunEnvelope's run_id. Alone: a run_kind 'run' submission (/v1/run). With pipeline_id: scopes the pipeline's rows to that submission."
|
|
4138
|
+
),
|
|
4139
|
+
pipeline_id: uuid.optional().describe(
|
|
4140
|
+
"The RunEnvelope's pipeline_id (run_kind 'pipeline'); rows come from /v1/pipelines/{id}/results."
|
|
4141
|
+
),
|
|
4142
|
+
document_id: uuid.optional().describe("Restrict to one document."),
|
|
4143
|
+
include: z.array(z.enum(["cells", "provenance"])).optional().describe("Extra per-field detail; heavier payload."),
|
|
4144
|
+
limit: z.number().int().min(1).max(200).optional().describe("Page size (default 50)."),
|
|
4145
|
+
cursor: z.string().min(1).optional().describe("Opaque cursor from pagination.next_cursor.")
|
|
4146
|
+
};
|
|
4147
|
+
function pickRef(args) {
|
|
4148
|
+
const hasRun = typeof args.run_id === "string" && args.run_id.length > 0;
|
|
4149
|
+
const hasPipe = typeof args.pipeline_id === "string" && args.pipeline_id.length > 0;
|
|
4150
|
+
if (hasRun === hasPipe) return null;
|
|
4151
|
+
return hasPipe ? { kind: "pipeline", id: args.pipeline_id } : { kind: "run", id: args.run_id };
|
|
4152
|
+
}
|
|
4153
|
+
async function handleRunSpec(getToken, baseUrl, args) {
|
|
4154
|
+
const docs = Array.isArray(args.document_ids) && args.document_ids.length > 0 ? args.document_ids : null;
|
|
4155
|
+
const urls = Array.isArray(args.file_urls) && args.file_urls.length > 0 ? args.file_urls : null;
|
|
4156
|
+
if (docs === null === (urls === null)) {
|
|
4157
|
+
return validationError("provide exactly one of document_ids or file_urls (non-empty).");
|
|
4158
|
+
}
|
|
4159
|
+
if (urls && urls.some((u) => !u.startsWith("https://"))) {
|
|
4160
|
+
return validationError("every file_urls entry must start with https://.");
|
|
4161
|
+
}
|
|
4162
|
+
if (docs && (args.batch_id !== void 0 || args.metadata !== void 0)) {
|
|
4163
|
+
return validationError(
|
|
4164
|
+
"batch_id and metadata only apply to the file_urls path; drop them for document_ids."
|
|
4165
|
+
);
|
|
4166
|
+
}
|
|
4167
|
+
return runTool(async () => {
|
|
4168
|
+
if (docs) {
|
|
4169
|
+
const res2 = await apiJson(
|
|
4170
|
+
getToken,
|
|
4171
|
+
baseUrl,
|
|
4172
|
+
"POST",
|
|
4173
|
+
"/v1/pipelines",
|
|
4174
|
+
{
|
|
4175
|
+
body: {
|
|
4176
|
+
schema_id: args.spec_id,
|
|
4177
|
+
document_ids: docs,
|
|
4178
|
+
...args.name ? { name: args.name } : {},
|
|
4179
|
+
...args.pipeline_mode ? { pipeline_mode: args.pipeline_mode } : {}
|
|
4180
|
+
}
|
|
4181
|
+
}
|
|
4182
|
+
);
|
|
4183
|
+
return {
|
|
4184
|
+
run_kind: "pipeline",
|
|
4185
|
+
run_id: res2.run_id ?? null,
|
|
4186
|
+
pipeline_id: res2.id,
|
|
4187
|
+
spec_id: res2.schema?.id ?? args.spec_id,
|
|
4188
|
+
spec_name: res2.schema?.name ?? null,
|
|
4189
|
+
status: mapRunStatus(res2.status),
|
|
4190
|
+
raw_status: res2.status ?? null,
|
|
4191
|
+
input_count: res2.document_count ?? docs.length,
|
|
4192
|
+
enqueued_documents: res2.enqueued_documents ?? null,
|
|
4193
|
+
appended: res2.appended === true,
|
|
4194
|
+
message: res2.message ?? null,
|
|
4195
|
+
links: res2.links ?? {}
|
|
4196
|
+
};
|
|
4197
|
+
}
|
|
4198
|
+
const res = await apiForm(getToken, baseUrl, "/v1/run", {
|
|
4199
|
+
spec_id: args.spec_id,
|
|
4200
|
+
file_urls: urls,
|
|
4201
|
+
name: args.name,
|
|
4202
|
+
pipeline_mode: args.pipeline_mode,
|
|
4203
|
+
batch_id: args.batch_id,
|
|
4204
|
+
metadata: args.metadata ? JSON.stringify(args.metadata) : void 0
|
|
4205
|
+
});
|
|
4206
|
+
return {
|
|
4207
|
+
run_kind: "run",
|
|
4208
|
+
run_id: res.run_id,
|
|
4209
|
+
pipeline_id: null,
|
|
4210
|
+
spec_id: res.spec_id ?? args.spec_id,
|
|
4211
|
+
spec_name: null,
|
|
4212
|
+
status: mapRunStatus(res.status),
|
|
4213
|
+
raw_status: res.status ?? null,
|
|
4214
|
+
input_count: res.input_count ?? urls.length,
|
|
4215
|
+
documents: res.documents ?? [],
|
|
4216
|
+
message: null,
|
|
4217
|
+
links: { poll: res.poll_url ?? `/v1/run/${res.run_id}` }
|
|
4218
|
+
};
|
|
4219
|
+
});
|
|
4220
|
+
}
|
|
4221
|
+
async function handleGetRun(getToken, baseUrl, args) {
|
|
4222
|
+
const ref = pickRef(args);
|
|
4223
|
+
if (!ref) return validationError("provide exactly one of run_id or pipeline_id.");
|
|
4224
|
+
return runTool(async () => {
|
|
4225
|
+
if (ref.kind === "run") {
|
|
4226
|
+
const r = await apiJson(
|
|
4227
|
+
getToken,
|
|
4228
|
+
baseUrl,
|
|
4229
|
+
"GET",
|
|
4230
|
+
`/v1/run/${encodeURIComponent(ref.id)}`
|
|
4231
|
+
);
|
|
4232
|
+
return {
|
|
4233
|
+
run_kind: "run",
|
|
4234
|
+
run_id: r["run_id"] ?? ref.id,
|
|
4235
|
+
pipeline_id: r["pipeline_id"] ?? null,
|
|
4236
|
+
spec_id: r["spec_id"] ?? null,
|
|
4237
|
+
status: mapRunStatus(r["status"]),
|
|
4238
|
+
raw_status: r["status"] ?? null,
|
|
4239
|
+
input_count: r["input_count"] ?? null,
|
|
4240
|
+
progress: r["progress"] ?? null,
|
|
4241
|
+
documents: r["documents"] ?? void 0,
|
|
4242
|
+
error_message: r["error_message"] ?? null,
|
|
4243
|
+
batch_id: r["batch_id"] ?? null,
|
|
4244
|
+
created_at: r["created_at"] ?? null,
|
|
4245
|
+
updated_at: r["updated_at"] ?? null
|
|
4246
|
+
};
|
|
4247
|
+
}
|
|
4248
|
+
const base = `/v1/pipelines/${encodeURIComponent(ref.id)}`;
|
|
4249
|
+
const p = await apiJson(getToken, baseUrl, "GET", base);
|
|
4250
|
+
const pr = await apiJson(getToken, baseUrl, "GET", `${base}/progress`);
|
|
4251
|
+
const raw = pr.status ?? p["status"];
|
|
4252
|
+
return {
|
|
4253
|
+
run_kind: "pipeline",
|
|
4254
|
+
run_id: null,
|
|
4255
|
+
pipeline_id: p["id"] ?? ref.id,
|
|
4256
|
+
spec_id: p["schema"]?.id ?? null,
|
|
4257
|
+
name: p["name"] ?? null,
|
|
4258
|
+
status: mapRunStatus(raw),
|
|
4259
|
+
raw_status: raw ?? null,
|
|
4260
|
+
progress: {
|
|
4261
|
+
total_documents: pr.totalDocuments ?? null,
|
|
4262
|
+
completed_documents: pr.completedDocuments ?? null,
|
|
4263
|
+
error_documents: pr.errorDocuments ?? null,
|
|
4264
|
+
finalization_pending: pr.finalizationPending ?? null,
|
|
4265
|
+
phases: (pr.phases ?? []).map((ph) => ({
|
|
4266
|
+
phase_id: ph.phaseId ?? null,
|
|
4267
|
+
name: ph.name ?? null,
|
|
4268
|
+
type: ph.type ?? null,
|
|
4269
|
+
completed: ph.completed ?? null,
|
|
4270
|
+
running: ph.running ?? null,
|
|
4271
|
+
errors: ph.errors ?? null
|
|
4272
|
+
}))
|
|
4273
|
+
},
|
|
4274
|
+
created_at: p["created_at"] ?? null,
|
|
4275
|
+
links: p["links"] ?? {}
|
|
4276
|
+
};
|
|
4277
|
+
});
|
|
4278
|
+
}
|
|
4279
|
+
async function handleGetRunResults(getToken, baseUrl, args) {
|
|
4280
|
+
const hasPipe = typeof args.pipeline_id === "string" && args.pipeline_id.length > 0;
|
|
4281
|
+
const hasRun = typeof args.run_id === "string" && args.run_id.length > 0;
|
|
4282
|
+
if (!hasPipe && !hasRun)
|
|
4283
|
+
return validationError("provide pipeline_id (optionally with run_id) or run_id.");
|
|
4284
|
+
return runTool(async () => {
|
|
4285
|
+
const kind = hasPipe ? "pipeline" : "run";
|
|
4286
|
+
const params = {
|
|
4287
|
+
...kind === "pipeline" ? { view: "documents", run_id: hasRun ? args.run_id : void 0 } : {},
|
|
4288
|
+
document_id: args.document_id,
|
|
4289
|
+
include: args.include?.length ? args.include.join(",") : void 0,
|
|
4290
|
+
limit: args.limit,
|
|
4291
|
+
cursor: args.cursor
|
|
4292
|
+
};
|
|
4293
|
+
const path = kind === "run" ? `/v1/run/${encodeURIComponent(args.run_id)}/results` : `/v1/pipelines/${encodeURIComponent(args.pipeline_id)}/results`;
|
|
4294
|
+
const body = await apiJson(getToken, baseUrl, "GET", path, { params });
|
|
4295
|
+
return { run_kind: kind, ...body };
|
|
4296
|
+
});
|
|
4297
|
+
}
|
|
4298
|
+
var READ_ONLY5 = {
|
|
4299
|
+
readOnlyHint: true,
|
|
4300
|
+
destructiveHint: false,
|
|
4301
|
+
idempotentHint: true,
|
|
4302
|
+
openWorldHint: false
|
|
4303
|
+
};
|
|
4304
|
+
function registerRunTools(server, getToken, baseUrl) {
|
|
4305
|
+
server.registerTool(
|
|
4306
|
+
"talonic_run_spec",
|
|
4307
|
+
{
|
|
4308
|
+
title: "Run a Spec pipeline",
|
|
4309
|
+
description: RUN_DESCRIPTION,
|
|
4310
|
+
inputSchema: runSpecInputSchema,
|
|
4311
|
+
annotations: {
|
|
4312
|
+
title: "Run a Spec pipeline",
|
|
4313
|
+
readOnlyHint: false,
|
|
4314
|
+
destructiveHint: false,
|
|
4315
|
+
openWorldHint: true
|
|
4316
|
+
},
|
|
4317
|
+
_meta: widgetToolMeta("runSpec")
|
|
4318
|
+
},
|
|
4319
|
+
async (args) => handleRunSpec(getToken, baseUrl, args)
|
|
4320
|
+
);
|
|
4321
|
+
server.registerTool(
|
|
4322
|
+
"talonic_get_run",
|
|
4323
|
+
{
|
|
4324
|
+
title: "Poll a Spec run",
|
|
4325
|
+
description: GET_RUN_DESCRIPTION,
|
|
4326
|
+
inputSchema: runRefInputSchema,
|
|
4327
|
+
annotations: { title: "Poll a Spec run", ...READ_ONLY5 },
|
|
4328
|
+
_meta: widgetToolMeta("getRun")
|
|
4329
|
+
},
|
|
4330
|
+
async (args) => handleGetRun(getToken, baseUrl, args)
|
|
4331
|
+
);
|
|
4332
|
+
server.registerTool(
|
|
4333
|
+
"talonic_get_run_results",
|
|
4334
|
+
{
|
|
4335
|
+
title: "Read a Spec run's rows",
|
|
4336
|
+
description: RESULTS_DESCRIPTION,
|
|
4337
|
+
inputSchema: resultsInputSchema,
|
|
4338
|
+
annotations: { title: "Read a Spec run's rows", ...READ_ONLY5 },
|
|
4339
|
+
_meta: widgetToolMeta("getRunResults")
|
|
4340
|
+
},
|
|
4341
|
+
async (args) => handleGetRunResults(getToken, baseUrl, args)
|
|
4342
|
+
);
|
|
4343
|
+
}
|
|
4344
|
+
var ASK_POLL_INTERVAL_MS = 2e3;
|
|
4345
|
+
var ASK_DEFAULT_WAIT_S = 45;
|
|
4346
|
+
var ASK_MAX_WAIT_S = 55;
|
|
4347
|
+
var POLL_HINT = "still processing \u2014 call talonic_get_answer with this ask_id in a few seconds";
|
|
4348
|
+
var ASK_DESCRIPTION = [
|
|
4349
|
+
"Ask a natural-language question over the workspace's documents and get a cited, verified answer (markdown). The Talonic agent plans over the structured field plane, runs read-only SQL over extracted cells, reads document text, and grounds every load-bearing claim in a source span. Consumes credits.",
|
|
4350
|
+
"",
|
|
4351
|
+
"USE WHEN: the user asks an open question about their documents ('which vendors invoiced us twice in May?'), wants a summary across documents, or the answer needs reasoning over several fields.",
|
|
4352
|
+
"NOT FOR: reading a known field's values (talonic_field_values, free) or filtering documents by a known value (talonic_filter, free); locating which field holds a concept (talonic_find_data).",
|
|
4353
|
+
"ARGS: `question`; optional `scope` { document_ids[], schema_id, pipeline_id, data_product_id, document_type, source_id, tags[], ingested_after, ingested_before } (ANDed), `conversation_id` (continue a thread), `output_format` { instruction, template }, `wait_seconds` (0\u201355, default 45).",
|
|
4354
|
+
"RETURNS: { ask_id, status ('completed'|'processing'|'error'), conversation_id, answer (markdown), citations[] { quote, document_id, kind, filename, app_url }, verification { verdict, checks_total, checks_unsupported, correction }, usage { tokens, credits_charged }, tool_calls, artifacts[], waited_ms }. If status is still 'processing' after the wait, call talonic_get_answer with the ask_id."
|
|
4355
|
+
].join("\n");
|
|
4356
|
+
var GET_ANSWER_DESCRIPTION = [
|
|
4357
|
+
"Poll an ask started by talonic_ask that was still processing when the wait ended.",
|
|
4358
|
+
"",
|
|
4359
|
+
"USE WHEN: talonic_ask returned status 'processing' with an ask_id \u2014 poll every few seconds until 'completed' or 'error'.",
|
|
4360
|
+
"NOT FOR: asking a new question (talonic_ask).",
|
|
4361
|
+
"ARGS: `ask_id`.",
|
|
4362
|
+
"RETURNS: the same answer envelope as talonic_ask (answer, citations[], verification, usage) or { status: 'processing', poll_hint }."
|
|
4363
|
+
].join("\n");
|
|
4364
|
+
var uuid2 = z.string().uuid();
|
|
4365
|
+
var scopeSchema = z.object({
|
|
4366
|
+
document_ids: z.array(uuid2).max(500).optional(),
|
|
4367
|
+
schema_id: uuid2.optional(),
|
|
4368
|
+
pipeline_id: uuid2.optional(),
|
|
4369
|
+
data_product_id: uuid2.optional(),
|
|
4370
|
+
document_type: z.string().min(1).optional(),
|
|
4371
|
+
source_id: uuid2.optional(),
|
|
4372
|
+
tags: z.array(z.string().min(1)).max(50).optional(),
|
|
4373
|
+
ingested_after: z.string().min(1).optional(),
|
|
4374
|
+
ingested_before: z.string().min(1).optional()
|
|
4375
|
+
}).optional().describe("Restrict the question to a slice of the workspace; present fields are ANDed.");
|
|
4376
|
+
var askInputSchema = {
|
|
4377
|
+
question: z.string().min(1).max(4e3).describe("The question, in the user's words."),
|
|
4378
|
+
scope: scopeSchema,
|
|
4379
|
+
conversation_id: uuid2.optional().describe("Continue this conversation; the agent sees prior turns."),
|
|
4380
|
+
output_format: z.object({
|
|
4381
|
+
instruction: z.string().max(1e3).optional(),
|
|
4382
|
+
template: z.string().max(4e3).optional()
|
|
4383
|
+
}).optional().describe("Shape the answer (form only, never grounding)."),
|
|
4384
|
+
wait_seconds: z.number().int().min(0).max(ASK_MAX_WAIT_S).optional().describe(
|
|
4385
|
+
`Seconds to wait for the answer before returning 'processing' (default ${ASK_DEFAULT_WAIT_S}, max ${ASK_MAX_WAIT_S}).`
|
|
4386
|
+
)
|
|
4387
|
+
};
|
|
4388
|
+
function withHint(body) {
|
|
4389
|
+
return body.status === "processing" ? { ...body, poll_hint: POLL_HINT } : body;
|
|
4390
|
+
}
|
|
4391
|
+
async function handleAsk(getToken, baseUrl, args, deps = {}) {
|
|
4392
|
+
if (typeof args.question !== "string" || args.question.trim().length === 0) {
|
|
4393
|
+
return validationError("question must be a non-empty string.");
|
|
4394
|
+
}
|
|
4395
|
+
const sleep2 = deps.sleep ?? sleep;
|
|
4396
|
+
const now = deps.now ?? Date.now;
|
|
4397
|
+
const requestedWaitS = Number.isFinite(args.wait_seconds) ? args.wait_seconds : ASK_DEFAULT_WAIT_S;
|
|
4398
|
+
const waitS = Math.max(0, Math.min(ASK_MAX_WAIT_S, Math.floor(requestedWaitS)));
|
|
4399
|
+
return runTool(async () => {
|
|
4400
|
+
const created = await apiJson(getToken, baseUrl, "POST", "/v1/ask", {
|
|
4401
|
+
body: {
|
|
4402
|
+
question: args.question,
|
|
4403
|
+
...args.scope ? { scope: args.scope } : {},
|
|
4404
|
+
...args.conversation_id ? { conversation_id: args.conversation_id } : {},
|
|
4405
|
+
...args.output_format ? { output_format: args.output_format } : {}
|
|
4406
|
+
},
|
|
4407
|
+
signal: AbortSignal.timeout(15e3)
|
|
4408
|
+
});
|
|
4409
|
+
const pollPath = `/v1/ask/${encodeURIComponent(created.ask_id)}`;
|
|
4410
|
+
const start = now();
|
|
4411
|
+
const deadline = start + waitS * 1e3;
|
|
4412
|
+
for (; ; ) {
|
|
4413
|
+
const pollTimeoutMs = Math.max(5e3, Math.min(15e3, deadline - now()));
|
|
4414
|
+
let body;
|
|
4415
|
+
try {
|
|
4416
|
+
body = await apiJson(getToken, baseUrl, "GET", pollPath, {
|
|
4417
|
+
signal: AbortSignal.timeout(pollTimeoutMs)
|
|
4418
|
+
});
|
|
4419
|
+
} catch {
|
|
4420
|
+
return {
|
|
4421
|
+
...withHint({ status: "processing", ask_id: created.ask_id }),
|
|
4422
|
+
ask_id: created.ask_id,
|
|
4423
|
+
waited_ms: now() - start
|
|
4424
|
+
};
|
|
4425
|
+
}
|
|
4426
|
+
const t = now();
|
|
4427
|
+
if (body.status !== "processing" || t >= deadline) {
|
|
4428
|
+
return { ...withHint(body), ask_id: body.ask_id ?? created.ask_id, waited_ms: t - start };
|
|
4429
|
+
}
|
|
4430
|
+
await sleep2(Math.min(ASK_POLL_INTERVAL_MS, deadline - t));
|
|
4431
|
+
}
|
|
4432
|
+
});
|
|
4433
|
+
}
|
|
4434
|
+
async function handleGetAnswer(getToken, baseUrl, args) {
|
|
4435
|
+
return runTool(async () => {
|
|
4436
|
+
const body = await apiJson(
|
|
4437
|
+
getToken,
|
|
4438
|
+
baseUrl,
|
|
4439
|
+
"GET",
|
|
4440
|
+
`/v1/ask/${encodeURIComponent(args.ask_id)}`
|
|
4441
|
+
);
|
|
4442
|
+
return { ...withHint(body), ask_id: body.ask_id ?? args.ask_id };
|
|
4443
|
+
});
|
|
4444
|
+
}
|
|
4445
|
+
function registerAskTools(server, getToken, baseUrl) {
|
|
4446
|
+
server.registerTool(
|
|
4447
|
+
"talonic_ask",
|
|
4448
|
+
{
|
|
4449
|
+
title: "Ask a question over the workspace",
|
|
4450
|
+
description: ASK_DESCRIPTION,
|
|
4451
|
+
inputSchema: askInputSchema,
|
|
4452
|
+
annotations: {
|
|
4453
|
+
title: "Ask a question over the workspace",
|
|
4454
|
+
readOnlyHint: false,
|
|
4455
|
+
destructiveHint: false,
|
|
4456
|
+
openWorldHint: false
|
|
4457
|
+
},
|
|
4458
|
+
_meta: widgetToolMeta("ask")
|
|
4459
|
+
},
|
|
4460
|
+
async (args) => handleAsk(getToken, baseUrl, args)
|
|
4461
|
+
);
|
|
4462
|
+
server.registerTool(
|
|
4463
|
+
"talonic_get_answer",
|
|
4464
|
+
{
|
|
4465
|
+
title: "Poll an ask for its answer",
|
|
4466
|
+
description: GET_ANSWER_DESCRIPTION,
|
|
4467
|
+
inputSchema: { ask_id: uuid2.describe("From talonic_ask.") },
|
|
4468
|
+
annotations: {
|
|
4469
|
+
title: "Poll an ask for its answer",
|
|
4470
|
+
readOnlyHint: true,
|
|
4471
|
+
destructiveHint: false,
|
|
4472
|
+
idempotentHint: true,
|
|
4473
|
+
openWorldHint: false
|
|
4474
|
+
},
|
|
4475
|
+
_meta: widgetToolMeta("getAnswer")
|
|
4476
|
+
},
|
|
4477
|
+
async (args) => handleGetAnswer(getToken, baseUrl, args)
|
|
4478
|
+
);
|
|
4479
|
+
}
|
|
2916
4480
|
|
|
2917
4481
|
// package.json
|
|
2918
4482
|
var package_default = {
|
|
2919
|
-
version: "0.1.
|
|
4483
|
+
version: "0.1.79"};
|
|
2920
4484
|
|
|
2921
4485
|
// src/version.ts
|
|
2922
4486
|
var VERSION = package_default.version;
|
|
@@ -2944,6 +4508,7 @@ function createServer(options) {
|
|
|
2944
4508
|
const fallback = options.apiKey ?? "";
|
|
2945
4509
|
return () => fallback;
|
|
2946
4510
|
})();
|
|
4511
|
+
const rawToken = withFetch(getToken, taggedFetch);
|
|
2947
4512
|
const getTalonic = (() => {
|
|
2948
4513
|
if (options.talonic) {
|
|
2949
4514
|
const t = options.talonic;
|
|
@@ -3017,6 +4582,10 @@ function createServer(options) {
|
|
|
3017
4582
|
"For Agent-stage work, follow list -> get -> claim -> heartbeat while needed ->",
|
|
3018
4583
|
"submit. Preserve the execution_epoch from claim and return only fields declared",
|
|
3019
4584
|
"in the task output_contract; never continue after a lease or epoch conflict.",
|
|
4585
|
+
"To run the customer's configured pipeline: talonic_list_specs -> talonic_run_spec (document_ids for",
|
|
4586
|
+
"workspace documents, file_urls for remote files) -> poll talonic_get_run until completed ->",
|
|
4587
|
+
"talonic_get_run_results. For open questions across documents use talonic_ask (costs credits;",
|
|
4588
|
+
"if it returns status processing, poll talonic_get_answer).",
|
|
3020
4589
|
"For External-mode app decisions, follow talonic_list_decision_tasks (by app_id) ->",
|
|
3021
4590
|
"talonic_claim_decision_task (the claim IS the payload: output_contract, precedents,",
|
|
3022
4591
|
"package descriptor) -> talonic_read_decision_package pages from package.first_cursor ->",
|
|
@@ -3048,21 +4617,24 @@ function createServer(options) {
|
|
|
3048
4617
|
registerGetBalance(server, getTalonic);
|
|
3049
4618
|
registerGetPricing(server, getTalonic);
|
|
3050
4619
|
registerGetUsage(server, getTalonic);
|
|
3051
|
-
registerRequestUpload(server,
|
|
3052
|
-
registerFieldTools(server,
|
|
3053
|
-
registerAgentRegistryTools(server,
|
|
3054
|
-
registerAgentTaskTools(server,
|
|
3055
|
-
|
|
4620
|
+
registerRequestUpload(server, rawToken, baseUrl);
|
|
4621
|
+
registerFieldTools(server, rawToken, baseUrl);
|
|
4622
|
+
registerAgentRegistryTools(server, rawToken, baseUrl);
|
|
4623
|
+
registerAgentTaskTools(server, rawToken, baseUrl);
|
|
4624
|
+
registerSpecTools(server, rawToken, baseUrl);
|
|
4625
|
+
registerRunTools(server, rawToken, baseUrl);
|
|
4626
|
+
registerAskTools(server, rawToken, baseUrl);
|
|
4627
|
+
registerDecisionTaskTools(server, rawToken, baseUrl, {
|
|
3056
4628
|
invocable: options.decisionTasksInvocable !== false
|
|
3057
4629
|
});
|
|
3058
4630
|
if (options.includeGrowthTools) {
|
|
3059
|
-
registerGrowthTools(server,
|
|
4631
|
+
registerGrowthTools(server, rawToken, baseUrl);
|
|
3060
4632
|
}
|
|
3061
4633
|
if (options.includeAdminAgentTaskTools) {
|
|
3062
|
-
registerAdminAgentTaskTools(server,
|
|
4634
|
+
registerAdminAgentTaskTools(server, rawToken, baseUrl);
|
|
3063
4635
|
}
|
|
3064
4636
|
registerSchemasResource(server, getTalonic);
|
|
3065
|
-
registerWebhooksResource(server,
|
|
4637
|
+
registerWebhooksResource(server, rawToken, baseUrl);
|
|
3066
4638
|
registerWidgets(server);
|
|
3067
4639
|
return server;
|
|
3068
4640
|
}
|