Sfoglia il codice sorgente

feat: add entities

Thomas Zhang 3 mesi fa
parent
commit
3cd3003693

+ 18 - 0
src/lib/types/entities/agent.ts

@@ -0,0 +1,18 @@
+import type { DeploymentStatus, IDRef, RuntimeTemplate } from './types';
+
+type Agent = {
+	id: string;
+	stack?: string;
+	name: string;
+	icon?: string;
+	description: string;
+	tags: string[];
+	systemPrompt?: string;
+	model: IDRef;
+	tools: IDRef[];
+	kbs: IDRef[];
+	runtime: RuntimeTemplate;
+	status?: DeploymentStatus;
+};
+
+export type { Agent };

+ 7 - 0
src/lib/types/entities/index.ts

@@ -0,0 +1,7 @@
+export * from './agent';
+export * from './kb';
+export * from './model';
+export * from './secret';
+export * from './stack';
+export * from './tool';
+export * from './types';

+ 73 - 0
src/lib/types/entities/kb.ts

@@ -0,0 +1,73 @@
+import type { DeploymentStatus, IDRef, RuntimeTemplate } from './types';
+
+type ExternalKBStatus = 'available' | 'error' | 'rate-limited';
+type KBDocumentStatus = 'pending' | 'available' | 'error';
+type KBDocumentType = 'text' | 'markdown' | 'html' | 'pdf' | 'docx';
+
+type KBDocumentSource =
+	| {
+			type: 'unknown';
+	  }
+	| {
+			type: 'upload';
+			fileName: string;
+	  };
+
+type ChunkingStrategy = {
+	strategy: string;
+	size: number;
+	overlap: number;
+	separators?: string[];
+};
+
+type KBDocument = {
+	id: string;
+	kb: IDRef;
+	name: string;
+	description: string;
+	tags: string[];
+	type: KBDocumentType;
+	sizeBytes: number;
+	source: KBDocumentSource;
+	chunking: ChunkingStrategy;
+	status?: KBDocumentStatus;
+};
+
+type KBBase = {
+	id: string;
+	stack?: string;
+	name: string;
+	icon?: string;
+	description: string;
+	tags: string[];
+	documents: KBDocument[];
+};
+
+type ExternalKB = KBBase & {
+	mode: 'external';
+	status?: ExternalKBStatus;
+};
+
+type ManagedKB = KBBase & {
+	mode: 'managed';
+	embedding?: IDRef;
+	reranker?: IDRef;
+	runtime: RuntimeTemplate;
+	ingestion?: RuntimeTemplate;
+	egestion?: RuntimeTemplate;
+	status?: DeploymentStatus;
+};
+
+type KnowledgeBase = ManagedKB | ExternalKB;
+
+export type {
+	ChunkingStrategy,
+	ExternalKB,
+	KBBase,
+	KBDocument,
+	KBDocumentSource,
+	KBDocumentStatus,
+	KBDocumentType,
+	KnowledgeBase,
+	ManagedKB,
+};

+ 135 - 0
src/lib/types/entities/model.ts

@@ -0,0 +1,135 @@
+import type { AuthConfig, DeploymentStatus, RuntimeTemplate } from './types';
+
+const MODEL_CATEGORIES: { value: ModelCategory; label: string }[] = [
+	{ value: 'language', label: 'Language' },
+	{ value: 'embedding', label: 'Embedding' },
+	{ value: 'reranker', label: 'Reranker' },
+];
+
+const MODEL_MODALITIES = [
+	{ value: 'text', label: 'Text' },
+	{ value: 'image', label: 'Image' },
+	{ value: 'video', label: 'Video' },
+	{ value: 'audio', label: 'Audio' },
+];
+
+const MODEL_PROVIDERS = [
+	{ value: 'openai', label: 'OpenAI' },
+	{ value: 'anthropic', label: 'Anthropic' },
+	{ value: 'cohere', label: 'Cohere' },
+	{ value: 'google', label: 'Google' },
+	{ value: 'azure', label: 'Azure' },
+	{ value: 'aws', label: 'AWS' },
+	{ value: 'deepseek', label: 'DeepSeek' },
+	{ value: 'minimax', label: 'MiniMax' },
+	{ value: 'moonshot', label: 'Moonshot AI' },
+	{ value: 'qwen', label: 'Qwen' },
+	{ value: 'zai', label: 'Z.ai' },
+	{ value: 'other', label: 'Other' },
+];
+
+const MODEL_RUNTIMES = [
+	{
+		value: 'llama.cpp',
+		label: 'llama.cpp',
+		supports: new Set(['language', 'embedding', 'reranker']),
+		versions: [
+			{ value: 'llama.cpp', label: 'CPU' },
+			{ value: 'llama.cpp-embedding', label: 'Embedding CPU' },
+			{ value: 'llama.cpp-reranker', label: 'Reranker CPU' },
+		],
+	},
+];
+
+type ModelCategory = 'language' | 'embedding' | 'reranker';
+type ModelModality = 'text' | 'image' | 'video' | 'audio';
+type ModelRuntime = 'llama.cpp' | 'vllm' | 'sglang' | 'tgi' | 'tei' | 'infinity';
+type ModelInferenceParameters = {
+	temperature?: string;
+	topP?: string;
+	maxTokens?: number;
+	extra?: {
+		[key: string]: string;
+	};
+};
+type ModelRuntimeInferenceParameters = {
+	chatTemplate?: string;
+	contextWindow?: number;
+	temperature?: string;
+	topK?: number;
+	topP?: string;
+	extra?: {
+		[key: string]: string;
+	};
+};
+type ExternalModelStatus = 'available' | 'error' | 'degraded' | 'rate-limited' | 'out-of-budget';
+
+type ModelInfo = {
+	family?: string;
+	baseModelId?: string;
+	releaseDate?: string;
+	displayName?: string;
+	parameterCount?: string;
+	// language models
+	contextWindow?: number;
+	inputs?: ModelModality[];
+	outputs?: ModelModality[];
+	capabilities?: string[];
+	// embedding models
+	embeddingDimensions?: number;
+	maxInputTokens?: number;
+	// all models
+	languages?: string[];
+};
+
+type ModelBase = {
+	id: string;
+	stack?: string;
+	name: string;
+	icon?: string;
+	description: string;
+	tags: string[];
+	info: ModelInfo;
+	category: ModelCategory;
+};
+
+type ExternalModel = ModelBase & {
+	mode: 'external';
+	provider: string;
+	providerModel: string;
+	apiBase?: string;
+	apiVersion?: string;
+	auth: AuthConfig;
+	extraParams?: Record<string, string>;
+	defaultInferenceParams?: ModelInferenceParameters;
+	status?: ExternalModelStatus;
+};
+
+type ManagedModel = ModelBase & {
+	mode: 'managed';
+	huggingFace?: {
+		endpoint?: string;
+		repo: string;
+		revision?: string;
+		fileName?: string;
+	};
+	runtime: RuntimeTemplate;
+	runtimeInferenceParameters?: ModelRuntimeInferenceParameters;
+	status?: DeploymentStatus;
+};
+
+type Model = ExternalModel | ManagedModel;
+
+export type {
+	ExternalModel,
+	ExternalModelStatus,
+	ManagedModel,
+	Model,
+	ModelBase,
+	ModelCategory,
+	ModelInferenceParameters,
+	ModelModality,
+	ModelRuntime,
+	ModelRuntimeInferenceParameters,
+};
+export { MODEL_CATEGORIES, MODEL_MODALITIES, MODEL_PROVIDERS, MODEL_RUNTIMES };

+ 12 - 0
src/lib/types/entities/secret.ts

@@ -0,0 +1,12 @@
+type SecretItem = {
+	key: string;
+	value: string;
+};
+
+type Secret = {
+	id: string;
+	name: string;
+	items: SecretItem[];
+};
+
+export type { Secret, SecretItem };

+ 28 - 0
src/lib/types/entities/stack.ts

@@ -0,0 +1,28 @@
+import type { RuntimeTemplate } from './types';
+
+type OptionalComponent = {
+	enabled: boolean;
+	runtime?: RuntimeTemplate;
+};
+
+type ComponentStatus = {
+	gateway?: string;
+	vectorStore?: string;
+	graphStore?: string;
+	database?: string;
+	observability?: string;
+};
+
+type Stack = {
+	id: string;
+	name: string;
+	sharedVolumes?: string[];
+	gateway?: OptionalComponent;
+	vectorStore?: OptionalComponent;
+	graphStore?: OptionalComponent;
+	database?: OptionalComponent;
+	observability?: OptionalComponent;
+	status?: ComponentStatus;
+};
+
+export type { Stack };

+ 30 - 0
src/lib/types/entities/tool.ts

@@ -0,0 +1,30 @@
+import type { AuthConfig, DeploymentStatus, RuntimeTemplate } from './types';
+
+type ExternalToolStatus = 'available' | 'error' | 'rate-limited' | 'out-of-budget';
+
+type ToolBase = {
+	id: string;
+	stack?: string;
+	name: string;
+	icon?: string;
+	description: string;
+	tags: string[];
+	transport: 'sse' | 'http';
+};
+
+type ExternalTool = ToolBase & {
+	mode: 'external';
+	endpoint: string;
+	auth: AuthConfig;
+	status?: ExternalToolStatus;
+};
+
+type ManagedTool = ToolBase & {
+	mode: 'managed';
+	runtime: RuntimeTemplate;
+	status?: DeploymentStatus;
+};
+
+type Tool = ExternalTool | ManagedTool;
+
+export type { ExternalTool, ExternalToolStatus, ManagedTool, Tool, ToolBase };

+ 40 - 0
src/lib/types/entities/types.ts

@@ -0,0 +1,40 @@
+const AUTH_TYPES = [
+	{ value: 'none', label: 'None' },
+	{ value: 'bearer', label: 'Bearer Token' },
+	{ value: 'api-key', label: 'API Key' },
+];
+
+type AuthConfig = { headers?: { name: string; value: string }[] } & (
+	| { type: 'none' }
+	| { type: 'bearer'; secretName: string; secretKey: string }
+	| { type: 'api-key'; headerName: string; secretName: string; secretKey: string }
+);
+
+type IDRef = {
+	type?: 'managed' | 'external';
+	id: string;
+	name?: string;
+	icon?: string;
+};
+
+type RuntimeTemplate = {
+	name: string;
+	version?: string;
+	replicas?: number;
+	volumes?: { name: string; size: string; mountPath: string }[];
+	image?: string;
+	command?: string[];
+	args?: string[];
+	extraArgs?: string[];
+	env?: { name: string; value: string }[];
+	port?: number;
+	node?: { [key: string]: string };
+	cpu?: string;
+	memory?: string;
+	gpu?: string;
+};
+
+type DeploymentStatus = 'not-deployed' | 'pending' | 'running' | 'degraded' | 'stopped';
+
+export type { AuthConfig, DeploymentStatus, IDRef, RuntimeTemplate };
+export { AUTH_TYPES };