Merge pull request #745 from CREDO23/sur-106-feat-public-chats

[Feature] Public Chat Sharing and Cloning
This commit is contained in:
Rohan Verma 2026-01-27 16:01:08 -08:00 committed by GitHub
commit 752a51d3fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 2253 additions and 474 deletions

View file

@ -25,6 +25,10 @@ export const useGithubStars = () => {
setStars(data?.stargazers_count);
} catch (err) {
// Ignore abort errors (expected on unmount)
if (err instanceof Error && err.name === "AbortError") {
return;
}
if (err instanceof Error) {
console.error("Error fetching stars:", err);
setError(err.message);
@ -37,7 +41,7 @@ export const useGithubStars = () => {
getStars();
return () => {
abortController.abort();
abortController.abort("Component unmounted");
};
}, []);

View file

@ -0,0 +1,51 @@
"use client";
import { type AppendMessage, useExternalStoreRuntime } from "@assistant-ui/react";
import { useCallback, useMemo } from "react";
import type { GetPublicChatResponse, PublicChatMessage } from "@/contracts/types/public-chat.types";
import { convertToThreadMessage } from "@/lib/chat/message-utils";
import type { MessageRecord } from "@/lib/chat/thread-persistence";
interface UsePublicChatRuntimeOptions {
data: GetPublicChatResponse | undefined;
}
/**
* Map PublicChatMessage to MessageRecord shape for reuse of convertToThreadMessage
*/
function toMessageRecord(msg: PublicChatMessage, idx: number): MessageRecord {
return {
id: idx,
thread_id: 0,
role: msg.role as "user" | "assistant" | "system",
content: msg.content,
created_at: msg.created_at,
author_id: msg.author ? "public" : null,
author_display_name: msg.author?.display_name ?? null,
author_avatar_url: msg.author?.avatar_url ?? null,
};
}
/**
* Creates a read-only runtime for public chat viewing.
*/
export function usePublicChatRuntime({ data }: UsePublicChatRuntimeOptions) {
const messages = useMemo(() => data?.messages ?? [], [data?.messages]);
// No-op - public chat is read-only
const onNew = useCallback(async (_message: AppendMessage) => {}, []);
const convertMessage = useCallback(
(msg: PublicChatMessage, idx: number) => convertToThreadMessage(toMessageRecord(msg, idx)),
[]
);
const runtime = useExternalStoreRuntime({
isRunning: false,
messages,
onNew,
convertMessage,
});
return runtime;
}

View file

@ -0,0 +1,14 @@
import { useQuery } from "@tanstack/react-query";
import type { GetPublicChatResponse } from "@/contracts/types/public-chat.types";
import { publicChatApiService } from "@/lib/apis/public-chat-api.service";
import { cacheKeys } from "@/lib/query-client/cache-keys";
export function usePublicChat(shareToken: string) {
return useQuery<GetPublicChatResponse, Error>({
queryKey: cacheKeys.publicChat.byToken(shareToken),
queryFn: () => publicChatApiService.getPublicChat({ share_token: shareToken }),
enabled: !!shareToken,
staleTime: 30_000,
retry: false,
});
}