@paymanai/payman-ask-sdk 1.2.10 → 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
@@ -208,6 +208,48 @@ function ChatInput({
208
208
  }
209
209
  );
210
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
+ }
211
253
  function ThinkingBlock({ text }) {
212
254
  const [isOpen, setIsOpen] = useState(false);
213
255
  const hasContent = typeof text === "string" && text.trim().length > 0;
@@ -249,12 +291,6 @@ function ThinkingBlock({ text }) {
249
291
  ] });
250
292
  }
251
293
  var FRIENDLY_ERROR_MESSAGE = "Oops, something went wrong. Please try again.";
252
- var WORKFLOW_FAILED = "WORKFLOW_FAILED";
253
- var STREAM_NOT_STARTED = "STREAM_NOT_STARTED";
254
- function isFriendlyError(errorDetails) {
255
- if (!errorDetails) return false;
256
- return errorDetails === WORKFLOW_FAILED || errorDetails === STREAM_NOT_STARTED || errorDetails.includes(WORKFLOW_FAILED);
257
- }
258
294
  function looksLikeRawError(text) {
259
295
  if (!text || text.length < 10) return false;
260
296
  return text.includes("errorType=") || /failed:\s*\{/.test(text);
@@ -294,7 +330,8 @@ function AgentMessage({
294
330
  const content = rawContent.replace(/\\n/g, "\n");
295
331
  const hasMeaningfulContent = content.length > 0 && !looksLikeRawError(content);
296
332
  const completedWithNoContent = !isStreaming && !isCancelled && content.length === 0 && (message.streamProgress === "completed" || message.streamProgress === "error");
297
- 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;
298
335
  const activeThinkingText = message.activeThinkingText;
299
336
  const allThinkingText = message.allThinkingText;
300
337
  const currentStep = useMemo(
@@ -491,7 +528,7 @@ function AgentMessage({
491
528
  {
492
529
  remarkPlugins: [remarkGfm],
493
530
  components: markdownComponents(),
494
- 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." : "")
495
532
  }
496
533
  )
497
534
  }