@startsimpli/integrations 0.2.215 → 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 +5 -5
- package/src/__tests__/briefing-record-library.test.ts +47 -0
- 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__/engine-scheduled-run.test.ts +8 -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/briefing-text.ts +11 -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 +15 -1
- package/src/corpus/extract.ts +10 -4
- package/src/corpus/index.ts +2 -0
- package/src/corpus/retrieval.ts +3 -0
- package/src/corpus/runs.ts +10 -1
- package/src/corpus/sharing.ts +132 -0
- package/src/corpus/types.ts +22 -2
|
@@ -15,7 +15,7 @@ import { decide } from './decide';
|
|
|
15
15
|
import { suggestionOf } from './suggestion';
|
|
16
16
|
import { SUGGESTED_STATUS } from '../item-status';
|
|
17
17
|
import type { Commitment, SourceDocument } from '../types';
|
|
18
|
-
import type { DecisionLabel, OwnerRelation, RuleId } from './types';
|
|
18
|
+
import type { DecisionLabel, ItemMatch, OwnerRelation, RuleId } from './types';
|
|
19
19
|
|
|
20
20
|
export interface EngineScope {
|
|
21
21
|
/** The person the pass runs for; every source must be theirs. */
|
|
@@ -63,7 +63,10 @@ export function ownerNamesFrom(items: Array<Pick<Commitment, 'ownerName' | 'owne
|
|
|
63
63
|
return [...counts].filter(([, n]) => n >= 2).sort((a, b) => b[1] - a[1]).map(([name]) => name);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export function applyPolicy(
|
|
66
|
+
export function applyPolicy(
|
|
67
|
+
fresh: Commitment[],
|
|
68
|
+
context: { scope: EngineScope; documents: SourceDocument[]; matches?: Record<string, ItemMatch> },
|
|
69
|
+
): PolicyOutcome {
|
|
67
70
|
const { scope } = context;
|
|
68
71
|
const byId = new Map(context.documents.map((doc) => [doc.id, doc]));
|
|
69
72
|
const out: PolicyOutcome = { kept: [], acted: 0, proposed: 0, skipped: {} };
|
|
@@ -90,13 +93,17 @@ export function applyPolicy(fresh: Commitment[], context: { scope: EngineScope;
|
|
|
90
93
|
const people = doc ? (doc.participants.length || doc.participantCount || 0) : 0;
|
|
91
94
|
return people > 0 ? people - 1 : 2;
|
|
92
95
|
})(),
|
|
93
|
-
match: null,
|
|
96
|
+
match: context.matches?.[item.externalId] ?? null,
|
|
94
97
|
}, { ownerSub: scope.ownerSub }, scope.labels ?? []);
|
|
95
98
|
|
|
96
99
|
if (decision.mode === 'skip') {
|
|
97
100
|
out.skipped[decision.rule] = (out.skipped[decision.rule] ?? 0) + 1;
|
|
98
101
|
continue;
|
|
99
102
|
}
|
|
103
|
+
// A merge or a link is never done silently: accepting one has to move mentions
|
|
104
|
+
// onto another row, which only the owner's "yes" (and the next pass) does.
|
|
105
|
+
const proposedOnly = decision.verb === 'merge' || decision.verb === 'link' ? decision.rule !== 'L-EXACT' : false;
|
|
106
|
+
if (proposedOnly) decision.mode = 'propose';
|
|
100
107
|
const kept: Commitment = { ...item, suggestion: suggestionOf(decision) };
|
|
101
108
|
if (owner === 'self' && !kept.ownerSub) kept.ownerSub = scope.ownerSub;
|
|
102
109
|
if (decision.mode === 'propose') {
|
|
@@ -74,8 +74,9 @@ function decideItem(candidate: ItemCandidate, context: DecisionContext, fire: Fi
|
|
|
74
74
|
// owner's own, or nothing (bd startsim-vrmx5; isolation audit, 2026-11-24).
|
|
75
75
|
const match = sameOwner(candidate.match, context) ? candidate.match! : null;
|
|
76
76
|
if (match?.strength === 'exact') return fire('L-EXACT', match.itemId);
|
|
77
|
-
|
|
78
|
-
if (match?.strength === '
|
|
77
|
+
const about = match?.title ? ` “${match.title}”` : ' an item you have';
|
|
78
|
+
if (match?.strength === 'anchored') return fire('L-NEAR', match.itemId, `Looks like${about}: same subject, nearly the same wording.`);
|
|
79
|
+
if (match?.strength === 'unanchored') return fire('L-RELATED', match.itemId, `Close to${about}, but a different subject.`);
|
|
79
80
|
|
|
80
81
|
if (candidate.owner === 'other') return fire('C-WAITING');
|
|
81
82
|
if (candidate.owner === 'none') return fire('C-UNOWNED');
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NEAR MATCHES AND STATED DATES, as the policy sees them (bd startsim-81mzy,
|
|
3
|
+
* Todo: ENG-151). `reconcile` reports what it found; `decide` judges it. This
|
|
4
|
+
* module is the plumbing between the two, shared by the write path and the dry run.
|
|
5
|
+
*/
|
|
6
|
+
import { decide } from './decide';
|
|
7
|
+
import { SUGGESTED_STATUS } from '../item-status';
|
|
8
|
+
import { matchStrength, identityOf } from '../commitments';
|
|
9
|
+
import type { CommitmentIdentity } from '../commitments';
|
|
10
|
+
import { pendingProposals, withProposal } from './proposed-due';
|
|
11
|
+
import type { Commitment, SourceDocument } from '../types';
|
|
12
|
+
import type { DecisionLabel, ItemMatch } from './types';
|
|
13
|
+
|
|
14
|
+
const RANK = { anchored: 2, unanchored: 1 } as const;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The best OPEN item of this owner's that a statement is near, but not identical
|
|
18
|
+
* to. Never another owner's item, and never a suggestion or a closed row: a
|
|
19
|
+
* merge onto something the owner has not accepted (or has dismissed) means nothing.
|
|
20
|
+
*/
|
|
21
|
+
export function nearMatchOf(items: Commitment[], identity: CommitmentIdentity, ownerSub: string): ItemMatch | null {
|
|
22
|
+
let best: ItemMatch | null = null;
|
|
23
|
+
for (const item of items) {
|
|
24
|
+
if (item.scope?.ownerSub !== ownerSub) continue;
|
|
25
|
+
if (item.status === SUGGESTED_STATUS || item.status === 'done' || item.status === 'dropped') continue;
|
|
26
|
+
const strength = matchStrength(identityOf(item), identity);
|
|
27
|
+
if (strength !== 'anchored' && strength !== 'unanchored') continue;
|
|
28
|
+
if (!best || RANK[strength] > RANK[best.strength as 'anchored' | 'unanchored']) {
|
|
29
|
+
best = { itemId: item.externalId, strength, itemOwnerSub: item.scope?.ownerSub ?? null, title: item.title };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return best;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const day = (iso: string | null | undefined) => (iso ?? '').slice(0, 10);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A source states a date for an item that already exists. The policy answers:
|
|
39
|
+
* leave it (a person set it, or it is the same date), set it (a graduated rule),
|
|
40
|
+
* or keep it on the item as a proposal. Returns whether the item changed.
|
|
41
|
+
*/
|
|
42
|
+
export function judgeStatedDate(
|
|
43
|
+
item: Commitment,
|
|
44
|
+
stated: { dueAt: string; documentId: string; quote: string },
|
|
45
|
+
document: SourceDocument,
|
|
46
|
+
engine: { ownerSub: string; labels?: readonly DecisionLabel[] },
|
|
47
|
+
extras: { basis?: string; confidence?: number } = {},
|
|
48
|
+
): boolean {
|
|
49
|
+
if (day(item.dueAt) === day(stated.dueAt)) return false;
|
|
50
|
+
const decision = decide({
|
|
51
|
+
kind: 'date',
|
|
52
|
+
documentId: stated.documentId,
|
|
53
|
+
documentOwnerSub: document.scope?.ownerSub ?? null,
|
|
54
|
+
documentSource: String(document.source ?? ''),
|
|
55
|
+
quote: stated.quote,
|
|
56
|
+
itemId: item.externalId,
|
|
57
|
+
dueAt: stated.dueAt,
|
|
58
|
+
humanEdited: item.dueSetByPerson ? ['due_at'] : [],
|
|
59
|
+
}, { ownerSub: engine.ownerSub }, engine.labels ?? []);
|
|
60
|
+
if (decision.mode === 'skip') return false;
|
|
61
|
+
if (decision.mode === 'act') {
|
|
62
|
+
item.dueAt = stated.dueAt;
|
|
63
|
+
if (extras.basis) item.dueBasis = extras.basis;
|
|
64
|
+
if (extras.confidence !== undefined) item.dueConfidence = extras.confidence;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
const next = withProposal(item.proposedDue, { dueAt: stated.dueAt, documentId: stated.documentId, quote: stated.quote, state: 'pending' });
|
|
68
|
+
if (!next) return false;
|
|
69
|
+
item.proposedDue = next;
|
|
70
|
+
return pendingProposals(next).length > 0;
|
|
71
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A DATE A LATER SOURCE STATES, kept ON the item it is about (bd startsim-81mzy,
|
|
3
|
+
* Todo: ENG-151) until the owner decides. Same shape of idea as "possibly done":
|
|
4
|
+
* one proposal per (item, source document), and a decided one is remembered so a
|
|
5
|
+
* re-sweep of the same document does not raise it again. Nothing here changes `dueAt`.
|
|
6
|
+
*/
|
|
7
|
+
export interface ProposedDue {
|
|
8
|
+
dueAt: string;
|
|
9
|
+
documentId: string;
|
|
10
|
+
quote: string;
|
|
11
|
+
state: 'pending' | 'dismissed';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const text = (v: unknown): string => (typeof v === 'string' ? v : v == null ? '' : String(v));
|
|
15
|
+
|
|
16
|
+
export function readProposedDue(raw: unknown): ProposedDue[] {
|
|
17
|
+
if (!Array.isArray(raw)) return [];
|
|
18
|
+
const out: ProposedDue[] = [];
|
|
19
|
+
for (const entry of raw) {
|
|
20
|
+
if (!entry || typeof entry !== 'object') continue;
|
|
21
|
+
const e = entry as Record<string, unknown>;
|
|
22
|
+
const dueAt = text(e.due_at ?? e.dueAt);
|
|
23
|
+
const documentId = text(e.document_id ?? e.documentId);
|
|
24
|
+
if (!documentId || !dueAt || Number.isNaN(Date.parse(dueAt))) continue;
|
|
25
|
+
out.push({ dueAt, documentId, quote: text(e.quote), state: e.state === 'dismissed' ? 'dismissed' : 'pending' });
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const writeProposedDue = (list: ProposedDue[]): Array<Record<string, unknown>> =>
|
|
31
|
+
list.map((p) => ({ due_at: p.dueAt, document_id: p.documentId, quote: p.quote.slice(0, 400), state: p.state }));
|
|
32
|
+
|
|
33
|
+
/** The list with `proposal` added, unless this document already has one (pending or decided). */
|
|
34
|
+
export function withProposal(existing: ProposedDue[] | undefined, proposal: ProposedDue): ProposedDue[] | null {
|
|
35
|
+
const list = existing ?? [];
|
|
36
|
+
if (list.some((p) => p.documentId === proposal.documentId)) return null;
|
|
37
|
+
return [...list, proposal];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const pendingProposals = (list: ProposedDue[] | undefined): ProposedDue[] =>
|
|
41
|
+
(list ?? []).filter((p) => p.state === 'pending');
|
|
42
|
+
|
|
43
|
+
export const dismissProposal = (list: ProposedDue[] | undefined, documentId: string): ProposedDue[] =>
|
|
44
|
+
(list ?? []).map((p) => (p.documentId === documentId ? { ...p, state: 'dismissed' as const } : p));
|
|
@@ -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
|
@@ -22,8 +22,10 @@
|
|
|
22
22
|
* blanks itself because an attribute was renamed is worse than one that shows a
|
|
23
23
|
* row with a missing subtitle.
|
|
24
24
|
*/
|
|
25
|
+
import { briefingSections } from './briefing-text';
|
|
25
26
|
import { readPossiblyDone, writePossiblyDone } from './possibly-done';
|
|
26
27
|
import { readSuggestion, writeSuggestion } from './engine/suggestion';
|
|
28
|
+
import { readProposedDue, writeProposedDue } from './engine/proposed-due';
|
|
27
29
|
import { withSourceEntity } from './source-entity';
|
|
28
30
|
import { decodeOwnerSubs, encodeOwnerSubs } from './owner-link';
|
|
29
31
|
import { readItemSync, type ItemSync } from '../task-tracker/item-sync';
|
|
@@ -230,6 +232,14 @@ function asText(value: unknown): string {
|
|
|
230
232
|
return '';
|
|
231
233
|
}
|
|
232
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
|
+
|
|
233
243
|
function asIso(value: unknown): string | null {
|
|
234
244
|
const text = asText(value);
|
|
235
245
|
if (!text) return null;
|
|
@@ -517,7 +527,7 @@ export function toSourceDocument(
|
|
|
517
527
|
const summary = asText(pick(data, 'summary', 'description'));
|
|
518
528
|
const fullText = asText(pick(data, 'body', 'text', 'content'));
|
|
519
529
|
|
|
520
|
-
const sections = toSections(pick(data, 'sections'));
|
|
530
|
+
const sections = [...toSections(pick(data, 'sections')), ...briefingSections(data)];
|
|
521
531
|
// A source that stored its long-form under a bare attribute rather than in
|
|
522
532
|
// `sections` still contributes one. Listed keys are storage spellings, not
|
|
523
533
|
// vendor knowledge: the same loop picks up a Drive connector's `extracted_text`.
|
|
@@ -758,6 +768,9 @@ export function toCommitment(
|
|
|
758
768
|
...(readSuggestion(pick(data, 'suggestion')) ? { suggestion: readSuggestion(pick(data, 'suggestion')) } : {}),
|
|
759
769
|
...(readPossiblyDone(pick(data, 'possibly_done', 'possiblyDone')).length
|
|
760
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 } : {}),
|
|
761
774
|
firstSeenAt: asIso(pick(data, 'first_seen_at', 'firstSeenAt')),
|
|
762
775
|
lastSeenAt: asIso(pick(data, 'last_seen_at', 'lastSeenAt')),
|
|
763
776
|
extractorVersion: asText(pick(data, 'extractor_version', 'extractorVersion')),
|
|
@@ -850,6 +863,7 @@ export function commitmentToEntity(commitment: Commitment): {
|
|
|
850
863
|
})),
|
|
851
864
|
...(commitment.possiblyDone?.length ? { possibly_done: writePossiblyDone(commitment.possiblyDone) } : {}),
|
|
852
865
|
...(commitment.suggestion ? { suggestion: writeSuggestion(commitment.suggestion) } : {}),
|
|
866
|
+
...(commitment.proposedDue?.length ? { proposed_due: writeProposedDue(commitment.proposedDue) } : {}),
|
|
853
867
|
extractor_version: commitment.extractorVersion,
|
|
854
868
|
source: commitment.source,
|
|
855
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,
|
package/src/corpus/retrieval.ts
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
* what was dropped is surfaced rather than swallowed, because a non-zero drop is
|
|
30
30
|
* a bug somewhere upstream that someone needs to see.
|
|
31
31
|
*/
|
|
32
|
+
import { BRIEFING_SOURCE_KEY } from './briefing-text';
|
|
32
33
|
import { stem } from './text';
|
|
33
34
|
import type { CorpusScope, RetrievedDocument, SourceDocument } from './types';
|
|
34
35
|
|
|
@@ -394,6 +395,8 @@ export function rankDocuments(
|
|
|
394
395
|
options: RetrieveOptions = {},
|
|
395
396
|
): RetrievedDocument[] {
|
|
396
397
|
const { limit = 8, now = Date.now(), minScore = 0.0001 } = options;
|
|
398
|
+
// A briefing is a view of the to-dos, never a source of them: Ask does not read it.
|
|
399
|
+
documents = documents.filter((document) => document.source !== BRIEFING_SOURCE_KEY);
|
|
397
400
|
const { include, exclude } = questionTerms(question);
|
|
398
401
|
const terms = new Set(include);
|
|
399
402
|
if (terms.size === 0) {
|
package/src/corpus/runs.ts
CHANGED
|
@@ -297,6 +297,15 @@ export function newExtractionRun(input: {
|
|
|
297
297
|
* • anything else → a new sweep, from the first document, with the previous
|
|
298
298
|
* one filed in `history`.
|
|
299
299
|
*/
|
|
300
|
+
/**
|
|
301
|
+
* A run record is readable more widely than the notes it was made from, so it keeps
|
|
302
|
+
* only WHICH item and document need review; the words stay on the item itself, as
|
|
303
|
+
* its "possibly done" claim, under the item's own privacy (bd startsim-vrmx5).
|
|
304
|
+
*/
|
|
305
|
+
export function reviewRefs(list: ReadonlyArray<{ commitmentId: string; documentId: string; quote?: string }> = []) {
|
|
306
|
+
return list.map(({ commitmentId, documentId }) => ({ commitmentId, documentId }));
|
|
307
|
+
}
|
|
308
|
+
|
|
300
309
|
export async function startExtractionRun(
|
|
301
310
|
request: StartExtractionRunRequest,
|
|
302
311
|
deps: ExtractionRunDeps,
|
|
@@ -436,7 +445,7 @@ export async function advanceExtractionRun(
|
|
|
436
445
|
modelIncompleteIds: result.modelFailure
|
|
437
446
|
? capped([...run.modelIncompleteIds, ...result.documentIds], config.idLimit)
|
|
438
447
|
: run.modelIncompleteIds,
|
|
439
|
-
needsReview: capped([...run.needsReview, ...result.needsReview], config.idLimit),
|
|
448
|
+
needsReview: capped([...reviewRefs(run.needsReview), ...reviewRefs(result.needsReview)], config.idLimit),
|
|
440
449
|
// WHAT ANSWERED beats what was configured, and a slice where nothing
|
|
441
450
|
// answered must not overwrite the name of the model that did.
|
|
442
451
|
provider: result.provider.live ? result.provider : run.provider,
|
|
@@ -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). */
|
|
@@ -1336,7 +1356,7 @@ export interface ExtractionRun {
|
|
|
1336
1356
|
processedIds: string[];
|
|
1337
1357
|
/** Documents that got the deterministic pass only, because the model did not answer. */
|
|
1338
1358
|
modelIncompleteIds: string[];
|
|
1339
|
-
needsReview: Array<{ commitmentId: string; documentId: string; quote
|
|
1359
|
+
needsReview: Array<{ commitmentId: string; documentId: string; quote?: string }>;
|
|
1340
1360
|
provider: LlmDescription;
|
|
1341
1361
|
startedAt: string;
|
|
1342
1362
|
updatedAt: string;
|