@loomcycle/explorer 0.9.0 → 0.12.0

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.
@@ -0,0 +1,23 @@
1
+ import type { BrowseScope, DocEdge, DocScope } from "../types";
2
+ import type { DocRulingAnswer, ExplorerDataLayer } from "./dataLayer";
3
+ import { type RulingAction, type RulingHooks, type RulingOutcome, type RulingScope } from "./ruling";
4
+ export declare function reviewScopeFor(scope: DocScope): RulingScope | undefined;
5
+ export declare function bulkReviewScope(data: Pick<ExplorerDataLayer, "documentRuleStatements">, scope: DocScope): RulingScope | undefined;
6
+ export declare function documentProposals(edges: DocEdge[], documentId: string): DocEdge[];
7
+ export interface ReviewPanel {
8
+ proposals: DocEdge[];
9
+ scope: RulingScope;
10
+ incomplete: boolean;
11
+ onChanged: () => void;
12
+ }
13
+ export declare function reviewPanel(scope: RulingScope | undefined, proposals: DocEdge[], incomplete: boolean, onChanged: () => void): ReviewPanel | undefined;
14
+ export interface DocumentRuling {
15
+ documentId: string;
16
+ action: RulingAction;
17
+ ids?: string[];
18
+ reason?: string;
19
+ scope: RulingScope;
20
+ browse?: BrowseScope;
21
+ }
22
+ export declare function ruleDocumentProposals(data: ExplorerDataLayer, r: DocumentRuling, hooks?: RulingHooks<DocRulingAnswer>): Promise<RulingOutcome>;
23
+ export declare function rulingNote(action: RulingAction, o: RulingOutcome): string;
@@ -0,0 +1,2 @@
1
+ import type { ChunkRow } from "../types";
2
+ export declare function chunkAncestors(chunks: readonly ChunkRow[], id: string | undefined): ChunkRow[];
@@ -0,0 +1,31 @@
1
+ import type { AcceptClassificationAnswer, ClassificationRecord, ClassifyAnswer, ClassifyCandidate, ClassifyStep } from "../types";
2
+ export interface PendingClassification {
3
+ proposedType?: string;
4
+ proposedTags: string[];
5
+ statementCount: number;
6
+ }
7
+ export declare function classificationRecord(fields: unknown): ClassificationRecord | undefined;
8
+ export declare function pendingClassification(fields: unknown): PendingClassification | undefined;
9
+ export declare function resultLabel(a: Pick<ClassifyAnswer, "result" | "write">): string;
10
+ export declare function classDisposition(a: Pick<ClassifyAnswer, "class" | "live" | "result" | "write">): string | undefined;
11
+ export declare function canApply(a: ClassifyAnswer): boolean;
12
+ export declare function formatShare(share: number | undefined): string;
13
+ export declare function stepLabel(step: string): string;
14
+ export declare function candidateDetail(c: ClassifyCandidate): string;
15
+ export interface StepSummary {
16
+ label: string;
17
+ chosen?: string;
18
+ method?: string;
19
+ neighbours?: number;
20
+ reason?: string;
21
+ candidates: {
22
+ class: string;
23
+ detail: string;
24
+ }[];
25
+ }
26
+ export declare function summarizeStep(s: ClassifyStep): StepSummary;
27
+ export declare function acceptSummary(a: AcceptClassificationAnswer): {
28
+ applied: string;
29
+ notices: string[];
30
+ };
31
+ export declare function classifyErrorText(e: unknown): string;
@@ -23,3 +23,18 @@ export type AssetFetch = (path: string) => Promise<Response>;
23
23
  * client uses, so an image asset loads under both cookie (web) and bearer
24
24
  * (standalone package) auth. */
25
25
  export declare function assetFetchFromConnection(c: Connection): AssetFetch;
26
+ /** JsonPost POSTs a JSON body to a relative loomcycle path and returns the parsed
27
+ * answer; a refusal rejects with an Error carrying the HTTP `status` and the
28
+ * server's `code` (e.g. `queue_changed`), its message the server's `error`. It
29
+ * reaches routes the pinned @loomcycle/client may not have a method for yet
30
+ * (RFC FS: POST /v1/_statements/rule and /revert), over the same transport. */
31
+ export type JsonPost = (path: string, body: unknown) => Promise<unknown>;
32
+ /** RequestError is a JsonPost refusal. */
33
+ export declare class RequestError extends Error {
34
+ readonly status: number;
35
+ readonly code?: string;
36
+ constructor(message: string, status: number, code?: string);
37
+ }
38
+ /** Build the JsonPost from a Connection — the same auth transport as the JSON
39
+ * client and the asset fetch. */
40
+ export declare function jsonPostFromConnection(c: Connection): JsonPost;
@@ -1,8 +1,9 @@
1
1
  import { type ReactNode } from "react";
2
2
  import type { LoomcycleClient } from "@loomcycle/client";
3
- import type { Backlink, BrowseScope, CanvasDoc, ChunkDetail, ChunkRevision, ChunkRow, DocEdge, DocScope, PathEntry, PathScope, RelatedChunk, UnlinkedMention } from "../types";
3
+ import type { AcceptClassificationAnswer, Backlink, BrowseScope, CanvasDoc, ChunkDetail, ChunkRevision, ChunkRow, ClassifyAnswer, ClassifyWrite, DocEdge, DocScope, PathEntry, StatementStatus, PathScope, RelatedChunk, UnlinkedMention } from "../types";
4
4
  import type { DocSummary, DocumentMeta } from "./colorScheme";
5
- import type { AssetFetch } from "./createClient";
5
+ import type { AssetFetch, JsonPost } from "./createClient";
6
+ import type { RulingCounts, RulingRequest } from "./ruling";
6
7
  export interface ChunkPatch {
7
8
  body?: string;
8
9
  fields?: unknown;
@@ -11,10 +12,31 @@ export interface ChunkPatch {
11
12
  type?: string;
12
13
  tags?: string[];
13
14
  }
15
+ export interface DocRulingFilter {
16
+ from_document_id: string;
17
+ }
18
+ export interface DocRulingAnswer extends RulingCounts {
19
+ sample?: DocEdge[] | null;
20
+ breakdown?: {
21
+ kind: string;
22
+ method: string;
23
+ count: number;
24
+ }[] | null;
25
+ }
26
+ export interface DocRevertAnswer {
27
+ ruling_id: string;
28
+ reverted: number;
29
+ changed: number;
30
+ }
14
31
  export interface PathLsPage {
15
32
  limit?: number;
16
33
  cursor?: string;
17
34
  }
35
+ export interface DocEdgesPage {
36
+ edges: DocEdge[];
37
+ truncated?: boolean;
38
+ next_cursor?: string;
39
+ }
18
40
  export interface PathLsResult {
19
41
  path: string;
20
42
  entries: PathEntry[];
@@ -50,9 +72,35 @@ export interface ExplorerDataLayer {
50
72
  documentReorderChunk(id: string, direction: "up" | "down", scope: DocScope, browse?: BrowseScope): Promise<unknown>;
51
73
  documentDeleteChunk(id: string, scope: DocScope, browse?: BrowseScope): Promise<unknown>;
52
74
  documentSetAsset(chunkId: string, mediaType: string, dataBase64: string, filename: string | undefined, scope: DocScope, browse?: BrowseScope): Promise<ChunkDetail>;
53
- documentGetEdges(documentId: string, scope: DocScope, browse?: BrowseScope): Promise<{
54
- edges: DocEdge[];
75
+ documentGetEdges(documentId: string, scope: DocScope, browse?: BrowseScope, page?: {
76
+ after?: string;
77
+ }): Promise<DocEdgesPage>;
78
+ documentGetEdge?(id: string, scope: DocScope, browse?: BrowseScope): Promise<{
79
+ statement: DocEdge;
80
+ }>;
81
+ documentAcceptStatement?(id: string, scope: DocScope, browse?: BrowseScope, reason?: string): Promise<{
82
+ id: string;
83
+ status: StatementStatus;
84
+ }>;
85
+ documentRejectStatement?(id: string, reason: string, scope: DocScope, browse?: BrowseScope): Promise<{
86
+ id: string;
87
+ status: StatementStatus;
88
+ }>;
89
+ documentListStatements?(scope: DocScope, browse?: BrowseScope, opts?: {
90
+ status?: StatementStatus;
91
+ kind?: string;
92
+ limit?: number;
93
+ after?: string;
94
+ }): Promise<{
95
+ statements: DocEdge[];
96
+ truncated?: boolean;
97
+ next_cursor?: string;
55
98
  }>;
99
+ documentRuleStatements?(req: RulingRequest<DocRulingFilter>, browse?: BrowseScope): Promise<DocRulingAnswer>;
100
+ documentRevertRuling?(rulingId: string, scope: "tenant" | "user", browse?: BrowseScope): Promise<DocRevertAnswer>;
101
+ documentClassify?(documentId: string, write: ClassifyWrite, scope: DocScope, browse?: BrowseScope): Promise<ClassifyAnswer>;
102
+ documentAcceptClassification?(documentId: string, scope: DocScope, browse?: BrowseScope): Promise<AcceptClassificationAnswer>;
103
+ documentEntityTypes?(scope: DocScope, browse?: BrowseScope): Promise<string[]>;
56
104
  documentAssetObjectUrl?(chunkId: string, scope: DocScope, browse?: BrowseScope): Promise<string>;
57
105
  documentUpdateChunk(id: string, revision: number, patch: ChunkPatch, scope: DocScope, browse?: BrowseScope): Promise<ChunkDetail>;
58
106
  documentExportMd(documentId: string, scope: DocScope, includeMetadata: boolean, browse?: BrowseScope): Promise<{
@@ -90,7 +138,7 @@ export interface ExplorerDataLayer {
90
138
  document_id: string;
91
139
  }>;
92
140
  }
93
- export declare function dataLayerFromClient(client: LoomcycleClient, assetFetch?: AssetFetch): ExplorerDataLayer;
141
+ export declare function dataLayerFromClient(client: LoomcycleClient, assetFetch?: AssetFetch, jsonPost?: JsonPost): ExplorerDataLayer;
94
142
  export declare function ExplorerDataProvider({ value, children, }: {
95
143
  value: ExplorerDataLayer;
96
144
  children: ReactNode;
@@ -0,0 +1,7 @@
1
+ import type { BrowseScope, DocEdge, DocScope } from "../types";
2
+ import type { ExplorerDataLayer } from "./dataLayer";
3
+ export declare const EDGE_PAGE_CAP = 20;
4
+ export declare function loadDocumentEdges(data: Pick<ExplorerDataLayer, "documentGetEdges">, documentId: string, scope: DocScope, browse?: BrowseScope, maxPages?: number): Promise<{
5
+ edges: DocEdge[];
6
+ incomplete: boolean;
7
+ }>;
@@ -0,0 +1,4 @@
1
+ export type NavigatorMode = "tree" | "stars";
2
+ export declare const NAVIGATOR_KEY = "loomcycle.explorer.navigator";
3
+ export declare function readNavigatorMode(storage: Pick<Storage, "getItem"> | undefined): NavigatorMode;
4
+ export declare function writeNavigatorMode(storage: Pick<Storage, "setItem"> | undefined, mode: NavigatorMode): void;
@@ -0,0 +1,114 @@
1
+ export declare const RULING_CHUNK = 1000;
2
+ export declare const QUEUE_CHANGED_RETRIES = 3;
3
+ export type RulingAction = "accept" | "reject";
4
+ export type RulingScope = "tenant" | "user";
5
+ /** One statement's outcome in a ruling or a revert: the status it was ruled to,
6
+ * or the refusal's code and message. */
7
+ export interface RulingItem {
8
+ id: string;
9
+ status?: string;
10
+ error?: string;
11
+ message?: string;
12
+ }
13
+ /** A rule call's body. `F` is the queue filter's shape. */
14
+ export interface RulingRequest<F> {
15
+ action: RulingAction;
16
+ ids?: string[];
17
+ filter?: F;
18
+ reason?: string;
19
+ dry_run: boolean;
20
+ expect_count?: number;
21
+ max?: number;
22
+ scope?: RulingScope;
23
+ /** Whose user scope (with scope user): another subject's, for an operator. */
24
+ scope_id?: string;
25
+ }
26
+ /** The counts of a rule call's answer that the sequence reads. */
27
+ export interface RulingCounts {
28
+ dry_run: boolean;
29
+ ruling_id?: string;
30
+ /** What the selection matches that the caller may read; expect_count repeats it. */
31
+ matched: number;
32
+ /** The part this call considers: at most RULING_CHUNK, first in queue order. */
33
+ selected: number;
34
+ /** Of `selected`, the ones the caller may not rule on. */
35
+ skipped: number;
36
+ to_rule: number;
37
+ ruled: number;
38
+ failed: number;
39
+ items?: RulingItem[] | null;
40
+ }
41
+ export interface RulingApi<F, R extends RulingCounts> {
42
+ rule(req: RulingRequest<F>): Promise<R>;
43
+ }
44
+ export interface RulingSelection<F> {
45
+ action: RulingAction;
46
+ ids?: string[];
47
+ filter?: F;
48
+ reason?: string;
49
+ scope?: RulingScope;
50
+ /** Whose user documents, with scope user: the subject a viewer is browsing.
51
+ * Every call of the ruling carries it. */
52
+ scopeId?: string;
53
+ }
54
+ /** Why a reviewer is asked to confirm: the first dry run, a dry run after the
55
+ * queue changed under the ruling (`queue_changed`), or one that found more
56
+ * than was confirmed while ruling in chunks. */
57
+ export type ConfirmReason = "first" | "queue_changed" | "grew";
58
+ export interface RulingProgress {
59
+ ruled: number;
60
+ failed: number;
61
+ /** What the reviewer confirmed: the dry run's match count. */
62
+ total: number;
63
+ chunks: number;
64
+ }
65
+ export interface RulingOutcome {
66
+ /** Each call that ruled made one ruling; undoing the whole ruling reverts each. */
67
+ rulingIds: string[];
68
+ ruled: number;
69
+ failed: number;
70
+ /** The last dry run's count of statements the caller may not rule on. */
71
+ skipped: number;
72
+ /** What the reviewer confirmed (0 when nothing matched). */
73
+ total: number;
74
+ /** The reviewer declined a confirm. */
75
+ cancelled: boolean;
76
+ /** The statements that did not take the ruling, with the runtime's reason. */
77
+ failures: RulingItem[];
78
+ /** A call failed part way; whatever was ruled before it is in rulingIds. */
79
+ error?: unknown;
80
+ }
81
+ export interface RulingHooks<R> {
82
+ /** Asked with each dry run the reviewer has not seen yet; false stops. Omitted
83
+ * (a single row, a hand-picked selection), nothing is asked. */
84
+ confirm?: (dry: R, why: ConfirmReason) => Promise<boolean>;
85
+ onProgress?: (p: RulingProgress) => void;
86
+ }
87
+ /** isQueueChanged recognizes the refusal of a real call whose expect_count no
88
+ * longer matches. Read off the error's `code`, which both @loomcycle/client's
89
+ * errors and a host's own carry. */
90
+ export declare function isQueueChanged(e: unknown): boolean;
91
+ /** runRuling rules a selection: ALWAYS a dry run first (the confirm sees its
92
+ * count and sample), then each real call carries that dry run's count as
93
+ * expect_count. Over RULING_CHUNK matches it rules in chunks — dry run, rule,
94
+ * dry run — until the selection is ruled, a chunk rules nothing (what is left
95
+ * cannot be ruled by this caller), or the reviewer stops.
96
+ *
97
+ * A queue that changed between a dry run and its ruling (queue_changed) is
98
+ * dry-run again and confirmed again. So is one that grew past what was
99
+ * confirmed while chunking: "all matching" means what the reviewer saw. */
100
+ export declare function runRuling<F, R extends RulingCounts>(api: RulingApi<F, R>, sel: RulingSelection<F>, hooks?: RulingHooks<R>): Promise<RulingOutcome>;
101
+ export interface UndoOutcome {
102
+ reverted: number;
103
+ changed: number;
104
+ /** Rulings the runtime could not undo (not found, refused), with why. */
105
+ errors: string[];
106
+ }
107
+ /** undoRulings reverts each ruling of a bulk ruling, newest first, and adds up
108
+ * what came back. One ruling failing does not stop the others. */
109
+ export declare function undoRulings(revert: (rulingId: string) => Promise<{
110
+ reverted: number;
111
+ changed: number;
112
+ }>, rulingIds: string[]): Promise<UndoOutcome>;
113
+ /** chunkCount is how many calls a confirmed ruling of `matched` takes. */
114
+ export declare function chunkCount(matched: number): number;
@@ -0,0 +1,13 @@
1
+ import type { EdgeEvidence, StatementFields } from "../types";
2
+ export declare const EVIDENCE_PREVIEW = 3;
3
+ export declare function statusLabel(s: StatementFields): string | undefined;
4
+ export declare function methodLabel(s: StatementFields): string | undefined;
5
+ export declare function isProposed(s: StatementFields): boolean;
6
+ export declare function formatNsDate(ns: number): string;
7
+ export declare function validityLabel(s: StatementFields): string | undefined;
8
+ export declare function verdictHint(s: StatementFields): string | undefined;
9
+ export declare function evidencePreview(s: StatementFields, max?: number): {
10
+ rows: EdgeEvidence[];
11
+ more: number;
12
+ };
13
+ export declare function clipQuote(quote: string, max?: number): string;
@@ -0,0 +1,4 @@
1
+ import type { ChunkDetail } from "../types";
2
+ export declare function isSubjectRoot(chunk: ChunkDetail | null | undefined): boolean;
3
+ export declare function entityTypeNames(described: unknown): string[];
4
+ export declare function subjectTypeChoices(inForce: string[], current: string | undefined): string[];