@longline/aqua-ui 1.0.313 → 1.0.315

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.
@@ -20,7 +20,7 @@ type TRecordingStatus = 'idle' | 'connecting' | 'recording';
20
20
  * AssemblyAIRecorder is currently recording; when a new recording is started,
21
21
  * the current one is stopped.
22
22
  */
23
- declare const useAssemblyAIRecorder: (url: string, onTranscript: TranscriptCallback) => {
23
+ declare const useAssemblyAIRecorder: (url: string, onTranscript: TranscriptCallback, authToken?: string) => {
24
24
  recordingStatus: TRecordingStatus;
25
25
  toggleRecording: () => Promise<void>;
26
26
  };
@@ -65,7 +65,7 @@ var moduleScript = /* js */ "\nconst MAX_16BIT_INT = 32767\nclass AudioProcessor
65
65
  * AssemblyAIRecorder is currently recording; when a new recording is started,
66
66
  * the current one is stopped.
67
67
  */
68
- var useAssemblyAIRecorder = function (url, onTranscript) {
68
+ var useAssemblyAIRecorder = function (url, onTranscript, authToken) {
69
69
  // State to track the current recording status
70
70
  var _a = useState('idle'), recordingStatus = _a[0], setRecordingStatus = _a[1];
71
71
  // WebSocket connection to AssemblyAI
@@ -169,12 +169,15 @@ var useAssemblyAIRecorder = function (url, onTranscript) {
169
169
  * Fetches a temporary token for the AssemblyAI WebSocket API
170
170
  */
171
171
  var fetchToken = function () { return __awaiter(void 0, void 0, void 0, function () {
172
- var response, data, err_1;
172
+ var headers, response, data, err_1;
173
173
  return __generator(this, function (_a) {
174
174
  switch (_a.label) {
175
175
  case 0:
176
176
  _a.trys.push([0, 3, , 4]);
177
- return [4 /*yield*/, fetch(url)];
177
+ headers = {};
178
+ if (authToken)
179
+ headers['Authorization'] = "Bearer ".concat(authToken);
180
+ return [4 /*yield*/, fetch(url, { headers: headers })];
178
181
  case 1:
179
182
  response = _a.sent();
180
183
  return [4 /*yield*/, response.json()];
@@ -7,7 +7,7 @@ interface IOpenAIStreamOptions {
7
7
  *
8
8
  * @returns `stream`: a function that takes a prompt and streaming callback.
9
9
  */
10
- declare const useOpenAIStream: (url: string) => {
10
+ declare const useOpenAIStream: (url: string, authToken?: string) => {
11
11
  stream: (prompt: string, onText: (text: string) => Promise<void>, options?: IOpenAIStreamOptions) => Promise<void>;
12
12
  cancel: () => void;
13
13
  };
@@ -49,7 +49,7 @@ import { useCallback, useRef } from 'react';
49
49
  *
50
50
  * @returns `stream`: a function that takes a prompt and streaming callback.
51
51
  */
52
- var useOpenAIStream = function (url) {
52
+ var useOpenAIStream = function (url, authToken) {
53
53
  var abortRef = useRef(null);
54
54
  /**
55
55
  * Streams a prompt to a backend AI endpoint and handles streamed chunks.
@@ -63,7 +63,7 @@ var useOpenAIStream = function (url) {
63
63
  args_1[_i - 2] = arguments[_i];
64
64
  }
65
65
  return __awaiter(void 0, __spreadArray([prompt_1, onText_1], args_1, true), void 0, function (prompt, onText, options) {
66
- var controller, response, reader, decoder, buffer, isDone, _a, done, value, parts, _b, parts_1, part, jsonStr, data, content, err_1;
66
+ var controller, headers, response, reader, decoder, buffer, isDone, _a, done, value, parts, _b, parts_1, part, jsonStr, data, content, err_1;
67
67
  var _c, _d, _e;
68
68
  if (options === void 0) { options = { temperature: 0, top_p: 0 }; }
69
69
  return __generator(this, function (_f) {
@@ -71,14 +71,17 @@ var useOpenAIStream = function (url) {
71
71
  case 0:
72
72
  controller = new AbortController();
73
73
  abortRef.current = controller;
74
+ headers = {
75
+ 'Content-Type': 'application/json',
76
+ 'Accept': 'text/event-stream',
77
+ 'Connection': 'keep-alive',
78
+ 'Cache-Control': 'no-cache, no-transform'
79
+ };
80
+ if (authToken)
81
+ headers['Authorization'] = "Bearer ".concat(authToken);
74
82
  return [4 /*yield*/, fetch(url, {
75
83
  method: 'POST',
76
- headers: {
77
- 'Content-Type': 'application/json',
78
- 'Accept': 'text/event-stream',
79
- 'Connection': 'keep-alive',
80
- 'Cache-Control': 'no-cache, no-transform'
81
- },
84
+ headers: headers,
82
85
  body: JSON.stringify({
83
86
  input: prompt,
84
87
  temperature: options.temperature || 0,
@@ -145,7 +148,7 @@ var useOpenAIStream = function (url) {
145
148
  }
146
149
  });
147
150
  });
148
- }, [url]);
151
+ }, [url, authToken]);
149
152
  /**
150
153
  * Cancels any ongoing stream.
151
154
  */
@@ -58,6 +58,10 @@ interface IEditorProps {
58
58
  * If not present, no AssemblyAI controls will be available.
59
59
  */
60
60
  assemblyAIurl?: string;
61
+ /**
62
+ * Optional Bearer token for authenticated AI requests.
63
+ */
64
+ authToken?: string;
61
65
  /**
62
66
  * Listeners are notified whenever the user interacts with the Editor.
63
67
  */
@@ -86,7 +86,7 @@ var EditorBase = function (props) {
86
86
  React.createElement("div", { className: props.className, ref: wrapperRef },
87
87
  React.createElement(OverlayScrollbarsComponent, { className: "scroller ".concat(fullscreen ? 'fullscreen' : ''), defer: true, options: { scrollbars: { theme: 'os-theme-dark', autoHide: 'leave' } } },
88
88
  !props.disabled && !props.ghost &&
89
- React.createElement(MenuBar, { allowFullscreen: props.allowFullscreen, codeButtons: props.codeButtons, fullscreen: fullscreen, editor: editor, onToggleFullscreen: handleToggleFullscreen, openAIurl: props.openAIurl, assemblyAIurl: props.assemblyAIurl }),
89
+ React.createElement(MenuBar, { allowFullscreen: props.allowFullscreen, codeButtons: props.codeButtons, fullscreen: fullscreen, editor: editor, onToggleFullscreen: handleToggleFullscreen, openAIurl: props.openAIurl, assemblyAIurl: props.assemblyAIurl, authToken: props.authToken }),
90
90
  React.createElement(EditorContent, { editor: editor, ref: setRef })))));
91
91
  };
92
92
  var pulse = keyframes(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n from {\n opacity: .15;\n }\n to {\n opacity: 1;\n }\n"], ["\n from {\n opacity: .15;\n }\n to {\n opacity: 1;\n }\n"])));
@@ -6,6 +6,10 @@ interface IProps {
6
6
  * URL for AI requests.
7
7
  */
8
8
  url: string;
9
+ /**
10
+ * Optional Bearer token for authenticated requests.
11
+ */
12
+ authToken?: string;
9
13
  }
10
14
  /**
11
15
  * `AIButton` provides a menu button that allows the user to run various
@@ -54,7 +54,7 @@ import { OpenAIMenu } from './OpenAIMenu';
54
54
  * with animated progress.
55
55
  */
56
56
  var OpenAIButton = function (props) {
57
- var streamOpenAI = useOpenAIStream(props.url).stream;
57
+ var streamOpenAI = useOpenAIStream(props.url, props.authToken).stream;
58
58
  var _a = useState(false), streaming = _a[0], setStreaming = _a[1];
59
59
  // The DOM parser is only created once, then used many times as content
60
60
  // is streamed in.
@@ -3,6 +3,10 @@ import { Editor } from '@tiptap/react';
3
3
  interface IProps {
4
4
  editor: Editor;
5
5
  url: string;
6
+ /**
7
+ * Optional Bearer token for authenticated requests.
8
+ */
9
+ authToken?: string;
6
10
  }
7
11
  declare const SpeechButton: (props: IProps) => React.JSX.Element;
8
12
  export { SpeechButton };
@@ -12,7 +12,7 @@ var SpeechButton = function (props) {
12
12
  view.dispatch(transaction);
13
13
  transcriptRef.current = text;
14
14
  };
15
- var _a = useAssemblyAIRecorder(props.url, onTranscript), recordingStatus = _a.recordingStatus, toggleRecording = _a.toggleRecording;
15
+ var _a = useAssemblyAIRecorder(props.url, onTranscript, props.authToken), recordingStatus = _a.recordingStatus, toggleRecording = _a.toggleRecording;
16
16
  useEffect(function () {
17
17
  if (recordingStatus == 'recording') {
18
18
  props.editor.setOptions({ editable: false });
@@ -25,6 +25,10 @@ interface IProps {
25
25
  * If not present, no AI controls will be available.
26
26
  */
27
27
  assemblyAIurl?: string;
28
+ /**
29
+ * Optional Bearer token for authenticated AI requests.
30
+ */
31
+ authToken?: string;
28
32
  /** Fired when fullscreen mode must be toggled. */
29
33
  onToggleFullscreen: () => void;
30
34
  }
@@ -33,9 +33,9 @@ var MenuBarBase = function (props) {
33
33
  React.createElement(CodeBlockButton, { editor: props.editor })),
34
34
  (props.openAIurl || props.allowFullscreen) && React.createElement(MenuSeparator, null),
35
35
  props.openAIurl &&
36
- React.createElement(OpenAIButton, { url: props.openAIurl, editor: props.editor }),
36
+ React.createElement(OpenAIButton, { url: props.openAIurl, editor: props.editor, authToken: props.authToken }),
37
37
  props.assemblyAIurl &&
38
- React.createElement(SpeechButton, { url: props.assemblyAIurl, editor: props.editor }),
38
+ React.createElement(SpeechButton, { url: props.assemblyAIurl, editor: props.editor, authToken: props.authToken }),
39
39
  props.allowFullscreen &&
40
40
  React.createElement(FullscreenButton, { fullscreen: props.fullscreen, editor: props.editor, onClick: props.onToggleFullscreen }))));
41
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longline/aqua-ui",
3
- "version": "1.0.313",
3
+ "version": "1.0.315",
4
4
  "description": "AquaUI",
5
5
  "author": "Alexander van Oostenrijk / Longline Environment",
6
6
  "license": "Commercial",