@miadi/connector 0.1.36 → 0.1.38
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/README.md +2 -1
- package/dist/approve.d.ts +1 -1
- package/dist/approve.js +58 -12
- package/dist/capabilities-html.d.ts +12 -0
- package/dist/capabilities-html.js +109 -0
- package/dist/capabilities.d.ts +262 -0
- package/dist/capabilities.js +429 -0
- package/dist/local-transcription.js +3 -3
- package/dist/mission-result.d.ts +15 -0
- package/dist/mission-result.js +18 -21
- package/dist/record-shares.d.ts +48 -0
- package/dist/record-shares.js +60 -0
- package/dist/research-shelf.d.ts +53 -14
- package/dist/research-shelf.js +83 -16
- package/dist/server.d.ts +4 -2
- package/dist/server.js +2 -1
- package/dist/tools.d.ts +2 -0
- package/dist/tools.js +101 -13
- package/dist/transcript-job.d.ts +7 -1
- package/dist/transcript-job.js +44 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +12 -3
package/dist/tools.js
CHANGED
|
@@ -28,11 +28,13 @@ import { authorizesActions, missionStatus, primaryIssueOf, resolveMissionSubject
|
|
|
28
28
|
import { authorizationReceipt, authorizeProvider, CHOICE_PROVIDERS, isPersonId, needsPersonChoice, providerPolicyOf } from "./provider-policy.js";
|
|
29
29
|
import { candidatesFor, CRITICALITIES, jevAdapter, modelPreflight, PREFLIGHT_CONTRACT, PREFLIGHT_VERSION, TASK_TYPES, } from "./model-preflight.js";
|
|
30
30
|
import { ShelfRefusal, listShelfArtefacts, readShelfArtefact } from "./research-shelf.js";
|
|
31
|
+
import { isShareRelation, shareTarget } from "./record-shares.js";
|
|
31
32
|
import { DELIVERY_STATES, readSteerDelivery, revokeInInbox, settlementOf, transcriptPathOf } from "./runtime-steer.js";
|
|
32
33
|
import { ADAPTERS, readFactoryConfig, runSteering, STEERING_CONTRACT_ID, steeringSupport } from "./steering-adapters.js";
|
|
33
34
|
import { checkGrant, isBusy, steerAttempts, steeringGrantOf, steeringRevoked, steerSession } from "./steer.js";
|
|
34
35
|
import { factoryLedgerPath, readFactoryReceipts, receiptsForRecord, recordsForSession } from "./factory-receipt.js";
|
|
35
|
-
import { missionResult, redactResult } from "./mission-result.js";
|
|
36
|
+
import { associationOf, missionResult, redactResult } from "./mission-result.js";
|
|
37
|
+
import { capabilitiesInput, clonesFromEnv, readChangedCapabilities, resolveCapabilities } from "./capabilities.js";
|
|
36
38
|
import { factoryDir as defaultFactoryDir } from "./queue-state.js";
|
|
37
39
|
import { join } from "node:path";
|
|
38
40
|
import { readingScope, canonicalVideo, suppliedDialogue } from "./reading/contract.js";
|
|
@@ -124,6 +126,18 @@ const personWordsField = z.string().min(1).max(4000).optional().describe("The pe
|
|
|
124
126
|
function withPrimary(refs, primary) {
|
|
125
127
|
return primary ? [primary, ...refs.filter((r) => r !== primary)] : refs;
|
|
126
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* What a mission names, resolved against the registry before anything is stored: an address the
|
|
131
|
+
* registry does not hold is refused by name (brings-into-being may name one with no row yet), and one
|
|
132
|
+
* refusal stores nothing (jgwill/Miadi#993).
|
|
133
|
+
*/
|
|
134
|
+
function declareCapabilities(input) {
|
|
135
|
+
const { declared, refused } = resolveCapabilities(input);
|
|
136
|
+
if (refused.length) {
|
|
137
|
+
throw new ToolRefusal(refused.every((r) => r.code === "not_in_registry") ? "unknown_capability" : "invalid_capability", `${refused.map((r) => r.message).join(" ")} Nothing was stored.`, { refused });
|
|
138
|
+
}
|
|
139
|
+
return declared;
|
|
140
|
+
}
|
|
127
141
|
/**
|
|
128
142
|
* Why GitHub did not answer a reference (jgwill/Miadi#913 B). A 404 without a
|
|
129
143
|
* token is a private repository as often as a missing issue, so nothing here is
|
|
@@ -216,7 +230,9 @@ export function registerTools(server, ctx) {
|
|
|
216
230
|
let viewer;
|
|
217
231
|
/**
|
|
218
232
|
* The signed-in person, held to Miadi's read tier unless the tool says
|
|
219
|
-
* otherwise: a person Miadi gives no API tier reaches
|
|
233
|
+
* otherwise: a person Miadi gives no API tier reaches get_capabilities,
|
|
234
|
+
* read_episode_file's foundation documents and the inquiry shelf's two reads,
|
|
235
|
+
* where the shelf's own rule decides (jgwill/Miadi#1005).
|
|
220
236
|
*/
|
|
221
237
|
const who = (extra, minTier = "read") => {
|
|
222
238
|
const found = personOf(extra);
|
|
@@ -413,7 +429,7 @@ export function registerTools(server, ctx) {
|
|
|
413
429
|
follow: "review_transcript_status",
|
|
414
430
|
status_page: `${config.publicUrl}/transcripts/<review id>`,
|
|
415
431
|
captions: ctx.approval?.captions ? "on (the video's spoken-language track)" : "off",
|
|
416
|
-
local_transcription: ctx.approval?.localTranscription ? "on (a
|
|
432
|
+
local_transcription: ctx.approval?.localTranscription ? "on (a video with no captions is transcribed from its audio on this host, never a withheld source)" : "off (the operator enables it with MIADI_TRANSCRIPT_LOCAL=faster-whisper)",
|
|
417
433
|
review_service_token: reviews.canSearch ? "present" : "absent",
|
|
418
434
|
decision_required: false,
|
|
419
435
|
independent_of_public_import: true,
|
|
@@ -925,7 +941,7 @@ export function registerTools(server, ctx) {
|
|
|
925
941
|
}));
|
|
926
942
|
server.registerTool("ensure_review_transcript", {
|
|
927
943
|
title: "Make sure a review holds its video's transcript",
|
|
928
|
-
description: "For an existing review made anywhere (the review service's own page, a manual edit, another client), acquire its video's transcript, store it on the review and read it back. It runs now under the authority that already covers processing a review: no transcript decision is asked, and nothing needs pasting. A transcript the review already holds is reused and kept. It takes the video's spoken-language YouTube captions,
|
|
944
|
+
description: "For an existing review made anywhere (the review service's own page, a manual edit, another client), acquire its video's transcript, store it on the review and read it back. It runs now under the authority that already covers processing a review: no transcript decision is asked, and nothing needs pasting. A transcript the review already holds is reused and kept. It takes the video's spoken-language YouTube captions and, when the video has none, transcribes its audio on the Miadi host where the operator enabled that. It calls no model service. A source registered as withheld is held until released. It never overwrites, never creates a version and never publishes. It answers within about 20 seconds with the job's progress, a plain summary and links, and the job goes on if it needs longer: follow it with review_transcript_status or the status link. Asking again is safe; it joins the running attempt. Needs a person who may contribute and who holds the write tier or registered the video's source.",
|
|
929
945
|
inputSchema: { review: z.string().min(1).describe("Review id, miadi-review:<uuid>, review URL, or the video's YouTube URL or id (when exactly one review of it exists)."), intention: z.string().max(2000).optional().describe("Why the transcript is needed, recorded with the job.") },
|
|
930
946
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
931
947
|
}, wrap(async (a, extra) => {
|
|
@@ -1351,12 +1367,22 @@ export function registerTools(server, ctx) {
|
|
|
1351
1367
|
}));
|
|
1352
1368
|
server.registerTool("link_records", {
|
|
1353
1369
|
title: "Relate two references",
|
|
1354
|
-
description: "Record a relation between two references (a review and an episode, a session and an issue, a beat and a source), with the relation's name and why."
|
|
1370
|
+
description: "Record a relation between two references (a review and an episode, a session and an issue, a beat and a source), with the relation's name and why. " +
|
|
1371
|
+
"To share a record you made (an inquiry, a handoff, a proposal) with a talking circle or one person, link from the record's id to miadi-circle:<circle id> or the person's id with the relation shared_with: its members, or that person, then read it on the record's page and in My Research. The relation share_withdrawn, from the same record to the same reader, ends the share. Only a record's author shares it.",
|
|
1355
1372
|
inputSchema: { from: z.string().min(1), to: z.string().min(1), relation: z.string().min(1).max(80), note: z.string().max(2000).optional(), ...base },
|
|
1356
1373
|
annotations: WRITE,
|
|
1357
1374
|
}, wrap(async (a, extra) => {
|
|
1358
1375
|
const { person, auth } = who(extra);
|
|
1359
1376
|
requireContribute(auth);
|
|
1377
|
+
if (isShareRelation(a.relation)) {
|
|
1378
|
+
const shared = all().find((r) => r.id === a.from);
|
|
1379
|
+
if (!shared)
|
|
1380
|
+
throw new ToolRefusal("not_found", `No record with the id ${a.from}: a share links from a record's id.`);
|
|
1381
|
+
if (shared.actor.person_id !== person.id)
|
|
1382
|
+
throw new ToolRefusal("forbidden", "Only a record's author shares it, or withdraws a share; this record was made by someone else.");
|
|
1383
|
+
if (!shareTarget(a.to))
|
|
1384
|
+
throw new ToolRefusal("invalid_ref", "A share reaches a talking circle (miadi-circle:<circle id>) or one person (their node id).");
|
|
1385
|
+
}
|
|
1360
1386
|
return append("link", person, auth, {
|
|
1361
1387
|
refs: [a.from, a.to],
|
|
1362
1388
|
intention: a.intention,
|
|
@@ -1544,6 +1570,7 @@ export function registerTools(server, ctx) {
|
|
|
1544
1570
|
repo: z.string().max(120).optional(),
|
|
1545
1571
|
delivery: deliveryField,
|
|
1546
1572
|
person_words: personWordsField,
|
|
1573
|
+
capabilities: capabilitiesInput.optional(),
|
|
1547
1574
|
...launchModelFields,
|
|
1548
1575
|
...base,
|
|
1549
1576
|
},
|
|
@@ -1558,6 +1585,7 @@ export function registerTools(server, ctx) {
|
|
|
1558
1585
|
const plan = modelPlan(resolution.provider.id, a.model, modelConfig().permitted);
|
|
1559
1586
|
if ("refusal" in plan)
|
|
1560
1587
|
throw new ToolRefusal(plan.refusal.code, plan.refusal.message, { permitted: plan.refusal.permitted });
|
|
1588
|
+
const capabilities = a.capabilities?.length ? declareCapabilities(a.capabilities) : undefined;
|
|
1561
1589
|
const r = append("work_proposal", person, auth, {
|
|
1562
1590
|
circle: a.circle,
|
|
1563
1591
|
refs: withPrimary(a.refs, a.primary_issue),
|
|
@@ -1577,6 +1605,7 @@ export function registerTools(server, ctx) {
|
|
|
1577
1605
|
...(a.primary_issue ? { primary_issue: a.primary_issue } : {}),
|
|
1578
1606
|
...(a.delivery ? { delivery: a.delivery } : {}),
|
|
1579
1607
|
...(a.person_words ? { person_words: a.person_words } : {}),
|
|
1608
|
+
...(capabilities ? { capabilities } : {}),
|
|
1580
1609
|
},
|
|
1581
1610
|
});
|
|
1582
1611
|
return { ...r, approval_url: approvalUrl(r.id), draft_review: await draftReviewOf(r) };
|
|
@@ -1651,18 +1680,55 @@ export function registerTools(server, ctx) {
|
|
|
1651
1680
|
requireContribute(auth);
|
|
1652
1681
|
const id = a.session_id.replace(/^session:/, "");
|
|
1653
1682
|
const startedAt = new Date().toISOString();
|
|
1683
|
+
// The capabilities its commits changed, read from the commits themselves and set against what the mission declared (jgwill/Miadi#993).
|
|
1684
|
+
// A submission already waiting is handed back unchanged by append, so it is not read a second time.
|
|
1685
|
+
const idempotencyKey = a.mission ? `${id}:${a.ending}:${a.mission}` : `${id}:${a.ending}`;
|
|
1686
|
+
const waiting = all().some((x) => x.kind === "session_completion_proposal" && x.idempotency_key === idempotencyKey && x.actor.person_id === person.id && (x.approval_state === undefined || x.approval_state === "awaiting_approval" || x.approval_state === "not_required"));
|
|
1687
|
+
const named = [...(a.result?.outputs ?? []), ...(a.evidence_refs ?? []).map((ref) => ({ ref }))];
|
|
1688
|
+
let changedCapabilities;
|
|
1689
|
+
if (!waiting && named.length) {
|
|
1690
|
+
try {
|
|
1691
|
+
const mission = a.mission ? all().find((x) => x.id === a.mission) : undefined;
|
|
1692
|
+
// Holdings are filed only for a result read as verified by the rule a mission's result is read by: an approved
|
|
1693
|
+
// mission, a submission that names it from a session it is bound to, made with the write tier (#922 R3, R4).
|
|
1694
|
+
const bound = new Set(mission ? receiptsForRecord(receipts(), mission.id).flatMap((x) => (x.session_id ? [x.session_id] : [])) : []);
|
|
1695
|
+
if (mission && !bound.size)
|
|
1696
|
+
for (const ref of mission.refs)
|
|
1697
|
+
if (/^session:[0-9a-f-]{36}$/.test(ref))
|
|
1698
|
+
bound.add(ref.slice(8));
|
|
1699
|
+
const association = associationOf({ names: Boolean(mission), sessionId: id, boundSessions: bound, writeTier: person.id === "system:writer" || person.api_tier === "write" });
|
|
1700
|
+
const REASON = {
|
|
1701
|
+
no_binding: "the mission has no bound session to compare this one with",
|
|
1702
|
+
not_bound_session: "this session is not one the mission is bound to",
|
|
1703
|
+
submitter_below_write_tier: "the submission was made below Miadi's write tier",
|
|
1704
|
+
};
|
|
1705
|
+
const filing = !mission
|
|
1706
|
+
? { allowed: false, reason: a.mission ? "the mission this completion names is not in the ledger" : "the completion names no mission" }
|
|
1707
|
+
: mission.approval_state !== "approved"
|
|
1708
|
+
? { allowed: false, reason: `the mission is ${(mission.approval_state ?? "undecided").replace(/_/g, " ")}, not approved` }
|
|
1709
|
+
: association.association !== "verified"
|
|
1710
|
+
? { allowed: false, reason: REASON[association.code ?? ""] ?? "the submission is not verified as the mission's result" }
|
|
1711
|
+
: { allowed: true };
|
|
1712
|
+
changedCapabilities = await readChangedCapabilities({ outputs: named, sessionId: id, ...(mission ? { mission } : {}), ...(a.mission ? { missionId: a.mission } : {}), filing, clones: ctx.clones ?? clonesFromEnv() });
|
|
1713
|
+
}
|
|
1714
|
+
catch {
|
|
1715
|
+
// A registry or a clone that cannot answer never refuses the ending: it is stored without the reading.
|
|
1716
|
+
changedCapabilities = undefined;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1654
1719
|
const r = append("session_completion_proposal", person, auth, {
|
|
1655
1720
|
circle: "continuity",
|
|
1656
1721
|
refs: a.mission ? [`session:${id}`, a.mission] : [`session:${id}`],
|
|
1657
1722
|
evidence_refs: a.evidence_refs,
|
|
1658
1723
|
approval_state: "awaiting_approval",
|
|
1659
|
-
idempotency_key:
|
|
1724
|
+
idempotency_key: idempotencyKey,
|
|
1660
1725
|
body: {
|
|
1661
1726
|
session_id: id,
|
|
1662
1727
|
ending: a.ending,
|
|
1663
1728
|
reason: a.reason,
|
|
1664
1729
|
...(a.mission ? { mission: a.mission } : {}),
|
|
1665
1730
|
...(a.result ? { result: a.result } : {}),
|
|
1731
|
+
...(changedCapabilities ? { changed_capabilities: changedCapabilities } : {}),
|
|
1666
1732
|
// Set by the connector, never by the caller: a result is verified only when the write tier submits it (#922 R3).
|
|
1667
1733
|
submitted_with_tier: person.api_tier ?? null,
|
|
1668
1734
|
},
|
|
@@ -1755,6 +1821,7 @@ export function registerTools(server, ctx) {
|
|
|
1755
1821
|
primary_issue: primaryIssue,
|
|
1756
1822
|
delivery: deliveryField,
|
|
1757
1823
|
person_words: personWordsField,
|
|
1824
|
+
capabilities: capabilitiesInput.optional(),
|
|
1758
1825
|
session: z.string().regex(/^[A-Za-z0-9._-]{3,80}$/).optional().describe("An existing tmux session to hand it to, or a name for a new one."),
|
|
1759
1826
|
cwd: z.string().max(300).optional().describe("Working folder for a new session (default: the factory runner's defaultCwd on the host)."),
|
|
1760
1827
|
provider: z
|
|
@@ -1787,6 +1854,7 @@ export function registerTools(server, ctx) {
|
|
|
1787
1854
|
const plan = modelPlan(resolution.provider.id, a.model, modelConfig().permitted);
|
|
1788
1855
|
if ("refusal" in plan)
|
|
1789
1856
|
throw new ToolRefusal(plan.refusal.code, plan.refusal.message, { permitted: plan.refusal.permitted });
|
|
1857
|
+
const capabilities = a.capabilities?.length ? declareCapabilities(a.capabilities) : undefined;
|
|
1790
1858
|
const r = append("run_request", person, auth, {
|
|
1791
1859
|
circle: a.circle,
|
|
1792
1860
|
refs: withPrimary(a.refs, a.primary_issue),
|
|
@@ -1807,6 +1875,7 @@ export function registerTools(server, ctx) {
|
|
|
1807
1875
|
...(a.primary_issue ? { primary_issue: a.primary_issue } : {}),
|
|
1808
1876
|
...(a.delivery ? { delivery: a.delivery } : {}),
|
|
1809
1877
|
...(a.person_words ? { person_words: a.person_words } : {}),
|
|
1878
|
+
...(capabilities ? { capabilities } : {}),
|
|
1810
1879
|
...(a.steering ? { steering: a.steering } : {}),
|
|
1811
1880
|
},
|
|
1812
1881
|
});
|
|
@@ -1865,6 +1934,7 @@ export function registerTools(server, ctx) {
|
|
|
1865
1934
|
primary_issue: primaryIssue,
|
|
1866
1935
|
delivery: deliveryField,
|
|
1867
1936
|
person_words: personWordsField,
|
|
1937
|
+
capabilities: capabilitiesInput.optional().describe("The whole new list of capabilities the mission reaches, replacing the old one; an empty list names none. Each address is checked as request_authorized_run checks it."),
|
|
1868
1938
|
session: z.string().regex(/^[A-Za-z0-9._-]{3,80}$/).optional(),
|
|
1869
1939
|
cwd: z.string().max(300).optional(),
|
|
1870
1940
|
provider: z.enum(["codex", "pi", "copilot", "claude"]).optional().describe("Verified installed on the connector host again, as request_authorized_run does."),
|
|
@@ -1934,6 +2004,13 @@ export function registerTools(server, ctx) {
|
|
|
1934
2004
|
for (const k of ["delivery", "person_words"])
|
|
1935
2005
|
if (c[k] !== undefined)
|
|
1936
2006
|
body[k] = c[k];
|
|
2007
|
+
if (c.capabilities !== undefined && (live?.kind === "run_request" || live?.kind === "work_proposal")) {
|
|
2008
|
+
const declared = c.capabilities.length ? declareCapabilities(c.capabilities) : [];
|
|
2009
|
+
if (declared.length)
|
|
2010
|
+
body.capabilities = declared;
|
|
2011
|
+
else
|
|
2012
|
+
delete body.capabilities;
|
|
2013
|
+
}
|
|
1937
2014
|
const nextRefs = withPrimary(c.refs ?? live?.refs ?? [], c.primary_issue ?? body.primary_issue);
|
|
1938
2015
|
let record;
|
|
1939
2016
|
try {
|
|
@@ -2453,11 +2530,18 @@ export function registerTools(server, ctx) {
|
|
|
2453
2530
|
research_url: `${config.miadiPublicUrl}/research`,
|
|
2454
2531
|
};
|
|
2455
2532
|
}));
|
|
2533
|
+
/** The talking circles this person sits in now, through Miadi as them, read only when a folder is shared with a circle (jgwill/Miadi#1005). */
|
|
2534
|
+
const circlesOf = (token) => async () => {
|
|
2535
|
+
const b = await miadi.get(token, "/api/circles").catch((e) => {
|
|
2536
|
+
throw new ToolRefusal("unavailable", `Your circles could not be read from Miadi (${e instanceof MiadiError ? `HTTP ${e.status}` : "unreachable"}), so what reaches you through a circle cannot be decided now.`);
|
|
2537
|
+
});
|
|
2538
|
+
return (b?.circles ?? []).filter((c) => c?.member === true && typeof c.id === "string").map((c) => c.id);
|
|
2539
|
+
};
|
|
2456
2540
|
server.registerTool("list_research_artifacts", {
|
|
2457
2541
|
title: "List what is on the inquiry shelf",
|
|
2458
|
-
description: "Reports and folders on Miadi's private inquiry shelf, as you may read them: each one's title, opening, words, sections, sources, files, date, owner, visibility, issue, episodes and, for a saved report, its sha256. All of it is computed from the files, never summarised. scope mine lists what you own; scope all, for Miadi's write tier, lists every folder. Search with query, narrow with kind, order with sort, and page with offset and next_offset. Read one with read_research_artifact. Read only: nothing is changed.",
|
|
2542
|
+
description: "Reports and folders on Miadi's private inquiry shelf, as you may read them: each one's title, opening, words, sections, sources, files, date, owner, visibility, issue, episodes and, for a saved report, its sha256. All of it is computed from the files, never summarised. Each says in access how it reaches you: as its owner, shared with you directly by a named person, through a talking circle you sit in (named), or as Miadi's write tier. scope mine lists what you own; scope shared lists what other people shared with you or with your circles; scope all, for Miadi's write tier, lists every folder. Search with query, narrow with kind, order with sort, and page with offset and next_offset. Read one with read_research_artifact. Read only: nothing is changed.",
|
|
2459
2543
|
inputSchema: {
|
|
2460
|
-
scope: z.enum(["mine", "all"]).default("mine"),
|
|
2544
|
+
scope: z.enum(["mine", "shared", "all"]).default("mine"),
|
|
2461
2545
|
query: z.string().max(200).optional().describe("Words to find in a title, an opening, a heading or a folder's name."),
|
|
2462
2546
|
kind: z.enum(["report", "folder", "notes"]).optional().describe("report: saved through a door. folder: holds a document. notes: agent instructions or unreadable files only."),
|
|
2463
2547
|
sort: z.enum(["newest", "oldest", "longest", "title"]).default("newest"),
|
|
@@ -2466,12 +2550,14 @@ export function registerTools(server, ctx) {
|
|
|
2466
2550
|
},
|
|
2467
2551
|
annotations: READ,
|
|
2468
2552
|
}, wrap(async (a, extra) => {
|
|
2469
|
-
|
|
2553
|
+
// No API tier needed: the shelf's own rule (shelfAccess) decides who reads what, and scope all stays the write tier's (jgwill/Miadi#1005).
|
|
2554
|
+
const { person } = who(extra, "none");
|
|
2470
2555
|
if (!config.inquiryRoot)
|
|
2471
2556
|
throw new ToolRefusal("unavailable", "This connector host has no inquiry shelf configured.");
|
|
2472
2557
|
try {
|
|
2473
2558
|
const { scope, query, kind, sort, limit, offset } = a;
|
|
2474
2559
|
return await listShelfArtefacts(config.inquiryRoot, person, {
|
|
2560
|
+
circles: circlesOf(person.token),
|
|
2475
2561
|
...(scope ? { scope } : {}),
|
|
2476
2562
|
...(query ? { query } : {}),
|
|
2477
2563
|
...(kind ? { kind } : {}),
|
|
@@ -2488,7 +2574,7 @@ export function registerTools(server, ctx) {
|
|
|
2488
2574
|
}));
|
|
2489
2575
|
server.registerTool("read_research_artifact", {
|
|
2490
2576
|
title: "Read a document on the inquiry shelf",
|
|
2491
|
-
description: "Read back what is on Miadi's private inquiry shelf, as you: a folder's owner, visibility, its issue, its episodes, the commit that holds it, whether anything on disk differs from that commit, and every file with its bytes and sha256. With the folder's report, or the file you name, you also get its text, in pages when long: pass page.next back; joined, the pages hash to sha256. integrity says whether a saved report's bytes are still the bytes saved.
|
|
2577
|
+
description: "Read back what is on Miadi's private inquiry shelf, as you: a folder's owner, visibility, its issue, its episodes, the commit that holds it, whether anything on disk differs from that commit, and every file with its bytes and sha256. With the folder's report, or the file you name, you also get its text, in pages when long: pass page.next back; joined, the pages hash to sha256. integrity says whether a saved report's bytes are still the bytes saved. Its owner reads it, and so does a person it is shared with, a member of a talking circle it is shared with (while they sit in it), and a person with Miadi's write tier; access says which of these you read it as, and through which circle or from whom. Text files only; hidden files and links are never served. Read only: nothing is changed.",
|
|
2492
2578
|
inputSchema: {
|
|
2493
2579
|
artefact: z.string().min(1).max(300).describe("The shelf folder's name, inquiry-artefact:<name> or the research_artifact record id save_research returned."),
|
|
2494
2580
|
file: z.string().min(1).max(500).optional().describe("A path in the folder, as files lists it. Default: its saved report, if it has one."),
|
|
@@ -2498,7 +2584,8 @@ export function registerTools(server, ctx) {
|
|
|
2498
2584
|
},
|
|
2499
2585
|
annotations: READ,
|
|
2500
2586
|
}, wrap(async (a, extra) => {
|
|
2501
|
-
|
|
2587
|
+
// No API tier needed: a participant reads what is shared with them; shelfAccess decides (jgwill/Miadi#1005).
|
|
2588
|
+
const { person } = who(extra, "none");
|
|
2502
2589
|
if (!config.inquiryRoot)
|
|
2503
2590
|
throw new ToolRefusal("unavailable", "This connector host has no inquiry shelf configured.");
|
|
2504
2591
|
const ref = a.artefact.trim();
|
|
@@ -2513,6 +2600,7 @@ export function registerTools(server, ctx) {
|
|
|
2513
2600
|
try {
|
|
2514
2601
|
const { file, offset, revision, max_bytes: maxBytes } = a;
|
|
2515
2602
|
return await readShelfArtefact(config.inquiryRoot, name, person, {
|
|
2603
|
+
circles: circlesOf(person.token),
|
|
2516
2604
|
...(file !== undefined ? { file } : {}),
|
|
2517
2605
|
...(offset !== undefined ? { offset } : {}),
|
|
2518
2606
|
...(revision !== undefined ? { revision } : {}),
|
|
@@ -2870,8 +2958,8 @@ export const TOOL_STATUS = {
|
|
|
2870
2958
|
request_deep_diver: "live, contribute, needs_approval",
|
|
2871
2959
|
link_review_to_episode: "live, contribute, needs_approval",
|
|
2872
2960
|
save_research: "live, contribute (the whole report, in parts when long; saved on the inquiry shelf with its issue, pushed; private by default)",
|
|
2873
|
-
list_research_artifacts: "live (the shelf as you may read it: yours, or every folder for the write tier; searched, sorted, paged)",
|
|
2874
|
-
read_research_artifact: "live (a shelf folder's manifest and its text files, paged, with sha256 and the commit that holds them; its owner or Miadi's write tier)",
|
|
2961
|
+
list_research_artifacts: "live, no API tier needed (the shelf as you may read it: yours, what is shared with you or your circles, or every folder for the write tier; searched, sorted, paged)",
|
|
2962
|
+
read_research_artifact: "live, no API tier needed (a shelf folder's manifest and its text files, paged, with sha256 and the commit that holds them; its owner, whom it is shared with, the members of a circle it is shared with, or Miadi's write tier)",
|
|
2875
2963
|
request_inquiry_episode: "live, contribute, needs_approval (weaves a shelf folder into an episode or starts one)",
|
|
2876
2964
|
show_decisions: "live (cards in the conversation; deciding on them needs the write tier and the miadi:approve sign-in)",
|
|
2877
2965
|
decide_request: "card only: the person's click on a decisions card; not offered to the assistant",
|
package/dist/transcript-job.d.ts
CHANGED
|
@@ -50,6 +50,10 @@ export interface TranscriptJobReceipt {
|
|
|
50
50
|
stored_at?: string;
|
|
51
51
|
readback?: Readback;
|
|
52
52
|
failure?: JobFailure;
|
|
53
|
+
/** The approved mission a worker later ran this job under (missionAuthority), recorded with the job it joined. */
|
|
54
|
+
authority?: Record<string, unknown>;
|
|
55
|
+
/** How many times this window ran the host's transcription of the audio. */
|
|
56
|
+
local_attempts?: number;
|
|
53
57
|
stages: JobStage[];
|
|
54
58
|
}
|
|
55
59
|
export interface ServiceAnswer {
|
|
@@ -95,7 +99,7 @@ export interface TranscriptJobIo {
|
|
|
95
99
|
service: ReviewTranscriptService;
|
|
96
100
|
/** The video's spoken-language captions. */
|
|
97
101
|
captions?: FetchCaptions;
|
|
98
|
-
/** A transcription made on this host, tried when captions
|
|
102
|
+
/** A transcription of the video's audio made on this host, tried when the video has no captions. Never for a withheld source. */
|
|
99
103
|
local?: FetchCaptions;
|
|
100
104
|
now?: () => number;
|
|
101
105
|
log?: (event: Record<string, unknown>) => void;
|
|
@@ -109,6 +113,8 @@ export interface TranscriptJobIo {
|
|
|
109
113
|
/** Told once each time a job reaches an ending (stored, held, failed), to announce it as a fact. Never fails the job. */
|
|
110
114
|
outcome?: (job: ConnectorRecord, receipt: TranscriptJobReceipt) => void | Promise<unknown>;
|
|
111
115
|
}
|
|
116
|
+
/** How many times one window runs this host's transcription of the audio before the job fails with what it last answered. */
|
|
117
|
+
export declare const MAX_LOCAL_ATTEMPTS = 3;
|
|
112
118
|
/** How long an attempt this process does not run may go without writing a stage before it counts as abandoned. */
|
|
113
119
|
export declare const STALE_MS: number;
|
|
114
120
|
export declare const jobKey: (reviewId: string) => string;
|
package/dist/transcript-job.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* 1. reuse: the review service already holds one, which stays (it is read back and its digest kept);
|
|
9
9
|
* 2. source: a source registered as withheld is neither read nor stored, until it is released;
|
|
10
10
|
* 3. acquire: the video's spoken-language captions, then a local transcription where the host enables it
|
|
11
|
-
*
|
|
11
|
+
* when the video has none. No model service is called and nothing here costs money;
|
|
12
12
|
* 4. store: one POST that never overwrites;
|
|
13
13
|
* 5. readback: the stored text is read from the service and its digest compared with what was sent.
|
|
14
14
|
*
|
|
@@ -74,6 +74,8 @@ const clock = (io) => (io.now ?? Date.now)();
|
|
|
74
74
|
const iso = (ms) => new Date(ms).toISOString();
|
|
75
75
|
/** A job that waits three days keeps the last stages only, so its receipt does not grow with every retry. */
|
|
76
76
|
const MAX_STAGES = 24;
|
|
77
|
+
/** How many times one window runs this host's transcription of the audio before the job fails with what it last answered. */
|
|
78
|
+
export const MAX_LOCAL_ATTEMPTS = 3;
|
|
77
79
|
/** How long an attempt this process does not run may go without writing a stage before it counts as abandoned. */
|
|
78
80
|
export const STALE_MS = 5 * 60_000;
|
|
79
81
|
export const jobKey = (reviewId) => `transcript:${reviewId}`;
|
|
@@ -203,6 +205,22 @@ const failures = {
|
|
|
203
205
|
owner: "operator",
|
|
204
206
|
retry: "none scheduled; ensure_review_transcript starts a new three-day window",
|
|
205
207
|
}),
|
|
208
|
+
// The video has no captions and this host does not transcribe audio: the job still retries (a track can arrive late),
|
|
209
|
+
// and names who can change the answer instead of saying nothing is needed.
|
|
210
|
+
local_off: (message) => ({
|
|
211
|
+
code: "waiting_for_captions",
|
|
212
|
+
message: `${message} Local transcription is off on this host, so the video's audio is not transcribed.`,
|
|
213
|
+
remedy: "An operator enables local transcription on the host (MIADI_TRANSCRIPT_LOCAL=faster-whisper). The next pass then transcribes the audio.",
|
|
214
|
+
owner: "operator",
|
|
215
|
+
retry: "every 15 minutes",
|
|
216
|
+
}),
|
|
217
|
+
local_failed: (message, attempts) => ({
|
|
218
|
+
code: "local_transcription_failed",
|
|
219
|
+
message: `The video has no usable captions, and this host's transcription of its audio produced no transcript in ${attempts} attempts. Last answer: ${message}`,
|
|
220
|
+
remedy: "Read the last answer. A video past the host's limit needs MIADI_TRANSCRIPT_LOCAL_MAX_MINUTES raised, and an engine error needs the host repaired. Then run ensure_review_transcript again, or the source owner supplies the exact transcript through request_review_operation store_transcript.",
|
|
221
|
+
owner: "operator",
|
|
222
|
+
retry: "none scheduled; ensure_review_transcript starts a new window",
|
|
223
|
+
}),
|
|
206
224
|
no_provider: () => ({
|
|
207
225
|
code: "provider_unavailable",
|
|
208
226
|
message: "This connector host has no way to read captions.",
|
|
@@ -240,11 +258,11 @@ async function attempt(io, startJob) {
|
|
|
240
258
|
delete r.next_attempt_at;
|
|
241
259
|
return save(note);
|
|
242
260
|
};
|
|
243
|
-
const wait = (code, message, stage, usedLocal = false) => {
|
|
261
|
+
const wait = (code, message, stage, usedLocal = false, specific) => {
|
|
244
262
|
const expired = clock(io) - Date.parse(r.since) >= TRANSCRIPT_WINDOW_MS;
|
|
245
263
|
if (expired)
|
|
246
264
|
return fail(failures.no_captions(message, usedLocal), stage, "Three days passed without a transcript.");
|
|
247
|
-
mark(stage, "waiting", message);
|
|
265
|
+
mark(stage, "waiting", specific?.message ?? message);
|
|
248
266
|
const next = clock(io) + TRANSCRIPT_RETRY_MS;
|
|
249
267
|
r = {
|
|
250
268
|
...r,
|
|
@@ -252,7 +270,9 @@ async function attempt(io, startJob) {
|
|
|
252
270
|
phase: code,
|
|
253
271
|
next_attempt_at: iso(next),
|
|
254
272
|
give_up_at: iso(Date.parse(r.since) + TRANSCRIPT_WINDOW_MS),
|
|
255
|
-
failure:
|
|
273
|
+
failure: specific
|
|
274
|
+
? { ...specific, retry: `every 15 minutes until ${iso(Date.parse(r.since) + TRANSCRIPT_WINDOW_MS)}` }
|
|
275
|
+
: { code, message, remedy: "None needed: the connector tries again by itself.", owner: "none", retry: `every 15 minutes until ${iso(Date.parse(r.since) + TRANSCRIPT_WINDOW_MS)}` },
|
|
256
276
|
};
|
|
257
277
|
return save(`Tries again at ${r.next_attempt_at}.`);
|
|
258
278
|
};
|
|
@@ -300,7 +320,7 @@ async function attempt(io, startJob) {
|
|
|
300
320
|
return save("Waiting for the source to be released.");
|
|
301
321
|
}
|
|
302
322
|
mark("source_check", "completed", source === "released" ? "The source is released for review." : "No source is registered for this video, and none is withheld.");
|
|
303
|
-
// 3. Acquire: captions first, then a
|
|
323
|
+
// 3. Acquire: captions first, then a transcription of the audio on this host where its operator enabled it.
|
|
304
324
|
if (!io.captions && !io.local)
|
|
305
325
|
return fail(failures.no_provider(), "acquire", "The host has no captions reader.");
|
|
306
326
|
mark("acquire", "started", "YouTube captions in the spoken language");
|
|
@@ -310,14 +330,23 @@ async function attempt(io, startJob) {
|
|
|
310
330
|
// The audio is downloaded and transcribed only when the video has no usable caption track. A reader that failed or a
|
|
311
331
|
// track not made yet waits and retries: a transient failure must not start sixteen minutes of work on this host.
|
|
312
332
|
const captionsAbsent = !io.captions || (answer?.state === "none_yet" && answer.absent === true);
|
|
313
|
-
|
|
314
|
-
|
|
333
|
+
// Every job starts from an authority that covers processing its review: the review service's review.created fact, a
|
|
334
|
+
// person with the write tier or the source's registrant, or an approved mission. So a review whose video has no
|
|
335
|
+
// captions gets its transcript from the audio as soon as it exists. A withheld source never reaches this point.
|
|
336
|
+
if ((!answer || answer.state !== "found") && io.local && captionsAbsent) {
|
|
337
|
+
r = { ...r, local_attempts: (r.local_attempts ?? 0) + 1 };
|
|
338
|
+
mark("acquire", "waiting", `Captions: ${answer?.state === "none_yet" ? answer.message ?? "none yet" : "no reader"} Transcribing the audio on this host (attempt ${r.local_attempts} of ${MAX_LOCAL_ATTEMPTS}).`);
|
|
315
339
|
save();
|
|
316
340
|
usedLocal = true;
|
|
317
341
|
answer = await io.local(r.video_id);
|
|
318
342
|
}
|
|
319
|
-
if (!answer || answer.state !== "found")
|
|
320
|
-
|
|
343
|
+
if (!answer || answer.state !== "found") {
|
|
344
|
+
const message = answer?.message ?? "YouTube has no captions for this video yet.";
|
|
345
|
+
// A transcription that keeps producing nothing ends as a failure a person reads, not as three days of retries.
|
|
346
|
+
if (usedLocal && (r.local_attempts ?? 0) >= MAX_LOCAL_ATTEMPTS)
|
|
347
|
+
return fail(failures.local_failed(message, r.local_attempts ?? MAX_LOCAL_ATTEMPTS), "acquire", "This host's transcription produced no transcript.");
|
|
348
|
+
return wait("waiting_for_captions", message, "acquire", usedLocal, !usedLocal && captionsAbsent ? failures.local_off(message) : undefined);
|
|
349
|
+
}
|
|
321
350
|
const text = answer.text.trim();
|
|
322
351
|
if (!text)
|
|
323
352
|
return wait("waiting_for_captions", "The captions hold no words.", "acquire", usedLocal);
|
|
@@ -435,11 +464,17 @@ export function ensureTranscript(io, input) {
|
|
|
435
464
|
}
|
|
436
465
|
else {
|
|
437
466
|
prior = receiptOf(job);
|
|
467
|
+
// A job an event opened records the approved mission a worker now runs it under.
|
|
468
|
+
if (input.authority?.basis === "approved_mission" && prior.authority?.mission !== input.authority.mission) {
|
|
469
|
+
prior = { ...prior, authority: input.authority };
|
|
470
|
+
job = commit(io, job, prior);
|
|
471
|
+
}
|
|
438
472
|
// A person asking again starts a new window when the job failed or was held, because the cause is usually repaired.
|
|
439
473
|
if (prior.state === "failed" || prior.state === "held") {
|
|
440
474
|
const next = { ...prior, state: "acquiring", phase: "requested", trigger: input.trigger, since: iso(now), stages: [...prior.stages, requested(iso(now), input.trigger)].slice(-MAX_STAGES) };
|
|
441
475
|
delete next.failure;
|
|
442
476
|
delete next.next_attempt_at;
|
|
477
|
+
delete next.local_attempts;
|
|
443
478
|
job = commit(io, job, next);
|
|
444
479
|
}
|
|
445
480
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.38";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.38";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miadi/connector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38",
|
|
4
4
|
"description": "The Miadi connector: one remote MCP service through which a person signed in with their Miadi person token, from ChatGPT or any MCP client, reads sessions, reviews, episodes and circles and records observations, inquiries, handoffs and proposals with their name on each record.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Miadi",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"types": "./dist/records.d.ts",
|
|
17
17
|
"import": "./dist/records.js"
|
|
18
18
|
},
|
|
19
|
+
"./capabilities": {
|
|
20
|
+
"types": "./dist/capabilities.d.ts",
|
|
21
|
+
"import": "./dist/capabilities.js"
|
|
22
|
+
},
|
|
19
23
|
"./research-digest": {
|
|
20
24
|
"types": "./dist/research-digest.d.ts",
|
|
21
25
|
"import": "./dist/research-digest.js"
|
|
@@ -32,6 +36,10 @@
|
|
|
32
36
|
"types": "./dist/research-shelf.d.ts",
|
|
33
37
|
"import": "./dist/research-shelf.js"
|
|
34
38
|
},
|
|
39
|
+
"./record-shares": {
|
|
40
|
+
"types": "./dist/record-shares.d.ts",
|
|
41
|
+
"import": "./dist/record-shares.js"
|
|
42
|
+
},
|
|
35
43
|
"./package.json": "./package.json"
|
|
36
44
|
},
|
|
37
45
|
"bin": {
|
|
@@ -43,10 +51,11 @@
|
|
|
43
51
|
"STEERING.md"
|
|
44
52
|
],
|
|
45
53
|
"dependencies": {
|
|
46
|
-
"@miadi/hooks-core": "^0.6.
|
|
54
|
+
"@miadi/hooks-core": "^0.6.1",
|
|
47
55
|
"@miadi/hooks-gateway": "^0.2.1",
|
|
48
|
-
"@miadi/inquiry-weave": "0.18.
|
|
56
|
+
"@miadi/inquiry-weave": "0.18.14",
|
|
49
57
|
"@miadi/node-service-kit": "0.1.2",
|
|
58
|
+
"@miadi/relational-git-repository-mapper": "^0.7.0",
|
|
50
59
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
51
60
|
"express": "^5.2.1",
|
|
52
61
|
"express-rate-limit": "^8.2.1",
|