@miadi/connector 0.1.40 → 0.1.42
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 +14 -3
- package/dist/comments.d.ts +80 -0
- package/dist/comments.js +119 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/record-view.d.ts +18 -0
- package/dist/record-view.js +45 -0
- package/dist/refs.d.ts +22 -0
- package/dist/refs.js +56 -0
- package/dist/reviews.d.ts +42 -0
- package/dist/reviews.js +111 -14
- package/dist/tools.js +211 -61
- package/dist/transcript-job.d.ts +2 -1
- package/dist/transcript-job.js +2 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +19 -3
package/README.md
CHANGED
|
@@ -22,17 +22,18 @@ Call `get_capabilities` first. It names the signed-in person, their Miadi API ti
|
|
|
22
22
|
|
|
23
23
|
| kind | tools |
|
|
24
24
|
|---|---|
|
|
25
|
-
| reads | `get_capabilities` `get_context` `list_circles` `get_circle` `list_sessions` `search_sessions` `get_session` `get_evidence` `read_episode_file` `get_evaluations` `get_narrative_beats` `review_lookup` `review_versions` `review_transcript_status` `handoff_status` `list_records` `get_run_result` `mission_status` `provider_capabilities` `mission_model_preflight` `search` `fetch` `list_research_artifacts` `read_research_artifact` |
|
|
26
|
-
| contributions | `ensure_review_transcript` `append_observation` `open_inquiry` `link_records` `propose_narrative_beat` `record_evaluation` `register_source_intent` `record_handoff` `update_handoff` `prepare_calendar_event` `save_research` |
|
|
25
|
+
| reads | `get_capabilities` `get_context` `list_circles` `get_circle` `list_sessions` `search_sessions` `get_session` `get_evidence` `list_episode_comments` `read_episode_file` `get_evaluations` `get_narrative_beats` `review_lookup` `review_versions` `review_transcript_status` `handoff_status` `list_records` `get_run_result` `mission_status` `provider_capabilities` `mission_model_preflight` `search` `fetch` `list_research_artifacts` `read_research_artifact` |
|
|
26
|
+
| contributions | `ensure_review_transcript` `append_observation` `comment_on_episode` `open_inquiry` `link_records` `propose_narrative_beat` `record_evaluation` `register_source_intent` `record_handoff` `update_handoff` `prepare_calendar_event` `save_research` |
|
|
27
27
|
| requests (approved by a person) | `propose_work` `propose_session_completion` `request_authorized_run` `request_session_steer` `revoke_session_steering` `request_review_operation` `request_deep_diver` `link_review_to_episode` `request_inquiry_episode` |
|
|
28
28
|
| decisions in the conversation | `show_decisions` (cards), `decide_request` (called by the card only) |
|
|
29
29
|
|
|
30
30
|
- **Reads** need Miadi's read tier and stay within it. A person Miadi gives no API tier reaches only `get_capabilities`. Sessions need the write tier, because a session's name and pane are operator data. For the same reason, below the write tier a record someone else made shows no session, working folder or seat, and no long bodies.
|
|
31
31
|
- **Episode files.** `get_evidence` lists an episode's files; each text file Miadi can preview carries a `read_ref` (`miadi-chronicle://<n>/<path>`). `read_episode_file` (or `fetch` with that ref) returns the file's whole UTF-8 text, read as the person through Miadi's file door, so Miadi's audience and room rules apply. The answer names the episode, the path, the content type, the byte count and the sha256, and `verified` says whether the text received hashes to what Miadi read. Only md, txt, yaml, yml and json files up to 512 KiB are read. A traversal, absolute, hidden or encoded path is refused before any URL is built. A longer text comes in pages cut on character boundaries: pass `page.next` back, and the joined pages hash to `sha256`. Other kinds answer `unsupported`, a file over the limit `too_large`, a missing one `not_found`, a ceremony note below the write gate `forbidden`.
|
|
32
|
+
- **Comments on an episode.** `comment_on_episode` publishes what a person says about an episode, in their name, optionally at a position of one of its media files (`media`, `at_seconds`, `until_seconds`). The comment is an observation that carries an `anchor`: the episode as Miadi resolved it, the media file's path and the position. `list_episode_comments` reads an episode's comments, by media file and by span of positions. Miadi's episode page shows them to a signed-in person who may open the episode. When the commenter sits in the episode's Root Circle, the comment is also said there as a turn, with their own token, and its record keeps the turn's id. The same `idempotency_key` returns the first comment and speaks no second turn. An episode's address is read under any written form: `miadi-chronicle://92` and `miadi-chronicle://092` name one episode in `get_context`, `get_evidence`, `list_records`, `handoff_status` and the comment tools. The comments Gérico's Space « Banque d'épisodes » published with `append_observation` (key `banque-episodes-…`) stay comments, and the media file and position are read from the sentence in their `intention` (jgwill/Miadi#1093).
|
|
32
33
|
- **One narrow grant.** A person with no Miadi API tier who holds `chronicle_foundations_read` (ticked by an admin under /admin → People → Additional permissions; admins hold it through their role) reaches `read_episode_file` for foundation documents only: `foundations/<topic>/*.md`, read through Miadi's `GET /api/chronicle/episodes/<ref>/foundations/<topic>/<file>.md`, which checks the permission on every read. Naming the episode alone lists them. Every other file and every other tool stays refused, and the permission gives no API tier. Unticking it refuses the next read. `get_capabilities` reports it under `foundation_read`, from Miadi's answer at that moment.
|
|
33
34
|
- **Contributions** need Miadi's read tier and the `miadi:contribute` scope, chosen at sign-in. A record is moved on (`update_handoff`) only by its author or the write tier, and a request's receipt comes only from its decision. They append a record to the ledger and change nothing else, except `save_research`: it saves a report on the inquiry shelf as a new folder (the Markdown exactly as given, owner and visibility recorded, private by default), opens the folder's inquiry issue, and commits and pushes the folder in the shelf's repository. A long report is sent in parts (`part`, `parts`, `upload_id`) and saved when the last part arrives; the answer returns its bytes, sha256 and first and last lines.
|
|
34
35
|
- **Sharing a record.** A record's author shares it with a talking circle or one person by linking from it: `link_records` with `from` the record's id, `to` `miadi-circle:<circle id>` or the person's id, and `relation` `shared_with`. `share_withdrawn`, from the same record to the same reader, ends the share. Only the author's links count, and `link_records` refuses a share from anyone else. The record's page (`/records/<id>`) admits its author, the people and members of the circles it is shared with (their circles read from Miadi on every read), and the read tier, and it says how the reader was admitted. Miadi's `/research` lists what is shared with a person under Shared.
|
|
35
|
-
- **Requests** append a record that waits for a decision. The answer gives an `approval_url`; Miadi's `/research` page offers the same decisions to a signed-in person with the write tier, and `show_decisions` shows them as cards inside the conversation (below). The person approves, approves with changes (their instructions are carried into what runs), sends it back for revision with instructions (`revision_requested`, nothing runs, `get_run_result` returns the instructions), or declines. Only the approval door runs a request, once, as that person; a second decision on the same request, at the same time or later, is refused:
|
|
36
|
+
- **Requests** append a record that waits for a decision. The answer gives an `approval_url`; Miadi's `/research` page offers the same decisions to a signed-in person with the write tier (and a review's page, `/reviews/<id>`, those on that review), and `show_decisions` shows them as cards inside the conversation (below). The person approves, approves with changes (their instructions are carried into what runs), sends it back for revision with instructions (`revision_requested`, nothing runs, `get_run_result` returns the instructions), or declines. Only the approval door runs a request, once, as that person; a second decision on the same request, at the same time or later, is refused:
|
|
36
37
|
- a run becomes a brief in the factory queue, which the intake delivers to a session;
|
|
37
38
|
- a work proposal starts its work the same way, as a brief written from the proposal;
|
|
38
39
|
- a review operation calls the review service;
|
|
@@ -191,6 +192,15 @@ Without that sign-in, or for a person without the write tier, the cards link to
|
|
|
191
192
|
|
|
192
193
|
Every record has a claim category: `observed`, `hypothesis`, `desired_future`, `fiction` or `verified_implementation`. Witnessed fact, envisioned features and fiction stay apart.
|
|
193
194
|
|
|
195
|
+
### The factory's review pages
|
|
196
|
+
|
|
197
|
+
Miadi's `/reviews` and `/reviews/<id>` use this package's own rules, so a person reads the same thing there as through the connector:
|
|
198
|
+
|
|
199
|
+
- `@miadi/connector/reviews`: `ReviewClient` (a review's public document, the list, the search and a review's state, with the service token kept on the server), the transcript-state rule, and which records name a review.
|
|
200
|
+
- `@miadi/connector/record-view`: what a record shows a reader below the write tier.
|
|
201
|
+
|
|
202
|
+
Asking from a review's page calls `request_review_operation`, `request_deep_diver`, `link_review_to_episode` or `ensure_review_transcript` on `/mcp`, server to server, with the person's own token as Bearer.
|
|
203
|
+
|
|
194
204
|
## Run it
|
|
195
205
|
|
|
196
206
|
```bash
|
|
@@ -263,6 +273,7 @@ The issues and the episode behind each part. `jgwill/Miadi` is a private reposit
|
|
|
263
273
|
| Codex on its requester's own choice | jgwill/Miadi#926 |
|
|
264
274
|
| the mission standard, and the local reviewer that will check S2 (A3) | jgwill/Miadi#939 |
|
|
265
275
|
| the tests the standard's bars were read from | Episode 564 (miadi-chronicle://564), `mission-draft-review-261105/` |
|
|
276
|
+
| the factory's review pages | jgwill/Miadi#961 |
|
|
266
277
|
| what a published README holds | jgwill/Miadi#685 |
|
|
267
278
|
|
|
268
279
|
On the factory host (gaia) the connector runs as the user service `miadi-connector.service`, installed from the Miadi repository's `scripts/ops/etc/miadi-connector.user.service`. That host's `/etc/miadi/miadi.env` sets `MIADI_CONNECTOR_PUBLIC_URL`, and the Cloudflare tunnel `gaia` serves that address from the loopback port. Its reading runtime is `packages/connector/scripts/host-reading-runtime.mjs`.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The comments of an episode, read from the ledger (jgwill/Miadi#1093; P1 of
|
|
3
|
+
* rispecs/episode-participants/SPEC.md). One read model for the connector's
|
|
4
|
+
* tools and for Miadi's pages, so both answer the same comments.
|
|
5
|
+
*
|
|
6
|
+
* A comment is an observation that carries an anchor (`body.anchor`, written
|
|
7
|
+
* by comment_on_episode): the episode, and optionally a media file and a
|
|
8
|
+
* position in it. The first comments were published before the anchor existed,
|
|
9
|
+
* by Gérico's Space « Banque d'épisodes », with append_observation: their key
|
|
10
|
+
* starts with `banque-episodes-` and the media file and position are in the
|
|
11
|
+
* sentence of their `intention`. They stay comments, and that one sentence is
|
|
12
|
+
* read for them. Nothing is read from a comment's own text. The other
|
|
13
|
+
* observations that cite an episode are reports, and are not comments.
|
|
14
|
+
*/
|
|
15
|
+
import type { ConnectorRecord } from "./records.js";
|
|
16
|
+
export interface CommentAnchor {
|
|
17
|
+
/** The episode as the connector resolved it when the comment was published; null on a Space's first comments. */
|
|
18
|
+
episode: {
|
|
19
|
+
folder: string | null;
|
|
20
|
+
number: number | null;
|
|
21
|
+
} | null;
|
|
22
|
+
/** The media file: its path inside the episode, or the bare name a Space stated. Null for the whole episode. */
|
|
23
|
+
media: string | null;
|
|
24
|
+
at_seconds: number | null;
|
|
25
|
+
until_seconds: number | null;
|
|
26
|
+
/** `fields`: the record carries the anchor. `intention`: read from the sentence the Space wrote. */
|
|
27
|
+
stated_in: "fields" | "intention";
|
|
28
|
+
}
|
|
29
|
+
/** The turn a comment also became in the episode's Root Circle, when its author sat there. */
|
|
30
|
+
export interface CircleTurn {
|
|
31
|
+
ceremony_id: string;
|
|
32
|
+
beat_id: string;
|
|
33
|
+
circle_id?: string;
|
|
34
|
+
circle_name?: string;
|
|
35
|
+
at?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface EpisodeComment {
|
|
38
|
+
id: string;
|
|
39
|
+
/** When it was published. */
|
|
40
|
+
at: string;
|
|
41
|
+
text: string;
|
|
42
|
+
author: {
|
|
43
|
+
person_id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
};
|
|
46
|
+
/** The client it came through, when that client registered a name. */
|
|
47
|
+
client: string | null;
|
|
48
|
+
claim_category: string | null;
|
|
49
|
+
intention: string | null;
|
|
50
|
+
anchor: CommentAnchor | null;
|
|
51
|
+
circle_turn: CircleTurn | null;
|
|
52
|
+
}
|
|
53
|
+
export interface CommentEpisode {
|
|
54
|
+
number?: number | null;
|
|
55
|
+
folder?: string | null;
|
|
56
|
+
/** Another folder carries the same number: a comment that names the number alone is then shown on neither. */
|
|
57
|
+
number_shared?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface CommentFilter {
|
|
60
|
+
media?: string;
|
|
61
|
+
from_seconds?: number;
|
|
62
|
+
to_seconds?: number;
|
|
63
|
+
person_id?: string;
|
|
64
|
+
}
|
|
65
|
+
/** The key Gérico's Space « Banque d'épisodes » gives a comment it publishes with append_observation. */
|
|
66
|
+
export declare const SPACE_COMMENT_KEY: RegExp;
|
|
67
|
+
/** Where a comment points, from its fields, else from the Space's sentence; null for the whole episode. */
|
|
68
|
+
export declare function anchorOf(r: ConnectorRecord): CommentAnchor | null;
|
|
69
|
+
export declare function isComment(r: ConnectorRecord): boolean;
|
|
70
|
+
export declare function commentOf(r: ConnectorRecord): EpisodeComment;
|
|
71
|
+
/** A listed path and a bare file name agree when the name is the path's last segment. */
|
|
72
|
+
export declare function sameMedia(a: string, b: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The comments on one episode, from the folded ledger (`current()`), in order
|
|
75
|
+
* of media file, then position, then time. A comment on the whole episode
|
|
76
|
+
* comes before the comments at a position.
|
|
77
|
+
*/
|
|
78
|
+
export declare function commentsOf(records: readonly ConnectorRecord[], episode: CommentEpisode, filter?: CommentFilter): EpisodeComment[];
|
|
79
|
+
/** 105 → "1:45", 3725 → "1:02:05". */
|
|
80
|
+
export declare function formatPosition(seconds: number): string;
|
package/dist/comments.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { parseChronicleAddress } from "./refs.js";
|
|
2
|
+
/** The key Gérico's Space « Banque d'épisodes » gives a comment it publishes with append_observation. */
|
|
3
|
+
export const SPACE_COMMENT_KEY = /^banque-episodes-/;
|
|
4
|
+
/** The sentence that Space writes in `intention`: sur « <file> », à <n> s du média. */
|
|
5
|
+
const SPACE_SENTENCE = /sur\s+«[\s\u00a0\u202f]*(.+?)[\s\u00a0\u202f]*»,?\s+à\s+(\d+(?:[.,]\d+)?)\s*s\b/;
|
|
6
|
+
const finite = (v) => (typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : null);
|
|
7
|
+
const text = (v) => (typeof v === "string" && v.trim() ? v.trim() : null);
|
|
8
|
+
/** Where a comment points, from its fields, else from the Space's sentence; null for the whole episode. */
|
|
9
|
+
export function anchorOf(r) {
|
|
10
|
+
const a = r.body.anchor;
|
|
11
|
+
if (a && typeof a === "object") {
|
|
12
|
+
const anchor = a;
|
|
13
|
+
const episode = anchor.episode && typeof anchor.episode === "object" ? anchor.episode : null;
|
|
14
|
+
const at = finite(anchor.at_seconds);
|
|
15
|
+
const until = finite(anchor.until_seconds);
|
|
16
|
+
return {
|
|
17
|
+
episode: episode ? { folder: text(episode.folder), number: finite(episode.number) } : null,
|
|
18
|
+
media: text(anchor.media),
|
|
19
|
+
at_seconds: at,
|
|
20
|
+
until_seconds: at !== null && until !== null && until > at ? until : null,
|
|
21
|
+
stated_in: "fields",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (!SPACE_COMMENT_KEY.test(r.idempotency_key ?? ""))
|
|
25
|
+
return null;
|
|
26
|
+
const said = SPACE_SENTENCE.exec(r.intention ?? "");
|
|
27
|
+
if (!said)
|
|
28
|
+
return null;
|
|
29
|
+
return { episode: null, media: said[1].trim(), at_seconds: Number(said[2].replace(",", ".")), until_seconds: null, stated_in: "intention" };
|
|
30
|
+
}
|
|
31
|
+
export function isComment(r) {
|
|
32
|
+
if (r.kind !== "observation" || r.state === "withdrawn")
|
|
33
|
+
return false;
|
|
34
|
+
const body = r.body;
|
|
35
|
+
if (body.reading || !text(body.text))
|
|
36
|
+
return false;
|
|
37
|
+
return Boolean(body.anchor && typeof body.anchor === "object") || SPACE_COMMENT_KEY.test(r.idempotency_key ?? "");
|
|
38
|
+
}
|
|
39
|
+
export function commentOf(r) {
|
|
40
|
+
const turn = r.completion_receipt?.circle_turn;
|
|
41
|
+
return {
|
|
42
|
+
id: r.id,
|
|
43
|
+
at: r.created_at,
|
|
44
|
+
text: String(r.body.text ?? ""),
|
|
45
|
+
author: { person_id: r.actor.person_id, name: r.actor.name },
|
|
46
|
+
client: r.actor.client_name ?? null,
|
|
47
|
+
claim_category: r.claim_category ?? null,
|
|
48
|
+
intention: r.intention ?? null,
|
|
49
|
+
anchor: anchorOf(r),
|
|
50
|
+
circle_turn: turn && typeof turn.ceremony_id === "string" && typeof turn.beat_id === "string" ? turn : null,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** A listed path and a bare file name agree when the name is the path's last segment. */
|
|
54
|
+
export function sameMedia(a, b) {
|
|
55
|
+
if (a === b)
|
|
56
|
+
return true;
|
|
57
|
+
const last = (p) => p.slice(p.lastIndexOf("/") + 1);
|
|
58
|
+
return (!a.includes("/") || !b.includes("/")) && last(a) === last(b);
|
|
59
|
+
}
|
|
60
|
+
function namesEpisode(r, anchor, episode) {
|
|
61
|
+
const byNumber = (n) => !episode.number_shared && n !== null && episode.number !== null && episode.number !== undefined && n === episode.number;
|
|
62
|
+
if (anchor?.episode?.folder && episode.folder)
|
|
63
|
+
return anchor.episode.folder === episode.folder;
|
|
64
|
+
if (anchor?.episode && byNumber(anchor.episode.number))
|
|
65
|
+
return true;
|
|
66
|
+
for (const ref of r.refs) {
|
|
67
|
+
const address = parseChronicleAddress(ref);
|
|
68
|
+
if (!address)
|
|
69
|
+
continue;
|
|
70
|
+
if (address.folder && episode.folder) {
|
|
71
|
+
if (address.folder === episode.folder)
|
|
72
|
+
return true;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (byNumber(address.number))
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The comments on one episode, from the folded ledger (`current()`), in order
|
|
82
|
+
* of media file, then position, then time. A comment on the whole episode
|
|
83
|
+
* comes before the comments at a position.
|
|
84
|
+
*/
|
|
85
|
+
export function commentsOf(records, episode, filter = {}) {
|
|
86
|
+
const out = [];
|
|
87
|
+
for (const r of records) {
|
|
88
|
+
if (!isComment(r))
|
|
89
|
+
continue;
|
|
90
|
+
const anchor = anchorOf(r);
|
|
91
|
+
if (!namesEpisode(r, anchor, episode))
|
|
92
|
+
continue;
|
|
93
|
+
if (filter.person_id && r.actor.person_id !== filter.person_id)
|
|
94
|
+
continue;
|
|
95
|
+
if (filter.media && !(anchor?.media && sameMedia(anchor.media, filter.media)))
|
|
96
|
+
continue;
|
|
97
|
+
if (filter.from_seconds !== undefined && !(anchor?.at_seconds != null && anchor.at_seconds >= filter.from_seconds))
|
|
98
|
+
continue;
|
|
99
|
+
if (filter.to_seconds !== undefined && !(anchor?.at_seconds != null && anchor.at_seconds <= filter.to_seconds))
|
|
100
|
+
continue;
|
|
101
|
+
out.push(commentOf(r));
|
|
102
|
+
}
|
|
103
|
+
// By the file's own name, so a Space's bare name and the listed path of one file read as one sequence.
|
|
104
|
+
const name = (media) => media.slice(media.lastIndexOf("/") + 1);
|
|
105
|
+
const key = (c) => [c.anchor?.media ? name(c.anchor.media) : "", c.anchor?.at_seconds ?? -1];
|
|
106
|
+
return out.sort((a, b) => {
|
|
107
|
+
const [am, ap] = key(a);
|
|
108
|
+
const [bm, bp] = key(b);
|
|
109
|
+
return am < bm ? -1 : am > bm ? 1 : ap - bp || (a.at < b.at ? -1 : a.at > b.at ? 1 : 0);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/** 105 → "1:45", 3725 → "1:02:05". */
|
|
113
|
+
export function formatPosition(seconds) {
|
|
114
|
+
const whole = Math.floor(seconds);
|
|
115
|
+
const h = Math.floor(whole / 3600);
|
|
116
|
+
const m = Math.floor((whole % 3600) / 60);
|
|
117
|
+
const s = whole % 60;
|
|
118
|
+
return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}` : `${m}:${String(s).padStart(2, "0")}`;
|
|
119
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { identifyThroughMiadi, MiadiUnavailable, type MiadiPerson, type ApiTier
|
|
|
4
4
|
export { MiadiOAuthProvider, SCOPES, SCOPE_READ, SCOPE_CONTRIBUTE, type Person } from "./oauth.js";
|
|
5
5
|
export { CIRCLES, CIRCLE_IDS, CLAIM_CATEGORIES, DOMAINS, HANDOFF_STATES, RECORD_KINDS, current, type ConnectorRecord, type CircleId, type ClaimCategory, type RecordKind, } from "./records.js";
|
|
6
6
|
export { TOOL_STATUS, githubGetter, steeringTransport } from "./tools.js";
|
|
7
|
+
export { cites, parseChronicleAddress, refMatcher, sameRef, type ChronicleAddress } from "./refs.js";
|
|
8
|
+
export { SPACE_COMMENT_KEY, anchorOf, commentOf, commentsOf, formatPosition, isComment, sameMedia, type CircleTurn, type CommentAnchor, type CommentEpisode, type CommentFilter, type EpisodeComment, } from "./comments.js";
|
|
7
9
|
export { factoryLedgerPath, readFactoryReceipts, receiptsForRecord, recordsForSession, type FactoryReceipt } from "./factory-receipt.js";
|
|
8
10
|
export { classifyOutput, missionResult, type GithubAnswer, type GithubGet, type MissionOutput, type MissionResult, type OutputCheck, type ResultSubmission, } from "./mission-result.js";
|
|
9
11
|
export { runBrief, readQueueState } from "./approve.js";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,8 @@ export { identifyThroughMiadi, MiadiUnavailable } from "./people.js";
|
|
|
4
4
|
export { MiadiOAuthProvider, SCOPES, SCOPE_READ, SCOPE_CONTRIBUTE } from "./oauth.js";
|
|
5
5
|
export { CIRCLES, CIRCLE_IDS, CLAIM_CATEGORIES, DOMAINS, HANDOFF_STATES, RECORD_KINDS, current, } from "./records.js";
|
|
6
6
|
export { TOOL_STATUS, githubGetter, steeringTransport } from "./tools.js";
|
|
7
|
+
export { cites, parseChronicleAddress, refMatcher, sameRef } from "./refs.js";
|
|
8
|
+
export { SPACE_COMMENT_KEY, anchorOf, commentOf, commentsOf, formatPosition, isComment, sameMedia, } from "./comments.js";
|
|
7
9
|
export { factoryLedgerPath, readFactoryReceipts, receiptsForRecord, recordsForSession } from "./factory-receipt.js";
|
|
8
10
|
export { classifyOutput, missionResult, } from "./mission-result.js";
|
|
9
11
|
export { runBrief, readQueueState } from "./approve.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a ledger record shows to a signed-in reader, the rule `list_records`, `fetch` and the factory's pages read by.
|
|
3
|
+
*
|
|
4
|
+
* A private reading (its drafts and its completion text) is for its source's owner and the write tier. Below the write
|
|
5
|
+
* tier, someone else's record keeps its story and loses the operator details a session view also withholds (session,
|
|
6
|
+
* cwd, the seat a brief went to) and its long bodies.
|
|
7
|
+
*
|
|
8
|
+
* Exported as `@miadi/connector/record-view` (jgwill/Miadi#961).
|
|
9
|
+
*/
|
|
10
|
+
import type { ConnectorRecord } from "./records.js";
|
|
11
|
+
export interface RecordViewer {
|
|
12
|
+
id: string;
|
|
13
|
+
api_tier?: string | null;
|
|
14
|
+
}
|
|
15
|
+
/** One record as this viewer may see it. The write tier and the record's author see it whole. */
|
|
16
|
+
export declare function redactRecord(r: ConnectorRecord, viewer: RecordViewer | undefined): ConnectorRecord;
|
|
17
|
+
/** Folded records (`current()`) as this viewer may read them: private readings left out, the rest redacted. */
|
|
18
|
+
export declare function recordsSeenBy(records: ConnectorRecord[], viewer: RecordViewer | undefined): ConnectorRecord[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a ledger record shows to a signed-in reader, the rule `list_records`, `fetch` and the factory's pages read by.
|
|
3
|
+
*
|
|
4
|
+
* A private reading (its drafts and its completion text) is for its source's owner and the write tier. Below the write
|
|
5
|
+
* tier, someone else's record keeps its story and loses the operator details a session view also withholds (session,
|
|
6
|
+
* cwd, the seat a brief went to) and its long bodies.
|
|
7
|
+
*
|
|
8
|
+
* Exported as `@miadi/connector/record-view` (jgwill/Miadi#961).
|
|
9
|
+
*/
|
|
10
|
+
import { canReadReading, readingOwner } from "./reading/privacy.js";
|
|
11
|
+
/** One record as this viewer may see it. The write tier and the record's author see it whole. */
|
|
12
|
+
export function redactRecord(r, viewer) {
|
|
13
|
+
if (!viewer || viewer.api_tier === "write" || r.actor.person_id === viewer.id)
|
|
14
|
+
return r;
|
|
15
|
+
if (r.body.reading && r.kind === "observation") {
|
|
16
|
+
const stage = r.body.reading;
|
|
17
|
+
return { ...r, refs: [], evidence_refs: [], body: { reading: { workflow_id: stage.workflow_id, stage: stage.stage, status: stage.status, sha256: stage.sha256, visibility: "source_owner_or_factory_operator" } } };
|
|
18
|
+
}
|
|
19
|
+
const body = { ...r.body };
|
|
20
|
+
// Grants contain source rights and locators; only the owner and operators inspect them.
|
|
21
|
+
if (body.reading)
|
|
22
|
+
body.reading = { visibility: "source_owner_or_factory_operator" };
|
|
23
|
+
// A steer's binding, pane, target and artifact path name the seat as the session does (#922 R2).
|
|
24
|
+
for (const k of ["session", "cwd", "session_id", "binding", "pane"])
|
|
25
|
+
delete body[k];
|
|
26
|
+
for (const k of ["markdown", "transcript"])
|
|
27
|
+
if (typeof body[k] === "string")
|
|
28
|
+
body[k] = `${body[k].length} chars`;
|
|
29
|
+
const receipt = r.completion_receipt ? { ...r.completion_receipt } : undefined;
|
|
30
|
+
if (receipt)
|
|
31
|
+
for (const k of ["to", "file", "session_id", "target", "artifact", "model_routing"])
|
|
32
|
+
delete receipt[k];
|
|
33
|
+
// A steer's message names its target pane.
|
|
34
|
+
if (receipt && r.kind === "session_steer_request")
|
|
35
|
+
delete receipt.message;
|
|
36
|
+
return { ...r, body, ...(receipt ? { completion_receipt: receipt } : {}) };
|
|
37
|
+
}
|
|
38
|
+
/** Folded records (`current()`) as this viewer may read them: private readings left out, the rest redacted. */
|
|
39
|
+
export function recordsSeenBy(records, viewer) {
|
|
40
|
+
// Completion results can contain exact drafts too. Their parent mission is hidden as well, so no reader of the
|
|
41
|
+
// ledger can rehydrate it from trusted records.
|
|
42
|
+
return records
|
|
43
|
+
.filter((r) => !viewer || canReadReading(r, records, viewer))
|
|
44
|
+
.map((r) => (readingOwner(r, records) === viewer?.id ? r : redactRecord(r, viewer)));
|
|
45
|
+
}
|
package/dist/refs.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ChronicleAddress {
|
|
2
|
+
/** The episode's number: from a numeric form, or from the folder's own name. */
|
|
3
|
+
number: number | null;
|
|
4
|
+
/** The folder, when the address names the episode by it. */
|
|
5
|
+
folder: string | null;
|
|
6
|
+
/** What follows the episode (a file path, a query, a fragment), as written. */
|
|
7
|
+
rest: string;
|
|
8
|
+
}
|
|
9
|
+
/** A chronicle address as the episode it names and what follows; null for any other reference. */
|
|
10
|
+
export declare function parseChronicleAddress(ref: string): ChronicleAddress | null;
|
|
11
|
+
/**
|
|
12
|
+
* A test for "this reference names the same thing as `ref`". Two folders are
|
|
13
|
+
* compared as folders, because numbers collide and the folder is the key.
|
|
14
|
+
* A number and a folder agree when the folder carries that number.
|
|
15
|
+
*/
|
|
16
|
+
export declare function refMatcher(ref: string): (other: string) => boolean;
|
|
17
|
+
export declare function sameRef(a: string, b: string): boolean;
|
|
18
|
+
/** True when a record cites `ref`, in what it is about or in its evidence. */
|
|
19
|
+
export declare function cites(record: {
|
|
20
|
+
refs: readonly string[];
|
|
21
|
+
evidence_refs: readonly string[];
|
|
22
|
+
}, ref: string | ((other: string) => boolean)): boolean;
|
package/dist/refs.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One comparison of references, for every read (jgwill/Miadi#1093; W1 and C1 of
|
|
3
|
+
* rispecs/episode-participants/SPEC.md).
|
|
4
|
+
*
|
|
5
|
+
* The ledger keeps a reference as its author wrote it, and one episode has
|
|
6
|
+
* several written forms: `miadi-chronicle://92`, `miadi-chronicle://092`,
|
|
7
|
+
* `miadi-chronicle:92`, `chronicle:<folder>`. Miadi reads them as one episode
|
|
8
|
+
* (`matchSegment` in @miadi/inquiry-weave's chronicle-dsl). A read here does the
|
|
9
|
+
* same: a chronicle address is compared by the episode it names and by what
|
|
10
|
+
* follows the episode, never by its spelling. Every other reference is
|
|
11
|
+
* compared as written. Nothing in the ledger is rewritten.
|
|
12
|
+
*/
|
|
13
|
+
import { episodeNumberOf } from "./episode-files.js";
|
|
14
|
+
const CHRONICLE = /^(?:miadi-chronicle|chronicle):(?:\/\/)?([^/?#\s]+)\/?(\S*)$/i;
|
|
15
|
+
/** The numeric forms Miadi's file door takes: 92, 092, ep92, episode-092. */
|
|
16
|
+
const NUMBERED = /^(?:ep(?:isode)?[-_]?)?0*(\d{1,5})$/i;
|
|
17
|
+
/** A chronicle address as the episode it names and what follows; null for any other reference. */
|
|
18
|
+
export function parseChronicleAddress(ref) {
|
|
19
|
+
const m = CHRONICLE.exec(ref.trim());
|
|
20
|
+
if (!m)
|
|
21
|
+
return null;
|
|
22
|
+
const head = m[1];
|
|
23
|
+
const rest = m[2].replace(/\/$/, "");
|
|
24
|
+
const numbered = NUMBERED.exec(head);
|
|
25
|
+
if (numbered)
|
|
26
|
+
return { number: Number.parseInt(numbered[1], 10), folder: null, rest };
|
|
27
|
+
return { number: episodeNumberOf(head), folder: head, rest };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A test for "this reference names the same thing as `ref`". Two folders are
|
|
31
|
+
* compared as folders, because numbers collide and the folder is the key.
|
|
32
|
+
* A number and a folder agree when the folder carries that number.
|
|
33
|
+
*/
|
|
34
|
+
export function refMatcher(ref) {
|
|
35
|
+
const wanted = parseChronicleAddress(ref);
|
|
36
|
+
if (!wanted)
|
|
37
|
+
return (other) => other === ref;
|
|
38
|
+
return (other) => {
|
|
39
|
+
if (other === ref)
|
|
40
|
+
return true;
|
|
41
|
+
const found = parseChronicleAddress(other);
|
|
42
|
+
if (!found || found.rest !== wanted.rest)
|
|
43
|
+
return false;
|
|
44
|
+
if (wanted.folder && found.folder)
|
|
45
|
+
return wanted.folder === found.folder;
|
|
46
|
+
return wanted.number !== null && wanted.number === found.number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function sameRef(a, b) {
|
|
50
|
+
return refMatcher(a)(b);
|
|
51
|
+
}
|
|
52
|
+
/** True when a record cites `ref`, in what it is about or in its evidence. */
|
|
53
|
+
export function cites(record, ref) {
|
|
54
|
+
const is = typeof ref === "string" ? refMatcher(ref) : ref;
|
|
55
|
+
return record.refs.some(is) || record.evidence_refs.some(is);
|
|
56
|
+
}
|
package/dist/reviews.d.ts
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
|
+
import type { ConnectorRecord } from "./records.js";
|
|
1
2
|
export declare function reviewToken(env?: NodeJS.ProcessEnv): string | undefined;
|
|
2
3
|
export declare function videoIdOf(input: string): string | null;
|
|
3
4
|
export declare function reviewIdOf(input: string): string | null;
|
|
5
|
+
/** Where a review's transcript stands (jgwill/Miadi#995). */
|
|
6
|
+
export type TranscriptState = "unknown" | "absent" | "acquiring" | "stored" | "failed" | "held";
|
|
7
|
+
/**
|
|
8
|
+
* A transcript's state from the review service and the connector's job for the review: what the service holds wins;
|
|
9
|
+
* a job that stored words the service no longer holds reads as absent; an unreachable service leaves what the job
|
|
10
|
+
* says, else unknown.
|
|
11
|
+
*/
|
|
12
|
+
export declare function transcriptStateOf(o: {
|
|
13
|
+
reachable: boolean;
|
|
14
|
+
has_transcript?: boolean;
|
|
15
|
+
job?: {
|
|
16
|
+
state: TranscriptState;
|
|
17
|
+
};
|
|
18
|
+
}): TranscriptState;
|
|
19
|
+
/** Each review's transcript job as the ledger holds it, from folded records (`current()`): one job per review. */
|
|
20
|
+
export declare function transcriptJobsOf(records: readonly ConnectorRecord[]): Map<string, {
|
|
21
|
+
id: string;
|
|
22
|
+
state: TranscriptState;
|
|
23
|
+
failure?: {
|
|
24
|
+
message?: string;
|
|
25
|
+
remedy?: string;
|
|
26
|
+
};
|
|
27
|
+
next_attempt_at?: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a folded record names a review: in what it cites, in its body, in the receipt of the operation that made or
|
|
31
|
+
* changed it, or, for a source and for a request made before the review existed, by its video.
|
|
32
|
+
*/
|
|
33
|
+
export declare function namesReview(record: ConnectorRecord, review: {
|
|
34
|
+
id: string;
|
|
35
|
+
video_id?: string | null;
|
|
36
|
+
}): boolean;
|
|
4
37
|
export interface ReviewSummary {
|
|
5
38
|
review_id: string;
|
|
6
39
|
ref: string;
|
|
@@ -19,6 +52,15 @@ export declare class ReviewClient {
|
|
|
19
52
|
private readonly fetchImpl;
|
|
20
53
|
constructor(baseUrl: string, token: string | undefined, fetchImpl?: typeof fetch);
|
|
21
54
|
get canSearch(): boolean;
|
|
55
|
+
/** Every review the service holds, read 100 at a time (`GET /api/reviews`), as the service orders them. */
|
|
56
|
+
list(max?: number): Promise<any[]>;
|
|
57
|
+
/**
|
|
58
|
+
* `GET /api/reviews/<id>?version=<n>`: one review with its kind, Deep Diver and workflow state and its
|
|
59
|
+
* transcript's metadata (`has_transcript`, digest, length, provenance), and that one version. Without a
|
|
60
|
+
* version, every version comes with it. Null on 404.
|
|
61
|
+
*/
|
|
62
|
+
state(reviewId: string, version?: number): Promise<any | null>;
|
|
63
|
+
private authed;
|
|
22
64
|
/** `/review/<id>/json`, optionally pinned to a version. Null on 404. */
|
|
23
65
|
get(reviewId: string, version?: number): Promise<any | null>;
|
|
24
66
|
search(q: string, limit?: number): Promise<any[]>;
|
package/dist/reviews.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Read access to the Miadi Review service. Published reviews are public
|
|
3
|
-
* (`/review/<id>/json`); search by keyword or video id
|
|
4
|
-
* token, read the same way the
|
|
5
|
-
* environment first, then the one
|
|
3
|
+
* (`/review/<id>/json`); listing, search by keyword or video id and a review's
|
|
4
|
+
* transcript metadata need the service token, read the same way the
|
|
5
|
+
* miadi-review skill reads it: the process environment first, then the one
|
|
6
|
+
* literal key in ${MIADI_REVIEW_ENV_FILE:-~/.env}.
|
|
6
7
|
*
|
|
7
8
|
* This client never creates, versions, deletes or marks a review: those are
|
|
8
9
|
* requests a person approves (see the review_* request tools).
|
|
10
|
+
*
|
|
11
|
+
* Exported as `@miadi/connector/reviews`, so the factory's `/reviews` pages read
|
|
12
|
+
* reviews the way the connector does (jgwill/Miadi#961).
|
|
9
13
|
*/
|
|
10
14
|
import { existsSync, readFileSync } from "node:fs";
|
|
11
15
|
import { homedir } from "node:os";
|
|
@@ -16,9 +20,10 @@ export function reviewToken(env = process.env) {
|
|
|
16
20
|
if (env.MIADI_REVIEW_TOKEN)
|
|
17
21
|
return env.MIADI_REVIEW_TOKEN;
|
|
18
22
|
const file = env.MIADI_REVIEW_ENV_FILE || join(homedir(), ".env");
|
|
19
|
-
|
|
23
|
+
// The file is named by the host, outside any project: a bundler must not trace it (jgwill/Miadi#961).
|
|
24
|
+
if (!existsSync(/* turbopackIgnore: true */ file))
|
|
20
25
|
return undefined;
|
|
21
|
-
for (const line of readFileSync(file, "utf8").split("\n")) {
|
|
26
|
+
for (const line of readFileSync(/* turbopackIgnore: true */ file, "utf8").split("\n")) {
|
|
22
27
|
const m = line.match(/^\s*(?:export\s+)?MIADI_REVIEW_TOKEN\s*=\s*(.*)\s*$/);
|
|
23
28
|
if (m)
|
|
24
29
|
return m[1].replace(/^['"]|['"]$/g, "") || undefined;
|
|
@@ -47,6 +52,64 @@ export function reviewIdOf(input) {
|
|
|
47
52
|
const id = fromUrl ? fromUrl[1] : s;
|
|
48
53
|
return UUID.test(id) ? id.toLowerCase() : null;
|
|
49
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* A transcript's state from the review service and the connector's job for the review: what the service holds wins;
|
|
57
|
+
* a job that stored words the service no longer holds reads as absent; an unreachable service leaves what the job
|
|
58
|
+
* says, else unknown.
|
|
59
|
+
*/
|
|
60
|
+
export function transcriptStateOf(o) {
|
|
61
|
+
if (o.reachable && o.has_transcript)
|
|
62
|
+
return "stored";
|
|
63
|
+
if (o.job && o.job.state !== "stored")
|
|
64
|
+
return o.job.state;
|
|
65
|
+
if (o.job && o.reachable)
|
|
66
|
+
return "absent";
|
|
67
|
+
return o.reachable ? "absent" : (o.job?.state ?? "unknown");
|
|
68
|
+
}
|
|
69
|
+
/** Each review's transcript job as the ledger holds it, from folded records (`current()`): one job per review. */
|
|
70
|
+
export function transcriptJobsOf(records) {
|
|
71
|
+
const out = new Map();
|
|
72
|
+
for (const r of records) {
|
|
73
|
+
if (r.kind !== "transcript_job")
|
|
74
|
+
continue;
|
|
75
|
+
const receipt = r.completion_receipt?.transcript;
|
|
76
|
+
if (!receipt?.review_id || !receipt.state)
|
|
77
|
+
continue;
|
|
78
|
+
out.set(receipt.review_id, { id: r.id, state: receipt.state, ...(receipt.failure ? { failure: receipt.failure } : {}), ...(receipt.next_attempt_at ? { next_attempt_at: receipt.next_attempt_at } : {}) });
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
const REVIEW_REF = /^(?:miadi-)?review:(?:\/\/)?([0-9a-f-]{36})(?:[/?#].*)?$|\/review\/([0-9a-f-]{36})(?:[/?#].*)?$/i;
|
|
83
|
+
/** The record kinds that name a review by its video: a source, and a request made before the review existed. */
|
|
84
|
+
const BY_VIDEO = new Set(["source_intent", "review_operation_request", "participant_consent_request"]);
|
|
85
|
+
/** Records about the connector's own running, which a review's page shows another way or not at all. */
|
|
86
|
+
const NOT_ABOUT_A_REVIEW = new Set(["transcript_job", "provider_choice", "provider_policy"]);
|
|
87
|
+
/**
|
|
88
|
+
* Whether a folded record names a review: in what it cites, in its body, in the receipt of the operation that made or
|
|
89
|
+
* changed it, or, for a source and for a request made before the review existed, by its video.
|
|
90
|
+
*/
|
|
91
|
+
export function namesReview(record, review) {
|
|
92
|
+
if (NOT_ABOUT_A_REVIEW.has(record.kind))
|
|
93
|
+
return false;
|
|
94
|
+
const id = review.id.toLowerCase();
|
|
95
|
+
const named = (value) => {
|
|
96
|
+
if (typeof value !== "string")
|
|
97
|
+
return false;
|
|
98
|
+
const m = REVIEW_REF.exec(value.trim());
|
|
99
|
+
return (m?.[1] ?? m?.[2])?.toLowerCase() === id;
|
|
100
|
+
};
|
|
101
|
+
if (record.refs.some(named) || record.evidence_refs.some(named))
|
|
102
|
+
return true;
|
|
103
|
+
const body = record.body;
|
|
104
|
+
if (typeof body.review_id === "string" && body.review_id.toLowerCase() === id)
|
|
105
|
+
return true;
|
|
106
|
+
if (named(body.from) || named(body.to) || named(body.subject_id))
|
|
107
|
+
return true;
|
|
108
|
+
const answered = record.completion_receipt?.response?.id;
|
|
109
|
+
if (record.kind === "review_operation_request" && typeof answered === "string" && answered.toLowerCase() === id)
|
|
110
|
+
return true;
|
|
111
|
+
return Boolean(review.video_id) && BY_VIDEO.has(record.kind) && body.video_id === review.video_id;
|
|
112
|
+
}
|
|
50
113
|
export class ReviewClient {
|
|
51
114
|
baseUrl;
|
|
52
115
|
token;
|
|
@@ -59,6 +122,48 @@ export class ReviewClient {
|
|
|
59
122
|
get canSearch() {
|
|
60
123
|
return Boolean(this.token);
|
|
61
124
|
}
|
|
125
|
+
/** Every review the service holds, read 100 at a time (`GET /api/reviews`), as the service orders them. */
|
|
126
|
+
async list(max = 5000) {
|
|
127
|
+
const out = [];
|
|
128
|
+
const seen = new Set();
|
|
129
|
+
for (let offset = 0; offset < max; offset += 100) {
|
|
130
|
+
const body = await this.authed(`/api/reviews?${new URLSearchParams({ limit: "100", offset: String(offset) })}`, "review list");
|
|
131
|
+
const rows = body?.reviews ?? [];
|
|
132
|
+
// A review that moved between two pages is listed once.
|
|
133
|
+
for (const row of rows) {
|
|
134
|
+
if (typeof row?.id !== "string" || seen.has(row.id))
|
|
135
|
+
continue;
|
|
136
|
+
seen.add(row.id);
|
|
137
|
+
out.push(row);
|
|
138
|
+
}
|
|
139
|
+
if (rows.length < 100)
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* `GET /api/reviews/<id>?version=<n>`: one review with its kind, Deep Diver and workflow state and its
|
|
146
|
+
* transcript's metadata (`has_transcript`, digest, length, provenance), and that one version. Without a
|
|
147
|
+
* version, every version comes with it. Null on 404.
|
|
148
|
+
*/
|
|
149
|
+
async state(reviewId, version) {
|
|
150
|
+
const q = version ? `?version=${version}` : "";
|
|
151
|
+
return this.authed(`/api/reviews/${reviewId}${q}`, "review state", true);
|
|
152
|
+
}
|
|
153
|
+
async authed(path, what, nullOn404 = false) {
|
|
154
|
+
if (!this.token)
|
|
155
|
+
throw new Error("MIADI_REVIEW_TOKEN is not configured on this host");
|
|
156
|
+
const res = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
157
|
+
headers: { accept: "application/json", authorization: `Bearer ${this.token}` },
|
|
158
|
+
signal: AbortSignal.timeout(15_000),
|
|
159
|
+
cache: "no-store",
|
|
160
|
+
});
|
|
161
|
+
if (nullOn404 && res.status === 404)
|
|
162
|
+
return null;
|
|
163
|
+
if (!res.ok)
|
|
164
|
+
throw new Error(`${what} answered ${res.status}`);
|
|
165
|
+
return res.json();
|
|
166
|
+
}
|
|
62
167
|
/** `/review/<id>/json`, optionally pinned to a version. Null on 404. */
|
|
63
168
|
async get(reviewId, version) {
|
|
64
169
|
const q = version ? `?v=${version}` : "";
|
|
@@ -70,15 +175,7 @@ export class ReviewClient {
|
|
|
70
175
|
return res.json();
|
|
71
176
|
}
|
|
72
177
|
async search(q, limit = 10) {
|
|
73
|
-
|
|
74
|
-
throw new Error("MIADI_REVIEW_TOKEN is not configured on the connector host");
|
|
75
|
-
const res = await this.fetchImpl(`${this.baseUrl}/api/reviews/search?${new URLSearchParams({ q, limit: String(limit) })}`, {
|
|
76
|
-
headers: { accept: "application/json", authorization: `Bearer ${this.token}` },
|
|
77
|
-
signal: AbortSignal.timeout(15_000),
|
|
78
|
-
});
|
|
79
|
-
if (!res.ok)
|
|
80
|
-
throw new Error(`review search answered ${res.status}`);
|
|
81
|
-
const body = await res.json();
|
|
178
|
+
const body = await this.authed(`/api/reviews/search?${new URLSearchParams({ q, limit: String(limit) })}`, "review search");
|
|
82
179
|
return body.reviews ?? body.results ?? [];
|
|
83
180
|
}
|
|
84
181
|
summary(r) {
|
package/dist/tools.js
CHANGED
|
@@ -30,6 +30,8 @@ import { authorizationReceipt, authorizeProvider, CHOICE_PROVIDERS, isPersonId,
|
|
|
30
30
|
import { candidatesFor, CRITICALITIES, jevAdapter, modelPreflight, PREFLIGHT_CONTRACT, PREFLIGHT_VERSION, TASK_TYPES, } from "./model-preflight.js";
|
|
31
31
|
import { ShelfRefusal, listShelfArtefacts, readShelfArtefact } from "./research-shelf.js";
|
|
32
32
|
import { isShareRelation, shareTarget } from "./record-shares.js";
|
|
33
|
+
import { cites, parseChronicleAddress, refMatcher } from "./refs.js";
|
|
34
|
+
import { commentOf, commentsOf, formatPosition, isComment, sameMedia } from "./comments.js";
|
|
33
35
|
import { DELIVERY_STATES, readSteerDelivery, revokeInInbox, settlementOf, transcriptPathOf } from "./runtime-steer.js";
|
|
34
36
|
import { ADAPTERS, readFactoryConfig, runSteering, STEERING_CONTRACT_ID, steeringSupport } from "./steering-adapters.js";
|
|
35
37
|
import { checkGrant, isBusy, steerAttempts, steeringGrantOf, steeringRevoked, steerSession } from "./steer.js";
|
|
@@ -41,7 +43,7 @@ import { join } from "node:path";
|
|
|
41
43
|
import { readingScope, canonicalVideo, suppliedDialogue } from "./reading/contract.js";
|
|
42
44
|
import { workflowId } from "./reading/workflow.js";
|
|
43
45
|
import { readingTask } from "./reading/adapters.js";
|
|
44
|
-
import {
|
|
46
|
+
import { recordsSeenBy, redactRecord } from "./record-view.js";
|
|
45
47
|
import { artefactVisibility, readArtefactWeave, saveResearchArtefact } from "@miadi/inquiry-weave";
|
|
46
48
|
import { ResearchUploads, UploadRefusal } from "./uploads.js";
|
|
47
49
|
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";
|
|
@@ -257,52 +259,25 @@ export function registerTools(server, ctx) {
|
|
|
257
259
|
viewer = found.person;
|
|
258
260
|
return found;
|
|
259
261
|
};
|
|
260
|
-
/**
|
|
261
|
-
|
|
262
|
-
* record keeps its story but not the operator details a session view also
|
|
263
|
-
* withholds (session, cwd, the seat a brief went to) nor long bodies.
|
|
264
|
-
*/
|
|
265
|
-
const redact = (r) => {
|
|
266
|
-
if (!viewer || viewer.api_tier === "write" || r.actor.person_id === viewer.id)
|
|
267
|
-
return r;
|
|
268
|
-
if (r.body.reading && r.kind === "observation") {
|
|
269
|
-
const stage = r.body.reading;
|
|
270
|
-
return { ...r, refs: [], evidence_refs: [], body: { reading: { workflow_id: stage.workflow_id, stage: stage.stage, status: stage.status, sha256: stage.sha256, visibility: "source_owner_or_factory_operator" } } };
|
|
271
|
-
}
|
|
272
|
-
const body = { ...r.body };
|
|
273
|
-
// Grants contain source rights and locators; only the owner and operators inspect them.
|
|
274
|
-
if (body.reading)
|
|
275
|
-
body.reading = { visibility: "source_owner_or_factory_operator" };
|
|
276
|
-
// A steer's binding, pane, target and artifact path name the seat as the session does (#922 R2).
|
|
277
|
-
for (const k of ["session", "cwd", "session_id", "binding", "pane"])
|
|
278
|
-
delete body[k];
|
|
279
|
-
for (const k of ["markdown", "transcript"])
|
|
280
|
-
if (typeof body[k] === "string")
|
|
281
|
-
body[k] = `${body[k].length} chars`;
|
|
282
|
-
const receipt = r.completion_receipt ? { ...r.completion_receipt } : undefined;
|
|
283
|
-
if (receipt)
|
|
284
|
-
for (const k of ["to", "file", "session_id", "target", "artifact", "model_routing"])
|
|
285
|
-
delete receipt[k];
|
|
286
|
-
// A steer's message names its target pane.
|
|
287
|
-
if (receipt && r.kind === "session_steer_request")
|
|
288
|
-
delete receipt.message;
|
|
289
|
-
return { ...r, body, ...(receipt ? { completion_receipt: receipt } : {}) };
|
|
290
|
-
};
|
|
262
|
+
/** What a record shows to the viewer (`record-view.ts`, shared with the factory's pages). */
|
|
263
|
+
const redact = (r) => redactRecord(r, viewer);
|
|
291
264
|
const actorOf = (person, auth) => {
|
|
292
265
|
const client = ctx.oauthState.read().clients[auth.clientId];
|
|
293
266
|
return { person_id: person.id, name: person.name, client_id: auth.clientId, ...(client?.client_name ? { client_name: client.client_name } : {}) };
|
|
294
267
|
};
|
|
295
268
|
const approvalUrl = (id) => `${config.publicUrl}/approve/${encodeURIComponent(id)}`;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
r.idempotency_key ===
|
|
269
|
+
/** The record this person already made with this key, which the same key hands back instead of a duplicate. */
|
|
270
|
+
const priorOf = (kind, person, key) => key
|
|
271
|
+
? // A request already decided (approved, declined, sent back) is not handed back: the same key makes a new one.
|
|
272
|
+
all().find((r) => r.kind === kind &&
|
|
273
|
+
r.idempotency_key === key &&
|
|
301
274
|
r.actor.person_id === person.id &&
|
|
302
|
-
(r.approval_state === undefined || r.approval_state === "awaiting_approval" || r.approval_state === "not_required"))
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
275
|
+
(r.approval_state === undefined || r.approval_state === "awaiting_approval" || r.approval_state === "not_required"))
|
|
276
|
+
: undefined;
|
|
277
|
+
const append = (kind, person, auth, fields) => {
|
|
278
|
+
const prior = priorOf(kind, person, fields.idempotency_key);
|
|
279
|
+
if (prior)
|
|
280
|
+
return prior;
|
|
306
281
|
return ledger.append({
|
|
307
282
|
id: newRecordId(kind),
|
|
308
283
|
kind,
|
|
@@ -351,17 +326,7 @@ export function registerTools(server, ctx) {
|
|
|
351
326
|
settleSteers();
|
|
352
327
|
return current(ledger.all());
|
|
353
328
|
};
|
|
354
|
-
const records = () =>
|
|
355
|
-
const raw = all();
|
|
356
|
-
// Completion results can contain exact drafts too. Hide their parent mission as
|
|
357
|
-
// well, so missionStatus/get_run_result cannot rehydrate it from trusted records.
|
|
358
|
-
return raw.filter(r => !viewer || canReadReading(r, raw, viewer)).map(r => {
|
|
359
|
-
// The source owner can read a factory-authored result for their private mission.
|
|
360
|
-
if (readingOwner(r, raw) === viewer?.id)
|
|
361
|
-
return r;
|
|
362
|
-
return redact(r);
|
|
363
|
-
});
|
|
364
|
-
};
|
|
329
|
+
const records = () => recordsSeenBy(all(), viewer);
|
|
365
330
|
/** Which provider a run may launch with and who authorized it, as every surface shows it (jgwill/Miadi#926). */
|
|
366
331
|
const providerAuthorizationOf = (r) => r && r.kind === "run_request" ? authorizeProvider(r, ledger.all(), { requireFresh: r.approval_state === "awaiting_approval" }) : undefined;
|
|
367
332
|
const authorizationOut = (a) => ({
|
|
@@ -393,7 +358,11 @@ export function registerTools(server, ctx) {
|
|
|
393
358
|
};
|
|
394
359
|
};
|
|
395
360
|
const uploads = new ResearchUploads(join(config.stateDir, "uploads"));
|
|
396
|
-
|
|
361
|
+
/** The records that cite a reference. An episode's address is compared by the episode it names, whatever its written form (./refs.ts, jgwill/Miadi#1093). */
|
|
362
|
+
const touching = (ref) => {
|
|
363
|
+
const is = refMatcher(ref);
|
|
364
|
+
return records().filter((r) => cites(r, is) || r.id === ref);
|
|
365
|
+
};
|
|
397
366
|
/** The factory runner's delivery receipts, read fresh: operator data, for the write tier only. */
|
|
398
367
|
const receipts = () => readFactoryReceipts(factoryLedgerPath(ctx.factoryDir ?? defaultFactoryDir()));
|
|
399
368
|
/** The Claude Code models this host permits, and the one it falls back to (jgwill/Miadi#943). */
|
|
@@ -769,6 +738,113 @@ export function registerTools(server, ctx) {
|
|
|
769
738
|
count: docs.length,
|
|
770
739
|
};
|
|
771
740
|
};
|
|
741
|
+
// ── the comments of an episode (jgwill/Miadi#1093, rispecs/episode-participants) ──
|
|
742
|
+
/** Who reads a published comment, in words (D2's recommendation: what the ledger gives today). */
|
|
743
|
+
const COMMENT_READERS = "Every person signed in to Miadi who may open this episode reads it, on the episode's page and through this connector. A visitor does not.";
|
|
744
|
+
/**
|
|
745
|
+
* One episode as Miadi resolves it for this person: its folder (the key), its number, the address
|
|
746
|
+
* this connector emits for it, its page and its media files. Any written form names the same
|
|
747
|
+
* episode, and Miadi answers its own 404 for an episode the person may not open.
|
|
748
|
+
*/
|
|
749
|
+
const episodeFor = async (person, episode) => {
|
|
750
|
+
const listing = await miadi.get(person.token, `/api/chronicle/episodes/${checkedEpisodeRef(episode)}/files`);
|
|
751
|
+
const folder = typeof listing?.episode?.path === "string" ? listing.episode.path : null;
|
|
752
|
+
if (!folder)
|
|
753
|
+
throw new ToolRefusal("not_found", `No episode answers to ${episode}.`);
|
|
754
|
+
const number = typeof listing.episode.number === "number" ? listing.episode.number : episodeNumberOf(folder);
|
|
755
|
+
return {
|
|
756
|
+
folder,
|
|
757
|
+
number,
|
|
758
|
+
title: typeof listing.episode.title === "string" ? listing.episode.title : null,
|
|
759
|
+
route: encodeURIComponent(folder),
|
|
760
|
+
ref: number === null ? `chronicle:${folder}` : `miadi-chronicle://${number}`,
|
|
761
|
+
label: number === null ? folder : `Episode ${number}`,
|
|
762
|
+
page: `${config.miadiPublicUrl}/chronicle/${encodeURIComponent(folder)}#comments`,
|
|
763
|
+
media: (Array.isArray(listing.files) ? listing.files : []).filter((f) => f?.kind === "media").map((f) => String(f.relativePath)),
|
|
764
|
+
};
|
|
765
|
+
};
|
|
766
|
+
/**
|
|
767
|
+
* A comment by a person seated in the episode's Root Circle is also a turn in its main ceremony
|
|
768
|
+
* (D12; Guillaume, 2026-11-23: "When a user comments, does that go on a talking circle for the
|
|
769
|
+
* episode? That could make sense."). It is said with the commenter's own token at the door a seated
|
|
770
|
+
* person speaks at, so Miadi applies its own seat rule, and the arrival wall shows it to the members.
|
|
771
|
+
* The comment stays the record and keeps the turn's id, so a repeated key never speaks twice.
|
|
772
|
+
* Nobody is seated and no circle is opened here. Whatever cannot happen is answered with its
|
|
773
|
+
* reason, and the comment stands.
|
|
774
|
+
*/
|
|
775
|
+
const sayInRootCircle = async (person, auth, record, episode) => {
|
|
776
|
+
try {
|
|
777
|
+
const comment = commentOf(record);
|
|
778
|
+
if (comment.circle_turn)
|
|
779
|
+
return { said: true, ...comment.circle_turn };
|
|
780
|
+
const circle = await miadi.request(person.token, "GET", `/api/chronicle/episodes/${episode.route}/circle`, undefined, 15_000);
|
|
781
|
+
const main = circle?.main;
|
|
782
|
+
const seated = Array.isArray(main?.circle?.members) && main.circle.members.some((m) => m?.person_id === person.id);
|
|
783
|
+
if (!main || !seated)
|
|
784
|
+
return { said: false, reason: `You do not sit in a Root Circle of ${episode.label}, so the comment is read on the episode's page and not in a circle.` };
|
|
785
|
+
const ceremonyId = typeof main.ceremony?.id === "string" ? main.ceremony.id : null;
|
|
786
|
+
if (!ceremonyId)
|
|
787
|
+
return { said: false, reason: `${main.circle.name ?? "The Root Circle"} has no open ceremony to speak in.` };
|
|
788
|
+
const at = comment.anchor?.at_seconds ?? null;
|
|
789
|
+
const where = [episode.ref, comment.anchor?.media ? `${comment.anchor.media}${at === null ? "" : ` at ${formatPosition(at)}`}` : null].filter(Boolean).join(" · ");
|
|
790
|
+
const answer = await miadi.post(person.token, `/api/ceremony/${encodeURIComponent(ceremonyId)}/turns`, {
|
|
791
|
+
said: [comment.text, where, record.id].join("\n\n"),
|
|
792
|
+
title: `${person.name} comments on ${episode.label}`.slice(0, 120),
|
|
793
|
+
});
|
|
794
|
+
const beatId = typeof answer?.turn?.id === "string" ? answer.turn.id : null;
|
|
795
|
+
if (!beatId)
|
|
796
|
+
return { said: false, reason: "The circle answered without a turn." };
|
|
797
|
+
const turn = {
|
|
798
|
+
ceremony_id: ceremonyId,
|
|
799
|
+
beat_id: beatId,
|
|
800
|
+
...(typeof main.circle.id === "string" ? { circle_id: main.circle.id } : {}),
|
|
801
|
+
...(typeof main.circle.name === "string" ? { circle_name: main.circle.name } : {}),
|
|
802
|
+
at: typeof answer.turn.timestamp === "string" ? answer.turn.timestamp : new Date().toISOString(),
|
|
803
|
+
};
|
|
804
|
+
ledger.append({
|
|
805
|
+
id: newRecordId("observation"),
|
|
806
|
+
kind: "observation",
|
|
807
|
+
created_at: new Date().toISOString(),
|
|
808
|
+
actor: actorOf(person, auth),
|
|
809
|
+
refs: record.refs,
|
|
810
|
+
evidence_refs: record.evidence_refs,
|
|
811
|
+
supersedes: record.id,
|
|
812
|
+
completion_receipt: { ...(record.completion_receipt ?? {}), circle_turn: turn },
|
|
813
|
+
body: {},
|
|
814
|
+
});
|
|
815
|
+
return { said: true, ...turn };
|
|
816
|
+
}
|
|
817
|
+
catch (error) {
|
|
818
|
+
const refused = error instanceof MiadiError && error.body && typeof error.body === "object" ? error.body.error : undefined;
|
|
819
|
+
return { said: false, reason: `The Root Circle did not take the turn: ${typeof refused === "string" ? refused : asState(error).state}.` };
|
|
820
|
+
}
|
|
821
|
+
};
|
|
822
|
+
server.registerTool("list_episode_comments", {
|
|
823
|
+
title: "The comments on an episode",
|
|
824
|
+
description: "The comments people published on one Chronicle episode: each with its author, its text, when it was published and where it points (the media file and the position in seconds, when it has them), and the turn it became in the episode's Root Circle when its author sits there. Narrow it to one media file, a span of positions or one author. Ordered by media file, then position, then time. A comment is published with comment_on_episode; the comments a Space published earlier with append_observation are read too.",
|
|
825
|
+
inputSchema: {
|
|
826
|
+
episode: z.string().min(1).describe("miadi-chronicle://<n>, an episode number or its folder. Every written form names the same episode."),
|
|
827
|
+
media: z.string().max(500).optional().describe("One media file, by its path inside the episode as get_evidence lists it."),
|
|
828
|
+
from_seconds: z.number().min(0).optional(),
|
|
829
|
+
to_seconds: z.number().min(0).optional(),
|
|
830
|
+
person_id: z.string().optional().describe("Only this person's comments."),
|
|
831
|
+
limit: z.number().int().min(1).max(200).optional(),
|
|
832
|
+
},
|
|
833
|
+
annotations: READ,
|
|
834
|
+
}, wrap(async (a, extra) => {
|
|
835
|
+
const { person } = who(extra);
|
|
836
|
+
const ep = await episodeFor(person, a.episode);
|
|
837
|
+
const found = commentsOf(records(), { number: ep.number, folder: ep.folder }, { media: a.media, from_seconds: a.from_seconds, to_seconds: a.to_seconds, person_id: a.person_id });
|
|
838
|
+
const comments = found.slice(0, a.limit ?? 100);
|
|
839
|
+
return {
|
|
840
|
+
episode: { ref: ep.ref, number: ep.number, folder: ep.folder, title: ep.title },
|
|
841
|
+
comments,
|
|
842
|
+
count: comments.length,
|
|
843
|
+
total: found.length,
|
|
844
|
+
shown_at: ep.page,
|
|
845
|
+
readable_by: COMMENT_READERS,
|
|
846
|
+
};
|
|
847
|
+
}));
|
|
772
848
|
const readEpisodeFile = async (person, a) => {
|
|
773
849
|
const path = a.path.trim();
|
|
774
850
|
const segments = checkRelativePath(path);
|
|
@@ -885,7 +961,7 @@ export function registerTools(server, ctx) {
|
|
|
885
961
|
}, wrap(async ({ episode, subject_ref }, extra) => {
|
|
886
962
|
const { person } = who(extra);
|
|
887
963
|
const evals = records().filter((r) => r.kind === "observation" && typeof r.body?.assessment === "string");
|
|
888
|
-
const scoped = subject_ref ? evals.filter((r) => r.refs.
|
|
964
|
+
const scoped = subject_ref ? evals.filter((r) => r.refs.some(refMatcher(subject_ref))) : evals;
|
|
889
965
|
return {
|
|
890
966
|
tracing: episode ? await miadi.get(person.token, `/api/chronicle/episodes/${episodeRef(episode)}/tracing`).catch(asState) : "give an episode to read its tracing records",
|
|
891
967
|
operational: scoped.filter((r) => r.body.assessment === "operational"),
|
|
@@ -1011,8 +1087,10 @@ export function registerTools(server, ctx) {
|
|
|
1011
1087
|
}, wrap(async ({ ref, circle: c, state }, extra) => {
|
|
1012
1088
|
who(extra);
|
|
1013
1089
|
let list = records().filter((r) => r.kind === "handoff" || r.kind === "source_intent");
|
|
1014
|
-
if (ref)
|
|
1015
|
-
|
|
1090
|
+
if (ref) {
|
|
1091
|
+
const is = refMatcher(ref);
|
|
1092
|
+
list = list.filter((r) => r.id === ref || cites(r, is));
|
|
1093
|
+
}
|
|
1016
1094
|
if (c)
|
|
1017
1095
|
list = list.filter((r) => r.to_circle === c || r.circle === c);
|
|
1018
1096
|
if (state)
|
|
@@ -1026,7 +1104,7 @@ export function registerTools(server, ctx) {
|
|
|
1026
1104
|
inputSchema: {
|
|
1027
1105
|
kind: z.string().optional(),
|
|
1028
1106
|
circle: circle.optional(),
|
|
1029
|
-
ref: z.string().optional(),
|
|
1107
|
+
ref: z.string().optional().describe("A reference the records cite. An episode's address finds them under any written form: miadi-chronicle://92 and miadi-chronicle://092 name one episode."),
|
|
1030
1108
|
person_id: z.string().optional(),
|
|
1031
1109
|
limit: z.number().int().min(1).max(200).optional(),
|
|
1032
1110
|
},
|
|
@@ -1038,8 +1116,10 @@ export function registerTools(server, ctx) {
|
|
|
1038
1116
|
list = list.filter((r) => r.kind === a.kind);
|
|
1039
1117
|
if (a.circle)
|
|
1040
1118
|
list = list.filter((r) => r.circle === a.circle || r.to_circle === a.circle);
|
|
1041
|
-
if (a.ref)
|
|
1042
|
-
|
|
1119
|
+
if (a.ref) {
|
|
1120
|
+
const is = refMatcher(a.ref);
|
|
1121
|
+
list = list.filter((r) => cites(r, is));
|
|
1122
|
+
}
|
|
1043
1123
|
if (a.person_id)
|
|
1044
1124
|
list = list.filter((r) => r.actor.person_id === a.person_id);
|
|
1045
1125
|
const out = list.reverse().slice(0, a.limit ?? 50);
|
|
@@ -1353,7 +1433,7 @@ export function registerTools(server, ctx) {
|
|
|
1353
1433
|
};
|
|
1354
1434
|
server.registerTool("append_observation", {
|
|
1355
1435
|
title: "Record an observation",
|
|
1356
|
-
description: "Record what was observed (or hypothesised, desired, imagined) about a source, in your name, with its claim category and the circle it concerns. Fiction and desired futures stay labelled as such.",
|
|
1436
|
+
description: "Record what was observed (or hypothesised, desired, imagined) about a source, in your name, with its claim category and the circle it concerns. Fiction and desired futures stay labelled as such. To comment on a Chronicle episode at a moment of its media, use comment_on_episode.",
|
|
1357
1437
|
inputSchema: {
|
|
1358
1438
|
text: z.string().min(1).max(20000),
|
|
1359
1439
|
claim_category: claim,
|
|
@@ -1368,7 +1448,7 @@ export function registerTools(server, ctx) {
|
|
|
1368
1448
|
}, wrap(async (a, extra) => {
|
|
1369
1449
|
const { person, auth } = who(extra);
|
|
1370
1450
|
requireContribute(auth);
|
|
1371
|
-
|
|
1451
|
+
const record = append("observation", person, auth, {
|
|
1372
1452
|
claim_category: a.claim_category,
|
|
1373
1453
|
circle: a.circle,
|
|
1374
1454
|
domain: a.domain,
|
|
@@ -1380,6 +1460,74 @@ export function registerTools(server, ctx) {
|
|
|
1380
1460
|
idempotency_key: a.idempotency_key,
|
|
1381
1461
|
body: { text: a.text },
|
|
1382
1462
|
});
|
|
1463
|
+
// A comment a Space publishes this way (./comments.ts) follows comment_on_episode's circle rule (jgwill/Miadi#1093).
|
|
1464
|
+
if (!isComment(record))
|
|
1465
|
+
return record;
|
|
1466
|
+
const address = record.refs.map(parseChronicleAddress).find((x) => x !== null);
|
|
1467
|
+
if (!address)
|
|
1468
|
+
return record;
|
|
1469
|
+
const head = address.folder ?? String(address.number);
|
|
1470
|
+
await sayInRootCircle(person, auth, record, {
|
|
1471
|
+
route: encodeURIComponent(head),
|
|
1472
|
+
ref: address.folder ? `chronicle:${address.folder}` : `miadi-chronicle://${address.number}`,
|
|
1473
|
+
label: address.number === null ? head : `Episode ${address.number}`,
|
|
1474
|
+
});
|
|
1475
|
+
return all().find((r) => r.id === record.id) ?? record;
|
|
1476
|
+
}));
|
|
1477
|
+
server.registerTool("comment_on_episode", {
|
|
1478
|
+
title: "Publish a comment on an episode",
|
|
1479
|
+
description: "Publishes a comment on one Chronicle episode, in your name: what you say about it, optionally at a position of one of its media files. It is read by every person signed in to Miadi who may open the episode, on the episode's page and with list_episode_comments. When you sit in the episode's Root Circle, it is also said there as a turn, in your name, and the circle's members see it on their arrival wall. Nothing is kept that is not published: a call either publishes the comment or refuses and writes nothing. Publish only on the person's own request to publish at Miadi.",
|
|
1480
|
+
inputSchema: {
|
|
1481
|
+
episode: z.string().min(1).describe("miadi-chronicle://<n>, an episode number or its folder. Every written form names the same episode."),
|
|
1482
|
+
text: z.string().min(1).max(20000),
|
|
1483
|
+
media: z.string().max(500).optional().describe("The media file the comment is about, by its path inside the episode as get_evidence lists it (audio/…mp3). Leave it out for a comment on the whole episode."),
|
|
1484
|
+
at_seconds: z.number().min(0).optional().describe("The position in that media file, in seconds."),
|
|
1485
|
+
until_seconds: z.number().min(0).optional().describe("The end of the span, when the comment is about more than a moment."),
|
|
1486
|
+
claim_category: claim.optional().describe("observed (the default), hypothesis, desired_future, fiction or verified_implementation."),
|
|
1487
|
+
...base,
|
|
1488
|
+
},
|
|
1489
|
+
annotations: WRITE,
|
|
1490
|
+
}, wrap(async (a, extra) => {
|
|
1491
|
+
const { person, auth } = who(extra);
|
|
1492
|
+
requireContribute(auth);
|
|
1493
|
+
const ep = await episodeFor(person, a.episode);
|
|
1494
|
+
let media = null;
|
|
1495
|
+
if (a.media !== undefined) {
|
|
1496
|
+
const named = String(a.media).trim();
|
|
1497
|
+
checkRelativePath(named);
|
|
1498
|
+
const found = ep.media.filter((path) => sameMedia(path, named));
|
|
1499
|
+
if (found.length !== 1) {
|
|
1500
|
+
throw new ToolRefusal("invalid_path", found.length ? `${named} names ${found.length} media files of ${ep.label}. Give the whole path of one.` : `${named} is not a media file of ${ep.label}.`, { media: ep.media });
|
|
1501
|
+
}
|
|
1502
|
+
media = found[0];
|
|
1503
|
+
}
|
|
1504
|
+
const seconds = (v) => (typeof v === "number" ? Math.round(v * 1000) / 1000 : null);
|
|
1505
|
+
const at = seconds(a.at_seconds);
|
|
1506
|
+
const until = seconds(a.until_seconds);
|
|
1507
|
+
if (at !== null && !media)
|
|
1508
|
+
throw new ToolRefusal("invalid_position", "A position is a moment of one media file: name the file in media. A comment on the whole episode has neither.", { media: ep.media });
|
|
1509
|
+
if (until !== null && (at === null || until <= at))
|
|
1510
|
+
throw new ToolRefusal("invalid_position", "until_seconds ends a span that at_seconds starts, and is greater than it.");
|
|
1511
|
+
const repeated = Boolean(priorOf("observation", person, a.idempotency_key));
|
|
1512
|
+
const record = append("observation", person, auth, {
|
|
1513
|
+
claim_category: a.claim_category ?? "observed",
|
|
1514
|
+
refs: [ep.ref],
|
|
1515
|
+
intention: a.intention,
|
|
1516
|
+
role: a.role,
|
|
1517
|
+
idempotency_key: a.idempotency_key,
|
|
1518
|
+
body: { text: a.text, anchor: { episode: { folder: ep.folder, number: ep.number }, media, at_seconds: at, until_seconds: until } },
|
|
1519
|
+
});
|
|
1520
|
+
const circle_turn = await sayInRootCircle(person, auth, record, ep);
|
|
1521
|
+
const stored = all().find((r) => r.id === record.id) ?? record;
|
|
1522
|
+
return {
|
|
1523
|
+
published: true,
|
|
1524
|
+
...(repeated ? { repeated: true, note: "This key was already published. This is that comment; nothing new was written." } : {}),
|
|
1525
|
+
record: stored,
|
|
1526
|
+
comment: commentOf(stored),
|
|
1527
|
+
shows_at: ep.page,
|
|
1528
|
+
readable_by: COMMENT_READERS,
|
|
1529
|
+
circle_turn,
|
|
1530
|
+
};
|
|
1383
1531
|
}));
|
|
1384
1532
|
server.registerTool("open_inquiry", {
|
|
1385
1533
|
title: "Open an inquiry",
|
|
@@ -2987,6 +3135,8 @@ export const TOOL_STATUS = {
|
|
|
2987
3135
|
search: "live",
|
|
2988
3136
|
fetch: "live",
|
|
2989
3137
|
append_observation: "live, contribute",
|
|
3138
|
+
list_episode_comments: "live (the comments published on one episode, by media file and position; any written form of the episode's address)",
|
|
3139
|
+
comment_on_episode: "live, contribute (publishes a comment in your name on an episode, at a position of a media file when given; when you sit in the episode's Root Circle it is also said there as a turn)",
|
|
2990
3140
|
open_inquiry: "live, contribute",
|
|
2991
3141
|
link_records: "live, contribute",
|
|
2992
3142
|
propose_narrative_beat: "live, contribute",
|
package/dist/transcript-job.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type FetchCaptions, type TranscriptMethod } from "./captions.js";
|
|
2
2
|
import { type Actor, type ConnectorRecord } from "./records.js";
|
|
3
|
+
import { type TranscriptState } from "./reviews.js";
|
|
3
4
|
import type { Ledger } from "./store.js";
|
|
4
|
-
export type TranscriptState
|
|
5
|
+
export type { TranscriptState };
|
|
5
6
|
export type StageName = "requested" | "reuse_check" | "source_check" | "acquire" | "store" | "readback";
|
|
6
7
|
export interface JobStage {
|
|
7
8
|
stage: StageName;
|
package/dist/transcript-job.js
CHANGED
|
@@ -23,6 +23,7 @@ import { mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
|
23
23
|
import { join } from "node:path";
|
|
24
24
|
import { TRANSCRIPT_RETRY_MS, TRANSCRIPT_WINDOW_MS, coverage, sourceOf } from "./captions.js";
|
|
25
25
|
import { current, newRecordId } from "./records.js";
|
|
26
|
+
import { transcriptStateOf } from "./reviews.js";
|
|
26
27
|
/** The review service's own transcript door, as the connector's token reaches it. */
|
|
27
28
|
export function reviewTranscriptService(config, fetchImpl = fetch) {
|
|
28
29
|
const call = async (method, path, body) => {
|
|
@@ -580,15 +581,7 @@ export async function transcriptStatus(io, input, links) {
|
|
|
580
581
|
const held = await io.service.state(input.review_id);
|
|
581
582
|
const reachable = held.status === 200;
|
|
582
583
|
const service = { reachable, ...(reachable ? { has_transcript: held.has_transcript, source: held.source ?? null, updated_at: held.updated_at ?? null } : { error: held.error ?? `The review service answered ${held.status}.` }) };
|
|
583
|
-
|
|
584
|
-
if (reachable && held.has_transcript)
|
|
585
|
-
state = "stored";
|
|
586
|
-
else if (receipt && receipt.state !== "stored")
|
|
587
|
-
state = receipt.state;
|
|
588
|
-
else if (receipt?.state === "stored" && reachable)
|
|
589
|
-
state = "absent"; // the job stored one that the service no longer holds
|
|
590
|
-
else
|
|
591
|
-
state = reachable ? "absent" : receipt ? receipt.state : "unknown";
|
|
584
|
+
const state = transcriptStateOf({ reachable, has_transcript: held.has_transcript, ...(receipt ? { job: receipt } : {}) });
|
|
592
585
|
let verified_now;
|
|
593
586
|
if (input.verify && reachable && held.has_transcript) {
|
|
594
587
|
const back = await readback(io, { review_id: input.review_id }, receipt?.state === "stored" ? receipt.sha256 : undefined);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.42";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.42";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miadi/connector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.42",
|
|
4
4
|
"description": "The Miadi connector: one remote MCP service through which a person signed in with their Miadi person token, from ChatGPT or any MCP client, reads sessions, reviews, episodes and circles and records observations, inquiries, handoffs and proposals with their name on each record.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Miadi",
|
|
@@ -40,6 +40,22 @@
|
|
|
40
40
|
"types": "./dist/record-shares.d.ts",
|
|
41
41
|
"import": "./dist/record-shares.js"
|
|
42
42
|
},
|
|
43
|
+
"./comments": {
|
|
44
|
+
"types": "./dist/comments.d.ts",
|
|
45
|
+
"import": "./dist/comments.js"
|
|
46
|
+
},
|
|
47
|
+
"./refs": {
|
|
48
|
+
"types": "./dist/refs.d.ts",
|
|
49
|
+
"import": "./dist/refs.js"
|
|
50
|
+
},
|
|
51
|
+
"./reviews": {
|
|
52
|
+
"types": "./dist/reviews.d.ts",
|
|
53
|
+
"import": "./dist/reviews.js"
|
|
54
|
+
},
|
|
55
|
+
"./record-view": {
|
|
56
|
+
"types": "./dist/record-view.d.ts",
|
|
57
|
+
"import": "./dist/record-view.js"
|
|
58
|
+
},
|
|
43
59
|
"./package.json": "./package.json"
|
|
44
60
|
},
|
|
45
61
|
"bin": {
|
|
@@ -53,9 +69,9 @@
|
|
|
53
69
|
"dependencies": {
|
|
54
70
|
"@miadi/hooks-core": "^0.6.2",
|
|
55
71
|
"@miadi/hooks-gateway": "^0.2.1",
|
|
56
|
-
"@miadi/inquiry-weave": "0.
|
|
72
|
+
"@miadi/inquiry-weave": "0.19.1",
|
|
57
73
|
"@miadi/node-service-kit": "0.1.2",
|
|
58
|
-
"@miadi/relational-git-repository-mapper": "^0.
|
|
74
|
+
"@miadi/relational-git-repository-mapper": "^0.8.0",
|
|
59
75
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
60
76
|
"express": "^5.2.1",
|
|
61
77
|
"express-rate-limit": "^8.2.1",
|