@startsimpli/integrations 0.2.216 → 0.2.217
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/package.json +3 -3
- package/src/__tests__/briefing-timezone-memory.test.ts +56 -0
- package/src/__tests__/corpus-storage.test.ts +6 -0
- package/src/__tests__/corpus-tracker.test.tsx +37 -0
- package/src/__tests__/engine-near-date.test.ts +136 -0
- package/src/__tests__/near-date-ui.test.tsx +74 -0
- package/src/__tests__/shared-with.test.tsx +78 -0
- package/src/__tests__/task-detail.test.tsx +1 -1
- package/src/components/DocumentDetail.tsx +3 -0
- package/src/components/SharedWith.tsx +140 -0
- package/src/components/pages/TaskDetailPage.tsx +4 -2
- package/src/components/pages/TrackerPage.tsx +27 -7
- package/src/components/pages/tracker/PossiblyDone.tsx +28 -2
- package/src/components/pages/tracker/Suggestion.tsx +15 -11
- package/src/components/table/todo-model.ts +3 -0
- package/src/corpus/briefing/generate-weekly.ts +2 -1
- package/src/corpus/briefing/generate.ts +2 -1
- package/src/corpus/briefing/zone.ts +24 -0
- package/src/corpus/client.ts +6 -0
- package/src/corpus/commitments.ts +48 -3
- package/src/corpus/engine/apply.ts +10 -3
- package/src/corpus/engine/decide.ts +3 -2
- package/src/corpus/engine/near-match.ts +71 -0
- package/src/corpus/engine/proposed-due.ts +44 -0
- package/src/corpus/engine/suggestion.ts +5 -0
- package/src/corpus/engine/types.ts +2 -0
- package/src/corpus/entities.ts +13 -0
- package/src/corpus/extract.ts +10 -4
- package/src/corpus/index.ts +2 -0
- package/src/corpus/sharing.ts +132 -0
- package/src/corpus/types.ts +21 -1
|
@@ -17,6 +17,8 @@ export interface Suggestion {
|
|
|
17
17
|
reason: string;
|
|
18
18
|
documentId: string;
|
|
19
19
|
quote: string;
|
|
20
|
+
/** The existing item a merge or link proposal is about (L-NEAR, L-RELATED). */
|
|
21
|
+
targetId?: string;
|
|
20
22
|
/** Set when the owner reviews a suggestion. */
|
|
21
23
|
outcome?: 'accepted' | 'edited' | 'rejected';
|
|
22
24
|
reviewedAt?: string;
|
|
@@ -30,6 +32,7 @@ export function suggestionOf(decision: Decision): Suggestion {
|
|
|
30
32
|
reason: decision.reason,
|
|
31
33
|
documentId: decision.evidence.documentId,
|
|
32
34
|
quote: decision.evidence.quote.slice(0, 400),
|
|
35
|
+
...(decision.targetId ? { targetId: decision.targetId } : {}),
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -50,6 +53,7 @@ export function readSuggestion(raw: unknown): Suggestion | undefined {
|
|
|
50
53
|
reason: String(r.reason ?? ''),
|
|
51
54
|
documentId: String(r.document_id ?? r.documentId ?? ''),
|
|
52
55
|
quote: String(r.quote ?? ''),
|
|
56
|
+
...(r.target_id || r.targetId ? { targetId: String(r.target_id ?? r.targetId) } : {}),
|
|
53
57
|
...(OUTCOMES.has(outcome) ? { outcome: outcome as Suggestion['outcome'] } : {}),
|
|
54
58
|
...(r.reviewed_at || r.reviewedAt ? { reviewedAt: String(r.reviewed_at ?? r.reviewedAt) } : {}),
|
|
55
59
|
};
|
|
@@ -59,6 +63,7 @@ export function writeSuggestion(s: Suggestion): Record<string, unknown> {
|
|
|
59
63
|
return {
|
|
60
64
|
rule: s.rule, mode: s.mode, confidence: s.confidence, reason: s.reason,
|
|
61
65
|
document_id: s.documentId, quote: s.quote,
|
|
66
|
+
...(s.targetId ? { target_id: s.targetId } : {}),
|
|
62
67
|
...(s.outcome ? { outcome: s.outcome } : {}),
|
|
63
68
|
...(s.reviewedAt ? { reviewed_at: s.reviewedAt } : {}),
|
|
64
69
|
};
|
|
@@ -90,6 +90,8 @@ export interface ItemMatch {
|
|
|
90
90
|
itemId: string;
|
|
91
91
|
strength: MatchStrength;
|
|
92
92
|
itemOwnerSub: string | null;
|
|
93
|
+
/** The item's title, for the plain sentence a proposal shows. */
|
|
94
|
+
title?: string;
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
/** "That is done" / "we dropped that", said in a later source. */
|
package/src/corpus/entities.ts
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
import { briefingSections } from './briefing-text';
|
|
26
26
|
import { readPossiblyDone, writePossiblyDone } from './possibly-done';
|
|
27
27
|
import { readSuggestion, writeSuggestion } from './engine/suggestion';
|
|
28
|
+
import { readProposedDue, writeProposedDue } from './engine/proposed-due';
|
|
28
29
|
import { withSourceEntity } from './source-entity';
|
|
29
30
|
import { decodeOwnerSubs, encodeOwnerSubs } from './owner-link';
|
|
30
31
|
import { readItemSync, type ItemSync } from '../task-tracker/item-sync';
|
|
@@ -231,6 +232,14 @@ function asText(value: unknown): string {
|
|
|
231
232
|
return '';
|
|
232
233
|
}
|
|
233
234
|
|
|
235
|
+
/** Did a person set the due date? The tenant stamps `field_edited_at.due_at` on a person's edit (see commitment-edit.ts). */
|
|
236
|
+
function editedDueAt(data: Record<string, unknown>): boolean {
|
|
237
|
+
const stamps = pick(data, 'field_edited_at', 'fieldEditedAt');
|
|
238
|
+
if (!stamps || typeof stamps !== 'object') return false;
|
|
239
|
+
const s = stamps as Record<string, unknown>;
|
|
240
|
+
return Boolean(s.due_at ?? s.dueAt ?? s.DueAt);
|
|
241
|
+
}
|
|
242
|
+
|
|
234
243
|
function asIso(value: unknown): string | null {
|
|
235
244
|
const text = asText(value);
|
|
236
245
|
if (!text) return null;
|
|
@@ -759,6 +768,9 @@ export function toCommitment(
|
|
|
759
768
|
...(readSuggestion(pick(data, 'suggestion')) ? { suggestion: readSuggestion(pick(data, 'suggestion')) } : {}),
|
|
760
769
|
...(readPossiblyDone(pick(data, 'possibly_done', 'possiblyDone')).length
|
|
761
770
|
? { possiblyDone: readPossiblyDone(pick(data, 'possibly_done', 'possiblyDone')) } : {}),
|
|
771
|
+
...(readProposedDue(pick(data, 'proposed_due', 'proposedDue')).length
|
|
772
|
+
? { proposedDue: readProposedDue(pick(data, 'proposed_due', 'proposedDue')) } : {}),
|
|
773
|
+
...(editedDueAt(data) ? { dueSetByPerson: true } : {}),
|
|
762
774
|
firstSeenAt: asIso(pick(data, 'first_seen_at', 'firstSeenAt')),
|
|
763
775
|
lastSeenAt: asIso(pick(data, 'last_seen_at', 'lastSeenAt')),
|
|
764
776
|
extractorVersion: asText(pick(data, 'extractor_version', 'extractorVersion')),
|
|
@@ -851,6 +863,7 @@ export function commitmentToEntity(commitment: Commitment): {
|
|
|
851
863
|
})),
|
|
852
864
|
...(commitment.possiblyDone?.length ? { possibly_done: writePossiblyDone(commitment.possiblyDone) } : {}),
|
|
853
865
|
...(commitment.suggestion ? { suggestion: writeSuggestion(commitment.suggestion) } : {}),
|
|
866
|
+
...(commitment.proposedDue?.length ? { proposed_due: writeProposedDue(commitment.proposedDue) } : {}),
|
|
854
867
|
extractor_version: commitment.extractorVersion,
|
|
855
868
|
source: commitment.source,
|
|
856
869
|
// Marks the row as pipeline-written, the same way the corpus delivery
|
package/src/corpus/extract.ts
CHANGED
|
@@ -431,7 +431,15 @@ export async function extractCommitments(
|
|
|
431
431
|
|
|
432
432
|
// 5. identity, dedupe within the run, then against what is stored.
|
|
433
433
|
const groups = mergeDrafts([...ruleDrafts, ...modelDrafts]);
|
|
434
|
-
|
|
434
|
+
// The owner's own reviews graduate a rule (./engine/graduation); automation never reviews.
|
|
435
|
+
const engineLabels = request.engine
|
|
436
|
+
? request.engine.labels ?? labelsFrom(existing.filter((item) => item.scope?.ownerSub === request.engine!.ownerSub))
|
|
437
|
+
: undefined;
|
|
438
|
+
const reconciled = reconcile(existing, groups, {
|
|
439
|
+
scope: request.scope,
|
|
440
|
+
documents,
|
|
441
|
+
...(request.engine ? { engine: { ownerSub: request.engine.ownerSub, labels: engineLabels } } : {}),
|
|
442
|
+
});
|
|
435
443
|
|
|
436
444
|
// 6. resolutions, against the documents the scope guard approved and nothing else.
|
|
437
445
|
const resolutions = applyResolutions(reconciled.commitments, claims, { documents, proposeOnly: Boolean(request.engine) });
|
|
@@ -492,9 +500,7 @@ export async function extractCommitments(
|
|
|
492
500
|
let written = resolutions.commitments;
|
|
493
501
|
if (request.engine) {
|
|
494
502
|
const ownerNames = [...new Set([...request.engine.ownerNames, ...ownerNamesFrom(existing, request.engine.ownerSub)])];
|
|
495
|
-
|
|
496
|
-
const labels = request.engine.labels ?? labelsFrom(existing.filter((item) => item.scope?.ownerSub === request.engine!.ownerSub));
|
|
497
|
-
policy = applyPolicy(fresh, { scope: { ...request.engine, ownerNames, labels }, documents });
|
|
503
|
+
policy = applyPolicy(fresh, { scope: { ...request.engine, ownerNames, labels: engineLabels }, documents, matches: reconciled.matches });
|
|
498
504
|
const kept = new Map(policy.kept.map((item) => [item.externalId, item]));
|
|
499
505
|
written = resolutions.commitments.flatMap((item) =>
|
|
500
506
|
freshIds.has(item.externalId) ? (kept.has(item.externalId) ? [kept.get(item.externalId)!] : []) : [item]);
|
package/src/corpus/index.ts
CHANGED
|
@@ -228,6 +228,8 @@ export {
|
|
|
228
228
|
} from './voice-sections';
|
|
229
229
|
export type { SaveCommitmentsOptions } from './types';
|
|
230
230
|
export type { DocumentFiling } from './filing';
|
|
231
|
+
export { createSharingApi } from './sharing';
|
|
232
|
+
export type { RecordShare, RecordShares, ShareChoices, ShareKind, ShareLevel } from './sharing';
|
|
231
233
|
|
|
232
234
|
export {
|
|
233
235
|
VOICE_SOURCE,
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHARING A RECORD WITH PEOPLE, A TEAM, OR THE WHOLE ORGANISATION (Todo ENG-158).
|
|
3
|
+
*
|
|
4
|
+
* A record is private to whoever it belongs to until they share it. One row in the
|
|
5
|
+
* tenant's `grants` table is one share; its `subject_type` says who it names:
|
|
6
|
+
*
|
|
7
|
+
* user -> one colleague (subject_id = their sub)
|
|
8
|
+
* group -> a team (subject_id = the team slug)
|
|
9
|
+
* org -> everyone in the caller's own organisation (subject_id = the org)
|
|
10
|
+
*
|
|
11
|
+
* Nothing here is named after a company or a product: the people, teams and
|
|
12
|
+
* organisation come from the tenant (`/org/roster/`, `/org/teams/`, `/whoami/`).
|
|
13
|
+
* "Everyone in the subtree" is deliberately not offered.
|
|
14
|
+
*/
|
|
15
|
+
import type { CorpusHttp } from './client';
|
|
16
|
+
|
|
17
|
+
export type ShareKind = 'user' | 'group' | 'org';
|
|
18
|
+
export type ShareLevel = 'viewer' | 'editor';
|
|
19
|
+
|
|
20
|
+
export interface RecordShare {
|
|
21
|
+
/** The grant row, for removing it. */
|
|
22
|
+
id: string;
|
|
23
|
+
kind: ShareKind;
|
|
24
|
+
subjectId: string;
|
|
25
|
+
level: ShareLevel;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ShareChoices {
|
|
29
|
+
/** The caller's own organisation: the id a whole-organisation share names. */
|
|
30
|
+
org?: { id: string; label: string };
|
|
31
|
+
people: Array<{ id: string; label: string }>;
|
|
32
|
+
teams: Array<{ id: string; label: string }>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface RecordShares {
|
|
36
|
+
shares: RecordShare[];
|
|
37
|
+
/** False when this caller may read the record but not change who else can. */
|
|
38
|
+
canShare: boolean;
|
|
39
|
+
reason?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SharingPaths {
|
|
43
|
+
grants?: string;
|
|
44
|
+
roster?: string;
|
|
45
|
+
teams?: string;
|
|
46
|
+
whoami?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const DEFAULTS: Required<SharingPaths> = {
|
|
50
|
+
grants: '/api/v1/grants/',
|
|
51
|
+
roster: '/api/v1/org/roster/',
|
|
52
|
+
teams: '/api/v1/org/teams/',
|
|
53
|
+
whoami: '/api/v1/whoami/',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
type Obj = Record<string, unknown>;
|
|
57
|
+
const str = (v: unknown) => (typeof v === 'string' ? v : '');
|
|
58
|
+
const rows = (body: unknown): Obj[] => {
|
|
59
|
+
const list = Array.isArray(body) ? body : (body as { results?: unknown })?.results;
|
|
60
|
+
return Array.isArray(list) ? (list.filter((r) => r && typeof r === 'object') as Obj[]) : [];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const KINDS: ShareKind[] = ['user', 'group', 'org'];
|
|
64
|
+
|
|
65
|
+
export async function listRecordShares(
|
|
66
|
+
http: CorpusHttp, documentId: string, paths: SharingPaths = {},
|
|
67
|
+
): Promise<RecordShares> {
|
|
68
|
+
const p = { ...DEFAULTS, ...paths };
|
|
69
|
+
const body = await http.get<unknown>(p.grants, { params: { entity: documentId, page_size: 100 } });
|
|
70
|
+
const envelope = (body ?? {}) as { may_share?: boolean; may_share_reason?: string };
|
|
71
|
+
const shares: RecordShare[] = [];
|
|
72
|
+
for (const row of rows(body)) {
|
|
73
|
+
const kind = str(row.subject_type) as ShareKind;
|
|
74
|
+
if (!KINDS.includes(kind)) continue; // a public link is publishing, not sharing
|
|
75
|
+
shares.push({
|
|
76
|
+
id: str(row.id), kind, subjectId: str(row.subject_id),
|
|
77
|
+
level: str(row.level) === 'editor' ? 'editor' : 'viewer',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return { shares, canShare: envelope.may_share === true, reason: envelope.may_share_reason || undefined };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function addRecordShare(
|
|
84
|
+
http: CorpusHttp, documentId: string, target: { kind: ShareKind; subjectId: string; level?: ShareLevel },
|
|
85
|
+
paths: SharingPaths = {},
|
|
86
|
+
): Promise<void> {
|
|
87
|
+
const p = { ...DEFAULTS, ...paths };
|
|
88
|
+
if (!http.post) throw new Error('This client cannot share records.');
|
|
89
|
+
await http.post(p.grants, {
|
|
90
|
+
entity: documentId, subject_type: target.kind, subject_id: target.subjectId,
|
|
91
|
+
level: target.level ?? 'viewer',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function removeRecordShare(
|
|
96
|
+
http: CorpusHttp, shareId: string, paths: SharingPaths = {},
|
|
97
|
+
): Promise<void> {
|
|
98
|
+
const p = { ...DEFAULTS, ...paths };
|
|
99
|
+
if (!http.delete) throw new Error('This client cannot change sharing.');
|
|
100
|
+
await http.delete(`${p.grants}${encodeURIComponent(shareId)}/`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Who a record can be shared with. A list that fails to load is empty, not fatal. */
|
|
104
|
+
export async function listShareChoices(
|
|
105
|
+
http: CorpusHttp, paths: SharingPaths = {},
|
|
106
|
+
): Promise<ShareChoices> {
|
|
107
|
+
const p = { ...DEFAULTS, ...paths };
|
|
108
|
+
const [who, roster, teams] = await Promise.all([
|
|
109
|
+
http.get<unknown>(p.whoami).catch(() => null),
|
|
110
|
+
http.get<unknown>(p.roster, { params: { page_size: 100 } }).catch(() => null),
|
|
111
|
+
http.get<unknown>(p.teams).catch(() => null),
|
|
112
|
+
]);
|
|
113
|
+
const w = (who ?? {}) as Obj;
|
|
114
|
+
const orgId = str(w.org_id) || str((w.org as Obj | undefined)?.id) || str(w.org);
|
|
115
|
+
return {
|
|
116
|
+
org: orgId ? { id: orgId, label: str(w.org_name) || 'Everyone in my organisation' } : undefined,
|
|
117
|
+
people: rows(roster).map((r) => ({ id: str(r.sub), label: str(r.label) || str(r.sub) })).filter((r) => r.id),
|
|
118
|
+
teams: rows(teams).map((r) => ({ id: str(r.slug), label: str(r.name) || str(r.slug) })).filter((r) => r.id),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function createSharingApi(http: CorpusHttp, paths: SharingPaths = {}) {
|
|
123
|
+
return {
|
|
124
|
+
listRecordShares: (documentId: string) => listRecordShares(http, documentId, paths),
|
|
125
|
+
listShareChoices: () => listShareChoices(http, paths),
|
|
126
|
+
...(http.post
|
|
127
|
+
? { addRecordShare: (documentId: string, target: { kind: ShareKind; subjectId: string; level?: ShareLevel }) =>
|
|
128
|
+
addRecordShare(http, documentId, target, paths) }
|
|
129
|
+
: {}),
|
|
130
|
+
...(http.delete ? { removeRecordShare: (shareId: string) => removeRecordShare(http, shareId, paths) } : {}),
|
|
131
|
+
};
|
|
132
|
+
}
|
package/src/corpus/types.ts
CHANGED
|
@@ -426,6 +426,8 @@ export interface ListSourcesOptions {
|
|
|
426
426
|
* What the composers are handed. An app implements it over its own HTTP client;
|
|
427
427
|
* `createCorpusApi` in `./client` does that for the tenant `/api/v1/*` endpoints.
|
|
428
428
|
*/
|
|
429
|
+
import type { RecordShares, ShareChoices, ShareKind, ShareLevel } from './sharing';
|
|
430
|
+
|
|
429
431
|
export interface CorpusApi {
|
|
430
432
|
/**
|
|
431
433
|
* One page of documents. `options.participants: false` returns the rows WITHOUT
|
|
@@ -476,6 +478,15 @@ export interface CorpusApi {
|
|
|
476
478
|
fileDocument?(documentId: string, focusId: string | null): Promise<void>;
|
|
477
479
|
/** The projects a document can be filed under. */
|
|
478
480
|
listFocusChoices?(): Promise<Array<{ id: string; title: string }>>;
|
|
481
|
+
/**
|
|
482
|
+
* SHARING (Todo ENG-158) — who may read a record beyond its owner. All optional:
|
|
483
|
+
* a client that cannot read shows nothing; one that cannot write shows the line
|
|
484
|
+
* without the menu.
|
|
485
|
+
*/
|
|
486
|
+
listRecordShares?(documentId: string): Promise<RecordShares>;
|
|
487
|
+
listShareChoices?(): Promise<ShareChoices>;
|
|
488
|
+
addRecordShare?(documentId: string, target: { kind: ShareKind; subjectId: string; level?: ShareLevel }): Promise<void>;
|
|
489
|
+
removeRecordShare?(shareId: string): Promise<void>;
|
|
479
490
|
/**
|
|
480
491
|
* Optional because a tenant with no payment connector has no money events, and
|
|
481
492
|
* a corpus surface that requires one would fail the Dropbox-only test.
|
|
@@ -839,6 +850,10 @@ export interface Commitment {
|
|
|
839
850
|
possiblyDone?: PossiblyDone[];
|
|
840
851
|
/** The engine decision that put this item here, and the owner's review of it (bd startsim-vrmx5). */
|
|
841
852
|
suggestion?: import('./engine/suggestion').Suggestion;
|
|
853
|
+
/** A later source states a different date; the owner decides (bd startsim-81mzy). `dueAt` is untouched. */
|
|
854
|
+
proposedDue?: import('./engine/proposed-due').ProposedDue[];
|
|
855
|
+
/** A person set the due date, so a source never proposes over it (the tenant's `field_edited_at.due_at`). */
|
|
856
|
+
dueSetByPerson?: boolean;
|
|
842
857
|
firstSeenAt: string | null;
|
|
843
858
|
lastSeenAt: string | null;
|
|
844
859
|
/** Which extractor produced it, so a later one can re-derive without orphaning. */
|
|
@@ -944,6 +959,11 @@ export interface CommitmentQuery {
|
|
|
944
959
|
status?: CommitmentStatus | CommitmentStatus[];
|
|
945
960
|
subtype?: CommitmentSubtype | CommitmentSubtype[];
|
|
946
961
|
owner?: string;
|
|
962
|
+
/**
|
|
963
|
+
* Only the items this member owns (central user id). A SERVER filter on `attr.owner_sub` (declared on
|
|
964
|
+
* every tenant; `owner_subs` is not, and the tenant refuses it). Unlike `owner` it matches the person, not a spelling of the name.
|
|
965
|
+
*/
|
|
966
|
+
ownerSub?: string;
|
|
947
967
|
/** ISO instants over `dueAt`. */
|
|
948
968
|
dueBefore?: string;
|
|
949
969
|
/** ISO instant over `lastSeenAt` — "what changed since last week". */
|
|
@@ -1000,7 +1020,7 @@ export interface CommitmentApi {
|
|
|
1000
1020
|
*/
|
|
1001
1021
|
updateCommitment?(item: Commitment, patch: Partial<Pick<Commitment,
|
|
1002
1022
|
'status' | 'statusReason' | 'ownerName' | 'ownerSub' | 'ownerSubs' | 'dueAt' | 'subtype'
|
|
1003
|
-
| 'title' | 'detail' | 'resolvedAt' | 'possiblyDone' | 'suggestion'>> & {
|
|
1023
|
+
| 'title' | 'detail' | 'resolvedAt' | 'possiblyDone' | 'suggestion' | 'proposedDue'>> & {
|
|
1004
1024
|
/** `private` hides the item from everyone but its owner; `null` makes it shared again. */
|
|
1005
1025
|
visibility?: 'private' | null;
|
|
1006
1026
|
/** `null` clears it (undoing a voice-set priority). */
|