@superinterface/react 3.2.1 → 3.4.0

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.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { MessagesPage, StyleProps, SerializedMessage, Avatar as Avatar$1, SerializedRunStep, ToolCall } from './types/index.cjs';
2
+ import { MessagesPage, ThreadStorageOptions, StyleProps, SerializedMessage, Avatar as Avatar$1, SerializedRunStep, ToolCall } from './types/index.cjs';
3
3
  import * as _tanstack_react_query from '@tanstack/react-query';
4
4
  import { UseInfiniteQueryOptions, InfiniteData, UseMutationOptions } from '@tanstack/react-query';
5
5
  import * as react_hook_form from 'react-hook-form';
@@ -13,16 +13,6 @@ import * as _radix_ui_themes_dist_cjs_components_table from '@radix-ui/themes/di
13
13
  import OpenAI from 'openai';
14
14
  import * as openai_resources_beta_threads_runs_steps from 'openai/resources/beta/threads/runs/steps';
15
15
 
16
- declare const options: {
17
- get: ({ assistantId, }: {
18
- assistantId: string;
19
- }) => string | undefined;
20
- set: ({ assistantId, threadId, }: {
21
- assistantId: string;
22
- threadId: string;
23
- }) => string | undefined;
24
- };
25
-
26
16
  type Args$9 = {
27
17
  children: React.ReactNode;
28
18
  baseUrl?: string;
@@ -33,9 +23,9 @@ type Args$9 = {
33
23
  queries?: UseInfiniteQueryOptions<InfiniteData<MessagesPage>>;
34
24
  mutations?: UseMutationOptions;
35
25
  };
36
- threadIdCookieOptions?: typeof options | null;
26
+ threadIdStorageOptions?: ThreadStorageOptions | null;
37
27
  };
38
- declare const SuperinterfaceProvider: ({ children, baseUrl, variables, defaultOptions, threadIdCookieOptions, }: Args$9) => react_jsx_runtime.JSX.Element;
28
+ declare const SuperinterfaceProvider: ({ children, baseUrl, variables, defaultOptions, threadIdStorageOptions, }: Args$9) => react_jsx_runtime.JSX.Element;
39
29
 
40
30
  declare const useSuperinterfaceContext: () => {
41
31
  baseUrl: string | null;
@@ -44,7 +34,7 @@ declare const useSuperinterfaceContext: () => {
44
34
  queries: Record<string, any>;
45
35
  mutations: Record<string, any>;
46
36
  };
47
- threadIdCookieOptions: typeof options | null;
37
+ threadIdStorageOptions: ThreadStorageOptions | null;
48
38
  createMessageAbortControllerRef: React.MutableRefObject<AbortController | null>;
49
39
  };
50
40
 
@@ -92,6 +82,7 @@ declare const Thread: {
92
82
  } & StyleProps) => react_jsx_runtime.JSX.Element;
93
83
  Input: (props: Omit<StyleProps, "style"> & {
94
84
  style?: Omit<React.CSSProperties, "minHeight" | "maxHeight" | "height">;
85
+ placeholder?: string;
95
86
  }) => react_jsx_runtime.JSX.Element;
96
87
  };
97
88
  Files: {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { MessagesPage, StyleProps, SerializedMessage, Avatar as Avatar$1, SerializedRunStep, ToolCall } from './types/index.js';
2
+ import { MessagesPage, ThreadStorageOptions, StyleProps, SerializedMessage, Avatar as Avatar$1, SerializedRunStep, ToolCall } from './types/index.js';
3
3
  import * as _tanstack_react_query from '@tanstack/react-query';
4
4
  import { UseInfiniteQueryOptions, InfiniteData, UseMutationOptions } from '@tanstack/react-query';
5
5
  import * as react_hook_form from 'react-hook-form';
@@ -13,16 +13,6 @@ import * as _radix_ui_themes_dist_cjs_components_table from '@radix-ui/themes/di
13
13
  import OpenAI from 'openai';
14
14
  import * as openai_resources_beta_threads_runs_steps from 'openai/resources/beta/threads/runs/steps';
15
15
 
16
- declare const options: {
17
- get: ({ assistantId, }: {
18
- assistantId: string;
19
- }) => string | undefined;
20
- set: ({ assistantId, threadId, }: {
21
- assistantId: string;
22
- threadId: string;
23
- }) => string | undefined;
24
- };
25
-
26
16
  type Args$9 = {
27
17
  children: React.ReactNode;
28
18
  baseUrl?: string;
@@ -33,9 +23,9 @@ type Args$9 = {
33
23
  queries?: UseInfiniteQueryOptions<InfiniteData<MessagesPage>>;
34
24
  mutations?: UseMutationOptions;
35
25
  };
36
- threadIdCookieOptions?: typeof options | null;
26
+ threadIdStorageOptions?: ThreadStorageOptions | null;
37
27
  };
38
- declare const SuperinterfaceProvider: ({ children, baseUrl, variables, defaultOptions, threadIdCookieOptions, }: Args$9) => react_jsx_runtime.JSX.Element;
28
+ declare const SuperinterfaceProvider: ({ children, baseUrl, variables, defaultOptions, threadIdStorageOptions, }: Args$9) => react_jsx_runtime.JSX.Element;
39
29
 
40
30
  declare const useSuperinterfaceContext: () => {
41
31
  baseUrl: string | null;
@@ -44,7 +34,7 @@ declare const useSuperinterfaceContext: () => {
44
34
  queries: Record<string, any>;
45
35
  mutations: Record<string, any>;
46
36
  };
47
- threadIdCookieOptions: typeof options | null;
37
+ threadIdStorageOptions: ThreadStorageOptions | null;
48
38
  createMessageAbortControllerRef: React.MutableRefObject<AbortController | null>;
49
39
  };
50
40
 
@@ -92,6 +82,7 @@ declare const Thread: {
92
82
  } & StyleProps) => react_jsx_runtime.JSX.Element;
93
83
  Input: (props: Omit<StyleProps, "style"> & {
94
84
  style?: Omit<React.CSSProperties, "minHeight" | "maxHeight" | "height">;
85
+ placeholder?: string;
95
86
  }) => react_jsx_runtime.JSX.Element;
96
87
  };
97
88
  Files: {
package/dist/index.js CHANGED
@@ -344,34 +344,74 @@ var merge = function(obj) {
344
344
  import { createContext } from "react";
345
345
  // src/lib/superinterfaceCloud/baseUrl.ts
346
346
  var baseUrl = "https://superinterface.ai/api/cloud";
347
- // src/lib/threadIdCookies/options/get.ts
347
+ // src/lib/threadIdStorage/cookieOptions/get.ts
348
348
  import Cookies from "js-cookie";
349
- // src/lib/threadIdCookies/key.ts
349
+ // src/lib/threadIdStorage/key.ts
350
350
  var key = function(param) {
351
351
  var assistantId = param.assistantId;
352
352
  return "superinterface-".concat(assistantId, "-threadId");
353
353
  };
354
- // src/lib/threadIdCookies/options/get.ts
354
+ // src/lib/threadIdStorage/cookieOptions/get.ts
355
355
  var get = function(param) {
356
356
  var assistantId = param.assistantId;
357
- return Cookies.get(key({
357
+ var _Cookies_get;
358
+ return (_Cookies_get = Cookies.get(key({
358
359
  assistantId: assistantId
359
- }));
360
+ }))) !== null && _Cookies_get !== void 0 ? _Cookies_get : null;
360
361
  };
361
- // src/lib/threadIdCookies/options/set.ts
362
+ // src/lib/threadIdStorage/cookieOptions/set.ts
362
363
  import Cookies2 from "js-cookie";
363
364
  var set = function(param) {
364
365
  var assistantId = param.assistantId, threadId = param.threadId;
365
366
  return Cookies2.set(key({
366
367
  assistantId: assistantId
367
- }), threadId, {
368
- expires: 7
369
- });
368
+ }), threadId);
369
+ };
370
+ // src/lib/threadIdStorage/cookieOptions/remove.ts
371
+ import Cookies3 from "js-cookie";
372
+ var remove = function(param) {
373
+ var assistantId = param.assistantId;
374
+ return Cookies3.remove(key({
375
+ assistantId: assistantId
376
+ }));
370
377
  };
371
- // src/lib/threadIdCookies/options/index.ts
372
- var options = {
378
+ // src/lib/threadIdStorage/cookieOptions/index.ts
379
+ var cookieOptions = {
373
380
  get: get,
374
- set: set
381
+ set: set,
382
+ remove: remove
383
+ };
384
+ // src/lib/threadIdStorage/localStorageOptions/get.ts
385
+ var get2 = function(param) {
386
+ var assistantId = param.assistantId;
387
+ return window.localStorage.getItem(key({
388
+ assistantId: assistantId
389
+ }));
390
+ };
391
+ // src/lib/threadIdStorage/localStorageOptions/set.ts
392
+ var set2 = function(param) {
393
+ var assistantId = param.assistantId, threadId = param.threadId;
394
+ return window.localStorage.setItem(key({
395
+ assistantId: assistantId
396
+ }), threadId);
397
+ };
398
+ // src/lib/threadIdStorage/localStorageOptions/remove.ts
399
+ var remove2 = function(param) {
400
+ var assistantId = param.assistantId;
401
+ return window.localStorage.removeItem(key({
402
+ assistantId: assistantId
403
+ }));
404
+ };
405
+ // src/lib/threadIdStorage/localStorageOptions/index.ts
406
+ var localStorageOptions = {
407
+ get: get2,
408
+ set: set2,
409
+ remove: remove2
410
+ };
411
+ // src/lib/iframes/isIframe.ts
412
+ var isIframe = function() {
413
+ if (typeof window === "undefined") return false;
414
+ return window.self !== window.top;
375
415
  };
376
416
  // src/contexts/core/SuperinterfaceContext/index.tsx
377
417
  var SuperinterfaceContext = createContext({
@@ -381,7 +421,7 @@ var SuperinterfaceContext = createContext({
381
421
  queries: {},
382
422
  mutations: {}
383
423
  },
384
- threadIdCookieOptions: options,
424
+ threadIdStorageOptions: isIframe() ? localStorageOptions : cookieOptions,
385
425
  createMessageAbortControllerRef: {
386
426
  current: null
387
427
  }
@@ -394,7 +434,7 @@ var useSuperinterfaceContext = function() {
394
434
  // src/components/core/SuperinterfaceProvider/index.tsx
395
435
  import { jsx } from "react/jsx-runtime";
396
436
  var SuperinterfaceProvider = function(param) {
397
- var children = param.children, baseUrl2 = param.baseUrl, variables = param.variables, defaultOptions = param.defaultOptions, threadIdCookieOptions = param.threadIdCookieOptions;
437
+ var children = param.children, baseUrl2 = param.baseUrl, variables = param.variables, defaultOptions = param.defaultOptions, threadIdStorageOptions = param.threadIdStorageOptions;
398
438
  var superinterfaceContext = useSuperinterfaceContext();
399
439
  var createMessageAbortControllerRef = useRef(null);
400
440
  var value = merge(superinterfaceContext, _object_spread_props(_object_spread({}, baseUrl2 ? {
@@ -403,8 +443,8 @@ var SuperinterfaceProvider = function(param) {
403
443
  variables: variables
404
444
  } : {}, defaultOptions ? {
405
445
  defaultOptions: defaultOptions
406
- } : {}, threadIdCookieOptions ? {
407
- threadIdCookieOptions: threadIdCookieOptions
446
+ } : {}, threadIdStorageOptions ? {
447
+ threadIdStorageOptions: threadIdStorageOptions
408
448
  } : {}), {
409
449
  createMessageAbortControllerRef: createMessageAbortControllerRef
410
450
  }));
@@ -984,11 +1024,11 @@ import { infiniteQueryOptions } from "@tanstack/react-query";
984
1024
  // src/lib/threads/queryOptions/variableParams.ts
985
1025
  var variableParams = function(param) {
986
1026
  var variables = param.variables, superinterfaceContext = param.superinterfaceContext;
987
- var _superinterfaceContext_threadIdCookieOptions;
1027
+ var _superinterfaceContext_threadIdStorageOptions;
988
1028
  if (variables.threadId) return variables;
989
1029
  if (!variables.assistantId) return variables;
990
- if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.get)) return variables;
991
- var threadId = superinterfaceContext.threadIdCookieOptions.get({
1030
+ if (!((_superinterfaceContext_threadIdStorageOptions = superinterfaceContext.threadIdStorageOptions) === null || _superinterfaceContext_threadIdStorageOptions === void 0 ? void 0 : _superinterfaceContext_threadIdStorageOptions.get)) return variables;
1031
+ var threadId = superinterfaceContext.threadIdStorageOptions.get({
992
1032
  assistantId: variables.assistantId
993
1033
  });
994
1034
  if (!threadId) return variables;
@@ -1247,11 +1287,11 @@ import { JSONParser } from "@streamparser/json-whatwg";
1247
1287
  // src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/handleResponse/handlers/threadCreated.ts
1248
1288
  var threadCreated = function(param) {
1249
1289
  var value = param.value, superinterfaceContext = param.superinterfaceContext;
1250
- var _superinterfaceContext_threadIdCookieOptions, _value_data_metadata, _value_data_metadata1;
1251
- if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.set)) return;
1290
+ var _superinterfaceContext_threadIdStorageOptions, _value_data_metadata, _value_data_metadata1;
1291
+ if (!((_superinterfaceContext_threadIdStorageOptions = superinterfaceContext.threadIdStorageOptions) === null || _superinterfaceContext_threadIdStorageOptions === void 0 ? void 0 : _superinterfaceContext_threadIdStorageOptions.set)) return;
1252
1292
  if (!((_value_data_metadata = value.data.metadata) === null || _value_data_metadata === void 0 ? void 0 : _value_data_metadata.assistantId)) return;
1253
1293
  if (!((_value_data_metadata1 = value.data.metadata) === null || _value_data_metadata1 === void 0 ? void 0 : _value_data_metadata1.threadId)) return;
1254
- superinterfaceContext.threadIdCookieOptions.set({
1294
+ superinterfaceContext.threadIdStorageOptions.set({
1255
1295
  // @ts-ignore-next-line
1256
1296
  assistantId: value.data.metadata.assistantId,
1257
1297
  // @ts-ignore-next-line
@@ -1740,11 +1780,11 @@ var handleResponse = function(param) {
1740
1780
  // src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/body.ts
1741
1781
  var body = function(param) {
1742
1782
  var variables = param.variables, superinterfaceContext = param.superinterfaceContext;
1743
- var _superinterfaceContext_threadIdCookieOptions;
1783
+ var _superinterfaceContext_threadIdStorageOptions;
1744
1784
  if (variables.threadId) return variables;
1745
1785
  if (!variables.assistantId) return variables;
1746
- if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.get)) return variables;
1747
- var threadId = superinterfaceContext.threadIdCookieOptions.get({
1786
+ if (!((_superinterfaceContext_threadIdStorageOptions = superinterfaceContext.threadIdStorageOptions) === null || _superinterfaceContext_threadIdStorageOptions === void 0 ? void 0 : _superinterfaceContext_threadIdStorageOptions.get)) return variables;
1787
+ var threadId = superinterfaceContext.threadIdStorageOptions.get({
1748
1788
  assistantId: variables.assistantId
1749
1789
  });
1750
1790
  if (!threadId) return variables;
@@ -3525,9 +3565,10 @@ var Input = function(props) {
3525
3565
  isDisabledPrevious,
3526
3566
  textareaProps
3527
3567
  ]);
3568
+ var _props_placeholder;
3528
3569
  return /* @__PURE__ */ jsx66(TextareaBase, _object_spread_props(_object_spread({
3529
3570
  minRows: 1,
3530
- placeholder: "Message ".concat(assistantNameContext, "..."),
3571
+ placeholder: (_props_placeholder = props.placeholder) !== null && _props_placeholder !== void 0 ? _props_placeholder : "Message ".concat(assistantNameContext, "..."),
3531
3572
  disabled: isDisabled,
3532
3573
  onKeyDown: function(e) {
3533
3574
  if (e.key === "Enter" && !e.shiftKey) {
@@ -3639,11 +3680,11 @@ var formData = function(variables) {
3639
3680
  // src/hooks/files/useCreateFile/lib/mutationOptions/mutationFn/body/index.ts
3640
3681
  var body2 = function(param) {
3641
3682
  var variables = param.variables, superinterfaceContext = param.superinterfaceContext;
3642
- var _superinterfaceContext_threadIdCookieOptions;
3683
+ var _superinterfaceContext_threadIdStorageOptions;
3643
3684
  if (variables.threadId) return formData(variables);
3644
3685
  if (!variables.assistantId) return formData(variables);
3645
- if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.get)) return formData(variables);
3646
- var threadId = superinterfaceContext.threadIdCookieOptions.get({
3686
+ if (!((_superinterfaceContext_threadIdStorageOptions = superinterfaceContext.threadIdStorageOptions) === null || _superinterfaceContext_threadIdStorageOptions === void 0 ? void 0 : _superinterfaceContext_threadIdStorageOptions.get)) return formData(variables);
3687
+ var threadId = superinterfaceContext.threadIdStorageOptions.get({
3647
3688
  assistantId: variables.assistantId
3648
3689
  });
3649
3690
  if (!threadId) return formData(variables);