@larc-iu/plaid-client 0.2.0-alpha.3 → 0.2.0-alpha.32

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.
Files changed (73) hide show
  1. package/README.md +39 -0
  2. package/package.json +13 -6
  3. package/src/apiAnnotations.d.ts +508 -0
  4. package/src/apiAnnotations.js +543 -0
  5. package/src/apiDocuments.d.ts +569 -0
  6. package/src/apiDocuments.js +551 -0
  7. package/src/apiLayers.d.ts +369 -0
  8. package/src/apiLayers.js +222 -0
  9. package/src/apiMessages.d.ts +293 -0
  10. package/src/apiMessages.js +265 -0
  11. package/src/apiPeople.d.ts +626 -0
  12. package/src/apiPeople.js +698 -0
  13. package/src/apiProject.d.ts +761 -0
  14. package/src/apiProject.js +774 -0
  15. package/src/apiServer.d.ts +457 -0
  16. package/src/apiServer.js +424 -0
  17. package/src/apiVocab.d.ts +456 -0
  18. package/src/apiVocab.js +425 -0
  19. package/src/batch.d.ts +54 -0
  20. package/src/batch.js +323 -0
  21. package/src/batchRef.d.ts +30 -0
  22. package/src/batchRef.js +128 -0
  23. package/src/client.d.ts +1321 -0
  24. package/src/client.js +743 -0
  25. package/src/codepoint.d.ts +94 -0
  26. package/src/codepoint.js +131 -1
  27. package/src/constraints.d.ts +85 -0
  28. package/src/constraints.js +112 -0
  29. package/src/created.d.ts +2 -0
  30. package/src/created.js +29 -0
  31. package/src/documentLock.d.ts +172 -0
  32. package/src/documentLock.js +384 -0
  33. package/src/entryForms.d.ts +68 -0
  34. package/src/entryForms.js +164 -0
  35. package/src/events.d.ts +60 -0
  36. package/src/events.js +271 -0
  37. package/src/families.d.ts +349 -0
  38. package/src/families.js +396 -0
  39. package/src/http.d.ts +233 -0
  40. package/src/http.js +809 -93
  41. package/src/ids.d.ts +26 -0
  42. package/src/ids.js +96 -0
  43. package/src/index.d.ts +101 -0
  44. package/src/index.js +183 -2105
  45. package/src/metadataOps.d.ts +15 -0
  46. package/src/metadataOps.js +124 -0
  47. package/src/operations.d.ts +36 -0
  48. package/src/operations.js +164 -0
  49. package/src/pagination.d.ts +49 -0
  50. package/src/pagination.js +20 -53
  51. package/src/provenance.d.ts +243 -0
  52. package/src/provenance.js +458 -36
  53. package/src/replayed.d.ts +3 -0
  54. package/src/replayed.js +31 -0
  55. package/src/requester.d.ts +60 -0
  56. package/src/requester.js +74 -0
  57. package/src/roles.d.ts +104 -0
  58. package/src/roles.js +64 -2
  59. package/src/serviceSchema.d.ts +337 -0
  60. package/src/serviceSchema.js +177 -60
  61. package/src/services.d.ts +319 -0
  62. package/src/services.js +742 -58
  63. package/src/sse.d.ts +30 -0
  64. package/src/sse.js +80 -3
  65. package/src/testing.d.ts +128 -0
  66. package/src/testing.js +379 -0
  67. package/src/textEdits.d.ts +59 -0
  68. package/src/textEdits.js +234 -0
  69. package/src/transforms.d.ts +25 -0
  70. package/src/transforms.js +11 -1
  71. package/src/types.d.ts +867 -0
  72. package/src/types.js +663 -0
  73. package/index.d.ts +0 -532
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Provenance: the cross-app convention for distinguishing machine-provided
3
+ * from human-labeled information, expressed as flat metadata keys on
4
+ * annotation entities (spans, relations, vocab links, optionally tokens).
5
+ * Flat scalar keys — the query engine matches flat metadata well, nested
6
+ * objects poorly.
7
+ *
8
+ * Two axes. ORIGIN is the `prov` key: absent means a trusted person (a
9
+ * verifier) made it; 'inferred' means an algorithm or service did;
10
+ * 'contributed' means a person whose work the project reviews (a
11
+ * contributor) did. TRUST is `provConfirmed`: true once a verifier vouched
12
+ * for the value. Together they give four states:
13
+ *
14
+ * human — no prov keys; a verifier made it.
15
+ * machine — { prov: 'inferred', provSource: '<producer>' };
16
+ * an algorithm/service made it, nobody has vouched.
17
+ * contributed — { prov: 'contributed', provSource: 'user:<id>' };
18
+ * a contributor made it, no verifier has vouched.
19
+ * verified — either origin + { provConfirmed: true }; a verifier
20
+ * confirmed (or edited) it. prov/provSource stay so
21
+ * the origin remains traceable.
22
+ *
23
+ * The write contract every machine writer must follow:
24
+ * 1. Machine writers may freely replace MACHINE (unverified) material.
25
+ * 2. Machine writers must never modify or delete human, contributed or
26
+ * verified material unless explicitly told to overwrite (an explicit,
27
+ * per-run, user-facing opt-in — for services, a declared boolean
28
+ * `overwrite` parameter). A contributor's work is a person's work.
29
+ * 3. A verifier's edit of machine or contributed material verifies it:
30
+ * the edit also stamps { provConfirmed: true } (see verifyOnEdit).
31
+ * A contributor's edit of anything marks it contributed: the edit
32
+ * merges stampContributed(userId) and drops any earlier confirmation
33
+ * (see contributeOnEdit). Who is a contributor is the PROJECT's call,
34
+ * recorded once for every app (see "Review" below); a service running
35
+ * as a contributor should stamp likewise.
36
+ *
37
+ * REVIEW: which people are contributors. A project records it under the
38
+ * reserved `plaid` config namespace, so every app that writes on a person's
39
+ * behalf reads the same answer:
40
+ *
41
+ * config.plaid.review = { users: [userId, ...], roles: ['writer', ...] }
42
+ *
43
+ * `users` names people whose work is reviewed whatever their role; `roles`
44
+ * names whole project roles ('reader' | 'writer' | 'maintainer'; an admin
45
+ * without an explicit role counts as a maintainer). Either may be absent.
46
+ * Nothing here grants or denies access: the ACL lists stay the permission
47
+ * model, and this only says whose work needs a verifier's look. Apps expose
48
+ * it as a per-member mark on their access screens (readReview, isReviewed,
49
+ * withReviewedUser) and derive the writer's policy from it (writerPolicy).
50
+ *
51
+ * Producer naming: 'service:<serviceId>' for services (use serviceSource),
52
+ * 'rule:<name>' for built-in rule algorithms, 'user:<userId>' for a
53
+ * contributor (use userSource), app-specific ids like 'gloss:doc-frequency'
54
+ * or 'flex-import' otherwise.
55
+ *
56
+ * PREDICTION EXTRAS. A producer may also record how confident it was and
57
+ * what else it considered, in two reserved slots split along the
58
+ * queryability line:
59
+ * - provProb: ONE flat number in [0, 1] — the producer's probability for
60
+ * the value it chose. Flat scalars are what the query engine filters
61
+ * and orders on, so "review the least-confident machine output first"
62
+ * is an ordinary query. Omit it unless you can honestly produce a
63
+ * probability (a raw logprob is NOT one — put it in provDetail), and
64
+ * calibrate it on held-out data, so that values stated at 70% are
65
+ * right about 70% of the time. Apps mark a value below the project's
66
+ * threshold (readConfidenceThreshold), one number for every producer.
67
+ * - provDetail: ONE open map for everything else — top-k alternatives or
68
+ * distributions, model name/version, raw scores. Deliberately nested
69
+ * (not queryable); keep it small (top-k, not whole-vocabulary dumps).
70
+ * provDetail describes the machine's ORIGINAL prediction and is kept after
71
+ * human edits (history is valuable). provProb is the producer's probability
72
+ * for the value the entity holds, however a person entered it: a value the
73
+ * producer weighed (one in provDetail.valueProbs, or formProbs for a
74
+ * morpheme's form) carries that probability, and a value it never weighed
75
+ * carries none (writerPolicy's valueEditStamp is the one implementation,
76
+ * and it reads the distribution itself). A consumer still must not present
77
+ * provProb as the machine's confidence once the entity is verified
78
+ * (provConfirmed is exactly the flag to check).
79
+ *
80
+ * Recommended provDetail keys, so consumers (review dashboards, ranked
81
+ * alternatives) can read any producer's output:
82
+ * - value (spans) / form (morpheme tokens): the value the producer
83
+ * wrote, mirroring the entity's own field. The entity may be edited
84
+ * later; this copy is what makes "accepted as-is" vs "corrected"
85
+ * answerable once the entity is verified.
86
+ * - valueProbs / formProbs: a top-k {label: probability} map over the
87
+ * alternatives the producer considered, the chosen label included
88
+ * (provProb, when given, is that label's entry duplicated flat).
89
+ * - valueLinks: on a gloss, a list of {value, item, prob}, one per
90
+ * alternative that stands for a lexicon entry: its label, the vocab
91
+ * item id and its probability (two senses may share a label, so this
92
+ * is a list, not a map). igt offers each alternative together with
93
+ * its entry as one choice, under Alt+Down on the gloss and in the
94
+ * lexicon popover.
95
+ * - model: what made the prediction (a model name, or a tool and its
96
+ * release such as 'stanza==1.11.0'), and version: which version of the
97
+ * writer ran ('<release>+<8 hex>', see the manual, "Provenance"). Every
98
+ * machine writer records both, one of rules alone only version.
99
+ * - anything else (language, adapter, raw scores).
100
+ */
101
+ /** The flat metadata keys of the provenance convention. */
102
+ export const PROV: Readonly<{
103
+ /** 'inferred' when produced by an algorithm/service; absent = human. */
104
+ key: "prov";
105
+ /** Which producer, e.g. 'service:<id>', 'rule:precedent-or-unique'. */
106
+ sourceKey: "provSource";
107
+ /** true once a human confirmed (or edited) the inferred value. */
108
+ confirmedKey: "provConfirmed";
109
+ /** Producer's probability ([0,1]) for the chosen value. Flat = queryable. */
110
+ probKey: "provProb";
111
+ /** Open map of producer extras (alternatives, model version, raw scores). */
112
+ detailKey: "provDetail";
113
+ /** `prov` for machine-made material. Any value but CONTRIBUTED reads as machine. */
114
+ INFERRED: "inferred";
115
+ /** `prov` for a contributor's material. */
116
+ CONTRIBUTED: "contributed";
117
+ }>;
118
+ /**
119
+ * Every provenance key, for a caller that has to name them as a set rather
120
+ * than read one: what a token layer declares under
121
+ * `config.plaid.preserveOnSplit` so a token born of a split inherits the
122
+ * origin of the token it came from, and what a reshape carries by hand.
123
+ *
124
+ * Provenance is the one metadata family Plaid itself owns. The user cannot
125
+ * maintain it, and in a shared project usually cannot even see it, since it
126
+ * may belong to an app they are not using. Everything else on an entity is
127
+ * the user's own content and no structural operation should touch it.
128
+ */
129
+ export const PROVENANCE_KEYS: readonly ("prov" | "provSource" | "provConfirmed" | "provProb" | "provDetail")[];
130
+ /** The four provenance states returned by provState. */
131
+ export const PROV_STATES: Readonly<{
132
+ HUMAN: "human";
133
+ MACHINE: "machine";
134
+ CONTRIBUTED: "contributed";
135
+ VERIFIED: "verified";
136
+ }>;
137
+ export function stampInferred(source: string, { prob, detail }?: {
138
+ prob?: number;
139
+ detail?: any;
140
+ }): {
141
+ provDetail?: any;
142
+ provProb?: number;
143
+ prov: "inferred";
144
+ provSource: string;
145
+ };
146
+ export function confirmedInferred(source: string, extras?: {
147
+ prob?: number;
148
+ detail?: Record<string, any>;
149
+ }): {
150
+ provConfirmed: boolean;
151
+ provDetail?: any;
152
+ provProb?: number;
153
+ prov: "inferred";
154
+ provSource: string;
155
+ };
156
+ /**
157
+ * The metadata fragment that verifies machine-made material:
158
+ * { provConfirmed: true }. Merge (PATCH) it over existing metadata so
159
+ * prov/provSource/provProb/provDetail survive. This is what verifyOnEdit
160
+ * returns for machine-unverified material; use it directly for explicit
161
+ * confirmation gestures (a "confirm" button, confirm-on-touch) where the
162
+ * caller has already checked isMachine.
163
+ */
164
+ export const PROV_CONFIRMED: Readonly<{
165
+ provConfirmed: true;
166
+ }>;
167
+ export function stampContributed(userId: string): {
168
+ prov: "contributed";
169
+ provSource: string;
170
+ };
171
+ export function provState(metadata: object | null | undefined): "human" | "machine" | "contributed" | "verified";
172
+ export function provOrigin(metadata: object | null | undefined): null | "inferred" | "contributed";
173
+ export function isMachine(metadata: object | null | undefined): boolean;
174
+ export function isProtected(metadata: object | null | undefined): boolean;
175
+ export function needsReview(metadata: object | null | undefined): boolean;
176
+ export function verifyOnEdit(metadata: object | null | undefined): Readonly<{
177
+ provConfirmed: true;
178
+ }>;
179
+ export function contributeOnEdit(metadata: object | null | undefined, userId: string): {
180
+ prov: "contributed";
181
+ provSource: string;
182
+ provConfirmed: null;
183
+ };
184
+ export function serviceSource(serviceId: string): string;
185
+ export function userSource(userId: string): string;
186
+ /** The config key, under the `plaid` namespace, holding the review lists. */
187
+ export const REVIEW_KEY: "review";
188
+ export function readReview(config?: object | null): {
189
+ users: string[];
190
+ roles: string[];
191
+ };
192
+ export function reviewsAnyone(config?: object | null): boolean;
193
+ export function projectRole(project: object, userId: string, { isAdmin }?: {
194
+ isAdmin?: boolean;
195
+ }): "maintainer" | "writer" | "reader";
196
+ export function isReviewed(project: object | null | undefined, userId: string | null | undefined, { isAdmin }?: {
197
+ isAdmin?: boolean;
198
+ }): boolean;
199
+ export function withReviewedUser(review: {
200
+ users?: string[];
201
+ roles?: string[];
202
+ } | null | undefined, userId: string, reviewed: boolean): {
203
+ users: string[];
204
+ roles: string[];
205
+ };
206
+ /**
207
+ * Key of the project's confidence setting under `config.plaid`:
208
+ * `{ threshold: number in [0, 1] }`. A machine value whose provProb is below
209
+ * the threshold is DOUBTFUL, and both apps give it a heavier mark. Producers
210
+ * write provProb calibrated on held-out data (manual, "Provenance"), so one
211
+ * number serves every service on the project.
212
+ */
213
+ export const CONFIDENCE_KEY: "confidence";
214
+ /** The threshold when a project sets none: below it, a calibrated value is more likely wrong than right. */
215
+ export const DEFAULT_CONFIDENCE_THRESHOLD: 0.5;
216
+ export function readConfidenceThreshold(config?: object | null): number;
217
+ export function machineProb(metadata: object | null | undefined): number | null;
218
+ export function isDoubtful(metadata: object | null | undefined, threshold?: number): boolean;
219
+ /** The provDetail key of a producer's distribution over a span's or relation's value. */
220
+ export const VALUE_PROBS_KEY: "valueProbs";
221
+ /** The provDetail key of a producer's distribution over a morpheme's form. */
222
+ export const FORM_PROBS_KEY: "formProbs";
223
+ export function readValueProbs(metadata: object | null | undefined, key?: string): {
224
+ [x: string]: number;
225
+ } | null;
226
+ export function writerPolicy(contributorId?: string | null): {
227
+ contributorId: string | null;
228
+ isContributor: boolean;
229
+ createStamp: any | null;
230
+ editStamp: (metadata: any) => any | null;
231
+ valueEditStamp: (metadata: any, opts?: {
232
+ changes?: boolean;
233
+ value?: string;
234
+ probsKey?: string;
235
+ prob?: number | null;
236
+ }) => any | null;
237
+ repointStamp: (metadata: any) => any | null;
238
+ confirmStamp: (metadata: any) => any | null;
239
+ confirmFragment: () => any;
240
+ adoptStamp: (source: string, detail?: any) => any;
241
+ reviewable: (metadata: any) => boolean;
242
+ reviewableState: (state: string) => boolean;
243
+ };