@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/index.js
CHANGED
|
@@ -3,6 +3,114 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
// src/server-factory.ts
|
|
6
|
+
function jsonOk(value) {
|
|
7
|
+
const result = {
|
|
8
|
+
content: [
|
|
9
|
+
{
|
|
10
|
+
type: "text",
|
|
11
|
+
text: JSON.stringify(value, null, 2)
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
};
|
|
15
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
16
|
+
result["structuredContent"] = value;
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
function validationError(message) {
|
|
21
|
+
return {
|
|
22
|
+
isError: true,
|
|
23
|
+
content: [{ type: "text", text: `Validation error: ${message}` }]
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function toolError(err) {
|
|
27
|
+
if (err instanceof TalonicError) {
|
|
28
|
+
const lines = [
|
|
29
|
+
`Talonic API error: ${err.message}`,
|
|
30
|
+
`code: ${err.code}`,
|
|
31
|
+
`status: ${err.status}`
|
|
32
|
+
];
|
|
33
|
+
if (err.requestId) lines.push(`request_id: ${err.requestId}`);
|
|
34
|
+
return {
|
|
35
|
+
isError: true,
|
|
36
|
+
content: [{ type: "text", text: lines.join("\n") }]
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
isError: true,
|
|
41
|
+
content: [
|
|
42
|
+
{
|
|
43
|
+
type: "text",
|
|
44
|
+
text: `Unexpected error: ${err instanceof Error ? err.message : String(err)}`
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/tools/_http.ts
|
|
51
|
+
var DEFAULT_BASE = "https://api.talonic.com";
|
|
52
|
+
function withFetch(getToken, fetchImpl) {
|
|
53
|
+
const source = (() => getToken());
|
|
54
|
+
source.fetch = fetchImpl;
|
|
55
|
+
return source;
|
|
56
|
+
}
|
|
57
|
+
function resolveFetch(getToken) {
|
|
58
|
+
return getToken.fetch ?? fetch;
|
|
59
|
+
}
|
|
60
|
+
function buildUrl(baseUrl, path, params = {}) {
|
|
61
|
+
const qs = new URLSearchParams();
|
|
62
|
+
for (const [k, v] of Object.entries(params)) {
|
|
63
|
+
if (v === void 0 || v === "") continue;
|
|
64
|
+
qs.set(k, String(v));
|
|
65
|
+
}
|
|
66
|
+
return `${baseUrl ?? DEFAULT_BASE}${path}${qs.size ? `?${qs}` : ""}`;
|
|
67
|
+
}
|
|
68
|
+
async function apiJson(getToken, baseUrl, method, path, opts = {}) {
|
|
69
|
+
const url = buildUrl(baseUrl, path, opts.params);
|
|
70
|
+
const res = await resolveFetch(getToken)(url, {
|
|
71
|
+
method,
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: `Bearer ${getToken()}`,
|
|
74
|
+
Accept: "application/json",
|
|
75
|
+
...opts.body !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
76
|
+
},
|
|
77
|
+
...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {},
|
|
78
|
+
...opts.signal ? { signal: opts.signal } : {}
|
|
79
|
+
});
|
|
80
|
+
if (!res.ok) {
|
|
81
|
+
const text = await res.text().catch(() => "");
|
|
82
|
+
throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
|
|
83
|
+
}
|
|
84
|
+
return await res.json();
|
|
85
|
+
}
|
|
86
|
+
async function apiForm(getToken, baseUrl, path, fields) {
|
|
87
|
+
const form = new FormData();
|
|
88
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
89
|
+
if (value === void 0) continue;
|
|
90
|
+
if (Array.isArray(value)) for (const item of value) form.append(key, item);
|
|
91
|
+
else form.append(key, value);
|
|
92
|
+
}
|
|
93
|
+
const res = await resolveFetch(getToken)(buildUrl(baseUrl, path), {
|
|
94
|
+
method: "POST",
|
|
95
|
+
headers: { Authorization: `Bearer ${getToken()}`, Accept: "application/json" },
|
|
96
|
+
body: form
|
|
97
|
+
});
|
|
98
|
+
if (!res.ok) {
|
|
99
|
+
const text = await res.text().catch(() => "");
|
|
100
|
+
throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
|
|
101
|
+
}
|
|
102
|
+
return await res.json();
|
|
103
|
+
}
|
|
104
|
+
function sleep(ms) {
|
|
105
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
106
|
+
}
|
|
107
|
+
async function runTool(fn) {
|
|
108
|
+
try {
|
|
109
|
+
return jsonOk(await fn());
|
|
110
|
+
} catch (err) {
|
|
111
|
+
return toolError(err);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
6
114
|
|
|
7
115
|
// src/resources/schemas-resource.ts
|
|
8
116
|
function registerSchemasResource(server, getTalonic) {
|
|
@@ -64,7 +172,7 @@ function registerWebhooksResource(server, getToken, baseUrl) {
|
|
|
64
172
|
await Promise.all(
|
|
65
173
|
WEBHOOK_INFO_ENDPOINTS.map(async ({ path, key }) => {
|
|
66
174
|
try {
|
|
67
|
-
const res = await
|
|
175
|
+
const res = await resolveFetch(getToken)(`${base}${path}`, {
|
|
68
176
|
headers: {
|
|
69
177
|
Authorization: `Bearer ${token}`,
|
|
70
178
|
Accept: "application/json"
|
|
@@ -112,14 +220,131 @@ var WIDGET_URIS = {
|
|
|
112
220
|
getBalance: "ui://widget/balance.html",
|
|
113
221
|
getPricing: "ui://widget/pricing.html",
|
|
114
222
|
getUsage: "ui://widget/usage.html",
|
|
115
|
-
requestUpload: "ui://widget/upload-link.html"
|
|
223
|
+
requestUpload: "ui://widget/upload-link.html",
|
|
224
|
+
listFields: "ui://widget/field-list.html",
|
|
225
|
+
getField: "ui://widget/field-card.html",
|
|
226
|
+
fieldValues: "ui://widget/field-values.html",
|
|
227
|
+
findData: "ui://widget/find-data.html",
|
|
228
|
+
listAgentTools: "ui://widget/agent-tools.html",
|
|
229
|
+
invokeAgentTool: "ui://widget/agent-tool-result.html",
|
|
230
|
+
listAgentTasks: "ui://widget/agent-task-list.html",
|
|
231
|
+
getAgentTask: "ui://widget/agent-task.html",
|
|
232
|
+
claimAgentTask: "ui://widget/agent-task-claim.html",
|
|
233
|
+
heartbeatAgentTask: "ui://widget/agent-task-heartbeat.html",
|
|
234
|
+
submitAgentTask: "ui://widget/agent-task-submitted.html",
|
|
235
|
+
listSpecs: "ui://widget/spec-list.html",
|
|
236
|
+
getSpec: "ui://widget/spec-card.html",
|
|
237
|
+
runSpec: "ui://widget/run-started.html",
|
|
238
|
+
getRun: "ui://widget/run-status.html",
|
|
239
|
+
getRunResults: "ui://widget/run-results.html",
|
|
240
|
+
ask: "ui://widget/answer.html",
|
|
241
|
+
getAnswer: "ui://widget/answer-polled.html",
|
|
242
|
+
listDecisionTasks: "ui://widget/decision-task-list.html",
|
|
243
|
+
claimDecisionTask: "ui://widget/decision-bundle.html",
|
|
244
|
+
readDecisionPackage: "ui://widget/decision-package.html",
|
|
245
|
+
heartbeatDecisionTask: "ui://widget/decision-task-heartbeat.html",
|
|
246
|
+
submitDecisionTask: "ui://widget/decision-task-submitted.html",
|
|
247
|
+
releaseDecisionTask: "ui://widget/decision-task-released.html",
|
|
248
|
+
failDecisionTask: "ui://widget/decision-task-failed.html"
|
|
249
|
+
};
|
|
250
|
+
WIDGET_URIS.extract;
|
|
251
|
+
var TOOL_INVOCATION_STATUS = {
|
|
252
|
+
extract: { invoking: "Extracting structured data\u2026", invoked: "Extraction complete" },
|
|
253
|
+
search: { invoking: "Searching the workspace\u2026", invoked: "Search results ready" },
|
|
254
|
+
filter: { invoking: "Filtering documents by field values\u2026", invoked: "Filter results ready" },
|
|
255
|
+
getDocument: { invoking: "Fetching document details\u2026", invoked: "Document details ready" },
|
|
256
|
+
toMarkdown: { invoking: "Converting document to markdown\u2026", invoked: "Markdown ready" },
|
|
257
|
+
listSchemas: { invoking: "Loading saved schemas\u2026", invoked: "Schemas listed" },
|
|
258
|
+
saveSchema: { invoking: "Saving schema\u2026", invoked: "Schema saved" },
|
|
259
|
+
getBalance: { invoking: "Checking credit balance\u2026", invoked: "Balance ready" },
|
|
260
|
+
getPricing: { invoking: "Loading pricing catalog\u2026", invoked: "Pricing ready" },
|
|
261
|
+
getUsage: { invoking: "Loading usage breakdown\u2026", invoked: "Usage ready" },
|
|
262
|
+
requestUpload: { invoking: "Preparing upload link\u2026", invoked: "Upload link ready" },
|
|
263
|
+
listFields: { invoking: "Loading the Field Registry\u2026", invoked: "Fields listed" },
|
|
264
|
+
getField: { invoking: "Loading field concept card\u2026", invoked: "Field card ready" },
|
|
265
|
+
fieldValues: {
|
|
266
|
+
invoking: "Reading field values across documents\u2026",
|
|
267
|
+
invoked: "Field values ready"
|
|
268
|
+
},
|
|
269
|
+
findData: { invoking: "Locating data behind the concept\u2026", invoked: "Matching data found" },
|
|
270
|
+
listAgentTools: { invoking: "Listing platform agent tools\u2026", invoked: "Agent tools listed" },
|
|
271
|
+
invokeAgentTool: { invoking: "Running platform agent tool\u2026", invoked: "Agent tool result ready" },
|
|
272
|
+
listAgentTasks: { invoking: "Loading agent task worklist\u2026", invoked: "Agent tasks listed" },
|
|
273
|
+
getAgentTask: { invoking: "Loading agent task\u2026", invoked: "Agent task ready" },
|
|
274
|
+
claimAgentTask: { invoking: "Claiming agent task\u2026", invoked: "Agent task claimed" },
|
|
275
|
+
heartbeatAgentTask: { invoking: "Extending task lease\u2026", invoked: "Lease extended" },
|
|
276
|
+
submitAgentTask: { invoking: "Submitting task outputs\u2026", invoked: "Task submitted" },
|
|
277
|
+
listSpecs: { invoking: "Loading Specs\u2026", invoked: "Specs listed" },
|
|
278
|
+
getSpec: { invoking: "Loading Spec structure\u2026", invoked: "Spec structure ready" },
|
|
279
|
+
runSpec: { invoking: "Starting the Spec run\u2026", invoked: "Run started" },
|
|
280
|
+
getRun: { invoking: "Checking run progress\u2026", invoked: "Run progress ready" },
|
|
281
|
+
getRunResults: { invoking: "Loading run results\u2026", invoked: "Run results ready" },
|
|
282
|
+
ask: { invoking: "Asking Talonic over your documents\u2026", invoked: "Answer ready" },
|
|
283
|
+
getAnswer: { invoking: "Checking for the answer\u2026", invoked: "Answer status ready" },
|
|
284
|
+
listDecisionTasks: { invoking: "Loading decision tasks\u2026", invoked: "Decision tasks listed" },
|
|
285
|
+
claimDecisionTask: { invoking: "Claiming decision task\u2026", invoked: "Decision task claimed" },
|
|
286
|
+
readDecisionPackage: { invoking: "Reading the decision package\u2026", invoked: "Package page ready" },
|
|
287
|
+
heartbeatDecisionTask: { invoking: "Extending the decision lease\u2026", invoked: "Lease extended" },
|
|
288
|
+
submitDecisionTask: { invoking: "Submitting the decision\u2026", invoked: "Decision submitted" },
|
|
289
|
+
releaseDecisionTask: { invoking: "Releasing the decision task\u2026", invoked: "Task released" },
|
|
290
|
+
failDecisionTask: {
|
|
291
|
+
invoking: "Reporting the task as undecidable\u2026",
|
|
292
|
+
invoked: "Task failed"
|
|
293
|
+
}
|
|
116
294
|
};
|
|
117
|
-
var
|
|
295
|
+
var WIDGET_DESCRIPTIONS = {
|
|
296
|
+
extract: "Card showing the extracted fields with per-field confidence, the source document, and the credit cost of the extraction.",
|
|
297
|
+
search: "Card listing the documents, fields, schemas and sources that matched the query, grouped by type.",
|
|
298
|
+
filter: "Table of documents whose extracted field values matched the filter, plus any API warnings about field types.",
|
|
299
|
+
getDocument: "Card with one document's metadata, processing status, and triage flags.",
|
|
300
|
+
toMarkdown: "Scrollable view of a document's OCR-converted markdown text.",
|
|
301
|
+
listSchemas: "Table of the workspace's saved extraction schemas with their field counts.",
|
|
302
|
+
saveSchema: "Confirmation card for a newly saved reusable schema.",
|
|
303
|
+
getBalance: "Card with the workspace credit balance, EUR value, tier, 30-day burn and projected runway.",
|
|
304
|
+
getPricing: "Table of Talonic's per-unit credit pricing with EUR values, free-tier badges and multipliers.",
|
|
305
|
+
getUsage: "Breakdown of credits consumed per function over the trailing window, with proportion bars.",
|
|
306
|
+
requestUpload: "Card with the browser upload link the user must open to add their file, plus the document id and expiry.",
|
|
307
|
+
listFields: "Table of Field Registry concepts with data type, maturity (core, proven, candidate) and occurrence counts.",
|
|
308
|
+
getField: "Concept card for one registry field: definition, synonyms, occurrence statistics, top values and schema usage.",
|
|
309
|
+
fieldValues: "Table of one field's current values across documents with confidence and source-text provenance.",
|
|
310
|
+
findData: "Ranked matches for a natural-language concept across four planes: fields, values, documents and passages.",
|
|
311
|
+
listAgentTools: "Table of the platform agent tool registry with each tool's impact, capability and whether this key may invoke it.",
|
|
312
|
+
invokeAgentTool: "Result of one platform agent tool call, rendered as a table, key-value tiles or a JSON tree, with citations.",
|
|
313
|
+
listAgentTasks: "Worklist of Agent-stage tasks with status, document, lease expiry, timeout and execution epoch.",
|
|
314
|
+
getAgentTask: "Card for one Agent-stage task: status, timing, instructions, declared output contract and the input snapshot.",
|
|
315
|
+
claimAgentTask: "Lease card confirming the claim: execution epoch to keep, lease expiry, and the task's instructions and contract.",
|
|
316
|
+
heartbeatAgentTask: "Lease card confirming the lease was extended, with the new expiry and execution epoch.",
|
|
317
|
+
submitAgentTask: "Confirmation that the declared outputs were submitted and the parked document resumed its pipeline.",
|
|
318
|
+
listSpecs: "Table of the workspace's Specs (configured pipelines) with version state, field and stage counts, and last update.",
|
|
319
|
+
getSpec: "Card for one Spec: version state, the schema it materializes onto, the rail's stages in order, the compiled phases, and its fields.",
|
|
320
|
+
runSpec: "Confirmation that a Spec run started: run kind, input count, spec/pipeline/run ids, status, and how to poll it.",
|
|
321
|
+
getRun: "Progress card for a Spec run: normalised status, documents completed / total / errors, and per-phase progress when available.",
|
|
322
|
+
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.",
|
|
323
|
+
ask: "Cited answer card: the answer text, verification verdict, source citations, artifacts and credit usage.",
|
|
324
|
+
getAnswer: "Polled answer card: the same cited answer with verification and citations, or a still-processing notice.",
|
|
325
|
+
listDecisionTasks: "Worklist of an External-mode app's decision tasks with status, run, epoch, lease expiry and SLA deadline.",
|
|
326
|
+
claimDecisionTask: "Claim bundle: the task's lease and epoch, the output contract to satisfy, precedents, and the input-package descriptor with its source documents.",
|
|
327
|
+
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.",
|
|
328
|
+
heartbeatDecisionTask: "Lease card confirming the decision task's lease was extended, with the new expiry and SLA deadline.",
|
|
329
|
+
submitDecisionTask: "Confirmation that the decision was submitted and verified; the run resumes.",
|
|
330
|
+
releaseDecisionTask: "Confirmation that the decision task was released back to available for another claimant.",
|
|
331
|
+
failDecisionTask: "Confirmation that the task was reported undecidable: a Human Review is raised and the app's fallback applies."
|
|
332
|
+
};
|
|
333
|
+
function widgetToolMeta(key) {
|
|
334
|
+
const uri = WIDGET_URIS[key];
|
|
335
|
+
const status3 = TOOL_INVOCATION_STATUS[key];
|
|
336
|
+
return {
|
|
337
|
+
ui: { resourceUri: uri },
|
|
338
|
+
"openai/outputTemplate": uri,
|
|
339
|
+
"openai/toolInvocation/invoking": status3.invoking,
|
|
340
|
+
"openai/toolInvocation/invoked": status3.invoked
|
|
341
|
+
};
|
|
342
|
+
}
|
|
118
343
|
|
|
119
344
|
// src/widgets/shared.ts
|
|
120
345
|
var WIDGET_DOMAIN = "https://talonic.com";
|
|
121
|
-
function widgetMeta() {
|
|
122
|
-
|
|
346
|
+
function widgetMeta(description) {
|
|
347
|
+
const meta = {
|
|
123
348
|
ui: {
|
|
124
349
|
domain: WIDGET_DOMAIN,
|
|
125
350
|
csp: {
|
|
@@ -133,8 +358,11 @@ function widgetMeta() {
|
|
|
133
358
|
connect_domains: [],
|
|
134
359
|
resource_domains: [],
|
|
135
360
|
redirect_domains: []
|
|
136
|
-
}
|
|
361
|
+
},
|
|
362
|
+
"openai/widgetPrefersBorder": true
|
|
137
363
|
};
|
|
364
|
+
if (description) meta["openai/widgetDescription"] = description;
|
|
365
|
+
return meta;
|
|
138
366
|
}
|
|
139
367
|
var BASE_CSS = `
|
|
140
368
|
:root {
|
|
@@ -194,6 +422,20 @@ var BASE_CSS = `
|
|
|
194
422
|
padding: 12px; max-height: 360px; overflow: auto; white-space: pre-wrap;
|
|
195
423
|
word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
196
424
|
font-size: 12px; }
|
|
425
|
+
.chip.good { background: rgba(22,163,74,.12); color: var(--good); }
|
|
426
|
+
.chip.warn { background: rgba(217,119,6,.14); color: var(--warn); }
|
|
427
|
+
.chip.bad { background: rgba(220,38,38,.12); color: var(--bad); }
|
|
428
|
+
.chip.info { background: rgba(79,70,229,.12); color: var(--accent); }
|
|
429
|
+
.plane { margin-top: 14px; }
|
|
430
|
+
.plane .subtitle { margin-bottom: 4px; }
|
|
431
|
+
.num { text-align: right; }
|
|
432
|
+
.tree-body { padding-left: 12px; border-left: 1px solid var(--border); margin: 2px 0 2px 2px; }
|
|
433
|
+
.node { padding: 2px 0; font-size: 13px; word-break: break-word; }
|
|
434
|
+
.node .k, .tree-body summary .k { color: var(--muted); }
|
|
435
|
+
details.tree { margin: 2px 0; }
|
|
436
|
+
details.tree > summary { cursor: pointer; font-size: 13px; list-style: none; }
|
|
437
|
+
details.tree > summary::before { content: "\u25B8 "; color: var(--muted); }
|
|
438
|
+
details.tree[open] > summary::before { content: "\u25BE "; }
|
|
197
439
|
`;
|
|
198
440
|
var HELPERS_JS = `
|
|
199
441
|
var root = document.getElementById("root");
|
|
@@ -224,6 +466,102 @@ var HELPERS_JS = `
|
|
|
224
466
|
if (navigator.clipboard) navigator.clipboard.writeText(text);
|
|
225
467
|
});
|
|
226
468
|
}
|
|
469
|
+
function chip(text, tone) {
|
|
470
|
+
if (text == null || text === "") return "";
|
|
471
|
+
return '<span class="chip' + (tone ? " " + tone : "") + '">' + esc(text) + '</span>';
|
|
472
|
+
}
|
|
473
|
+
function clamp(s, n) {
|
|
474
|
+
var t = String(s == null ? "" : s);
|
|
475
|
+
return t.length > n ? t.slice(0, n - 1) + "\u2026" : t;
|
|
476
|
+
}
|
|
477
|
+
function shortId(id) {
|
|
478
|
+
var s = String(id == null ? "" : id);
|
|
479
|
+
if (!s) return "\u2014";
|
|
480
|
+
return s.length > 8 ? s.slice(0, 8) : s;
|
|
481
|
+
}
|
|
482
|
+
function idChip(id) {
|
|
483
|
+
var s = String(id == null ? "" : id);
|
|
484
|
+
if (!s) return '<span class="muted">\u2014</span>';
|
|
485
|
+
return '<span class="mono" title="' + esc(s) + '">' + esc(shortId(s)) + '</span>';
|
|
486
|
+
}
|
|
487
|
+
function relTime(iso) {
|
|
488
|
+
if (!iso) return "\u2014";
|
|
489
|
+
var t = Date.parse(iso);
|
|
490
|
+
if (isNaN(t)) return String(iso);
|
|
491
|
+
var d = Math.round((t - Date.now()) / 1000);
|
|
492
|
+
var a = Math.abs(d);
|
|
493
|
+
var n, u;
|
|
494
|
+
if (a < 60) { n = a; u = "s"; }
|
|
495
|
+
else if (a < 3600) { n = Math.round(a / 60); u = "m"; }
|
|
496
|
+
else if (a < 86400) { n = Math.round(a / 3600); u = "h"; }
|
|
497
|
+
else { n = Math.round(a / 86400); u = "d"; }
|
|
498
|
+
return d >= 0 ? "in " + n + u : n + u + " ago";
|
|
499
|
+
}
|
|
500
|
+
function isFlat(obj) {
|
|
501
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return false;
|
|
502
|
+
return Object.keys(obj).every(function (k) { var v = obj[k]; return v == null || typeof v !== "object"; });
|
|
503
|
+
}
|
|
504
|
+
function isRowArray(v) {
|
|
505
|
+
return Array.isArray(v) && v.length > 0 && v.every(function (r) { return !!r && typeof r === "object" && !Array.isArray(r); });
|
|
506
|
+
}
|
|
507
|
+
function dataTable(rows, columns) {
|
|
508
|
+
if (!Array.isArray(rows) || !rows.length) return "";
|
|
509
|
+
var cols = columns ? columns.slice() : [];
|
|
510
|
+
if (!columns) {
|
|
511
|
+
rows.forEach(function (r) {
|
|
512
|
+
if (r && typeof r === "object" && !Array.isArray(r)) {
|
|
513
|
+
Object.keys(r).forEach(function (k) { if (cols.indexOf(k) < 0) cols.push(k); });
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
var extraCols = cols.length > 12 ? cols.length - 12 : 0;
|
|
518
|
+
cols = cols.slice(0, 12);
|
|
519
|
+
var shown = rows.slice(0, 50);
|
|
520
|
+
var html = '<table><thead><tr>' + cols.map(function (c) { return '<th>' + esc(c) + '</th>'; }).join("") + '</tr></thead><tbody>';
|
|
521
|
+
shown.forEach(function (r) {
|
|
522
|
+
html += '<tr>' + cols.map(function (c) {
|
|
523
|
+
var v = r && typeof r === "object" && !Array.isArray(r) ? r[c] : r;
|
|
524
|
+
var cell = v != null && typeof v === "object" ? clamp(JSON.stringify(v), 80) : fmt(v);
|
|
525
|
+
return '<td class="val">' + esc(cell) + '</td>';
|
|
526
|
+
}).join("") + '</tr>';
|
|
527
|
+
});
|
|
528
|
+
html += '</tbody></table>';
|
|
529
|
+
var more = [];
|
|
530
|
+
if (rows.length > shown.length) more.push("+" + (rows.length - shown.length) + " more rows");
|
|
531
|
+
if (extraCols) more.push("+" + extraCols + " more columns");
|
|
532
|
+
if (more.length) html += '<div class="muted small" style="margin-top:6px">' + esc(more.join(" \xB7 ")) + '</div>';
|
|
533
|
+
return html;
|
|
534
|
+
}
|
|
535
|
+
function kvTiles(obj) {
|
|
536
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return "";
|
|
537
|
+
var keys = Object.keys(obj);
|
|
538
|
+
if (!keys.length) return "";
|
|
539
|
+
return '<div class="grid">' + keys.map(function (k) {
|
|
540
|
+
var v = obj[k];
|
|
541
|
+
var text = v != null && typeof v === "object" ? clamp(JSON.stringify(v), 120) : fmt(v);
|
|
542
|
+
return '<div class="kv"><span class="k">' + esc(k) + '</span><span class="val">' + esc(text === "" ? "\u2014" : text) + '</span></div>';
|
|
543
|
+
}).join("") + '</div>';
|
|
544
|
+
}
|
|
545
|
+
function jsonTree(value, depth, budget) {
|
|
546
|
+
depth = depth || 0;
|
|
547
|
+
budget = budget || { n: 400 };
|
|
548
|
+
if (budget.n-- <= 0) return '<span class="muted">\u2026</span>';
|
|
549
|
+
if (value == null || typeof value !== "object") return '<span class="val mono">' + esc(fmt(value)) + '</span>';
|
|
550
|
+
if (depth >= 6) return '<span class="muted">' + esc(clamp(JSON.stringify(value), 80)) + '</span>';
|
|
551
|
+
var isArr = Array.isArray(value);
|
|
552
|
+
var keys = isArr ? value.map(function (_, i) { return String(i); }) : Object.keys(value);
|
|
553
|
+
if (!keys.length) return '<span class="muted">' + (isArr ? "[]" : "{}") + '</span>';
|
|
554
|
+
var inner = keys.map(function (k) {
|
|
555
|
+
var v = value[k];
|
|
556
|
+
var label = '<span class="k mono">' + esc(k) + '</span>';
|
|
557
|
+
if (v == null || typeof v !== "object") {
|
|
558
|
+
return '<div class="node">' + label + ' <span class="val mono">' + esc(fmt(v)) + '</span></div>';
|
|
559
|
+
}
|
|
560
|
+
var size = Array.isArray(v) ? "[" + v.length + "]" : "{" + Object.keys(v).length + "}";
|
|
561
|
+
return '<details class="tree"' + (depth < 1 ? " open" : "") + '><summary>' + label + ' <span class="muted small">' + size + '</span></summary>' + jsonTree(v, depth + 1, budget) + '</details>';
|
|
562
|
+
}).join("");
|
|
563
|
+
return '<div class="tree-body">' + inner + '</div>';
|
|
564
|
+
}
|
|
227
565
|
`;
|
|
228
566
|
var BOOTSTRAP_JS = `
|
|
229
567
|
function payloadFromHost() {
|
|
@@ -287,7 +625,7 @@ function registerWidget(server, opts) {
|
|
|
287
625
|
uri: opts.uri,
|
|
288
626
|
mimeType: WIDGET_MIME,
|
|
289
627
|
text: opts.html,
|
|
290
|
-
_meta: widgetMeta()
|
|
628
|
+
_meta: widgetMeta(opts.description)
|
|
291
629
|
}
|
|
292
630
|
]
|
|
293
631
|
})
|
|
@@ -686,134 +1024,939 @@ var WIDGET_HTML11 = buildWidgetHtml({
|
|
|
686
1024
|
renderBody: RENDER_BODY11
|
|
687
1025
|
});
|
|
688
1026
|
|
|
1027
|
+
// src/widgets/field-list.ts
|
|
1028
|
+
function getFieldListWidgetHtml() {
|
|
1029
|
+
return WIDGET_HTML12;
|
|
1030
|
+
}
|
|
1031
|
+
var RENDER_BODY12 = `
|
|
1032
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1033
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1034
|
+
if (!rows.length) { empty("No fields match."); return; }
|
|
1035
|
+
function maturityTone(m) { return m === "core" ? "good" : m === "proven" ? "info" : m === "candidate" ? "warn" : ""; }
|
|
1036
|
+
var body = rows.map(function (f) {
|
|
1037
|
+
f = f && typeof f === "object" ? f : {};
|
|
1038
|
+
var name = f.display_name || f.canonical_name || f.id || "(field)";
|
|
1039
|
+
var sup = f.superseded_by ? ' <span class="chip bad" title="' + esc(f.superseded_by) + '">superseded</span>' : "";
|
|
1040
|
+
var canon = f.canonical_name && f.canonical_name !== name ? '<div class="muted small mono">' + esc(f.canonical_name) + '</div>' : "";
|
|
1041
|
+
return '<tr>'
|
|
1042
|
+
+ '<td><div class="val">' + esc(name) + sup + '</div>' + canon + '</td>'
|
|
1043
|
+
+ '<td>' + chip(f.data_type, "") + '</td>'
|
|
1044
|
+
+ '<td>' + chip(f.maturity, maturityTone(f.maturity)) + (f.tier != null ? ' <span class="muted small">tier ' + esc(f.tier) + '</span>' : "") + '</td>'
|
|
1045
|
+
+ '<td class="val num">' + esc(f.occurrence_count != null ? f.occurrence_count : "\u2014") + '</td>'
|
|
1046
|
+
+ '</tr>';
|
|
1047
|
+
}).join("");
|
|
1048
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1049
|
+
root.innerHTML = ''
|
|
1050
|
+
+ '<div class="header"><div><div class="title">Field Registry</div><div class="subtitle">' + rows.length + ' of ' + total + ' fields</div></div>'
|
|
1051
|
+
+ (pg.has_more ? '<span class="chip">more available</span>' : "") + '</div>'
|
|
1052
|
+
+ '<table><thead><tr><th>Field</th><th>Type</th><th>Maturity</th><th class="num">Occurrences</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1053
|
+
`;
|
|
1054
|
+
var WIDGET_HTML12 = buildWidgetHtml({
|
|
1055
|
+
title: "Talonic \u2014 Field Registry",
|
|
1056
|
+
renderBody: RENDER_BODY12
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
// src/widgets/field-card.ts
|
|
1060
|
+
function getFieldCardWidgetHtml() {
|
|
1061
|
+
return WIDGET_HTML13;
|
|
1062
|
+
}
|
|
1063
|
+
var RENDER_BODY13 = `
|
|
1064
|
+
if (!payload || (!payload.canonical_name && !payload.id)) { empty("No field card."); return; }
|
|
1065
|
+
var def = payload.definition && typeof payload.definition === "object" ? payload.definition : {};
|
|
1066
|
+
var occ = payload.occurrence && typeof payload.occurrence === "object" ? payload.occurrence : {};
|
|
1067
|
+
var vals = payload.values && typeof payload.values === "object" ? payload.values : {};
|
|
1068
|
+
var usage = payload.usage && typeof payload.usage === "object" ? payload.usage : {};
|
|
1069
|
+
var ident = payload.identity && typeof payload.identity === "object" ? payload.identity : {};
|
|
1070
|
+
var res = payload.resolution && typeof payload.resolution === "object" ? payload.resolution : null;
|
|
1071
|
+
function maturityTone(m) { return m === "core" ? "good" : m === "proven" ? "info" : m === "candidate" ? "warn" : ""; }
|
|
1072
|
+
var name = payload.display_name || payload.canonical_name || payload.id;
|
|
1073
|
+
var definition = def.description || payload.description || def.instruction || payload.master_instruction || "";
|
|
1074
|
+
var synonymList = Array.isArray(def.synonyms) ? def.synonyms : Array.isArray(payload.synonyms) ? payload.synonyms : [];
|
|
1075
|
+
var synonyms = synonymList.slice(0, 12).map(function (s) { return chip(s, ""); }).join("");
|
|
1076
|
+
var top = Array.isArray(vals.top) ? vals.top.slice(0, 8) : [];
|
|
1077
|
+
var topHtml = top.map(function (t) {
|
|
1078
|
+
t = t && typeof t === "object" ? t : {};
|
|
1079
|
+
var share = typeof t.share === "number" ? Math.max(0, Math.min(100, Math.round(t.share * 100))) : null;
|
|
1080
|
+
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>'
|
|
1081
|
+
+ (share == null ? "" : '<span class="bar"><span style="width:' + share + '%"></span></span> <span class="muted small">' + share + '%</span>') + '</td></tr>';
|
|
1082
|
+
}).join("");
|
|
1083
|
+
var rate = typeof occ.occurrence_rate === "number" ? (Math.round(occ.occurrence_rate * 1000) / 10) + "%" : "\u2014";
|
|
1084
|
+
var redirected = res && Array.isArray(res.redirected_from) && res.redirected_from.length ? res.redirected_from.join(", ") : "";
|
|
1085
|
+
var occCount = occ.occurrence_count != null ? occ.occurrence_count : payload.occurrence_count != null ? payload.occurrence_count : "\u2014";
|
|
1086
|
+
root.innerHTML = ''
|
|
1087
|
+
+ '<div class="header"><div><div class="title">' + esc(name) + '</div>'
|
|
1088
|
+
+ (payload.canonical_name && payload.canonical_name !== name ? '<div class="subtitle mono">' + esc(payload.canonical_name) + '</div>' : "") + '</div>'
|
|
1089
|
+
+ '<div>' + chip(payload.data_type, "") + chip(payload.maturity, maturityTone(payload.maturity))
|
|
1090
|
+
+ (payload.tier != null ? chip("tier " + payload.tier, "") : "")
|
|
1091
|
+
+ (ident.superseded_by || payload.superseded_by ? chip("superseded", "bad") : "")
|
|
1092
|
+
+ (ident.link_key ? chip("link key", "info") : "") + '</div></div>'
|
|
1093
|
+
+ (definition ? '<div class="small" style="white-space:pre-wrap">' + esc(clamp(definition, 600)) + '</div>' : '<div class="muted small">No definition recorded.</div>')
|
|
1094
|
+
+ (synonyms ? '<div style="margin-top:8px"><div class="muted small">Also known as</div><div>' + synonyms + '</div></div>' : "")
|
|
1095
|
+
+ '<div class="grid">'
|
|
1096
|
+
+ '<div class="kv"><span class="k">Occurrences</span><span class="val">' + esc(occCount) + '</span></div>'
|
|
1097
|
+
+ '<div class="kv"><span class="k">Documents</span><span class="val">' + esc(occ.document_count != null ? occ.document_count : "\u2014") + '</span></div>'
|
|
1098
|
+
+ '<div class="kv"><span class="k">Occurrence rate</span><span class="val">' + esc(rate) + '</span></div>'
|
|
1099
|
+
+ '<div class="kv"><span class="k">Distinct values</span><span class="val">' + esc(vals.distinct_count != null ? vals.distinct_count : "\u2014") + '</span></div>'
|
|
1100
|
+
+ '<div class="kv"><span class="k">Used in schemas</span><span class="val">' + esc(usage.schema_count != null ? usage.schema_count : "\u2014") + '</span></div>'
|
|
1101
|
+
+ '<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>'
|
|
1102
|
+
+ '</div>'
|
|
1103
|
+
+ (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>' : "")
|
|
1104
|
+
+ (res ? '<div class="muted small" style="margin-top:10px">Resolved by ' + esc(res.matched_by || "id") + (redirected ? ' \xB7 redirected from ' + esc(redirected) : "") + '</div>' : "");
|
|
1105
|
+
`;
|
|
1106
|
+
var WIDGET_HTML13 = buildWidgetHtml({
|
|
1107
|
+
title: "Talonic \u2014 Field Card",
|
|
1108
|
+
renderBody: RENDER_BODY13
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
// src/widgets/field-values.ts
|
|
1112
|
+
function getFieldValuesWidgetHtml() {
|
|
1113
|
+
return WIDGET_HTML14;
|
|
1114
|
+
}
|
|
1115
|
+
var RENDER_BODY14 = `
|
|
1116
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1117
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1118
|
+
var name = payload.canonical_name || payload.field_id || "field";
|
|
1119
|
+
if (!rows.length) { empty("No values recorded for " + name + "."); return; }
|
|
1120
|
+
var body = rows.map(function (r) {
|
|
1121
|
+
r = r && typeof r === "object" ? r : { value: r };
|
|
1122
|
+
var prov = r.provenance && typeof r.provenance === "object" ? r.provenance : {};
|
|
1123
|
+
var flags = (prov.needs_confirmation ? chip("needs confirmation", "warn") : "") + (prov.via_redirect ? chip("via redirect", "info") : "");
|
|
1124
|
+
return '<tr>'
|
|
1125
|
+
+ '<td class="val mono">' + esc(clamp(fmt(r.value), 80)) + '</td>'
|
|
1126
|
+
+ '<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>'
|
|
1127
|
+
+ '<td>' + confBar(r.confidence) + '</td>'
|
|
1128
|
+
+ '<td class="small">' + (prov.raw_field_name ? '<div class="mono">' + esc(prov.raw_field_name) + '</div>' : "")
|
|
1129
|
+
+ (prov.source_text ? '<div class="muted">\u201C' + esc(clamp(prov.source_text, 90)) + '\u201D</div>' : "") + flags + '</td>'
|
|
1130
|
+
+ '</tr>';
|
|
1131
|
+
}).join("");
|
|
1132
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1133
|
+
root.innerHTML = ''
|
|
1134
|
+
+ '<div class="header"><div><div class="title">' + esc(name) + '</div><div class="subtitle">' + rows.length + ' of ' + total + ' values</div></div>'
|
|
1135
|
+
+ (pg.has_more ? '<span class="chip">more available</span>' : "") + '</div>'
|
|
1136
|
+
+ '<table><thead><tr><th>Value</th><th>Document</th><th>Confidence</th><th>Provenance</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1137
|
+
`;
|
|
1138
|
+
var WIDGET_HTML14 = buildWidgetHtml({
|
|
1139
|
+
title: "Talonic \u2014 Field Values",
|
|
1140
|
+
renderBody: RENDER_BODY14
|
|
1141
|
+
});
|
|
1142
|
+
|
|
1143
|
+
// src/widgets/find-data.ts
|
|
1144
|
+
function getFindDataWidgetHtml() {
|
|
1145
|
+
return WIDGET_HTML15;
|
|
1146
|
+
}
|
|
1147
|
+
var RENDER_BODY15 = `
|
|
1148
|
+
var res = payload && payload.result && typeof payload.result === "object" ? payload.result : (payload && typeof payload === "object" ? payload : {});
|
|
1149
|
+
var fields = Array.isArray(res.fields) ? res.fields : [];
|
|
1150
|
+
var values = Array.isArray(res.values) ? res.values : [];
|
|
1151
|
+
var docs = Array.isArray(res.documents) ? res.documents : [];
|
|
1152
|
+
var passages = Array.isArray(res.passages) ? res.passages : [];
|
|
1153
|
+
var total = fields.length + values.length + docs.length + passages.length;
|
|
1154
|
+
var query = typeof res.query === "string" ? res.query : "";
|
|
1155
|
+
if (!total) { empty("Nothing in the workspace matches" + (query ? " \u201C" + query + "\u201D" : "") + "."); return; }
|
|
1156
|
+
function scoreBar(s) {
|
|
1157
|
+
if (typeof s !== "number") return "";
|
|
1158
|
+
var p = Math.max(0, Math.min(100, Math.round(s * 100)));
|
|
1159
|
+
return '<span class="bar"><span style="width:' + p + '%"></span></span> <span class="muted small">' + p + '%</span>';
|
|
1160
|
+
}
|
|
1161
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1162
|
+
function plane(label, items, renderItem) {
|
|
1163
|
+
if (!items.length) return "";
|
|
1164
|
+
return '<div class="plane"><div class="subtitle">' + esc(label) + ' (' + items.length + ')</div>' + items.map(function (i) { return renderItem(obj(i)); }).join("") + '</div>';
|
|
1165
|
+
}
|
|
1166
|
+
var fieldsHtml = plane("Fields", fields, function (f) {
|
|
1167
|
+
var samples = Array.isArray(f.samples) ? f.samples.slice(0, 3).map(function (s) {
|
|
1168
|
+
var v = s && typeof s === "object" && "value" in s ? s.value : s;
|
|
1169
|
+
return chip(clamp(fmt(v), 40), "");
|
|
1170
|
+
}).join("") : "";
|
|
1171
|
+
return '<div class="kv"><div><span class="val">' + esc(f.display_name || f.canonical_name || "(field)") + '</span> ' + chip(f.data_type, "")
|
|
1172
|
+
+ (f.tier != null ? chip("tier " + f.tier, "") : "") + (f.match ? chip(f.match, "info") : "") + '</div>'
|
|
1173
|
+
+ '<div class="small muted">' + (f.occurrence_count != null ? esc(f.occurrence_count) + ' occurrences \xB7 ' : "") + scoreBar(f.score) + '</div>'
|
|
1174
|
+
+ (samples ? '<div>' + samples + '</div>' : "") + '</div>';
|
|
1175
|
+
});
|
|
1176
|
+
var valuesHtml = plane("Values", values, function (v) {
|
|
1177
|
+
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 || "")
|
|
1178
|
+
+ (v.filename ? ' \xB7 ' + esc(v.filename) : "") + ' ' + scoreBar(v.score) + '</span></div>';
|
|
1179
|
+
});
|
|
1180
|
+
var docsHtml = plane("Documents", docs, function (d) {
|
|
1181
|
+
return '<div class="kv"><span class="val">' + esc(d.filename || shortId(d.document_id)) + '</span><span class="small muted">' + scoreBar(d.score) + '</span>'
|
|
1182
|
+
+ (d.best_passage ? '<span class="small">' + esc(clamp(d.best_passage, 160)) + '</span>' : "") + '</div>';
|
|
1183
|
+
});
|
|
1184
|
+
var passagesHtml = plane("Passages", passages, function (p) {
|
|
1185
|
+
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>';
|
|
1186
|
+
});
|
|
1187
|
+
root.innerHTML = ''
|
|
1188
|
+
+ '<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>'
|
|
1189
|
+
+ fieldsHtml + valuesHtml + docsHtml + passagesHtml;
|
|
1190
|
+
`;
|
|
1191
|
+
var WIDGET_HTML15 = buildWidgetHtml({
|
|
1192
|
+
title: "Talonic \u2014 Find Data",
|
|
1193
|
+
renderBody: RENDER_BODY15
|
|
1194
|
+
});
|
|
1195
|
+
|
|
1196
|
+
// src/widgets/agent-tools.ts
|
|
1197
|
+
function getAgentToolsWidgetHtml() {
|
|
1198
|
+
return WIDGET_HTML16;
|
|
1199
|
+
}
|
|
1200
|
+
var RENDER_BODY16 = `
|
|
1201
|
+
var tools = Array.isArray(payload.tools) ? payload.tools : [];
|
|
1202
|
+
if (!tools.length) { empty("No agent tools are visible to this credential."); return; }
|
|
1203
|
+
function impactTone(i) { return i === "read" ? "good" : i === "draft_mutation" ? "warn" : i === "live_mutation" ? "bad" : ""; }
|
|
1204
|
+
var body = tools.map(function (t) {
|
|
1205
|
+
t = t && typeof t === "object" ? t : {};
|
|
1206
|
+
return '<tr>'
|
|
1207
|
+
+ '<td><div class="val mono">' + esc(t.name || "(tool)") + '</div><div class="muted small">' + esc(clamp(t.description, 140)) + '</div></td>'
|
|
1208
|
+
+ '<td>' + chip(t.impact, impactTone(t.impact)) + '</td>'
|
|
1209
|
+
+ '<td>' + chip(t.capability, "") + '</td>'
|
|
1210
|
+
+ '<td>' + (t.can_invoke ? '<span class="chip good">\u2713 invocable</span>' : '<span class="muted small">\u2014</span>') + '</td>'
|
|
1211
|
+
+ '</tr>';
|
|
1212
|
+
}).join("");
|
|
1213
|
+
var inv = typeof payload.invocable_count === "number" ? payload.invocable_count : tools.filter(function (t) { return t && t.can_invoke; }).length;
|
|
1214
|
+
var total = typeof payload.totalCount === "number" ? payload.totalCount : tools.length;
|
|
1215
|
+
root.innerHTML = ''
|
|
1216
|
+
+ '<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>'
|
|
1217
|
+
+ '<table><thead><tr><th>Tool</th><th>Impact</th><th>Capability</th><th>Access</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1218
|
+
`;
|
|
1219
|
+
var WIDGET_HTML16 = buildWidgetHtml({
|
|
1220
|
+
title: "Talonic \u2014 Agent Tools",
|
|
1221
|
+
renderBody: RENDER_BODY16
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1224
|
+
// src/widgets/agent-tool-result.ts
|
|
1225
|
+
function getAgentToolResultWidgetHtml() {
|
|
1226
|
+
return WIDGET_HTML17;
|
|
1227
|
+
}
|
|
1228
|
+
var RENDER_BODY17 = `
|
|
1229
|
+
var result = payload && typeof payload === "object" ? payload.result : undefined;
|
|
1230
|
+
var toolName = (payload && payload.tool) || "agent tool";
|
|
1231
|
+
var isEmptyResult = result == null || result === ""
|
|
1232
|
+
|| (Array.isArray(result) && result.length === 0)
|
|
1233
|
+
|| (typeof result === "object" && !Array.isArray(result) && Object.keys(result).length === 0);
|
|
1234
|
+
var body;
|
|
1235
|
+
if (isEmptyResult) body = '<div class="empty">The tool returned no data.</div>';
|
|
1236
|
+
else if (isRowArray(result)) body = dataTable(result);
|
|
1237
|
+
else if (isFlat(result)) body = kvTiles(result);
|
|
1238
|
+
else if (typeof result === "object") body = jsonTree(result);
|
|
1239
|
+
else body = '<pre class="md">' + esc(fmt(result)) + '</pre>';
|
|
1240
|
+
var cites = Array.isArray(payload.citations) ? payload.citations : [];
|
|
1241
|
+
var arts = Array.isArray(payload.artifacts) ? payload.artifacts : [];
|
|
1242
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1243
|
+
var citeHtml = cites.length ? '<div class="plane"><div class="subtitle">Citations (' + cites.length + ')</div>' + cites.slice(0, 20).map(function (c) {
|
|
1244
|
+
c = obj(c);
|
|
1245
|
+
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>';
|
|
1246
|
+
}).join("") + '</div>' : "";
|
|
1247
|
+
var artHtml = arts.length ? '<div class="plane"><div class="subtitle">Artifacts (' + arts.length + ')</div>' + arts.slice(0, 20).map(function (a) {
|
|
1248
|
+
a = obj(a);
|
|
1249
|
+
var link = typeof a.link === "string" && /^https:\\/\\//.test(a.link) ? a.link : "";
|
|
1250
|
+
return '<div class="kv"><span class="val">' + esc(a.label || a.type || a.id || "artifact") + '</span>'
|
|
1251
|
+
+ (link ? '<a class="btn small" href="' + esc(link) + '" target="_blank" rel="noopener noreferrer">Open</a>' : "") + '</div>';
|
|
1252
|
+
}).join("") + '</div>' : "";
|
|
1253
|
+
var count = "";
|
|
1254
|
+
if (!isEmptyResult) {
|
|
1255
|
+
if (isRowArray(result)) count = result.length + (result.length === 1 ? " row" : " rows");
|
|
1256
|
+
else if (result && typeof result === "object" && !Array.isArray(result)) {
|
|
1257
|
+
var keyCount = Object.keys(result).length;
|
|
1258
|
+
count = keyCount + (keyCount === 1 ? " key" : " keys");
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
root.innerHTML = ''
|
|
1262
|
+
+ '<div class="header"><div><div class="title mono">' + esc(toolName) + '</div>' + (count ? '<div class="subtitle">' + esc(count) + '</div>' : "") + '</div></div>'
|
|
1263
|
+
+ body + citeHtml + artHtml;
|
|
1264
|
+
`;
|
|
1265
|
+
var WIDGET_HTML17 = buildWidgetHtml({
|
|
1266
|
+
title: "Talonic \u2014 Agent Tool Result",
|
|
1267
|
+
renderBody: RENDER_BODY17
|
|
1268
|
+
});
|
|
1269
|
+
|
|
1270
|
+
// src/widgets/agent-task-shared.ts
|
|
1271
|
+
var TASK_JS = `
|
|
1272
|
+
function statusTone(s) {
|
|
1273
|
+
return s === "available" ? "info" : s === "claimed" || s === "submitted" ? "good" : s === "timed_out" ? "bad" : s === "cancelled" ? "warn" : "";
|
|
1274
|
+
}
|
|
1275
|
+
function taskTiming(p) {
|
|
1276
|
+
return '<div class="grid">'
|
|
1277
|
+
+ '<div class="kv"><span class="k">Document</span> <span class="val">' + idChip(p.document_id) + '</span></div>'
|
|
1278
|
+
+ '<div class="kv"><span class="k">Pipeline</span> <span class="val">' + idChip(p.pipeline_id) + '</span></div>'
|
|
1279
|
+
+ '<div class="kv"><span class="k">Phase</span> <span class="val">' + esc(p.phase_index != null ? p.phase_index : "\u2014") + '</span></div>'
|
|
1280
|
+
+ '<div class="kv"><span class="k">Execution epoch</span> <span class="val">' + esc(p.execution_epoch != null ? p.execution_epoch : "\u2014") + '</span></div>'
|
|
1281
|
+
+ '<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>'
|
|
1282
|
+
+ '<div class="kv"><span class="k">Times out</span> <span class="val">' + esc(p.timeout_at ? relTime(p.timeout_at) : "\u2014") + '</span></div>'
|
|
1283
|
+
+ '</div>';
|
|
1284
|
+
}
|
|
1285
|
+
function taskSections(p) {
|
|
1286
|
+
var html = "";
|
|
1287
|
+
if (typeof p.instructions === "string" && p.instructions) {
|
|
1288
|
+
html += '<div class="plane"><div class="subtitle">Instructions</div><div class="small" style="white-space:pre-wrap">' + esc(clamp(p.instructions, 1200)) + '</div></div>';
|
|
1289
|
+
}
|
|
1290
|
+
if (Array.isArray(p.output_contract) && p.output_contract.length) {
|
|
1291
|
+
html += '<div class="plane"><div class="subtitle">Output contract (' + p.output_contract.length + ')</div>'
|
|
1292
|
+
+ '<table><thead><tr><th>Field</th><th>Type</th><th>Required</th></tr></thead><tbody>'
|
|
1293
|
+
+ p.output_contract.map(function (f) {
|
|
1294
|
+
f = f && typeof f === "object" ? f : {};
|
|
1295
|
+
return '<tr><td class="val mono">' + esc(f.key || "") + '</td><td>' + chip(f.dataType, "") + '</td><td>'
|
|
1296
|
+
+ (f.required ? chip("required", "warn") : '<span class="muted small">optional</span>') + '</td></tr>';
|
|
1297
|
+
}).join("")
|
|
1298
|
+
+ '</tbody></table></div>';
|
|
1299
|
+
}
|
|
1300
|
+
var snap = p.input_snapshot;
|
|
1301
|
+
if (snap && typeof snap === "object" && !Array.isArray(snap) && Object.keys(snap).length) {
|
|
1302
|
+
html += '<div class="plane"><div class="subtitle">Input snapshot</div>' + (isFlat(snap) ? kvTiles(snap) : jsonTree(snap)) + '</div>';
|
|
1303
|
+
}
|
|
1304
|
+
if (p.timeout_fallthrough) {
|
|
1305
|
+
html += '<div class="muted small" style="margin-top:10px">On timeout: ' + esc(String(p.timeout_fallthrough).replace(/_/g, " ")) + '</div>';
|
|
1306
|
+
}
|
|
1307
|
+
return html;
|
|
1308
|
+
}
|
|
1309
|
+
`;
|
|
1310
|
+
|
|
1311
|
+
// src/widgets/agent-task-list.ts
|
|
1312
|
+
function getAgentTaskListWidgetHtml() {
|
|
1313
|
+
return WIDGET_HTML18;
|
|
1314
|
+
}
|
|
1315
|
+
var RENDER_BODY18 = TASK_JS + `
|
|
1316
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1317
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1318
|
+
if (!rows.length) { empty("No agent tasks in this worklist."); return; }
|
|
1319
|
+
var body = rows.map(function (t) {
|
|
1320
|
+
t = t && typeof t === "object" ? t : {};
|
|
1321
|
+
return '<tr>'
|
|
1322
|
+
+ '<td>' + idChip(t.id) + '</td>'
|
|
1323
|
+
+ '<td>' + chip(t.status, statusTone(t.status)) + '</td>'
|
|
1324
|
+
+ '<td>' + idChip(t.document_id) + '</td>'
|
|
1325
|
+
+ '<td class="val num">' + esc(t.phase_index != null ? t.phase_index : "\u2014") + '</td>'
|
|
1326
|
+
+ '<td class="val">' + esc(t.lease_expires_at ? relTime(t.lease_expires_at) : "\u2014") + '</td>'
|
|
1327
|
+
+ '<td class="val">' + esc(t.timeout_at ? relTime(t.timeout_at) : "\u2014") + '</td>'
|
|
1328
|
+
+ '<td class="val num">' + esc(t.execution_epoch != null ? t.execution_epoch : "\u2014") + '</td>'
|
|
1329
|
+
+ '</tr>';
|
|
1330
|
+
}).join("");
|
|
1331
|
+
var counts = {};
|
|
1332
|
+
rows.forEach(function (t) { var s = t && typeof t === "object" && t.status ? t.status : "unknown"; counts[s] = (counts[s] || 0) + 1; });
|
|
1333
|
+
var summary = Object.keys(counts).map(function (s) { return chip(counts[s] + " " + s, statusTone(s)); }).join("");
|
|
1334
|
+
root.innerHTML = ''
|
|
1335
|
+
+ '<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>'
|
|
1336
|
+
+ '<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>';
|
|
1337
|
+
`;
|
|
1338
|
+
var WIDGET_HTML18 = buildWidgetHtml({
|
|
1339
|
+
title: "Talonic \u2014 Agent Tasks",
|
|
1340
|
+
renderBody: RENDER_BODY18
|
|
1341
|
+
});
|
|
1342
|
+
|
|
1343
|
+
// src/widgets/agent-task.ts
|
|
1344
|
+
function getAgentTaskWidgetHtml() {
|
|
1345
|
+
return WIDGET_HTML19;
|
|
1346
|
+
}
|
|
1347
|
+
var RENDER_BODY19 = TASK_JS + `
|
|
1348
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No agent task."); return; }
|
|
1349
|
+
root.innerHTML = ''
|
|
1350
|
+
+ '<div class="header"><div><div class="title">Agent task ' + idChip(payload.id) + '</div>'
|
|
1351
|
+
+ '<div class="subtitle">' + esc(payload.created_at ? "created " + relTime(payload.created_at) : "") + '</div></div>'
|
|
1352
|
+
+ '<div>' + chip(payload.status, statusTone(payload.status)) + '</div></div>'
|
|
1353
|
+
+ taskTiming(payload) + taskSections(payload);
|
|
1354
|
+
`;
|
|
1355
|
+
var WIDGET_HTML19 = buildWidgetHtml({
|
|
1356
|
+
title: "Talonic \u2014 Agent Task",
|
|
1357
|
+
renderBody: RENDER_BODY19
|
|
1358
|
+
});
|
|
1359
|
+
|
|
1360
|
+
// src/widgets/agent-task-lease.ts
|
|
1361
|
+
function getAgentTaskClaimWidgetHtml() {
|
|
1362
|
+
return CLAIM_HTML;
|
|
1363
|
+
}
|
|
1364
|
+
function getAgentTaskHeartbeatWidgetHtml() {
|
|
1365
|
+
return HEARTBEAT_HTML;
|
|
1366
|
+
}
|
|
1367
|
+
var LEASE_BODY = `
|
|
1368
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No lease information."); return; }
|
|
1369
|
+
root.innerHTML = ''
|
|
1370
|
+
+ '<div class="header"><div><div class="title">' + HEADLINE + '</div><div class="subtitle">Task ' + idChip(payload.id) + '</div></div>'
|
|
1371
|
+
+ '<div>' + chip(payload.status, statusTone(payload.status)) + '</div></div>'
|
|
1372
|
+
+ '<div class="big">' + esc(payload.execution_epoch != null ? payload.execution_epoch : "\u2014") + ' <span class="muted small">execution epoch</span></div>'
|
|
1373
|
+
+ '<div class="muted small">Keep this epoch for heartbeat and submit.' + (payload.lease_expires_at ? ' Lease expires ' + esc(relTime(payload.lease_expires_at)) + '.' : "") + '</div>'
|
|
1374
|
+
+ taskTiming(payload) + taskSections(payload);
|
|
1375
|
+
`;
|
|
1376
|
+
function leaseWidget(headline, title) {
|
|
1377
|
+
return buildWidgetHtml({
|
|
1378
|
+
title,
|
|
1379
|
+
renderBody: TASK_JS + " var HEADLINE = " + JSON.stringify(headline) + ";\n" + LEASE_BODY
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
var CLAIM_HTML = leaseWidget("Task claimed", "Talonic \u2014 Agent Task Claimed");
|
|
1383
|
+
var HEARTBEAT_HTML = leaseWidget("Lease extended", "Talonic \u2014 Agent Task Lease");
|
|
1384
|
+
|
|
1385
|
+
// src/widgets/agent-task-submitted.ts
|
|
1386
|
+
function getAgentTaskSubmittedWidgetHtml() {
|
|
1387
|
+
return WIDGET_HTML20;
|
|
1388
|
+
}
|
|
1389
|
+
var RENDER_BODY20 = TASK_JS + `
|
|
1390
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No submission recorded."); return; }
|
|
1391
|
+
root.innerHTML = ''
|
|
1392
|
+
+ '<div class="header"><div><div class="title">Outputs submitted</div><div class="subtitle">Task ' + idChip(payload.id)
|
|
1393
|
+
+ (payload.submitted_at ? ' \xB7 ' + esc(relTime(payload.submitted_at)) : "") + '</div></div>'
|
|
1394
|
+
+ '<div>' + chip(payload.status, statusTone(payload.status)) + '</div></div>'
|
|
1395
|
+
+ '<div class="small">The parked document resumes its pipeline from this stage.</div>'
|
|
1396
|
+
+ taskTiming(payload);
|
|
1397
|
+
`;
|
|
1398
|
+
var WIDGET_HTML20 = buildWidgetHtml({
|
|
1399
|
+
title: "Talonic \u2014 Agent Task Submitted",
|
|
1400
|
+
renderBody: RENDER_BODY20
|
|
1401
|
+
});
|
|
1402
|
+
|
|
1403
|
+
// src/widgets/spec-list.ts
|
|
1404
|
+
function getSpecListWidgetHtml() {
|
|
1405
|
+
return WIDGET_HTML21;
|
|
1406
|
+
}
|
|
1407
|
+
var RENDER_BODY21 = `
|
|
1408
|
+
if (!payload || typeof payload !== "object") { empty("No Specs in this workspace."); return; }
|
|
1409
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1410
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1411
|
+
if (!rows.length) { empty("No Specs in this workspace."); return; }
|
|
1412
|
+
function versionChip(s) {
|
|
1413
|
+
if (s.version == null) return chip("unpublished", "bad");
|
|
1414
|
+
if (s.materialized_version != null && s.materialized_version === s.version) return chip("v" + s.version + " live", "good");
|
|
1415
|
+
return chip("v" + s.version + " not live", "warn");
|
|
1416
|
+
}
|
|
1417
|
+
var body = rows.map(function (s) {
|
|
1418
|
+
s = s && typeof s === "object" ? s : {};
|
|
1419
|
+
return '<tr>'
|
|
1420
|
+
+ '<td><div class="val">' + esc(s.name || s.id || "(spec)") + '</div>' + (s.description ? '<div class="muted small">' + esc(clamp(s.description, 100)) + '</div>' : "") + '</td>'
|
|
1421
|
+
+ '<td>' + versionChip(s) + '</td>'
|
|
1422
|
+
+ '<td class="val num">' + esc(s.field_count != null ? s.field_count : "\u2014") + '</td>'
|
|
1423
|
+
+ '<td class="val num">' + esc(s.node_count != null ? s.node_count : "\u2014") + '</td>'
|
|
1424
|
+
+ '<td class="val">' + esc(s.updated_at ? relTime(s.updated_at) : "\u2014") + '</td>'
|
|
1425
|
+
+ '</tr>';
|
|
1426
|
+
}).join("");
|
|
1427
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1428
|
+
root.innerHTML = ''
|
|
1429
|
+
+ '<div class="header"><div><div class="title">Specs</div><div class="subtitle">' + rows.length + ' of ' + total + ' Specs</div></div>'
|
|
1430
|
+
+ (pg.has_more ? '<span class="chip">more available</span>' : "") + '</div>'
|
|
1431
|
+
+ '<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>';
|
|
1432
|
+
`;
|
|
1433
|
+
var WIDGET_HTML21 = buildWidgetHtml({ title: "Talonic \u2014 Specs", renderBody: RENDER_BODY21 });
|
|
1434
|
+
|
|
1435
|
+
// src/widgets/spec-card.ts
|
|
1436
|
+
function getSpecCardWidgetHtml() {
|
|
1437
|
+
return WIDGET_HTML22;
|
|
1438
|
+
}
|
|
1439
|
+
var CSS = `
|
|
1440
|
+
.rail { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 6px; }
|
|
1441
|
+
.rail .arrow { color: var(--muted); font-size: 12px; }
|
|
1442
|
+
`;
|
|
1443
|
+
var RENDER_BODY22 = `
|
|
1444
|
+
if (!payload || typeof payload !== "object" || (!payload.id && !payload.name)) { empty("No Spec."); return; }
|
|
1445
|
+
var nodes = Array.isArray(payload.nodes) ? payload.nodes : [];
|
|
1446
|
+
var phases = Array.isArray(payload.phases) ? payload.phases : [];
|
|
1447
|
+
var fields = Array.isArray(payload.fields) ? payload.fields : [];
|
|
1448
|
+
var versions = Array.isArray(payload.versions) ? payload.versions : [];
|
|
1449
|
+
var schema = payload.schema && typeof payload.schema === "object" ? payload.schema : null;
|
|
1450
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1451
|
+
var versionChip = payload.version == null ? chip("unpublished", "bad")
|
|
1452
|
+
: (payload.materialized_version != null && payload.materialized_version === payload.version ? chip("v" + payload.version + " live", "good") : chip("v" + payload.version + " not live", "warn"));
|
|
1453
|
+
var fieldCount = typeof payload.field_count === "number" ? payload.field_count : fields.length;
|
|
1454
|
+
var railHtml = nodes.length ? '<div class="plane"><div class="subtitle">Rail (' + nodes.length + ' stages)</div><div class="rail">'
|
|
1455
|
+
+ 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("")
|
|
1456
|
+
+ '</div></div>' : "";
|
|
1457
|
+
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>'
|
|
1458
|
+
+ 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("")
|
|
1459
|
+
+ '</tbody></table></div>' : "";
|
|
1460
|
+
var fieldHtml = fields.length ? '<div class="plane"><div class="subtitle">Fields (' + fields.length + ')</div><div>'
|
|
1461
|
+
+ 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>' : "";
|
|
1462
|
+
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>'
|
|
1463
|
+
+ 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("")
|
|
1464
|
+
+ '</tbody></table></div>' : "";
|
|
1465
|
+
root.innerHTML = ''
|
|
1466
|
+
+ '<div class="header"><div><div class="title">' + esc(payload.name || payload.id) + '</div>'
|
|
1467
|
+
+ (payload.description ? '<div class="subtitle">' + esc(clamp(payload.description, 140)) + '</div>' : "") + '</div>'
|
|
1468
|
+
+ '<div>' + versionChip + chip(fieldCount + " fields", "") + '</div></div>'
|
|
1469
|
+
+ '<div class="grid">'
|
|
1470
|
+
+ '<div class="kv"><span class="k">Spec id</span> <span class="val">' + idChip(payload.id) + '</span></div>'
|
|
1471
|
+
+ '<div class="kv"><span class="k">Schema</span> <span class="val">' + (schema ? esc(schema.name || "") + " " + idChip(schema.id) : idChip(payload.schema_id)) + '</span></div>'
|
|
1472
|
+
+ '<div class="kv"><span class="k">Materialized</span> <span class="val">' + esc(payload.materialized_at ? relTime(payload.materialized_at) : "\u2014") + '</span></div>'
|
|
1473
|
+
+ '<div class="kv"><span class="k">Updated</span> <span class="val">' + esc(payload.updated_at ? relTime(payload.updated_at) : "\u2014") + '</span></div>'
|
|
1474
|
+
+ '</div>'
|
|
1475
|
+
+ railHtml + phaseHtml + fieldHtml + versionHtml;
|
|
1476
|
+
`;
|
|
1477
|
+
var WIDGET_HTML22 = buildWidgetHtml({ title: "Talonic \u2014 Spec", css: CSS, renderBody: RENDER_BODY22 });
|
|
1478
|
+
|
|
1479
|
+
// src/widgets/run-started.ts
|
|
1480
|
+
function getRunStartedWidgetHtml() {
|
|
1481
|
+
return WIDGET_HTML23;
|
|
1482
|
+
}
|
|
1483
|
+
var RENDER_BODY23 = `
|
|
1484
|
+
if (!payload || typeof payload !== "object" || (!payload.pipeline_id && !payload.run_id)) { empty("No run was started."); return; }
|
|
1485
|
+
function kb(n) { return typeof n === "number" ? (n >= 1048576 ? (n / 1048576).toFixed(1) + " MB" : Math.max(1, Math.round(n / 1024)) + " KB") : "\u2014"; }
|
|
1486
|
+
var kind = payload.run_kind === "run" ? "run" : "pipeline";
|
|
1487
|
+
var docs = Array.isArray(payload.documents) ? payload.documents : [];
|
|
1488
|
+
var pollArg = kind === "pipeline" && payload.pipeline_id ? "pipeline_id " + shortId(payload.pipeline_id) : "run_id " + shortId(payload.run_id);
|
|
1489
|
+
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>'
|
|
1490
|
+
+ 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("")
|
|
1491
|
+
+ '</tbody></table>' + (docs.length > 20 ? '<div class="muted small">+' + (docs.length - 20) + ' more</div>' : "") + '</div>' : "";
|
|
1492
|
+
root.innerHTML = ''
|
|
1493
|
+
+ '<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>'
|
|
1494
|
+
+ '<div>' + chip(kind, "info") + chip(payload.status, payload.status === "failed" ? "bad" : payload.status === "completed" ? "good" : "") + '</div></div>'
|
|
1495
|
+
+ '<div class="big">' + esc(typeof payload.input_count === "number" ? payload.input_count : docs.length || "\u2014") + ' <span class="muted small">documents</span></div>'
|
|
1496
|
+
+ '<div class="grid">'
|
|
1497
|
+
+ '<div class="kv"><span class="k">Spec</span> <span class="val">' + idChip(payload.spec_id) + '</span></div>'
|
|
1498
|
+
+ '<div class="kv"><span class="k">Pipeline</span> <span class="val">' + idChip(payload.pipeline_id) + '</span></div>'
|
|
1499
|
+
+ '<div class="kv"><span class="k">Run</span> <span class="val">' + idChip(payload.run_id) + '</span></div>'
|
|
1500
|
+
+ '<div class="kv"><span class="k">Enqueued</span> <span class="val">' + esc(payload.enqueued_documents != null ? payload.enqueued_documents : "\u2014") + '</span></div>'
|
|
1501
|
+
+ '</div>'
|
|
1502
|
+
+ (payload.message ? '<div class="muted small" style="margin-top:8px">' + esc(payload.message) + '</div>' : "")
|
|
1503
|
+
+ '<div class="small" style="margin-top:8px">Poll with talonic_get_run (' + esc(pollArg) + ') every 5\u201310 s, then talonic_get_run_results.</div>'
|
|
1504
|
+
+ docHtml;
|
|
1505
|
+
`;
|
|
1506
|
+
var WIDGET_HTML23 = buildWidgetHtml({ title: "Talonic \u2014 Run Started", renderBody: RENDER_BODY23 });
|
|
1507
|
+
|
|
1508
|
+
// src/widgets/run-status.ts
|
|
1509
|
+
function getRunStatusWidgetHtml() {
|
|
1510
|
+
return WIDGET_HTML24;
|
|
1511
|
+
}
|
|
1512
|
+
var CSS2 = `
|
|
1513
|
+
.progress { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
|
|
1514
|
+
.progress .bar { width: 160px; height: 8px; }
|
|
1515
|
+
`;
|
|
1516
|
+
var RENDER_BODY24 = `
|
|
1517
|
+
if (!payload || typeof payload !== "object" || (!payload.pipeline_id && !payload.run_id)) { empty("No run to show."); return; }
|
|
1518
|
+
function tone(s) { return s === "completed" ? "good" : s === "failed" ? "bad" : "info"; }
|
|
1519
|
+
var status = typeof payload.status === "string" ? payload.status : "processing";
|
|
1520
|
+
var pr = payload.progress && typeof payload.progress === "object" ? payload.progress : {};
|
|
1521
|
+
var total = typeof pr.total_documents === "number" ? pr.total_documents : null;
|
|
1522
|
+
var done = typeof pr.completed_documents === "number" ? pr.completed_documents : null;
|
|
1523
|
+
var errs = typeof pr.error_documents === "number" ? pr.error_documents : null;
|
|
1524
|
+
var pct = total == null ? 0 : (total > 0 ? Math.max(0, Math.min(100, Math.round(((done || 0) / total) * 100))) : (status === "completed" ? 100 : 0));
|
|
1525
|
+
var totalText = total == null ? "\u2014" : String(total);
|
|
1526
|
+
var doneText = done == null ? "\u2014" : String(done);
|
|
1527
|
+
var phases = Array.isArray(pr.phases) ? pr.phases : [];
|
|
1528
|
+
var docs = Array.isArray(payload.documents) ? payload.documents : [];
|
|
1529
|
+
var pending = Array.isArray(pr.finalization_pending) ? pr.finalization_pending : [];
|
|
1530
|
+
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>'
|
|
1531
|
+
+ 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("")
|
|
1532
|
+
+ '</tbody></table></div>' : "";
|
|
1533
|
+
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>'
|
|
1534
|
+
+ 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("")
|
|
1535
|
+
+ '</tbody></table></div>' : "";
|
|
1536
|
+
root.innerHTML = ''
|
|
1537
|
+
+ '<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>'
|
|
1538
|
+
+ '<div>' + chip(status, tone(status)) + '</div></div>'
|
|
1539
|
+
+ '<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>'
|
|
1540
|
+
+ (pending.length ? '<div class="muted small" style="margin-top:6px">Finalizing: ' + esc(pending.join(", ")) + '</div>' : "")
|
|
1541
|
+
+ (payload.error_message ? '<div class="small" style="margin-top:8px;color:var(--bad)">' + esc(payload.error_message) + '</div>' : "")
|
|
1542
|
+
+ phaseHtml + docHtml;
|
|
1543
|
+
`;
|
|
1544
|
+
var WIDGET_HTML24 = buildWidgetHtml({
|
|
1545
|
+
title: "Talonic \u2014 Run Progress",
|
|
1546
|
+
css: CSS2,
|
|
1547
|
+
renderBody: RENDER_BODY24
|
|
1548
|
+
});
|
|
1549
|
+
|
|
1550
|
+
// src/widgets/run-results.ts
|
|
1551
|
+
function getRunResultsWidgetHtml() {
|
|
1552
|
+
return WIDGET_HTML25;
|
|
1553
|
+
}
|
|
1554
|
+
var RENDER_BODY25 = `
|
|
1555
|
+
if (!payload || typeof payload !== "object") { empty("No result rows yet."); return; }
|
|
1556
|
+
var cols = Array.isArray(payload.columns) ? payload.columns.filter(function (c) { return c && typeof c === "object"; }) : [];
|
|
1557
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1558
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1559
|
+
if (!rows.length) { empty("No result rows yet."); return; }
|
|
1560
|
+
function tone(s) { return s === "complete" || s === "completed" ? "good" : s === "error" ? "bad" : s === "partial" ? "warn" : "info"; }
|
|
1561
|
+
var shownCols = cols.slice(0, 10);
|
|
1562
|
+
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>';
|
|
1563
|
+
var body = rows.slice(0, 50).map(function (r) {
|
|
1564
|
+
r = r && typeof r === "object" ? r : {};
|
|
1565
|
+
var f = r.fields && typeof r.fields === "object" ? r.fields : {};
|
|
1566
|
+
return '<tr><td class="val">' + esc(r.filename || shortId(r.document_id)) + '</td><td>' + chip(r.status, tone(r.status)) + '</td>'
|
|
1567
|
+
+ 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>';
|
|
1568
|
+
}).join("");
|
|
1569
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1570
|
+
var held = typeof payload.pending_review_count === "number" ? payload.pending_review_count : 0;
|
|
1571
|
+
var more = [];
|
|
1572
|
+
if (rows.length > 50) more.push("+" + (rows.length - 50) + " more rows");
|
|
1573
|
+
if (cols.length > 10) more.push("+" + (cols.length - 10) + " more columns");
|
|
1574
|
+
root.innerHTML = ''
|
|
1575
|
+
+ '<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>'
|
|
1576
|
+
+ '<div>' + chip(payload.status, payload.status === "completed" ? "good" : payload.status === "failed" ? "bad" : "info") + (held ? chip(held + " held for review", "warn") : "") + '</div></div>'
|
|
1577
|
+
+ '<table><thead>' + head + '</thead><tbody>' + body + '</tbody></table>'
|
|
1578
|
+
+ (more.length ? '<div class="muted small" style="margin-top:6px">' + esc(more.join(" \xB7 ")) + '</div>' : "");
|
|
1579
|
+
`;
|
|
1580
|
+
var WIDGET_HTML25 = buildWidgetHtml({ title: "Talonic \u2014 Run Results", renderBody: RENDER_BODY25 });
|
|
1581
|
+
|
|
1582
|
+
// src/widgets/answer.ts
|
|
1583
|
+
function getAnswerWidgetHtml() {
|
|
1584
|
+
return ANSWER_HTML;
|
|
1585
|
+
}
|
|
1586
|
+
function getAnswerPolledWidgetHtml() {
|
|
1587
|
+
return POLLED_HTML;
|
|
1588
|
+
}
|
|
1589
|
+
var CSS3 = `
|
|
1590
|
+
.cite { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--border); }
|
|
1591
|
+
.cite:last-child { border-bottom: none; }
|
|
1592
|
+
pre.md.answer { max-height: 480px; font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, sans-serif; }
|
|
1593
|
+
`;
|
|
1594
|
+
var ANSWER_BODY = `
|
|
1595
|
+
if (!payload || typeof payload !== "object" || !payload.ask_id) { empty("No answer."); return; }
|
|
1596
|
+
var status = typeof payload.status === "string" ? payload.status : "processing";
|
|
1597
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1598
|
+
var ver = obj(payload.verification);
|
|
1599
|
+
var usage = obj(payload.usage);
|
|
1600
|
+
var cites = Array.isArray(payload.citations) ? payload.citations : [];
|
|
1601
|
+
var arts = Array.isArray(payload.artifacts) ? payload.artifacts : [];
|
|
1602
|
+
var verdictTone = ver.verdict === "supported" ? "good" : ver.verdict === "issues" ? "warn" : ver.verdict === "unverifiable" ? "bad" : "";
|
|
1603
|
+
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>'
|
|
1604
|
+
+ '<div>' + (status === "completed" ? chip(ver.verdict, verdictTone) : chip(status, status === "error" ? "bad" : "info")) + '</div></div>';
|
|
1605
|
+
if (status === "processing") {
|
|
1606
|
+
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>';
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
var answer = typeof payload.answer === "string" ? payload.answer : (payload.answer == null ? "" : fmt(payload.answer));
|
|
1610
|
+
var citeHtml = cites.length ? '<div class="plane"><div class="subtitle">Citations (' + cites.length + ')</div>' + cites.slice(0, 20).map(function (c, i) {
|
|
1611
|
+
c = obj(c);
|
|
1612
|
+
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>';
|
|
1613
|
+
}).join("") + '</div>' : "";
|
|
1614
|
+
var artHtml = arts.length ? '<div class="plane"><div class="subtitle">Artifacts (' + arts.length + ')</div>' + arts.slice(0, 10).map(function (a) {
|
|
1615
|
+
a = obj(a);
|
|
1616
|
+
var link = typeof a.link === "string" && /^https:\\/\\//.test(a.link) ? a.link : "";
|
|
1617
|
+
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>';
|
|
1618
|
+
}).join("") + '</div>' : "";
|
|
1619
|
+
var tiles = [];
|
|
1620
|
+
if (typeof usage.credits_charged === "number") tiles.push(usage.credits_charged + " credits");
|
|
1621
|
+
if (typeof usage.tokens === "number") tiles.push(usage.tokens + " tokens");
|
|
1622
|
+
if (typeof payload.tool_calls === "number") tiles.push(payload.tool_calls + " tool call" + (payload.tool_calls === 1 ? "" : "s"));
|
|
1623
|
+
if (typeof payload.waited_ms === "number") tiles.push((payload.waited_ms / 1000).toFixed(1) + " s");
|
|
1624
|
+
if (typeof ver.checks_total === "number") tiles.push(ver.checks_total + " checks, " + (ver.checks_unsupported || 0) + " unsupported");
|
|
1625
|
+
root.innerHTML = head
|
|
1626
|
+
+ (answer ? '<pre class="md answer">' + esc(answer) + '</pre>' : '<div class="muted small">The agent returned no answer text.</div>')
|
|
1627
|
+
+ (ver.correction ? '<div class="small" style="margin-top:6px"><span class="muted">Correction:</span> ' + esc(ver.correction) + '</div>' : "")
|
|
1628
|
+
+ citeHtml + artHtml
|
|
1629
|
+
+ (tiles.length ? '<div class="muted small" style="margin-top:10px">' + esc(tiles.join(" \xB7 ")) + '</div>' : "");
|
|
1630
|
+
`;
|
|
1631
|
+
function answerWidget(headline, title) {
|
|
1632
|
+
return buildWidgetHtml({
|
|
1633
|
+
title,
|
|
1634
|
+
css: CSS3,
|
|
1635
|
+
renderBody: " var HEADLINE = " + JSON.stringify(headline) + ";\n" + ANSWER_BODY
|
|
1636
|
+
});
|
|
1637
|
+
}
|
|
1638
|
+
var ANSWER_HTML = answerWidget("Answer", "Talonic \u2014 Answer");
|
|
1639
|
+
var POLLED_HTML = answerWidget("Answer (polled)", "Talonic \u2014 Answer (polled)");
|
|
1640
|
+
|
|
1641
|
+
// src/widgets/decision-task-shared.ts
|
|
1642
|
+
var DECISION_JS = `
|
|
1643
|
+
function decisionTone(s) {
|
|
1644
|
+
return s === "available" ? "info" : s === "claimed" || s === "submitted" ? "good" : s === "failed" || s === "timed_out" ? "bad" : s === "released" || s === "cancelled" ? "warn" : "";
|
|
1645
|
+
}
|
|
1646
|
+
function decisionMeta(p) {
|
|
1647
|
+
return '<div class="grid">'
|
|
1648
|
+
+ '<div class="kv"><span class="k">Run</span> <span class="val">' + idChip(p.run_id) + '</span></div>'
|
|
1649
|
+
+ '<div class="kv"><span class="k">App</span> <span class="val">' + idChip(p.app_id) + '</span></div>'
|
|
1650
|
+
+ '<div class="kv"><span class="k">Execution epoch</span> <span class="val">' + esc(p.execution_epoch != null ? p.execution_epoch : "\u2014") + '</span></div>'
|
|
1651
|
+
+ '<div class="kv"><span class="k">Claimed by</span> <span class="val">' + esc(p.claimed_by || "\u2014") + '</span></div>'
|
|
1652
|
+
+ '<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>'
|
|
1653
|
+
+ '<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>'
|
|
1654
|
+
+ '</div>';
|
|
1655
|
+
}
|
|
1656
|
+
`;
|
|
1657
|
+
|
|
1658
|
+
// src/widgets/decision-task-list.ts
|
|
1659
|
+
function getDecisionTaskListWidgetHtml() {
|
|
1660
|
+
return WIDGET_HTML26;
|
|
1661
|
+
}
|
|
1662
|
+
var RENDER_BODY26 = DECISION_JS + `
|
|
1663
|
+
if (!payload || typeof payload !== "object") { empty("No decision tasks for this app."); return; }
|
|
1664
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1665
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1666
|
+
if (!rows.length) { empty("No decision tasks for this app."); return; }
|
|
1667
|
+
var body = rows.map(function (t) {
|
|
1668
|
+
t = t && typeof t === "object" ? t : {};
|
|
1669
|
+
return '<tr><td>' + idChip(t.id) + '</td><td>' + chip(t.status, decisionTone(t.status)) + '</td><td>' + idChip(t.run_id) + '</td>'
|
|
1670
|
+
+ '<td class="val num">' + esc(t.execution_epoch != null ? t.execution_epoch : "\u2014") + '</td>'
|
|
1671
|
+
+ '<td class="val">' + esc(t.lease_expires_at ? relTime(t.lease_expires_at) : "\u2014") + '</td>'
|
|
1672
|
+
+ '<td class="val">' + esc(t.sla_deadline_at ? relTime(t.sla_deadline_at) : "\u2014") + '</td></tr>';
|
|
1673
|
+
}).join("");
|
|
1674
|
+
var counts = Object.create(null);
|
|
1675
|
+
rows.forEach(function (t) { var s = t && typeof t === "object" && t.status ? t.status : "unknown"; counts[s] = (counts[s] || 0) + 1; });
|
|
1676
|
+
var summary = Object.keys(counts).map(function (s) { return chip(counts[s] + " " + s, decisionTone(s)); }).join("");
|
|
1677
|
+
var app = rows[0] && typeof rows[0] === "object" ? rows[0].app_id : null;
|
|
1678
|
+
root.innerHTML = ''
|
|
1679
|
+
+ '<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>'
|
|
1680
|
+
+ '<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>';
|
|
1681
|
+
`;
|
|
1682
|
+
var WIDGET_HTML26 = buildWidgetHtml({ title: "Talonic \u2014 Decision Tasks", renderBody: RENDER_BODY26 });
|
|
1683
|
+
|
|
1684
|
+
// src/widgets/decision-bundle.ts
|
|
1685
|
+
function getDecisionBundleWidgetHtml() {
|
|
1686
|
+
return WIDGET_HTML27;
|
|
1687
|
+
}
|
|
1688
|
+
var RENDER_BODY27 = DECISION_JS + `
|
|
1689
|
+
var task = payload && payload.task && typeof payload.task === "object" ? payload.task : null;
|
|
1690
|
+
if (!task || !task.id) { empty("No decision task was claimed."); return; }
|
|
1691
|
+
var contract = payload.output_contract;
|
|
1692
|
+
var precedents = Array.isArray(payload.precedents) ? payload.precedents : [];
|
|
1693
|
+
var pkg = payload.package && typeof payload.package === "object" ? payload.package : {};
|
|
1694
|
+
var docs = Array.isArray(pkg.documents) ? pkg.documents : [];
|
|
1695
|
+
var contractHtml = contract && typeof contract === "object" ? (isFlat(contract) ? kvTiles(contract) : jsonTree(contract)) : '<div class="muted small">No output contract on this task.</div>';
|
|
1696
|
+
var precHtml = precedents.length ? '<div class="plane"><div class="subtitle">Precedents (' + precedents.length + ')</div>' + precedents.slice(0, 5).map(function (p) {
|
|
1697
|
+
p = p && typeof p === "object" ? p : {};
|
|
1698
|
+
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>';
|
|
1699
|
+
}).join("") + '</div>' : "";
|
|
1700
|
+
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>' : "";
|
|
1701
|
+
root.innerHTML = ''
|
|
1702
|
+
+ '<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>'
|
|
1703
|
+
+ '<div class="big">' + esc(task.execution_epoch != null ? task.execution_epoch : "\u2014") + ' <span class="muted small">execution epoch</span></div>'
|
|
1704
|
+
+ '<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>'
|
|
1705
|
+
+ decisionMeta(task)
|
|
1706
|
+
+ '<div class="plane"><div class="subtitle">Output contract</div>' + contractHtml + '</div>'
|
|
1707
|
+
+ '<div class="plane"><div class="subtitle">Input package</div><div class="grid">'
|
|
1708
|
+
+ '<div class="kv"><span class="k">Kind</span> <span class="val">' + esc(pkg.package_kind || "\u2014") + '</span></div>'
|
|
1709
|
+
+ '<div class="kv"><span class="k">Records</span> <span class="val">' + esc(pkg.record_count != null ? pkg.record_count : "\u2014") + '</span></div>'
|
|
1710
|
+
+ '<div class="kv"><span class="k">Page size</span> <span class="val">' + esc(pkg.page_size != null ? pkg.page_size : "\u2014") + '</span></div>'
|
|
1711
|
+
+ '<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>'
|
|
1712
|
+
+ '</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>'
|
|
1713
|
+
+ precHtml + docHtml;
|
|
1714
|
+
`;
|
|
1715
|
+
var WIDGET_HTML27 = buildWidgetHtml({
|
|
1716
|
+
title: "Talonic \u2014 Decision Task Claimed",
|
|
1717
|
+
renderBody: RENDER_BODY27
|
|
1718
|
+
});
|
|
1719
|
+
|
|
1720
|
+
// src/widgets/decision-package.ts
|
|
1721
|
+
function getDecisionPackageWidgetHtml() {
|
|
1722
|
+
return WIDGET_HTML28;
|
|
1723
|
+
}
|
|
1724
|
+
var RENDER_BODY28 = `
|
|
1725
|
+
if (!payload || typeof payload !== "object" || !payload.task_id) { empty("No package page."); return; }
|
|
1726
|
+
var records = Array.isArray(payload.data) ? payload.data : [];
|
|
1727
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1728
|
+
var docs = Array.isArray(payload.documents) ? payload.documents : [];
|
|
1729
|
+
var body = !records.length ? '<div class="empty">This page has no records.</div>' : (isRowArray(records) ? dataTable(records) : jsonTree(records));
|
|
1730
|
+
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>' : "";
|
|
1731
|
+
root.innerHTML = ''
|
|
1732
|
+
+ '<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>'
|
|
1733
|
+
+ '<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>'
|
|
1734
|
+
+ body
|
|
1735
|
+
+ (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>' : "")
|
|
1736
|
+
+ '<div class="small" style="margin-top:8px">Copy evidence locators verbatim from these records into talonic_submit_decision_task.</div>'
|
|
1737
|
+
+ docHtml;
|
|
1738
|
+
`;
|
|
1739
|
+
var WIDGET_HTML28 = buildWidgetHtml({
|
|
1740
|
+
title: "Talonic \u2014 Decision Package",
|
|
1741
|
+
renderBody: RENDER_BODY28
|
|
1742
|
+
});
|
|
1743
|
+
|
|
1744
|
+
// src/widgets/decision-task-card.ts
|
|
1745
|
+
function getDecisionHeartbeatWidgetHtml() {
|
|
1746
|
+
return HEARTBEAT_HTML2;
|
|
1747
|
+
}
|
|
1748
|
+
function getDecisionSubmittedWidgetHtml() {
|
|
1749
|
+
return SUBMITTED_HTML;
|
|
1750
|
+
}
|
|
1751
|
+
function getDecisionReleasedWidgetHtml() {
|
|
1752
|
+
return RELEASED_HTML;
|
|
1753
|
+
}
|
|
1754
|
+
function getDecisionFailedWidgetHtml() {
|
|
1755
|
+
return FAILED_HTML;
|
|
1756
|
+
}
|
|
1757
|
+
var CARD_BODY = `
|
|
1758
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No decision task."); return; }
|
|
1759
|
+
root.innerHTML = ''
|
|
1760
|
+
+ '<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>'
|
|
1761
|
+
+ '<div>' + chip(payload.status, decisionTone(payload.status)) + '</div></div>'
|
|
1762
|
+
+ '<div class="small">' + NOTE + '</div>'
|
|
1763
|
+
+ decisionMeta(payload);
|
|
1764
|
+
`;
|
|
1765
|
+
function card(headline, note, title) {
|
|
1766
|
+
return buildWidgetHtml({
|
|
1767
|
+
title,
|
|
1768
|
+
renderBody: DECISION_JS + " var HEADLINE = " + JSON.stringify(headline) + ";\n var NOTE = " + JSON.stringify(note) + ";\n" + CARD_BODY
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
var HEARTBEAT_HTML2 = card(
|
|
1772
|
+
"Lease extended",
|
|
1773
|
+
"Keep heartbeating before the lease expires; the SLA deadline is the hard stop.",
|
|
1774
|
+
"Talonic \u2014 Decision Task Lease"
|
|
1775
|
+
);
|
|
1776
|
+
var SUBMITTED_HTML = card(
|
|
1777
|
+
"Decision submitted",
|
|
1778
|
+
"The platform verified the decision and resumes the run.",
|
|
1779
|
+
"Talonic \u2014 Decision Submitted"
|
|
1780
|
+
);
|
|
1781
|
+
var RELEASED_HTML = card(
|
|
1782
|
+
"Task released",
|
|
1783
|
+
"The task is available again for another claimant; the next claim bumps the epoch.",
|
|
1784
|
+
"Talonic \u2014 Decision Task Released"
|
|
1785
|
+
);
|
|
1786
|
+
var FAILED_HTML = card(
|
|
1787
|
+
"Task failed",
|
|
1788
|
+
"A Human Review was raised with your reason and the app's fallback policy applies.",
|
|
1789
|
+
"Talonic \u2014 Decision Task Failed"
|
|
1790
|
+
);
|
|
1791
|
+
|
|
689
1792
|
// src/widgets/register.ts
|
|
690
|
-
|
|
691
|
-
|
|
1793
|
+
var WIDGET_REGISTRY = {
|
|
1794
|
+
extract: {
|
|
692
1795
|
name: "extraction-result-widget",
|
|
693
|
-
uri: WIDGET_URIS.extract,
|
|
694
1796
|
title: "Talonic Extraction Result",
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
function registerWidgets(server) {
|
|
700
|
-
registerExtractionResultWidget(server);
|
|
701
|
-
registerWidget(server, {
|
|
1797
|
+
html: getExtractionResultWidgetHtml
|
|
1798
|
+
},
|
|
1799
|
+
search: {
|
|
702
1800
|
name: "search-results-widget",
|
|
703
|
-
uri: WIDGET_URIS.search,
|
|
704
1801
|
title: "Talonic Search Results",
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
registerWidget(server, {
|
|
1802
|
+
html: getSearchResultsWidgetHtml
|
|
1803
|
+
},
|
|
1804
|
+
filter: {
|
|
709
1805
|
name: "filter-results-widget",
|
|
710
|
-
uri: WIDGET_URIS.filter,
|
|
711
1806
|
title: "Talonic Filter Results",
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
registerWidget(server, {
|
|
1807
|
+
html: getFilterResultsWidgetHtml
|
|
1808
|
+
},
|
|
1809
|
+
getDocument: {
|
|
716
1810
|
name: "document-meta-widget",
|
|
717
|
-
uri: WIDGET_URIS.getDocument,
|
|
718
1811
|
title: "Talonic Document",
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
registerWidget(server, {
|
|
1812
|
+
html: getDocumentMetaWidgetHtml
|
|
1813
|
+
},
|
|
1814
|
+
toMarkdown: {
|
|
723
1815
|
name: "markdown-view-widget",
|
|
724
|
-
uri: WIDGET_URIS.toMarkdown,
|
|
725
1816
|
title: "Talonic Markdown",
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
registerWidget(server, {
|
|
1817
|
+
html: getMarkdownViewWidgetHtml
|
|
1818
|
+
},
|
|
1819
|
+
listSchemas: {
|
|
730
1820
|
name: "schema-list-widget",
|
|
731
|
-
uri: WIDGET_URIS.listSchemas,
|
|
732
1821
|
title: "Talonic Schemas",
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
registerWidget(server, {
|
|
1822
|
+
html: getSchemaListWidgetHtml
|
|
1823
|
+
},
|
|
1824
|
+
saveSchema: {
|
|
737
1825
|
name: "schema-saved-widget",
|
|
738
|
-
uri: WIDGET_URIS.saveSchema,
|
|
739
1826
|
title: "Talonic Schema Saved",
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
html:
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
name: "
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
1827
|
+
html: getSchemaSavedWidgetHtml
|
|
1828
|
+
},
|
|
1829
|
+
getBalance: { name: "balance-widget", title: "Talonic Balance", html: getBalanceWidgetHtml },
|
|
1830
|
+
getPricing: { name: "pricing-widget", title: "Talonic Pricing", html: getPricingWidgetHtml },
|
|
1831
|
+
getUsage: { name: "usage-widget", title: "Talonic Usage", html: getUsageWidgetHtml },
|
|
1832
|
+
requestUpload: {
|
|
1833
|
+
name: "upload-link-widget",
|
|
1834
|
+
title: "Talonic Upload Link",
|
|
1835
|
+
html: getUploadLinkWidgetHtml
|
|
1836
|
+
},
|
|
1837
|
+
listFields: {
|
|
1838
|
+
name: "field-list-widget",
|
|
1839
|
+
title: "Talonic Field Registry",
|
|
1840
|
+
html: getFieldListWidgetHtml
|
|
1841
|
+
},
|
|
1842
|
+
getField: {
|
|
1843
|
+
name: "field-card-widget",
|
|
1844
|
+
title: "Talonic Field Card",
|
|
1845
|
+
html: getFieldCardWidgetHtml
|
|
1846
|
+
},
|
|
1847
|
+
fieldValues: {
|
|
1848
|
+
name: "field-values-widget",
|
|
1849
|
+
title: "Talonic Field Values",
|
|
1850
|
+
html: getFieldValuesWidgetHtml
|
|
1851
|
+
},
|
|
1852
|
+
findData: { name: "find-data-widget", title: "Talonic Find Data", html: getFindDataWidgetHtml },
|
|
1853
|
+
listAgentTools: {
|
|
1854
|
+
name: "agent-tools-widget",
|
|
1855
|
+
title: "Talonic Agent Tools",
|
|
1856
|
+
html: getAgentToolsWidgetHtml
|
|
1857
|
+
},
|
|
1858
|
+
invokeAgentTool: {
|
|
1859
|
+
name: "agent-tool-result-widget",
|
|
1860
|
+
title: "Talonic Agent Tool Result",
|
|
1861
|
+
html: getAgentToolResultWidgetHtml
|
|
1862
|
+
},
|
|
1863
|
+
listAgentTasks: {
|
|
1864
|
+
name: "agent-task-list-widget",
|
|
1865
|
+
title: "Talonic Agent Tasks",
|
|
1866
|
+
html: getAgentTaskListWidgetHtml
|
|
1867
|
+
},
|
|
1868
|
+
getAgentTask: {
|
|
1869
|
+
name: "agent-task-widget",
|
|
1870
|
+
title: "Talonic Agent Task",
|
|
1871
|
+
html: getAgentTaskWidgetHtml
|
|
1872
|
+
},
|
|
1873
|
+
claimAgentTask: {
|
|
1874
|
+
name: "agent-task-claim-widget",
|
|
1875
|
+
title: "Talonic Agent Task Claimed",
|
|
1876
|
+
html: getAgentTaskClaimWidgetHtml
|
|
1877
|
+
},
|
|
1878
|
+
heartbeatAgentTask: {
|
|
1879
|
+
name: "agent-task-heartbeat-widget",
|
|
1880
|
+
title: "Talonic Agent Task Lease",
|
|
1881
|
+
html: getAgentTaskHeartbeatWidgetHtml
|
|
1882
|
+
},
|
|
1883
|
+
submitAgentTask: {
|
|
1884
|
+
name: "agent-task-submitted-widget",
|
|
1885
|
+
title: "Talonic Agent Task Submitted",
|
|
1886
|
+
html: getAgentTaskSubmittedWidgetHtml
|
|
1887
|
+
},
|
|
1888
|
+
listSpecs: { name: "spec-list-widget", title: "Talonic Specs", html: getSpecListWidgetHtml },
|
|
1889
|
+
getSpec: { name: "spec-card-widget", title: "Talonic Spec", html: getSpecCardWidgetHtml },
|
|
1890
|
+
runSpec: {
|
|
1891
|
+
name: "run-started-widget",
|
|
1892
|
+
title: "Talonic Run Started",
|
|
1893
|
+
html: getRunStartedWidgetHtml
|
|
1894
|
+
},
|
|
1895
|
+
getRun: {
|
|
1896
|
+
name: "run-status-widget",
|
|
1897
|
+
title: "Talonic Run Progress",
|
|
1898
|
+
html: getRunStatusWidgetHtml
|
|
1899
|
+
},
|
|
1900
|
+
getRunResults: {
|
|
1901
|
+
name: "run-results-widget",
|
|
1902
|
+
title: "Talonic Run Results",
|
|
1903
|
+
html: getRunResultsWidgetHtml
|
|
1904
|
+
},
|
|
1905
|
+
ask: { name: "answer-widget", title: "Talonic Answer", html: getAnswerWidgetHtml },
|
|
1906
|
+
getAnswer: {
|
|
1907
|
+
name: "answer-polled-widget",
|
|
1908
|
+
title: "Talonic Answer (polled)",
|
|
1909
|
+
html: getAnswerPolledWidgetHtml
|
|
1910
|
+
},
|
|
1911
|
+
listDecisionTasks: {
|
|
1912
|
+
name: "decision-task-list-widget",
|
|
1913
|
+
title: "Talonic Decision Tasks",
|
|
1914
|
+
html: getDecisionTaskListWidgetHtml
|
|
1915
|
+
},
|
|
1916
|
+
claimDecisionTask: {
|
|
1917
|
+
name: "decision-bundle-widget",
|
|
1918
|
+
title: "Talonic Decision Task Claimed",
|
|
1919
|
+
html: getDecisionBundleWidgetHtml
|
|
1920
|
+
},
|
|
1921
|
+
readDecisionPackage: {
|
|
1922
|
+
name: "decision-package-widget",
|
|
1923
|
+
title: "Talonic Decision Package",
|
|
1924
|
+
html: getDecisionPackageWidgetHtml
|
|
1925
|
+
},
|
|
1926
|
+
heartbeatDecisionTask: {
|
|
1927
|
+
name: "decision-task-heartbeat-widget",
|
|
1928
|
+
title: "Talonic Decision Task Lease",
|
|
1929
|
+
html: getDecisionHeartbeatWidgetHtml
|
|
1930
|
+
},
|
|
1931
|
+
submitDecisionTask: {
|
|
1932
|
+
name: "decision-task-submitted-widget",
|
|
1933
|
+
title: "Talonic Decision Submitted",
|
|
1934
|
+
html: getDecisionSubmittedWidgetHtml
|
|
1935
|
+
},
|
|
1936
|
+
releaseDecisionTask: {
|
|
1937
|
+
name: "decision-task-released-widget",
|
|
1938
|
+
title: "Talonic Decision Task Released",
|
|
1939
|
+
html: getDecisionReleasedWidgetHtml
|
|
1940
|
+
},
|
|
1941
|
+
failDecisionTask: {
|
|
1942
|
+
name: "decision-task-failed-widget",
|
|
1943
|
+
title: "Talonic Decision Task Failed",
|
|
1944
|
+
html: getDecisionFailedWidgetHtml
|
|
1945
|
+
}
|
|
1946
|
+
};
|
|
1947
|
+
function registerOne(server, key) {
|
|
1948
|
+
const entry = WIDGET_REGISTRY[key];
|
|
764
1949
|
registerWidget(server, {
|
|
765
|
-
name:
|
|
766
|
-
uri: WIDGET_URIS
|
|
767
|
-
title:
|
|
768
|
-
description:
|
|
769
|
-
html:
|
|
1950
|
+
name: entry.name,
|
|
1951
|
+
uri: WIDGET_URIS[key],
|
|
1952
|
+
title: entry.title,
|
|
1953
|
+
description: WIDGET_DESCRIPTIONS[key],
|
|
1954
|
+
html: entry.html()
|
|
770
1955
|
});
|
|
771
1956
|
}
|
|
772
|
-
function
|
|
773
|
-
const
|
|
774
|
-
content: [
|
|
775
|
-
{
|
|
776
|
-
type: "text",
|
|
777
|
-
text: JSON.stringify(value, null, 2)
|
|
778
|
-
}
|
|
779
|
-
]
|
|
780
|
-
};
|
|
781
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
782
|
-
result["structuredContent"] = value;
|
|
783
|
-
}
|
|
784
|
-
return result;
|
|
785
|
-
}
|
|
786
|
-
function validationError(message) {
|
|
787
|
-
return {
|
|
788
|
-
isError: true,
|
|
789
|
-
content: [{ type: "text", text: `Validation error: ${message}` }]
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
function toolError(err) {
|
|
793
|
-
if (err instanceof TalonicError) {
|
|
794
|
-
const lines = [
|
|
795
|
-
`Talonic API error: ${err.message}`,
|
|
796
|
-
`code: ${err.code}`,
|
|
797
|
-
`status: ${err.status}`
|
|
798
|
-
];
|
|
799
|
-
if (err.requestId) lines.push(`request_id: ${err.requestId}`);
|
|
800
|
-
return {
|
|
801
|
-
isError: true,
|
|
802
|
-
content: [{ type: "text", text: lines.join("\n") }]
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
return {
|
|
806
|
-
isError: true,
|
|
807
|
-
content: [
|
|
808
|
-
{
|
|
809
|
-
type: "text",
|
|
810
|
-
text: `Unexpected error: ${err instanceof Error ? err.message : String(err)}`
|
|
811
|
-
}
|
|
812
|
-
]
|
|
813
|
-
};
|
|
1957
|
+
function registerWidgets(server) {
|
|
1958
|
+
for (const key of Object.keys(WIDGET_REGISTRY)) registerOne(server, key);
|
|
814
1959
|
}
|
|
815
|
-
|
|
816
|
-
// src/tools/extract.ts
|
|
817
1960
|
var DESCRIPTION = [
|
|
818
1961
|
"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.",
|
|
819
1962
|
"",
|
|
@@ -988,10 +2131,7 @@ function registerExtract(server, getTalonic) {
|
|
|
988
2131
|
destructiveHint: false,
|
|
989
2132
|
openWorldHint: true
|
|
990
2133
|
},
|
|
991
|
-
_meta:
|
|
992
|
-
ui: { resourceUri: EXTRACTION_RESULT_WIDGET_URI },
|
|
993
|
-
"openai/outputTemplate": EXTRACTION_RESULT_WIDGET_URI
|
|
994
|
-
}
|
|
2134
|
+
_meta: widgetToolMeta("extract")
|
|
995
2135
|
},
|
|
996
2136
|
async (args) => handleExtract(getTalonic(), args)
|
|
997
2137
|
);
|
|
@@ -1120,10 +2260,7 @@ function registerFilter(server, getTalonic) {
|
|
|
1120
2260
|
destructiveHint: false,
|
|
1121
2261
|
openWorldHint: false
|
|
1122
2262
|
},
|
|
1123
|
-
_meta:
|
|
1124
|
-
ui: { resourceUri: WIDGET_URIS.filter },
|
|
1125
|
-
"openai/outputTemplate": WIDGET_URIS.filter
|
|
1126
|
-
}
|
|
2263
|
+
_meta: widgetToolMeta("filter")
|
|
1127
2264
|
},
|
|
1128
2265
|
async (args) => handleFilter(getTalonic(), args)
|
|
1129
2266
|
);
|
|
@@ -1169,10 +2306,7 @@ function registerGetBalance(server, getTalonic) {
|
|
|
1169
2306
|
destructiveHint: false,
|
|
1170
2307
|
openWorldHint: false
|
|
1171
2308
|
},
|
|
1172
|
-
_meta:
|
|
1173
|
-
ui: { resourceUri: WIDGET_URIS.getBalance },
|
|
1174
|
-
"openai/outputTemplate": WIDGET_URIS.getBalance
|
|
1175
|
-
}
|
|
2309
|
+
_meta: widgetToolMeta("getBalance")
|
|
1176
2310
|
},
|
|
1177
2311
|
async () => handleGetBalance(getTalonic())
|
|
1178
2312
|
);
|
|
@@ -1224,10 +2358,7 @@ function registerGetPricing(server, getTalonic) {
|
|
|
1224
2358
|
destructiveHint: false,
|
|
1225
2359
|
openWorldHint: false
|
|
1226
2360
|
},
|
|
1227
|
-
_meta:
|
|
1228
|
-
ui: { resourceUri: WIDGET_URIS.getPricing },
|
|
1229
|
-
"openai/outputTemplate": WIDGET_URIS.getPricing
|
|
1230
|
-
}
|
|
2361
|
+
_meta: widgetToolMeta("getPricing")
|
|
1231
2362
|
},
|
|
1232
2363
|
async () => handleGetPricing(getTalonic())
|
|
1233
2364
|
);
|
|
@@ -1276,10 +2407,7 @@ function registerGetUsage(server, getTalonic) {
|
|
|
1276
2407
|
destructiveHint: false,
|
|
1277
2408
|
openWorldHint: false
|
|
1278
2409
|
},
|
|
1279
|
-
_meta:
|
|
1280
|
-
ui: { resourceUri: WIDGET_URIS.getUsage },
|
|
1281
|
-
"openai/outputTemplate": WIDGET_URIS.getUsage
|
|
1282
|
-
}
|
|
2410
|
+
_meta: widgetToolMeta("getUsage")
|
|
1283
2411
|
},
|
|
1284
2412
|
async (args) => handleGetUsage(getTalonic(), args.days)
|
|
1285
2413
|
);
|
|
@@ -1370,10 +2498,7 @@ function registerGetDocument(server, getTalonic) {
|
|
|
1370
2498
|
destructiveHint: false,
|
|
1371
2499
|
openWorldHint: false
|
|
1372
2500
|
},
|
|
1373
|
-
_meta:
|
|
1374
|
-
ui: { resourceUri: WIDGET_URIS.getDocument },
|
|
1375
|
-
"openai/outputTemplate": WIDGET_URIS.getDocument
|
|
1376
|
-
}
|
|
2501
|
+
_meta: widgetToolMeta("getDocument")
|
|
1377
2502
|
},
|
|
1378
2503
|
async (args) => handleGetDocument(getTalonic(), args)
|
|
1379
2504
|
);
|
|
@@ -1443,10 +2568,7 @@ function registerListSchemas(server, getTalonic) {
|
|
|
1443
2568
|
destructiveHint: false,
|
|
1444
2569
|
openWorldHint: false
|
|
1445
2570
|
},
|
|
1446
|
-
_meta:
|
|
1447
|
-
ui: { resourceUri: WIDGET_URIS.listSchemas },
|
|
1448
|
-
"openai/outputTemplate": WIDGET_URIS.listSchemas
|
|
1449
|
-
}
|
|
2571
|
+
_meta: widgetToolMeta("listSchemas")
|
|
1450
2572
|
},
|
|
1451
2573
|
async () => handleListSchemas(getTalonic())
|
|
1452
2574
|
);
|
|
@@ -1510,10 +2632,7 @@ function registerSaveSchema(server, getTalonic) {
|
|
|
1510
2632
|
destructiveHint: false,
|
|
1511
2633
|
openWorldHint: false
|
|
1512
2634
|
},
|
|
1513
|
-
_meta:
|
|
1514
|
-
ui: { resourceUri: WIDGET_URIS.saveSchema },
|
|
1515
|
-
"openai/outputTemplate": WIDGET_URIS.saveSchema
|
|
1516
|
-
}
|
|
2635
|
+
_meta: widgetToolMeta("saveSchema")
|
|
1517
2636
|
},
|
|
1518
2637
|
async (args) => handleSaveSchema(getTalonic(), args)
|
|
1519
2638
|
);
|
|
@@ -1611,10 +2730,7 @@ function registerSearch(server, getTalonic) {
|
|
|
1611
2730
|
destructiveHint: false,
|
|
1612
2731
|
openWorldHint: false
|
|
1613
2732
|
},
|
|
1614
|
-
_meta:
|
|
1615
|
-
ui: { resourceUri: WIDGET_URIS.search },
|
|
1616
|
-
"openai/outputTemplate": WIDGET_URIS.search
|
|
1617
|
-
}
|
|
2733
|
+
_meta: widgetToolMeta("search")
|
|
1618
2734
|
},
|
|
1619
2735
|
async (args) => handleSearch(getTalonic(), args)
|
|
1620
2736
|
);
|
|
@@ -1643,7 +2759,7 @@ async function handleRequestUpload(getToken, baseUrl, args) {
|
|
|
1643
2759
|
try {
|
|
1644
2760
|
const base = baseUrl ?? "https://api.talonic.com";
|
|
1645
2761
|
const token = getToken();
|
|
1646
|
-
const res = await
|
|
2762
|
+
const res = await resolveFetch(getToken)(`${base}/v1/documents/upload-session`, {
|
|
1647
2763
|
method: "POST",
|
|
1648
2764
|
headers: {
|
|
1649
2765
|
Authorization: `Bearer ${token}`,
|
|
@@ -1682,22 +2798,19 @@ function registerRequestUpload(server, getToken, baseUrl) {
|
|
|
1682
2798
|
destructiveHint: false,
|
|
1683
2799
|
openWorldHint: false
|
|
1684
2800
|
},
|
|
1685
|
-
_meta:
|
|
1686
|
-
ui: { resourceUri: WIDGET_URIS.requestUpload },
|
|
1687
|
-
"openai/outputTemplate": WIDGET_URIS.requestUpload
|
|
1688
|
-
}
|
|
2801
|
+
_meta: widgetToolMeta("requestUpload")
|
|
1689
2802
|
},
|
|
1690
2803
|
async (args) => handleRequestUpload(getToken, baseUrl, args)
|
|
1691
2804
|
);
|
|
1692
2805
|
}
|
|
1693
|
-
var
|
|
2806
|
+
var DEFAULT_BASE2 = "https://api.talonic.com";
|
|
1694
2807
|
var RANGES = ["7d", "30d", "90d"];
|
|
1695
2808
|
async function growthGet(getToken, baseUrl, path, params) {
|
|
1696
2809
|
try {
|
|
1697
2810
|
const qs = new URLSearchParams();
|
|
1698
2811
|
for (const [k, v] of Object.entries(params)) if (v !== void 0 && v !== "") qs.set(k, v);
|
|
1699
|
-
const url = `${baseUrl ??
|
|
1700
|
-
const res = await
|
|
2812
|
+
const url = `${baseUrl ?? DEFAULT_BASE2}/v1/growth/${path}${qs.size ? `?${qs}` : ""}`;
|
|
2813
|
+
const res = await resolveFetch(getToken)(url, {
|
|
1701
2814
|
headers: { Authorization: `Bearer ${getToken()}`, Accept: "application/json" }
|
|
1702
2815
|
});
|
|
1703
2816
|
if (res.status === 403) {
|
|
@@ -1832,7 +2945,7 @@ function registerGrowthTools(server, getToken, baseUrl) {
|
|
|
1832
2945
|
async (args) => handleGrowthToolsUsage(getToken, baseUrl, args)
|
|
1833
2946
|
);
|
|
1834
2947
|
}
|
|
1835
|
-
var
|
|
2948
|
+
var DEFAULT_BASE3 = "https://api.talonic.com";
|
|
1836
2949
|
var TASK_STATUSES = ["available", "claimed", "submitted", "timed_out", "cancelled"];
|
|
1837
2950
|
var taskId = z.string().uuid().describe("Agent task UUID.");
|
|
1838
2951
|
var executionEpoch = z.number().int().min(1).max(2147483647).describe("Execution epoch returned by the successful claim. Stale epochs are rejected.");
|
|
@@ -1863,7 +2976,7 @@ var adminPayloadAccessInput = {
|
|
|
1863
2976
|
totp_code: adminTotp
|
|
1864
2977
|
};
|
|
1865
2978
|
function apiUrl(baseUrl, path, query) {
|
|
1866
|
-
const base = (baseUrl ??
|
|
2979
|
+
const base = (baseUrl ?? DEFAULT_BASE3).replace(/\/$/, "");
|
|
1867
2980
|
const url = new URL(`${base}${path}`);
|
|
1868
2981
|
for (const [key, value] of Object.entries(query ?? {})) {
|
|
1869
2982
|
if (value !== void 0 && value !== "") url.searchParams.set(key, String(value));
|
|
@@ -1872,7 +2985,7 @@ function apiUrl(baseUrl, path, query) {
|
|
|
1872
2985
|
}
|
|
1873
2986
|
async function agentTaskRequest(getToken, baseUrl, request) {
|
|
1874
2987
|
try {
|
|
1875
|
-
const response = await
|
|
2988
|
+
const response = await resolveFetch(getToken)(apiUrl(baseUrl, request.path, request.query), {
|
|
1876
2989
|
method: request.method ?? "GET",
|
|
1877
2990
|
headers: {
|
|
1878
2991
|
Authorization: `Bearer ${getToken()}`,
|
|
@@ -2034,7 +3147,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2034
3147
|
title: "List Agent Tasks",
|
|
2035
3148
|
description: DESCRIPTIONS.list,
|
|
2036
3149
|
inputSchema: listInput,
|
|
2037
|
-
annotations: { title: "List Agent Tasks", ...READ_ONLY2 }
|
|
3150
|
+
annotations: { title: "List Agent Tasks", ...READ_ONLY2 },
|
|
3151
|
+
_meta: widgetToolMeta("listAgentTasks")
|
|
2038
3152
|
},
|
|
2039
3153
|
async (args) => handleListAgentTasks(getToken, baseUrl, args)
|
|
2040
3154
|
);
|
|
@@ -2044,7 +3158,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2044
3158
|
title: "Get Agent Task",
|
|
2045
3159
|
description: DESCRIPTIONS.get,
|
|
2046
3160
|
inputSchema: idInput,
|
|
2047
|
-
annotations: { title: "Get Agent Task", ...READ_ONLY2 }
|
|
3161
|
+
annotations: { title: "Get Agent Task", ...READ_ONLY2 },
|
|
3162
|
+
_meta: widgetToolMeta("getAgentTask")
|
|
2048
3163
|
},
|
|
2049
3164
|
async (args) => handleGetAgentTask(getToken, baseUrl, args)
|
|
2050
3165
|
);
|
|
@@ -2054,7 +3169,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2054
3169
|
title: "Claim Agent Task",
|
|
2055
3170
|
description: DESCRIPTIONS.claim,
|
|
2056
3171
|
inputSchema: idInput,
|
|
2057
|
-
annotations: { title: "Claim Agent Task", ...MUTATING }
|
|
3172
|
+
annotations: { title: "Claim Agent Task", ...MUTATING },
|
|
3173
|
+
_meta: widgetToolMeta("claimAgentTask")
|
|
2058
3174
|
},
|
|
2059
3175
|
async (args) => handleClaimAgentTask(getToken, baseUrl, args)
|
|
2060
3176
|
);
|
|
@@ -2064,7 +3180,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2064
3180
|
title: "Heartbeat Agent Task",
|
|
2065
3181
|
description: DESCRIPTIONS.heartbeat,
|
|
2066
3182
|
inputSchema: heartbeatInput,
|
|
2067
|
-
annotations: { title: "Heartbeat Agent Task", ...MUTATING }
|
|
3183
|
+
annotations: { title: "Heartbeat Agent Task", ...MUTATING },
|
|
3184
|
+
_meta: widgetToolMeta("heartbeatAgentTask")
|
|
2068
3185
|
},
|
|
2069
3186
|
async (args) => handleHeartbeatAgentTask(getToken, baseUrl, args)
|
|
2070
3187
|
);
|
|
@@ -2074,7 +3191,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2074
3191
|
title: "Submit Agent Task",
|
|
2075
3192
|
description: DESCRIPTIONS.submit,
|
|
2076
3193
|
inputSchema: submitInput,
|
|
2077
|
-
annotations: { title: "Submit Agent Task", ...MUTATING }
|
|
3194
|
+
annotations: { title: "Submit Agent Task", ...MUTATING },
|
|
3195
|
+
_meta: widgetToolMeta("submitAgentTask")
|
|
2078
3196
|
},
|
|
2079
3197
|
async (args) => handleSubmitAgentTask(getToken, baseUrl, args)
|
|
2080
3198
|
);
|
|
@@ -2147,43 +3265,6 @@ function registerAdminAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2147
3265
|
async (args) => handleAdminSubmitAgentTask(getToken, baseUrl, args)
|
|
2148
3266
|
);
|
|
2149
3267
|
}
|
|
2150
|
-
|
|
2151
|
-
// src/tools/_http.ts
|
|
2152
|
-
var DEFAULT_BASE3 = "https://api.talonic.com";
|
|
2153
|
-
function buildUrl(baseUrl, path, params = {}) {
|
|
2154
|
-
const qs = new URLSearchParams();
|
|
2155
|
-
for (const [k, v] of Object.entries(params)) {
|
|
2156
|
-
if (v === void 0 || v === "") continue;
|
|
2157
|
-
qs.set(k, String(v));
|
|
2158
|
-
}
|
|
2159
|
-
return `${baseUrl ?? DEFAULT_BASE3}${path}${qs.size ? `?${qs}` : ""}`;
|
|
2160
|
-
}
|
|
2161
|
-
async function apiJson(getToken, baseUrl, method, path, opts = {}) {
|
|
2162
|
-
const url = buildUrl(baseUrl, path, opts.params);
|
|
2163
|
-
const res = await fetch(url, {
|
|
2164
|
-
method,
|
|
2165
|
-
headers: {
|
|
2166
|
-
Authorization: `Bearer ${getToken()}`,
|
|
2167
|
-
Accept: "application/json",
|
|
2168
|
-
...opts.body !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
2169
|
-
},
|
|
2170
|
-
...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {}
|
|
2171
|
-
});
|
|
2172
|
-
if (!res.ok) {
|
|
2173
|
-
const text = await res.text().catch(() => "");
|
|
2174
|
-
throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
|
|
2175
|
-
}
|
|
2176
|
-
return await res.json();
|
|
2177
|
-
}
|
|
2178
|
-
async function runTool(fn) {
|
|
2179
|
-
try {
|
|
2180
|
-
return jsonOk(await fn());
|
|
2181
|
-
} catch (err) {
|
|
2182
|
-
return toolError(err);
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
|
|
2186
|
-
// src/tools/decision-tasks.ts
|
|
2187
3268
|
var DECIDE_SCOPE = "apps:decide";
|
|
2188
3269
|
var TASK_STATUSES2 = [
|
|
2189
3270
|
"available",
|
|
@@ -2368,7 +3449,12 @@ var DESCRIPTIONS2 = {
|
|
|
2368
3449
|
function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
2369
3450
|
const invocable = options.invocable !== false;
|
|
2370
3451
|
const describe = (text) => invocable ? text : NOT_INVOCABLE_PREFIX + text;
|
|
2371
|
-
const
|
|
3452
|
+
const metaFor = (key) => ({
|
|
3453
|
+
_meta: {
|
|
3454
|
+
...widgetToolMeta(key),
|
|
3455
|
+
...invocable ? {} : { "talonic/can_invoke": false, "talonic/required_scope": DECIDE_SCOPE }
|
|
3456
|
+
}
|
|
3457
|
+
});
|
|
2372
3458
|
server.registerTool(
|
|
2373
3459
|
"talonic_list_decision_tasks",
|
|
2374
3460
|
{
|
|
@@ -2376,7 +3462,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2376
3462
|
description: describe(DESCRIPTIONS2.list),
|
|
2377
3463
|
inputSchema: listInput2,
|
|
2378
3464
|
annotations: { title: "List Decision Tasks", ...READ_ONLY3 },
|
|
2379
|
-
...
|
|
3465
|
+
...metaFor("listDecisionTasks")
|
|
2380
3466
|
},
|
|
2381
3467
|
async (args) => handleListDecisionTasks(getToken, baseUrl, args)
|
|
2382
3468
|
);
|
|
@@ -2387,7 +3473,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2387
3473
|
description: describe(DESCRIPTIONS2.claim),
|
|
2388
3474
|
inputSchema: idInput2,
|
|
2389
3475
|
annotations: { title: "Claim Decision Task", ...MUTATING2 },
|
|
2390
|
-
...
|
|
3476
|
+
...metaFor("claimDecisionTask")
|
|
2391
3477
|
},
|
|
2392
3478
|
async (args) => handleClaimDecisionTask(getToken, baseUrl, args)
|
|
2393
3479
|
);
|
|
@@ -2398,7 +3484,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2398
3484
|
description: describe(DESCRIPTIONS2.package),
|
|
2399
3485
|
inputSchema: packageInput,
|
|
2400
3486
|
annotations: { title: "Read Decision Package", ...READ_ONLY3 },
|
|
2401
|
-
...
|
|
3487
|
+
...metaFor("readDecisionPackage")
|
|
2402
3488
|
},
|
|
2403
3489
|
async (args) => handleReadDecisionPackage(getToken, baseUrl, args)
|
|
2404
3490
|
);
|
|
@@ -2409,7 +3495,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2409
3495
|
description: describe(DESCRIPTIONS2.heartbeat),
|
|
2410
3496
|
inputSchema: epochInput,
|
|
2411
3497
|
annotations: { title: "Heartbeat Decision Task", ...MUTATING2 },
|
|
2412
|
-
...
|
|
3498
|
+
...metaFor("heartbeatDecisionTask")
|
|
2413
3499
|
},
|
|
2414
3500
|
async (args) => handleHeartbeatDecisionTask(getToken, baseUrl, args)
|
|
2415
3501
|
);
|
|
@@ -2420,7 +3506,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2420
3506
|
description: describe(DESCRIPTIONS2.submit),
|
|
2421
3507
|
inputSchema: submitInput2,
|
|
2422
3508
|
annotations: { title: "Submit Decision Task", ...MUTATING2 },
|
|
2423
|
-
...
|
|
3509
|
+
...metaFor("submitDecisionTask")
|
|
2424
3510
|
},
|
|
2425
3511
|
async (args) => handleSubmitDecisionTask(getToken, baseUrl, args)
|
|
2426
3512
|
);
|
|
@@ -2431,7 +3517,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2431
3517
|
description: describe(DESCRIPTIONS2.release),
|
|
2432
3518
|
inputSchema: epochInput,
|
|
2433
3519
|
annotations: { title: "Release Decision Task", ...MUTATING2 },
|
|
2434
|
-
...
|
|
3520
|
+
...metaFor("releaseDecisionTask")
|
|
2435
3521
|
},
|
|
2436
3522
|
async (args) => handleReleaseDecisionTask(getToken, baseUrl, args)
|
|
2437
3523
|
);
|
|
@@ -2442,7 +3528,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2442
3528
|
description: describe(DESCRIPTIONS2.fail),
|
|
2443
3529
|
inputSchema: failInput,
|
|
2444
3530
|
annotations: { title: "Fail Decision Task", ...MUTATING2 },
|
|
2445
|
-
...
|
|
3531
|
+
...metaFor("failDecisionTask")
|
|
2446
3532
|
},
|
|
2447
3533
|
async (args) => handleFailDecisionTask(getToken, baseUrl, args)
|
|
2448
3534
|
);
|
|
@@ -2543,10 +3629,7 @@ function registerToMarkdown(server, getTalonic) {
|
|
|
2543
3629
|
destructiveHint: false,
|
|
2544
3630
|
openWorldHint: true
|
|
2545
3631
|
},
|
|
2546
|
-
_meta:
|
|
2547
|
-
ui: { resourceUri: WIDGET_URIS.toMarkdown },
|
|
2548
|
-
"openai/outputTemplate": WIDGET_URIS.toMarkdown
|
|
2549
|
-
}
|
|
3632
|
+
_meta: widgetToolMeta("toMarkdown")
|
|
2550
3633
|
},
|
|
2551
3634
|
async (args) => handleToMarkdown(getTalonic(), args)
|
|
2552
3635
|
);
|
|
@@ -2620,7 +3703,7 @@ async function handleGetField(getToken, baseUrl, args) {
|
|
|
2620
3703
|
return validationError("Provide either `field_id` or `name`, not both.");
|
|
2621
3704
|
return runTool(async () => {
|
|
2622
3705
|
const { id, resolution } = await resolveFieldId(getToken, baseUrl, args);
|
|
2623
|
-
const
|
|
3706
|
+
const card2 = await apiJson(
|
|
2624
3707
|
getToken,
|
|
2625
3708
|
baseUrl,
|
|
2626
3709
|
"GET",
|
|
@@ -2629,7 +3712,7 @@ async function handleGetField(getToken, baseUrl, args) {
|
|
|
2629
3712
|
params: { follow_redirects: true }
|
|
2630
3713
|
}
|
|
2631
3714
|
);
|
|
2632
|
-
const out = { ...
|
|
3715
|
+
const out = { ...card2 };
|
|
2633
3716
|
if (resolution) out["resolution"] = resolution;
|
|
2634
3717
|
if (args.include_history) {
|
|
2635
3718
|
out["history"] = await apiJson(getToken, baseUrl, "GET", `/v1/fields/${id}/history`, {
|
|
@@ -2690,7 +3773,8 @@ function registerFieldTools(server, getToken, baseUrl) {
|
|
|
2690
3773
|
destructiveHint: false,
|
|
2691
3774
|
idempotentHint: true,
|
|
2692
3775
|
openWorldHint: false
|
|
2693
|
-
}
|
|
3776
|
+
},
|
|
3777
|
+
_meta: widgetToolMeta("listFields")
|
|
2694
3778
|
},
|
|
2695
3779
|
async (args) => handleListFields(getToken, baseUrl, args)
|
|
2696
3780
|
);
|
|
@@ -2705,7 +3789,8 @@ function registerFieldTools(server, getToken, baseUrl) {
|
|
|
2705
3789
|
destructiveHint: false,
|
|
2706
3790
|
idempotentHint: true,
|
|
2707
3791
|
openWorldHint: false
|
|
2708
|
-
}
|
|
3792
|
+
},
|
|
3793
|
+
_meta: widgetToolMeta("getField")
|
|
2709
3794
|
},
|
|
2710
3795
|
async (args) => handleGetField(getToken, baseUrl, args)
|
|
2711
3796
|
);
|
|
@@ -2720,7 +3805,8 @@ function registerFieldTools(server, getToken, baseUrl) {
|
|
|
2720
3805
|
destructiveHint: false,
|
|
2721
3806
|
idempotentHint: true,
|
|
2722
3807
|
openWorldHint: false
|
|
2723
|
-
}
|
|
3808
|
+
},
|
|
3809
|
+
_meta: widgetToolMeta("fieldValues")
|
|
2724
3810
|
},
|
|
2725
3811
|
async (args) => handleFieldValues(getToken, baseUrl, args)
|
|
2726
3812
|
);
|
|
@@ -2777,6 +3863,7 @@ async function handleFindData(getToken, baseUrl, args) {
|
|
|
2777
3863
|
}
|
|
2778
3864
|
var LIST_TOOLS_DESCRIPTION = [
|
|
2779
3865
|
"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.",
|
|
3866
|
+
"Target API: https://talonic.com/docs/api (GET /v1/agent/tools).",
|
|
2780
3867
|
"",
|
|
2781
3868
|
"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.",
|
|
2782
3869
|
"NOT FOR: discovering fields (talonic_list_fields / talonic_find_data) or documents (talonic_search) \u2014 those are shaped for you.",
|
|
@@ -2813,6 +3900,8 @@ async function handleListAgentTools(getToken, baseUrl, args) {
|
|
|
2813
3900
|
}
|
|
2814
3901
|
var INVOKE_DESCRIPTION = [
|
|
2815
3902
|
"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).",
|
|
3903
|
+
"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.",
|
|
3904
|
+
"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).",
|
|
2816
3905
|
"",
|
|
2817
3906
|
"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.",
|
|
2818
3907
|
"NOT FOR: anything a dedicated talonic_* tool already does (prefer those \u2014 they are shaped for you).",
|
|
@@ -2854,7 +3943,8 @@ function registerAgentRegistryTools(server, getToken, baseUrl) {
|
|
|
2854
3943
|
destructiveHint: false,
|
|
2855
3944
|
idempotentHint: true,
|
|
2856
3945
|
openWorldHint: false
|
|
2857
|
-
}
|
|
3946
|
+
},
|
|
3947
|
+
_meta: widgetToolMeta("findData")
|
|
2858
3948
|
},
|
|
2859
3949
|
async (args) => handleFindData(getToken, baseUrl, args)
|
|
2860
3950
|
);
|
|
@@ -2869,7 +3959,8 @@ function registerAgentRegistryTools(server, getToken, baseUrl) {
|
|
|
2869
3959
|
destructiveHint: false,
|
|
2870
3960
|
idempotentHint: true,
|
|
2871
3961
|
openWorldHint: false
|
|
2872
|
-
}
|
|
3962
|
+
},
|
|
3963
|
+
_meta: widgetToolMeta("listAgentTools")
|
|
2873
3964
|
},
|
|
2874
3965
|
async (args) => handleListAgentTools(getToken, baseUrl, args)
|
|
2875
3966
|
);
|
|
@@ -2884,15 +3975,487 @@ function registerAgentRegistryTools(server, getToken, baseUrl) {
|
|
|
2884
3975
|
destructiveHint: false,
|
|
2885
3976
|
idempotentHint: false,
|
|
2886
3977
|
openWorldHint: false
|
|
2887
|
-
}
|
|
3978
|
+
},
|
|
3979
|
+
_meta: widgetToolMeta("invokeAgentTool")
|
|
2888
3980
|
},
|
|
2889
3981
|
async (args) => handleInvokeAgentTool(getToken, baseUrl, args)
|
|
2890
3982
|
);
|
|
2891
3983
|
}
|
|
3984
|
+
var LIST_DESCRIPTION2 = [
|
|
3985
|
+
"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.",
|
|
3986
|
+
"",
|
|
3987
|
+
"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.",
|
|
3988
|
+
"NOT FOR: ad-hoc extraction schemas (talonic_list_schemas) or discovering fields (talonic_list_fields).",
|
|
3989
|
+
"ARGS: optional `search` (name contains, case-insensitive), `limit` (1\u2013100, default 20), `cursor` (from pagination.next_cursor), `order` (asc|desc by updated_at).",
|
|
3990
|
+
"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 } }."
|
|
3991
|
+
].join("\n");
|
|
3992
|
+
var GET_DESCRIPTION2 = [
|
|
3993
|
+
"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).",
|
|
3994
|
+
"",
|
|
3995
|
+
"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.",
|
|
3996
|
+
"NOT FOR: listing Specs (talonic_list_specs) or starting a run (talonic_run_spec).",
|
|
3997
|
+
"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 }).",
|
|
3998
|
+
"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[]."
|
|
3999
|
+
].join("\n");
|
|
4000
|
+
var listSpecsInputSchema = {
|
|
4001
|
+
search: z.string().min(1).optional().describe("Case-insensitive contains match on the Spec name."),
|
|
4002
|
+
limit: z.number().int().min(1).max(100).optional().describe("Page size (default 20)."),
|
|
4003
|
+
cursor: z.string().min(1).optional().describe("Opaque cursor from pagination.next_cursor."),
|
|
4004
|
+
order: z.enum(["asc", "desc"]).optional().describe("Sort by updated_at (default desc).")
|
|
4005
|
+
};
|
|
4006
|
+
var getSpecInputSchema = {
|
|
4007
|
+
spec_id: z.string().uuid().describe("Spec UUID (from talonic_list_specs)."),
|
|
4008
|
+
include_versions: z.boolean().optional().describe("Also fetch the published versions list (adds `versions[]`).")
|
|
4009
|
+
};
|
|
4010
|
+
async function handleListSpecs(getToken, baseUrl, args) {
|
|
4011
|
+
const params = {
|
|
4012
|
+
search: args.search,
|
|
4013
|
+
limit: args.limit,
|
|
4014
|
+
cursor: args.cursor,
|
|
4015
|
+
order: args.order
|
|
4016
|
+
};
|
|
4017
|
+
return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/specs", { params }));
|
|
4018
|
+
}
|
|
4019
|
+
async function handleGetSpec(getToken, baseUrl, args) {
|
|
4020
|
+
return runTool(async () => {
|
|
4021
|
+
const path = `/v1/specs/${encodeURIComponent(args.spec_id)}`;
|
|
4022
|
+
const spec = await apiJson(getToken, baseUrl, "GET", path);
|
|
4023
|
+
if (!args.include_versions) return spec;
|
|
4024
|
+
const versions = await apiJson(
|
|
4025
|
+
getToken,
|
|
4026
|
+
baseUrl,
|
|
4027
|
+
"GET",
|
|
4028
|
+
`${path}/versions`
|
|
4029
|
+
);
|
|
4030
|
+
return { ...spec, versions: versions.data ?? [] };
|
|
4031
|
+
});
|
|
4032
|
+
}
|
|
4033
|
+
var READ_ONLY4 = {
|
|
4034
|
+
readOnlyHint: true,
|
|
4035
|
+
destructiveHint: false,
|
|
4036
|
+
idempotentHint: true,
|
|
4037
|
+
openWorldHint: false
|
|
4038
|
+
};
|
|
4039
|
+
function registerSpecTools(server, getToken, baseUrl) {
|
|
4040
|
+
server.registerTool(
|
|
4041
|
+
"talonic_list_specs",
|
|
4042
|
+
{
|
|
4043
|
+
title: "List Specs",
|
|
4044
|
+
description: LIST_DESCRIPTION2,
|
|
4045
|
+
inputSchema: listSpecsInputSchema,
|
|
4046
|
+
annotations: { title: "List Specs", ...READ_ONLY4 },
|
|
4047
|
+
_meta: widgetToolMeta("listSpecs")
|
|
4048
|
+
},
|
|
4049
|
+
async (args) => handleListSpecs(getToken, baseUrl, args)
|
|
4050
|
+
);
|
|
4051
|
+
server.registerTool(
|
|
4052
|
+
"talonic_get_spec",
|
|
4053
|
+
{
|
|
4054
|
+
title: "Get a Spec's structure",
|
|
4055
|
+
description: GET_DESCRIPTION2,
|
|
4056
|
+
inputSchema: getSpecInputSchema,
|
|
4057
|
+
annotations: { title: "Get a Spec's structure", ...READ_ONLY4 },
|
|
4058
|
+
_meta: widgetToolMeta("getSpec")
|
|
4059
|
+
},
|
|
4060
|
+
async (args) => handleGetSpec(getToken, baseUrl, args)
|
|
4061
|
+
);
|
|
4062
|
+
}
|
|
4063
|
+
function mapRunStatus(raw) {
|
|
4064
|
+
if (raw === "completed") return "completed";
|
|
4065
|
+
if (raw === "failed" || raw === "error" || raw === "cancelled" || raw === "canceled")
|
|
4066
|
+
return "failed";
|
|
4067
|
+
return "processing";
|
|
4068
|
+
}
|
|
4069
|
+
var RUN_DESCRIPTION = [
|
|
4070
|
+
"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.",
|
|
4071
|
+
"",
|
|
4072
|
+
"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.",
|
|
4073
|
+
"NOT FOR: one-off extraction with an ad-hoc schema (talonic_extract), or checking progress (talonic_get_run) / reading rows (talonic_get_run_results).",
|
|
4074
|
+
"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.",
|
|
4075
|
+
"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."
|
|
4076
|
+
].join("\n");
|
|
4077
|
+
var GET_RUN_DESCRIPTION = [
|
|
4078
|
+
"Poll a Spec run started by talonic_run_spec: normalised status plus document-level progress and, for pipelines, per-phase progress.",
|
|
4079
|
+
"",
|
|
4080
|
+
"USE WHEN: waiting for a run to finish \u2014 poll every 5\u201310 s; stop on `completed` or `failed`.",
|
|
4081
|
+
"NOT FOR: reading the structured rows (talonic_get_run_results) or starting a run (talonic_run_spec).",
|
|
4082
|
+
"ARGS: exactly one of `pipeline_id` (run_kind 'pipeline') or `run_id` (run_kind 'run'), from the RunEnvelope.",
|
|
4083
|
+
"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 }."
|
|
4084
|
+
].join("\n");
|
|
4085
|
+
var RESULTS_DESCRIPTION = [
|
|
4086
|
+
"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.",
|
|
4087
|
+
"",
|
|
4088
|
+
"USE WHEN: talonic_get_run reports `completed` (partial rows are also readable while `processing`).",
|
|
4089
|
+
"NOT FOR: progress (talonic_get_run) or per-field provenance of a single value (include: ['provenance'] here, or talonic_field_values).",
|
|
4090
|
+
"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`.",
|
|
4091
|
+
"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 }."
|
|
4092
|
+
].join("\n");
|
|
4093
|
+
var uuid = z.string().uuid();
|
|
4094
|
+
var documentIdsArg2 = z.array(uuid).min(1).max(500).optional().describe("Workspace document ids (1\u2013500). Mutually exclusive with file_urls.");
|
|
4095
|
+
var fileUrlsArg = z.array(z.string().url()).min(1).max(20).optional().describe("Public https file URLs (1\u201320). Mutually exclusive with document_ids.");
|
|
4096
|
+
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).");
|
|
4097
|
+
var runSpecInputSchema = {
|
|
4098
|
+
spec_id: uuid.describe("Spec UUID (talonic_list_specs)."),
|
|
4099
|
+
document_ids: documentIdsArg2,
|
|
4100
|
+
file_urls: fileUrlsArg,
|
|
4101
|
+
name: z.string().min(1).max(200).optional().describe("Display name for the run."),
|
|
4102
|
+
pipeline_mode: z.enum(["new", "append"]).optional().describe("`new` (default) or `append` to the Spec's existing pipeline."),
|
|
4103
|
+
batch_id: z.string().min(1).max(200).optional().describe("Caller grouping key (file_urls path only)."),
|
|
4104
|
+
metadata: metadataArg
|
|
4105
|
+
};
|
|
4106
|
+
var runRefInputSchema = {
|
|
4107
|
+
run_id: uuid.optional().describe("From a run_kind 'run' envelope (/v1/run)."),
|
|
4108
|
+
pipeline_id: uuid.optional().describe("From a run_kind 'pipeline' envelope (/v1/pipelines).")
|
|
4109
|
+
};
|
|
4110
|
+
var resultsInputSchema = {
|
|
4111
|
+
run_id: uuid.optional().describe(
|
|
4112
|
+
"The RunEnvelope's run_id. Alone: a run_kind 'run' submission (/v1/run). With pipeline_id: scopes the pipeline's rows to that submission."
|
|
4113
|
+
),
|
|
4114
|
+
pipeline_id: uuid.optional().describe(
|
|
4115
|
+
"The RunEnvelope's pipeline_id (run_kind 'pipeline'); rows come from /v1/pipelines/{id}/results."
|
|
4116
|
+
),
|
|
4117
|
+
document_id: uuid.optional().describe("Restrict to one document."),
|
|
4118
|
+
include: z.array(z.enum(["cells", "provenance"])).optional().describe("Extra per-field detail; heavier payload."),
|
|
4119
|
+
limit: z.number().int().min(1).max(200).optional().describe("Page size (default 50)."),
|
|
4120
|
+
cursor: z.string().min(1).optional().describe("Opaque cursor from pagination.next_cursor.")
|
|
4121
|
+
};
|
|
4122
|
+
function pickRef(args) {
|
|
4123
|
+
const hasRun = typeof args.run_id === "string" && args.run_id.length > 0;
|
|
4124
|
+
const hasPipe = typeof args.pipeline_id === "string" && args.pipeline_id.length > 0;
|
|
4125
|
+
if (hasRun === hasPipe) return null;
|
|
4126
|
+
return hasPipe ? { kind: "pipeline", id: args.pipeline_id } : { kind: "run", id: args.run_id };
|
|
4127
|
+
}
|
|
4128
|
+
async function handleRunSpec(getToken, baseUrl, args) {
|
|
4129
|
+
const docs = Array.isArray(args.document_ids) && args.document_ids.length > 0 ? args.document_ids : null;
|
|
4130
|
+
const urls = Array.isArray(args.file_urls) && args.file_urls.length > 0 ? args.file_urls : null;
|
|
4131
|
+
if (docs === null === (urls === null)) {
|
|
4132
|
+
return validationError("provide exactly one of document_ids or file_urls (non-empty).");
|
|
4133
|
+
}
|
|
4134
|
+
if (urls && urls.some((u) => !u.startsWith("https://"))) {
|
|
4135
|
+
return validationError("every file_urls entry must start with https://.");
|
|
4136
|
+
}
|
|
4137
|
+
if (docs && (args.batch_id !== void 0 || args.metadata !== void 0)) {
|
|
4138
|
+
return validationError(
|
|
4139
|
+
"batch_id and metadata only apply to the file_urls path; drop them for document_ids."
|
|
4140
|
+
);
|
|
4141
|
+
}
|
|
4142
|
+
return runTool(async () => {
|
|
4143
|
+
if (docs) {
|
|
4144
|
+
const res2 = await apiJson(
|
|
4145
|
+
getToken,
|
|
4146
|
+
baseUrl,
|
|
4147
|
+
"POST",
|
|
4148
|
+
"/v1/pipelines",
|
|
4149
|
+
{
|
|
4150
|
+
body: {
|
|
4151
|
+
schema_id: args.spec_id,
|
|
4152
|
+
document_ids: docs,
|
|
4153
|
+
...args.name ? { name: args.name } : {},
|
|
4154
|
+
...args.pipeline_mode ? { pipeline_mode: args.pipeline_mode } : {}
|
|
4155
|
+
}
|
|
4156
|
+
}
|
|
4157
|
+
);
|
|
4158
|
+
return {
|
|
4159
|
+
run_kind: "pipeline",
|
|
4160
|
+
run_id: res2.run_id ?? null,
|
|
4161
|
+
pipeline_id: res2.id,
|
|
4162
|
+
spec_id: res2.schema?.id ?? args.spec_id,
|
|
4163
|
+
spec_name: res2.schema?.name ?? null,
|
|
4164
|
+
status: mapRunStatus(res2.status),
|
|
4165
|
+
raw_status: res2.status ?? null,
|
|
4166
|
+
input_count: res2.document_count ?? docs.length,
|
|
4167
|
+
enqueued_documents: res2.enqueued_documents ?? null,
|
|
4168
|
+
appended: res2.appended === true,
|
|
4169
|
+
message: res2.message ?? null,
|
|
4170
|
+
links: res2.links ?? {}
|
|
4171
|
+
};
|
|
4172
|
+
}
|
|
4173
|
+
const res = await apiForm(getToken, baseUrl, "/v1/run", {
|
|
4174
|
+
spec_id: args.spec_id,
|
|
4175
|
+
file_urls: urls,
|
|
4176
|
+
name: args.name,
|
|
4177
|
+
pipeline_mode: args.pipeline_mode,
|
|
4178
|
+
batch_id: args.batch_id,
|
|
4179
|
+
metadata: args.metadata ? JSON.stringify(args.metadata) : void 0
|
|
4180
|
+
});
|
|
4181
|
+
return {
|
|
4182
|
+
run_kind: "run",
|
|
4183
|
+
run_id: res.run_id,
|
|
4184
|
+
pipeline_id: null,
|
|
4185
|
+
spec_id: res.spec_id ?? args.spec_id,
|
|
4186
|
+
spec_name: null,
|
|
4187
|
+
status: mapRunStatus(res.status),
|
|
4188
|
+
raw_status: res.status ?? null,
|
|
4189
|
+
input_count: res.input_count ?? urls.length,
|
|
4190
|
+
documents: res.documents ?? [],
|
|
4191
|
+
message: null,
|
|
4192
|
+
links: { poll: res.poll_url ?? `/v1/run/${res.run_id}` }
|
|
4193
|
+
};
|
|
4194
|
+
});
|
|
4195
|
+
}
|
|
4196
|
+
async function handleGetRun(getToken, baseUrl, args) {
|
|
4197
|
+
const ref = pickRef(args);
|
|
4198
|
+
if (!ref) return validationError("provide exactly one of run_id or pipeline_id.");
|
|
4199
|
+
return runTool(async () => {
|
|
4200
|
+
if (ref.kind === "run") {
|
|
4201
|
+
const r = await apiJson(
|
|
4202
|
+
getToken,
|
|
4203
|
+
baseUrl,
|
|
4204
|
+
"GET",
|
|
4205
|
+
`/v1/run/${encodeURIComponent(ref.id)}`
|
|
4206
|
+
);
|
|
4207
|
+
return {
|
|
4208
|
+
run_kind: "run",
|
|
4209
|
+
run_id: r["run_id"] ?? ref.id,
|
|
4210
|
+
pipeline_id: r["pipeline_id"] ?? null,
|
|
4211
|
+
spec_id: r["spec_id"] ?? null,
|
|
4212
|
+
status: mapRunStatus(r["status"]),
|
|
4213
|
+
raw_status: r["status"] ?? null,
|
|
4214
|
+
input_count: r["input_count"] ?? null,
|
|
4215
|
+
progress: r["progress"] ?? null,
|
|
4216
|
+
documents: r["documents"] ?? void 0,
|
|
4217
|
+
error_message: r["error_message"] ?? null,
|
|
4218
|
+
batch_id: r["batch_id"] ?? null,
|
|
4219
|
+
created_at: r["created_at"] ?? null,
|
|
4220
|
+
updated_at: r["updated_at"] ?? null
|
|
4221
|
+
};
|
|
4222
|
+
}
|
|
4223
|
+
const base = `/v1/pipelines/${encodeURIComponent(ref.id)}`;
|
|
4224
|
+
const p = await apiJson(getToken, baseUrl, "GET", base);
|
|
4225
|
+
const pr = await apiJson(getToken, baseUrl, "GET", `${base}/progress`);
|
|
4226
|
+
const raw = pr.status ?? p["status"];
|
|
4227
|
+
return {
|
|
4228
|
+
run_kind: "pipeline",
|
|
4229
|
+
run_id: null,
|
|
4230
|
+
pipeline_id: p["id"] ?? ref.id,
|
|
4231
|
+
spec_id: p["schema"]?.id ?? null,
|
|
4232
|
+
name: p["name"] ?? null,
|
|
4233
|
+
status: mapRunStatus(raw),
|
|
4234
|
+
raw_status: raw ?? null,
|
|
4235
|
+
progress: {
|
|
4236
|
+
total_documents: pr.totalDocuments ?? null,
|
|
4237
|
+
completed_documents: pr.completedDocuments ?? null,
|
|
4238
|
+
error_documents: pr.errorDocuments ?? null,
|
|
4239
|
+
finalization_pending: pr.finalizationPending ?? null,
|
|
4240
|
+
phases: (pr.phases ?? []).map((ph) => ({
|
|
4241
|
+
phase_id: ph.phaseId ?? null,
|
|
4242
|
+
name: ph.name ?? null,
|
|
4243
|
+
type: ph.type ?? null,
|
|
4244
|
+
completed: ph.completed ?? null,
|
|
4245
|
+
running: ph.running ?? null,
|
|
4246
|
+
errors: ph.errors ?? null
|
|
4247
|
+
}))
|
|
4248
|
+
},
|
|
4249
|
+
created_at: p["created_at"] ?? null,
|
|
4250
|
+
links: p["links"] ?? {}
|
|
4251
|
+
};
|
|
4252
|
+
});
|
|
4253
|
+
}
|
|
4254
|
+
async function handleGetRunResults(getToken, baseUrl, args) {
|
|
4255
|
+
const hasPipe = typeof args.pipeline_id === "string" && args.pipeline_id.length > 0;
|
|
4256
|
+
const hasRun = typeof args.run_id === "string" && args.run_id.length > 0;
|
|
4257
|
+
if (!hasPipe && !hasRun)
|
|
4258
|
+
return validationError("provide pipeline_id (optionally with run_id) or run_id.");
|
|
4259
|
+
return runTool(async () => {
|
|
4260
|
+
const kind = hasPipe ? "pipeline" : "run";
|
|
4261
|
+
const params = {
|
|
4262
|
+
...kind === "pipeline" ? { view: "documents", run_id: hasRun ? args.run_id : void 0 } : {},
|
|
4263
|
+
document_id: args.document_id,
|
|
4264
|
+
include: args.include?.length ? args.include.join(",") : void 0,
|
|
4265
|
+
limit: args.limit,
|
|
4266
|
+
cursor: args.cursor
|
|
4267
|
+
};
|
|
4268
|
+
const path = kind === "run" ? `/v1/run/${encodeURIComponent(args.run_id)}/results` : `/v1/pipelines/${encodeURIComponent(args.pipeline_id)}/results`;
|
|
4269
|
+
const body = await apiJson(getToken, baseUrl, "GET", path, { params });
|
|
4270
|
+
return { run_kind: kind, ...body };
|
|
4271
|
+
});
|
|
4272
|
+
}
|
|
4273
|
+
var READ_ONLY5 = {
|
|
4274
|
+
readOnlyHint: true,
|
|
4275
|
+
destructiveHint: false,
|
|
4276
|
+
idempotentHint: true,
|
|
4277
|
+
openWorldHint: false
|
|
4278
|
+
};
|
|
4279
|
+
function registerRunTools(server, getToken, baseUrl) {
|
|
4280
|
+
server.registerTool(
|
|
4281
|
+
"talonic_run_spec",
|
|
4282
|
+
{
|
|
4283
|
+
title: "Run a Spec pipeline",
|
|
4284
|
+
description: RUN_DESCRIPTION,
|
|
4285
|
+
inputSchema: runSpecInputSchema,
|
|
4286
|
+
annotations: {
|
|
4287
|
+
title: "Run a Spec pipeline",
|
|
4288
|
+
readOnlyHint: false,
|
|
4289
|
+
destructiveHint: false,
|
|
4290
|
+
openWorldHint: true
|
|
4291
|
+
},
|
|
4292
|
+
_meta: widgetToolMeta("runSpec")
|
|
4293
|
+
},
|
|
4294
|
+
async (args) => handleRunSpec(getToken, baseUrl, args)
|
|
4295
|
+
);
|
|
4296
|
+
server.registerTool(
|
|
4297
|
+
"talonic_get_run",
|
|
4298
|
+
{
|
|
4299
|
+
title: "Poll a Spec run",
|
|
4300
|
+
description: GET_RUN_DESCRIPTION,
|
|
4301
|
+
inputSchema: runRefInputSchema,
|
|
4302
|
+
annotations: { title: "Poll a Spec run", ...READ_ONLY5 },
|
|
4303
|
+
_meta: widgetToolMeta("getRun")
|
|
4304
|
+
},
|
|
4305
|
+
async (args) => handleGetRun(getToken, baseUrl, args)
|
|
4306
|
+
);
|
|
4307
|
+
server.registerTool(
|
|
4308
|
+
"talonic_get_run_results",
|
|
4309
|
+
{
|
|
4310
|
+
title: "Read a Spec run's rows",
|
|
4311
|
+
description: RESULTS_DESCRIPTION,
|
|
4312
|
+
inputSchema: resultsInputSchema,
|
|
4313
|
+
annotations: { title: "Read a Spec run's rows", ...READ_ONLY5 },
|
|
4314
|
+
_meta: widgetToolMeta("getRunResults")
|
|
4315
|
+
},
|
|
4316
|
+
async (args) => handleGetRunResults(getToken, baseUrl, args)
|
|
4317
|
+
);
|
|
4318
|
+
}
|
|
4319
|
+
var ASK_POLL_INTERVAL_MS = 2e3;
|
|
4320
|
+
var ASK_DEFAULT_WAIT_S = 45;
|
|
4321
|
+
var ASK_MAX_WAIT_S = 55;
|
|
4322
|
+
var POLL_HINT = "still processing \u2014 call talonic_get_answer with this ask_id in a few seconds";
|
|
4323
|
+
var ASK_DESCRIPTION = [
|
|
4324
|
+
"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.",
|
|
4325
|
+
"",
|
|
4326
|
+
"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.",
|
|
4327
|
+
"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).",
|
|
4328
|
+
"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).",
|
|
4329
|
+
"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."
|
|
4330
|
+
].join("\n");
|
|
4331
|
+
var GET_ANSWER_DESCRIPTION = [
|
|
4332
|
+
"Poll an ask started by talonic_ask that was still processing when the wait ended.",
|
|
4333
|
+
"",
|
|
4334
|
+
"USE WHEN: talonic_ask returned status 'processing' with an ask_id \u2014 poll every few seconds until 'completed' or 'error'.",
|
|
4335
|
+
"NOT FOR: asking a new question (talonic_ask).",
|
|
4336
|
+
"ARGS: `ask_id`.",
|
|
4337
|
+
"RETURNS: the same answer envelope as talonic_ask (answer, citations[], verification, usage) or { status: 'processing', poll_hint }."
|
|
4338
|
+
].join("\n");
|
|
4339
|
+
var uuid2 = z.string().uuid();
|
|
4340
|
+
var scopeSchema = z.object({
|
|
4341
|
+
document_ids: z.array(uuid2).max(500).optional(),
|
|
4342
|
+
schema_id: uuid2.optional(),
|
|
4343
|
+
pipeline_id: uuid2.optional(),
|
|
4344
|
+
data_product_id: uuid2.optional(),
|
|
4345
|
+
document_type: z.string().min(1).optional(),
|
|
4346
|
+
source_id: uuid2.optional(),
|
|
4347
|
+
tags: z.array(z.string().min(1)).max(50).optional(),
|
|
4348
|
+
ingested_after: z.string().min(1).optional(),
|
|
4349
|
+
ingested_before: z.string().min(1).optional()
|
|
4350
|
+
}).optional().describe("Restrict the question to a slice of the workspace; present fields are ANDed.");
|
|
4351
|
+
var askInputSchema = {
|
|
4352
|
+
question: z.string().min(1).max(4e3).describe("The question, in the user's words."),
|
|
4353
|
+
scope: scopeSchema,
|
|
4354
|
+
conversation_id: uuid2.optional().describe("Continue this conversation; the agent sees prior turns."),
|
|
4355
|
+
output_format: z.object({
|
|
4356
|
+
instruction: z.string().max(1e3).optional(),
|
|
4357
|
+
template: z.string().max(4e3).optional()
|
|
4358
|
+
}).optional().describe("Shape the answer (form only, never grounding)."),
|
|
4359
|
+
wait_seconds: z.number().int().min(0).max(ASK_MAX_WAIT_S).optional().describe(
|
|
4360
|
+
`Seconds to wait for the answer before returning 'processing' (default ${ASK_DEFAULT_WAIT_S}, max ${ASK_MAX_WAIT_S}).`
|
|
4361
|
+
)
|
|
4362
|
+
};
|
|
4363
|
+
function withHint(body) {
|
|
4364
|
+
return body.status === "processing" ? { ...body, poll_hint: POLL_HINT } : body;
|
|
4365
|
+
}
|
|
4366
|
+
async function handleAsk(getToken, baseUrl, args, deps = {}) {
|
|
4367
|
+
if (typeof args.question !== "string" || args.question.trim().length === 0) {
|
|
4368
|
+
return validationError("question must be a non-empty string.");
|
|
4369
|
+
}
|
|
4370
|
+
const sleep2 = deps.sleep ?? sleep;
|
|
4371
|
+
const now = deps.now ?? Date.now;
|
|
4372
|
+
const requestedWaitS = Number.isFinite(args.wait_seconds) ? args.wait_seconds : ASK_DEFAULT_WAIT_S;
|
|
4373
|
+
const waitS = Math.max(0, Math.min(ASK_MAX_WAIT_S, Math.floor(requestedWaitS)));
|
|
4374
|
+
return runTool(async () => {
|
|
4375
|
+
const created = await apiJson(getToken, baseUrl, "POST", "/v1/ask", {
|
|
4376
|
+
body: {
|
|
4377
|
+
question: args.question,
|
|
4378
|
+
...args.scope ? { scope: args.scope } : {},
|
|
4379
|
+
...args.conversation_id ? { conversation_id: args.conversation_id } : {},
|
|
4380
|
+
...args.output_format ? { output_format: args.output_format } : {}
|
|
4381
|
+
},
|
|
4382
|
+
signal: AbortSignal.timeout(15e3)
|
|
4383
|
+
});
|
|
4384
|
+
const pollPath = `/v1/ask/${encodeURIComponent(created.ask_id)}`;
|
|
4385
|
+
const start = now();
|
|
4386
|
+
const deadline = start + waitS * 1e3;
|
|
4387
|
+
for (; ; ) {
|
|
4388
|
+
const pollTimeoutMs = Math.max(5e3, Math.min(15e3, deadline - now()));
|
|
4389
|
+
let body;
|
|
4390
|
+
try {
|
|
4391
|
+
body = await apiJson(getToken, baseUrl, "GET", pollPath, {
|
|
4392
|
+
signal: AbortSignal.timeout(pollTimeoutMs)
|
|
4393
|
+
});
|
|
4394
|
+
} catch {
|
|
4395
|
+
return {
|
|
4396
|
+
...withHint({ status: "processing", ask_id: created.ask_id }),
|
|
4397
|
+
ask_id: created.ask_id,
|
|
4398
|
+
waited_ms: now() - start
|
|
4399
|
+
};
|
|
4400
|
+
}
|
|
4401
|
+
const t = now();
|
|
4402
|
+
if (body.status !== "processing" || t >= deadline) {
|
|
4403
|
+
return { ...withHint(body), ask_id: body.ask_id ?? created.ask_id, waited_ms: t - start };
|
|
4404
|
+
}
|
|
4405
|
+
await sleep2(Math.min(ASK_POLL_INTERVAL_MS, deadline - t));
|
|
4406
|
+
}
|
|
4407
|
+
});
|
|
4408
|
+
}
|
|
4409
|
+
async function handleGetAnswer(getToken, baseUrl, args) {
|
|
4410
|
+
return runTool(async () => {
|
|
4411
|
+
const body = await apiJson(
|
|
4412
|
+
getToken,
|
|
4413
|
+
baseUrl,
|
|
4414
|
+
"GET",
|
|
4415
|
+
`/v1/ask/${encodeURIComponent(args.ask_id)}`
|
|
4416
|
+
);
|
|
4417
|
+
return { ...withHint(body), ask_id: body.ask_id ?? args.ask_id };
|
|
4418
|
+
});
|
|
4419
|
+
}
|
|
4420
|
+
function registerAskTools(server, getToken, baseUrl) {
|
|
4421
|
+
server.registerTool(
|
|
4422
|
+
"talonic_ask",
|
|
4423
|
+
{
|
|
4424
|
+
title: "Ask a question over the workspace",
|
|
4425
|
+
description: ASK_DESCRIPTION,
|
|
4426
|
+
inputSchema: askInputSchema,
|
|
4427
|
+
annotations: {
|
|
4428
|
+
title: "Ask a question over the workspace",
|
|
4429
|
+
readOnlyHint: false,
|
|
4430
|
+
destructiveHint: false,
|
|
4431
|
+
openWorldHint: false
|
|
4432
|
+
},
|
|
4433
|
+
_meta: widgetToolMeta("ask")
|
|
4434
|
+
},
|
|
4435
|
+
async (args) => handleAsk(getToken, baseUrl, args)
|
|
4436
|
+
);
|
|
4437
|
+
server.registerTool(
|
|
4438
|
+
"talonic_get_answer",
|
|
4439
|
+
{
|
|
4440
|
+
title: "Poll an ask for its answer",
|
|
4441
|
+
description: GET_ANSWER_DESCRIPTION,
|
|
4442
|
+
inputSchema: { ask_id: uuid2.describe("From talonic_ask.") },
|
|
4443
|
+
annotations: {
|
|
4444
|
+
title: "Poll an ask for its answer",
|
|
4445
|
+
readOnlyHint: true,
|
|
4446
|
+
destructiveHint: false,
|
|
4447
|
+
idempotentHint: true,
|
|
4448
|
+
openWorldHint: false
|
|
4449
|
+
},
|
|
4450
|
+
_meta: widgetToolMeta("getAnswer")
|
|
4451
|
+
},
|
|
4452
|
+
async (args) => handleGetAnswer(getToken, baseUrl, args)
|
|
4453
|
+
);
|
|
4454
|
+
}
|
|
2892
4455
|
|
|
2893
4456
|
// package.json
|
|
2894
4457
|
var package_default = {
|
|
2895
|
-
version: "0.1.
|
|
4458
|
+
version: "0.1.79"};
|
|
2896
4459
|
|
|
2897
4460
|
// src/version.ts
|
|
2898
4461
|
var VERSION = package_default.version;
|
|
@@ -2920,6 +4483,7 @@ function createServer(options) {
|
|
|
2920
4483
|
const fallback = options.apiKey ?? "";
|
|
2921
4484
|
return () => fallback;
|
|
2922
4485
|
})();
|
|
4486
|
+
const rawToken = withFetch(getToken, taggedFetch);
|
|
2923
4487
|
const getTalonic = (() => {
|
|
2924
4488
|
if (options.talonic) {
|
|
2925
4489
|
const t = options.talonic;
|
|
@@ -2993,6 +4557,10 @@ function createServer(options) {
|
|
|
2993
4557
|
"For Agent-stage work, follow list -> get -> claim -> heartbeat while needed ->",
|
|
2994
4558
|
"submit. Preserve the execution_epoch from claim and return only fields declared",
|
|
2995
4559
|
"in the task output_contract; never continue after a lease or epoch conflict.",
|
|
4560
|
+
"To run the customer's configured pipeline: talonic_list_specs -> talonic_run_spec (document_ids for",
|
|
4561
|
+
"workspace documents, file_urls for remote files) -> poll talonic_get_run until completed ->",
|
|
4562
|
+
"talonic_get_run_results. For open questions across documents use talonic_ask (costs credits;",
|
|
4563
|
+
"if it returns status processing, poll talonic_get_answer).",
|
|
2996
4564
|
"For External-mode app decisions, follow talonic_list_decision_tasks (by app_id) ->",
|
|
2997
4565
|
"talonic_claim_decision_task (the claim IS the payload: output_contract, precedents,",
|
|
2998
4566
|
"package descriptor) -> talonic_read_decision_package pages from package.first_cursor ->",
|
|
@@ -3024,21 +4592,24 @@ function createServer(options) {
|
|
|
3024
4592
|
registerGetBalance(server, getTalonic);
|
|
3025
4593
|
registerGetPricing(server, getTalonic);
|
|
3026
4594
|
registerGetUsage(server, getTalonic);
|
|
3027
|
-
registerRequestUpload(server,
|
|
3028
|
-
registerFieldTools(server,
|
|
3029
|
-
registerAgentRegistryTools(server,
|
|
3030
|
-
registerAgentTaskTools(server,
|
|
3031
|
-
|
|
4595
|
+
registerRequestUpload(server, rawToken, baseUrl);
|
|
4596
|
+
registerFieldTools(server, rawToken, baseUrl);
|
|
4597
|
+
registerAgentRegistryTools(server, rawToken, baseUrl);
|
|
4598
|
+
registerAgentTaskTools(server, rawToken, baseUrl);
|
|
4599
|
+
registerSpecTools(server, rawToken, baseUrl);
|
|
4600
|
+
registerRunTools(server, rawToken, baseUrl);
|
|
4601
|
+
registerAskTools(server, rawToken, baseUrl);
|
|
4602
|
+
registerDecisionTaskTools(server, rawToken, baseUrl, {
|
|
3032
4603
|
invocable: options.decisionTasksInvocable !== false
|
|
3033
4604
|
});
|
|
3034
4605
|
if (options.includeGrowthTools) {
|
|
3035
|
-
registerGrowthTools(server,
|
|
4606
|
+
registerGrowthTools(server, rawToken, baseUrl);
|
|
3036
4607
|
}
|
|
3037
4608
|
if (options.includeAdminAgentTaskTools) {
|
|
3038
|
-
registerAdminAgentTaskTools(server,
|
|
4609
|
+
registerAdminAgentTaskTools(server, rawToken, baseUrl);
|
|
3039
4610
|
}
|
|
3040
4611
|
registerSchemasResource(server, getTalonic);
|
|
3041
|
-
registerWebhooksResource(server,
|
|
4612
|
+
registerWebhooksResource(server, rawToken, baseUrl);
|
|
3042
4613
|
registerWidgets(server);
|
|
3043
4614
|
return server;
|
|
3044
4615
|
}
|