@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.
@@ -308,7 +308,7 @@ interface QuestionOption {
308
308
  * Answer data for a single question, including predefined options and custom "Other" text.
309
309
  */
310
310
  interface QuestionAnswerData {
311
- /** Selected predefined options (labels) */
311
+ /** Selected predefined options (option IDs) */
312
312
  options: string[];
313
313
  /** Custom text entered when user selects "Other" option */
314
314
  customText?: string;
@@ -573,6 +573,11 @@ interface ChatDataSource {
573
573
  submitQuestionAnswers(sessionId: string, questionId: string, answers: QuestionAnswers): Promise<{
574
574
  success: boolean;
575
575
  error?: string;
576
+ data?: {
577
+ session: Session$1;
578
+ turns: ConversationTurn$1[];
579
+ pendingQuestion?: PendingQuestion$1 | null;
580
+ };
576
581
  }>;
577
582
  rejectPendingQuestion(sessionId: string): Promise<{
578
583
  success: boolean;
@@ -3558,6 +3563,11 @@ declare class HttpDataSource implements ChatDataSource {
3558
3563
  submitQuestionAnswers(sessionId: string, questionId: string, answers: QuestionAnswers): Promise<{
3559
3564
  success: boolean;
3560
3565
  error?: string;
3566
+ data?: {
3567
+ session: Session$1;
3568
+ turns: ConversationTurn$1[];
3569
+ pendingQuestion?: PendingQuestion$1 | null;
3570
+ };
3561
3571
  }>;
3562
3572
  rejectPendingQuestion(sessionId: string): Promise<{
3563
3573
  success: boolean;
@@ -308,7 +308,7 @@ interface QuestionOption {
308
308
  * Answer data for a single question, including predefined options and custom "Other" text.
309
309
  */
310
310
  interface QuestionAnswerData {
311
- /** Selected predefined options (labels) */
311
+ /** Selected predefined options (option IDs) */
312
312
  options: string[];
313
313
  /** Custom text entered when user selects "Other" option */
314
314
  customText?: string;
@@ -573,6 +573,11 @@ interface ChatDataSource {
573
573
  submitQuestionAnswers(sessionId: string, questionId: string, answers: QuestionAnswers): Promise<{
574
574
  success: boolean;
575
575
  error?: string;
576
+ data?: {
577
+ session: Session$1;
578
+ turns: ConversationTurn$1[];
579
+ pendingQuestion?: PendingQuestion$1 | null;
580
+ };
576
581
  }>;
577
582
  rejectPendingQuestion(sessionId: string): Promise<{
578
583
  success: boolean;
@@ -3558,6 +3563,11 @@ declare class HttpDataSource implements ChatDataSource {
3558
3563
  submitQuestionAnswers(sessionId: string, questionId: string, answers: QuestionAnswers): Promise<{
3559
3564
  success: boolean;
3560
3565
  error?: string;
3566
+ data?: {
3567
+ session: Session$1;
3568
+ turns: ConversationTurn$1[];
3569
+ pendingQuestion?: PendingQuestion$1 | null;
3570
+ };
3561
3571
  }>;
3562
3572
  rejectPendingQuestion(sessionId: string): Promise<{
3563
3573
  success: boolean;
@@ -1868,7 +1868,7 @@ function pendingQuestionFromInterrupt(interrupt, fallbackTurnId) {
1868
1868
  options: Array.isArray(question.options) ? question.options.filter((option) => !!option && typeof option.id === "string").map((option) => ({
1869
1869
  id: option.id,
1870
1870
  label: typeof option.label === "string" ? option.label : "",
1871
- value: typeof option.label === "string" ? option.label : ""
1871
+ value: option.id
1872
1872
  })) : []
1873
1873
  })) : [];
1874
1874
  return {
@@ -3012,14 +3012,9 @@ var ChatMachine = class {
3012
3012
  if (!curSessionId || !curPendingQuestion) {
3013
3013
  return;
3014
3014
  }
3015
- const previousTurns = this.state.messaging.turns;
3016
3015
  this._updateMessaging({ loading: true });
3017
3016
  this._updateSession({ error: null, errorRetryable: false });
3018
3017
  const previousPendingQuestion = curPendingQuestion;
3019
- this._updateMessaging({
3020
- pendingQuestion: null,
3021
- turns: applyTurnLifecycleForPendingQuestion(previousTurns, null)
3022
- });
3023
3018
  try {
3024
3019
  const result = await this.dataSource.submitQuestionAnswers(
3025
3020
  curSessionId,
@@ -3030,60 +3025,28 @@ var ChatMachine = class {
3030
3025
  return;
3031
3026
  }
3032
3027
  if (result.success) {
3033
- if (curSessionId !== "new") {
3034
- try {
3035
- const fetchResult = await this.dataSource.fetchSession(curSessionId);
3036
- if (this.disposed) {
3037
- return;
3038
- }
3039
- if (fetchResult) {
3040
- this._updateSession({ session: fetchResult.session });
3041
- const hasMalformedRefresh = previousTurns.length > 0 && Array.isArray(fetchResult.turns) && fetchResult.turns.length === 0;
3042
- if (hasMalformedRefresh) {
3043
- console.warn("[ChatMachine] Preserving previous turns due to empty post-HITL refetch payload", {
3044
- sessionId: curSessionId,
3045
- previousTurnCount: previousTurns.length
3046
- });
3047
- this._updateSession({
3048
- error: "Failed to fully refresh session. Showing last known messages.",
3049
- errorRetryable: true
3050
- });
3051
- this._updateMessaging({
3052
- pendingQuestion: fetchResult.pendingQuestion || null,
3053
- turns: applyTurnLifecycleForPendingQuestion(
3054
- previousTurns,
3055
- fetchResult.pendingQuestion || null
3056
- )
3057
- });
3058
- } else {
3059
- this._setTurnsFromFetch(fetchResult.turns, fetchResult.pendingQuestion || null);
3060
- }
3061
- } else {
3062
- this._updateSession({ error: "Failed to load updated session", errorRetryable: true });
3063
- }
3064
- } catch (fetchErr) {
3065
- if (this.disposed) {
3066
- return;
3067
- }
3068
- const normalized = normalizeRPCError(fetchErr, "Failed to load updated session");
3069
- this._updateSession({ error: normalized.userMessage, errorRetryable: true });
3028
+ if (result.data) {
3029
+ this._updateSession({ session: result.data.session });
3030
+ this._setTurnsFromFetch(result.data.turns, result.data.pendingQuestion || null);
3031
+ } else if (curSessionId !== "new") {
3032
+ const fetchResult = await this.dataSource.fetchSession(curSessionId);
3033
+ if (this.disposed) {
3034
+ return;
3035
+ }
3036
+ if (fetchResult) {
3037
+ this._updateSession({ session: fetchResult.session });
3038
+ this._setTurnsFromFetch(fetchResult.turns, fetchResult.pendingQuestion || null);
3039
+ } else {
3040
+ this._updateSession({ error: "Failed to load updated session", errorRetryable: true });
3070
3041
  }
3071
3042
  }
3072
3043
  } else {
3073
- this._updateMessaging({
3074
- pendingQuestion: previousPendingQuestion,
3075
- turns: applyTurnLifecycleForPendingQuestion(previousTurns, previousPendingQuestion)
3076
- });
3077
3044
  this._updateSession({ error: result.error || "Failed to submit answers", errorRetryable: false });
3078
3045
  }
3079
3046
  } catch (err) {
3080
3047
  if (this.disposed) {
3081
3048
  return;
3082
3049
  }
3083
- this._updateMessaging({
3084
- pendingQuestion: previousPendingQuestion,
3085
- turns: applyTurnLifecycleForPendingQuestion(previousTurns, previousPendingQuestion)
3086
- });
3087
3050
  const normalized = normalizeRPCError(err, "Failed to submit answers");
3088
3051
  this._updateSession({ error: normalized.userMessage, errorRetryable: normalized.retryable });
3089
3052
  } finally {
@@ -6517,13 +6480,13 @@ function InlineQuestionForm({ pendingQuestion }) {
6517
6480
  const currentAnswer = answers[currentQuestion?.id];
6518
6481
  const currentOtherText = otherTexts[currentQuestion?.id] || "";
6519
6482
  const handleOptionChange = useCallback(
6520
- (optionLabel, checked) => {
6483
+ (optionID, checked) => {
6521
6484
  if (!currentQuestion) {
6522
6485
  return;
6523
6486
  }
6524
6487
  const questionId = currentQuestion.id;
6525
6488
  const existingAnswer = answers[questionId] || { options: [] };
6526
- const isOtherOption = optionLabel === "__other__";
6489
+ const isOtherOption = optionID === "__other__";
6527
6490
  const isMultiSelect2 = currentQuestion.type === "MULTIPLE_CHOICE";
6528
6491
  if (isOtherOption) {
6529
6492
  setAnswers({
@@ -6538,14 +6501,14 @@ function InlineQuestionForm({ pendingQuestion }) {
6538
6501
  let newOptions;
6539
6502
  if (isMultiSelect2) {
6540
6503
  if (!checked) {
6541
- newOptions = existingAnswer.options.filter((o) => o !== optionLabel);
6542
- } else if (existingAnswer.options.includes(optionLabel)) {
6504
+ newOptions = existingAnswer.options.filter((o) => o !== optionID);
6505
+ } else if (existingAnswer.options.includes(optionID)) {
6543
6506
  newOptions = existingAnswer.options;
6544
6507
  } else {
6545
- newOptions = [...existingAnswer.options, optionLabel];
6508
+ newOptions = [...existingAnswer.options, optionID];
6546
6509
  }
6547
6510
  } else {
6548
- newOptions = checked ? [optionLabel] : [];
6511
+ newOptions = checked ? [optionID] : [];
6549
6512
  }
6550
6513
  setAnswers({
6551
6514
  ...answers,
@@ -6636,7 +6599,7 @@ function InlineQuestionForm({ pendingQuestion }) {
6636
6599
  const options = (currentQuestion.options || []).filter((option) => Boolean(option && typeof option.label === "string")).map((option, index) => ({
6637
6600
  id: option.id || `${currentQuestion.id}-option-${index}`,
6638
6601
  label: option.label,
6639
- value: option.value || option.label
6602
+ value: option.value || option.id || `${currentQuestion.id}-option-${index}`
6640
6603
  }));
6641
6604
  const isOtherSelected = currentAnswer?.customText !== void 0;
6642
6605
  const canProceed = isCurrentAnswerValid();
@@ -6684,7 +6647,7 @@ function InlineQuestionForm({ pendingQuestion }) {
6684
6647
  ] }),
6685
6648
  /* @__PURE__ */ jsxs("div", { className: "px-4 pb-2 space-y-1.5", children: [
6686
6649
  options.map((option) => {
6687
- const isSelected = currentAnswer?.options.includes(option.label) || false;
6650
+ const isSelected = currentAnswer?.options.includes(option.id) || false;
6688
6651
  return /* @__PURE__ */ jsxs(
6689
6652
  "label",
6690
6653
  {
@@ -6712,7 +6675,7 @@ function InlineQuestionForm({ pendingQuestion }) {
6712
6675
  name: `question-${currentQuestion.id}`,
6713
6676
  value: option.value,
6714
6677
  checked: isSelected,
6715
- onChange: (e) => handleOptionChange(option.label, e.target.checked),
6678
+ onChange: (e) => handleOptionChange(option.id, e.target.checked),
6716
6679
  className: "sr-only"
6717
6680
  }
6718
6681
  ),
@@ -14861,12 +14824,12 @@ function QuestionStep({
14861
14824
  const data = selectedAnswers[question.id] || { };
14862
14825
  setOtherText(data.customText || "");
14863
14826
  }, [question.id]);
14864
- const handleOptionClick = (optionLabel) => {
14827
+ const handleOptionClick = (optionID) => {
14865
14828
  if (isMultiSelect) {
14866
- const newOptions = selectedOptions.includes(optionLabel) ? selectedOptions.filter((a) => a !== optionLabel) : [...selectedOptions, optionLabel];
14829
+ const newOptions = selectedOptions.includes(optionID) ? selectedOptions.filter((a) => a !== optionID) : [...selectedOptions, optionID];
14867
14830
  onAnswer({ options: newOptions, customText: otherText || void 0 });
14868
14831
  } else {
14869
- onAnswer({ options: [optionLabel], customText: otherText || void 0 });
14832
+ onAnswer({ options: [optionID], customText: otherText || void 0 });
14870
14833
  }
14871
14834
  };
14872
14835
  const handleOtherTextChange = (text) => {
@@ -14880,11 +14843,11 @@ function QuestionStep({
14880
14843
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-2", children: question.text }) }),
14881
14844
  isMultiSelect && /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-500 dark:text-gray-500 italic", children: t("BiChat.Question.SelectMulti") }),
14882
14845
  /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 gap-3 sm:grid-cols-2", children: (question.options || []).map((option) => {
14883
- const isSelected = selectedOptions.includes(option.label);
14846
+ const isSelected = selectedOptions.includes(option.id);
14884
14847
  return /* @__PURE__ */ jsx(
14885
14848
  "button",
14886
14849
  {
14887
- onClick: () => handleOptionClick(option.label),
14850
+ onClick: () => handleOptionClick(option.id),
14888
14851
  className: `
14889
14852
  cursor-pointer relative p-4 text-left border-2 rounded-lg transition-all
14890
14853
  ${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"}
@@ -14952,6 +14915,7 @@ function ConfirmationStep({
14952
14915
  const answerData = answers[question.id] || { options: [] };
14953
14916
  const selectedOptions = answerData.options || [];
14954
14917
  const customText = answerData.customText;
14918
+ const optionLabelByID = new Map((question.options || []).map((option) => [option.id, option.label]));
14955
14919
  const hasAnswer = selectedOptions.length > 0 || !!customText;
14956
14920
  return /* @__PURE__ */ jsxs(
14957
14921
  "div",
@@ -14964,7 +14928,7 @@ function ConfirmationStep({
14964
14928
  "span",
14965
14929
  {
14966
14930
  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",
14967
- children: option
14931
+ children: optionLabelByID.get(option) || option
14968
14932
  },
14969
14933
  option
14970
14934
  )),
@@ -16793,10 +16757,11 @@ function sanitizePendingQuestion(rawPendingQuestion, sessionID) {
16793
16757
  return true;
16794
16758
  }).map((option, optionIndex) => {
16795
16759
  const label = readString2(option.label);
16760
+ const id = readString2(option.id, `${questionID}-opt-${optionIndex}`);
16796
16761
  return {
16797
- id: readString2(option.id, `${questionID}-opt-${optionIndex}`),
16762
+ id,
16798
16763
  label,
16799
- value: label
16764
+ value: id
16800
16765
  };
16801
16766
  }) : [];
16802
16767
  return {
@@ -17774,12 +17739,19 @@ async function submitQuestionAnswers(callRPC, sessionId, questionId, answers) {
17774
17739
  flatAnswers[qId] = answerData.options.join(", ");
17775
17740
  }
17776
17741
  }
17777
- await callRPC("bichat.question.submit", {
17742
+ const result = await callRPC("bichat.question.submit", {
17778
17743
  sessionId,
17779
17744
  checkpointId: questionId,
17780
17745
  answers: flatAnswers
17781
17746
  });
17782
- return { success: true };
17747
+ return {
17748
+ success: true,
17749
+ data: {
17750
+ session: toSession(result.session),
17751
+ turns: normalizeTurns(sanitizeConversationTurns(result.turns, sessionId)),
17752
+ pendingQuestion: sanitizePendingQuestion(result.pendingQuestion, sessionId)
17753
+ }
17754
+ };
17783
17755
  } catch (err) {
17784
17756
  return { success: false, error: err instanceof Error ? err.message : "Unknown error" };
17785
17757
  }