Use this file to discover all available pages before exploring further.
This guide assumes that you have completed the Quickstart.
An example project demonstrating implementation of this guide can be found
here.
Enable thread-level sharing with the C1ShareThread component. You provide a generateShareLink(messages) function; the SDK gathers messages, opens a modal, and handles copying/confirmation.
1
Frontend: Add a Thread Share trigger
First, destructure the C1Chat component as explained the Integrating Custom Components guide, so that you can integrate a custom header. Next,
use the C1ShareThread component to display a share button in your chat header, which automatically opens a modal to generate a share link using the generateShareLink function you defined.The updated code for the chat page will look something like this:
Implement an endpoint that returns the thread for a given threadId.
Implement a message store to store the message history. If you’ve followed the Quickstart, you’ll have a message store already, which you can move
to a common location (such as /lib/messageStore.ts) and modify it to persist message history across API routes and requests as follows:
/lib/messageStore.ts
import OpenAI from "openai";export type DBMessage = OpenAI.Chat.ChatCompletionMessageParam & { id?: string;};const messagesStore: { [threadId: string]: DBMessage[];} = {};export const getMessageStore = (id: string) => { const messageList = await fetchMessagesFromDB(id); // fetch from db here return { addMessage: (message: DBMessage) => { // save to db here }, messageList, };};
/app/api/share/[threadId]/route.ts
import { NextRequest, NextResponse } from "next/server";import { getMessageStore } from "@/lib/messageStore";export async function GET( req: NextRequest, { params }: { params: Promise<{ threadId: string }> }) { const { threadId } = await params; if (!threadId) { return NextResponse.json( { error: "Thread ID is required" }, { status: 400 } ); } const messageStore = getMessageStore(threadId); return NextResponse.json(messageStore.messageList);}