@superinterface/react 2.5.0 → 2.6.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.cjs +129 -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 +125 -18
- package/dist/index.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,30 @@ 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
|
+
console.log({
|
|
369
|
+
variables: variables,
|
|
370
|
+
superinterfaceContext: superinterfaceContext
|
|
371
|
+
});
|
|
372
|
+
if (variables.threadId) return variables;
|
|
373
|
+
if (!variables.assistantId) return variables;
|
|
374
|
+
if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.get)) return variables;
|
|
375
|
+
console.log("using");
|
|
376
|
+
var threadId = superinterfaceContext.threadIdCookieOptions.get({
|
|
377
|
+
assistantId: variables.assistantId
|
|
378
|
+
});
|
|
379
|
+
if (!threadId) return variables;
|
|
380
|
+
console.log({
|
|
381
|
+
threadId: threadId
|
|
382
|
+
});
|
|
383
|
+
return _object_spread_props(_object_spread({}, variables), {
|
|
384
|
+
threadId: threadId
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
// src/lib/threads/queryOptions/index.ts
|
|
329
388
|
var queryOptions = function(param) {
|
|
330
389
|
var queryKeyBase = param.queryKeyBase, path = param.path, queryClient = param.queryClient, threadContext = param.threadContext, superinterfaceContext = param.superinterfaceContext;
|
|
331
390
|
var queryKey = _to_consumable_array(queryKeyBase).concat([
|
|
@@ -341,12 +400,13 @@ var queryOptions = function(param) {
|
|
|
341
400
|
_queryKey2 = _sliced_to_array(queryKey2, 2), _key = _queryKey2[0], variables = _queryKey2[1];
|
|
342
401
|
params = new URLSearchParams(_object_spread({}, pageParam ? {
|
|
343
402
|
pageParam: pageParam
|
|
344
|
-
} : {},
|
|
403
|
+
} : {}, variableParams({
|
|
404
|
+
variables: variables,
|
|
405
|
+
superinterfaceContext: superinterfaceContext
|
|
406
|
+
})));
|
|
345
407
|
return [
|
|
346
408
|
2,
|
|
347
|
-
fetch("".concat(superinterfaceContext.baseUrl).concat(path, "?").concat(params), _object_spread({
|
|
348
|
-
credentials: "include"
|
|
349
|
-
}, superinterfaceContext.publicApiKey ? {
|
|
409
|
+
fetch("".concat(superinterfaceContext.baseUrl).concat(path, "?").concat(params), _object_spread({}, superinterfaceContext.publicApiKey ? {
|
|
350
410
|
headers: {
|
|
351
411
|
Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
|
|
352
412
|
}
|
|
@@ -1577,6 +1637,25 @@ var onMutate = function(param) {
|
|
|
1577
1637
|
};
|
|
1578
1638
|
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/index.ts
|
|
1579
1639
|
import { JSONParser } from "@streamparser/json-whatwg";
|
|
1640
|
+
// src/lib/threadIdCookies/ensure.ts
|
|
1641
|
+
var ensure = function(param) {
|
|
1642
|
+
var superinterfaceContext = param.superinterfaceContext, variables = param.variables, value = param.value;
|
|
1643
|
+
var _superinterfaceContext_threadIdCookieOptions;
|
|
1644
|
+
console.log({
|
|
1645
|
+
value: value,
|
|
1646
|
+
variables: variables,
|
|
1647
|
+
superinterfaceContext: superinterfaceContext
|
|
1648
|
+
});
|
|
1649
|
+
if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.set)) return;
|
|
1650
|
+
if (value.value.event !== "thread.run.created") return;
|
|
1651
|
+
if (variables.threadId) return;
|
|
1652
|
+
if (!variables.assistantId) return;
|
|
1653
|
+
console.log("saving");
|
|
1654
|
+
superinterfaceContext.threadIdCookieOptions.set({
|
|
1655
|
+
assistantId: variables.assistantId,
|
|
1656
|
+
threadId: value.value.data.thread_id
|
|
1657
|
+
});
|
|
1658
|
+
};
|
|
1580
1659
|
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/handleResponse/handlers/extendMessage.ts
|
|
1581
1660
|
import { last as last2 } from "radash";
|
|
1582
1661
|
var extendMessage = function(param) {
|
|
@@ -1809,9 +1888,9 @@ var updatedToolCall = function(param) {
|
|
|
1809
1888
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1810
1889
|
try {
|
|
1811
1890
|
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[
|
|
1891
|
+
var _step_value = _sliced_to_array(_step.value, 2), key2 = _step_value[0], value = _step_value[1];
|
|
1892
|
+
var _result_function_key2;
|
|
1893
|
+
result.function[key2] = "".concat((_result_function_key2 = result.function[key2]) !== null && _result_function_key2 !== void 0 ? _result_function_key2 : "").concat(value);
|
|
1815
1894
|
}
|
|
1816
1895
|
} catch (err) {
|
|
1817
1896
|
_didIteratorError = true;
|
|
@@ -1930,6 +2009,29 @@ var handleResponse = function(param) {
|
|
|
1930
2009
|
value: value.value
|
|
1931
2010
|
}));
|
|
1932
2011
|
};
|
|
2012
|
+
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/body.ts
|
|
2013
|
+
var body = function(param) {
|
|
2014
|
+
var variables = param.variables, superinterfaceContext = param.superinterfaceContext;
|
|
2015
|
+
var _superinterfaceContext_threadIdCookieOptions;
|
|
2016
|
+
console.log({
|
|
2017
|
+
variables: variables,
|
|
2018
|
+
superinterfaceContext: superinterfaceContext
|
|
2019
|
+
});
|
|
2020
|
+
if (variables.threadId) return variables;
|
|
2021
|
+
if (!variables.assistantId) return variables;
|
|
2022
|
+
if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.get)) return variables;
|
|
2023
|
+
console.log("using");
|
|
2024
|
+
var threadId = superinterfaceContext.threadIdCookieOptions.get({
|
|
2025
|
+
assistantId: variables.assistantId
|
|
2026
|
+
});
|
|
2027
|
+
if (!threadId) return variables;
|
|
2028
|
+
console.log({
|
|
2029
|
+
threadId: threadId
|
|
2030
|
+
});
|
|
2031
|
+
return _object_spread_props(_object_spread({}, variables), {
|
|
2032
|
+
threadId: threadId
|
|
2033
|
+
});
|
|
2034
|
+
};
|
|
1933
2035
|
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/index.ts
|
|
1934
2036
|
var mutationFn = function(param) {
|
|
1935
2037
|
var superinterfaceContext = param.superinterfaceContext, queryClient = param.queryClient, threadContext = param.threadContext;
|
|
@@ -1943,8 +2045,10 @@ var mutationFn = function(param) {
|
|
|
1943
2045
|
4,
|
|
1944
2046
|
fetch("".concat(superinterfaceContext.baseUrl, "/messages"), _object_spread({
|
|
1945
2047
|
method: "POST",
|
|
1946
|
-
body: JSON.stringify(
|
|
1947
|
-
|
|
2048
|
+
body: JSON.stringify(body({
|
|
2049
|
+
variables: variables,
|
|
2050
|
+
superinterfaceContext: superinterfaceContext
|
|
2051
|
+
}))
|
|
1948
2052
|
}, superinterfaceContext.publicApiKey ? {
|
|
1949
2053
|
headers: {
|
|
1950
2054
|
Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
|
|
@@ -1989,6 +2093,11 @@ var mutationFn = function(param) {
|
|
|
1989
2093
|
messagesQueryKey: messagesQueryKey,
|
|
1990
2094
|
queryClient: queryClient
|
|
1991
2095
|
});
|
|
2096
|
+
ensure({
|
|
2097
|
+
superinterfaceContext: superinterfaceContext,
|
|
2098
|
+
variables: variables,
|
|
2099
|
+
value: value
|
|
2100
|
+
});
|
|
1992
2101
|
return [
|
|
1993
2102
|
3,
|
|
1994
2103
|
2
|
|
@@ -2942,13 +3051,11 @@ var useMessageAudio = function(param) {
|
|
|
2942
3051
|
}
|
|
2943
3052
|
}
|
|
2944
3053
|
}, isHtmlAudioSupported ? {} : {
|
|
2945
|
-
xhr:
|
|
3054
|
+
xhr: _object_spread({}, superinterfaceContext.publicApiKey ? {
|
|
2946
3055
|
headers: {
|
|
2947
3056
|
Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
|
|
2948
3057
|
}
|
|
2949
|
-
} : {})
|
|
2950
|
-
withCredentials: true
|
|
2951
|
-
})
|
|
3058
|
+
} : {})
|
|
2952
3059
|
}));
|
|
2953
3060
|
}, [
|
|
2954
3061
|
unplayedMessageSentences,
|