tycho-components 0.46.5 → 0.47.1
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/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './common';
|
|
|
2
2
|
export * from './shell';
|
|
3
3
|
export { default as HelpButton } from './shell/Header/HelpButton';
|
|
4
4
|
export type { HelpAction } from './shell/Header/HelpButton/HelpButton';
|
|
5
|
+
export { loadHelpAssistant, openHelpAssistant, isHelpAssistantEnabled, } from './shell/Header/HelpButton/helpAssistant';
|
|
5
6
|
export * from './configs';
|
|
6
7
|
export * from './functions';
|
|
7
8
|
export * from './features';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './common';
|
|
2
2
|
export * from './shell';
|
|
3
3
|
export { default as HelpButton } from './shell/Header/HelpButton';
|
|
4
|
+
export { loadHelpAssistant, openHelpAssistant, isHelpAssistantEnabled, } from './shell/Header/HelpButton/helpAssistant';
|
|
4
5
|
export * from './configs';
|
|
5
6
|
export * from './functions';
|
|
6
7
|
export * from './features';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CorpusHub help assistant — offline RAG chat (tycho-brahe/corpushub-rag).
|
|
3
|
+
*
|
|
4
|
+
* The widget is a single implementation served by the RAG API itself (`GET <api>widget.js`), so the
|
|
5
|
+
* fronts never carry a copy: changing the assistant is a RAG deploy, not a front rebuild.
|
|
6
|
+
* Call `loadHelpAssistant(import.meta.env.VITE_APP_HELP_ASSISTANT_API)` once at app start (main.tsx).
|
|
7
|
+
* With no API URL (e.g. production today) nothing is loaded and the Header help button stays hidden.
|
|
8
|
+
*/
|
|
9
|
+
type AgentApi = {
|
|
10
|
+
open: () => void;
|
|
11
|
+
close?: () => void;
|
|
12
|
+
toggle?: () => void;
|
|
13
|
+
isOpen?: () => boolean;
|
|
14
|
+
_pendingOpen?: boolean;
|
|
15
|
+
};
|
|
16
|
+
declare global {
|
|
17
|
+
interface Window {
|
|
18
|
+
CorpusHubAgent?: AgentApi;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
type Options = {
|
|
22
|
+
/** 'floating' (default) shows the widget's own corner button; 'none' leaves opening to the app. */
|
|
23
|
+
launcher?: 'floating' | 'none';
|
|
24
|
+
};
|
|
25
|
+
export declare function loadHelpAssistant(api?: string, options?: Options): void;
|
|
26
|
+
export declare function isHelpAssistantEnabled(): boolean;
|
|
27
|
+
export declare function openHelpAssistant(): void;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const SELECTOR = 'script[data-corpushub-agent]';
|
|
2
|
+
export function loadHelpAssistant(api, options = {}) {
|
|
3
|
+
if (!api || typeof document === 'undefined' || document.querySelector(SELECTOR))
|
|
4
|
+
return;
|
|
5
|
+
const base = api.endsWith('/') ? api : `${api}/`;
|
|
6
|
+
// Stub until the script arrives: an early open() is remembered and honoured by the widget.
|
|
7
|
+
if (!window.CorpusHubAgent) {
|
|
8
|
+
window.CorpusHubAgent = {
|
|
9
|
+
_pendingOpen: false,
|
|
10
|
+
open() {
|
|
11
|
+
this._pendingOpen = true;
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const script = document.createElement('script');
|
|
16
|
+
script.src = `${base}widget.js`;
|
|
17
|
+
script.dataset.api = base;
|
|
18
|
+
script.dataset.corpushubAgent = '';
|
|
19
|
+
if (options.launcher)
|
|
20
|
+
script.dataset.launcher = options.launcher;
|
|
21
|
+
script.defer = true;
|
|
22
|
+
document.head.appendChild(script);
|
|
23
|
+
}
|
|
24
|
+
export function isHelpAssistantEnabled() {
|
|
25
|
+
return typeof document !== 'undefined' && !!document.querySelector(SELECTOR);
|
|
26
|
+
}
|
|
27
|
+
export function openHelpAssistant() {
|
|
28
|
+
window.CorpusHubAgent?.open();
|
|
29
|
+
}
|