@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.
@@ -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;
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.113.0-4`).
18
+ * It follows semantic versioning (e.g., `0.113.0-5`).
19
19
  *
20
20
  * @generated
21
21
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/components",
3
- "version": "0.113.0-5",
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-5';
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
@@ -6162,7 +6162,7 @@
6162
6162
  isAnimated: true,
6163
6163
  supportsPointerTracking: true,
6164
6164
  render({ context, size, palette, createRandom, timeMs, interaction }) {
6165
- const { morphologyProfile, animationPhase, leftEyePhaseOffset, rightEyePhaseOffset, tentacleProfiles, skinSpots } = getOctopus3d4StableState(createRandom);
6165
+ const { morphologyProfile, animationPhase, leftEyePhaseOffset, rightEyePhaseOffset, tentacleProfiles, skinSpots, } = getOctopus3d4StableState(createRandom);
6166
6166
  const sceneCenterX = size * 0.5;
6167
6167
  const sceneCenterY = size * 0.535;
6168
6168
  const bob = Math.sin(timeMs / 980 + animationPhase) * size * 0.013;
@@ -6510,10 +6510,7 @@
6510
6510
  Math.max(0, Math.cos(effectiveLongitude)) * 0.12 +
6511
6511
  lowerBlend * tentacleInfluence.core * (0.12 + tentacleInfluence.depthScale * 0.07) -
6512
6512
  Math.max(0, -Math.cos(effectiveLongitude)) * 0.05;
6513
- const tentacleTubeRadius = lowerBlend *
6514
- tentacleInfluence.core *
6515
- (0.12 + tipBlend * 0.07 + tentacleInfluence.widthScale * 0.028) *
6516
- radiusX;
6513
+ const tentacleTubeRadius = lowerBlend * tentacleInfluence.core * (0.12 + tipBlend * 0.07 + tentacleInfluence.widthScale * 0.028) * radiusX;
6517
6514
  const planarRadiusX = cosineLatitude * radiusX * horizontalScale + tentacleTubeRadius;
6518
6515
  const planarRadiusZ = cosineLatitude * radiusZ * depthScale + tentacleTubeRadius * 0.74;
6519
6516
  const lowerDrop = lowerBlend *
@@ -6525,9 +6522,7 @@
6525
6522
  (morphologyProfile.tentacles.flowLengthScale - 1) * 0.1));
6526
6523
  const combinedTentacleSway = (primaryTentacleWave + secondaryTentacleWave) * radiusX * (0.06 + tipBlend * 0.06);
6527
6524
  return {
6528
- x: Math.sin(effectiveLongitude) * planarRadiusX +
6529
- combinedTentacleSway +
6530
- tentacleCurl * radiusX * 0.18,
6525
+ x: Math.sin(effectiveLongitude) * planarRadiusX + combinedTentacleSway + tentacleCurl * radiusX * 0.18,
6531
6526
  y: Math.sin(latitude) * radiusY * (1 + upperBlend * 0.14) -
6532
6527
  upperBlend * radiusY * 0.12 +
6533
6528
  lowerDrop +
@@ -14164,10 +14159,10 @@
14164
14159
  *
14165
14160
  * @private
14166
14161
  */
14167
- const TEAM_SYSTEM_MESSAGE_GUIDANCE_LINES = [
14168
- '- If a teammate is relevant to the request, consult that teammate using the matching tool.',
14169
- '- Do not ask the user for information that a listed teammate can provide directly.',
14170
- ];
14162
+ const TEAM_SYSTEM_MESSAGE_GUIDANCE = spacetrim.spaceTrim(`
14163
+ - If a teammate is relevant to the request, consult that teammate using the matching tool.
14164
+ - Do not ask the user for information that a listed teammate can provide directly.
14165
+ `);
14171
14166
  /**
14172
14167
  * Constant for remote agents by Url.
14173
14168
  */
@@ -14349,7 +14344,7 @@
14349
14344
  `);
14350
14345
  });
14351
14346
  return spacetrim.spaceTrim((block) => `
14352
- ${block(TEAM_SYSTEM_MESSAGE_GUIDANCE_LINES.join('\n'))}
14347
+ ${block(TEAM_SYSTEM_MESSAGE_GUIDANCE)}
14353
14348
 
14354
14349
  ${block(teammateSections.join('\n\n'))}
14355
14350
  `);
@@ -31163,9 +31158,9 @@
31163
31158
  * @private function of `useChatInputAreaDictation`
31164
31159
  */
31165
31160
  function insertDictationChunk(params) {
31166
- const { currentValue, dictatedText, selectionStart, selectionEnd, shouldReplaceSelection } = params;
31161
+ const { currentValue, dictatedText, selectionStart, selectionEnd, isReplacingSelection } = params;
31167
31162
  const replaceStart = selectionStart;
31168
- const replaceEnd = shouldReplaceSelection ? selectionEnd : selectionStart;
31163
+ const replaceEnd = isReplacingSelection ? selectionEnd : selectionStart;
31169
31164
  const prefix = currentValue.slice(0, replaceStart);
31170
31165
  const suffix = currentValue.slice(replaceEnd);
31171
31166
  const previousCharacter = prefix.slice(-1);
@@ -31207,7 +31202,7 @@
31207
31202
  if (!previousWord || !correctedWord) {
31208
31203
  continue;
31209
31204
  }
31210
- if (previousWord.toLowerCase() !== correctedWord.toLowerCase()) {
31205
+ if (previousWord !== correctedWord) {
31211
31206
  nextDictionary[previousWord.toLowerCase()] = correctedWord;
31212
31207
  }
31213
31208
  }
@@ -31701,17 +31696,73 @@
31701
31696
  pendingStopFallbackRef.current = null;
31702
31697
  }
31703
31698
  /**
31704
- * Captures whether the next finalized chunk should replace the current selection.
31699
+ * Captures where the next finalized chunk should be inserted.
31705
31700
  *
31706
31701
  * @private function of `useChatInputAreaDictation`
31707
31702
  */
31708
- function captureSelectionReplacementIntent(textareaRef, replaceSelectionOnNextFinalRef) {
31703
+ function captureDictationInsertionSelection(textareaRef, dictationInsertionSelectionRef) {
31709
31704
  const textarea = textareaRef.current;
31710
31705
  if (!textarea) {
31711
31706
  return;
31712
31707
  }
31713
- const { selectionStart, selectionEnd } = resolveTextareaSelection(textarea, 0);
31714
- 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
+ };
31715
31766
  }
31716
31767
  /**
31717
31768
  * Produces the corrected chunk value only when a real correction should be applied.
@@ -31792,7 +31843,7 @@
31792
31843
  *
31793
31844
  * @private function of `useChatInputAreaDictation`
31794
31845
  */
31795
- function useChatInputAreaDictationFinalResultHandler({ textareaRef, messageContentRef, applyMessageContent, dictationSettings, dictationDictionary, replaceSelectionOnNextFinalRef, focusTextareaSelection, state, }) {
31846
+ function useChatInputAreaDictationFinalResultHandler({ textareaRef, messageContentRef, applyMessageContent, dictationSettings, dictationDictionary, dictationInsertionSelectionRef, focusTextareaSelection, state, }) {
31796
31847
  const { setDictationUiState, setDictationInterimText, setDictationError, setDictationLastFinalChunk, setDictationEditableChunk, setDictationChunks, setIsDictationPanelExpanded, } = state;
31797
31848
  return react.useCallback((rawText) => {
31798
31849
  const textarea = textareaRef.current;
@@ -31804,15 +31855,15 @@
31804
31855
  if (!refinedText) {
31805
31856
  return;
31806
31857
  }
31807
- const { selectionStart, selectionEnd } = resolveTextareaSelection(textarea, previousMessageContent.length);
31858
+ const { selectionStart, selectionEnd, isReplacingSelection } = resolveDictationInsertionSelection(textarea, previousMessageContent.length, dictationInsertionSelectionRef.current);
31808
31859
  const insertion = insertDictationChunk({
31809
31860
  currentValue: previousMessageContent,
31810
31861
  dictatedText: refinedText,
31811
31862
  selectionStart,
31812
31863
  selectionEnd,
31813
- shouldReplaceSelection: replaceSelectionOnNextFinalRef.current,
31864
+ isReplacingSelection,
31814
31865
  });
31815
- replaceSelectionOnNextFinalRef.current = false;
31866
+ updateDictationInsertionCaret(dictationInsertionSelectionRef, insertion.caret);
31816
31867
  setDictationInterimText('');
31817
31868
  setDictationError(null);
31818
31869
  setDictationUiState('listening');
@@ -31832,10 +31883,10 @@
31832
31883
  }, [
31833
31884
  applyMessageContent,
31834
31885
  dictationDictionary,
31886
+ dictationInsertionSelectionRef,
31835
31887
  dictationSettings,
31836
31888
  focusTextareaSelection,
31837
31889
  messageContentRef,
31838
- replaceSelectionOnNextFinalRef,
31839
31890
  setDictationChunks,
31840
31891
  setDictationEditableChunk,
31841
31892
  setDictationError,
@@ -31883,7 +31934,7 @@
31883
31934
  return;
31884
31935
  case 'STOP':
31885
31936
  clearPendingStopFallback();
31886
- setDictationUiState((currentState) => (currentState === 'disabled' ? currentState : 'idle'));
31937
+ setDictationUiState((currentState) => currentState === 'disabled' || currentState === 'error' ? currentState : 'idle');
31887
31938
  setDictationInterimText('');
31888
31939
  return;
31889
31940
  }
@@ -31924,13 +31975,13 @@
31924
31975
  *
31925
31976
  * @private function of `useChatInputAreaDictation`
31926
31977
  */
31927
- function useChatInputAreaDictationVoiceInputControls({ speechRecognition, textareaRef, resolvedSpeechRecognitionLanguage, whisperMode, pendingStopFallbackRef, replaceSelectionOnNextFinalRef, clearPendingStopFallback, state, }) {
31978
+ function useChatInputAreaDictationVoiceInputControls({ speechRecognition, textareaRef, resolvedSpeechRecognitionLanguage, whisperMode, pendingStopFallbackRef, dictationInsertionSelectionRef, clearPendingStopFallback, state, }) {
31928
31979
  const { dictationUiState, setDictationUiState, setDictationInterimText, setDictationError } = state;
31929
31980
  const startVoiceInput = react.useCallback(() => {
31930
31981
  if (!speechRecognition) {
31931
31982
  return;
31932
31983
  }
31933
- captureSelectionReplacementIntent(textareaRef, replaceSelectionOnNextFinalRef);
31984
+ captureDictationInsertionSelection(textareaRef, dictationInsertionSelectionRef);
31934
31985
  setDictationError(null);
31935
31986
  setDictationInterimText('');
31936
31987
  setDictationUiState('listening');
@@ -31940,7 +31991,7 @@
31940
31991
  whisperMode,
31941
31992
  });
31942
31993
  }, [
31943
- replaceSelectionOnNextFinalRef,
31994
+ dictationInsertionSelectionRef,
31944
31995
  resolvedSpeechRecognitionLanguage,
31945
31996
  setDictationError,
31946
31997
  setDictationInterimText,
@@ -31992,7 +32043,7 @@
31992
32043
  *
31993
32044
  * @private function of `useChatInputAreaDictation`
31994
32045
  */
31995
- 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, }) {
31996
32047
  const handleBacktrackLastChunk = react.useCallback(() => {
31997
32048
  var _a;
31998
32049
  const previousChunks = [...dictationChunks];
@@ -32000,35 +32051,51 @@
32000
32051
  if (!lastChunk) {
32001
32052
  return;
32002
32053
  }
32054
+ const nextMessageContent = removeTrackedDictationChunk(messageContentRef.current, lastChunk);
32055
+ const nextCaret = Math.min(lastChunk.start, nextMessageContent.length);
32003
32056
  setDictationChunks(previousChunks);
32004
- applyMessageContent(lastChunk.beforeValue);
32057
+ applyMessageContent(nextMessageContent);
32005
32058
  const previousFinalChunk = ((_a = previousChunks[previousChunks.length - 1]) === null || _a === void 0 ? void 0 : _a.finalText) || '';
32006
32059
  setDictationLastFinalChunk(previousFinalChunk);
32007
32060
  setDictationEditableChunk(previousFinalChunk);
32008
- focusTextareaSelection(lastChunk.start, lastChunk.start);
32061
+ updateDictationInsertionCaret(dictationInsertionSelectionRef, nextCaret);
32062
+ focusTextareaSelection(nextCaret, nextCaret);
32009
32063
  }, [
32010
32064
  applyMessageContent,
32065
+ dictationInsertionSelectionRef,
32011
32066
  dictationChunks,
32012
32067
  focusTextareaSelection,
32068
+ messageContentRef,
32013
32069
  setDictationChunks,
32014
32070
  setDictationEditableChunk,
32015
32071
  setDictationLastFinalChunk,
32016
32072
  ]);
32017
32073
  const handleApplyCorrection = react.useCallback(() => {
32074
+ var _a;
32018
32075
  const correctedChunk = resolveCorrectedDictationChunk(dictationEditableChunk, dictationLastFinalChunk);
32019
32076
  if (!correctedChunk) {
32020
32077
  return;
32021
32078
  }
32022
- 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);
32023
32085
  applyMessageContent(nextMessageContent);
32024
32086
  setDictationLastFinalChunk(correctedChunk);
32025
32087
  setDictationChunks((previousChunks) => replaceLastDictationChunk(previousChunks, correctedChunk));
32026
32088
  setDictationDictionary(learnDictationDictionary(dictationLastFinalChunk, correctedChunk, dictationDictionary));
32089
+ updateDictationInsertionCaret(dictationInsertionSelectionRef, correctionCaret);
32090
+ focusTextareaSelection(correctionCaret, correctionCaret);
32027
32091
  }, [
32028
32092
  applyMessageContent,
32029
32093
  dictationDictionary,
32030
32094
  dictationEditableChunk,
32095
+ dictationChunks,
32096
+ dictationInsertionSelectionRef,
32031
32097
  dictationLastFinalChunk,
32098
+ focusTextareaSelection,
32032
32099
  messageContentRef,
32033
32100
  setDictationChunks,
32034
32101
  setDictationDictionary,
@@ -32046,7 +32113,7 @@
32046
32113
  */
32047
32114
  function useChatInputAreaDictation({ speechRecognition, speechRecognitionLanguage, textareaRef, messageContentRef, applyMessageContent, }) {
32048
32115
  const pendingStopFallbackRef = react.useRef(null);
32049
- const replaceSelectionOnNextFinalRef = react.useRef(false);
32116
+ const dictationInsertionSelectionRef = react.useRef(null);
32050
32117
  const [dictationUiState, setDictationUiState] = react.useState('idle');
32051
32118
  const [dictationInterimText, setDictationInterimText] = react.useState('');
32052
32119
  const [dictationError, setDictationError] = react.useState(null);
@@ -32079,7 +32146,7 @@
32079
32146
  applyMessageContent,
32080
32147
  dictationSettings,
32081
32148
  dictationDictionary,
32082
- replaceSelectionOnNextFinalRef,
32149
+ dictationInsertionSelectionRef,
32083
32150
  focusTextareaSelection,
32084
32151
  state: dictationState,
32085
32152
  });
@@ -32099,7 +32166,7 @@
32099
32166
  resolvedSpeechRecognitionLanguage,
32100
32167
  whisperMode: dictationSettings.whisperMode,
32101
32168
  pendingStopFallbackRef,
32102
- replaceSelectionOnNextFinalRef,
32169
+ dictationInsertionSelectionRef,
32103
32170
  clearPendingStopFallback,
32104
32171
  state: {
32105
32172
  dictationUiState,
@@ -32113,6 +32180,7 @@
32113
32180
  dictationLastFinalChunk,
32114
32181
  dictationEditableChunk,
32115
32182
  dictationDictionary,
32183
+ dictationInsertionSelectionRef,
32116
32184
  messageContentRef,
32117
32185
  applyMessageContent,
32118
32186
  focusTextareaSelection,