@websolutespa/bom-llm 0.0.9 → 0.0.10

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/CHANGELOG.md CHANGED
@@ -1,58 +1,65 @@
1
- # @websolutespa/bom-llm
2
-
3
- ## 0.0.9
4
-
5
- ### Patch Changes
6
-
7
- - Updating: dependencies
8
-
9
- ## 0.0.8
10
-
11
- ### Patch Changes
12
-
13
- - Modified: Speech synthesis & recognition, disclaimer, markdown
14
-
15
- ## 0.0.7
16
-
17
- ### Patch Changes
18
-
19
- - Modified: components dangerouslySetInnerHTML, styles, useLlm status opened with threadId
20
-
21
- ## 0.0.6
22
-
23
- ### Patch Changes
24
-
25
- - Fixing: threads
26
- - Modified: MessageService, FormRecap, useLlm
27
-
28
- ## 0.0.5
29
-
30
- ### Patch Changes
31
-
32
- - Added: declarations
33
- - Modified: FormRecap, QuickLinks
34
-
35
- ## 0.0.4
36
-
37
- ### Patch Changes
38
-
39
- - Modified: decorateUrl async behaviour
40
-
41
- ## 0.0.3
42
-
43
- ### Patch Changes
44
-
45
- - Added: markdown support
46
-
47
- ## 0.0.2
48
-
49
- ### Patch Changes
50
-
51
- - Added: abort stream
52
- - Modified: speech, useLlm, message service, canvas, icons
53
-
54
- ## 0.0.1
55
-
56
- ### Patch Changes
57
-
58
- - Added: first release.
1
+ # @websolutespa/bom-llm
2
+
3
+ ## 0.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Added: embed options
8
+ - Added: returning instance with methods
9
+
10
+ ## 0.0.9
11
+
12
+ ### Patch Changes
13
+
14
+ - Updating: dependencies
15
+
16
+ ## 0.0.8
17
+
18
+ ### Patch Changes
19
+
20
+ - Modified: Speech synthesis & recognition, disclaimer, markdown
21
+
22
+ ## 0.0.7
23
+
24
+ ### Patch Changes
25
+
26
+ - Modified: components dangerouslySetInnerHTML, styles, useLlm status opened with threadId
27
+
28
+ ## 0.0.6
29
+
30
+ ### Patch Changes
31
+
32
+ - Fixing: threads
33
+ - Modified: MessageService, FormRecap, useLlm
34
+
35
+ ## 0.0.5
36
+
37
+ ### Patch Changes
38
+
39
+ - Added: declarations
40
+ - Modified: FormRecap, QuickLinks
41
+
42
+ ## 0.0.4
43
+
44
+ ### Patch Changes
45
+
46
+ - Modified: decorateUrl async behaviour
47
+
48
+ ## 0.0.3
49
+
50
+ ### Patch Changes
51
+
52
+ - Added: markdown support
53
+
54
+ ## 0.0.2
55
+
56
+ ### Patch Changes
57
+
58
+ - Added: abort stream
59
+ - Modified: speech, useLlm, message service, canvas, icons
60
+
61
+ ## 0.0.1
62
+
63
+ ### Patch Changes
64
+
65
+ - Added: first release.
package/README.md CHANGED
@@ -65,11 +65,28 @@ document.addEventListener('DOMContentLoaded', () => {
65
65
  apiKey: 'MY_API_KEY',
66
66
  threadId: searchParams.get('llmThreadId'),
67
67
  };
68
- bomLlm(options);
68
+ // returned instance
69
+ const llm = bomLlm(options);
69
70
  }
70
71
  });
71
72
  ```
72
73
 
74
+ Using imperatively.
75
+
76
+ ```js
77
+ const llm = bomLlm(options);
78
+ // using open command imperatively
79
+ setTimeout(() => {
80
+ llm.open();
81
+ }, 4000);
82
+ ```
83
+
84
+ Using embed tag.
85
+
86
+ ```html
87
+ <llm-embed />
88
+ ```
89
+
73
90
  ### Running test
74
91
 
75
92
  Add parameter test = true.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { LlmInstance } from '@websolutespa/bom-mixer-llm';
2
+
1
3
  type LlmItem = Record<string, any> & {
2
4
  type: string;
3
5
  };
@@ -11,8 +13,9 @@ type LlmOptions = {
11
13
  test?: boolean;
12
14
  threadId?: string;
13
15
  opened?: boolean;
16
+ embedded?: boolean;
14
17
  };
15
18
 
16
- declare function bomLlm(props: LlmOptions): void;
19
+ declare function bomLlm(props: LlmOptions): LlmInstance | undefined;
17
20
 
18
21
  export { bomLlm };
@@ -286,16 +286,46 @@
286
286
  box-sizing: border-box;
287
287
  }
288
288
 
289
+ llm-embed {
290
+ display: block;
291
+ width: 100%;
292
+ max-height: 100vh;
293
+ background: transparent;
294
+ overflow: clip;
295
+ }
296
+ @media (max-width: 799px) {
297
+ llm-embed {
298
+ height: 100vh;
299
+ }
300
+ }
301
+ @media (min-width: 800px) {
302
+ llm-embed {
303
+ aspect-ratio: 1/1;
304
+ }
305
+ }
306
+ @media (min-width: 1080px) {
307
+ llm-embed {
308
+ aspect-ratio: 4/3;
309
+ }
310
+ }
311
+ @media (min-width: 1440px) {
312
+ llm-embed {
313
+ aspect-ratio: 16/9;
314
+ }
315
+ }
316
+
289
317
  .llm {
290
- position: fixed;
291
318
  display: flex;
292
319
  flex-direction: column;
293
320
  align-items: center;
294
321
  justify-content: flex-end;
295
- top: 0;
296
- left: 0;
297
322
  width: 100%;
298
323
  height: 100%;
324
+ }
325
+ .llm:not(.-embedded) {
326
+ position: fixed;
327
+ top: 0;
328
+ left: 0;
299
329
  pointer-events: none;
300
330
  z-index: 9999;
301
331
  }
@@ -1072,7 +1102,8 @@
1072
1102
  }
1073
1103
 
1074
1104
  .llm .llm__main {
1075
- position: absolute;
1105
+ display: block;
1106
+ position: relative;
1076
1107
  pointer-events: auto;
1077
1108
  inset: 0;
1078
1109
  background: var(--llm-color-ui-1);
@@ -1112,14 +1143,26 @@
1112
1143
  }
1113
1144
  .llm .llm__content {
1114
1145
  min-height: 100%;
1115
- padding-top: 100px;
1116
- padding-bottom: 180px;
1117
1146
  display: flex;
1118
1147
  flex-direction: column;
1119
1148
  justify-content: center;
1120
1149
  }
1150
+ .llm.-embedded .llm__main {
1151
+ width: 100%;
1152
+ height: 100%;
1153
+ }
1154
+ .llm.-embedded .llm__content {
1155
+ padding: 80px 0 0 0;
1156
+ }
1157
+ .llm:not(.-embedded) .llm__main {
1158
+ position: absolute;
1159
+ }
1160
+ .llm:not(.-embedded) .llm__content {
1161
+ padding-top: 100px;
1162
+ padding-bottom: 180px;
1163
+ }
1121
1164
  @media (min-width: 1024px) {
1122
- .llm .llm__content {
1165
+ .llm:not(.-embedded) .llm__content {
1123
1166
  padding: 200px 0;
1124
1167
  padding-bottom: 280px;
1125
1168
  }
package/dist/umd/index.js CHANGED
@@ -23803,6 +23803,7 @@
23803
23803
  apiKey,
23804
23804
  threadId,
23805
23805
  opened,
23806
+ embedded,
23806
23807
  decorateUrl,
23807
23808
  endpoint,
23808
23809
  test,
@@ -23815,7 +23816,8 @@
23815
23816
  prompt: '',
23816
23817
  locale: 'en',
23817
23818
  streaming: false,
23818
- opened: opened != null ? opened : threadId != null ? true : false,
23819
+ opened: opened != null || embedded != null ? Boolean(opened || embedded) : threadId != null ? true : false,
23820
+ embedded: embedded || false,
23819
23821
  hidden: false,
23820
23822
  fixed: false,
23821
23823
  idle: true,
@@ -28797,6 +28799,7 @@ void main(void) {
28797
28799
 
28798
28800
  const Main = () => {
28799
28801
  const lenisRef = reactExports.useRef(null);
28802
+ const embedded = useLlm(state => state.embedded);
28800
28803
  const messages = useLlm(state => state.messages);
28801
28804
  const {
28802
28805
  setLenis
@@ -28867,7 +28870,7 @@ void main(void) {
28867
28870
  initial: "hidden",
28868
28871
  animate: "show",
28869
28872
  exit: "exit",
28870
- children: /*#__PURE__*/jsxRuntimeExports.jsx(Header, {})
28873
+ children: !embedded && /*#__PURE__*/jsxRuntimeExports.jsx(Header, {})
28871
28874
  }), /*#__PURE__*/jsxRuntimeExports.jsx(v, {
28872
28875
  ref: lenisRef,
28873
28876
  className: "llm__scroller",
@@ -28941,16 +28944,23 @@ void main(void) {
28941
28944
  });
28942
28945
  };
28943
28946
 
28944
- const LlmComponent = props => {
28947
+ const LlmComponent = /*#__PURE__*/reactExports.forwardRef((props, ref) => {
28945
28948
  const {
28946
28949
  locale
28947
28950
  } = useLayout();
28948
28951
  const {
28949
- init
28952
+ init,
28953
+ open
28950
28954
  } = useLlm(state => state.actions);
28951
28955
  const app = useLlm(state => state.app);
28952
28956
  const idle = useLlm(state => state.idle);
28953
28957
  const opened = useLlm(state => state.opened);
28958
+ const embedded = useLlm(state => state.embedded);
28959
+ reactExports.useImperativeHandle(ref, () => ({
28960
+ open: () => {
28961
+ open();
28962
+ }
28963
+ }));
28954
28964
  reactExports.useEffect(() => {
28955
28965
  init(locale);
28956
28966
  }, [init, locale]);
@@ -28959,7 +28969,8 @@ void main(void) {
28959
28969
  }, [opened]);
28960
28970
  const mounted = useMounted();
28961
28971
  const classNames = getClassNames('llm', {
28962
- '-open': opened
28972
+ '-open': opened,
28973
+ '-embedded': embedded
28963
28974
  });
28964
28975
  if (mounted) {
28965
28976
  return /*#__PURE__*/jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {
@@ -28976,7 +28987,7 @@ void main(void) {
28976
28987
  } else {
28977
28988
  return /*#__PURE__*/jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
28978
28989
  }
28979
- };
28990
+ });
28980
28991
 
28981
28992
  const ErrorBoundaryContext = /*#__PURE__*/reactExports.createContext(null);
28982
28993
  const initialState = {
@@ -29230,12 +29241,14 @@ void main(void) {
29230
29241
  }
29231
29242
  }];
29232
29243
 
29233
- function App(_a) {
29244
+ const App = _a => {
29234
29245
  var {
29235
29246
  locale,
29236
- market
29247
+ market,
29248
+ instance
29237
29249
  } = _a,
29238
- props = __rest(_a, ["locale", "market"]);
29250
+ props = __rest(_a, ["locale", "market", "instance"]);
29251
+ const llmRef = reactExports.useRef(null);
29239
29252
  const data = reactExports.useMemo(() => {
29240
29253
  if (isBrowser$1) {
29241
29254
  const htmlLang = getHtmlLang();
@@ -29285,7 +29298,11 @@ void main(void) {
29285
29298
  market: data.market,
29286
29299
  title: data.title,
29287
29300
  abstract: data.description,
29288
- category: 'uncategorized',
29301
+ category: {
29302
+ id: 'uncategorized',
29303
+ slug: 'uncategorized',
29304
+ title: 'uncategorized'
29305
+ },
29289
29306
  slug: data.slug,
29290
29307
  href: data.canonical,
29291
29308
  id: 1,
@@ -29294,6 +29311,12 @@ void main(void) {
29294
29311
  canonical: data.canonical
29295
29312
  };
29296
29313
  const extra = {};
29314
+ reactExports.useEffect(() => {
29315
+ if (llmRef.current && instance) {
29316
+ // console.log('App', llmRef.current, instance);
29317
+ Object.assign(instance, llmRef.current);
29318
+ }
29319
+ }, []);
29297
29320
  return jsxRuntimeExports.jsx(ErrorBoundary, {
29298
29321
  FallbackComponent: ErrorHandler,
29299
29322
  children: jsxRuntimeExports.jsx(LayoutProvider, {
@@ -29305,14 +29328,16 @@ void main(void) {
29305
29328
  extra: extra,
29306
29329
  children: jsxRuntimeExports.jsx(LlmProvider, Object.assign({}, props, {
29307
29330
  endpoint: endpoint,
29308
- children: jsxRuntimeExports.jsx(LlmComponent, {})
29331
+ children: jsxRuntimeExports.jsx(LlmComponent, {
29332
+ ref: llmRef
29333
+ })
29309
29334
  }))
29310
29335
  })
29311
29336
  })
29312
29337
  })
29313
29338
  })
29314
29339
  });
29315
- }
29340
+ };
29316
29341
  function getLabels(locale) {
29317
29342
  return label.map(x => {
29318
29343
  const localizedItem = localizeItem(x, locale, 'en');
@@ -29348,9 +29373,27 @@ void main(void) {
29348
29373
  const node = document.createElement('div');
29349
29374
  node.setAttribute('id', 'bom-llm');
29350
29375
  body.appendChild(node);
29351
- client.createRoot(node).render(jsxRuntimeExports.jsx(React.StrictMode, {
29352
- children: jsxRuntimeExports.jsx(App, Object.assign({}, props))
29376
+ const llm = {
29377
+ open: () => {
29378
+ console.log('unitialized');
29379
+ }
29380
+ };
29381
+ const root = client.createRoot(node);
29382
+ root.render(jsxRuntimeExports.jsx(React.StrictMode, {
29383
+ children: jsxRuntimeExports.jsx(App, Object.assign({}, props, {
29384
+ instance: llm
29385
+ }))
29353
29386
  }));
29387
+ const nodes = Array.from(document.querySelectorAll('llm-embed'));
29388
+ nodes.forEach(node => {
29389
+ const root = client.createRoot(node);
29390
+ root.render(jsxRuntimeExports.jsx(React.StrictMode, {
29391
+ children: jsxRuntimeExports.jsx(App, Object.assign({}, props, {
29392
+ embedded: true
29393
+ }))
29394
+ }));
29395
+ });
29396
+ return llm;
29354
29397
  }
29355
29398
  if (typeof window !== 'undefined') {
29356
29399
  window.bomLlm = bomLlm;