@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.d.mts CHANGED
@@ -31,7 +31,7 @@ type MessageDisplay = {
31
31
  content: string;
32
32
  timestamp: string;
33
33
  isError?: boolean;
34
- /** When set to "WORKFLOW_FAILED" or "STREAM_NOT_STARTED", the UI shows the friendly "Oops, something went wrong" message. Other errors (e.g. subintent failures) do not show it. */
34
+ /** "WORKFLOW_FAILED" and "STREAM_NOT_STARTED" show the friendly fallback; HTTP 409 conflicts render the backend message from the error payload. */
35
35
  errorDetails?: string;
36
36
  chunks?: ChunkDisplay[];
37
37
  tracingData?: unknown;
@@ -339,7 +339,7 @@ type StreamingMessageProps = {
339
339
  currentMessage?: string;
340
340
  /** Stream progress */
341
341
  streamProgress: StreamProgress;
342
- /** When set to "WORKFLOW_FAILED" or "STREAM_NOT_STARTED", the UI shows the friendly error message. Other errors do not. */
342
+ /** "WORKFLOW_FAILED" and "STREAM_NOT_STARTED" show the friendly fallback; HTTP 409 conflicts render the backend message from the error payload. */
343
343
  error?: string;
344
344
  /** Streaming steps */
345
345
  steps?: StreamingStep[];
package/dist/index.d.ts CHANGED
@@ -31,7 +31,7 @@ type MessageDisplay = {
31
31
  content: string;
32
32
  timestamp: string;
33
33
  isError?: boolean;
34
- /** When set to "WORKFLOW_FAILED" or "STREAM_NOT_STARTED", the UI shows the friendly "Oops, something went wrong" message. Other errors (e.g. subintent failures) do not show it. */
34
+ /** "WORKFLOW_FAILED" and "STREAM_NOT_STARTED" show the friendly fallback; HTTP 409 conflicts render the backend message from the error payload. */
35
35
  errorDetails?: string;
36
36
  chunks?: ChunkDisplay[];
37
37
  tracingData?: unknown;
@@ -339,7 +339,7 @@ type StreamingMessageProps = {
339
339
  currentMessage?: string;
340
340
  /** Stream progress */
341
341
  streamProgress: StreamProgress;
342
- /** When set to "WORKFLOW_FAILED" or "STREAM_NOT_STARTED", the UI shows the friendly error message. Other errors do not. */
342
+ /** "WORKFLOW_FAILED" and "STREAM_NOT_STARTED" show the friendly fallback; HTTP 409 conflicts render the backend message from the error payload. */
343
343
  error?: string;
344
344
  /** Streaming steps */
345
345
  steps?: StreamingStep[];
package/dist/index.js CHANGED
@@ -214,6 +214,48 @@ function ChatInput({
214
214
  }
215
215
  );
216
216
  }
217
+
218
+ // src/utils/errorMessages.ts
219
+ var WORKFLOW_FAILED = "WORKFLOW_FAILED";
220
+ var STREAM_NOT_STARTED = "STREAM_NOT_STARTED";
221
+ var HTTP_ERROR_PREFIX = /^HTTP\s+(\d+)\s*:\s*([\s\S]+)$/;
222
+ function isFriendlyWorkflowError(errorDetails) {
223
+ if (!errorDetails) return false;
224
+ return errorDetails === WORKFLOW_FAILED || errorDetails === STREAM_NOT_STARTED || errorDetails.includes(WORKFLOW_FAILED);
225
+ }
226
+ function parseErrorPayload(payload) {
227
+ try {
228
+ const parsed = JSON.parse(payload);
229
+ if (typeof parsed === "string") {
230
+ return { message: parsed.trim() || void 0 };
231
+ }
232
+ if (typeof parsed === "object" && parsed !== null) {
233
+ const record = parsed;
234
+ return {
235
+ status: typeof record.status === "number" ? record.status : void 0,
236
+ message: typeof record.message === "string" && record.message.trim() ? record.message.trim() : void 0
237
+ };
238
+ }
239
+ } catch {
240
+ }
241
+ return {};
242
+ }
243
+ function getConflictErrorMessage(errorDetails) {
244
+ if (!errorDetails) return void 0;
245
+ const trimmedError = errorDetails.trim();
246
+ const httpMatch = trimmedError.match(HTTP_ERROR_PREFIX);
247
+ const httpStatus = httpMatch ? Number(httpMatch[1]) : void 0;
248
+ const rawPayload = (httpMatch ? httpMatch[2] : trimmedError).trim();
249
+ const payload = parseErrorPayload(rawPayload);
250
+ const status = payload.status ?? httpStatus;
251
+ if (status !== 409) {
252
+ return void 0;
253
+ }
254
+ if (payload.message) {
255
+ return payload.message;
256
+ }
257
+ return rawPayload || void 0;
258
+ }
217
259
  function ThinkingBlock({ text }) {
218
260
  const [isOpen, setIsOpen] = react.useState(false);
219
261
  const hasContent = typeof text === "string" && text.trim().length > 0;
@@ -255,12 +297,6 @@ function ThinkingBlock({ text }) {
255
297
  ] });
256
298
  }
257
299
  var FRIENDLY_ERROR_MESSAGE = "Oops, something went wrong. Please try again.";
258
- var WORKFLOW_FAILED = "WORKFLOW_FAILED";
259
- var STREAM_NOT_STARTED = "STREAM_NOT_STARTED";
260
- function isFriendlyError(errorDetails) {
261
- if (!errorDetails) return false;
262
- return errorDetails === WORKFLOW_FAILED || errorDetails === STREAM_NOT_STARTED || errorDetails.includes(WORKFLOW_FAILED);
263
- }
264
300
  function looksLikeRawError(text) {
265
301
  if (!text || text.length < 10) return false;
266
302
  return text.includes("errorType=") || /failed:\s*\{/.test(text);
@@ -300,7 +336,8 @@ function AgentMessage({
300
336
  const content = rawContent.replace(/\\n/g, "\n");
301
337
  const hasMeaningfulContent = content.length > 0 && !looksLikeRawError(content);
302
338
  const completedWithNoContent = !isStreaming && !isCancelled && content.length === 0 && (message.streamProgress === "completed" || message.streamProgress === "error");
303
- const isError = (isFriendlyError(message.errorDetails) || looksLikeRawError(content)) && !hasMeaningfulContent || completedWithNoContent;
339
+ const conflictErrorMessage = getConflictErrorMessage(message.errorDetails);
340
+ const isError = !!conflictErrorMessage || (isFriendlyWorkflowError(message.errorDetails) || looksLikeRawError(content)) && !hasMeaningfulContent || completedWithNoContent;
304
341
  const activeThinkingText = message.activeThinkingText;
305
342
  const allThinkingText = message.allThinkingText;
306
343
  const currentStep = react.useMemo(
@@ -497,7 +534,7 @@ function AgentMessage({
497
534
  {
498
535
  remarkPlugins: [remarkGfm__default.default],
499
536
  components: markdownComponents(),
500
- children: isError ? FRIENDLY_ERROR_MESSAGE : content || (isStreaming ? "Thinking..." : isCancelled ? "Request was stopped." : "")
537
+ children: isError ? conflictErrorMessage ?? FRIENDLY_ERROR_MESSAGE : content || (isStreaming ? "Thinking..." : isCancelled ? "Request was stopped." : "")
501
538
  }
502
539
  )
503
540
  }