feat: add runtime event handling for providers in ProvidersSection feat: update routing to include Channels and Agents pages feat: extend route types and navigation items for Channels and Agents feat: implement agents store for managing agent data and interactions fix: update chat store to utilize agents store for agent-related functionality chore: export agents store from index fix: enhance runtime types for better event handling fix: update Vite config to handle dev server URL correctly
120 lines
3.4 KiB
TypeScript
120 lines
3.4 KiB
TypeScript
export const DEFAULT_AGENT_ID = 'main';
|
|
export const DEFAULT_MAIN_SESSION_SUFFIX = 'main';
|
|
export const DEFAULT_CHANNEL_ACCOUNT_ID = 'default';
|
|
|
|
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' | 'agent-config';
|
|
overrideModelRef?: string | null;
|
|
inheritedModel?: boolean;
|
|
workspace?: string;
|
|
agentDir?: string;
|
|
channelTypes?: 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 AgentChannelBinding {
|
|
channelType: string;
|
|
accountId: string;
|
|
agentId: string;
|
|
}
|
|
|
|
export interface AgentChannelBindingInput {
|
|
channelType: string;
|
|
accountId: string;
|
|
agentId: string;
|
|
}
|
|
|
|
export interface AgentChannelUnbindingInput {
|
|
channelType: string;
|
|
accountId: string;
|
|
}
|
|
|
|
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 normalizeChannelType(value: string | null | undefined): string {
|
|
return String(value ?? '').trim().toLowerCase();
|
|
}
|
|
|
|
export function normalizeChannelAccountId(value: string | null | undefined): string {
|
|
const normalized = String(value ?? '').trim();
|
|
return normalized || DEFAULT_CHANNEL_ACCOUNT_ID;
|
|
}
|
|
|
|
export function buildChannelAccountOwnerKey(
|
|
channelType: string,
|
|
accountId: string | null | undefined = DEFAULT_CHANNEL_ACCOUNT_ID,
|
|
): string {
|
|
return `${normalizeChannelType(channelType)}:${normalizeChannelAccountId(accountId)}`;
|
|
}
|
|
|
|
export function parseChannelAccountOwnerKey(key: string): {
|
|
channelType: string;
|
|
accountId: string;
|
|
} {
|
|
const trimmed = String(key ?? '').trim();
|
|
const separatorIndex = trimmed.indexOf(':');
|
|
if (separatorIndex === -1) {
|
|
return {
|
|
channelType: normalizeChannelType(trimmed),
|
|
accountId: DEFAULT_CHANNEL_ACCOUNT_ID,
|
|
};
|
|
}
|
|
|
|
return {
|
|
channelType: normalizeChannelType(trimmed.slice(0, separatorIndex)),
|
|
accountId: normalizeChannelAccountId(trimmed.slice(separatorIndex + 1)),
|
|
};
|
|
}
|
|
|
|
export function resolveChannelAccountOwner(
|
|
channelAccountOwners: Record<string, string> | null | undefined,
|
|
channelType: string,
|
|
accountId?: string | null,
|
|
): string | null {
|
|
if (!channelAccountOwners) return null;
|
|
const key = buildChannelAccountOwnerKey(channelType, accountId);
|
|
const owner = channelAccountOwners[key];
|
|
return typeof owner === 'string' && owner.trim() ? owner : null;
|
|
}
|
|
|
|
export type AgentSummaryLike = AgentSummary;
|
|
export type AgentsSnapshotLike = AgentsSnapshot;
|