@plaisolutions/react 0.24.0 → 0.24.2
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/README.md +4 -0
- package/dist/components/index.d.ts +43 -34
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +9 -3
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +113 -93
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -81,7 +81,9 @@ function useChat(options) {
|
|
|
81
81
|
initialMessages: optionsRef.current.initialMessages,
|
|
82
82
|
generateId: () => optionsRef.current.generateId?.() ?? `local_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`,
|
|
83
83
|
onEvent: (event) => optionsRef.current.onEvent?.(event),
|
|
84
|
-
onError: (error) => optionsRef.current.onError?.(error)
|
|
84
|
+
onError: (error) => optionsRef.current.onError?.(error),
|
|
85
|
+
uiActionHandlers: () => optionsRef.current.uiActionHandlers,
|
|
86
|
+
onUiActionIssue: (issue) => optionsRef.current.onUiActionIssue?.(issue)
|
|
85
87
|
});
|
|
86
88
|
}, [
|
|
87
89
|
external,
|
|
@@ -97,6 +99,11 @@ function useChat(options) {
|
|
|
97
99
|
owned.stop();
|
|
98
100
|
};
|
|
99
101
|
}, [owned]);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!owned) return;
|
|
104
|
+
const saved = optionsRef.current.initialMessages;
|
|
105
|
+
if (saved?.length) owned.uiActions.replay(saved);
|
|
106
|
+
}, [owned]);
|
|
100
107
|
const actions = useMemo(() => ({
|
|
101
108
|
sendMessage: chat.sendMessage.bind(chat),
|
|
102
109
|
decideToolActions: chat.decideToolActions.bind(chat),
|
|
@@ -111,7 +118,10 @@ function useChat(options) {
|
|
|
111
118
|
uploadFile: chat.uploadFile.bind(chat),
|
|
112
119
|
stop: chat.stop.bind(chat),
|
|
113
120
|
reset: chat.reset.bind(chat),
|
|
114
|
-
hydrate:
|
|
121
|
+
hydrate: (messages) => {
|
|
122
|
+
chat.hydrate(messages);
|
|
123
|
+
chat.uiActions.replay(messages);
|
|
124
|
+
},
|
|
115
125
|
clearError: chat.clearError.bind(chat)
|
|
116
126
|
}), [chat]);
|
|
117
127
|
return {
|
|
@@ -8243,7 +8253,7 @@ function aggregateSourceToolParts(parts, position) {
|
|
|
8243
8253
|
...remainingParts.slice(insertionIndex)
|
|
8244
8254
|
];
|
|
8245
8255
|
}
|
|
8246
|
-
function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD, sourceToolResultsLayout = "aggregated", sourceToolResultsPosition, maxVisibleSourceCards = 3, datasourceToolResultsPosition, onOpenAgentThread, getResourceDownloadUrl, locale, memoryProposal, toolConfirmation, renderText, renderToolCall, renderThinking, isStreaming = false, resolveFileLinks = true, thinkingLabel, completedThinkingLabel, readMoreLabel, readLessLabel, className,...props }) {
|
|
8256
|
+
function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD, sourceToolResultsLayout = "aggregated", sourceToolResultsPosition, maxVisibleSourceCards = 3, datasourceToolResultsPosition, onOpenAgentThread, getResourceDownloadUrl, locale, memoryProposal, toolConfirmation, renderText, renderToolCall, renderThinking, isStreaming = false, resolveFileLinks = true, generatedFiles, thinkingLabel, completedThinkingLabel, readMoreLabel, readLessLabel, className,...props }) {
|
|
8247
8257
|
const copy = getUiCopy(locale);
|
|
8248
8258
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
8249
8259
|
const textContent = useMemo(() => message.parts.filter((part) => part.type === "text").map((part) => part.text).join("\n"), [message.parts]);
|
|
@@ -8255,7 +8265,7 @@ function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD,
|
|
|
8255
8265
|
const shouldAggregateSourceResults = message.role === "assistant" && sourceToolResultsLayout === "aggregated" && !renderToolCall;
|
|
8256
8266
|
const displayParts = useMemo(() => {
|
|
8257
8267
|
if (!resolveFileLinks || message.role !== "assistant") return message.parts;
|
|
8258
|
-
const files = getMessageGeneratedFiles(message);
|
|
8268
|
+
const files = generatedFiles ?? getMessageGeneratedFiles(message);
|
|
8259
8269
|
return message.parts.map((part) => {
|
|
8260
8270
|
if (part.type !== "text") return part;
|
|
8261
8271
|
const text$2 = resolveGeneratedFileLinks(part.text, files);
|
|
@@ -8264,7 +8274,11 @@ function MessageParts({ message, collapseThreshold = DEFAULT_COLLAPSE_THRESHOLD,
|
|
|
8264
8274
|
text: text$2
|
|
8265
8275
|
};
|
|
8266
8276
|
});
|
|
8267
|
-
}, [
|
|
8277
|
+
}, [
|
|
8278
|
+
message,
|
|
8279
|
+
resolveFileLinks,
|
|
8280
|
+
generatedFiles
|
|
8281
|
+
]);
|
|
8268
8282
|
const orderedParts = useMemo(() => shouldAggregateSourceResults ? aggregateSourceToolParts(displayParts, resolvedSourceResultsPosition) : orderMessageParts(displayParts, resolvedSourceResultsPosition).map(({ part, index }) => ({
|
|
8269
8283
|
kind: "part",
|
|
8270
8284
|
part,
|
|
@@ -8319,6 +8333,7 @@ function AssistantMessage({ message, avatar, footer, messageClassName, contentCl
|
|
|
8319
8333
|
const contentParts = message.parts.filter((part) => part.type !== "tool-call");
|
|
8320
8334
|
const renderableToolParts = toolParts.filter((part) => isRenderableToolPart(part, messagePartsProps?.locale, Boolean(messagePartsProps?.renderToolCall), Boolean(messagePartsProps?.memoryProposal)));
|
|
8321
8335
|
const hasContentRow = contentParts.length > 0 || footer !== void 0;
|
|
8336
|
+
const generatedFiles = messagePartsProps?.generatedFiles ?? (messagePartsProps?.resolveFileLinks === false ? void 0 : getMessageGeneratedFiles(message));
|
|
8322
8337
|
return /* @__PURE__ */ jsxs("div", {
|
|
8323
8338
|
className: joinClasses("plai-assistant-message flex w-full flex-col gap-2", className),
|
|
8324
8339
|
...props,
|
|
@@ -8342,6 +8357,7 @@ function AssistantMessage({ message, avatar, footer, messageClassName, contentCl
|
|
|
8342
8357
|
className: contentClassName,
|
|
8343
8358
|
children: [contentParts.length > 0 ? /* @__PURE__ */ jsx(MessageParts, {
|
|
8344
8359
|
...messagePartsProps,
|
|
8360
|
+
generatedFiles,
|
|
8345
8361
|
message: withParts(message, contentParts),
|
|
8346
8362
|
className: contentPartsClassName
|
|
8347
8363
|
}) : null, footer]
|