chat-js 1.0.0-alpha.8 → 1.0.0-beta.0

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 (84) hide show
  1. package/README.md +7 -5
  2. package/dist/index.js +7161 -6308
  3. package/package.json +2 -2
  4. package/templates/chat-app/agent/agent.ts +0 -2
  5. package/templates/chat-app/app/editor.css +0 -6
  6. package/templates/chat-app/app/layout.tsx +11 -18
  7. package/templates/chat-app/app/opengraph-image.png +0 -0
  8. package/templates/chat-app/chat.config.ts +0 -44
  9. package/templates/chat-app/chatjs/core/gateway/runtime.ts +0 -7
  10. package/templates/chat-app/chatjs/core/ui/slots.tsx +15 -5
  11. package/templates/chat-app/chatjs/generated/installed-chat-ui.ts +4 -0
  12. package/templates/chat-app/chatjs/generated/installed.ts +2 -0
  13. package/templates/chat-app/chatjs/plugins/guest-chat/signed-out.tsx +7 -4
  14. package/templates/chat-app/chatjs/plugins/mcp/routes/connectors-page.tsx +4 -1
  15. package/templates/chat-app/chatjs/plugins/mcp/ui/connectors-settings.tsx +1 -1
  16. package/templates/chat-app/chatjs/plugins/mcp/ui/mcp-connect-dialog.tsx +1 -1
  17. package/templates/chat-app/chatjs/plugins/mcp/ui/mcp-create-dialog.tsx +1 -1
  18. package/templates/chat-app/chatjs/plugins/model-preferences/model-row.tsx +3 -0
  19. package/templates/chat-app/chatjs/plugins/model-preferences/models-settings.tsx +1 -0
  20. package/templates/chat-app/chatjs/plugins/projects/routes/project-page.tsx +10 -1
  21. package/templates/chat-app/chatjs/plugins/projects/ui/delete-project-dialog.tsx +0 -3
  22. package/templates/chat-app/chatjs/plugins/projects/ui/project-icon-picker.tsx +1 -0
  23. package/templates/chat-app/chatjs/plugins/streamdown-math/chat-ui.ts +11 -0
  24. package/templates/chat-app/chatjs/plugins/streamdown-math/plugin.json +6 -0
  25. package/templates/chat-app/chatjs/plugins/streamdown-mermaid/chat-ui.ts +10 -0
  26. package/templates/chat-app/chatjs/plugins/streamdown-mermaid/plugin.json +6 -0
  27. package/templates/chat-app/chatjs/providers/gateway.ts +49 -55
  28. package/templates/chat-app/chatjs/tools/generate-image/tool.test.ts +3 -14
  29. package/templates/chat-app/components/ai-elements/response.tsx +16 -15
  30. package/templates/chat-app/components/auth-form-view.tsx +35 -43
  31. package/templates/chat-app/components/chat/chat-composer.tsx +55 -20
  32. package/templates/chat-app/components/chat/chat-sidebar.tsx +5 -3
  33. package/templates/chat-app/components/composer/prompt-form.tsx +7 -1
  34. package/templates/chat-app/components/eve/eve-chat-error.tsx +12 -2
  35. package/templates/chat-app/components/eve/eve-conversation.tsx +223 -154
  36. package/templates/chat-app/components/eve/eve-creation-recovery.tsx +32 -1
  37. package/templates/chat-app/components/eve/eve-history-list.tsx +1 -1
  38. package/templates/chat-app/components/model-selection-indicator.tsx +12 -10
  39. package/templates/chat-app/components/model-selector-view.tsx +211 -186
  40. package/templates/chat-app/components/new-chat-button.tsx +1 -1
  41. package/templates/chat-app/components/settings/settings-nav.tsx +1 -1
  42. package/templates/chat-app/components/settings/settings-navigation-link.tsx +1 -0
  43. package/templates/chat-app/components/sidebar-top-row.tsx +1 -1
  44. package/templates/chat-app/components/ui/sidebar.tsx +1 -1
  45. package/templates/chat-app/components/ui/trace.tsx +1 -1
  46. package/templates/chat-app/hooks/use-auto-focus.ts +12 -13
  47. package/templates/chat-app/lib/ai/active-gateway.ts +0 -9
  48. package/templates/chat-app/lib/ai/app-models.test.ts +0 -4
  49. package/templates/chat-app/lib/ai/app-models.ts +11 -6
  50. package/templates/chat-app/lib/ai/gateways/registry.ts +4 -31
  51. package/templates/chat-app/lib/ai/model-catalog.ts +50 -0
  52. package/templates/chat-app/lib/ai/models.ts +4 -39
  53. package/templates/chat-app/lib/ai/providers.ts +2 -16
  54. package/templates/chat-app/lib/config-schema.ts +0 -96
  55. package/templates/chat-app/lib/devtools-disabled.ts +1 -0
  56. package/templates/chat-app/lib/eve/model-selection.test.ts +47 -50
  57. package/templates/chat-app/lib/eve/model-selection.ts +5 -37
  58. package/templates/chat-app/lib/eve/tool-cost.test.ts +18 -6
  59. package/templates/chat-app/lib/eve/tool-cost.ts +10 -18
  60. package/templates/chat-app/oxfmt.config.ts +0 -2
  61. package/templates/chat-app/package.json +7 -9
  62. package/templates/chat-app/proxy.ts +2 -4
  63. package/templates/chat-app/scripts/build-eve.test.ts +56 -0
  64. package/templates/chat-app/scripts/build-eve.ts +12 -5
  65. package/templates/chat-app/scripts/check-env.ts +2 -17
  66. package/templates/chat-app/scripts/environment-validation-report.ts +1 -20
  67. package/templates/chat-app/trpc/react.tsx +2 -2
  68. package/templates/electron/forge.config.ts +1 -19
  69. package/templates/electron/scripts/write-branding.ts +1 -5
  70. package/templates/chat-app/app/privacy/page.tsx +0 -153
  71. package/templates/chat-app/app/terms/page.tsx +0 -270
  72. package/templates/chat-app/components/ai-elements/context-hover.radix.tsx +0 -15
  73. package/templates/chat-app/components/ai-elements/context-hover.tsx +0 -17
  74. package/templates/chat-app/components/ai-elements/context.tsx +0 -405
  75. package/templates/chat-app/components/composer/editor.css +0 -96
  76. package/templates/chat-app/components/lexical-chat-input.tsx +0 -276
  77. package/templates/chat-app/components/model-selection-indicator.radix.tsx +0 -17
  78. package/templates/chat-app/components/ui/resizable.tsx +0 -49
  79. package/templates/chat-app/lib/ai/gateways/fallback-models.ts +0 -29
  80. package/templates/chat-app/lib/ai/models.generated.ts +0 -4242
  81. package/templates/chat-app/lib/ai/usage-token-details.test.ts +0 -76
  82. package/templates/chat-app/lib/ai/usage-token-details.ts +0 -33
  83. package/templates/chat-app/scripts/fetch-models.ts +0 -30
  84. package/templates/chat-app/scripts/gateway-snapshot-warning.test.ts +0 -9
@@ -8,7 +8,6 @@ import {
8
8
  CardTitle,
9
9
  } from "@/components/ui/card";
10
10
  import { InternalLink } from "@/components/internal-link";
11
- import { cn } from "@/lib/utils";
12
11
 
13
12
  export const AuthFormView = ({
14
13
  mode,
@@ -27,46 +26,39 @@ export const AuthFormView = ({
27
26
  readonly children: ReactNode;
28
27
  readonly className?: string;
29
28
  }) => (
30
- <div className={cn("flex flex-col gap-6", className)}>
31
- <Card>
32
- <CardHeader className="text-center">
33
- <CardTitle className="text-xl">
34
- {title ?? (mode === "login" ? "Welcome back" : "Create an account")}
35
- </CardTitle>
36
- <CardDescription>
37
- {description ??
38
- (mode === "login"
39
- ? "Sign in to your account"
40
- : "Get started in seconds")}
41
- </CardDescription>
42
- </CardHeader>
43
- <CardContent>
44
- <div className="grid gap-6">
45
- {children}
46
- {footer ?? (
47
- <div className="text-center text-sm">
48
- {mode === "login"
49
- ? "Don't have an account? "
50
- : "Already have an account? "}
51
- <InternalLink
52
- className="underline underline-offset-4"
53
- href={
54
- mode === "login"
55
- ? `/register?${new URLSearchParams(query)}`
56
- : `/login?${new URLSearchParams(query)}`
57
- }
58
- >
59
- {mode === "login" ? "Sign up" : "Sign in"}
60
- </InternalLink>
61
- </div>
62
- )}
63
- </div>
64
- </CardContent>
65
- </Card>
66
- <div className="text-muted-foreground [&_a]:hover:text-primary text-center text-xs text-balance [&_a]:underline [&_a]:underline-offset-4">
67
- By clicking continue, you agree to our{" "}
68
- <InternalLink href="/terms">Terms of Service</InternalLink> and{" "}
69
- <InternalLink href="/privacy">Privacy Policy</InternalLink>.
70
- </div>
71
- </div>
29
+ <Card className={className}>
30
+ <CardHeader className="text-center">
31
+ <CardTitle className="text-xl">
32
+ {title ?? (mode === "login" ? "Welcome back" : "Create an account")}
33
+ </CardTitle>
34
+ <CardDescription>
35
+ {description ??
36
+ (mode === "login"
37
+ ? "Sign in to your account"
38
+ : "Get started in seconds")}
39
+ </CardDescription>
40
+ </CardHeader>
41
+ <CardContent>
42
+ <div className="grid gap-6">
43
+ {children}
44
+ {footer ?? (
45
+ <div className="text-center text-sm">
46
+ {mode === "login"
47
+ ? "Don't have an account? "
48
+ : "Already have an account? "}
49
+ <InternalLink
50
+ className="underline underline-offset-4"
51
+ href={
52
+ mode === "login"
53
+ ? `/register?${new URLSearchParams(query)}`
54
+ : `/login?${new URLSearchParams(query)}`
55
+ }
56
+ >
57
+ {mode === "login" ? "Sign up" : "Sign in"}
58
+ </InternalLink>
59
+ </div>
60
+ )}
61
+ </div>
62
+ </CardContent>
63
+ </Card>
72
64
  );
@@ -7,14 +7,16 @@ import {
7
7
  InputGroup,
8
8
  InputGroupAddon,
9
9
  InputGroupButton,
10
+ InputGroupTextarea,
10
11
  } from "@/components/ui/input-group";
11
12
  import { ArrowUpIcon, Loader2Icon, SquareIcon } from "lucide-react";
12
13
 
13
14
  import type { ChatStatus } from "ai";
14
15
 
15
- import { LexicalChatInput } from "../lexical-chat-input";
16
+ import { useAutoFocus } from "@/hooks/use-auto-focus";
17
+ import { useMounted } from "@/hooks/use-mounted";
16
18
 
17
- import React from "react";
19
+ import React, { useLayoutEffect } from "react";
18
20
  import type { ReadonlyReactNode } from "@/lib/readonly-react-node";
19
21
 
20
22
  import { useIsMobile } from "@/hooks/use-mobile";
@@ -105,7 +107,7 @@ const canSubmitDraft = (
105
107
  * @param {boolean | undefined} readOnly Runtime-owned readOnly value.
106
108
  * @param {boolean | undefined} allowDraftWhileBusy Allows typing during a submission without a Stop action.
107
109
  * @param {boolean | undefined} allowSendWhileStreaming Switches Stop to Send when the draft contains text or files.
108
- * @param {ComponentProps<typeof LexicalChatInput>["onPaste"] | undefined} onPaste Runtime-owned onPaste value.
110
+ * @param {ComponentProps<"textarea">["onPaste"] | undefined} onPaste Runtime-owned onPaste value.
109
111
  * @returns {React.JSX.Element} The composed message interface.
110
112
  */
111
113
  export const ChatComposer = ({
@@ -134,7 +136,7 @@ export const ChatComposer = ({
134
136
  readonly readOnly?: boolean;
135
137
  readonly allowDraftWhileBusy?: boolean;
136
138
  readonly allowSendWhileStreaming?: boolean;
137
- readonly onPaste?: ComponentProps<typeof LexicalChatInput>["onPaste"];
139
+ readonly onPaste?: ComponentProps<"textarea">["onPaste"];
138
140
  readonly draft: string;
139
141
  readonly onDraftChange: (draft: string) => void;
140
142
  readonly onSubmit: () => void;
@@ -146,6 +148,7 @@ export const ChatComposer = ({
146
148
  readonly tools?: ReadonlyReactNode;
147
149
  }): ReactJSX.Element => {
148
150
  const isMobile = useIsMobile();
151
+ const mounted = useMounted();
149
152
  const busy = status === "submitted" || status === "streaming";
150
153
  const hasDraft = Boolean(draft.trim()) || hasAttachments;
151
154
  const actionStatus = composerActionStatus(
@@ -154,6 +157,35 @@ export const ChatComposer = ({
154
157
  hasDraft
155
158
  );
156
159
  const editorReadOnly = readOnly || (busy && !onStop && !allowDraftWhileBusy);
160
+ const inputRef = useAutoFocus(autoFocus && !editorReadOnly);
161
+ useLayoutEffect((): (() => void) | undefined => {
162
+ const input = inputRef.current;
163
+ if (!input || !draft || CSS.supports("field-sizing", "content")) {
164
+ return undefined;
165
+ }
166
+
167
+ // Clearing the explicit height lets shorter or newly unwrapped drafts shrink.
168
+ const fitDraft = (): void => {
169
+ input.style.height = "";
170
+ input.style.height = `${input.scrollHeight}px`;
171
+ };
172
+ fitDraft();
173
+ let width = input.offsetWidth;
174
+ let frame = 0;
175
+ const observer = new ResizeObserver(() => {
176
+ if (input.offsetWidth !== width) {
177
+ width = input.offsetWidth;
178
+ cancelAnimationFrame(frame);
179
+ frame = requestAnimationFrame(fitDraft);
180
+ }
181
+ });
182
+ observer.observe(input);
183
+ return () => {
184
+ observer.disconnect();
185
+ cancelAnimationFrame(frame);
186
+ input.style.height = "";
187
+ };
188
+ }, [draft, inputRef]);
157
189
  const canSend =
158
190
  !disabled &&
159
191
  !editorReadOnly &&
@@ -191,34 +223,37 @@ export const ChatComposer = ({
191
223
  ) : undefined
192
224
  }
193
225
  >
194
- <LexicalChatInput
226
+ <InputGroupTextarea
195
227
  aria-label="Message"
196
- autoFocus={autoFocus}
197
- className="max-h-[max(35svh,5rem)] min-h-[60px] overflow-y-scroll sm:min-h-[80px]"
228
+ className="max-h-[max(35svh,5rem)] min-h-[60px] flex-none [scrollbar-width:thin] overflow-y-auto px-2.5 pt-2.5 pb-[5px] leading-normal [tab-size:1] placeholder:text-base placeholder-shown:pt-2 placeholder-shown:pl-3 sm:min-h-[80px] md:text-[15px]"
198
229
  data-testid="multimodal-input"
199
- initialValue={draft}
200
- onEnterSubmit={(
201
- event: Readonly<
202
- Pick<KeyboardEvent, "isComposing" | "ctrlKey" | "shiftKey">
203
- >
204
- ) => {
230
+ dir="auto"
231
+ ref={inputRef}
232
+ rows={1}
233
+ spellCheck
234
+ value={draft}
235
+ onChange={(event) => {
236
+ onDraftChange(event.currentTarget.value);
237
+ }}
238
+ onKeyDown={(event) => {
205
239
  if (
206
- event.isComposing ||
207
- !(isMobile ? event.ctrlKey : !event.shiftKey)
240
+ event.key === "Enter" &&
241
+ !event.nativeEvent.isComposing &&
242
+ // oxlint-disable-next-line typescript/no-deprecated -- WebKit clears isComposing before the IME confirmation keydown; 229 still identifies it.
243
+ event.nativeEvent.keyCode !== 229 &&
244
+ (isMobile ? event.ctrlKey : !event.shiftKey)
208
245
  ) {
209
- return false;
246
+ event.preventDefault();
247
+ submit();
210
248
  }
211
- submit();
212
- return true;
213
249
  }}
214
- onInputChange={onDraftChange}
215
250
  onPaste={onPaste}
216
251
  placeholder={
217
252
  isMobile
218
253
  ? "Send a message... (Ctrl+Enter to send)"
219
254
  : "Send a message..."
220
255
  }
221
- readOnly={editorReadOnly}
256
+ readOnly={!mounted || editorReadOnly}
222
257
  />
223
258
  </PromptForm>
224
259
  );
@@ -98,10 +98,12 @@ export const ChatSidebar = ({
98
98
  >
99
99
  <SidebarHeader className="shrink-0">
100
100
  <SidebarMenu>
101
- <div className="flex flex-row items-center justify-between">
101
+ <SidebarMenuItem>
102
102
  <SidebarTopRow />
103
- </div>
104
- <NewChatButton />
103
+ </SidebarMenuItem>
104
+ <SidebarMenuItem>
105
+ <NewChatButton />
106
+ </SidebarMenuItem>
105
107
  <Suspense
106
108
  fallback={
107
109
  <SidebarMenuItem>
@@ -28,7 +28,13 @@ export const PromptForm = ({
28
28
  InputGroupAddon: typeof InputGroupAddon;
29
29
  };
30
30
  }): JSX.Element => (
31
- <form className={cn("@container w-full", className)} {...props}>
31
+ <form
32
+ className={cn(
33
+ "@container w-full [--muted-foreground:color-mix(in_oklab,var(--foreground)_65%,var(--background))]",
34
+ className
35
+ )}
36
+ {...props}
37
+ >
32
38
  <primitives.InputGroup
33
39
  className={cn("overflow-hidden", editable && "has-disabled:opacity-100")}
34
40
  >
@@ -4,13 +4,23 @@ import { CircleAlert } from "lucide-react";
4
4
  import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
5
5
 
6
6
  export const EveChatError = ({
7
+ children,
7
8
  message,
9
+ title = "Chat error",
8
10
  }: {
11
+ readonly children?: ReactNode;
9
12
  readonly message: string;
13
+ readonly title?: string;
10
14
  }): ReactNode => (
11
- <Alert variant="destructive">
15
+ <Alert
16
+ className="has-[>svg]:grid-cols-[auto_minmax(0,1fr)]"
17
+ variant="destructive"
18
+ >
12
19
  <CircleAlert className="size-4" aria-hidden="true" />
13
- <AlertTitle>Chat error</AlertTitle>
20
+ <AlertTitle>{title}</AlertTitle>
14
21
  <AlertDescription className="wrap-anywhere">{message}</AlertDescription>
22
+ {children !== undefined && (
23
+ <div className="col-start-2 mt-2">{children}</div>
24
+ )}
15
25
  </Alert>
16
26
  );