feat: add more metadata for shared session view (#1919)
This commit is contained in:
@@ -65,8 +65,10 @@ const SessionHistoryView: React.FC<SessionHistoryViewProps> = ({
|
|||||||
// Create a shared session
|
// Create a shared session
|
||||||
const shareToken = await createSharedSession(
|
const shareToken = await createSharedSession(
|
||||||
config.baseUrl,
|
config.baseUrl,
|
||||||
|
session.metadata.working_dir,
|
||||||
session.messages,
|
session.messages,
|
||||||
session.metadata.description || 'Shared Session'
|
session.metadata.description || 'Shared Session',
|
||||||
|
session.metadata.total_tokens
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create the shareable link
|
// Create the shareable link
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Clock, Globe } from 'lucide-react';
|
import { Clock, Globe, MessageSquare, Folder } from 'lucide-react';
|
||||||
import { type SharedSessionDetails } from '../../sharedSessions';
|
import { type SharedSessionDetails } from '../../sharedSessions';
|
||||||
import { SessionHeaderCard, SessionMessages } from './SessionViewComponents';
|
import { SessionHeaderCard, SessionMessages } from './SessionViewComponents';
|
||||||
|
|
||||||
@@ -35,9 +35,26 @@ const SharedSessionView: React.FC<SharedSessionViewProps> = ({
|
|||||||
<Clock className="w-4 h-4 mr-1" />
|
<Clock className="w-4 h-4 mr-1" />
|
||||||
{new Date(session.messages[0]?.created * 1000).toLocaleString()}
|
{new Date(session.messages[0]?.created * 1000).toLocaleString()}
|
||||||
</span>
|
</span>
|
||||||
<span className="flex items-center">
|
{/* <span className="flex items-center">
|
||||||
<Globe className="w-4 h-4 mr-1" />
|
<Globe className="w-4 h-4 mr-1" />
|
||||||
{session.base_url}
|
{session.base_url}
|
||||||
|
</span> */}
|
||||||
|
<span className="flex items-center">
|
||||||
|
<MessageSquare className="w-4 h-4 mr-1" />
|
||||||
|
{session.message_count} messages
|
||||||
|
</span>
|
||||||
|
{session.total_tokens !== null && (
|
||||||
|
<span className="flex items-center">
|
||||||
|
{session.total_tokens.toLocaleString()} tokens
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{session && (
|
||||||
|
<div className="flex items-center text-sm text-textSubtle mt-1">
|
||||||
|
<span className="flex items-center">
|
||||||
|
<Folder className="w-4 h-4 mr-1" />
|
||||||
|
{session.working_dir}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import { Message, createUserMessage, createAssistantMessage } from './types/message';
|
import { Message } from './types/message';
|
||||||
|
|
||||||
export interface SharedSessionDetails {
|
export interface SharedSessionDetails {
|
||||||
share_token: string;
|
share_token: string;
|
||||||
created_at: number;
|
created_at: number;
|
||||||
base_url: string;
|
base_url: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
working_dir: string;
|
||||||
messages: Message[];
|
messages: Message[];
|
||||||
|
message_count: number;
|
||||||
|
total_tokens: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,8 +45,11 @@ export async function fetchSharedSessionDetails(
|
|||||||
share_token: data.share_token,
|
share_token: data.share_token,
|
||||||
created_at: data.created_at,
|
created_at: data.created_at,
|
||||||
base_url: data.base_url,
|
base_url: data.base_url,
|
||||||
description: data.description || 'Shared Session',
|
description: data.description,
|
||||||
|
working_dir: data.working_dir,
|
||||||
messages: data.messages,
|
messages: data.messages,
|
||||||
|
message_count: data.message_count,
|
||||||
|
total_tokens: data.total_tokens,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching shared session:', error);
|
console.error('Error fetching shared session:', error);
|
||||||
@@ -54,14 +60,19 @@ export async function fetchSharedSessionDetails(
|
|||||||
/**
|
/**
|
||||||
* Creates a new shared session
|
* Creates a new shared session
|
||||||
* @param baseUrl The base URL for session sharing API
|
* @param baseUrl The base URL for session sharing API
|
||||||
|
* @param workingDir The working directory for the shared session
|
||||||
* @param messages The messages to include in the shared session
|
* @param messages The messages to include in the shared session
|
||||||
* @param description Optional description for the shared session
|
* @param description Description for the shared session
|
||||||
|
* @param totalTokens Total token count for the session, or null if not available
|
||||||
|
* @param userName The user name for who is sharing the session
|
||||||
* @returns Promise with the share token
|
* @returns Promise with the share token
|
||||||
*/
|
*/
|
||||||
export async function createSharedSession(
|
export async function createSharedSession(
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
|
workingDir: string,
|
||||||
messages: Message[],
|
messages: Message[],
|
||||||
description?: string
|
description: string,
|
||||||
|
totalTokens: number | null
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${baseUrl}/sessions/share`, {
|
const response = await fetch(`${baseUrl}/sessions/share`, {
|
||||||
@@ -70,9 +81,11 @@ export async function createSharedSession(
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
working_dir: workingDir,
|
||||||
messages,
|
messages,
|
||||||
description: description || 'Shared Session',
|
description: description,
|
||||||
base_url: baseUrl,
|
base_url: baseUrl,
|
||||||
|
total_tokens: totalTokens ?? null,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user