@miadi/connector 0.1.33 → 0.1.36
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 +15 -2
- package/dist/approve.d.ts +7 -0
- package/dist/approve.js +54 -0
- package/dist/bin.js +8 -0
- package/dist/captions.d.ts +66 -2
- package/dist/captions.js +111 -57
- package/dist/local-transcription.d.ts +21 -0
- package/dist/local-transcription.js +111 -0
- package/dist/reading/contract.d.ts +1 -1
- package/dist/reading/host-runtime.d.ts +7 -0
- package/dist/reading/host-runtime.js +61 -0
- package/dist/reading/runtime-report.d.ts +21 -0
- package/dist/reading/runtime-report.js +40 -0
- package/dist/records.d.ts +1 -1
- package/dist/records.js +2 -0
- package/dist/review-events.d.ts +9 -0
- package/dist/review-events.js +59 -0
- package/dist/server.d.ts +5 -1
- package/dist/server.js +5 -0
- package/dist/tools.js +135 -10
- package/dist/transcript-intake.d.ts +24 -0
- package/dist/transcript-intake.js +121 -0
- package/dist/transcript-job.d.ts +197 -0
- package/dist/transcript-job.js +574 -0
- package/dist/transcript-routes.d.ts +14 -0
- package/dist/transcript-routes.js +92 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page and the JSON a review's transcript is followed on, without an embedded card (jgwill/Miadi#995).
|
|
3
|
+
*
|
|
4
|
+
* `GET /transcripts/<review id>` is a link that outlasts the conversation that made it. It reads like
|
|
5
|
+
* `/records/<id>`: a person signs in with their Miadi person token (a form on the page, or a Bearer header
|
|
6
|
+
* for a script) and needs Miadi's read tier. It shows what review_transcript_status shows: the state, the
|
|
7
|
+
* plain summary, the job's stages, the digest and readback, the failure with who can remedy it, and the
|
|
8
|
+
* retry schedule. It only reads. Acquiring a transcript is ensure_review_transcript.
|
|
9
|
+
*/
|
|
10
|
+
import express from "express";
|
|
11
|
+
import { escapeHtml } from "@miadi/node-service-kit/format";
|
|
12
|
+
import { page, transcriptJobIo } from "./approve.js";
|
|
13
|
+
import { MiadiUnavailable } from "./people.js";
|
|
14
|
+
import { reviewIdOf } from "./reviews.js";
|
|
15
|
+
import { transcriptStatus } from "./transcript-job.js";
|
|
16
|
+
const row = (k, v) => (v === undefined || v === null || v === "" ? "" : `<dt>${escapeHtml(k)}</dt><dd>${escapeHtml(String(v))}</dd>`);
|
|
17
|
+
const link = (href, text) => (href ? `<a href="${escapeHtml(href)}">${escapeHtml(text)}</a>` : "");
|
|
18
|
+
export function statusHtml(s) {
|
|
19
|
+
const r = s.job?.receipt;
|
|
20
|
+
const stages = (r?.stages ?? [])
|
|
21
|
+
.map((x) => `<tr><td>${escapeHtml(x.at.slice(11, 19))}</td><td>${escapeHtml(x.stage)}</td><td>${escapeHtml(x.status)}</td><td>${escapeHtml(x.detail ?? "")}</td></tr>`)
|
|
22
|
+
.join("");
|
|
23
|
+
return page(`Transcript: ${s.state}`, `<h1>Transcript: ${escapeHtml(s.state)}</h1>
|
|
24
|
+
<p>${escapeHtml(s.summary)}</p>
|
|
25
|
+
<dl>
|
|
26
|
+
${row("Review", s.review_id)}${row("Video", s.video_id)}
|
|
27
|
+
${row("Method", r?.method)}${row("Source", r?.source)}${row("Language", r?.language)}${row("Why this track", r?.basis)}
|
|
28
|
+
${row("Words", r?.words)}${row("Characters", r?.chars)}${row("Covers", r?.covers)}${row("sha256", r?.sha256)}
|
|
29
|
+
${row("Readback", r?.readback ? `${r.readback.ok ? "matches" : "differs"}: ${r.readback.chars} characters, sha256 ${r.readback.sha256}, checked ${r.readback.checked_at}` : undefined)}
|
|
30
|
+
${row("Read back now", s.verified_now ? `${s.verified_now.ok ? "matches" : "differs"}: sha256 ${s.verified_now.sha256}` : undefined)}
|
|
31
|
+
${row("Attempts", r?.attempts)}${row("Last attempt", r?.last_attempt_at)}${row("Next attempt", r?.next_attempt_at)}${row("Gives up", r?.give_up_at)}
|
|
32
|
+
${row("Review service", s.service.reachable ? (s.service.has_transcript ? "holds a transcript" : "holds no transcript") : s.service.error)}
|
|
33
|
+
${r?.failure ? row("Failure", r.failure.message) + row("Remedy", `${r.failure.remedy} (${r.failure.owner})`) + row("Retry", r.failure.retry) : ""}
|
|
34
|
+
</dl>
|
|
35
|
+
${stages ? `<h2>Stages</h2><table><thead><tr><th>At (UTC)</th><th>Stage</th><th>Status</th><th>Detail</th></tr></thead><tbody>${stages}</tbody></table>` : ""}
|
|
36
|
+
<p>${link(s.links.review, "The review")} · ${link(s.links.job, "The job record")} · <span class="muted">transcript API (token): ${escapeHtml(s.links.transcript_api)}</span></p>
|
|
37
|
+
<p class="muted">No decision is needed for this job. It runs under the authority that already covers processing a review.</p>`);
|
|
38
|
+
}
|
|
39
|
+
const signIn = (id, error) => page("Transcript status", `<h1>Transcript status</h1><p>${escapeHtml(id)}</p>
|
|
40
|
+
${error ? `<p class="err" role="alert">${escapeHtml(error)}</p>` : ""}
|
|
41
|
+
<form method="post"><label for="t">Your Miadi person token</label><input id="t" name="person_token" type="password" autocomplete="off" required>
|
|
42
|
+
<div class="row"><button class="primary" type="submit">Read</button></div></form>`);
|
|
43
|
+
export function registerTranscriptRoutes(app, deps, publicUrl) {
|
|
44
|
+
const form = express.urlencoded({ extended: false, limit: "16kb" });
|
|
45
|
+
const links = (id) => (job) => ({
|
|
46
|
+
status: `${publicUrl}/transcripts/${id}`,
|
|
47
|
+
review: `${deps.config.reviewUrl}/review/${id}`,
|
|
48
|
+
transcript_api: `${deps.config.reviewUrl}/api/reviews/${id}/transcript`,
|
|
49
|
+
...(job ? { job: `${publicUrl}/records/${encodeURIComponent(job)}` } : {}),
|
|
50
|
+
decision: null,
|
|
51
|
+
});
|
|
52
|
+
/** The status as this person may read it, or the page that says why not. */
|
|
53
|
+
async function read(req, res, token, wantsJson) {
|
|
54
|
+
const id = reviewIdOf(String(req.params.id));
|
|
55
|
+
if (!id)
|
|
56
|
+
return void res.status(404).type("html").send(page("Not found", "<h1>No review with that id</h1>"));
|
|
57
|
+
let person;
|
|
58
|
+
try {
|
|
59
|
+
person = await deps.identify(token);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (!(error instanceof MiadiUnavailable))
|
|
63
|
+
throw error;
|
|
64
|
+
return void (wantsJson ? res.status(503).json({ error: "unavailable", message: "Miadi could not be reached." }) : res.status(503).type("html").send(signIn(id, "Miadi could not be reached. Try again in a minute.")));
|
|
65
|
+
}
|
|
66
|
+
if (!person)
|
|
67
|
+
return void (wantsJson ? res.status(401).json({ error: "unauthenticated" }) : res.status(401).type("html").send(signIn(id, "Miadi did not recognise that person token.")));
|
|
68
|
+
if (person.api_tier !== "read" && person.api_tier !== "write") {
|
|
69
|
+
const message = `Reading a transcript's status needs Miadi's read tier; ${person.name} has ${person.api_tier ?? "no API tier"}.`;
|
|
70
|
+
return void (wantsJson ? res.status(403).json({ error: "forbidden", message }) : res.status(403).type("html").send(signIn(id, message)));
|
|
71
|
+
}
|
|
72
|
+
const verify = req.query.verify === "1" || req.query.verify === "true";
|
|
73
|
+
const status = await transcriptStatus(transcriptJobIo(deps), { review_id: id, ...(verify ? { verify } : {}) }, links(id));
|
|
74
|
+
if (wantsJson)
|
|
75
|
+
return void res.json(status);
|
|
76
|
+
res.type("html").send(statusHtml(status));
|
|
77
|
+
}
|
|
78
|
+
app.get("/transcripts/:id", async (req, res) => {
|
|
79
|
+
const bearer = /^Bearer\s+(.+)$/i.exec(String(req.headers.authorization ?? ""))?.[1]?.trim();
|
|
80
|
+
const wantsJson = req.query.format === "json" || String(req.headers.accept ?? "").includes("application/json");
|
|
81
|
+
if (!bearer) {
|
|
82
|
+
const id = reviewIdOf(String(req.params.id));
|
|
83
|
+
if (!id)
|
|
84
|
+
return void res.status(404).type("html").send(page("Not found", "<h1>No review with that id</h1>"));
|
|
85
|
+
return void (wantsJson ? res.status(401).json({ error: "unauthenticated", message: "Send the Miadi person token as a Bearer header, or open this link in a browser." }) : res.type("html").send(signIn(id)));
|
|
86
|
+
}
|
|
87
|
+
await read(req, res, bearer, wantsJson).catch((error) => res.status(500).type("html").send(page("Error", `<h1>The status could not be read</h1><p>${escapeHtml(error instanceof Error ? error.message : String(error))}</p>`)));
|
|
88
|
+
});
|
|
89
|
+
app.post("/transcripts/:id", form, async (req, res) => {
|
|
90
|
+
await read(req, res, String((req.body ?? {}).person_token ?? "").trim(), false).catch((error) => res.status(500).type("html").send(page("Error", `<h1>The status could not be read</h1><p>${escapeHtml(error instanceof Error ? error.message : String(error))}</p>`)));
|
|
91
|
+
});
|
|
92
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.36";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.36";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miadi/connector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
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",
|
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
"STEERING.md"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
+
"@miadi/hooks-core": "^0.6.0",
|
|
47
|
+
"@miadi/hooks-gateway": "^0.2.1",
|
|
46
48
|
"@miadi/inquiry-weave": "0.18.13",
|
|
47
49
|
"@miadi/node-service-kit": "0.1.2",
|
|
48
50
|
"@modelcontextprotocol/sdk": "^1.30.0",
|