@startsimpli/integrations 0.2.137 → 0.2.139

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,92 @@
1
+ /**
2
+ * THE OPEN-QUESTIONS QUEUE (bd startsim-tmrvi.3 / tmrvi.9).
3
+ *
4
+ * One row per (person, item, kind): a thing Tandem is unsure about and has
5
+ * either held back (a team, a private space) or ASSUMED an answer to (a due date,
6
+ * a project, an owner). Rows are tenant-side entities of type `open_question`:
7
+ * the person's own to-dos and the model's doubts about them are tenant-originated
8
+ * data, not something ingested from a remote API.
9
+ */
10
+ export const QUESTION_KINDS = ['team', 'private_space', 'due_date', 'project', 'ownership'] as const;
11
+ export type QuestionKind = (typeof QUESTION_KINDS)[number];
12
+
13
+ export type QuestionStatus = 'open' | 'resolved' | 'expired';
14
+
15
+ /** Why a question left the queue. */
16
+ export type QuestionResolution = 'answered' | 'item_changed' | 'item_closed' | 'item_gone';
17
+
18
+ export interface AssumedValue {
19
+ value: string | null;
20
+ display?: string;
21
+ confidence: number;
22
+ reason: string;
23
+ }
24
+
25
+ export interface QuestionCandidate {
26
+ value: string;
27
+ confidence: number;
28
+ reason: string;
29
+ }
30
+
31
+ export interface OpenQuestion {
32
+ /** The question row's own id. */
33
+ id: string;
34
+ itemId: string;
35
+ kind: QuestionKind;
36
+ question: string;
37
+ status: QuestionStatus;
38
+ /** What Tandem is acting on until it is confirmed; absent for held items. */
39
+ assumed?: AssumedValue;
40
+ candidates: QuestionCandidate[];
41
+ /** Higher is asked first. */
42
+ score: number;
43
+ ownerSub: string;
44
+ noteId?: string;
45
+ resolution?: QuestionResolution;
46
+ createdAt: string;
47
+ updatedAt: string;
48
+ resolvedAt?: string;
49
+ }
50
+
51
+ export interface QuestionAnswer {
52
+ /** A team id, an ISO date (or empty to clear), a focus id, or a member sub. */
53
+ value: string;
54
+ /** Human label for the value (an owner's name). */
55
+ label?: string;
56
+ }
57
+
58
+ /** What the queue needs to know about an item (from its commitment row). */
59
+ export interface ItemView {
60
+ id: string;
61
+ title: string;
62
+ status: string;
63
+ dueAt: string | null;
64
+ focusId: string;
65
+ ownerName: string;
66
+ ownerSub: string;
67
+ noteId?: string;
68
+ openKind: string;
69
+ openText: string;
70
+ }
71
+
72
+ /** A question as derived from the current state of items and notes, before storage. */
73
+ export interface DerivedQuestion {
74
+ itemId: string;
75
+ kind: QuestionKind;
76
+ question: string;
77
+ assumed?: AssumedValue;
78
+ candidates: QuestionCandidate[];
79
+ noteId?: string;
80
+ /** Held items re-ask when the engine holds them again; assumptions are asked once. */
81
+ reopens: boolean;
82
+ }
83
+
84
+ /** The entity type key and attributes the tenant must declare. */
85
+ export const OPEN_QUESTION_TYPE = 'open_question';
86
+ export const OPEN_QUESTION_LABEL = 'Open question';
87
+ export const OPEN_QUESTION_ATTRIBUTES: Array<[string, string]> = [
88
+ ['item_id', 'text'], ['kind', 'text'], ['question', 'text'], ['status', 'text'],
89
+ ['assumed', 'text'], ['candidates', 'text'], ['answer', 'text'], ['score', 'integer'],
90
+ ['owner_sub', 'text'], ['note_id', 'text'], ['resolution', 'text'],
91
+ ['created_at', 'date'], ['updated_at', 'date'], ['resolved_at', 'date'],
92
+ ];
@@ -0,0 +1,89 @@
1
+ /**
2
+ * THE TRACKER'S REAL TEAMS, for the team classifier (bd startsim-6z7vi.7).
3
+ *
4
+ * Extraction needs `listTeams` to place an engineering-sounding item. The teams
5
+ * are what the member's connected task tracker reaches (`choices?kind=team` on
6
+ * their own connection), so this reads them through the member connections api
7
+ * and names no vendor: the first CONNECTED connection whose catalog row says
8
+ * `kind: task_tracker` is the tracker.
9
+ *
10
+ * - a private team, and the member's `personal_container_id`, are never offered:
11
+ * personal work goes there by the engine, business work must not;
12
+ * - the answer is read once per lister, so a run that classifies several slices
13
+ * does not re-walk the tracker;
14
+ * - a failure is thrown, not hidden: extraction already treats a failed team read
15
+ * as "no teams" and holds the items as `needs_team`.
16
+ */
17
+ import type { Connection, MemberConnectionsApi } from '../components/pages/types';
18
+ import { isTaskTracker, readTaskSync, withTaskSync } from '../task-tracker/sync-config';
19
+ import type { TeamCandidate } from './types';
20
+
21
+ const MAX_PAGES = 20;
22
+
23
+ export type TrackerTeamsApi = Pick<MemberConnectionsApi, 'connections' | 'connectorCatalog'> & {
24
+ connectionChoices: NonNullable<MemberConnectionsApi['connectionChoices']>;
25
+ };
26
+
27
+ async function findTracker(api: Pick<MemberConnectionsApi, 'connections' | 'connectorCatalog'>): Promise<Connection | undefined> {
28
+ const [mine, catalog] = await Promise.all([api.connections(), api.connectorCatalog()]);
29
+ const kinds = new Map(catalog.results.map((entry) => [entry.key, entry]));
30
+ return mine.results.find((c) => c.status === 'connected' && isTaskTracker(kinds.get(c.connector_key)));
31
+ }
32
+
33
+ const text = (v: unknown): string => (typeof v === 'string' ? v.trim() : '');
34
+
35
+ export function createTrackerTeamLister(api: TrackerTeamsApi): () => Promise<TeamCandidate[]> {
36
+ let pending: Promise<TeamCandidate[]> | null = null;
37
+
38
+ async function read(): Promise<TeamCandidate[]> {
39
+ const tracker = await findTracker(api);
40
+ if (!tracker) return [];
41
+ const personal = readTaskSync(tracker).personal_container_id;
42
+
43
+ const teams: TeamCandidate[] = [];
44
+ let cursor: string | undefined;
45
+ for (let page = 0; page < MAX_PAGES; page += 1) {
46
+ const res = await api.connectionChoices(tracker.id, { kind: 'team', ...(cursor ? { cursor } : {}) });
47
+ for (const row of res.results) {
48
+ const detail = (row.detail ?? {}) as Record<string, unknown>;
49
+ if (detail.private === true || row.id === personal) continue;
50
+ teams.push({
51
+ id: row.id,
52
+ title: row.label,
53
+ key: text(detail.key) || row.label,
54
+ detail: text(detail.description),
55
+ });
56
+ }
57
+ if (!res.has_more || !res.cursor) break;
58
+ cursor = res.cursor;
59
+ }
60
+ return teams;
61
+ }
62
+
63
+ return () => {
64
+ if (!pending) {
65
+ pending = read().catch((error: unknown) => {
66
+ pending = null;
67
+ throw error;
68
+ });
69
+ }
70
+ return pending;
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Save the member's private space (`personal_container_id`) on their tracker
76
+ * connection: the stored `task_sync` block with the one field laid over it, since
77
+ * the server replaces the block whole.
78
+ */
79
+ export function createPersonalSpaceSetter(
80
+ api: Pick<MemberConnectionsApi, 'connections' | 'connectorCatalog'> & {
81
+ updateConnectionConfig: NonNullable<MemberConnectionsApi['updateConnectionConfig']>;
82
+ },
83
+ ): (containerId: string) => Promise<void> {
84
+ return async (containerId) => {
85
+ const tracker = await findTracker(api);
86
+ if (!tracker) throw new Error('No task tracker is connected.');
87
+ await api.updateConnectionConfig(tracker.id, { task_sync: withTaskSync(tracker, { personal_container_id: containerId }) });
88
+ };
89
+ }