@miadi/connector 0.1.32 → 0.1.35
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 +52 -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 +6 -1
- package/dist/tools.js +172 -10
- package/dist/transcript-intake.d.ts +24 -0
- package/dist/transcript-intake.js +118 -0
- package/dist/transcript-job.d.ts +190 -0
- package/dist/transcript-job.js +507 -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,7 @@
|
|
|
1
|
+
import { type FetchCaptions } from "../captions.js";
|
|
2
|
+
import type { ReadingAdapters } from "./workflow.js";
|
|
3
|
+
export type ReadingRuntime = Pick<ReadingAdapters, "providers" | "acquire" | "generateV1" | "generateSurvey" | "generateReflection">;
|
|
4
|
+
export declare function createReadingRuntime(o?: {
|
|
5
|
+
captions?: FetchCaptions;
|
|
6
|
+
probe?: () => boolean;
|
|
7
|
+
}): ReadingRuntime;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host's reading runtime (jgwill/Miadi#995): the module `MIADI_READING_ADAPTER` names.
|
|
3
|
+
*
|
|
4
|
+
* It declares what this host can do today and nothing else. Transcript acquisition is real: the video's
|
|
5
|
+
* spoken-language YouTube captions, read by the same reader the transcript job uses, with their
|
|
6
|
+
* timecodes, at no cost and with no model. The generation stages (the base review, the academic survey,
|
|
7
|
+
* the reflective pass) have no provider authorized on this host, so they are declared unavailable and
|
|
8
|
+
* the workflow stops at them with a named blocker instead of generating from memory. Acquiring a
|
|
9
|
+
* transcript does not depend on the review service's import handshake: only `importApproved` does.
|
|
10
|
+
*/
|
|
11
|
+
import { execFileSync } from "node:child_process";
|
|
12
|
+
import { youtubeCaptions } from "../captions.js";
|
|
13
|
+
import { block } from "./contract.js";
|
|
14
|
+
const unavailable = (why) => ({ id: "unconfigured", available: false, external: false, media: false, max_cost_usd: 0, method: why, idempotent: true });
|
|
15
|
+
/** Whether uvx, which runs the caption reader, is installed here. */
|
|
16
|
+
function hasUvx() {
|
|
17
|
+
try {
|
|
18
|
+
execFileSync("uvx", ["--version"], { stdio: "ignore", timeout: 15_000 });
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function createReadingRuntime(o = {}) {
|
|
26
|
+
const captions = o.captions ?? youtubeCaptions;
|
|
27
|
+
const available = (o.probe ?? hasUvx)();
|
|
28
|
+
const noModel = async () => block("blocked_permission", "No generation provider is authorized on this host. Configure and verify one in this runtime, with a declared cost ceiling and a durable retry contract; nothing is generated from memory.");
|
|
29
|
+
return {
|
|
30
|
+
providers: {
|
|
31
|
+
transcript: { id: "youtube-captions", available, external: false, media: false, max_cost_usd: 0, method: "yt-dlp json3, spoken-language captions, no model", idempotent: true },
|
|
32
|
+
v1: unavailable("no generation provider authorized"),
|
|
33
|
+
academic: unavailable("no generation provider authorized"),
|
|
34
|
+
reflective: unavailable("no generation provider authorized"),
|
|
35
|
+
},
|
|
36
|
+
async acquire(context) {
|
|
37
|
+
const answer = await captions(context.video_id);
|
|
38
|
+
if (answer.state !== "found")
|
|
39
|
+
return null;
|
|
40
|
+
return {
|
|
41
|
+
video_id: context.video_id,
|
|
42
|
+
kind: "captions",
|
|
43
|
+
channel: "video",
|
|
44
|
+
text: answer.text,
|
|
45
|
+
language: answer.language,
|
|
46
|
+
locator: `https://youtu.be/${context.video_id}#${answer.track}`,
|
|
47
|
+
provider: "youtube-captions",
|
|
48
|
+
caption_kind: answer.kind === "manual" ? "manual" : "automatic",
|
|
49
|
+
fetched_at: answer.fetched_at,
|
|
50
|
+
rights: context.scope.rights,
|
|
51
|
+
timestamp_granularity: "segment",
|
|
52
|
+
alignment_status: "unknown",
|
|
53
|
+
speaker_status: "unknown",
|
|
54
|
+
segments: answer.segments ?? [],
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
generateV1: noModel,
|
|
58
|
+
generateSurvey: noModel,
|
|
59
|
+
generateReflection: noModel,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface RuntimeReport {
|
|
2
|
+
provider_runtime: "not_configured" | "configured_failed" | "configured_transcript_unavailable" | "verified_transcript_only" | "verified_all_stages";
|
|
3
|
+
adapter?: string;
|
|
4
|
+
providers?: Record<string, {
|
|
5
|
+
id: string;
|
|
6
|
+
available: boolean;
|
|
7
|
+
method: string;
|
|
8
|
+
external: boolean;
|
|
9
|
+
media: boolean;
|
|
10
|
+
max_cost_usd: number;
|
|
11
|
+
}>;
|
|
12
|
+
detail?: string;
|
|
13
|
+
checked_at: string;
|
|
14
|
+
}
|
|
15
|
+
type Loader = (path: string) => Promise<{
|
|
16
|
+
createReadingRuntime?: () => {
|
|
17
|
+
providers?: Record<string, any>;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
export declare function readingRuntimeReport(env?: NodeJS.ProcessEnv, load?: Loader, now?: () => number): Promise<RuntimeReport>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the host's reading runtime can do, found by loading it (jgwill/Miadi#995). `get_capabilities` used to
|
|
3
|
+
* say only that an adapter path was set. It now loads the module the host names, asks it what it provides
|
|
4
|
+
* and reports each stage, so "configured" and "works" are not the same word.
|
|
5
|
+
*/
|
|
6
|
+
import { basename, resolve } from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
const defaultLoader = (path) => import(pathToFileURL(resolve(path)).href);
|
|
9
|
+
const kept = new Map();
|
|
10
|
+
const KEEP_MS = 60_000;
|
|
11
|
+
export async function readingRuntimeReport(env = process.env, load = defaultLoader, now = Date.now) {
|
|
12
|
+
const path = env.MIADI_READING_ADAPTER;
|
|
13
|
+
const checked_at = new Date(now()).toISOString();
|
|
14
|
+
if (!path)
|
|
15
|
+
return { provider_runtime: "not_configured", detail: "MIADI_READING_ADAPTER names no module on this host.", checked_at };
|
|
16
|
+
const hit = kept.get(path);
|
|
17
|
+
if (hit && now() - hit.at < KEEP_MS)
|
|
18
|
+
return hit.report;
|
|
19
|
+
let report;
|
|
20
|
+
try {
|
|
21
|
+
const mod = await load(path);
|
|
22
|
+
if (typeof mod.createReadingRuntime !== "function")
|
|
23
|
+
throw new Error("The module exports no createReadingRuntime().");
|
|
24
|
+
const providers = mod.createReadingRuntime().providers ?? {};
|
|
25
|
+
const shown = Object.fromEntries(Object.entries(providers).map(([stage, p]) => [stage, { id: String(p.id), available: p.available === true, method: String(p.method), external: p.external === true, media: p.media === true, max_cost_usd: Number(p.max_cost_usd) }]));
|
|
26
|
+
const generation = ["v1", "academic", "reflective"].every((s) => shown[s]?.available);
|
|
27
|
+
report = {
|
|
28
|
+
provider_runtime: !shown.transcript?.available ? "configured_transcript_unavailable" : generation ? "verified_all_stages" : "verified_transcript_only",
|
|
29
|
+
adapter: basename(path),
|
|
30
|
+
providers: shown,
|
|
31
|
+
...(generation ? {} : { detail: "Transcript acquisition works. The generation stages have no authorized provider, so a reading stops there with a named blocker." }),
|
|
32
|
+
checked_at,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
report = { provider_runtime: "configured_failed", adapter: basename(path), detail: error instanceof Error ? error.message : String(error), checked_at };
|
|
37
|
+
}
|
|
38
|
+
kept.set(path, { at: now(), report });
|
|
39
|
+
return report;
|
|
40
|
+
}
|
package/dist/records.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export declare const DOMAINS: readonly ["creative", "ceremonial", "engineering"]
|
|
|
36
36
|
/** #815 "claim category": what kind of statement a record makes. */
|
|
37
37
|
export declare const CLAIM_CATEGORIES: readonly ["observed", "hypothesis", "desired_future", "fiction", "verified_implementation"];
|
|
38
38
|
export type ClaimCategory = (typeof CLAIM_CATEGORIES)[number];
|
|
39
|
-
export declare const RECORD_KINDS: readonly ["observation", "inquiry", "link", "work_proposal", "run_request", "handoff", "source_intent", "review_operation_request", "participant_consent_request", "deep_diver_request", "review_episode_link_request", "calendar_event_draft", "session_completion_proposal", "research_artifact", "inquiry_episode_request", "session_steer_request", "steering_revocation", "provider_choice", "provider_policy"];
|
|
39
|
+
export declare const RECORD_KINDS: readonly ["observation", "inquiry", "link", "work_proposal", "run_request", "handoff", "source_intent", "review_operation_request", "participant_consent_request", "deep_diver_request", "review_episode_link_request", "calendar_event_draft", "session_completion_proposal", "research_artifact", "inquiry_episode_request", "session_steer_request", "steering_revocation", "provider_choice", "provider_policy", "transcript_job"];
|
|
40
40
|
export type RecordKind = (typeof RECORD_KINDS)[number];
|
|
41
41
|
/** #816 handoff states. */
|
|
42
42
|
export declare const HANDOFF_STATES: readonly ["pending", "blocked", "ready", "in_progress", "completed", "withdrawn"];
|
package/dist/records.js
CHANGED
|
@@ -67,6 +67,8 @@ export const RECORD_KINDS = [
|
|
|
67
67
|
// A requester's own per-mission provider choice and provider policy, made on the connector's pages (jgwill/Miadi#926).
|
|
68
68
|
"provider_choice",
|
|
69
69
|
"provider_policy",
|
|
70
|
+
// A review's transcript acquired by the connector: one job per review, its stages and receipt (jgwill/Miadi#995).
|
|
71
|
+
"transcript_job",
|
|
70
72
|
];
|
|
71
73
|
/** #816 handoff states. */
|
|
72
74
|
export const HANDOFF_STATES = ["pending", "blocked", "ready", "in_progress", "completed", "withdrawn"];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConnectorRecord } from "./records.js";
|
|
2
|
+
import type { TranscriptJobReceipt } from "./transcript-job.js";
|
|
3
|
+
export declare const TRANSCRIPT_SUBSCRIBER = "connector-transcripts";
|
|
4
|
+
export declare function eventsDir(env?: NodeJS.ProcessEnv): string;
|
|
5
|
+
export declare function transcriptInbox(dir?: string): string;
|
|
6
|
+
/** The fact a job's ending announces, or null for a state that is not an ending. */
|
|
7
|
+
export declare function transcriptOutcomeEvent(job: ConnectorRecord, r: TranscriptJobReceipt, at: string): import("@miadi/hooks-core").HookEventEnvelope | null;
|
|
8
|
+
/** Records a job's ending in the event ledger. The same ending announced twice is one fact. */
|
|
9
|
+
export declare function announceTranscriptOutcome(job: ConnectorRecord, r: TranscriptJobReceipt, dir?: string, now?: () => string): Promise<import("@miadi/hooks-gateway").GatewayReceipt | null>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connector's side of the review service's facts (jgwill/Miadi#995).
|
|
3
|
+
*
|
|
4
|
+
* Miadi's ingress (/api/factory/review-events) records each `review.created` in the event ledger and hands
|
|
5
|
+
* it to this connector's inbox, `<events dir>/inbox/connector-transcripts/`. The connector makes sure the
|
|
6
|
+
* review holds its transcript (transcript-intake.ts), and announces what became of it as a fact of its own,
|
|
7
|
+
* `review.transcript.stored`, `…held` or `…failed`, recorded in the same ledger on the review's trace.
|
|
8
|
+
*
|
|
9
|
+
* The folders are the host's (`MIADI_EVENTS_DIR`, default `/srv/miadi/events`); the event shapes are
|
|
10
|
+
* `@miadi/hooks-core`'s and the ledger is `@miadi/hooks-gateway`'s, so a broker can replace the folders
|
|
11
|
+
* later without changing what is announced.
|
|
12
|
+
*/
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { buildReviewTranscriptEvent } from "@miadi/hooks-core";
|
|
15
|
+
import { JsonlLedger, receiveEnvelope } from "@miadi/hooks-gateway";
|
|
16
|
+
export const TRANSCRIPT_SUBSCRIBER = "connector-transcripts";
|
|
17
|
+
export function eventsDir(env = process.env) {
|
|
18
|
+
return env.MIADI_EVENTS_DIR || "/srv/miadi/events";
|
|
19
|
+
}
|
|
20
|
+
export function transcriptInbox(dir = eventsDir()) {
|
|
21
|
+
return join(dir, "inbox", TRANSCRIPT_SUBSCRIBER);
|
|
22
|
+
}
|
|
23
|
+
const OUTCOME = {
|
|
24
|
+
stored: "review.transcript.stored",
|
|
25
|
+
held: "review.transcript.held",
|
|
26
|
+
failed: "review.transcript.failed",
|
|
27
|
+
};
|
|
28
|
+
/** The fact a job's ending announces, or null for a state that is not an ending. */
|
|
29
|
+
export function transcriptOutcomeEvent(job, r, at) {
|
|
30
|
+
const event = OUTCOME[r.state];
|
|
31
|
+
if (!event)
|
|
32
|
+
return null;
|
|
33
|
+
const authority = (job.body.authority ?? {});
|
|
34
|
+
const payload = {
|
|
35
|
+
review: { id: r.review_id, video_id: r.video_id },
|
|
36
|
+
job: job.id,
|
|
37
|
+
phase: r.phase,
|
|
38
|
+
attempts: r.attempts,
|
|
39
|
+
...(r.method ? { method: r.method } : {}),
|
|
40
|
+
...(r.source ? { source: r.source } : {}),
|
|
41
|
+
...(r.language ? { language: r.language } : {}),
|
|
42
|
+
...(r.track ? { track: r.track } : {}),
|
|
43
|
+
...(r.words ? { words: r.words } : {}),
|
|
44
|
+
...(r.covers ? { covers: r.covers } : {}),
|
|
45
|
+
...(r.sha256 ? { sha256: r.sha256 } : {}),
|
|
46
|
+
...(r.readback ? { readback_ok: r.readback.ok } : {}),
|
|
47
|
+
...(r.failure ? { failure: { code: r.failure.code, owner: r.failure.owner, message: r.failure.message, remedy: r.failure.remedy } } : {}),
|
|
48
|
+
...(typeof authority.idempotency_key === "string" ? { caused_by: authority.idempotency_key } : {}),
|
|
49
|
+
};
|
|
50
|
+
return buildReviewTranscriptEvent({ event, payload, captured_at: at });
|
|
51
|
+
}
|
|
52
|
+
/** Records a job's ending in the event ledger. The same ending announced twice is one fact. */
|
|
53
|
+
export async function announceTranscriptOutcome(job, r, dir = eventsDir(), now = () => new Date().toISOString()) {
|
|
54
|
+
const envelope = transcriptOutcomeEvent(job, r, now());
|
|
55
|
+
if (!envelope)
|
|
56
|
+
return null;
|
|
57
|
+
const received = await receiveEnvelope(envelope, { ledger: new JsonlLedger(join(dir, "ledger")), now });
|
|
58
|
+
return "receipt" in received ? received.receipt : null;
|
|
59
|
+
}
|
package/dist/server.d.ts
CHANGED
|
@@ -45,6 +45,10 @@ export interface ConnectorDeps {
|
|
|
45
45
|
wakeRunner?: () => void;
|
|
46
46
|
/** Reads a video's captions for an approved create; the service passes youtubeCaptions, tests their own. */
|
|
47
47
|
captions?: FetchCaptions;
|
|
48
|
+
/** A transcription made on this host, tried for a released source whose captions are missing (jgwill/Miadi#995). */
|
|
49
|
+
localTranscription?: FetchCaptions;
|
|
50
|
+
/** The event folder: the review.created facts this connector takes, and the ledger it announces outcomes in (jgwill/Miadi#995). */
|
|
51
|
+
eventsDir?: string;
|
|
48
52
|
/** Person-token attempts allowed per address in 15 minutes on each sign-in form (default 30). */
|
|
49
53
|
tokenAttemptsPerWindow?: number;
|
|
50
54
|
/** Where decision events go (default: one JSON line on stdout, the service journal); tests collect them (jgwill/Miadi#924). */
|
|
@@ -55,4 +59,4 @@ export declare function createConnectorApp(config: ConnectorConfig, deps: Connec
|
|
|
55
59
|
provider: MiadiOAuthProvider;
|
|
56
60
|
ledger: Ledger<ConnectorRecord>;
|
|
57
61
|
};
|
|
58
|
-
export declare const INSTRUCTIONS = "Miadi is a relational software factory: agent sessions, Miadi reviews of screenwalks, Chronicle episodes, talking circles and the five accountable circles (Story, Stewardship, Engineering, Evaluation, Continuity) across three domains (Creative, Ceremonial, Engineering).\n\nStart with get_capabilities: it says who you are signed in as, which tools are live, and which return not_implemented.\n\nEvery tool is offered on every connection. A client that loads tools on demand shows only those its last tool search matched: a tool you do not see is not missing. Search for it by its exact name, get_capabilities first, before telling the person a tool is absent. The main reads are get_capabilities, get_context, search, fetch, list_records, list_sessions, get_session, review_lookup, read_episode_file and show_decisions.\n\nRules every tool keeps:\n- Every record names the person who made it, with a claim category: observed, hypothesis, desired_future, fiction or verified_implementation. Keep fiction and desired futures apart from what was observed.\n- Requests (runs, work proposals, review operations, Deep Diver, review-to-episode links, inquiry-to-episode weaves, session completion) are recorded as awaiting_approval. Nothing runs, publishes or closes until a person decides. After making a request, call show_decisions: it shows the request as a card in the conversation, where the person decides with their own click (or follows its approval page). Never claim a decision the card has not reported. The person may approve, approve with changes (their instructions are carried into what runs), send it back for revision with instructions (approval_state revision_requested; read the instructions with get_run_result and revise it in place with revise_pending_request), or decline.\n- A new or revised run or work proposal answers with draft_review: the aspects of the mission standard to revise, each with why, the question to settle and who can settle it. Read it before show_decisions. It carries no verdict, it advises and blocks nothing, and next_action says what to do. Answer what your conversation holds, ask the person the rest, then revise. preferences lists the person's standing preferences for you to apply. Fill delivery with the one exact place the result lands, and person_words with the person's own words, verbatim, for anything credited to them.\n- A mission is revised, never re-requested: to change a run or work proposal that still awaits a decision, call revise_pending_request with its id and the version you read (expected_version). It keeps one id, one approval page and one card; get_request_history shows every version. A new request_authorized_run or propose_work is for a new mission only. Requests made earlier as separate versions are joined with supersede_pending_requests, naming their exact ids, only when the person names or confirms them.\n- A research report (a Deep Research report) is delivered with save_research exactly as written, never summarised or shortened, with its sources; a long report goes in parts. Check the bytes and first and last lines the answer returns against what you sent.\n- An unknown id is answered as not found, never invented. A missing backing service is answered as unavailable.\n- Use the miadi-review:<uuid>, miadi-chronicle://<n>, owner/repo#n and session:<uuid> reference forms.";
|
|
62
|
+
export declare const INSTRUCTIONS = "Miadi is a relational software factory: agent sessions, Miadi reviews of screenwalks, Chronicle episodes, talking circles and the five accountable circles (Story, Stewardship, Engineering, Evaluation, Continuity) across three domains (Creative, Ceremonial, Engineering).\n\nStart with get_capabilities: it says who you are signed in as, which tools are live, and which return not_implemented.\n\nEvery tool is offered on every connection. A client that loads tools on demand shows only those its last tool search matched: a tool you do not see is not missing. Search for it by its exact name, get_capabilities first, before telling the person a tool is absent. The main reads are get_capabilities, get_context, search, fetch, list_records, list_sessions, search_sessions, get_session, review_lookup, read_episode_file and show_decisions.\n\nRules every tool keeps:\n- Every record names the person who made it, with a claim category: observed, hypothesis, desired_future, fiction or verified_implementation. Keep fiction and desired futures apart from what was observed.\n- Requests (runs, work proposals, review operations, Deep Diver, review-to-episode links, inquiry-to-episode weaves, session completion) are recorded as awaiting_approval. Nothing runs, publishes or closes until a person decides. After making a request, call show_decisions: it shows the request as a card in the conversation, where the person decides with their own click (or follows its approval page). Never claim a decision the card has not reported. The person may approve, approve with changes (their instructions are carried into what runs), send it back for revision with instructions (approval_state revision_requested; read the instructions with get_run_result and revise it in place with revise_pending_request), or decline.\n- A new or revised run or work proposal answers with draft_review: the aspects of the mission standard to revise, each with why, the question to settle and who can settle it. Read it before show_decisions. It carries no verdict, it advises and blocks nothing, and next_action says what to do. Answer what your conversation holds, ask the person the rest, then revise. preferences lists the person's standing preferences for you to apply. Fill delivery with the one exact place the result lands, and person_words with the person's own words, verbatim, for anything credited to them.\n- A mission is revised, never re-requested: to change a run or work proposal that still awaits a decision, call revise_pending_request with its id and the version you read (expected_version). It keeps one id, one approval page and one card; get_request_history shows every version. A new request_authorized_run or propose_work is for a new mission only. Requests made earlier as separate versions are joined with supersede_pending_requests, naming their exact ids, only when the person names or confirms them.\n- A research report (a Deep Research report) is delivered with save_research exactly as written, never summarised or shortened, with its sources; a long report goes in parts. Check the bytes and first and last lines the answer returns against what you sent.\n- A review's transcript is acquired by ensure_review_transcript, for a review made anywhere. It needs no decision and no pasted text, takes the video's own captions, never overwrites and calls no model. review_lookup and review_versions carry the transcript's state (unknown, absent, acquiring, stored, held or failed). review_transcript_status follows a job, and every answer carries plain links that work when no card is shown.\n- An unknown id is answered as not found, never invented. A missing backing service is answered as unavailable.\n- Use the miadi-review:<uuid>, miadi-chronicle://<n>, owner/repo#n and session:<uuid> reference forms.";
|
package/dist/server.js
CHANGED
|
@@ -5,6 +5,7 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
|
|
|
5
5
|
import { mcpAuthRouter, createOAuthMetadata, getOAuthProtectedResourceMetadataUrl } from "@modelcontextprotocol/sdk/server/auth/router.js";
|
|
6
6
|
import { requireBearerAuth } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
|
7
7
|
import { MiadiOAuthProvider, SCOPES, SCOPE_CONTRIBUTE, SCOPE_READ, emptyOAuthState } from "./oauth.js";
|
|
8
|
+
import { registerTranscriptRoutes } from "./transcript-routes.js";
|
|
8
9
|
import { logDecision, reconcileInterrupted, registerApprovalRoutes, registerConsentRoutes, registerProviderPolicyRoutes, startTranscriptSettling, page } from "./approve.js";
|
|
9
10
|
import { DecisionTokens } from "./decisions.js";
|
|
10
11
|
import { JsonFile, Ledger, ensureStateDir, statePaths } from "./store.js";
|
|
@@ -94,6 +95,8 @@ export function createConnectorApp(config, deps) {
|
|
|
94
95
|
...(deps.steeringRuntime ? { steeringRuntime: deps.steeringRuntime } : {}),
|
|
95
96
|
...(deps.wakeRunner ? { wakeRunner: deps.wakeRunner } : {}),
|
|
96
97
|
...(deps.captions ? { captions: deps.captions } : {}),
|
|
98
|
+
...(deps.localTranscription ? { localTranscription: deps.localTranscription } : {}),
|
|
99
|
+
...(deps.eventsDir ? { eventsDir: deps.eventsDir } : {}),
|
|
97
100
|
log: deps.log,
|
|
98
101
|
modelRouting: { adapter: deps.jevAdapter, env: deps.draftReviewEnv, fetchImpl: deps.fetchImpl, providersProbe: deps.providersProbe, modelOf: deps.modelOf },
|
|
99
102
|
};
|
|
@@ -101,6 +104,7 @@ export function createConnectorApp(config, deps) {
|
|
|
101
104
|
reconcileInterrupted(approvalDeps);
|
|
102
105
|
startTranscriptSettling(approvalDeps);
|
|
103
106
|
registerApprovalRoutes(app, approvalDeps);
|
|
107
|
+
registerTranscriptRoutes(app, approvalDeps, config.publicUrl);
|
|
104
108
|
registerProviderPolicyRoutes(app, approvalDeps);
|
|
105
109
|
const decisionTokens = new DecisionTokens(config.stateDir, config.decisionTokenTtl);
|
|
106
110
|
approvalDeps.consentLink = (id) => `${config.publicUrl}/consent/${encodeURIComponent(id)}?k=${decisionTokens.consentKey(id)}`;
|
|
@@ -179,7 +183,7 @@ export const INSTRUCTIONS = `Miadi is a relational software factory: agent sessi
|
|
|
179
183
|
|
|
180
184
|
Start with get_capabilities: it says who you are signed in as, which tools are live, and which return not_implemented.
|
|
181
185
|
|
|
182
|
-
Every tool is offered on every connection. A client that loads tools on demand shows only those its last tool search matched: a tool you do not see is not missing. Search for it by its exact name, get_capabilities first, before telling the person a tool is absent. The main reads are get_capabilities, get_context, search, fetch, list_records, list_sessions, get_session, review_lookup, read_episode_file and show_decisions.
|
|
186
|
+
Every tool is offered on every connection. A client that loads tools on demand shows only those its last tool search matched: a tool you do not see is not missing. Search for it by its exact name, get_capabilities first, before telling the person a tool is absent. The main reads are get_capabilities, get_context, search, fetch, list_records, list_sessions, search_sessions, get_session, review_lookup, read_episode_file and show_decisions.
|
|
183
187
|
|
|
184
188
|
Rules every tool keeps:
|
|
185
189
|
- Every record names the person who made it, with a claim category: observed, hypothesis, desired_future, fiction or verified_implementation. Keep fiction and desired futures apart from what was observed.
|
|
@@ -187,5 +191,6 @@ Rules every tool keeps:
|
|
|
187
191
|
- A new or revised run or work proposal answers with draft_review: the aspects of the mission standard to revise, each with why, the question to settle and who can settle it. Read it before show_decisions. It carries no verdict, it advises and blocks nothing, and next_action says what to do. Answer what your conversation holds, ask the person the rest, then revise. preferences lists the person's standing preferences for you to apply. Fill delivery with the one exact place the result lands, and person_words with the person's own words, verbatim, for anything credited to them.
|
|
188
192
|
- A mission is revised, never re-requested: to change a run or work proposal that still awaits a decision, call revise_pending_request with its id and the version you read (expected_version). It keeps one id, one approval page and one card; get_request_history shows every version. A new request_authorized_run or propose_work is for a new mission only. Requests made earlier as separate versions are joined with supersede_pending_requests, naming their exact ids, only when the person names or confirms them.
|
|
189
193
|
- A research report (a Deep Research report) is delivered with save_research exactly as written, never summarised or shortened, with its sources; a long report goes in parts. Check the bytes and first and last lines the answer returns against what you sent.
|
|
194
|
+
- A review's transcript is acquired by ensure_review_transcript, for a review made anywhere. It needs no decision and no pasted text, takes the video's own captions, never overwrites and calls no model. review_lookup and review_versions carry the transcript's state (unknown, absent, acquiring, stored, held or failed). review_transcript_status follows a job, and every answer carries plain links that work when no card is shown.
|
|
190
195
|
- An unknown id is answered as not found, never invented. A missing backing service is answered as unavailable.
|
|
191
196
|
- Use the miadi-review:<uuid>, miadi-chronicle://<n>, owner/repo#n and session:<uuid> reference forms.`;
|
package/dist/tools.js
CHANGED
|
@@ -16,9 +16,11 @@ import { reviewIdOf, videoIdOf } from "./reviews.js";
|
|
|
16
16
|
import { SCOPE_APPROVE, SCOPE_CONTRIBUTE } from "./oauth.js";
|
|
17
17
|
import { CIRCLES, CIRCLE_IDS, CLAIM_CATEGORIES, DOMAINS, HANDOFF_STATES, current, newRecordId, } from "./records.js";
|
|
18
18
|
import { VERSION } from "./version.js";
|
|
19
|
-
import { AlreadyDecided, DECISIONS, DecisionConflict, KIND_LABELS, ProviderChoiceRequired, STILL_RUNNING, StaleVersion, approvalStateOf, consequenceOf, decide, decisionWaitOf, isApprovable, isBeingDecided, logDecision, readQueueState, requestProjection, settleWithin, } from "./approve.js";
|
|
19
|
+
import { AlreadyDecided, DECISIONS, DecisionConflict, KIND_LABELS, ProviderChoiceRequired, STILL_RUNNING, StaleVersion, approvalStateOf, consequenceOf, decide, decisionWaitOf, isApprovable, isBeingDecided, logDecision, readQueueState, transcriptJobIo, requestProjection, settleWithin, } from "./approve.js";
|
|
20
20
|
import { RevisionRefused, requestHistory, revisionRecord, supersedeRecords, versionOf } from "./revisions.js";
|
|
21
21
|
import { coverage } from "./captions.js";
|
|
22
|
+
import { readingRuntimeReport } from "./reading/runtime-report.js";
|
|
23
|
+
import { ensureTranscript, transcriptStatus } from "./transcript-job.js";
|
|
22
24
|
import { DECISIONS_CARD_EARLIER_URIS, DECISIONS_CARD_HTML, DECISIONS_CARD_URI, DECISION_TOKENS_META } from "./decisions.js";
|
|
23
25
|
import { CLAUDE_MODELS, CLAUDE_MODELS_VERIFIED, claudeModelCandidates, claudeModelConfig, firstModelInTranscript, JEV_WITHIN_CLAUDE, MODEL_NAME, modelPlan } from "./claude-models.js";
|
|
24
26
|
import { discoverProviders, jevConfigOf, resolveProvider, routerPreflight, PROVIDERS } from "./providers.js";
|
|
@@ -399,11 +401,23 @@ export function registerTools(server, ctx) {
|
|
|
399
401
|
contract: "jgwill/Miadi#815 Connector v2, jgwill/Miadi#816 Review Bridge",
|
|
400
402
|
reading_workflow: {
|
|
401
403
|
contract: "transcript-first-v1",
|
|
402
|
-
|
|
404
|
+
// Found by loading the module the host names, not by whether a path is set (jgwill/Miadi#995).
|
|
405
|
+
...(await readingRuntimeReport()),
|
|
403
406
|
transcript_store: "private connector ledger source-part receipts before generation",
|
|
404
407
|
import: "blocked_until_authenticated_sha256_cas_v1_handshake",
|
|
405
408
|
publication: "separate_exact_candidate_approval",
|
|
406
409
|
},
|
|
410
|
+
// How a review gets its transcript: no card and no decision needed (jgwill/Miadi#995).
|
|
411
|
+
transcript_acquisition: {
|
|
412
|
+
start: "ensure_review_transcript",
|
|
413
|
+
follow: "review_transcript_status",
|
|
414
|
+
status_page: `${config.publicUrl}/transcripts/<review id>`,
|
|
415
|
+
captions: ctx.approval?.captions ? "on (the video's spoken-language track)" : "off",
|
|
416
|
+
local_transcription: ctx.approval?.localTranscription ? "on (a released source whose captions are missing)" : "off (the operator enables it with MIADI_TRANSCRIPT_LOCAL=faster-whisper)",
|
|
417
|
+
review_service_token: reviews.canSearch ? "present" : "absent",
|
|
418
|
+
decision_required: false,
|
|
419
|
+
independent_of_public_import: true,
|
|
420
|
+
},
|
|
407
421
|
signed_in_as: { person_id: person.id, name: person.name, role: person.role ?? null, miadi_api_tier: person.api_tier, via: auth.clientId },
|
|
408
422
|
scopes: auth.scopes,
|
|
409
423
|
can_contribute: auth.scopes.includes(SCOPE_CONTRIBUTE),
|
|
@@ -490,6 +504,50 @@ export function registerTools(server, ctx) {
|
|
|
490
504
|
const resolved = await miadi.get(person.token, `/api/chronicle/resolve?uri=${encodeURIComponent(uri)}`);
|
|
491
505
|
return { ref: r, kind: "miadi_reference", resolved, cited_by: cited };
|
|
492
506
|
}));
|
|
507
|
+
/** Where a review's transcript job and result can be followed without a card: plain links that outlast the conversation (jgwill/Miadi#995). */
|
|
508
|
+
const transcriptLinks = (reviewId, jobId) => ({
|
|
509
|
+
status: `${config.publicUrl}/transcripts/${reviewId}`,
|
|
510
|
+
review: `${config.reviewUrl}/review/${reviewId}`,
|
|
511
|
+
transcript_api: `${config.reviewUrl}/api/reviews/${reviewId}/transcript`,
|
|
512
|
+
...(jobId ? { job: `${config.publicUrl}/records/${encodeURIComponent(jobId)}` } : {}),
|
|
513
|
+
decision: null,
|
|
514
|
+
});
|
|
515
|
+
/** A review's transcript state for lookups: read-only, and never a reason for the lookup to fail. */
|
|
516
|
+
async function transcriptBrief(reviewId, videoId) {
|
|
517
|
+
const links = transcriptLinks(reviewId);
|
|
518
|
+
if (!ctx.approval || !reviews.canSearch)
|
|
519
|
+
return { state: "unknown", summary: "The connector host has no review service token, so the transcript's state cannot be read.", links };
|
|
520
|
+
try {
|
|
521
|
+
const st = await transcriptStatus(transcriptJobIo(ctx.approval), { review_id: reviewId, video_id: videoId ?? null }, (job) => transcriptLinks(reviewId, job));
|
|
522
|
+
return { state: st.state, summary: st.summary, links: st.links, ...(st.job ? { job: st.job.id } : {}) };
|
|
523
|
+
}
|
|
524
|
+
catch (error) {
|
|
525
|
+
return { state: "unknown", summary: `The transcript's state could not be read: ${error instanceof Error ? error.message : String(error)}.`, links };
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/** A review named by id, URL or video, with the video it reviews. Never creates anything. */
|
|
529
|
+
async function reviewNamed(input) {
|
|
530
|
+
const id = reviewIdOf(input);
|
|
531
|
+
if (id) {
|
|
532
|
+
const r = await reviews.get(id);
|
|
533
|
+
if (!r)
|
|
534
|
+
throw new ToolRefusal("not_found", "No review with this id.");
|
|
535
|
+
if (typeof r.video_id !== "string")
|
|
536
|
+
throw new ToolRefusal("invalid_ref", "This review names no YouTube video, so it has no transcript to acquire.");
|
|
537
|
+
return { review_id: id, video_id: r.video_id };
|
|
538
|
+
}
|
|
539
|
+
const video = videoIdOf(input);
|
|
540
|
+
if (!video)
|
|
541
|
+
throw new ToolRefusal("invalid_ref", "Give a review UUID, miadi-review:<uuid>, the review's URL, or its video's YouTube URL or id.");
|
|
542
|
+
const found = await lookupByVideo(video);
|
|
543
|
+
if (!Array.isArray(found))
|
|
544
|
+
throw new ToolRefusal("unavailable", found.message);
|
|
545
|
+
if (!found.length)
|
|
546
|
+
throw new ToolRefusal("no_review", "No review of this video exists, so there is nothing to attach a transcript to. request_review_operation create makes one and stores the captions once it is approved.");
|
|
547
|
+
if (found.length > 1)
|
|
548
|
+
throw new ToolRefusal("ambiguous", "Several reviews exist for this video; pass the review id.", { reviews: found });
|
|
549
|
+
return { review_id: found[0].review_id, video_id: video };
|
|
550
|
+
}
|
|
493
551
|
async function lookupByVideo(videoId) {
|
|
494
552
|
if (!reviews.canSearch)
|
|
495
553
|
return { state: "search_unavailable", message: "The connector host has no review service token; give the review id instead." };
|
|
@@ -559,6 +617,43 @@ export function registerTools(server, ctx) {
|
|
|
559
617
|
qs.set("limit", String(args.limit ?? 30));
|
|
560
618
|
return miadi.get(person.token, `/api/session?${qs}`);
|
|
561
619
|
}));
|
|
620
|
+
server.registerTool("search_sessions", {
|
|
621
|
+
title: "Search inside agent sessions",
|
|
622
|
+
description: "Which agent sessions said, wrote, ran or committed something: words in a person's prompts and the agent's replies, a command, a file written, a commit, a push, an issue (owner/repo#n) or a repository. Each session comes with its matching moments (kind, time, an excerpt), newest first, and bounds that name how many sessions the read left. Miadi searches the capture on its host (miadi-hooks-interpret search), so a seat with no file access gets the same answer. Needs Miadi's write tier: sessions are operator data.",
|
|
623
|
+
inputSchema: {
|
|
624
|
+
q: z.string().min(1).describe('Words a moment holds, all of them, any case. "a phrase" is one word; owner/repo#n also matches the issue\'s URL and #n in a commit of that repository.'),
|
|
625
|
+
since: z.string().optional().describe("A duration back from now (45m, 2h, 3d), a date or an ISO time."),
|
|
626
|
+
until: z.string().optional().describe("A duration back from now, a date or an ISO time."),
|
|
627
|
+
team: z.string().optional().describe("The binding line's team id, e.g. T8."),
|
|
628
|
+
session_ids: z.array(z.string()).max(50).optional().describe("Only these sessions: ids, session:<id>, or id prefixes of 8 characters or more."),
|
|
629
|
+
kinds: z
|
|
630
|
+
.array(z.enum(["prompt", "message", "reply", "command", "file", "commit", "push", "publication"]))
|
|
631
|
+
.optional()
|
|
632
|
+
.describe("Only these kinds of moment."),
|
|
633
|
+
limit: z.number().int().min(1).max(100).optional().describe("Sessions to return (default 10)."),
|
|
634
|
+
moments: z.number().int().min(1).max(50).optional().describe("Moments per session (default 5)."),
|
|
635
|
+
},
|
|
636
|
+
annotations: READ,
|
|
637
|
+
}, wrap(async (args, extra) => {
|
|
638
|
+
const { person } = who(extra);
|
|
639
|
+
requireTier(person, "write");
|
|
640
|
+
const qs = new URLSearchParams({ q: args.q });
|
|
641
|
+
if (args.since)
|
|
642
|
+
qs.set("since", args.since);
|
|
643
|
+
if (args.until)
|
|
644
|
+
qs.set("until", args.until);
|
|
645
|
+
if (args.team)
|
|
646
|
+
qs.set("team", args.team);
|
|
647
|
+
if (args.session_ids?.length)
|
|
648
|
+
qs.set("session", args.session_ids.map((s) => s.replace(/^session:/, "")).join(","));
|
|
649
|
+
if (args.kinds?.length)
|
|
650
|
+
qs.set("kind", args.kinds.join(","));
|
|
651
|
+
if (args.limit)
|
|
652
|
+
qs.set("limit", String(args.limit));
|
|
653
|
+
if (args.moments)
|
|
654
|
+
qs.set("moments", String(args.moments));
|
|
655
|
+
return miadi.get(person.token, `/api/session/search?${qs}`);
|
|
656
|
+
}));
|
|
562
657
|
server.registerTool("get_session", {
|
|
563
658
|
title: "One agent session",
|
|
564
659
|
description: "One session by id: what it was asked to do, what its record says it completed, what it holds, its ending (proposed or decided), the live pane state, its commits and related episodes, its missions (each labelled by binding: factory_receipt for a brief the factory runner delivered, miadi_run for a miadi-run mission given to it or signed by it), and the connector records that cite it (handoffs, completion proposals).",
|
|
@@ -778,13 +873,14 @@ export function registerTools(server, ctx) {
|
|
|
778
873
|
if (!r)
|
|
779
874
|
return { query, state: "not_found", review_id: id };
|
|
780
875
|
const holders = await miadi.get(person.token, `/api/chronicle/resolve?uri=${encodeURIComponent(`miadi-review:${id}`)}`).then((b) => b?.holders ?? b?.resolution?.holders ?? null, () => null);
|
|
781
|
-
return { query, state: "found", review: reviews.summary(r), holders, cited_by: touching(`miadi-review:${id}`) };
|
|
876
|
+
return { query, state: "found", review: reviews.summary(r), transcript: await transcriptBrief(id, r.video_id), holders, cited_by: touching(`miadi-review:${id}`) };
|
|
782
877
|
}
|
|
783
878
|
const video = videoIdOf(query);
|
|
784
879
|
if (video) {
|
|
785
880
|
const found = await lookupByVideo(video);
|
|
786
881
|
const intents = records().filter((r) => r.kind === "source_intent" && r.body.video_id === video);
|
|
787
|
-
|
|
882
|
+
const withTranscript = Array.isArray(found) ? await Promise.all(found.slice(0, 5).map(async (x) => ({ ...x, transcript: await transcriptBrief(x.review_id, video) }))) : found;
|
|
883
|
+
return { query, video_id: video, state: Array.isArray(found) && found.length ? "found" : "no_review", reviews: withTranscript, source_intents: intents };
|
|
788
884
|
}
|
|
789
885
|
if (!reviews.canSearch)
|
|
790
886
|
return { query, state: "search_unavailable" };
|
|
@@ -804,6 +900,7 @@ export function registerTools(server, ctx) {
|
|
|
804
900
|
return { state: "not_found", review_id: id };
|
|
805
901
|
return {
|
|
806
902
|
review: reviews.summary(r),
|
|
903
|
+
transcript: await transcriptBrief(id, r.video_id),
|
|
807
904
|
versions: r.versions ?? [],
|
|
808
905
|
selected: r.version
|
|
809
906
|
? { version: r.version.version, model: r.version.model, created_at: r.version.created_at, markdown: r.version.markdown, data: r.version.data }
|
|
@@ -811,6 +908,55 @@ export function registerTools(server, ctx) {
|
|
|
811
908
|
raw_url: `${config.reviewUrl}/review/${id}/raw${version ? `?v=${version}` : ""}`,
|
|
812
909
|
};
|
|
813
910
|
}));
|
|
911
|
+
server.registerTool("review_transcript_status", {
|
|
912
|
+
title: "Where a review's transcript stands",
|
|
913
|
+
description: "Read-only. For a review (id, miadi-review:<uuid>, URL, or its video), says whether its transcript is unknown, absent, acquiring, stored, held (a withheld source) or failed, with the job's stages, the retry schedule, the digest and coverage of what is stored, the failure's reason and who can remedy it, and plain links that work without a card (status page, review, transcript API, job record). verify:true reads the stored transcript back from the review service and hashes it now. It changes nothing; ensure_review_transcript is what acquires it.",
|
|
914
|
+
inputSchema: { review: z.string().min(1).describe("Review id, miadi-review:<uuid>, review URL, or the video's YouTube URL or id."), verify: z.boolean().optional().describe("Read the stored transcript back from the review service and hash it now (no record is written).") },
|
|
915
|
+
annotations: READ,
|
|
916
|
+
}, wrap(async ({ review, verify }, extra) => {
|
|
917
|
+
who(extra);
|
|
918
|
+
if (!ctx.approval)
|
|
919
|
+
throw new ToolRefusal("unavailable", "This connector runs no transcript jobs.");
|
|
920
|
+
if (!reviews.canSearch)
|
|
921
|
+
throw new ToolRefusal("unavailable", "The connector host has no review service token, so a transcript's state cannot be read.");
|
|
922
|
+
const named = await reviewNamed(review);
|
|
923
|
+
return transcriptStatus(transcriptJobIo(ctx.approval), { ...named, ...(verify ? { verify } : {}) }, (job) => transcriptLinks(named.review_id, job));
|
|
924
|
+
}));
|
|
925
|
+
server.registerTool("ensure_review_transcript", {
|
|
926
|
+
title: "Make sure a review holds its video's transcript",
|
|
927
|
+
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, then a local transcription where the host enables it and the source is released, and calls no model. 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.",
|
|
928
|
+
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.") },
|
|
929
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
930
|
+
}, wrap(async (a, extra) => {
|
|
931
|
+
const { person, auth } = who(extra);
|
|
932
|
+
requireContribute(auth);
|
|
933
|
+
if (!ctx.approval || (!ctx.approval.captions && !ctx.approval.localTranscription))
|
|
934
|
+
throw new ToolRefusal("unavailable", "This connector host has no captions reader, so it cannot acquire a transcript. An operator wires one in bin.ts.");
|
|
935
|
+
if (!reviews.canSearch)
|
|
936
|
+
throw new ToolRefusal("unavailable", "The connector host has no review service token, so a transcript cannot be stored or read back.");
|
|
937
|
+
const named = await reviewNamed(a.review);
|
|
938
|
+
// The authority that already covers processing a review: the write tier, or the person who registered the video's source.
|
|
939
|
+
const registered = all().some((r) => r.kind === "source_intent" && r.body.video_id === named.video_id && r.actor.person_id === person.id);
|
|
940
|
+
if (person.api_tier !== "write" && !registered) {
|
|
941
|
+
throw new ToolRefusal("forbidden", "Acquiring a review's transcript needs Miadi's write tier or being the person who registered this video's source (register_source_intent).");
|
|
942
|
+
}
|
|
943
|
+
const io = transcriptJobIo(ctx.approval);
|
|
944
|
+
const ensured = ensureTranscript(io, { review_id: named.review_id, video_id: named.video_id, actor: actorOf(person, auth), trigger: `ensure_review_transcript by ${person.name}${a.intention ? `: ${a.intention}` : ""}` });
|
|
945
|
+
const waitedFrom = Date.now();
|
|
946
|
+
const settled = await settleWithin(ensured.done, decisionWaitOf(ctx.approval));
|
|
947
|
+
const status = await transcriptStatus(io, named, (job) => transcriptLinks(named.review_id, job));
|
|
948
|
+
return {
|
|
949
|
+
...status,
|
|
950
|
+
ensure: {
|
|
951
|
+
authority: person.api_tier === "write" ? "Miadi write tier" : "the person who registered this video's source",
|
|
952
|
+
decision_required: false,
|
|
953
|
+
joined_running_attempt: ensured.joined,
|
|
954
|
+
attempt: settled === STILL_RUNNING ? "running" : "finished",
|
|
955
|
+
waited_ms: Date.now() - waitedFrom,
|
|
956
|
+
next: settled === STILL_RUNNING ? "The attempt goes on. Follow it with review_transcript_status or the status link." : status.state === "acquiring" ? "The connector retries by itself at next_attempt_at." : "Nothing further is needed from this call.",
|
|
957
|
+
},
|
|
958
|
+
};
|
|
959
|
+
}));
|
|
814
960
|
server.registerTool("handoff_status", {
|
|
815
961
|
title: "Handoffs between circles",
|
|
816
962
|
description: "Handoffs and their state (pending, blocked, ready, in_progress, completed, withdrawn), responsible circle, next action, receipts and human gates. Filter by a reference, a circle or a state.",
|
|
@@ -872,6 +1018,7 @@ export function registerTools(server, ctx) {
|
|
|
872
1018
|
bound.add(ref.slice(8));
|
|
873
1019
|
const checked = isMission ? await missionResult(r, all(), bound, { githubGet: github, approvalUrl }) : undefined;
|
|
874
1020
|
const result = checked && person.api_tier !== "write" ? redactResult(checked) : checked;
|
|
1021
|
+
const projection = requestProjection(r, { reviewBase: ctx.approval?.config.reviewUrl, factoryDir: ctx.factoryDir });
|
|
875
1022
|
return {
|
|
876
1023
|
record: r,
|
|
877
1024
|
version: versionOf(r),
|
|
@@ -892,7 +1039,14 @@ export function registerTools(server, ctx) {
|
|
|
892
1039
|
}
|
|
893
1040
|
: {}),
|
|
894
1041
|
// Where the request stands, in the words every surface uses (jgwill/Miadi#889).
|
|
895
|
-
projection
|
|
1042
|
+
projection,
|
|
1043
|
+
// Plain words and plain links, so a client that draws no card still shows where the request stands (jgwill/Miadi#995).
|
|
1044
|
+
...(projection ? { summary: `${projection.label}. ${projection.lines.join(" ")}`.trim() } : {}),
|
|
1045
|
+
links: {
|
|
1046
|
+
decision: isApprovable(r) ? approvalUrl(r.id) : null,
|
|
1047
|
+
record: `${config.publicUrl}/records/${encodeURIComponent(r.id)}`,
|
|
1048
|
+
result: projection?.receipt_url ?? null,
|
|
1049
|
+
},
|
|
896
1050
|
...(r.kind === "run_request" || r.kind === "work_proposal" ? { draft_review: reviewShownTo(ctx.draftReview?.stored(r), r, person) } : {}),
|
|
897
1051
|
...(r.approval_state === "revision_requested"
|
|
898
1052
|
? { revision: { instructions: r.completion_receipt?.instructions, next: `Revise it in place: revise_pending_request with request_id ${r.id} and expected_version ${versionOf(r)}.` } }
|
|
@@ -2074,7 +2228,7 @@ export function registerTools(server, ctx) {
|
|
|
2074
2228
|
}));
|
|
2075
2229
|
server.registerTool("request_review_operation", {
|
|
2076
2230
|
title: "Request a review operation",
|
|
2077
|
-
description: "Ask for one review-service operation: create (a review from a YouTube URL; once approved it also stores the video's YouTube captions as the review's transcript, with no model call), import_markdown (a hand-written version), new_version (regenerate), store_transcript. It waits for a person's approval; check review_lookup first so nothing is duplicated.",
|
|
2231
|
+
description: "Ask for one review-service operation: create (a review from a YouTube URL; once approved it also stores the video's YouTube captions as the review's transcript, with no model call), import_markdown (a hand-written version), new_version (regenerate), store_transcript (exact text you supply, which a person approves; a review's own transcript is acquired by ensure_review_transcript with no decision). It waits for a person's approval; check review_lookup first so nothing is duplicated.",
|
|
2078
2232
|
inputSchema: {
|
|
2079
2233
|
operation: z.enum(["create", "import_markdown", "new_version", "store_transcript"]),
|
|
2080
2234
|
review_id: z.string().optional(),
|
|
@@ -2430,14 +2584,17 @@ export function registerTools(server, ctx) {
|
|
|
2430
2584
|
shown[k] = `${shown[k].length} chars`;
|
|
2431
2585
|
return JSON.stringify({ ...shown, refs: r.refs.length ? r.refs : undefined }, null, 2);
|
|
2432
2586
|
};
|
|
2587
|
+
const CARD_META = { ui: { prefersBorder: true, csp: { connectDomains: [], resourceDomains: [] } }, "openai/widgetDescription": "Cards for the requests awaiting the person's decision." };
|
|
2433
2588
|
for (const uri of [DECISIONS_CARD_URI, ...DECISIONS_CARD_EARLIER_URIS]) {
|
|
2434
|
-
server.registerResource(uri === DECISIONS_CARD_URI ? "miadi-decisions-card" : `miadi-decisions-card-${uri.replace(/\W+/g, "-")}`, uri,
|
|
2589
|
+
server.registerResource(uri === DECISIONS_CARD_URI ? "miadi-decisions-card" : `miadi-decisions-card-${uri.replace(/\W+/g, "-")}`, uri,
|
|
2590
|
+
// The same template metadata on the listing and on the read: a host that takes the listing's entry would otherwise see none (jgwill/Miadi#995).
|
|
2591
|
+
{ title: "Miadi decisions", description: "Requests awaiting a person's decision, decided by the person's own click.", mimeType: "text/html;profile=mcp-app", _meta: CARD_META }, async () => ({
|
|
2435
2592
|
contents: [
|
|
2436
2593
|
{
|
|
2437
2594
|
uri,
|
|
2438
2595
|
mimeType: "text/html;profile=mcp-app",
|
|
2439
2596
|
text: DECISIONS_CARD_HTML,
|
|
2440
|
-
_meta:
|
|
2597
|
+
_meta: CARD_META,
|
|
2441
2598
|
},
|
|
2442
2599
|
],
|
|
2443
2600
|
}));
|
|
@@ -2499,8 +2656,10 @@ export function registerTools(server, ctx) {
|
|
|
2499
2656
|
...(reason ? { reason } : {}),
|
|
2500
2657
|
...(decisions.length ? {} : { message: record_id ? "That request is not awaiting a decision." : "No request is waiting for a decision." }),
|
|
2501
2658
|
};
|
|
2659
|
+
// A client may draw no card, and a card shows nothing to the model: each request is also a line with its own link (jgwill/Miadi#995).
|
|
2660
|
+
const lines = decisions.slice(0, 10).map((d) => `- ${d.id} · ${d.kind_label} · ${d.title} · ${d.projection?.label ?? d.projection?.stage ?? "waiting"} · ${d.approval_url}`);
|
|
2502
2661
|
const text = decisions.length
|
|
2503
|
-
? `${decisions.length} request(s) shown as cards; ${actionable.length} await a decision. ${canDecide ? "The person decides an awaiting request on its card; do not decide or claim a decision for them." : reason}`
|
|
2662
|
+
? `${decisions.length} request(s) shown as cards; ${actionable.length} await a decision. ${canDecide ? "The person decides an awaiting request on its card, or on its link if no card appears; do not decide or claim a decision for them." : reason}\n${lines.join("\n")}${decisions.length > lines.length ? `\n… and ${decisions.length - lines.length} more in structuredContent.` : ""}`
|
|
2504
2663
|
: structured.message;
|
|
2505
2664
|
return { structuredContent: structured, content: [{ type: "text", text }], _meta: { [DECISION_TOKENS_META]: tokens } };
|
|
2506
2665
|
}
|
|
@@ -2669,12 +2828,15 @@ export const TOOL_STATUS = {
|
|
|
2669
2828
|
get_circle: "live",
|
|
2670
2829
|
list_sessions: "live, Miadi write tier",
|
|
2671
2830
|
get_session: "live, Miadi write tier",
|
|
2831
|
+
search_sessions: "live, Miadi write tier (searched on Miadi's host; the read stops at 20 s and names what it left)",
|
|
2672
2832
|
get_evidence: "live",
|
|
2673
2833
|
read_episode_file: "live (Miadi read tier: an episode's text files; chronicle_foundations_read alone: foundations/<topic>/*.md; up to 512 KiB, paged; read as you, nothing changed)",
|
|
2674
2834
|
get_evaluations: "live (tracing records and recorded assessments; no provider scores)",
|
|
2675
2835
|
get_narrative_beats: "live (NCP project beats and candidate beats)",
|
|
2676
2836
|
review_lookup: "live (video search needs the review token on the connector host)",
|
|
2677
|
-
review_versions: "live",
|
|
2837
|
+
review_versions: "live (carries the transcript's state)",
|
|
2838
|
+
review_transcript_status: "live (read-only: unknown, absent, acquiring, stored, held or failed, with stages, digest, readback, retry schedule, remedy and plain links)",
|
|
2839
|
+
ensure_review_transcript: "live, contribute (acquires and stores an existing review's transcript under the authority that covers processing it: write tier or the source's registrant; no decision, no model call, never overwrites)",
|
|
2678
2840
|
handoff_status: "live",
|
|
2679
2841
|
list_records: "live",
|
|
2680
2842
|
get_run_result: "live",
|