Revert "chore: cleanup context window ui, adjust for reasoning + added db migration" (#1169)
This commit is contained in:
parent
02dde68ea3
commit
d3b3449eb8
13 changed files with 142 additions and 873 deletions
|
|
@ -18,7 +18,6 @@ import {
|
||||||
saveChat,
|
saveChat,
|
||||||
saveMessages,
|
saveMessages,
|
||||||
} from '@/lib/db/queries';
|
} from '@/lib/db/queries';
|
||||||
import { updateChatLastContextById } from '@/lib/db/queries';
|
|
||||||
import { convertToUIMessages, generateUUID } from '@/lib/utils';
|
import { convertToUIMessages, generateUUID } from '@/lib/utils';
|
||||||
import { generateTitleFromUserMessage } from '../../actions';
|
import { generateTitleFromUserMessage } from '../../actions';
|
||||||
import { createDocument } from '@/lib/ai/tools/create-document';
|
import { createDocument } from '@/lib/ai/tools/create-document';
|
||||||
|
|
@ -209,17 +208,6 @@ export async function POST(request: Request) {
|
||||||
chatId: id,
|
chatId: id,
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (finalUsage) {
|
|
||||||
try {
|
|
||||||
await updateChatLastContextById({
|
|
||||||
chatId: id,
|
|
||||||
context: finalUsage,
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
console.warn('Unable to persist last usage for chat', id, err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
return 'Oops, an error occurred!';
|
return 'Oops, an error occurred!';
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import { getChatById, getMessagesByChatId } from '@/lib/db/queries';
|
||||||
import { DataStreamHandler } from '@/components/data-stream-handler';
|
import { DataStreamHandler } from '@/components/data-stream-handler';
|
||||||
import { DEFAULT_CHAT_MODEL } from '@/lib/ai/models';
|
import { DEFAULT_CHAT_MODEL } from '@/lib/ai/models';
|
||||||
import { convertToUIMessages } from '@/lib/utils';
|
import { convertToUIMessages } from '@/lib/utils';
|
||||||
import { LanguageModelV2Usage } from '@ai-sdk/provider';
|
|
||||||
|
|
||||||
export default async function Page(props: { params: Promise<{ id: string }> }) {
|
export default async function Page(props: { params: Promise<{ id: string }> }) {
|
||||||
const params = await props.params;
|
const params = await props.params;
|
||||||
|
|
@ -54,7 +53,6 @@ export default async function Page(props: { params: Promise<{ id: string }> }) {
|
||||||
isReadonly={session?.user?.id !== chat.userId}
|
isReadonly={session?.user?.id !== chat.userId}
|
||||||
session={session}
|
session={session}
|
||||||
autoResume={true}
|
autoResume={true}
|
||||||
initialLastContext={chat.lastContext}
|
|
||||||
/>
|
/>
|
||||||
<DataStreamHandler />
|
<DataStreamHandler />
|
||||||
</>
|
</>
|
||||||
|
|
@ -71,7 +69,6 @@ export default async function Page(props: { params: Promise<{ id: string }> }) {
|
||||||
isReadonly={session?.user?.id !== chat.userId}
|
isReadonly={session?.user?.id !== chat.userId}
|
||||||
session={session}
|
session={session}
|
||||||
autoResume={true}
|
autoResume={true}
|
||||||
initialLastContext={chat.lastContext}
|
|
||||||
/>
|
/>
|
||||||
<DataStreamHandler />
|
<DataStreamHandler />
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ export function Chat({
|
||||||
isReadonly,
|
isReadonly,
|
||||||
session,
|
session,
|
||||||
autoResume,
|
autoResume,
|
||||||
initialLastContext,
|
|
||||||
}: {
|
}: {
|
||||||
id: string;
|
id: string;
|
||||||
initialMessages: ChatMessage[];
|
initialMessages: ChatMessage[];
|
||||||
|
|
@ -40,7 +39,6 @@ export function Chat({
|
||||||
isReadonly: boolean;
|
isReadonly: boolean;
|
||||||
session: Session;
|
session: Session;
|
||||||
autoResume: boolean;
|
autoResume: boolean;
|
||||||
initialLastContext?: LanguageModelUsage;
|
|
||||||
}) {
|
}) {
|
||||||
const { visibilityType } = useChatVisibility({
|
const { visibilityType } = useChatVisibility({
|
||||||
chatId: id,
|
chatId: id,
|
||||||
|
|
@ -51,9 +49,7 @@ export function Chat({
|
||||||
const { setDataStream } = useDataStream();
|
const { setDataStream } = useDataStream();
|
||||||
|
|
||||||
const [input, setInput] = useState<string>('');
|
const [input, setInput] = useState<string>('');
|
||||||
const [usage, setUsage] = useState<LanguageModelUsage | undefined>(
|
const [usage, setUsage] = useState<LanguageModelUsage | undefined>(undefined);
|
||||||
initialLastContext,
|
|
||||||
);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
messages,
|
messages,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import type { ComponentProps } from 'react';
|
||||||
import type { LanguageModelUsage } from 'ai';
|
import type { LanguageModelUsage } from 'ai';
|
||||||
import { breakdownTokens, estimateCost, normalizeUsage } from 'tokenlens';
|
import { breakdownTokens, estimateCost, normalizeUsage } from 'tokenlens';
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
import { Progress } from '@/components/ui/progress';
|
|
||||||
|
|
||||||
export type ContextProps = ComponentProps<'button'> & {
|
export type ContextProps = ComponentProps<'button'> & {
|
||||||
/** Total context window size in tokens */
|
/** Total context window size in tokens */
|
||||||
|
|
@ -21,6 +20,8 @@ export type ContextProps = ComponentProps<'button'> & {
|
||||||
usage?: LanguageModelUsage | undefined;
|
usage?: LanguageModelUsage | undefined;
|
||||||
/** Optional model id (canonical or alias) to compute cost */
|
/** Optional model id (canonical or alias) to compute cost */
|
||||||
modelId?: string;
|
modelId?: string;
|
||||||
|
/** Show token breakdown and optional cost inside hover */
|
||||||
|
showBreakdown?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const THOUSAND = 1000;
|
const THOUSAND = 1000;
|
||||||
|
|
@ -80,11 +81,6 @@ const formatUSD = (value?: number) => {
|
||||||
return `$${trimmed}`;
|
return `$${trimmed}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatUSDFixed = (value?: number, decimals = 5) => {
|
|
||||||
if (value === undefined || !Number.isFinite(value)) return undefined;
|
|
||||||
return `$${Number(value).toFixed(decimals)}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
type ContextIconProps = {
|
type ContextIconProps = {
|
||||||
percent: number; // 0 - 100
|
percent: number; // 0 - 100
|
||||||
};
|
};
|
||||||
|
|
@ -129,46 +125,13 @@ export const ContextIcon = ({ percent }: ContextIconProps) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function TokensWithCost({
|
|
||||||
tokens,
|
|
||||||
costText,
|
|
||||||
}: {
|
|
||||||
tokens?: number;
|
|
||||||
costText?: string;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<span>
|
|
||||||
{tokens === undefined ? '—' : formatTokens(tokens)}
|
|
||||||
{costText ? (
|
|
||||||
<span className="ml-2 text-muted-foreground">• {costText}</span>
|
|
||||||
) : null}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function InfoRow({
|
|
||||||
label,
|
|
||||||
tokens,
|
|
||||||
costText,
|
|
||||||
}: {
|
|
||||||
label: string;
|
|
||||||
tokens?: number;
|
|
||||||
costText?: string;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div className="flex items-center justify-between text-xs">
|
|
||||||
<span className="text-muted-foreground">{label}</span>
|
|
||||||
<TokensWithCost tokens={tokens} costText={costText} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const Context = ({
|
export const Context = ({
|
||||||
className,
|
className,
|
||||||
maxTokens,
|
maxTokens,
|
||||||
usedTokens,
|
usedTokens,
|
||||||
usage,
|
usage,
|
||||||
modelId,
|
modelId,
|
||||||
|
showBreakdown,
|
||||||
...props
|
...props
|
||||||
}: ContextProps) => {
|
}: ContextProps) => {
|
||||||
const safeMax = Math.max(0, Number.isFinite(maxTokens) ? maxTokens : 0);
|
const safeMax = Math.max(0, Number.isFinite(maxTokens) ? maxTokens : 0);
|
||||||
|
|
@ -176,105 +139,38 @@ export const Context = ({
|
||||||
Math.max(0, Number.isFinite(usedTokens) ? usedTokens : 0),
|
Math.max(0, Number.isFinite(usedTokens) ? usedTokens : 0),
|
||||||
safeMax,
|
safeMax,
|
||||||
);
|
);
|
||||||
|
|
||||||
// used percent and used tokens to display (demo-aware)
|
|
||||||
const displayUsedTokens = safeUsed;
|
|
||||||
const usedPercent =
|
const usedPercent =
|
||||||
safeMax > 0
|
safeMax > 0
|
||||||
? Math.min(
|
? Math.min(PERCENT_MAX, Math.max(0, (safeUsed / safeMax) * PERCENT_MAX))
|
||||||
PERCENT_MAX,
|
|
||||||
Math.max(0, (displayUsedTokens / safeMax) * PERCENT_MAX),
|
|
||||||
)
|
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
const displayPct = formatPercent(Math.round(usedPercent * 10) / 10);
|
const displayPct = formatPercent(Math.round(usedPercent * 10) / 10);
|
||||||
|
|
||||||
const used = formatTokens(displayUsedTokens);
|
const used = formatTokens(safeUsed);
|
||||||
const total = formatTokens(safeMax);
|
const total = formatTokens(safeMax);
|
||||||
|
|
||||||
const uNorm = normalizeUsage(usage);
|
const uNorm = normalizeUsage(usage as any);
|
||||||
const uBreakdown = breakdownTokens(usage);
|
const uBreakdown = breakdownTokens(usage as any);
|
||||||
|
|
||||||
const hasUsage =
|
|
||||||
!!usage &&
|
|
||||||
((uNorm.input ?? 0) > 0 ||
|
|
||||||
(uNorm.output ?? 0) > 0 ||
|
|
||||||
(uBreakdown.cacheReads ?? 0) > 0 ||
|
|
||||||
(uBreakdown.cacheWrites ?? 0) > 0 ||
|
|
||||||
(uBreakdown.reasoningTokens ?? 0) > 0);
|
|
||||||
|
|
||||||
// Values to render in rows (demo or real)
|
|
||||||
const displayInput = uNorm.input;
|
|
||||||
const displayOutput = uNorm.output;
|
|
||||||
|
|
||||||
// Per-segment costs
|
|
||||||
const inputCostText = modelId
|
|
||||||
? formatUSDFixed(
|
|
||||||
estimateCost({
|
|
||||||
modelId,
|
|
||||||
usage: { input: displayInput ?? 0, output: 0 },
|
|
||||||
}).inputUSD,
|
|
||||||
)
|
|
||||||
: undefined;
|
|
||||||
const outputCostText = modelId
|
|
||||||
? formatUSDFixed(
|
|
||||||
estimateCost({
|
|
||||||
modelId,
|
|
||||||
usage: { input: 0, output: displayOutput ?? 0 },
|
|
||||||
}).outputUSD,
|
|
||||||
)
|
|
||||||
: undefined;
|
|
||||||
// Not supported by tokenlens pricing hints; leave undefined so no bullet is shown
|
|
||||||
const cacheReadsTokens = uBreakdown.cacheReads ?? 0;
|
|
||||||
const cacheWritesTokens = uBreakdown.cacheWrites ?? 0;
|
|
||||||
const cacheReadsCostText =
|
|
||||||
modelId && cacheReadsTokens > 0
|
|
||||||
? formatUSDFixed(
|
|
||||||
estimateCost({
|
|
||||||
modelId,
|
|
||||||
// Cast to any to support extended pricing fields provided by tokenlens
|
|
||||||
usage: { cacheReads: cacheReadsTokens } as any,
|
|
||||||
}).totalUSD,
|
|
||||||
)
|
|
||||||
: undefined;
|
|
||||||
const cacheWritesCostText =
|
|
||||||
modelId && cacheWritesTokens > 0
|
|
||||||
? formatUSDFixed(
|
|
||||||
estimateCost({
|
|
||||||
modelId,
|
|
||||||
usage: { cacheWrites: cacheWritesTokens } as any,
|
|
||||||
}).totalUSD,
|
|
||||||
)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const reasoningTokens = uBreakdown.reasoningTokens ?? 0;
|
|
||||||
const reasoningCostText =
|
|
||||||
modelId && reasoningTokens > 0
|
|
||||||
? formatUSDFixed(
|
|
||||||
estimateCost({
|
|
||||||
modelId,
|
|
||||||
usage: { reasoningTokens },
|
|
||||||
}).totalUSD,
|
|
||||||
)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const costUSD = modelId
|
const costUSD = modelId
|
||||||
? estimateCost({
|
? estimateCost({ modelId, usage: uNorm }).totalUSD
|
||||||
modelId,
|
|
||||||
usage: { input: displayInput ?? 0, output: displayOutput ?? 0 },
|
|
||||||
}).totalUSD
|
|
||||||
: undefined;
|
: undefined;
|
||||||
const costText = formatUSDFixed(costUSD);
|
const costText = formatUSD(costUSD);
|
||||||
|
|
||||||
|
const segInput = Math.max(0, uNorm.input ?? 0);
|
||||||
|
const segOutput = Math.max(0, uNorm.output ?? 0);
|
||||||
|
const segCacheR = Math.max(0, uBreakdown.cacheReads ?? 0);
|
||||||
|
const segCacheW = Math.max(0, uBreakdown.cacheWrites ?? 0);
|
||||||
|
const denom = safeMax > 0 ? safeMax : 1;
|
||||||
|
const w = (n: number) =>
|
||||||
|
`${Math.min(100, Math.max(0, (n / denom) * 100)).toFixed(2)}%`;
|
||||||
const fmtOrUnknown = (n?: number) =>
|
const fmtOrUnknown = (n?: number) =>
|
||||||
n === undefined ? '—' : formatTokens(n);
|
n === undefined ? '—' : formatTokens(n);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HoverCard closeDelay={100} openDelay={100}>
|
<HoverCard closeDelay={100} openDelay={100}>
|
||||||
<HoverCardTrigger asChild>
|
<HoverCardTrigger asChild>
|
||||||
<button
|
<button
|
||||||
className={cn(
|
className={cn(
|
||||||
'inline-flex select-none items-center gap-1 rounded-md px-2.5 py-1 text-sm',
|
'inline-flex select-none items-center gap-2 rounded-md px-2.5 py-1 text-sm',
|
||||||
'bg-background text-foreground',
|
'bg-background text-foreground',
|
||||||
)}
|
)}
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -286,46 +182,100 @@ export const Context = ({
|
||||||
<ContextIcon percent={usedPercent} />
|
<ContextIcon percent={usedPercent} />
|
||||||
</button>
|
</button>
|
||||||
</HoverCardTrigger>
|
</HoverCardTrigger>
|
||||||
<HoverCardContent align="end" side="top" className="w-fit p-3">
|
<HoverCardContent align="center" className="w-fit p-3">
|
||||||
<div className="min-w-[240px] space-y-2">
|
<div className="min-w-[240px] space-y-2">
|
||||||
<p className="text-start text-sm">
|
<p className="text-center text-sm">
|
||||||
{displayPct} • {used} / {total} tokens
|
{displayPct} • {used} / {total} tokens
|
||||||
|
{costText ? (
|
||||||
|
<span className="ml-1 text-muted-foreground">• {costText}</span>
|
||||||
|
) : null}
|
||||||
</p>
|
</p>
|
||||||
|
{true && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Progress className="h-2 bg-muted" value={usedPercent} />
|
<div className="h-2 w-full overflow-hidden rounded-full bg-muted">
|
||||||
|
<div
|
||||||
|
className="h-full"
|
||||||
|
style={{
|
||||||
|
width: w(segCacheR),
|
||||||
|
background: 'var(--chart-2)',
|
||||||
|
opacity: 0.9,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className="h-full"
|
||||||
|
style={{
|
||||||
|
width: w(segCacheW),
|
||||||
|
background: 'var(--chart-4)',
|
||||||
|
opacity: 0.9,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className="h-full"
|
||||||
|
style={{
|
||||||
|
width: w(segInput),
|
||||||
|
background: 'var(--chart-1)',
|
||||||
|
opacity: 0.9,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className="h-full"
|
||||||
|
style={{
|
||||||
|
width: w(segOutput),
|
||||||
|
background: 'var(--chart-3)',
|
||||||
|
opacity: 0.9,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="grid grid-cols-2 gap-x-4 gap-y-1 text-xs">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<span className="flex items-center gap-2 text-muted-foreground">
|
||||||
|
<span className="inline-block size-2 rounded-sm bg-chart-1" />
|
||||||
|
Cache Hits
|
||||||
|
</span>
|
||||||
|
<span>{fmtOrUnknown(uBreakdown.cacheReads)}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<span className="flex items-center gap-2 text-muted-foreground">
|
||||||
|
<span className="inline-block size-2 rounded-sm bg-chart-2" />
|
||||||
|
Cache Writes
|
||||||
|
</span>
|
||||||
|
<span>{fmtOrUnknown(uBreakdown.cacheWrites)}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<span className="flex items-center gap-2 text-muted-foreground">
|
||||||
|
<span className="inline-block size-2 rounded-sm bg-chart-3" />
|
||||||
|
Input
|
||||||
|
</span>
|
||||||
|
<span>{formatTokens(uNorm.input)}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<span className="flex items-center gap-2 text-muted-foreground">
|
||||||
|
<span className="inline-block size-2 rounded-sm bg-chart-4" />
|
||||||
|
Output
|
||||||
|
</span>
|
||||||
|
<span>{formatTokens(uNorm.output)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{showBreakdown && (
|
||||||
<div className="mt-1 space-y-1">
|
<div className="mt-1 space-y-1">
|
||||||
{hasUsage && uBreakdown.cacheReads && uBreakdown.cacheReads > 0 && (
|
<div className="flex items-center justify-between text-xs">
|
||||||
<InfoRow
|
<span className="text-muted-foreground">Cache Hits</span>
|
||||||
label="Cache Hits"
|
<span>{fmtOrUnknown(uBreakdown.cacheReads)}</span>
|
||||||
tokens={uBreakdown.cacheReads}
|
</div>
|
||||||
costText={cacheReadsCostText}
|
<div className="flex items-center justify-between text-xs">
|
||||||
/>
|
<span className="text-muted-foreground">Cache Writes</span>
|
||||||
)}
|
<span>{fmtOrUnknown(uBreakdown.cacheWrites)}</span>
|
||||||
{hasUsage &&
|
</div>
|
||||||
uBreakdown.cacheWrites &&
|
<div className="flex items-center justify-between text-xs">
|
||||||
uBreakdown.cacheWrites > 0 && (
|
<span className="text-muted-foreground">Input</span>
|
||||||
<InfoRow
|
<span>{formatTokens(uNorm.input)}</span>
|
||||||
label="Cache Writes"
|
</div>
|
||||||
tokens={uBreakdown.cacheWrites}
|
<div className="flex items-center justify-between text-xs">
|
||||||
costText={cacheWritesCostText}
|
<span className="text-muted-foreground">Output</span>
|
||||||
/>
|
<span>{formatTokens(uNorm.output)}</span>
|
||||||
)}
|
</div>
|
||||||
<InfoRow
|
|
||||||
label="Input"
|
|
||||||
tokens={displayInput}
|
|
||||||
costText={inputCostText}
|
|
||||||
/>
|
|
||||||
<InfoRow
|
|
||||||
label="Output"
|
|
||||||
tokens={displayOutput}
|
|
||||||
costText={outputCostText}
|
|
||||||
/>
|
|
||||||
<InfoRow
|
|
||||||
label="Reasoning"
|
|
||||||
tokens={reasoningTokens > 0 ? reasoningTokens : undefined}
|
|
||||||
costText={reasoningCostText}
|
|
||||||
/>
|
|
||||||
{costText && (
|
{costText && (
|
||||||
<>
|
<>
|
||||||
<Separator className="mt-1" />
|
<Separator className="mt-1" />
|
||||||
|
|
@ -336,6 +286,7 @@ export const Context = ({
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</HoverCardContent>
|
</HoverCardContent>
|
||||||
</HoverCard>
|
</HoverCard>
|
||||||
|
|
|
||||||
|
|
@ -214,6 +214,7 @@ function PureMultimodalInput({
|
||||||
usedTokens,
|
usedTokens,
|
||||||
usage,
|
usage,
|
||||||
modelId: modelResolver.modelId,
|
modelId: modelResolver.modelId,
|
||||||
|
showBreakdown: true as const,
|
||||||
}),
|
}),
|
||||||
[contextMax, usedTokens, usage, modelResolver],
|
[contextMax, usedTokens, usage, modelResolver],
|
||||||
);
|
);
|
||||||
|
|
@ -342,7 +343,7 @@ function PureMultimodalInput({
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex flex-row gap-2 items-start">
|
|
||||||
<PromptInputTextarea
|
<PromptInputTextarea
|
||||||
data-testid="multimodal-input"
|
data-testid="multimodal-input"
|
||||||
ref={textareaRef}
|
ref={textareaRef}
|
||||||
|
|
@ -352,12 +353,10 @@ function PureMultimodalInput({
|
||||||
minHeight={44}
|
minHeight={44}
|
||||||
maxHeight={200}
|
maxHeight={200}
|
||||||
disableAutoResize={true}
|
disableAutoResize={true}
|
||||||
className="text-sm flex-grow resize-none py-3 px-3 [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none] bg-transparent !border-0 !border-none outline-none ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:outline-none placeholder:text-muted-foreground"
|
className="text-sm resize-none p-3 [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none] bg-transparent !border-0 !border-none outline-none ring-0 focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:outline-none placeholder:text-muted-foreground"
|
||||||
rows={1}
|
rows={1}
|
||||||
autoFocus
|
autoFocus
|
||||||
/>{' '}
|
/>
|
||||||
<Context {...contextProps} />
|
|
||||||
</div>
|
|
||||||
<PromptInputToolbar className="px-3 py-2 !border-t-0 !border-top-0 shadow-none dark:!border-transparent dark:border-0">
|
<PromptInputToolbar className="px-3 py-2 !border-t-0 !border-top-0 shadow-none dark:!border-transparent dark:border-0">
|
||||||
<PromptInputTools className="gap-2">
|
<PromptInputTools className="gap-2">
|
||||||
<AttachmentsButton
|
<AttachmentsButton
|
||||||
|
|
@ -366,8 +365,8 @@ function PureMultimodalInput({
|
||||||
selectedModelId={selectedModelId}
|
selectedModelId={selectedModelId}
|
||||||
/>
|
/>
|
||||||
<ModelSelectorCompact selectedModelId={selectedModelId} />
|
<ModelSelectorCompact selectedModelId={selectedModelId} />
|
||||||
|
<Context {...contextProps} />
|
||||||
</PromptInputTools>
|
</PromptInputTools>
|
||||||
|
|
||||||
{status === 'submitted' ? (
|
{status === 'submitted' ? (
|
||||||
<StopButton stop={stop} setMessages={setMessages} />
|
<StopButton stop={stop} setMessages={setMessages} />
|
||||||
) : (
|
) : (
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
"use client"
|
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import * as ProgressPrimitive from "@radix-ui/react-progress"
|
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
|
|
||||||
const Progress = React.forwardRef<
|
|
||||||
React.ElementRef<typeof ProgressPrimitive.Root>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
|
|
||||||
>(({ className, value, ...props }, ref) => (
|
|
||||||
<ProgressPrimitive.Root
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"relative h-4 w-full overflow-hidden rounded-full bg-secondary",
|
|
||||||
className
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<ProgressPrimitive.Indicator
|
|
||||||
className="h-full w-full flex-1 bg-primary transition-all"
|
|
||||||
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
|
|
||||||
/>
|
|
||||||
</ProgressPrimitive.Root>
|
|
||||||
))
|
|
||||||
Progress.displayName = ProgressPrimitive.Root.displayName
|
|
||||||
|
|
||||||
export { Progress }
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
ALTER TABLE "Chat" ADD COLUMN "lastContext" jsonb;
|
|
||||||
|
|
@ -1,571 +0,0 @@
|
||||||
{
|
|
||||||
"id": "097660a7-976a-4b3e-8ebb-79312e3ece6f",
|
|
||||||
"prevId": "443de550-b7e8-4bfb-b229-c12dc6c132f0",
|
|
||||||
"version": "7",
|
|
||||||
"dialect": "postgresql",
|
|
||||||
"tables": {
|
|
||||||
"public.Chat": {
|
|
||||||
"name": "Chat",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "gen_random_uuid()"
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"name": "createdAt",
|
|
||||||
"type": "timestamp",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"title": {
|
|
||||||
"name": "title",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"userId": {
|
|
||||||
"name": "userId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"visibility": {
|
|
||||||
"name": "visibility",
|
|
||||||
"type": "varchar",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'private'"
|
|
||||||
},
|
|
||||||
"lastContext": {
|
|
||||||
"name": "lastContext",
|
|
||||||
"type": "jsonb",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {
|
|
||||||
"Chat_userId_User_id_fk": {
|
|
||||||
"name": "Chat_userId_User_id_fk",
|
|
||||||
"tableFrom": "Chat",
|
|
||||||
"tableTo": "User",
|
|
||||||
"columnsFrom": [
|
|
||||||
"userId"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.Document": {
|
|
||||||
"name": "Document",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "gen_random_uuid()"
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"name": "createdAt",
|
|
||||||
"type": "timestamp",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"title": {
|
|
||||||
"name": "title",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"content": {
|
|
||||||
"name": "content",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"text": {
|
|
||||||
"name": "text",
|
|
||||||
"type": "varchar",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "'text'"
|
|
||||||
},
|
|
||||||
"userId": {
|
|
||||||
"name": "userId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {
|
|
||||||
"Document_userId_User_id_fk": {
|
|
||||||
"name": "Document_userId_User_id_fk",
|
|
||||||
"tableFrom": "Document",
|
|
||||||
"tableTo": "User",
|
|
||||||
"columnsFrom": [
|
|
||||||
"userId"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"compositePrimaryKeys": {
|
|
||||||
"Document_id_createdAt_pk": {
|
|
||||||
"name": "Document_id_createdAt_pk",
|
|
||||||
"columns": [
|
|
||||||
"id",
|
|
||||||
"createdAt"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.Message_v2": {
|
|
||||||
"name": "Message_v2",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "gen_random_uuid()"
|
|
||||||
},
|
|
||||||
"chatId": {
|
|
||||||
"name": "chatId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"role": {
|
|
||||||
"name": "role",
|
|
||||||
"type": "varchar",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"parts": {
|
|
||||||
"name": "parts",
|
|
||||||
"type": "json",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"attachments": {
|
|
||||||
"name": "attachments",
|
|
||||||
"type": "json",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"name": "createdAt",
|
|
||||||
"type": "timestamp",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {
|
|
||||||
"Message_v2_chatId_Chat_id_fk": {
|
|
||||||
"name": "Message_v2_chatId_Chat_id_fk",
|
|
||||||
"tableFrom": "Message_v2",
|
|
||||||
"tableTo": "Chat",
|
|
||||||
"columnsFrom": [
|
|
||||||
"chatId"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.Message": {
|
|
||||||
"name": "Message",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "gen_random_uuid()"
|
|
||||||
},
|
|
||||||
"chatId": {
|
|
||||||
"name": "chatId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"role": {
|
|
||||||
"name": "role",
|
|
||||||
"type": "varchar",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"content": {
|
|
||||||
"name": "content",
|
|
||||||
"type": "json",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"name": "createdAt",
|
|
||||||
"type": "timestamp",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {
|
|
||||||
"Message_chatId_Chat_id_fk": {
|
|
||||||
"name": "Message_chatId_Chat_id_fk",
|
|
||||||
"tableFrom": "Message",
|
|
||||||
"tableTo": "Chat",
|
|
||||||
"columnsFrom": [
|
|
||||||
"chatId"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.Stream": {
|
|
||||||
"name": "Stream",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "gen_random_uuid()"
|
|
||||||
},
|
|
||||||
"chatId": {
|
|
||||||
"name": "chatId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"name": "createdAt",
|
|
||||||
"type": "timestamp",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {
|
|
||||||
"Stream_chatId_Chat_id_fk": {
|
|
||||||
"name": "Stream_chatId_Chat_id_fk",
|
|
||||||
"tableFrom": "Stream",
|
|
||||||
"tableTo": "Chat",
|
|
||||||
"columnsFrom": [
|
|
||||||
"chatId"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"compositePrimaryKeys": {
|
|
||||||
"Stream_id_pk": {
|
|
||||||
"name": "Stream_id_pk",
|
|
||||||
"columns": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.Suggestion": {
|
|
||||||
"name": "Suggestion",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "gen_random_uuid()"
|
|
||||||
},
|
|
||||||
"documentId": {
|
|
||||||
"name": "documentId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"documentCreatedAt": {
|
|
||||||
"name": "documentCreatedAt",
|
|
||||||
"type": "timestamp",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"originalText": {
|
|
||||||
"name": "originalText",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"suggestedText": {
|
|
||||||
"name": "suggestedText",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"description": {
|
|
||||||
"name": "description",
|
|
||||||
"type": "text",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
},
|
|
||||||
"isResolved": {
|
|
||||||
"name": "isResolved",
|
|
||||||
"type": "boolean",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true,
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"userId": {
|
|
||||||
"name": "userId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"name": "createdAt",
|
|
||||||
"type": "timestamp",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {
|
|
||||||
"Suggestion_userId_User_id_fk": {
|
|
||||||
"name": "Suggestion_userId_User_id_fk",
|
|
||||||
"tableFrom": "Suggestion",
|
|
||||||
"tableTo": "User",
|
|
||||||
"columnsFrom": [
|
|
||||||
"userId"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
},
|
|
||||||
"Suggestion_documentId_documentCreatedAt_Document_id_createdAt_fk": {
|
|
||||||
"name": "Suggestion_documentId_documentCreatedAt_Document_id_createdAt_fk",
|
|
||||||
"tableFrom": "Suggestion",
|
|
||||||
"tableTo": "Document",
|
|
||||||
"columnsFrom": [
|
|
||||||
"documentId",
|
|
||||||
"documentCreatedAt"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id",
|
|
||||||
"createdAt"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"compositePrimaryKeys": {
|
|
||||||
"Suggestion_id_pk": {
|
|
||||||
"name": "Suggestion_id_pk",
|
|
||||||
"columns": [
|
|
||||||
"id"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.User": {
|
|
||||||
"name": "User",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"id": {
|
|
||||||
"name": "id",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": true,
|
|
||||||
"notNull": true,
|
|
||||||
"default": "gen_random_uuid()"
|
|
||||||
},
|
|
||||||
"email": {
|
|
||||||
"name": "email",
|
|
||||||
"type": "varchar(64)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"password": {
|
|
||||||
"name": "password",
|
|
||||||
"type": "varchar(64)",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {},
|
|
||||||
"compositePrimaryKeys": {},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.Vote_v2": {
|
|
||||||
"name": "Vote_v2",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"chatId": {
|
|
||||||
"name": "chatId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"messageId": {
|
|
||||||
"name": "messageId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"isUpvoted": {
|
|
||||||
"name": "isUpvoted",
|
|
||||||
"type": "boolean",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {
|
|
||||||
"Vote_v2_chatId_Chat_id_fk": {
|
|
||||||
"name": "Vote_v2_chatId_Chat_id_fk",
|
|
||||||
"tableFrom": "Vote_v2",
|
|
||||||
"tableTo": "Chat",
|
|
||||||
"columnsFrom": [
|
|
||||||
"chatId"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
},
|
|
||||||
"Vote_v2_messageId_Message_v2_id_fk": {
|
|
||||||
"name": "Vote_v2_messageId_Message_v2_id_fk",
|
|
||||||
"tableFrom": "Vote_v2",
|
|
||||||
"tableTo": "Message_v2",
|
|
||||||
"columnsFrom": [
|
|
||||||
"messageId"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"compositePrimaryKeys": {
|
|
||||||
"Vote_v2_chatId_messageId_pk": {
|
|
||||||
"name": "Vote_v2_chatId_messageId_pk",
|
|
||||||
"columns": [
|
|
||||||
"chatId",
|
|
||||||
"messageId"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
},
|
|
||||||
"public.Vote": {
|
|
||||||
"name": "Vote",
|
|
||||||
"schema": "",
|
|
||||||
"columns": {
|
|
||||||
"chatId": {
|
|
||||||
"name": "chatId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"messageId": {
|
|
||||||
"name": "messageId",
|
|
||||||
"type": "uuid",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
},
|
|
||||||
"isUpvoted": {
|
|
||||||
"name": "isUpvoted",
|
|
||||||
"type": "boolean",
|
|
||||||
"primaryKey": false,
|
|
||||||
"notNull": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"indexes": {},
|
|
||||||
"foreignKeys": {
|
|
||||||
"Vote_chatId_Chat_id_fk": {
|
|
||||||
"name": "Vote_chatId_Chat_id_fk",
|
|
||||||
"tableFrom": "Vote",
|
|
||||||
"tableTo": "Chat",
|
|
||||||
"columnsFrom": [
|
|
||||||
"chatId"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
},
|
|
||||||
"Vote_messageId_Message_id_fk": {
|
|
||||||
"name": "Vote_messageId_Message_id_fk",
|
|
||||||
"tableFrom": "Vote",
|
|
||||||
"tableTo": "Message",
|
|
||||||
"columnsFrom": [
|
|
||||||
"messageId"
|
|
||||||
],
|
|
||||||
"columnsTo": [
|
|
||||||
"id"
|
|
||||||
],
|
|
||||||
"onDelete": "no action",
|
|
||||||
"onUpdate": "no action"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"compositePrimaryKeys": {
|
|
||||||
"Vote_chatId_messageId_pk": {
|
|
||||||
"name": "Vote_chatId_messageId_pk",
|
|
||||||
"columns": [
|
|
||||||
"chatId",
|
|
||||||
"messageId"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"uniqueConstraints": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"enums": {},
|
|
||||||
"schemas": {},
|
|
||||||
"sequences": {},
|
|
||||||
"_meta": {
|
|
||||||
"columns": {},
|
|
||||||
"schemas": {},
|
|
||||||
"tables": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -50,13 +50,6 @@
|
||||||
"when": 1746118166211,
|
"when": 1746118166211,
|
||||||
"tag": "0006_marvelous_frog_thor",
|
"tag": "0006_marvelous_frog_thor",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
},
|
|
||||||
{
|
|
||||||
"idx": 7,
|
|
||||||
"version": "7",
|
|
||||||
"when": 1757362773211,
|
|
||||||
"tag": "0007_flowery_ben_parker",
|
|
||||||
"breakpoints": true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +33,6 @@ import { generateUUID } from '../utils';
|
||||||
import { generateHashedPassword } from './utils';
|
import { generateHashedPassword } from './utils';
|
||||||
import type { VisibilityType } from '@/components/visibility-selector';
|
import type { VisibilityType } from '@/components/visibility-selector';
|
||||||
import { ChatSDKError } from '../errors';
|
import { ChatSDKError } from '../errors';
|
||||||
import { LanguageModelV2Usage } from '@ai-sdk/provider';
|
|
||||||
|
|
||||||
// Optionally, if not using email/pass login, you can
|
// Optionally, if not using email/pass login, you can
|
||||||
// use the Drizzle adapter for Auth.js / NextAuth
|
// use the Drizzle adapter for Auth.js / NextAuth
|
||||||
|
|
@ -203,10 +202,7 @@ export async function getChatsByUserId({
|
||||||
export async function getChatById({ id }: { id: string }) {
|
export async function getChatById({ id }: { id: string }) {
|
||||||
try {
|
try {
|
||||||
const [selectedChat] = await db.select().from(chat).where(eq(chat.id, id));
|
const [selectedChat] = await db.select().from(chat).where(eq(chat.id, id));
|
||||||
return {
|
return selectedChat;
|
||||||
...selectedChat,
|
|
||||||
lastContext: selectedChat.lastContext as LanguageModelV2Usage,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new ChatSDKError('bad_request:database', 'Failed to get chat by id');
|
throw new ChatSDKError('bad_request:database', 'Failed to get chat by id');
|
||||||
}
|
}
|
||||||
|
|
@ -473,32 +469,10 @@ export async function updateChatVisiblityById({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateChatLastContextById({
|
|
||||||
chatId,
|
|
||||||
context,
|
|
||||||
}: {
|
|
||||||
chatId: string;
|
|
||||||
// Store raw LanguageModelUsage to keep it simple
|
|
||||||
context: LanguageModelV2Usage;
|
|
||||||
}) {
|
|
||||||
try {
|
|
||||||
return await db
|
|
||||||
.update(chat)
|
|
||||||
.set({ lastContext: context as any })
|
|
||||||
.where(eq(chat.id, chatId));
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Failed to update lastContext for chat', chatId, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getMessageCountByUserId({
|
export async function getMessageCountByUserId({
|
||||||
id,
|
id,
|
||||||
differenceInHours,
|
differenceInHours,
|
||||||
}: {
|
}: { id: string; differenceInHours: number }) {
|
||||||
id: string;
|
|
||||||
differenceInHours: number;
|
|
||||||
}) {
|
|
||||||
try {
|
try {
|
||||||
const twentyFourHoursAgo = new Date(
|
const twentyFourHoursAgo = new Date(
|
||||||
Date.now() - differenceInHours * 60 * 60 * 1000,
|
Date.now() - differenceInHours * 60 * 60 * 1000,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import {
|
||||||
varchar,
|
varchar,
|
||||||
timestamp,
|
timestamp,
|
||||||
json,
|
json,
|
||||||
jsonb,
|
|
||||||
uuid,
|
uuid,
|
||||||
text,
|
text,
|
||||||
primaryKey,
|
primaryKey,
|
||||||
|
|
@ -30,7 +29,6 @@ export const chat = pgTable('Chat', {
|
||||||
visibility: varchar('visibility', { enum: ['public', 'private'] })
|
visibility: varchar('visibility', { enum: ['public', 'private'] })
|
||||||
.notNull()
|
.notNull()
|
||||||
.default('private'),
|
.default('private'),
|
||||||
lastContext: jsonb('lastContext'),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type Chat = InferSelectModel<typeof chat>;
|
export type Chat = InferSelectModel<typeof chat>;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@
|
||||||
"@radix-ui/react-hover-card": "^1.1.15",
|
"@radix-ui/react-hover-card": "^1.1.15",
|
||||||
"@radix-ui/react-icons": "^1.3.0",
|
"@radix-ui/react-icons": "^1.3.0",
|
||||||
"@radix-ui/react-label": "^2.1.0",
|
"@radix-ui/react-label": "^2.1.0",
|
||||||
"@radix-ui/react-progress": "^1.1.7",
|
|
||||||
"@radix-ui/react-scroll-area": "^1.2.10",
|
"@radix-ui/react-scroll-area": "^1.2.10",
|
||||||
"@radix-ui/react-select": "^2.1.2",
|
"@radix-ui/react-select": "^2.1.2",
|
||||||
"@radix-ui/react-separator": "^1.1.0",
|
"@radix-ui/react-separator": "^1.1.0",
|
||||||
|
|
@ -96,7 +95,7 @@
|
||||||
"swr": "^2.2.5",
|
"swr": "^2.2.5",
|
||||||
"tailwind-merge": "^2.5.2",
|
"tailwind-merge": "^2.5.2",
|
||||||
"tailwindcss-animate": "^1.0.7",
|
"tailwindcss-animate": "^1.0.7",
|
||||||
"tokenlens": "^1.1.2",
|
"tokenlens": "^1.0.0",
|
||||||
"use-stick-to-bottom": "^1.1.1",
|
"use-stick-to-bottom": "^1.1.1",
|
||||||
"usehooks-ts": "^3.1.0",
|
"usehooks-ts": "^3.1.0",
|
||||||
"zod": "^3.25.76"
|
"zod": "^3.25.76"
|
||||||
|
|
|
||||||
36
pnpm-lock.yaml
generated
36
pnpm-lock.yaml
generated
|
|
@ -68,9 +68,6 @@ importers:
|
||||||
'@radix-ui/react-label':
|
'@radix-ui/react-label':
|
||||||
specifier: ^2.1.0
|
specifier: ^2.1.0
|
||||||
version: 2.1.2(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@19.0.0-rc-45804af1-20241021(react@19.0.0-rc-45804af1-20241021))(react@19.0.0-rc-45804af1-20241021)
|
version: 2.1.2(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@19.0.0-rc-45804af1-20241021(react@19.0.0-rc-45804af1-20241021))(react@19.0.0-rc-45804af1-20241021)
|
||||||
'@radix-ui/react-progress':
|
|
||||||
specifier: ^1.1.7
|
|
||||||
version: 1.1.7(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@19.0.0-rc-45804af1-20241021(react@19.0.0-rc-45804af1-20241021))(react@19.0.0-rc-45804af1-20241021)
|
|
||||||
'@radix-ui/react-scroll-area':
|
'@radix-ui/react-scroll-area':
|
||||||
specifier: ^1.2.10
|
specifier: ^1.2.10
|
||||||
version: 1.2.10(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@19.0.0-rc-45804af1-20241021(react@19.0.0-rc-45804af1-20241021))(react@19.0.0-rc-45804af1-20241021)
|
version: 1.2.10(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@19.0.0-rc-45804af1-20241021(react@19.0.0-rc-45804af1-20241021))(react@19.0.0-rc-45804af1-20241021)
|
||||||
|
|
@ -240,8 +237,8 @@ importers:
|
||||||
specifier: ^1.0.7
|
specifier: ^1.0.7
|
||||||
version: 1.0.7(tailwindcss@3.4.17)
|
version: 1.0.7(tailwindcss@3.4.17)
|
||||||
tokenlens:
|
tokenlens:
|
||||||
specifier: ^1.1.2
|
specifier: ^1.0.0
|
||||||
version: 1.1.2
|
version: 1.0.0
|
||||||
use-stick-to-bottom:
|
use-stick-to-bottom:
|
||||||
specifier: ^1.1.1
|
specifier: ^1.1.1
|
||||||
version: 1.1.1(react@19.0.0-rc-45804af1-20241021)
|
version: 1.1.1(react@19.0.0-rc-45804af1-20241021)
|
||||||
|
|
@ -1630,19 +1627,6 @@ packages:
|
||||||
'@types/react-dom':
|
'@types/react-dom':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
'@radix-ui/react-progress@1.1.7':
|
|
||||||
resolution: {integrity: sha512-vPdg/tF6YC/ynuBIJlk1mm7Le0VgW6ub6J2UWnTQ7/D23KXcPI1qy+0vBkgKgd38RCMJavBXpB83HPNFMTb0Fg==}
|
|
||||||
peerDependencies:
|
|
||||||
'@types/react': '*'
|
|
||||||
'@types/react-dom': '*'
|
|
||||||
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
|
|
||||||
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
|
|
||||||
peerDependenciesMeta:
|
|
||||||
'@types/react':
|
|
||||||
optional: true
|
|
||||||
'@types/react-dom':
|
|
||||||
optional: true
|
|
||||||
|
|
||||||
'@radix-ui/react-roving-focus@1.1.2':
|
'@radix-ui/react-roving-focus@1.1.2':
|
||||||
resolution: {integrity: sha512-zgMQWkNO169GtGqRvYrzb0Zf8NhMHS2DuEB/TiEmVnpr5OqPU3i8lfbxaAmC2J/KYuIQxyoQQ6DxepyXp61/xw==}
|
resolution: {integrity: sha512-zgMQWkNO169GtGqRvYrzb0Zf8NhMHS2DuEB/TiEmVnpr5OqPU3i8lfbxaAmC2J/KYuIQxyoQQ6DxepyXp61/xw==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
|
|
@ -4707,8 +4691,8 @@ packages:
|
||||||
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
|
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
|
||||||
engines: {node: '>=8.0'}
|
engines: {node: '>=8.0'}
|
||||||
|
|
||||||
tokenlens@1.1.2:
|
tokenlens@1.0.0:
|
||||||
resolution: {integrity: sha512-PICXahAiVS/2nyc30SijuYZj5wIm2G9+2U7fdvQbl5pa/hIUpQ8H+RdYOzOrSvva6GMqPM5+6cWd9Hqi81Yv3g==}
|
resolution: {integrity: sha512-IslxKcdsPQv4yTUgzeAe9UoEuvXUW6BZyKvKc4N9D7IWnyUBvSTJ3hq8Wb13fM8CkgaS/0k28vpJIQiVQJrpVA==}
|
||||||
|
|
||||||
trim-lines@3.0.1:
|
trim-lines@3.0.1:
|
||||||
resolution: {integrity: sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==}
|
resolution: {integrity: sha512-kRj8B+YHZCc9kQYdWfJB2/oUl9rA99qbowYYBtr4ui4mZyAQ2JpvVBd/6U2YloATfqBhBTSMhTpgBHtU0Mf3Rg==}
|
||||||
|
|
@ -6029,16 +6013,6 @@ snapshots:
|
||||||
'@types/react': 18.3.18
|
'@types/react': 18.3.18
|
||||||
'@types/react-dom': 18.3.5(@types/react@18.3.18)
|
'@types/react-dom': 18.3.5(@types/react@18.3.18)
|
||||||
|
|
||||||
'@radix-ui/react-progress@1.1.7(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@19.0.0-rc-45804af1-20241021(react@19.0.0-rc-45804af1-20241021))(react@19.0.0-rc-45804af1-20241021)':
|
|
||||||
dependencies:
|
|
||||||
'@radix-ui/react-context': 1.1.2(@types/react@18.3.18)(react@19.0.0-rc-45804af1-20241021)
|
|
||||||
'@radix-ui/react-primitive': 2.1.3(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@19.0.0-rc-45804af1-20241021(react@19.0.0-rc-45804af1-20241021))(react@19.0.0-rc-45804af1-20241021)
|
|
||||||
react: 19.0.0-rc-45804af1-20241021
|
|
||||||
react-dom: 19.0.0-rc-45804af1-20241021(react@19.0.0-rc-45804af1-20241021)
|
|
||||||
optionalDependencies:
|
|
||||||
'@types/react': 18.3.18
|
|
||||||
'@types/react-dom': 18.3.5(@types/react@18.3.18)
|
|
||||||
|
|
||||||
'@radix-ui/react-roving-focus@1.1.2(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@19.0.0-rc-45804af1-20241021(react@19.0.0-rc-45804af1-20241021))(react@19.0.0-rc-45804af1-20241021)':
|
'@radix-ui/react-roving-focus@1.1.2(@types/react-dom@18.3.5(@types/react@18.3.18))(@types/react@18.3.18)(react-dom@19.0.0-rc-45804af1-20241021(react@19.0.0-rc-45804af1-20241021))(react@19.0.0-rc-45804af1-20241021)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@radix-ui/primitive': 1.1.1
|
'@radix-ui/primitive': 1.1.1
|
||||||
|
|
@ -9738,7 +9712,7 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
is-number: 7.0.0
|
is-number: 7.0.0
|
||||||
|
|
||||||
tokenlens@1.1.2: {}
|
tokenlens@1.0.0: {}
|
||||||
|
|
||||||
trim-lines@3.0.1: {}
|
trim-lines@3.0.1: {}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue