@open-mercato/ui 0.10.1-develop.8278.1.f7f8e5ab1a → 0.10.1-develop.8287.1.7313a0fe67
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/.turbo/turbo-build.log +1 -1
- package/dist/ai/AiChat.js +40 -14
- package/dist/ai/AiChat.js.map +2 -2
- package/dist/ai/LoopTracePanel.js +30 -23
- package/dist/ai/LoopTracePanel.js.map +2 -2
- package/dist/ai/citations/merge.js +72 -0
- package/dist/ai/citations/merge.js.map +7 -0
- package/dist/ai/citations/registry.js +97 -0
- package/dist/ai/citations/registry.js.map +7 -0
- package/dist/ai/conversation-store.js +4 -1
- package/dist/ai/conversation-store.js.map +2 -2
- package/dist/ai/index.js +40 -1
- package/dist/ai/index.js.map +2 -2
- package/dist/ai/parts/CitationsPart.js +135 -0
- package/dist/ai/parts/CitationsPart.js.map +7 -0
- package/dist/ai/parts/index.js +2 -0
- package/dist/ai/parts/index.js.map +2 -2
- package/dist/ai/run-trace-link.js +33 -0
- package/dist/ai/run-trace-link.js.map +7 -0
- package/dist/ai/ui-part-registry.js +12 -0
- package/dist/ai/ui-part-registry.js.map +2 -2
- package/dist/ai/useAiChat.js +7 -3
- package/dist/ai/useAiChat.js.map +2 -2
- package/dist/backend/DataTable.js +1 -1
- package/dist/backend/DataTable.js.map +2 -2
- package/dist/backend/detail/AttachmentMetadataDialog.js +137 -101
- package/dist/backend/detail/AttachmentMetadataDialog.js.map +2 -2
- package/dist/backend/detail/DocumentStructurePanel.js +384 -0
- package/dist/backend/detail/DocumentStructurePanel.js.map +7 -0
- package/package.json +3 -3
- package/src/ai/AiChat.tsx +47 -22
- package/src/ai/LoopTracePanel.tsx +44 -10
- package/src/ai/__tests__/AiChat.run-trace.test.tsx +264 -0
- package/src/ai/citations/__tests__/href-safety-cases.ts +33 -0
- package/src/ai/citations/__tests__/registry.test.ts +156 -0
- package/src/ai/citations/merge.ts +83 -0
- package/src/ai/citations/registry.ts +138 -0
- package/src/ai/conversation-store.ts +3 -0
- package/src/ai/index.ts +27 -0
- package/src/ai/parts/CitationsPart.tsx +146 -0
- package/src/ai/parts/__tests__/CitationsPart.test.tsx +105 -0
- package/src/ai/parts/index.ts +1 -0
- package/src/ai/run-trace-link.ts +33 -0
- package/src/ai/ui-part-registry.ts +13 -0
- package/src/ai/useAiChat.ts +13 -5
- package/src/backend/DataTable.tsx +3 -1
- package/src/backend/__tests__/AttachmentMetadataDialog.test.tsx +32 -1
- package/src/backend/__tests__/lazy-heavy-libraries.test.ts +7 -0
- package/src/backend/detail/AttachmentMetadataDialog.tsx +161 -119
- package/src/backend/detail/DocumentStructurePanel.tsx +514 -0
- package/src/backend/detail/__tests__/AttachmentMetadataDialog.tabs.test.tsx +89 -0
- package/src/backend/detail/__tests__/DocumentStructurePanel.test.tsx +153 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
import { ExternalLink } from "lucide-react";
|
|
6
|
+
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
7
|
+
import { Button } from "../../primitives/button.js";
|
|
8
|
+
import {
|
|
9
|
+
fallbackCitation,
|
|
10
|
+
isExternalCitationHref,
|
|
11
|
+
resolveCitation
|
|
12
|
+
} from "../citations/registry.js";
|
|
13
|
+
import { readCitationsPayload } from "../citations/merge.js";
|
|
14
|
+
function CitationQuote({ quote }) {
|
|
15
|
+
const t = useT();
|
|
16
|
+
const [expanded, setExpanded] = React.useState(false);
|
|
17
|
+
const quoteId = React.useId();
|
|
18
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-start gap-1", children: [
|
|
19
|
+
/* @__PURE__ */ jsx(
|
|
20
|
+
"blockquote",
|
|
21
|
+
{
|
|
22
|
+
id: quoteId,
|
|
23
|
+
className: expanded ? "border-l-2 border-border pl-2 text-xs text-muted-foreground" : "line-clamp-3 border-l-2 border-border pl-2 text-xs text-muted-foreground",
|
|
24
|
+
children: quote
|
|
25
|
+
}
|
|
26
|
+
),
|
|
27
|
+
/* @__PURE__ */ jsx(
|
|
28
|
+
Button,
|
|
29
|
+
{
|
|
30
|
+
type: "button",
|
|
31
|
+
variant: "link",
|
|
32
|
+
size: "2xs",
|
|
33
|
+
className: "px-0",
|
|
34
|
+
"aria-expanded": expanded,
|
|
35
|
+
"aria-controls": quoteId,
|
|
36
|
+
onClick: () => setExpanded((value) => !value),
|
|
37
|
+
children: expanded ? t("ui.ai.citations.showLess", "Show less") : t("ui.ai.citations.showMore", "Show more")
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
] });
|
|
41
|
+
}
|
|
42
|
+
function CitationTitle({ resolved }) {
|
|
43
|
+
const t = useT();
|
|
44
|
+
const href = resolved.href;
|
|
45
|
+
if (!href) {
|
|
46
|
+
return /* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: resolved.title });
|
|
47
|
+
}
|
|
48
|
+
const linkClassName = "font-medium text-primary underline-offset-4 hover:underline";
|
|
49
|
+
if (isExternalCitationHref(href)) {
|
|
50
|
+
return /* @__PURE__ */ jsxs(
|
|
51
|
+
"a",
|
|
52
|
+
{
|
|
53
|
+
href,
|
|
54
|
+
target: "_blank",
|
|
55
|
+
rel: "noopener noreferrer",
|
|
56
|
+
className: `inline-flex items-center gap-1 ${linkClassName}`,
|
|
57
|
+
"aria-label": t("ui.ai.citations.openSource", "Open source: {title} (opens in a new tab)", { title: resolved.title }),
|
|
58
|
+
children: [
|
|
59
|
+
/* @__PURE__ */ jsx("span", { children: resolved.title }),
|
|
60
|
+
/* @__PURE__ */ jsx(ExternalLink, { className: "size-3", "aria-hidden": true })
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return /* @__PURE__ */ jsx(Link, { href, className: linkClassName, children: resolved.title });
|
|
66
|
+
}
|
|
67
|
+
function useResolvedCitations(citations) {
|
|
68
|
+
const citationsKey = JSON.stringify(citations);
|
|
69
|
+
const fallbacks = React.useMemo(
|
|
70
|
+
() => JSON.parse(citationsKey).map(fallbackCitation),
|
|
71
|
+
[citationsKey]
|
|
72
|
+
);
|
|
73
|
+
const [resolved, setResolved] = React.useState(null);
|
|
74
|
+
React.useEffect(() => {
|
|
75
|
+
let cancelled = false;
|
|
76
|
+
const pending = JSON.parse(citationsKey);
|
|
77
|
+
Promise.all(pending.map((citation) => resolveCitation(citation))).then((items) => {
|
|
78
|
+
if (!cancelled) setResolved({ key: citationsKey, items });
|
|
79
|
+
}).catch(() => void 0);
|
|
80
|
+
return () => {
|
|
81
|
+
cancelled = true;
|
|
82
|
+
};
|
|
83
|
+
}, [citationsKey]);
|
|
84
|
+
return resolved && resolved.key === citationsKey ? resolved.items : fallbacks;
|
|
85
|
+
}
|
|
86
|
+
function CitationsPart({ payload }) {
|
|
87
|
+
const t = useT();
|
|
88
|
+
const { citations, title } = React.useMemo(() => readCitationsPayload(payload), [payload]);
|
|
89
|
+
const resolved = useResolvedCitations(citations);
|
|
90
|
+
const headingId = React.useId();
|
|
91
|
+
if (citations.length === 0) return null;
|
|
92
|
+
const heading = title ?? t("ui.ai.citations.title", "Sources");
|
|
93
|
+
return /* @__PURE__ */ jsxs(
|
|
94
|
+
"section",
|
|
95
|
+
{
|
|
96
|
+
className: "flex flex-col gap-2 rounded-md border border-border bg-muted/40 p-3 text-sm",
|
|
97
|
+
"aria-labelledby": headingId,
|
|
98
|
+
"data-ai-citations": "",
|
|
99
|
+
children: [
|
|
100
|
+
/* @__PURE__ */ jsx("h4", { id: headingId, className: "text-xs font-medium text-muted-foreground", children: heading }),
|
|
101
|
+
/* @__PURE__ */ jsx("ol", { className: "flex flex-col gap-2", children: citations.map((citation, index) => {
|
|
102
|
+
const entry = resolved[index] ?? fallbackCitation(citation);
|
|
103
|
+
return /* @__PURE__ */ jsxs(
|
|
104
|
+
"li",
|
|
105
|
+
{
|
|
106
|
+
className: "flex gap-2",
|
|
107
|
+
"data-ai-citation-kind": citation.kind,
|
|
108
|
+
children: [
|
|
109
|
+
/* @__PURE__ */ jsxs("span", { className: "shrink-0 font-mono text-xs text-muted-foreground", "aria-hidden": true, children: [
|
|
110
|
+
"[",
|
|
111
|
+
index + 1,
|
|
112
|
+
"]"
|
|
113
|
+
] }),
|
|
114
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-col gap-1", children: [
|
|
115
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-baseline gap-x-2", children: [
|
|
116
|
+
/* @__PURE__ */ jsx(CitationTitle, { resolved: entry }),
|
|
117
|
+
citation.locator ? /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: citation.locator }) : null
|
|
118
|
+
] }),
|
|
119
|
+
citation.quote ? /* @__PURE__ */ jsx(CitationQuote, { quote: citation.quote }) : null
|
|
120
|
+
] })
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
`${citation.kind}:${citation.ref}:${citation.locator ?? ""}`
|
|
124
|
+
);
|
|
125
|
+
}) })
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
var CitationsPart_default = CitationsPart;
|
|
131
|
+
export {
|
|
132
|
+
CitationsPart,
|
|
133
|
+
CitationsPart_default as default
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=CitationsPart.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/ai/parts/CitationsPart.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport { ExternalLink } from 'lucide-react'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Button } from '../../primitives/button'\nimport type { AiUiPartProps } from '../ui-part-registry'\nimport {\n fallbackCitation,\n isExternalCitationHref,\n resolveCitation,\n type AiCitationRef,\n type ResolvedCitation,\n} from '../citations/registry'\nimport { readCitationsPayload } from '../citations/merge'\n\nfunction CitationQuote({ quote }: { quote: string }) {\n const t = useT()\n const [expanded, setExpanded] = React.useState(false)\n const quoteId = React.useId()\n return (\n <div className=\"flex flex-col items-start gap-1\">\n <blockquote\n id={quoteId}\n className={\n expanded\n ? 'border-l-2 border-border pl-2 text-xs text-muted-foreground'\n : 'line-clamp-3 border-l-2 border-border pl-2 text-xs text-muted-foreground'\n }\n >\n {quote}\n </blockquote>\n <Button\n type=\"button\"\n variant=\"link\"\n size=\"2xs\"\n className=\"px-0\"\n aria-expanded={expanded}\n aria-controls={quoteId}\n onClick={() => setExpanded((value) => !value)}\n >\n {expanded\n ? t('ui.ai.citations.showLess', 'Show less')\n : t('ui.ai.citations.showMore', 'Show more')}\n </Button>\n </div>\n )\n}\n\nfunction CitationTitle({ resolved }: { resolved: ResolvedCitation }) {\n const t = useT()\n const href = resolved.href\n if (!href) {\n return <span className=\"font-medium text-foreground\">{resolved.title}</span>\n }\n const linkClassName = 'font-medium text-primary underline-offset-4 hover:underline'\n if (isExternalCitationHref(href)) {\n return (\n <a\n href={href}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className={`inline-flex items-center gap-1 ${linkClassName}`}\n aria-label={t('ui.ai.citations.openSource', 'Open source: {title} (opens in a new tab)', { title: resolved.title })}\n >\n <span>{resolved.title}</span>\n <ExternalLink className=\"size-3\" aria-hidden />\n </a>\n )\n }\n return (\n <Link href={href} className={linkClassName}>\n {resolved.title}\n </Link>\n )\n}\n\nfunction useResolvedCitations(citations: AiCitationRef[]): ResolvedCitation[] {\n const citationsKey = JSON.stringify(citations)\n const fallbacks = React.useMemo(\n () => (JSON.parse(citationsKey) as AiCitationRef[]).map(fallbackCitation),\n [citationsKey],\n )\n const [resolved, setResolved] = React.useState<{ key: string; items: ResolvedCitation[] } | null>(null)\n React.useEffect(() => {\n let cancelled = false\n const pending = JSON.parse(citationsKey) as AiCitationRef[]\n Promise.all(pending.map((citation) => resolveCitation(citation)))\n .then((items) => {\n if (!cancelled) setResolved({ key: citationsKey, items })\n })\n .catch(() => undefined)\n return () => {\n cancelled = true\n }\n }, [citationsKey])\n return resolved && resolved.key === citationsKey ? resolved.items : fallbacks\n}\n\nexport function CitationsPart({ payload }: AiUiPartProps) {\n const t = useT()\n const { citations, title } = React.useMemo(() => readCitationsPayload(payload), [payload])\n const resolved = useResolvedCitations(citations)\n const headingId = React.useId()\n if (citations.length === 0) return null\n const heading = title ?? t('ui.ai.citations.title', 'Sources')\n return (\n <section\n className=\"flex flex-col gap-2 rounded-md border border-border bg-muted/40 p-3 text-sm\"\n aria-labelledby={headingId}\n data-ai-citations=\"\"\n >\n <h4 id={headingId} className=\"text-xs font-medium text-muted-foreground\">\n {heading}\n </h4>\n <ol className=\"flex flex-col gap-2\">\n {citations.map((citation, index) => {\n const entry = resolved[index] ?? fallbackCitation(citation)\n return (\n <li\n key={`${citation.kind}:${citation.ref}:${citation.locator ?? ''}`}\n className=\"flex gap-2\"\n data-ai-citation-kind={citation.kind}\n >\n <span className=\"shrink-0 font-mono text-xs text-muted-foreground\" aria-hidden>\n [{index + 1}]\n </span>\n <div className=\"flex min-w-0 flex-col gap-1\">\n <div className=\"flex flex-wrap items-baseline gap-x-2\">\n <CitationTitle resolved={entry} />\n {citation.locator ? (\n <span className=\"text-xs text-muted-foreground\">{citation.locator}</span>\n ) : null}\n </div>\n {citation.quote ? <CitationQuote quote={citation.quote} /> : null}\n </div>\n </li>\n )\n })}\n </ol>\n </section>\n )\n}\n\nexport default CitationsPart\n"],
|
|
5
|
+
"mappings": ";AAsBI,SACE,KADF;AApBJ,YAAY,WAAW;AACvB,OAAO,UAAU;AACjB,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AACrB,SAAS,cAAc;AAEvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,4BAA4B;AAErC,SAAS,cAAc,EAAE,MAAM,GAAsB;A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AmD,eAAW,MAAC;AAAA;AAAA,kBAC3E,QAAQ;AAAA,kBAAE;AAAA,mBACd;AAAA,gBACA,qBAAC,SAAI,WAAU,+BACb;AAAA,uCAAC,SAAI,WAAU,yCACb;AAAA,wCAAC,iBAAc,UAAU,OAAO;AAAA,oBAC/B,SAAS,UACR,oBAAC,UAAK,WAAU,iCAAiC,mBAAS,SAAQ,IAChE;AAAA,qBACN;AAAA,kBACC,SAAS,QAAQ,oBAAC,iBAAc,OAAO,SAAS,OAAO,IAAK;AAAA,mBAC/D;AAAA;AAAA;AAAA,YAfK,GAAG,SAAS,IAAI,IAAI,SAAS,GAAG,IAAI,SAAS,WAAW,EAAE;AAAA,UAgBjE;AAAA,QAEJ,CAAC,GACH;AAAA;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,wBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/ai/parts/index.js
CHANGED
|
@@ -11,8 +11,10 @@ import {
|
|
|
11
11
|
cancelPendingAction
|
|
12
12
|
} from "./pending-action-api.js";
|
|
13
13
|
import { AI_MUTATION_APPROVAL_CARDS } from "./approval-cards-map.js";
|
|
14
|
+
import { CitationsPart } from "./CitationsPart.js";
|
|
14
15
|
export {
|
|
15
16
|
AI_MUTATION_APPROVAL_CARDS,
|
|
17
|
+
CitationsPart,
|
|
16
18
|
ConfirmationCard,
|
|
17
19
|
FieldDiffCard,
|
|
18
20
|
MutationPreviewCard,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/ai/parts/index.ts"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nexport { MutationPreviewCard } from './MutationPreviewCard'\nexport { FieldDiffCard } from './FieldDiffCard'\nexport { ConfirmationCard } from './ConfirmationCard'\nexport { MutationResultCard } from './MutationResultCard'\nexport {\n useAiPendingActionPolling,\n type UseAiPendingActionPollingOptions,\n type UseAiPendingActionPollingResult,\n} from './useAiPendingActionPolling'\nexport {\n confirmPendingAction,\n cancelPendingAction,\n type PendingActionMutationOk,\n type PendingActionMutationError,\n type PendingActionMutationResult,\n} from './pending-action-api'\nexport type {\n AiPendingActionCardAction,\n AiPendingActionCardStatus,\n AiPendingActionCardFieldDiff,\n AiPendingActionCardRecordDiff,\n AiPendingActionCardFailedRecord,\n AiPendingActionCardExecutionResult,\n} from './types'\nexport { AI_MUTATION_APPROVAL_CARDS } from './approval-cards-map'\n"],
|
|
5
|
-
"mappings": ";AAEA,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AASP,SAAS,kCAAkC;",
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nexport { MutationPreviewCard } from './MutationPreviewCard'\nexport { FieldDiffCard } from './FieldDiffCard'\nexport { ConfirmationCard } from './ConfirmationCard'\nexport { MutationResultCard } from './MutationResultCard'\nexport {\n useAiPendingActionPolling,\n type UseAiPendingActionPollingOptions,\n type UseAiPendingActionPollingResult,\n} from './useAiPendingActionPolling'\nexport {\n confirmPendingAction,\n cancelPendingAction,\n type PendingActionMutationOk,\n type PendingActionMutationError,\n type PendingActionMutationResult,\n} from './pending-action-api'\nexport type {\n AiPendingActionCardAction,\n AiPendingActionCardStatus,\n AiPendingActionCardFieldDiff,\n AiPendingActionCardRecordDiff,\n AiPendingActionCardFailedRecord,\n AiPendingActionCardExecutionResult,\n} from './types'\nexport { AI_MUTATION_APPROVAL_CARDS } from './approval-cards-map'\nexport { CitationsPart } from './CitationsPart'\n"],
|
|
5
|
+
"mappings": ";AAEA,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AASP,SAAS,kCAAkC;AAC3C,SAAS,qBAAqB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { hasFeature } from "@open-mercato/shared/security/features";
|
|
3
|
+
import { useBackendChrome } from "../backend/BackendChromeProvider.js";
|
|
4
|
+
const AI_ASSISTANT_RUNS_VIEW_FEATURE = "ai_assistant.runs.view";
|
|
5
|
+
const AI_RUN_DETAIL_PATH = "/backend/config/ai-assistant/runs";
|
|
6
|
+
function readNonEmptyString(value) {
|
|
7
|
+
if (typeof value !== "string") return null;
|
|
8
|
+
const trimmed = value.trim();
|
|
9
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
10
|
+
}
|
|
11
|
+
function readRunIdFromLoopTrace(trace) {
|
|
12
|
+
if (!trace || typeof trace !== "object") return null;
|
|
13
|
+
return readNonEmptyString(trace.runId);
|
|
14
|
+
}
|
|
15
|
+
function readRunIdFromMessageMetadata(metadata) {
|
|
16
|
+
if (!metadata || typeof metadata !== "object") return null;
|
|
17
|
+
return readNonEmptyString(metadata.runId);
|
|
18
|
+
}
|
|
19
|
+
function buildAiRunTraceHref(runId) {
|
|
20
|
+
return `${AI_RUN_DETAIL_PATH}/${encodeURIComponent(runId)}`;
|
|
21
|
+
}
|
|
22
|
+
function useCanViewAiRunTrace() {
|
|
23
|
+
const { payload } = useBackendChrome();
|
|
24
|
+
return hasFeature(payload?.grantedFeatures, AI_ASSISTANT_RUNS_VIEW_FEATURE);
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
AI_ASSISTANT_RUNS_VIEW_FEATURE,
|
|
28
|
+
buildAiRunTraceHref,
|
|
29
|
+
readRunIdFromLoopTrace,
|
|
30
|
+
readRunIdFromMessageMetadata,
|
|
31
|
+
useCanViewAiRunTrace
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=run-trace-link.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ai/run-trace-link.ts"],
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport { hasFeature } from '@open-mercato/shared/security/features'\nimport { useBackendChrome } from '../backend/BackendChromeProvider'\n\nexport const AI_ASSISTANT_RUNS_VIEW_FEATURE = 'ai_assistant.runs.view'\n\nconst AI_RUN_DETAIL_PATH = '/backend/config/ai-assistant/runs'\n\nfunction readNonEmptyString(value: unknown): string | null {\n if (typeof value !== 'string') return null\n const trimmed = value.trim()\n return trimmed.length > 0 ? trimmed : null\n}\n\nexport function readRunIdFromLoopTrace(trace: unknown): string | null {\n if (!trace || typeof trace !== 'object') return null\n return readNonEmptyString((trace as { runId?: unknown }).runId)\n}\n\nexport function readRunIdFromMessageMetadata(metadata: unknown): string | null {\n if (!metadata || typeof metadata !== 'object') return null\n return readNonEmptyString((metadata as { runId?: unknown }).runId)\n}\n\nexport function buildAiRunTraceHref(runId: string): string {\n return `${AI_RUN_DETAIL_PATH}/${encodeURIComponent(runId)}`\n}\n\nexport function useCanViewAiRunTrace(): boolean {\n const { payload } = useBackendChrome()\n return hasFeature(payload?.grantedFeatures, AI_ASSISTANT_RUNS_VIEW_FEATURE)\n}\n"],
|
|
5
|
+
"mappings": ";AAEA,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AAE1B,MAAM,iCAAiC;AAE9C,MAAM,qBAAqB;AAE3B,SAAS,mBAAmB,OAA+B;AACzD,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAM,UAAU,MAAM,KAAK;AAC3B,SAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEO,SAAS,uBAAuB,OAA+B;AACpE,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,SAAO,mBAAoB,MAA8B,KAAK;AAChE;AAEO,SAAS,6BAA6B,UAAkC;AAC7E,MAAI,CAAC,YAAY,OAAO,aAAa,SAAU,QAAO;AACtD,SAAO,mBAAoB,SAAiC,KAAK;AACnE;AAEO,SAAS,oBAAoB,OAAuB;AACzD,SAAO,GAAG,kBAAkB,IAAI,mBAAmB,KAAK,CAAC;AAC3D;AAEO,SAAS,uBAAgC;AAC9C,QAAM,EAAE,QAAQ,IAAI,iBAAiB;AACrC,SAAO,WAAW,SAAS,iBAAiB,8BAA8B;AAC5E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -5,6 +5,12 @@ import {
|
|
|
5
5
|
} from "./ui-part-slots.js";
|
|
6
6
|
import { PendingPhase3Placeholder } from "./ui-parts/pending-phase3-placeholder.js";
|
|
7
7
|
import { AI_MUTATION_APPROVAL_CARDS } from "./parts/approval-cards-map.js";
|
|
8
|
+
import { CitationsPart } from "./parts/CitationsPart.js";
|
|
9
|
+
import { AI_CITATIONS_COMPONENT_ID } from "./citations/registry.js";
|
|
10
|
+
function seedLiveBuiltInParts(store) {
|
|
11
|
+
if (store.has(AI_CITATIONS_COMPONENT_ID)) return;
|
|
12
|
+
store.set(AI_CITATIONS_COMPONENT_ID, CitationsPart);
|
|
13
|
+
}
|
|
8
14
|
function seedReservedSlots(store, options = { seedLive: false }) {
|
|
9
15
|
for (const reservedId of RESERVED_AI_UI_PART_IDS) {
|
|
10
16
|
if (store.has(reservedId)) continue;
|
|
@@ -28,6 +34,9 @@ function createAiUiPartRegistry(options) {
|
|
|
28
34
|
if (seedReserved) {
|
|
29
35
|
seedReservedSlots(store, { seedLive });
|
|
30
36
|
}
|
|
37
|
+
if (seedLive) {
|
|
38
|
+
seedLiveBuiltInParts(store);
|
|
39
|
+
}
|
|
31
40
|
const registry = {
|
|
32
41
|
register(componentId, component) {
|
|
33
42
|
if (!componentId) {
|
|
@@ -61,6 +70,9 @@ function createAiUiPartRegistry(options) {
|
|
|
61
70
|
if (seedReserved) {
|
|
62
71
|
seedReservedSlots(store, { seedLive });
|
|
63
72
|
}
|
|
73
|
+
if (seedLive) {
|
|
74
|
+
seedLiveBuiltInParts(store);
|
|
75
|
+
}
|
|
64
76
|
}
|
|
65
77
|
};
|
|
66
78
|
return registry;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ai/ui-part-registry.ts"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport type { ComponentType } from 'react'\nimport {\n RESERVED_AI_UI_PART_IDS,\n isReservedAiUiPartId,\n type ReservedAiUiPartId,\n} from './ui-part-slots'\nimport { PendingPhase3Placeholder } from './ui-parts/pending-phase3-placeholder'\nimport { AI_MUTATION_APPROVAL_CARDS } from './parts/approval-cards-map'\n\nexport { RESERVED_AI_UI_PART_IDS, isReservedAiUiPartId }\nexport type { ReservedAiUiPartId }\n\nexport type AiUiPartComponentId = ReservedAiUiPartId | (string & {})\n\nexport type AiUiPartProps = {\n /** Stable component id emitted by the server-side UI-part producer. */\n componentId: AiUiPartComponentId\n /** Arbitrary payload the server attached to this UI part. */\n payload?: unknown\n /** Optional pending-action id for mutation-approval cards (Phase 3). */\n pendingActionId?: string\n}\n\nexport type AiUiPartComponent<P = AiUiPartProps> = ComponentType<P>\n\nexport interface AiUiPartRegistryEntry {\n componentId: string\n reserved: boolean\n}\n\n/**\n * A UI-part registry instance. Consumers typically use\n * {@link defaultAiUiPartRegistry} for global registrations; tests and embedded\n * pages that need isolation can construct a dedicated registry via\n * {@link createAiUiPartRegistry} and pass it to `<AiChat registry={...} />`.\n */\nexport interface AiUiPartRegistry {\n register<P = AiUiPartProps>(\n componentId: AiUiPartComponentId,\n component: AiUiPartComponent<P>,\n ): void\n unregister(componentId: AiUiPartComponentId): void\n resolve<P = AiUiPartProps>(\n componentId: AiUiPartComponentId,\n ): AiUiPartComponent<P> | null\n has(componentId: AiUiPartComponentId): boolean\n list(): AiUiPartRegistryEntry[]\n clear(): void\n}\n\ntype RegistryStore = Map<string, AiUiPartComponent<AiUiPartProps>>\n\nexport interface CreateAiUiPartRegistryOptions {\n /**\n * When true (default) the registry is pre-seeded with the shared\n * `PendingPhase3Placeholder` for every id in {@link RESERVED_AI_UI_PART_IDS}.\n * Pass `false` to get an empty registry \u2014 useful for tests that want to\n * assert the registry is genuinely empty.\n */\n seedReservedPlaceholders?: boolean\n /**\n * When true, the registry is pre-seeded with the live Phase 3 mutation\n * approval cards from `@open-mercato/ui/ai/parts` instead of the humane\n * pending placeholder. The app-wide {@link defaultAiUiPartRegistry}\n * opts in, so end users see the real cards without any bootstrap wiring;\n * scoped registries created via {@link createAiUiPartRegistry} keep the\n * placeholder by default so unit tests and embedded playground mounts\n * stay deterministic and isolated.\n */\n seedLiveApprovalCards?: boolean\n}\n\nfunction seedReservedSlots(\n store: RegistryStore,\n options: { seedLive: boolean } = { seedLive: false },\n): void {\n for (const reservedId of RESERVED_AI_UI_PART_IDS) {\n if (store.has(reservedId)) continue\n if (options.seedLive && AI_MUTATION_APPROVAL_CARDS[reservedId]) {\n store.set(\n reservedId,\n AI_MUTATION_APPROVAL_CARDS[reservedId] as AiUiPartComponent<AiUiPartProps>,\n )\n continue\n }\n store.set(\n reservedId,\n PendingPhase3Placeholder as AiUiPartComponent<AiUiPartProps>,\n )\n }\n}\n\n/**\n * Create a fresh UI-part registry. By default the four Phase 3 reserved\n * slot ids are pre-seeded with {@link PendingPhase3Placeholder} so consumers\n * that forget to register the real cards see a humane \"Phase 3 pending\"\n * state instead of the neutral debug chip.\n */\nexport function createAiUiPartRegistry(\n options?: CreateAiUiPartRegistryOptions,\n): AiUiPartRegistry {\n const seedReserved = options?.seedReservedPlaceholders !== false\n const seedLive = options?.seedLiveApprovalCards === true\n const store: RegistryStore = new Map()\n if (seedReserved) {\n seedReservedSlots(store, { seedLive })\n }\n\n const registry: AiUiPartRegistry = {\n register(componentId, component) {\n if (!componentId) {\n throw new Error('registerAiUiPart requires a non-empty componentId')\n }\n store.set(componentId, component as AiUiPartComponent<AiUiPartProps>)\n },\n unregister(componentId) {\n store.delete(componentId)\n },\n resolve<P = AiUiPartProps>(componentId: AiUiPartComponentId) {\n const found = store.get(componentId)\n if (!found) return null\n return found as unknown as AiUiPartComponent<P>\n },\n has(componentId) {\n return store.has(componentId)\n },\n list() {\n const entries: AiUiPartRegistryEntry[] = []\n for (const componentId of store.keys()) {\n entries.push({\n componentId,\n reserved: isReservedAiUiPartId(componentId),\n })\n }\n return entries\n },\n clear() {\n store.clear()\n if (seedReserved) {\n seedReservedSlots(store, { seedLive })\n }\n },\n }\n return registry\n}\n\nconst REGISTRY_GLOBAL_KEY = '__openMercatoAiUiPartRegistry'\n\nfunction getDefaultRegistry(): AiUiPartRegistry {\n const scope = globalThis as typeof globalThis & {\n [REGISTRY_GLOBAL_KEY]?: AiUiPartRegistry\n }\n if (!scope[REGISTRY_GLOBAL_KEY]) {\n // Default registry seeds the LIVE mutation-approval cards (Step 5.10).\n // Scoped registries created via `createAiUiPartRegistry()` still default\n // to the humane placeholder so playground embeds + unit tests stay\n // deterministic and isolated.\n scope[REGISTRY_GLOBAL_KEY] = createAiUiPartRegistry({ seedLiveApprovalCards: true })\n }\n return scope[REGISTRY_GLOBAL_KEY]\n}\n\n/**\n * The app-wide default UI-part registry. Seeded with Phase 3 placeholders on\n * first access. Tests that need a clean registry should instantiate their own\n * via {@link createAiUiPartRegistry} and pass it to `<AiChat registry={...}>`.\n */\nexport const defaultAiUiPartRegistry: AiUiPartRegistry = new Proxy(\n {} as AiUiPartRegistry,\n {\n get(_target, prop: keyof AiUiPartRegistry) {\n const impl = getDefaultRegistry()\n const value = impl[prop]\n return typeof value === 'function' ? value.bind(impl) : value\n },\n },\n)\n\n/**\n * Register a UI-part component on the module-global default registry. Legacy\n * Step 4.1 API \u2014 preserved verbatim so existing callers keep working. Prefer\n * {@link defaultAiUiPartRegistry} directly (or a scoped registry) in new code.\n *\n * Idempotent: re-registering overwrites the previous entry so hot reload and\n * Phase 3 card replacement (which overwrites the seeded placeholder) stay\n * deterministic.\n */\nexport function registerAiUiPart<P = AiUiPartProps>(\n componentId: AiUiPartComponentId,\n component: AiUiPartComponent<P>,\n): void {\n defaultAiUiPartRegistry.register(componentId, component)\n}\n\n/**\n * Resolve a registered UI-part component on the module-global default\n * registry. Returns `null` when no component has been registered \u2014 callers\n * MUST handle the null case gracefully (the canonical consumer, `<AiChat>`,\n * renders a neutral placeholder chip + logs a `console.warn`).\n */\nexport function resolveAiUiPart<P = AiUiPartProps>(\n componentId: AiUiPartComponentId,\n): AiUiPartComponent<P> | null {\n return defaultAiUiPartRegistry.resolve<P>(componentId)\n}\n\n/**\n * Remove a UI-part component registration from the module-global default\n * registry. Primarily useful for tests to keep a clean slate between runs.\n */\nexport function unregisterAiUiPart(componentId: AiUiPartComponentId): void {\n defaultAiUiPartRegistry.unregister(componentId)\n}\n\n/**\n * Clear every registration on the module-global default registry and re-seed\n * the Phase 3 reserved placeholders. Test-only helper; production code must\n * never invoke this.\n */\nexport function resetAiUiPartRegistryForTests(): void {\n defaultAiUiPartRegistry.clear()\n}\n\n/**\n * Snapshot every registration on the module-global default registry. Used by\n * debugging UIs (Step 4.6) to enumerate what's registered without mutating\n * state.\n */\nexport function listAiUiParts(): AiUiPartRegistryEntry[] {\n return defaultAiUiPartRegistry.list()\n}\n"],
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,gCAAgC;AACzC,SAAS,kCAAkC;
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport type { ComponentType } from 'react'\nimport {\n RESERVED_AI_UI_PART_IDS,\n isReservedAiUiPartId,\n type ReservedAiUiPartId,\n} from './ui-part-slots'\nimport { PendingPhase3Placeholder } from './ui-parts/pending-phase3-placeholder'\nimport { AI_MUTATION_APPROVAL_CARDS } from './parts/approval-cards-map'\nimport { CitationsPart } from './parts/CitationsPart'\nimport { AI_CITATIONS_COMPONENT_ID } from './citations/registry'\n\nexport { RESERVED_AI_UI_PART_IDS, isReservedAiUiPartId }\nexport type { ReservedAiUiPartId }\n\nexport type AiUiPartComponentId = ReservedAiUiPartId | (string & {})\n\nexport type AiUiPartProps = {\n /** Stable component id emitted by the server-side UI-part producer. */\n componentId: AiUiPartComponentId\n /** Arbitrary payload the server attached to this UI part. */\n payload?: unknown\n /** Optional pending-action id for mutation-approval cards (Phase 3). */\n pendingActionId?: string\n}\n\nexport type AiUiPartComponent<P = AiUiPartProps> = ComponentType<P>\n\nexport interface AiUiPartRegistryEntry {\n componentId: string\n reserved: boolean\n}\n\n/**\n * A UI-part registry instance. Consumers typically use\n * {@link defaultAiUiPartRegistry} for global registrations; tests and embedded\n * pages that need isolation can construct a dedicated registry via\n * {@link createAiUiPartRegistry} and pass it to `<AiChat registry={...} />`.\n */\nexport interface AiUiPartRegistry {\n register<P = AiUiPartProps>(\n componentId: AiUiPartComponentId,\n component: AiUiPartComponent<P>,\n ): void\n unregister(componentId: AiUiPartComponentId): void\n resolve<P = AiUiPartProps>(\n componentId: AiUiPartComponentId,\n ): AiUiPartComponent<P> | null\n has(componentId: AiUiPartComponentId): boolean\n list(): AiUiPartRegistryEntry[]\n clear(): void\n}\n\ntype RegistryStore = Map<string, AiUiPartComponent<AiUiPartProps>>\n\nexport interface CreateAiUiPartRegistryOptions {\n /**\n * When true (default) the registry is pre-seeded with the shared\n * `PendingPhase3Placeholder` for every id in {@link RESERVED_AI_UI_PART_IDS}.\n * Pass `false` to get an empty registry \u2014 useful for tests that want to\n * assert the registry is genuinely empty.\n */\n seedReservedPlaceholders?: boolean\n /**\n * When true, the registry is pre-seeded with the live Phase 3 mutation\n * approval cards from `@open-mercato/ui/ai/parts` instead of the humane\n * pending placeholder. The app-wide {@link defaultAiUiPartRegistry}\n * opts in, so end users see the real cards without any bootstrap wiring;\n * scoped registries created via {@link createAiUiPartRegistry} keep the\n * placeholder by default so unit tests and embedded playground mounts\n * stay deterministic and isolated.\n */\n seedLiveApprovalCards?: boolean\n}\n\nfunction seedLiveBuiltInParts(store: RegistryStore): void {\n if (store.has(AI_CITATIONS_COMPONENT_ID)) return\n store.set(AI_CITATIONS_COMPONENT_ID, CitationsPart as AiUiPartComponent<AiUiPartProps>)\n}\n\nfunction seedReservedSlots(\n store: RegistryStore,\n options: { seedLive: boolean } = { seedLive: false },\n): void {\n for (const reservedId of RESERVED_AI_UI_PART_IDS) {\n if (store.has(reservedId)) continue\n if (options.seedLive && AI_MUTATION_APPROVAL_CARDS[reservedId]) {\n store.set(\n reservedId,\n AI_MUTATION_APPROVAL_CARDS[reservedId] as AiUiPartComponent<AiUiPartProps>,\n )\n continue\n }\n store.set(\n reservedId,\n PendingPhase3Placeholder as AiUiPartComponent<AiUiPartProps>,\n )\n }\n}\n\n/**\n * Create a fresh UI-part registry. By default the four Phase 3 reserved\n * slot ids are pre-seeded with {@link PendingPhase3Placeholder} so consumers\n * that forget to register the real cards see a humane \"Phase 3 pending\"\n * state instead of the neutral debug chip.\n */\nexport function createAiUiPartRegistry(\n options?: CreateAiUiPartRegistryOptions,\n): AiUiPartRegistry {\n const seedReserved = options?.seedReservedPlaceholders !== false\n const seedLive = options?.seedLiveApprovalCards === true\n const store: RegistryStore = new Map()\n if (seedReserved) {\n seedReservedSlots(store, { seedLive })\n }\n if (seedLive) {\n seedLiveBuiltInParts(store)\n }\n\n const registry: AiUiPartRegistry = {\n register(componentId, component) {\n if (!componentId) {\n throw new Error('registerAiUiPart requires a non-empty componentId')\n }\n store.set(componentId, component as AiUiPartComponent<AiUiPartProps>)\n },\n unregister(componentId) {\n store.delete(componentId)\n },\n resolve<P = AiUiPartProps>(componentId: AiUiPartComponentId) {\n const found = store.get(componentId)\n if (!found) return null\n return found as unknown as AiUiPartComponent<P>\n },\n has(componentId) {\n return store.has(componentId)\n },\n list() {\n const entries: AiUiPartRegistryEntry[] = []\n for (const componentId of store.keys()) {\n entries.push({\n componentId,\n reserved: isReservedAiUiPartId(componentId),\n })\n }\n return entries\n },\n clear() {\n store.clear()\n if (seedReserved) {\n seedReservedSlots(store, { seedLive })\n }\n if (seedLive) {\n seedLiveBuiltInParts(store)\n }\n },\n }\n return registry\n}\n\nconst REGISTRY_GLOBAL_KEY = '__openMercatoAiUiPartRegistry'\n\nfunction getDefaultRegistry(): AiUiPartRegistry {\n const scope = globalThis as typeof globalThis & {\n [REGISTRY_GLOBAL_KEY]?: AiUiPartRegistry\n }\n if (!scope[REGISTRY_GLOBAL_KEY]) {\n // Default registry seeds the LIVE mutation-approval cards (Step 5.10).\n // Scoped registries created via `createAiUiPartRegistry()` still default\n // to the humane placeholder so playground embeds + unit tests stay\n // deterministic and isolated.\n scope[REGISTRY_GLOBAL_KEY] = createAiUiPartRegistry({ seedLiveApprovalCards: true })\n }\n return scope[REGISTRY_GLOBAL_KEY]\n}\n\n/**\n * The app-wide default UI-part registry. Seeded with Phase 3 placeholders on\n * first access. Tests that need a clean registry should instantiate their own\n * via {@link createAiUiPartRegistry} and pass it to `<AiChat registry={...}>`.\n */\nexport const defaultAiUiPartRegistry: AiUiPartRegistry = new Proxy(\n {} as AiUiPartRegistry,\n {\n get(_target, prop: keyof AiUiPartRegistry) {\n const impl = getDefaultRegistry()\n const value = impl[prop]\n return typeof value === 'function' ? value.bind(impl) : value\n },\n },\n)\n\n/**\n * Register a UI-part component on the module-global default registry. Legacy\n * Step 4.1 API \u2014 preserved verbatim so existing callers keep working. Prefer\n * {@link defaultAiUiPartRegistry} directly (or a scoped registry) in new code.\n *\n * Idempotent: re-registering overwrites the previous entry so hot reload and\n * Phase 3 card replacement (which overwrites the seeded placeholder) stay\n * deterministic.\n */\nexport function registerAiUiPart<P = AiUiPartProps>(\n componentId: AiUiPartComponentId,\n component: AiUiPartComponent<P>,\n): void {\n defaultAiUiPartRegistry.register(componentId, component)\n}\n\n/**\n * Resolve a registered UI-part component on the module-global default\n * registry. Returns `null` when no component has been registered \u2014 callers\n * MUST handle the null case gracefully (the canonical consumer, `<AiChat>`,\n * renders a neutral placeholder chip + logs a `console.warn`).\n */\nexport function resolveAiUiPart<P = AiUiPartProps>(\n componentId: AiUiPartComponentId,\n): AiUiPartComponent<P> | null {\n return defaultAiUiPartRegistry.resolve<P>(componentId)\n}\n\n/**\n * Remove a UI-part component registration from the module-global default\n * registry. Primarily useful for tests to keep a clean slate between runs.\n */\nexport function unregisterAiUiPart(componentId: AiUiPartComponentId): void {\n defaultAiUiPartRegistry.unregister(componentId)\n}\n\n/**\n * Clear every registration on the module-global default registry and re-seed\n * the Phase 3 reserved placeholders. Test-only helper; production code must\n * never invoke this.\n */\nexport function resetAiUiPartRegistryForTests(): void {\n defaultAiUiPartRegistry.clear()\n}\n\n/**\n * Snapshot every registration on the module-global default registry. Used by\n * debugging UIs (Step 4.6) to enumerate what's registered without mutating\n * state.\n */\nexport function listAiUiParts(): AiUiPartRegistryEntry[] {\n return defaultAiUiPartRegistry.list()\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,gCAAgC;AACzC,SAAS,kCAAkC;AAC3C,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AAiE1C,SAAS,qBAAqB,OAA4B;AACxD,MAAI,MAAM,IAAI,yBAAyB,EAAG;AAC1C,QAAM,IAAI,2BAA2B,aAAiD;AACxF;AAEA,SAAS,kBACP,OACA,UAAiC,EAAE,UAAU,MAAM,GAC7C;AACN,aAAW,cAAc,yBAAyB;AAChD,QAAI,MAAM,IAAI,UAAU,EAAG;AAC3B,QAAI,QAAQ,YAAY,2BAA2B,UAAU,GAAG;AAC9D,YAAM;AAAA,QACJ;AAAA,QACA,2BAA2B,UAAU;AAAA,MACvC;AACA;AAAA,IACF;AACA,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAQO,SAAS,uBACd,SACkB;AAClB,QAAM,eAAe,SAAS,6BAA6B;AAC3D,QAAM,WAAW,SAAS,0BAA0B;AACpD,QAAM,QAAuB,oBAAI,IAAI;AACrC,MAAI,cAAc;AAChB,sBAAkB,OAAO,EAAE,SAAS,CAAC;AAAA,EACvC;AACA,MAAI,UAAU;AACZ,yBAAqB,KAAK;AAAA,EAC5B;AAEA,QAAM,WAA6B;AAAA,IACjC,S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AAS,aAAa,SAAS;AACzD;AAQO,SAAS,gBACd,aAC6B;AAC7B,SAAO,wBAAwB,QAAW,WAAW;AACvD;AAMO,SAAS,mBAAmB,aAAwC;AACzE,0BAAwB,WAAW,WAAW;AAChD;AAOO,SAAS,gCAAsC;AACpD,0BAAwB,MAAM;AAChC;AAOO,SAAS,gBAAyC;AACvD,SAAO,wBAAwB,KAAK;AACtC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/ai/useAiChat.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { createAiAgentTransport } from "@open-mercato/ai-assistant/modules/ai_assistant/lib/agent-transport";
|
|
4
4
|
import { apiFetch } from "../backend/utils/api.js";
|
|
5
|
+
import { readRunIdFromLoopTrace } from "./run-trace-link.js";
|
|
5
6
|
import {
|
|
6
7
|
createAiServerConversation,
|
|
7
8
|
importAiLocalConversation,
|
|
@@ -793,10 +794,13 @@ function useAiChat(input) {
|
|
|
793
794
|
}
|
|
794
795
|
builder = { ...builder, reasoningStreaming: false };
|
|
795
796
|
const finalSnapshot = builder;
|
|
797
|
+
const turnRunId = readRunIdFromLoopTrace(pendingLoopTrace);
|
|
796
798
|
updateMessages(
|
|
797
|
-
(current) => current.map(
|
|
798
|
-
(entry
|
|
799
|
-
|
|
799
|
+
(current) => current.map((entry) => {
|
|
800
|
+
if (entry.id !== assistantId) return entry;
|
|
801
|
+
const merged = mergeAssistantMessage(entry, finalSnapshot);
|
|
802
|
+
return turnRunId ? { ...merged, runId: turnRunId } : merged;
|
|
803
|
+
}),
|
|
800
804
|
{ persistWhenUnmounted: true }
|
|
801
805
|
);
|
|
802
806
|
if (mountedRef.current) {
|