@chat-js/cli 0.2.1 → 0.4.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.
- package/dist/index.js +216 -171
- package/package.json +1 -1
- package/templates/chat-app/CHANGELOG.md +19 -0
- package/templates/chat-app/app/(chat)/actions.ts +9 -9
- package/templates/chat-app/app/(chat)/api/chat/prepare/route.ts +94 -0
- package/templates/chat-app/app/(chat)/api/chat/route.ts +97 -14
- package/templates/chat-app/chat.config.ts +144 -156
- package/templates/chat-app/components/chat-sync.tsx +6 -3
- package/templates/chat-app/components/feedback-actions.tsx +7 -3
- package/templates/chat-app/components/message-editor.tsx +8 -3
- package/templates/chat-app/components/message-siblings.tsx +14 -1
- package/templates/chat-app/components/model-selector.tsx +669 -407
- package/templates/chat-app/components/multimodal-input.tsx +252 -18
- package/templates/chat-app/components/parallel-response-cards.tsx +157 -0
- package/templates/chat-app/components/part/text-message-part.tsx +9 -5
- package/templates/chat-app/components/retry-button.tsx +25 -8
- package/templates/chat-app/components/user-message.tsx +136 -125
- package/templates/chat-app/hooks/chat-sync-hooks.ts +11 -0
- package/templates/chat-app/hooks/use-navigate-to-message.ts +39 -0
- package/templates/chat-app/lib/ai/gateway-model-defaults.ts +154 -100
- package/templates/chat-app/lib/ai/gateways/openrouter-gateway.ts +2 -2
- package/templates/chat-app/lib/ai/tools/generate-image.ts +9 -2
- package/templates/chat-app/lib/ai/tools/generate-video.ts +3 -0
- package/templates/chat-app/lib/ai/types.ts +74 -3
- package/templates/chat-app/lib/config-schema.ts +131 -132
- package/templates/chat-app/lib/config.ts +2 -2
- package/templates/chat-app/lib/db/migrations/0044_gray_red_shift.sql +5 -0
- package/templates/chat-app/lib/db/migrations/meta/0044_snapshot.json +1567 -0
- package/templates/chat-app/lib/db/migrations/meta/_journal.json +8 -1
- package/templates/chat-app/lib/db/queries.ts +84 -4
- package/templates/chat-app/lib/db/schema.ts +4 -1
- package/templates/chat-app/lib/message-conversion.ts +14 -2
- package/templates/chat-app/lib/stores/hooks-threads.ts +37 -1
- package/templates/chat-app/lib/stores/with-threads.test.ts +137 -0
- package/templates/chat-app/lib/stores/with-threads.ts +157 -4
- package/templates/chat-app/lib/thread-utils.ts +23 -2
- package/templates/chat-app/package.json +1 -1
- package/templates/chat-app/providers/chat-input-provider.tsx +40 -2
- package/templates/chat-app/scripts/db-branch-delete.sh +7 -1
- package/templates/chat-app/scripts/db-branch-use.sh +7 -1
- package/templates/chat-app/scripts/with-db.sh +7 -1
- package/templates/chat-app/vitest.config.ts +2 -0
|
@@ -2,7 +2,7 @@ import { useMessageById } from "@ai-sdk-tools/store";
|
|
|
2
2
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
3
|
import { ThumbsDown, ThumbsUp } from "lucide-react";
|
|
4
4
|
import { toast } from "sonner";
|
|
5
|
-
import type
|
|
5
|
+
import { getPrimarySelectedModelId, type ChatMessage } from "@/lib/ai/types";
|
|
6
6
|
import type { Vote } from "@/lib/db/schema";
|
|
7
7
|
import { useSession } from "@/providers/session-provider";
|
|
8
8
|
import { useTRPC } from "@/trpc/react";
|
|
@@ -97,9 +97,13 @@ export function FeedbackActions({
|
|
|
97
97
|
|
|
98
98
|
function SelectedModelId({ messageId }: { messageId: string }) {
|
|
99
99
|
const message = useMessageById<ChatMessage>(messageId);
|
|
100
|
-
|
|
100
|
+
const selectedModelId = getPrimarySelectedModelId(
|
|
101
|
+
message?.metadata?.selectedModel
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return selectedModelId ? (
|
|
101
105
|
<div className="ml-2 flex items-center">
|
|
102
|
-
<Tag>{
|
|
106
|
+
<Tag>{selectedModelId}</Tag>
|
|
103
107
|
</div>
|
|
104
108
|
) : null;
|
|
105
109
|
}
|
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import { useChatStatus } from "@ai-sdk-tools/store";
|
|
3
3
|
import { type Dispatch, type SetStateAction, useCallback } from "react";
|
|
4
4
|
import type { ModelId } from "@/lib/ai/app-models";
|
|
5
|
-
import
|
|
5
|
+
import {
|
|
6
|
+
getPrimarySelectedModelId,
|
|
7
|
+
type ChatMessage,
|
|
8
|
+
} from "@/lib/ai/types";
|
|
6
9
|
import {
|
|
7
10
|
getAttachmentsFromMessage,
|
|
8
11
|
getTextContentFromMessage,
|
|
@@ -52,7 +55,8 @@ export function MessageEditor(
|
|
|
52
55
|
const initialAttachments = getAttachmentsFromMessage(props.message);
|
|
53
56
|
|
|
54
57
|
// Use selectedModel from the message metadata, or fall back to current selected model
|
|
55
|
-
const messageSelectedModel = props.message.metadata?.selectedModel
|
|
58
|
+
const messageSelectedModel = props.message.metadata?.selectedModel;
|
|
59
|
+
const primaryModelId = getPrimarySelectedModelId(messageSelectedModel) as ModelId | null;
|
|
56
60
|
const { parentMessageId: _parentMessageId, ...rest } = props;
|
|
57
61
|
return (
|
|
58
62
|
<ChatInputProvider
|
|
@@ -61,7 +65,8 @@ export function MessageEditor(
|
|
|
61
65
|
initialTool={props.message.metadata?.selectedTool}
|
|
62
66
|
key={`edit-${props.message.id}`}
|
|
63
67
|
localStorageEnabled={false}
|
|
64
|
-
overrideModelId={
|
|
68
|
+
overrideModelId={primaryModelId || undefined}
|
|
69
|
+
overrideModelSelection={messageSelectedModel || undefined}
|
|
65
70
|
>
|
|
66
71
|
<MessageEditorContent
|
|
67
72
|
{...rest}
|
|
@@ -2,7 +2,11 @@ import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
|
2
2
|
import { memo } from "react";
|
|
3
3
|
import { Action } from "@/components/ai-elements/actions";
|
|
4
4
|
import { useNavigateToSibling } from "@/hooks/use-navigate-to-sibling";
|
|
5
|
-
import {
|
|
5
|
+
import { useMessageRoleById } from "@/lib/stores/hooks-base";
|
|
6
|
+
import {
|
|
7
|
+
useMessageSiblingInfo,
|
|
8
|
+
useParallelGroupInfo,
|
|
9
|
+
} from "@/lib/stores/hooks-threads";
|
|
6
10
|
import { useSession } from "@/providers/session-provider";
|
|
7
11
|
|
|
8
12
|
function PureMessageSiblings({
|
|
@@ -15,10 +19,19 @@ function PureMessageSiblings({
|
|
|
15
19
|
const { data: session } = useSession();
|
|
16
20
|
const _isAuthenticated = !!session?.user;
|
|
17
21
|
|
|
22
|
+
const role = useMessageRoleById(messageId);
|
|
18
23
|
const siblingInfo = useMessageSiblingInfo(messageId);
|
|
24
|
+
const parallelGroupInfo = useParallelGroupInfo(messageId);
|
|
19
25
|
const navigateToSibling = useNavigateToSibling();
|
|
20
26
|
const hasSiblings = siblingInfo && siblingInfo.siblings.length > 1;
|
|
21
27
|
|
|
28
|
+
// Hide sibling nav for assistant messages in a parallel group — those use
|
|
29
|
+
// the response cards for navigation. User messages should always show
|
|
30
|
+
// sibling nav even when they spawned parallel responses.
|
|
31
|
+
if (parallelGroupInfo && role === "assistant") {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
22
35
|
return (
|
|
23
36
|
<div className="flex items-center justify-center gap-1">
|
|
24
37
|
{hasSiblings && (
|