@paymanai/payman-ask-sdk 1.2.19 → 1.2.20

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
@@ -49,6 +49,8 @@ type MessageDisplay = {
49
49
  activeThinkingText?: string;
50
50
  /** All thinking accumulated across blocks (for post-stream display) */
51
51
  allThinkingText?: string;
52
+ /** True while RAG image URLs are being resolved after the final response is shown */
53
+ isResolvingImages?: boolean;
52
54
  };
53
55
  type SessionParams = {
54
56
  id?: string;
@@ -64,6 +66,8 @@ type APIConfig = {
64
66
  headers?: Record<string, string>;
65
67
  /** API endpoint for streaming (default: /api/workflows/ask/stream) */
66
68
  streamEndpoint?: string;
69
+ /** API endpoint for resolving RAG image URLs (default: /api/playground/ask/resolve-image-urls) */
70
+ resolveImagesEndpoint?: string;
67
71
  };
68
72
  type ChatConfig = {
69
73
  /** API configuration - required for the library to make calls */
package/dist/index.d.ts CHANGED
@@ -49,6 +49,8 @@ type MessageDisplay = {
49
49
  activeThinkingText?: string;
50
50
  /** All thinking accumulated across blocks (for post-stream display) */
51
51
  allThinkingText?: string;
52
+ /** True while RAG image URLs are being resolved after the final response is shown */
53
+ isResolvingImages?: boolean;
52
54
  };
53
55
  type SessionParams = {
54
56
  id?: string;
@@ -64,6 +66,8 @@ type APIConfig = {
64
66
  headers?: Record<string, string>;
65
67
  /** API endpoint for streaming (default: /api/workflows/ask/stream) */
66
68
  streamEndpoint?: string;
69
+ /** API endpoint for resolving RAG image URLs (default: /api/playground/ask/resolve-image-urls) */
70
+ resolveImagesEndpoint?: string;
67
71
  };
68
72
  type ChatConfig = {
69
73
  /** API configuration - required for the library to make calls */
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ var lucideReact = require('lucide-react');
9
9
  var jsxRuntime = require('react/jsx-runtime');
10
10
  var ReactMarkdown = require('react-markdown');
11
11
  var remarkGfm = require('remark-gfm');
12
+ var reactDom = require('react-dom');
12
13
 
13
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
15
 
@@ -321,6 +322,256 @@ function ChatInput({
321
322
  }
322
323
  );
323
324
  }
325
+ function ImageLightbox({
326
+ src,
327
+ alt = "",
328
+ onClose
329
+ }) {
330
+ const [isMounted, setIsMounted] = react.useState(false);
331
+ const [isImageLoaded, setIsImageLoaded] = react.useState(false);
332
+ const overlayStyle = {
333
+ position: "fixed",
334
+ inset: 0,
335
+ zIndex: 2147483647,
336
+ display: "flex",
337
+ alignItems: "center",
338
+ justifyContent: "center",
339
+ padding: 16,
340
+ background: "rgba(2, 6, 23, 0.92)",
341
+ isolation: "isolate"
342
+ };
343
+ const frameStyle = {
344
+ position: "relative",
345
+ width: "min(92vw, 1280px)",
346
+ height: "min(88vh, 920px)",
347
+ display: "flex",
348
+ alignItems: "center",
349
+ justifyContent: "center",
350
+ overflow: "hidden"
351
+ };
352
+ react.useEffect(() => {
353
+ setIsMounted(true);
354
+ return () => setIsMounted(false);
355
+ }, []);
356
+ react.useEffect(() => {
357
+ setIsImageLoaded(false);
358
+ }, [src]);
359
+ react.useEffect(() => {
360
+ if (typeof document === "undefined") return;
361
+ const previousOverflow = document.body.style.overflow;
362
+ document.body.style.overflow = "hidden";
363
+ return () => {
364
+ document.body.style.overflow = previousOverflow;
365
+ };
366
+ }, []);
367
+ react.useEffect(() => {
368
+ if (typeof document === "undefined") return;
369
+ const handleKeyDown = (event) => {
370
+ if (event.key === "Escape") {
371
+ onClose();
372
+ }
373
+ };
374
+ document.addEventListener("keydown", handleKeyDown);
375
+ return () => {
376
+ document.removeEventListener("keydown", handleKeyDown);
377
+ };
378
+ }, [onClose]);
379
+ if (!isMounted || typeof document === "undefined") {
380
+ return null;
381
+ }
382
+ return reactDom.createPortal(
383
+ /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: /* @__PURE__ */ jsxRuntime.jsxs(
384
+ framerMotion.motion.div,
385
+ {
386
+ style: overlayStyle,
387
+ initial: { opacity: 0 },
388
+ animate: { opacity: 1 },
389
+ exit: { opacity: 0 },
390
+ transition: { duration: 0.18 },
391
+ onClick: onClose,
392
+ children: [
393
+ /* @__PURE__ */ jsxRuntime.jsx(
394
+ "button",
395
+ {
396
+ type: "button",
397
+ onClick: onClose,
398
+ className: "absolute top-4 right-4 z-[1] flex h-9 w-9 items-center justify-center rounded-full bg-black/60 text-white/90 transition-colors hover:bg-black/75",
399
+ "aria-label": "Close",
400
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "h-4 w-4" })
401
+ }
402
+ ),
403
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: frameStyle, onClick: (event) => event.stopPropagation(), children: [
404
+ !isImageLoaded ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "absolute inset-0 flex flex-col items-center justify-center gap-2", children: [
405
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-5 w-5 animate-spin text-white/80" }),
406
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium text-white/90", children: "Loading image" }),
407
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-white/60", children: "Reference image" })
408
+ ] }) : null,
409
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-full w-full items-center justify-center p-3 sm:p-4", children: /* @__PURE__ */ jsxRuntime.jsx(
410
+ "img",
411
+ {
412
+ src,
413
+ alt,
414
+ draggable: false,
415
+ onLoad: () => setIsImageLoaded(true),
416
+ className: `block h-full w-full rounded-xl object-contain shadow-2xl transition-opacity duration-200 ${isImageLoaded ? "opacity-100" : "opacity-0"}`
417
+ }
418
+ ) })
419
+ ] })
420
+ ]
421
+ }
422
+ ) }),
423
+ document.body
424
+ );
425
+ }
426
+ var RAG_IMAGE_PATH_REGEX = /^(?:https?:\/\/[^/\s]+)?\/api\/rag\/chunks\/[^"'\s]+\/image(?:[?#][^"'\s]*)?$/;
427
+ function isUnresolvedRagImageSource(src) {
428
+ return RAG_IMAGE_PATH_REGEX.test(src);
429
+ }
430
+ function LoadingImageCard({
431
+ label,
432
+ description
433
+ }) {
434
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "my-3 flex min-h-36 w-full flex-col items-center justify-center gap-2 px-4 py-5 text-center", children: [
435
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-5 w-5 animate-spin text-slate-500 dark:text-slate-300" }),
436
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-slate-600 dark:text-slate-200", children: label }),
437
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-[11px] leading-relaxed text-slate-500/90 dark:text-slate-300/80", children: description })
438
+ ] });
439
+ }
440
+ function BrokenImageCard({ alt }) {
441
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "my-3 flex min-h-44 w-full flex-col items-center justify-center gap-2 rounded-xl border border-dashed border-red-200 bg-red-50/60 px-4 py-5 text-center dark:border-red-900/40 dark:bg-red-950/20", children: [
442
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-red-600 dark:text-red-300", children: "Unable to load image" }),
443
+ alt ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "max-w-sm text-[11px] leading-relaxed text-red-500/80 dark:text-red-200/80", children: alt }) : null
444
+ ] });
445
+ }
446
+ function MarkdownImage({
447
+ src,
448
+ alt,
449
+ isResolving = false
450
+ }) {
451
+ const imageFrameStyle = {
452
+ width: "min(100%, 32rem)",
453
+ maxWidth: "100%"
454
+ };
455
+ const imageStyle = {
456
+ display: "block",
457
+ width: "100%",
458
+ height: "auto",
459
+ maxWidth: "100%",
460
+ maxHeight: "18rem",
461
+ objectFit: "contain"
462
+ };
463
+ const [isLoaded, setIsLoaded] = react.useState(false);
464
+ const [hasError, setHasError] = react.useState(false);
465
+ const [isLightboxOpen, setIsLightboxOpen] = react.useState(false);
466
+ const isUnresolvedRagImage = react.useMemo(
467
+ () => src ? isUnresolvedRagImageSource(src) : false,
468
+ [src]
469
+ );
470
+ const isResolvingRagImage = isResolving && isUnresolvedRagImage;
471
+ react.useEffect(() => {
472
+ setIsLoaded(false);
473
+ setHasError(false);
474
+ setIsLightboxOpen(false);
475
+ }, [src]);
476
+ if (!src) {
477
+ return null;
478
+ }
479
+ if (isResolvingRagImage) {
480
+ return /* @__PURE__ */ jsxRuntime.jsx(LoadingImageCard, { label: "Loading image", description: "Reference image" });
481
+ }
482
+ if (hasError) {
483
+ return /* @__PURE__ */ jsxRuntime.jsx(BrokenImageCard, { alt });
484
+ }
485
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
486
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "my-3 block w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
487
+ "button",
488
+ {
489
+ type: "button",
490
+ onClick: () => {
491
+ if (isLoaded) {
492
+ setIsLightboxOpen(true);
493
+ }
494
+ },
495
+ disabled: !isLoaded,
496
+ "aria-busy": !isLoaded,
497
+ className: "group relative mx-auto flex w-full items-center justify-center overflow-hidden rounded-xl bg-black/[0.03] px-3 py-3 text-left transition-colors hover:bg-black/[0.05] disabled:cursor-wait disabled:hover:bg-black/[0.03] dark:bg-white/[0.03] dark:hover:bg-white/[0.05] dark:disabled:hover:bg-white/[0.03]",
498
+ style: {
499
+ ...imageFrameStyle,
500
+ ...!isLoaded ? { minHeight: "9rem" } : {}
501
+ },
502
+ children: /* @__PURE__ */ jsxRuntime.jsx(
503
+ "img",
504
+ {
505
+ src,
506
+ alt: alt || "",
507
+ className: `relative z-[1] block h-auto max-h-[22rem] w-full max-w-full rounded-lg object-contain transition-opacity duration-200 ${isLoaded ? "opacity-100" : "opacity-0"}`,
508
+ style: imageStyle,
509
+ onLoad: () => {
510
+ setHasError(false);
511
+ setIsLoaded(true);
512
+ },
513
+ onError: () => {
514
+ setIsLoaded(false);
515
+ setHasError(true);
516
+ }
517
+ }
518
+ )
519
+ }
520
+ ) }),
521
+ isLightboxOpen && isLoaded ? /* @__PURE__ */ jsxRuntime.jsx(
522
+ ImageLightbox,
523
+ {
524
+ src,
525
+ alt,
526
+ onClose: () => setIsLightboxOpen(false)
527
+ }
528
+ ) : null
529
+ ] });
530
+ }
531
+ function createMarkdownComponents(options = {}) {
532
+ return {
533
+ p: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-3 last:mb-0 text-sm leading-relaxed", children }),
534
+ code: ({ className: codeClassName, children }) => {
535
+ const isInline = !codeClassName;
536
+ return isInline ? /* @__PURE__ */ jsxRuntime.jsx("code", { className: "payman-agent-code-inline rounded-md px-1.5 py-0.5 font-mono text-xs break-all", children }) : /* @__PURE__ */ jsxRuntime.jsx("code", { className: "payman-agent-code-block my-2 block overflow-x-auto rounded-lg p-3 font-mono text-xs whitespace-pre", children });
537
+ },
538
+ pre: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "my-2 max-w-full overflow-x-auto rounded-lg", children }),
539
+ ul: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "mb-3 ml-4 list-disc space-y-1 text-sm", children }),
540
+ ol: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("ol", { className: "mb-3 ml-4 list-decimal space-y-1 text-sm", children }),
541
+ li: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "text-sm leading-relaxed", children }),
542
+ h1: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "mt-4 mb-2 text-lg font-semibold first:mt-0", children }),
543
+ h2: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "mt-3 mb-2 text-base font-semibold first:mt-0", children }),
544
+ h3: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "mt-2 mb-1 text-sm font-semibold first:mt-0", children }),
545
+ strong: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("strong", { className: "font-semibold", children }),
546
+ em: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("em", { className: "italic", children }),
547
+ blockquote: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("blockquote", { className: "payman-agent-blockquote my-2 pl-4 italic", children }),
548
+ hr: () => /* @__PURE__ */ jsxRuntime.jsx("hr", { className: "payman-agent-hr my-4" }),
549
+ a: ({ href, children }) => /* @__PURE__ */ jsxRuntime.jsx(
550
+ "a",
551
+ {
552
+ href,
553
+ target: "_blank",
554
+ rel: "noopener noreferrer",
555
+ className: "payman-agent-link underline decoration-1 underline-offset-2",
556
+ children
557
+ }
558
+ ),
559
+ img: ({ src, alt }) => /* @__PURE__ */ jsxRuntime.jsx(
560
+ MarkdownImage,
561
+ {
562
+ src: typeof src === "string" ? src : void 0,
563
+ alt: typeof alt === "string" ? alt : void 0,
564
+ isResolving: options.isResolvingImages
565
+ }
566
+ ),
567
+ table: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative my-4 -mx-1 w-full overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsx("table", { className: "payman-agent-table min-w-full caption-bottom overflow-hidden rounded-lg text-sm", children }) }),
568
+ thead: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "payman-agent-thead [&_tr]:border-b", children }),
569
+ tbody: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "[&_tr:last-child]:border-0", children }),
570
+ tr: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "payman-agent-tr border-b transition-colors", children }),
571
+ th: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("th", { className: "h-10 px-3 text-left align-middle text-xs font-medium whitespace-nowrap", children }),
572
+ td: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("td", { className: "p-3 align-middle text-sm whitespace-nowrap", children })
573
+ };
574
+ }
324
575
 
325
576
  // src/utils/errorMessages.ts
326
577
  var WORKFLOW_FAILED = "WORKFLOW_FAILED";
@@ -453,6 +704,12 @@ function AgentMessage({
453
704
  ),
454
705
  [message.steps, currentExecutingStepId]
455
706
  );
707
+ const markdownRenderers = react.useMemo(
708
+ () => createMarkdownComponents({
709
+ isResolvingImages: message.isResolvingImages
710
+ }),
711
+ [message.isResolvingImages]
712
+ );
456
713
  const getStepsLabel = (streaming) => {
457
714
  const count = message.steps.length;
458
715
  const stepWord = count === 1 ? "step" : "steps";
@@ -640,7 +897,7 @@ function AgentMessage({
640
897
  ReactMarkdown__default.default,
641
898
  {
642
899
  remarkPlugins: [remarkGfm__default.default],
643
- components: markdownComponents(),
900
+ components: markdownRenderers,
644
901
  children: isError ? conflictErrorMessage ?? FRIENDLY_ERROR_MESSAGE : content || (isStreaming ? "Thinking..." : isCancelled ? "Request was stopped." : "")
645
902
  }
646
903
  )
@@ -691,42 +948,6 @@ function AgentMessage({
691
948
  }
692
949
  return messageContent;
693
950
  }
694
- function markdownComponents(_isError) {
695
- return {
696
- p: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-3 last:mb-0 text-sm leading-relaxed", children }),
697
- code: ({ className: codeClassName, children }) => {
698
- const isInline = !codeClassName;
699
- return isInline ? /* @__PURE__ */ jsxRuntime.jsx("code", { className: "px-1.5 py-0.5 rounded-md text-xs font-mono break-all payman-agent-code-inline", children }) : /* @__PURE__ */ jsxRuntime.jsx("code", { className: "block p-3 rounded-lg text-xs font-mono overflow-x-auto my-2 whitespace-pre payman-agent-code-block", children });
700
- },
701
- pre: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "my-2 overflow-x-auto max-w-full rounded-lg", children }),
702
- ul: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "list-disc ml-4 mb-3 space-y-1 text-sm", children }),
703
- ol: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("ol", { className: "list-decimal ml-4 mb-3 space-y-1 text-sm", children }),
704
- li: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "text-sm leading-relaxed", children }),
705
- h1: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-lg font-semibold mb-2 mt-4 first:mt-0", children }),
706
- h2: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-base font-semibold mb-2 mt-3 first:mt-0", children }),
707
- h3: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("h3", { className: "text-sm font-semibold mb-1 mt-2 first:mt-0", children }),
708
- strong: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("strong", { className: "font-semibold", children }),
709
- em: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("em", { className: "italic", children }),
710
- blockquote: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("blockquote", { className: "pl-4 my-2 italic payman-agent-blockquote", children }),
711
- hr: () => /* @__PURE__ */ jsxRuntime.jsx("hr", { className: "my-4 payman-agent-hr" }),
712
- a: ({ href, children }) => /* @__PURE__ */ jsxRuntime.jsx(
713
- "a",
714
- {
715
- href,
716
- target: "_blank",
717
- rel: "noopener noreferrer",
718
- className: "underline underline-offset-2 decoration-1 payman-agent-link",
719
- children
720
- }
721
- ),
722
- table: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative w-full overflow-x-auto my-4 -mx-1", children: /* @__PURE__ */ jsxRuntime.jsx("table", { className: "min-w-full caption-bottom text-sm rounded-lg overflow-hidden payman-agent-table", children }) }),
723
- thead: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "[&_tr]:border-b payman-agent-thead", children }),
724
- tbody: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "[&_tr:last-child]:border-0", children }),
725
- tr: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "border-b transition-colors payman-agent-tr", children }),
726
- th: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("th", { className: "h-10 px-3 text-left align-middle font-medium whitespace-nowrap text-xs", children }),
727
- td: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("td", { className: "p-3 align-middle text-sm whitespace-nowrap", children })
728
- };
729
- }
730
951
  function UserMessage({
731
952
  message,
732
953
  animated = false,