feat: add models management and usage history components
- Introduced RequestContentDialog for displaying request content details. - Added UsageBarChart for visualizing token usage data. - Implemented UsageHistorySection to manage and display usage history with filtering and pagination. - Created provider-types for managing provider-related types. - Developed ModelsPage to encapsulate models configuration, providers, and usage history. - Defined usage-history types and utility functions for managing usage data. - Updated routing to include models page and redirect agents to models. - Refactored chat store to integrate models instead of agents. - Established models store for managing model-related state and data fetching.
This commit is contained in:
@@ -1,92 +1 @@
|
||||
export const DEFAULT_AGENT_ID = 'main';
|
||||
export const DEFAULT_MAIN_SESSION_SUFFIX = 'main';
|
||||
|
||||
export interface AgentSummary {
|
||||
id: string;
|
||||
name: string;
|
||||
isDefault: boolean;
|
||||
providerAccountId: string | null;
|
||||
modelRef: string | null;
|
||||
modelDisplay: string;
|
||||
mainSessionKey: string;
|
||||
vendorId?: string | null;
|
||||
source?: 'synthetic-main' | 'provider-account';
|
||||
}
|
||||
|
||||
export interface AgentsSnapshot {
|
||||
agents: AgentSummary[];
|
||||
defaultAgentId: string;
|
||||
defaultProviderAccountId: string | null;
|
||||
defaultModelRef: string | null;
|
||||
mainSessionSuffix: string;
|
||||
configuredChannelTypes: string[];
|
||||
channelOwners: Record<string, string>;
|
||||
channelAccountOwners: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface ParsedSessionKey {
|
||||
sessionKey: string;
|
||||
agentId: string;
|
||||
sessionId: string;
|
||||
isAgentSession: boolean;
|
||||
}
|
||||
|
||||
export function normalizeAgentId(value: string | null | undefined): string {
|
||||
const normalized = String(value ?? '').trim().toLowerCase();
|
||||
return normalized || DEFAULT_AGENT_ID;
|
||||
}
|
||||
|
||||
export function normalizeSessionSuffix(value: string | null | undefined): string {
|
||||
const normalized = String(value ?? '').trim().toLowerCase();
|
||||
return normalized || DEFAULT_MAIN_SESSION_SUFFIX;
|
||||
}
|
||||
|
||||
export function buildAgentSessionKey(agentId: string, sessionId: string): string {
|
||||
return `agent:${normalizeAgentId(agentId)}:${normalizeSessionSuffix(sessionId)}`;
|
||||
}
|
||||
|
||||
export function buildMainSessionKey(
|
||||
agentId: string,
|
||||
sessionId = DEFAULT_MAIN_SESSION_SUFFIX,
|
||||
): string {
|
||||
return buildAgentSessionKey(agentId, sessionId);
|
||||
}
|
||||
|
||||
export function parseSessionKey(sessionKey: string): ParsedSessionKey {
|
||||
const trimmed = String(sessionKey ?? '').trim();
|
||||
|
||||
if (trimmed.startsWith('agent:')) {
|
||||
const parts = trimmed.split(':');
|
||||
const agentId = normalizeAgentId(parts[1]);
|
||||
const sessionId = normalizeSessionSuffix(parts.slice(2).join(':'));
|
||||
return {
|
||||
sessionKey: buildAgentSessionKey(agentId, sessionId),
|
||||
agentId,
|
||||
sessionId,
|
||||
isAgentSession: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (trimmed.startsWith('local:')) {
|
||||
const parts = trimmed.split(':');
|
||||
const agentId = normalizeAgentId(parts[1]);
|
||||
const sessionId = normalizeSessionSuffix(parts.slice(2).join(':'));
|
||||
return {
|
||||
sessionKey: buildAgentSessionKey(agentId, sessionId),
|
||||
agentId,
|
||||
sessionId,
|
||||
isAgentSession: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
sessionKey: trimmed,
|
||||
agentId: DEFAULT_AGENT_ID,
|
||||
sessionId: normalizeSessionSuffix(trimmed),
|
||||
isAgentSession: false,
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeAgentSessionKey(sessionKey: string): string {
|
||||
return parseSessionKey(sessionKey).sessionKey;
|
||||
}
|
||||
export * from './models';
|
||||
|
||||
112
runtime-shared/lib/models.ts
Normal file
112
runtime-shared/lib/models.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
export const DEFAULT_AGENT_ID = 'main';
|
||||
export const DEFAULT_MAIN_SESSION_SUFFIX = 'main';
|
||||
export const DEFAULT_MODEL_ID = DEFAULT_AGENT_ID;
|
||||
|
||||
export interface AgentSummary {
|
||||
id: string;
|
||||
name: string;
|
||||
isDefault: boolean;
|
||||
providerAccountId: string | null;
|
||||
modelRef: string | null;
|
||||
modelDisplay: string;
|
||||
mainSessionKey: string;
|
||||
vendorId?: string | null;
|
||||
source?: 'synthetic-main' | 'provider-account';
|
||||
}
|
||||
|
||||
export type ModelSummary = AgentSummary;
|
||||
|
||||
export interface ModelsSnapshot {
|
||||
models: ModelSummary[];
|
||||
agents?: ModelSummary[];
|
||||
defaultAgentId: string;
|
||||
defaultProviderAccountId: string | null;
|
||||
defaultModelRef: string | null;
|
||||
mainSessionSuffix: string;
|
||||
configuredChannelTypes: string[];
|
||||
channelOwners: Record<string, string>;
|
||||
channelAccountOwners: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface AgentsSnapshot {
|
||||
agents: AgentSummary[];
|
||||
models?: AgentSummary[];
|
||||
defaultAgentId: string;
|
||||
defaultProviderAccountId: string | null;
|
||||
defaultModelRef: string | null;
|
||||
mainSessionSuffix: string;
|
||||
configuredChannelTypes: string[];
|
||||
channelOwners: Record<string, string>;
|
||||
channelAccountOwners: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface ParsedSessionKey {
|
||||
sessionKey: string;
|
||||
agentId: string;
|
||||
sessionId: string;
|
||||
isAgentSession: boolean;
|
||||
}
|
||||
|
||||
export function normalizeAgentId(value: string | null | undefined): string {
|
||||
const normalized = String(value ?? '').trim().toLowerCase();
|
||||
return normalized || DEFAULT_AGENT_ID;
|
||||
}
|
||||
|
||||
export function normalizeSessionSuffix(value: string | null | undefined): string {
|
||||
const normalized = String(value ?? '').trim().toLowerCase();
|
||||
return normalized || DEFAULT_MAIN_SESSION_SUFFIX;
|
||||
}
|
||||
|
||||
export function buildAgentSessionKey(agentId: string, sessionId: string): string {
|
||||
return `agent:${normalizeAgentId(agentId)}:${normalizeSessionSuffix(sessionId)}`;
|
||||
}
|
||||
|
||||
export function buildMainSessionKey(
|
||||
agentId: string,
|
||||
sessionId = DEFAULT_MAIN_SESSION_SUFFIX,
|
||||
): string {
|
||||
return buildAgentSessionKey(agentId, sessionId);
|
||||
}
|
||||
|
||||
export function parseSessionKey(sessionKey: string): ParsedSessionKey {
|
||||
const trimmed = String(sessionKey ?? '').trim();
|
||||
|
||||
if (trimmed.startsWith('agent:')) {
|
||||
const parts = trimmed.split(':');
|
||||
const agentId = normalizeAgentId(parts[1]);
|
||||
const sessionId = normalizeSessionSuffix(parts.slice(2).join(':'));
|
||||
return {
|
||||
sessionKey: buildAgentSessionKey(agentId, sessionId),
|
||||
agentId,
|
||||
sessionId,
|
||||
isAgentSession: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (trimmed.startsWith('local:')) {
|
||||
const parts = trimmed.split(':');
|
||||
const agentId = normalizeAgentId(parts[1]);
|
||||
const sessionId = normalizeSessionSuffix(parts.slice(2).join(':'));
|
||||
return {
|
||||
sessionKey: buildAgentSessionKey(agentId, sessionId),
|
||||
agentId,
|
||||
sessionId,
|
||||
isAgentSession: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
sessionKey: trimmed,
|
||||
agentId: DEFAULT_AGENT_ID,
|
||||
sessionId: normalizeSessionSuffix(trimmed),
|
||||
isAgentSession: false,
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeAgentSessionKey(sessionKey: string): string {
|
||||
return parseSessionKey(sessionKey).sessionKey;
|
||||
}
|
||||
|
||||
export const normalizeModelId = normalizeAgentId;
|
||||
export const buildModelSessionKey = buildAgentSessionKey;
|
||||
export const normalizeModelSessionKey = normalizeAgentSessionKey;
|
||||
Reference in New Issue
Block a user