@startsimpli/integrations 0.2.60 → 0.2.61
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__/filed-under-multi.test.tsx +33 -0
- package/src/__tests__/fixtures/voice-multitopic.ts +60 -0
- package/src/__tests__/voice-eval.test.ts +32 -0
- package/src/__tests__/voice-notes-page.test.tsx +36 -0
- package/src/__tests__/voice-quality.test.ts +1 -1
- package/src/__tests__/voice-sections.test.ts +306 -0
- package/src/components/FiledUnder.tsx +19 -13
- package/src/components/pages/VoiceNotesPage.tsx +42 -14
- package/src/corpus/client.ts +9 -2
- package/src/corpus/commitments.ts +5 -0
- package/src/corpus/entities.ts +4 -0
- package/src/corpus/extract.ts +24 -4
- package/src/corpus/filing.ts +57 -0
- package/src/corpus/index.ts +11 -0
- package/src/corpus/llm.ts +35 -10
- package/src/corpus/types.ts +23 -1
- package/src/corpus/voice-sections.ts +140 -0
- package/src/corpus/voice.ts +86 -20
package/src/corpus/voice.ts
CHANGED
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
* be a second copy of the same fact that disagrees the first time someone
|
|
15
15
|
* changes it in Planning.
|
|
16
16
|
*
|
|
17
|
+
* A NOTE CAN BE ABOUT SEVERAL PROJECTS (bd startsim-ij1lw.6): it has one
|
|
18
|
+
* `about_focus` edge per distinct section project, and the sections themselves
|
|
19
|
+
* (label, kind, project) live in `voice_sections` — see ./voice-sections.
|
|
20
|
+
*
|
|
17
21
|
* THE MODEL ONLY EVER CHOOSES FROM A LIST IT WAS GIVEN. Focus ids are echoed
|
|
18
22
|
* back and validated against that list; an id it invented, or `null`, files
|
|
19
23
|
* nothing and leaves the note unfiled — visibly, rather than under a guess.
|
|
@@ -24,11 +28,14 @@
|
|
|
24
28
|
import type { CorpusHttp } from './client';
|
|
25
29
|
import type { TenantEntity, TenantRelationship } from './entities';
|
|
26
30
|
import type { CorpusScope } from './types';
|
|
27
|
-
import { ABOUT_FOCUS, fileDocument, listFocusChoices } from './filing';
|
|
31
|
+
import { ABOUT_FOCUS, fileDocument, listFocusChoices, setDocumentFocuses } from './filing';
|
|
32
|
+
import { filingsFromRow, filingsToRow, uniqueFocusIds } from './voice-sections';
|
|
33
|
+
import type { SectionFiling, VoiceSection } from './voice-sections';
|
|
28
34
|
import type { FocusChoice } from './filing';
|
|
29
35
|
|
|
30
36
|
export { ABOUT_FOCUS };
|
|
31
37
|
export type { FocusChoice };
|
|
38
|
+
export type { SectionFiling, VoiceSection, VoiceItem, VoiceSectionKind } from './voice-sections';
|
|
32
39
|
|
|
33
40
|
export const VOICE_SOURCE = 'voice';
|
|
34
41
|
export const VOICE_SOURCE_LABEL = 'Voice note';
|
|
@@ -46,8 +53,10 @@ export interface AnalysisUsage {
|
|
|
46
53
|
export interface VoiceAnalysis {
|
|
47
54
|
title: string;
|
|
48
55
|
summary: string;
|
|
49
|
-
/** One of the offered focus ids, or null when none fit. */
|
|
56
|
+
/** One of the offered focus ids, or null when none fit. With sections: the dominant section's. */
|
|
50
57
|
focusId: string | null;
|
|
58
|
+
/** One entry per topic spoken (bd startsim-ij1lw.6). Absent on a single-topic / pre-sections analysis. */
|
|
59
|
+
sections?: VoiceSection[];
|
|
51
60
|
usage?: AnalysisUsage;
|
|
52
61
|
}
|
|
53
62
|
|
|
@@ -118,6 +127,8 @@ export function voiceToEntity(input: {
|
|
|
118
127
|
durationMs?: number;
|
|
119
128
|
error?: string;
|
|
120
129
|
usage?: VoiceUsage;
|
|
130
|
+
/** Where each section is filed. Kept as `voice_sections` — never `sections`, which the extractor reads as text. */
|
|
131
|
+
sections?: Array<{ label: string; kind: SectionFiling['kind']; focusId: string | null }>;
|
|
121
132
|
}): { entity_type: string; external_id: string; name: string; data: Record<string, unknown> } {
|
|
122
133
|
return {
|
|
123
134
|
entity_type: 'source_document',
|
|
@@ -137,6 +148,7 @@ export function voiceToEntity(input: {
|
|
|
137
148
|
...(input.durationMs !== undefined ? { duration_ms: input.durationMs } : {}),
|
|
138
149
|
...(input.error !== undefined ? { voice_error: input.error } : {}),
|
|
139
150
|
...(input.usage ? { voice_usage: usageToRow(input.usage) } : {}),
|
|
151
|
+
...(input.sections?.length ? { voice_sections: filingsToRow(input.sections) } : {}),
|
|
140
152
|
},
|
|
141
153
|
};
|
|
142
154
|
}
|
|
@@ -230,7 +242,10 @@ function noteUsage(heard: TranscriptOutcome, llm: AnalysisUsage | undefined, dur
|
|
|
230
242
|
|
|
231
243
|
export interface FinishedVoiceNote {
|
|
232
244
|
id: string;
|
|
245
|
+
/** The first project the note is filed under (the dominant one), or null. */
|
|
233
246
|
focusId: string | null;
|
|
247
|
+
/** Every project it is filed under — one per distinct section project. */
|
|
248
|
+
focusIds: string[];
|
|
234
249
|
title: string;
|
|
235
250
|
transcript: string;
|
|
236
251
|
/** Set when the project edge was refused; the note itself is still `ready`. */
|
|
@@ -279,24 +294,28 @@ export async function finishVoiceNote(
|
|
|
279
294
|
await deps.http.post('api/v1/entities/upsert', voiceToEntity({
|
|
280
295
|
noteId: started.noteId, title, status: 'ready', occurredAt: at.toISOString(),
|
|
281
296
|
body: transcript, summary: analysis.summary,
|
|
297
|
+
sections: analysis.sections,
|
|
282
298
|
usage: noteUsage(outcome, analysis.usage, submission.durationMs),
|
|
283
299
|
}));
|
|
284
300
|
// Filing is best-effort AFTER the note is already `ready`: a refused edge
|
|
285
301
|
// must leave a readable, unfiled note — not overwrite it as `failed` and
|
|
286
|
-
// throw away the transcript and summary that were just produced.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
302
|
+
// throw away the transcript and summary that were just produced. One edge
|
|
303
|
+
// per distinct project, each tried on its own so one refusal leaves the rest.
|
|
304
|
+
const wanted = analysis.sections?.length ? uniqueFocusIds(analysis.sections) : analysis.focusId ? [analysis.focusId] : [];
|
|
305
|
+
const filed: string[] = [];
|
|
306
|
+
const errors: string[] = [];
|
|
307
|
+
for (const focusId of wanted) {
|
|
290
308
|
try {
|
|
291
|
-
await deps.http.post('api/v1/relationships', {
|
|
292
|
-
|
|
293
|
-
});
|
|
309
|
+
await deps.http.post('api/v1/relationships', { rel_type: ABOUT_FOCUS, source: started.id, target: focusId });
|
|
310
|
+
filed.push(focusId);
|
|
294
311
|
} catch (error) {
|
|
295
|
-
|
|
296
|
-
filingError = error instanceof Error ? error.message : String(error);
|
|
312
|
+
errors.push(error instanceof Error ? error.message : String(error));
|
|
297
313
|
}
|
|
298
314
|
}
|
|
299
|
-
return {
|
|
315
|
+
return {
|
|
316
|
+
id: started.id, focusId: filed[0] ?? null, focusIds: filed, title, transcript,
|
|
317
|
+
...(errors.length ? { filingError: errors.join('; ') } : {}),
|
|
318
|
+
};
|
|
300
319
|
} catch (error) {
|
|
301
320
|
return fail(error);
|
|
302
321
|
}
|
|
@@ -315,7 +334,14 @@ export interface VoiceNote {
|
|
|
315
334
|
error?: string;
|
|
316
335
|
occurredAt: string | null;
|
|
317
336
|
durationMs?: number;
|
|
337
|
+
/** The first project the note is filed under, or null. */
|
|
318
338
|
focusId: string | null;
|
|
339
|
+
/** Every project it is filed under (several when it has sections). */
|
|
340
|
+
focusIds?: string[];
|
|
341
|
+
/** Where each topic of the note is filed; empty for a single-topic or older note. */
|
|
342
|
+
sections?: SectionFiling[];
|
|
343
|
+
/** The row's external id — what an upsert keys on. */
|
|
344
|
+
externalId?: string;
|
|
319
345
|
audioRef?: string;
|
|
320
346
|
/** Provider, model, audio seconds and tokens behind this note — cost is derivable from it. */
|
|
321
347
|
usage?: VoiceUsage;
|
|
@@ -328,8 +354,10 @@ export interface VoiceNotesApi {
|
|
|
328
354
|
submit(audio: Blob, meta: { durationMs: number }): Promise<{ id: string }>;
|
|
329
355
|
list(): Promise<VoiceNote[]>;
|
|
330
356
|
listFocuses(): Promise<VoiceFocus[]>;
|
|
331
|
-
/** Move a note to another project, or `null` to unfile it. */
|
|
357
|
+
/** Move a note to another project, or `null` to unfile it. With sections: every section moves. */
|
|
332
358
|
file(noteId: string, focusId: string | null): Promise<void>;
|
|
359
|
+
/** Move ONE section of a note to a project (or unfile it); the note's edges follow. Absent = no per-section control. */
|
|
360
|
+
fileSection?(noteId: string, sectionIndex: number, focusId: string | null): Promise<void>;
|
|
333
361
|
/** Re-run a failed note from its stored audio (bd startsim-ikxdz). Absent = no Retry button. */
|
|
334
362
|
retry?(noteId: string): Promise<void>;
|
|
335
363
|
/** Delete a note, its project edge and its recording. Absent = no Delete button. */
|
|
@@ -342,7 +370,8 @@ function text(value: unknown): string {
|
|
|
342
370
|
return typeof value === 'string' ? value : '';
|
|
343
371
|
}
|
|
344
372
|
|
|
345
|
-
export function toVoiceNote(entity: TenantEntity,
|
|
373
|
+
export function toVoiceNote(entity: TenantEntity, filedUnder: string | string[] | null): VoiceNote {
|
|
374
|
+
const focusIds = Array.isArray(filedUnder) ? filedUnder : filedUnder ? [filedUnder] : [];
|
|
346
375
|
const data = (entity.data ?? {}) as Record<string, unknown>;
|
|
347
376
|
// The @startsimpli/api client camel-cases keys inside `data` too, so every
|
|
348
377
|
// snake_case field is read under both spellings.
|
|
@@ -361,7 +390,10 @@ export function toVoiceNote(entity: TenantEntity, focusId: string | null): Voice
|
|
|
361
390
|
...(error ? { error } : {}),
|
|
362
391
|
occurredAt: text(pick('occurred_at', 'occurredAt')) || null,
|
|
363
392
|
...(typeof durationMs === 'number' ? { durationMs } : {}),
|
|
364
|
-
focusId,
|
|
393
|
+
focusId: focusIds[0] ?? null,
|
|
394
|
+
focusIds,
|
|
395
|
+
sections: filingsFromRow(pick('voice_sections', 'voiceSections')),
|
|
396
|
+
...(entity.external_id ?? entity.externalId ? { externalId: String(entity.external_id ?? entity.externalId) } : {}),
|
|
365
397
|
...(audioRef ? { audioRef } : {}),
|
|
366
398
|
...(usage ? { usage } : {}),
|
|
367
399
|
};
|
|
@@ -383,6 +415,24 @@ export function createVoiceApi(options: CreateVoiceApiOptions): VoiceNotesApi {
|
|
|
383
415
|
const { http } = options;
|
|
384
416
|
const submit = options.server?.upload ?? options.upload;
|
|
385
417
|
if (!submit) throw new Error('createVoiceApi needs an upload function or a server client.');
|
|
418
|
+
|
|
419
|
+
async function readFilings(noteId: string): Promise<{ row: TenantEntity; filings: SectionFiling[] }> {
|
|
420
|
+
const row = await http.get<TenantEntity>(`api/v1/entities/${encodeURIComponent(noteId)}`);
|
|
421
|
+
const data = (row?.data ?? {}) as Record<string, unknown>;
|
|
422
|
+
return { row, filings: filingsFromRow(data.voice_sections ?? data.voiceSections) };
|
|
423
|
+
}
|
|
424
|
+
/** The ONE writer of section filing: the sections on the row, then the edges as their union. */
|
|
425
|
+
async function writeFilings(noteId: string, row: TenantEntity, filings: SectionFiling[]): Promise<void> {
|
|
426
|
+
if (!http.post) throw new Error('This client is read-only.');
|
|
427
|
+
await http.post('api/v1/entities/upsert', {
|
|
428
|
+
entity_type: 'source_document',
|
|
429
|
+
external_id: row.external_id ?? row.externalId,
|
|
430
|
+
name: row.name,
|
|
431
|
+
data: { voice_sections: filingsToRow(filings) },
|
|
432
|
+
});
|
|
433
|
+
await setDocumentFocuses(http, noteId, uniqueFocusIds(filings));
|
|
434
|
+
}
|
|
435
|
+
|
|
386
436
|
return {
|
|
387
437
|
submit,
|
|
388
438
|
...(options.server?.retry ? { retry: options.server.retry } : {}),
|
|
@@ -398,18 +448,34 @@ export function createVoiceApi(options: CreateVoiceApiOptions): VoiceNotesApi {
|
|
|
398
448
|
const edges = await http.get<Page<TenantRelationship>>('api/v1/relationships', {
|
|
399
449
|
params: { rel_type: ABOUT_FOCUS, entity__in: rows.map((r) => r.id).join(','), page_size: 200 },
|
|
400
450
|
});
|
|
401
|
-
const focusOf = new Map<string, string>();
|
|
402
|
-
for (const edge of edges.results ?? [])
|
|
451
|
+
const focusOf = new Map<string, string[]>();
|
|
452
|
+
for (const edge of edges.results ?? []) {
|
|
453
|
+
const list = focusOf.get(String(edge.source)) ?? [];
|
|
454
|
+
list.push(String(edge.target));
|
|
455
|
+
focusOf.set(String(edge.source), list);
|
|
456
|
+
}
|
|
403
457
|
return rows
|
|
404
458
|
// `source=voice` may be ignored by an older backend (it says so in
|
|
405
459
|
// `applied_filters`); never show another source's rows as voice notes.
|
|
406
460
|
.filter((r) => text(((r.data ?? {}) as Record<string, unknown>).source) === VOICE_SOURCE)
|
|
407
|
-
.map((r) => toVoiceNote(r, focusOf.get(String(r.id)) ??
|
|
461
|
+
.map((r) => toVoiceNote(r, focusOf.get(String(r.id)) ?? []));
|
|
408
462
|
},
|
|
409
463
|
|
|
410
464
|
listFocuses: () => listFocusChoices(http),
|
|
411
465
|
|
|
412
|
-
// Replace, never add
|
|
413
|
-
|
|
466
|
+
// Replace, never add. A note with sections moves every section to the one
|
|
467
|
+
// project (the sections are what say where it lives); one without keeps the
|
|
468
|
+
// plain single-edge move.
|
|
469
|
+
async file(noteId, focusId) {
|
|
470
|
+
const { row, filings } = await readFilings(noteId);
|
|
471
|
+
if (!filings.length) return fileDocument(http, noteId, focusId);
|
|
472
|
+
await writeFilings(noteId, row, filings.map((f) => ({ ...f, focusId })));
|
|
473
|
+
},
|
|
474
|
+
|
|
475
|
+
async fileSection(noteId, sectionIndex, focusId) {
|
|
476
|
+
const { row, filings } = await readFilings(noteId);
|
|
477
|
+
if (!filings[sectionIndex]) throw new Error('That section no longer exists.');
|
|
478
|
+
await writeFilings(noteId, row, filings.map((f, i) => (i === sectionIndex ? { ...f, focusId } : f)));
|
|
479
|
+
},
|
|
414
480
|
};
|
|
415
481
|
}
|