@talonic/mcp 0.1.104 → 0.1.105
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 +8 -0
- package/dist/content.js +1910 -11
- package/dist/content.js.map +1 -1
- package/dist/http-server.js +794 -24
- package/dist/http-server.js.map +1 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +772 -20
- package/dist/index.js.map +1 -1
- package/dist/server.js +789 -20
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -3907,10 +3907,10 @@ function handleImport(getToken, baseUrl, args) {
|
|
|
3907
3907
|
if (!!args.all === !!args.document_ids?.length)
|
|
3908
3908
|
return Promise.resolve(validationError("Pass either `all: true` or `document_ids`, not both."));
|
|
3909
3909
|
if (args.all) {
|
|
3910
|
-
const { query, contract_keys, only_priced, limit:
|
|
3910
|
+
const { query, contract_keys, only_priced, limit: limit3, dry_run } = args;
|
|
3911
3911
|
return runTool(
|
|
3912
3912
|
() => apiJson(getToken, baseUrl, "POST", "/v1/contracts/import/all", {
|
|
3913
|
-
body: { query, contract_keys, only_priced, limit:
|
|
3913
|
+
body: { query, contract_keys, only_priced, limit: limit3, dry_run }
|
|
3914
3914
|
})
|
|
3915
3915
|
);
|
|
3916
3916
|
}
|
|
@@ -8295,6 +8295,517 @@ function registerAppsTools(server, getToken, baseUrl) {
|
|
|
8295
8295
|
async (args) => handleListApps(getToken, baseUrl, args)
|
|
8296
8296
|
);
|
|
8297
8297
|
}
|
|
8298
|
+
var APP_MODES = ["rules", "assisted", "external", "autonomous"];
|
|
8299
|
+
var REVIEW_KINDS = ["resolution", "approval", "data_request", "judgment"];
|
|
8300
|
+
var REVIEW_STATUSES = ["open", "assigned", "resolved", "expired", "cancelled"];
|
|
8301
|
+
var VERDICT_OUTCOMES = ["passed", "failed", "indeterminate", "not_applicable"];
|
|
8302
|
+
var appId = zUuid().describe(
|
|
8303
|
+
"App id: the UUID `id` from talonic_list_apps or talonic_create_app (not the app_\u2026 public id)."
|
|
8304
|
+
);
|
|
8305
|
+
var runId = zUuid().describe(
|
|
8306
|
+
"App run UUID (run_id from talonic_run_app or talonic_list_app_runs)."
|
|
8307
|
+
);
|
|
8308
|
+
var reviewId = zUuid().describe("Human Review UUID (id from talonic_list_app_reviews).");
|
|
8309
|
+
var limit2 = z.number().int().min(1).max(200).optional().describe("Page size (default 50, max 200).");
|
|
8310
|
+
var offset = z.number().int().min(0).optional().describe("Rows to skip before the page.");
|
|
8311
|
+
var jsonObject = () => z.record(z.string(), z.json());
|
|
8312
|
+
var READ_ONLY3 = {
|
|
8313
|
+
readOnlyHint: true,
|
|
8314
|
+
destructiveHint: false,
|
|
8315
|
+
idempotentHint: true,
|
|
8316
|
+
openWorldHint: false
|
|
8317
|
+
};
|
|
8318
|
+
var MUTATING2 = {
|
|
8319
|
+
readOnlyHint: false,
|
|
8320
|
+
destructiveHint: false,
|
|
8321
|
+
idempotentHint: false,
|
|
8322
|
+
openWorldHint: false
|
|
8323
|
+
};
|
|
8324
|
+
var appPath = (id, suffix = "") => `/v1/apps/${encodeURIComponent(id)}${suffix}`;
|
|
8325
|
+
var runPath = (id, suffix = "") => `/v1/runs/${encodeURIComponent(id)}${suffix}`;
|
|
8326
|
+
var reviewPath = (id, suffix = "") => `/v1/reviews/${encodeURIComponent(id)}${suffix}`;
|
|
8327
|
+
var get = (t, b, path, params) => runTool(() => apiJson(t, b, "GET", path, params ? { params } : {}));
|
|
8328
|
+
var send = (t, b, method, path, body) => runTool(() => apiJson(t, b, method, path, body === void 0 ? {} : { body }));
|
|
8329
|
+
function defined2(o) {
|
|
8330
|
+
return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0));
|
|
8331
|
+
}
|
|
8332
|
+
var handleGetApp = (t, b, a) => get(t, b, appPath(a.app_id));
|
|
8333
|
+
var handleCreateApp = (t, b, a) => send(t, b, "POST", "/v1/apps", defined2({ ...a }));
|
|
8334
|
+
var handleSaveAppDraft = (t, b, a) => send(t, b, "PATCH", appPath(a.app_id), { content: a.content });
|
|
8335
|
+
var handleListAppVersions = (t, b, a) => get(t, b, appPath(a.app_id, "/versions"));
|
|
8336
|
+
var handlePublishApp = (t, b, a) => send(t, b, "POST", appPath(a.app_id, `/versions/${a.version}/publish`));
|
|
8337
|
+
var handleSetAppEnabled = (t, b, a, enabled) => send(t, b, "POST", appPath(a.app_id, enabled ? "/enable" : "/disable"));
|
|
8338
|
+
var handleRunApp = (t, b, a) => send(
|
|
8339
|
+
t,
|
|
8340
|
+
b,
|
|
8341
|
+
"POST",
|
|
8342
|
+
appPath(a.app_id, "/runs"),
|
|
8343
|
+
defined2({ input: a.input ?? {}, dry_run: a.dry_run, idempotency_key: a.idempotency_key })
|
|
8344
|
+
);
|
|
8345
|
+
var handleListAppRuns = (t, b, a) => get(t, b, appPath(a.app_id, "/runs"), { limit: a.limit, offset: a.offset });
|
|
8346
|
+
async function handleGetAppRun(t, b, a) {
|
|
8347
|
+
return runTool(async () => {
|
|
8348
|
+
const run = await apiJson(t, b, "GET", runPath(a.run_id));
|
|
8349
|
+
if (!a.include_events) return run;
|
|
8350
|
+
const events = await apiJson(t, b, "GET", runPath(a.run_id, "/events"));
|
|
8351
|
+
return { run, events: events?.events ?? [] };
|
|
8352
|
+
});
|
|
8353
|
+
}
|
|
8354
|
+
var handleGetRunRecord = (t, b, a) => get(t, b, runPath(a.run_id, "/record"));
|
|
8355
|
+
var handleGetRunVerdicts = (t, b, a) => get(t, b, runPath(a.run_id, "/verdicts"), {
|
|
8356
|
+
rolled: a.rolled,
|
|
8357
|
+
auto: a.auto,
|
|
8358
|
+
rule: a.rule,
|
|
8359
|
+
status: a.status,
|
|
8360
|
+
limit: a.limit,
|
|
8361
|
+
cursor: a.cursor
|
|
8362
|
+
});
|
|
8363
|
+
var handleListAppReviews = (t, b, a) => get(t, b, "/v1/reviews", { ...a });
|
|
8364
|
+
var handleRaiseAppReview = (t, b, a) => {
|
|
8365
|
+
const { app_id, ...body } = a;
|
|
8366
|
+
return send(t, b, "POST", appPath(app_id, "/reviews"), defined2(body));
|
|
8367
|
+
};
|
|
8368
|
+
var handleResolveAppReview = (t, b, a) => send(
|
|
8369
|
+
t,
|
|
8370
|
+
b,
|
|
8371
|
+
"POST",
|
|
8372
|
+
reviewPath(a.review_id, "/resolve"),
|
|
8373
|
+
defined2({ values: a.values, feedback: a.feedback })
|
|
8374
|
+
);
|
|
8375
|
+
var handleInterviewReview = (t, b, a) => send(
|
|
8376
|
+
t,
|
|
8377
|
+
b,
|
|
8378
|
+
"POST",
|
|
8379
|
+
reviewPath(a.review_id, "/interview"),
|
|
8380
|
+
defined2({ message: a.message, transcript: a.transcript })
|
|
8381
|
+
);
|
|
8382
|
+
var handleListAppPrecedents = (t, b, a) => get(t, b, appPath(a.app_id, "/precedents"), {
|
|
8383
|
+
similar_to: a.similar_to ? JSON.stringify(a.similar_to) : void 0
|
|
8384
|
+
});
|
|
8385
|
+
var handleGetAppLogic = (t, b, a) => get(t, b, appPath(a.app_id, "/logic"));
|
|
8386
|
+
var handleGetAppFields = (t, b, a) => get(t, b, appPath(a.app_id, "/logic/fields"));
|
|
8387
|
+
var handleInterpretRules = (t, b, a) => send(
|
|
8388
|
+
t,
|
|
8389
|
+
b,
|
|
8390
|
+
"POST",
|
|
8391
|
+
appPath(a.app_id, "/logic/compile"),
|
|
8392
|
+
defined2({
|
|
8393
|
+
card_ids: a.card_ids && a.card_ids.length > 0 ? a.card_ids : void 0,
|
|
8394
|
+
guidance: a.guidance || void 0,
|
|
8395
|
+
locale: a.locale
|
|
8396
|
+
})
|
|
8397
|
+
);
|
|
8398
|
+
var handleProposeEdit = (t, b, a) => send(t, b, "POST", appPath(a.app_id, "/edit-proposals"), { instruction: a.instruction });
|
|
8399
|
+
var handleApplyEdit = (t, b, a) => send(t, b, "POST", appPath(a.app_id, "/edit-proposals/apply"), { ops: a.ops });
|
|
8400
|
+
var handleGetAcceptance = (t, b, a) => get(t, b, appPath(a.app_id, "/acceptance"));
|
|
8401
|
+
var handleSaveAcceptance = (t, b, a) => send(
|
|
8402
|
+
t,
|
|
8403
|
+
b,
|
|
8404
|
+
"PUT",
|
|
8405
|
+
appPath(a.app_id, "/acceptance"),
|
|
8406
|
+
defined2({ cases: a.cases, tolerance: a.tolerance })
|
|
8407
|
+
);
|
|
8408
|
+
var handleCheckAcceptance = (t, b, a) => get(t, b, appPath(a.app_id, "/acceptance/check"), { run_id: a.run_id });
|
|
8409
|
+
var BUILD_FLOW = "FLOW: talonic_create_app -> talonic_save_app_draft -> talonic_interpret_app_rules -> talonic_publish_app -> talonic_run_app (dry_run first) -> talonic_get_app_run / talonic_get_run_verdicts -> talonic_save_app_acceptance + talonic_check_app_acceptance -> talonic_enable_app.";
|
|
8410
|
+
var D = {
|
|
8411
|
+
get: [
|
|
8412
|
+
"Read one app's manifest: mode, active version, enabled state, contract (what it reads and acts on), output contract, thresholds, triggers, fallback.",
|
|
8413
|
+
"USE WHEN: inspecting an app before changing or running it. NOT FOR: the editable draft (talonic_get_app_logic) or listing apps (talonic_list_apps)."
|
|
8414
|
+
].join("\n"),
|
|
8415
|
+
create: [
|
|
8416
|
+
"Create a new app. It starts disabled with no versions; the slug can no longer change once a version is published.",
|
|
8417
|
+
"USE WHEN: the user asks to set up a new app. ARGS: slug (lowercase letters, digits, hyphens, 3-64 chars), display_name, mode, optional one-sentence description.",
|
|
8418
|
+
"Modes: rules (decides from written rules), assisted (rules with people confirming), external (an outside agent decides through the decision-task tools), autonomous (finds candidate rules in the app's data).",
|
|
8419
|
+
"RETURNS: the manifest; use its `id` (UUID) with every other app tool.",
|
|
8420
|
+
BUILD_FLOW
|
|
8421
|
+
].join("\n"),
|
|
8422
|
+
saveDraft: [
|
|
8423
|
+
"Create or replace the app's single draft version: logic (rule sentences, or the external connection), input bindings, output contract (JSON Schema 2020-12), thresholds, triggers, fallback. Drafts are the only versions that can change.",
|
|
8424
|
+
"USE WHEN: authoring configuration in full. For a plain-language change to an existing draft prefer talonic_propose_app_edit + talonic_apply_app_edit.",
|
|
8425
|
+
"ARGS: app_id, content (the full version content object; read the current one with talonic_get_app_logic). RETURNS: { version, status, content_hash }; pass version to talonic_publish_app."
|
|
8426
|
+
].join("\n"),
|
|
8427
|
+
versions: [
|
|
8428
|
+
"List an app's versions, newest first: version number, status (draft, published, superseded), content hash, published_at.",
|
|
8429
|
+
"USE WHEN: you need the draft's version number for talonic_publish_app, or to see what is live."
|
|
8430
|
+
].join("\n"),
|
|
8431
|
+
publish: [
|
|
8432
|
+
"Publish the app's draft: freezes it, makes it the active version (the previous one is superseded) and locks the slug on first publish.",
|
|
8433
|
+
"USE WHEN: the draft is tested (talonic_run_app with dry_run, talonic_check_app_acceptance) and the user wants it live. Publishing does not enable the app; call talonic_enable_app for triggers to fire.",
|
|
8434
|
+
"ARGS: app_id and the draft's version number (from talonic_save_app_draft or talonic_list_app_versions). A number that is not the current draft is HTTP 409."
|
|
8435
|
+
].join("\n"),
|
|
8436
|
+
enable: [
|
|
8437
|
+
"Enable an app so its triggers fire and it can be run. Needs a published version. Enabling an app that acts on outside systems needs a workspace owner (HTTP 403 otherwise).",
|
|
8438
|
+
"USE WHEN: the user asks to switch the app on. ARGS: app_id."
|
|
8439
|
+
].join("\n"),
|
|
8440
|
+
disable: [
|
|
8441
|
+
"Disable an app at once (the kill switch): triggers stop and open work is no longer offered. Past runs and records are kept.",
|
|
8442
|
+
"USE WHEN: the user asks to stop or pause an app. ARGS: app_id."
|
|
8443
|
+
].join("\n"),
|
|
8444
|
+
run: [
|
|
8445
|
+
"Start one run of an app's active version and return it. A rules app usually finishes in the call with its decision; an external app stops at awaiting_decision until its decision task is submitted.",
|
|
8446
|
+
"USE WHEN: testing or executing an app. Set dry_run:true first: a full trace with no side effects (no actions, no webhooks to outside systems).",
|
|
8447
|
+
"ARGS: app_id, optional input object, dry_run, idempotency_key (reusing a key returns the existing run instead of starting another). Consumes credits.",
|
|
8448
|
+
"NEXT: talonic_get_app_run for status and decision; talonic_get_run_verdicts for per-subject results."
|
|
8449
|
+
].join("\n"),
|
|
8450
|
+
listRuns: [
|
|
8451
|
+
"List an app's runs, newest first, with status, decision and who decided; `total` counts every run.",
|
|
8452
|
+
"ARGS: app_id, optional limit (max 200) and offset."
|
|
8453
|
+
].join("\n"),
|
|
8454
|
+
getRun: [
|
|
8455
|
+
"Read one run: status, decision, decided_by, thresholds applied, reviews raised, timing.",
|
|
8456
|
+
"USE WHEN: checking a run you started or found. include_events:true adds the run's journal (every event in order).",
|
|
8457
|
+
"NOT FOR: Spec/pipeline runs (talonic_get_run). ARGS: run_id, optional include_events."
|
|
8458
|
+
].join("\n"),
|
|
8459
|
+
record: [
|
|
8460
|
+
"Export a finished run's sealed decision record: the immutable, audit-ready result with its decision, who decided (rules, a person or an outside agent) and the evidence.",
|
|
8461
|
+
"USE WHEN: the user needs the final, auditable outcome. A run that has not finished has no record yet (HTTP 404). ARGS: run_id."
|
|
8462
|
+
].join("\n"),
|
|
8463
|
+
verdicts: [
|
|
8464
|
+
"Read a batch run's per-subject results: a summary plus one row per subject with its overall outcome, the auto flag, and each rule's outcome with reasons and evidence.",
|
|
8465
|
+
"USE WHEN: inspecting what a run decided per record. Single-decision runs have none (HTTP 404; use talonic_get_app_run).",
|
|
8466
|
+
"ARGS: run_id; optional rolled (overall outcome), auto, rule + status (always together), limit (max 200), cursor (from `next`)."
|
|
8467
|
+
].join("\n"),
|
|
8468
|
+
listReviews: [
|
|
8469
|
+
"List Human Reviews: questions apps raised for a person (approvals, missing data, judgment calls, exceptions), newest first, with `total`.",
|
|
8470
|
+
"USE WHEN: finding open reviews to answer, or checking the result of one already resolved (status 'resolved' shows its values). Omit app_id for the whole workspace.",
|
|
8471
|
+
"ARGS: optional app_id, status, kind, assignee_user_id, limit (max 200), offset."
|
|
8472
|
+
].join("\n"),
|
|
8473
|
+
raiseReview: [
|
|
8474
|
+
"Ask a person a question on an app instead of guessing: a Human Review with a JSON Schema for the answer.",
|
|
8475
|
+
"USE WHEN: a decision needs a person's input. ARGS: app_id, kind (resolution | approval | data_request | judgment), question, input_contract (JSON Schema the answer must satisfy), optional run_id, context, team_id.",
|
|
8476
|
+
"NEXT: the answer arrives through talonic_resolve_app_review (or the web app); read it with talonic_list_app_reviews status 'resolved'."
|
|
8477
|
+
].join("\n"),
|
|
8478
|
+
resolveReview: [
|
|
8479
|
+
"Answer a Human Review: values (validated against the review's input_contract) plus optional feedback that teaches the app (proposal_verdict correct | incorrect | partial, correction, generalize).",
|
|
8480
|
+
"USE WHEN: the user gives the answer. 'approval' reviews accept only a person's answer; an API key or agent is refused (HTTP 403). Needs operate access on the app.",
|
|
8481
|
+
"RETURNS: the resolved review with its values. ARGS: review_id, values, optional feedback."
|
|
8482
|
+
].join("\n"),
|
|
8483
|
+
interview: [
|
|
8484
|
+
"Hold one turn of a guided conversation on an open Human Review: send the reviewer's message and the earlier turns (the server keeps no state); get back a follow-up question or a readback with proposed answer values.",
|
|
8485
|
+
"ready:true only when the proposed values satisfy the review's input contract. Nothing is submitted: finish with talonic_resolve_app_review.",
|
|
8486
|
+
"ARGS: review_id, message, optional transcript [{ role: user | assistant, text }]."
|
|
8487
|
+
].join("\n"),
|
|
8488
|
+
precedents: [
|
|
8489
|
+
"List an app's precedents: past resolved reviews it reuses for similar future runs.",
|
|
8490
|
+
"ARGS: app_id, optional similar_to (match keys object) to narrow to similar cases. An app with none returns an empty list."
|
|
8491
|
+
].join("\n"),
|
|
8492
|
+
getLogic: [
|
|
8493
|
+
"Read an app's logic: the editable draft and the active published version, including each rule with its interpretation state and plain-language readback.",
|
|
8494
|
+
"USE WHEN: before editing, or to get the draft's full content for talonic_save_app_draft."
|
|
8495
|
+
].join("\n"),
|
|
8496
|
+
getFields: [
|
|
8497
|
+
"List the fields the app's rules can use, per bound data source. This is everything the app can see.",
|
|
8498
|
+
"USE WHEN: before writing or fixing rules, so they name fields that exist."
|
|
8499
|
+
].join("\n"),
|
|
8500
|
+
interpret: [
|
|
8501
|
+
"Turn the draft's pending rule sentences into checkable rules against the app's fields, and save the draft.",
|
|
8502
|
+
"ARGS: app_id; optional card_ids (default: all pending), guidance (plain language, e.g. 'the city is in shipper_city_state') for rules that stayed pending, locale for the readbacks.",
|
|
8503
|
+
"RETURNS: the rules plus warnings saying why any rule stayed pending."
|
|
8504
|
+
].join("\n"),
|
|
8505
|
+
proposeEdit: [
|
|
8506
|
+
"Turn a plain-language change request into typed edit operations on the app's rules (add, rewrite, delete, pause, resume, fallback, mode). Nothing is saved.",
|
|
8507
|
+
"USE WHEN: the user describes a change in words. Show the summary to the user, then apply the accepted ops with talonic_apply_app_edit."
|
|
8508
|
+
].join("\n"),
|
|
8509
|
+
applyEdit: [
|
|
8510
|
+
"Apply accepted edit operations from talonic_propose_app_edit to the draft. They are re-checked against the current draft; changed rules are interpreted again and warnings returned.",
|
|
8511
|
+
"ARGS: app_id, ops (from the proposal, unchanged)."
|
|
8512
|
+
].join("\n"),
|
|
8513
|
+
getAcceptance: [
|
|
8514
|
+
"Read the app's acceptance set: the labeled expected results a correct run must reproduce, and the accepted mismatch share. null when none is saved."
|
|
8515
|
+
].join("\n"),
|
|
8516
|
+
saveAcceptance: [
|
|
8517
|
+
"Replace the app's acceptance set: the expected results a correct run must reproduce, plus tolerance (accepted mismatch share, 0 to 1). This is the app's definition of done.",
|
|
8518
|
+
"ARGS: app_id, cases (per subject: subject_key + expected_outcome and/or expected_auto; for single-decision apps: expected_decision), optional tolerance (default 0)."
|
|
8519
|
+
].join("\n"),
|
|
8520
|
+
checkAcceptance: [
|
|
8521
|
+
"Score a run against the app's acceptance set by comparing recorded results: the same run always gets the same score. Returns score, pass/fail and each mismatch.",
|
|
8522
|
+
"USE WHEN: after talonic_run_app, to decide whether the app is ready to publish or still correct. ARGS: app_id, optional run_id (default: the latest completed run)."
|
|
8523
|
+
].join("\n")
|
|
8524
|
+
};
|
|
8525
|
+
var acceptanceCase = z.object({
|
|
8526
|
+
subject_key: z.string().min(1).max(256).optional(),
|
|
8527
|
+
expected_outcome: z.enum(VERDICT_OUTCOMES).optional(),
|
|
8528
|
+
expected_auto: z.boolean().optional(),
|
|
8529
|
+
expected_decision: z.string().min(1).max(64).optional(),
|
|
8530
|
+
note: z.string().max(300).optional()
|
|
8531
|
+
}).describe(
|
|
8532
|
+
"One expected result: subject_key + expected_outcome (and/or expected_auto) for batch apps, or expected_decision for single-decision apps."
|
|
8533
|
+
);
|
|
8534
|
+
function registerAppsToolset(server, getToken, baseUrl) {
|
|
8535
|
+
const t = getToken;
|
|
8536
|
+
const b = baseUrl;
|
|
8537
|
+
const reg = (name, title, description, inputSchema11, annotations, handler) => server.registerTool(
|
|
8538
|
+
name,
|
|
8539
|
+
{ title, description, inputSchema: inputSchema11, annotations: { title, ...annotations } },
|
|
8540
|
+
handler
|
|
8541
|
+
);
|
|
8542
|
+
reg(
|
|
8543
|
+
"talonic_create_app",
|
|
8544
|
+
"Create App",
|
|
8545
|
+
D.create,
|
|
8546
|
+
{
|
|
8547
|
+
slug: z.string().regex(/^[a-z0-9][a-z0-9-]{1,62}[a-z0-9]$/).describe("Lowercase letters, digits and hyphens, 3-64 chars."),
|
|
8548
|
+
display_name: z.string().min(1).max(200),
|
|
8549
|
+
mode: z.enum(APP_MODES),
|
|
8550
|
+
description: z.string().max(2e3).optional().describe("One sentence about the app.")
|
|
8551
|
+
},
|
|
8552
|
+
MUTATING2,
|
|
8553
|
+
(a) => handleCreateApp(t, b, a)
|
|
8554
|
+
);
|
|
8555
|
+
reg(
|
|
8556
|
+
"talonic_get_app",
|
|
8557
|
+
"Get App",
|
|
8558
|
+
D.get,
|
|
8559
|
+
{ app_id: appId },
|
|
8560
|
+
READ_ONLY3,
|
|
8561
|
+
(a) => handleGetApp(t, b, a)
|
|
8562
|
+
);
|
|
8563
|
+
reg(
|
|
8564
|
+
"talonic_get_app_logic",
|
|
8565
|
+
"Get App Logic",
|
|
8566
|
+
D.getLogic,
|
|
8567
|
+
{ app_id: appId },
|
|
8568
|
+
READ_ONLY3,
|
|
8569
|
+
(a) => handleGetAppLogic(t, b, a)
|
|
8570
|
+
);
|
|
8571
|
+
reg(
|
|
8572
|
+
"talonic_get_app_fields",
|
|
8573
|
+
"Get App Fields",
|
|
8574
|
+
D.getFields,
|
|
8575
|
+
{ app_id: appId },
|
|
8576
|
+
READ_ONLY3,
|
|
8577
|
+
(a) => handleGetAppFields(t, b, a)
|
|
8578
|
+
);
|
|
8579
|
+
reg(
|
|
8580
|
+
"talonic_save_app_draft",
|
|
8581
|
+
"Save App Draft",
|
|
8582
|
+
D.saveDraft,
|
|
8583
|
+
{ app_id: appId, content: jsonObject().describe("Full version content object.") },
|
|
8584
|
+
MUTATING2,
|
|
8585
|
+
(a) => handleSaveAppDraft(t, b, a)
|
|
8586
|
+
);
|
|
8587
|
+
reg(
|
|
8588
|
+
"talonic_interpret_app_rules",
|
|
8589
|
+
"Interpret App Rules",
|
|
8590
|
+
D.interpret,
|
|
8591
|
+
{
|
|
8592
|
+
app_id: appId,
|
|
8593
|
+
card_ids: z.array(z.string().min(1).max(128)).max(50).optional().describe("Rule card ids; omit for all pending."),
|
|
8594
|
+
guidance: z.string().max(1e3).optional().describe("Plain-language hint for stuck rules."),
|
|
8595
|
+
locale: z.string().max(10).optional().describe("Language of reasons and readbacks, e.g. de.")
|
|
8596
|
+
},
|
|
8597
|
+
MUTATING2,
|
|
8598
|
+
(a) => handleInterpretRules(t, b, a)
|
|
8599
|
+
);
|
|
8600
|
+
reg(
|
|
8601
|
+
"talonic_propose_app_edit",
|
|
8602
|
+
"Propose App Edit",
|
|
8603
|
+
D.proposeEdit,
|
|
8604
|
+
{
|
|
8605
|
+
app_id: appId,
|
|
8606
|
+
instruction: z.string().min(8).max(2e3).describe("The change, in plain language.")
|
|
8607
|
+
},
|
|
8608
|
+
{ ...READ_ONLY3, idempotentHint: false },
|
|
8609
|
+
(a) => handleProposeEdit(t, b, a)
|
|
8610
|
+
);
|
|
8611
|
+
reg(
|
|
8612
|
+
"talonic_apply_app_edit",
|
|
8613
|
+
"Apply App Edit",
|
|
8614
|
+
D.applyEdit,
|
|
8615
|
+
{
|
|
8616
|
+
app_id: appId,
|
|
8617
|
+
ops: z.array(jsonObject()).min(1).max(20).describe("Accepted ops from the proposal.")
|
|
8618
|
+
},
|
|
8619
|
+
MUTATING2,
|
|
8620
|
+
(a) => handleApplyEdit(t, b, a)
|
|
8621
|
+
);
|
|
8622
|
+
reg(
|
|
8623
|
+
"talonic_list_app_versions",
|
|
8624
|
+
"List App Versions",
|
|
8625
|
+
D.versions,
|
|
8626
|
+
{ app_id: appId },
|
|
8627
|
+
READ_ONLY3,
|
|
8628
|
+
(a) => handleListAppVersions(t, b, a)
|
|
8629
|
+
);
|
|
8630
|
+
reg(
|
|
8631
|
+
"talonic_publish_app",
|
|
8632
|
+
"Publish App",
|
|
8633
|
+
D.publish,
|
|
8634
|
+
{ app_id: appId, version: z.number().int().min(1).describe("The draft's version number.") },
|
|
8635
|
+
MUTATING2,
|
|
8636
|
+
(a) => handlePublishApp(t, b, a)
|
|
8637
|
+
);
|
|
8638
|
+
reg(
|
|
8639
|
+
"talonic_enable_app",
|
|
8640
|
+
"Enable App",
|
|
8641
|
+
D.enable,
|
|
8642
|
+
{ app_id: appId },
|
|
8643
|
+
MUTATING2,
|
|
8644
|
+
(a) => handleSetAppEnabled(t, b, a, true)
|
|
8645
|
+
);
|
|
8646
|
+
reg(
|
|
8647
|
+
"talonic_disable_app",
|
|
8648
|
+
"Disable App",
|
|
8649
|
+
D.disable,
|
|
8650
|
+
{ app_id: appId },
|
|
8651
|
+
MUTATING2,
|
|
8652
|
+
(a) => handleSetAppEnabled(t, b, a, false)
|
|
8653
|
+
);
|
|
8654
|
+
reg(
|
|
8655
|
+
"talonic_get_app_acceptance",
|
|
8656
|
+
"Get App Acceptance Set",
|
|
8657
|
+
D.getAcceptance,
|
|
8658
|
+
{ app_id: appId },
|
|
8659
|
+
READ_ONLY3,
|
|
8660
|
+
(a) => handleGetAcceptance(t, b, a)
|
|
8661
|
+
);
|
|
8662
|
+
reg(
|
|
8663
|
+
"talonic_save_app_acceptance",
|
|
8664
|
+
"Save App Acceptance Set",
|
|
8665
|
+
D.saveAcceptance,
|
|
8666
|
+
{
|
|
8667
|
+
app_id: appId,
|
|
8668
|
+
cases: z.array(acceptanceCase).min(1).max(2e3),
|
|
8669
|
+
tolerance: z.number().min(0).max(1).optional().describe("Accepted mismatch share (default 0).")
|
|
8670
|
+
},
|
|
8671
|
+
MUTATING2,
|
|
8672
|
+
(a) => handleSaveAcceptance(t, b, a)
|
|
8673
|
+
);
|
|
8674
|
+
reg(
|
|
8675
|
+
"talonic_check_app_acceptance",
|
|
8676
|
+
"Check App Acceptance",
|
|
8677
|
+
D.checkAcceptance,
|
|
8678
|
+
{
|
|
8679
|
+
app_id: appId,
|
|
8680
|
+
run_id: zUuid().optional().describe("Run to score; default the latest completed run.")
|
|
8681
|
+
},
|
|
8682
|
+
READ_ONLY3,
|
|
8683
|
+
(a) => handleCheckAcceptance(t, b, a)
|
|
8684
|
+
);
|
|
8685
|
+
reg(
|
|
8686
|
+
"talonic_run_app",
|
|
8687
|
+
"Run App",
|
|
8688
|
+
D.run,
|
|
8689
|
+
{
|
|
8690
|
+
app_id: appId,
|
|
8691
|
+
input: jsonObject().optional().describe("Run input, checked against the app's input schema."),
|
|
8692
|
+
dry_run: z.boolean().optional().describe("Full trace, no side effects."),
|
|
8693
|
+
idempotency_key: z.string().min(1).max(64).optional()
|
|
8694
|
+
},
|
|
8695
|
+
MUTATING2,
|
|
8696
|
+
(a) => handleRunApp(t, b, a)
|
|
8697
|
+
);
|
|
8698
|
+
reg(
|
|
8699
|
+
"talonic_list_app_runs",
|
|
8700
|
+
"List App Runs",
|
|
8701
|
+
D.listRuns,
|
|
8702
|
+
{ app_id: appId, limit: limit2, offset },
|
|
8703
|
+
READ_ONLY3,
|
|
8704
|
+
(a) => handleListAppRuns(t, b, a)
|
|
8705
|
+
);
|
|
8706
|
+
reg(
|
|
8707
|
+
"talonic_get_app_run",
|
|
8708
|
+
"Get App Run",
|
|
8709
|
+
D.getRun,
|
|
8710
|
+
{ run_id: runId, include_events: z.boolean().optional() },
|
|
8711
|
+
READ_ONLY3,
|
|
8712
|
+
(a) => handleGetAppRun(t, b, a)
|
|
8713
|
+
);
|
|
8714
|
+
reg(
|
|
8715
|
+
"talonic_get_run_record",
|
|
8716
|
+
"Get Run Record",
|
|
8717
|
+
D.record,
|
|
8718
|
+
{ run_id: runId },
|
|
8719
|
+
READ_ONLY3,
|
|
8720
|
+
(a) => handleGetRunRecord(t, b, a)
|
|
8721
|
+
);
|
|
8722
|
+
reg(
|
|
8723
|
+
"talonic_get_run_verdicts",
|
|
8724
|
+
"Get Run Verdicts",
|
|
8725
|
+
D.verdicts,
|
|
8726
|
+
{
|
|
8727
|
+
run_id: runId,
|
|
8728
|
+
rolled: z.enum(VERDICT_OUTCOMES).optional().describe("Filter by overall outcome."),
|
|
8729
|
+
auto: z.boolean().optional().describe("Filter by the auto flag."),
|
|
8730
|
+
rule: z.string().min(1).max(128).optional().describe("Rule id; needs status."),
|
|
8731
|
+
status: z.enum(VERDICT_OUTCOMES).optional().describe("That rule's outcome; needs rule."),
|
|
8732
|
+
limit: limit2,
|
|
8733
|
+
cursor: z.string().min(1).max(512).optional().describe("`next` from the previous page.")
|
|
8734
|
+
},
|
|
8735
|
+
READ_ONLY3,
|
|
8736
|
+
(a) => handleGetRunVerdicts(t, b, a)
|
|
8737
|
+
);
|
|
8738
|
+
reg(
|
|
8739
|
+
"talonic_list_app_reviews",
|
|
8740
|
+
"List Human Reviews",
|
|
8741
|
+
D.listReviews,
|
|
8742
|
+
{
|
|
8743
|
+
app_id: appId.optional(),
|
|
8744
|
+
status: z.enum(REVIEW_STATUSES).optional(),
|
|
8745
|
+
kind: z.enum(REVIEW_KINDS).optional(),
|
|
8746
|
+
assignee_user_id: zUuid().optional().describe("Only reviews assigned to this user."),
|
|
8747
|
+
limit: limit2,
|
|
8748
|
+
offset
|
|
8749
|
+
},
|
|
8750
|
+
READ_ONLY3,
|
|
8751
|
+
(a) => handleListAppReviews(t, b, a)
|
|
8752
|
+
);
|
|
8753
|
+
reg(
|
|
8754
|
+
"talonic_raise_app_review",
|
|
8755
|
+
"Raise Human Review",
|
|
8756
|
+
D.raiseReview,
|
|
8757
|
+
{
|
|
8758
|
+
app_id: appId,
|
|
8759
|
+
run_id: runId.optional(),
|
|
8760
|
+
kind: z.enum(REVIEW_KINDS),
|
|
8761
|
+
question: z.string().min(1).max(4e3),
|
|
8762
|
+
context: jsonObject().optional(),
|
|
8763
|
+
input_contract: jsonObject().describe("JSON Schema the answer must satisfy."),
|
|
8764
|
+
team_id: zUuid().optional().describe("Review team to assign.")
|
|
8765
|
+
},
|
|
8766
|
+
MUTATING2,
|
|
8767
|
+
(a) => handleRaiseAppReview(t, b, a)
|
|
8768
|
+
);
|
|
8769
|
+
reg(
|
|
8770
|
+
"talonic_resolve_app_review",
|
|
8771
|
+
"Resolve Human Review",
|
|
8772
|
+
D.resolveReview,
|
|
8773
|
+
{
|
|
8774
|
+
review_id: reviewId,
|
|
8775
|
+
values: jsonObject().describe("Answer values matching the review's input_contract."),
|
|
8776
|
+
feedback: z.object({
|
|
8777
|
+
proposal_verdict: z.enum(["correct", "incorrect", "partial"]).optional(),
|
|
8778
|
+
correction: z.string().max(4e3).optional(),
|
|
8779
|
+
generalize: z.boolean().optional()
|
|
8780
|
+
}).optional().describe("Optional feedback that teaches the app.")
|
|
8781
|
+
},
|
|
8782
|
+
MUTATING2,
|
|
8783
|
+
(a) => handleResolveAppReview(t, b, a)
|
|
8784
|
+
);
|
|
8785
|
+
reg(
|
|
8786
|
+
"talonic_interview_app_review",
|
|
8787
|
+
"Interview Human Review",
|
|
8788
|
+
D.interview,
|
|
8789
|
+
{
|
|
8790
|
+
review_id: reviewId,
|
|
8791
|
+
message: z.string().min(1).max(4e3).describe("The reviewer's message for this turn."),
|
|
8792
|
+
transcript: z.array(z.object({ role: z.enum(["user", "assistant"]), text: z.string().max(2e3) })).max(20).optional().describe("Earlier turns, oldest first.")
|
|
8793
|
+
},
|
|
8794
|
+
{ ...READ_ONLY3, idempotentHint: false },
|
|
8795
|
+
(a) => handleInterviewReview(t, b, a)
|
|
8796
|
+
);
|
|
8797
|
+
reg(
|
|
8798
|
+
"talonic_list_app_precedents",
|
|
8799
|
+
"List App Precedents",
|
|
8800
|
+
D.precedents,
|
|
8801
|
+
{ app_id: appId, similar_to: jsonObject().optional().describe("Match keys of the case.") },
|
|
8802
|
+
READ_ONLY3,
|
|
8803
|
+
(a) => handleListAppPrecedents(t, b, a)
|
|
8804
|
+
);
|
|
8805
|
+
}
|
|
8806
|
+
function probeAppsToolsetAccess(token, baseUrl) {
|
|
8807
|
+
return probeAccessState(token, baseUrl, "/v1/apps");
|
|
8808
|
+
}
|
|
8298
8809
|
var DECIDE_SCOPE = "apps:decide";
|
|
8299
8810
|
var TASK_STATUSES2 = [
|
|
8300
8811
|
"available",
|
|
@@ -8306,7 +8817,7 @@ var TASK_STATUSES2 = [
|
|
|
8306
8817
|
"cancelled"
|
|
8307
8818
|
];
|
|
8308
8819
|
var PACKAGE_PAGE_LIMIT_MAX = 2e3;
|
|
8309
|
-
var
|
|
8820
|
+
var appId2 = zUuid().describe(
|
|
8310
8821
|
"Id of an External-mode app (from talonic_list_apps, where mode is 'external')."
|
|
8311
8822
|
);
|
|
8312
8823
|
var taskId2 = zUuid().describe("Decision task UUID.");
|
|
@@ -8334,7 +8845,7 @@ var serviceVersion = z.string().min(1).max(64).optional().describe("Optional bui
|
|
|
8334
8845
|
var failReason = z.string().min(1).max(2e3).describe(
|
|
8335
8846
|
"Why the task cannot be decided, up to 2,000 characters. Recorded on the Human Review the fail raises."
|
|
8336
8847
|
);
|
|
8337
|
-
var listInput2 = { app_id:
|
|
8848
|
+
var listInput2 = { app_id: appId2, status: status2, limit: listLimit, cursor: cursor2 };
|
|
8338
8849
|
var idInput2 = { task_id: taskId2 };
|
|
8339
8850
|
var packageInput = { task_id: taskId2, cursor: packageCursor, limit: packageLimit };
|
|
8340
8851
|
var epochInput = { task_id: taskId2, execution_epoch: executionEpoch2 };
|
|
@@ -8409,12 +8920,12 @@ function handleFailDecisionTask(getToken, baseUrl, args) {
|
|
|
8409
8920
|
})
|
|
8410
8921
|
);
|
|
8411
8922
|
}
|
|
8412
|
-
var
|
|
8923
|
+
var READ_ONLY4 = {
|
|
8413
8924
|
readOnlyHint: true,
|
|
8414
8925
|
destructiveHint: false,
|
|
8415
8926
|
openWorldHint: false
|
|
8416
8927
|
};
|
|
8417
|
-
var
|
|
8928
|
+
var MUTATING3 = {
|
|
8418
8929
|
readOnlyHint: false,
|
|
8419
8930
|
destructiveHint: false,
|
|
8420
8931
|
openWorldHint: false
|
|
@@ -8496,7 +9007,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
8496
9007
|
title: "List Decision Tasks",
|
|
8497
9008
|
description: DESCRIPTIONS2.list,
|
|
8498
9009
|
inputSchema: listInput2,
|
|
8499
|
-
annotations: { title: "List Decision Tasks", ...
|
|
9010
|
+
annotations: { title: "List Decision Tasks", ...READ_ONLY4 },
|
|
8500
9011
|
...metaFor("listDecisionTasks")
|
|
8501
9012
|
},
|
|
8502
9013
|
async (args) => handleListDecisionTasks(getToken, baseUrl, args)
|
|
@@ -8507,7 +9018,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
8507
9018
|
title: "Claim Decision Task",
|
|
8508
9019
|
description: DESCRIPTIONS2.claim,
|
|
8509
9020
|
inputSchema: idInput2,
|
|
8510
|
-
annotations: { title: "Claim Decision Task", ...
|
|
9021
|
+
annotations: { title: "Claim Decision Task", ...MUTATING3 },
|
|
8511
9022
|
...metaFor("claimDecisionTask")
|
|
8512
9023
|
},
|
|
8513
9024
|
async (args) => handleClaimDecisionTask(getToken, baseUrl, args)
|
|
@@ -8518,7 +9029,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
8518
9029
|
title: "Read Decision Package",
|
|
8519
9030
|
description: DESCRIPTIONS2.package,
|
|
8520
9031
|
inputSchema: packageInput,
|
|
8521
|
-
annotations: { title: "Read Decision Package", ...
|
|
9032
|
+
annotations: { title: "Read Decision Package", ...READ_ONLY4 },
|
|
8522
9033
|
...metaFor("readDecisionPackage")
|
|
8523
9034
|
},
|
|
8524
9035
|
async (args) => handleReadDecisionPackage(getToken, baseUrl, args)
|
|
@@ -8529,7 +9040,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
8529
9040
|
title: "Heartbeat Decision Task",
|
|
8530
9041
|
description: DESCRIPTIONS2.heartbeat,
|
|
8531
9042
|
inputSchema: epochInput,
|
|
8532
|
-
annotations: { title: "Heartbeat Decision Task", ...
|
|
9043
|
+
annotations: { title: "Heartbeat Decision Task", ...MUTATING3 },
|
|
8533
9044
|
...metaFor("heartbeatDecisionTask")
|
|
8534
9045
|
},
|
|
8535
9046
|
async (args) => handleHeartbeatDecisionTask(getToken, baseUrl, args)
|
|
@@ -8540,7 +9051,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
8540
9051
|
title: "Submit Decision Task",
|
|
8541
9052
|
description: DESCRIPTIONS2.submit,
|
|
8542
9053
|
inputSchema: submitInput2,
|
|
8543
|
-
annotations: { title: "Submit Decision Task", ...
|
|
9054
|
+
annotations: { title: "Submit Decision Task", ...MUTATING3 },
|
|
8544
9055
|
...metaFor("submitDecisionTask")
|
|
8545
9056
|
},
|
|
8546
9057
|
async (args) => handleSubmitDecisionTask(getToken, baseUrl, args)
|
|
@@ -8551,7 +9062,7 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
8551
9062
|
title: "Release Decision Task",
|
|
8552
9063
|
description: DESCRIPTIONS2.release,
|
|
8553
9064
|
inputSchema: epochInput,
|
|
8554
|
-
annotations: { title: "Release Decision Task", ...
|
|
9065
|
+
annotations: { title: "Release Decision Task", ...MUTATING3 },
|
|
8555
9066
|
...metaFor("releaseDecisionTask")
|
|
8556
9067
|
},
|
|
8557
9068
|
async (args) => handleReleaseDecisionTask(getToken, baseUrl, args)
|
|
@@ -8568,6 +9079,236 @@ function registerDecisionTaskTools(server, getToken, baseUrl, options = {}) {
|
|
|
8568
9079
|
async (args) => handleFailDecisionTask(getToken, baseUrl, args)
|
|
8569
9080
|
);
|
|
8570
9081
|
}
|
|
9082
|
+
|
|
9083
|
+
// src/tools/mining-driver.ts
|
|
9084
|
+
var appId3 = zUuid().describe(
|
|
9085
|
+
"Id (UUID) of an autonomous app, from talonic_list_apps where mode is 'autonomous'."
|
|
9086
|
+
);
|
|
9087
|
+
var runId2 = zUuid().describe(
|
|
9088
|
+
"The round's run id (run_id from talonic_mining_list_rounds, or the decision task's run_id)."
|
|
9089
|
+
);
|
|
9090
|
+
var executionEpoch3 = z.number().int().min(1).max(2147483647).describe("execution_epoch from talonic_claim_decision_task. A stale epoch is HTTP 409.");
|
|
9091
|
+
var toolName = z.string().regex(/^[a-z][a-z0-9_]{0,63}$/).describe("A tool name from talonic_mining_list_round_tools.");
|
|
9092
|
+
var READ_ONLY5 = {
|
|
9093
|
+
readOnlyHint: true,
|
|
9094
|
+
destructiveHint: false,
|
|
9095
|
+
idempotentHint: true,
|
|
9096
|
+
openWorldHint: false
|
|
9097
|
+
};
|
|
9098
|
+
var MUTATING4 = {
|
|
9099
|
+
readOnlyHint: false,
|
|
9100
|
+
destructiveHint: false,
|
|
9101
|
+
idempotentHint: false,
|
|
9102
|
+
openWorldHint: false
|
|
9103
|
+
};
|
|
9104
|
+
var roundsPath = (app, suffix = "") => `/v1/apps/${encodeURIComponent(app)}/mining/rounds${suffix}`;
|
|
9105
|
+
var roundPath = (app, run, suffix = "") => roundsPath(app, `/${encodeURIComponent(run)}${suffix}`);
|
|
9106
|
+
var BUSY_BACKOFF_MS = [500, 1e3, 2e3, 4e3];
|
|
9107
|
+
var POLL_INTERVAL_MS = 2e3;
|
|
9108
|
+
var DEFAULT_WAIT_SECONDS = 25;
|
|
9109
|
+
var MAX_WAIT_SECONDS = 120;
|
|
9110
|
+
var realSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
9111
|
+
function isBusy(err) {
|
|
9112
|
+
if (!(err instanceof ApiHttpError) || err.status !== 409) return false;
|
|
9113
|
+
try {
|
|
9114
|
+
const body = JSON.parse(err.body);
|
|
9115
|
+
return (body.details?.refused ?? body.error?.details?.refused) === "busy";
|
|
9116
|
+
} catch {
|
|
9117
|
+
return /"refused"\s*:\s*"busy"/.test(err.body);
|
|
9118
|
+
}
|
|
9119
|
+
}
|
|
9120
|
+
var handleMiningListRounds = (t, b, a) => runTool(
|
|
9121
|
+
() => apiJson(t, b, "GET", roundsPath(a.app_id), { params: { limit: a.limit, offset: a.offset } })
|
|
9122
|
+
);
|
|
9123
|
+
var handleMiningGetRound = (t, b, a) => runTool(() => apiJson(t, b, "GET", roundPath(a.app_id, a.run_id)));
|
|
9124
|
+
var handleMiningStartRound = (t, b, a) => runTool(
|
|
9125
|
+
() => a.phase === "reconcile" ? apiJson(t, b, "POST", roundsPath(a.app_id, "/reconcile")) : apiJson(t, b, "POST", roundsPath(a.app_id), {
|
|
9126
|
+
body: {
|
|
9127
|
+
...a.phase ? { phase: a.phase } : {},
|
|
9128
|
+
...a.dry_run !== void 0 ? { dry_run: a.dry_run } : {}
|
|
9129
|
+
}
|
|
9130
|
+
})
|
|
9131
|
+
);
|
|
9132
|
+
var handleMiningListRoundTools = (t, b, a) => runTool(() => apiJson(t, b, "GET", roundPath(a.app_id, a.run_id, "/tools")));
|
|
9133
|
+
async function handleMiningCallRoundTool(t, b, a, timing = {}) {
|
|
9134
|
+
const sleep2 = timing.sleep ?? realSleep;
|
|
9135
|
+
const now = timing.now ?? Date.now;
|
|
9136
|
+
return runTool(async () => {
|
|
9137
|
+
const path = roundPath(a.app_id, a.run_id, `/tools/${encodeURIComponent(a.name)}`);
|
|
9138
|
+
const body = { execution_epoch: a.execution_epoch, input: a.input ?? {} };
|
|
9139
|
+
let answer;
|
|
9140
|
+
for (let attempt = 0; ; attempt++) {
|
|
9141
|
+
try {
|
|
9142
|
+
answer = await apiJson(t, b, "POST", path, { body });
|
|
9143
|
+
break;
|
|
9144
|
+
} catch (err) {
|
|
9145
|
+
const backoff = BUSY_BACKOFF_MS[attempt];
|
|
9146
|
+
if (!isBusy(err) || backoff === void 0) throw err;
|
|
9147
|
+
await sleep2(backoff);
|
|
9148
|
+
}
|
|
9149
|
+
}
|
|
9150
|
+
if (answer?.status !== "running" || !answer.call_id) return answer;
|
|
9151
|
+
const waitMs = Math.min(a.wait_seconds ?? DEFAULT_WAIT_SECONDS, MAX_WAIT_SECONDS) * 1e3;
|
|
9152
|
+
const deadline = now() + waitMs;
|
|
9153
|
+
const callId = answer.call_id;
|
|
9154
|
+
while (now() < deadline) {
|
|
9155
|
+
await sleep2(POLL_INTERVAL_MS);
|
|
9156
|
+
const polled = await apiJson(
|
|
9157
|
+
t,
|
|
9158
|
+
b,
|
|
9159
|
+
"GET",
|
|
9160
|
+
roundPath(a.app_id, a.run_id, `/tools/calls/${encodeURIComponent(callId)}`),
|
|
9161
|
+
{ params: { execution_epoch: a.execution_epoch } }
|
|
9162
|
+
);
|
|
9163
|
+
if (polled?.status !== "running") return polled;
|
|
9164
|
+
}
|
|
9165
|
+
return {
|
|
9166
|
+
call_id: callId,
|
|
9167
|
+
status: "running",
|
|
9168
|
+
next_step: "The call is still running. Poll talonic_mining_get_round_tool_call with this call_id; heartbeat the task if its lease is close to expiring."
|
|
9169
|
+
};
|
|
9170
|
+
});
|
|
9171
|
+
}
|
|
9172
|
+
var handleMiningGetRoundToolCall = (t, b, a) => runTool(
|
|
9173
|
+
() => apiJson(
|
|
9174
|
+
t,
|
|
9175
|
+
b,
|
|
9176
|
+
"GET",
|
|
9177
|
+
roundPath(a.app_id, a.run_id, `/tools/calls/${encodeURIComponent(a.call_id)}`),
|
|
9178
|
+
{
|
|
9179
|
+
params: { execution_epoch: a.execution_epoch }
|
|
9180
|
+
}
|
|
9181
|
+
)
|
|
9182
|
+
);
|
|
9183
|
+
var DRIVER_FLOW = "FLOW for a round waiting for an outside driver: talonic_list_decision_tasks (the app's tasks) -> talonic_claim_decision_task (keep execution_epoch) -> talonic_read_decision_package (the round's brief and tools) -> talonic_mining_list_round_tools -> talonic_mining_call_round_tool, repeatedly, with talonic_heartbeat_decision_task before the lease ends -> talonic_submit_decision_task with outcome { summary, protocol_feedback }, evidence [] and a one-line rationale.";
|
|
9184
|
+
var AUTH_NOTE2 = "AUTH: a tlnc_ key needs a per-app 'decide' grant (plus 'read' for the round reads); an OAuth connector session needs the apps:decide scope and a live workspace role of senior_member or above. A 403 names what is missing: tell the user, do not retry.";
|
|
9185
|
+
var D2 = {
|
|
9186
|
+
listRounds: [
|
|
9187
|
+
"List an autonomous app's rule-finding rounds, newest first: phase, status, what each found, and for a round waiting for an outside driver its task state (claimed by whom, lease, deadline). `total` counts every round.",
|
|
9188
|
+
"USE WHEN: finding a round to drive or checking progress. ARGS: app_id, optional limit (max 200), offset."
|
|
9189
|
+
].join("\n"),
|
|
9190
|
+
getRound: [
|
|
9191
|
+
"Read one rule-finding round: phase, status, budget, findings, candidate rules, summary, and the driver block for an externally driven round.",
|
|
9192
|
+
"ARGS: app_id, run_id."
|
|
9193
|
+
].join("\n"),
|
|
9194
|
+
startRound: [
|
|
9195
|
+
"Start a rule-finding round on an autonomous app. Without phase the app's plan picks the next one; reconcile reviews rules whose candidates lapsed (needs configure access). dry_run re-grades without searching.",
|
|
9196
|
+
"USE WHEN: the user asks to look for new rules now. Only one externally driven round per app can be open (HTTP 409 with the open task otherwise).",
|
|
9197
|
+
"RETURNS: { run_id, status, phase, \u2026 }. A round with an outside driver then waits for a claim: see talonic_list_decision_tasks."
|
|
9198
|
+
].join("\n"),
|
|
9199
|
+
listTools: [
|
|
9200
|
+
"List the tools you may call on a round you hold the claim on, with their inputs, the round's remaining budget and the retry rule for a busy round.",
|
|
9201
|
+
"USE WHEN: right after claiming the round's decision task, or to check remaining budget.",
|
|
9202
|
+
DRIVER_FLOW,
|
|
9203
|
+
AUTH_NOTE2
|
|
9204
|
+
].join("\n"),
|
|
9205
|
+
callTool: [
|
|
9206
|
+
"Call one round tool by name with its input, as the current claimant. The call runs under the app's grants and the round's budgets; a tool's own error comes back as is_error:true with a reason, not as a failure of this call.",
|
|
9207
|
+
"Busy rounds are retried for you. A call that runs long is polled for up to wait_seconds (default 25, max 120); if it is still running you get its call_id: poll talonic_mining_get_round_tool_call.",
|
|
9208
|
+
"Do not call tools on one round in parallel. close_round is not a tool here: close the round with talonic_submit_decision_task.",
|
|
9209
|
+
"ARGS: app_id, run_id, execution_epoch, name, input (object, default {}), optional wait_seconds. A stale or foreign claim or an expired lease is HTTP 409: claim again.",
|
|
9210
|
+
AUTH_NOTE2
|
|
9211
|
+
].join("\n"),
|
|
9212
|
+
getCall: [
|
|
9213
|
+
"Read a round tool call that was still running: status running | done, and its content and is_error once done. Only the round's current claimant can read it.",
|
|
9214
|
+
"ARGS: app_id, run_id, call_id, execution_epoch.",
|
|
9215
|
+
AUTH_NOTE2
|
|
9216
|
+
].join("\n")
|
|
9217
|
+
};
|
|
9218
|
+
function registerMiningDriverTools(server, getToken, baseUrl, options = {}) {
|
|
9219
|
+
const t = getToken;
|
|
9220
|
+
const b = baseUrl;
|
|
9221
|
+
const decideMeta = options.invocable === false ? { _meta: { "talonic/can_invoke": false, "talonic/required_scope": DECIDE_SCOPE } } : {};
|
|
9222
|
+
server.registerTool(
|
|
9223
|
+
"talonic_mining_list_rounds",
|
|
9224
|
+
{
|
|
9225
|
+
title: "List Mining Rounds",
|
|
9226
|
+
description: D2.listRounds,
|
|
9227
|
+
inputSchema: {
|
|
9228
|
+
app_id: appId3,
|
|
9229
|
+
limit: z.number().int().min(1).max(200).optional(),
|
|
9230
|
+
offset: z.number().int().min(0).optional()
|
|
9231
|
+
},
|
|
9232
|
+
annotations: { title: "List Mining Rounds", ...READ_ONLY5 }
|
|
9233
|
+
},
|
|
9234
|
+
(a) => handleMiningListRounds(t, b, a)
|
|
9235
|
+
);
|
|
9236
|
+
server.registerTool(
|
|
9237
|
+
"talonic_mining_get_round",
|
|
9238
|
+
{
|
|
9239
|
+
title: "Get Mining Round",
|
|
9240
|
+
description: D2.getRound,
|
|
9241
|
+
inputSchema: { app_id: appId3, run_id: runId2 },
|
|
9242
|
+
annotations: { title: "Get Mining Round", ...READ_ONLY5 }
|
|
9243
|
+
},
|
|
9244
|
+
(a) => handleMiningGetRound(t, b, a)
|
|
9245
|
+
);
|
|
9246
|
+
server.registerTool(
|
|
9247
|
+
"talonic_mining_start_round",
|
|
9248
|
+
{
|
|
9249
|
+
title: "Start Mining Round",
|
|
9250
|
+
description: D2.startRound,
|
|
9251
|
+
inputSchema: {
|
|
9252
|
+
app_id: appId3,
|
|
9253
|
+
phase: z.enum(["discovery", "hypothesis", "reconcile"]).optional(),
|
|
9254
|
+
dry_run: z.boolean().optional()
|
|
9255
|
+
},
|
|
9256
|
+
annotations: { title: "Start Mining Round", ...MUTATING4 }
|
|
9257
|
+
},
|
|
9258
|
+
(a) => handleMiningStartRound(t, b, a)
|
|
9259
|
+
);
|
|
9260
|
+
server.registerTool(
|
|
9261
|
+
"talonic_mining_list_round_tools",
|
|
9262
|
+
{
|
|
9263
|
+
title: "List Round Tools",
|
|
9264
|
+
description: D2.listTools,
|
|
9265
|
+
inputSchema: { app_id: appId3, run_id: runId2 },
|
|
9266
|
+
annotations: { title: "List Round Tools", ...READ_ONLY5 },
|
|
9267
|
+
...decideMeta
|
|
9268
|
+
},
|
|
9269
|
+
(a) => handleMiningListRoundTools(t, b, a)
|
|
9270
|
+
);
|
|
9271
|
+
server.registerTool(
|
|
9272
|
+
"talonic_mining_call_round_tool",
|
|
9273
|
+
{
|
|
9274
|
+
title: "Call Round Tool",
|
|
9275
|
+
description: D2.callTool,
|
|
9276
|
+
inputSchema: {
|
|
9277
|
+
app_id: appId3,
|
|
9278
|
+
run_id: runId2,
|
|
9279
|
+
execution_epoch: executionEpoch3,
|
|
9280
|
+
name: toolName,
|
|
9281
|
+
input: z.record(z.string(), z.json()).optional().describe("The tool's input object."),
|
|
9282
|
+
wait_seconds: z.number().int().min(0).max(MAX_WAIT_SECONDS).optional().describe(`Seconds to keep polling a long call (default ${DEFAULT_WAIT_SECONDS}).`)
|
|
9283
|
+
},
|
|
9284
|
+
annotations: { title: "Call Round Tool", ...MUTATING4 },
|
|
9285
|
+
...decideMeta
|
|
9286
|
+
},
|
|
9287
|
+
(a) => handleMiningCallRoundTool(t, b, a)
|
|
9288
|
+
);
|
|
9289
|
+
server.registerTool(
|
|
9290
|
+
"talonic_mining_get_round_tool_call",
|
|
9291
|
+
{
|
|
9292
|
+
title: "Get Round Tool Call",
|
|
9293
|
+
description: D2.getCall,
|
|
9294
|
+
inputSchema: {
|
|
9295
|
+
app_id: appId3,
|
|
9296
|
+
run_id: runId2,
|
|
9297
|
+
call_id: zUuid().describe("call_id from talonic_mining_call_round_tool."),
|
|
9298
|
+
execution_epoch: executionEpoch3
|
|
9299
|
+
},
|
|
9300
|
+
annotations: { title: "Get Round Tool Call", ...READ_ONLY5 },
|
|
9301
|
+
...decideMeta
|
|
9302
|
+
},
|
|
9303
|
+
(a) => handleMiningGetRoundToolCall(t, b, a)
|
|
9304
|
+
);
|
|
9305
|
+
}
|
|
9306
|
+
function probeMiningInUse(token, baseUrl) {
|
|
9307
|
+
return probeAccessState(token, baseUrl, "/v1/apps", (body) => {
|
|
9308
|
+
const apps = body?.apps;
|
|
9309
|
+
return Array.isArray(apps) && apps.some((a) => a?.mode === "autonomous");
|
|
9310
|
+
});
|
|
9311
|
+
}
|
|
8571
9312
|
var DESCRIPTION11 = [
|
|
8572
9313
|
"Get the OCR-converted markdown text of a document.",
|
|
8573
9314
|
"",
|
|
@@ -9110,7 +9851,7 @@ async function handleGetSpec(getToken, baseUrl, args) {
|
|
|
9110
9851
|
return { ...spec, versions: versions.data ?? [] };
|
|
9111
9852
|
});
|
|
9112
9853
|
}
|
|
9113
|
-
var
|
|
9854
|
+
var READ_ONLY6 = {
|
|
9114
9855
|
readOnlyHint: true,
|
|
9115
9856
|
destructiveHint: false,
|
|
9116
9857
|
idempotentHint: true,
|
|
@@ -9123,7 +9864,7 @@ function registerSpecTools(server, getToken, baseUrl) {
|
|
|
9123
9864
|
title: "List pipelines",
|
|
9124
9865
|
description: LIST_DESCRIPTION5,
|
|
9125
9866
|
inputSchema: listSpecsInputSchema,
|
|
9126
|
-
annotations: { title: "List pipelines", ...
|
|
9867
|
+
annotations: { title: "List pipelines", ...READ_ONLY6 },
|
|
9127
9868
|
_meta: widgetToolMeta("listSpecs")
|
|
9128
9869
|
},
|
|
9129
9870
|
async (args) => handleListSpecs(getToken, baseUrl, args)
|
|
@@ -9134,7 +9875,7 @@ function registerSpecTools(server, getToken, baseUrl) {
|
|
|
9134
9875
|
title: "Look up a pipeline",
|
|
9135
9876
|
description: GET_DESCRIPTION4,
|
|
9136
9877
|
inputSchema: getSpecInputSchema,
|
|
9137
|
-
annotations: { title: "Look up a pipeline", ...
|
|
9878
|
+
annotations: { title: "Look up a pipeline", ...READ_ONLY6 },
|
|
9138
9879
|
_meta: widgetToolMeta("getSpec")
|
|
9139
9880
|
},
|
|
9140
9881
|
async (args) => handleGetSpec(getToken, baseUrl, args)
|
|
@@ -9350,7 +10091,7 @@ async function handleGetRunResults(getToken, baseUrl, args) {
|
|
|
9350
10091
|
return { run_kind: kind, ...body };
|
|
9351
10092
|
});
|
|
9352
10093
|
}
|
|
9353
|
-
var
|
|
10094
|
+
var READ_ONLY7 = {
|
|
9354
10095
|
readOnlyHint: true,
|
|
9355
10096
|
destructiveHint: false,
|
|
9356
10097
|
idempotentHint: true,
|
|
@@ -9379,7 +10120,7 @@ function registerRunTools(server, getToken, baseUrl) {
|
|
|
9379
10120
|
title: "Check run progress",
|
|
9380
10121
|
description: GET_RUN_DESCRIPTION,
|
|
9381
10122
|
inputSchema: runRefInputSchema,
|
|
9382
|
-
annotations: { title: "Check run progress", ...
|
|
10123
|
+
annotations: { title: "Check run progress", ...READ_ONLY7 },
|
|
9383
10124
|
_meta: widgetToolMeta("getRun")
|
|
9384
10125
|
},
|
|
9385
10126
|
async (args) => handleGetRun(getToken, baseUrl, args)
|
|
@@ -9390,7 +10131,7 @@ function registerRunTools(server, getToken, baseUrl) {
|
|
|
9390
10131
|
title: "Read run results",
|
|
9391
10132
|
description: RESULTS_DESCRIPTION,
|
|
9392
10133
|
inputSchema: resultsInputSchema,
|
|
9393
|
-
annotations: { title: "Read run results", ...
|
|
10134
|
+
annotations: { title: "Read run results", ...READ_ONLY7 },
|
|
9394
10135
|
_meta: widgetToolMeta("getRunResults")
|
|
9395
10136
|
},
|
|
9396
10137
|
async (args) => handleGetRunResults(getToken, baseUrl, args)
|
|
@@ -11647,7 +12388,7 @@ function registerToolGroups(server, keys, getToken, baseUrl) {
|
|
|
11647
12388
|
|
|
11648
12389
|
// package.json
|
|
11649
12390
|
var package_default = {
|
|
11650
|
-
version: "0.1.
|
|
12391
|
+
version: "0.1.105"};
|
|
11651
12392
|
|
|
11652
12393
|
// src/version.ts
|
|
11653
12394
|
var VERSION = package_default.version;
|
|
@@ -11710,6 +12451,16 @@ function buildServerInstructions(opts) {
|
|
|
11710
12451
|
"apps:decide consent and a senior_member role or above; on HTTP 403 tell the user",
|
|
11711
12452
|
"which consent or role is missing instead of retrying."
|
|
11712
12453
|
] : [],
|
|
12454
|
+
...opts.includeAppsToolset ? [
|
|
12455
|
+
"To build an app: talonic_create_app -> talonic_save_app_draft ->",
|
|
12456
|
+
"talonic_interpret_app_rules -> talonic_publish_app -> talonic_run_app (dry_run first) ->",
|
|
12457
|
+
"talonic_get_app_run or talonic_get_run_verdicts -> talonic_check_app_acceptance.",
|
|
12458
|
+
"Human Reviews: talonic_list_app_reviews -> talonic_resolve_app_review."
|
|
12459
|
+
] : [],
|
|
12460
|
+
...opts.includeMiningDriverTools ? [
|
|
12461
|
+
"A rule-finding round waiting for an outside driver is claimed and closed with the",
|
|
12462
|
+
"decision-task tools; in between, call its tools with talonic_mining_call_round_tool."
|
|
12463
|
+
] : [],
|
|
11713
12464
|
"Tools that change workspace data (saving schemas, app updates, decisions) should only",
|
|
11714
12465
|
"be called when the user asked for that change. Every error ends with a 'Next step'",
|
|
11715
12466
|
"line: follow it.",
|
|
@@ -11773,7 +12524,9 @@ function createServer(options) {
|
|
|
11773
12524
|
instructions: buildServerInstructions({
|
|
11774
12525
|
includeGenericExecutor: options.includeGenericExecutor !== false,
|
|
11775
12526
|
includeAgentTaskTools: options.includeAgentTaskTools !== false,
|
|
11776
|
-
includeDecisionTaskTools: options.includeDecisionTaskTools !== false
|
|
12527
|
+
includeDecisionTaskTools: options.includeDecisionTaskTools !== false,
|
|
12528
|
+
includeAppsToolset: options.includeAppsToolset === true,
|
|
12529
|
+
includeMiningDriverTools: options.includeMiningDriverTools === true
|
|
11777
12530
|
})
|
|
11778
12531
|
}
|
|
11779
12532
|
);
|
|
@@ -11815,6 +12568,14 @@ function createServer(options) {
|
|
|
11815
12568
|
invocable: options.decisionTasksInvocable !== false
|
|
11816
12569
|
});
|
|
11817
12570
|
}
|
|
12571
|
+
if (options.includeAppsToolset) {
|
|
12572
|
+
registerAppsToolset(server, rawToken, baseUrl);
|
|
12573
|
+
}
|
|
12574
|
+
if (options.includeMiningDriverTools) {
|
|
12575
|
+
registerMiningDriverTools(server, rawToken, baseUrl, {
|
|
12576
|
+
invocable: options.decisionTasksInvocable !== false
|
|
12577
|
+
});
|
|
12578
|
+
}
|
|
11818
12579
|
if (options.includeGrowthTools) {
|
|
11819
12580
|
registerGrowthTools(server, rawToken, baseUrl);
|
|
11820
12581
|
}
|
|
@@ -11915,6 +12676,8 @@ async function main(argv = process.argv.slice(2), env = process.env, out = (line
|
|
|
11915
12676
|
includePriceBaselineTools,
|
|
11916
12677
|
includePortfolioTools,
|
|
11917
12678
|
includeProcessesTools,
|
|
12679
|
+
appsToolsetAnswer,
|
|
12680
|
+
miningAnswer,
|
|
11918
12681
|
toolGroups
|
|
11919
12682
|
] = await Promise.all([
|
|
11920
12683
|
probeGrowthAccess(apiKey, baseUrl),
|
|
@@ -11928,8 +12691,12 @@ async function main(argv = process.argv.slice(2), env = process.env, out = (line
|
|
|
11928
12691
|
probePriceBaselineAccess(apiKey, baseUrl),
|
|
11929
12692
|
probePortfolioAccess(apiKey, baseUrl),
|
|
11930
12693
|
probeProcessesAccess(apiKey, baseUrl),
|
|
12694
|
+
probeAppsToolsetAccess(apiKey, baseUrl),
|
|
12695
|
+
probeMiningInUse(apiKey, baseUrl),
|
|
11931
12696
|
probeToolGroups(apiKey, baseUrl)
|
|
11932
12697
|
]);
|
|
12698
|
+
const includeAppsToolset = appsToolsetAnswer === true;
|
|
12699
|
+
const includeMiningDriverTools = miningAnswer === true;
|
|
11933
12700
|
const server = createServer({
|
|
11934
12701
|
apiKey,
|
|
11935
12702
|
...baseUrl ? { baseUrl } : {},
|
|
@@ -11944,6 +12711,8 @@ async function main(argv = process.argv.slice(2), env = process.env, out = (line
|
|
|
11944
12711
|
includePriceBaselineTools,
|
|
11945
12712
|
includePortfolioTools,
|
|
11946
12713
|
includeProcessesTools,
|
|
12714
|
+
includeAppsToolset,
|
|
12715
|
+
includeMiningDriverTools,
|
|
11947
12716
|
toolGroups
|
|
11948
12717
|
});
|
|
11949
12718
|
const transport = new StdioServerTransport();
|