@superinterface/react 2.5.0 → 2.6.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.cjs +107 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +103 -18
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +0 -6
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +0 -6
- package/dist/server.js.map +1 -1
- package/dist/utils.cjs +14 -5
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +5 -1
- package/dist/utils.d.ts +5 -1
- package/dist/utils.js +6 -1
- package/dist/utils.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.cts
CHANGED
|
@@ -7,6 +7,16 @@ import * as _tanstack_query_core_build_legacy_queryClient_Ho_z40Sw from '@tansta
|
|
|
7
7
|
import * as _tanstack_react_query_build_legacy_types from '@tanstack/react-query/build/legacy/types';
|
|
8
8
|
import OpenAI from 'openai';
|
|
9
9
|
|
|
10
|
+
declare const options: {
|
|
11
|
+
get: ({ assistantId, }: {
|
|
12
|
+
assistantId: string;
|
|
13
|
+
}) => string | undefined;
|
|
14
|
+
set: ({ assistantId, threadId, }: {
|
|
15
|
+
assistantId: string;
|
|
16
|
+
threadId: string;
|
|
17
|
+
}) => string | undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
10
20
|
type Args$6 = {
|
|
11
21
|
children: React.ReactNode;
|
|
12
22
|
baseUrl?: string;
|
|
@@ -18,8 +28,9 @@ type Args$6 = {
|
|
|
18
28
|
queries?: UseInfiniteQueryOptions<InfiniteData<MessagesPage>>;
|
|
19
29
|
mutations?: UseMutationOptions;
|
|
20
30
|
};
|
|
31
|
+
threadIdCookieOptions?: typeof options | null;
|
|
21
32
|
};
|
|
22
|
-
declare const SuperinterfaceProvider: ({ children, baseUrl, publicApiKey, variables, defaultOptions, }: Args$6) => react_jsx_runtime.JSX.Element;
|
|
33
|
+
declare const SuperinterfaceProvider: ({ children, baseUrl, publicApiKey, variables, defaultOptions, threadIdCookieOptions, }: Args$6) => react_jsx_runtime.JSX.Element;
|
|
23
34
|
|
|
24
35
|
declare const useSuperinterfaceContext: () => {
|
|
25
36
|
baseUrl: string | null;
|
|
@@ -29,6 +40,15 @@ declare const useSuperinterfaceContext: () => {
|
|
|
29
40
|
mutations: Record<string, any>;
|
|
30
41
|
};
|
|
31
42
|
publicApiKey?: string | undefined;
|
|
43
|
+
threadIdCookieOptions: {
|
|
44
|
+
get: ({ assistantId, }: {
|
|
45
|
+
assistantId: string;
|
|
46
|
+
}) => string | undefined;
|
|
47
|
+
set: ({ assistantId, threadId, }: {
|
|
48
|
+
assistantId: string;
|
|
49
|
+
threadId: string;
|
|
50
|
+
}) => string | undefined;
|
|
51
|
+
} | null;
|
|
32
52
|
};
|
|
33
53
|
|
|
34
54
|
type Args$5 = Args$6;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,16 @@ import * as _tanstack_query_core_build_legacy_queryClient_Ho_z40Sw from '@tansta
|
|
|
7
7
|
import * as _tanstack_react_query_build_legacy_types from '@tanstack/react-query/build/legacy/types';
|
|
8
8
|
import OpenAI from 'openai';
|
|
9
9
|
|
|
10
|
+
declare const options: {
|
|
11
|
+
get: ({ assistantId, }: {
|
|
12
|
+
assistantId: string;
|
|
13
|
+
}) => string | undefined;
|
|
14
|
+
set: ({ assistantId, threadId, }: {
|
|
15
|
+
assistantId: string;
|
|
16
|
+
threadId: string;
|
|
17
|
+
}) => string | undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
10
20
|
type Args$6 = {
|
|
11
21
|
children: React.ReactNode;
|
|
12
22
|
baseUrl?: string;
|
|
@@ -18,8 +28,9 @@ type Args$6 = {
|
|
|
18
28
|
queries?: UseInfiniteQueryOptions<InfiniteData<MessagesPage>>;
|
|
19
29
|
mutations?: UseMutationOptions;
|
|
20
30
|
};
|
|
31
|
+
threadIdCookieOptions?: typeof options | null;
|
|
21
32
|
};
|
|
22
|
-
declare const SuperinterfaceProvider: ({ children, baseUrl, publicApiKey, variables, defaultOptions, }: Args$6) => react_jsx_runtime.JSX.Element;
|
|
33
|
+
declare const SuperinterfaceProvider: ({ children, baseUrl, publicApiKey, variables, defaultOptions, threadIdCookieOptions, }: Args$6) => react_jsx_runtime.JSX.Element;
|
|
23
34
|
|
|
24
35
|
declare const useSuperinterfaceContext: () => {
|
|
25
36
|
baseUrl: string | null;
|
|
@@ -29,6 +40,15 @@ declare const useSuperinterfaceContext: () => {
|
|
|
29
40
|
mutations: Record<string, any>;
|
|
30
41
|
};
|
|
31
42
|
publicApiKey?: string | undefined;
|
|
43
|
+
threadIdCookieOptions: {
|
|
44
|
+
get: ({ assistantId, }: {
|
|
45
|
+
assistantId: string;
|
|
46
|
+
}) => string | undefined;
|
|
47
|
+
set: ({ assistantId, threadId, }: {
|
|
48
|
+
assistantId: string;
|
|
49
|
+
threadId: string;
|
|
50
|
+
}) => string | undefined;
|
|
51
|
+
} | null;
|
|
32
52
|
};
|
|
33
53
|
|
|
34
54
|
type Args$5 = Args$6;
|
package/dist/index.js
CHANGED
|
@@ -285,13 +285,46 @@ var merge = function(obj) {
|
|
|
285
285
|
};
|
|
286
286
|
// src/contexts/core/SuperinterfaceContext/index.tsx
|
|
287
287
|
import { createContext } from "react";
|
|
288
|
+
// src/lib/superinterfaceCloud/baseUrl.ts
|
|
289
|
+
var baseUrl = "https://superinterface.ai/api/cloud";
|
|
290
|
+
// src/lib/threadIdCookies/options/get.ts
|
|
291
|
+
import Cookies from "js-cookie";
|
|
292
|
+
// src/lib/threadIdCookies/key.ts
|
|
293
|
+
var key = function(param) {
|
|
294
|
+
var assistantId = param.assistantId;
|
|
295
|
+
return "superinterface-".concat(assistantId, "-threadId");
|
|
296
|
+
};
|
|
297
|
+
// src/lib/threadIdCookies/options/get.ts
|
|
298
|
+
var get = function(param) {
|
|
299
|
+
var assistantId = param.assistantId;
|
|
300
|
+
return Cookies.get(key({
|
|
301
|
+
assistantId: assistantId
|
|
302
|
+
}));
|
|
303
|
+
};
|
|
304
|
+
// src/lib/threadIdCookies/options/set.ts
|
|
305
|
+
import Cookies2 from "js-cookie";
|
|
306
|
+
var set = function(param) {
|
|
307
|
+
var assistantId = param.assistantId, threadId = param.threadId;
|
|
308
|
+
return Cookies2.set(key({
|
|
309
|
+
assistantId: assistantId
|
|
310
|
+
}), threadId, {
|
|
311
|
+
expires: 270
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
// src/lib/threadIdCookies/options/index.ts
|
|
315
|
+
var options = {
|
|
316
|
+
get: get,
|
|
317
|
+
set: set
|
|
318
|
+
};
|
|
319
|
+
// src/contexts/core/SuperinterfaceContext/index.tsx
|
|
288
320
|
var SuperinterfaceContext = createContext({
|
|
289
|
-
baseUrl:
|
|
321
|
+
baseUrl: baseUrl,
|
|
290
322
|
variables: {},
|
|
291
323
|
defaultOptions: {
|
|
292
324
|
queries: {},
|
|
293
325
|
mutations: {}
|
|
294
|
-
}
|
|
326
|
+
},
|
|
327
|
+
threadIdCookieOptions: options
|
|
295
328
|
});
|
|
296
329
|
// src/hooks/core/useSuperinterfaceContext/index.ts
|
|
297
330
|
import { useContext } from "react";
|
|
@@ -301,16 +334,18 @@ var useSuperinterfaceContext = function() {
|
|
|
301
334
|
// src/components/core/SuperinterfaceProvider/index.tsx
|
|
302
335
|
import { jsx } from "react/jsx-runtime";
|
|
303
336
|
var SuperinterfaceProvider = function(param) {
|
|
304
|
-
var children = param.children,
|
|
337
|
+
var children = param.children, baseUrl2 = param.baseUrl, publicApiKey = param.publicApiKey, variables = param.variables, defaultOptions = param.defaultOptions, threadIdCookieOptions = param.threadIdCookieOptions;
|
|
305
338
|
var superinterfaceContext = useSuperinterfaceContext();
|
|
306
|
-
var value = merge(superinterfaceContext, _object_spread({},
|
|
307
|
-
baseUrl:
|
|
339
|
+
var value = merge(superinterfaceContext, _object_spread({}, baseUrl2 ? {
|
|
340
|
+
baseUrl: baseUrl2
|
|
308
341
|
} : {}, publicApiKey ? {
|
|
309
342
|
publicApiKey: publicApiKey
|
|
310
343
|
} : {}, variables ? {
|
|
311
344
|
variables: variables
|
|
312
345
|
} : {}, defaultOptions ? {
|
|
313
346
|
defaultOptions: defaultOptions
|
|
347
|
+
} : {}, threadIdCookieOptions ? {
|
|
348
|
+
threadIdCookieOptions: threadIdCookieOptions
|
|
314
349
|
} : {}));
|
|
315
350
|
return /* @__PURE__ */ jsx(SuperinterfaceContext.Provider, {
|
|
316
351
|
value: value,
|
|
@@ -326,6 +361,22 @@ import { useMemo } from "react";
|
|
|
326
361
|
import { useInfiniteQuery, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
327
362
|
// src/lib/threads/queryOptions/index.ts
|
|
328
363
|
import { infiniteQueryOptions } from "@tanstack/react-query";
|
|
364
|
+
// src/lib/threads/queryOptions/variableParams.ts
|
|
365
|
+
var variableParams = function(param) {
|
|
366
|
+
var variables = param.variables, superinterfaceContext = param.superinterfaceContext;
|
|
367
|
+
var _superinterfaceContext_threadIdCookieOptions;
|
|
368
|
+
if (variables.threadId) return variables;
|
|
369
|
+
if (!variables.assistantId) return variables;
|
|
370
|
+
if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.get)) return variables;
|
|
371
|
+
var threadId = superinterfaceContext.threadIdCookieOptions.get({
|
|
372
|
+
assistantId: variables.assistantId
|
|
373
|
+
});
|
|
374
|
+
if (!threadId) return variables;
|
|
375
|
+
return _object_spread_props(_object_spread({}, variables), {
|
|
376
|
+
threadId: threadId
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
// src/lib/threads/queryOptions/index.ts
|
|
329
380
|
var queryOptions = function(param) {
|
|
330
381
|
var queryKeyBase = param.queryKeyBase, path = param.path, queryClient = param.queryClient, threadContext = param.threadContext, superinterfaceContext = param.superinterfaceContext;
|
|
331
382
|
var queryKey = _to_consumable_array(queryKeyBase).concat([
|
|
@@ -341,12 +392,13 @@ var queryOptions = function(param) {
|
|
|
341
392
|
_queryKey2 = _sliced_to_array(queryKey2, 2), _key = _queryKey2[0], variables = _queryKey2[1];
|
|
342
393
|
params = new URLSearchParams(_object_spread({}, pageParam ? {
|
|
343
394
|
pageParam: pageParam
|
|
344
|
-
} : {},
|
|
395
|
+
} : {}, variableParams({
|
|
396
|
+
variables: variables,
|
|
397
|
+
superinterfaceContext: superinterfaceContext
|
|
398
|
+
})));
|
|
345
399
|
return [
|
|
346
400
|
2,
|
|
347
|
-
fetch("".concat(superinterfaceContext.baseUrl).concat(path, "?").concat(params), _object_spread({
|
|
348
|
-
credentials: "include"
|
|
349
|
-
}, superinterfaceContext.publicApiKey ? {
|
|
401
|
+
fetch("".concat(superinterfaceContext.baseUrl).concat(path, "?").concat(params), _object_spread({}, superinterfaceContext.publicApiKey ? {
|
|
350
402
|
headers: {
|
|
351
403
|
Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
|
|
352
404
|
}
|
|
@@ -1577,6 +1629,19 @@ var onMutate = function(param) {
|
|
|
1577
1629
|
};
|
|
1578
1630
|
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/index.ts
|
|
1579
1631
|
import { JSONParser } from "@streamparser/json-whatwg";
|
|
1632
|
+
// src/lib/threadIdCookies/ensure.ts
|
|
1633
|
+
var ensure = function(param) {
|
|
1634
|
+
var superinterfaceContext = param.superinterfaceContext, variables = param.variables, value = param.value;
|
|
1635
|
+
var _superinterfaceContext_threadIdCookieOptions;
|
|
1636
|
+
if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.set)) return;
|
|
1637
|
+
if (value.value.event !== "thread.run.created") return;
|
|
1638
|
+
if (variables.threadId) return;
|
|
1639
|
+
if (!variables.assistantId) return;
|
|
1640
|
+
superinterfaceContext.threadIdCookieOptions.set({
|
|
1641
|
+
assistantId: variables.assistantId,
|
|
1642
|
+
threadId: value.value.data.thread_id
|
|
1643
|
+
});
|
|
1644
|
+
};
|
|
1580
1645
|
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/handleResponse/handlers/extendMessage.ts
|
|
1581
1646
|
import { last as last2 } from "radash";
|
|
1582
1647
|
var extendMessage = function(param) {
|
|
@@ -1809,9 +1874,9 @@ var updatedToolCall = function(param) {
|
|
|
1809
1874
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1810
1875
|
try {
|
|
1811
1876
|
for(var _iterator = Object.entries(delta.function)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1812
|
-
var _step_value = _sliced_to_array(_step.value, 2),
|
|
1813
|
-
var
|
|
1814
|
-
result.function[
|
|
1877
|
+
var _step_value = _sliced_to_array(_step.value, 2), key2 = _step_value[0], value = _step_value[1];
|
|
1878
|
+
var _result_function_key2;
|
|
1879
|
+
result.function[key2] = "".concat((_result_function_key2 = result.function[key2]) !== null && _result_function_key2 !== void 0 ? _result_function_key2 : "").concat(value);
|
|
1815
1880
|
}
|
|
1816
1881
|
} catch (err) {
|
|
1817
1882
|
_didIteratorError = true;
|
|
@@ -1930,6 +1995,21 @@ var handleResponse = function(param) {
|
|
|
1930
1995
|
value: value.value
|
|
1931
1996
|
}));
|
|
1932
1997
|
};
|
|
1998
|
+
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/body.ts
|
|
1999
|
+
var body = function(param) {
|
|
2000
|
+
var variables = param.variables, superinterfaceContext = param.superinterfaceContext;
|
|
2001
|
+
var _superinterfaceContext_threadIdCookieOptions;
|
|
2002
|
+
if (variables.threadId) return variables;
|
|
2003
|
+
if (!variables.assistantId) return variables;
|
|
2004
|
+
if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.get)) return variables;
|
|
2005
|
+
var threadId = superinterfaceContext.threadIdCookieOptions.get({
|
|
2006
|
+
assistantId: variables.assistantId
|
|
2007
|
+
});
|
|
2008
|
+
if (!threadId) return variables;
|
|
2009
|
+
return _object_spread_props(_object_spread({}, variables), {
|
|
2010
|
+
threadId: threadId
|
|
2011
|
+
});
|
|
2012
|
+
};
|
|
1933
2013
|
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/index.ts
|
|
1934
2014
|
var mutationFn = function(param) {
|
|
1935
2015
|
var superinterfaceContext = param.superinterfaceContext, queryClient = param.queryClient, threadContext = param.threadContext;
|
|
@@ -1943,8 +2023,10 @@ var mutationFn = function(param) {
|
|
|
1943
2023
|
4,
|
|
1944
2024
|
fetch("".concat(superinterfaceContext.baseUrl, "/messages"), _object_spread({
|
|
1945
2025
|
method: "POST",
|
|
1946
|
-
body: JSON.stringify(
|
|
1947
|
-
|
|
2026
|
+
body: JSON.stringify(body({
|
|
2027
|
+
variables: variables,
|
|
2028
|
+
superinterfaceContext: superinterfaceContext
|
|
2029
|
+
}))
|
|
1948
2030
|
}, superinterfaceContext.publicApiKey ? {
|
|
1949
2031
|
headers: {
|
|
1950
2032
|
Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
|
|
@@ -1989,6 +2071,11 @@ var mutationFn = function(param) {
|
|
|
1989
2071
|
messagesQueryKey: messagesQueryKey,
|
|
1990
2072
|
queryClient: queryClient
|
|
1991
2073
|
});
|
|
2074
|
+
ensure({
|
|
2075
|
+
superinterfaceContext: superinterfaceContext,
|
|
2076
|
+
variables: variables,
|
|
2077
|
+
value: value
|
|
2078
|
+
});
|
|
1992
2079
|
return [
|
|
1993
2080
|
3,
|
|
1994
2081
|
2
|
|
@@ -2942,13 +3029,11 @@ var useMessageAudio = function(param) {
|
|
|
2942
3029
|
}
|
|
2943
3030
|
}
|
|
2944
3031
|
}, isHtmlAudioSupported ? {} : {
|
|
2945
|
-
xhr:
|
|
3032
|
+
xhr: _object_spread({}, superinterfaceContext.publicApiKey ? {
|
|
2946
3033
|
headers: {
|
|
2947
3034
|
Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
|
|
2948
3035
|
}
|
|
2949
|
-
} : {})
|
|
2950
|
-
withCredentials: true
|
|
2951
|
-
})
|
|
3036
|
+
} : {})
|
|
2952
3037
|
}));
|
|
2953
3038
|
}, [
|
|
2954
3039
|
unplayedMessageSentences,
|