yc-agent-ui 1.2.3 → 1.2.4

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.
Files changed (101) hide show
  1. package/es/components/dialog/index.d.ts +6 -6
  2. package/es/components/dialog/src/index.vue.d.ts +2 -2
  3. package/es/components/dialog-form/index.d.ts +6 -6
  4. package/es/components/dialog-form/src/index.vue.d.ts +6 -6
  5. package/es/components/display-item/index.d.ts +21 -21
  6. package/es/components/display-item/src/index.vue.d.ts +19 -19
  7. package/es/components/drawer-form/index.d.ts +18 -18
  8. package/es/components/drawer-form/src/index.vue.d.ts +10 -10
  9. package/es/components/form/index.d.ts +12 -12
  10. package/es/components/form/src/form-content.vue.d.ts +12 -12
  11. package/es/components/form/src/index.vue.d.ts +12 -12
  12. package/es/components/form-item/index.d.ts +12 -12
  13. package/es/components/form-item/src/index.vue.d.ts +10 -10
  14. package/es/components/page/index.d.ts +258 -258
  15. package/es/components/page/src/index.vue.d.ts +90 -90
  16. package/es/components/render/index.d.ts +1 -1
  17. package/es/components/render/src/index.vue.d.ts +1 -1
  18. package/es/components/search/index.d.ts +78 -78
  19. package/es/components/search/src/index.vue.d.ts +30 -30
  20. package/es/components/table/src/table-column.vue.d.ts +46 -46
  21. package/es/components/yc-ai-chat/index.d.ts +2 -1
  22. package/es/components/yc-ai-chat/src/question-card.vue.d.ts +17 -0
  23. package/es/components/yc-ai-chat/src/question-validation.d.ts +5 -0
  24. package/es/components/yc-ai-chat/src/type.d.ts +51 -0
  25. package/es/components/yc-plus-page/src/index.vue.d.ts +264 -264
  26. package/es/components/yc-select-v2/src/index.vue.d.ts +1 -1
  27. package/es/hooks/usePlusFormReset.d.ts +144 -144
  28. package/es/index.css +11 -11
  29. package/es/index.mjs +1 -0
  30. package/es/packages/components/index.mjs +1 -0
  31. package/es/packages/components/yc-ai-chat/index.mjs +1 -0
  32. package/es/packages/components/yc-ai-chat/src/question-card.vue.mjs +5 -0
  33. package/es/packages/components/yc-ai-chat/src/question-card2.vue.mjs +459 -0
  34. package/es/packages/components/yc-ai-chat/src/question-validation.mjs +77 -0
  35. package/es/version.d.ts +1 -1
  36. package/es/version.mjs +1 -1
  37. package/index.css +1 -1
  38. package/index.js +1579 -1047
  39. package/index.min.js +21 -21
  40. package/index.min.mjs +20 -20
  41. package/index.mjs +1573 -1042
  42. package/lib/components/dialog/index.d.ts +6 -6
  43. package/lib/components/dialog/src/index.vue.d.ts +2 -2
  44. package/lib/components/dialog-form/index.d.ts +6 -6
  45. package/lib/components/dialog-form/src/index.vue.d.ts +6 -6
  46. package/lib/components/display-item/index.d.ts +21 -21
  47. package/lib/components/display-item/src/index.vue.d.ts +19 -19
  48. package/lib/components/drawer-form/index.d.ts +18 -18
  49. package/lib/components/drawer-form/src/index.vue.d.ts +10 -10
  50. package/lib/components/form/index.d.ts +12 -12
  51. package/lib/components/form/src/form-content.vue.d.ts +12 -12
  52. package/lib/components/form/src/index.vue.d.ts +12 -12
  53. package/lib/components/form-item/index.d.ts +12 -12
  54. package/lib/components/form-item/src/index.vue.d.ts +10 -10
  55. package/lib/components/page/index.d.ts +258 -258
  56. package/lib/components/page/src/index.vue.d.ts +90 -90
  57. package/lib/components/render/index.d.ts +1 -1
  58. package/lib/components/render/src/index.vue.d.ts +1 -1
  59. package/lib/components/search/index.d.ts +78 -78
  60. package/lib/components/search/src/index.vue.d.ts +30 -30
  61. package/lib/components/table/src/table-column.vue.d.ts +46 -46
  62. package/lib/components/yc-ai-chat/index.d.ts +2 -1
  63. package/lib/components/yc-ai-chat/src/question-card.vue.d.ts +17 -0
  64. package/lib/components/yc-ai-chat/src/question-validation.d.ts +5 -0
  65. package/lib/components/yc-ai-chat/src/type.d.ts +51 -0
  66. package/lib/components/yc-plus-page/src/index.vue.d.ts +264 -264
  67. package/lib/components/yc-select-v2/src/index.vue.d.ts +1 -1
  68. package/lib/hooks/usePlusFormReset.d.ts +144 -144
  69. package/lib/index.css +10 -10
  70. package/lib/index.js +2 -0
  71. package/lib/packages/components/index.js +2 -0
  72. package/lib/packages/components/yc-ai-chat/index.js +2 -0
  73. package/lib/packages/components/yc-ai-chat/src/question-card.vue.js +9 -0
  74. package/lib/packages/components/yc-ai-chat/src/question-card2.vue.js +463 -0
  75. package/lib/packages/components/yc-ai-chat/src/question-validation.js +81 -0
  76. package/lib/version.d.ts +1 -1
  77. package/lib/version.js +1 -1
  78. package/locale/en.js +1 -1
  79. package/locale/en.min.js +1 -1
  80. package/locale/en.min.mjs +1 -1
  81. package/locale/en.mjs +1 -1
  82. package/locale/ja.js +1 -1
  83. package/locale/ja.min.js +1 -1
  84. package/locale/ja.min.mjs +1 -1
  85. package/locale/ja.mjs +1 -1
  86. package/locale/ko.js +1 -1
  87. package/locale/ko.min.js +1 -1
  88. package/locale/ko.min.mjs +1 -1
  89. package/locale/ko.mjs +1 -1
  90. package/locale/zh-cn.js +1 -1
  91. package/locale/zh-cn.min.js +1 -1
  92. package/locale/zh-cn.min.mjs +1 -1
  93. package/locale/zh-cn.mjs +1 -1
  94. package/locale/zh-tw.js +1 -1
  95. package/locale/zh-tw.min.js +1 -1
  96. package/locale/zh-tw.min.mjs +1 -1
  97. package/locale/zh-tw.mjs +1 -1
  98. package/package.json +1 -1
  99. package/theme-chalk/index.css +1 -1
  100. package/theme-chalk/plus-yc-ai-chat.css +1 -1
  101. package/theme-chalk/src/yc-ai-chat.scss +408 -0
@@ -0,0 +1,459 @@
1
+ import { defineComponent, reactive, watch, computed, openBlock, createElementBlock, normalizeClass, createElementVNode, toDisplayString, Fragment, renderList, createCommentVNode, withDirectives, vModelText } from 'vue';
2
+ import { validChatQuestionRequest, validChatOtherText, validChatAnswersForRequest } from './question-validation.mjs';
3
+
4
+ const _hoisted_1 = ["data-state", "data-testid"];
5
+ const _hoisted_2 = { class: "yc-chat-question-card__header question-card__header" };
6
+ const _hoisted_3 = { class: "yc-chat-question-card__title-wrap" };
7
+ const _hoisted_4 = { class: "yc-chat-question-card__title" };
8
+ const _hoisted_5 = { class: "yc-chat-question-card__questions" };
9
+ const _hoisted_6 = ["disabled"];
10
+ const _hoisted_7 = { class: "yc-chat-question-card__legend" };
11
+ const _hoisted_8 = {
12
+ key: 0,
13
+ class: "yc-chat-question-card__mode-tag"
14
+ };
15
+ const _hoisted_9 = { class: "yc-chat-question-card__options" };
16
+ const _hoisted_10 = ["data-testid", "type", "name", "checked", "onChange"];
17
+ const _hoisted_11 = {
18
+ key: 0,
19
+ viewBox: "0 0 12 12",
20
+ fill: "none"
21
+ };
22
+ const _hoisted_12 = { class: "yc-chat-question-card__option-body" };
23
+ const _hoisted_13 = { class: "yc-chat-question-card__option-label" };
24
+ const _hoisted_14 = {
25
+ key: 0,
26
+ class: "yc-chat-question-card__option-desc"
27
+ };
28
+ const _hoisted_15 = {
29
+ key: 1,
30
+ class: "yc-chat-question-card__event question-card__event"
31
+ };
32
+ const _hoisted_16 = ["data-testid", "type", "name", "checked", "onChange"];
33
+ const _hoisted_17 = {
34
+ key: 0,
35
+ viewBox: "0 0 12 12",
36
+ fill: "none"
37
+ };
38
+ const _hoisted_18 = { class: "yc-chat-question-card__option-body" };
39
+ const _hoisted_19 = { class: "yc-chat-question-card__option-label" };
40
+ const _hoisted_20 = {
41
+ key: 0,
42
+ class: "yc-chat-question-card__textarea-box"
43
+ };
44
+ const _hoisted_21 = ["onUpdate:modelValue", "data-testid"];
45
+ const _hoisted_22 = {
46
+ key: 0,
47
+ class: "yc-chat-question-card__notice question-card__notice"
48
+ };
49
+ const _hoisted_23 = {
50
+ key: 1,
51
+ class: "yc-chat-question-card__notice question-card__notice"
52
+ };
53
+ const _hoisted_24 = {
54
+ key: 2,
55
+ class: "yc-chat-question-card__notice question-card__notice",
56
+ "data-testid": "client-event-not-executed"
57
+ };
58
+ const _hoisted_25 = {
59
+ key: 3,
60
+ class: "yc-chat-question-card__actions question-card__actions"
61
+ };
62
+ const _hoisted_26 = ["disabled"];
63
+ const _hoisted_27 = ["disabled"];
64
+ var _sfc_main = /* @__PURE__ */ defineComponent({
65
+ ...{
66
+ name: "YcChatQuestionCard"
67
+ },
68
+ __name: "question-card",
69
+ props: {
70
+ interaction: {},
71
+ submitting: { type: Boolean, default: false },
72
+ answerEnabled: { type: Boolean, default: true },
73
+ unavailableReason: { default: "" },
74
+ title: { default: "\u9700\u8981\u4F60\u7684\u56DE\u7B54" },
75
+ compact: { type: Boolean, default: false }
76
+ },
77
+ emits: ["answer", "cancel"],
78
+ setup(__props, { emit: __emit }) {
79
+ const props = __props;
80
+ const emit = __emit;
81
+ const selected = reactive({});
82
+ const otherActive = reactive({});
83
+ const otherText = reactive({});
84
+ const statusLabels = {
85
+ preparing: "\u51C6\u5907\u4E2D",
86
+ pending: "\u5F85\u56DE\u7B54",
87
+ answered: "\u5DF2\u56DE\u7B54",
88
+ invalidated: "\u5DF2\u5931\u6548",
89
+ expired: "\u5DF2\u8FC7\u671F",
90
+ cancelled: "\u5DF2\u53D6\u6D88",
91
+ superseded: "\u5DF2\u88AB\u65B0\u6D88\u606F\u66FF\u4EE3"
92
+ };
93
+ watch(
94
+ () => [props.interaction.request.request_id, props.interaction.answers],
95
+ () => {
96
+ var _a, _b;
97
+ for (const question of props.interaction.request.questions) {
98
+ const answer = props.interaction.answers.find(
99
+ (item) => item.question_id === question.id
100
+ );
101
+ selected[question.id] = [...(_a = answer == null ? void 0 : answer.selected_option_ids) != null ? _a : []];
102
+ otherActive[question.id] = (answer == null ? void 0 : answer.other_text) != null;
103
+ otherText[question.id] = (_b = answer == null ? void 0 : answer.other_text) != null ? _b : "";
104
+ }
105
+ },
106
+ { immediate: true, deep: true }
107
+ );
108
+ const requestIsValid = computed(
109
+ () => validChatQuestionRequest(props.interaction.request)
110
+ );
111
+ const canAnswer = computed(
112
+ () => props.answerEnabled && props.interaction.state === "pending" && requestIsValid.value
113
+ );
114
+ const complete = computed(
115
+ () => props.interaction.request.questions.every((question) => {
116
+ var _a, _b, _c;
117
+ if (otherActive[question.id]) {
118
+ return validChatOtherText((_a = otherText[question.id]) != null ? _a : "");
119
+ }
120
+ return ((_c = (_b = selected[question.id]) == null ? void 0 : _b.length) != null ? _c : 0) > 0;
121
+ })
122
+ );
123
+ function optionChecked(question, optionId) {
124
+ var _a, _b;
125
+ return (_b = (_a = selected[question.id]) == null ? void 0 : _a.includes(optionId)) != null ? _b : false;
126
+ }
127
+ function selectOption(question, optionId) {
128
+ var _a;
129
+ if (!canAnswer.value) return;
130
+ otherActive[question.id] = false;
131
+ otherText[question.id] = "";
132
+ if (question.selection_mode === "single") {
133
+ selected[question.id] = [optionId];
134
+ return;
135
+ }
136
+ const current = (_a = selected[question.id]) != null ? _a : [];
137
+ selected[question.id] = current.includes(optionId) ? current.filter((id) => id !== optionId) : [...current, optionId];
138
+ }
139
+ function selectOther(question, enabled) {
140
+ if (!canAnswer.value) return;
141
+ otherActive[question.id] = enabled;
142
+ if (enabled) selected[question.id] = [];
143
+ }
144
+ function eventSummary(option) {
145
+ if (!option.event) return "";
146
+ const text = JSON.stringify(option.event.payload);
147
+ return text.length > 160 ? `${text.slice(0, 157)}...` : text;
148
+ }
149
+ function submit() {
150
+ if (!canAnswer.value || !complete.value || props.submitting) return;
151
+ const answers = props.interaction.request.questions.map((question) => {
152
+ var _a, _b;
153
+ return {
154
+ question_id: question.id,
155
+ selected_option_ids: otherActive[question.id] ? [] : [...(_a = selected[question.id]) != null ? _a : []].sort(),
156
+ other_text: otherActive[question.id] ? ((_b = otherText[question.id]) == null ? void 0 : _b.trim()) || null : null
157
+ };
158
+ });
159
+ if (validChatAnswersForRequest(props.interaction.request, answers)) {
160
+ emit("answer", answers);
161
+ }
162
+ }
163
+ return (_ctx, _cache) => {
164
+ var _a;
165
+ return openBlock(), createElementBlock("section", {
166
+ class: normalizeClass(["yc-chat-question-card question-card", { "is-compact": __props.compact, "is-readonly": !canAnswer.value }]),
167
+ "data-state": __props.interaction.state,
168
+ "data-testid": `question-card-${__props.interaction.request.request_id}`
169
+ }, [
170
+ createElementVNode("header", _hoisted_2, [
171
+ createElementVNode("div", _hoisted_3, [
172
+ _cache[1] || (_cache[1] = createElementVNode(
173
+ "span",
174
+ {
175
+ class: "yc-chat-question-card__badge-icon",
176
+ "aria-hidden": "true"
177
+ },
178
+ [
179
+ createElementVNode("svg", {
180
+ viewBox: "0 0 18 18",
181
+ fill: "none"
182
+ }, [
183
+ createElementVNode("path", {
184
+ d: "M9 2.25C9.42 5.45 10.75 6.78 13.95 7.2C10.75 7.62 9.42 8.95 9 12.15C8.58 8.95 7.25 7.62 4.05 7.2C7.25 6.78 8.58 5.45 9 2.25Z",
185
+ fill: "currentColor"
186
+ }),
187
+ createElementVNode("circle", {
188
+ cx: "14.2",
189
+ cy: "13.2",
190
+ r: "1.35",
191
+ fill: "currentColor",
192
+ opacity: "0.7"
193
+ })
194
+ ])
195
+ ],
196
+ -1
197
+ /* CACHED */
198
+ )),
199
+ createElementVNode(
200
+ "strong",
201
+ _hoisted_4,
202
+ toDisplayString(__props.title),
203
+ 1
204
+ /* TEXT */
205
+ )
206
+ ]),
207
+ createElementVNode(
208
+ "span",
209
+ {
210
+ class: normalizeClass(["yc-chat-question-card__status question-card__status", `is-${__props.interaction.state}`])
211
+ },
212
+ toDisplayString(statusLabels[__props.interaction.state]),
213
+ 3
214
+ /* TEXT, CLASS */
215
+ )
216
+ ]),
217
+ createElementVNode("div", _hoisted_5, [
218
+ (openBlock(true), createElementBlock(
219
+ Fragment,
220
+ null,
221
+ renderList(__props.interaction.request.questions, (question) => {
222
+ return openBlock(), createElementBlock("fieldset", {
223
+ key: question.id,
224
+ class: "yc-chat-question-card__question question-card__question",
225
+ disabled: !canAnswer.value
226
+ }, [
227
+ createElementVNode("legend", _hoisted_7, [
228
+ createElementVNode(
229
+ "span",
230
+ null,
231
+ toDisplayString(question.title),
232
+ 1
233
+ /* TEXT */
234
+ ),
235
+ question.selection_mode === "multiple" ? (openBlock(), createElementBlock("span", _hoisted_8, " \u53EF\u591A\u9009 ")) : createCommentVNode("v-if", true)
236
+ ]),
237
+ createElementVNode("div", _hoisted_9, [
238
+ (openBlock(true), createElementBlock(
239
+ Fragment,
240
+ null,
241
+ renderList(question.options, (option) => {
242
+ return openBlock(), createElementBlock(
243
+ "label",
244
+ {
245
+ key: option.id,
246
+ class: normalizeClass(["yc-chat-question-card__option question-card__option", {
247
+ "is-selected": optionChecked(question, option.id),
248
+ "is-disabled": !canAnswer.value
249
+ }])
250
+ },
251
+ [
252
+ createElementVNode("input", {
253
+ class: "yc-chat-question-card__native-input",
254
+ "data-testid": `option-${question.id}-${option.id}`,
255
+ type: question.selection_mode === "single" ? "radio" : "checkbox",
256
+ name: `question-${__props.interaction.request.request_id}-${question.id}`,
257
+ checked: optionChecked(question, option.id),
258
+ onChange: ($event) => selectOption(question, option.id)
259
+ }, null, 40, _hoisted_10),
260
+ createElementVNode(
261
+ "span",
262
+ {
263
+ class: normalizeClass(["yc-chat-question-card__control", [
264
+ `is-${question.selection_mode}`,
265
+ { "is-checked": optionChecked(question, option.id) }
266
+ ]]),
267
+ "aria-hidden": "true"
268
+ },
269
+ [
270
+ question.selection_mode === "multiple" && optionChecked(question, option.id) ? (openBlock(), createElementBlock("svg", _hoisted_11, [..._cache[2] || (_cache[2] = [
271
+ createElementVNode(
272
+ "path",
273
+ {
274
+ d: "M2.5 6.2L4.9 8.6L9.5 3.6",
275
+ stroke: "currentColor",
276
+ "stroke-width": "1.7",
277
+ "stroke-linecap": "round",
278
+ "stroke-linejoin": "round"
279
+ },
280
+ null,
281
+ -1
282
+ /* CACHED */
283
+ )
284
+ ])])) : createCommentVNode("v-if", true)
285
+ ],
286
+ 2
287
+ /* CLASS */
288
+ ),
289
+ createElementVNode("span", _hoisted_12, [
290
+ createElementVNode(
291
+ "strong",
292
+ _hoisted_13,
293
+ toDisplayString(option.label),
294
+ 1
295
+ /* TEXT */
296
+ ),
297
+ option.description ? (openBlock(), createElementBlock(
298
+ "small",
299
+ _hoisted_14,
300
+ toDisplayString(option.description),
301
+ 1
302
+ /* TEXT */
303
+ )) : createCommentVNode("v-if", true),
304
+ option.event ? (openBlock(), createElementBlock("span", _hoisted_15, [
305
+ createElementVNode(
306
+ "span",
307
+ null,
308
+ toDisplayString(option.event.type) + " \xB7 v" + toDisplayString(option.event.version) + " \xB7 \u53C2\u6570",
309
+ 1
310
+ /* TEXT */
311
+ ),
312
+ createElementVNode(
313
+ "code",
314
+ null,
315
+ toDisplayString(eventSummary(option)),
316
+ 1
317
+ /* TEXT */
318
+ ),
319
+ _cache[3] || (_cache[3] = createElementVNode(
320
+ "em",
321
+ null,
322
+ "Admin \u4E0D\u652F\u6301\u6267\u884C\u5BA2\u6237\u7AEF\u4E8B\u4EF6",
323
+ -1
324
+ /* CACHED */
325
+ ))
326
+ ])) : createCommentVNode("v-if", true)
327
+ ])
328
+ ],
329
+ 2
330
+ /* CLASS */
331
+ );
332
+ }),
333
+ 128
334
+ /* KEYED_FRAGMENT */
335
+ )),
336
+ createElementVNode(
337
+ "div",
338
+ {
339
+ class: normalizeClass(["yc-chat-question-card__other-wrap", { "is-selected": otherActive[question.id] }])
340
+ },
341
+ [
342
+ createElementVNode(
343
+ "label",
344
+ {
345
+ class: normalizeClass(["yc-chat-question-card__option yc-chat-question-card__other question-card__option question-card__other", {
346
+ "is-selected": otherActive[question.id],
347
+ "is-disabled": !canAnswer.value
348
+ }])
349
+ },
350
+ [
351
+ createElementVNode("input", {
352
+ class: "yc-chat-question-card__native-input",
353
+ "data-testid": `other-${question.id}`,
354
+ type: question.selection_mode === "single" ? "radio" : "checkbox",
355
+ name: `question-${__props.interaction.request.request_id}-${question.id}`,
356
+ checked: otherActive[question.id],
357
+ onChange: ($event) => selectOther(question, $event.target.checked)
358
+ }, null, 40, _hoisted_16),
359
+ createElementVNode(
360
+ "span",
361
+ {
362
+ class: normalizeClass(["yc-chat-question-card__control", [
363
+ `is-${question.selection_mode}`,
364
+ { "is-checked": otherActive[question.id] }
365
+ ]]),
366
+ "aria-hidden": "true"
367
+ },
368
+ [
369
+ question.selection_mode === "multiple" && otherActive[question.id] ? (openBlock(), createElementBlock("svg", _hoisted_17, [..._cache[4] || (_cache[4] = [
370
+ createElementVNode(
371
+ "path",
372
+ {
373
+ d: "M2.5 6.2L4.9 8.6L9.5 3.6",
374
+ stroke: "currentColor",
375
+ "stroke-width": "1.7",
376
+ "stroke-linecap": "round",
377
+ "stroke-linejoin": "round"
378
+ },
379
+ null,
380
+ -1
381
+ /* CACHED */
382
+ )
383
+ ])])) : createCommentVNode("v-if", true)
384
+ ],
385
+ 2
386
+ /* CLASS */
387
+ ),
388
+ createElementVNode("span", _hoisted_18, [
389
+ createElementVNode(
390
+ "strong",
391
+ _hoisted_19,
392
+ toDisplayString(question.other.label),
393
+ 1
394
+ /* TEXT */
395
+ )
396
+ ])
397
+ ],
398
+ 2
399
+ /* CLASS */
400
+ ),
401
+ otherActive[question.id] ? (openBlock(), createElementBlock("div", _hoisted_20, [
402
+ withDirectives(createElementVNode("textarea", {
403
+ "onUpdate:modelValue": ($event) => otherText[question.id] = $event,
404
+ class: "yc-chat-question-card__textarea",
405
+ "data-testid": `other-text-${question.id}`,
406
+ rows: "2",
407
+ placeholder: "\u8BF7\u8F93\u5165\u4F60\u7684\u8865\u5145\u8BF4\u660E\u6216\u81EA\u5B9A\u4E49\u7B54\u6848\u2026"
408
+ }, null, 8, _hoisted_21), [
409
+ [vModelText, otherText[question.id]]
410
+ ])
411
+ ])) : createCommentVNode("v-if", true)
412
+ ],
413
+ 2
414
+ /* CLASS */
415
+ )
416
+ ])
417
+ ], 8, _hoisted_6);
418
+ }),
419
+ 128
420
+ /* KEYED_FRAGMENT */
421
+ ))
422
+ ]),
423
+ !requestIsValid.value ? (openBlock(), createElementBlock("p", _hoisted_22, " \u4EA4\u4E92\u8BF7\u6C42\u4E0D\u7B26\u5408\u5BA2\u6237\u7AEF\u4E8B\u4EF6\u7EA6\u675F\uFF0C\u65E0\u6CD5\u63D0\u4EA4\u56DE\u7B54\u3002 ")) : createCommentVNode("v-if", true),
424
+ !__props.answerEnabled && __props.interaction.state === "pending" ? (openBlock(), createElementBlock(
425
+ "p",
426
+ _hoisted_23,
427
+ toDisplayString(__props.unavailableReason || "\u5F53\u524D\u754C\u9762\u6682\u4E0D\u652F\u6301\u63D0\u4EA4\u56DE\u7B54"),
428
+ 1
429
+ /* TEXT */
430
+ )) : createCommentVNode("v-if", true),
431
+ ((_a = __props.interaction.receipt) == null ? void 0 : _a.clientEvent) ? (openBlock(), createElementBlock(
432
+ "p",
433
+ _hoisted_24,
434
+ " \u5BA2\u6237\u7AEF\u4E8B\u4EF6 " + toDisplayString(__props.interaction.receipt.clientEvent.type) + " \u672A\u5728 Admin \u6267\u884C\u3002 ",
435
+ 1
436
+ /* TEXT */
437
+ )) : createCommentVNode("v-if", true),
438
+ __props.interaction.state === "pending" ? (openBlock(), createElementBlock("div", _hoisted_25, [
439
+ createElementVNode("button", {
440
+ type: "button",
441
+ class: "yc-chat-question-card__btn yc-chat-question-card__btn--cancel question-card__cancel",
442
+ "data-testid": "cancel-interaction",
443
+ disabled: !__props.answerEnabled || __props.submitting,
444
+ onClick: _cache[0] || (_cache[0] = ($event) => emit("cancel"))
445
+ }, " \u53D6\u6D88 ", 8, _hoisted_26),
446
+ createElementVNode("button", {
447
+ type: "button",
448
+ class: "yc-chat-question-card__btn yc-chat-question-card__btn--submit",
449
+ "data-testid": "submit-answers",
450
+ disabled: !canAnswer.value || !complete.value || __props.submitting,
451
+ onClick: submit
452
+ }, toDisplayString(__props.submitting ? "\u63D0\u4EA4\u4E2D\u2026" : "\u63D0\u4EA4\u56DE\u7B54"), 9, _hoisted_27)
453
+ ])) : createCommentVNode("v-if", true)
454
+ ], 10, _hoisted_1);
455
+ };
456
+ }
457
+ });
458
+
459
+ export { _sfc_main as default };
@@ -0,0 +1,77 @@
1
+ const ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
2
+ const EVENT_TYPE_PATTERN = /^[A-Za-z0-9._-]{1,100}$/;
3
+ function codePointLength(value) {
4
+ return Array.from(value).length;
5
+ }
6
+ function hasForbiddenControl(value, allowLineBreaks) {
7
+ var _a;
8
+ for (const character of value) {
9
+ const point = (_a = character.codePointAt(0)) != null ? _a : 0;
10
+ if ((point >= 0 && point <= 31 || point >= 127 && point <= 159) && (!allowLineBreaks || point !== 9 && point !== 10 && point !== 13)) {
11
+ return true;
12
+ }
13
+ }
14
+ return false;
15
+ }
16
+ function validText(value, minimum, maximum, allowLineBreaks = false) {
17
+ const length = codePointLength(value);
18
+ return length >= minimum && length <= maximum && value.trim().length > 0 && !hasForbiddenControl(value, allowLineBreaks);
19
+ }
20
+ function validChatOtherText(value) {
21
+ return validText(value, 1, 2e3, true);
22
+ }
23
+ function validChatQuestionRequest(request) {
24
+ var _a, _b, _c;
25
+ if (request.schema !== "interaction.question.v1" || !validText(request.request_id, 1, 256) || !validText(request.tool_call_id, 1, 256) || request.questions.length < 1 || request.questions.length > 5) {
26
+ return false;
27
+ }
28
+ const questionIds = /* @__PURE__ */ new Set();
29
+ let hasEvent = false;
30
+ for (const question of request.questions) {
31
+ if (!ID_PATTERN.test(question.id) || questionIds.has(question.id) || !validText(question.title, 1, 500) || !["single", "multiple"].includes(question.selection_mode) || question.options.length < 1 || question.options.length > 10 || ((_a = question.other) == null ? void 0 : _a.enabled) !== true || ((_b = question.other) == null ? void 0 : _b.label) !== "\u5176\u4ED6") {
32
+ return false;
33
+ }
34
+ questionIds.add(question.id);
35
+ const optionIds = /* @__PURE__ */ new Set();
36
+ const optionLabels = /* @__PURE__ */ new Set();
37
+ for (const option of question.options) {
38
+ const normalizedLabel = option.label.trim();
39
+ if (!ID_PATTERN.test(option.id) || optionIds.has(option.id) || !validText(option.label, 1, 100) || normalizedLabel === "\u5176\u4ED6" || optionLabels.has(normalizedLabel) || option.description !== void 0 && option.description !== "" && !validText(option.description, 1, 300)) {
40
+ return false;
41
+ }
42
+ optionIds.add(option.id);
43
+ optionLabels.add(normalizedLabel);
44
+ if (option.event) {
45
+ hasEvent = true;
46
+ if (!EVENT_TYPE_PATTERN.test(option.event.type) || !Number.isInteger(option.event.version) || option.event.version < 1 || option.event.payload === null || typeof option.event.payload !== "object" || Array.isArray(option.event.payload)) {
47
+ return false;
48
+ }
49
+ }
50
+ }
51
+ }
52
+ if (hasEvent && (request.questions.length !== 1 || ((_c = request.questions[0]) == null ? void 0 : _c.selection_mode) !== "single")) {
53
+ return false;
54
+ }
55
+ return true;
56
+ }
57
+ function validChatAnswersForRequest(request, answers) {
58
+ if (!validChatQuestionRequest(request)) return false;
59
+ if (answers.length !== request.questions.length) return false;
60
+ return request.questions.every((question, index) => {
61
+ const answer = answers[index];
62
+ if (!answer || answer.question_id !== question.id) return false;
63
+ const allowed = new Set(question.options.map((option) => option.id));
64
+ if (new Set(answer.selected_option_ids).size !== answer.selected_option_ids.length || answer.selected_option_ids.some((id) => !allowed.has(id))) {
65
+ return false;
66
+ }
67
+ if (answer.other_text !== null) {
68
+ return answer.selected_option_ids.length === 0 && validChatOtherText(answer.other_text);
69
+ }
70
+ if (question.selection_mode === "single") {
71
+ return answer.selected_option_ids.length === 1;
72
+ }
73
+ return answer.selected_option_ids.length >= 1;
74
+ });
75
+ }
76
+
77
+ export { validChatAnswersForRequest, validChatOtherText, validChatQuestionRequest };
package/es/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "1.2.3";
1
+ export declare const version = "1.2.4";
package/es/version.mjs CHANGED
@@ -1,3 +1,3 @@
1
- const version = "1.2.3";
1
+ const version = "1.2.4";
2
2
 
3
3
  export { version };