Files
zn-ai/runtime-shared/lib/models.ts
duanshuwen 721344883f refactor: reorganize imports and update type references across services
- Updated import paths for types and utilities in config-service, menu-service, script-execution-service, script-store-service, and window-service to reflect new structure.
- Moved utility functions like debounce and cloneDeep to shared utilities.
- Created new runtime and script types files to centralize type definitions.
- Removed deprecated task-types and locale messages files.
- Updated constants to use shared definitions and added new placeholders for providers.
- Enhanced provider type information with additional placeholders for different languages.
2026-04-21 23:25:51 +08:00

101 lines
2.5 KiB
TypeScript

import {
DEFAULT_AGENT_ID,
DEFAULT_CHANNEL_ACCOUNT_ID,
DEFAULT_MAIN_SESSION_SUFFIX,
buildAgentSessionKey,
buildMainSessionKey,
buildChannelAccountOwnerKey,
normalizeAgentId,
normalizeChannelAccountId,
normalizeChannelType,
normalizeSessionSuffix,
parseChannelAccountOwnerKey,
resolveChannelAccountOwner,
type AgentSummary,
type AgentChannelBinding,
type AgentChannelBindingInput,
type AgentChannelUnbindingInput,
type AgentsSnapshot,
} from './agents';
export type ModelSummary = AgentSummary;
export const DEFAULT_MODEL_ID = DEFAULT_AGENT_ID;
export type ModelsSnapshot = AgentsSnapshot & {
models: ModelSummary[];
agents?: ModelSummary[];
};
export interface ParsedSessionKey {
sessionKey: string;
agentId: string;
sessionId: string;
isAgentSession: boolean;
}
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;
export {
DEFAULT_AGENT_ID,
DEFAULT_CHANNEL_ACCOUNT_ID,
DEFAULT_MAIN_SESSION_SUFFIX,
buildAgentSessionKey,
buildMainSessionKey,
buildChannelAccountOwnerKey,
normalizeAgentId,
normalizeChannelAccountId,
normalizeChannelType,
normalizeSessionSuffix,
parseChannelAccountOwnerKey,
resolveChannelAccountOwner,
};
export type {
AgentSummary,
AgentChannelBinding,
AgentChannelBindingInput,
AgentChannelUnbindingInput,
AgentsSnapshot,
};