@sybilion/uilib 1.2.15 → 1.2.17

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.
Files changed (54) hide show
  1. package/dist/esm/components/ui/Chat/Chat.js +4 -3
  2. package/dist/esm/components/ui/Chat/Chat.styl.js +2 -2
  3. package/dist/esm/components/ui/Chat/ChatChrome/ChatChrome.js +20 -3
  4. package/dist/esm/components/ui/Chat/ChatChrome/ChatChrome.styl.js +2 -2
  5. package/dist/esm/components/ui/Chat/ChatEmptyState/ChatEmptyState.js +3 -2
  6. package/dist/esm/components/ui/Chat/ChatEmptyState/ChatEmptyState.styl.js +1 -1
  7. package/dist/esm/components/ui/Chat/ChatEmptyState/icons/sparkles.svg.js +77 -0
  8. package/dist/esm/components/ui/Chat/ChatPrompt/ChatPrompt.js +3 -13
  9. package/dist/esm/components/ui/Chat/ChatPrompt/ChatPrompt.styl.js +2 -2
  10. package/dist/esm/components/ui/Chat/ChatSheet/ChatSelector.js +14 -3
  11. package/dist/esm/components/ui/Chat/ChatSheet/ChatSelector.styl.js +7 -0
  12. package/dist/esm/components/ui/Chat/ChatSheet/ChatSheet.js +2 -1
  13. package/dist/esm/components/ui/Chat/ChatSheet/useChatPanelChromeModel.js +2 -15
  14. package/dist/esm/components/ui/Page/AppShell/AppShell.styl.js +1 -1
  15. package/dist/esm/components/ui/Page/PageContent/PageContent.styl.js +1 -1
  16. package/dist/esm/types/src/components/ui/Chat/Chat.d.ts +1 -1
  17. package/dist/esm/types/src/components/ui/Chat/Chat.types.d.ts +3 -2
  18. package/dist/esm/types/src/components/ui/Chat/ChatChrome/ChatChrome.d.ts +1 -1
  19. package/dist/esm/types/src/components/ui/Chat/ChatChrome/ChatChrome.types.d.ts +0 -1
  20. package/dist/esm/types/src/components/ui/Chat/ChatEmptyState/ChatEmptyState.d.ts +2 -1
  21. package/dist/esm/types/src/components/ui/Chat/ChatEmptyState/ChatEmptyState.types.d.ts +2 -0
  22. package/dist/esm/types/src/components/ui/Chat/ChatPrompt/ChatPrompt.d.ts +1 -1
  23. package/dist/esm/types/src/components/ui/Chat/ChatSheet/ChatSelector.d.ts +2 -1
  24. package/dist/esm/types/src/components/ui/Chat/ChatSheet/ChatSheet.d.ts +1 -1
  25. package/dist/esm/types/src/components/ui/Chat/ChatSheet/useChatPanelChromeModel.d.ts +4 -1
  26. package/package.json +1 -6
  27. package/src/components/ui/Chat/Chat.styl +10 -0
  28. package/src/components/ui/Chat/Chat.styl.d.ts +1 -0
  29. package/src/components/ui/Chat/Chat.tsx +14 -1
  30. package/src/components/ui/Chat/Chat.types.ts +3 -2
  31. package/src/components/ui/Chat/ChatChrome/ChatChrome.styl +10 -12
  32. package/src/components/ui/Chat/ChatChrome/ChatChrome.styl.d.ts +1 -3
  33. package/src/components/ui/Chat/ChatChrome/ChatChrome.tsx +24 -5
  34. package/src/components/ui/Chat/ChatChrome/ChatChrome.types.ts +0 -1
  35. package/src/components/ui/Chat/ChatEmptyState/ChatEmptyState.styl +5 -5
  36. package/src/components/ui/Chat/ChatEmptyState/ChatEmptyState.tsx +10 -3
  37. package/src/components/ui/Chat/ChatEmptyState/ChatEmptyState.types.ts +2 -0
  38. package/src/components/ui/Chat/ChatEmptyState/icons/sparkles.svg +22 -0
  39. package/src/components/ui/Chat/ChatPrompt/ChatPrompt.styl +0 -19
  40. package/src/components/ui/Chat/ChatPrompt/ChatPrompt.styl.d.ts +0 -2
  41. package/src/components/ui/Chat/ChatPrompt/ChatPrompt.tsx +1 -26
  42. package/src/components/ui/Chat/ChatSheet/ChatSelector.styl +24 -0
  43. package/src/components/ui/Chat/ChatSheet/ChatSelector.styl.d.ts +10 -0
  44. package/src/components/ui/Chat/ChatSheet/ChatSelector.tsx +59 -21
  45. package/src/components/ui/Chat/ChatSheet/ChatSheet.tsx +2 -0
  46. package/src/components/ui/Chat/ChatSheet/useChatPanelChromeModel.tsx +5 -16
  47. package/src/components/ui/Page/AppShell/AppShell.styl +2 -0
  48. package/src/components/ui/Page/PageContent/PageContent.styl +0 -1
  49. package/src/docs/docsHeaderActions.tsx +8 -0
  50. package/src/docs/index.tsx +3 -1
  51. package/src/docs/pages/ChatPage.tsx +93 -42
  52. package/dist/standalone/vite-sybilion-standalone-dev.d.ts +0 -13
  53. package/dist/standalone/vite-sybilion-standalone-dev.js +0 -49
  54. package/src/standalone/vite-sybilion-standalone-dev.ts +0 -65
@@ -1,18 +1,67 @@
1
- import { useState } from 'react';
2
-
3
- import {
4
- Chat,
5
- ChatMessage,
6
- ChatPrompt,
7
- MessageRole,
8
- } from '#uilib/components/ui/Chat';
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+
3
+ import { ChatChrome, Message, MessageRole } from '#uilib/components/ui/Chat';
9
4
  import { PageContentSection } from '#uilib/components/ui/Page';
5
+ import { ScrollRef } from '@homecode/ui';
10
6
 
11
7
  import { AppPageHeader } from '../components/AppPageHeader/AppPageHeader';
12
8
  import { DocsHeaderActions } from '../docsHeaderActions';
13
9
 
10
+ const NO_QUICK_REPLY_KEYS: ReadonlySet<string> = new Set();
11
+
12
+ const ASSISTANT_REPLY_TEXT =
13
+ 'This is a generic assistant reply for the docs preview. Wire your app to a real model here.';
14
+
15
+ function makeMessage(role: MessageRole, text: string): Message {
16
+ return {
17
+ id: crypto.randomUUID(),
18
+ role,
19
+ text,
20
+ timestamp: Date.now(),
21
+ };
22
+ }
23
+
14
24
  export default function ChatPage() {
15
- const [text, setText] = useState('');
25
+ const [messages, setMessages] = useState<Message[]>([]);
26
+ const [isLoading, setIsLoading] = useState(false);
27
+ const replyTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
28
+ const scrollRef = useRef<ScrollRef>(null);
29
+
30
+ useEffect(() => {
31
+ return () => {
32
+ if (replyTimeoutRef.current != null) {
33
+ clearTimeout(replyTimeoutRef.current);
34
+ }
35
+ };
36
+ }, []);
37
+
38
+ const isEmpty = messages.length === 0 && !isLoading;
39
+ const isLastMessageFromUser =
40
+ messages.length > 0 &&
41
+ messages[messages.length - 1]?.role === MessageRole.USER;
42
+
43
+ const onSubmit = useCallback(
44
+ (raw: string) => {
45
+ const text = raw.trim();
46
+ if (!text || isLoading) return;
47
+
48
+ setMessages(prev => [...prev, makeMessage(MessageRole.USER, text)]);
49
+ setIsLoading(true);
50
+
51
+ if (replyTimeoutRef.current != null) {
52
+ clearTimeout(replyTimeoutRef.current);
53
+ }
54
+ replyTimeoutRef.current = setTimeout(() => {
55
+ replyTimeoutRef.current = null;
56
+ setMessages(prev => [
57
+ ...prev,
58
+ makeMessage(MessageRole.ASSISTANT, ASSISTANT_REPLY_TEXT),
59
+ ]);
60
+ setIsLoading(false);
61
+ }, 900);
62
+ },
63
+ [isLoading],
64
+ );
16
65
 
17
66
  return (
18
67
  <>
@@ -22,39 +71,41 @@ export default function ChatPage() {
22
71
  subheader="Chat shell with message list and prompt."
23
72
  actions={<DocsHeaderActions />}
24
73
  />
25
- <PageContentSection
26
- style={{
27
- maxWidth: 560,
28
- border: '1px solid var(--border)',
29
- borderRadius: 12,
30
- padding: 16,
31
- }}
32
- >
33
- <Chat>
34
- <ChatMessage
35
- role={MessageRole.ASSISTANT}
36
- text="This is a static assistant message in the docs preview."
37
- />
38
- <ChatMessage role={MessageRole.USER} text="Example user message." />
39
- <ChatPrompt
40
- id="docs-chat-inline"
41
- placeholder="Message…"
42
- onSubmit={msg => {
43
- setText(msg);
44
- }}
45
- />
46
- {text ? (
47
- <p
48
- style={{
49
- marginTop: 12,
50
- fontSize: 12,
51
- color: 'var(--muted-foreground)',
52
- }}
53
- >
54
- Last submit (local only): {text}
55
- </p>
56
- ) : null}
57
- </Chat>
74
+ <PageContentSection>
75
+ <ChatChrome
76
+ showResizeHandle={false}
77
+ resizeHandle={undefined}
78
+ onClose={undefined}
79
+ isEmpty={isEmpty}
80
+ renderPresets={() => null}
81
+ messages={messages}
82
+ onQuickReply={() => {}}
83
+ suppressedQuickReplyKeys={NO_QUICK_REPLY_KEYS}
84
+ isLoading={isLoading}
85
+ scriptContinueLabel={undefined}
86
+ onScriptContinue={undefined}
87
+ showBranchActionsRow={false}
88
+ showSyntheticBranchButtons={false}
89
+ unusedBranchKeys={[]}
90
+ isScriptComplete={false}
91
+ onGenerateDashboard={undefined}
92
+ generatingDashboard={false}
93
+ onGenerateDashboardClick={() => {}}
94
+ showInlinePresets={false}
95
+ isLastMessageFromUser={isLastMessageFromUser}
96
+ scrollRef={scrollRef}
97
+ effectiveScopeId="docs-chat-inline"
98
+ onPromptSubmit={onSubmit}
99
+ onChatDeleted={() => {}}
100
+ emptyState={{
101
+ title: 'Start a conversation',
102
+ description:
103
+ 'Send a message below. This demo appends a canned reply after a short delay.',
104
+ additionalContent: (
105
+ <p>Optional empty-state slot via additionalContent.</p>
106
+ ),
107
+ }}
108
+ />
58
109
  </PageContentSection>
59
110
  </>
60
111
  );
@@ -1,13 +0,0 @@
1
- import type { UserConfig } from 'vite';
2
- export type SybilionStandaloneViteDevOptions = {
3
- mode: string;
4
- /** Directory containing `.env*` files. @default process.cwd() */
5
- envDir?: string;
6
- /** Prefix proxied to Sybilion API (SDK `apiPrefix`). @default `/api` */
7
- apiPrefix?: string;
8
- };
9
- /**
10
- * Vite `server` + `preview` fragment for standalone Sybilion SPAs: same-origin `/api` in dev,
11
- * proxied to `VITE_SYBILION_API_BASE_URL`. Uses `PORT` from env (default `3000`).
12
- */
13
- export declare function sybilionStandaloneViteDev(options: SybilionStandaloneViteDevOptions): Pick<UserConfig, 'server' | 'preview'>;
@@ -1,49 +0,0 @@
1
- import { loadEnv } from 'vite';
2
-
3
- const DEFAULT_PORT = 3000;
4
- const SYBILION_API_ENV = 'VITE_SYBILION_API_BASE_URL';
5
- let warnedMissingApiUrl = false;
6
- function parsePort(raw) {
7
- if (raw == null || raw === '')
8
- return DEFAULT_PORT;
9
- const n = Number.parseInt(raw, 10);
10
- if (!Number.isFinite(n) || n <= 0 || n > 65_535)
11
- return DEFAULT_PORT;
12
- return n;
13
- }
14
- function normalizeApiPrefix(apiPrefix) {
15
- return apiPrefix.startsWith('/') ? apiPrefix : `/${apiPrefix}`;
16
- }
17
- /**
18
- * Vite `server` + `preview` fragment for standalone Sybilion SPAs: same-origin `/api` in dev,
19
- * proxied to `VITE_SYBILION_API_BASE_URL`. Uses `PORT` from env (default `3000`).
20
- */
21
- function sybilionStandaloneViteDev(options) {
22
- const envDir = options.envDir ?? process.cwd();
23
- const apiPrefix = normalizeApiPrefix(options.apiPrefix ?? '/api');
24
- const env = loadEnv(options.mode, envDir, '');
25
- const port = parsePort(env.PORT);
26
- const target = (env[SYBILION_API_ENV] ?? '').replace(/\/$/, '');
27
- const proxy = {};
28
- if (target) {
29
- proxy[apiPrefix] = {
30
- target,
31
- changeOrigin: true,
32
- secure: true,
33
- };
34
- }
35
- else if (options.mode === 'development' && !warnedMissingApiUrl) {
36
- warnedMissingApiUrl = true;
37
- console.warn(`[@sybilion/uilib] ${SYBILION_API_ENV} is not set; API dev proxy disabled.`);
38
- }
39
- const serverPreview = {
40
- port,
41
- proxy,
42
- };
43
- return {
44
- server: serverPreview,
45
- preview: serverPreview,
46
- };
47
- }
48
-
49
- export { sybilionStandaloneViteDev };
@@ -1,65 +0,0 @@
1
- import type { UserConfig } from 'vite';
2
- import { loadEnv } from 'vite';
3
-
4
- const DEFAULT_PORT = 3000;
5
- const SYBILION_API_ENV = 'VITE_SYBILION_API_BASE_URL';
6
-
7
- export type SybilionStandaloneViteDevOptions = {
8
- mode: string;
9
- /** Directory containing `.env*` files. @default process.cwd() */
10
- envDir?: string;
11
- /** Prefix proxied to Sybilion API (SDK `apiPrefix`). @default `/api` */
12
- apiPrefix?: string;
13
- };
14
-
15
- let warnedMissingApiUrl = false;
16
-
17
- function parsePort(raw: string | undefined): number {
18
- if (raw == null || raw === '') return DEFAULT_PORT;
19
- const n = Number.parseInt(raw, 10);
20
- if (!Number.isFinite(n) || n <= 0 || n > 65_535) return DEFAULT_PORT;
21
- return n;
22
- }
23
-
24
- function normalizeApiPrefix(apiPrefix: string): string {
25
- return apiPrefix.startsWith('/') ? apiPrefix : `/${apiPrefix}`;
26
- }
27
-
28
- /**
29
- * Vite `server` + `preview` fragment for standalone Sybilion SPAs: same-origin `/api` in dev,
30
- * proxied to `VITE_SYBILION_API_BASE_URL`. Uses `PORT` from env (default `3000`).
31
- */
32
- export function sybilionStandaloneViteDev(
33
- options: SybilionStandaloneViteDevOptions,
34
- ): Pick<UserConfig, 'server' | 'preview'> {
35
- const envDir = options.envDir ?? process.cwd();
36
- const apiPrefix = normalizeApiPrefix(options.apiPrefix ?? '/api');
37
- const env = loadEnv(options.mode, envDir, '');
38
- const port = parsePort(env.PORT);
39
- const target = (env[SYBILION_API_ENV] ?? '').replace(/\/$/, '');
40
-
41
- const proxy: NonNullable<UserConfig['server']>['proxy'] = {};
42
-
43
- if (target) {
44
- proxy[apiPrefix] = {
45
- target,
46
- changeOrigin: true,
47
- secure: true,
48
- };
49
- } else if (options.mode === 'development' && !warnedMissingApiUrl) {
50
- warnedMissingApiUrl = true;
51
- console.warn(
52
- `[@sybilion/uilib] ${SYBILION_API_ENV} is not set; API dev proxy disabled.`,
53
- );
54
- }
55
-
56
- const serverPreview = {
57
- port,
58
- proxy,
59
- };
60
-
61
- return {
62
- server: serverPreview,
63
- preview: serverPreview,
64
- };
65
- }