@talonic/mcp 0.1.78 → 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/http-server.js
CHANGED
|
@@ -7,6 +7,114 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
9
|
// src/http-server.ts
|
|
10
|
+
function jsonOk(value) {
|
|
11
|
+
const result = {
|
|
12
|
+
content: [
|
|
13
|
+
{
|
|
14
|
+
type: "text",
|
|
15
|
+
text: JSON.stringify(value, null, 2)
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
};
|
|
19
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
20
|
+
result["structuredContent"] = value;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
function validationError(message) {
|
|
25
|
+
return {
|
|
26
|
+
isError: true,
|
|
27
|
+
content: [{ type: "text", text: `Validation error: ${message}` }]
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function toolError(err) {
|
|
31
|
+
if (err instanceof TalonicError) {
|
|
32
|
+
const lines = [
|
|
33
|
+
`Talonic API error: ${err.message}`,
|
|
34
|
+
`code: ${err.code}`,
|
|
35
|
+
`status: ${err.status}`
|
|
36
|
+
];
|
|
37
|
+
if (err.requestId) lines.push(`request_id: ${err.requestId}`);
|
|
38
|
+
return {
|
|
39
|
+
isError: true,
|
|
40
|
+
content: [{ type: "text", text: lines.join("\n") }]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
isError: true,
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
type: "text",
|
|
48
|
+
text: `Unexpected error: ${err instanceof Error ? err.message : String(err)}`
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/tools/_http.ts
|
|
55
|
+
var DEFAULT_BASE = "https://api.talonic.com";
|
|
56
|
+
function withFetch(getToken, fetchImpl) {
|
|
57
|
+
const source = (() => getToken());
|
|
58
|
+
source.fetch = fetchImpl;
|
|
59
|
+
return source;
|
|
60
|
+
}
|
|
61
|
+
function resolveFetch(getToken) {
|
|
62
|
+
return getToken.fetch ?? fetch;
|
|
63
|
+
}
|
|
64
|
+
function buildUrl(baseUrl, path, params = {}) {
|
|
65
|
+
const qs = new URLSearchParams();
|
|
66
|
+
for (const [k, v] of Object.entries(params)) {
|
|
67
|
+
if (v === void 0 || v === "") continue;
|
|
68
|
+
qs.set(k, String(v));
|
|
69
|
+
}
|
|
70
|
+
return `${baseUrl ?? DEFAULT_BASE}${path}${qs.size ? `?${qs}` : ""}`;
|
|
71
|
+
}
|
|
72
|
+
async function apiJson(getToken, baseUrl, method, path, opts = {}) {
|
|
73
|
+
const url = buildUrl(baseUrl, path, opts.params);
|
|
74
|
+
const res = await resolveFetch(getToken)(url, {
|
|
75
|
+
method,
|
|
76
|
+
headers: {
|
|
77
|
+
Authorization: `Bearer ${getToken()}`,
|
|
78
|
+
Accept: "application/json",
|
|
79
|
+
...opts.body !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
80
|
+
},
|
|
81
|
+
...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {},
|
|
82
|
+
...opts.signal ? { signal: opts.signal } : {}
|
|
83
|
+
});
|
|
84
|
+
if (!res.ok) {
|
|
85
|
+
const text = await res.text().catch(() => "");
|
|
86
|
+
throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
|
|
87
|
+
}
|
|
88
|
+
return await res.json();
|
|
89
|
+
}
|
|
90
|
+
async function apiForm(getToken, baseUrl, path, fields) {
|
|
91
|
+
const form = new FormData();
|
|
92
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
93
|
+
if (value === void 0) continue;
|
|
94
|
+
if (Array.isArray(value)) for (const item of value) form.append(key, item);
|
|
95
|
+
else form.append(key, value);
|
|
96
|
+
}
|
|
97
|
+
const res = await resolveFetch(getToken)(buildUrl(baseUrl, path), {
|
|
98
|
+
method: "POST",
|
|
99
|
+
headers: { Authorization: `Bearer ${getToken()}`, Accept: "application/json" },
|
|
100
|
+
body: form
|
|
101
|
+
});
|
|
102
|
+
if (!res.ok) {
|
|
103
|
+
const text = await res.text().catch(() => "");
|
|
104
|
+
throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
|
|
105
|
+
}
|
|
106
|
+
return await res.json();
|
|
107
|
+
}
|
|
108
|
+
function sleep(ms) {
|
|
109
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
110
|
+
}
|
|
111
|
+
async function runTool(fn) {
|
|
112
|
+
try {
|
|
113
|
+
return jsonOk(await fn());
|
|
114
|
+
} catch (err) {
|
|
115
|
+
return toolError(err);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
10
118
|
|
|
11
119
|
// src/resources/schemas-resource.ts
|
|
12
120
|
function registerSchemasResource(server, getTalonic) {
|
|
@@ -68,7 +176,7 @@ function registerWebhooksResource(server, getToken, baseUrl) {
|
|
|
68
176
|
await Promise.all(
|
|
69
177
|
WEBHOOK_INFO_ENDPOINTS.map(async ({ path, key }) => {
|
|
70
178
|
try {
|
|
71
|
-
const res = await
|
|
179
|
+
const res = await resolveFetch(getToken)(`${base}${path}`, {
|
|
72
180
|
headers: {
|
|
73
181
|
Authorization: `Bearer ${token}`,
|
|
74
182
|
Accept: "application/json"
|
|
@@ -116,14 +224,137 @@ var WIDGET_URIS = {
|
|
|
116
224
|
getBalance: "ui://widget/balance.html",
|
|
117
225
|
getPricing: "ui://widget/pricing.html",
|
|
118
226
|
getUsage: "ui://widget/usage.html",
|
|
119
|
-
requestUpload: "ui://widget/upload-link.html"
|
|
227
|
+
requestUpload: "ui://widget/upload-link.html",
|
|
228
|
+
listFields: "ui://widget/field-list.html",
|
|
229
|
+
getField: "ui://widget/field-card.html",
|
|
230
|
+
fieldValues: "ui://widget/field-values.html",
|
|
231
|
+
findData: "ui://widget/find-data.html",
|
|
232
|
+
listAgentTools: "ui://widget/agent-tools.html",
|
|
233
|
+
invokeAgentTool: "ui://widget/agent-tool-result.html",
|
|
234
|
+
listAgentTasks: "ui://widget/agent-task-list.html",
|
|
235
|
+
getAgentTask: "ui://widget/agent-task.html",
|
|
236
|
+
claimAgentTask: "ui://widget/agent-task-claim.html",
|
|
237
|
+
heartbeatAgentTask: "ui://widget/agent-task-heartbeat.html",
|
|
238
|
+
submitAgentTask: "ui://widget/agent-task-submitted.html",
|
|
239
|
+
listSpecs: "ui://widget/spec-list.html",
|
|
240
|
+
getSpec: "ui://widget/spec-card.html",
|
|
241
|
+
runSpec: "ui://widget/run-started.html",
|
|
242
|
+
getRun: "ui://widget/run-status.html",
|
|
243
|
+
getRunResults: "ui://widget/run-results.html",
|
|
244
|
+
ask: "ui://widget/answer.html",
|
|
245
|
+
getAnswer: "ui://widget/answer-polled.html",
|
|
246
|
+
listDecisionTasks: "ui://widget/decision-task-list.html",
|
|
247
|
+
claimDecisionTask: "ui://widget/decision-bundle.html",
|
|
248
|
+
readDecisionPackage: "ui://widget/decision-package.html",
|
|
249
|
+
heartbeatDecisionTask: "ui://widget/decision-task-heartbeat.html",
|
|
250
|
+
submitDecisionTask: "ui://widget/decision-task-submitted.html",
|
|
251
|
+
releaseDecisionTask: "ui://widget/decision-task-released.html",
|
|
252
|
+
failDecisionTask: "ui://widget/decision-task-failed.html"
|
|
120
253
|
};
|
|
121
|
-
|
|
254
|
+
WIDGET_URIS.extract;
|
|
255
|
+
var TOOL_INVOCATION_STATUS = {
|
|
256
|
+
extract: { invoking: "Extracting structured data\u2026", invoked: "Extraction complete" },
|
|
257
|
+
search: { invoking: "Searching the workspace\u2026", invoked: "Search results ready" },
|
|
258
|
+
filter: { invoking: "Filtering documents by field values\u2026", invoked: "Filter results ready" },
|
|
259
|
+
getDocument: { invoking: "Fetching document details\u2026", invoked: "Document details ready" },
|
|
260
|
+
toMarkdown: { invoking: "Converting document to markdown\u2026", invoked: "Markdown ready" },
|
|
261
|
+
listSchemas: { invoking: "Loading saved schemas\u2026", invoked: "Schemas listed" },
|
|
262
|
+
saveSchema: { invoking: "Saving schema\u2026", invoked: "Schema saved" },
|
|
263
|
+
getBalance: { invoking: "Checking credit balance\u2026", invoked: "Balance ready" },
|
|
264
|
+
getPricing: { invoking: "Loading pricing catalog\u2026", invoked: "Pricing ready" },
|
|
265
|
+
getUsage: { invoking: "Loading usage breakdown\u2026", invoked: "Usage ready" },
|
|
266
|
+
requestUpload: { invoking: "Preparing upload link\u2026", invoked: "Upload link ready" },
|
|
267
|
+
listFields: { invoking: "Loading the Field Registry\u2026", invoked: "Fields listed" },
|
|
268
|
+
getField: { invoking: "Loading field concept card\u2026", invoked: "Field card ready" },
|
|
269
|
+
fieldValues: {
|
|
270
|
+
invoking: "Reading field values across documents\u2026",
|
|
271
|
+
invoked: "Field values ready"
|
|
272
|
+
},
|
|
273
|
+
findData: { invoking: "Locating data behind the concept\u2026", invoked: "Matching data found" },
|
|
274
|
+
listAgentTools: { invoking: "Listing platform agent tools\u2026", invoked: "Agent tools listed" },
|
|
275
|
+
invokeAgentTool: { invoking: "Running platform agent tool\u2026", invoked: "Agent tool result ready" },
|
|
276
|
+
listAgentTasks: { invoking: "Loading agent task worklist\u2026", invoked: "Agent tasks listed" },
|
|
277
|
+
getAgentTask: { invoking: "Loading agent task\u2026", invoked: "Agent task ready" },
|
|
278
|
+
claimAgentTask: { invoking: "Claiming agent task\u2026", invoked: "Agent task claimed" },
|
|
279
|
+
heartbeatAgentTask: { invoking: "Extending task lease\u2026", invoked: "Lease extended" },
|
|
280
|
+
submitAgentTask: { invoking: "Submitting task outputs\u2026", invoked: "Task submitted" },
|
|
281
|
+
listSpecs: { invoking: "Loading Specs\u2026", invoked: "Specs listed" },
|
|
282
|
+
getSpec: { invoking: "Loading Spec structure\u2026", invoked: "Spec structure ready" },
|
|
283
|
+
runSpec: { invoking: "Starting the Spec run\u2026", invoked: "Run started" },
|
|
284
|
+
getRun: { invoking: "Checking run progress\u2026", invoked: "Run progress ready" },
|
|
285
|
+
getRunResults: { invoking: "Loading run results\u2026", invoked: "Run results ready" },
|
|
286
|
+
ask: { invoking: "Asking Talonic over your documents\u2026", invoked: "Answer ready" },
|
|
287
|
+
getAnswer: { invoking: "Checking for the answer\u2026", invoked: "Answer status ready" },
|
|
288
|
+
listDecisionTasks: { invoking: "Loading decision tasks\u2026", invoked: "Decision tasks listed" },
|
|
289
|
+
claimDecisionTask: { invoking: "Claiming decision task\u2026", invoked: "Decision task claimed" },
|
|
290
|
+
readDecisionPackage: { invoking: "Reading the decision package\u2026", invoked: "Package page ready" },
|
|
291
|
+
heartbeatDecisionTask: { invoking: "Extending the decision lease\u2026", invoked: "Lease extended" },
|
|
292
|
+
submitDecisionTask: { invoking: "Submitting the decision\u2026", invoked: "Decision submitted" },
|
|
293
|
+
releaseDecisionTask: { invoking: "Releasing the decision task\u2026", invoked: "Task released" },
|
|
294
|
+
failDecisionTask: {
|
|
295
|
+
invoking: "Reporting the task as undecidable\u2026",
|
|
296
|
+
invoked: "Task failed"
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
var WIDGET_DESCRIPTIONS = {
|
|
300
|
+
extract: "Card showing the extracted fields with per-field confidence, the source document, and the credit cost of the extraction.",
|
|
301
|
+
search: "Card listing the documents, fields, schemas and sources that matched the query, grouped by type.",
|
|
302
|
+
filter: "Table of documents whose extracted field values matched the filter, plus any API warnings about field types.",
|
|
303
|
+
getDocument: "Card with one document's metadata, processing status, and triage flags.",
|
|
304
|
+
toMarkdown: "Scrollable view of a document's OCR-converted markdown text.",
|
|
305
|
+
listSchemas: "Table of the workspace's saved extraction schemas with their field counts.",
|
|
306
|
+
saveSchema: "Confirmation card for a newly saved reusable schema.",
|
|
307
|
+
getBalance: "Card with the workspace credit balance, EUR value, tier, 30-day burn and projected runway.",
|
|
308
|
+
getPricing: "Table of Talonic's per-unit credit pricing with EUR values, free-tier badges and multipliers.",
|
|
309
|
+
getUsage: "Breakdown of credits consumed per function over the trailing window, with proportion bars.",
|
|
310
|
+
requestUpload: "Card with the browser upload link the user must open to add their file, plus the document id and expiry.",
|
|
311
|
+
listFields: "Table of Field Registry concepts with data type, maturity (core, proven, candidate) and occurrence counts.",
|
|
312
|
+
getField: "Concept card for one registry field: definition, synonyms, occurrence statistics, top values and schema usage.",
|
|
313
|
+
fieldValues: "Table of one field's current values across documents with confidence and source-text provenance.",
|
|
314
|
+
findData: "Ranked matches for a natural-language concept across four planes: fields, values, documents and passages.",
|
|
315
|
+
listAgentTools: "Table of the platform agent tool registry with each tool's impact, capability and whether this key may invoke it.",
|
|
316
|
+
invokeAgentTool: "Result of one platform agent tool call, rendered as a table, key-value tiles or a JSON tree, with citations.",
|
|
317
|
+
listAgentTasks: "Worklist of Agent-stage tasks with status, document, lease expiry, timeout and execution epoch.",
|
|
318
|
+
getAgentTask: "Card for one Agent-stage task: status, timing, instructions, declared output contract and the input snapshot.",
|
|
319
|
+
claimAgentTask: "Lease card confirming the claim: execution epoch to keep, lease expiry, and the task's instructions and contract.",
|
|
320
|
+
heartbeatAgentTask: "Lease card confirming the lease was extended, with the new expiry and execution epoch.",
|
|
321
|
+
submitAgentTask: "Confirmation that the declared outputs were submitted and the parked document resumed its pipeline.",
|
|
322
|
+
listSpecs: "Table of the workspace's Specs (configured pipelines) with version state, field and stage counts, and last update.",
|
|
323
|
+
getSpec: "Card for one Spec: version state, the schema it materializes onto, the rail's stages in order, the compiled phases, and its fields.",
|
|
324
|
+
runSpec: "Confirmation that a Spec run started: run kind, input count, spec/pipeline/run ids, status, and how to poll it.",
|
|
325
|
+
getRun: "Progress card for a Spec run: normalised status, documents completed / total / errors, and per-phase progress when available.",
|
|
326
|
+
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.",
|
|
327
|
+
ask: "Cited answer card: the answer text, verification verdict, source citations, artifacts and credit usage.",
|
|
328
|
+
getAnswer: "Polled answer card: the same cited answer with verification and citations, or a still-processing notice.",
|
|
329
|
+
listDecisionTasks: "Worklist of an External-mode app's decision tasks with status, run, epoch, lease expiry and SLA deadline.",
|
|
330
|
+
claimDecisionTask: "Claim bundle: the task's lease and epoch, the output contract to satisfy, precedents, and the input-package descriptor with its source documents.",
|
|
331
|
+
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.",
|
|
332
|
+
heartbeatDecisionTask: "Lease card confirming the decision task's lease was extended, with the new expiry and SLA deadline.",
|
|
333
|
+
submitDecisionTask: "Confirmation that the decision was submitted and verified; the run resumes.",
|
|
334
|
+
releaseDecisionTask: "Confirmation that the decision task was released back to available for another claimant.",
|
|
335
|
+
failDecisionTask: "Confirmation that the task was reported undecidable: a Human Review is raised and the app's fallback applies."
|
|
336
|
+
};
|
|
337
|
+
function widgetToolMeta(key) {
|
|
338
|
+
const uri = WIDGET_URIS[key];
|
|
339
|
+
const status3 = TOOL_INVOCATION_STATUS[key];
|
|
340
|
+
return {
|
|
341
|
+
ui: { resourceUri: uri },
|
|
342
|
+
"openai/outputTemplate": uri,
|
|
343
|
+
"openai/toolInvocation/invoking": status3.invoking,
|
|
344
|
+
"openai/toolInvocation/invoked": status3.invoked
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function widgetKeyForUri(uri) {
|
|
348
|
+
for (const key of Object.keys(WIDGET_URIS)) {
|
|
349
|
+
if (WIDGET_URIS[key] === uri) return key;
|
|
350
|
+
}
|
|
351
|
+
return void 0;
|
|
352
|
+
}
|
|
122
353
|
|
|
123
354
|
// src/widgets/shared.ts
|
|
124
355
|
var WIDGET_DOMAIN = "https://talonic.com";
|
|
125
|
-
function widgetMeta() {
|
|
126
|
-
|
|
356
|
+
function widgetMeta(description) {
|
|
357
|
+
const meta = {
|
|
127
358
|
ui: {
|
|
128
359
|
domain: WIDGET_DOMAIN,
|
|
129
360
|
csp: {
|
|
@@ -137,8 +368,11 @@ function widgetMeta() {
|
|
|
137
368
|
connect_domains: [],
|
|
138
369
|
resource_domains: [],
|
|
139
370
|
redirect_domains: []
|
|
140
|
-
}
|
|
371
|
+
},
|
|
372
|
+
"openai/widgetPrefersBorder": true
|
|
141
373
|
};
|
|
374
|
+
if (description) meta["openai/widgetDescription"] = description;
|
|
375
|
+
return meta;
|
|
142
376
|
}
|
|
143
377
|
var BASE_CSS = `
|
|
144
378
|
:root {
|
|
@@ -198,6 +432,20 @@ var BASE_CSS = `
|
|
|
198
432
|
padding: 12px; max-height: 360px; overflow: auto; white-space: pre-wrap;
|
|
199
433
|
word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
200
434
|
font-size: 12px; }
|
|
435
|
+
.chip.good { background: rgba(22,163,74,.12); color: var(--good); }
|
|
436
|
+
.chip.warn { background: rgba(217,119,6,.14); color: var(--warn); }
|
|
437
|
+
.chip.bad { background: rgba(220,38,38,.12); color: var(--bad); }
|
|
438
|
+
.chip.info { background: rgba(79,70,229,.12); color: var(--accent); }
|
|
439
|
+
.plane { margin-top: 14px; }
|
|
440
|
+
.plane .subtitle { margin-bottom: 4px; }
|
|
441
|
+
.num { text-align: right; }
|
|
442
|
+
.tree-body { padding-left: 12px; border-left: 1px solid var(--border); margin: 2px 0 2px 2px; }
|
|
443
|
+
.node { padding: 2px 0; font-size: 13px; word-break: break-word; }
|
|
444
|
+
.node .k, .tree-body summary .k { color: var(--muted); }
|
|
445
|
+
details.tree { margin: 2px 0; }
|
|
446
|
+
details.tree > summary { cursor: pointer; font-size: 13px; list-style: none; }
|
|
447
|
+
details.tree > summary::before { content: "\u25B8 "; color: var(--muted); }
|
|
448
|
+
details.tree[open] > summary::before { content: "\u25BE "; }
|
|
201
449
|
`;
|
|
202
450
|
var HELPERS_JS = `
|
|
203
451
|
var root = document.getElementById("root");
|
|
@@ -228,6 +476,102 @@ var HELPERS_JS = `
|
|
|
228
476
|
if (navigator.clipboard) navigator.clipboard.writeText(text);
|
|
229
477
|
});
|
|
230
478
|
}
|
|
479
|
+
function chip(text, tone) {
|
|
480
|
+
if (text == null || text === "") return "";
|
|
481
|
+
return '<span class="chip' + (tone ? " " + tone : "") + '">' + esc(text) + '</span>';
|
|
482
|
+
}
|
|
483
|
+
function clamp(s, n) {
|
|
484
|
+
var t = String(s == null ? "" : s);
|
|
485
|
+
return t.length > n ? t.slice(0, n - 1) + "\u2026" : t;
|
|
486
|
+
}
|
|
487
|
+
function shortId(id) {
|
|
488
|
+
var s = String(id == null ? "" : id);
|
|
489
|
+
if (!s) return "\u2014";
|
|
490
|
+
return s.length > 8 ? s.slice(0, 8) : s;
|
|
491
|
+
}
|
|
492
|
+
function idChip(id) {
|
|
493
|
+
var s = String(id == null ? "" : id);
|
|
494
|
+
if (!s) return '<span class="muted">\u2014</span>';
|
|
495
|
+
return '<span class="mono" title="' + esc(s) + '">' + esc(shortId(s)) + '</span>';
|
|
496
|
+
}
|
|
497
|
+
function relTime(iso) {
|
|
498
|
+
if (!iso) return "\u2014";
|
|
499
|
+
var t = Date.parse(iso);
|
|
500
|
+
if (isNaN(t)) return String(iso);
|
|
501
|
+
var d = Math.round((t - Date.now()) / 1000);
|
|
502
|
+
var a = Math.abs(d);
|
|
503
|
+
var n, u;
|
|
504
|
+
if (a < 60) { n = a; u = "s"; }
|
|
505
|
+
else if (a < 3600) { n = Math.round(a / 60); u = "m"; }
|
|
506
|
+
else if (a < 86400) { n = Math.round(a / 3600); u = "h"; }
|
|
507
|
+
else { n = Math.round(a / 86400); u = "d"; }
|
|
508
|
+
return d >= 0 ? "in " + n + u : n + u + " ago";
|
|
509
|
+
}
|
|
510
|
+
function isFlat(obj) {
|
|
511
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return false;
|
|
512
|
+
return Object.keys(obj).every(function (k) { var v = obj[k]; return v == null || typeof v !== "object"; });
|
|
513
|
+
}
|
|
514
|
+
function isRowArray(v) {
|
|
515
|
+
return Array.isArray(v) && v.length > 0 && v.every(function (r) { return !!r && typeof r === "object" && !Array.isArray(r); });
|
|
516
|
+
}
|
|
517
|
+
function dataTable(rows, columns) {
|
|
518
|
+
if (!Array.isArray(rows) || !rows.length) return "";
|
|
519
|
+
var cols = columns ? columns.slice() : [];
|
|
520
|
+
if (!columns) {
|
|
521
|
+
rows.forEach(function (r) {
|
|
522
|
+
if (r && typeof r === "object" && !Array.isArray(r)) {
|
|
523
|
+
Object.keys(r).forEach(function (k) { if (cols.indexOf(k) < 0) cols.push(k); });
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
var extraCols = cols.length > 12 ? cols.length - 12 : 0;
|
|
528
|
+
cols = cols.slice(0, 12);
|
|
529
|
+
var shown = rows.slice(0, 50);
|
|
530
|
+
var html = '<table><thead><tr>' + cols.map(function (c) { return '<th>' + esc(c) + '</th>'; }).join("") + '</tr></thead><tbody>';
|
|
531
|
+
shown.forEach(function (r) {
|
|
532
|
+
html += '<tr>' + cols.map(function (c) {
|
|
533
|
+
var v = r && typeof r === "object" && !Array.isArray(r) ? r[c] : r;
|
|
534
|
+
var cell = v != null && typeof v === "object" ? clamp(JSON.stringify(v), 80) : fmt(v);
|
|
535
|
+
return '<td class="val">' + esc(cell) + '</td>';
|
|
536
|
+
}).join("") + '</tr>';
|
|
537
|
+
});
|
|
538
|
+
html += '</tbody></table>';
|
|
539
|
+
var more = [];
|
|
540
|
+
if (rows.length > shown.length) more.push("+" + (rows.length - shown.length) + " more rows");
|
|
541
|
+
if (extraCols) more.push("+" + extraCols + " more columns");
|
|
542
|
+
if (more.length) html += '<div class="muted small" style="margin-top:6px">' + esc(more.join(" \xB7 ")) + '</div>';
|
|
543
|
+
return html;
|
|
544
|
+
}
|
|
545
|
+
function kvTiles(obj) {
|
|
546
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return "";
|
|
547
|
+
var keys = Object.keys(obj);
|
|
548
|
+
if (!keys.length) return "";
|
|
549
|
+
return '<div class="grid">' + keys.map(function (k) {
|
|
550
|
+
var v = obj[k];
|
|
551
|
+
var text = v != null && typeof v === "object" ? clamp(JSON.stringify(v), 120) : fmt(v);
|
|
552
|
+
return '<div class="kv"><span class="k">' + esc(k) + '</span><span class="val">' + esc(text === "" ? "\u2014" : text) + '</span></div>';
|
|
553
|
+
}).join("") + '</div>';
|
|
554
|
+
}
|
|
555
|
+
function jsonTree(value, depth, budget) {
|
|
556
|
+
depth = depth || 0;
|
|
557
|
+
budget = budget || { n: 400 };
|
|
558
|
+
if (budget.n-- <= 0) return '<span class="muted">\u2026</span>';
|
|
559
|
+
if (value == null || typeof value !== "object") return '<span class="val mono">' + esc(fmt(value)) + '</span>';
|
|
560
|
+
if (depth >= 6) return '<span class="muted">' + esc(clamp(JSON.stringify(value), 80)) + '</span>';
|
|
561
|
+
var isArr = Array.isArray(value);
|
|
562
|
+
var keys = isArr ? value.map(function (_, i) { return String(i); }) : Object.keys(value);
|
|
563
|
+
if (!keys.length) return '<span class="muted">' + (isArr ? "[]" : "{}") + '</span>';
|
|
564
|
+
var inner = keys.map(function (k) {
|
|
565
|
+
var v = value[k];
|
|
566
|
+
var label = '<span class="k mono">' + esc(k) + '</span>';
|
|
567
|
+
if (v == null || typeof v !== "object") {
|
|
568
|
+
return '<div class="node">' + label + ' <span class="val mono">' + esc(fmt(v)) + '</span></div>';
|
|
569
|
+
}
|
|
570
|
+
var size = Array.isArray(v) ? "[" + v.length + "]" : "{" + Object.keys(v).length + "}";
|
|
571
|
+
return '<details class="tree"' + (depth < 1 ? " open" : "") + '><summary>' + label + ' <span class="muted small">' + size + '</span></summary>' + jsonTree(v, depth + 1, budget) + '</details>';
|
|
572
|
+
}).join("");
|
|
573
|
+
return '<div class="tree-body">' + inner + '</div>';
|
|
574
|
+
}
|
|
231
575
|
`;
|
|
232
576
|
var BOOTSTRAP_JS = `
|
|
233
577
|
function payloadFromHost() {
|
|
@@ -291,7 +635,7 @@ function registerWidget(server, opts) {
|
|
|
291
635
|
uri: opts.uri,
|
|
292
636
|
mimeType: WIDGET_MIME,
|
|
293
637
|
text: opts.html,
|
|
294
|
-
_meta: widgetMeta()
|
|
638
|
+
_meta: widgetMeta(opts.description)
|
|
295
639
|
}
|
|
296
640
|
]
|
|
297
641
|
})
|
|
@@ -690,150 +1034,947 @@ var WIDGET_HTML11 = buildWidgetHtml({
|
|
|
690
1034
|
renderBody: RENDER_BODY11
|
|
691
1035
|
});
|
|
692
1036
|
|
|
693
|
-
// src/widgets/
|
|
694
|
-
function
|
|
695
|
-
|
|
696
|
-
[WIDGET_URIS.extract]: getExtractionResultWidgetHtml,
|
|
697
|
-
[WIDGET_URIS.search]: getSearchResultsWidgetHtml,
|
|
698
|
-
[WIDGET_URIS.filter]: getFilterResultsWidgetHtml,
|
|
699
|
-
[WIDGET_URIS.getDocument]: getDocumentMetaWidgetHtml,
|
|
700
|
-
[WIDGET_URIS.toMarkdown]: getMarkdownViewWidgetHtml,
|
|
701
|
-
[WIDGET_URIS.listSchemas]: getSchemaListWidgetHtml,
|
|
702
|
-
[WIDGET_URIS.saveSchema]: getSchemaSavedWidgetHtml,
|
|
703
|
-
[WIDGET_URIS.getBalance]: getBalanceWidgetHtml,
|
|
704
|
-
[WIDGET_URIS.getPricing]: getPricingWidgetHtml,
|
|
705
|
-
[WIDGET_URIS.getUsage]: getUsageWidgetHtml,
|
|
706
|
-
[WIDGET_URIS.requestUpload]: getUploadLinkWidgetHtml
|
|
707
|
-
};
|
|
708
|
-
return map[uri]?.();
|
|
1037
|
+
// src/widgets/field-list.ts
|
|
1038
|
+
function getFieldListWidgetHtml() {
|
|
1039
|
+
return WIDGET_HTML12;
|
|
709
1040
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
1041
|
+
var RENDER_BODY12 = `
|
|
1042
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1043
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1044
|
+
if (!rows.length) { empty("No fields match."); return; }
|
|
1045
|
+
function maturityTone(m) { return m === "core" ? "good" : m === "proven" ? "info" : m === "candidate" ? "warn" : ""; }
|
|
1046
|
+
var body = rows.map(function (f) {
|
|
1047
|
+
f = f && typeof f === "object" ? f : {};
|
|
1048
|
+
var name = f.display_name || f.canonical_name || f.id || "(field)";
|
|
1049
|
+
var sup = f.superseded_by ? ' <span class="chip bad" title="' + esc(f.superseded_by) + '">superseded</span>' : "";
|
|
1050
|
+
var canon = f.canonical_name && f.canonical_name !== name ? '<div class="muted small mono">' + esc(f.canonical_name) + '</div>' : "";
|
|
1051
|
+
return '<tr>'
|
|
1052
|
+
+ '<td><div class="val">' + esc(name) + sup + '</div>' + canon + '</td>'
|
|
1053
|
+
+ '<td>' + chip(f.data_type, "") + '</td>'
|
|
1054
|
+
+ '<td>' + chip(f.maturity, maturityTone(f.maturity)) + (f.tier != null ? ' <span class="muted small">tier ' + esc(f.tier) + '</span>' : "") + '</td>'
|
|
1055
|
+
+ '<td class="val num">' + esc(f.occurrence_count != null ? f.occurrence_count : "\u2014") + '</td>'
|
|
1056
|
+
+ '</tr>';
|
|
1057
|
+
}).join("");
|
|
1058
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1059
|
+
root.innerHTML = ''
|
|
1060
|
+
+ '<div class="header"><div><div class="title">Field Registry</div><div class="subtitle">' + rows.length + ' of ' + total + ' fields</div></div>'
|
|
1061
|
+
+ (pg.has_more ? '<span class="chip">more available</span>' : "") + '</div>'
|
|
1062
|
+
+ '<table><thead><tr><th>Field</th><th>Type</th><th>Maturity</th><th class="num">Occurrences</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1063
|
+
`;
|
|
1064
|
+
var WIDGET_HTML12 = buildWidgetHtml({
|
|
1065
|
+
title: "Talonic \u2014 Field Registry",
|
|
1066
|
+
renderBody: RENDER_BODY12
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
// src/widgets/field-card.ts
|
|
1070
|
+
function getFieldCardWidgetHtml() {
|
|
1071
|
+
return WIDGET_HTML13;
|
|
1072
|
+
}
|
|
1073
|
+
var RENDER_BODY13 = `
|
|
1074
|
+
if (!payload || (!payload.canonical_name && !payload.id)) { empty("No field card."); return; }
|
|
1075
|
+
var def = payload.definition && typeof payload.definition === "object" ? payload.definition : {};
|
|
1076
|
+
var occ = payload.occurrence && typeof payload.occurrence === "object" ? payload.occurrence : {};
|
|
1077
|
+
var vals = payload.values && typeof payload.values === "object" ? payload.values : {};
|
|
1078
|
+
var usage = payload.usage && typeof payload.usage === "object" ? payload.usage : {};
|
|
1079
|
+
var ident = payload.identity && typeof payload.identity === "object" ? payload.identity : {};
|
|
1080
|
+
var res = payload.resolution && typeof payload.resolution === "object" ? payload.resolution : null;
|
|
1081
|
+
function maturityTone(m) { return m === "core" ? "good" : m === "proven" ? "info" : m === "candidate" ? "warn" : ""; }
|
|
1082
|
+
var name = payload.display_name || payload.canonical_name || payload.id;
|
|
1083
|
+
var definition = def.description || payload.description || def.instruction || payload.master_instruction || "";
|
|
1084
|
+
var synonymList = Array.isArray(def.synonyms) ? def.synonyms : Array.isArray(payload.synonyms) ? payload.synonyms : [];
|
|
1085
|
+
var synonyms = synonymList.slice(0, 12).map(function (s) { return chip(s, ""); }).join("");
|
|
1086
|
+
var top = Array.isArray(vals.top) ? vals.top.slice(0, 8) : [];
|
|
1087
|
+
var topHtml = top.map(function (t) {
|
|
1088
|
+
t = t && typeof t === "object" ? t : {};
|
|
1089
|
+
var share = typeof t.share === "number" ? Math.max(0, Math.min(100, Math.round(t.share * 100))) : null;
|
|
1090
|
+
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>'
|
|
1091
|
+
+ (share == null ? "" : '<span class="bar"><span style="width:' + share + '%"></span></span> <span class="muted small">' + share + '%</span>') + '</td></tr>';
|
|
1092
|
+
}).join("");
|
|
1093
|
+
var rate = typeof occ.occurrence_rate === "number" ? (Math.round(occ.occurrence_rate * 1000) / 10) + "%" : "\u2014";
|
|
1094
|
+
var redirected = res && Array.isArray(res.redirected_from) && res.redirected_from.length ? res.redirected_from.join(", ") : "";
|
|
1095
|
+
var occCount = occ.occurrence_count != null ? occ.occurrence_count : payload.occurrence_count != null ? payload.occurrence_count : "\u2014";
|
|
1096
|
+
root.innerHTML = ''
|
|
1097
|
+
+ '<div class="header"><div><div class="title">' + esc(name) + '</div>'
|
|
1098
|
+
+ (payload.canonical_name && payload.canonical_name !== name ? '<div class="subtitle mono">' + esc(payload.canonical_name) + '</div>' : "") + '</div>'
|
|
1099
|
+
+ '<div>' + chip(payload.data_type, "") + chip(payload.maturity, maturityTone(payload.maturity))
|
|
1100
|
+
+ (payload.tier != null ? chip("tier " + payload.tier, "") : "")
|
|
1101
|
+
+ (ident.superseded_by || payload.superseded_by ? chip("superseded", "bad") : "")
|
|
1102
|
+
+ (ident.link_key ? chip("link key", "info") : "") + '</div></div>'
|
|
1103
|
+
+ (definition ? '<div class="small" style="white-space:pre-wrap">' + esc(clamp(definition, 600)) + '</div>' : '<div class="muted small">No definition recorded.</div>')
|
|
1104
|
+
+ (synonyms ? '<div style="margin-top:8px"><div class="muted small">Also known as</div><div>' + synonyms + '</div></div>' : "")
|
|
1105
|
+
+ '<div class="grid">'
|
|
1106
|
+
+ '<div class="kv"><span class="k">Occurrences</span><span class="val">' + esc(occCount) + '</span></div>'
|
|
1107
|
+
+ '<div class="kv"><span class="k">Documents</span><span class="val">' + esc(occ.document_count != null ? occ.document_count : "\u2014") + '</span></div>'
|
|
1108
|
+
+ '<div class="kv"><span class="k">Occurrence rate</span><span class="val">' + esc(rate) + '</span></div>'
|
|
1109
|
+
+ '<div class="kv"><span class="k">Distinct values</span><span class="val">' + esc(vals.distinct_count != null ? vals.distinct_count : "\u2014") + '</span></div>'
|
|
1110
|
+
+ '<div class="kv"><span class="k">Used in schemas</span><span class="val">' + esc(usage.schema_count != null ? usage.schema_count : "\u2014") + '</span></div>'
|
|
1111
|
+
+ '<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>'
|
|
1112
|
+
+ '</div>'
|
|
1113
|
+
+ (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>' : "")
|
|
1114
|
+
+ (res ? '<div class="muted small" style="margin-top:10px">Resolved by ' + esc(res.matched_by || "id") + (redirected ? ' \xB7 redirected from ' + esc(redirected) : "") + '</div>' : "");
|
|
1115
|
+
`;
|
|
1116
|
+
var WIDGET_HTML13 = buildWidgetHtml({
|
|
1117
|
+
title: "Talonic \u2014 Field Card",
|
|
1118
|
+
renderBody: RENDER_BODY13
|
|
1119
|
+
});
|
|
1120
|
+
|
|
1121
|
+
// src/widgets/field-values.ts
|
|
1122
|
+
function getFieldValuesWidgetHtml() {
|
|
1123
|
+
return WIDGET_HTML14;
|
|
1124
|
+
}
|
|
1125
|
+
var RENDER_BODY14 = `
|
|
1126
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1127
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1128
|
+
var name = payload.canonical_name || payload.field_id || "field";
|
|
1129
|
+
if (!rows.length) { empty("No values recorded for " + name + "."); return; }
|
|
1130
|
+
var body = rows.map(function (r) {
|
|
1131
|
+
r = r && typeof r === "object" ? r : { value: r };
|
|
1132
|
+
var prov = r.provenance && typeof r.provenance === "object" ? r.provenance : {};
|
|
1133
|
+
var flags = (prov.needs_confirmation ? chip("needs confirmation", "warn") : "") + (prov.via_redirect ? chip("via redirect", "info") : "");
|
|
1134
|
+
return '<tr>'
|
|
1135
|
+
+ '<td class="val mono">' + esc(clamp(fmt(r.value), 80)) + '</td>'
|
|
1136
|
+
+ '<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>'
|
|
1137
|
+
+ '<td>' + confBar(r.confidence) + '</td>'
|
|
1138
|
+
+ '<td class="small">' + (prov.raw_field_name ? '<div class="mono">' + esc(prov.raw_field_name) + '</div>' : "")
|
|
1139
|
+
+ (prov.source_text ? '<div class="muted">\u201C' + esc(clamp(prov.source_text, 90)) + '\u201D</div>' : "") + flags + '</td>'
|
|
1140
|
+
+ '</tr>';
|
|
1141
|
+
}).join("");
|
|
1142
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1143
|
+
root.innerHTML = ''
|
|
1144
|
+
+ '<div class="header"><div><div class="title">' + esc(name) + '</div><div class="subtitle">' + rows.length + ' of ' + total + ' values</div></div>'
|
|
1145
|
+
+ (pg.has_more ? '<span class="chip">more available</span>' : "") + '</div>'
|
|
1146
|
+
+ '<table><thead><tr><th>Value</th><th>Document</th><th>Confidence</th><th>Provenance</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1147
|
+
`;
|
|
1148
|
+
var WIDGET_HTML14 = buildWidgetHtml({
|
|
1149
|
+
title: "Talonic \u2014 Field Values",
|
|
1150
|
+
renderBody: RENDER_BODY14
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
// src/widgets/find-data.ts
|
|
1154
|
+
function getFindDataWidgetHtml() {
|
|
1155
|
+
return WIDGET_HTML15;
|
|
1156
|
+
}
|
|
1157
|
+
var RENDER_BODY15 = `
|
|
1158
|
+
var res = payload && payload.result && typeof payload.result === "object" ? payload.result : (payload && typeof payload === "object" ? payload : {});
|
|
1159
|
+
var fields = Array.isArray(res.fields) ? res.fields : [];
|
|
1160
|
+
var values = Array.isArray(res.values) ? res.values : [];
|
|
1161
|
+
var docs = Array.isArray(res.documents) ? res.documents : [];
|
|
1162
|
+
var passages = Array.isArray(res.passages) ? res.passages : [];
|
|
1163
|
+
var total = fields.length + values.length + docs.length + passages.length;
|
|
1164
|
+
var query = typeof res.query === "string" ? res.query : "";
|
|
1165
|
+
if (!total) { empty("Nothing in the workspace matches" + (query ? " \u201C" + query + "\u201D" : "") + "."); return; }
|
|
1166
|
+
function scoreBar(s) {
|
|
1167
|
+
if (typeof s !== "number") return "";
|
|
1168
|
+
var p = Math.max(0, Math.min(100, Math.round(s * 100)));
|
|
1169
|
+
return '<span class="bar"><span style="width:' + p + '%"></span></span> <span class="muted small">' + p + '%</span>';
|
|
1170
|
+
}
|
|
1171
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1172
|
+
function plane(label, items, renderItem) {
|
|
1173
|
+
if (!items.length) return "";
|
|
1174
|
+
return '<div class="plane"><div class="subtitle">' + esc(label) + ' (' + items.length + ')</div>' + items.map(function (i) { return renderItem(obj(i)); }).join("") + '</div>';
|
|
1175
|
+
}
|
|
1176
|
+
var fieldsHtml = plane("Fields", fields, function (f) {
|
|
1177
|
+
var samples = Array.isArray(f.samples) ? f.samples.slice(0, 3).map(function (s) {
|
|
1178
|
+
var v = s && typeof s === "object" && "value" in s ? s.value : s;
|
|
1179
|
+
return chip(clamp(fmt(v), 40), "");
|
|
1180
|
+
}).join("") : "";
|
|
1181
|
+
return '<div class="kv"><div><span class="val">' + esc(f.display_name || f.canonical_name || "(field)") + '</span> ' + chip(f.data_type, "")
|
|
1182
|
+
+ (f.tier != null ? chip("tier " + f.tier, "") : "") + (f.match ? chip(f.match, "info") : "") + '</div>'
|
|
1183
|
+
+ '<div class="small muted">' + (f.occurrence_count != null ? esc(f.occurrence_count) + ' occurrences \xB7 ' : "") + scoreBar(f.score) + '</div>'
|
|
1184
|
+
+ (samples ? '<div>' + samples + '</div>' : "") + '</div>';
|
|
1185
|
+
});
|
|
1186
|
+
var valuesHtml = plane("Values", values, function (v) {
|
|
1187
|
+
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 || "")
|
|
1188
|
+
+ (v.filename ? ' \xB7 ' + esc(v.filename) : "") + ' ' + scoreBar(v.score) + '</span></div>';
|
|
1189
|
+
});
|
|
1190
|
+
var docsHtml = plane("Documents", docs, function (d) {
|
|
1191
|
+
return '<div class="kv"><span class="val">' + esc(d.filename || shortId(d.document_id)) + '</span><span class="small muted">' + scoreBar(d.score) + '</span>'
|
|
1192
|
+
+ (d.best_passage ? '<span class="small">' + esc(clamp(d.best_passage, 160)) + '</span>' : "") + '</div>';
|
|
1193
|
+
});
|
|
1194
|
+
var passagesHtml = plane("Passages", passages, function (p) {
|
|
1195
|
+
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>';
|
|
1196
|
+
});
|
|
1197
|
+
root.innerHTML = ''
|
|
1198
|
+
+ '<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>'
|
|
1199
|
+
+ fieldsHtml + valuesHtml + docsHtml + passagesHtml;
|
|
1200
|
+
`;
|
|
1201
|
+
var WIDGET_HTML15 = buildWidgetHtml({
|
|
1202
|
+
title: "Talonic \u2014 Find Data",
|
|
1203
|
+
renderBody: RENDER_BODY15
|
|
1204
|
+
});
|
|
1205
|
+
|
|
1206
|
+
// src/widgets/agent-tools.ts
|
|
1207
|
+
function getAgentToolsWidgetHtml() {
|
|
1208
|
+
return WIDGET_HTML16;
|
|
1209
|
+
}
|
|
1210
|
+
var RENDER_BODY16 = `
|
|
1211
|
+
var tools = Array.isArray(payload.tools) ? payload.tools : [];
|
|
1212
|
+
if (!tools.length) { empty("No agent tools are visible to this credential."); return; }
|
|
1213
|
+
function impactTone(i) { return i === "read" ? "good" : i === "draft_mutation" ? "warn" : i === "live_mutation" ? "bad" : ""; }
|
|
1214
|
+
var body = tools.map(function (t) {
|
|
1215
|
+
t = t && typeof t === "object" ? t : {};
|
|
1216
|
+
return '<tr>'
|
|
1217
|
+
+ '<td><div class="val mono">' + esc(t.name || "(tool)") + '</div><div class="muted small">' + esc(clamp(t.description, 140)) + '</div></td>'
|
|
1218
|
+
+ '<td>' + chip(t.impact, impactTone(t.impact)) + '</td>'
|
|
1219
|
+
+ '<td>' + chip(t.capability, "") + '</td>'
|
|
1220
|
+
+ '<td>' + (t.can_invoke ? '<span class="chip good">\u2713 invocable</span>' : '<span class="muted small">\u2014</span>') + '</td>'
|
|
1221
|
+
+ '</tr>';
|
|
1222
|
+
}).join("");
|
|
1223
|
+
var inv = typeof payload.invocable_count === "number" ? payload.invocable_count : tools.filter(function (t) { return t && t.can_invoke; }).length;
|
|
1224
|
+
var total = typeof payload.totalCount === "number" ? payload.totalCount : tools.length;
|
|
1225
|
+
root.innerHTML = ''
|
|
1226
|
+
+ '<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>'
|
|
1227
|
+
+ '<table><thead><tr><th>Tool</th><th>Impact</th><th>Capability</th><th>Access</th></tr></thead><tbody>' + body + '</tbody></table>';
|
|
1228
|
+
`;
|
|
1229
|
+
var WIDGET_HTML16 = buildWidgetHtml({
|
|
1230
|
+
title: "Talonic \u2014 Agent Tools",
|
|
1231
|
+
renderBody: RENDER_BODY16
|
|
1232
|
+
});
|
|
1233
|
+
|
|
1234
|
+
// src/widgets/agent-tool-result.ts
|
|
1235
|
+
function getAgentToolResultWidgetHtml() {
|
|
1236
|
+
return WIDGET_HTML17;
|
|
1237
|
+
}
|
|
1238
|
+
var RENDER_BODY17 = `
|
|
1239
|
+
var result = payload && typeof payload === "object" ? payload.result : undefined;
|
|
1240
|
+
var toolName = (payload && payload.tool) || "agent tool";
|
|
1241
|
+
var isEmptyResult = result == null || result === ""
|
|
1242
|
+
|| (Array.isArray(result) && result.length === 0)
|
|
1243
|
+
|| (typeof result === "object" && !Array.isArray(result) && Object.keys(result).length === 0);
|
|
1244
|
+
var body;
|
|
1245
|
+
if (isEmptyResult) body = '<div class="empty">The tool returned no data.</div>';
|
|
1246
|
+
else if (isRowArray(result)) body = dataTable(result);
|
|
1247
|
+
else if (isFlat(result)) body = kvTiles(result);
|
|
1248
|
+
else if (typeof result === "object") body = jsonTree(result);
|
|
1249
|
+
else body = '<pre class="md">' + esc(fmt(result)) + '</pre>';
|
|
1250
|
+
var cites = Array.isArray(payload.citations) ? payload.citations : [];
|
|
1251
|
+
var arts = Array.isArray(payload.artifacts) ? payload.artifacts : [];
|
|
1252
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1253
|
+
var citeHtml = cites.length ? '<div class="plane"><div class="subtitle">Citations (' + cites.length + ')</div>' + cites.slice(0, 20).map(function (c) {
|
|
1254
|
+
c = obj(c);
|
|
1255
|
+
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>';
|
|
1256
|
+
}).join("") + '</div>' : "";
|
|
1257
|
+
var artHtml = arts.length ? '<div class="plane"><div class="subtitle">Artifacts (' + arts.length + ')</div>' + arts.slice(0, 20).map(function (a) {
|
|
1258
|
+
a = obj(a);
|
|
1259
|
+
var link = typeof a.link === "string" && /^https:\\/\\//.test(a.link) ? a.link : "";
|
|
1260
|
+
return '<div class="kv"><span class="val">' + esc(a.label || a.type || a.id || "artifact") + '</span>'
|
|
1261
|
+
+ (link ? '<a class="btn small" href="' + esc(link) + '" target="_blank" rel="noopener noreferrer">Open</a>' : "") + '</div>';
|
|
1262
|
+
}).join("") + '</div>' : "";
|
|
1263
|
+
var count = "";
|
|
1264
|
+
if (!isEmptyResult) {
|
|
1265
|
+
if (isRowArray(result)) count = result.length + (result.length === 1 ? " row" : " rows");
|
|
1266
|
+
else if (result && typeof result === "object" && !Array.isArray(result)) {
|
|
1267
|
+
var keyCount = Object.keys(result).length;
|
|
1268
|
+
count = keyCount + (keyCount === 1 ? " key" : " keys");
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
root.innerHTML = ''
|
|
1272
|
+
+ '<div class="header"><div><div class="title mono">' + esc(toolName) + '</div>' + (count ? '<div class="subtitle">' + esc(count) + '</div>' : "") + '</div></div>'
|
|
1273
|
+
+ body + citeHtml + artHtml;
|
|
1274
|
+
`;
|
|
1275
|
+
var WIDGET_HTML17 = buildWidgetHtml({
|
|
1276
|
+
title: "Talonic \u2014 Agent Tool Result",
|
|
1277
|
+
renderBody: RENDER_BODY17
|
|
1278
|
+
});
|
|
1279
|
+
|
|
1280
|
+
// src/widgets/agent-task-shared.ts
|
|
1281
|
+
var TASK_JS = `
|
|
1282
|
+
function statusTone(s) {
|
|
1283
|
+
return s === "available" ? "info" : s === "claimed" || s === "submitted" ? "good" : s === "timed_out" ? "bad" : s === "cancelled" ? "warn" : "";
|
|
1284
|
+
}
|
|
1285
|
+
function taskTiming(p) {
|
|
1286
|
+
return '<div class="grid">'
|
|
1287
|
+
+ '<div class="kv"><span class="k">Document</span> <span class="val">' + idChip(p.document_id) + '</span></div>'
|
|
1288
|
+
+ '<div class="kv"><span class="k">Pipeline</span> <span class="val">' + idChip(p.pipeline_id) + '</span></div>'
|
|
1289
|
+
+ '<div class="kv"><span class="k">Phase</span> <span class="val">' + esc(p.phase_index != null ? p.phase_index : "\u2014") + '</span></div>'
|
|
1290
|
+
+ '<div class="kv"><span class="k">Execution epoch</span> <span class="val">' + esc(p.execution_epoch != null ? p.execution_epoch : "\u2014") + '</span></div>'
|
|
1291
|
+
+ '<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>'
|
|
1292
|
+
+ '<div class="kv"><span class="k">Times out</span> <span class="val">' + esc(p.timeout_at ? relTime(p.timeout_at) : "\u2014") + '</span></div>'
|
|
1293
|
+
+ '</div>';
|
|
1294
|
+
}
|
|
1295
|
+
function taskSections(p) {
|
|
1296
|
+
var html = "";
|
|
1297
|
+
if (typeof p.instructions === "string" && p.instructions) {
|
|
1298
|
+
html += '<div class="plane"><div class="subtitle">Instructions</div><div class="small" style="white-space:pre-wrap">' + esc(clamp(p.instructions, 1200)) + '</div></div>';
|
|
1299
|
+
}
|
|
1300
|
+
if (Array.isArray(p.output_contract) && p.output_contract.length) {
|
|
1301
|
+
html += '<div class="plane"><div class="subtitle">Output contract (' + p.output_contract.length + ')</div>'
|
|
1302
|
+
+ '<table><thead><tr><th>Field</th><th>Type</th><th>Required</th></tr></thead><tbody>'
|
|
1303
|
+
+ p.output_contract.map(function (f) {
|
|
1304
|
+
f = f && typeof f === "object" ? f : {};
|
|
1305
|
+
return '<tr><td class="val mono">' + esc(f.key || "") + '</td><td>' + chip(f.dataType, "") + '</td><td>'
|
|
1306
|
+
+ (f.required ? chip("required", "warn") : '<span class="muted small">optional</span>') + '</td></tr>';
|
|
1307
|
+
}).join("")
|
|
1308
|
+
+ '</tbody></table></div>';
|
|
1309
|
+
}
|
|
1310
|
+
var snap = p.input_snapshot;
|
|
1311
|
+
if (snap && typeof snap === "object" && !Array.isArray(snap) && Object.keys(snap).length) {
|
|
1312
|
+
html += '<div class="plane"><div class="subtitle">Input snapshot</div>' + (isFlat(snap) ? kvTiles(snap) : jsonTree(snap)) + '</div>';
|
|
1313
|
+
}
|
|
1314
|
+
if (p.timeout_fallthrough) {
|
|
1315
|
+
html += '<div class="muted small" style="margin-top:10px">On timeout: ' + esc(String(p.timeout_fallthrough).replace(/_/g, " ")) + '</div>';
|
|
1316
|
+
}
|
|
1317
|
+
return html;
|
|
1318
|
+
}
|
|
1319
|
+
`;
|
|
1320
|
+
|
|
1321
|
+
// src/widgets/agent-task-list.ts
|
|
1322
|
+
function getAgentTaskListWidgetHtml() {
|
|
1323
|
+
return WIDGET_HTML18;
|
|
1324
|
+
}
|
|
1325
|
+
var RENDER_BODY18 = TASK_JS + `
|
|
1326
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1327
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1328
|
+
if (!rows.length) { empty("No agent tasks in this worklist."); return; }
|
|
1329
|
+
var body = rows.map(function (t) {
|
|
1330
|
+
t = t && typeof t === "object" ? t : {};
|
|
1331
|
+
return '<tr>'
|
|
1332
|
+
+ '<td>' + idChip(t.id) + '</td>'
|
|
1333
|
+
+ '<td>' + chip(t.status, statusTone(t.status)) + '</td>'
|
|
1334
|
+
+ '<td>' + idChip(t.document_id) + '</td>'
|
|
1335
|
+
+ '<td class="val num">' + esc(t.phase_index != null ? t.phase_index : "\u2014") + '</td>'
|
|
1336
|
+
+ '<td class="val">' + esc(t.lease_expires_at ? relTime(t.lease_expires_at) : "\u2014") + '</td>'
|
|
1337
|
+
+ '<td class="val">' + esc(t.timeout_at ? relTime(t.timeout_at) : "\u2014") + '</td>'
|
|
1338
|
+
+ '<td class="val num">' + esc(t.execution_epoch != null ? t.execution_epoch : "\u2014") + '</td>'
|
|
1339
|
+
+ '</tr>';
|
|
1340
|
+
}).join("");
|
|
1341
|
+
var counts = {};
|
|
1342
|
+
rows.forEach(function (t) { var s = t && typeof t === "object" && t.status ? t.status : "unknown"; counts[s] = (counts[s] || 0) + 1; });
|
|
1343
|
+
var summary = Object.keys(counts).map(function (s) { return chip(counts[s] + " " + s, statusTone(s)); }).join("");
|
|
1344
|
+
root.innerHTML = ''
|
|
1345
|
+
+ '<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>'
|
|
1346
|
+
+ '<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>';
|
|
1347
|
+
`;
|
|
1348
|
+
var WIDGET_HTML18 = buildWidgetHtml({
|
|
1349
|
+
title: "Talonic \u2014 Agent Tasks",
|
|
1350
|
+
renderBody: RENDER_BODY18
|
|
1351
|
+
});
|
|
1352
|
+
|
|
1353
|
+
// src/widgets/agent-task.ts
|
|
1354
|
+
function getAgentTaskWidgetHtml() {
|
|
1355
|
+
return WIDGET_HTML19;
|
|
1356
|
+
}
|
|
1357
|
+
var RENDER_BODY19 = TASK_JS + `
|
|
1358
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No agent task."); return; }
|
|
1359
|
+
root.innerHTML = ''
|
|
1360
|
+
+ '<div class="header"><div><div class="title">Agent task ' + idChip(payload.id) + '</div>'
|
|
1361
|
+
+ '<div class="subtitle">' + esc(payload.created_at ? "created " + relTime(payload.created_at) : "") + '</div></div>'
|
|
1362
|
+
+ '<div>' + chip(payload.status, statusTone(payload.status)) + '</div></div>'
|
|
1363
|
+
+ taskTiming(payload) + taskSections(payload);
|
|
1364
|
+
`;
|
|
1365
|
+
var WIDGET_HTML19 = buildWidgetHtml({
|
|
1366
|
+
title: "Talonic \u2014 Agent Task",
|
|
1367
|
+
renderBody: RENDER_BODY19
|
|
1368
|
+
});
|
|
1369
|
+
|
|
1370
|
+
// src/widgets/agent-task-lease.ts
|
|
1371
|
+
function getAgentTaskClaimWidgetHtml() {
|
|
1372
|
+
return CLAIM_HTML;
|
|
1373
|
+
}
|
|
1374
|
+
function getAgentTaskHeartbeatWidgetHtml() {
|
|
1375
|
+
return HEARTBEAT_HTML;
|
|
1376
|
+
}
|
|
1377
|
+
var LEASE_BODY = `
|
|
1378
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No lease information."); return; }
|
|
1379
|
+
root.innerHTML = ''
|
|
1380
|
+
+ '<div class="header"><div><div class="title">' + HEADLINE + '</div><div class="subtitle">Task ' + idChip(payload.id) + '</div></div>'
|
|
1381
|
+
+ '<div>' + chip(payload.status, statusTone(payload.status)) + '</div></div>'
|
|
1382
|
+
+ '<div class="big">' + esc(payload.execution_epoch != null ? payload.execution_epoch : "\u2014") + ' <span class="muted small">execution epoch</span></div>'
|
|
1383
|
+
+ '<div class="muted small">Keep this epoch for heartbeat and submit.' + (payload.lease_expires_at ? ' Lease expires ' + esc(relTime(payload.lease_expires_at)) + '.' : "") + '</div>'
|
|
1384
|
+
+ taskTiming(payload) + taskSections(payload);
|
|
1385
|
+
`;
|
|
1386
|
+
function leaseWidget(headline, title) {
|
|
1387
|
+
return buildWidgetHtml({
|
|
1388
|
+
title,
|
|
1389
|
+
renderBody: TASK_JS + " var HEADLINE = " + JSON.stringify(headline) + ";\n" + LEASE_BODY
|
|
717
1390
|
});
|
|
718
1391
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
1392
|
+
var CLAIM_HTML = leaseWidget("Task claimed", "Talonic \u2014 Agent Task Claimed");
|
|
1393
|
+
var HEARTBEAT_HTML = leaseWidget("Lease extended", "Talonic \u2014 Agent Task Lease");
|
|
1394
|
+
|
|
1395
|
+
// src/widgets/agent-task-submitted.ts
|
|
1396
|
+
function getAgentTaskSubmittedWidgetHtml() {
|
|
1397
|
+
return WIDGET_HTML20;
|
|
1398
|
+
}
|
|
1399
|
+
var RENDER_BODY20 = TASK_JS + `
|
|
1400
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No submission recorded."); return; }
|
|
1401
|
+
root.innerHTML = ''
|
|
1402
|
+
+ '<div class="header"><div><div class="title">Outputs submitted</div><div class="subtitle">Task ' + idChip(payload.id)
|
|
1403
|
+
+ (payload.submitted_at ? ' \xB7 ' + esc(relTime(payload.submitted_at)) : "") + '</div></div>'
|
|
1404
|
+
+ '<div>' + chip(payload.status, statusTone(payload.status)) + '</div></div>'
|
|
1405
|
+
+ '<div class="small">The parked document resumes its pipeline from this stage.</div>'
|
|
1406
|
+
+ taskTiming(payload);
|
|
1407
|
+
`;
|
|
1408
|
+
var WIDGET_HTML20 = buildWidgetHtml({
|
|
1409
|
+
title: "Talonic \u2014 Agent Task Submitted",
|
|
1410
|
+
renderBody: RENDER_BODY20
|
|
1411
|
+
});
|
|
1412
|
+
|
|
1413
|
+
// src/widgets/spec-list.ts
|
|
1414
|
+
function getSpecListWidgetHtml() {
|
|
1415
|
+
return WIDGET_HTML21;
|
|
1416
|
+
}
|
|
1417
|
+
var RENDER_BODY21 = `
|
|
1418
|
+
if (!payload || typeof payload !== "object") { empty("No Specs in this workspace."); return; }
|
|
1419
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1420
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1421
|
+
if (!rows.length) { empty("No Specs in this workspace."); return; }
|
|
1422
|
+
function versionChip(s) {
|
|
1423
|
+
if (s.version == null) return chip("unpublished", "bad");
|
|
1424
|
+
if (s.materialized_version != null && s.materialized_version === s.version) return chip("v" + s.version + " live", "good");
|
|
1425
|
+
return chip("v" + s.version + " not live", "warn");
|
|
1426
|
+
}
|
|
1427
|
+
var body = rows.map(function (s) {
|
|
1428
|
+
s = s && typeof s === "object" ? s : {};
|
|
1429
|
+
return '<tr>'
|
|
1430
|
+
+ '<td><div class="val">' + esc(s.name || s.id || "(spec)") + '</div>' + (s.description ? '<div class="muted small">' + esc(clamp(s.description, 100)) + '</div>' : "") + '</td>'
|
|
1431
|
+
+ '<td>' + versionChip(s) + '</td>'
|
|
1432
|
+
+ '<td class="val num">' + esc(s.field_count != null ? s.field_count : "\u2014") + '</td>'
|
|
1433
|
+
+ '<td class="val num">' + esc(s.node_count != null ? s.node_count : "\u2014") + '</td>'
|
|
1434
|
+
+ '<td class="val">' + esc(s.updated_at ? relTime(s.updated_at) : "\u2014") + '</td>'
|
|
1435
|
+
+ '</tr>';
|
|
1436
|
+
}).join("");
|
|
1437
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1438
|
+
root.innerHTML = ''
|
|
1439
|
+
+ '<div class="header"><div><div class="title">Specs</div><div class="subtitle">' + rows.length + ' of ' + total + ' Specs</div></div>'
|
|
1440
|
+
+ (pg.has_more ? '<span class="chip">more available</span>' : "") + '</div>'
|
|
1441
|
+
+ '<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>';
|
|
1442
|
+
`;
|
|
1443
|
+
var WIDGET_HTML21 = buildWidgetHtml({ title: "Talonic \u2014 Specs", renderBody: RENDER_BODY21 });
|
|
1444
|
+
|
|
1445
|
+
// src/widgets/spec-card.ts
|
|
1446
|
+
function getSpecCardWidgetHtml() {
|
|
1447
|
+
return WIDGET_HTML22;
|
|
1448
|
+
}
|
|
1449
|
+
var CSS = `
|
|
1450
|
+
.rail { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 6px; }
|
|
1451
|
+
.rail .arrow { color: var(--muted); font-size: 12px; }
|
|
1452
|
+
`;
|
|
1453
|
+
var RENDER_BODY22 = `
|
|
1454
|
+
if (!payload || typeof payload !== "object" || (!payload.id && !payload.name)) { empty("No Spec."); return; }
|
|
1455
|
+
var nodes = Array.isArray(payload.nodes) ? payload.nodes : [];
|
|
1456
|
+
var phases = Array.isArray(payload.phases) ? payload.phases : [];
|
|
1457
|
+
var fields = Array.isArray(payload.fields) ? payload.fields : [];
|
|
1458
|
+
var versions = Array.isArray(payload.versions) ? payload.versions : [];
|
|
1459
|
+
var schema = payload.schema && typeof payload.schema === "object" ? payload.schema : null;
|
|
1460
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1461
|
+
var versionChip = payload.version == null ? chip("unpublished", "bad")
|
|
1462
|
+
: (payload.materialized_version != null && payload.materialized_version === payload.version ? chip("v" + payload.version + " live", "good") : chip("v" + payload.version + " not live", "warn"));
|
|
1463
|
+
var fieldCount = typeof payload.field_count === "number" ? payload.field_count : fields.length;
|
|
1464
|
+
var railHtml = nodes.length ? '<div class="plane"><div class="subtitle">Rail (' + nodes.length + ' stages)</div><div class="rail">'
|
|
1465
|
+
+ 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("")
|
|
1466
|
+
+ '</div></div>' : "";
|
|
1467
|
+
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>'
|
|
1468
|
+
+ 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("")
|
|
1469
|
+
+ '</tbody></table></div>' : "";
|
|
1470
|
+
var fieldHtml = fields.length ? '<div class="plane"><div class="subtitle">Fields (' + fields.length + ')</div><div>'
|
|
1471
|
+
+ 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>' : "";
|
|
1472
|
+
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>'
|
|
1473
|
+
+ 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("")
|
|
1474
|
+
+ '</tbody></table></div>' : "";
|
|
1475
|
+
root.innerHTML = ''
|
|
1476
|
+
+ '<div class="header"><div><div class="title">' + esc(payload.name || payload.id) + '</div>'
|
|
1477
|
+
+ (payload.description ? '<div class="subtitle">' + esc(clamp(payload.description, 140)) + '</div>' : "") + '</div>'
|
|
1478
|
+
+ '<div>' + versionChip + chip(fieldCount + " fields", "") + '</div></div>'
|
|
1479
|
+
+ '<div class="grid">'
|
|
1480
|
+
+ '<div class="kv"><span class="k">Spec id</span> <span class="val">' + idChip(payload.id) + '</span></div>'
|
|
1481
|
+
+ '<div class="kv"><span class="k">Schema</span> <span class="val">' + (schema ? esc(schema.name || "") + " " + idChip(schema.id) : idChip(payload.schema_id)) + '</span></div>'
|
|
1482
|
+
+ '<div class="kv"><span class="k">Materialized</span> <span class="val">' + esc(payload.materialized_at ? relTime(payload.materialized_at) : "\u2014") + '</span></div>'
|
|
1483
|
+
+ '<div class="kv"><span class="k">Updated</span> <span class="val">' + esc(payload.updated_at ? relTime(payload.updated_at) : "\u2014") + '</span></div>'
|
|
1484
|
+
+ '</div>'
|
|
1485
|
+
+ railHtml + phaseHtml + fieldHtml + versionHtml;
|
|
1486
|
+
`;
|
|
1487
|
+
var WIDGET_HTML22 = buildWidgetHtml({ title: "Talonic \u2014 Spec", css: CSS, renderBody: RENDER_BODY22 });
|
|
1488
|
+
|
|
1489
|
+
// src/widgets/run-started.ts
|
|
1490
|
+
function getRunStartedWidgetHtml() {
|
|
1491
|
+
return WIDGET_HTML23;
|
|
1492
|
+
}
|
|
1493
|
+
var RENDER_BODY23 = `
|
|
1494
|
+
if (!payload || typeof payload !== "object" || (!payload.pipeline_id && !payload.run_id)) { empty("No run was started."); return; }
|
|
1495
|
+
function kb(n) { return typeof n === "number" ? (n >= 1048576 ? (n / 1048576).toFixed(1) + " MB" : Math.max(1, Math.round(n / 1024)) + " KB") : "\u2014"; }
|
|
1496
|
+
var kind = payload.run_kind === "run" ? "run" : "pipeline";
|
|
1497
|
+
var docs = Array.isArray(payload.documents) ? payload.documents : [];
|
|
1498
|
+
var pollArg = kind === "pipeline" && payload.pipeline_id ? "pipeline_id " + shortId(payload.pipeline_id) : "run_id " + shortId(payload.run_id);
|
|
1499
|
+
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>'
|
|
1500
|
+
+ 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("")
|
|
1501
|
+
+ '</tbody></table>' + (docs.length > 20 ? '<div class="muted small">+' + (docs.length - 20) + ' more</div>' : "") + '</div>' : "";
|
|
1502
|
+
root.innerHTML = ''
|
|
1503
|
+
+ '<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>'
|
|
1504
|
+
+ '<div>' + chip(kind, "info") + chip(payload.status, payload.status === "failed" ? "bad" : payload.status === "completed" ? "good" : "") + '</div></div>'
|
|
1505
|
+
+ '<div class="big">' + esc(typeof payload.input_count === "number" ? payload.input_count : docs.length || "\u2014") + ' <span class="muted small">documents</span></div>'
|
|
1506
|
+
+ '<div class="grid">'
|
|
1507
|
+
+ '<div class="kv"><span class="k">Spec</span> <span class="val">' + idChip(payload.spec_id) + '</span></div>'
|
|
1508
|
+
+ '<div class="kv"><span class="k">Pipeline</span> <span class="val">' + idChip(payload.pipeline_id) + '</span></div>'
|
|
1509
|
+
+ '<div class="kv"><span class="k">Run</span> <span class="val">' + idChip(payload.run_id) + '</span></div>'
|
|
1510
|
+
+ '<div class="kv"><span class="k">Enqueued</span> <span class="val">' + esc(payload.enqueued_documents != null ? payload.enqueued_documents : "\u2014") + '</span></div>'
|
|
1511
|
+
+ '</div>'
|
|
1512
|
+
+ (payload.message ? '<div class="muted small" style="margin-top:8px">' + esc(payload.message) + '</div>' : "")
|
|
1513
|
+
+ '<div class="small" style="margin-top:8px">Poll with talonic_get_run (' + esc(pollArg) + ') every 5\u201310 s, then talonic_get_run_results.</div>'
|
|
1514
|
+
+ docHtml;
|
|
1515
|
+
`;
|
|
1516
|
+
var WIDGET_HTML23 = buildWidgetHtml({ title: "Talonic \u2014 Run Started", renderBody: RENDER_BODY23 });
|
|
1517
|
+
|
|
1518
|
+
// src/widgets/run-status.ts
|
|
1519
|
+
function getRunStatusWidgetHtml() {
|
|
1520
|
+
return WIDGET_HTML24;
|
|
1521
|
+
}
|
|
1522
|
+
var CSS2 = `
|
|
1523
|
+
.progress { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
|
|
1524
|
+
.progress .bar { width: 160px; height: 8px; }
|
|
1525
|
+
`;
|
|
1526
|
+
var RENDER_BODY24 = `
|
|
1527
|
+
if (!payload || typeof payload !== "object" || (!payload.pipeline_id && !payload.run_id)) { empty("No run to show."); return; }
|
|
1528
|
+
function tone(s) { return s === "completed" ? "good" : s === "failed" ? "bad" : "info"; }
|
|
1529
|
+
var status = typeof payload.status === "string" ? payload.status : "processing";
|
|
1530
|
+
var pr = payload.progress && typeof payload.progress === "object" ? payload.progress : {};
|
|
1531
|
+
var total = typeof pr.total_documents === "number" ? pr.total_documents : null;
|
|
1532
|
+
var done = typeof pr.completed_documents === "number" ? pr.completed_documents : null;
|
|
1533
|
+
var errs = typeof pr.error_documents === "number" ? pr.error_documents : null;
|
|
1534
|
+
var pct = total == null ? 0 : (total > 0 ? Math.max(0, Math.min(100, Math.round(((done || 0) / total) * 100))) : (status === "completed" ? 100 : 0));
|
|
1535
|
+
var totalText = total == null ? "\u2014" : String(total);
|
|
1536
|
+
var doneText = done == null ? "\u2014" : String(done);
|
|
1537
|
+
var phases = Array.isArray(pr.phases) ? pr.phases : [];
|
|
1538
|
+
var docs = Array.isArray(payload.documents) ? payload.documents : [];
|
|
1539
|
+
var pending = Array.isArray(pr.finalization_pending) ? pr.finalization_pending : [];
|
|
1540
|
+
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>'
|
|
1541
|
+
+ 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("")
|
|
1542
|
+
+ '</tbody></table></div>' : "";
|
|
1543
|
+
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>'
|
|
1544
|
+
+ 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("")
|
|
1545
|
+
+ '</tbody></table></div>' : "";
|
|
1546
|
+
root.innerHTML = ''
|
|
1547
|
+
+ '<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>'
|
|
1548
|
+
+ '<div>' + chip(status, tone(status)) + '</div></div>'
|
|
1549
|
+
+ '<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>'
|
|
1550
|
+
+ (pending.length ? '<div class="muted small" style="margin-top:6px">Finalizing: ' + esc(pending.join(", ")) + '</div>' : "")
|
|
1551
|
+
+ (payload.error_message ? '<div class="small" style="margin-top:8px;color:var(--bad)">' + esc(payload.error_message) + '</div>' : "")
|
|
1552
|
+
+ phaseHtml + docHtml;
|
|
1553
|
+
`;
|
|
1554
|
+
var WIDGET_HTML24 = buildWidgetHtml({
|
|
1555
|
+
title: "Talonic \u2014 Run Progress",
|
|
1556
|
+
css: CSS2,
|
|
1557
|
+
renderBody: RENDER_BODY24
|
|
1558
|
+
});
|
|
1559
|
+
|
|
1560
|
+
// src/widgets/run-results.ts
|
|
1561
|
+
function getRunResultsWidgetHtml() {
|
|
1562
|
+
return WIDGET_HTML25;
|
|
1563
|
+
}
|
|
1564
|
+
var RENDER_BODY25 = `
|
|
1565
|
+
if (!payload || typeof payload !== "object") { empty("No result rows yet."); return; }
|
|
1566
|
+
var cols = Array.isArray(payload.columns) ? payload.columns.filter(function (c) { return c && typeof c === "object"; }) : [];
|
|
1567
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1568
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1569
|
+
if (!rows.length) { empty("No result rows yet."); return; }
|
|
1570
|
+
function tone(s) { return s === "complete" || s === "completed" ? "good" : s === "error" ? "bad" : s === "partial" ? "warn" : "info"; }
|
|
1571
|
+
var shownCols = cols.slice(0, 10);
|
|
1572
|
+
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>';
|
|
1573
|
+
var body = rows.slice(0, 50).map(function (r) {
|
|
1574
|
+
r = r && typeof r === "object" ? r : {};
|
|
1575
|
+
var f = r.fields && typeof r.fields === "object" ? r.fields : {};
|
|
1576
|
+
return '<tr><td class="val">' + esc(r.filename || shortId(r.document_id)) + '</td><td>' + chip(r.status, tone(r.status)) + '</td>'
|
|
1577
|
+
+ 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>';
|
|
1578
|
+
}).join("");
|
|
1579
|
+
var total = typeof pg.total === "number" ? pg.total : rows.length;
|
|
1580
|
+
var held = typeof payload.pending_review_count === "number" ? payload.pending_review_count : 0;
|
|
1581
|
+
var more = [];
|
|
1582
|
+
if (rows.length > 50) more.push("+" + (rows.length - 50) + " more rows");
|
|
1583
|
+
if (cols.length > 10) more.push("+" + (cols.length - 10) + " more columns");
|
|
1584
|
+
root.innerHTML = ''
|
|
1585
|
+
+ '<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>'
|
|
1586
|
+
+ '<div>' + chip(payload.status, payload.status === "completed" ? "good" : payload.status === "failed" ? "bad" : "info") + (held ? chip(held + " held for review", "warn") : "") + '</div></div>'
|
|
1587
|
+
+ '<table><thead>' + head + '</thead><tbody>' + body + '</tbody></table>'
|
|
1588
|
+
+ (more.length ? '<div class="muted small" style="margin-top:6px">' + esc(more.join(" \xB7 ")) + '</div>' : "");
|
|
1589
|
+
`;
|
|
1590
|
+
var WIDGET_HTML25 = buildWidgetHtml({ title: "Talonic \u2014 Run Results", renderBody: RENDER_BODY25 });
|
|
1591
|
+
|
|
1592
|
+
// src/widgets/answer.ts
|
|
1593
|
+
function getAnswerWidgetHtml() {
|
|
1594
|
+
return ANSWER_HTML;
|
|
1595
|
+
}
|
|
1596
|
+
function getAnswerPolledWidgetHtml() {
|
|
1597
|
+
return POLLED_HTML;
|
|
1598
|
+
}
|
|
1599
|
+
var CSS3 = `
|
|
1600
|
+
.cite { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--border); }
|
|
1601
|
+
.cite:last-child { border-bottom: none; }
|
|
1602
|
+
pre.md.answer { max-height: 480px; font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, sans-serif; }
|
|
1603
|
+
`;
|
|
1604
|
+
var ANSWER_BODY = `
|
|
1605
|
+
if (!payload || typeof payload !== "object" || !payload.ask_id) { empty("No answer."); return; }
|
|
1606
|
+
var status = typeof payload.status === "string" ? payload.status : "processing";
|
|
1607
|
+
function obj(x) { return x && typeof x === "object" ? x : {}; }
|
|
1608
|
+
var ver = obj(payload.verification);
|
|
1609
|
+
var usage = obj(payload.usage);
|
|
1610
|
+
var cites = Array.isArray(payload.citations) ? payload.citations : [];
|
|
1611
|
+
var arts = Array.isArray(payload.artifacts) ? payload.artifacts : [];
|
|
1612
|
+
var verdictTone = ver.verdict === "supported" ? "good" : ver.verdict === "issues" ? "warn" : ver.verdict === "unverifiable" ? "bad" : "";
|
|
1613
|
+
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>'
|
|
1614
|
+
+ '<div>' + (status === "completed" ? chip(ver.verdict, verdictTone) : chip(status, status === "error" ? "bad" : "info")) + '</div></div>';
|
|
1615
|
+
if (status === "processing") {
|
|
1616
|
+
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>';
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
var answer = typeof payload.answer === "string" ? payload.answer : (payload.answer == null ? "" : fmt(payload.answer));
|
|
1620
|
+
var citeHtml = cites.length ? '<div class="plane"><div class="subtitle">Citations (' + cites.length + ')</div>' + cites.slice(0, 20).map(function (c, i) {
|
|
1621
|
+
c = obj(c);
|
|
1622
|
+
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>';
|
|
1623
|
+
}).join("") + '</div>' : "";
|
|
1624
|
+
var artHtml = arts.length ? '<div class="plane"><div class="subtitle">Artifacts (' + arts.length + ')</div>' + arts.slice(0, 10).map(function (a) {
|
|
1625
|
+
a = obj(a);
|
|
1626
|
+
var link = typeof a.link === "string" && /^https:\\/\\//.test(a.link) ? a.link : "";
|
|
1627
|
+
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>';
|
|
1628
|
+
}).join("") + '</div>' : "";
|
|
1629
|
+
var tiles = [];
|
|
1630
|
+
if (typeof usage.credits_charged === "number") tiles.push(usage.credits_charged + " credits");
|
|
1631
|
+
if (typeof usage.tokens === "number") tiles.push(usage.tokens + " tokens");
|
|
1632
|
+
if (typeof payload.tool_calls === "number") tiles.push(payload.tool_calls + " tool call" + (payload.tool_calls === 1 ? "" : "s"));
|
|
1633
|
+
if (typeof payload.waited_ms === "number") tiles.push((payload.waited_ms / 1000).toFixed(1) + " s");
|
|
1634
|
+
if (typeof ver.checks_total === "number") tiles.push(ver.checks_total + " checks, " + (ver.checks_unsupported || 0) + " unsupported");
|
|
1635
|
+
root.innerHTML = head
|
|
1636
|
+
+ (answer ? '<pre class="md answer">' + esc(answer) + '</pre>' : '<div class="muted small">The agent returned no answer text.</div>')
|
|
1637
|
+
+ (ver.correction ? '<div class="small" style="margin-top:6px"><span class="muted">Correction:</span> ' + esc(ver.correction) + '</div>' : "")
|
|
1638
|
+
+ citeHtml + artHtml
|
|
1639
|
+
+ (tiles.length ? '<div class="muted small" style="margin-top:10px">' + esc(tiles.join(" \xB7 ")) + '</div>' : "");
|
|
1640
|
+
`;
|
|
1641
|
+
function answerWidget(headline, title) {
|
|
1642
|
+
return buildWidgetHtml({
|
|
1643
|
+
title,
|
|
1644
|
+
css: CSS3,
|
|
1645
|
+
renderBody: " var HEADLINE = " + JSON.stringify(headline) + ";\n" + ANSWER_BODY
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
var ANSWER_HTML = answerWidget("Answer", "Talonic \u2014 Answer");
|
|
1649
|
+
var POLLED_HTML = answerWidget("Answer (polled)", "Talonic \u2014 Answer (polled)");
|
|
1650
|
+
|
|
1651
|
+
// src/widgets/decision-task-shared.ts
|
|
1652
|
+
var DECISION_JS = `
|
|
1653
|
+
function decisionTone(s) {
|
|
1654
|
+
return s === "available" ? "info" : s === "claimed" || s === "submitted" ? "good" : s === "failed" || s === "timed_out" ? "bad" : s === "released" || s === "cancelled" ? "warn" : "";
|
|
1655
|
+
}
|
|
1656
|
+
function decisionMeta(p) {
|
|
1657
|
+
return '<div class="grid">'
|
|
1658
|
+
+ '<div class="kv"><span class="k">Run</span> <span class="val">' + idChip(p.run_id) + '</span></div>'
|
|
1659
|
+
+ '<div class="kv"><span class="k">App</span> <span class="val">' + idChip(p.app_id) + '</span></div>'
|
|
1660
|
+
+ '<div class="kv"><span class="k">Execution epoch</span> <span class="val">' + esc(p.execution_epoch != null ? p.execution_epoch : "\u2014") + '</span></div>'
|
|
1661
|
+
+ '<div class="kv"><span class="k">Claimed by</span> <span class="val">' + esc(p.claimed_by || "\u2014") + '</span></div>'
|
|
1662
|
+
+ '<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>'
|
|
1663
|
+
+ '<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>'
|
|
1664
|
+
+ '</div>';
|
|
1665
|
+
}
|
|
1666
|
+
`;
|
|
1667
|
+
|
|
1668
|
+
// src/widgets/decision-task-list.ts
|
|
1669
|
+
function getDecisionTaskListWidgetHtml() {
|
|
1670
|
+
return WIDGET_HTML26;
|
|
1671
|
+
}
|
|
1672
|
+
var RENDER_BODY26 = DECISION_JS + `
|
|
1673
|
+
if (!payload || typeof payload !== "object") { empty("No decision tasks for this app."); return; }
|
|
1674
|
+
var rows = Array.isArray(payload.data) ? payload.data : [];
|
|
1675
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1676
|
+
if (!rows.length) { empty("No decision tasks for this app."); return; }
|
|
1677
|
+
var body = rows.map(function (t) {
|
|
1678
|
+
t = t && typeof t === "object" ? t : {};
|
|
1679
|
+
return '<tr><td>' + idChip(t.id) + '</td><td>' + chip(t.status, decisionTone(t.status)) + '</td><td>' + idChip(t.run_id) + '</td>'
|
|
1680
|
+
+ '<td class="val num">' + esc(t.execution_epoch != null ? t.execution_epoch : "\u2014") + '</td>'
|
|
1681
|
+
+ '<td class="val">' + esc(t.lease_expires_at ? relTime(t.lease_expires_at) : "\u2014") + '</td>'
|
|
1682
|
+
+ '<td class="val">' + esc(t.sla_deadline_at ? relTime(t.sla_deadline_at) : "\u2014") + '</td></tr>';
|
|
1683
|
+
}).join("");
|
|
1684
|
+
var counts = Object.create(null);
|
|
1685
|
+
rows.forEach(function (t) { var s = t && typeof t === "object" && t.status ? t.status : "unknown"; counts[s] = (counts[s] || 0) + 1; });
|
|
1686
|
+
var summary = Object.keys(counts).map(function (s) { return chip(counts[s] + " " + s, decisionTone(s)); }).join("");
|
|
1687
|
+
var app = rows[0] && typeof rows[0] === "object" ? rows[0].app_id : null;
|
|
1688
|
+
root.innerHTML = ''
|
|
1689
|
+
+ '<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>'
|
|
1690
|
+
+ '<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>';
|
|
1691
|
+
`;
|
|
1692
|
+
var WIDGET_HTML26 = buildWidgetHtml({ title: "Talonic \u2014 Decision Tasks", renderBody: RENDER_BODY26 });
|
|
1693
|
+
|
|
1694
|
+
// src/widgets/decision-bundle.ts
|
|
1695
|
+
function getDecisionBundleWidgetHtml() {
|
|
1696
|
+
return WIDGET_HTML27;
|
|
1697
|
+
}
|
|
1698
|
+
var RENDER_BODY27 = DECISION_JS + `
|
|
1699
|
+
var task = payload && payload.task && typeof payload.task === "object" ? payload.task : null;
|
|
1700
|
+
if (!task || !task.id) { empty("No decision task was claimed."); return; }
|
|
1701
|
+
var contract = payload.output_contract;
|
|
1702
|
+
var precedents = Array.isArray(payload.precedents) ? payload.precedents : [];
|
|
1703
|
+
var pkg = payload.package && typeof payload.package === "object" ? payload.package : {};
|
|
1704
|
+
var docs = Array.isArray(pkg.documents) ? pkg.documents : [];
|
|
1705
|
+
var contractHtml = contract && typeof contract === "object" ? (isFlat(contract) ? kvTiles(contract) : jsonTree(contract)) : '<div class="muted small">No output contract on this task.</div>';
|
|
1706
|
+
var precHtml = precedents.length ? '<div class="plane"><div class="subtitle">Precedents (' + precedents.length + ')</div>' + precedents.slice(0, 5).map(function (p) {
|
|
1707
|
+
p = p && typeof p === "object" ? p : {};
|
|
1708
|
+
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>';
|
|
1709
|
+
}).join("") + '</div>' : "";
|
|
1710
|
+
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>' : "";
|
|
1711
|
+
root.innerHTML = ''
|
|
1712
|
+
+ '<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>'
|
|
1713
|
+
+ '<div class="big">' + esc(task.execution_epoch != null ? task.execution_epoch : "\u2014") + ' <span class="muted small">execution epoch</span></div>'
|
|
1714
|
+
+ '<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>'
|
|
1715
|
+
+ decisionMeta(task)
|
|
1716
|
+
+ '<div class="plane"><div class="subtitle">Output contract</div>' + contractHtml + '</div>'
|
|
1717
|
+
+ '<div class="plane"><div class="subtitle">Input package</div><div class="grid">'
|
|
1718
|
+
+ '<div class="kv"><span class="k">Kind</span> <span class="val">' + esc(pkg.package_kind || "\u2014") + '</span></div>'
|
|
1719
|
+
+ '<div class="kv"><span class="k">Records</span> <span class="val">' + esc(pkg.record_count != null ? pkg.record_count : "\u2014") + '</span></div>'
|
|
1720
|
+
+ '<div class="kv"><span class="k">Page size</span> <span class="val">' + esc(pkg.page_size != null ? pkg.page_size : "\u2014") + '</span></div>'
|
|
1721
|
+
+ '<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>'
|
|
1722
|
+
+ '</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>'
|
|
1723
|
+
+ precHtml + docHtml;
|
|
1724
|
+
`;
|
|
1725
|
+
var WIDGET_HTML27 = buildWidgetHtml({
|
|
1726
|
+
title: "Talonic \u2014 Decision Task Claimed",
|
|
1727
|
+
renderBody: RENDER_BODY27
|
|
1728
|
+
});
|
|
1729
|
+
|
|
1730
|
+
// src/widgets/decision-package.ts
|
|
1731
|
+
function getDecisionPackageWidgetHtml() {
|
|
1732
|
+
return WIDGET_HTML28;
|
|
1733
|
+
}
|
|
1734
|
+
var RENDER_BODY28 = `
|
|
1735
|
+
if (!payload || typeof payload !== "object" || !payload.task_id) { empty("No package page."); return; }
|
|
1736
|
+
var records = Array.isArray(payload.data) ? payload.data : [];
|
|
1737
|
+
var pg = payload.pagination && typeof payload.pagination === "object" ? payload.pagination : {};
|
|
1738
|
+
var docs = Array.isArray(payload.documents) ? payload.documents : [];
|
|
1739
|
+
var body = !records.length ? '<div class="empty">This page has no records.</div>' : (isRowArray(records) ? dataTable(records) : jsonTree(records));
|
|
1740
|
+
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>' : "";
|
|
1741
|
+
root.innerHTML = ''
|
|
1742
|
+
+ '<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>'
|
|
1743
|
+
+ '<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>'
|
|
1744
|
+
+ body
|
|
1745
|
+
+ (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>' : "")
|
|
1746
|
+
+ '<div class="small" style="margin-top:8px">Copy evidence locators verbatim from these records into talonic_submit_decision_task.</div>'
|
|
1747
|
+
+ docHtml;
|
|
1748
|
+
`;
|
|
1749
|
+
var WIDGET_HTML28 = buildWidgetHtml({
|
|
1750
|
+
title: "Talonic \u2014 Decision Package",
|
|
1751
|
+
renderBody: RENDER_BODY28
|
|
1752
|
+
});
|
|
1753
|
+
|
|
1754
|
+
// src/widgets/decision-task-card.ts
|
|
1755
|
+
function getDecisionHeartbeatWidgetHtml() {
|
|
1756
|
+
return HEARTBEAT_HTML2;
|
|
1757
|
+
}
|
|
1758
|
+
function getDecisionSubmittedWidgetHtml() {
|
|
1759
|
+
return SUBMITTED_HTML;
|
|
1760
|
+
}
|
|
1761
|
+
function getDecisionReleasedWidgetHtml() {
|
|
1762
|
+
return RELEASED_HTML;
|
|
1763
|
+
}
|
|
1764
|
+
function getDecisionFailedWidgetHtml() {
|
|
1765
|
+
return FAILED_HTML;
|
|
1766
|
+
}
|
|
1767
|
+
var CARD_BODY = `
|
|
1768
|
+
if (!payload || typeof payload !== "object" || !payload.id) { empty("No decision task."); return; }
|
|
1769
|
+
root.innerHTML = ''
|
|
1770
|
+
+ '<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>'
|
|
1771
|
+
+ '<div>' + chip(payload.status, decisionTone(payload.status)) + '</div></div>'
|
|
1772
|
+
+ '<div class="small">' + NOTE + '</div>'
|
|
1773
|
+
+ decisionMeta(payload);
|
|
1774
|
+
`;
|
|
1775
|
+
function card(headline, note, title) {
|
|
1776
|
+
return buildWidgetHtml({
|
|
1777
|
+
title,
|
|
1778
|
+
renderBody: DECISION_JS + " var HEADLINE = " + JSON.stringify(headline) + ";\n var NOTE = " + JSON.stringify(note) + ";\n" + CARD_BODY
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
var HEARTBEAT_HTML2 = card(
|
|
1782
|
+
"Lease extended",
|
|
1783
|
+
"Keep heartbeating before the lease expires; the SLA deadline is the hard stop.",
|
|
1784
|
+
"Talonic \u2014 Decision Task Lease"
|
|
1785
|
+
);
|
|
1786
|
+
var SUBMITTED_HTML = card(
|
|
1787
|
+
"Decision submitted",
|
|
1788
|
+
"The platform verified the decision and resumes the run.",
|
|
1789
|
+
"Talonic \u2014 Decision Submitted"
|
|
1790
|
+
);
|
|
1791
|
+
var RELEASED_HTML = card(
|
|
1792
|
+
"Task released",
|
|
1793
|
+
"The task is available again for another claimant; the next claim bumps the epoch.",
|
|
1794
|
+
"Talonic \u2014 Decision Task Released"
|
|
1795
|
+
);
|
|
1796
|
+
var FAILED_HTML = card(
|
|
1797
|
+
"Task failed",
|
|
1798
|
+
"A Human Review was raised with your reason and the app's fallback policy applies.",
|
|
1799
|
+
"Talonic \u2014 Decision Task Failed"
|
|
1800
|
+
);
|
|
1801
|
+
|
|
1802
|
+
// src/widgets/register.ts
|
|
1803
|
+
var WIDGET_REGISTRY = {
|
|
1804
|
+
extract: {
|
|
1805
|
+
name: "extraction-result-widget",
|
|
1806
|
+
title: "Talonic Extraction Result",
|
|
1807
|
+
html: getExtractionResultWidgetHtml
|
|
1808
|
+
},
|
|
1809
|
+
search: {
|
|
722
1810
|
name: "search-results-widget",
|
|
723
|
-
uri: WIDGET_URIS.search,
|
|
724
1811
|
title: "Talonic Search Results",
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
registerWidget(server, {
|
|
1812
|
+
html: getSearchResultsWidgetHtml
|
|
1813
|
+
},
|
|
1814
|
+
filter: {
|
|
729
1815
|
name: "filter-results-widget",
|
|
730
|
-
uri: WIDGET_URIS.filter,
|
|
731
1816
|
title: "Talonic Filter Results",
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
registerWidget(server, {
|
|
1817
|
+
html: getFilterResultsWidgetHtml
|
|
1818
|
+
},
|
|
1819
|
+
getDocument: {
|
|
736
1820
|
name: "document-meta-widget",
|
|
737
|
-
uri: WIDGET_URIS.getDocument,
|
|
738
1821
|
title: "Talonic Document",
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
registerWidget(server, {
|
|
1822
|
+
html: getDocumentMetaWidgetHtml
|
|
1823
|
+
},
|
|
1824
|
+
toMarkdown: {
|
|
743
1825
|
name: "markdown-view-widget",
|
|
744
|
-
uri: WIDGET_URIS.toMarkdown,
|
|
745
1826
|
title: "Talonic Markdown",
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
registerWidget(server, {
|
|
1827
|
+
html: getMarkdownViewWidgetHtml
|
|
1828
|
+
},
|
|
1829
|
+
listSchemas: {
|
|
750
1830
|
name: "schema-list-widget",
|
|
751
|
-
uri: WIDGET_URIS.listSchemas,
|
|
752
1831
|
title: "Talonic Schemas",
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
registerWidget(server, {
|
|
1832
|
+
html: getSchemaListWidgetHtml
|
|
1833
|
+
},
|
|
1834
|
+
saveSchema: {
|
|
757
1835
|
name: "schema-saved-widget",
|
|
758
|
-
uri: WIDGET_URIS.saveSchema,
|
|
759
1836
|
title: "Talonic Schema Saved",
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
title: "Talonic Balance",
|
|
767
|
-
description: "Inline view of the workspace credit balance, tier, burn, and runway.",
|
|
768
|
-
html: getBalanceWidgetHtml()
|
|
769
|
-
});
|
|
770
|
-
registerWidget(server, {
|
|
771
|
-
name: "pricing-widget",
|
|
772
|
-
uri: WIDGET_URIS.getPricing,
|
|
773
|
-
title: "Talonic Pricing",
|
|
774
|
-
description: "Inline view of the credit pricing catalog: per-unit rates, EUR values, and multipliers.",
|
|
775
|
-
html: getPricingWidgetHtml()
|
|
776
|
-
});
|
|
777
|
-
registerWidget(server, {
|
|
778
|
-
name: "usage-widget",
|
|
779
|
-
uri: WIDGET_URIS.getUsage,
|
|
780
|
-
title: "Talonic Usage",
|
|
781
|
-
description: "Inline breakdown of credit consumption per function over the trailing window.",
|
|
782
|
-
html: getUsageWidgetHtml()
|
|
783
|
-
});
|
|
784
|
-
registerWidget(server, {
|
|
1837
|
+
html: getSchemaSavedWidgetHtml
|
|
1838
|
+
},
|
|
1839
|
+
getBalance: { name: "balance-widget", title: "Talonic Balance", html: getBalanceWidgetHtml },
|
|
1840
|
+
getPricing: { name: "pricing-widget", title: "Talonic Pricing", html: getPricingWidgetHtml },
|
|
1841
|
+
getUsage: { name: "usage-widget", title: "Talonic Usage", html: getUsageWidgetHtml },
|
|
1842
|
+
requestUpload: {
|
|
785
1843
|
name: "upload-link-widget",
|
|
786
|
-
uri: WIDGET_URIS.requestUpload,
|
|
787
1844
|
title: "Talonic Upload Link",
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
1845
|
+
html: getUploadLinkWidgetHtml
|
|
1846
|
+
},
|
|
1847
|
+
listFields: {
|
|
1848
|
+
name: "field-list-widget",
|
|
1849
|
+
title: "Talonic Field Registry",
|
|
1850
|
+
html: getFieldListWidgetHtml
|
|
1851
|
+
},
|
|
1852
|
+
getField: {
|
|
1853
|
+
name: "field-card-widget",
|
|
1854
|
+
title: "Talonic Field Card",
|
|
1855
|
+
html: getFieldCardWidgetHtml
|
|
1856
|
+
},
|
|
1857
|
+
fieldValues: {
|
|
1858
|
+
name: "field-values-widget",
|
|
1859
|
+
title: "Talonic Field Values",
|
|
1860
|
+
html: getFieldValuesWidgetHtml
|
|
1861
|
+
},
|
|
1862
|
+
findData: { name: "find-data-widget", title: "Talonic Find Data", html: getFindDataWidgetHtml },
|
|
1863
|
+
listAgentTools: {
|
|
1864
|
+
name: "agent-tools-widget",
|
|
1865
|
+
title: "Talonic Agent Tools",
|
|
1866
|
+
html: getAgentToolsWidgetHtml
|
|
1867
|
+
},
|
|
1868
|
+
invokeAgentTool: {
|
|
1869
|
+
name: "agent-tool-result-widget",
|
|
1870
|
+
title: "Talonic Agent Tool Result",
|
|
1871
|
+
html: getAgentToolResultWidgetHtml
|
|
1872
|
+
},
|
|
1873
|
+
listAgentTasks: {
|
|
1874
|
+
name: "agent-task-list-widget",
|
|
1875
|
+
title: "Talonic Agent Tasks",
|
|
1876
|
+
html: getAgentTaskListWidgetHtml
|
|
1877
|
+
},
|
|
1878
|
+
getAgentTask: {
|
|
1879
|
+
name: "agent-task-widget",
|
|
1880
|
+
title: "Talonic Agent Task",
|
|
1881
|
+
html: getAgentTaskWidgetHtml
|
|
1882
|
+
},
|
|
1883
|
+
claimAgentTask: {
|
|
1884
|
+
name: "agent-task-claim-widget",
|
|
1885
|
+
title: "Talonic Agent Task Claimed",
|
|
1886
|
+
html: getAgentTaskClaimWidgetHtml
|
|
1887
|
+
},
|
|
1888
|
+
heartbeatAgentTask: {
|
|
1889
|
+
name: "agent-task-heartbeat-widget",
|
|
1890
|
+
title: "Talonic Agent Task Lease",
|
|
1891
|
+
html: getAgentTaskHeartbeatWidgetHtml
|
|
1892
|
+
},
|
|
1893
|
+
submitAgentTask: {
|
|
1894
|
+
name: "agent-task-submitted-widget",
|
|
1895
|
+
title: "Talonic Agent Task Submitted",
|
|
1896
|
+
html: getAgentTaskSubmittedWidgetHtml
|
|
1897
|
+
},
|
|
1898
|
+
listSpecs: { name: "spec-list-widget", title: "Talonic Specs", html: getSpecListWidgetHtml },
|
|
1899
|
+
getSpec: { name: "spec-card-widget", title: "Talonic Spec", html: getSpecCardWidgetHtml },
|
|
1900
|
+
runSpec: {
|
|
1901
|
+
name: "run-started-widget",
|
|
1902
|
+
title: "Talonic Run Started",
|
|
1903
|
+
html: getRunStartedWidgetHtml
|
|
1904
|
+
},
|
|
1905
|
+
getRun: {
|
|
1906
|
+
name: "run-status-widget",
|
|
1907
|
+
title: "Talonic Run Progress",
|
|
1908
|
+
html: getRunStatusWidgetHtml
|
|
1909
|
+
},
|
|
1910
|
+
getRunResults: {
|
|
1911
|
+
name: "run-results-widget",
|
|
1912
|
+
title: "Talonic Run Results",
|
|
1913
|
+
html: getRunResultsWidgetHtml
|
|
1914
|
+
},
|
|
1915
|
+
ask: { name: "answer-widget", title: "Talonic Answer", html: getAnswerWidgetHtml },
|
|
1916
|
+
getAnswer: {
|
|
1917
|
+
name: "answer-polled-widget",
|
|
1918
|
+
title: "Talonic Answer (polled)",
|
|
1919
|
+
html: getAnswerPolledWidgetHtml
|
|
1920
|
+
},
|
|
1921
|
+
listDecisionTasks: {
|
|
1922
|
+
name: "decision-task-list-widget",
|
|
1923
|
+
title: "Talonic Decision Tasks",
|
|
1924
|
+
html: getDecisionTaskListWidgetHtml
|
|
1925
|
+
},
|
|
1926
|
+
claimDecisionTask: {
|
|
1927
|
+
name: "decision-bundle-widget",
|
|
1928
|
+
title: "Talonic Decision Task Claimed",
|
|
1929
|
+
html: getDecisionBundleWidgetHtml
|
|
1930
|
+
},
|
|
1931
|
+
readDecisionPackage: {
|
|
1932
|
+
name: "decision-package-widget",
|
|
1933
|
+
title: "Talonic Decision Package",
|
|
1934
|
+
html: getDecisionPackageWidgetHtml
|
|
1935
|
+
},
|
|
1936
|
+
heartbeatDecisionTask: {
|
|
1937
|
+
name: "decision-task-heartbeat-widget",
|
|
1938
|
+
title: "Talonic Decision Task Lease",
|
|
1939
|
+
html: getDecisionHeartbeatWidgetHtml
|
|
1940
|
+
},
|
|
1941
|
+
submitDecisionTask: {
|
|
1942
|
+
name: "decision-task-submitted-widget",
|
|
1943
|
+
title: "Talonic Decision Submitted",
|
|
1944
|
+
html: getDecisionSubmittedWidgetHtml
|
|
1945
|
+
},
|
|
1946
|
+
releaseDecisionTask: {
|
|
1947
|
+
name: "decision-task-released-widget",
|
|
1948
|
+
title: "Talonic Decision Task Released",
|
|
1949
|
+
html: getDecisionReleasedWidgetHtml
|
|
1950
|
+
},
|
|
1951
|
+
failDecisionTask: {
|
|
1952
|
+
name: "decision-task-failed-widget",
|
|
1953
|
+
title: "Talonic Decision Task Failed",
|
|
1954
|
+
html: getDecisionFailedWidgetHtml
|
|
803
1955
|
}
|
|
804
|
-
|
|
1956
|
+
};
|
|
1957
|
+
function getWidgetTemplateHtml(uri) {
|
|
1958
|
+
const key = widgetKeyForUri(uri);
|
|
1959
|
+
return key ? WIDGET_REGISTRY[key].html() : void 0;
|
|
805
1960
|
}
|
|
806
|
-
function
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
content: [{ type: "text", text: `Validation error: ${message}` }]
|
|
810
|
-
};
|
|
1961
|
+
function getWidgetTemplateMeta(uri) {
|
|
1962
|
+
const key = widgetKeyForUri(uri);
|
|
1963
|
+
return key ? widgetMeta(WIDGET_DESCRIPTIONS[key]) : void 0;
|
|
811
1964
|
}
|
|
812
|
-
function
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
]
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
}
|
|
825
|
-
return {
|
|
826
|
-
isError: true,
|
|
827
|
-
content: [
|
|
828
|
-
{
|
|
829
|
-
type: "text",
|
|
830
|
-
text: `Unexpected error: ${err instanceof Error ? err.message : String(err)}`
|
|
831
|
-
}
|
|
832
|
-
]
|
|
833
|
-
};
|
|
1965
|
+
function registerOne(server, key) {
|
|
1966
|
+
const entry = WIDGET_REGISTRY[key];
|
|
1967
|
+
registerWidget(server, {
|
|
1968
|
+
name: entry.name,
|
|
1969
|
+
uri: WIDGET_URIS[key],
|
|
1970
|
+
title: entry.title,
|
|
1971
|
+
description: WIDGET_DESCRIPTIONS[key],
|
|
1972
|
+
html: entry.html()
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
function registerWidgets(server) {
|
|
1976
|
+
for (const key of Object.keys(WIDGET_REGISTRY)) registerOne(server, key);
|
|
834
1977
|
}
|
|
835
|
-
|
|
836
|
-
// src/tools/extract.ts
|
|
837
1978
|
var DESCRIPTION = [
|
|
838
1979
|
"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.",
|
|
839
1980
|
"",
|
|
@@ -1008,10 +2149,7 @@ function registerExtract(server, getTalonic) {
|
|
|
1008
2149
|
destructiveHint: false,
|
|
1009
2150
|
openWorldHint: true
|
|
1010
2151
|
},
|
|
1011
|
-
_meta:
|
|
1012
|
-
ui: { resourceUri: EXTRACTION_RESULT_WIDGET_URI },
|
|
1013
|
-
"openai/outputTemplate": EXTRACTION_RESULT_WIDGET_URI
|
|
1014
|
-
}
|
|
2152
|
+
_meta: widgetToolMeta("extract")
|
|
1015
2153
|
},
|
|
1016
2154
|
async (args) => handleExtract(getTalonic(), args)
|
|
1017
2155
|
);
|
|
@@ -1140,10 +2278,7 @@ function registerFilter(server, getTalonic) {
|
|
|
1140
2278
|
destructiveHint: false,
|
|
1141
2279
|
openWorldHint: false
|
|
1142
2280
|
},
|
|
1143
|
-
_meta:
|
|
1144
|
-
ui: { resourceUri: WIDGET_URIS.filter },
|
|
1145
|
-
"openai/outputTemplate": WIDGET_URIS.filter
|
|
1146
|
-
}
|
|
2281
|
+
_meta: widgetToolMeta("filter")
|
|
1147
2282
|
},
|
|
1148
2283
|
async (args) => handleFilter(getTalonic(), args)
|
|
1149
2284
|
);
|
|
@@ -1189,10 +2324,7 @@ function registerGetBalance(server, getTalonic) {
|
|
|
1189
2324
|
destructiveHint: false,
|
|
1190
2325
|
openWorldHint: false
|
|
1191
2326
|
},
|
|
1192
|
-
_meta:
|
|
1193
|
-
ui: { resourceUri: WIDGET_URIS.getBalance },
|
|
1194
|
-
"openai/outputTemplate": WIDGET_URIS.getBalance
|
|
1195
|
-
}
|
|
2327
|
+
_meta: widgetToolMeta("getBalance")
|
|
1196
2328
|
},
|
|
1197
2329
|
async () => handleGetBalance(getTalonic())
|
|
1198
2330
|
);
|
|
@@ -1244,10 +2376,7 @@ function registerGetPricing(server, getTalonic) {
|
|
|
1244
2376
|
destructiveHint: false,
|
|
1245
2377
|
openWorldHint: false
|
|
1246
2378
|
},
|
|
1247
|
-
_meta:
|
|
1248
|
-
ui: { resourceUri: WIDGET_URIS.getPricing },
|
|
1249
|
-
"openai/outputTemplate": WIDGET_URIS.getPricing
|
|
1250
|
-
}
|
|
2379
|
+
_meta: widgetToolMeta("getPricing")
|
|
1251
2380
|
},
|
|
1252
2381
|
async () => handleGetPricing(getTalonic())
|
|
1253
2382
|
);
|
|
@@ -1296,10 +2425,7 @@ function registerGetUsage(server, getTalonic) {
|
|
|
1296
2425
|
destructiveHint: false,
|
|
1297
2426
|
openWorldHint: false
|
|
1298
2427
|
},
|
|
1299
|
-
_meta:
|
|
1300
|
-
ui: { resourceUri: WIDGET_URIS.getUsage },
|
|
1301
|
-
"openai/outputTemplate": WIDGET_URIS.getUsage
|
|
1302
|
-
}
|
|
2428
|
+
_meta: widgetToolMeta("getUsage")
|
|
1303
2429
|
},
|
|
1304
2430
|
async (args) => handleGetUsage(getTalonic(), args.days)
|
|
1305
2431
|
);
|
|
@@ -1390,10 +2516,7 @@ function registerGetDocument(server, getTalonic) {
|
|
|
1390
2516
|
destructiveHint: false,
|
|
1391
2517
|
openWorldHint: false
|
|
1392
2518
|
},
|
|
1393
|
-
_meta:
|
|
1394
|
-
ui: { resourceUri: WIDGET_URIS.getDocument },
|
|
1395
|
-
"openai/outputTemplate": WIDGET_URIS.getDocument
|
|
1396
|
-
}
|
|
2519
|
+
_meta: widgetToolMeta("getDocument")
|
|
1397
2520
|
},
|
|
1398
2521
|
async (args) => handleGetDocument(getTalonic(), args)
|
|
1399
2522
|
);
|
|
@@ -1463,10 +2586,7 @@ function registerListSchemas(server, getTalonic) {
|
|
|
1463
2586
|
destructiveHint: false,
|
|
1464
2587
|
openWorldHint: false
|
|
1465
2588
|
},
|
|
1466
|
-
_meta:
|
|
1467
|
-
ui: { resourceUri: WIDGET_URIS.listSchemas },
|
|
1468
|
-
"openai/outputTemplate": WIDGET_URIS.listSchemas
|
|
1469
|
-
}
|
|
2589
|
+
_meta: widgetToolMeta("listSchemas")
|
|
1470
2590
|
},
|
|
1471
2591
|
async () => handleListSchemas(getTalonic())
|
|
1472
2592
|
);
|
|
@@ -1530,10 +2650,7 @@ function registerSaveSchema(server, getTalonic) {
|
|
|
1530
2650
|
destructiveHint: false,
|
|
1531
2651
|
openWorldHint: false
|
|
1532
2652
|
},
|
|
1533
|
-
_meta:
|
|
1534
|
-
ui: { resourceUri: WIDGET_URIS.saveSchema },
|
|
1535
|
-
"openai/outputTemplate": WIDGET_URIS.saveSchema
|
|
1536
|
-
}
|
|
2653
|
+
_meta: widgetToolMeta("saveSchema")
|
|
1537
2654
|
},
|
|
1538
2655
|
async (args) => handleSaveSchema(getTalonic(), args)
|
|
1539
2656
|
);
|
|
@@ -1631,10 +2748,7 @@ function registerSearch(server, getTalonic) {
|
|
|
1631
2748
|
destructiveHint: false,
|
|
1632
2749
|
openWorldHint: false
|
|
1633
2750
|
},
|
|
1634
|
-
_meta:
|
|
1635
|
-
ui: { resourceUri: WIDGET_URIS.search },
|
|
1636
|
-
"openai/outputTemplate": WIDGET_URIS.search
|
|
1637
|
-
}
|
|
2751
|
+
_meta: widgetToolMeta("search")
|
|
1638
2752
|
},
|
|
1639
2753
|
async (args) => handleSearch(getTalonic(), args)
|
|
1640
2754
|
);
|
|
@@ -1663,7 +2777,7 @@ async function handleRequestUpload(getToken, baseUrl, args) {
|
|
|
1663
2777
|
try {
|
|
1664
2778
|
const base = baseUrl ?? "https://api.talonic.com";
|
|
1665
2779
|
const token = getToken();
|
|
1666
|
-
const res = await
|
|
2780
|
+
const res = await resolveFetch(getToken)(`${base}/v1/documents/upload-session`, {
|
|
1667
2781
|
method: "POST",
|
|
1668
2782
|
headers: {
|
|
1669
2783
|
Authorization: `Bearer ${token}`,
|
|
@@ -1702,22 +2816,19 @@ function registerRequestUpload(server, getToken, baseUrl) {
|
|
|
1702
2816
|
destructiveHint: false,
|
|
1703
2817
|
openWorldHint: false
|
|
1704
2818
|
},
|
|
1705
|
-
_meta:
|
|
1706
|
-
ui: { resourceUri: WIDGET_URIS.requestUpload },
|
|
1707
|
-
"openai/outputTemplate": WIDGET_URIS.requestUpload
|
|
1708
|
-
}
|
|
2819
|
+
_meta: widgetToolMeta("requestUpload")
|
|
1709
2820
|
},
|
|
1710
2821
|
async (args) => handleRequestUpload(getToken, baseUrl, args)
|
|
1711
2822
|
);
|
|
1712
2823
|
}
|
|
1713
|
-
var
|
|
2824
|
+
var DEFAULT_BASE2 = "https://api.talonic.com";
|
|
1714
2825
|
var RANGES = ["7d", "30d", "90d"];
|
|
1715
2826
|
async function growthGet(getToken, baseUrl, path, params) {
|
|
1716
2827
|
try {
|
|
1717
2828
|
const qs = new URLSearchParams();
|
|
1718
2829
|
for (const [k, v] of Object.entries(params)) if (v !== void 0 && v !== "") qs.set(k, v);
|
|
1719
|
-
const url = `${baseUrl ??
|
|
1720
|
-
const res = await
|
|
2830
|
+
const url = `${baseUrl ?? DEFAULT_BASE2}/v1/growth/${path}${qs.size ? `?${qs}` : ""}`;
|
|
2831
|
+
const res = await resolveFetch(getToken)(url, {
|
|
1721
2832
|
headers: { Authorization: `Bearer ${getToken()}`, Accept: "application/json" }
|
|
1722
2833
|
});
|
|
1723
2834
|
if (res.status === 403) {
|
|
@@ -1740,7 +2851,7 @@ async function growthGet(getToken, baseUrl, path, params) {
|
|
|
1740
2851
|
}
|
|
1741
2852
|
async function probeGrowthAccess(token, baseUrl) {
|
|
1742
2853
|
try {
|
|
1743
|
-
const res = await fetch(`${baseUrl ??
|
|
2854
|
+
const res = await fetch(`${baseUrl ?? DEFAULT_BASE2}/v1/growth/access`, {
|
|
1744
2855
|
headers: { Authorization: `Bearer ${token}`, Accept: "application/json" },
|
|
1745
2856
|
signal: AbortSignal.timeout(5e3)
|
|
1746
2857
|
});
|
|
@@ -1863,7 +2974,7 @@ function registerGrowthTools(server, getToken, baseUrl) {
|
|
|
1863
2974
|
async (args) => handleGrowthToolsUsage(getToken, baseUrl, args)
|
|
1864
2975
|
);
|
|
1865
2976
|
}
|
|
1866
|
-
var
|
|
2977
|
+
var DEFAULT_BASE3 = "https://api.talonic.com";
|
|
1867
2978
|
var TASK_STATUSES = ["available", "claimed", "submitted", "timed_out", "cancelled"];
|
|
1868
2979
|
var taskId = z.string().uuid().describe("Agent task UUID.");
|
|
1869
2980
|
var executionEpoch = z.number().int().min(1).max(2147483647).describe("Execution epoch returned by the successful claim. Stale epochs are rejected.");
|
|
@@ -1894,7 +3005,7 @@ var adminPayloadAccessInput = {
|
|
|
1894
3005
|
totp_code: adminTotp
|
|
1895
3006
|
};
|
|
1896
3007
|
function apiUrl(baseUrl, path, query) {
|
|
1897
|
-
const base = (baseUrl ??
|
|
3008
|
+
const base = (baseUrl ?? DEFAULT_BASE3).replace(/\/$/, "");
|
|
1898
3009
|
const url = new URL(`${base}${path}`);
|
|
1899
3010
|
for (const [key, value] of Object.entries(query ?? {})) {
|
|
1900
3011
|
if (value !== void 0 && value !== "") url.searchParams.set(key, String(value));
|
|
@@ -1903,7 +3014,7 @@ function apiUrl(baseUrl, path, query) {
|
|
|
1903
3014
|
}
|
|
1904
3015
|
async function agentTaskRequest(getToken, baseUrl, request) {
|
|
1905
3016
|
try {
|
|
1906
|
-
const response = await
|
|
3017
|
+
const response = await resolveFetch(getToken)(apiUrl(baseUrl, request.path, request.query), {
|
|
1907
3018
|
method: request.method ?? "GET",
|
|
1908
3019
|
headers: {
|
|
1909
3020
|
Authorization: `Bearer ${getToken()}`,
|
|
@@ -2076,7 +3187,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2076
3187
|
title: "List Agent Tasks",
|
|
2077
3188
|
description: DESCRIPTIONS.list,
|
|
2078
3189
|
inputSchema: listInput,
|
|
2079
|
-
annotations: { title: "List Agent Tasks", ...READ_ONLY2 }
|
|
3190
|
+
annotations: { title: "List Agent Tasks", ...READ_ONLY2 },
|
|
3191
|
+
_meta: widgetToolMeta("listAgentTasks")
|
|
2080
3192
|
},
|
|
2081
3193
|
async (args) => handleListAgentTasks(getToken, baseUrl, args)
|
|
2082
3194
|
);
|
|
@@ -2086,7 +3198,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2086
3198
|
title: "Get Agent Task",
|
|
2087
3199
|
description: DESCRIPTIONS.get,
|
|
2088
3200
|
inputSchema: idInput,
|
|
2089
|
-
annotations: { title: "Get Agent Task", ...READ_ONLY2 }
|
|
3201
|
+
annotations: { title: "Get Agent Task", ...READ_ONLY2 },
|
|
3202
|
+
_meta: widgetToolMeta("getAgentTask")
|
|
2090
3203
|
},
|
|
2091
3204
|
async (args) => handleGetAgentTask(getToken, baseUrl, args)
|
|
2092
3205
|
);
|
|
@@ -2096,7 +3209,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2096
3209
|
title: "Claim Agent Task",
|
|
2097
3210
|
description: DESCRIPTIONS.claim,
|
|
2098
3211
|
inputSchema: idInput,
|
|
2099
|
-
annotations: { title: "Claim Agent Task", ...MUTATING }
|
|
3212
|
+
annotations: { title: "Claim Agent Task", ...MUTATING },
|
|
3213
|
+
_meta: widgetToolMeta("claimAgentTask")
|
|
2100
3214
|
},
|
|
2101
3215
|
async (args) => handleClaimAgentTask(getToken, baseUrl, args)
|
|
2102
3216
|
);
|
|
@@ -2106,7 +3220,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2106
3220
|
title: "Heartbeat Agent Task",
|
|
2107
3221
|
description: DESCRIPTIONS.heartbeat,
|
|
2108
3222
|
inputSchema: heartbeatInput,
|
|
2109
|
-
annotations: { title: "Heartbeat Agent Task", ...MUTATING }
|
|
3223
|
+
annotations: { title: "Heartbeat Agent Task", ...MUTATING },
|
|
3224
|
+
_meta: widgetToolMeta("heartbeatAgentTask")
|
|
2110
3225
|
},
|
|
2111
3226
|
async (args) => handleHeartbeatAgentTask(getToken, baseUrl, args)
|
|
2112
3227
|
);
|
|
@@ -2116,7 +3231,8 @@ function registerAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2116
3231
|
title: "Submit Agent Task",
|
|
2117
3232
|
description: DESCRIPTIONS.submit,
|
|
2118
3233
|
inputSchema: submitInput,
|
|
2119
|
-
annotations: { title: "Submit Agent Task", ...MUTATING }
|
|
3234
|
+
annotations: { title: "Submit Agent Task", ...MUTATING },
|
|
3235
|
+
_meta: widgetToolMeta("submitAgentTask")
|
|
2120
3236
|
},
|
|
2121
3237
|
async (args) => handleSubmitAgentTask(getToken, baseUrl, args)
|
|
2122
3238
|
);
|
|
@@ -2189,43 +3305,6 @@ function registerAdminAgentTaskTools(server, getToken, baseUrl) {
|
|
|
2189
3305
|
async (args) => handleAdminSubmitAgentTask(getToken, baseUrl, args)
|
|
2190
3306
|
);
|
|
2191
3307
|
}
|
|
2192
|
-
|
|
2193
|
-
// src/tools/_http.ts
|
|
2194
|
-
var DEFAULT_BASE3 = "https://api.talonic.com";
|
|
2195
|
-
function buildUrl(baseUrl, path, params = {}) {
|
|
2196
|
-
const qs = new URLSearchParams();
|
|
2197
|
-
for (const [k, v] of Object.entries(params)) {
|
|
2198
|
-
if (v === void 0 || v === "") continue;
|
|
2199
|
-
qs.set(k, String(v));
|
|
2200
|
-
}
|
|
2201
|
-
return `${baseUrl ?? DEFAULT_BASE3}${path}${qs.size ? `?${qs}` : ""}`;
|
|
2202
|
-
}
|
|
2203
|
-
async function apiJson(getToken, baseUrl, method, path, opts = {}) {
|
|
2204
|
-
const url = buildUrl(baseUrl, path, opts.params);
|
|
2205
|
-
const res = await fetch(url, {
|
|
2206
|
-
method,
|
|
2207
|
-
headers: {
|
|
2208
|
-
Authorization: `Bearer ${getToken()}`,
|
|
2209
|
-
Accept: "application/json",
|
|
2210
|
-
...opts.body !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
2211
|
-
},
|
|
2212
|
-
...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {}
|
|
2213
|
-
});
|
|
2214
|
-
if (!res.ok) {
|
|
2215
|
-
const text = await res.text().catch(() => "");
|
|
2216
|
-
throw new Error(`Talonic API error: HTTP ${res.status}${text ? ` \u2014 ${text}` : ""}`);
|
|
2217
|
-
}
|
|
2218
|
-
return await res.json();
|
|
2219
|
-
}
|
|
2220
|
-
async function runTool(fn) {
|
|
2221
|
-
try {
|
|
2222
|
-
return jsonOk(await fn());
|
|
2223
|
-
} catch (err) {
|
|
2224
|
-
return toolError(err);
|
|
2225
|
-
}
|
|
2226
|
-
}
|
|
2227
|
-
|
|
2228
|
-
// src/tools/decision-tasks.ts
|
|
2229
3308
|
var DECIDE_SCOPE = "apps:decide";
|
|
2230
3309
|
function tokenHasDecideScope(token) {
|
|
2231
3310
|
if (token.startsWith("tlnc_")) return true;
|
|
@@ -2422,7 +3501,12 @@ var DESCRIPTIONS2 = {
|
|
|
2422
3501
|
function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
2423
3502
|
const invocable = options.invocable !== false;
|
|
2424
3503
|
const describe = (text) => invocable ? text : NOT_INVOCABLE_PREFIX + text;
|
|
2425
|
-
const
|
|
3504
|
+
const metaFor = (key) => ({
|
|
3505
|
+
_meta: {
|
|
3506
|
+
...widgetToolMeta(key),
|
|
3507
|
+
...invocable ? {} : { "talonic/can_invoke": false, "talonic/required_scope": DECIDE_SCOPE }
|
|
3508
|
+
}
|
|
3509
|
+
});
|
|
2426
3510
|
server.registerTool(
|
|
2427
3511
|
"talonic_list_decision_tasks",
|
|
2428
3512
|
{
|
|
@@ -2430,7 +3514,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2430
3514
|
description: describe(DESCRIPTIONS2.list),
|
|
2431
3515
|
inputSchema: listInput2,
|
|
2432
3516
|
annotations: { title: "List Decision Tasks", ...READ_ONLY3 },
|
|
2433
|
-
...
|
|
3517
|
+
...metaFor("listDecisionTasks")
|
|
2434
3518
|
},
|
|
2435
3519
|
async (args) => handleListDecisionTasks(getToken, baseUrl, args)
|
|
2436
3520
|
);
|
|
@@ -2441,7 +3525,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2441
3525
|
description: describe(DESCRIPTIONS2.claim),
|
|
2442
3526
|
inputSchema: idInput2,
|
|
2443
3527
|
annotations: { title: "Claim Decision Task", ...MUTATING2 },
|
|
2444
|
-
...
|
|
3528
|
+
...metaFor("claimDecisionTask")
|
|
2445
3529
|
},
|
|
2446
3530
|
async (args) => handleClaimDecisionTask(getToken, baseUrl, args)
|
|
2447
3531
|
);
|
|
@@ -2452,7 +3536,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2452
3536
|
description: describe(DESCRIPTIONS2.package),
|
|
2453
3537
|
inputSchema: packageInput,
|
|
2454
3538
|
annotations: { title: "Read Decision Package", ...READ_ONLY3 },
|
|
2455
|
-
...
|
|
3539
|
+
...metaFor("readDecisionPackage")
|
|
2456
3540
|
},
|
|
2457
3541
|
async (args) => handleReadDecisionPackage(getToken, baseUrl, args)
|
|
2458
3542
|
);
|
|
@@ -2463,7 +3547,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2463
3547
|
description: describe(DESCRIPTIONS2.heartbeat),
|
|
2464
3548
|
inputSchema: epochInput,
|
|
2465
3549
|
annotations: { title: "Heartbeat Decision Task", ...MUTATING2 },
|
|
2466
|
-
...
|
|
3550
|
+
...metaFor("heartbeatDecisionTask")
|
|
2467
3551
|
},
|
|
2468
3552
|
async (args) => handleHeartbeatDecisionTask(getToken, baseUrl, args)
|
|
2469
3553
|
);
|
|
@@ -2474,7 +3558,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2474
3558
|
description: describe(DESCRIPTIONS2.submit),
|
|
2475
3559
|
inputSchema: submitInput2,
|
|
2476
3560
|
annotations: { title: "Submit Decision Task", ...MUTATING2 },
|
|
2477
|
-
...
|
|
3561
|
+
...metaFor("submitDecisionTask")
|
|
2478
3562
|
},
|
|
2479
3563
|
async (args) => handleSubmitDecisionTask(getToken, baseUrl, args)
|
|
2480
3564
|
);
|
|
@@ -2485,7 +3569,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2485
3569
|
description: describe(DESCRIPTIONS2.release),
|
|
2486
3570
|
inputSchema: epochInput,
|
|
2487
3571
|
annotations: { title: "Release Decision Task", ...MUTATING2 },
|
|
2488
|
-
...
|
|
3572
|
+
...metaFor("releaseDecisionTask")
|
|
2489
3573
|
},
|
|
2490
3574
|
async (args) => handleReleaseDecisionTask(getToken, baseUrl, args)
|
|
2491
3575
|
);
|
|
@@ -2496,7 +3580,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
2496
3580
|
description: describe(DESCRIPTIONS2.fail),
|
|
2497
3581
|
inputSchema: failInput,
|
|
2498
3582
|
annotations: { title: "Fail Decision Task", ...MUTATING2 },
|
|
2499
|
-
...
|
|
3583
|
+
...metaFor("failDecisionTask")
|
|
2500
3584
|
},
|
|
2501
3585
|
async (args) => handleFailDecisionTask(getToken, baseUrl, args)
|
|
2502
3586
|
);
|
|
@@ -2597,10 +3681,7 @@ function registerToMarkdown(server, getTalonic) {
|
|
|
2597
3681
|
destructiveHint: false,
|
|
2598
3682
|
openWorldHint: true
|
|
2599
3683
|
},
|
|
2600
|
-
_meta:
|
|
2601
|
-
ui: { resourceUri: WIDGET_URIS.toMarkdown },
|
|
2602
|
-
"openai/outputTemplate": WIDGET_URIS.toMarkdown
|
|
2603
|
-
}
|
|
3684
|
+
_meta: widgetToolMeta("toMarkdown")
|
|
2604
3685
|
},
|
|
2605
3686
|
async (args) => handleToMarkdown(getTalonic(), args)
|
|
2606
3687
|
);
|
|
@@ -2674,7 +3755,7 @@ async function handleGetField(getToken, baseUrl, args) {
|
|
|
2674
3755
|
return validationError("Provide either `field_id` or `name`, not both.");
|
|
2675
3756
|
return runTool(async () => {
|
|
2676
3757
|
const { id, resolution } = await resolveFieldId(getToken, baseUrl, args);
|
|
2677
|
-
const
|
|
3758
|
+
const card2 = await apiJson(
|
|
2678
3759
|
getToken,
|
|
2679
3760
|
baseUrl,
|
|
2680
3761
|
"GET",
|
|
@@ -2683,7 +3764,7 @@ async function handleGetField(getToken, baseUrl, args) {
|
|
|
2683
3764
|
params: { follow_redirects: true }
|
|
2684
3765
|
}
|
|
2685
3766
|
);
|
|
2686
|
-
const out = { ...
|
|
3767
|
+
const out = { ...card2 };
|
|
2687
3768
|
if (resolution) out["resolution"] = resolution;
|
|
2688
3769
|
if (args.include_history) {
|
|
2689
3770
|
out["history"] = await apiJson(getToken, baseUrl, "GET", `/v1/fields/${id}/history`, {
|
|
@@ -2744,7 +3825,8 @@ function registerFieldTools(server, getToken, baseUrl) {
|
|
|
2744
3825
|
destructiveHint: false,
|
|
2745
3826
|
idempotentHint: true,
|
|
2746
3827
|
openWorldHint: false
|
|
2747
|
-
}
|
|
3828
|
+
},
|
|
3829
|
+
_meta: widgetToolMeta("listFields")
|
|
2748
3830
|
},
|
|
2749
3831
|
async (args) => handleListFields(getToken, baseUrl, args)
|
|
2750
3832
|
);
|
|
@@ -2759,7 +3841,8 @@ function registerFieldTools(server, getToken, baseUrl) {
|
|
|
2759
3841
|
destructiveHint: false,
|
|
2760
3842
|
idempotentHint: true,
|
|
2761
3843
|
openWorldHint: false
|
|
2762
|
-
}
|
|
3844
|
+
},
|
|
3845
|
+
_meta: widgetToolMeta("getField")
|
|
2763
3846
|
},
|
|
2764
3847
|
async (args) => handleGetField(getToken, baseUrl, args)
|
|
2765
3848
|
);
|
|
@@ -2774,7 +3857,8 @@ function registerFieldTools(server, getToken, baseUrl) {
|
|
|
2774
3857
|
destructiveHint: false,
|
|
2775
3858
|
idempotentHint: true,
|
|
2776
3859
|
openWorldHint: false
|
|
2777
|
-
}
|
|
3860
|
+
},
|
|
3861
|
+
_meta: widgetToolMeta("fieldValues")
|
|
2778
3862
|
},
|
|
2779
3863
|
async (args) => handleFieldValues(getToken, baseUrl, args)
|
|
2780
3864
|
);
|
|
@@ -2831,6 +3915,7 @@ async function handleFindData(getToken, baseUrl, args) {
|
|
|
2831
3915
|
}
|
|
2832
3916
|
var LIST_TOOLS_DESCRIPTION = [
|
|
2833
3917
|
"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.",
|
|
3918
|
+
"Target API: https://talonic.com/docs/api (GET /v1/agent/tools).",
|
|
2834
3919
|
"",
|
|
2835
3920
|
"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.",
|
|
2836
3921
|
"NOT FOR: discovering fields (talonic_list_fields / talonic_find_data) or documents (talonic_search) \u2014 those are shaped for you.",
|
|
@@ -2867,6 +3952,8 @@ async function handleListAgentTools(getToken, baseUrl, args) {
|
|
|
2867
3952
|
}
|
|
2868
3953
|
var INVOKE_DESCRIPTION = [
|
|
2869
3954
|
"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).",
|
|
3955
|
+
"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.",
|
|
3956
|
+
"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).",
|
|
2870
3957
|
"",
|
|
2871
3958
|
"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.",
|
|
2872
3959
|
"NOT FOR: anything a dedicated talonic_* tool already does (prefer those \u2014 they are shaped for you).",
|
|
@@ -2908,7 +3995,8 @@ function registerAgentRegistryTools(server, getToken, baseUrl) {
|
|
|
2908
3995
|
destructiveHint: false,
|
|
2909
3996
|
idempotentHint: true,
|
|
2910
3997
|
openWorldHint: false
|
|
2911
|
-
}
|
|
3998
|
+
},
|
|
3999
|
+
_meta: widgetToolMeta("findData")
|
|
2912
4000
|
},
|
|
2913
4001
|
async (args) => handleFindData(getToken, baseUrl, args)
|
|
2914
4002
|
);
|
|
@@ -2923,7 +4011,8 @@ function registerAgentRegistryTools(server, getToken, baseUrl) {
|
|
|
2923
4011
|
destructiveHint: false,
|
|
2924
4012
|
idempotentHint: true,
|
|
2925
4013
|
openWorldHint: false
|
|
2926
|
-
}
|
|
4014
|
+
},
|
|
4015
|
+
_meta: widgetToolMeta("listAgentTools")
|
|
2927
4016
|
},
|
|
2928
4017
|
async (args) => handleListAgentTools(getToken, baseUrl, args)
|
|
2929
4018
|
);
|
|
@@ -2938,15 +4027,487 @@ function registerAgentRegistryTools(server, getToken, baseUrl) {
|
|
|
2938
4027
|
destructiveHint: false,
|
|
2939
4028
|
idempotentHint: false,
|
|
2940
4029
|
openWorldHint: false
|
|
2941
|
-
}
|
|
4030
|
+
},
|
|
4031
|
+
_meta: widgetToolMeta("invokeAgentTool")
|
|
2942
4032
|
},
|
|
2943
4033
|
async (args) => handleInvokeAgentTool(getToken, baseUrl, args)
|
|
2944
4034
|
);
|
|
2945
4035
|
}
|
|
4036
|
+
var LIST_DESCRIPTION2 = [
|
|
4037
|
+
"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.",
|
|
4038
|
+
"",
|
|
4039
|
+
"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.",
|
|
4040
|
+
"NOT FOR: ad-hoc extraction schemas (talonic_list_schemas) or discovering fields (talonic_list_fields).",
|
|
4041
|
+
"ARGS: optional `search` (name contains, case-insensitive), `limit` (1\u2013100, default 20), `cursor` (from pagination.next_cursor), `order` (asc|desc by updated_at).",
|
|
4042
|
+
"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 } }."
|
|
4043
|
+
].join("\n");
|
|
4044
|
+
var GET_DESCRIPTION2 = [
|
|
4045
|
+
"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).",
|
|
4046
|
+
"",
|
|
4047
|
+
"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.",
|
|
4048
|
+
"NOT FOR: listing Specs (talonic_list_specs) or starting a run (talonic_run_spec).",
|
|
4049
|
+
"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 }).",
|
|
4050
|
+
"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[]."
|
|
4051
|
+
].join("\n");
|
|
4052
|
+
var listSpecsInputSchema = {
|
|
4053
|
+
search: z.string().min(1).optional().describe("Case-insensitive contains match on the Spec name."),
|
|
4054
|
+
limit: z.number().int().min(1).max(100).optional().describe("Page size (default 20)."),
|
|
4055
|
+
cursor: z.string().min(1).optional().describe("Opaque cursor from pagination.next_cursor."),
|
|
4056
|
+
order: z.enum(["asc", "desc"]).optional().describe("Sort by updated_at (default desc).")
|
|
4057
|
+
};
|
|
4058
|
+
var getSpecInputSchema = {
|
|
4059
|
+
spec_id: z.string().uuid().describe("Spec UUID (from talonic_list_specs)."),
|
|
4060
|
+
include_versions: z.boolean().optional().describe("Also fetch the published versions list (adds `versions[]`).")
|
|
4061
|
+
};
|
|
4062
|
+
async function handleListSpecs(getToken, baseUrl, args) {
|
|
4063
|
+
const params = {
|
|
4064
|
+
search: args.search,
|
|
4065
|
+
limit: args.limit,
|
|
4066
|
+
cursor: args.cursor,
|
|
4067
|
+
order: args.order
|
|
4068
|
+
};
|
|
4069
|
+
return runTool(() => apiJson(getToken, baseUrl, "GET", "/v1/specs", { params }));
|
|
4070
|
+
}
|
|
4071
|
+
async function handleGetSpec(getToken, baseUrl, args) {
|
|
4072
|
+
return runTool(async () => {
|
|
4073
|
+
const path = `/v1/specs/${encodeURIComponent(args.spec_id)}`;
|
|
4074
|
+
const spec = await apiJson(getToken, baseUrl, "GET", path);
|
|
4075
|
+
if (!args.include_versions) return spec;
|
|
4076
|
+
const versions = await apiJson(
|
|
4077
|
+
getToken,
|
|
4078
|
+
baseUrl,
|
|
4079
|
+
"GET",
|
|
4080
|
+
`${path}/versions`
|
|
4081
|
+
);
|
|
4082
|
+
return { ...spec, versions: versions.data ?? [] };
|
|
4083
|
+
});
|
|
4084
|
+
}
|
|
4085
|
+
var READ_ONLY4 = {
|
|
4086
|
+
readOnlyHint: true,
|
|
4087
|
+
destructiveHint: false,
|
|
4088
|
+
idempotentHint: true,
|
|
4089
|
+
openWorldHint: false
|
|
4090
|
+
};
|
|
4091
|
+
function registerSpecTools(server, getToken, baseUrl) {
|
|
4092
|
+
server.registerTool(
|
|
4093
|
+
"talonic_list_specs",
|
|
4094
|
+
{
|
|
4095
|
+
title: "List Specs",
|
|
4096
|
+
description: LIST_DESCRIPTION2,
|
|
4097
|
+
inputSchema: listSpecsInputSchema,
|
|
4098
|
+
annotations: { title: "List Specs", ...READ_ONLY4 },
|
|
4099
|
+
_meta: widgetToolMeta("listSpecs")
|
|
4100
|
+
},
|
|
4101
|
+
async (args) => handleListSpecs(getToken, baseUrl, args)
|
|
4102
|
+
);
|
|
4103
|
+
server.registerTool(
|
|
4104
|
+
"talonic_get_spec",
|
|
4105
|
+
{
|
|
4106
|
+
title: "Get a Spec's structure",
|
|
4107
|
+
description: GET_DESCRIPTION2,
|
|
4108
|
+
inputSchema: getSpecInputSchema,
|
|
4109
|
+
annotations: { title: "Get a Spec's structure", ...READ_ONLY4 },
|
|
4110
|
+
_meta: widgetToolMeta("getSpec")
|
|
4111
|
+
},
|
|
4112
|
+
async (args) => handleGetSpec(getToken, baseUrl, args)
|
|
4113
|
+
);
|
|
4114
|
+
}
|
|
4115
|
+
function mapRunStatus(raw) {
|
|
4116
|
+
if (raw === "completed") return "completed";
|
|
4117
|
+
if (raw === "failed" || raw === "error" || raw === "cancelled" || raw === "canceled")
|
|
4118
|
+
return "failed";
|
|
4119
|
+
return "processing";
|
|
4120
|
+
}
|
|
4121
|
+
var RUN_DESCRIPTION = [
|
|
4122
|
+
"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.",
|
|
4123
|
+
"",
|
|
4124
|
+
"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.",
|
|
4125
|
+
"NOT FOR: one-off extraction with an ad-hoc schema (talonic_extract), or checking progress (talonic_get_run) / reading rows (talonic_get_run_results).",
|
|
4126
|
+
"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.",
|
|
4127
|
+
"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."
|
|
4128
|
+
].join("\n");
|
|
4129
|
+
var GET_RUN_DESCRIPTION = [
|
|
4130
|
+
"Poll a Spec run started by talonic_run_spec: normalised status plus document-level progress and, for pipelines, per-phase progress.",
|
|
4131
|
+
"",
|
|
4132
|
+
"USE WHEN: waiting for a run to finish \u2014 poll every 5\u201310 s; stop on `completed` or `failed`.",
|
|
4133
|
+
"NOT FOR: reading the structured rows (talonic_get_run_results) or starting a run (talonic_run_spec).",
|
|
4134
|
+
"ARGS: exactly one of `pipeline_id` (run_kind 'pipeline') or `run_id` (run_kind 'run'), from the RunEnvelope.",
|
|
4135
|
+
"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 }."
|
|
4136
|
+
].join("\n");
|
|
4137
|
+
var RESULTS_DESCRIPTION = [
|
|
4138
|
+
"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.",
|
|
4139
|
+
"",
|
|
4140
|
+
"USE WHEN: talonic_get_run reports `completed` (partial rows are also readable while `processing`).",
|
|
4141
|
+
"NOT FOR: progress (talonic_get_run) or per-field provenance of a single value (include: ['provenance'] here, or talonic_field_values).",
|
|
4142
|
+
"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`.",
|
|
4143
|
+
"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 }."
|
|
4144
|
+
].join("\n");
|
|
4145
|
+
var uuid = z.string().uuid();
|
|
4146
|
+
var documentIdsArg2 = z.array(uuid).min(1).max(500).optional().describe("Workspace document ids (1\u2013500). Mutually exclusive with file_urls.");
|
|
4147
|
+
var fileUrlsArg = z.array(z.string().url()).min(1).max(20).optional().describe("Public https file URLs (1\u201320). Mutually exclusive with document_ids.");
|
|
4148
|
+
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).");
|
|
4149
|
+
var runSpecInputSchema = {
|
|
4150
|
+
spec_id: uuid.describe("Spec UUID (talonic_list_specs)."),
|
|
4151
|
+
document_ids: documentIdsArg2,
|
|
4152
|
+
file_urls: fileUrlsArg,
|
|
4153
|
+
name: z.string().min(1).max(200).optional().describe("Display name for the run."),
|
|
4154
|
+
pipeline_mode: z.enum(["new", "append"]).optional().describe("`new` (default) or `append` to the Spec's existing pipeline."),
|
|
4155
|
+
batch_id: z.string().min(1).max(200).optional().describe("Caller grouping key (file_urls path only)."),
|
|
4156
|
+
metadata: metadataArg
|
|
4157
|
+
};
|
|
4158
|
+
var runRefInputSchema = {
|
|
4159
|
+
run_id: uuid.optional().describe("From a run_kind 'run' envelope (/v1/run)."),
|
|
4160
|
+
pipeline_id: uuid.optional().describe("From a run_kind 'pipeline' envelope (/v1/pipelines).")
|
|
4161
|
+
};
|
|
4162
|
+
var resultsInputSchema = {
|
|
4163
|
+
run_id: uuid.optional().describe(
|
|
4164
|
+
"The RunEnvelope's run_id. Alone: a run_kind 'run' submission (/v1/run). With pipeline_id: scopes the pipeline's rows to that submission."
|
|
4165
|
+
),
|
|
4166
|
+
pipeline_id: uuid.optional().describe(
|
|
4167
|
+
"The RunEnvelope's pipeline_id (run_kind 'pipeline'); rows come from /v1/pipelines/{id}/results."
|
|
4168
|
+
),
|
|
4169
|
+
document_id: uuid.optional().describe("Restrict to one document."),
|
|
4170
|
+
include: z.array(z.enum(["cells", "provenance"])).optional().describe("Extra per-field detail; heavier payload."),
|
|
4171
|
+
limit: z.number().int().min(1).max(200).optional().describe("Page size (default 50)."),
|
|
4172
|
+
cursor: z.string().min(1).optional().describe("Opaque cursor from pagination.next_cursor.")
|
|
4173
|
+
};
|
|
4174
|
+
function pickRef(args) {
|
|
4175
|
+
const hasRun = typeof args.run_id === "string" && args.run_id.length > 0;
|
|
4176
|
+
const hasPipe = typeof args.pipeline_id === "string" && args.pipeline_id.length > 0;
|
|
4177
|
+
if (hasRun === hasPipe) return null;
|
|
4178
|
+
return hasPipe ? { kind: "pipeline", id: args.pipeline_id } : { kind: "run", id: args.run_id };
|
|
4179
|
+
}
|
|
4180
|
+
async function handleRunSpec(getToken, baseUrl, args) {
|
|
4181
|
+
const docs = Array.isArray(args.document_ids) && args.document_ids.length > 0 ? args.document_ids : null;
|
|
4182
|
+
const urls = Array.isArray(args.file_urls) && args.file_urls.length > 0 ? args.file_urls : null;
|
|
4183
|
+
if (docs === null === (urls === null)) {
|
|
4184
|
+
return validationError("provide exactly one of document_ids or file_urls (non-empty).");
|
|
4185
|
+
}
|
|
4186
|
+
if (urls && urls.some((u) => !u.startsWith("https://"))) {
|
|
4187
|
+
return validationError("every file_urls entry must start with https://.");
|
|
4188
|
+
}
|
|
4189
|
+
if (docs && (args.batch_id !== void 0 || args.metadata !== void 0)) {
|
|
4190
|
+
return validationError(
|
|
4191
|
+
"batch_id and metadata only apply to the file_urls path; drop them for document_ids."
|
|
4192
|
+
);
|
|
4193
|
+
}
|
|
4194
|
+
return runTool(async () => {
|
|
4195
|
+
if (docs) {
|
|
4196
|
+
const res2 = await apiJson(
|
|
4197
|
+
getToken,
|
|
4198
|
+
baseUrl,
|
|
4199
|
+
"POST",
|
|
4200
|
+
"/v1/pipelines",
|
|
4201
|
+
{
|
|
4202
|
+
body: {
|
|
4203
|
+
schema_id: args.spec_id,
|
|
4204
|
+
document_ids: docs,
|
|
4205
|
+
...args.name ? { name: args.name } : {},
|
|
4206
|
+
...args.pipeline_mode ? { pipeline_mode: args.pipeline_mode } : {}
|
|
4207
|
+
}
|
|
4208
|
+
}
|
|
4209
|
+
);
|
|
4210
|
+
return {
|
|
4211
|
+
run_kind: "pipeline",
|
|
4212
|
+
run_id: res2.run_id ?? null,
|
|
4213
|
+
pipeline_id: res2.id,
|
|
4214
|
+
spec_id: res2.schema?.id ?? args.spec_id,
|
|
4215
|
+
spec_name: res2.schema?.name ?? null,
|
|
4216
|
+
status: mapRunStatus(res2.status),
|
|
4217
|
+
raw_status: res2.status ?? null,
|
|
4218
|
+
input_count: res2.document_count ?? docs.length,
|
|
4219
|
+
enqueued_documents: res2.enqueued_documents ?? null,
|
|
4220
|
+
appended: res2.appended === true,
|
|
4221
|
+
message: res2.message ?? null,
|
|
4222
|
+
links: res2.links ?? {}
|
|
4223
|
+
};
|
|
4224
|
+
}
|
|
4225
|
+
const res = await apiForm(getToken, baseUrl, "/v1/run", {
|
|
4226
|
+
spec_id: args.spec_id,
|
|
4227
|
+
file_urls: urls,
|
|
4228
|
+
name: args.name,
|
|
4229
|
+
pipeline_mode: args.pipeline_mode,
|
|
4230
|
+
batch_id: args.batch_id,
|
|
4231
|
+
metadata: args.metadata ? JSON.stringify(args.metadata) : void 0
|
|
4232
|
+
});
|
|
4233
|
+
return {
|
|
4234
|
+
run_kind: "run",
|
|
4235
|
+
run_id: res.run_id,
|
|
4236
|
+
pipeline_id: null,
|
|
4237
|
+
spec_id: res.spec_id ?? args.spec_id,
|
|
4238
|
+
spec_name: null,
|
|
4239
|
+
status: mapRunStatus(res.status),
|
|
4240
|
+
raw_status: res.status ?? null,
|
|
4241
|
+
input_count: res.input_count ?? urls.length,
|
|
4242
|
+
documents: res.documents ?? [],
|
|
4243
|
+
message: null,
|
|
4244
|
+
links: { poll: res.poll_url ?? `/v1/run/${res.run_id}` }
|
|
4245
|
+
};
|
|
4246
|
+
});
|
|
4247
|
+
}
|
|
4248
|
+
async function handleGetRun(getToken, baseUrl, args) {
|
|
4249
|
+
const ref = pickRef(args);
|
|
4250
|
+
if (!ref) return validationError("provide exactly one of run_id or pipeline_id.");
|
|
4251
|
+
return runTool(async () => {
|
|
4252
|
+
if (ref.kind === "run") {
|
|
4253
|
+
const r = await apiJson(
|
|
4254
|
+
getToken,
|
|
4255
|
+
baseUrl,
|
|
4256
|
+
"GET",
|
|
4257
|
+
`/v1/run/${encodeURIComponent(ref.id)}`
|
|
4258
|
+
);
|
|
4259
|
+
return {
|
|
4260
|
+
run_kind: "run",
|
|
4261
|
+
run_id: r["run_id"] ?? ref.id,
|
|
4262
|
+
pipeline_id: r["pipeline_id"] ?? null,
|
|
4263
|
+
spec_id: r["spec_id"] ?? null,
|
|
4264
|
+
status: mapRunStatus(r["status"]),
|
|
4265
|
+
raw_status: r["status"] ?? null,
|
|
4266
|
+
input_count: r["input_count"] ?? null,
|
|
4267
|
+
progress: r["progress"] ?? null,
|
|
4268
|
+
documents: r["documents"] ?? void 0,
|
|
4269
|
+
error_message: r["error_message"] ?? null,
|
|
4270
|
+
batch_id: r["batch_id"] ?? null,
|
|
4271
|
+
created_at: r["created_at"] ?? null,
|
|
4272
|
+
updated_at: r["updated_at"] ?? null
|
|
4273
|
+
};
|
|
4274
|
+
}
|
|
4275
|
+
const base = `/v1/pipelines/${encodeURIComponent(ref.id)}`;
|
|
4276
|
+
const p = await apiJson(getToken, baseUrl, "GET", base);
|
|
4277
|
+
const pr = await apiJson(getToken, baseUrl, "GET", `${base}/progress`);
|
|
4278
|
+
const raw = pr.status ?? p["status"];
|
|
4279
|
+
return {
|
|
4280
|
+
run_kind: "pipeline",
|
|
4281
|
+
run_id: null,
|
|
4282
|
+
pipeline_id: p["id"] ?? ref.id,
|
|
4283
|
+
spec_id: p["schema"]?.id ?? null,
|
|
4284
|
+
name: p["name"] ?? null,
|
|
4285
|
+
status: mapRunStatus(raw),
|
|
4286
|
+
raw_status: raw ?? null,
|
|
4287
|
+
progress: {
|
|
4288
|
+
total_documents: pr.totalDocuments ?? null,
|
|
4289
|
+
completed_documents: pr.completedDocuments ?? null,
|
|
4290
|
+
error_documents: pr.errorDocuments ?? null,
|
|
4291
|
+
finalization_pending: pr.finalizationPending ?? null,
|
|
4292
|
+
phases: (pr.phases ?? []).map((ph) => ({
|
|
4293
|
+
phase_id: ph.phaseId ?? null,
|
|
4294
|
+
name: ph.name ?? null,
|
|
4295
|
+
type: ph.type ?? null,
|
|
4296
|
+
completed: ph.completed ?? null,
|
|
4297
|
+
running: ph.running ?? null,
|
|
4298
|
+
errors: ph.errors ?? null
|
|
4299
|
+
}))
|
|
4300
|
+
},
|
|
4301
|
+
created_at: p["created_at"] ?? null,
|
|
4302
|
+
links: p["links"] ?? {}
|
|
4303
|
+
};
|
|
4304
|
+
});
|
|
4305
|
+
}
|
|
4306
|
+
async function handleGetRunResults(getToken, baseUrl, args) {
|
|
4307
|
+
const hasPipe = typeof args.pipeline_id === "string" && args.pipeline_id.length > 0;
|
|
4308
|
+
const hasRun = typeof args.run_id === "string" && args.run_id.length > 0;
|
|
4309
|
+
if (!hasPipe && !hasRun)
|
|
4310
|
+
return validationError("provide pipeline_id (optionally with run_id) or run_id.");
|
|
4311
|
+
return runTool(async () => {
|
|
4312
|
+
const kind = hasPipe ? "pipeline" : "run";
|
|
4313
|
+
const params = {
|
|
4314
|
+
...kind === "pipeline" ? { view: "documents", run_id: hasRun ? args.run_id : void 0 } : {},
|
|
4315
|
+
document_id: args.document_id,
|
|
4316
|
+
include: args.include?.length ? args.include.join(",") : void 0,
|
|
4317
|
+
limit: args.limit,
|
|
4318
|
+
cursor: args.cursor
|
|
4319
|
+
};
|
|
4320
|
+
const path = kind === "run" ? `/v1/run/${encodeURIComponent(args.run_id)}/results` : `/v1/pipelines/${encodeURIComponent(args.pipeline_id)}/results`;
|
|
4321
|
+
const body = await apiJson(getToken, baseUrl, "GET", path, { params });
|
|
4322
|
+
return { run_kind: kind, ...body };
|
|
4323
|
+
});
|
|
4324
|
+
}
|
|
4325
|
+
var READ_ONLY5 = {
|
|
4326
|
+
readOnlyHint: true,
|
|
4327
|
+
destructiveHint: false,
|
|
4328
|
+
idempotentHint: true,
|
|
4329
|
+
openWorldHint: false
|
|
4330
|
+
};
|
|
4331
|
+
function registerRunTools(server, getToken, baseUrl) {
|
|
4332
|
+
server.registerTool(
|
|
4333
|
+
"talonic_run_spec",
|
|
4334
|
+
{
|
|
4335
|
+
title: "Run a Spec pipeline",
|
|
4336
|
+
description: RUN_DESCRIPTION,
|
|
4337
|
+
inputSchema: runSpecInputSchema,
|
|
4338
|
+
annotations: {
|
|
4339
|
+
title: "Run a Spec pipeline",
|
|
4340
|
+
readOnlyHint: false,
|
|
4341
|
+
destructiveHint: false,
|
|
4342
|
+
openWorldHint: true
|
|
4343
|
+
},
|
|
4344
|
+
_meta: widgetToolMeta("runSpec")
|
|
4345
|
+
},
|
|
4346
|
+
async (args) => handleRunSpec(getToken, baseUrl, args)
|
|
4347
|
+
);
|
|
4348
|
+
server.registerTool(
|
|
4349
|
+
"talonic_get_run",
|
|
4350
|
+
{
|
|
4351
|
+
title: "Poll a Spec run",
|
|
4352
|
+
description: GET_RUN_DESCRIPTION,
|
|
4353
|
+
inputSchema: runRefInputSchema,
|
|
4354
|
+
annotations: { title: "Poll a Spec run", ...READ_ONLY5 },
|
|
4355
|
+
_meta: widgetToolMeta("getRun")
|
|
4356
|
+
},
|
|
4357
|
+
async (args) => handleGetRun(getToken, baseUrl, args)
|
|
4358
|
+
);
|
|
4359
|
+
server.registerTool(
|
|
4360
|
+
"talonic_get_run_results",
|
|
4361
|
+
{
|
|
4362
|
+
title: "Read a Spec run's rows",
|
|
4363
|
+
description: RESULTS_DESCRIPTION,
|
|
4364
|
+
inputSchema: resultsInputSchema,
|
|
4365
|
+
annotations: { title: "Read a Spec run's rows", ...READ_ONLY5 },
|
|
4366
|
+
_meta: widgetToolMeta("getRunResults")
|
|
4367
|
+
},
|
|
4368
|
+
async (args) => handleGetRunResults(getToken, baseUrl, args)
|
|
4369
|
+
);
|
|
4370
|
+
}
|
|
4371
|
+
var ASK_POLL_INTERVAL_MS = 2e3;
|
|
4372
|
+
var ASK_DEFAULT_WAIT_S = 45;
|
|
4373
|
+
var ASK_MAX_WAIT_S = 55;
|
|
4374
|
+
var POLL_HINT = "still processing \u2014 call talonic_get_answer with this ask_id in a few seconds";
|
|
4375
|
+
var ASK_DESCRIPTION = [
|
|
4376
|
+
"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.",
|
|
4377
|
+
"",
|
|
4378
|
+
"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.",
|
|
4379
|
+
"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).",
|
|
4380
|
+
"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).",
|
|
4381
|
+
"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."
|
|
4382
|
+
].join("\n");
|
|
4383
|
+
var GET_ANSWER_DESCRIPTION = [
|
|
4384
|
+
"Poll an ask started by talonic_ask that was still processing when the wait ended.",
|
|
4385
|
+
"",
|
|
4386
|
+
"USE WHEN: talonic_ask returned status 'processing' with an ask_id \u2014 poll every few seconds until 'completed' or 'error'.",
|
|
4387
|
+
"NOT FOR: asking a new question (talonic_ask).",
|
|
4388
|
+
"ARGS: `ask_id`.",
|
|
4389
|
+
"RETURNS: the same answer envelope as talonic_ask (answer, citations[], verification, usage) or { status: 'processing', poll_hint }."
|
|
4390
|
+
].join("\n");
|
|
4391
|
+
var uuid2 = z.string().uuid();
|
|
4392
|
+
var scopeSchema = z.object({
|
|
4393
|
+
document_ids: z.array(uuid2).max(500).optional(),
|
|
4394
|
+
schema_id: uuid2.optional(),
|
|
4395
|
+
pipeline_id: uuid2.optional(),
|
|
4396
|
+
data_product_id: uuid2.optional(),
|
|
4397
|
+
document_type: z.string().min(1).optional(),
|
|
4398
|
+
source_id: uuid2.optional(),
|
|
4399
|
+
tags: z.array(z.string().min(1)).max(50).optional(),
|
|
4400
|
+
ingested_after: z.string().min(1).optional(),
|
|
4401
|
+
ingested_before: z.string().min(1).optional()
|
|
4402
|
+
}).optional().describe("Restrict the question to a slice of the workspace; present fields are ANDed.");
|
|
4403
|
+
var askInputSchema = {
|
|
4404
|
+
question: z.string().min(1).max(4e3).describe("The question, in the user's words."),
|
|
4405
|
+
scope: scopeSchema,
|
|
4406
|
+
conversation_id: uuid2.optional().describe("Continue this conversation; the agent sees prior turns."),
|
|
4407
|
+
output_format: z.object({
|
|
4408
|
+
instruction: z.string().max(1e3).optional(),
|
|
4409
|
+
template: z.string().max(4e3).optional()
|
|
4410
|
+
}).optional().describe("Shape the answer (form only, never grounding)."),
|
|
4411
|
+
wait_seconds: z.number().int().min(0).max(ASK_MAX_WAIT_S).optional().describe(
|
|
4412
|
+
`Seconds to wait for the answer before returning 'processing' (default ${ASK_DEFAULT_WAIT_S}, max ${ASK_MAX_WAIT_S}).`
|
|
4413
|
+
)
|
|
4414
|
+
};
|
|
4415
|
+
function withHint(body) {
|
|
4416
|
+
return body.status === "processing" ? { ...body, poll_hint: POLL_HINT } : body;
|
|
4417
|
+
}
|
|
4418
|
+
async function handleAsk(getToken, baseUrl, args, deps = {}) {
|
|
4419
|
+
if (typeof args.question !== "string" || args.question.trim().length === 0) {
|
|
4420
|
+
return validationError("question must be a non-empty string.");
|
|
4421
|
+
}
|
|
4422
|
+
const sleep2 = deps.sleep ?? sleep;
|
|
4423
|
+
const now = deps.now ?? Date.now;
|
|
4424
|
+
const requestedWaitS = Number.isFinite(args.wait_seconds) ? args.wait_seconds : ASK_DEFAULT_WAIT_S;
|
|
4425
|
+
const waitS = Math.max(0, Math.min(ASK_MAX_WAIT_S, Math.floor(requestedWaitS)));
|
|
4426
|
+
return runTool(async () => {
|
|
4427
|
+
const created = await apiJson(getToken, baseUrl, "POST", "/v1/ask", {
|
|
4428
|
+
body: {
|
|
4429
|
+
question: args.question,
|
|
4430
|
+
...args.scope ? { scope: args.scope } : {},
|
|
4431
|
+
...args.conversation_id ? { conversation_id: args.conversation_id } : {},
|
|
4432
|
+
...args.output_format ? { output_format: args.output_format } : {}
|
|
4433
|
+
},
|
|
4434
|
+
signal: AbortSignal.timeout(15e3)
|
|
4435
|
+
});
|
|
4436
|
+
const pollPath = `/v1/ask/${encodeURIComponent(created.ask_id)}`;
|
|
4437
|
+
const start = now();
|
|
4438
|
+
const deadline = start + waitS * 1e3;
|
|
4439
|
+
for (; ; ) {
|
|
4440
|
+
const pollTimeoutMs = Math.max(5e3, Math.min(15e3, deadline - now()));
|
|
4441
|
+
let body;
|
|
4442
|
+
try {
|
|
4443
|
+
body = await apiJson(getToken, baseUrl, "GET", pollPath, {
|
|
4444
|
+
signal: AbortSignal.timeout(pollTimeoutMs)
|
|
4445
|
+
});
|
|
4446
|
+
} catch {
|
|
4447
|
+
return {
|
|
4448
|
+
...withHint({ status: "processing", ask_id: created.ask_id }),
|
|
4449
|
+
ask_id: created.ask_id,
|
|
4450
|
+
waited_ms: now() - start
|
|
4451
|
+
};
|
|
4452
|
+
}
|
|
4453
|
+
const t = now();
|
|
4454
|
+
if (body.status !== "processing" || t >= deadline) {
|
|
4455
|
+
return { ...withHint(body), ask_id: body.ask_id ?? created.ask_id, waited_ms: t - start };
|
|
4456
|
+
}
|
|
4457
|
+
await sleep2(Math.min(ASK_POLL_INTERVAL_MS, deadline - t));
|
|
4458
|
+
}
|
|
4459
|
+
});
|
|
4460
|
+
}
|
|
4461
|
+
async function handleGetAnswer(getToken, baseUrl, args) {
|
|
4462
|
+
return runTool(async () => {
|
|
4463
|
+
const body = await apiJson(
|
|
4464
|
+
getToken,
|
|
4465
|
+
baseUrl,
|
|
4466
|
+
"GET",
|
|
4467
|
+
`/v1/ask/${encodeURIComponent(args.ask_id)}`
|
|
4468
|
+
);
|
|
4469
|
+
return { ...withHint(body), ask_id: body.ask_id ?? args.ask_id };
|
|
4470
|
+
});
|
|
4471
|
+
}
|
|
4472
|
+
function registerAskTools(server, getToken, baseUrl) {
|
|
4473
|
+
server.registerTool(
|
|
4474
|
+
"talonic_ask",
|
|
4475
|
+
{
|
|
4476
|
+
title: "Ask a question over the workspace",
|
|
4477
|
+
description: ASK_DESCRIPTION,
|
|
4478
|
+
inputSchema: askInputSchema,
|
|
4479
|
+
annotations: {
|
|
4480
|
+
title: "Ask a question over the workspace",
|
|
4481
|
+
readOnlyHint: false,
|
|
4482
|
+
destructiveHint: false,
|
|
4483
|
+
openWorldHint: false
|
|
4484
|
+
},
|
|
4485
|
+
_meta: widgetToolMeta("ask")
|
|
4486
|
+
},
|
|
4487
|
+
async (args) => handleAsk(getToken, baseUrl, args)
|
|
4488
|
+
);
|
|
4489
|
+
server.registerTool(
|
|
4490
|
+
"talonic_get_answer",
|
|
4491
|
+
{
|
|
4492
|
+
title: "Poll an ask for its answer",
|
|
4493
|
+
description: GET_ANSWER_DESCRIPTION,
|
|
4494
|
+
inputSchema: { ask_id: uuid2.describe("From talonic_ask.") },
|
|
4495
|
+
annotations: {
|
|
4496
|
+
title: "Poll an ask for its answer",
|
|
4497
|
+
readOnlyHint: true,
|
|
4498
|
+
destructiveHint: false,
|
|
4499
|
+
idempotentHint: true,
|
|
4500
|
+
openWorldHint: false
|
|
4501
|
+
},
|
|
4502
|
+
_meta: widgetToolMeta("getAnswer")
|
|
4503
|
+
},
|
|
4504
|
+
async (args) => handleGetAnswer(getToken, baseUrl, args)
|
|
4505
|
+
);
|
|
4506
|
+
}
|
|
2946
4507
|
|
|
2947
4508
|
// package.json
|
|
2948
4509
|
var package_default = {
|
|
2949
|
-
version: "0.1.
|
|
4510
|
+
version: "0.1.79"};
|
|
2950
4511
|
|
|
2951
4512
|
// src/version.ts
|
|
2952
4513
|
var VERSION = package_default.version;
|
|
@@ -2974,6 +4535,7 @@ function createServer(options) {
|
|
|
2974
4535
|
const fallback = options.apiKey ?? "";
|
|
2975
4536
|
return () => fallback;
|
|
2976
4537
|
})();
|
|
4538
|
+
const rawToken = withFetch(getToken, taggedFetch);
|
|
2977
4539
|
const getTalonic = (() => {
|
|
2978
4540
|
if (options.talonic) {
|
|
2979
4541
|
const t = options.talonic;
|
|
@@ -3047,6 +4609,10 @@ function createServer(options) {
|
|
|
3047
4609
|
"For Agent-stage work, follow list -> get -> claim -> heartbeat while needed ->",
|
|
3048
4610
|
"submit. Preserve the execution_epoch from claim and return only fields declared",
|
|
3049
4611
|
"in the task output_contract; never continue after a lease or epoch conflict.",
|
|
4612
|
+
"To run the customer's configured pipeline: talonic_list_specs -> talonic_run_spec (document_ids for",
|
|
4613
|
+
"workspace documents, file_urls for remote files) -> poll talonic_get_run until completed ->",
|
|
4614
|
+
"talonic_get_run_results. For open questions across documents use talonic_ask (costs credits;",
|
|
4615
|
+
"if it returns status processing, poll talonic_get_answer).",
|
|
3050
4616
|
"For External-mode app decisions, follow talonic_list_decision_tasks (by app_id) ->",
|
|
3051
4617
|
"talonic_claim_decision_task (the claim IS the payload: output_contract, precedents,",
|
|
3052
4618
|
"package descriptor) -> talonic_read_decision_package pages from package.first_cursor ->",
|
|
@@ -3078,21 +4644,24 @@ function createServer(options) {
|
|
|
3078
4644
|
registerGetBalance(server, getTalonic);
|
|
3079
4645
|
registerGetPricing(server, getTalonic);
|
|
3080
4646
|
registerGetUsage(server, getTalonic);
|
|
3081
|
-
registerRequestUpload(server,
|
|
3082
|
-
registerFieldTools(server,
|
|
3083
|
-
registerAgentRegistryTools(server,
|
|
3084
|
-
registerAgentTaskTools(server,
|
|
3085
|
-
|
|
4647
|
+
registerRequestUpload(server, rawToken, baseUrl);
|
|
4648
|
+
registerFieldTools(server, rawToken, baseUrl);
|
|
4649
|
+
registerAgentRegistryTools(server, rawToken, baseUrl);
|
|
4650
|
+
registerAgentTaskTools(server, rawToken, baseUrl);
|
|
4651
|
+
registerSpecTools(server, rawToken, baseUrl);
|
|
4652
|
+
registerRunTools(server, rawToken, baseUrl);
|
|
4653
|
+
registerAskTools(server, rawToken, baseUrl);
|
|
4654
|
+
registerDecisionTaskTools(server, rawToken, baseUrl, {
|
|
3086
4655
|
invocable: options.decisionTasksInvocable !== false
|
|
3087
4656
|
});
|
|
3088
4657
|
if (options.includeGrowthTools) {
|
|
3089
|
-
registerGrowthTools(server,
|
|
4658
|
+
registerGrowthTools(server, rawToken, baseUrl);
|
|
3090
4659
|
}
|
|
3091
4660
|
if (options.includeAdminAgentTaskTools) {
|
|
3092
|
-
registerAdminAgentTaskTools(server,
|
|
4661
|
+
registerAdminAgentTaskTools(server, rawToken, baseUrl);
|
|
3093
4662
|
}
|
|
3094
4663
|
registerSchemasResource(server, getTalonic);
|
|
3095
|
-
registerWebhooksResource(server,
|
|
4664
|
+
registerWebhooksResource(server, rawToken, baseUrl);
|
|
3096
4665
|
registerWidgets(server);
|
|
3097
4666
|
return server;
|
|
3098
4667
|
}
|
|
@@ -3330,7 +4899,7 @@ function createRequestHandler(options = {}) {
|
|
|
3330
4899
|
uri: widgetRead.uri,
|
|
3331
4900
|
mimeType: "text/html;profile=mcp-app",
|
|
3332
4901
|
text: html,
|
|
3333
|
-
_meta:
|
|
4902
|
+
_meta: getWidgetTemplateMeta(widgetRead.uri)
|
|
3334
4903
|
}
|
|
3335
4904
|
]
|
|
3336
4905
|
}
|
|
@@ -3354,7 +4923,10 @@ function createRequestHandler(options = {}) {
|
|
|
3354
4923
|
}
|
|
3355
4924
|
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
|
|
3356
4925
|
const [includeGrowthTools, includeAdminAgentTaskTools] = await Promise.all([
|
|
3357
|
-
(options.growthAccess ?? growthAccessCached
|
|
4926
|
+
(options.growthAccess ?? ((currentToken) => growthAccessCached(
|
|
4927
|
+
currentToken,
|
|
4928
|
+
(candidate) => probeGrowthAccess(candidate, process.env["TALONIC_BASE_URL"])
|
|
4929
|
+
)))(token),
|
|
3358
4930
|
(options.adminAgentTaskAccess ?? ((currentToken) => adminAgentTaskAccessCached(
|
|
3359
4931
|
currentToken,
|
|
3360
4932
|
(candidate) => probeAgentTaskAdminAccess(candidate, process.env["TALONIC_BASE_URL"])
|
|
@@ -3364,6 +4936,7 @@ function createRequestHandler(options = {}) {
|
|
|
3364
4936
|
tokenProvider: () => token,
|
|
3365
4937
|
includeGrowthTools,
|
|
3366
4938
|
includeAdminAgentTaskTools,
|
|
4939
|
+
...process.env["TALONIC_BASE_URL"] ? { baseUrl: process.env["TALONIC_BASE_URL"] } : {},
|
|
3367
4940
|
// Listing UX only: an OAuth token that visibly lacks apps:decide gets
|
|
3368
4941
|
// the decision-task tools marked non-invocable. The platform decides.
|
|
3369
4942
|
decisionTasksInvocable: tokenHasDecideScope(token)
|