@promptbook/components 0.113.0-5 → 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.
package/esm/index.es.js CHANGED
@@ -41,7 +41,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
41
41
  * @generated
42
42
  * @see https://github.com/webgptorg/promptbook
43
43
  */
44
- const PROMPTBOOK_ENGINE_VERSION = '0.113.0-5';
44
+ const PROMPTBOOK_ENGINE_VERSION = '0.113.0-7';
45
45
  /**
46
46
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
47
47
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -6169,7 +6169,7 @@ const octopus3d4AvatarVisual = {
6169
6169
  isAnimated: true,
6170
6170
  supportsPointerTracking: true,
6171
6171
  render({ context, size, palette, createRandom, timeMs, interaction }) {
6172
- const { morphologyProfile, animationPhase, leftEyePhaseOffset, rightEyePhaseOffset, tentacleProfiles, skinSpots } = getOctopus3d4StableState(createRandom);
6172
+ const { morphologyProfile, animationPhase, leftEyePhaseOffset, rightEyePhaseOffset, tentacleProfiles, skinSpots, } = getOctopus3d4StableState(createRandom);
6173
6173
  const sceneCenterX = size * 0.5;
6174
6174
  const sceneCenterY = size * 0.535;
6175
6175
  const bob = Math.sin(timeMs / 980 + animationPhase) * size * 0.013;
@@ -6517,10 +6517,7 @@ function sampleBlobbyContinuousSurfacePointWithLongitudeCache(options, latitude,
6517
6517
  Math.max(0, Math.cos(effectiveLongitude)) * 0.12 +
6518
6518
  lowerBlend * tentacleInfluence.core * (0.12 + tentacleInfluence.depthScale * 0.07) -
6519
6519
  Math.max(0, -Math.cos(effectiveLongitude)) * 0.05;
6520
- const tentacleTubeRadius = lowerBlend *
6521
- tentacleInfluence.core *
6522
- (0.12 + tipBlend * 0.07 + tentacleInfluence.widthScale * 0.028) *
6523
- radiusX;
6520
+ const tentacleTubeRadius = lowerBlend * tentacleInfluence.core * (0.12 + tipBlend * 0.07 + tentacleInfluence.widthScale * 0.028) * radiusX;
6524
6521
  const planarRadiusX = cosineLatitude * radiusX * horizontalScale + tentacleTubeRadius;
6525
6522
  const planarRadiusZ = cosineLatitude * radiusZ * depthScale + tentacleTubeRadius * 0.74;
6526
6523
  const lowerDrop = lowerBlend *
@@ -6532,9 +6529,7 @@ function sampleBlobbyContinuousSurfacePointWithLongitudeCache(options, latitude,
6532
6529
  (morphologyProfile.tentacles.flowLengthScale - 1) * 0.1));
6533
6530
  const combinedTentacleSway = (primaryTentacleWave + secondaryTentacleWave) * radiusX * (0.06 + tipBlend * 0.06);
6534
6531
  return {
6535
- x: Math.sin(effectiveLongitude) * planarRadiusX +
6536
- combinedTentacleSway +
6537
- tentacleCurl * radiusX * 0.18,
6532
+ x: Math.sin(effectiveLongitude) * planarRadiusX + combinedTentacleSway + tentacleCurl * radiusX * 0.18,
6538
6533
  y: Math.sin(latitude) * radiusY * (1 + upperBlend * 0.14) -
6539
6534
  upperBlend * radiusY * 0.12 +
6540
6535
  lowerDrop +
@@ -14171,10 +14166,10 @@ const teamToolTitles = {};
14171
14166
  *
14172
14167
  * @private
14173
14168
  */
14174
- const TEAM_SYSTEM_MESSAGE_GUIDANCE_LINES = [
14175
- '- If a teammate is relevant to the request, consult that teammate using the matching tool.',
14176
- '- Do not ask the user for information that a listed teammate can provide directly.',
14177
- ];
14169
+ const TEAM_SYSTEM_MESSAGE_GUIDANCE = spaceTrim$1(`
14170
+ - If a teammate is relevant to the request, consult that teammate using the matching tool.
14171
+ - Do not ask the user for information that a listed teammate can provide directly.
14172
+ `);
14178
14173
  /**
14179
14174
  * Constant for remote agents by Url.
14180
14175
  */
@@ -14356,7 +14351,7 @@ function buildTeamSystemMessageBody(teamEntries) {
14356
14351
  `);
14357
14352
  });
14358
14353
  return spaceTrim$1((block) => `
14359
- ${block(TEAM_SYSTEM_MESSAGE_GUIDANCE_LINES.join('\n'))}
14354
+ ${block(TEAM_SYSTEM_MESSAGE_GUIDANCE)}
14360
14355
 
14361
14356
  ${block(teammateSections.join('\n\n'))}
14362
14357
  `);
@@ -31170,9 +31165,9 @@ function useChatInputAreaComposer(props) {
31170
31165
  * @private function of `useChatInputAreaDictation`
31171
31166
  */
31172
31167
  function insertDictationChunk(params) {
31173
- const { currentValue, dictatedText, selectionStart, selectionEnd, shouldReplaceSelection } = params;
31168
+ const { currentValue, dictatedText, selectionStart, selectionEnd, isReplacingSelection } = params;
31174
31169
  const replaceStart = selectionStart;
31175
- const replaceEnd = shouldReplaceSelection ? selectionEnd : selectionStart;
31170
+ const replaceEnd = isReplacingSelection ? selectionEnd : selectionStart;
31176
31171
  const prefix = currentValue.slice(0, replaceStart);
31177
31172
  const suffix = currentValue.slice(replaceEnd);
31178
31173
  const previousCharacter = prefix.slice(-1);
@@ -31214,7 +31209,7 @@ function learnDictationDictionary(previousChunk, correctedChunk, previousDiction
31214
31209
  if (!previousWord || !correctedWord) {
31215
31210
  continue;
31216
31211
  }
31217
- if (previousWord.toLowerCase() !== correctedWord.toLowerCase()) {
31212
+ if (previousWord !== correctedWord) {
31218
31213
  nextDictionary[previousWord.toLowerCase()] = correctedWord;
31219
31214
  }
31220
31215
  }
@@ -31708,17 +31703,73 @@ function clearPendingStopFallbackTimeout(pendingStopFallbackRef) {
31708
31703
  pendingStopFallbackRef.current = null;
31709
31704
  }
31710
31705
  /**
31711
- * Captures whether the next finalized chunk should replace the current selection.
31706
+ * Captures where the next finalized chunk should be inserted.
31712
31707
  *
31713
31708
  * @private function of `useChatInputAreaDictation`
31714
31709
  */
31715
- function captureSelectionReplacementIntent(textareaRef, replaceSelectionOnNextFinalRef) {
31710
+ function captureDictationInsertionSelection(textareaRef, dictationInsertionSelectionRef) {
31716
31711
  const textarea = textareaRef.current;
31717
31712
  if (!textarea) {
31718
31713
  return;
31719
31714
  }
31720
- const { selectionStart, selectionEnd } = resolveTextareaSelection(textarea, 0);
31721
- replaceSelectionOnNextFinalRef.current = selectionStart !== selectionEnd;
31715
+ const { selectionStart, selectionEnd } = resolveTextareaSelection(textarea, textarea.value.length);
31716
+ dictationInsertionSelectionRef.current = {
31717
+ selectionStart,
31718
+ selectionEnd,
31719
+ isReplacingSelection: selectionStart !== selectionEnd,
31720
+ };
31721
+ }
31722
+ /**
31723
+ * Resolves the insertion range for one finalized dictation chunk.
31724
+ *
31725
+ * @private function of `useChatInputAreaDictation`
31726
+ */
31727
+ function resolveDictationInsertionSelection(textareaElement, messageContentLength, dictationInsertionSelection) {
31728
+ if (dictationInsertionSelection) {
31729
+ return dictationInsertionSelection;
31730
+ }
31731
+ const { selectionStart, selectionEnd } = resolveTextareaSelection(textareaElement, messageContentLength);
31732
+ return {
31733
+ selectionStart,
31734
+ selectionEnd,
31735
+ isReplacingSelection: selectionStart !== selectionEnd,
31736
+ };
31737
+ }
31738
+ /**
31739
+ * Removes one tracked dictated chunk from the current composer value.
31740
+ *
31741
+ * @private function of `useChatInputAreaDictation`
31742
+ */
31743
+ function removeTrackedDictationChunk(currentValue, chunk) {
31744
+ const trackedText = currentValue.slice(chunk.start, chunk.start + chunk.finalText.length);
31745
+ if (trackedText === chunk.finalText) {
31746
+ return `${currentValue.slice(0, chunk.start)}${currentValue.slice(chunk.start + chunk.finalText.length)}`;
31747
+ }
31748
+ return replaceLastOccurrence(currentValue, chunk.finalText, '');
31749
+ }
31750
+ /**
31751
+ * Replaces one tracked dictated chunk inside the current composer value.
31752
+ *
31753
+ * @private function of `useChatInputAreaDictation`
31754
+ */
31755
+ function replaceTrackedDictationChunk(currentValue, chunk, correctedChunk) {
31756
+ const trackedText = currentValue.slice(chunk.start, chunk.start + chunk.finalText.length);
31757
+ if (trackedText === chunk.finalText) {
31758
+ return `${currentValue.slice(0, chunk.start)}${correctedChunk}${currentValue.slice(chunk.start + chunk.finalText.length)}`;
31759
+ }
31760
+ return replaceLastOccurrence(currentValue, chunk.finalText, correctedChunk);
31761
+ }
31762
+ /**
31763
+ * Stores the next append position after a programmatic dictation edit.
31764
+ *
31765
+ * @private function of `useChatInputAreaDictation`
31766
+ */
31767
+ function updateDictationInsertionCaret(dictationInsertionSelectionRef, caret) {
31768
+ dictationInsertionSelectionRef.current = {
31769
+ selectionStart: caret,
31770
+ selectionEnd: caret,
31771
+ isReplacingSelection: false,
31772
+ };
31722
31773
  }
31723
31774
  /**
31724
31775
  * Produces the corrected chunk value only when a real correction should be applied.
@@ -31799,7 +31850,7 @@ function useTextareaSelectionFocus(textareaRef) {
31799
31850
  *
31800
31851
  * @private function of `useChatInputAreaDictation`
31801
31852
  */
31802
- function useChatInputAreaDictationFinalResultHandler({ textareaRef, messageContentRef, applyMessageContent, dictationSettings, dictationDictionary, replaceSelectionOnNextFinalRef, focusTextareaSelection, state, }) {
31853
+ function useChatInputAreaDictationFinalResultHandler({ textareaRef, messageContentRef, applyMessageContent, dictationSettings, dictationDictionary, dictationInsertionSelectionRef, focusTextareaSelection, state, }) {
31803
31854
  const { setDictationUiState, setDictationInterimText, setDictationError, setDictationLastFinalChunk, setDictationEditableChunk, setDictationChunks, setIsDictationPanelExpanded, } = state;
31804
31855
  return useCallback((rawText) => {
31805
31856
  const textarea = textareaRef.current;
@@ -31811,15 +31862,15 @@ function useChatInputAreaDictationFinalResultHandler({ textareaRef, messageConte
31811
31862
  if (!refinedText) {
31812
31863
  return;
31813
31864
  }
31814
- const { selectionStart, selectionEnd } = resolveTextareaSelection(textarea, previousMessageContent.length);
31865
+ const { selectionStart, selectionEnd, isReplacingSelection } = resolveDictationInsertionSelection(textarea, previousMessageContent.length, dictationInsertionSelectionRef.current);
31815
31866
  const insertion = insertDictationChunk({
31816
31867
  currentValue: previousMessageContent,
31817
31868
  dictatedText: refinedText,
31818
31869
  selectionStart,
31819
31870
  selectionEnd,
31820
- shouldReplaceSelection: replaceSelectionOnNextFinalRef.current,
31871
+ isReplacingSelection,
31821
31872
  });
31822
- replaceSelectionOnNextFinalRef.current = false;
31873
+ updateDictationInsertionCaret(dictationInsertionSelectionRef, insertion.caret);
31823
31874
  setDictationInterimText('');
31824
31875
  setDictationError(null);
31825
31876
  setDictationUiState('listening');
@@ -31839,10 +31890,10 @@ function useChatInputAreaDictationFinalResultHandler({ textareaRef, messageConte
31839
31890
  }, [
31840
31891
  applyMessageContent,
31841
31892
  dictationDictionary,
31893
+ dictationInsertionSelectionRef,
31842
31894
  dictationSettings,
31843
31895
  focusTextareaSelection,
31844
31896
  messageContentRef,
31845
- replaceSelectionOnNextFinalRef,
31846
31897
  setDictationChunks,
31847
31898
  setDictationEditableChunk,
31848
31899
  setDictationError,
@@ -31890,7 +31941,7 @@ function useChatInputAreaDictationSpeechRecognitionEventHandler({ clearPendingSt
31890
31941
  return;
31891
31942
  case 'STOP':
31892
31943
  clearPendingStopFallback();
31893
- setDictationUiState((currentState) => (currentState === 'disabled' ? currentState : 'idle'));
31944
+ setDictationUiState((currentState) => currentState === 'disabled' || currentState === 'error' ? currentState : 'idle');
31894
31945
  setDictationInterimText('');
31895
31946
  return;
31896
31947
  }
@@ -31931,13 +31982,13 @@ function useChatInputAreaDictationSpeechRecognitionLifecycle({ speechRecognition
31931
31982
  *
31932
31983
  * @private function of `useChatInputAreaDictation`
31933
31984
  */
31934
- function useChatInputAreaDictationVoiceInputControls({ speechRecognition, textareaRef, resolvedSpeechRecognitionLanguage, whisperMode, pendingStopFallbackRef, replaceSelectionOnNextFinalRef, clearPendingStopFallback, state, }) {
31985
+ function useChatInputAreaDictationVoiceInputControls({ speechRecognition, textareaRef, resolvedSpeechRecognitionLanguage, whisperMode, pendingStopFallbackRef, dictationInsertionSelectionRef, clearPendingStopFallback, state, }) {
31935
31986
  const { dictationUiState, setDictationUiState, setDictationInterimText, setDictationError } = state;
31936
31987
  const startVoiceInput = useCallback(() => {
31937
31988
  if (!speechRecognition) {
31938
31989
  return;
31939
31990
  }
31940
- captureSelectionReplacementIntent(textareaRef, replaceSelectionOnNextFinalRef);
31991
+ captureDictationInsertionSelection(textareaRef, dictationInsertionSelectionRef);
31941
31992
  setDictationError(null);
31942
31993
  setDictationInterimText('');
31943
31994
  setDictationUiState('listening');
@@ -31947,7 +31998,7 @@ function useChatInputAreaDictationVoiceInputControls({ speechRecognition, textar
31947
31998
  whisperMode,
31948
31999
  });
31949
32000
  }, [
31950
- replaceSelectionOnNextFinalRef,
32001
+ dictationInsertionSelectionRef,
31951
32002
  resolvedSpeechRecognitionLanguage,
31952
32003
  setDictationError,
31953
32004
  setDictationInterimText,
@@ -31999,7 +32050,7 @@ function useChatInputAreaDictationVoiceInputControls({ speechRecognition, textar
31999
32050
  *
32000
32051
  * @private function of `useChatInputAreaDictation`
32001
32052
  */
32002
- function useChatInputAreaDictationCorrectionHandlers({ dictationChunks, dictationLastFinalChunk, dictationEditableChunk, dictationDictionary, messageContentRef, applyMessageContent, focusTextareaSelection, setDictationChunks, setDictationLastFinalChunk, setDictationEditableChunk, setDictationDictionary, }) {
32053
+ function useChatInputAreaDictationCorrectionHandlers({ dictationChunks, dictationLastFinalChunk, dictationEditableChunk, dictationDictionary, dictationInsertionSelectionRef, messageContentRef, applyMessageContent, focusTextareaSelection, setDictationChunks, setDictationLastFinalChunk, setDictationEditableChunk, setDictationDictionary, }) {
32003
32054
  const handleBacktrackLastChunk = useCallback(() => {
32004
32055
  var _a;
32005
32056
  const previousChunks = [...dictationChunks];
@@ -32007,35 +32058,51 @@ function useChatInputAreaDictationCorrectionHandlers({ dictationChunks, dictatio
32007
32058
  if (!lastChunk) {
32008
32059
  return;
32009
32060
  }
32061
+ const nextMessageContent = removeTrackedDictationChunk(messageContentRef.current, lastChunk);
32062
+ const nextCaret = Math.min(lastChunk.start, nextMessageContent.length);
32010
32063
  setDictationChunks(previousChunks);
32011
- applyMessageContent(lastChunk.beforeValue);
32064
+ applyMessageContent(nextMessageContent);
32012
32065
  const previousFinalChunk = ((_a = previousChunks[previousChunks.length - 1]) === null || _a === void 0 ? void 0 : _a.finalText) || '';
32013
32066
  setDictationLastFinalChunk(previousFinalChunk);
32014
32067
  setDictationEditableChunk(previousFinalChunk);
32015
- focusTextareaSelection(lastChunk.start, lastChunk.start);
32068
+ updateDictationInsertionCaret(dictationInsertionSelectionRef, nextCaret);
32069
+ focusTextareaSelection(nextCaret, nextCaret);
32016
32070
  }, [
32017
32071
  applyMessageContent,
32072
+ dictationInsertionSelectionRef,
32018
32073
  dictationChunks,
32019
32074
  focusTextareaSelection,
32075
+ messageContentRef,
32020
32076
  setDictationChunks,
32021
32077
  setDictationEditableChunk,
32022
32078
  setDictationLastFinalChunk,
32023
32079
  ]);
32024
32080
  const handleApplyCorrection = useCallback(() => {
32081
+ var _a;
32025
32082
  const correctedChunk = resolveCorrectedDictationChunk(dictationEditableChunk, dictationLastFinalChunk);
32026
32083
  if (!correctedChunk) {
32027
32084
  return;
32028
32085
  }
32029
- const nextMessageContent = replaceLastOccurrence(messageContentRef.current, dictationLastFinalChunk, correctedChunk);
32086
+ const lastChunk = dictationChunks[dictationChunks.length - 1];
32087
+ const nextMessageContent = lastChunk
32088
+ ? replaceTrackedDictationChunk(messageContentRef.current, lastChunk, correctedChunk)
32089
+ : replaceLastOccurrence(messageContentRef.current, dictationLastFinalChunk, correctedChunk);
32090
+ const correctionStart = (_a = lastChunk === null || lastChunk === void 0 ? void 0 : lastChunk.start) !== null && _a !== void 0 ? _a : nextMessageContent.length;
32091
+ const correctionCaret = Math.min(correctionStart + correctedChunk.length, nextMessageContent.length);
32030
32092
  applyMessageContent(nextMessageContent);
32031
32093
  setDictationLastFinalChunk(correctedChunk);
32032
32094
  setDictationChunks((previousChunks) => replaceLastDictationChunk(previousChunks, correctedChunk));
32033
32095
  setDictationDictionary(learnDictationDictionary(dictationLastFinalChunk, correctedChunk, dictationDictionary));
32096
+ updateDictationInsertionCaret(dictationInsertionSelectionRef, correctionCaret);
32097
+ focusTextareaSelection(correctionCaret, correctionCaret);
32034
32098
  }, [
32035
32099
  applyMessageContent,
32036
32100
  dictationDictionary,
32037
32101
  dictationEditableChunk,
32102
+ dictationChunks,
32103
+ dictationInsertionSelectionRef,
32038
32104
  dictationLastFinalChunk,
32105
+ focusTextareaSelection,
32039
32106
  messageContentRef,
32040
32107
  setDictationChunks,
32041
32108
  setDictationDictionary,
@@ -32053,7 +32120,7 @@ function useChatInputAreaDictationCorrectionHandlers({ dictationChunks, dictatio
32053
32120
  */
32054
32121
  function useChatInputAreaDictation({ speechRecognition, speechRecognitionLanguage, textareaRef, messageContentRef, applyMessageContent, }) {
32055
32122
  const pendingStopFallbackRef = useRef(null);
32056
- const replaceSelectionOnNextFinalRef = useRef(false);
32123
+ const dictationInsertionSelectionRef = useRef(null);
32057
32124
  const [dictationUiState, setDictationUiState] = useState('idle');
32058
32125
  const [dictationInterimText, setDictationInterimText] = useState('');
32059
32126
  const [dictationError, setDictationError] = useState(null);
@@ -32086,7 +32153,7 @@ function useChatInputAreaDictation({ speechRecognition, speechRecognitionLanguag
32086
32153
  applyMessageContent,
32087
32154
  dictationSettings,
32088
32155
  dictationDictionary,
32089
- replaceSelectionOnNextFinalRef,
32156
+ dictationInsertionSelectionRef,
32090
32157
  focusTextareaSelection,
32091
32158
  state: dictationState,
32092
32159
  });
@@ -32106,7 +32173,7 @@ function useChatInputAreaDictation({ speechRecognition, speechRecognitionLanguag
32106
32173
  resolvedSpeechRecognitionLanguage,
32107
32174
  whisperMode: dictationSettings.whisperMode,
32108
32175
  pendingStopFallbackRef,
32109
- replaceSelectionOnNextFinalRef,
32176
+ dictationInsertionSelectionRef,
32110
32177
  clearPendingStopFallback,
32111
32178
  state: {
32112
32179
  dictationUiState,
@@ -32120,6 +32187,7 @@ function useChatInputAreaDictation({ speechRecognition, speechRecognitionLanguag
32120
32187
  dictationLastFinalChunk,
32121
32188
  dictationEditableChunk,
32122
32189
  dictationDictionary,
32190
+ dictationInsertionSelectionRef,
32123
32191
  messageContentRef,
32124
32192
  applyMessageContent,
32125
32193
  focusTextareaSelection,