@plaisolutions/react 0.10.1 → 0.12.0

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.
@@ -1,6 +1,7 @@
1
1
  import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
2
2
  import { Bot, Brain, Check, CheckCircle2, ChevronDown, CircleX, Copy, Database, File, FileText, Globe, LoaderCircle, MessageSquare, Minus, Plug, Plus, RotateCcw, ThumbsDown, ThumbsUp, Workflow, XCircle } from "lucide-react";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ import { HttpStatusError } from "@plaisolutions/client";
4
5
 
5
6
  //#region src/components/datasource-tool-result-card.tsx
6
7
  function DatasourceIcon() {
@@ -115,8 +116,64 @@ function ResourceCardContent({ icon, type, title, description }) {
115
116
  ] });
116
117
  }
117
118
  function ResourceCard(props) {
118
- const { className: customClassName, variant = "card",...contentProps } = props;
119
+ const { className: customClassName, variant = "card", resourceId, requiresDownloadUrl = false, getResourceDownloadUrl,...contentProps } = props;
120
+ const [downloadState, setDownloadState] = useState("idle");
121
+ const abortControllerRef = useRef(null);
119
122
  const className = joinClasses("block rounded-lg bg-neutral-100 p-4 text-left text-neutral-950", variant === "card" ? "min-h-[183px] w-[186px] max-w-full" : "w-full", customClassName);
123
+ const interactiveClassName = `${className} transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950`;
124
+ useEffect(() => () => {
125
+ abortControllerRef.current?.abort();
126
+ }, []);
127
+ const openProtectedResource = useCallback(async () => {
128
+ if (!resourceId || !getResourceDownloadUrl || downloadState === "loading") return;
129
+ abortControllerRef.current?.abort();
130
+ const abortController = new AbortController();
131
+ abortControllerRef.current = abortController;
132
+ setDownloadState("loading");
133
+ const popup = window.open("about:blank", "_blank");
134
+ if (popup) popup.opener = null;
135
+ try {
136
+ const downloadUrl = await getResourceDownloadUrl({
137
+ resourceId,
138
+ signal: abortController.signal
139
+ });
140
+ if (abortController.signal.aborted) {
141
+ popup?.close();
142
+ return;
143
+ }
144
+ if (!downloadUrl.trim()) throw new Error("The resource download URL is empty.");
145
+ if (popup && !popup.closed) popup.location.replace(downloadUrl);
146
+ else if (!window.open(downloadUrl, "_blank", "noopener,noreferrer")) throw new Error("The resource window was blocked.");
147
+ setDownloadState("idle");
148
+ } catch {
149
+ popup?.close();
150
+ if (!abortController.signal.aborted) setDownloadState("error");
151
+ }
152
+ }, [
153
+ downloadState,
154
+ getResourceDownloadUrl,
155
+ resourceId
156
+ ]);
157
+ if (requiresDownloadUrl && resourceId && getResourceDownloadUrl) return /* @__PURE__ */ jsxs("button", {
158
+ type: "button",
159
+ className: `${interactiveClassName} border-0 disabled:cursor-wait disabled:opacity-70`,
160
+ onClick: openProtectedResource,
161
+ disabled: downloadState === "loading",
162
+ "aria-busy": downloadState === "loading",
163
+ children: [
164
+ /* @__PURE__ */ jsx(ResourceCardContent, { ...contentProps }),
165
+ downloadState === "loading" ? /* @__PURE__ */ jsx("span", {
166
+ className: "mt-2 block text-xs text-neutral-600",
167
+ "aria-live": "polite",
168
+ children: "Opening resource…"
169
+ }) : null,
170
+ downloadState === "error" ? /* @__PURE__ */ jsx("span", {
171
+ className: "mt-2 block text-xs text-red-700",
172
+ role: "alert",
173
+ children: "Unable to open resource. Try again."
174
+ }) : null
175
+ ]
176
+ });
120
177
  if (!contentProps.url) return /* @__PURE__ */ jsx("article", {
121
178
  "aria-label": `${contentProps.title}: ${contentProps.description}`,
122
179
  className,
@@ -126,7 +183,7 @@ function ResourceCard(props) {
126
183
  href: contentProps.url,
127
184
  target: "_blank",
128
185
  rel: "noreferrer noopener",
129
- className: `${className} transition-colors hover:bg-neutral-200 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950`,
186
+ className: interactiveClassName,
130
187
  children: /* @__PURE__ */ jsx(ResourceCardContent, { ...contentProps })
131
188
  });
132
189
  }
@@ -614,6 +671,9 @@ function isGoogleDriveResource(resource) {
614
671
  readNestedString(records, ["datasource", "origin"])
615
672
  ].some((candidate) => candidate?.toUpperCase() === "GOOGLE_DRIVE") || isGoogleDriveUrl(resource.external_url) || isGoogleDriveUrl(resource.url);
616
673
  }
674
+ function requiresResourceDownloadUrl(resource, locale) {
675
+ return Boolean(resource.store && !resource.external_url && !getLocalizedOpenGraphValue(resource, "url", locale) && !isGoogleDriveResource(resource));
676
+ }
617
677
  function getResourceUrl(resource, locale) {
618
678
  const openGraphUrl = getLocalizedOpenGraphValue(resource, "url", locale);
619
679
  if (openGraphUrl) return openGraphUrl;
@@ -649,16 +709,20 @@ function readString(value, key) {
649
709
  const candidate = value?.[key];
650
710
  return typeof candidate === "string" && candidate.trim() ? candidate : null;
651
711
  }
652
- function toResourceCardProps(resource, locale) {
712
+ function toResourceCardProps(resource, locale, getResourceDownloadUrl) {
713
+ const requiresDownloadUrl = requiresResourceDownloadUrl(resource, locale);
653
714
  return {
654
715
  icon: getResourceIcon(resource, locale),
655
716
  type: getResourceType(resource, locale),
656
717
  title: getResourceTitle(resource, locale),
657
718
  description: getResourceDescription(resource, locale),
658
- url: getResourceUrl(resource, locale)
719
+ url: requiresDownloadUrl ? null : getResourceUrl(resource, locale),
720
+ resourceId: resource.id,
721
+ getResourceDownloadUrl: requiresDownloadUrl ? getResourceDownloadUrl : void 0,
722
+ requiresDownloadUrl
659
723
  };
660
724
  }
661
- function toFolderCardProps(folder, group, locale) {
725
+ function toFolderCardProps(folder, group, locale, getResourceDownloadUrl) {
662
726
  const datasource = group[0]?.datasource;
663
727
  const type = getLocalizedOpenGraphValue(folder, "type", locale) ?? readString(folder.extra_info, "type") ?? datasource?.type ?? "FOLDER";
664
728
  return {
@@ -667,7 +731,7 @@ function toFolderCardProps(folder, group, locale) {
667
731
  description: getLocalizedOpenGraphValue(folder, "description", locale) ?? readString(folder.extra_info, "description") ?? readString(folder.extra_info, "summary") ?? datasource?.description ?? datasource?.summary ?? "",
668
732
  type,
669
733
  url: getLocalizedOpenGraphValue(folder, "url", locale),
670
- resources: group.map((resource) => toResourceCardProps(resource, locale))
734
+ resources: group.map((resource) => toResourceCardProps(resource, locale, getResourceDownloadUrl))
671
735
  };
672
736
  }
673
737
  function isDatasourceResource(value) {
@@ -676,7 +740,7 @@ function isDatasourceResource(value) {
676
740
  const datasource = value.datasource;
677
741
  return typeof value.id === "string" && typeof value.name === "string" && typeof value.type === "string" && (value.url === null || typeof value.url === "string") && (value.external_url === null || typeof value.external_url === "string") && isObject(value.metadata) && isObject(value.extra_info) && (folder === null || isObject(folder) && typeof folder.id === "string" && typeof folder.name === "string" && isObject(folder.extra_info)) && (datasource === null || isObject(datasource) && typeof datasource.type === "string" && (datasource.description === null || typeof datasource.description === "string") && (datasource.summary === null || typeof datasource.summary === "string"));
678
742
  }
679
- function getDatasourceResourceCards(resources, locale) {
743
+ function getDatasourceResourceCards(resources, locale, getResourceDownloadUrl) {
680
744
  const folderGroups = /* @__PURE__ */ new Map();
681
745
  const ungroupedResources = [];
682
746
  const seenUrls = /* @__PURE__ */ new Set();
@@ -701,11 +765,11 @@ function getDatasourceResourceCards(resources, locale) {
701
765
  return [...Array.from(folderGroups.values()).map(({ folder, resources: group }) => ({
702
766
  kind: "folder",
703
767
  key: `folder-${folder.id}`,
704
- props: toFolderCardProps(folder, group, locale)
768
+ props: toFolderCardProps(folder, group, locale, getResourceDownloadUrl)
705
769
  })), ...ungroupedResources.map((resource) => ({
706
770
  kind: "resource",
707
771
  key: `resource-${resource.id}`,
708
- props: toResourceCardProps(resource, locale)
772
+ props: toResourceCardProps(resource, locale, getResourceDownloadUrl)
709
773
  }))];
710
774
  }
711
775
  function DatasourceResourceCardView({ card, variant = "card" }) {
@@ -718,8 +782,8 @@ function DatasourceResourceCardView({ card, variant = "card" }) {
718
782
  variant
719
783
  });
720
784
  }
721
- function DatasourceToolResources({ resources, locale, className }) {
722
- const cards = getDatasourceResourceCards(resources, locale);
785
+ function DatasourceToolResources({ resources, locale, className, getResourceDownloadUrl }) {
786
+ const cards = getDatasourceResourceCards(resources, locale, getResourceDownloadUrl);
723
787
  return /* @__PURE__ */ jsx("section", {
724
788
  "aria-label": "Recursos de la fuente de datos",
725
789
  className: joinClasses("flex flex-wrap gap-3", className),
@@ -955,8 +1019,8 @@ function getDatasourceResources$2(part) {
955
1019
  const resources = part.metadata?.resources;
956
1020
  return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
957
1021
  }
958
- function getAggregatedCards(parts, locale) {
959
- const datasourceCards = parts.filter((part) => part.toolType === "datasource").flatMap((part) => getDatasourceResourceCards(getDatasourceResources$2(part), locale).map((card) => ({
1022
+ function getAggregatedCards(parts, locale, getResourceDownloadUrl) {
1023
+ const datasourceCards = parts.filter((part) => part.toolType === "datasource").flatMap((part) => getDatasourceResourceCards(getDatasourceResources$2(part), locale, getResourceDownloadUrl).map((card) => ({
960
1024
  kind: "datasource",
961
1025
  key: `${part.id}-${card.key}`,
962
1026
  card
@@ -991,8 +1055,8 @@ function SourceCard({ source, variant = "card" }) {
991
1055
  function getTotalSourceCount(cards) {
992
1056
  return cards.reduce((count, source) => count + (source.kind === "web" ? getWebSearchResults(source.part).length : 1), 0);
993
1057
  }
994
- function AggregatedSourceResults({ parts, locale, maxVisible = 3, className }) {
995
- const cards = getAggregatedCards(parts, locale);
1058
+ function AggregatedSourceResults({ parts, locale, maxVisible = 3, className, getResourceDownloadUrl }) {
1059
+ const cards = getAggregatedCards(parts, locale, getResourceDownloadUrl);
996
1060
  if (cards.length === 0) return null;
997
1061
  const visibleLimit = Number.isFinite(maxVisible) && maxVisible >= 1 ? Math.floor(maxVisible) : 3;
998
1062
  const visibleCards = cards.slice(0, visibleLimit);
@@ -2292,6 +2356,7 @@ const TOOL_USE_ACTIONS = {
2292
2356
  external_datasource: "query",
2293
2357
  firecrawl_search: "web",
2294
2358
  http_request: "request",
2359
+ memory_proposal: "tool",
2295
2360
  mcp_tool: "request",
2296
2361
  office_documents: "documents",
2297
2362
  perplexity: "web",
@@ -2430,6 +2495,357 @@ function ToolUseIndicator({ part, locale, className,...props }) {
2430
2495
  });
2431
2496
  }
2432
2497
 
2498
+ //#endregion
2499
+ //#region src/components/memory-proposal-card.tsx
2500
+ const COPY = {
2501
+ en: {
2502
+ title: "Memory proposal",
2503
+ user: "Personal memory",
2504
+ project: "Project learning",
2505
+ create: "Create",
2506
+ update: "Update",
2507
+ delete: "Delete",
2508
+ previous: "Previous content",
2509
+ proposed: "Proposed content",
2510
+ accept: "Accept",
2511
+ reject: "Reject",
2512
+ review: "Sent for admin review",
2513
+ unavailable: "This proposal cannot be resolved here",
2514
+ accepted: "Accepted",
2515
+ rejected: "Rejected",
2516
+ expired: "Expired",
2517
+ conflicted: "Could not be applied because the memory changed",
2518
+ conflictError: "The memory changed. The latest status has been loaded.",
2519
+ expiredError: "This proposal is no longer available.",
2520
+ permissionError: "You no longer have permission to resolve this proposal.",
2521
+ genericError: "The proposal could not be resolved."
2522
+ },
2523
+ es: {
2524
+ title: "Propuesta de memoria",
2525
+ user: "Memoria personal",
2526
+ project: "Aprendizaje del proyecto",
2527
+ create: "Crear",
2528
+ update: "Actualizar",
2529
+ delete: "Eliminar",
2530
+ previous: "Contenido anterior",
2531
+ proposed: "Contenido propuesto",
2532
+ accept: "Aceptar",
2533
+ reject: "Rechazar",
2534
+ review: "Enviado para revisión de un administrador",
2535
+ unavailable: "Esta propuesta no se puede resolver aquí",
2536
+ accepted: "Aceptada",
2537
+ rejected: "Rechazada",
2538
+ expired: "Caducada",
2539
+ conflicted: "No se pudo aplicar porque la memoria cambió",
2540
+ conflictError: "La memoria cambió. Se ha cargado el estado más reciente.",
2541
+ expiredError: "Esta propuesta ya no está disponible.",
2542
+ permissionError: "Ya no tienes permiso para resolver esta propuesta.",
2543
+ genericError: "No se pudo resolver la propuesta."
2544
+ },
2545
+ ca: {
2546
+ title: "Proposta de memòria",
2547
+ user: "Memòria personal",
2548
+ project: "Aprenentatge del projecte",
2549
+ create: "Crear",
2550
+ update: "Actualitzar",
2551
+ delete: "Eliminar",
2552
+ previous: "Contingut anterior",
2553
+ proposed: "Contingut proposat",
2554
+ accept: "Acceptar",
2555
+ reject: "Rebutjar",
2556
+ review: "Enviat per a revisió d'un administrador",
2557
+ unavailable: "Aquesta proposta no es pot resoldre aquí",
2558
+ accepted: "Acceptada",
2559
+ rejected: "Rebutjada",
2560
+ expired: "Caducada",
2561
+ conflicted: "No s'ha pogut aplicar perquè la memòria ha canviat",
2562
+ conflictError: "La memòria ha canviat. S'ha carregat l'estat més recent.",
2563
+ expiredError: "Aquesta proposta ja no està disponible.",
2564
+ permissionError: "Ja no tens permís per resoldre aquesta proposta.",
2565
+ genericError: "No s'ha pogut resoldre la proposta."
2566
+ },
2567
+ da: {
2568
+ title: "Hukommelsesforslag",
2569
+ user: "Personlig hukommelse",
2570
+ project: "Projektlæring",
2571
+ create: "Opret",
2572
+ update: "Opdater",
2573
+ delete: "Slet",
2574
+ previous: "Tidligere indhold",
2575
+ proposed: "Foreslået indhold",
2576
+ accept: "Acceptér",
2577
+ reject: "Afvis",
2578
+ review: "Sendt til administratorgennemgang",
2579
+ unavailable: "Forslaget kan ikke behandles her",
2580
+ accepted: "Accepteret",
2581
+ rejected: "Afvist",
2582
+ expired: "Udløbet",
2583
+ conflicted: "Kunne ikke anvendes, fordi hukommelsen blev ændret",
2584
+ conflictError: "Hukommelsen blev ændret. Den seneste status er indlæst.",
2585
+ expiredError: "Forslaget er ikke længere tilgængeligt.",
2586
+ permissionError: "Du har ikke længere tilladelse til at behandle forslaget.",
2587
+ genericError: "Forslaget kunne ikke behandles."
2588
+ },
2589
+ de: {
2590
+ title: "Speichervorschlag",
2591
+ user: "Persönliche Erinnerung",
2592
+ project: "Projektwissen",
2593
+ create: "Erstellen",
2594
+ update: "Aktualisieren",
2595
+ delete: "Löschen",
2596
+ previous: "Vorheriger Inhalt",
2597
+ proposed: "Vorgeschlagener Inhalt",
2598
+ accept: "Akzeptieren",
2599
+ reject: "Ablehnen",
2600
+ review: "Zur Administratorprüfung gesendet",
2601
+ unavailable: "Dieser Vorschlag kann hier nicht bearbeitet werden",
2602
+ accepted: "Akzeptiert",
2603
+ rejected: "Abgelehnt",
2604
+ expired: "Abgelaufen",
2605
+ conflicted: "Nicht angewendet, da sich die Erinnerung geändert hat",
2606
+ conflictError: "Die Erinnerung hat sich geändert. Der aktuelle Status wurde geladen.",
2607
+ expiredError: "Dieser Vorschlag ist nicht mehr verfügbar.",
2608
+ permissionError: "Sie dürfen diesen Vorschlag nicht mehr bearbeiten.",
2609
+ genericError: "Der Vorschlag konnte nicht bearbeitet werden."
2610
+ },
2611
+ fr: {
2612
+ title: "Proposition de mémoire",
2613
+ user: "Mémoire personnelle",
2614
+ project: "Apprentissage du projet",
2615
+ create: "Créer",
2616
+ update: "Modifier",
2617
+ delete: "Supprimer",
2618
+ previous: "Contenu précédent",
2619
+ proposed: "Contenu proposé",
2620
+ accept: "Accepter",
2621
+ reject: "Refuser",
2622
+ review: "Envoyé à un administrateur pour examen",
2623
+ unavailable: "Cette proposition ne peut pas être traitée ici",
2624
+ accepted: "Acceptée",
2625
+ rejected: "Refusée",
2626
+ expired: "Expirée",
2627
+ conflicted: "Impossible à appliquer car la mémoire a changé",
2628
+ conflictError: "La mémoire a changé. Le dernier état a été chargé.",
2629
+ expiredError: "Cette proposition n'est plus disponible.",
2630
+ permissionError: "Vous n'avez plus l'autorisation de traiter cette proposition.",
2631
+ genericError: "La proposition n'a pas pu être traitée."
2632
+ },
2633
+ it: {
2634
+ title: "Proposta di memoria",
2635
+ user: "Memoria personale",
2636
+ project: "Apprendimento del progetto",
2637
+ create: "Crea",
2638
+ update: "Aggiorna",
2639
+ delete: "Elimina",
2640
+ previous: "Contenuto precedente",
2641
+ proposed: "Contenuto proposto",
2642
+ accept: "Accetta",
2643
+ reject: "Rifiuta",
2644
+ review: "Inviata alla revisione di un amministratore",
2645
+ unavailable: "Questa proposta non può essere gestita qui",
2646
+ accepted: "Accettata",
2647
+ rejected: "Rifiutata",
2648
+ expired: "Scaduta",
2649
+ conflicted: "Non applicata perché la memoria è cambiata",
2650
+ conflictError: "La memoria è cambiata. È stato caricato lo stato più recente.",
2651
+ expiredError: "Questa proposta non è più disponibile.",
2652
+ permissionError: "Non hai più il permesso di gestire questa proposta.",
2653
+ genericError: "Impossibile gestire la proposta."
2654
+ },
2655
+ no: {
2656
+ title: "Minneforslag",
2657
+ user: "Personlig minne",
2658
+ project: "Prosjektlæring",
2659
+ create: "Opprett",
2660
+ update: "Oppdater",
2661
+ delete: "Slett",
2662
+ previous: "Tidligere innhold",
2663
+ proposed: "Foreslått innhold",
2664
+ accept: "Godta",
2665
+ reject: "Avvis",
2666
+ review: "Sendt til administratorgjennomgang",
2667
+ unavailable: "Forslaget kan ikke behandles her",
2668
+ accepted: "Godtatt",
2669
+ rejected: "Avvist",
2670
+ expired: "Utløpt",
2671
+ conflicted: "Kunne ikke brukes fordi minnet ble endret",
2672
+ conflictError: "Minnet ble endret. Den nyeste statusen er lastet inn.",
2673
+ expiredError: "Forslaget er ikke lenger tilgjengelig.",
2674
+ permissionError: "Du har ikke lenger tillatelse til å behandle forslaget.",
2675
+ genericError: "Forslaget kunne ikke behandles."
2676
+ },
2677
+ pt: {
2678
+ title: "Proposta de memória",
2679
+ user: "Memória pessoal",
2680
+ project: "Aprendizagem do projeto",
2681
+ create: "Criar",
2682
+ update: "Atualizar",
2683
+ delete: "Eliminar",
2684
+ previous: "Conteúdo anterior",
2685
+ proposed: "Conteúdo proposto",
2686
+ accept: "Aceitar",
2687
+ reject: "Rejeitar",
2688
+ review: "Enviado para revisão de um administrador",
2689
+ unavailable: "Esta proposta não pode ser resolvida aqui",
2690
+ accepted: "Aceite",
2691
+ rejected: "Rejeitada",
2692
+ expired: "Expirada",
2693
+ conflicted: "Não aplicada porque a memória foi alterada",
2694
+ conflictError: "A memória foi alterada. O estado mais recente foi carregado.",
2695
+ expiredError: "Esta proposta já não está disponível.",
2696
+ permissionError: "Já não tem permissão para resolver esta proposta.",
2697
+ genericError: "Não foi possível resolver a proposta."
2698
+ },
2699
+ sv: {
2700
+ title: "Minnesförslag",
2701
+ user: "Personligt minne",
2702
+ project: "Projektlärdom",
2703
+ create: "Skapa",
2704
+ update: "Uppdatera",
2705
+ delete: "Ta bort",
2706
+ previous: "Tidigare innehåll",
2707
+ proposed: "Föreslaget innehåll",
2708
+ accept: "Godkänn",
2709
+ reject: "Avvisa",
2710
+ review: "Skickat för administratörsgranskning",
2711
+ unavailable: "Förslaget kan inte hanteras här",
2712
+ accepted: "Godkänt",
2713
+ rejected: "Avvisat",
2714
+ expired: "Utgånget",
2715
+ conflicted: "Kunde inte tillämpas eftersom minnet ändrades",
2716
+ conflictError: "Minnet ändrades. Den senaste statusen har lästs in.",
2717
+ expiredError: "Förslaget är inte längre tillgängligt.",
2718
+ permissionError: "Du har inte längre behörighet att hantera förslaget.",
2719
+ genericError: "Förslaget kunde inte hanteras."
2720
+ }
2721
+ };
2722
+ const REDACTED = "[redacted]";
2723
+ function MemoryProposalCard({ proposal: initial, actions, activeAgentId, locale, className }) {
2724
+ const copy = COPY[getSupportedToolLocale(locale)];
2725
+ const [proposal, setProposal] = useState(initial);
2726
+ const [resolving, setResolving] = useState(false);
2727
+ const [error, setError] = useState(null);
2728
+ useEffect(() => setProposal((current) => mergeProposal(current, initial)), [initial]);
2729
+ async function resolve(accept) {
2730
+ if (resolving) return;
2731
+ setResolving(true);
2732
+ setError(null);
2733
+ try {
2734
+ const next = accept ? await actions.acceptMemoryProposal({ proposalId: proposal.id }) : await actions.rejectMemoryProposal({ proposalId: proposal.id });
2735
+ setProposal((current) => mergeProposal(current, next));
2736
+ } catch (cause) {
2737
+ const status = cause instanceof HttpStatusError ? cause.status : 0;
2738
+ setError(status === 409 ? copy.conflictError : status === 410 ? copy.expiredError : status === 401 || status === 403 ? copy.permissionError : copy.genericError);
2739
+ try {
2740
+ const latest = await actions.getMemoryProposal({ proposalId: proposal.id });
2741
+ setProposal((current) => mergeProposal(current, latest));
2742
+ } catch {}
2743
+ } finally {
2744
+ setResolving(false);
2745
+ }
2746
+ }
2747
+ const canResolve = proposal.status === "PENDING" && proposal.can_resolve === true && proposal.agent_id === activeAgentId;
2748
+ const statusCopy = proposal.status === "ACCEPTED" ? copy.accepted : proposal.status === "REJECTED" ? copy.rejected : proposal.status === "EXPIRED" ? copy.expired : proposal.status === "CONFLICTED" ? copy.conflicted : null;
2749
+ const operation = proposal.operation === "CREATE" ? copy.create : proposal.operation === "UPDATE" ? copy.update : copy.delete;
2750
+ return /* @__PURE__ */ jsxs("section", {
2751
+ className: joinClasses("space-y-3 rounded-lg border border-emerald-200 bg-emerald-50/30 p-4 text-left", className),
2752
+ "data-memory-proposal-id": proposal.id,
2753
+ children: [
2754
+ /* @__PURE__ */ jsxs("header", {
2755
+ className: "space-y-2",
2756
+ children: [/* @__PURE__ */ jsxs("h4", {
2757
+ className: "flex items-center gap-2 text-sm font-semibold text-slate-900",
2758
+ children: [/* @__PURE__ */ jsx(Brain, { className: "size-4" }), copy.title]
2759
+ }), /* @__PURE__ */ jsxs("div", {
2760
+ className: "flex flex-wrap gap-2 text-xs",
2761
+ children: [
2762
+ /* @__PURE__ */ jsx("span", {
2763
+ className: "rounded-full border border-slate-300 bg-white px-2 py-0.5",
2764
+ children: proposal.scope === "USER" ? copy.user : copy.project
2765
+ }),
2766
+ /* @__PURE__ */ jsx("span", {
2767
+ className: "rounded-full bg-slate-100 px-2 py-0.5",
2768
+ children: operation
2769
+ }),
2770
+ /* @__PURE__ */ jsx("span", {
2771
+ className: "rounded-full bg-slate-100 px-2 py-0.5",
2772
+ children: formatCategory(proposal.category)
2773
+ })
2774
+ ]
2775
+ })]
2776
+ }),
2777
+ proposal.previous_content && proposal.previous_content !== REDACTED ? /* @__PURE__ */ jsxs("div", {
2778
+ className: "rounded-md bg-slate-100 p-3 text-sm",
2779
+ children: [/* @__PURE__ */ jsx("span", {
2780
+ className: "mb-1 block text-xs font-medium text-slate-500",
2781
+ children: copy.previous
2782
+ }), /* @__PURE__ */ jsx("p", {
2783
+ className: "whitespace-pre-wrap break-words",
2784
+ children: proposal.previous_content
2785
+ })]
2786
+ }) : null,
2787
+ proposal.content && proposal.content !== REDACTED ? /* @__PURE__ */ jsxs("div", {
2788
+ className: "text-sm",
2789
+ children: [/* @__PURE__ */ jsx("span", {
2790
+ className: "mb-1 block text-xs font-medium text-slate-500",
2791
+ children: copy.proposed
2792
+ }), /* @__PURE__ */ jsx("p", {
2793
+ className: "whitespace-pre-wrap break-words",
2794
+ children: proposal.content
2795
+ })]
2796
+ }) : null,
2797
+ canResolve ? /* @__PURE__ */ jsxs("div", {
2798
+ className: "flex gap-2",
2799
+ children: [/* @__PURE__ */ jsxs("button", {
2800
+ type: "button",
2801
+ disabled: resolving,
2802
+ onClick: () => void resolve(true),
2803
+ className: "inline-flex items-center rounded-md bg-slate-900 px-3 py-1.5 text-xs font-medium text-white disabled:opacity-50",
2804
+ children: [resolving ? /* @__PURE__ */ jsx(LoaderCircle, { className: "mr-2 size-3 animate-spin" }) : null, copy.accept]
2805
+ }), /* @__PURE__ */ jsx("button", {
2806
+ type: "button",
2807
+ disabled: resolving,
2808
+ onClick: () => void resolve(false),
2809
+ className: "rounded-md border border-slate-300 bg-white px-3 py-1.5 text-xs font-medium disabled:opacity-50",
2810
+ children: copy.reject
2811
+ })]
2812
+ }) : null,
2813
+ proposal.status === "PENDING" && !canResolve ? /* @__PURE__ */ jsx("p", {
2814
+ className: "text-xs font-medium text-slate-500",
2815
+ children: proposal.scope === "PROJECT" ? copy.review : copy.unavailable
2816
+ }) : null,
2817
+ proposal.status === "ACCEPTED" && statusCopy ? /* @__PURE__ */ jsxs("span", {
2818
+ className: "inline-flex items-center gap-1.5 rounded-full border bg-white px-3 py-1 text-xs font-medium text-slate-900 shadow-sm",
2819
+ children: [statusCopy, /* @__PURE__ */ jsx(Check, {
2820
+ className: "size-3.5 stroke-[2.5] text-emerald-600",
2821
+ "aria-hidden": "true"
2822
+ })]
2823
+ }) : null,
2824
+ statusCopy && proposal.status !== "ACCEPTED" ? /* @__PURE__ */ jsx("p", {
2825
+ className: "text-xs font-medium text-slate-500",
2826
+ children: statusCopy
2827
+ }) : null,
2828
+ error ? /* @__PURE__ */ jsx("p", {
2829
+ className: "text-xs text-red-600",
2830
+ children: error
2831
+ }) : null
2832
+ ]
2833
+ });
2834
+ }
2835
+ function mergeProposal(current, incoming) {
2836
+ if (current.id !== incoming.id) return incoming;
2837
+ return {
2838
+ ...incoming,
2839
+ content: incoming.content === REDACTED ? current.content : incoming.content,
2840
+ previous_content: incoming.previous_content === REDACTED ? current.previous_content : incoming.previous_content,
2841
+ rationale: incoming.rationale === REDACTED ? current.rationale : incoming.rationale
2842
+ };
2843
+ }
2844
+ function formatCategory(category) {
2845
+ const value = category.replaceAll("_", " ").toLowerCase();
2846
+ return `${value.charAt(0).toUpperCase()}${value.slice(1)}`;
2847
+ }
2848
+
2433
2849
  //#endregion
2434
2850
  //#region src/components/tool-result-card.tsx
2435
2851
  function formatJson(value) {
@@ -2447,7 +2863,18 @@ function getDatasourceResources$1(part) {
2447
2863
  const resources = part.metadata.resources;
2448
2864
  return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
2449
2865
  }
2450
- function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAgentThread }) {
2866
+ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAgentThread, getResourceDownloadUrl, memoryProposal }) {
2867
+ if (part.toolType === "memory_proposal") {
2868
+ const proposal = part.metadata?.proposal;
2869
+ if (!memoryProposal || !proposal || typeof proposal !== "object") return null;
2870
+ return /* @__PURE__ */ jsx(MemoryProposalCard, {
2871
+ proposal,
2872
+ actions: memoryProposal.actions,
2873
+ activeAgentId: memoryProposal.activeAgentId,
2874
+ locale,
2875
+ className
2876
+ });
2877
+ }
2451
2878
  if (part.state === "pending") return /* @__PURE__ */ jsx(ToolUseIndicator, {
2452
2879
  part,
2453
2880
  locale,
@@ -2500,7 +2927,8 @@ function ToolResultCard({ part, className, detailsOpen = true, locale, onOpenAge
2500
2927
  if (datasourceResources.length > 0) return /* @__PURE__ */ jsx(DatasourceToolResources, {
2501
2928
  resources: datasourceResources,
2502
2929
  locale,
2503
- className
2930
+ className,
2931
+ getResourceDownloadUrl
2504
2932
  });
2505
2933
  if (part.toolType === "datasource") return null;
2506
2934
  return /* @__PURE__ */ jsxs("section", {
@@ -2708,7 +3136,7 @@ function getMessageTextClassName(role) {
2708
3136
  function getMessageTextAlignmentClassName(role) {
2709
3137
  return role === "user" ? "text-right" : "text-left";
2710
3138
  }
2711
- function renderPart(part, index, message, isStreaming, onOpenAgentThread, locale, renderText, renderToolCall, renderThinking, thinkingLabel, completedThinkingLabel, textClassName) {
3139
+ function renderPart(part, index, message, isStreaming, onOpenAgentThread, getResourceDownloadUrl, locale, memoryProposal, renderText, renderToolCall, renderThinking, thinkingLabel, completedThinkingLabel, textClassName) {
2712
3140
  if (part.type === "text") {
2713
3141
  if (renderText) return /* @__PURE__ */ jsx("div", { children: renderText(part, {
2714
3142
  message,
@@ -2764,7 +3192,9 @@ function renderPart(part, index, message, isStreaming, onOpenAgentThread, locale
2764
3192
  return /* @__PURE__ */ jsx(ToolResultCard, {
2765
3193
  part,
2766
3194
  locale,
2767
- onOpenAgentThread
3195
+ onOpenAgentThread,
3196
+ getResourceDownloadUrl,
3197
+ memoryProposal
2768
3198
  }, `tool-${part.id}-${index}`);
2769
3199
  }
2770
3200
  if (part.type === "thinking") {
@@ -2820,7 +3250,7 @@ function aggregateSourceToolParts(parts, position) {
2820
3250
  ...remainingParts.slice(insertionIndex)
2821
3251
  ];
2822
3252
  }
2823
- function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD, sourceToolResultsLayout = "aggregated", sourceToolResultsPosition, maxVisibleSourceCards = 3, datasourceToolResultsPosition, onOpenAgentThread, locale, renderText, renderToolCall, renderThinking, isStreaming = false, thinkingLabel, completedThinkingLabel, readMoreLabel = "Read more", readLessLabel = "Read less", className,...props }) {
3253
+ function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD, sourceToolResultsLayout = "aggregated", sourceToolResultsPosition, maxVisibleSourceCards = 3, datasourceToolResultsPosition, onOpenAgentThread, getResourceDownloadUrl, locale, memoryProposal, renderText, renderToolCall, renderThinking, isStreaming = false, thinkingLabel, completedThinkingLabel, readMoreLabel = "Read more", readLessLabel = "Read less", className,...props }) {
2824
3254
  const [isExpanded, setIsExpanded] = useState(false);
2825
3255
  const textContent = useMemo(() => message.parts.filter((part) => part.type === "text").map((part) => part.text).join("\n"), [message.parts]);
2826
3256
  const canCollapse = message.role === "user" && message.parts.every((part) => part.type === "text") && textContent.length > collapseThreshold;
@@ -2848,8 +3278,9 @@ function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD,
2848
3278
  }) : orderedParts.map((item) => item.kind === "source-results" ? /* @__PURE__ */ jsx(AggregatedSourceResults, {
2849
3279
  parts: item.parts,
2850
3280
  locale,
2851
- maxVisible: maxVisibleSourceCards
2852
- }, `source-results-${item.index}`) : renderPart(item.part, item.index, message, isStreaming, onOpenAgentThread, locale, renderText, renderToolCall, renderThinking, thinkingLabel, completedThinkingLabel, textClassName)), canCollapse ? /* @__PURE__ */ jsx("button", {
3281
+ maxVisible: maxVisibleSourceCards,
3282
+ getResourceDownloadUrl
3283
+ }, `source-results-${item.index}`) : renderPart(item.part, item.index, message, isStreaming, onOpenAgentThread, getResourceDownloadUrl, locale, memoryProposal, renderText, renderToolCall, renderThinking, thinkingLabel, completedThinkingLabel, textClassName)), canCollapse ? /* @__PURE__ */ jsx("button", {
2853
3284
  type: "button",
2854
3285
  className: "text-xs font-medium text-slate-600 hover:text-slate-900",
2855
3286
  onClick: () => setIsExpanded((previous) => !previous),
@@ -2865,7 +3296,8 @@ function getDatasourceResources(part) {
2865
3296
  const resources = part.metadata?.resources;
2866
3297
  return Array.isArray(resources) ? resources.filter(isDatasourceResource) : [];
2867
3298
  }
2868
- function isRenderableToolPart(part, locale, hasCustomRenderer = false) {
3299
+ function isRenderableToolPart(part, locale, hasCustomRenderer = false, hasMemoryProposalClient = false) {
3300
+ if (part.toolType === "memory_proposal") return hasMemoryProposalClient;
2869
3301
  if (hasCustomRenderer || part.toolType !== "datasource") return true;
2870
3302
  if (part.state !== "completed") return true;
2871
3303
  return getDatasourceResourceCards(getDatasourceResources(part), locale).length > 0;
@@ -2879,7 +3311,7 @@ function withParts(message, parts) {
2879
3311
  function AssistantMessage({ message, avatar, footer, messageClassName, contentClassName, toolResultsClassName, toolPartsClassName, contentPartsClassName, messagePartsProps, className,...props }) {
2880
3312
  const toolParts = message.parts.filter((part) => part.type === "tool-call");
2881
3313
  const contentParts = message.parts.filter((part) => part.type !== "tool-call");
2882
- const renderableToolParts = toolParts.filter((part) => isRenderableToolPart(part, messagePartsProps?.locale, Boolean(messagePartsProps?.renderToolCall)));
3314
+ const renderableToolParts = toolParts.filter((part) => isRenderableToolPart(part, messagePartsProps?.locale, Boolean(messagePartsProps?.renderToolCall), Boolean(messagePartsProps?.memoryProposal)));
2883
3315
  const hasContentRow = contentParts.length > 0 || footer !== void 0;
2884
3316
  return /* @__PURE__ */ jsxs("div", {
2885
3317
  className: joinClasses("plai-assistant-message flex w-full flex-col gap-2", className),
@@ -2937,7 +3369,11 @@ function isRoutedMessageProps(props) {
2937
3369
  }
2938
3370
  function Message(props) {
2939
3371
  if (!isRoutedMessageProps(props)) return /* @__PURE__ */ jsx(MessageRoot, { ...props });
2940
- const { message, avatar, footer, messageClassName, contentClassName, partsClassName, toolResultsClassName, toolPartsClassName, messagePartsProps, className,...rootProps } = props;
3372
+ const { message, avatar, footer, messageClassName, contentClassName, partsClassName, toolResultsClassName, toolPartsClassName, messagePartsProps, getResourceDownloadUrl, className,...rootProps } = props;
3373
+ const routedMessagePartsProps = getResourceDownloadUrl ? {
3374
+ ...messagePartsProps,
3375
+ getResourceDownloadUrl
3376
+ } : messagePartsProps;
2941
3377
  if (message.role === "assistant") return /* @__PURE__ */ jsx(AssistantMessage, {
2942
3378
  ...rootProps,
2943
3379
  className,
@@ -2949,7 +3385,7 @@ function Message(props) {
2949
3385
  contentPartsClassName: partsClassName,
2950
3386
  toolResultsClassName,
2951
3387
  toolPartsClassName,
2952
- messagePartsProps
3388
+ messagePartsProps: routedMessagePartsProps
2953
3389
  });
2954
3390
  if (message.role === "user") return /* @__PURE__ */ jsx(UserMessage, {
2955
3391
  ...rootProps,
@@ -2959,7 +3395,7 @@ function Message(props) {
2959
3395
  footer,
2960
3396
  contentClassName,
2961
3397
  partsClassName,
2962
- messagePartsProps
3398
+ messagePartsProps: routedMessagePartsProps
2963
3399
  });
2964
3400
  return /* @__PURE__ */ jsxs(MessageRoot, {
2965
3401
  ...rootProps,
@@ -2968,7 +3404,7 @@ function Message(props) {
2968
3404
  children: [avatar, /* @__PURE__ */ jsxs(MessageContent, {
2969
3405
  className: contentClassName,
2970
3406
  children: [/* @__PURE__ */ jsx(MessageParts, {
2971
- ...messagePartsProps,
3407
+ ...routedMessagePartsProps,
2972
3408
  message,
2973
3409
  className: partsClassName
2974
3410
  }), footer]
@@ -3566,5 +4002,5 @@ async function dummyTranscribeAudio(_audio, signal) {
3566
4002
  }
3567
4003
 
3568
4004
  //#endregion
3569
- export { AggregatedSourceResults, ArrowUp, AssistantMessage, Clipboard, DatasourceFolderCard, DatasourceToolResources, DatasourceToolResultCard, Loader, Message, MessageAvatar, MessageContent, MessageFooter, MessageHeader, MessageParts, MessageRoot, Microphone, PROMPT_FORM_FILE_ACCEPT, Paperclip, PromptForm, PromptFormAttachButton, PromptFormIconButton, Reload, ResourceCard, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, SpeechToTextToggle, Stop, Thinking, ThumbDown, ThumbUp, ToolError, ToolResultAgentInvocationCard, ToolResultBrowserCard, ToolResultCard, ToolResultExternalDatasourceCard, ToolResultHttpRequestCard, ToolResultMcpCard, ToolResultOfficeDocumentsCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, ToolUseIndicator, UserMessage, X, dummyTranscribeAudio, getLocalizedOpenGraphValue, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, isAllowedPromptFormFile, partitionPromptFormFiles, useSpeechToText };
4005
+ export { AggregatedSourceResults, ArrowUp, AssistantMessage, Clipboard, DatasourceFolderCard, DatasourceToolResources, DatasourceToolResultCard, Loader, MemoryProposalCard, Message, MessageAvatar, MessageContent, MessageFooter, MessageHeader, MessageParts, MessageRoot, Microphone, PROMPT_FORM_FILE_ACCEPT, Paperclip, PromptForm, PromptFormAttachButton, PromptFormIconButton, Reload, ResourceCard, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, SpeechToTextToggle, Stop, Thinking, ThumbDown, ThumbUp, ToolError, ToolResultAgentInvocationCard, ToolResultBrowserCard, ToolResultCard, ToolResultExternalDatasourceCard, ToolResultHttpRequestCard, ToolResultMcpCard, ToolResultOfficeDocumentsCard, ToolResultWebSearchCard, ToolResultWorkflowDispatchCard, ToolUseIndicator, UserMessage, X, dummyTranscribeAudio, getLocalizedOpenGraphValue, getResourceDescription, getResourceIcon, getResourceOpenGraphImage, getResourceOpenGraphType, getResourceTitle, getResourceType, getResourceUrl, getToolUseLabel, isAllowedPromptFormFile, partitionPromptFormFiles, useSpeechToText };
3570
4006
  //# sourceMappingURL=index.js.map