@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @kognitivedev/ui
|
|
2
|
+
|
|
3
|
+
## 0.2.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- release
|
|
8
|
+
|
|
9
|
+
- Updated dependencies []:
|
|
10
|
+
- @kognitivedev/shared@0.2.11
|
|
11
|
+
|
|
12
|
+
## 0.2.10
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- release
|
|
17
|
+
|
|
18
|
+
- Updated dependencies []:
|
|
19
|
+
- @kognitivedev/shared@0.2.10
|
package/README.md
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# @kognitivedev/ui
|
|
2
|
+
|
|
3
|
+
React components for building agentic chat UIs with Kognitive. Drop-in `<Thread />` for instant results, or use headless primitives for full control.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @kognitivedev/ui
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**Peer dependencies:** `react`, `ai`, `@ai-sdk/react`, `zod`
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { KognitiveUI } from "@kognitivedev/ui";
|
|
17
|
+
|
|
18
|
+
function App() {
|
|
19
|
+
return (
|
|
20
|
+
<KognitiveUI agentName="my-agent" baseUrl="http://localhost:3001">
|
|
21
|
+
<KognitiveUI.Thread />
|
|
22
|
+
</KognitiveUI>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or point at a custom API route:
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
<KognitiveUI api="/api/chat" agentName="assistant" resourceId={{ userId: "user-1" }}>
|
|
31
|
+
<KognitiveUI.Thread allowAttachments />
|
|
32
|
+
</KognitiveUI>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
### Tool UI Registration
|
|
38
|
+
|
|
39
|
+
Register custom React components for tool calls — type-safe when using `@kognitivedev/tools`:
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { makeToolUI } from "@kognitivedev/ui";
|
|
43
|
+
import { weatherTool } from "./tools";
|
|
44
|
+
|
|
45
|
+
const WeatherUI = makeToolUI({
|
|
46
|
+
tool: weatherTool,
|
|
47
|
+
render: ({ input, output, state }) => (
|
|
48
|
+
<div>{input.city}: {output?.temp}deg</div>
|
|
49
|
+
),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
<KognitiveUI toolUIs={[WeatherUI]} ...>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Batch register by name with `toolkit()`:
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { toolkit } from "@kognitivedev/ui";
|
|
59
|
+
|
|
60
|
+
const myToolkit = toolkit({
|
|
61
|
+
"weather-lookup": { render: ({ input, output }) => <WeatherCard {...output} /> },
|
|
62
|
+
"calculate": { render: ({ input, output }) => <span>{output?.result}</span> },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
<KognitiveUI toolkit={myToolkit} ...>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Message Editing
|
|
69
|
+
|
|
70
|
+
Users can edit sent messages and regenerate from that point. The Edit button appears on user messages, and submitting the edit trims the conversation and re-sends.
|
|
71
|
+
|
|
72
|
+
### Feedback / Ratings
|
|
73
|
+
|
|
74
|
+
Thumbs up/down on assistant messages:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
<KognitiveUI
|
|
78
|
+
onFeedback={(messageId, type) => {
|
|
79
|
+
// type is "positive" or "negative"
|
|
80
|
+
fetch("/api/feedback", { method: "POST", body: JSON.stringify({ messageId, type }) });
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Suggested Follow-ups
|
|
86
|
+
|
|
87
|
+
Show clickable suggestion chips after the assistant responds:
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
<KognitiveUI suggestions={["What's the weather?", "Tell me more"]}>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Tool Approval (Human-in-the-Loop)
|
|
94
|
+
|
|
95
|
+
When a tool enters `approval-requested` state, an Approve/Reject card renders automatically:
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
<KognitiveUI
|
|
99
|
+
onToolApproval={(toolCallId, approved) => {
|
|
100
|
+
console.log(`Tool ${toolCallId}: ${approved ? "approved" : "rejected"}`);
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Error Display
|
|
106
|
+
|
|
107
|
+
Stream errors are shown as dismissible banners via `ThreadPrimitive.Error` and the `ErrorBanner` component.
|
|
108
|
+
|
|
109
|
+
### File Attachments
|
|
110
|
+
|
|
111
|
+
Click-to-upload, drag-and-drop, and paste-to-upload are all supported:
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
<KognitiveUI.Thread allowAttachments />
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Keyboard Shortcuts
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
import { useKeyboardShortcuts } from "@kognitivedev/ui";
|
|
121
|
+
|
|
122
|
+
useKeyboardShortcuts([
|
|
123
|
+
{ key: "Escape", handler: () => stop() },
|
|
124
|
+
{ key: "k", ctrl: true, handler: () => clearMessages() },
|
|
125
|
+
]);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Events System
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
import { useKognitiveEvent, KognitiveEventEmitter } from "@kognitivedev/ui";
|
|
132
|
+
|
|
133
|
+
const emitter = new KognitiveEventEmitter();
|
|
134
|
+
useKognitiveEvent(emitter, "message:received", (data) => {
|
|
135
|
+
analytics.track("message_received", data);
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Events: `message:send`, `message:received`, `status:change`, `tool:invoked`, `tool:completed`, `error`
|
|
140
|
+
|
|
141
|
+
### Thread Management
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
<KognitiveUI baseUrl="http://localhost:3001" agentName="agent" threads>
|
|
145
|
+
<div className="grid grid-cols-[280px_1fr]">
|
|
146
|
+
<KognitiveUI.ThreadList />
|
|
147
|
+
<KognitiveUI.Thread />
|
|
148
|
+
</div>
|
|
149
|
+
</KognitiveUI>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## API Reference
|
|
153
|
+
|
|
154
|
+
### `<KognitiveUI>` Props
|
|
155
|
+
|
|
156
|
+
| Prop | Type | Description |
|
|
157
|
+
|------|------|-------------|
|
|
158
|
+
| `api` | `string` | Explicit API endpoint URL. Takes priority over baseUrl+agentName. |
|
|
159
|
+
| `agentName` | `string` | **Required.** Agent name. |
|
|
160
|
+
| `baseUrl` | `string` | Base URL of the Kognitive runtime. |
|
|
161
|
+
| `headers` | `Record<string, string>` | Auth headers. |
|
|
162
|
+
| `resourceId` | `{ userId?, sessionId?, organizationId? }` | User identity. |
|
|
163
|
+
| `sessionId` | `string` | Controlled session/thread ID. |
|
|
164
|
+
| `threads` | `boolean` | Enable thread management sidebar. |
|
|
165
|
+
| `threadApiBase` | `string` | Override thread API base URL. |
|
|
166
|
+
| `toolUIs` | `ToolUIRegistration[]` | Tool UI registrations from `makeToolUI()`. |
|
|
167
|
+
| `toolkit` | `ToolUIRegistration[]` | Tool UI registrations from `toolkit()`. |
|
|
168
|
+
| `body` | `Record<string, unknown>` | Extra request body fields. |
|
|
169
|
+
| `suggestions` | `string[]` | Follow-up prompt suggestions. |
|
|
170
|
+
| `onFeedback` | `(messageId, type) => void` | Feedback callback (positive/negative). |
|
|
171
|
+
| `onToolApproval` | `(toolCallId, approved) => void` | Tool approval callback. |
|
|
172
|
+
|
|
173
|
+
### Primitives
|
|
174
|
+
|
|
175
|
+
Headless, unstyled components. Compose them for full control.
|
|
176
|
+
|
|
177
|
+
- **ThreadPrimitive** — `Root`, `Messages`, `Empty`, `Loading`, `Error`, `Suggestions`, `ScrollToBottom`
|
|
178
|
+
- **MessagePrimitive** — `Root`, `Content`, `Role`
|
|
179
|
+
- **ComposerPrimitive** — `Root`, `Input`, `Send`, `Attachments`, `AttachmentTrigger`, `EditRoot`
|
|
180
|
+
- **ActionBarPrimitive** — `Root`, `Copy`, `Retry`, `Stop`, `Feedback`, `Edit`
|
|
181
|
+
- **ToolUIPrimitive** — `Root`, `Fallback`
|
|
182
|
+
- **ThreadListPrimitive** — `Root`, `Items`, `Item`, `New`
|
|
183
|
+
|
|
184
|
+
### Composed Components
|
|
185
|
+
|
|
186
|
+
Pre-styled with Tailwind. Every `className` is overridable.
|
|
187
|
+
|
|
188
|
+
- `Thread` — Full chat: messages + composer + status + error + suggestions
|
|
189
|
+
- `Message` — Bubble with avatar, content, edit mode, feedback, copy
|
|
190
|
+
- `Composer` — Input + send + attachment support (drag-drop, paste)
|
|
191
|
+
- `ThreadList` — Sidebar with thread items + new button
|
|
192
|
+
- `ToolInvocation` — Collapsible tool card with approval UI
|
|
193
|
+
- `ToolApproval` — Approve/reject card for tool calls
|
|
194
|
+
- `MarkdownContent` — Basic markdown renderer
|
|
195
|
+
- `ErrorBanner` — Dismissible error display
|
|
196
|
+
- `Suggestions` — Follow-up prompt chips
|
|
197
|
+
- `AttachmentPreview` — File/image thumbnails
|
|
198
|
+
- `StatusIndicator` — Streaming/ready/error dot
|
|
199
|
+
|
|
200
|
+
### Hooks
|
|
201
|
+
|
|
202
|
+
- `useKognitiveChat(config)` — Standalone chat hook (no provider needed)
|
|
203
|
+
- `useKognitive()` — Access full context (messages, send, status, error, etc.)
|
|
204
|
+
- `useThreadManager(config)` — Thread CRUD operations
|
|
205
|
+
- `useKeyboardShortcuts(shortcuts)` — Register keyboard shortcuts
|
|
206
|
+
- `useKognitiveEvent(emitter, event, handler)` — Subscribe to lifecycle events
|
|
207
|
+
- `useAutoScroll(deps)` — Auto-scroll on dependency change
|
|
208
|
+
- `useCopyToClipboard()` — Copy text with success state
|
|
209
|
+
- `useStreamingStatus()` — Get current ChatStatus
|
|
210
|
+
|
|
211
|
+
### Primitive Hooks
|
|
212
|
+
|
|
213
|
+
- `useThread()` — Thread-level state (messages, status, send, stop)
|
|
214
|
+
- `useMessage()` — Message-level state (message, isEditing, startEdit, submitEdit)
|
|
215
|
+
- `useComposer()` — Composer state (input, files, submit, isDisabled)
|
|
216
|
+
- `useThreadList()` — Thread list state (threads, activeSessionId, createThread)
|
|
217
|
+
|
|
218
|
+
## Custom Layout with Primitives
|
|
219
|
+
|
|
220
|
+
```tsx
|
|
221
|
+
import {
|
|
222
|
+
KognitiveUI,
|
|
223
|
+
ThreadPrimitive,
|
|
224
|
+
MessagePrimitive,
|
|
225
|
+
ComposerPrimitive,
|
|
226
|
+
ActionBarPrimitive,
|
|
227
|
+
} from "@kognitivedev/ui";
|
|
228
|
+
|
|
229
|
+
<KognitiveUI api="/api/chat" agentName="agent">
|
|
230
|
+
<ThreadPrimitive.Root>
|
|
231
|
+
<ThreadPrimitive.Empty>No messages yet</ThreadPrimitive.Empty>
|
|
232
|
+
<ThreadPrimitive.Error>{(err) => <p>{err.message}</p>}</ThreadPrimitive.Error>
|
|
233
|
+
|
|
234
|
+
<ThreadPrimitive.Messages>
|
|
235
|
+
{(message) => (
|
|
236
|
+
<MessagePrimitive.Root key={message.id} message={message}>
|
|
237
|
+
<MessagePrimitive.Content
|
|
238
|
+
components={{
|
|
239
|
+
Text: ({ text }) => <MyMarkdown>{text}</MyMarkdown>,
|
|
240
|
+
}}
|
|
241
|
+
/>
|
|
242
|
+
<ActionBarPrimitive.Root>
|
|
243
|
+
<ActionBarPrimitive.Copy />
|
|
244
|
+
<ActionBarPrimitive.Feedback />
|
|
245
|
+
<ActionBarPrimitive.Edit />
|
|
246
|
+
</ActionBarPrimitive.Root>
|
|
247
|
+
</MessagePrimitive.Root>
|
|
248
|
+
)}
|
|
249
|
+
</ThreadPrimitive.Messages>
|
|
250
|
+
|
|
251
|
+
<ThreadPrimitive.Suggestions />
|
|
252
|
+
|
|
253
|
+
<ComposerPrimitive.Root>
|
|
254
|
+
<ComposerPrimitive.Attachments />
|
|
255
|
+
<ComposerPrimitive.Input placeholder="Ask..." />
|
|
256
|
+
<ComposerPrimitive.Send>Send</ComposerPrimitive.Send>
|
|
257
|
+
</ComposerPrimitive.Root>
|
|
258
|
+
</ThreadPrimitive.Root>
|
|
259
|
+
</KognitiveUI>
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## License
|
|
263
|
+
|
|
264
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const registry_1 = require("../tool-ui/registry");
|
|
5
|
+
(0, vitest_1.describe)("Context isolation", () => {
|
|
6
|
+
(0, vitest_1.it)("ToolUIRegistry can be constructed standalone", () => {
|
|
7
|
+
const registry = new registry_1.ToolUIRegistry();
|
|
8
|
+
(0, vitest_1.expect)(registry.names()).toHaveLength(0);
|
|
9
|
+
});
|
|
10
|
+
(0, vitest_1.it)("ToolUIRegistry supports full CRUD lifecycle", () => {
|
|
11
|
+
const registry = new registry_1.ToolUIRegistry();
|
|
12
|
+
// Initially empty
|
|
13
|
+
(0, vitest_1.expect)(registry.has("tool-a")).toBe(false);
|
|
14
|
+
(0, vitest_1.expect)(registry.get("tool-a")).toBeUndefined();
|
|
15
|
+
// Register
|
|
16
|
+
const component = () => null;
|
|
17
|
+
registry.register({ toolName: "tool-a", component });
|
|
18
|
+
(0, vitest_1.expect)(registry.has("tool-a")).toBe(true);
|
|
19
|
+
(0, vitest_1.expect)(registry.get("tool-a")).toBe(component);
|
|
20
|
+
(0, vitest_1.expect)(registry.names()).toContain("tool-a");
|
|
21
|
+
// Overwrite
|
|
22
|
+
const component2 = () => null;
|
|
23
|
+
registry.register({ toolName: "tool-a", component: component2 });
|
|
24
|
+
(0, vitest_1.expect)(registry.get("tool-a")).toBe(component2);
|
|
25
|
+
// Multiple
|
|
26
|
+
registry.register({ toolName: "tool-b", component });
|
|
27
|
+
(0, vitest_1.expect)(registry.names()).toHaveLength(2);
|
|
28
|
+
});
|
|
29
|
+
(0, vitest_1.it)("ToolUIRegistry.registerAll registers multiple at once", () => {
|
|
30
|
+
const registry = new registry_1.ToolUIRegistry();
|
|
31
|
+
registry.registerAll([
|
|
32
|
+
{ toolName: "a", component: () => null },
|
|
33
|
+
{ toolName: "b", component: () => null },
|
|
34
|
+
{ toolName: "c", component: () => null },
|
|
35
|
+
]);
|
|
36
|
+
(0, vitest_1.expect)(registry.names()).toHaveLength(3);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const use_kognitive_event_1 = require("../hooks/use-kognitive-event");
|
|
5
|
+
(0, vitest_1.describe)("KognitiveEventEmitter", () => {
|
|
6
|
+
(0, vitest_1.it)("emits events to registered listeners", () => {
|
|
7
|
+
const emitter = new use_kognitive_event_1.KognitiveEventEmitter();
|
|
8
|
+
const handler = vitest_1.vi.fn();
|
|
9
|
+
emitter.on("message:send", handler);
|
|
10
|
+
emitter.emit("message:send", { text: "hello" });
|
|
11
|
+
(0, vitest_1.expect)(handler).toHaveBeenCalledWith({ text: "hello" });
|
|
12
|
+
});
|
|
13
|
+
(0, vitest_1.it)("supports multiple listeners for the same event", () => {
|
|
14
|
+
const emitter = new use_kognitive_event_1.KognitiveEventEmitter();
|
|
15
|
+
const h1 = vitest_1.vi.fn();
|
|
16
|
+
const h2 = vitest_1.vi.fn();
|
|
17
|
+
emitter.on("message:received", h1);
|
|
18
|
+
emitter.on("message:received", h2);
|
|
19
|
+
emitter.emit("message:received", "data");
|
|
20
|
+
(0, vitest_1.expect)(h1).toHaveBeenCalledOnce();
|
|
21
|
+
(0, vitest_1.expect)(h2).toHaveBeenCalledOnce();
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.it)("returns an unsubscribe function", () => {
|
|
24
|
+
const emitter = new use_kognitive_event_1.KognitiveEventEmitter();
|
|
25
|
+
const handler = vitest_1.vi.fn();
|
|
26
|
+
const unsub = emitter.on("status:change", handler);
|
|
27
|
+
emitter.emit("status:change", "streaming");
|
|
28
|
+
(0, vitest_1.expect)(handler).toHaveBeenCalledOnce();
|
|
29
|
+
unsub();
|
|
30
|
+
emitter.emit("status:change", "ready");
|
|
31
|
+
(0, vitest_1.expect)(handler).toHaveBeenCalledOnce(); // not called again
|
|
32
|
+
});
|
|
33
|
+
(0, vitest_1.it)("does not throw when emitting with no listeners", () => {
|
|
34
|
+
const emitter = new use_kognitive_event_1.KognitiveEventEmitter();
|
|
35
|
+
(0, vitest_1.expect)(() => emitter.emit("error", new Error("test"))).not.toThrow();
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.it)("swallows listener errors", () => {
|
|
38
|
+
const emitter = new use_kognitive_event_1.KognitiveEventEmitter();
|
|
39
|
+
emitter.on("tool:invoked", () => { throw new Error("boom"); });
|
|
40
|
+
const good = vitest_1.vi.fn();
|
|
41
|
+
emitter.on("tool:invoked", good);
|
|
42
|
+
(0, vitest_1.expect)(() => emitter.emit("tool:invoked", {})).not.toThrow();
|
|
43
|
+
(0, vitest_1.expect)(good).toHaveBeenCalledOnce();
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)("supports all event types", () => {
|
|
46
|
+
const emitter = new use_kognitive_event_1.KognitiveEventEmitter();
|
|
47
|
+
const events = [
|
|
48
|
+
"message:send",
|
|
49
|
+
"message:received",
|
|
50
|
+
"status:change",
|
|
51
|
+
"tool:invoked",
|
|
52
|
+
"tool:completed",
|
|
53
|
+
"error",
|
|
54
|
+
];
|
|
55
|
+
for (const event of events) {
|
|
56
|
+
const handler = vitest_1.vi.fn();
|
|
57
|
+
emitter.on(event, handler);
|
|
58
|
+
emitter.emit(event, "test");
|
|
59
|
+
(0, vitest_1.expect)(handler).toHaveBeenCalledWith("test");
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
// Test the shortcut matching logic directly (not the hook, since it needs React)
|
|
5
|
+
(0, vitest_1.describe)("Keyboard shortcut matching", () => {
|
|
6
|
+
function matchShortcut(shortcut, event) {
|
|
7
|
+
const ctrlOrMeta = shortcut.ctrl || shortcut.meta;
|
|
8
|
+
const matchesMod = ctrlOrMeta ? !!(event.ctrlKey || event.metaKey) : true;
|
|
9
|
+
const matchesShift = shortcut.shift ? !!event.shiftKey : !event.shiftKey;
|
|
10
|
+
return event.key.toLowerCase() === shortcut.key.toLowerCase() && matchesMod && matchesShift;
|
|
11
|
+
}
|
|
12
|
+
(0, vitest_1.it)("matches simple key", () => {
|
|
13
|
+
(0, vitest_1.expect)(matchShortcut({ key: "Escape" }, { key: "Escape" })).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
(0, vitest_1.it)("does not match different key", () => {
|
|
16
|
+
(0, vitest_1.expect)(matchShortcut({ key: "Escape" }, { key: "Enter" })).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.it)("matches Ctrl+key", () => {
|
|
19
|
+
(0, vitest_1.expect)(matchShortcut({ key: "c", ctrl: true }, { key: "c", ctrlKey: true })).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
(0, vitest_1.it)("matches Meta+key (Mac Cmd)", () => {
|
|
22
|
+
(0, vitest_1.expect)(matchShortcut({ key: "c", meta: true }, { key: "c", metaKey: true })).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
(0, vitest_1.it)("matches Ctrl+Shift+key", () => {
|
|
25
|
+
(0, vitest_1.expect)(matchShortcut({ key: "c", ctrl: true, shift: true }, { key: "c", ctrlKey: true, shiftKey: true })).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
(0, vitest_1.it)("does not match when shift is required but not pressed", () => {
|
|
28
|
+
(0, vitest_1.expect)(matchShortcut({ key: "c", ctrl: true, shift: true }, { key: "c", ctrlKey: true, shiftKey: false })).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.it)("does not match when shift is pressed but not required", () => {
|
|
31
|
+
(0, vitest_1.expect)(matchShortcut({ key: "c", ctrl: true }, { key: "c", ctrlKey: true, shiftKey: true })).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
(0, vitest_1.it)("is case insensitive", () => {
|
|
34
|
+
(0, vitest_1.expect)(matchShortcut({ key: "escape" }, { key: "Escape" })).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const kognitive_runtime_1 = require("../runtime/kognitive-runtime");
|
|
5
|
+
(0, vitest_1.describe)("KognitiveRuntime", () => {
|
|
6
|
+
(0, vitest_1.it)("creates a transport from config", () => {
|
|
7
|
+
const runtime = new kognitive_runtime_1.KognitiveRuntime({
|
|
8
|
+
baseUrl: "http://localhost:3001",
|
|
9
|
+
agentName: "test-agent",
|
|
10
|
+
});
|
|
11
|
+
const transport = runtime.createTransport();
|
|
12
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
(0, vitest_1.it)("creates a transport with custom sessionId", () => {
|
|
15
|
+
const runtime = new kognitive_runtime_1.KognitiveRuntime({
|
|
16
|
+
baseUrl: "http://localhost:3001",
|
|
17
|
+
agentName: "test-agent",
|
|
18
|
+
});
|
|
19
|
+
const transport = runtime.createTransport("session-123");
|
|
20
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.it)("creates ThreadManager when threads=true", () => {
|
|
23
|
+
const runtime = new kognitive_runtime_1.KognitiveRuntime({
|
|
24
|
+
baseUrl: "http://localhost:3001",
|
|
25
|
+
agentName: "test-agent",
|
|
26
|
+
threads: true,
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.expect)(runtime.threadManager).not.toBeNull();
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.it)("does not create ThreadManager when threads=false", () => {
|
|
31
|
+
const runtime = new kognitive_runtime_1.KognitiveRuntime({
|
|
32
|
+
baseUrl: "http://localhost:3001",
|
|
33
|
+
agentName: "test-agent",
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.expect)(runtime.threadManager).toBeNull();
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.it)("uses custom threadApiBase", () => {
|
|
38
|
+
const runtime = new kognitive_runtime_1.KognitiveRuntime({
|
|
39
|
+
baseUrl: "http://localhost:3001",
|
|
40
|
+
agentName: "test-agent",
|
|
41
|
+
threads: true,
|
|
42
|
+
threadApiBase: "http://custom:4000/threads",
|
|
43
|
+
});
|
|
44
|
+
(0, vitest_1.expect)(runtime.threadManager).not.toBeNull();
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.it)("stores config for later access", () => {
|
|
47
|
+
const config = {
|
|
48
|
+
baseUrl: "http://localhost:3001",
|
|
49
|
+
agentName: "test-agent",
|
|
50
|
+
headers: { Authorization: "Bearer token" },
|
|
51
|
+
resourceId: { userId: "user-1" },
|
|
52
|
+
};
|
|
53
|
+
const runtime = new kognitive_runtime_1.KognitiveRuntime(config);
|
|
54
|
+
(0, vitest_1.expect)(runtime.config.baseUrl).toBe(config.baseUrl);
|
|
55
|
+
(0, vitest_1.expect)(runtime.config.agentName).toBe(config.agentName);
|
|
56
|
+
(0, vitest_1.expect)(runtime.config.headers).toEqual(config.headers);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const kognitive_transport_1 = require("../runtime/kognitive-transport");
|
|
5
|
+
(0, vitest_1.describe)("createKognitiveTransport", () => {
|
|
6
|
+
(0, vitest_1.describe)("URL resolution", () => {
|
|
7
|
+
(0, vitest_1.it)("uses baseUrl + agentName to construct URL", () => {
|
|
8
|
+
const transport = (0, kognitive_transport_1.createKognitiveTransport)({
|
|
9
|
+
baseUrl: "http://localhost:3001",
|
|
10
|
+
agentName: "my-agent",
|
|
11
|
+
});
|
|
12
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
(0, vitest_1.it)("uses explicit api URL when provided", () => {
|
|
15
|
+
const transport = (0, kognitive_transport_1.createKognitiveTransport)({
|
|
16
|
+
api: "/api/chat",
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
(0, vitest_1.it)("api takes priority over baseUrl + agentName", () => {
|
|
21
|
+
const transport = (0, kognitive_transport_1.createKognitiveTransport)({
|
|
22
|
+
api: "/api/custom",
|
|
23
|
+
baseUrl: "http://localhost:3001",
|
|
24
|
+
agentName: "agent",
|
|
25
|
+
});
|
|
26
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.it)("throws when neither api nor baseUrl+agentName provided", () => {
|
|
29
|
+
(0, vitest_1.expect)(() => (0, kognitive_transport_1.createKognitiveTransport)({})).toThrow("requires either `api` or both `baseUrl` and `agentName`");
|
|
30
|
+
});
|
|
31
|
+
(0, vitest_1.it)("throws when only baseUrl provided (no agentName)", () => {
|
|
32
|
+
(0, vitest_1.expect)(() => (0, kognitive_transport_1.createKognitiveTransport)({ baseUrl: "http://localhost:3001" })).toThrow();
|
|
33
|
+
});
|
|
34
|
+
(0, vitest_1.it)("throws when only agentName provided (no baseUrl)", () => {
|
|
35
|
+
(0, vitest_1.expect)(() => (0, kognitive_transport_1.createKognitiveTransport)({ agentName: "my-agent" })).toThrow();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
(0, vitest_1.describe)("URL construction", () => {
|
|
39
|
+
(0, vitest_1.it)("URL-encodes the agent name", () => {
|
|
40
|
+
const transport = (0, kognitive_transport_1.createKognitiveTransport)({
|
|
41
|
+
baseUrl: "http://localhost:3001",
|
|
42
|
+
agentName: "agent with spaces",
|
|
43
|
+
});
|
|
44
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
45
|
+
});
|
|
46
|
+
(0, vitest_1.it)("strips trailing slash from baseUrl", () => {
|
|
47
|
+
const transport = (0, kognitive_transport_1.createKognitiveTransport)({
|
|
48
|
+
baseUrl: "http://localhost:3001/",
|
|
49
|
+
agentName: "test",
|
|
50
|
+
});
|
|
51
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
(0, vitest_1.describe)("config passthrough", () => {
|
|
55
|
+
(0, vitest_1.it)("accepts sessionId", () => {
|
|
56
|
+
const transport = (0, kognitive_transport_1.createKognitiveTransport)({
|
|
57
|
+
api: "/api/chat",
|
|
58
|
+
sessionId: "sess-123",
|
|
59
|
+
});
|
|
60
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
61
|
+
});
|
|
62
|
+
(0, vitest_1.it)("accepts full resourceId with userId, sessionId, organizationId", () => {
|
|
63
|
+
const transport = (0, kognitive_transport_1.createKognitiveTransport)({
|
|
64
|
+
api: "/api/chat",
|
|
65
|
+
resourceId: {
|
|
66
|
+
userId: "user-1",
|
|
67
|
+
sessionId: "sess-1",
|
|
68
|
+
organizationId: "org-1",
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
72
|
+
});
|
|
73
|
+
(0, vitest_1.it)("accepts custom headers", () => {
|
|
74
|
+
const transport = (0, kognitive_transport_1.createKognitiveTransport)({
|
|
75
|
+
api: "/api/chat",
|
|
76
|
+
headers: { Authorization: "Bearer token123" },
|
|
77
|
+
});
|
|
78
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
79
|
+
});
|
|
80
|
+
(0, vitest_1.it)("accepts extra body fields", () => {
|
|
81
|
+
const transport = (0, kognitive_transport_1.createKognitiveTransport)({
|
|
82
|
+
api: "/api/chat",
|
|
83
|
+
body: { agentName: "assistant", customField: true },
|
|
84
|
+
});
|
|
85
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
86
|
+
});
|
|
87
|
+
(0, vitest_1.it)("sends agentName in body when using api mode", () => {
|
|
88
|
+
// When api is set and agentName is provided, agentName should be in body
|
|
89
|
+
const transport = (0, kognitive_transport_1.createKognitiveTransport)({
|
|
90
|
+
api: "/api/chat",
|
|
91
|
+
agentName: "assistant",
|
|
92
|
+
});
|
|
93
|
+
(0, vitest_1.expect)(transport).toBeDefined();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const make_tool_ui_1 = require("../tool-ui/make-tool-ui");
|
|
5
|
+
const registry_1 = require("../tool-ui/registry");
|
|
6
|
+
(0, vitest_1.describe)("makeToolUI", () => {
|
|
7
|
+
(0, vitest_1.it)("creates a registration from a tool object with id", () => {
|
|
8
|
+
const render = () => null;
|
|
9
|
+
const reg = (0, make_tool_ui_1.makeToolUI)({
|
|
10
|
+
tool: { id: "weather" },
|
|
11
|
+
render,
|
|
12
|
+
});
|
|
13
|
+
(0, vitest_1.expect)(reg.toolName).toBe("weather");
|
|
14
|
+
(0, vitest_1.expect)(reg.component).toBe(render);
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.it)("creates a registration from toolName string", () => {
|
|
17
|
+
const render = () => null;
|
|
18
|
+
const reg = (0, make_tool_ui_1.makeToolUI)({
|
|
19
|
+
toolName: "database_query",
|
|
20
|
+
render,
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.expect)(reg.toolName).toBe("database_query");
|
|
23
|
+
(0, vitest_1.expect)(reg.component).toBe(render);
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)("integrates with ToolUIRegistry", () => {
|
|
26
|
+
const reg = (0, make_tool_ui_1.makeToolUI)({
|
|
27
|
+
tool: { id: "my-tool" },
|
|
28
|
+
render: () => null,
|
|
29
|
+
});
|
|
30
|
+
const registry = new registry_1.ToolUIRegistry();
|
|
31
|
+
registry.register(reg);
|
|
32
|
+
(0, vitest_1.expect)(registry.has("my-tool")).toBe(true);
|
|
33
|
+
(0, vitest_1.expect)(registry.get("my-tool")).toBe(reg.component);
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.it)("tool.id takes priority over toolName in tool-based registration", () => {
|
|
36
|
+
const reg = (0, make_tool_ui_1.makeToolUI)({
|
|
37
|
+
tool: { id: "from-tool-id" },
|
|
38
|
+
render: () => null,
|
|
39
|
+
});
|
|
40
|
+
(0, vitest_1.expect)(reg.toolName).toBe("from-tool-id");
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.it)("multiple registrations can coexist in registry", () => {
|
|
43
|
+
const reg1 = (0, make_tool_ui_1.makeToolUI)({ tool: { id: "tool-a" }, render: () => "a" });
|
|
44
|
+
const reg2 = (0, make_tool_ui_1.makeToolUI)({ toolName: "tool-b", render: () => "b" });
|
|
45
|
+
const registry = new registry_1.ToolUIRegistry();
|
|
46
|
+
registry.register(reg1);
|
|
47
|
+
registry.register(reg2);
|
|
48
|
+
(0, vitest_1.expect)(registry.names()).toEqual(vitest_1.expect.arrayContaining(["tool-a", "tool-b"]));
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|