@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.cjs
CHANGED
|
@@ -282,12 +282,12 @@ var __copyProps = function(to, from, except, desc) {
|
|
|
282
282
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
283
283
|
try {
|
|
284
284
|
var _loop = function() {
|
|
285
|
-
var
|
|
286
|
-
if (!__hasOwnProp.call(to,
|
|
285
|
+
var key2 = _step.value;
|
|
286
|
+
if (!__hasOwnProp.call(to, key2) && key2 !== except) __defProp(to, key2, {
|
|
287
287
|
get: function() {
|
|
288
|
-
return from[
|
|
288
|
+
return from[key2];
|
|
289
289
|
},
|
|
290
|
-
enumerable: !(desc = __getOwnPropDesc(from,
|
|
290
|
+
enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable
|
|
291
291
|
});
|
|
292
292
|
};
|
|
293
293
|
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
@@ -412,13 +412,46 @@ var merge = function(obj) {
|
|
|
412
412
|
};
|
|
413
413
|
// src/contexts/core/SuperinterfaceContext/index.tsx
|
|
414
414
|
var import_react = require("react");
|
|
415
|
+
// src/lib/superinterfaceCloud/baseUrl.ts
|
|
416
|
+
var baseUrl = "https://superinterface.ai/api/cloud";
|
|
417
|
+
// src/lib/threadIdCookies/options/get.ts
|
|
418
|
+
var import_js_cookie = __toESM(require("js-cookie"), 1);
|
|
419
|
+
// src/lib/threadIdCookies/key.ts
|
|
420
|
+
var key = function(param) {
|
|
421
|
+
var assistantId = param.assistantId;
|
|
422
|
+
return "superinterface-".concat(assistantId, "-threadId");
|
|
423
|
+
};
|
|
424
|
+
// src/lib/threadIdCookies/options/get.ts
|
|
425
|
+
var get = function(param) {
|
|
426
|
+
var assistantId = param.assistantId;
|
|
427
|
+
return import_js_cookie.default.get(key({
|
|
428
|
+
assistantId: assistantId
|
|
429
|
+
}));
|
|
430
|
+
};
|
|
431
|
+
// src/lib/threadIdCookies/options/set.ts
|
|
432
|
+
var import_js_cookie2 = __toESM(require("js-cookie"), 1);
|
|
433
|
+
var set = function(param) {
|
|
434
|
+
var assistantId = param.assistantId, threadId = param.threadId;
|
|
435
|
+
return import_js_cookie2.default.set(key({
|
|
436
|
+
assistantId: assistantId
|
|
437
|
+
}), threadId, {
|
|
438
|
+
expires: 270
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
// src/lib/threadIdCookies/options/index.ts
|
|
442
|
+
var options = {
|
|
443
|
+
get: get,
|
|
444
|
+
set: set
|
|
445
|
+
};
|
|
446
|
+
// src/contexts/core/SuperinterfaceContext/index.tsx
|
|
415
447
|
var SuperinterfaceContext = (0, import_react.createContext)({
|
|
416
|
-
baseUrl:
|
|
448
|
+
baseUrl: baseUrl,
|
|
417
449
|
variables: {},
|
|
418
450
|
defaultOptions: {
|
|
419
451
|
queries: {},
|
|
420
452
|
mutations: {}
|
|
421
|
-
}
|
|
453
|
+
},
|
|
454
|
+
threadIdCookieOptions: options
|
|
422
455
|
});
|
|
423
456
|
// src/hooks/core/useSuperinterfaceContext/index.ts
|
|
424
457
|
var import_react2 = require("react");
|
|
@@ -428,16 +461,18 @@ var useSuperinterfaceContext = function() {
|
|
|
428
461
|
// src/components/core/SuperinterfaceProvider/index.tsx
|
|
429
462
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
430
463
|
var SuperinterfaceProvider = function(param) {
|
|
431
|
-
var children = param.children,
|
|
464
|
+
var children = param.children, baseUrl2 = param.baseUrl, publicApiKey = param.publicApiKey, variables = param.variables, defaultOptions = param.defaultOptions, threadIdCookieOptions = param.threadIdCookieOptions;
|
|
432
465
|
var superinterfaceContext = useSuperinterfaceContext();
|
|
433
|
-
var value = merge(superinterfaceContext, _object_spread({},
|
|
434
|
-
baseUrl:
|
|
466
|
+
var value = merge(superinterfaceContext, _object_spread({}, baseUrl2 ? {
|
|
467
|
+
baseUrl: baseUrl2
|
|
435
468
|
} : {}, publicApiKey ? {
|
|
436
469
|
publicApiKey: publicApiKey
|
|
437
470
|
} : {}, variables ? {
|
|
438
471
|
variables: variables
|
|
439
472
|
} : {}, defaultOptions ? {
|
|
440
473
|
defaultOptions: defaultOptions
|
|
474
|
+
} : {}, threadIdCookieOptions ? {
|
|
475
|
+
threadIdCookieOptions: threadIdCookieOptions
|
|
441
476
|
} : {}));
|
|
442
477
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SuperinterfaceContext.Provider, {
|
|
443
478
|
value: value,
|
|
@@ -453,6 +488,30 @@ var import_react3 = require("react");
|
|
|
453
488
|
var import_react_query2 = require("@tanstack/react-query");
|
|
454
489
|
// src/lib/threads/queryOptions/index.ts
|
|
455
490
|
var import_react_query = require("@tanstack/react-query");
|
|
491
|
+
// src/lib/threads/queryOptions/variableParams.ts
|
|
492
|
+
var variableParams = function(param) {
|
|
493
|
+
var variables = param.variables, superinterfaceContext = param.superinterfaceContext;
|
|
494
|
+
var _superinterfaceContext_threadIdCookieOptions;
|
|
495
|
+
console.log({
|
|
496
|
+
variables: variables,
|
|
497
|
+
superinterfaceContext: superinterfaceContext
|
|
498
|
+
});
|
|
499
|
+
if (variables.threadId) return variables;
|
|
500
|
+
if (!variables.assistantId) return variables;
|
|
501
|
+
if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.get)) return variables;
|
|
502
|
+
console.log("using");
|
|
503
|
+
var threadId = superinterfaceContext.threadIdCookieOptions.get({
|
|
504
|
+
assistantId: variables.assistantId
|
|
505
|
+
});
|
|
506
|
+
if (!threadId) return variables;
|
|
507
|
+
console.log({
|
|
508
|
+
threadId: threadId
|
|
509
|
+
});
|
|
510
|
+
return _object_spread_props(_object_spread({}, variables), {
|
|
511
|
+
threadId: threadId
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
// src/lib/threads/queryOptions/index.ts
|
|
456
515
|
var queryOptions = function(param) {
|
|
457
516
|
var queryKeyBase = param.queryKeyBase, path = param.path, queryClient = param.queryClient, threadContext = param.threadContext, superinterfaceContext = param.superinterfaceContext;
|
|
458
517
|
var queryKey = _to_consumable_array(queryKeyBase).concat([
|
|
@@ -468,12 +527,13 @@ var queryOptions = function(param) {
|
|
|
468
527
|
_queryKey2 = _sliced_to_array(queryKey2, 2), _key = _queryKey2[0], variables = _queryKey2[1];
|
|
469
528
|
params = new URLSearchParams(_object_spread({}, pageParam ? {
|
|
470
529
|
pageParam: pageParam
|
|
471
|
-
} : {},
|
|
530
|
+
} : {}, variableParams({
|
|
531
|
+
variables: variables,
|
|
532
|
+
superinterfaceContext: superinterfaceContext
|
|
533
|
+
})));
|
|
472
534
|
return [
|
|
473
535
|
2,
|
|
474
|
-
fetch("".concat(superinterfaceContext.baseUrl).concat(path, "?").concat(params), _object_spread({
|
|
475
|
-
credentials: "include"
|
|
476
|
-
}, superinterfaceContext.publicApiKey ? {
|
|
536
|
+
fetch("".concat(superinterfaceContext.baseUrl).concat(path, "?").concat(params), _object_spread({}, superinterfaceContext.publicApiKey ? {
|
|
477
537
|
headers: {
|
|
478
538
|
Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
|
|
479
539
|
}
|
|
@@ -1704,6 +1764,25 @@ var onMutate = function(param) {
|
|
|
1704
1764
|
};
|
|
1705
1765
|
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/index.ts
|
|
1706
1766
|
var import_json_whatwg = require("@streamparser/json-whatwg");
|
|
1767
|
+
// src/lib/threadIdCookies/ensure.ts
|
|
1768
|
+
var ensure = function(param) {
|
|
1769
|
+
var superinterfaceContext = param.superinterfaceContext, variables = param.variables, value = param.value;
|
|
1770
|
+
var _superinterfaceContext_threadIdCookieOptions;
|
|
1771
|
+
console.log({
|
|
1772
|
+
value: value,
|
|
1773
|
+
variables: variables,
|
|
1774
|
+
superinterfaceContext: superinterfaceContext
|
|
1775
|
+
});
|
|
1776
|
+
if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.set)) return;
|
|
1777
|
+
if (value.value.event !== "thread.run.created") return;
|
|
1778
|
+
if (variables.threadId) return;
|
|
1779
|
+
if (!variables.assistantId) return;
|
|
1780
|
+
console.log("saving");
|
|
1781
|
+
superinterfaceContext.threadIdCookieOptions.set({
|
|
1782
|
+
assistantId: variables.assistantId,
|
|
1783
|
+
threadId: value.value.data.thread_id
|
|
1784
|
+
});
|
|
1785
|
+
};
|
|
1707
1786
|
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/handleResponse/handlers/extendMessage.ts
|
|
1708
1787
|
var import_radash5 = require("radash");
|
|
1709
1788
|
var extendMessage = function(param) {
|
|
@@ -1936,9 +2015,9 @@ var updatedToolCall = function(param) {
|
|
|
1936
2015
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1937
2016
|
try {
|
|
1938
2017
|
for(var _iterator = Object.entries(delta.function)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1939
|
-
var _step_value = _sliced_to_array(_step.value, 2),
|
|
1940
|
-
var
|
|
1941
|
-
result.function[
|
|
2018
|
+
var _step_value = _sliced_to_array(_step.value, 2), key2 = _step_value[0], value = _step_value[1];
|
|
2019
|
+
var _result_function_key2;
|
|
2020
|
+
result.function[key2] = "".concat((_result_function_key2 = result.function[key2]) !== null && _result_function_key2 !== void 0 ? _result_function_key2 : "").concat(value);
|
|
1942
2021
|
}
|
|
1943
2022
|
} catch (err) {
|
|
1944
2023
|
_didIteratorError = true;
|
|
@@ -2057,6 +2136,29 @@ var handleResponse = function(param) {
|
|
|
2057
2136
|
value: value.value
|
|
2058
2137
|
}));
|
|
2059
2138
|
};
|
|
2139
|
+
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/body.ts
|
|
2140
|
+
var body = function(param) {
|
|
2141
|
+
var variables = param.variables, superinterfaceContext = param.superinterfaceContext;
|
|
2142
|
+
var _superinterfaceContext_threadIdCookieOptions;
|
|
2143
|
+
console.log({
|
|
2144
|
+
variables: variables,
|
|
2145
|
+
superinterfaceContext: superinterfaceContext
|
|
2146
|
+
});
|
|
2147
|
+
if (variables.threadId) return variables;
|
|
2148
|
+
if (!variables.assistantId) return variables;
|
|
2149
|
+
if (!((_superinterfaceContext_threadIdCookieOptions = superinterfaceContext.threadIdCookieOptions) === null || _superinterfaceContext_threadIdCookieOptions === void 0 ? void 0 : _superinterfaceContext_threadIdCookieOptions.get)) return variables;
|
|
2150
|
+
console.log("using");
|
|
2151
|
+
var threadId = superinterfaceContext.threadIdCookieOptions.get({
|
|
2152
|
+
assistantId: variables.assistantId
|
|
2153
|
+
});
|
|
2154
|
+
if (!threadId) return variables;
|
|
2155
|
+
console.log({
|
|
2156
|
+
threadId: threadId
|
|
2157
|
+
});
|
|
2158
|
+
return _object_spread_props(_object_spread({}, variables), {
|
|
2159
|
+
threadId: threadId
|
|
2160
|
+
});
|
|
2161
|
+
};
|
|
2060
2162
|
// src/hooks/messages/useCreateMessage/lib/mutationOptions/mutationFn/index.ts
|
|
2061
2163
|
var mutationFn = function(param) {
|
|
2062
2164
|
var superinterfaceContext = param.superinterfaceContext, queryClient = param.queryClient, threadContext = param.threadContext;
|
|
@@ -2070,8 +2172,10 @@ var mutationFn = function(param) {
|
|
|
2070
2172
|
4,
|
|
2071
2173
|
fetch("".concat(superinterfaceContext.baseUrl, "/messages"), _object_spread({
|
|
2072
2174
|
method: "POST",
|
|
2073
|
-
body: JSON.stringify(
|
|
2074
|
-
|
|
2175
|
+
body: JSON.stringify(body({
|
|
2176
|
+
variables: variables,
|
|
2177
|
+
superinterfaceContext: superinterfaceContext
|
|
2178
|
+
}))
|
|
2075
2179
|
}, superinterfaceContext.publicApiKey ? {
|
|
2076
2180
|
headers: {
|
|
2077
2181
|
Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
|
|
@@ -2116,6 +2220,11 @@ var mutationFn = function(param) {
|
|
|
2116
2220
|
messagesQueryKey: messagesQueryKey,
|
|
2117
2221
|
queryClient: queryClient
|
|
2118
2222
|
});
|
|
2223
|
+
ensure({
|
|
2224
|
+
superinterfaceContext: superinterfaceContext,
|
|
2225
|
+
variables: variables,
|
|
2226
|
+
value: value
|
|
2227
|
+
});
|
|
2119
2228
|
return [
|
|
2120
2229
|
3,
|
|
2121
2230
|
2
|
|
@@ -3069,13 +3178,11 @@ var useMessageAudio = function(param) {
|
|
|
3069
3178
|
}
|
|
3070
3179
|
}
|
|
3071
3180
|
}, isHtmlAudioSupported ? {} : {
|
|
3072
|
-
xhr:
|
|
3181
|
+
xhr: _object_spread({}, superinterfaceContext.publicApiKey ? {
|
|
3073
3182
|
headers: {
|
|
3074
3183
|
Authorization: "Bearer ".concat(superinterfaceContext.publicApiKey)
|
|
3075
3184
|
}
|
|
3076
|
-
} : {})
|
|
3077
|
-
withCredentials: true
|
|
3078
|
-
})
|
|
3185
|
+
} : {})
|
|
3079
3186
|
}));
|
|
3080
3187
|
}, [
|
|
3081
3188
|
unplayedMessageSentences,
|