@arbidocs/react 0.4.109 → 0.4.111

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/README.md CHANGED
@@ -184,7 +184,7 @@ const run = useRunTask() // approves a run parked for access (tem
184
184
  const runs = useTaskRuns(taskId) // polls while a run is in flight
185
185
  const save = useSaveAgentConfig() // { agentExtId, sections: { Agents: { PERSONA, ... } } }
186
186
  const grant = useGrantAgentAccess() // { agentExtId, workspaceId, mode?: { kind: 'standing' | 'temporary' } }
187
- const contacts = usePendingContacts() // + useAddContacts(), useRemoveContacts()
187
+ const contacts = usePendingContacts() // + useInviteContacts(), useCreateContact(), useUpdateContact(), useDeleteContact()
188
188
  ```
189
189
 
190
190
  Form-to-request mappings (`taskComposerToCreateRequest`, `composePersona`, ...) are in
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkAFGE55RQ_cjs = require('../chunk-AFGE55RQ.cjs');
4
+ var chunk3AADNIOK_cjs = require('../chunk-3AADNIOK.cjs');
4
5
  var chunkT4IJHRRD_cjs = require('../chunk-T4IJHRRD.cjs');
5
6
  var chunk5DCRIWCA_cjs = require('../chunk-5DCRIWCA.cjs');
6
- var chunk3AADNIOK_cjs = require('../chunk-3AADNIOK.cjs');
7
7
  var chunkVOFNX4P6_cjs = require('../chunk-VOFNX4P6.cjs');
8
8
  var chunkTBELZWGV_cjs = require('../chunk-TBELZWGV.cjs');
9
9
  require('../chunk-Z3LLUO32.cjs');
@@ -552,6 +552,18 @@ function useStreamedArtifact({
552
552
  return { phase, artifact, docId, error, cleaned, retry };
553
553
  }
554
554
 
555
+ Object.defineProperty(exports, "buildHybridRedlineMarkdown", {
556
+ enumerable: true,
557
+ get: function () { return chunk3AADNIOK_cjs.buildHybridRedlineMarkdown; }
558
+ });
559
+ Object.defineProperty(exports, "buildHybridRedlineWithRegions", {
560
+ enumerable: true,
561
+ get: function () { return chunk3AADNIOK_cjs.buildHybridRedlineWithRegions; }
562
+ });
563
+ Object.defineProperty(exports, "revertRedlineRegion", {
564
+ enumerable: true,
565
+ get: function () { return chunk3AADNIOK_cjs.revertRedlineRegion; }
566
+ });
555
567
  Object.defineProperty(exports, "documentVersions", {
556
568
  enumerable: true,
557
569
  get: function () { return chunkT4IJHRRD_cjs.documentVersions; }
@@ -620,18 +632,6 @@ Object.defineProperty(exports, "unwrapCitationLinks", {
620
632
  enumerable: true,
621
633
  get: function () { return chunk5DCRIWCA_cjs.unwrapCitationLinks; }
622
634
  });
623
- Object.defineProperty(exports, "buildHybridRedlineMarkdown", {
624
- enumerable: true,
625
- get: function () { return chunk3AADNIOK_cjs.buildHybridRedlineMarkdown; }
626
- });
627
- Object.defineProperty(exports, "buildHybridRedlineWithRegions", {
628
- enumerable: true,
629
- get: function () { return chunk3AADNIOK_cjs.buildHybridRedlineWithRegions; }
630
- });
631
- Object.defineProperty(exports, "revertRedlineRegion", {
632
- enumerable: true,
633
- get: function () { return chunk3AADNIOK_cjs.revertRedlineRegion; }
634
- });
635
635
  Object.defineProperty(exports, "normalizeMarkdown", {
636
636
  enumerable: true,
637
637
  get: function () { return chunkVOFNX4P6_cjs.normalizeMarkdown; }
@@ -1,10 +1,10 @@
1
1
  import { arbiQueryKeys, useDocuments, useDocumentVersionList } from '../chunk-5WXNTCI3.js';
2
+ import { revertRedlineRegion, buildHybridRedlineWithRegions, buildHybridRedlineMarkdown } from '../chunk-74N436VK.js';
3
+ export { buildHybridRedlineMarkdown, buildHybridRedlineWithRegions, revertRedlineRegion } from '../chunk-74N436VK.js';
2
4
  import { isDocumentId, parseVersionRef, flattenChunks, documentVersions, toArtifactVersions, findVersion, versionLabel } from '../chunk-HKUD2NZN.js';
3
5
  export { documentVersions, findVersion, flattenChunks, isDocumentId, parseVersionRef, savedFromId, toArtifactVersions, versionLabel, versionRef } from '../chunk-HKUD2NZN.js';
4
6
  import { cleanDraftWithReport } from '../chunk-G6FHNURH.js';
5
7
  export { cleanDraftMarkdown, cleanDraftWithReport, promoteBoldTitle, repairParsedStructure, repairParsedTitle, stripAgentPreamble, unescapeMarkdown, unwrapCitationLinks } from '../chunk-G6FHNURH.js';
6
- import { revertRedlineRegion, buildHybridRedlineWithRegions, buildHybridRedlineMarkdown } from '../chunk-74N436VK.js';
7
- export { buildHybridRedlineMarkdown, buildHybridRedlineWithRegions, revertRedlineRegion } from '../chunk-74N436VK.js';
8
8
  import { normalizeMarkdown } from '../chunk-WUTL62MC.js';
9
9
  export { normalizeMarkdown } from '../chunk-WUTL62MC.js';
10
10
  import { MarkdownRenderer } from '../chunk-EKRRORFO.js';
@@ -1,5 +1,5 @@
1
- import { Dialog, DialogContent } from './chunk-YNNAJJ5Z.js';
2
1
  import { MarkdownRenderer } from './chunk-EKRRORFO.js';
2
+ import { Dialog, DialogContent } from './chunk-YNNAJJ5Z.js';
3
3
  import { getCollisionPadding, usePortalContainer, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuLabel, DropdownMenuItem, DropdownMenuSeparator } from './chunk-47CCGUWR.js';
4
4
  import { cn } from './chunk-SN5YV6FF.js';
5
5
  import * as React from 'react';
@@ -674,8 +674,256 @@ function classifyMediaError(err, kind) {
674
674
  }
675
675
  return `Could not access the ${kind}. Please try again.`;
676
676
  }
677
+
678
+ // src/documents/chunked-recorder.ts
679
+ var AUDIO_MIME_PREFERENCE = [
680
+ "audio/webm;codecs=opus",
681
+ "audio/ogg;codecs=opus",
682
+ "audio/mp4;codecs=mp4a.40.2",
683
+ "audio/mp4"
684
+ ];
685
+ var VIDEO_MIME_PREFERENCE = [
686
+ "video/webm;codecs=av01,opus",
687
+ "video/webm;codecs=av1,opus",
688
+ "video/webm;codecs=vp9,opus",
689
+ "video/webm;codecs=vp8,opus",
690
+ "video/webm",
691
+ "video/mp4"
692
+ ];
693
+ function pickRecorderMimeType(kind, isTypeSupported = (t) => typeof MediaRecorder !== "undefined" && MediaRecorder.isTypeSupported(t)) {
694
+ const list = kind === "audio" ? AUDIO_MIME_PREFERENCE : VIDEO_MIME_PREFERENCE;
695
+ for (const type of list) {
696
+ try {
697
+ if (isTypeSupported(type)) return type;
698
+ } catch {
699
+ }
700
+ }
701
+ return list[list.length - 1];
702
+ }
703
+ function createChunkedRecorder(options) {
704
+ const now = options.now ?? (() => Date.now());
705
+ const mode = options.mode ?? "restart";
706
+ let running = false;
707
+ let index = 0;
708
+ let timer = null;
709
+ let tail = Promise.resolve();
710
+ const recorderInit = () => ({
711
+ mimeType: options.mimeType,
712
+ ...options.audioBitsPerSecond ? { audioBitsPerSecond: options.audioBitsPerSecond } : {},
713
+ ...options.videoBitsPerSecond ? { videoBitsPerSecond: options.videoBitsPerSecond } : {}
714
+ });
715
+ const fail = (err) => {
716
+ running = false;
717
+ if (timer !== null) clearTimeout(timer);
718
+ timer = null;
719
+ options.onError?.(err);
720
+ };
721
+ const beginPart = () => {
722
+ let recorder;
723
+ try {
724
+ recorder = new MediaRecorder(options.stream, recorderInit());
725
+ } catch (err) {
726
+ fail(err);
727
+ return void 0;
728
+ }
729
+ const chunks = [];
730
+ const part = { recorder, startedAt: now(), chunks };
731
+ recorder.ondataavailable = (e) => {
732
+ if (e.data.size > 0) chunks.push(e.data);
733
+ };
734
+ recorder.onstart = () => {
735
+ part.startedAt = now();
736
+ };
737
+ try {
738
+ recorder.start();
739
+ } catch (err) {
740
+ fail(err);
741
+ return void 0;
742
+ }
743
+ return part;
744
+ };
745
+ const endPart = (part) => new Promise((resolve) => {
746
+ const { recorder, startedAt, chunks } = part;
747
+ const durationMs = Math.max(0, now() - startedAt);
748
+ const partIndex = index++;
749
+ const emit = () => {
750
+ if (chunks.length) {
751
+ const type = recorder.mimeType || options.mimeType;
752
+ options.onChunk({
753
+ blob: new Blob(chunks, { type }),
754
+ mimeType: type,
755
+ index: partIndex,
756
+ startedAt,
757
+ durationMs,
758
+ standalone: true
759
+ });
760
+ }
761
+ resolve();
762
+ };
763
+ if (recorder.state === "inactive") {
764
+ emit();
765
+ return;
766
+ }
767
+ recorder.onstop = emit;
768
+ recorder.stop();
769
+ });
770
+ let open;
771
+ const rotate = () => {
772
+ if (!running || !open) return;
773
+ const finished = open;
774
+ open = beginPart();
775
+ tail = tail.then(() => endPart(finished));
776
+ if (running) timer = setTimeout(rotate, options.chunkMs);
777
+ };
778
+ let sliceStartedAt = 0;
779
+ let sliceRecorder = null;
780
+ let stopResolve = null;
781
+ const startTimeslice = () => {
782
+ let recorder;
783
+ try {
784
+ recorder = new MediaRecorder(options.stream, recorderInit());
785
+ } catch (err) {
786
+ fail(err);
787
+ return;
788
+ }
789
+ sliceRecorder = recorder;
790
+ sliceStartedAt = now();
791
+ recorder.ondataavailable = (e) => {
792
+ const at = now();
793
+ const startedAt = sliceStartedAt;
794
+ sliceStartedAt = at;
795
+ if (!e.data.size) return;
796
+ const type = recorder.mimeType || options.mimeType;
797
+ const partIndex = index++;
798
+ options.onChunk({
799
+ blob: e.data,
800
+ mimeType: type,
801
+ index: partIndex,
802
+ startedAt,
803
+ durationMs: Math.max(0, at - startedAt),
804
+ standalone: partIndex === 0
805
+ });
806
+ };
807
+ recorder.onstop = () => {
808
+ stopResolve?.();
809
+ stopResolve = null;
810
+ };
811
+ try {
812
+ recorder.start();
813
+ } catch (err) {
814
+ sliceRecorder = null;
815
+ fail(err);
816
+ return;
817
+ }
818
+ timer = setInterval(() => {
819
+ if (recorder.state === "recording") recorder.requestData();
820
+ }, options.chunkMs);
821
+ };
822
+ return {
823
+ get running() {
824
+ return running;
825
+ },
826
+ start() {
827
+ if (running) return;
828
+ running = true;
829
+ index = 0;
830
+ if (mode === "timeslice") {
831
+ startTimeslice();
832
+ return;
833
+ }
834
+ open = beginPart();
835
+ if (running) timer = setTimeout(rotate, options.chunkMs);
836
+ },
837
+ stop() {
838
+ if (!running && !open && !sliceRecorder) return tail;
839
+ running = false;
840
+ if (timer !== null) {
841
+ clearTimeout(timer);
842
+ clearInterval(timer);
843
+ }
844
+ timer = null;
845
+ if (mode === "timeslice") {
846
+ const recorder = sliceRecorder;
847
+ sliceRecorder = null;
848
+ if (!recorder || recorder.state === "inactive") return tail;
849
+ tail = new Promise((resolve) => {
850
+ stopResolve = resolve;
851
+ recorder.stop();
852
+ });
853
+ return tail;
854
+ }
855
+ const finished = open;
856
+ open = void 0;
857
+ if (finished) tail = tail.then(() => endPart(finished));
858
+ return tail;
859
+ }
860
+ };
861
+ }
862
+
863
+ // src/documents/audio-segmenter.ts
864
+ var DEFAULT_SEGMENTER_CONFIG = {
865
+ voiceThreshold: 0.3,
866
+ silenceMs: 700,
867
+ maxMs: 1e4,
868
+ minVoiceMs: 600
869
+ };
870
+ var INITIAL_SEGMENTER_STATE = { phase: "idle" };
871
+ function levelFromRms(rms) {
872
+ return Math.sqrt(Math.min(1, rms * 8));
873
+ }
874
+ function end(state, at, reason, config) {
875
+ return {
876
+ type: "end",
877
+ at,
878
+ startedAt: state.startedAt,
879
+ voiceMs: state.voiceMs,
880
+ keep: state.voiceMs >= config.minVoiceMs,
881
+ reason
882
+ };
883
+ }
884
+ function stepSegmenter(state, level, t, config = DEFAULT_SEGMENTER_CONFIG) {
885
+ const voice = level >= config.voiceThreshold;
886
+ if (state.phase === "idle") {
887
+ if (!voice) return { state, events: [] };
888
+ return {
889
+ state: { phase: "voice", startedAt: t, lastVoiceAt: t, lastSampleAt: t, voiceMs: 0 },
890
+ events: [{ type: "start", at: t }]
891
+ };
892
+ }
893
+ const dt = Math.max(0, t - state.lastSampleAt);
894
+ const next = {
895
+ ...state,
896
+ lastSampleAt: t,
897
+ lastVoiceAt: voice ? t : state.lastVoiceAt,
898
+ voiceMs: state.voiceMs + (voice ? dt : 0)
899
+ };
900
+ if (t - next.startedAt >= config.maxMs) {
901
+ const events = [end(next, t, "max", config)];
902
+ if (!voice) return { state: { phase: "idle" }, events };
903
+ events.push({ type: "start", at: t });
904
+ return {
905
+ state: { phase: "voice", startedAt: t, lastVoiceAt: t, lastSampleAt: t, voiceMs: 0 },
906
+ events
907
+ };
908
+ }
909
+ const silence = config.silenceMs + (next.voiceMs < config.minVoiceMs ? config.holdShortMs ?? 0 : 0);
910
+ if (!voice && t - next.lastVoiceAt >= silence) {
911
+ return { state: { phase: "idle" }, events: [end(next, t, "silence", config)] };
912
+ }
913
+ return { state: next, events: [] };
914
+ }
915
+ function flushSegmenter(state, t, config = DEFAULT_SEGMENTER_CONFIG) {
916
+ if (state.phase === "idle") return { state, events: [] };
917
+ return { state: { phase: "idle" }, events: [end(state, t, "flush", config)] };
918
+ }
677
919
  var LEVEL_UPDATE_INTERVAL_MS = 50;
678
- function useAudioRecorder() {
920
+ function pickSegmentMimeType() {
921
+ if (MediaRecorder.isTypeSupported("audio/webm;codecs=opus")) return "audio/webm;codecs=opus";
922
+ return MediaRecorder.isTypeSupported("audio/webm") ? "audio/webm" : "audio/mp4";
923
+ }
924
+ function useAudioRecorder(options = {}) {
925
+ const optionsRef = useRef(options);
926
+ optionsRef.current = options;
679
927
  const [state, setState] = useState("idle");
680
928
  const [level, setLevel] = useState(0);
681
929
  const [elapsedMs, setElapsedMs] = useState(0);
@@ -685,6 +933,7 @@ function useAudioRecorder() {
685
933
  const mediaRecorderRef = useRef(null);
686
934
  const chunksRef = useRef([]);
687
935
  const streamRef = useRef(null);
936
+ const ownsStreamRef = useRef(false);
688
937
  const stateRef = useRef("idle");
689
938
  stateRef.current = state;
690
939
  const segmentStartRef = useRef(0);
@@ -692,60 +941,195 @@ function useAudioRecorder() {
692
941
  const audioContextRef = useRef(null);
693
942
  const analyserRef = useRef(null);
694
943
  const levelRafRef = useRef(null);
944
+ const levelIntervalRef = useRef(null);
945
+ const segmentingRef = useRef(false);
946
+ const segmenterStateRef = useRef(INITIAL_SEGMENTER_STATE);
947
+ const openSegmentRef = useRef(null);
948
+ const segmentMimeTypeRef = useRef(null);
949
+ const chunkedRef = useRef(null);
950
+ const segmenterConfig = useCallback(
951
+ () => ({ ...DEFAULT_SEGMENTER_CONFIG, ...optionsRef.current.segmenter }),
952
+ []
953
+ );
954
+ const beginSegment = useCallback(() => {
955
+ const stream = streamRef.current;
956
+ const mt = segmentMimeTypeRef.current;
957
+ if (!stream || !mt) return;
958
+ const recorder = new MediaRecorder(stream, { mimeType: mt });
959
+ const chunks = [];
960
+ recorder.ondataavailable = (e) => {
961
+ if (e.data.size > 0) chunks.push(e.data);
962
+ };
963
+ recorder.start();
964
+ openSegmentRef.current = { recorder, chunks, startedAt: Date.now() };
965
+ }, []);
966
+ const endSegment = useCallback((keep, voiceMs) => {
967
+ const open = openSegmentRef.current;
968
+ openSegmentRef.current = null;
969
+ if (!open) return;
970
+ const { recorder, chunks, startedAt } = open;
971
+ const durationMs = Date.now() - startedAt;
972
+ recorder.onstop = () => {
973
+ const onSegment = optionsRef.current.onSegment;
974
+ if (!keep || !chunks.length || !onSegment) return;
975
+ const type = recorder.mimeType || segmentMimeTypeRef.current || "audio/webm";
976
+ onSegment({
977
+ blob: new Blob(chunks, { type }),
978
+ mimeType: type,
979
+ startedAt,
980
+ durationMs,
981
+ voiceMs
982
+ });
983
+ };
984
+ if (recorder.state !== "inactive") recorder.stop();
985
+ }, []);
986
+ const applySegmenterEvents = useCallback(
987
+ (events) => {
988
+ for (const event of events) {
989
+ if (event.type === "start") beginSegment();
990
+ else endSegment(event.keep, event.voiceMs);
991
+ }
992
+ },
993
+ [beginSegment, endSegment]
994
+ );
995
+ const flushOpenSegment = useCallback(() => {
996
+ if (!segmentingRef.current) return;
997
+ const flushed = flushSegmenter(segmenterStateRef.current, performance.now(), segmenterConfig());
998
+ segmenterStateRef.current = flushed.state;
999
+ applySegmenterEvents(flushed.events);
1000
+ endSegment(false, 0);
1001
+ }, [segmenterConfig, applySegmenterEvents, endSegment]);
695
1002
  const stopMeter = useCallback(() => {
696
1003
  if (levelRafRef.current !== null) cancelAnimationFrame(levelRafRef.current);
697
1004
  levelRafRef.current = null;
1005
+ if (levelIntervalRef.current !== null) clearInterval(levelIntervalRef.current);
1006
+ levelIntervalRef.current = null;
698
1007
  analyserRef.current = null;
699
1008
  void audioContextRef.current?.close().catch(() => {
700
1009
  });
701
1010
  audioContextRef.current = null;
702
1011
  }, []);
703
- const startMeter = useCallback((stream) => {
704
- const audioContext = new AudioContext();
705
- const source = audioContext.createMediaStreamSource(stream);
706
- const analyser = audioContext.createAnalyser();
707
- analyser.fftSize = 256;
708
- source.connect(analyser);
709
- audioContextRef.current = audioContext;
710
- analyserRef.current = analyser;
711
- const data = new Uint8Array(analyser.frequencyBinCount);
712
- let lastUpdate = 0;
713
- const tick = (t) => {
714
- const active = analyserRef.current;
715
- if (!active) return;
716
- if (t - lastUpdate >= LEVEL_UPDATE_INTERVAL_MS) {
717
- lastUpdate = t;
718
- active.getByteTimeDomainData(data);
719
- let sumSquares = 0;
720
- for (let i = 0; i < data.length; i++) {
721
- const centered = (data[i] - 128) / 128;
722
- sumSquares += centered * centered;
1012
+ const startMeter = useCallback(
1013
+ (stream) => {
1014
+ const audioContext = new AudioContext();
1015
+ const source = audioContext.createMediaStreamSource(stream);
1016
+ const analyser = audioContext.createAnalyser();
1017
+ analyser.fftSize = 256;
1018
+ source.connect(analyser);
1019
+ audioContextRef.current = audioContext;
1020
+ analyserRef.current = analyser;
1021
+ const data = new Uint8Array(analyser.frequencyBinCount);
1022
+ const segmenting = segmentingRef.current;
1023
+ let lastUpdate = 0;
1024
+ const tick = (t) => {
1025
+ const active = analyserRef.current;
1026
+ if (!active) return;
1027
+ if (t - lastUpdate >= LEVEL_UPDATE_INTERVAL_MS) {
1028
+ lastUpdate = t;
1029
+ active.getByteTimeDomainData(data);
1030
+ let sumSquares = 0;
1031
+ for (let i = 0; i < data.length; i++) {
1032
+ const centered = (data[i] - 128) / 128;
1033
+ sumSquares += centered * centered;
1034
+ }
1035
+ const rms = Math.sqrt(sumSquares / data.length);
1036
+ const nextLevel = levelFromRms(rms);
1037
+ setLevel(nextLevel);
1038
+ setElapsedMs(accumulatedMsRef.current + (t - segmentStartRef.current));
1039
+ if (segmenting) {
1040
+ const step = stepSegmenter(segmenterStateRef.current, nextLevel, t, segmenterConfig());
1041
+ segmenterStateRef.current = step.state;
1042
+ applySegmenterEvents(step.events);
1043
+ }
723
1044
  }
724
- const rms = Math.sqrt(sumSquares / data.length);
725
- setLevel(Math.sqrt(Math.min(1, rms * 8)));
726
- setElapsedMs(accumulatedMsRef.current + (t - segmentStartRef.current));
1045
+ if (!segmenting) levelRafRef.current = requestAnimationFrame(tick);
1046
+ };
1047
+ if (segmenting) {
1048
+ levelIntervalRef.current = setInterval(
1049
+ () => tick(performance.now()),
1050
+ LEVEL_UPDATE_INTERVAL_MS
1051
+ );
1052
+ } else {
1053
+ levelRafRef.current = requestAnimationFrame(tick);
727
1054
  }
728
- levelRafRef.current = requestAnimationFrame(tick);
729
- };
730
- levelRafRef.current = requestAnimationFrame(tick);
731
- }, []);
1055
+ },
1056
+ [segmenterConfig, applySegmenterEvents]
1057
+ );
732
1058
  const stopTracks = useCallback(() => {
733
- streamRef.current?.getTracks().forEach((t) => t.stop());
1059
+ if (ownsStreamRef.current) streamRef.current?.getTracks().forEach((t) => t.stop());
734
1060
  streamRef.current = null;
1061
+ ownsStreamRef.current = false;
735
1062
  }, []);
736
1063
  useEffect(
737
1064
  () => () => {
1065
+ void chunkedRef.current?.stop();
1066
+ chunkedRef.current = null;
1067
+ flushOpenSegment();
1068
+ endSegment(false, 0);
1069
+ segmentingRef.current = false;
1070
+ segmenterStateRef.current = INITIAL_SEGMENTER_STATE;
738
1071
  stopTracks();
739
1072
  stopMeter();
740
1073
  },
741
- [stopTracks, stopMeter]
1074
+ [flushOpenSegment, endSegment, stopTracks, stopMeter]
742
1075
  );
1076
+ useEffect(() => {
1077
+ const onPageHide = () => flushOpenSegment();
1078
+ window.addEventListener("pagehide", onPageHide);
1079
+ return () => window.removeEventListener("pagehide", onPageHide);
1080
+ }, [flushOpenSegment]);
743
1081
  const start = useCallback(async () => {
744
1082
  if (stateRef.current === "recording" || stateRef.current === "paused") return;
745
1083
  setError(null);
746
1084
  try {
747
- const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
1085
+ const { track, onSegment } = optionsRef.current;
1086
+ const stream = track ? new MediaStream([track]) : await navigator.mediaDevices.getUserMedia({ audio: true });
748
1087
  streamRef.current = stream;
1088
+ ownsStreamRef.current = !track;
1089
+ const { chunkMs } = optionsRef.current;
1090
+ if (onSegment && chunkMs) {
1091
+ const mt2 = optionsRef.current.mimeType ?? pickRecorderMimeType("audio");
1092
+ const chunked = createChunkedRecorder({
1093
+ stream,
1094
+ mimeType: mt2,
1095
+ chunkMs,
1096
+ audioBitsPerSecond: optionsRef.current.audioBitsPerSecond,
1097
+ onChunk: (chunk) => optionsRef.current.onSegment?.({
1098
+ blob: chunk.blob,
1099
+ mimeType: chunk.mimeType,
1100
+ startedAt: chunk.startedAt,
1101
+ durationMs: chunk.durationMs,
1102
+ voiceMs: chunk.durationMs,
1103
+ index: chunk.index
1104
+ }),
1105
+ onError: (err) => setError(classifyMediaError(err, "microphone"))
1106
+ });
1107
+ chunkedRef.current = chunked;
1108
+ segmentingRef.current = false;
1109
+ setMimeType(mt2);
1110
+ setBlob(null);
1111
+ accumulatedMsRef.current = 0;
1112
+ segmentStartRef.current = performance.now();
1113
+ chunked.start();
1114
+ stateRef.current = "recording";
1115
+ setState("recording");
1116
+ return;
1117
+ }
1118
+ if (onSegment) {
1119
+ const mt2 = pickSegmentMimeType();
1120
+ segmentMimeTypeRef.current = mt2;
1121
+ segmentingRef.current = true;
1122
+ segmenterStateRef.current = INITIAL_SEGMENTER_STATE;
1123
+ setMimeType(mt2);
1124
+ setBlob(null);
1125
+ accumulatedMsRef.current = 0;
1126
+ segmentStartRef.current = performance.now();
1127
+ stateRef.current = "recording";
1128
+ setState("recording");
1129
+ startMeter(stream);
1130
+ return;
1131
+ }
1132
+ segmentingRef.current = false;
749
1133
  const mt = MediaRecorder.isTypeSupported("audio/webm") ? "audio/webm" : "audio/mp4";
750
1134
  const recorder = new MediaRecorder(stream, { mimeType: mt });
751
1135
  chunksRef.current = [];
@@ -761,11 +1145,13 @@ function useAudioRecorder() {
761
1145
  setState("recording");
762
1146
  startMeter(stream);
763
1147
  } catch (err) {
1148
+ segmentingRef.current = false;
764
1149
  stopTracks();
765
1150
  setError(classifyMediaError(err, "microphone"));
766
1151
  }
767
1152
  }, [startMeter, stopTracks]);
768
1153
  const pause = useCallback(() => {
1154
+ if (segmentingRef.current || chunkedRef.current) return;
769
1155
  const recorder = mediaRecorderRef.current;
770
1156
  if (!recorder || recorder.state !== "recording") return;
771
1157
  recorder.pause();
@@ -775,6 +1161,7 @@ function useAudioRecorder() {
775
1161
  setState("paused");
776
1162
  }, [stopMeter]);
777
1163
  const resume = useCallback(() => {
1164
+ if (segmentingRef.current || chunkedRef.current) return;
778
1165
  const recorder = mediaRecorderRef.current;
779
1166
  if (!recorder || recorder.state !== "paused") return;
780
1167
  recorder.resume();
@@ -783,6 +1170,26 @@ function useAudioRecorder() {
783
1170
  if (streamRef.current) startMeter(streamRef.current);
784
1171
  }, [startMeter]);
785
1172
  const stop = useCallback(() => {
1173
+ const chunked = chunkedRef.current;
1174
+ if (chunked) {
1175
+ chunkedRef.current = null;
1176
+ void chunked.stop();
1177
+ setElapsedMs(accumulatedMsRef.current + (performance.now() - segmentStartRef.current));
1178
+ stopTracks();
1179
+ stateRef.current = "stopped";
1180
+ setState("stopped");
1181
+ return;
1182
+ }
1183
+ if (segmentingRef.current) {
1184
+ flushOpenSegment();
1185
+ segmentingRef.current = false;
1186
+ stopMeter();
1187
+ stopTracks();
1188
+ setLevel(0);
1189
+ stateRef.current = "stopped";
1190
+ setState("stopped");
1191
+ return;
1192
+ }
786
1193
  const recorder = mediaRecorderRef.current;
787
1194
  if (!recorder || recorder.state === "inactive") return;
788
1195
  const finalElapsed = recorder.state === "paused" ? accumulatedMsRef.current : accumulatedMsRef.current + (performance.now() - segmentStartRef.current);
@@ -796,7 +1203,7 @@ function useAudioRecorder() {
796
1203
  setState("stopped");
797
1204
  };
798
1205
  recorder.stop();
799
- }, [stopMeter, stopTracks]);
1206
+ }, [stopMeter, stopTracks, flushOpenSegment]);
800
1207
  const reset = useCallback(() => {
801
1208
  setState("idle");
802
1209
  setBlob(null);
@@ -3978,6 +4385,6 @@ function DocumentCard({
3978
4385
  );
3979
4386
  }
3980
4387
 
3981
- export { AgentBadge, AiMarkdown, ArbiBotHeadIcon, AudIcon, Avatar, AvatarFallback, AvatarImage, BASE_COLORS2 as BASE_COLORS, Badge, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Collapsible, CollapsibleContent2 as CollapsibleContent, CollapsibleTrigger2 as CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, DictateProvider, DocIcon, DocumentCard, DocumentEntity, ENTITY_MAPPINGS, EmlIcon, EntityIcon, EntityPill, FILE_TYPE_COLORS, HoverCard, HoverCardContent, HoverCardTrigger, HtmlIcon, IconToggle, ImgIcon, InlineMicButton, Input, Label2 as Label, MarkMenu, MicRecordingOverlay, MicWaveformIndicator, NEUTRAL_GRAY2 as NEUTRAL_GRAY, PLACEHOLDER_COLOR, PassageCard, PdfIcon, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, PresenceLabel, Progress, ProjectEntity, RadioGroup, RadioGroupItem, RagDot, RelevanceDot, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator2 as Separator, Slider, StatusPill, Switch, TAG_TYPE_ICONS, TAG_TYPE_LABELS, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TagEntity, Textarea, ThreadVisibilityIcon, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TxtIcon, UserEntity, UserMenu, VISIBILITY_ICONS, VerifiedBadge, VidIcon, VisibilityIcon, VisibilityToggle, XlsIcon, badgeVariants, cardVariants, classifyMediaError, configureEntityRegistry, configureRagLabels, configureStatusRegistry, formatElapsed, getDocIcon, getEntityColor2 as getEntityColor, getEntityColorStyles, getEntityIcon, getEntityLabel, getStatusVariant, getTagTypeIcon, getTagTypeLabel, getWorkspaceColor, returnFocusToMark, toggleVariants, useAudioRecorder };
3982
- //# sourceMappingURL=chunk-P4A5EG5B.js.map
3983
- //# sourceMappingURL=chunk-P4A5EG5B.js.map
4388
+ export { AUDIO_MIME_PREFERENCE, AgentBadge, AiMarkdown, ArbiBotHeadIcon, AudIcon, Avatar, AvatarFallback, AvatarImage, BASE_COLORS2 as BASE_COLORS, Badge, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, Collapsible, CollapsibleContent2 as CollapsibleContent, CollapsibleTrigger2 as CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, DEFAULT_SEGMENTER_CONFIG, DictateProvider, DocIcon, DocumentCard, DocumentEntity, ENTITY_MAPPINGS, EmlIcon, EntityIcon, EntityPill, FILE_TYPE_COLORS, HoverCard, HoverCardContent, HoverCardTrigger, HtmlIcon, INITIAL_SEGMENTER_STATE, IconToggle, ImgIcon, InlineMicButton, Input, Label2 as Label, MarkMenu, MicRecordingOverlay, MicWaveformIndicator, NEUTRAL_GRAY2 as NEUTRAL_GRAY, PLACEHOLDER_COLOR, PassageCard, PdfIcon, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, PresenceLabel, Progress, ProjectEntity, RadioGroup, RadioGroupItem, RagDot, RelevanceDot, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator2 as Separator, Slider, StatusPill, Switch, TAG_TYPE_ICONS, TAG_TYPE_LABELS, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TagEntity, Textarea, ThreadVisibilityIcon, Toggle, ToggleGroup, ToggleGroupItem, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TxtIcon, UserEntity, UserMenu, VIDEO_MIME_PREFERENCE, VISIBILITY_ICONS, VerifiedBadge, VidIcon, VisibilityIcon, VisibilityToggle, XlsIcon, badgeVariants, cardVariants, classifyMediaError, configureEntityRegistry, configureRagLabels, configureStatusRegistry, createChunkedRecorder, flushSegmenter, formatElapsed, getDocIcon, getEntityColor2 as getEntityColor, getEntityColorStyles, getEntityIcon, getEntityLabel, getStatusVariant, getTagTypeIcon, getTagTypeLabel, getWorkspaceColor, levelFromRms, pickRecorderMimeType, returnFocusToMark, stepSegmenter, toggleVariants, useAudioRecorder };
4389
+ //# sourceMappingURL=chunk-5L46Z7HZ.js.map
4390
+ //# sourceMappingURL=chunk-5L46Z7HZ.js.map