@miadi/connector 0.1.41 → 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 +11 -1
- package/dist/record-view.d.ts +18 -0
- package/dist/record-view.js +45 -0
- package/dist/reviews.d.ts +42 -0
- package/dist/reviews.js +111 -14
- package/dist/tools.js +4 -43
- 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 +9 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Call `get_capabilities` first. It names the signed-in person, their Miadi API ti
|
|
|
33
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.
|
|
34
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.
|
|
35
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.
|
|
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 `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:
|
|
37
37
|
- a run becomes a brief in the factory queue, which the intake delivers to a session;
|
|
38
38
|
- a work proposal starts its work the same way, as a brief written from the proposal;
|
|
39
39
|
- a review operation calls the review service;
|
|
@@ -192,6 +192,15 @@ Without that sign-in, or for a person without the write tier, the cards link to
|
|
|
192
192
|
|
|
193
193
|
Every record has a claim category: `observed`, `hypothesis`, `desired_future`, `fiction` or `verified_implementation`. Witnessed fact, envisioned features and fiction stay apart.
|
|
194
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
|
+
|
|
195
204
|
## Run it
|
|
196
205
|
|
|
197
206
|
```bash
|
|
@@ -264,6 +273,7 @@ The issues and the episode behind each part. `jgwill/Miadi` is a private reposit
|
|
|
264
273
|
| Codex on its requester's own choice | jgwill/Miadi#926 |
|
|
265
274
|
| the mission standard, and the local reviewer that will check S2 (A3) | jgwill/Miadi#939 |
|
|
266
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 |
|
|
267
277
|
| what a published README holds | jgwill/Miadi#685 |
|
|
268
278
|
|
|
269
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,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/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
|
@@ -43,7 +43,7 @@ import { join } from "node:path";
|
|
|
43
43
|
import { readingScope, canonicalVideo, suppliedDialogue } from "./reading/contract.js";
|
|
44
44
|
import { workflowId } from "./reading/workflow.js";
|
|
45
45
|
import { readingTask } from "./reading/adapters.js";
|
|
46
|
-
import {
|
|
46
|
+
import { recordsSeenBy, redactRecord } from "./record-view.js";
|
|
47
47
|
import { artefactVisibility, readArtefactWeave, saveResearchArtefact } from "@miadi/inquiry-weave";
|
|
48
48
|
import { ResearchUploads, UploadRefusal } from "./uploads.js";
|
|
49
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";
|
|
@@ -259,37 +259,8 @@ export function registerTools(server, ctx) {
|
|
|
259
259
|
viewer = found.person;
|
|
260
260
|
return found;
|
|
261
261
|
};
|
|
262
|
-
/**
|
|
263
|
-
|
|
264
|
-
* record keeps its story but not the operator details a session view also
|
|
265
|
-
* withholds (session, cwd, the seat a brief went to) nor long bodies.
|
|
266
|
-
*/
|
|
267
|
-
const redact = (r) => {
|
|
268
|
-
if (!viewer || viewer.api_tier === "write" || r.actor.person_id === viewer.id)
|
|
269
|
-
return r;
|
|
270
|
-
if (r.body.reading && r.kind === "observation") {
|
|
271
|
-
const stage = r.body.reading;
|
|
272
|
-
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" } } };
|
|
273
|
-
}
|
|
274
|
-
const body = { ...r.body };
|
|
275
|
-
// Grants contain source rights and locators; only the owner and operators inspect them.
|
|
276
|
-
if (body.reading)
|
|
277
|
-
body.reading = { visibility: "source_owner_or_factory_operator" };
|
|
278
|
-
// A steer's binding, pane, target and artifact path name the seat as the session does (#922 R2).
|
|
279
|
-
for (const k of ["session", "cwd", "session_id", "binding", "pane"])
|
|
280
|
-
delete body[k];
|
|
281
|
-
for (const k of ["markdown", "transcript"])
|
|
282
|
-
if (typeof body[k] === "string")
|
|
283
|
-
body[k] = `${body[k].length} chars`;
|
|
284
|
-
const receipt = r.completion_receipt ? { ...r.completion_receipt } : undefined;
|
|
285
|
-
if (receipt)
|
|
286
|
-
for (const k of ["to", "file", "session_id", "target", "artifact", "model_routing"])
|
|
287
|
-
delete receipt[k];
|
|
288
|
-
// A steer's message names its target pane.
|
|
289
|
-
if (receipt && r.kind === "session_steer_request")
|
|
290
|
-
delete receipt.message;
|
|
291
|
-
return { ...r, body, ...(receipt ? { completion_receipt: receipt } : {}) };
|
|
292
|
-
};
|
|
262
|
+
/** What a record shows to the viewer (`record-view.ts`, shared with the factory's pages). */
|
|
263
|
+
const redact = (r) => redactRecord(r, viewer);
|
|
293
264
|
const actorOf = (person, auth) => {
|
|
294
265
|
const client = ctx.oauthState.read().clients[auth.clientId];
|
|
295
266
|
return { person_id: person.id, name: person.name, client_id: auth.clientId, ...(client?.client_name ? { client_name: client.client_name } : {}) };
|
|
@@ -355,17 +326,7 @@ export function registerTools(server, ctx) {
|
|
|
355
326
|
settleSteers();
|
|
356
327
|
return current(ledger.all());
|
|
357
328
|
};
|
|
358
|
-
const records = () =>
|
|
359
|
-
const raw = all();
|
|
360
|
-
// Completion results can contain exact drafts too. Hide their parent mission as
|
|
361
|
-
// well, so missionStatus/get_run_result cannot rehydrate it from trusted records.
|
|
362
|
-
return raw.filter(r => !viewer || canReadReading(r, raw, viewer)).map(r => {
|
|
363
|
-
// The source owner can read a factory-authored result for their private mission.
|
|
364
|
-
if (readingOwner(r, raw) === viewer?.id)
|
|
365
|
-
return r;
|
|
366
|
-
return redact(r);
|
|
367
|
-
});
|
|
368
|
-
};
|
|
329
|
+
const records = () => recordsSeenBy(all(), viewer);
|
|
369
330
|
/** Which provider a run may launch with and who authorized it, as every surface shows it (jgwill/Miadi#926). */
|
|
370
331
|
const providerAuthorizationOf = (r) => r && r.kind === "run_request" ? authorizeProvider(r, ledger.all(), { requireFresh: r.approval_state === "awaiting_approval" }) : undefined;
|
|
371
332
|
const authorizationOut = (a) => ({
|
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",
|
|
@@ -48,6 +48,14 @@
|
|
|
48
48
|
"types": "./dist/refs.d.ts",
|
|
49
49
|
"import": "./dist/refs.js"
|
|
50
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
|
+
},
|
|
51
59
|
"./package.json": "./package.json"
|
|
52
60
|
},
|
|
53
61
|
"bin": {
|