@promptbook/components 0.113.0-6 → 0.113.0-7

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.
@@ -8,7 +8,7 @@ export declare function insertDictationChunk(params: {
8
8
  readonly dictatedText: string;
9
9
  readonly selectionStart: number;
10
10
  readonly selectionEnd: number;
11
- readonly shouldReplaceSelection: boolean;
11
+ readonly isReplacingSelection: boolean;
12
12
  }): {
13
13
  nextValue: string;
14
14
  start: number;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Creates a Commander argument parser that accepts only positive integers.
3
+ *
4
+ * The returned parser is meant to be passed as the coercion callback of `command.option(...)`.
5
+ * It throws a branded `NotAllowed` error with a clear message referencing the given option name
6
+ * when the provided value is not a positive integer.
7
+ *
8
+ * @private internal utility of `promptbookCli`
9
+ */
10
+ export declare function createPositiveIntegerOptionParser(optionName: string): (value: string) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/components",
3
- "version": "0.113.0-6",
3
+ "version": "0.113.0-7",
4
4
  "description": "Promptbook: Create persistent AI agents that turn your company's scattered knowledge into action",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -34,7 +34,7 @@
34
34
  * @generated
35
35
  * @see https://github.com/webgptorg/promptbook
36
36
  */
37
- const PROMPTBOOK_ENGINE_VERSION = '0.113.0-6';
37
+ const PROMPTBOOK_ENGINE_VERSION = '0.113.0-7';
38
38
  /**
39
39
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
40
40
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -31158,9 +31158,9 @@
31158
31158
  * @private function of `useChatInputAreaDictation`
31159
31159
  */
31160
31160
  function insertDictationChunk(params) {
31161
- const { currentValue, dictatedText, selectionStart, selectionEnd, shouldReplaceSelection } = params;
31161
+ const { currentValue, dictatedText, selectionStart, selectionEnd, isReplacingSelection } = params;
31162
31162
  const replaceStart = selectionStart;
31163
- const replaceEnd = shouldReplaceSelection ? selectionEnd : selectionStart;
31163
+ const replaceEnd = isReplacingSelection ? selectionEnd : selectionStart;
31164
31164
  const prefix = currentValue.slice(0, replaceStart);
31165
31165
  const suffix = currentValue.slice(replaceEnd);
31166
31166
  const previousCharacter = prefix.slice(-1);
@@ -31202,7 +31202,7 @@
31202
31202
  if (!previousWord || !correctedWord) {
31203
31203
  continue;
31204
31204
  }
31205
- if (previousWord.toLowerCase() !== correctedWord.toLowerCase()) {
31205
+ if (previousWord !== correctedWord) {
31206
31206
  nextDictionary[previousWord.toLowerCase()] = correctedWord;
31207
31207
  }
31208
31208
  }
@@ -31696,17 +31696,73 @@
31696
31696
  pendingStopFallbackRef.current = null;
31697
31697
  }
31698
31698
  /**
31699
- * Captures whether the next finalized chunk should replace the current selection.
31699
+ * Captures where the next finalized chunk should be inserted.
31700
31700
  *
31701
31701
  * @private function of `useChatInputAreaDictation`
31702
31702
  */
31703
- function captureSelectionReplacementIntent(textareaRef, replaceSelectionOnNextFinalRef) {
31703
+ function captureDictationInsertionSelection(textareaRef, dictationInsertionSelectionRef) {
31704
31704
  const textarea = textareaRef.current;
31705
31705
  if (!textarea) {
31706
31706
  return;
31707
31707
  }
31708
- const { selectionStart, selectionEnd } = resolveTextareaSelection(textarea, 0);
31709
- replaceSelectionOnNextFinalRef.current = selectionStart !== selectionEnd;
31708
+ const { selectionStart, selectionEnd } = resolveTextareaSelection(textarea, textarea.value.length);
31709
+ dictationInsertionSelectionRef.current = {
31710
+ selectionStart,
31711
+ selectionEnd,
31712
+ isReplacingSelection: selectionStart !== selectionEnd,
31713
+ };
31714
+ }
31715
+ /**
31716
+ * Resolves the insertion range for one finalized dictation chunk.
31717
+ *
31718
+ * @private function of `useChatInputAreaDictation`
31719
+ */
31720
+ function resolveDictationInsertionSelection(textareaElement, messageContentLength, dictationInsertionSelection) {
31721
+ if (dictationInsertionSelection) {
31722
+ return dictationInsertionSelection;
31723
+ }
31724
+ const { selectionStart, selectionEnd } = resolveTextareaSelection(textareaElement, messageContentLength);
31725
+ return {
31726
+ selectionStart,
31727
+ selectionEnd,
31728
+ isReplacingSelection: selectionStart !== selectionEnd,
31729
+ };
31730
+ }
31731
+ /**
31732
+ * Removes one tracked dictated chunk from the current composer value.
31733
+ *
31734
+ * @private function of `useChatInputAreaDictation`
31735
+ */
31736
+ function removeTrackedDictationChunk(currentValue, chunk) {
31737
+ const trackedText = currentValue.slice(chunk.start, chunk.start + chunk.finalText.length);
31738
+ if (trackedText === chunk.finalText) {
31739
+ return `${currentValue.slice(0, chunk.start)}${currentValue.slice(chunk.start + chunk.finalText.length)}`;
31740
+ }
31741
+ return replaceLastOccurrence(currentValue, chunk.finalText, '');
31742
+ }
31743
+ /**
31744
+ * Replaces one tracked dictated chunk inside the current composer value.
31745
+ *
31746
+ * @private function of `useChatInputAreaDictation`
31747
+ */
31748
+ function replaceTrackedDictationChunk(currentValue, chunk, correctedChunk) {
31749
+ const trackedText = currentValue.slice(chunk.start, chunk.start + chunk.finalText.length);
31750
+ if (trackedText === chunk.finalText) {
31751
+ return `${currentValue.slice(0, chunk.start)}${correctedChunk}${currentValue.slice(chunk.start + chunk.finalText.length)}`;
31752
+ }
31753
+ return replaceLastOccurrence(currentValue, chunk.finalText, correctedChunk);
31754
+ }
31755
+ /**
31756
+ * Stores the next append position after a programmatic dictation edit.
31757
+ *
31758
+ * @private function of `useChatInputAreaDictation`
31759
+ */
31760
+ function updateDictationInsertionCaret(dictationInsertionSelectionRef, caret) {
31761
+ dictationInsertionSelectionRef.current = {
31762
+ selectionStart: caret,
31763
+ selectionEnd: caret,
31764
+ isReplacingSelection: false,
31765
+ };
31710
31766
  }
31711
31767
  /**
31712
31768
  * Produces the corrected chunk value only when a real correction should be applied.
@@ -31787,7 +31843,7 @@
31787
31843
  *
31788
31844
  * @private function of `useChatInputAreaDictation`
31789
31845
  */
31790
- function useChatInputAreaDictationFinalResultHandler({ textareaRef, messageContentRef, applyMessageContent, dictationSettings, dictationDictionary, replaceSelectionOnNextFinalRef, focusTextareaSelection, state, }) {
31846
+ function useChatInputAreaDictationFinalResultHandler({ textareaRef, messageContentRef, applyMessageContent, dictationSettings, dictationDictionary, dictationInsertionSelectionRef, focusTextareaSelection, state, }) {
31791
31847
  const { setDictationUiState, setDictationInterimText, setDictationError, setDictationLastFinalChunk, setDictationEditableChunk, setDictationChunks, setIsDictationPanelExpanded, } = state;
31792
31848
  return react.useCallback((rawText) => {
31793
31849
  const textarea = textareaRef.current;
@@ -31799,15 +31855,15 @@
31799
31855
  if (!refinedText) {
31800
31856
  return;
31801
31857
  }
31802
- const { selectionStart, selectionEnd } = resolveTextareaSelection(textarea, previousMessageContent.length);
31858
+ const { selectionStart, selectionEnd, isReplacingSelection } = resolveDictationInsertionSelection(textarea, previousMessageContent.length, dictationInsertionSelectionRef.current);
31803
31859
  const insertion = insertDictationChunk({
31804
31860
  currentValue: previousMessageContent,
31805
31861
  dictatedText: refinedText,
31806
31862
  selectionStart,
31807
31863
  selectionEnd,
31808
- shouldReplaceSelection: replaceSelectionOnNextFinalRef.current,
31864
+ isReplacingSelection,
31809
31865
  });
31810
- replaceSelectionOnNextFinalRef.current = false;
31866
+ updateDictationInsertionCaret(dictationInsertionSelectionRef, insertion.caret);
31811
31867
  setDictationInterimText('');
31812
31868
  setDictationError(null);
31813
31869
  setDictationUiState('listening');
@@ -31827,10 +31883,10 @@
31827
31883
  }, [
31828
31884
  applyMessageContent,
31829
31885
  dictationDictionary,
31886
+ dictationInsertionSelectionRef,
31830
31887
  dictationSettings,
31831
31888
  focusTextareaSelection,
31832
31889
  messageContentRef,
31833
- replaceSelectionOnNextFinalRef,
31834
31890
  setDictationChunks,
31835
31891
  setDictationEditableChunk,
31836
31892
  setDictationError,
@@ -31878,7 +31934,7 @@
31878
31934
  return;
31879
31935
  case 'STOP':
31880
31936
  clearPendingStopFallback();
31881
- setDictationUiState((currentState) => (currentState === 'disabled' ? currentState : 'idle'));
31937
+ setDictationUiState((currentState) => currentState === 'disabled' || currentState === 'error' ? currentState : 'idle');
31882
31938
  setDictationInterimText('');
31883
31939
  return;
31884
31940
  }
@@ -31919,13 +31975,13 @@
31919
31975
  *
31920
31976
  * @private function of `useChatInputAreaDictation`
31921
31977
  */
31922
- function useChatInputAreaDictationVoiceInputControls({ speechRecognition, textareaRef, resolvedSpeechRecognitionLanguage, whisperMode, pendingStopFallbackRef, replaceSelectionOnNextFinalRef, clearPendingStopFallback, state, }) {
31978
+ function useChatInputAreaDictationVoiceInputControls({ speechRecognition, textareaRef, resolvedSpeechRecognitionLanguage, whisperMode, pendingStopFallbackRef, dictationInsertionSelectionRef, clearPendingStopFallback, state, }) {
31923
31979
  const { dictationUiState, setDictationUiState, setDictationInterimText, setDictationError } = state;
31924
31980
  const startVoiceInput = react.useCallback(() => {
31925
31981
  if (!speechRecognition) {
31926
31982
  return;
31927
31983
  }
31928
- captureSelectionReplacementIntent(textareaRef, replaceSelectionOnNextFinalRef);
31984
+ captureDictationInsertionSelection(textareaRef, dictationInsertionSelectionRef);
31929
31985
  setDictationError(null);
31930
31986
  setDictationInterimText('');
31931
31987
  setDictationUiState('listening');
@@ -31935,7 +31991,7 @@
31935
31991
  whisperMode,
31936
31992
  });
31937
31993
  }, [
31938
- replaceSelectionOnNextFinalRef,
31994
+ dictationInsertionSelectionRef,
31939
31995
  resolvedSpeechRecognitionLanguage,
31940
31996
  setDictationError,
31941
31997
  setDictationInterimText,
@@ -31987,7 +32043,7 @@
31987
32043
  *
31988
32044
  * @private function of `useChatInputAreaDictation`
31989
32045
  */
31990
- function useChatInputAreaDictationCorrectionHandlers({ dictationChunks, dictationLastFinalChunk, dictationEditableChunk, dictationDictionary, messageContentRef, applyMessageContent, focusTextareaSelection, setDictationChunks, setDictationLastFinalChunk, setDictationEditableChunk, setDictationDictionary, }) {
32046
+ function useChatInputAreaDictationCorrectionHandlers({ dictationChunks, dictationLastFinalChunk, dictationEditableChunk, dictationDictionary, dictationInsertionSelectionRef, messageContentRef, applyMessageContent, focusTextareaSelection, setDictationChunks, setDictationLastFinalChunk, setDictationEditableChunk, setDictationDictionary, }) {
31991
32047
  const handleBacktrackLastChunk = react.useCallback(() => {
31992
32048
  var _a;
31993
32049
  const previousChunks = [...dictationChunks];
@@ -31995,35 +32051,51 @@
31995
32051
  if (!lastChunk) {
31996
32052
  return;
31997
32053
  }
32054
+ const nextMessageContent = removeTrackedDictationChunk(messageContentRef.current, lastChunk);
32055
+ const nextCaret = Math.min(lastChunk.start, nextMessageContent.length);
31998
32056
  setDictationChunks(previousChunks);
31999
- applyMessageContent(lastChunk.beforeValue);
32057
+ applyMessageContent(nextMessageContent);
32000
32058
  const previousFinalChunk = ((_a = previousChunks[previousChunks.length - 1]) === null || _a === void 0 ? void 0 : _a.finalText) || '';
32001
32059
  setDictationLastFinalChunk(previousFinalChunk);
32002
32060
  setDictationEditableChunk(previousFinalChunk);
32003
- focusTextareaSelection(lastChunk.start, lastChunk.start);
32061
+ updateDictationInsertionCaret(dictationInsertionSelectionRef, nextCaret);
32062
+ focusTextareaSelection(nextCaret, nextCaret);
32004
32063
  }, [
32005
32064
  applyMessageContent,
32065
+ dictationInsertionSelectionRef,
32006
32066
  dictationChunks,
32007
32067
  focusTextareaSelection,
32068
+ messageContentRef,
32008
32069
  setDictationChunks,
32009
32070
  setDictationEditableChunk,
32010
32071
  setDictationLastFinalChunk,
32011
32072
  ]);
32012
32073
  const handleApplyCorrection = react.useCallback(() => {
32074
+ var _a;
32013
32075
  const correctedChunk = resolveCorrectedDictationChunk(dictationEditableChunk, dictationLastFinalChunk);
32014
32076
  if (!correctedChunk) {
32015
32077
  return;
32016
32078
  }
32017
- const nextMessageContent = replaceLastOccurrence(messageContentRef.current, dictationLastFinalChunk, correctedChunk);
32079
+ const lastChunk = dictationChunks[dictationChunks.length - 1];
32080
+ const nextMessageContent = lastChunk
32081
+ ? replaceTrackedDictationChunk(messageContentRef.current, lastChunk, correctedChunk)
32082
+ : replaceLastOccurrence(messageContentRef.current, dictationLastFinalChunk, correctedChunk);
32083
+ const correctionStart = (_a = lastChunk === null || lastChunk === void 0 ? void 0 : lastChunk.start) !== null && _a !== void 0 ? _a : nextMessageContent.length;
32084
+ const correctionCaret = Math.min(correctionStart + correctedChunk.length, nextMessageContent.length);
32018
32085
  applyMessageContent(nextMessageContent);
32019
32086
  setDictationLastFinalChunk(correctedChunk);
32020
32087
  setDictationChunks((previousChunks) => replaceLastDictationChunk(previousChunks, correctedChunk));
32021
32088
  setDictationDictionary(learnDictationDictionary(dictationLastFinalChunk, correctedChunk, dictationDictionary));
32089
+ updateDictationInsertionCaret(dictationInsertionSelectionRef, correctionCaret);
32090
+ focusTextareaSelection(correctionCaret, correctionCaret);
32022
32091
  }, [
32023
32092
  applyMessageContent,
32024
32093
  dictationDictionary,
32025
32094
  dictationEditableChunk,
32095
+ dictationChunks,
32096
+ dictationInsertionSelectionRef,
32026
32097
  dictationLastFinalChunk,
32098
+ focusTextareaSelection,
32027
32099
  messageContentRef,
32028
32100
  setDictationChunks,
32029
32101
  setDictationDictionary,
@@ -32041,7 +32113,7 @@
32041
32113
  */
32042
32114
  function useChatInputAreaDictation({ speechRecognition, speechRecognitionLanguage, textareaRef, messageContentRef, applyMessageContent, }) {
32043
32115
  const pendingStopFallbackRef = react.useRef(null);
32044
- const replaceSelectionOnNextFinalRef = react.useRef(false);
32116
+ const dictationInsertionSelectionRef = react.useRef(null);
32045
32117
  const [dictationUiState, setDictationUiState] = react.useState('idle');
32046
32118
  const [dictationInterimText, setDictationInterimText] = react.useState('');
32047
32119
  const [dictationError, setDictationError] = react.useState(null);
@@ -32074,7 +32146,7 @@
32074
32146
  applyMessageContent,
32075
32147
  dictationSettings,
32076
32148
  dictationDictionary,
32077
- replaceSelectionOnNextFinalRef,
32149
+ dictationInsertionSelectionRef,
32078
32150
  focusTextareaSelection,
32079
32151
  state: dictationState,
32080
32152
  });
@@ -32094,7 +32166,7 @@
32094
32166
  resolvedSpeechRecognitionLanguage,
32095
32167
  whisperMode: dictationSettings.whisperMode,
32096
32168
  pendingStopFallbackRef,
32097
- replaceSelectionOnNextFinalRef,
32169
+ dictationInsertionSelectionRef,
32098
32170
  clearPendingStopFallback,
32099
32171
  state: {
32100
32172
  dictationUiState,
@@ -32108,6 +32180,7 @@
32108
32180
  dictationLastFinalChunk,
32109
32181
  dictationEditableChunk,
32110
32182
  dictationDictionary,
32183
+ dictationInsertionSelectionRef,
32111
32184
  messageContentRef,
32112
32185
  applyMessageContent,
32113
32186
  focusTextareaSelection,