@miadi/connector 0.1.43 → 0.1.44

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/dist/tools.js CHANGED
@@ -44,6 +44,7 @@ import { readingScope, canonicalVideo, suppliedDialogue } from "./reading/contra
44
44
  import { workflowId } from "./reading/workflow.js";
45
45
  import { readingTask } from "./reading/adapters.js";
46
46
  import { recordsSeenBy, redactRecord } from "./record-view.js";
47
+ import { MAX_REGISTRATION_BYTES, MIN_REGISTRATION_BYTES, REGISTRY_REVIEW_KIND, REVIEW_SOURCE_RELATION, ScreenwalkRefusal, inventoryOf, listRegistrations, looksLikeScreenwalk, namesOf, namesScreenwalk, pageText, partIndex, readBrief, readMoments, readRegistration, readinessOf, registryOrigins, relateRegistration, reviewRecordsOf, reviewRelationsOf, screenwalkRefOf, screenwalksOfReview, selectRegistration, videoOf, } from "./screenwalks.js";
47
48
  import { artefactVisibility, readArtefactWeave, saveResearchArtefact } from "@miadi/inquiry-weave";
48
49
  import { ResearchUploads, UploadRefusal } from "./uploads.js";
49
50
  import { DEFAULT_PAGE_BYTES, FOUNDATIONS_PERMISSION, FileRefusal, MAX_TEXT_BYTES, MIN_PAGE_BYTES, TEXT_TYPES, checkRelativePath, episodeNumberOf, extensionOf, fileRef, holdsFoundationRead, isFoundationDoc, pageOf, parseFileRef, } from "./episode-files.js";
@@ -103,6 +104,8 @@ function wrap(fn) {
103
104
  catch (error) {
104
105
  if (error instanceof ToolRefusal)
105
106
  return fail({ error: error.code, message: error.message, ...(error.detail ? { detail: error.detail } : {}) });
107
+ if (error instanceof ScreenwalkRefusal)
108
+ return fail({ error: error.code, message: error.message, ...(error.detail ? { detail: error.detail } : {}) });
106
109
  if (error instanceof UploadRefusal)
107
110
  return fail({ error: "invalid_upload", message: error.message });
108
111
  if (error instanceof FileRefusal)
@@ -122,7 +125,7 @@ function wrap(fn) {
122
125
  }
123
126
  const READ = { readOnlyHint: true, destructiveHint: false, openWorldHint: false };
124
127
  const WRITE = { readOnlyHint: false, destructiveHint: false, openWorldHint: false };
125
- const refs = z.array(z.string()).max(50).default([]).describe("References: miadi-review:<uuid>, miadi-chronicle://<n>, owner/repo#n, session:<uuid>, a record id, or a URL.");
128
+ const refs = z.array(z.string()).max(50).default([]).describe("References: miadi-review:<uuid>, miadi-chronicle://<n>, miadi-screenwalk:<id>, owner/repo#n, session:<uuid>, a record id, or a URL.");
126
129
  const circle = z.enum(CIRCLE_IDS);
127
130
  const claim = z.enum(CLAIM_CATEGORIES).describe("observed, hypothesis, desired_future, fiction or verified_implementation.");
128
131
  const primaryIssue = z
@@ -450,6 +453,19 @@ export function registerTools(server, ctx) {
450
453
  // Host truth, as provider_capabilities is: what this host would load into a new session.
451
454
  ...(person.api_tier !== "write" ? {} : { on_this_host: Object.fromEntries(Object.values(ADAPTERS).map((a) => { const s = steeringOf(a.provider); return [a.provider, { steerable: s.steerable, adapter: s.adapter?.version ?? null, ...(s.reason ? { reason: s.reason } : {}) }]; })) }),
452
455
  },
456
+ // The Screenwalk Registry, read as the person through Miadi's registry door (jgwill/Miadi#1180).
457
+ screenwalk_registry: {
458
+ read: "get_screenwalk",
459
+ list: "list_screenwalks",
460
+ review_step: "request_screenwalk_review",
461
+ registry: `${config.miadiPublicUrl}/screenwalks`,
462
+ accepts: ["<registry id>", "miadi-screenwalk:<id>", `${config.miadiPublicUrl}/screenwalks/<id>`],
463
+ authority: "your own Miadi sign-in: the registry's rights decide what you read (review or steward screenwalk registrations, or a facilitator's seat), and stewarding decides whether a relation is written on a registration",
464
+ review_match: "the registration's YouTube video id, searched in the Miadi Review Service",
465
+ review_search: reviews.canSearch ? "enabled" : "disabled: no review service token on the connector host",
466
+ relation: `a link (${REVIEW_SOURCE_RELATION}) in the connector's records from the registration to the review, and a ${REGISTRY_REVIEW_KIND} relation on the registration to the review`,
467
+ not_done_here: "No review is created without a person's approval. No inventory is copied into a review. A registration is not a transcript.",
468
+ },
453
469
  foundation_read: {
454
470
  permission: FOUNDATIONS_PERMISSION,
455
471
  held: foundations,
@@ -471,7 +487,7 @@ export function registerTools(server, ctx) {
471
487
  }));
472
488
  server.registerTool("get_context", {
473
489
  title: "Resolve a reference",
474
- description: "Resolve one reference to what it points at: miadi-review:<uuid> (with the episodes that hold it), miadi-chronicle://<n> or chronicle:<folder>, miadi-ceremony:, miadi-circle:, miadi-foundation:, miadi-tracing:, session:<uuid>, owner/repo#n (GitHub issue), a YouTube URL or video id, or a connector record id. Also lists connector records that cite it.",
490
+ description: "Resolve one reference to what it points at: miadi-review:<uuid> (with the episodes that hold it), miadi-screenwalk:<id> or a screenwalk's page URL (its registration's identity, video and standing), miadi-chronicle://<n> or chronicle:<folder>, miadi-ceremony:, miadi-circle:, miadi-foundation:, miadi-tracing:, session:<uuid>, owner/repo#n (GitHub issue), a YouTube URL or video id, or a connector record id. Also lists connector records that cite it.",
475
491
  inputSchema: { ref: z.string().min(1) },
476
492
  annotations: READ,
477
493
  }, wrap(async ({ ref }, extra) => {
@@ -509,6 +525,10 @@ export function registerTools(server, ctx) {
509
525
  cited_by: cited,
510
526
  };
511
527
  }
528
+ if (looksLikeScreenwalk(r, walkOrigins)) {
529
+ const w = await walkRead(person, r);
530
+ return { ref: r, kind: "screenwalk", ...walkHead(person, w), cited_by: records().filter((x) => namesScreenwalk(x, w.named.id)), next: "get_screenwalk reads the whole registration, its brief or its moments." };
531
+ }
512
532
  const video = videoIdOf(r);
513
533
  if (video && !reviewIdOf(r)) {
514
534
  return { ref: r, kind: "video", video_id: video, reviews: await lookupByVideo(video), cited_by: cited };
@@ -569,6 +589,137 @@ export function registerTools(server, ctx) {
569
589
  const found = (await reviews.search(videoId, 10)).filter((x) => x.video_id === videoId);
570
590
  return found.map((x) => reviews.summary(x));
571
591
  }
592
+ // ── the screenwalk registry, read as the person (jgwill/Miadi#1180) ─────
593
+ const walkOrigins = registryOrigins(config);
594
+ /** Where a registration is read by a person, on this factory's public address. */
595
+ const walkLinks = (id) => {
596
+ const record = `${config.miadiPublicUrl}/api/screenwalks/registrations/${encodeURIComponent(id)}`;
597
+ return { page_url: `${config.miadiPublicUrl}/screenwalks/${encodeURIComponent(id)}`, record_url: record, brief_url: `${record}?format=brief`, moments_url: `${record}?format=moments` };
598
+ };
599
+ /** A registration read as the person. The registry's refusal becomes this tool's, in the registry's terms. */
600
+ async function walkRead(person, input) {
601
+ const named = screenwalkRefOf(input, walkOrigins);
602
+ const read = await readRegistration(miadi, person.token, named.id);
603
+ if (read.state !== "found")
604
+ throw new ToolRefusal(read.state, read.message, { screenwalk: named.reference });
605
+ return { named, registration: read.registration, summary: read.summary, read_at: new Date().toISOString() };
606
+ }
607
+ /** What every answer about one registration carries: its identity, its video, where it stands, and where and as whom it was read. */
608
+ const walkHead = (person, w) => ({
609
+ state: "found",
610
+ screenwalk: { id: w.named.id, reference: w.named.reference, ...walkLinks(w.named.id) },
611
+ resolved_from: w.named.form,
612
+ schema: w.registration.schema ?? null,
613
+ revision: w.registration.revision,
614
+ registered: w.registration.registered ?? null,
615
+ ...(w.registration.test === true ? { test: true } : {}),
616
+ video: videoOf(w.registration),
617
+ names: namesOf(w.registration, w.summary),
618
+ readiness: readinessOf(w.registration, w.summary),
619
+ inventory: inventoryOf(w.registration),
620
+ source: {
621
+ registry: `${config.miadiPublicUrl}/screenwalks`,
622
+ door: `GET /api/screenwalks/registrations/${w.named.id}`,
623
+ read_as: { person_id: person.id, name: person.name },
624
+ read_at: w.read_at,
625
+ revision: w.registration.revision,
626
+ },
627
+ });
628
+ /**
629
+ * The reviews the Miadi Review Service holds of one video, matched by its YouTube video id: the key the registry and
630
+ * the Review Service share. A search that cannot run is an answer of its own, never read as "no review".
631
+ */
632
+ async function reviewsOfVideo(videoId) {
633
+ if (!reviews.canSearch)
634
+ return { state: "lookup_unavailable", reviews: [], message: "The connector host has no review service token, so the Miadi Review Service cannot be searched by video." };
635
+ try {
636
+ const found = (await reviews.search(videoId, 10)).filter((x) => x.video_id === videoId).map((x) => reviews.summary(x));
637
+ return { state: found.length === 0 ? "no_review" : found.length === 1 ? "found" : "ambiguous", reviews: found };
638
+ }
639
+ catch (error) {
640
+ return { state: "lookup_unavailable", reviews: [], message: `The Miadi Review Service could not be searched: ${error instanceof Error ? error.message : String(error)}.` };
641
+ }
642
+ }
643
+ const WALK_REVIEW_NEXT = {
644
+ related: "The registration and the review of its video are related in both directions. review_lookup reads the review.",
645
+ found: "A review of this video exists. request_screenwalk_review records the relation between the two and creates nothing.",
646
+ no_review: "No review of this video exists. request_screenwalk_review prepares one create request with this registration as its source, for a person to approve.",
647
+ ambiguous: "Several reviews of this video exist. Nothing is related or created until a person names the one.",
648
+ lookup_unavailable: "Whether a review exists is unknown. Ask for no new review until the lookup works.",
649
+ };
650
+ /** Read-only: whether a review of the registration's video exists, and what relates the two on each side. */
651
+ async function walkReview(w) {
652
+ const video = videoOf(w.registration);
653
+ const onRegistration = reviewRelationsOf(w.registration);
654
+ const inRecords = reviewRecordsOf(records(), w.named.id);
655
+ const base = { matched_by: "youtube_video_id", video_id: video.video_id, service: config.reviewUrl };
656
+ if (!video.video_id) {
657
+ return { ...base, state: "no_video_id", message: "The registration's video URL names no YouTube video id, so no review can be matched to it.", reviews: [], relation: { on_registration: onRegistration, in_connector_records: inRecords } };
658
+ }
659
+ const found = await reviewsOfVideo(video.video_id);
660
+ const one = found.state === "found" ? found.reviews[0] : null;
661
+ const recorded = one ? { from_registration: onRegistration.some((x) => x.review_id === one.review_id), from_review: inRecords.some((x) => x.review_id === one.review_id) } : null;
662
+ return {
663
+ ...base,
664
+ state: found.state,
665
+ ...(found.message ? { message: found.message } : {}),
666
+ reviews: found.reviews,
667
+ relation: { on_registration: onRegistration, in_connector_records: inRecords, ...(recorded ? { recorded } : {}) },
668
+ next: WALK_REVIEW_NEXT[recorded?.from_registration && recorded.from_review ? "related" : found.state],
669
+ };
670
+ }
671
+ /**
672
+ * Record that a review is the review of a registered screenwalk's video, on both sides, once: a link in the
673
+ * connector's records (the name those records already give a source and its review), which a review's page and
674
+ * review_lookup read, and a relation on the registration itself, which its page and its brief read. The second is
675
+ * written as the person and needs the right to steward registrations; without it the first still stands.
676
+ */
677
+ async function relateWalkReview(person, auth, w, review, source, a) {
678
+ const to = `miadi-review:${review.review_id}`;
679
+ const prior = all().find((r) => r.kind === "link" && r.body.relation === REVIEW_SOURCE_RELATION && namesScreenwalk(r, w.named.id) && reviewIdOf(String(r.body.to ?? "")) === review.review_id);
680
+ const link = prior ??
681
+ append("link", person, auth, {
682
+ circle: "continuity",
683
+ refs: [w.named.reference, to],
684
+ intention: a.intention ?? "Relate a registered screenwalk to the Miadi Review of its video.",
685
+ ...(a.role ? { role: a.role } : {}),
686
+ idempotency_key: `screenwalk-review:${w.named.id}:${review.review_id}`,
687
+ body: {
688
+ from: w.named.reference,
689
+ to,
690
+ relation: REVIEW_SOURCE_RELATION,
691
+ note: `The Miadi Review Service holds this one review of the video the screenwalk registers (YouTube video id ${String(source.video_id)}). The registration was read at revision ${String(source.revision)}.`,
692
+ source,
693
+ },
694
+ });
695
+ const held = reviewRelationsOf(w.registration).find((x) => x.review_id === review.review_id);
696
+ // The registry writes its addresses with "//" (miadi-chronicle://257); the review's address follows it there.
697
+ const relation = { id: `review-${review.review_id}`, kind: REGISTRY_REVIEW_KIND, target: `miadi-review://${review.review_id}` };
698
+ const words = {
699
+ ...relation,
700
+ label: "Miadi Review of this walk's video",
701
+ note: `${review.url}. Matched by the YouTube video id ${String(source.video_id)}. Recorded through the Miadi connector; the connector's record is ${link.id}.`,
702
+ };
703
+ let written = held ? { state: "held" } : await relateRegistration(miadi, person.token, w.named.id, w.registration.revision, words);
704
+ if (written.state === "not_recorded" && written.reason === "conflict") {
705
+ // The registration moved between the read and the write: read it once more and write against what it is now.
706
+ const again = await readRegistration(miadi, person.token, w.named.id);
707
+ if (again.state === "found") {
708
+ written = reviewRelationsOf(again.registration).some((x) => x.review_id === review.review_id)
709
+ ? { state: "held" }
710
+ : await relateRegistration(miadi, person.token, w.named.id, again.registration.revision, words);
711
+ }
712
+ }
713
+ return {
714
+ from_review: { state: prior ? "held" : "recorded", where: "the connector's records", record: link.id, from: w.named.reference, to, relation: REVIEW_SOURCE_RELATION, read_by: ["review_lookup", "get_screenwalk", `${config.miadiPublicUrl}/reviews/${review.review_id}`] },
715
+ from_registration: {
716
+ where: "the registration",
717
+ ...(held ? { relation: held.id, kind: held.kind, target: held.target } : relation),
718
+ ...written,
719
+ read_by: ["get_screenwalk", walkLinks(w.named.id).page_url],
720
+ },
721
+ };
722
+ }
572
723
  server.registerTool("list_circles", {
573
724
  title: "The five circles, and the talking circles you belong to",
574
725
  description: "The five accountable circles (Story, Stewardship, Engineering, Evaluation, Continuity) with what each is accountable for and how many handoffs each holds open, and the Miadi talking circles your person token reaches.",
@@ -984,7 +1135,7 @@ export function registerTools(server, ctx) {
984
1135
  }));
985
1136
  server.registerTool("review_lookup", {
986
1137
  title: "Find a Miadi review",
987
- description: "Find the review of a video before anything is created: by review id, review URL, YouTube URL or video id, or keywords. Returns review id, latest version, video, Deep Diver readiness and the episodes that hold it. Never creates a review.",
1138
+ description: "Find the review of a video before anything is created: by review id, review URL, YouTube URL or video id, or keywords. Returns review id, latest version, video, Deep Diver readiness, the episodes that hold it and the registered screenwalks related to it. Never creates a review.",
988
1139
  inputSchema: { query: z.string().min(1) },
989
1140
  annotations: READ,
990
1141
  }, wrap(async ({ query }, extra) => {
@@ -995,13 +1146,13 @@ export function registerTools(server, ctx) {
995
1146
  if (!r)
996
1147
  return { query, state: "not_found", review_id: id };
997
1148
  const holders = await miadi.get(person.token, `/api/chronicle/resolve?uri=${encodeURIComponent(`miadi-review:${id}`)}`).then((b) => b?.holders ?? b?.resolution?.holders ?? null, () => null);
998
- return { query, state: "found", review: reviews.summary(r), transcript: await transcriptBrief(id, r.video_id), holders, cited_by: touching(`miadi-review:${id}`) };
1149
+ return { query, state: "found", review: reviews.summary(r), transcript: await transcriptBrief(id, r.video_id), holders, screenwalks: screenwalksOfReview(records(), id), cited_by: touching(`miadi-review:${id}`) };
999
1150
  }
1000
1151
  const video = videoIdOf(query);
1001
1152
  if (video) {
1002
1153
  const found = await lookupByVideo(video);
1003
1154
  const intents = records().filter((r) => r.kind === "source_intent" && r.body.video_id === video);
1004
- const withTranscript = Array.isArray(found) ? await Promise.all(found.slice(0, 5).map(async (x) => ({ ...x, transcript: await transcriptBrief(x.review_id, video) }))) : found;
1155
+ const withTranscript = Array.isArray(found) ? await Promise.all(found.slice(0, 5).map(async (x) => ({ ...x, transcript: await transcriptBrief(x.review_id, video), screenwalks: screenwalksOfReview(records(), x.review_id) }))) : found;
1005
1156
  return { query, video_id: video, state: Array.isArray(found) && found.length ? "found" : "no_review", reviews: withTranscript, source_intents: intents };
1006
1157
  }
1007
1158
  if (!reviews.canSearch)
@@ -1079,6 +1230,167 @@ export function registerTools(server, ctx) {
1079
1230
  },
1080
1231
  };
1081
1232
  }));
1233
+ server.registerTool("get_screenwalk", {
1234
+ title: "Read a registered screenwalk",
1235
+ description: "Read one screenwalk's registration from the Screenwalk Registry, as you: its registry id and page, the canonical YouTube URL and video id, the safe title, title and description with where they stand, its revision and who registered it, and the inventory already prepared for it (question sets and their states, segments, sources, questions, purpose lists and their items, relations including correlates, names as heard, coverage, and what a person checked), in the registry's own schema. Give the registry id (2612021410), miadi-screenwalk:<id>, or the screenwalk's page URL on this factory. format: record (the default; parts keeps only the top-level parts you name, purpose keeps one purpose list), brief (the registry's Markdown brief; purpose gives the brief of one list) or moments (one row per timeframe). A registration larger than max_bytes comes in pages with its size and sha256, never cut silently. With record it also says whether the Miadi Review Service holds a review of this video, matched by the YouTube video id, and what relates the two. Read-only: it never changes the registration and never creates a review. The inventory is the registry's record of what was asked about the video, not a review and not a transcript.",
1236
+ inputSchema: {
1237
+ ref: z.string().min(1).max(500).describe("The registry id, miadi-screenwalk:<id>, or the screenwalk's page URL on this factory's registry."),
1238
+ format: z.enum(["record", "brief", "moments"]).default("record"),
1239
+ purpose: z.string().max(80).optional().describe("A purpose list's id (follow-ups, circle-topics, …). With brief: the brief of that list. With record: that list only among the purposes."),
1240
+ parts: z.array(z.string().min(1).max(40)).max(30).optional().describe("With record: only these top-level parts of the registration (video, rounds, decisions, knowledge, purposes, relations, names, topics, notices, coverage, stages, …)."),
1241
+ offset: z.number().int().min(0).optional().describe("With a paged answer: the next.offset it returned."),
1242
+ revision: z.string().max(64).optional().describe("With offset: the next.revision it returned, so pages of two revisions are never joined."),
1243
+ max_bytes: z.number().int().min(MIN_REGISTRATION_BYTES).max(MAX_REGISTRATION_BYTES).optional().describe("The most bytes of registration, brief or moments one answer carries. Default 100000."),
1244
+ },
1245
+ annotations: READ,
1246
+ }, wrap(async (a, extra) => {
1247
+ const { person } = who(extra);
1248
+ const format = a.format ?? "record";
1249
+ if (format !== "record" && a.parts?.length)
1250
+ throw new ToolRefusal("invalid_request", "parts selects parts of the record; the brief and the moment index are the registry's own projections and come whole.");
1251
+ if (format === "moments" && a.purpose)
1252
+ throw new ToolRefusal("invalid_request", "purpose selects a list in the brief or in the record; the moment index has no purpose filter.");
1253
+ const w = await walkRead(person, a.ref);
1254
+ const head = walkHead(person, w);
1255
+ const lists = (Array.isArray(w.registration.purposes) ? w.registration.purposes : []).map((l) => String(l?.id));
1256
+ if (a.purpose && !lists.includes(a.purpose))
1257
+ throw new ToolRefusal("purpose_not_found", `No purpose list "${a.purpose}" in this registration.`, { purposes: lists });
1258
+ const paging = { ...(a.offset !== undefined ? { offset: a.offset } : {}), ...(a.revision ? { revision: a.revision } : {}), ...(a.max_bytes ? { maxBytes: a.max_bytes } : {}) };
1259
+ if (format === "brief") {
1260
+ const brief = await readBrief(miadi, person.token, w.named.id, a.purpose);
1261
+ if (brief.state !== "found")
1262
+ throw new ToolRefusal(brief.state, brief.message, { screenwalk: w.named.reference });
1263
+ const page = pageText(brief.markdown, paging);
1264
+ return { ...head, format, ...(a.purpose ? { purpose: a.purpose } : {}), brief: { bytes: page.bytes, sha256: page.sha256, complete: page.complete, page: page.page, markdown: page.text } };
1265
+ }
1266
+ if (format === "moments") {
1267
+ const m = await readMoments(miadi, person.token, w.named.id);
1268
+ if (m.state !== "found")
1269
+ throw new ToolRefusal(m.state, m.message, { screenwalk: w.named.reference });
1270
+ const page = pageText(JSON.stringify(m.moments), paging);
1271
+ return {
1272
+ ...head,
1273
+ format,
1274
+ moments_revision: m.revision,
1275
+ ...(m.revision !== null && m.revision !== w.registration.revision ? { note: "The registration changed between the two reads: the moment index is of the revision it names." } : {}),
1276
+ rows: m.moments.length,
1277
+ ...(page.complete ? { moments: m.moments } : { moments: null, paged: { encoding: "json", bytes: page.bytes, sha256: page.sha256, page: page.page, text: page.text } }),
1278
+ };
1279
+ }
1280
+ const selected = selectRegistration(w.registration, { ...(a.parts?.length ? { parts: a.parts } : {}), ...(a.purpose ? { purpose: a.purpose } : {}) });
1281
+ const page = pageText(JSON.stringify(selected.value), paging);
1282
+ return {
1283
+ ...head,
1284
+ format,
1285
+ parts: {
1286
+ returned: selected.returned,
1287
+ left_out: selected.left_out,
1288
+ ...("purposes_left_out" in selected ? { purpose: selected.purpose, purposes_left_out: selected.purposes_left_out } : {}),
1289
+ index: partIndex(w.registration),
1290
+ },
1291
+ ...(page.complete
1292
+ ? { registration: selected.value }
1293
+ : {
1294
+ registration: null,
1295
+ paged: {
1296
+ encoding: "json",
1297
+ bytes: page.bytes,
1298
+ sha256: page.sha256,
1299
+ page: page.page,
1300
+ text: page.text,
1301
+ note: "This selection is larger than one answer carries. Its JSON text comes in pages: join them in order and check the sha256, or ask for fewer parts.",
1302
+ },
1303
+ }),
1304
+ // A following page of one read does not search the Review Service again.
1305
+ ...(a.offset ? {} : { review: await walkReview(w) }),
1306
+ };
1307
+ }));
1308
+ server.registerTool("list_screenwalks", {
1309
+ title: "List registered screenwalks",
1310
+ description: "The screenwalk registrations you may see in the Screenwalk Registry, newest registration first, as the registry's own list returns them: registry id, page, video URL and id, title, where the names stand, revision, who registered it and when, coverage and counts. Filter by the day they were registered (registered_on, a UTC day) or a window (registered_from, registered_to), by status, coverage, a name heard in them, or a video (YouTube URL or id). with_review adds, for at most 10 rows, whether the Miadi Review Service holds a review of each video. Read-only. A registration listed here says nothing about whether another agent's validation of it has finished.",
1311
+ inputSchema: {
1312
+ registered_on: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional().describe("A UTC day, YYYY-MM-DD: the registrations registered that day."),
1313
+ registered_from: z.string().max(40).optional().describe("An ISO date or instant: registered at or after it."),
1314
+ registered_to: z.string().max(40).optional().describe("An ISO date or instant: registered before it."),
1315
+ status: z.enum(["proposed", "needs_review", "approved", "approved_with_changes", "rejected"]).optional(),
1316
+ coverage: z.enum(["thin", "partial", "complete"]).optional(),
1317
+ name: z.string().max(100).optional().describe("Words of a name heard, likely or settled in the registration."),
1318
+ video: z.string().max(200).optional().describe("A YouTube URL or video id: the registrations of that video."),
1319
+ with_review: z.boolean().optional().describe("Add each row's review state from the Miadi Review Service (at most 10 rows a call)."),
1320
+ limit: z.number().int().min(1).max(100).default(25),
1321
+ offset: z.number().int().min(0).default(0),
1322
+ },
1323
+ annotations: READ,
1324
+ }, wrap(async (a, extra) => {
1325
+ const { person } = who(extra);
1326
+ const instant = (value, what) => {
1327
+ if (!value)
1328
+ return null;
1329
+ const t = Date.parse(value);
1330
+ if (!Number.isFinite(t))
1331
+ throw new ToolRefusal("invalid_request", `${what} is an ISO date or instant (2026-12-02 or 2026-12-02T15:00:00Z).`);
1332
+ return t;
1333
+ };
1334
+ const day = instant(a.registered_on ? `${a.registered_on}T00:00:00.000Z` : undefined, "registered_on");
1335
+ const from = day ?? instant(a.registered_from, "registered_from");
1336
+ const to = day !== null ? day + 86_400_000 : instant(a.registered_to, "registered_to");
1337
+ const video = a.video ? videoOf({ video: { url: a.video.trim().length === 11 ? `https://youtu.be/${a.video.trim()}` : a.video } }).video_id : null;
1338
+ if (a.video && !video)
1339
+ throw new ToolRefusal("invalid_ref", "video is a YouTube URL or an 11-character video id.");
1340
+ const listed = await listRegistrations(miadi, person.token, { ...(a.status ? { status: a.status } : {}), ...(a.name ? { name: a.name } : {}), ...(a.coverage ? { coverage: a.coverage } : {}) });
1341
+ if (listed.state !== "found")
1342
+ throw new ToolRefusal(listed.state, listed.message);
1343
+ const read_at = new Date().toISOString();
1344
+ const kept = listed.registrations.filter((s) => {
1345
+ const at = Date.parse(String(s?.registered?.at ?? ""));
1346
+ if (from !== null && !(at >= from))
1347
+ return false;
1348
+ if (to !== null && !(at < to))
1349
+ return false;
1350
+ return !video || videoOf({ video: s?.video }).video_id === video;
1351
+ });
1352
+ const limit = Math.min(a.limit ?? 25, a.with_review ? 10 : 100);
1353
+ const offset = a.offset ?? 0;
1354
+ const page = kept.slice(offset, offset + limit);
1355
+ const rows = await Promise.all(page.map(async (s) => {
1356
+ const v = videoOf({ video: s?.video });
1357
+ const row = {
1358
+ screenwalk: s?.screenwalk ?? null,
1359
+ reference: s?.reference ?? null,
1360
+ page_url: walkLinks(String(s?.screenwalk ?? "")).page_url,
1361
+ registered: { at: s?.registered?.at ?? null, by: s?.registered?.by?.name ?? null },
1362
+ video: { url: v.url, video_id: v.video_id, duration: v.duration },
1363
+ title: s?.current?.title ?? v.uploaded_title,
1364
+ safe_title: s?.current?.safe_title ?? null,
1365
+ status: s?.status ?? null,
1366
+ approved: s?.approved === true,
1367
+ revision: s?.revision ?? null,
1368
+ coverage: s?.coverage ?? null,
1369
+ transcript: s?.transcript ?? null,
1370
+ counts: s?.counts ?? null,
1371
+ purpose_items: s?.detail?.checked?.purpose_items?.total ?? null,
1372
+ ...(s?.test ? { test: true } : {}),
1373
+ };
1374
+ if (!a.with_review)
1375
+ return row;
1376
+ if (!v.video_id)
1377
+ return { ...row, review: { state: "no_video_id", reviews: [] } };
1378
+ const found = await reviewsOfVideo(v.video_id);
1379
+ return { ...row, review: { state: found.state, ...(found.message ? { message: found.message } : {}), reviews: found.reviews.map((x) => ({ review_id: x.review_id, ref: x.ref, url: x.url, title: x.title, latest_version: x.latest_version })) } };
1380
+ }));
1381
+ return {
1382
+ registry: `${config.miadiPublicUrl}/screenwalks`,
1383
+ filters: { ...(a.registered_on ? { registered_on: a.registered_on } : {}), ...(a.registered_from ? { registered_from: a.registered_from } : {}), ...(a.registered_to ? { registered_to: a.registered_to } : {}), ...(a.status ? { status: a.status } : {}), ...(a.coverage ? { coverage: a.coverage } : {}), ...(a.name ? { name: a.name } : {}), ...(video ? { video_id: video } : {}) },
1384
+ total: kept.length,
1385
+ offset,
1386
+ returned: rows.length,
1387
+ next_offset: offset + rows.length < kept.length ? offset + rows.length : null,
1388
+ ...(a.with_review && (a.limit ?? 25) > 10 ? { note: "with_review reads at most 10 rows a call; follow next_offset for the rest." } : {}),
1389
+ ...(a.with_review ? { review_match: "each video's YouTube id, searched in the Miadi Review Service" } : {}),
1390
+ registrations: rows,
1391
+ source: { door: "GET /api/screenwalks/registrations", read_as: { person_id: person.id, name: person.name }, read_at },
1392
+ };
1393
+ }));
1082
1394
  server.registerTool("handoff_status", {
1083
1395
  title: "Handoffs between circles",
1084
1396
  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.",
@@ -2534,6 +2846,96 @@ export function registerTools(server, ctx) {
2534
2846
  });
2535
2847
  return { ...r, body: { ...r.body, markdown: a.markdown ? `${a.markdown.length} chars` : undefined, transcript: a.transcript ? `${a.transcript.length} chars` : undefined }, approval_url: approvalUrl(r.id) };
2536
2848
  }));
2849
+ server.registerTool("request_screenwalk_review", {
2850
+ title: "Relate a registered screenwalk to its review, or ask for one",
2851
+ description: "One step from a registered screenwalk to its Miadi Review, safe to repeat. It reads the registration as you, takes its canonical YouTube video id and looks that video up in the Miadi Review Service. When one review exists it creates nothing: it records the relation between the registration and that review, in the connector's records and on the registration (the second when you may steward registrations), and returns the review. When none exists it prepares one create request for the canonical video, carrying the registry reference and the revision read; it waits for a person's approval like every review operation, and asking again returns the same request. When several reviews exist, or the Review Service cannot be searched, it writes nothing and says so. It never copies the registration's inventory into a review, never treats its answers as a transcript, and starts no Deep Diver and no episode link.",
2852
+ inputSchema: {
2853
+ screenwalk: z.string().min(1).max(500).describe("The registry id, miadi-screenwalk:<id>, or the screenwalk's page URL on this factory's registry."),
2854
+ refs,
2855
+ ...base,
2856
+ },
2857
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
2858
+ }, wrap(async (a, extra) => {
2859
+ const { person, auth } = who(extra);
2860
+ requireContribute(auth);
2861
+ const w = await walkRead(person, a.screenwalk);
2862
+ if (w.registration.test === true)
2863
+ throw new ToolRefusal("test_record", "This registration is a test record: no review is related to it or asked for it.");
2864
+ const video = videoOf(w.registration);
2865
+ if (!video.video_id)
2866
+ throw new ToolRefusal("no_video_id", "The registration's video URL names no YouTube video id, so no review can be matched or asked for.", { screenwalk: w.named.reference });
2867
+ const links = walkLinks(w.named.id);
2868
+ const source = {
2869
+ kind: "screenwalk_registration",
2870
+ reference: w.named.reference,
2871
+ revision: w.registration.revision,
2872
+ page_url: links.page_url,
2873
+ video_id: video.video_id,
2874
+ video_url: video.canonical_url,
2875
+ matched_by: "youtube_video_id",
2876
+ read_at: w.read_at,
2877
+ };
2878
+ const found = await reviewsOfVideo(video.video_id);
2879
+ const head = {
2880
+ screenwalk: { id: w.named.id, reference: w.named.reference, page_url: links.page_url, revision: w.registration.revision },
2881
+ video: { video_id: video.video_id, canonical_url: video.canonical_url },
2882
+ lookup: { service: config.reviewUrl, matched_by: "youtube_video_id", state: found.state },
2883
+ review_created: false,
2884
+ };
2885
+ if (found.state === "lookup_unavailable") {
2886
+ return { ...head, state: "lookup_unavailable", message: `${found.message} Nothing was recorded and no request was made: a create request is prepared only after the lookup has answered.` };
2887
+ }
2888
+ if (found.state === "ambiguous") {
2889
+ return { ...head, state: "ambiguous", message: "Several reviews of this video exist in the Miadi Review Service. Nothing was related and no request was made: a person names the review this registration belongs with.", reviews: found.reviews };
2890
+ }
2891
+ if (found.state === "found") {
2892
+ const review = found.reviews[0];
2893
+ const relation = await relateWalkReview(person, auth, w, review, source, a);
2894
+ const both = relation.from_registration.state === "recorded" || relation.from_registration.state === "held";
2895
+ return {
2896
+ ...head,
2897
+ state: "review_exists",
2898
+ message: both
2899
+ ? "A review of this video exists. No review was created. The registration and the review are related in both directions."
2900
+ : "A review of this video exists. No review was created. The relation is in the connector's records; it is not on the registration yet.",
2901
+ review,
2902
+ relation,
2903
+ };
2904
+ }
2905
+ // No review: one create request for this video stands at a time, whoever asked for it.
2906
+ const standing = all().find((r) => r.kind === "review_operation_request" &&
2907
+ r.body.operation === "create" &&
2908
+ r.body.video_id === video.video_id &&
2909
+ (r.approval_state === "awaiting_approval" || (r.approval_state === "approved" && r.state !== "completed" && r.completion_receipt?.outcome !== "failed")));
2910
+ if (standing) {
2911
+ return {
2912
+ ...head,
2913
+ state: standing.approval_state === "approved" ? "create_running" : "create_waiting",
2914
+ message: standing.approval_state === "approved"
2915
+ ? "A create request for this video was approved and has not finished. No second request was made."
2916
+ : "A create request for this video already waits for a person's approval. No second request was made.",
2917
+ request: redact(standing),
2918
+ names_this_registration: namesScreenwalk(standing, w.named.id),
2919
+ approval_url: approvalUrl(standing.id),
2920
+ };
2921
+ }
2922
+ const r = append("review_operation_request", person, auth, {
2923
+ circle: "continuity",
2924
+ refs: [...new Set([w.named.reference, ...a.refs, `https://youtu.be/${video.video_id}`])],
2925
+ intention: a.intention,
2926
+ role: a.role,
2927
+ idempotency_key: a.idempotency_key ?? `screenwalk:${w.named.id}:review:create`,
2928
+ approval_state: "awaiting_approval",
2929
+ body: { operation: "create", review_id: null, video_id: video.video_id, source },
2930
+ });
2931
+ return {
2932
+ ...head,
2933
+ state: "create_prepared",
2934
+ message: "No review of this video exists. One create request waits for a person's approval; nothing runs until then. Once the review exists, asking again records the relation.",
2935
+ request: r,
2936
+ approval_url: approvalUrl(r.id),
2937
+ };
2938
+ }));
2537
2939
  server.registerTool("request_participant_consent", {
2538
2940
  title: "Ask a person in a video whether its words may be published",
2539
2941
  description: "For a person on the record in a withheld video: filmed, or their own voice, words or screens shown. A person only mentioned, by name or as a kind of user, needs no question, so never ask because a name is spoken. A person's release from the start of a production will replace this door (jgwill/Miadi#962). This records one question to them, with the video's YouTube captions for them to read, and answers with a link only they decide on, no Miadi sign-in needed. Their yes releases the source and stores the words on the review; their not yet keeps them private, and the source's owner cannot release it around them. It sends nothing: pass consent_url to whoever speaks with that person, or an admin reads the email on approval_url and presses Send.",
@@ -3124,6 +3526,8 @@ export const TOOL_STATUS = {
3124
3526
  get_narrative_beats: "live (NCP project beats and candidate beats)",
3125
3527
  review_lookup: "live (video search needs the review token on the connector host)",
3126
3528
  review_versions: "live (carries the transcript's state)",
3529
+ get_screenwalk: "live (the Screenwalk Registry read as you: one registration by registry id, miadi-screenwalk:<id> or its page URL, in the registry's schema, or its brief or its moments; paged when large; says whether a review of its video exists)",
3530
+ list_screenwalks: "live (the registrations you may see, by the day they were registered, status, coverage, a name or a video)",
3127
3531
  review_transcript_status: "live (read-only: unknown, absent, acquiring, stored, held or failed, with stages, digest, readback, retry schedule, remedy and plain links)",
3128
3532
  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)",
3129
3533
  handoff_status: "live",
@@ -3154,6 +3558,7 @@ export const TOOL_STATUS = {
3154
3558
  request_session_steer: "live, contribute, write tier (one correction to a working agent, forwarded to its runtime; runs inside an approved run's steering grant, else one scoped human decision; get_capabilities.steering says whether the transport works now and which providers have an adapter)",
3155
3559
  revoke_session_steering: "live, contribute, write tier (stops a run's steering, or one steer not yet consumed)",
3156
3560
  request_review_operation: "live, contribute, needs_approval (create also stores the video's YouTube captions as the review's transcript, no model call)",
3561
+ request_screenwalk_review: "live, contribute, needs_approval for a create (relates a registered screenwalk to the existing review of its video, or prepares one create request a person approves; never a second review of one video)",
3157
3562
  request_participant_consent: "live, contribute (one question to a person on the record in a withheld video, never for a name only mentioned, answered on a link only they decide on; sends nothing)",
3158
3563
  request_screenwalk_reading: "live, contribute, needs_approval (host provider adapter required; stops at editorial decision)",
3159
3564
  request_reading_import: "live, contribute, needs_approval (exact public import; atomic service contract required)",
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.43";
1
+ export declare const VERSION = "0.1.44";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.1.43";
1
+ export const VERSION = "0.1.44";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@miadi/connector",
3
- "version": "0.1.43",
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.",
3
+ "version": "0.1.44",
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, registered screenwalks, episodes and circles and records observations, inquiries, handoffs and proposals with their name on each record.",
5
5
  "license": "MIT",
6
6
  "author": "Miadi",
7
7
  "type": "module",