@iota-uz/sdk 0.4.22 → 0.4.23
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/bichat/index.cjs +42 -70
- package/dist/bichat/index.cjs.map +1 -1
- package/dist/bichat/index.d.cts +11 -1
- package/dist/bichat/index.d.ts +11 -1
- package/dist/bichat/index.mjs +42 -70
- package/dist/bichat/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bichat/index.cjs
CHANGED
|
@@ -1880,7 +1880,7 @@ function pendingQuestionFromInterrupt(interrupt, fallbackTurnId) {
|
|
|
1880
1880
|
options: Array.isArray(question.options) ? question.options.filter((option) => !!option && typeof option.id === "string").map((option) => ({
|
|
1881
1881
|
id: option.id,
|
|
1882
1882
|
label: typeof option.label === "string" ? option.label : "",
|
|
1883
|
-
value:
|
|
1883
|
+
value: option.id
|
|
1884
1884
|
})) : []
|
|
1885
1885
|
})) : [];
|
|
1886
1886
|
return {
|
|
@@ -3024,14 +3024,9 @@ var ChatMachine = class {
|
|
|
3024
3024
|
if (!curSessionId || !curPendingQuestion) {
|
|
3025
3025
|
return;
|
|
3026
3026
|
}
|
|
3027
|
-
const previousTurns = this.state.messaging.turns;
|
|
3028
3027
|
this._updateMessaging({ loading: true });
|
|
3029
3028
|
this._updateSession({ error: null, errorRetryable: false });
|
|
3030
3029
|
const previousPendingQuestion = curPendingQuestion;
|
|
3031
|
-
this._updateMessaging({
|
|
3032
|
-
pendingQuestion: null,
|
|
3033
|
-
turns: applyTurnLifecycleForPendingQuestion(previousTurns, null)
|
|
3034
|
-
});
|
|
3035
3030
|
try {
|
|
3036
3031
|
const result = await this.dataSource.submitQuestionAnswers(
|
|
3037
3032
|
curSessionId,
|
|
@@ -3042,60 +3037,28 @@ var ChatMachine = class {
|
|
|
3042
3037
|
return;
|
|
3043
3038
|
}
|
|
3044
3039
|
if (result.success) {
|
|
3045
|
-
if (
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
});
|
|
3059
|
-
this._updateSession({
|
|
3060
|
-
error: "Failed to fully refresh session. Showing last known messages.",
|
|
3061
|
-
errorRetryable: true
|
|
3062
|
-
});
|
|
3063
|
-
this._updateMessaging({
|
|
3064
|
-
pendingQuestion: fetchResult.pendingQuestion || null,
|
|
3065
|
-
turns: applyTurnLifecycleForPendingQuestion(
|
|
3066
|
-
previousTurns,
|
|
3067
|
-
fetchResult.pendingQuestion || null
|
|
3068
|
-
)
|
|
3069
|
-
});
|
|
3070
|
-
} else {
|
|
3071
|
-
this._setTurnsFromFetch(fetchResult.turns, fetchResult.pendingQuestion || null);
|
|
3072
|
-
}
|
|
3073
|
-
} else {
|
|
3074
|
-
this._updateSession({ error: "Failed to load updated session", errorRetryable: true });
|
|
3075
|
-
}
|
|
3076
|
-
} catch (fetchErr) {
|
|
3077
|
-
if (this.disposed) {
|
|
3078
|
-
return;
|
|
3079
|
-
}
|
|
3080
|
-
const normalized = normalizeRPCError(fetchErr, "Failed to load updated session");
|
|
3081
|
-
this._updateSession({ error: normalized.userMessage, errorRetryable: true });
|
|
3040
|
+
if (result.data) {
|
|
3041
|
+
this._updateSession({ session: result.data.session });
|
|
3042
|
+
this._setTurnsFromFetch(result.data.turns, result.data.pendingQuestion || null);
|
|
3043
|
+
} else if (curSessionId !== "new") {
|
|
3044
|
+
const fetchResult = await this.dataSource.fetchSession(curSessionId);
|
|
3045
|
+
if (this.disposed) {
|
|
3046
|
+
return;
|
|
3047
|
+
}
|
|
3048
|
+
if (fetchResult) {
|
|
3049
|
+
this._updateSession({ session: fetchResult.session });
|
|
3050
|
+
this._setTurnsFromFetch(fetchResult.turns, fetchResult.pendingQuestion || null);
|
|
3051
|
+
} else {
|
|
3052
|
+
this._updateSession({ error: "Failed to load updated session", errorRetryable: true });
|
|
3082
3053
|
}
|
|
3083
3054
|
}
|
|
3084
3055
|
} else {
|
|
3085
|
-
this._updateMessaging({
|
|
3086
|
-
pendingQuestion: previousPendingQuestion,
|
|
3087
|
-
turns: applyTurnLifecycleForPendingQuestion(previousTurns, previousPendingQuestion)
|
|
3088
|
-
});
|
|
3089
3056
|
this._updateSession({ error: result.error || "Failed to submit answers", errorRetryable: false });
|
|
3090
3057
|
}
|
|
3091
3058
|
} catch (err) {
|
|
3092
3059
|
if (this.disposed) {
|
|
3093
3060
|
return;
|
|
3094
3061
|
}
|
|
3095
|
-
this._updateMessaging({
|
|
3096
|
-
pendingQuestion: previousPendingQuestion,
|
|
3097
|
-
turns: applyTurnLifecycleForPendingQuestion(previousTurns, previousPendingQuestion)
|
|
3098
|
-
});
|
|
3099
3062
|
const normalized = normalizeRPCError(err, "Failed to submit answers");
|
|
3100
3063
|
this._updateSession({ error: normalized.userMessage, errorRetryable: normalized.retryable });
|
|
3101
3064
|
} finally {
|
|
@@ -6529,13 +6492,13 @@ function InlineQuestionForm({ pendingQuestion }) {
|
|
|
6529
6492
|
const currentAnswer = answers[currentQuestion?.id];
|
|
6530
6493
|
const currentOtherText = otherTexts[currentQuestion?.id] || "";
|
|
6531
6494
|
const handleOptionChange = React.useCallback(
|
|
6532
|
-
(
|
|
6495
|
+
(optionID, checked) => {
|
|
6533
6496
|
if (!currentQuestion) {
|
|
6534
6497
|
return;
|
|
6535
6498
|
}
|
|
6536
6499
|
const questionId = currentQuestion.id;
|
|
6537
6500
|
const existingAnswer = answers[questionId] || { options: [] };
|
|
6538
|
-
const isOtherOption =
|
|
6501
|
+
const isOtherOption = optionID === "__other__";
|
|
6539
6502
|
const isMultiSelect2 = currentQuestion.type === "MULTIPLE_CHOICE";
|
|
6540
6503
|
if (isOtherOption) {
|
|
6541
6504
|
setAnswers({
|
|
@@ -6550,14 +6513,14 @@ function InlineQuestionForm({ pendingQuestion }) {
|
|
|
6550
6513
|
let newOptions;
|
|
6551
6514
|
if (isMultiSelect2) {
|
|
6552
6515
|
if (!checked) {
|
|
6553
|
-
newOptions = existingAnswer.options.filter((o) => o !==
|
|
6554
|
-
} else if (existingAnswer.options.includes(
|
|
6516
|
+
newOptions = existingAnswer.options.filter((o) => o !== optionID);
|
|
6517
|
+
} else if (existingAnswer.options.includes(optionID)) {
|
|
6555
6518
|
newOptions = existingAnswer.options;
|
|
6556
6519
|
} else {
|
|
6557
|
-
newOptions = [...existingAnswer.options,
|
|
6520
|
+
newOptions = [...existingAnswer.options, optionID];
|
|
6558
6521
|
}
|
|
6559
6522
|
} else {
|
|
6560
|
-
newOptions = checked ? [
|
|
6523
|
+
newOptions = checked ? [optionID] : [];
|
|
6561
6524
|
}
|
|
6562
6525
|
setAnswers({
|
|
6563
6526
|
...answers,
|
|
@@ -6648,7 +6611,7 @@ function InlineQuestionForm({ pendingQuestion }) {
|
|
|
6648
6611
|
const options = (currentQuestion.options || []).filter((option) => Boolean(option && typeof option.label === "string")).map((option, index) => ({
|
|
6649
6612
|
id: option.id || `${currentQuestion.id}-option-${index}`,
|
|
6650
6613
|
label: option.label,
|
|
6651
|
-
value: option.value || option.
|
|
6614
|
+
value: option.value || option.id || `${currentQuestion.id}-option-${index}`
|
|
6652
6615
|
}));
|
|
6653
6616
|
const isOtherSelected = currentAnswer?.customText !== void 0;
|
|
6654
6617
|
const canProceed = isCurrentAnswerValid();
|
|
@@ -6696,7 +6659,7 @@ function InlineQuestionForm({ pendingQuestion }) {
|
|
|
6696
6659
|
] }),
|
|
6697
6660
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 pb-2 space-y-1.5", children: [
|
|
6698
6661
|
options.map((option) => {
|
|
6699
|
-
const isSelected = currentAnswer?.options.includes(option.
|
|
6662
|
+
const isSelected = currentAnswer?.options.includes(option.id) || false;
|
|
6700
6663
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6701
6664
|
"label",
|
|
6702
6665
|
{
|
|
@@ -6724,7 +6687,7 @@ function InlineQuestionForm({ pendingQuestion }) {
|
|
|
6724
6687
|
name: `question-${currentQuestion.id}`,
|
|
6725
6688
|
value: option.value,
|
|
6726
6689
|
checked: isSelected,
|
|
6727
|
-
onChange: (e) => handleOptionChange(option.
|
|
6690
|
+
onChange: (e) => handleOptionChange(option.id, e.target.checked),
|
|
6728
6691
|
className: "sr-only"
|
|
6729
6692
|
}
|
|
6730
6693
|
),
|
|
@@ -14873,12 +14836,12 @@ function QuestionStep({
|
|
|
14873
14836
|
const data = selectedAnswers[question.id] || { };
|
|
14874
14837
|
setOtherText(data.customText || "");
|
|
14875
14838
|
}, [question.id]);
|
|
14876
|
-
const handleOptionClick = (
|
|
14839
|
+
const handleOptionClick = (optionID) => {
|
|
14877
14840
|
if (isMultiSelect) {
|
|
14878
|
-
const newOptions = selectedOptions.includes(
|
|
14841
|
+
const newOptions = selectedOptions.includes(optionID) ? selectedOptions.filter((a) => a !== optionID) : [...selectedOptions, optionID];
|
|
14879
14842
|
onAnswer({ options: newOptions, customText: otherText || void 0 });
|
|
14880
14843
|
} else {
|
|
14881
|
-
onAnswer({ options: [
|
|
14844
|
+
onAnswer({ options: [optionID], customText: otherText || void 0 });
|
|
14882
14845
|
}
|
|
14883
14846
|
};
|
|
14884
14847
|
const handleOtherTextChange = (text) => {
|
|
@@ -14892,11 +14855,11 @@ function QuestionStep({
|
|
|
14892
14855
|
/* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-2", children: question.text }) }),
|
|
14893
14856
|
isMultiSelect && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-500 italic", children: t("BiChat.Question.SelectMulti") }),
|
|
14894
14857
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-1 gap-3 sm:grid-cols-2", children: (question.options || []).map((option) => {
|
|
14895
|
-
const isSelected = selectedOptions.includes(option.
|
|
14858
|
+
const isSelected = selectedOptions.includes(option.id);
|
|
14896
14859
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
14897
14860
|
"button",
|
|
14898
14861
|
{
|
|
14899
|
-
onClick: () => handleOptionClick(option.
|
|
14862
|
+
onClick: () => handleOptionClick(option.id),
|
|
14900
14863
|
className: `
|
|
14901
14864
|
cursor-pointer relative p-4 text-left border-2 rounded-lg transition-all
|
|
14902
14865
|
${isSelected ? "border-primary-500 bg-white dark:bg-gray-800" : "border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 hover:border-gray-300 dark:hover:border-gray-600"}
|
|
@@ -14964,6 +14927,7 @@ function ConfirmationStep({
|
|
|
14964
14927
|
const answerData = answers[question.id] || { options: [] };
|
|
14965
14928
|
const selectedOptions = answerData.options || [];
|
|
14966
14929
|
const customText = answerData.customText;
|
|
14930
|
+
const optionLabelByID = new Map((question.options || []).map((option) => [option.id, option.label]));
|
|
14967
14931
|
const hasAnswer = selectedOptions.length > 0 || !!customText;
|
|
14968
14932
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
14969
14933
|
"div",
|
|
@@ -14976,7 +14940,7 @@ function ConfirmationStep({
|
|
|
14976
14940
|
"span",
|
|
14977
14941
|
{
|
|
14978
14942
|
className: "inline-flex items-center px-3 py-1 rounded-lg text-sm font-medium border border-primary-500 bg-primary-500/10 text-primary-600 dark:border-primary-400 dark:bg-primary-400/10 dark:text-primary-400",
|
|
14979
|
-
children: option
|
|
14943
|
+
children: optionLabelByID.get(option) || option
|
|
14980
14944
|
},
|
|
14981
14945
|
option
|
|
14982
14946
|
)),
|
|
@@ -16805,10 +16769,11 @@ function sanitizePendingQuestion(rawPendingQuestion, sessionID) {
|
|
|
16805
16769
|
return true;
|
|
16806
16770
|
}).map((option, optionIndex) => {
|
|
16807
16771
|
const label = readString2(option.label);
|
|
16772
|
+
const id = readString2(option.id, `${questionID}-opt-${optionIndex}`);
|
|
16808
16773
|
return {
|
|
16809
|
-
id
|
|
16774
|
+
id,
|
|
16810
16775
|
label,
|
|
16811
|
-
value:
|
|
16776
|
+
value: id
|
|
16812
16777
|
};
|
|
16813
16778
|
}) : [];
|
|
16814
16779
|
return {
|
|
@@ -17786,12 +17751,19 @@ async function submitQuestionAnswers(callRPC, sessionId, questionId, answers) {
|
|
|
17786
17751
|
flatAnswers[qId] = answerData.options.join(", ");
|
|
17787
17752
|
}
|
|
17788
17753
|
}
|
|
17789
|
-
await callRPC("bichat.question.submit", {
|
|
17754
|
+
const result = await callRPC("bichat.question.submit", {
|
|
17790
17755
|
sessionId,
|
|
17791
17756
|
checkpointId: questionId,
|
|
17792
17757
|
answers: flatAnswers
|
|
17793
17758
|
});
|
|
17794
|
-
return {
|
|
17759
|
+
return {
|
|
17760
|
+
success: true,
|
|
17761
|
+
data: {
|
|
17762
|
+
session: toSession(result.session),
|
|
17763
|
+
turns: normalizeTurns(sanitizeConversationTurns(result.turns, sessionId)),
|
|
17764
|
+
pendingQuestion: sanitizePendingQuestion(result.pendingQuestion, sessionId)
|
|
17765
|
+
}
|
|
17766
|
+
};
|
|
17795
17767
|
} catch (err) {
|
|
17796
17768
|
return { success: false, error: err instanceof Error ? err.message : "Unknown error" };
|
|
17797
17769
|
}
|