@paymanai/payman-ask-sdk 1.2.11 → 1.2.12

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.mjs CHANGED
@@ -56,6 +56,7 @@ function ChatInput({
56
56
  value,
57
57
  onChange,
58
58
  onSend,
59
+ onPause,
59
60
  disabled = false,
60
61
  placeholder = "Type your message...",
61
62
  isWaitingForResponse = false,
@@ -87,6 +88,7 @@ function ChatInput({
87
88
  }
88
89
  };
89
90
  const isInputDisabled = disabled || isWaitingForResponse;
91
+ const showPauseButton = isWaitingForResponse && onPause;
90
92
  const showVoiceButton = enableVoice && onVoicePress != null;
91
93
  const isVoiceButtonDisabled = isWaitingForResponse || !voiceAvailable || !isSessionParamsConfigured;
92
94
  const canSend = !isInputDisabled && !!value.trim();
@@ -167,7 +169,22 @@ function ChatInput({
167
169
  ]
168
170
  }
169
171
  ),
170
- /* @__PURE__ */ jsx(
172
+ showPauseButton ? /* @__PURE__ */ jsx(
173
+ "button",
174
+ {
175
+ type: "button",
176
+ onClick: onPause,
177
+ className: cn(
178
+ "flex items-center justify-center",
179
+ "w-8 h-8 rounded-full",
180
+ "payman-chat-input-btn-pause",
181
+ "hover:opacity-90 active:scale-95",
182
+ "transition-all duration-150"
183
+ ),
184
+ "aria-label": "Stop response",
185
+ children: /* @__PURE__ */ jsx(Square, { className: "w-3.5 h-3.5", fill: "currentColor" })
186
+ }
187
+ ) : /* @__PURE__ */ jsx(
171
188
  "button",
172
189
  {
173
190
  type: "button",
@@ -191,6 +208,48 @@ function ChatInput({
191
208
  }
192
209
  );
193
210
  }
211
+
212
+ // src/utils/errorMessages.ts
213
+ var WORKFLOW_FAILED = "WORKFLOW_FAILED";
214
+ var STREAM_NOT_STARTED = "STREAM_NOT_STARTED";
215
+ var HTTP_ERROR_PREFIX = /^HTTP\s+(\d+)\s*:\s*([\s\S]+)$/;
216
+ function isFriendlyWorkflowError(errorDetails) {
217
+ if (!errorDetails) return false;
218
+ return errorDetails === WORKFLOW_FAILED || errorDetails === STREAM_NOT_STARTED || errorDetails.includes(WORKFLOW_FAILED);
219
+ }
220
+ function parseErrorPayload(payload) {
221
+ try {
222
+ const parsed = JSON.parse(payload);
223
+ if (typeof parsed === "string") {
224
+ return { message: parsed.trim() || void 0 };
225
+ }
226
+ if (typeof parsed === "object" && parsed !== null) {
227
+ const record = parsed;
228
+ return {
229
+ status: typeof record.status === "number" ? record.status : void 0,
230
+ message: typeof record.message === "string" && record.message.trim() ? record.message.trim() : void 0
231
+ };
232
+ }
233
+ } catch {
234
+ }
235
+ return {};
236
+ }
237
+ function getConflictErrorMessage(errorDetails) {
238
+ if (!errorDetails) return void 0;
239
+ const trimmedError = errorDetails.trim();
240
+ const httpMatch = trimmedError.match(HTTP_ERROR_PREFIX);
241
+ const httpStatus = httpMatch ? Number(httpMatch[1]) : void 0;
242
+ const rawPayload = (httpMatch ? httpMatch[2] : trimmedError).trim();
243
+ const payload = parseErrorPayload(rawPayload);
244
+ const status = payload.status ?? httpStatus;
245
+ if (status !== 409) {
246
+ return void 0;
247
+ }
248
+ if (payload.message) {
249
+ return payload.message;
250
+ }
251
+ return rawPayload || void 0;
252
+ }
194
253
  function ThinkingBlock({ text }) {
195
254
  const [isOpen, setIsOpen] = useState(false);
196
255
  const hasContent = typeof text === "string" && text.trim().length > 0;
@@ -232,12 +291,6 @@ function ThinkingBlock({ text }) {
232
291
  ] });
233
292
  }
234
293
  var FRIENDLY_ERROR_MESSAGE = "Oops, something went wrong. Please try again.";
235
- var WORKFLOW_FAILED = "WORKFLOW_FAILED";
236
- var STREAM_NOT_STARTED = "STREAM_NOT_STARTED";
237
- function isFriendlyError(errorDetails) {
238
- if (!errorDetails) return false;
239
- return errorDetails === WORKFLOW_FAILED || errorDetails === STREAM_NOT_STARTED || errorDetails.includes(WORKFLOW_FAILED);
240
- }
241
294
  function looksLikeRawError(text) {
242
295
  if (!text || text.length < 10) return false;
243
296
  return text.includes("errorType=") || /failed:\s*\{/.test(text);
@@ -277,7 +330,8 @@ function AgentMessage({
277
330
  const content = rawContent.replace(/\\n/g, "\n");
278
331
  const hasMeaningfulContent = content.length > 0 && !looksLikeRawError(content);
279
332
  const completedWithNoContent = !isStreaming && !isCancelled && content.length === 0 && (message.streamProgress === "completed" || message.streamProgress === "error");
280
- const isError = (isFriendlyError(message.errorDetails) || looksLikeRawError(content)) && !hasMeaningfulContent || completedWithNoContent;
333
+ const conflictErrorMessage = getConflictErrorMessage(message.errorDetails);
334
+ const isError = !!conflictErrorMessage || (isFriendlyWorkflowError(message.errorDetails) || looksLikeRawError(content)) && !hasMeaningfulContent || completedWithNoContent;
281
335
  const activeThinkingText = message.activeThinkingText;
282
336
  const allThinkingText = message.allThinkingText;
283
337
  const currentStep = useMemo(
@@ -474,7 +528,7 @@ function AgentMessage({
474
528
  {
475
529
  remarkPlugins: [remarkGfm],
476
530
  components: markdownComponents(),
477
- children: isError ? FRIENDLY_ERROR_MESSAGE : content || (isStreaming ? "Thinking..." : isCancelled ? "Request was stopped." : "")
531
+ children: isError ? conflictErrorMessage ?? FRIENDLY_ERROR_MESSAGE : content || (isStreaming ? "Thinking..." : isCancelled ? "Request was stopped." : "")
478
532
  }
479
533
  )
480
534
  }
@@ -1550,6 +1604,7 @@ function PaymanChat({
1550
1604
  value: inputValue,
1551
1605
  onChange: setInputValue,
1552
1606
  onSend: handleSend,
1607
+ onPause: cancelStream,
1553
1608
  disabled: isInputDisabled,
1554
1609
  placeholder: isRecording ? "Listening..." : placeholder,
1555
1610
  isWaitingForResponse,