@kognitivedev/ui 0.2.11
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 +2 -0
- package/CHANGELOG.md +19 -0
- package/README.md +264 -0
- package/dist/__tests__/context-provider.test.d.ts +1 -0
- package/dist/__tests__/context-provider.test.js +38 -0
- package/dist/__tests__/event-emitter.test.d.ts +1 -0
- package/dist/__tests__/event-emitter.test.js +62 -0
- package/dist/__tests__/keyboard-shortcuts.test.d.ts +1 -0
- package/dist/__tests__/keyboard-shortcuts.test.js +36 -0
- package/dist/__tests__/kognitive-runtime.test.d.ts +1 -0
- package/dist/__tests__/kognitive-runtime.test.js +58 -0
- package/dist/__tests__/kognitive-transport.test.d.ts +1 -0
- package/dist/__tests__/kognitive-transport.test.js +96 -0
- package/dist/__tests__/make-tool-ui.test.d.ts +1 -0
- package/dist/__tests__/make-tool-ui.test.js +50 -0
- package/dist/__tests__/message-helpers.test.d.ts +1 -0
- package/dist/__tests__/message-helpers.test.js +80 -0
- package/dist/__tests__/thread-manager.test.d.ts +1 -0
- package/dist/__tests__/thread-manager.test.js +84 -0
- package/dist/__tests__/tool-ui-registry.test.d.ts +1 -0
- package/dist/__tests__/tool-ui-registry.test.js +68 -0
- package/dist/__tests__/toolkit.test.d.ts +1 -0
- package/dist/__tests__/toolkit.test.js +33 -0
- package/dist/components/attachment-preview.d.ts +8 -0
- package/dist/components/attachment-preview.js +10 -0
- package/dist/components/composer.d.ts +6 -0
- package/dist/components/composer.js +10 -0
- package/dist/components/error-banner.d.ts +6 -0
- package/dist/components/error-banner.js +8 -0
- package/dist/components/markdown-content.d.ts +13 -0
- package/dist/components/markdown-content.js +31 -0
- package/dist/components/message.d.ts +7 -0
- package/dist/components/message.js +28 -0
- package/dist/components/status-indicator.d.ts +6 -0
- package/dist/components/status-indicator.js +16 -0
- package/dist/components/suggestions.d.ts +4 -0
- package/dist/components/suggestions.js +12 -0
- package/dist/components/thread-list.d.ts +4 -0
- package/dist/components/thread-list.js +20 -0
- package/dist/components/thread.d.ts +15 -0
- package/dist/components/thread.js +19 -0
- package/dist/components/tool-approval.d.ts +7 -0
- package/dist/components/tool-approval.js +12 -0
- package/dist/components/tool-invocation.d.ts +5 -0
- package/dist/components/tool-invocation.js +33 -0
- package/dist/context/kognitive-context.d.ts +2 -0
- package/dist/context/kognitive-context.js +6 -0
- package/dist/context/types.d.ts +44 -0
- package/dist/context/types.js +2 -0
- package/dist/context/use-kognitive.d.ts +1 -0
- package/dist/context/use-kognitive.js +7 -0
- package/dist/hooks/use-auto-scroll.d.ts +2 -0
- package/dist/hooks/use-auto-scroll.js +18 -0
- package/dist/hooks/use-copy-to-clipboard.d.ts +4 -0
- package/dist/hooks/use-copy-to-clipboard.js +13 -0
- package/dist/hooks/use-keyboard-shortcuts.d.ts +8 -0
- package/dist/hooks/use-keyboard-shortcuts.js +24 -0
- package/dist/hooks/use-kognitive-chat.d.ts +38 -0
- package/dist/hooks/use-kognitive-chat.js +35 -0
- package/dist/hooks/use-kognitive-event.d.ts +12 -0
- package/dist/hooks/use-kognitive-event.js +47 -0
- package/dist/hooks/use-streaming-status.d.ts +2 -0
- package/dist/hooks/use-streaming-status.js +8 -0
- package/dist/hooks/use-thread-manager.d.ts +20 -0
- package/dist/hooks/use-thread-manager.js +83 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +92 -0
- package/dist/kognitive-ui.d.ts +48 -0
- package/dist/kognitive-ui.js +130 -0
- package/dist/primitives/action-bar/action-bar-copy.d.ts +6 -0
- package/dist/primitives/action-bar/action-bar-copy.js +16 -0
- package/dist/primitives/action-bar/action-bar-edit.d.ts +6 -0
- package/dist/primitives/action-bar/action-bar-edit.js +11 -0
- package/dist/primitives/action-bar/action-bar-feedback.d.ts +10 -0
- package/dist/primitives/action-bar/action-bar-feedback.js +30 -0
- package/dist/primitives/action-bar/action-bar-retry.d.ts +6 -0
- package/dist/primitives/action-bar/action-bar-retry.js +25 -0
- package/dist/primitives/action-bar/action-bar-root.d.ts +6 -0
- package/dist/primitives/action-bar/action-bar-root.js +7 -0
- package/dist/primitives/action-bar/action-bar-stop.d.ts +6 -0
- package/dist/primitives/action-bar/action-bar-stop.js +11 -0
- package/dist/primitives/action-bar/index.d.ts +14 -0
- package/dist/primitives/action-bar/index.js +17 -0
- package/dist/primitives/composer/composer-attachment-trigger.d.ts +7 -0
- package/dist/primitives/composer/composer-attachment-trigger.js +33 -0
- package/dist/primitives/composer/composer-attachments.d.ts +7 -0
- package/dist/primitives/composer/composer-attachments.js +16 -0
- package/dist/primitives/composer/composer-input.d.ts +6 -0
- package/dist/primitives/composer/composer-input.js +19 -0
- package/dist/primitives/composer/composer-root.d.ts +6 -0
- package/dist/primitives/composer/composer-root.js +91 -0
- package/dist/primitives/composer/composer-send.d.ts +6 -0
- package/dist/primitives/composer/composer-send.js +10 -0
- package/dist/primitives/composer/edit-composer-root.d.ts +11 -0
- package/dist/primitives/composer/edit-composer-root.js +24 -0
- package/dist/primitives/composer/index.d.ts +15 -0
- package/dist/primitives/composer/index.js +19 -0
- package/dist/primitives/composer/use-composer.d.ts +12 -0
- package/dist/primitives/composer/use-composer.js +6 -0
- package/dist/primitives/message/index.d.ts +9 -0
- package/dist/primitives/message/index.js +13 -0
- package/dist/primitives/message/message-content.d.ts +25 -0
- package/dist/primitives/message/message-content.js +70 -0
- package/dist/primitives/message/message-role.d.ts +6 -0
- package/dist/primitives/message/message-role.js +11 -0
- package/dist/primitives/message/message-root.d.ts +9 -0
- package/dist/primitives/message/message-root.js +38 -0
- package/dist/primitives/message/use-message.d.ts +10 -0
- package/dist/primitives/message/use-message.js +6 -0
- package/dist/primitives/thread/index.d.ts +17 -0
- package/dist/primitives/thread/index.js +21 -0
- package/dist/primitives/thread/thread-empty.d.ts +5 -0
- package/dist/primitives/thread/thread-empty.js +11 -0
- package/dist/primitives/thread/thread-error.d.ts +6 -0
- package/dist/primitives/thread/thread-error.js +11 -0
- package/dist/primitives/thread/thread-loading.d.ts +5 -0
- package/dist/primitives/thread/thread-loading.js +11 -0
- package/dist/primitives/thread/thread-messages.d.ts +6 -0
- package/dist/primitives/thread/thread-messages.js +9 -0
- package/dist/primitives/thread/thread-root.d.ts +6 -0
- package/dist/primitives/thread/thread-root.js +12 -0
- package/dist/primitives/thread/thread-scroll-to-bottom.d.ts +6 -0
- package/dist/primitives/thread/thread-scroll-to-bottom.js +14 -0
- package/dist/primitives/thread/thread-suggestions.d.ts +6 -0
- package/dist/primitives/thread/thread-suggestions.js +14 -0
- package/dist/primitives/thread/use-thread.d.ts +9 -0
- package/dist/primitives/thread/use-thread.js +6 -0
- package/dist/primitives/thread-list/index.d.ts +11 -0
- package/dist/primitives/thread-list/index.js +15 -0
- package/dist/primitives/thread-list/thread-list-item.d.ts +9 -0
- package/dist/primitives/thread-list/thread-list-item.js +13 -0
- package/dist/primitives/thread-list/thread-list-items.d.ts +6 -0
- package/dist/primitives/thread-list/thread-list-items.js +9 -0
- package/dist/primitives/thread-list/thread-list-new.d.ts +6 -0
- package/dist/primitives/thread-list/thread-list-new.js +13 -0
- package/dist/primitives/thread-list/thread-list-root.d.ts +6 -0
- package/dist/primitives/thread-list/thread-list-root.js +16 -0
- package/dist/primitives/thread-list/use-thread-list.d.ts +9 -0
- package/dist/primitives/thread-list/use-thread-list.js +6 -0
- package/dist/primitives/tool-ui/index.d.ts +7 -0
- package/dist/primitives/tool-ui/index.js +11 -0
- package/dist/primitives/tool-ui/tool-ui-fallback.d.ts +5 -0
- package/dist/primitives/tool-ui/tool-ui-fallback.js +20 -0
- package/dist/primitives/tool-ui/tool-ui-root.d.ts +5 -0
- package/dist/primitives/tool-ui/tool-ui-root.js +20 -0
- package/dist/primitives/tool-ui/use-tool-ui.d.ts +2 -0
- package/dist/primitives/tool-ui/use-tool-ui.js +8 -0
- package/dist/runtime/kognitive-runtime.d.ts +30 -0
- package/dist/runtime/kognitive-runtime.js +32 -0
- package/dist/runtime/kognitive-transport.d.ts +26 -0
- package/dist/runtime/kognitive-transport.js +42 -0
- package/dist/runtime/thread-manager.d.ts +17 -0
- package/dist/runtime/thread-manager.js +62 -0
- package/dist/runtime/types.d.ts +58 -0
- package/dist/runtime/types.js +2 -0
- package/dist/tool-ui/make-tool-ui.d.ts +59 -0
- package/dist/tool-ui/make-tool-ui.js +10 -0
- package/dist/tool-ui/registry.d.ts +9 -0
- package/dist/tool-ui/registry.js +26 -0
- package/dist/tool-ui/tool-ui-context.d.ts +2 -0
- package/dist/tool-ui/tool-ui-context.js +6 -0
- package/dist/tool-ui/toolkit.d.ts +31 -0
- package/dist/tool-ui/toolkit.js +33 -0
- package/dist/tool-ui/types.d.ts +19 -0
- package/dist/tool-ui/types.js +2 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/utils/cn.js +8 -0
- package/dist/utils/create-context.d.ts +1 -0
- package/dist/utils/create-context.js +16 -0
- package/dist/utils/message-helpers.d.ts +6 -0
- package/dist/utils/message-helpers.js +46 -0
- package/package.json +56 -0
- package/src/__tests__/context-provider.test.ts +43 -0
- package/src/__tests__/event-emitter.test.ts +69 -0
- package/src/__tests__/keyboard-shortcuts.test.ts +55 -0
- package/src/__tests__/kognitive-runtime.test.ts +62 -0
- package/src/__tests__/kognitive-transport.test.ts +113 -0
- package/src/__tests__/make-tool-ui.test.ts +60 -0
- package/src/__tests__/message-helpers.test.ts +101 -0
- package/src/__tests__/thread-manager.test.ts +118 -0
- package/src/__tests__/tool-ui-registry.test.ts +80 -0
- package/src/__tests__/toolkit.test.ts +37 -0
- package/src/components/attachment-preview.tsx +46 -0
- package/src/components/composer.tsx +59 -0
- package/src/components/error-banner.tsx +33 -0
- package/src/components/markdown-content.tsx +64 -0
- package/src/components/message.tsx +145 -0
- package/src/components/status-indicator.tsx +26 -0
- package/src/components/suggestions.tsx +27 -0
- package/src/components/thread-list.tsx +69 -0
- package/src/components/thread.tsx +89 -0
- package/src/components/tool-approval.tsx +54 -0
- package/src/components/tool-invocation.tsx +94 -0
- package/src/context/kognitive-context.tsx +8 -0
- package/src/context/types.ts +43 -0
- package/src/context/use-kognitive.ts +5 -0
- package/src/hooks/use-auto-scroll.ts +19 -0
- package/src/hooks/use-copy-to-clipboard.ts +16 -0
- package/src/hooks/use-keyboard-shortcuts.ts +34 -0
- package/src/hooks/use-kognitive-chat.ts +73 -0
- package/src/hooks/use-kognitive-event.ts +56 -0
- package/src/hooks/use-streaming-status.ts +7 -0
- package/src/hooks/use-thread-manager.ts +114 -0
- package/src/index.ts +56 -0
- package/src/kognitive-ui.tsx +216 -0
- package/src/primitives/action-bar/action-bar-copy.tsx +30 -0
- package/src/primitives/action-bar/action-bar-edit.tsx +24 -0
- package/src/primitives/action-bar/action-bar-feedback.tsx +59 -0
- package/src/primitives/action-bar/action-bar-retry.tsx +38 -0
- package/src/primitives/action-bar/action-bar-root.tsx +14 -0
- package/src/primitives/action-bar/action-bar-stop.tsx +24 -0
- package/src/primitives/action-bar/index.ts +15 -0
- package/src/primitives/composer/composer-attachment-trigger.tsx +70 -0
- package/src/primitives/composer/composer-attachments.tsx +36 -0
- package/src/primitives/composer/composer-input.tsx +46 -0
- package/src/primitives/composer/composer-root.tsx +130 -0
- package/src/primitives/composer/composer-send.tsx +23 -0
- package/src/primitives/composer/edit-composer-root.tsx +52 -0
- package/src/primitives/composer/index.ts +17 -0
- package/src/primitives/composer/use-composer.ts +19 -0
- package/src/primitives/message/index.ts +11 -0
- package/src/primitives/message/message-content.tsx +117 -0
- package/src/primitives/message/message-role.tsx +13 -0
- package/src/primitives/message/message-root.tsx +64 -0
- package/src/primitives/message/use-message.ts +17 -0
- package/src/primitives/thread/index.ts +19 -0
- package/src/primitives/thread/thread-empty.tsx +12 -0
- package/src/primitives/thread/thread-error.tsx +18 -0
- package/src/primitives/thread/thread-loading.tsx +12 -0
- package/src/primitives/thread/thread-messages.tsx +12 -0
- package/src/primitives/thread/thread-root.tsx +28 -0
- package/src/primitives/thread/thread-scroll-to-bottom.tsx +26 -0
- package/src/primitives/thread/thread-suggestions.tsx +31 -0
- package/src/primitives/thread/use-thread.ts +16 -0
- package/src/primitives/thread-list/index.ts +13 -0
- package/src/primitives/thread-list/thread-list-item.tsx +37 -0
- package/src/primitives/thread-list/thread-list-items.tsx +19 -0
- package/src/primitives/thread-list/thread-list-new.tsx +26 -0
- package/src/primitives/thread-list/thread-list-root.tsx +29 -0
- package/src/primitives/thread-list/use-thread-list.ts +16 -0
- package/src/primitives/tool-ui/index.ts +9 -0
- package/src/primitives/tool-ui/tool-ui-fallback.tsx +63 -0
- package/src/primitives/tool-ui/tool-ui-root.tsx +26 -0
- package/src/primitives/tool-ui/use-tool-ui.ts +7 -0
- package/src/runtime/kognitive-runtime.ts +56 -0
- package/src/runtime/kognitive-transport.ts +56 -0
- package/src/runtime/thread-manager.ts +92 -0
- package/src/runtime/types.ts +63 -0
- package/src/tool-ui/make-tool-ui.ts +71 -0
- package/src/tool-ui/registry.ts +27 -0
- package/src/tool-ui/tool-ui-context.tsx +8 -0
- package/src/tool-ui/toolkit.ts +40 -0
- package/src/tool-ui/types.ts +29 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/create-context.ts +18 -0
- package/src/utils/message-helpers.ts +42 -0
- package/tsconfig.json +15 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KognitiveUI = KognitiveUI;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_2 = require("@ai-sdk/react");
|
|
7
|
+
const kognitive_transport_1 = require("./runtime/kognitive-transport");
|
|
8
|
+
const thread_manager_1 = require("./runtime/thread-manager");
|
|
9
|
+
const registry_1 = require("./tool-ui/registry");
|
|
10
|
+
const kognitive_context_1 = require("./context/kognitive-context");
|
|
11
|
+
const tool_ui_context_1 = require("./tool-ui/tool-ui-context");
|
|
12
|
+
const thread_1 = require("./components/thread");
|
|
13
|
+
const thread_list_1 = require("./components/thread-list");
|
|
14
|
+
const composer_1 = require("./components/composer");
|
|
15
|
+
function KognitiveUIInner(props) {
|
|
16
|
+
const { api, agentName, baseUrl, headers, resourceId, sessionId: controlledSessionId, threads: threadsEnabled, threadApiBase, toolUIs, toolkit: toolkitRegistrations, body: extraBody, onFeedback, onToolApproval, suggestions = [], children, } = props;
|
|
17
|
+
// ── Tool UI Registry ──
|
|
18
|
+
const toolUIRegistry = (0, react_1.useMemo)(() => {
|
|
19
|
+
const registry = new registry_1.ToolUIRegistry();
|
|
20
|
+
if (toolUIs)
|
|
21
|
+
registry.registerAll(toolUIs);
|
|
22
|
+
if (toolkitRegistrations)
|
|
23
|
+
registry.registerAll(toolkitRegistrations);
|
|
24
|
+
return registry;
|
|
25
|
+
}, [toolUIs, toolkitRegistrations]);
|
|
26
|
+
// ── Thread Management ──
|
|
27
|
+
const [threadsList, setThreadsList] = (0, react_1.useState)([]);
|
|
28
|
+
const [activeSessionId, setActiveSessionId] = (0, react_1.useState)(controlledSessionId !== null && controlledSessionId !== void 0 ? controlledSessionId : null);
|
|
29
|
+
const threadManager = (0, react_1.useMemo)(() => {
|
|
30
|
+
if (!threadsEnabled || !baseUrl)
|
|
31
|
+
return null;
|
|
32
|
+
const base = threadApiBase !== null && threadApiBase !== void 0 ? threadApiBase : `${baseUrl.replace(/\/$/, "")}/api/agents/${encodeURIComponent(agentName)}/threads`;
|
|
33
|
+
return new thread_manager_1.ThreadManager({ baseUrl: base, headers });
|
|
34
|
+
}, [threadsEnabled, threadApiBase, baseUrl, agentName, headers]);
|
|
35
|
+
const refreshThreads = (0, react_1.useCallback)(async (preferredSessionId) => {
|
|
36
|
+
if (!threadManager)
|
|
37
|
+
return;
|
|
38
|
+
const threads = await threadManager.list();
|
|
39
|
+
setThreadsList(threads);
|
|
40
|
+
if (preferredSessionId) {
|
|
41
|
+
setActiveSessionId(preferredSessionId);
|
|
42
|
+
}
|
|
43
|
+
else if (!activeSessionId && threads.length > 0) {
|
|
44
|
+
setActiveSessionId(threads[0].sessionId);
|
|
45
|
+
}
|
|
46
|
+
else if (threads.length === 0) {
|
|
47
|
+
const thread = await threadManager.create();
|
|
48
|
+
setThreadsList([thread]);
|
|
49
|
+
setActiveSessionId(thread.sessionId);
|
|
50
|
+
}
|
|
51
|
+
}, [threadManager, activeSessionId]);
|
|
52
|
+
const createThread = (0, react_1.useCallback)(async () => {
|
|
53
|
+
if (!threadManager)
|
|
54
|
+
return;
|
|
55
|
+
const thread = await threadManager.create();
|
|
56
|
+
await refreshThreads(thread.sessionId);
|
|
57
|
+
}, [threadManager, refreshThreads]);
|
|
58
|
+
(0, react_1.useEffect)(() => {
|
|
59
|
+
if (threadManager) {
|
|
60
|
+
void refreshThreads();
|
|
61
|
+
}
|
|
62
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
63
|
+
}, [threadManager]);
|
|
64
|
+
(0, react_1.useEffect)(() => {
|
|
65
|
+
if (controlledSessionId !== undefined) {
|
|
66
|
+
setActiveSessionId(controlledSessionId);
|
|
67
|
+
}
|
|
68
|
+
}, [controlledSessionId]);
|
|
69
|
+
// ── Transport + Chat ──
|
|
70
|
+
const transport = (0, react_1.useMemo)(() => (0, kognitive_transport_1.createKognitiveTransport)({
|
|
71
|
+
api,
|
|
72
|
+
baseUrl,
|
|
73
|
+
agentName,
|
|
74
|
+
sessionId: activeSessionId !== null && activeSessionId !== void 0 ? activeSessionId : undefined,
|
|
75
|
+
resourceId,
|
|
76
|
+
headers,
|
|
77
|
+
body: extraBody,
|
|
78
|
+
}), [api, baseUrl, agentName, activeSessionId, resourceId, headers, extraBody]);
|
|
79
|
+
const { messages, sendMessage, status, stop, setMessages, error } = (0, react_2.useChat)({
|
|
80
|
+
transport,
|
|
81
|
+
});
|
|
82
|
+
(0, react_1.useEffect)(() => {
|
|
83
|
+
setMessages([]);
|
|
84
|
+
}, [activeSessionId, setMessages]);
|
|
85
|
+
// ── Send helper ──
|
|
86
|
+
const send = (0, react_1.useCallback)((text, options) => {
|
|
87
|
+
const parts = [{ type: "text", text }];
|
|
88
|
+
if (options === null || options === void 0 ? void 0 : options.files) {
|
|
89
|
+
parts.push(...options.files);
|
|
90
|
+
}
|
|
91
|
+
sendMessage({ role: "user", parts });
|
|
92
|
+
}, [sendMessage]);
|
|
93
|
+
// Refresh threads after a stream completes
|
|
94
|
+
const prevStatusRef = (0, react_1.useRef)(status);
|
|
95
|
+
(0, react_1.useEffect)(() => {
|
|
96
|
+
if (prevStatusRef.current === "streaming" &&
|
|
97
|
+
status === "ready" &&
|
|
98
|
+
threadManager) {
|
|
99
|
+
void refreshThreads(activeSessionId !== null && activeSessionId !== void 0 ? activeSessionId : undefined);
|
|
100
|
+
}
|
|
101
|
+
prevStatusRef.current = status;
|
|
102
|
+
}, [status, threadManager, refreshThreads, activeSessionId]);
|
|
103
|
+
const isStreaming = status === "streaming";
|
|
104
|
+
return ((0, jsx_runtime_1.jsx)(tool_ui_context_1.ToolUIRegistryProvider, { value: toolUIRegistry, children: (0, jsx_runtime_1.jsx)(kognitive_context_1.KognitiveContextProvider, { value: {
|
|
105
|
+
messages,
|
|
106
|
+
send,
|
|
107
|
+
status,
|
|
108
|
+
isStreaming,
|
|
109
|
+
stop,
|
|
110
|
+
setMessages,
|
|
111
|
+
threadManager,
|
|
112
|
+
toolUIRegistry,
|
|
113
|
+
activeSessionId,
|
|
114
|
+
setActiveSessionId,
|
|
115
|
+
threads: threadsList,
|
|
116
|
+
refreshThreads: () => refreshThreads(),
|
|
117
|
+
createThread,
|
|
118
|
+
agentName,
|
|
119
|
+
error,
|
|
120
|
+
onFeedback,
|
|
121
|
+
onToolApproval,
|
|
122
|
+
suggestions,
|
|
123
|
+
}, children: children }) }));
|
|
124
|
+
}
|
|
125
|
+
function KognitiveUI(props) {
|
|
126
|
+
return (0, jsx_runtime_1.jsx)(KognitiveUIInner, Object.assign({}, props));
|
|
127
|
+
}
|
|
128
|
+
KognitiveUI.Thread = thread_1.Thread;
|
|
129
|
+
KognitiveUI.ThreadList = thread_list_1.ThreadList;
|
|
130
|
+
KognitiveUI.Composer = composer_1.Composer;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface ActionBarCopyProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
children?: ReactNode | ((copied: boolean) => ReactNode);
|
|
5
|
+
}
|
|
6
|
+
export declare function ActionBarCopy({ className, children }: ActionBarCopyProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionBarCopy = ActionBarCopy;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const use_message_1 = require("../message/use-message");
|
|
7
|
+
const use_copy_to_clipboard_1 = require("../../hooks/use-copy-to-clipboard");
|
|
8
|
+
const message_helpers_1 = require("../../utils/message-helpers");
|
|
9
|
+
function ActionBarCopy({ className, children }) {
|
|
10
|
+
const { message } = (0, use_message_1.useMessage)();
|
|
11
|
+
const { copied, copy } = (0, use_copy_to_clipboard_1.useCopyToClipboard)();
|
|
12
|
+
const handleCopy = (0, react_1.useCallback)(() => {
|
|
13
|
+
void copy((0, message_helpers_1.getMessageText)(message));
|
|
14
|
+
}, [copy, message]);
|
|
15
|
+
return ((0, jsx_runtime_1.jsx)("button", { type: "button", className: className, onClick: handleCopy, "aria-label": copied ? "Copied" : "Copy message", "data-copied": copied || undefined, children: typeof children === "function" ? children(copied) : children !== null && children !== void 0 ? children : (copied ? "Copied" : "Copy") }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionBarEdit = ActionBarEdit;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const use_message_1 = require("../message/use-message");
|
|
6
|
+
function ActionBarEdit({ className, children }) {
|
|
7
|
+
const { message, startEdit, isEditing } = (0, use_message_1.useMessage)();
|
|
8
|
+
if (message.role !== "user" || isEditing)
|
|
9
|
+
return null;
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)("button", { type: "button", className: className, onClick: startEdit, "aria-label": "Edit message", children: children !== null && children !== void 0 ? children : "Edit" }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface ActionBarFeedbackProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
children?: (props: {
|
|
5
|
+
selected: "positive" | "negative" | null;
|
|
6
|
+
onPositive: () => void;
|
|
7
|
+
onNegative: () => void;
|
|
8
|
+
}) => ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export declare function ActionBarFeedback({ className, children }: ActionBarFeedbackProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionBarFeedback = ActionBarFeedback;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const use_message_1 = require("../message/use-message");
|
|
7
|
+
const kognitive_context_1 = require("../../context/kognitive-context");
|
|
8
|
+
function ActionBarFeedback({ className, children }) {
|
|
9
|
+
const { message } = (0, use_message_1.useMessage)();
|
|
10
|
+
const { onFeedback } = (0, kognitive_context_1.useKognitiveContext)();
|
|
11
|
+
const [selected, setSelected] = (0, react_1.useState)(null);
|
|
12
|
+
const handlePositive = (0, react_1.useCallback)(() => {
|
|
13
|
+
const next = selected === "positive" ? null : "positive";
|
|
14
|
+
setSelected(next);
|
|
15
|
+
if (next && onFeedback)
|
|
16
|
+
onFeedback(message.id, "positive");
|
|
17
|
+
}, [selected, onFeedback, message.id]);
|
|
18
|
+
const handleNegative = (0, react_1.useCallback)(() => {
|
|
19
|
+
const next = selected === "negative" ? null : "negative";
|
|
20
|
+
setSelected(next);
|
|
21
|
+
if (next && onFeedback)
|
|
22
|
+
onFeedback(message.id, "negative");
|
|
23
|
+
}, [selected, onFeedback, message.id]);
|
|
24
|
+
if (!onFeedback)
|
|
25
|
+
return null;
|
|
26
|
+
if (children) {
|
|
27
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children({ selected, onPositive: handlePositive, onNegative: handleNegative }) });
|
|
28
|
+
}
|
|
29
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: className, role: "group", "aria-label": "Message feedback", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", onClick: handlePositive, "aria-label": "Good response", "aria-pressed": selected === "positive", "data-selected": selected === "positive" || undefined, children: selected === "positive" ? "\u{1F44D}" : "\u{1F44D}\u{200D}" }), (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: handleNegative, "aria-label": "Bad response", "aria-pressed": selected === "negative", "data-selected": selected === "negative" || undefined, children: selected === "negative" ? "\u{1F44E}" : "\u{1F44E}\u{200D}" })] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionBarRetry = ActionBarRetry;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const kognitive_context_1 = require("../../context/kognitive-context");
|
|
7
|
+
function ActionBarRetry({ className, children }) {
|
|
8
|
+
const { messages, send } = (0, kognitive_context_1.useKognitiveContext)();
|
|
9
|
+
const handleRetry = (0, react_1.useCallback)(() => {
|
|
10
|
+
// Find the last user message and re-send it
|
|
11
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
12
|
+
if (messages[i].role === "user") {
|
|
13
|
+
const text = messages[i].parts
|
|
14
|
+
.filter((p) => p.type === "text")
|
|
15
|
+
.map((p) => p.text)
|
|
16
|
+
.join("\n");
|
|
17
|
+
if (text) {
|
|
18
|
+
send(text);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, [messages, send]);
|
|
24
|
+
return ((0, jsx_runtime_1.jsx)("button", { type: "button", className: className, onClick: handleRetry, "aria-label": "Retry", children: children !== null && children !== void 0 ? children : "Retry" }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionBarRoot = ActionBarRoot;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
function ActionBarRoot({ className, children }) {
|
|
6
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: className, role: "toolbar", "aria-label": "Message actions", children: children }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionBarStop = ActionBarStop;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const kognitive_context_1 = require("../../context/kognitive-context");
|
|
6
|
+
function ActionBarStop({ className, children }) {
|
|
7
|
+
const { stop, isStreaming } = (0, kognitive_context_1.useKognitiveContext)();
|
|
8
|
+
if (!isStreaming)
|
|
9
|
+
return null;
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)("button", { type: "button", className: className, onClick: stop, "aria-label": "Stop", children: children !== null && children !== void 0 ? children : "Stop" }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ActionBarRoot } from "./action-bar-root";
|
|
2
|
+
import { ActionBarCopy } from "./action-bar-copy";
|
|
3
|
+
import { ActionBarRetry } from "./action-bar-retry";
|
|
4
|
+
import { ActionBarStop } from "./action-bar-stop";
|
|
5
|
+
import { ActionBarFeedback } from "./action-bar-feedback";
|
|
6
|
+
import { ActionBarEdit } from "./action-bar-edit";
|
|
7
|
+
export declare const ActionBarPrimitive: {
|
|
8
|
+
Root: typeof ActionBarRoot;
|
|
9
|
+
Copy: typeof ActionBarCopy;
|
|
10
|
+
Retry: typeof ActionBarRetry;
|
|
11
|
+
Stop: typeof ActionBarStop;
|
|
12
|
+
Feedback: typeof ActionBarFeedback;
|
|
13
|
+
Edit: typeof ActionBarEdit;
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionBarPrimitive = void 0;
|
|
4
|
+
const action_bar_root_1 = require("./action-bar-root");
|
|
5
|
+
const action_bar_copy_1 = require("./action-bar-copy");
|
|
6
|
+
const action_bar_retry_1 = require("./action-bar-retry");
|
|
7
|
+
const action_bar_stop_1 = require("./action-bar-stop");
|
|
8
|
+
const action_bar_feedback_1 = require("./action-bar-feedback");
|
|
9
|
+
const action_bar_edit_1 = require("./action-bar-edit");
|
|
10
|
+
exports.ActionBarPrimitive = {
|
|
11
|
+
Root: action_bar_root_1.ActionBarRoot,
|
|
12
|
+
Copy: action_bar_copy_1.ActionBarCopy,
|
|
13
|
+
Retry: action_bar_retry_1.ActionBarRetry,
|
|
14
|
+
Stop: action_bar_stop_1.ActionBarStop,
|
|
15
|
+
Feedback: action_bar_feedback_1.ActionBarFeedback,
|
|
16
|
+
Edit: action_bar_edit_1.ActionBarEdit,
|
|
17
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface ComposerAttachmentTriggerProps {
|
|
3
|
+
accept?: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare function ComposerAttachmentTrigger({ accept, className, children, }: ComposerAttachmentTriggerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComposerAttachmentTrigger = ComposerAttachmentTrigger;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const use_composer_1 = require("./use-composer");
|
|
7
|
+
function ComposerAttachmentTrigger({ accept = "image/*", className, children, }) {
|
|
8
|
+
const { addFile } = (0, use_composer_1.useComposer)();
|
|
9
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
10
|
+
const handleClick = (0, react_1.useCallback)(() => {
|
|
11
|
+
var _a;
|
|
12
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
13
|
+
}, []);
|
|
14
|
+
const handleChange = (0, react_1.useCallback)(async (e) => {
|
|
15
|
+
const fileList = e.target.files;
|
|
16
|
+
if (!fileList)
|
|
17
|
+
return;
|
|
18
|
+
for (const file of Array.from(fileList)) {
|
|
19
|
+
const buffer = await file.arrayBuffer();
|
|
20
|
+
const base64 = btoa(new Uint8Array(buffer).reduce((data, byte) => data + String.fromCharCode(byte), ""));
|
|
21
|
+
addFile({
|
|
22
|
+
type: "file",
|
|
23
|
+
mediaType: file.type,
|
|
24
|
+
url: `data:${file.type};base64,${base64}`,
|
|
25
|
+
filename: file.name,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// Reset input so the same file can be selected again
|
|
29
|
+
if (inputRef.current)
|
|
30
|
+
inputRef.current.value = "";
|
|
31
|
+
}, [addFile]);
|
|
32
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { ref: inputRef, type: "file", accept: accept, multiple: true, onChange: handleChange, style: { display: "none" }, "aria-hidden": true }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: className, onClick: handleClick, "aria-label": "Attach file", children: children !== null && children !== void 0 ? children : "+" })] }));
|
|
33
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { FileUIPart } from "ai";
|
|
3
|
+
export interface ComposerAttachmentsProps {
|
|
4
|
+
className?: string;
|
|
5
|
+
children?: (file: FileUIPart, index: number, remove: () => void) => ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare function ComposerAttachments({ className, children }: ComposerAttachmentsProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComposerAttachments = ComposerAttachments;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const use_composer_1 = require("./use-composer");
|
|
6
|
+
function ComposerAttachments({ className, children }) {
|
|
7
|
+
const { files, removeFile } = (0, use_composer_1.useComposer)();
|
|
8
|
+
if (files.length === 0)
|
|
9
|
+
return null;
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: className, "data-attachment-count": files.length, children: files.map((file, index) => {
|
|
11
|
+
if (children) {
|
|
12
|
+
return children(file, index, () => removeFile(index));
|
|
13
|
+
}
|
|
14
|
+
return ((0, jsx_runtime_1.jsxs)("div", { "data-attachment": true, children: [(0, jsx_runtime_1.jsx)("span", { children: file.mediaType }), (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: () => removeFile(index), "aria-label": "Remove attachment", children: "x" })] }, index));
|
|
15
|
+
}) }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComposerInput = ComposerInput;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const use_composer_1 = require("./use-composer");
|
|
7
|
+
function ComposerInput({ placeholder = "Send a message...", className, rows = 1, }) {
|
|
8
|
+
const { input, setInput, submit, isDisabled } = (0, use_composer_1.useComposer)();
|
|
9
|
+
const handleKeyDown = (0, react_1.useCallback)((e) => {
|
|
10
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
11
|
+
e.preventDefault();
|
|
12
|
+
submit();
|
|
13
|
+
}
|
|
14
|
+
}, [submit]);
|
|
15
|
+
const handleChange = (0, react_1.useCallback)((e) => {
|
|
16
|
+
setInput(e.target.value);
|
|
17
|
+
}, [setInput]);
|
|
18
|
+
return ((0, jsx_runtime_1.jsx)("textarea", { className: className, value: input, onChange: handleChange, onKeyDown: handleKeyDown, placeholder: placeholder, disabled: isDisabled, rows: rows, "aria-label": "Message input" }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComposerRoot = ComposerRoot;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const kognitive_context_1 = require("../../context/kognitive-context");
|
|
7
|
+
const use_composer_1 = require("./use-composer");
|
|
8
|
+
async function fileToFileUIPart(file) {
|
|
9
|
+
const buffer = await file.arrayBuffer();
|
|
10
|
+
const base64 = btoa(new Uint8Array(buffer).reduce((data, byte) => data + String.fromCharCode(byte), ""));
|
|
11
|
+
return {
|
|
12
|
+
type: "file",
|
|
13
|
+
mediaType: file.type || "application/octet-stream",
|
|
14
|
+
url: `data:${file.type || "application/octet-stream"};base64,${base64}`,
|
|
15
|
+
filename: file.name,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function ComposerRoot({ className, children }) {
|
|
19
|
+
const { send, isStreaming } = (0, kognitive_context_1.useKognitiveContext)();
|
|
20
|
+
const [input, setInput] = (0, react_1.useState)("");
|
|
21
|
+
const [files, setFiles] = (0, react_1.useState)([]);
|
|
22
|
+
const [isDragOver, setIsDragOver] = (0, react_1.useState)(false);
|
|
23
|
+
const addFile = (0, react_1.useCallback)((file) => {
|
|
24
|
+
setFiles((prev) => [...prev, file]);
|
|
25
|
+
}, []);
|
|
26
|
+
const removeFile = (0, react_1.useCallback)((index) => {
|
|
27
|
+
setFiles((prev) => prev.filter((_, i) => i !== index));
|
|
28
|
+
}, []);
|
|
29
|
+
const clearFiles = (0, react_1.useCallback)(() => {
|
|
30
|
+
setFiles([]);
|
|
31
|
+
}, []);
|
|
32
|
+
const submit = (0, react_1.useCallback)(() => {
|
|
33
|
+
const text = input.trim();
|
|
34
|
+
if (!text && files.length === 0)
|
|
35
|
+
return;
|
|
36
|
+
send(text, files.length > 0 ? { files } : undefined);
|
|
37
|
+
setInput("");
|
|
38
|
+
setFiles([]);
|
|
39
|
+
}, [input, files, send]);
|
|
40
|
+
const handleSubmit = (0, react_1.useCallback)((e) => {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
submit();
|
|
43
|
+
}, [submit]);
|
|
44
|
+
// ── Drag-and-drop ──
|
|
45
|
+
const handleDragOver = (0, react_1.useCallback)((e) => {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
setIsDragOver(true);
|
|
48
|
+
}, []);
|
|
49
|
+
const handleDragLeave = (0, react_1.useCallback)((e) => {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
setIsDragOver(false);
|
|
52
|
+
}, []);
|
|
53
|
+
const handleDrop = (0, react_1.useCallback)(async (e) => {
|
|
54
|
+
var _a;
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
setIsDragOver(false);
|
|
57
|
+
const droppedFiles = (_a = e.dataTransfer) === null || _a === void 0 ? void 0 : _a.files;
|
|
58
|
+
if (!droppedFiles)
|
|
59
|
+
return;
|
|
60
|
+
for (const file of Array.from(droppedFiles)) {
|
|
61
|
+
const part = await fileToFileUIPart(file);
|
|
62
|
+
addFile(part);
|
|
63
|
+
}
|
|
64
|
+
}, [addFile]);
|
|
65
|
+
// ── Paste upload ──
|
|
66
|
+
const handlePaste = (0, react_1.useCallback)(async (e) => {
|
|
67
|
+
var _a;
|
|
68
|
+
const items = (_a = e.clipboardData) === null || _a === void 0 ? void 0 : _a.items;
|
|
69
|
+
if (!items)
|
|
70
|
+
return;
|
|
71
|
+
for (const item of Array.from(items)) {
|
|
72
|
+
if (item.kind === "file") {
|
|
73
|
+
const file = item.getAsFile();
|
|
74
|
+
if (file) {
|
|
75
|
+
const part = await fileToFileUIPart(file);
|
|
76
|
+
addFile(part);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}, [addFile]);
|
|
81
|
+
return ((0, jsx_runtime_1.jsx)(use_composer_1.ComposerContextProvider, { value: {
|
|
82
|
+
input,
|
|
83
|
+
setInput,
|
|
84
|
+
files,
|
|
85
|
+
addFile,
|
|
86
|
+
removeFile,
|
|
87
|
+
clearFiles,
|
|
88
|
+
submit,
|
|
89
|
+
isDisabled: isStreaming,
|
|
90
|
+
}, children: (0, jsx_runtime_1.jsx)("form", { className: className, onSubmit: handleSubmit, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleDrop, onPaste: handlePaste, "data-drag-over": isDragOver || undefined, children: children }) }));
|
|
91
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComposerSend = ComposerSend;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const use_composer_1 = require("./use-composer");
|
|
6
|
+
function ComposerSend({ className, children }) {
|
|
7
|
+
const { input, files, isDisabled } = (0, use_composer_1.useComposer)();
|
|
8
|
+
const isEmpty = !input.trim() && files.length === 0;
|
|
9
|
+
return ((0, jsx_runtime_1.jsx)("button", { type: "submit", className: className, disabled: isEmpty || isDisabled, "aria-label": "Send message", children: children !== null && children !== void 0 ? children : "Send" }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface EditComposerRootProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
children?: ReactNode | ((props: {
|
|
5
|
+
value: string;
|
|
6
|
+
setValue: (v: string) => void;
|
|
7
|
+
submit: () => void;
|
|
8
|
+
cancel: () => void;
|
|
9
|
+
}) => ReactNode);
|
|
10
|
+
}
|
|
11
|
+
export declare function EditComposerRoot({ className, children }: EditComposerRootProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EditComposerRoot = EditComposerRoot;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const use_message_1 = require("../message/use-message");
|
|
7
|
+
const message_helpers_1 = require("../../utils/message-helpers");
|
|
8
|
+
function EditComposerRoot({ className, children }) {
|
|
9
|
+
const { message, isEditing, submitEdit, cancelEdit } = (0, use_message_1.useMessage)();
|
|
10
|
+
const [value, setValue] = (0, react_1.useState)(() => (0, message_helpers_1.getMessageText)(message));
|
|
11
|
+
const handleSubmit = (0, react_1.useCallback)((e) => {
|
|
12
|
+
e.preventDefault();
|
|
13
|
+
const text = value.trim();
|
|
14
|
+
if (text)
|
|
15
|
+
submitEdit(text);
|
|
16
|
+
}, [value, submitEdit]);
|
|
17
|
+
if (!isEditing)
|
|
18
|
+
return null;
|
|
19
|
+
if (typeof children === "function") {
|
|
20
|
+
return ((0, jsx_runtime_1.jsx)("form", { className: className, onSubmit: handleSubmit, children: children({ value, setValue, submit: () => { const t = value.trim(); if (t)
|
|
21
|
+
submitEdit(t); }, cancel: cancelEdit }) }));
|
|
22
|
+
}
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)("form", { className: className, onSubmit: handleSubmit, children: [(0, jsx_runtime_1.jsx)("textarea", { value: value, onChange: (e) => setValue(e.target.value), rows: 3, "aria-label": "Edit message" }), (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("button", { type: "submit", children: "Save & Send" }), (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: cancelEdit, children: "Cancel" })] })] }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ComposerRoot } from "./composer-root";
|
|
2
|
+
import { ComposerInput } from "./composer-input";
|
|
3
|
+
import { ComposerSend } from "./composer-send";
|
|
4
|
+
import { ComposerAttachments } from "./composer-attachments";
|
|
5
|
+
import { ComposerAttachmentTrigger } from "./composer-attachment-trigger";
|
|
6
|
+
import { EditComposerRoot } from "./edit-composer-root";
|
|
7
|
+
export declare const ComposerPrimitive: {
|
|
8
|
+
Root: typeof ComposerRoot;
|
|
9
|
+
Input: typeof ComposerInput;
|
|
10
|
+
Send: typeof ComposerSend;
|
|
11
|
+
Attachments: typeof ComposerAttachments;
|
|
12
|
+
AttachmentTrigger: typeof ComposerAttachmentTrigger;
|
|
13
|
+
EditRoot: typeof EditComposerRoot;
|
|
14
|
+
};
|
|
15
|
+
export { useComposer } from "./use-composer";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useComposer = exports.ComposerPrimitive = void 0;
|
|
4
|
+
const composer_root_1 = require("./composer-root");
|
|
5
|
+
const composer_input_1 = require("./composer-input");
|
|
6
|
+
const composer_send_1 = require("./composer-send");
|
|
7
|
+
const composer_attachments_1 = require("./composer-attachments");
|
|
8
|
+
const composer_attachment_trigger_1 = require("./composer-attachment-trigger");
|
|
9
|
+
const edit_composer_root_1 = require("./edit-composer-root");
|
|
10
|
+
exports.ComposerPrimitive = {
|
|
11
|
+
Root: composer_root_1.ComposerRoot,
|
|
12
|
+
Input: composer_input_1.ComposerInput,
|
|
13
|
+
Send: composer_send_1.ComposerSend,
|
|
14
|
+
Attachments: composer_attachments_1.ComposerAttachments,
|
|
15
|
+
AttachmentTrigger: composer_attachment_trigger_1.ComposerAttachmentTrigger,
|
|
16
|
+
EditRoot: edit_composer_root_1.EditComposerRoot,
|
|
17
|
+
};
|
|
18
|
+
var use_composer_1 = require("./use-composer");
|
|
19
|
+
Object.defineProperty(exports, "useComposer", { enumerable: true, get: function () { return use_composer_1.useComposer; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FileUIPart } from "ai";
|
|
2
|
+
export interface ComposerContextValue {
|
|
3
|
+
input: string;
|
|
4
|
+
setInput: (value: string) => void;
|
|
5
|
+
files: FileUIPart[];
|
|
6
|
+
addFile: (file: FileUIPart) => void;
|
|
7
|
+
removeFile: (index: number) => void;
|
|
8
|
+
clearFiles: () => void;
|
|
9
|
+
submit: () => void;
|
|
10
|
+
isDisabled: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const ComposerContextProvider: import("react").Provider<ComposerContextValue | null>, useComposer: () => ComposerContextValue, ComposerContext: import("react").Context<ComposerContextValue | null>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ComposerContext = exports.useComposer = exports.ComposerContextProvider = void 0;
|
|
5
|
+
const create_context_1 = require("../../utils/create-context");
|
|
6
|
+
_a = (0, create_context_1.createContext)("Composer"), exports.ComposerContextProvider = _a[0], exports.useComposer = _a[1], exports.ComposerContext = _a[2];
|