@dxos/plugin-transcription 0.8.1-main.ba2dec9 → 0.8.1-staging.391c573

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 (48) hide show
  1. package/dist/lib/browser/{TranscriptContainer-N4KQHMY4.mjs → TranscriptContainer-HAZP6CA4.mjs} +2 -2
  2. package/dist/lib/browser/{chunk-BDVUIRBP.mjs → chunk-6ZBM4EDB.mjs} +2 -2
  3. package/dist/lib/browser/chunk-7WGWZT65.mjs +393 -0
  4. package/dist/lib/browser/chunk-7WGWZT65.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +7 -5
  6. package/dist/lib/browser/index.mjs.map +2 -2
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/{react-surface-UPTZBHVB.mjs → react-surface-Q7TXDD4O.mjs} +3 -3
  9. package/dist/lib/node/{TranscriptContainer-4BWXOVML.cjs → TranscriptContainer-34ARMIII.cjs} +7 -7
  10. package/dist/lib/node/{TranscriptContainer-4BWXOVML.cjs.map → TranscriptContainer-34ARMIII.cjs.map} +2 -2
  11. package/dist/lib/node/{chunk-I35KHI2G.cjs → chunk-5SKPVCFI.cjs} +5 -5
  12. package/dist/lib/node/{chunk-ANSWGFMS.cjs → chunk-SHYOIEFT.cjs} +226 -73
  13. package/dist/lib/node/chunk-SHYOIEFT.cjs.map +7 -0
  14. package/dist/lib/node/index.cjs +9 -7
  15. package/dist/lib/node/index.cjs.map +2 -2
  16. package/dist/lib/node/meta.json +1 -1
  17. package/dist/lib/node/{react-surface-NCKXB7EQ.cjs → react-surface-GDE6AIDT.cjs} +7 -7
  18. package/dist/lib/node-esm/{TranscriptContainer-6IKRASR6.mjs → TranscriptContainer-GJXPGREG.mjs} +2 -2
  19. package/dist/lib/node-esm/{chunk-2CPKXRN6.mjs → chunk-5I6S5KWM.mjs} +2 -2
  20. package/dist/lib/node-esm/chunk-V2GWVMQL.mjs +394 -0
  21. package/dist/lib/node-esm/chunk-V2GWVMQL.mjs.map +7 -0
  22. package/dist/lib/node-esm/index.mjs +7 -5
  23. package/dist/lib/node-esm/index.mjs.map +2 -2
  24. package/dist/lib/node-esm/meta.json +1 -1
  25. package/dist/lib/node-esm/{react-surface-2WJQ67LB.mjs → react-surface-54E3UGAN.mjs} +3 -3
  26. package/dist/types/src/components/Transcript/Transcript.d.ts +3 -0
  27. package/dist/types/src/components/Transcript/Transcript.d.ts.map +1 -1
  28. package/dist/types/src/components/Transcript/Transcript.stories.d.ts.map +1 -1
  29. package/dist/types/src/components/TranscriptContainer.d.ts.map +1 -1
  30. package/package.json +38 -36
  31. package/src/components/Transcript/Transcript.stories.tsx +17 -11
  32. package/src/components/Transcript/Transcript.tsx +218 -49
  33. package/src/components/TranscriptContainer.tsx +13 -19
  34. package/src/components/transcription.stories.tsx +1 -1
  35. package/src/translations.ts +1 -1
  36. package/dist/lib/browser/chunk-YX447BJ4.mjs +0 -241
  37. package/dist/lib/browser/chunk-YX447BJ4.mjs.map +0 -7
  38. package/dist/lib/node/chunk-ANSWGFMS.cjs.map +0 -7
  39. package/dist/lib/node-esm/chunk-ZMK2QLW2.mjs +0 -242
  40. package/dist/lib/node-esm/chunk-ZMK2QLW2.mjs.map +0 -7
  41. /package/dist/lib/browser/{TranscriptContainer-N4KQHMY4.mjs.map → TranscriptContainer-HAZP6CA4.mjs.map} +0 -0
  42. /package/dist/lib/browser/{chunk-BDVUIRBP.mjs.map → chunk-6ZBM4EDB.mjs.map} +0 -0
  43. /package/dist/lib/browser/{react-surface-UPTZBHVB.mjs.map → react-surface-Q7TXDD4O.mjs.map} +0 -0
  44. /package/dist/lib/node/{chunk-I35KHI2G.cjs.map → chunk-5SKPVCFI.cjs.map} +0 -0
  45. /package/dist/lib/node/{react-surface-NCKXB7EQ.cjs.map → react-surface-GDE6AIDT.cjs.map} +0 -0
  46. /package/dist/lib/node-esm/{TranscriptContainer-6IKRASR6.mjs.map → TranscriptContainer-GJXPGREG.mjs.map} +0 -0
  47. /package/dist/lib/node-esm/{chunk-2CPKXRN6.mjs.map → chunk-5I6S5KWM.mjs.map} +0 -0
  48. /package/dist/lib/node-esm/{react-surface-2WJQ67LB.mjs.map → react-surface-54E3UGAN.mjs.map} +0 -0
@@ -8,7 +8,6 @@ import { type StoryObj, type Meta } from '@storybook/react';
8
8
  import React from 'react';
9
9
 
10
10
  import { faker } from '@dxos/random';
11
- import { ScrollContainer } from '@dxos/react-ui-components';
12
11
  import { withTheme, withLayout } from '@dxos/storybook-utils';
13
12
 
14
13
  import { Transcript } from './Transcript';
@@ -17,19 +16,19 @@ import translations from '../../translations';
17
16
  const meta: Meta<typeof Transcript> = {
18
17
  title: 'plugins/plugin-transcription/Transcript',
19
18
  component: Transcript,
20
- render: (args) => (
21
- <div className='flex w-[30rem] p-2'>
22
- <ScrollContainer>
19
+ render: (args) => {
20
+ return (
21
+ <div className='flex w-[50rem] h-full'>
23
22
  <Transcript {...args} />
24
- </ScrollContainer>
25
- </div>
26
- ),
23
+ </div>
24
+ );
25
+ },
27
26
  decorators: [
28
27
  withTheme,
29
28
  withLayout({
30
29
  tooltips: true,
31
30
  fullscreen: true,
32
- classNames: 'justify-center',
31
+ classNames: 'flex justify-center',
33
32
  }),
34
33
  ],
35
34
  parameters: {
@@ -51,10 +50,12 @@ const names = Array.from({ length: 3 }, () => faker.person.fullName());
51
50
 
52
51
  export const Default: Story = {
53
52
  args: {
54
- blocks: Array.from({ length: 6 + Math.floor(Math.random()) * 15 }, () => ({
53
+ ignoreAttention: true,
54
+ attendableId: 'story',
55
+ blocks: Array.from({ length: 200 }, () => ({
55
56
  id: faker.string.uuid(),
56
57
  author: faker.helpers.arrayElement(names),
57
- segments: Array.from({ length: 1 + Math.floor(Math.random() * 3) }, () => ({
58
+ segments: Array.from({ length: 1 + Math.floor(Math.random() * 2) }, () => ({
58
59
  started: next(),
59
60
  text: faker.lorem.paragraph(),
60
61
  })),
@@ -62,4 +63,9 @@ export const Default: Story = {
62
63
  },
63
64
  };
64
65
 
65
- export const Empty: Story = {};
66
+ export const Empty: Story = {
67
+ args: {
68
+ ignoreAttention: true,
69
+ attendableId: 'story',
70
+ },
71
+ };
@@ -2,68 +2,237 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { formatDistanceToNow } from 'date-fns/formatDistanceToNow';
6
- import React, { type FC } from 'react';
5
+ import { intervalToDuration } from 'date-fns/intervalToDuration';
6
+ import React, { type FC, useCallback, useEffect, useMemo, useRef, useState, type WheelEvent } from 'react';
7
+ import { useResizeDetector } from 'react-resize-detector';
7
8
 
8
- import { Icon, IconButton, useTranslation } from '@dxos/react-ui';
9
+ import { log } from '@dxos/log';
10
+ import { useAttention } from '@dxos/react-ui-attention';
11
+ import {
12
+ type DxGridCellValue,
13
+ type DxGridElement,
14
+ type DxGridAxisMeta,
15
+ type DxGridPlaneCells,
16
+ Grid,
17
+ toPlaneCellIndex,
18
+ } from '@dxos/react-ui-grid';
19
+ import { mx } from '@dxos/react-ui-theme';
9
20
 
10
- import { TRANSCRIPTION_PLUGIN } from '../../meta';
11
21
  import { type TranscriptBlock } from '../../types';
12
22
 
13
- // TODO(burdon): react-ui-list.
14
23
  // TODO(burdon): Actions (e.g., mark, summarize, translate, label, delete).
15
24
 
25
+ const timeWidth = 70;
26
+ const lineHeight = 24;
27
+ const cellSpacing = 12;
28
+
29
+ const authorClasses = 'text-[16px] leading-[24px] dx-tag';
30
+
31
+ // NOTE: These classes are required for synchronous measurement.
32
+ const segmentTextClasses = 'text-[16px] leading-[24px] whitespace-pre-wrap break-words hyphens-none';
33
+
34
+ type QueueRows = [number, number, number][];
35
+
16
36
  export type TranscriptProps = {
37
+ attendableId?: string;
38
+ ignoreAttention?: boolean;
17
39
  blocks?: TranscriptBlock[];
18
40
  };
19
41
 
20
- export const Transcript: FC<TranscriptProps> = ({ blocks }) => {
21
- const { t } = useTranslation(TRANSCRIPTION_PLUGIN);
22
- const hoverButton = 'p-1 min-bs-1 transition-opacity duration-250 opacity-10 group-hover:opacity-100';
42
+ export const Transcript: FC<TranscriptProps> = ({ attendableId, ignoreAttention, blocks }) => {
43
+ const { hasAttention } = useAttention(attendableId);
44
+ const { ref, width } = useResizeDetector();
45
+ const measureRef = useRef<HTMLDivElement>(null);
23
46
 
24
- return (
25
- <div role='list' className='flex flex-col grow gap-2 m-1'>
26
- {blocks?.map((block) => (
27
- <div
28
- role='listitem'
29
- key={block.id}
30
- className='flex flex-col py-1 border border-transparent hover:border-separator rounded'
31
- >
32
- <div className='group flex items-center px-2'>
33
- <Icon icon='ph--user--regular' />
34
- <div className='px-2 text-sm text-subdued'>{block.author}</div>
35
- <div className='grow' />
36
- <IconButton
37
- disabled
38
- icon='ph--x--regular'
39
- label={t('delete button')}
40
- iconOnly
41
- size={4}
42
- classNames={hoverButton}
43
- />
44
- </div>
47
+ const textWidth = width ? width - timeWidth : 0;
48
+ const transcriptColumns = width
49
+ ? {
50
+ grid: {
51
+ 0: { size: timeWidth },
52
+ 1: { size: textWidth },
53
+ },
54
+ }
55
+ : undefined;
56
+
57
+ const transcriptRows = {
58
+ grid: { size: lineHeight },
59
+ };
60
+
61
+ const [queueMap, setQueueMap] = useState<QueueRows>([]);
62
+ useEffect(() => {
63
+ if (measureRef.current) {
64
+ // TODO(burdon): Only measure rows that have changed. Cache other values.
65
+ // TODO(burdon): Build into grid with estimated height and correct on the fly.
66
+ void mapTranscriptQueue(measureRef.current, blocks, true).then((queueMap) => {
67
+ setQueueMap(queueMap);
68
+ if (measureRef.current) {
69
+ void mapTranscriptQueue(measureRef.current, blocks, false).then(setQueueMap);
70
+ }
71
+ });
72
+ }
73
+ }, [blocks, measureRef.current]);
74
+
75
+ const rows = useMemo(
76
+ () =>
77
+ ({
78
+ grid: queueMap.reduce((acc: DxGridAxisMeta['grid'], row, rowIndex) => {
79
+ acc[rowIndex] = { size: row[2] };
80
+ return acc;
81
+ }, {}),
82
+ }) satisfies DxGridAxisMeta,
83
+ [queueMap],
84
+ );
85
+
86
+ const [dxGrid, setDxGrid] = useState<DxGridElement | null>(null);
87
+ useEffect(() => {
88
+ if (dxGrid && Array.isArray(blocks)) {
89
+ const start = blocks[0]?.segments[0]?.started ?? 0;
90
+
91
+ dxGrid.getCells = (range, plane) => {
92
+ switch (plane) {
93
+ case 'grid': {
94
+ const cells: DxGridPlaneCells = {};
95
+ for (let row = range.start.row; row <= range.end.row && row < queueMap.length; row++) {
96
+ const [blockIndex, segmentIndex] = queueMap[row];
97
+ const { author, segments } = blocks[blockIndex] ?? { author: '', segments: [] };
98
+ const { started: end, text } = segments[segmentIndex] ?? { started: 0, text: '' };
99
+
100
+ cells[toPlaneCellIndex({ col: 0, row })] = (
101
+ segmentIndex === 0
102
+ ? {
103
+ readonly: true,
104
+ accessoryHtml: `<span class="pbs-1 text-xs text-neutral-500">${formatElapsed(start, end)}</span>`,
105
+ }
106
+ : {}
107
+ ) satisfies DxGridCellValue;
108
+
109
+ cells[toPlaneCellIndex({ col: 1, row })] = (
110
+ segmentIndex < 0
111
+ ? {
112
+ value: author,
113
+ readonly: true,
114
+ // TODO(burdon): Color based on username.
115
+ className: authorClasses,
116
+ }
117
+ : {
118
+ readonly: true,
119
+ accessoryHtml: `<div class="${segmentTextClasses}">${text.trim()}</div>`,
120
+ }
121
+ ) satisfies DxGridCellValue;
122
+ }
123
+
124
+ return cells;
125
+ }
126
+ default:
127
+ return {};
128
+ }
129
+ };
130
+ }
131
+ }, [dxGrid, queueMap, blocks]);
45
132
 
46
- {block.segments.map((segment, i) => (
47
- <div key={i} className='group flex flex-col'>
48
- <div className='px-2'>{segment.text}</div>
49
- <div className='flex gap-1 items-center justify-between px-2'>
50
- <div className='grow' />
51
- <div className='truncate text-xs text-subdued'>
52
- {formatDistanceToNow(segment.started, { addSuffix: true })}
53
- </div>
54
- <IconButton
55
- disabled
56
- icon='ph--bookmark-simple--regular'
57
- label={t('bookmark button')}
58
- iconOnly
59
- size={4}
60
- classNames={hoverButton}
61
- />
62
- </div>
133
+ const handleWheel = useCallback(
134
+ (event: WheelEvent) => {
135
+ if (!ignoreAttention && !hasAttention) {
136
+ event.stopPropagation();
137
+ }
138
+ },
139
+ [hasAttention, ignoreAttention],
140
+ );
141
+
142
+ return (
143
+ <div role='none' ref={ref} className='grow'>
144
+ {transcriptColumns && (
145
+ <>
146
+ <div className='relative'>
147
+ <div
148
+ className='absolute top-0 z-10 p-1 border invisible'
149
+ style={{ left: timeWidth, width: transcriptColumns.grid['1'].size }}
150
+ >
151
+ <div ref={measureRef} className={mx(segmentTextClasses)} />
63
152
  </div>
64
- ))}
65
- </div>
66
- ))}
153
+ </div>
154
+ <Grid.Root id={`${attendableId}--transcript`}>
155
+ <Grid.Content
156
+ ref={setDxGrid}
157
+ className='[--dx-grid-base:var(--dx-baseSurface)] [--dx-grid-lines:var(--dx-baseSurface)] [&_.dx-grid]:min-bs-0 [&_.dx-grid]:select-auto'
158
+ columns={transcriptColumns}
159
+ rowDefault={transcriptRows}
160
+ rows={rows}
161
+ limitColumns={2}
162
+ limitRows={queueMap.length}
163
+ onWheel={handleWheel}
164
+ />
165
+ </Grid.Root>
166
+ </>
167
+ )}
67
168
  </div>
68
169
  );
69
170
  };
171
+
172
+ const mapTranscriptQueue = async (
173
+ div: HTMLDivElement,
174
+ blocks?: TranscriptBlock[],
175
+ estimate = false,
176
+ ): Promise<QueueRows> => {
177
+ if (!blocks || !Array.isArray(blocks) || blocks.length === 0) {
178
+ return [];
179
+ } else {
180
+ const ts = Date.now();
181
+ await document.fonts.ready;
182
+
183
+ const rows: QueueRows = [];
184
+ let blockIndex = 0;
185
+ for (const block of blocks) {
186
+ rows.push([blockIndex, -1, lineHeight + cellSpacing]);
187
+ let segmentIndex = 0;
188
+ for (const segment of block.segments) {
189
+ const height = await measureSegment(div, segment.text, estimate);
190
+ rows.push([blockIndex, segmentIndex, height + cellSpacing]);
191
+ segmentIndex++;
192
+ }
193
+ blockIndex++;
194
+ }
195
+
196
+ log('render', { duration: Date.now() - ts });
197
+ return rows;
198
+
199
+ // return blocks.flatMap((block, blockIndex) => {
200
+ // return [
201
+ // [blockIndex, -1, lineHeight + cellSpacing],
202
+ // ...block.segments.map((segment, segmentIndex) => {
203
+ // div.innerHTML = segment.text;
204
+ // const height = measureSegmentSync(div, segment.text) + cellSpacing;
205
+ // return [blockIndex, segmentIndex, height] as [number, number, number];
206
+ // }),
207
+ // ];
208
+ // });
209
+ }
210
+ };
211
+
212
+ // TODO(burdon): Occasional random measurement error (-1 actual lines).
213
+ // const measureSegmentSync = (div: HTMLDivElement, text: string): number => {
214
+ // div.innerHTML = text;
215
+ // void div.offsetHeight;
216
+ // return div.offsetHeight;
217
+ // };
218
+
219
+ const measureSegment = async (div: HTMLDivElement, text: string, estimate = false): Promise<number> => {
220
+ return new Promise((resolve) => {
221
+ div.innerHTML = text;
222
+ if (estimate) {
223
+ const { height } = div.getBoundingClientRect();
224
+ resolve(height);
225
+ } else {
226
+ requestAnimationFrame(() => {
227
+ const { height } = div.getBoundingClientRect();
228
+ resolve(height);
229
+ });
230
+ }
231
+ });
232
+ };
233
+
234
+ export const formatElapsed = (start: Date, end: Date) => {
235
+ const { hours, minutes, seconds } = intervalToDuration({ start, end });
236
+ const pad = (n = 0) => String(n).padStart(2, '0');
237
+ return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
238
+ };
@@ -8,7 +8,7 @@ import React, { useCallback, useMemo, useState, type FC } from 'react';
8
8
  import { chain, createIntent, LayoutAction, useIntentDispatcher } from '@dxos/app-framework';
9
9
  import { Message } from '@dxos/artifact';
10
10
  import { AIServiceEdgeClient, DEFAULT_LLM_MODEL, MixedStreamParser, type AIServiceClient } from '@dxos/assistant';
11
- import { create, getSpace, makeRef } from '@dxos/client/echo';
11
+ import { create, fullyQualifiedId, getSpace, makeRef } from '@dxos/client/echo';
12
12
  import { QueueImpl } from '@dxos/echo-db';
13
13
  import { createStatic, isInstanceOf } from '@dxos/echo-schema';
14
14
  import { invariant } from '@dxos/invariant';
@@ -19,7 +19,6 @@ import { CollectionType, SpaceAction } from '@dxos/plugin-space/types';
19
19
  import { useConfig } from '@dxos/react-client';
20
20
  import { useEdgeClient, useQueue, type EdgeHttpClient } from '@dxos/react-edge-client';
21
21
  import { IconButton, Toolbar, useTranslation } from '@dxos/react-ui';
22
- import { ScrollContainer } from '@dxos/react-ui-components';
23
22
  import { StackItem } from '@dxos/react-ui-stack';
24
23
  import { TextType } from '@dxos/schema';
25
24
 
@@ -32,6 +31,7 @@ export const TranscriptionContainer: FC<{ transcript: TranscriptType }> = ({ tra
32
31
  const edge = useEdgeClient();
33
32
  const ai = useAiServiceClient();
34
33
  const { dispatchPromise: dispatch } = useIntentDispatcher();
34
+ const attendableId = fullyQualifiedId(transcript);
35
35
 
36
36
  const queue = useQueue<TranscriptBlock>(edge, transcript.queue ? DXN.parse(transcript.queue) : undefined, {
37
37
  pollInterval: 1_000,
@@ -58,23 +58,17 @@ export const TranscriptionContainer: FC<{ transcript: TranscriptType }> = ({ tra
58
58
 
59
59
  // TODO(dmaretskyi): Move action to menu.
60
60
  return (
61
- <StackItem.Content toolbar={true}>
62
- <StackItem.Heading>
63
- <Toolbar.Root classNames='flex gap-2'>
64
- <IconButton
65
- icon='ph--subtitles--regular'
66
- iconOnly
67
- size={5}
68
- disabled={isSummarizing}
69
- onClick={handleSummarize}
70
- label={t('summary button')}
71
- />
72
- {isSummarizing && <div className='text-sm'>{t('summarizing label')}</div>}
73
- </Toolbar.Root>
74
- </StackItem.Heading>
75
- <ScrollContainer>
76
- <Transcript blocks={queue?.items} />
77
- </ScrollContainer>
61
+ <StackItem.Content toolbar={false} classNames='relative'>
62
+ <Toolbar.Root classNames='absolute block-start-1 inline-end-1 z-[1] is-min'>
63
+ <IconButton
64
+ icon='ph--pen--regular'
65
+ size={5}
66
+ disabled={isSummarizing}
67
+ onClick={handleSummarize}
68
+ label={t(isSummarizing ? 'summarizing label' : 'summary button')}
69
+ />
70
+ </Toolbar.Root>
71
+ <Transcript blocks={queue?.items} attendableId={attendableId} />
78
72
  </StackItem.Content>
79
73
  );
80
74
  };
@@ -48,7 +48,7 @@ const UX: FC<{
48
48
  />
49
49
  </Toolbar.Root>
50
50
  <ScrollContainer>
51
- <Transcript blocks={blocks} />
51
+ <Transcript blocks={blocks} attendableId='story' />
52
52
  </ScrollContainer>
53
53
  </div>
54
54
  );
@@ -20,7 +20,7 @@ export default [
20
20
 
21
21
  'delete button': 'Delete',
22
22
  'bookmark button': 'Bookmark',
23
- 'summary button': 'Create summary',
23
+ 'summary button': 'Summarize',
24
24
  'summarizing label': 'Summarizing...',
25
25
  },
26
26
  },
@@ -1,241 +0,0 @@
1
- import {
2
- TRANSCRIPTION_PLUGIN,
3
- TranscriptBlock
4
- } from "./chunk-QIHUPVQD.mjs";
5
-
6
- // packages/plugins/experimental/plugin-transcription/src/components/TranscriptContainer.tsx
7
- import { pipe } from "effect";
8
- import React2, { useCallback, useMemo, useState } from "react";
9
- import { chain, createIntent, LayoutAction, useIntentDispatcher } from "@dxos/app-framework";
10
- import { Message } from "@dxos/artifact";
11
- import { AIServiceEdgeClient, DEFAULT_LLM_MODEL, MixedStreamParser } from "@dxos/assistant";
12
- import { create, getSpace, makeRef } from "@dxos/client/echo";
13
- import { QueueImpl } from "@dxos/echo-db";
14
- import { createStatic, isInstanceOf } from "@dxos/echo-schema";
15
- import { invariant } from "@dxos/invariant";
16
- import { DXN } from "@dxos/keys";
17
- import { log } from "@dxos/log";
18
- import { DocumentType } from "@dxos/plugin-markdown/types";
19
- import { CollectionType, SpaceAction } from "@dxos/plugin-space/types";
20
- import { useConfig } from "@dxos/react-client";
21
- import { useEdgeClient, useQueue } from "@dxos/react-edge-client";
22
- import { IconButton as IconButton2, Toolbar, useTranslation as useTranslation2 } from "@dxos/react-ui";
23
- import { ScrollContainer } from "@dxos/react-ui-components";
24
- import { StackItem } from "@dxos/react-ui-stack";
25
- import { TextType } from "@dxos/schema";
26
-
27
- // packages/plugins/experimental/plugin-transcription/src/components/Transcript/Transcript.tsx
28
- import { formatDistanceToNow } from "date-fns/formatDistanceToNow";
29
- import React from "react";
30
- import { Icon, IconButton, useTranslation } from "@dxos/react-ui";
31
- var Transcript = ({ blocks }) => {
32
- const { t } = useTranslation(TRANSCRIPTION_PLUGIN);
33
- const hoverButton = "p-1 min-bs-1 transition-opacity duration-250 opacity-10 group-hover:opacity-100";
34
- return /* @__PURE__ */ React.createElement("div", {
35
- role: "list",
36
- className: "flex flex-col grow gap-2 m-1"
37
- }, blocks?.map((block) => /* @__PURE__ */ React.createElement("div", {
38
- role: "listitem",
39
- key: block.id,
40
- className: "flex flex-col py-1 border border-transparent hover:border-separator rounded"
41
- }, /* @__PURE__ */ React.createElement("div", {
42
- className: "group flex items-center px-2"
43
- }, /* @__PURE__ */ React.createElement(Icon, {
44
- icon: "ph--user--regular"
45
- }), /* @__PURE__ */ React.createElement("div", {
46
- className: "px-2 text-sm text-subdued"
47
- }, block.author), /* @__PURE__ */ React.createElement("div", {
48
- className: "grow"
49
- }), /* @__PURE__ */ React.createElement(IconButton, {
50
- disabled: true,
51
- icon: "ph--x--regular",
52
- label: t("delete button"),
53
- iconOnly: true,
54
- size: 4,
55
- classNames: hoverButton
56
- })), block.segments.map((segment, i) => /* @__PURE__ */ React.createElement("div", {
57
- key: i,
58
- className: "group flex flex-col"
59
- }, /* @__PURE__ */ React.createElement("div", {
60
- className: "px-2"
61
- }, segment.text), /* @__PURE__ */ React.createElement("div", {
62
- className: "flex gap-1 items-center justify-between px-2"
63
- }, /* @__PURE__ */ React.createElement("div", {
64
- className: "grow"
65
- }), /* @__PURE__ */ React.createElement("div", {
66
- className: "truncate text-xs text-subdued"
67
- }, formatDistanceToNow(segment.started, {
68
- addSuffix: true
69
- })), /* @__PURE__ */ React.createElement(IconButton, {
70
- disabled: true,
71
- icon: "ph--bookmark-simple--regular",
72
- label: t("bookmark button"),
73
- iconOnly: true,
74
- size: 4,
75
- classNames: hoverButton
76
- })))))));
77
- };
78
-
79
- // packages/plugins/experimental/plugin-transcription/src/components/TranscriptContainer.tsx
80
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-transcription/src/components/TranscriptContainer.tsx";
81
- var TranscriptionContainer = ({ transcript }) => {
82
- const { t } = useTranslation2(TRANSCRIPTION_PLUGIN);
83
- const edge = useEdgeClient();
84
- const ai = useAiServiceClient();
85
- const { dispatchPromise: dispatch } = useIntentDispatcher();
86
- const queue = useQueue(edge, transcript.queue ? DXN.parse(transcript.queue) : void 0, {
87
- pollInterval: 1e3
88
- });
89
- const [isSummarizing, setIsSummarizing] = useState(false);
90
- const handleSummarize = useCallback(async () => {
91
- setIsSummarizing(true);
92
- try {
93
- const document = await summarizeTranscript(edge, ai, transcript);
94
- const space = getSpace(transcript);
95
- const target = space?.properties[CollectionType.typename]?.target;
96
- await dispatch(pipe(createIntent(SpaceAction.AddObject, {
97
- object: document,
98
- target
99
- }), chain(LayoutAction.Open, {
100
- part: "main"
101
- })));
102
- } finally {
103
- setIsSummarizing(false);
104
- }
105
- }, [
106
- transcript,
107
- edge
108
- ]);
109
- return /* @__PURE__ */ React2.createElement(StackItem.Content, {
110
- toolbar: true
111
- }, /* @__PURE__ */ React2.createElement(StackItem.Heading, null, /* @__PURE__ */ React2.createElement(Toolbar.Root, {
112
- classNames: "flex gap-2"
113
- }, /* @__PURE__ */ React2.createElement(IconButton2, {
114
- icon: "ph--subtitles--regular",
115
- iconOnly: true,
116
- size: 5,
117
- disabled: isSummarizing,
118
- onClick: handleSummarize,
119
- label: t("summary button")
120
- }), isSummarizing && /* @__PURE__ */ React2.createElement("div", {
121
- className: "text-sm"
122
- }, t("summarizing label")))), /* @__PURE__ */ React2.createElement(ScrollContainer, null, /* @__PURE__ */ React2.createElement(Transcript, {
123
- blocks: queue?.items
124
- })));
125
- };
126
- var TranscriptContainer_default = TranscriptionContainer;
127
- var summarizeTranscript = async (edge, ai, transcript) => {
128
- invariant(transcript.queue, "No queue found for transcript", {
129
- F: __dxlog_file,
130
- L: 86,
131
- S: void 0,
132
- A: [
133
- "transcript.queue",
134
- "'No queue found for transcript'"
135
- ]
136
- });
137
- const queue = new QueueImpl(edge, DXN.parse(transcript.queue));
138
- await queue.refresh();
139
- const content = queue.items.filter((block) => isInstanceOf(TranscriptBlock, block)).map((block) => `${block.author}: ${block.segments.map((segment) => segment.text).join("\n")}`).join("\n\n");
140
- const parser = new MixedStreamParser();
141
- log.info("summarizing transcript", {
142
- blockCount: queue.items.length
143
- }, {
144
- F: __dxlog_file,
145
- L: 97,
146
- S: void 0,
147
- C: (f, a) => f(...a)
148
- });
149
- const output = await parser.parse(await ai.exec({
150
- model: DEFAULT_LLM_MODEL,
151
- systemPrompt: SUMMARIZE_PROMPT,
152
- history: [
153
- createStatic(Message, {
154
- role: "user",
155
- content: [
156
- {
157
- type: "text",
158
- text: content
159
- }
160
- ]
161
- })
162
- ]
163
- }));
164
- log.info("transcript summary", {
165
- output
166
- }, {
167
- F: __dxlog_file,
168
- L: 106,
169
- S: void 0,
170
- C: (f, a) => f(...a)
171
- });
172
- invariant(output[0].content[0].type === "text", "Expected text content", {
173
- F: __dxlog_file,
174
- L: 107,
175
- S: void 0,
176
- A: [
177
- "output[0].content[0].type === 'text'",
178
- "'Expected text content'"
179
- ]
180
- });
181
- const summary = output[0].content[0].text;
182
- const name = `Summary ${(transcript.started ?? /* @__PURE__ */ new Date()).toLocaleString("en-US", {
183
- year: "numeric",
184
- month: "long",
185
- day: "numeric",
186
- hour: "2-digit",
187
- minute: "2-digit"
188
- })}`;
189
- return create(DocumentType, {
190
- name,
191
- content: makeRef(create(TextType, {
192
- content: summary
193
- })),
194
- threads: []
195
- });
196
- };
197
- var SUMMARIZE_PROMPT = `
198
- # Goal
199
- Create a markdown summary of the transcript provided.
200
-
201
- # Formatting
202
- - Format the summary as a markdown document without extra comments like "Here is the summary of the transcript:".
203
- - Use markdown formatting for headings and bullet points.
204
- - Format the summary as a list of key points and takeaways.
205
- - All names of people should be in bold.
206
-
207
- # Note Taking
208
- - Correlate items in the summary with the person of origin to build a coherent narrative.
209
- - Include short quotes verbatim where appropriate. Especially when concerned with design decisions and problem descriptions.
210
-
211
- # Tasks
212
- At the end of the summary include tasks.
213
- Extract only the tasks that are:
214
- - Directly actionable.
215
- - Clearly assigned to a person or team (or can easily be inferred).
216
- - Strongly implied by the conversation and/or user note (no speculative tasks).
217
- - Specific enough that someone reading them would know exactly what to do next.
218
-
219
- Format all tasks as markdown checkboxes using the syntax:
220
- - [ ] Task description
221
-
222
- Additional information can be included (indented).
223
-
224
- If no actionable tasks are found, omit this tasks section.
225
- `;
226
- var useAiServiceClient = () => {
227
- const config = useConfig();
228
- const endpoint = config.values.runtime?.services?.ai?.server ?? "http://localhost:8788";
229
- return useMemo(() => new AIServiceEdgeClient({
230
- endpoint
231
- }), [
232
- endpoint
233
- ]);
234
- };
235
-
236
- export {
237
- Transcript,
238
- TranscriptionContainer,
239
- TranscriptContainer_default
240
- };
241
- //# sourceMappingURL=chunk-YX447BJ4.mjs.map