import { __exportAll } from "../../_virtual/rolldown_runtime.js";
import { relations } from "drizzle-orm";
import { boolean, doublePrecision, foreignKey, index, integer, jsonb, numeric, pgTable, primaryKey, text, timestamp, unique, varchar } from "drizzle-orm/pg-core";

//#region src/db/manage/manage-schema.ts
var manage_schema_exports = /* @__PURE__ */ __exportAll({
	agentDatasetRelations: () => agentDatasetRelations,
	agentDatasetRelationsRelations: () => agentDatasetRelationsRelations,
	agentEvaluatorRelations: () => agentEvaluatorRelations,
	agentEvaluatorRelationsRelations: () => agentEvaluatorRelationsRelations,
	agentRelations: () => agentRelations,
	agentToolRelationsRelations: () => agentToolRelationsRelations,
	agents: () => agents,
	artifactComponents: () => artifactComponents,
	artifactComponentsRelations: () => artifactComponentsRelations,
	contextConfigs: () => contextConfigs,
	contextConfigsRelations: () => contextConfigsRelations,
	credentialReferences: () => credentialReferences,
	credentialReferencesRelations: () => credentialReferencesRelations,
	dataComponents: () => dataComponents,
	dataComponentsRelations: () => dataComponentsRelations,
	dataset: () => dataset,
	datasetItem: () => datasetItem,
	datasetRunConfig: () => datasetRunConfig,
	datasetRunConfigAgentRelations: () => datasetRunConfigAgentRelations,
	datasetRunConfigEvaluatorRelations: () => datasetRunConfigEvaluatorRelations,
	evaluationJobConfig: () => evaluationJobConfig,
	evaluationJobConfigEvaluatorRelations: () => evaluationJobConfigEvaluatorRelations,
	evaluationRunConfig: () => evaluationRunConfig,
	evaluationRunConfigEvaluationSuiteConfigRelations: () => evaluationRunConfigEvaluationSuiteConfigRelations,
	evaluationSuiteConfig: () => evaluationSuiteConfig,
	evaluationSuiteConfigEvaluatorRelations: () => evaluationSuiteConfigEvaluatorRelations,
	evaluator: () => evaluator,
	externalAgents: () => externalAgents,
	externalAgentsRelations: () => externalAgentsRelations,
	functionTools: () => functionTools,
	functionToolsRelations: () => functionToolsRelations,
	functions: () => functions,
	functionsRelations: () => functionsRelations,
	projects: () => projects,
	projectsRelations: () => projectsRelations,
	skillFiles: () => skillFiles,
	skillFilesRelations: () => skillFilesRelations,
	skills: () => skills,
	skillsRelations: () => skillsRelations,
	subAgentArtifactComponents: () => subAgentArtifactComponents,
	subAgentArtifactComponentsRelations: () => subAgentArtifactComponentsRelations,
	subAgentDataComponents: () => subAgentDataComponents,
	subAgentDataComponentsRelations: () => subAgentDataComponentsRelations,
	subAgentExternalAgentRelations: () => subAgentExternalAgentRelations,
	subAgentExternalAgentRelationsRelations: () => subAgentExternalAgentRelationsRelations,
	subAgentFunctionToolRelations: () => subAgentFunctionToolRelations,
	subAgentFunctionToolRelationsRelations: () => subAgentFunctionToolRelationsRelations,
	subAgentRelations: () => subAgentRelations,
	subAgentRelationsRelations: () => subAgentRelationsRelations,
	subAgentSkills: () => subAgentSkills,
	subAgentSkillsRelations: () => subAgentSkillsRelations,
	subAgentTeamAgentRelations: () => subAgentTeamAgentRelations,
	subAgentTeamAgentRelationsRelations: () => subAgentTeamAgentRelationsRelations,
	subAgentToolRelations: () => subAgentToolRelations,
	subAgents: () => subAgents,
	subAgentsRelations: () => subAgentsRelations,
	tools: () => tools,
	toolsRelations: () => toolsRelations,
	triggerUsers: () => triggerUsers,
	triggers: () => triggers,
	webhookDestinationAgents: () => webhookDestinationAgents,
	webhookDestinationAgentsRelations: () => webhookDestinationAgentsRelations,
	webhookDestinationEvaluators: () => webhookDestinationEvaluators,
	webhookDestinationEvaluatorsRelations: () => webhookDestinationEvaluatorsRelations,
	webhookDestinations: () => webhookDestinations,
	webhookDestinationsRelations: () => webhookDestinationsRelations
});
const tenantScoped = {
	tenantId: varchar("tenant_id", { length: 256 }).notNull(),
	id: varchar("id", { length: 256 }).notNull()
};
const projectScoped = {
	...tenantScoped,
	projectId: varchar("project_id", { length: 256 }).notNull()
};
const agentScoped = {
	...projectScoped,
	agentId: varchar("agent_id", { length: 256 }).notNull()
};
const subAgentScoped = {
	...agentScoped,
	subAgentId: varchar("sub_agent_id", { length: 256 }).notNull()
};
const uiProperties = {
	name: varchar("name", { length: 256 }).notNull(),
	description: text("description")
};
const timestamps = {
	createdAt: timestamp("created_at", { mode: "string" }).notNull().defaultNow(),
	updatedAt: timestamp("updated_at", { mode: "string" }).notNull().defaultNow()
};
const projects = pgTable("projects", {
	...tenantScoped,
	...uiProperties,
	models: jsonb("models").$type(),
	stopWhen: jsonb("stop_when").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [table.tenantId, table.id] })]);
const agents = pgTable("agent", {
	...projectScoped,
	...uiProperties,
	defaultSubAgentId: varchar("default_sub_agent_id", { length: 256 }),
	contextConfigId: varchar("context_config_id", { length: 256 }),
	models: jsonb("models").$type(),
	statusUpdates: jsonb("status_updates").$type(),
	prompt: text("prompt"),
	stopWhen: jsonb("stop_when").$type(),
	executionMode: varchar("execution_mode", { length: 50 }).$type().notNull().default("classic"),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "agent_project_fk"
}).onDelete("cascade")]);
const contextConfigs = pgTable("context_configs", {
	...agentScoped,
	headersSchema: jsonb("headers_schema").$type(),
	contextVariables: jsonb("context_variables").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.agentId,
	table.id
] }), foreignKey({
	columns: [
		table.tenantId,
		table.projectId,
		table.agentId
	],
	foreignColumns: [
		agents.tenantId,
		agents.projectId,
		agents.id
	],
	name: "context_configs_agent_fk"
}).onDelete("cascade")]);
const triggers = pgTable("triggers", {
	...agentScoped,
	...uiProperties,
	enabled: boolean("enabled").notNull().default(true),
	inputSchema: jsonb("input_schema").$type(),
	outputTransform: jsonb("output_transform").$type(),
	messageTemplate: text("message_template"),
	authentication: jsonb("authentication").$type(),
	signingSecretCredentialReferenceId: varchar("signing_secret_credential_reference_id", { length: 256 }),
	signatureVerification: jsonb("signature_verification").$type().default(null),
	runAsUserId: varchar("run_as_user_id", { length: 256 }),
	dispatchDelayMs: integer("dispatch_delay_ms"),
	createdBy: varchar("created_by", { length: 256 }),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.agentId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId
		],
		foreignColumns: [
			agents.tenantId,
			agents.projectId,
			agents.id
		],
		name: "triggers_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [table.signingSecretCredentialReferenceId],
		foreignColumns: [credentialReferences.id],
		name: "triggers_credential_reference_fk"
	}).onDelete("set null")
]);
const webhookDestinations = pgTable("webhook_destinations", {
	...projectScoped,
	...uiProperties,
	enabled: boolean("enabled").notNull().default(true),
	url: text("url"),
	slackChannelId: varchar("slack_channel_id", { length: 256 }),
	eventTypes: jsonb("event_types").$type().notNull(),
	headers: jsonb("headers").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "webhook_destinations_project_fk"
}).onDelete("cascade")]);
const webhookDestinationAgents = pgTable("webhook_destination_agents", {
	...projectScoped,
	webhookDestinationId: varchar("webhook_destination_id", { length: 256 }).notNull(),
	agentId: varchar("agent_id", { length: 256 }).notNull(),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.webhookDestinationId
		],
		foreignColumns: [
			webhookDestinations.tenantId,
			webhookDestinations.projectId,
			webhookDestinations.id
		],
		name: "webhook_destination_agents_destination_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId
		],
		foreignColumns: [
			agents.tenantId,
			agents.projectId,
			agents.id
		],
		name: "webhook_destination_agents_agent_fk"
	}).onDelete("cascade")
]);
const webhookDestinationsRelations = relations(webhookDestinations, ({ one, many }) => ({
	project: one(projects, {
		fields: [webhookDestinations.tenantId, webhookDestinations.projectId],
		references: [projects.tenantId, projects.id]
	}),
	webhookDestinationAgents: many(webhookDestinationAgents),
	webhookDestinationEvaluators: many(webhookDestinationEvaluators)
}));
const webhookDestinationAgentsRelations = relations(webhookDestinationAgents, ({ one }) => ({
	webhookDestination: one(webhookDestinations, {
		fields: [
			webhookDestinationAgents.tenantId,
			webhookDestinationAgents.projectId,
			webhookDestinationAgents.webhookDestinationId
		],
		references: [
			webhookDestinations.tenantId,
			webhookDestinations.projectId,
			webhookDestinations.id
		]
	}),
	agent: one(agents, {
		fields: [
			webhookDestinationAgents.tenantId,
			webhookDestinationAgents.projectId,
			webhookDestinationAgents.agentId
		],
		references: [
			agents.tenantId,
			agents.projectId,
			agents.id
		]
	})
}));
const webhookDestinationEvaluators = pgTable("webhook_destination_evaluators", {
	...projectScoped,
	webhookDestinationId: varchar("webhook_destination_id", { length: 256 }).notNull(),
	evaluatorId: varchar("evaluator_id", { length: 256 }).notNull(),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.webhookDestinationId
		],
		foreignColumns: [
			webhookDestinations.tenantId,
			webhookDestinations.projectId,
			webhookDestinations.id
		],
		name: "webhook_destination_evaluators_destination_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.evaluatorId
		],
		foreignColumns: [
			evaluator.tenantId,
			evaluator.projectId,
			evaluator.id
		],
		name: "webhook_destination_evaluators_evaluator_fk"
	}).onDelete("cascade")
]);
const webhookDestinationEvaluatorsRelations = relations(webhookDestinationEvaluators, ({ one }) => ({
	webhookDestination: one(webhookDestinations, {
		fields: [
			webhookDestinationEvaluators.tenantId,
			webhookDestinationEvaluators.projectId,
			webhookDestinationEvaluators.webhookDestinationId
		],
		references: [
			webhookDestinations.tenantId,
			webhookDestinations.projectId,
			webhookDestinations.id
		]
	}),
	evaluator: one(evaluator, {
		fields: [
			webhookDestinationEvaluators.tenantId,
			webhookDestinationEvaluators.projectId,
			webhookDestinationEvaluators.evaluatorId
		],
		references: [
			evaluator.tenantId,
			evaluator.projectId,
			evaluator.id
		]
	})
}));
const triggerUsers = pgTable("trigger_users", {
	tenantId: varchar("tenant_id", { length: 256 }).notNull(),
	projectId: varchar("project_id", { length: 256 }).notNull(),
	agentId: varchar("agent_id", { length: 256 }).notNull(),
	triggerId: varchar("trigger_id", { length: 256 }).notNull(),
	userId: varchar("user_id", { length: 256 }).notNull(),
	createdAt: timestamp("created_at", {
		withTimezone: true,
		mode: "string"
	}).notNull().defaultNow()
}, (table) => [
	primaryKey({
		name: "trigger_users_pk",
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.triggerId,
			table.userId
		]
	}),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.triggerId
		],
		foreignColumns: [
			triggers.tenantId,
			triggers.projectId,
			triggers.agentId,
			triggers.id
		],
		name: "trigger_users_trigger_fk"
	}).onDelete("cascade"),
	index("trigger_users_user_idx").on(table.userId),
	index("trigger_users_trigger_idx").on(table.tenantId, table.projectId, table.agentId, table.triggerId)
]);
const subAgents = pgTable("sub_agents", {
	...agentScoped,
	...uiProperties,
	prompt: text("prompt"),
	conversationHistoryConfig: jsonb("conversation_history_config").$type().default({
		mode: "full",
		limit: 50,
		maxOutputTokens: 4e3,
		includeInternal: false,
		messageTypes: ["chat", "tool-result"]
	}),
	models: jsonb("models").$type(),
	stopWhen: jsonb("stop_when").$type(),
	outputContract: jsonb("output_contract").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.agentId,
	table.id
] }), foreignKey({
	columns: [
		table.tenantId,
		table.projectId,
		table.agentId
	],
	foreignColumns: [
		agents.tenantId,
		agents.projectId,
		agents.id
	],
	name: "sub_agents_agents_fk"
}).onDelete("cascade")]);
const skills = pgTable("skills", {
	...projectScoped,
	id: varchar("id", { length: 64 }).notNull(),
	name: varchar("name", { length: 64 }).notNull(),
	description: text("description").notNull(),
	content: text("content").notNull(),
	metadata: jsonb("metadata").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "skills_project_fk"
}).onDelete("cascade")]);
const skillFiles = pgTable("skill_files", {
	...projectScoped,
	skillId: varchar("skill_id", { length: 64 }).notNull(),
	filePath: varchar("file_path", { length: 1024 }).notNull(),
	content: text("content").notNull(),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.skillId
		],
		foreignColumns: [
			skills.tenantId,
			skills.projectId,
			skills.id
		],
		name: "skill_files_skill_fk"
	}).onDelete("cascade"),
	unique("skill_files_skill_path_unique").on(table.tenantId, table.projectId, table.skillId, table.filePath),
	index("skill_files_skill_idx").on(table.skillId)
]);
const subAgentSkills = pgTable("sub_agent_skills", {
	...subAgentScoped,
	skillId: varchar("skill_id", { length: 64 }).notNull(),
	index: numeric({ mode: "number" }).notNull().default(0),
	alwaysLoaded: boolean("always_loaded").notNull().default(false),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.agentId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.subAgentId
		],
		foreignColumns: [
			subAgents.tenantId,
			subAgents.projectId,
			subAgents.agentId,
			subAgents.id
		],
		name: "sub_agent_skills_sub_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.skillId
		],
		foreignColumns: [
			skills.tenantId,
			skills.projectId,
			skills.id
		],
		name: "sub_agent_skills_skill_fk"
	}).onDelete("cascade"),
	unique("sub_agent_skills_sub_agent_skill_unique").on(table.tenantId, table.projectId, table.agentId, table.subAgentId, table.skillId),
	index("sub_agent_skills_skill_idx").on(table.skillId)
]);
const subAgentRelations = pgTable("sub_agent_relations", {
	...agentScoped,
	sourceSubAgentId: varchar("source_sub_agent_id", { length: 256 }).notNull(),
	targetSubAgentId: varchar("target_sub_agent_id", { length: 256 }),
	relationType: varchar("relation_type", { length: 256 }),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.agentId,
	table.id
] }), foreignKey({
	columns: [
		table.tenantId,
		table.projectId,
		table.agentId
	],
	foreignColumns: [
		agents.tenantId,
		agents.projectId,
		agents.id
	],
	name: "sub_agent_relations_agent_fk"
}).onDelete("cascade")]);
const externalAgents = pgTable("external_agents", {
	...projectScoped,
	...uiProperties,
	baseUrl: text("base_url").notNull(),
	credentialReferenceId: varchar("credential_reference_id", { length: 256 }),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.id
	] }),
	foreignKey({
		columns: [table.tenantId, table.projectId],
		foreignColumns: [projects.tenantId, projects.id],
		name: "external_agents_project_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [table.credentialReferenceId],
		foreignColumns: [credentialReferences.id],
		name: "external_agents_credential_reference_fk"
	}).onDelete("set null")
]);
const dataComponents = pgTable("data_components", {
	...projectScoped,
	...uiProperties,
	props: jsonb("props").$type().notNull(),
	render: jsonb("render").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "data_components_project_fk"
}).onDelete("cascade")]);
const subAgentDataComponents = pgTable("sub_agent_data_components", {
	...subAgentScoped,
	dataComponentId: varchar("data_component_id", { length: 256 }).notNull(),
	createdAt: timestamp("created_at", { mode: "string" }).notNull().defaultNow()
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.subAgentId
		],
		foreignColumns: [
			subAgents.tenantId,
			subAgents.projectId,
			subAgents.agentId,
			subAgents.id
		],
		name: "sub_agent_data_components_sub_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.dataComponentId
		],
		foreignColumns: [
			dataComponents.tenantId,
			dataComponents.projectId,
			dataComponents.id
		],
		name: "sub_agent_data_components_data_component_fk"
	}).onDelete("cascade")
]);
const artifactComponents = pgTable("artifact_components", {
	...projectScoped,
	...uiProperties,
	props: jsonb("props").$type(),
	render: jsonb("render").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "artifact_components_project_fk"
}).onDelete("cascade")]);
const subAgentArtifactComponents = pgTable("sub_agent_artifact_components", {
	...subAgentScoped,
	artifactComponentId: varchar("artifact_component_id", { length: 256 }).notNull(),
	createdAt: timestamp("created_at", { mode: "string" }).notNull().defaultNow()
}, (table) => [
	primaryKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.subAgentId,
			table.id
		],
		name: "sub_agent_artifact_components_pk"
	}),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.subAgentId
		],
		foreignColumns: [
			subAgents.tenantId,
			subAgents.projectId,
			subAgents.agentId,
			subAgents.id
		],
		name: "sub_agent_artifact_components_sub_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.artifactComponentId
		],
		foreignColumns: [
			artifactComponents.tenantId,
			artifactComponents.projectId,
			artifactComponents.id
		],
		name: "sub_agent_artifact_components_artifact_component_fk"
	}).onDelete("cascade")
]);
const tools = pgTable("tools", {
	...projectScoped,
	...uiProperties,
	config: jsonb("config").$type().notNull(),
	credentialReferenceId: varchar("credential_reference_id", { length: 256 }),
	credentialScope: varchar("credential_scope", { length: 50 }).notNull().default("project"),
	headers: jsonb("headers").$type(),
	imageUrl: text("image_url"),
	capabilities: jsonb("capabilities").$type(),
	lastError: text("last_error"),
	isWorkApp: boolean("is_work_app").notNull().default(false),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.id
	] }),
	foreignKey({
		columns: [table.tenantId, table.projectId],
		foreignColumns: [projects.tenantId, projects.id],
		name: "tools_project_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [table.credentialReferenceId],
		foreignColumns: [credentialReferences.id],
		name: "tools_credential_reference_fk"
	}).onDelete("set null")
]);
const functionTools = pgTable("function_tools", {
	...agentScoped,
	...uiProperties,
	functionId: varchar("function_id", { length: 256 }).notNull(),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.agentId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId
		],
		foreignColumns: [
			agents.tenantId,
			agents.projectId,
			agents.id
		],
		name: "function_tools_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.functionId
		],
		foreignColumns: [
			functions.tenantId,
			functions.projectId,
			functions.id
		],
		name: "function_tools_function_fk"
	}).onDelete("cascade")
]);
const functions = pgTable("functions", {
	...projectScoped,
	inputSchema: jsonb("input_schema").$type(),
	executeCode: text("execute_code").notNull(),
	dependencies: jsonb("dependencies").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "functions_project_fk"
}).onDelete("cascade")]);
const subAgentToolRelations = pgTable("sub_agent_tool_relations", {
	...subAgentScoped,
	toolId: varchar("tool_id", { length: 256 }).notNull(),
	selectedTools: jsonb("selected_tools").$type(),
	headers: jsonb("headers").$type(),
	toolPolicies: jsonb("tool_policies").$type(),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.agentId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.subAgentId
		],
		foreignColumns: [
			subAgents.tenantId,
			subAgents.projectId,
			subAgents.agentId,
			subAgents.id
		],
		name: "sub_agent_tool_relations_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.toolId
		],
		foreignColumns: [
			tools.tenantId,
			tools.projectId,
			tools.id
		],
		name: "sub_agent_tool_relations_tool_fk"
	}).onDelete("cascade")
]);
const subAgentExternalAgentRelations = pgTable("sub_agent_external_agent_relations", {
	...subAgentScoped,
	externalAgentId: varchar("external_agent_id", { length: 256 }).notNull(),
	headers: jsonb("headers").$type(),
	...timestamps
}, (table) => [
	primaryKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.id
		],
		name: "sub_agent_external_agent_relations_pk"
	}),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.subAgentId
		],
		foreignColumns: [
			subAgents.tenantId,
			subAgents.projectId,
			subAgents.agentId,
			subAgents.id
		],
		name: "sub_agent_external_agent_relations_sub_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.externalAgentId
		],
		foreignColumns: [
			externalAgents.tenantId,
			externalAgents.projectId,
			externalAgents.id
		],
		name: "sub_agent_external_agent_relations_external_agent_fk"
	}).onDelete("cascade")
]);
const subAgentTeamAgentRelations = pgTable("sub_agent_team_agent_relations", {
	...subAgentScoped,
	targetAgentId: varchar("target_agent_id", { length: 256 }).notNull(),
	headers: jsonb("headers").$type(),
	...timestamps
}, (table) => [
	primaryKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.id
		],
		name: "sub_agent_team_agent_relations_pk"
	}),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.subAgentId
		],
		foreignColumns: [
			subAgents.tenantId,
			subAgents.projectId,
			subAgents.agentId,
			subAgents.id
		],
		name: "sub_agent_team_agent_relations_sub_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.targetAgentId
		],
		foreignColumns: [
			agents.tenantId,
			agents.projectId,
			agents.id
		],
		name: "sub_agent_team_agent_relations_target_agent_fk"
	}).onDelete("cascade")
]);
const subAgentFunctionToolRelations = pgTable("sub_agent_function_tool_relations", {
	...subAgentScoped,
	functionToolId: varchar("function_tool_id", { length: 256 }).notNull(),
	toolPolicies: jsonb("tool_policies").$type(),
	...timestamps
}, (table) => [
	primaryKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.id
		],
		name: "sub_agent_function_tool_relations_pk"
	}),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.subAgentId
		],
		foreignColumns: [
			subAgents.tenantId,
			subAgents.projectId,
			subAgents.agentId,
			subAgents.id
		],
		name: "sub_agent_function_tool_relations_sub_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId,
			table.functionToolId
		],
		foreignColumns: [
			functionTools.tenantId,
			functionTools.projectId,
			functionTools.agentId,
			functionTools.id
		],
		name: "sub_agent_function_tool_relations_function_tool_fk"
	}).onDelete("cascade")
]);
const credentialReferences = pgTable("credential_references", {
	...projectScoped,
	name: uiProperties.name,
	type: varchar("type", { length: 256 }).notNull(),
	credentialStoreId: varchar("credential_store_id", { length: 256 }).notNull(),
	retrievalParams: jsonb("retrieval_params").$type(),
	toolId: varchar("tool_id", { length: 256 }),
	userId: varchar("user_id", { length: 256 }),
	createdBy: varchar("created_by", { length: 256 }),
	...timestamps
}, (t) => [
	primaryKey({ columns: [
		t.tenantId,
		t.projectId,
		t.id
	] }),
	foreignKey({
		columns: [t.tenantId, t.projectId],
		foreignColumns: [projects.tenantId, projects.id],
		name: "credential_references_project_fk"
	}).onDelete("cascade"),
	unique("credential_references_id_unique").on(t.id),
	unique("credential_references_tool_user_unique").on(t.toolId, t.userId)
]);
/**
* A collection of test cases/items used for evaluation. Contains dataset items
* that define input/output pairs for testing agents. Used for batch evaluation
* runs where conversations are created from dataset items. Each datasetRun
* specifies which agent to use when executing the dataset.
*
* one-to-many relationship with datasetItem
*
* Includes: name and timestamps
*/
const dataset = pgTable("dataset", {
	...projectScoped,
	name: uiProperties.name,
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "dataset_project_fk"
}).onDelete("cascade")]);
/**
* Individual test case within a dataset. Contains the input messages to send
* to an agent and optionally expected output.
* When a dataset run executes, it creates conversations from these items.
*
* Includes: input (messages array with optional headers), expected output (array of messages),
* and timestamps.
*/
const datasetItem = pgTable("dataset_item", {
	...projectScoped,
	datasetId: varchar("dataset_id", { length: 256 }).notNull(),
	input: jsonb("input").$type().notNull(),
	expectedOutput: jsonb("expected_output").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [
		table.tenantId,
		table.projectId,
		table.datasetId
	],
	foreignColumns: [
		dataset.tenantId,
		dataset.projectId,
		dataset.id
	],
	name: "dataset_item_dataset_fk"
}).onDelete("cascade")]);
const evaluator = pgTable("evaluator", {
	...projectScoped,
	...uiProperties,
	prompt: text("prompt").notNull(),
	schema: jsonb("schema").$type().notNull(),
	model: jsonb("model").$type().notNull(),
	passCriteria: jsonb("pass_criteria").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "evaluator_project_fk"
}).onDelete("cascade")]);
const datasetRunConfig = pgTable("dataset_run_config", {
	...projectScoped,
	...uiProperties,
	datasetId: varchar("dataset_id", { length: 256 }).notNull(),
	dispatchDelayMs: integer("dispatch_delay_ms"),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.id
	] }),
	foreignKey({
		columns: [table.tenantId, table.projectId],
		foreignColumns: [projects.tenantId, projects.id],
		name: "dataset_run_config_project_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.datasetId
		],
		foreignColumns: [
			dataset.tenantId,
			dataset.projectId,
			dataset.id
		],
		name: "dataset_run_config_dataset_fk"
	}).onDelete("cascade")
]);
/**
* Configuration that defines what to evaluate. Contains filters and evaluators.
* Example: "Evaluate conversations for agentId X with filters Y"
*
* Linked to one or more evaluationRunConfigs (via join table) that define when to run.
* When triggered, creates an evaluationRun with computed filters based on the criteria.
*
* Configuration-level filters:
* - Filters stored in filters JSONB field
*
* many to many relationship with evaluationRunConfig
*
* Includes: name, description, filters (JSONB for evaluation criteria),
* sampleRate for sampling, and timestamps
*/
const evaluationSuiteConfig = pgTable("evaluation_suite_config", {
	...projectScoped,
	filters: jsonb("filters").$type(),
	sampleRate: doublePrecision("sample_rate"),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "evaluation_suite_config_project_fk"
}).onDelete("cascade")]);
/**
* Links evaluators to evaluation suite configs. Many-to-many relationship that
* attaches evaluators to an evaluation suite configuration. Each evaluator must
* have its own model configuration defined.
*
* Includes: evaluationSuiteConfigId, evaluatorId, and timestamps
*/
const evaluationSuiteConfigEvaluatorRelations = pgTable("evaluation_suite_config_evaluator_relations", {
	...projectScoped,
	evaluationSuiteConfigId: varchar("evaluation_suite_config_id", { length: 256 }).notNull(),
	evaluatorId: varchar("evaluator_id", { length: 256 }).notNull(),
	...timestamps
}, (table) => [
	primaryKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.id
		],
		name: "eval_suite_cfg_evaluator_rel_pk"
	}),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.evaluationSuiteConfigId
		],
		foreignColumns: [
			evaluationSuiteConfig.tenantId,
			evaluationSuiteConfig.projectId,
			evaluationSuiteConfig.id
		],
		name: "eval_suite_cfg_evaluator_rel_suite_cfg_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.evaluatorId
		],
		foreignColumns: [
			evaluator.tenantId,
			evaluator.projectId,
			evaluator.id
		],
		name: "eval_suite_cfg_evaluator_rel_evaluator_fk"
	}).onDelete("cascade")
]);
/**
* Links evaluation run configs to evaluation suite configs. Many-to-many relationship that
* allows one suite config to have multiple run schedules, and one run config to be used
* by multiple suite configs.
*
* Includes: evaluationRunConfigId, evaluationSuiteConfigId, and timestamps
*/
const evaluationRunConfigEvaluationSuiteConfigRelations = pgTable("evaluation_run_config_evaluation_suite_config_relations", {
	...projectScoped,
	evaluationRunConfigId: varchar("evaluation_run_config_id", { length: 256 }).notNull(),
	evaluationSuiteConfigId: varchar("evaluation_suite_config_id", { length: 256 }).notNull(),
	...timestamps
}, (table) => [
	primaryKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.id
		],
		name: "eval_run_cfg_eval_suite_cfg_rel_pk"
	}),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.evaluationRunConfigId
		],
		foreignColumns: [
			evaluationRunConfig.tenantId,
			evaluationRunConfig.projectId,
			evaluationRunConfig.id
		],
		name: "eval_run_cfg_eval_suite_rel_run_cfg_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.evaluationSuiteConfigId
		],
		foreignColumns: [
			evaluationSuiteConfig.tenantId,
			evaluationSuiteConfig.projectId,
			evaluationSuiteConfig.id
		],
		name: "eval_run_cfg_eval_suite_rel_suite_cfg_fk"
	}).onDelete("cascade")
]);
/**
* Configuration for automated evaluation runs. Trigger policies is conversation end.
* Can be linked to multiple evaluation suite configs via join table.
* many to many relationship with evaluationSuiteConfig
*
* Evaluations are automatically triggered when regular conversations complete.
* When a conversation ends, creates an evaluationRun that evaluates that conversation.
*
* NOTE: Evaluation run configs ONLY run on regular conversations, NOT dataset run conversations.
* Dataset runs create their own evaluationJobConfig with specific evaluators at run-time.
*
* one to many relationship with evaluationRun
*/
const evaluationRunConfig = pgTable("evaluation_run_config", {
	...projectScoped,
	...uiProperties,
	isActive: boolean("is_active").notNull().default(true),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "evaluation_run_config_project_fk"
}).onDelete("cascade")]);
/**
* Configuration for a one-off evaluation job to be executed.
* Example: "Evaluate all conversations in datasetRunId 1234"
*
* Created manually or by external systems. Contains job-specific filters like
* datasetRunIds, conversationIds, and absolute dateRange.
*
* one to many relationship with evaluationRun
*
* When a job completes, an evaluationRun is created with evaluationJobConfigId set.
*
* Includes: jobFilters (specific filters for this job execution: datasetRunIds, conversationIds,
* dateRange with absolute dates), and timestamps
*/
const evaluationJobConfig = pgTable("evaluation_job_config", {
	...projectScoped,
	jobFilters: jsonb("job_filters").$type(),
	...timestamps
}, (table) => [primaryKey({ columns: [
	table.tenantId,
	table.projectId,
	table.id
] }), foreignKey({
	columns: [table.tenantId, table.projectId],
	foreignColumns: [projects.tenantId, projects.id],
	name: "evaluation_job_config_project_fk"
}).onDelete("cascade")]);
/**
* Links evaluators to evaluation job configs. Many-to-many relationship that
* attaches evaluators to an evaluation job configuration. Each evaluator must
* have its own model configuration defined.
*
* Includes: evaluationJobConfigId, evaluatorId, and timestamps
*/
const evaluationJobConfigEvaluatorRelations = pgTable("evaluation_job_config_evaluator_relations", {
	...projectScoped,
	evaluationJobConfigId: varchar("evaluation_job_config_id", { length: 256 }).notNull(),
	evaluatorId: varchar("evaluator_id", { length: 256 }).notNull(),
	...timestamps
}, (table) => [
	primaryKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.id
		],
		name: "eval_job_cfg_evaluator_rel_pk"
	}),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.evaluationJobConfigId
		],
		foreignColumns: [
			evaluationJobConfig.tenantId,
			evaluationJobConfig.projectId,
			evaluationJobConfig.id
		],
		name: "eval_job_cfg_evaluator_rel_job_cfg_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.evaluatorId
		],
		foreignColumns: [
			evaluator.tenantId,
			evaluator.projectId,
			evaluator.id
		],
		name: "eval_job_cfg_evaluator_rel_evaluator_fk"
	}).onDelete("cascade")
]);
const projectsRelations = relations(projects, ({ many }) => ({
	subAgents: many(subAgents),
	agents: many(agents),
	tools: many(tools),
	functions: many(functions),
	contextConfigs: many(contextConfigs),
	externalAgents: many(externalAgents),
	dataComponents: many(dataComponents),
	artifactComponents: many(artifactComponents),
	credentialReferences: many(credentialReferences),
	skills: many(skills),
	skillFiles: many(skillFiles)
}));
const contextConfigsRelations = relations(contextConfigs, ({ many, one }) => ({
	project: one(projects, {
		fields: [contextConfigs.tenantId, contextConfigs.projectId],
		references: [projects.tenantId, projects.id]
	}),
	agents: many(agents)
}));
const subAgentsRelations = relations(subAgents, ({ many, one }) => ({
	project: one(projects, {
		fields: [subAgents.tenantId, subAgents.projectId],
		references: [projects.tenantId, projects.id]
	}),
	defaultForAgents: many(agents),
	sourceRelations: many(subAgentRelations, { relationName: "sourceRelations" }),
	targetRelations: many(subAgentRelations, { relationName: "targetRelations" }),
	toolRelations: many(subAgentToolRelations),
	functionToolRelations: many(subAgentFunctionToolRelations),
	dataComponentRelations: many(subAgentDataComponents),
	artifactComponentRelations: many(subAgentArtifactComponents),
	skillRelations: many(subAgentSkills)
}));
const agentRelations = relations(agents, ({ one, many }) => ({
	project: one(projects, {
		fields: [agents.tenantId, agents.projectId],
		references: [projects.tenantId, projects.id]
	}),
	defaultSubAgent: one(subAgents, {
		fields: [agents.defaultSubAgentId],
		references: [subAgents.id]
	}),
	contextConfig: one(contextConfigs, {
		fields: [agents.contextConfigId],
		references: [contextConfigs.id]
	}),
	functionTools: many(functionTools)
}));
const externalAgentsRelations = relations(externalAgents, ({ one, many }) => ({
	project: one(projects, {
		fields: [externalAgents.tenantId, externalAgents.projectId],
		references: [projects.tenantId, projects.id]
	}),
	subAgentExternalAgentRelations: many(subAgentExternalAgentRelations),
	credentialReference: one(credentialReferences, {
		fields: [externalAgents.credentialReferenceId],
		references: [credentialReferences.id]
	})
}));
const agentToolRelationsRelations = relations(subAgentToolRelations, ({ one }) => ({
	subAgent: one(subAgents, {
		fields: [subAgentToolRelations.subAgentId],
		references: [subAgents.id]
	}),
	tool: one(tools, {
		fields: [subAgentToolRelations.toolId],
		references: [tools.id]
	})
}));
const credentialReferencesRelations = relations(credentialReferences, ({ one, many }) => ({
	project: one(projects, {
		fields: [credentialReferences.tenantId, credentialReferences.projectId],
		references: [projects.tenantId, projects.id]
	}),
	tools: many(tools),
	externalAgents: many(externalAgents)
}));
const toolsRelations = relations(tools, ({ one, many }) => ({
	project: one(projects, {
		fields: [tools.tenantId, tools.projectId],
		references: [projects.tenantId, projects.id]
	}),
	subAgentRelations: many(subAgentToolRelations),
	credentialReference: one(credentialReferences, {
		fields: [tools.credentialReferenceId],
		references: [credentialReferences.id]
	})
}));
const artifactComponentsRelations = relations(artifactComponents, ({ many, one }) => ({
	project: one(projects, {
		fields: [artifactComponents.tenantId, artifactComponents.projectId],
		references: [projects.tenantId, projects.id]
	}),
	subAgentRelations: many(subAgentArtifactComponents)
}));
const subAgentArtifactComponentsRelations = relations(subAgentArtifactComponents, ({ one }) => ({
	subAgent: one(subAgents, {
		fields: [subAgentArtifactComponents.subAgentId],
		references: [subAgents.id]
	}),
	artifactComponent: one(artifactComponents, {
		fields: [subAgentArtifactComponents.artifactComponentId],
		references: [artifactComponents.id]
	})
}));
const dataComponentsRelations = relations(dataComponents, ({ many, one }) => ({
	project: one(projects, {
		fields: [dataComponents.tenantId, dataComponents.projectId],
		references: [projects.tenantId, projects.id]
	}),
	subAgentRelations: many(subAgentDataComponents)
}));
const subAgentDataComponentsRelations = relations(subAgentDataComponents, ({ one }) => ({
	subAgent: one(subAgents, {
		fields: [subAgentDataComponents.subAgentId],
		references: [subAgents.id]
	}),
	dataComponent: one(dataComponents, {
		fields: [subAgentDataComponents.dataComponentId],
		references: [dataComponents.id]
	})
}));
const skillsRelations = relations(skills, ({ one, many }) => ({
	project: one(projects, {
		fields: [skills.tenantId, skills.projectId],
		references: [projects.tenantId, projects.id]
	}),
	files: many(skillFiles),
	subAgentRelations: many(subAgentSkills)
}));
const skillFilesRelations = relations(skillFiles, ({ one }) => ({
	project: one(projects, {
		fields: [skillFiles.tenantId, skillFiles.projectId],
		references: [projects.tenantId, projects.id]
	}),
	skill: one(skills, {
		fields: [
			skillFiles.tenantId,
			skillFiles.projectId,
			skillFiles.skillId
		],
		references: [
			skills.tenantId,
			skills.projectId,
			skills.id
		]
	})
}));
const subAgentSkillsRelations = relations(subAgentSkills, ({ one }) => ({
	subAgent: one(subAgents, {
		fields: [
			subAgentSkills.tenantId,
			subAgentSkills.projectId,
			subAgentSkills.agentId,
			subAgentSkills.subAgentId
		],
		references: [
			subAgents.tenantId,
			subAgents.projectId,
			subAgents.agentId,
			subAgents.id
		]
	}),
	skill: one(skills, {
		fields: [
			subAgentSkills.tenantId,
			subAgentSkills.projectId,
			subAgentSkills.skillId
		],
		references: [
			skills.tenantId,
			skills.projectId,
			skills.id
		]
	})
}));
const functionsRelations = relations(functions, ({ many, one }) => ({
	functionTools: many(functionTools),
	project: one(projects, {
		fields: [functions.tenantId, functions.projectId],
		references: [projects.tenantId, projects.id]
	})
}));
const subAgentRelationsRelations = relations(subAgentRelations, ({ one }) => ({
	agent: one(agents, {
		fields: [subAgentRelations.agentId],
		references: [agents.id]
	}),
	sourceSubAgent: one(subAgents, {
		fields: [subAgentRelations.sourceSubAgentId],
		references: [subAgents.id],
		relationName: "sourceRelations"
	}),
	targetSubAgent: one(subAgents, {
		fields: [subAgentRelations.targetSubAgentId],
		references: [subAgents.id],
		relationName: "targetRelations"
	})
}));
const functionToolsRelations = relations(functionTools, ({ one, many }) => ({
	project: one(projects, {
		fields: [functionTools.tenantId, functionTools.projectId],
		references: [projects.tenantId, projects.id]
	}),
	agent: one(agents, {
		fields: [
			functionTools.tenantId,
			functionTools.projectId,
			functionTools.agentId
		],
		references: [
			agents.tenantId,
			agents.projectId,
			agents.id
		]
	}),
	function: one(functions, {
		fields: [
			functionTools.tenantId,
			functionTools.projectId,
			functionTools.functionId
		],
		references: [
			functions.tenantId,
			functions.projectId,
			functions.id
		]
	}),
	subAgentRelations: many(subAgentFunctionToolRelations)
}));
const subAgentFunctionToolRelationsRelations = relations(subAgentFunctionToolRelations, ({ one }) => ({
	subAgent: one(subAgents, {
		fields: [subAgentFunctionToolRelations.subAgentId],
		references: [subAgents.id]
	}),
	functionTool: one(functionTools, {
		fields: [subAgentFunctionToolRelations.functionToolId],
		references: [functionTools.id]
	})
}));
const subAgentExternalAgentRelationsRelations = relations(subAgentExternalAgentRelations, ({ one }) => ({
	subAgent: one(subAgents, {
		fields: [
			subAgentExternalAgentRelations.tenantId,
			subAgentExternalAgentRelations.projectId,
			subAgentExternalAgentRelations.agentId,
			subAgentExternalAgentRelations.subAgentId
		],
		references: [
			subAgents.tenantId,
			subAgents.projectId,
			subAgents.agentId,
			subAgents.id
		]
	}),
	externalAgent: one(externalAgents, {
		fields: [
			subAgentExternalAgentRelations.tenantId,
			subAgentExternalAgentRelations.projectId,
			subAgentExternalAgentRelations.externalAgentId
		],
		references: [
			externalAgents.tenantId,
			externalAgents.projectId,
			externalAgents.id
		]
	})
}));
const subAgentTeamAgentRelationsRelations = relations(subAgentTeamAgentRelations, ({ one }) => ({
	subAgent: one(subAgents, {
		fields: [
			subAgentTeamAgentRelations.tenantId,
			subAgentTeamAgentRelations.projectId,
			subAgentTeamAgentRelations.agentId,
			subAgentTeamAgentRelations.subAgentId
		],
		references: [
			subAgents.tenantId,
			subAgents.projectId,
			subAgents.agentId,
			subAgents.id
		]
	}),
	targetAgent: one(agents, {
		fields: [
			subAgentTeamAgentRelations.tenantId,
			subAgentTeamAgentRelations.projectId,
			subAgentTeamAgentRelations.targetAgentId
		],
		references: [
			agents.tenantId,
			agents.projectId,
			agents.id
		]
	})
}));
/**
* Links agents to datasets. Many-to-many relationship that scopes a dataset
* to specific agents. When a dataset has agent relations, it is only associated
* with those agents. When it has NO agent relations, it is treated as
* project-wide and available to all agents.
*
* Includes: agentId, datasetId, and timestamps
*/
const agentDatasetRelations = pgTable("agent_dataset_relations", {
	...projectScoped,
	agentId: varchar("agent_id", { length: 256 }).notNull(),
	datasetId: varchar("dataset_id", { length: 256 }).notNull(),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId
		],
		foreignColumns: [
			agents.tenantId,
			agents.projectId,
			agents.id
		],
		name: "agent_dataset_relations_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.datasetId
		],
		foreignColumns: [
			dataset.tenantId,
			dataset.projectId,
			dataset.id
		],
		name: "agent_dataset_relations_dataset_fk"
	}).onDelete("cascade"),
	unique("agent_dataset_relations_unique").on(table.tenantId, table.projectId, table.agentId, table.datasetId)
]);
/**
* Links agents to evaluators. Many-to-many relationship that scopes an evaluator
* to specific agents. When an evaluator has agent relations, it is only associated
* with those agents. When it has NO agent relations, it is treated as
* project-wide and available to all agents.
*
* Includes: agentId, evaluatorId, and timestamps
*/
const agentEvaluatorRelations = pgTable("agent_evaluator_relations", {
	...projectScoped,
	agentId: varchar("agent_id", { length: 256 }).notNull(),
	evaluatorId: varchar("evaluator_id", { length: 256 }).notNull(),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId
		],
		foreignColumns: [
			agents.tenantId,
			agents.projectId,
			agents.id
		],
		name: "agent_evaluator_relations_agent_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.evaluatorId
		],
		foreignColumns: [
			evaluator.tenantId,
			evaluator.projectId,
			evaluator.id
		],
		name: "agent_evaluator_relations_evaluator_fk"
	}).onDelete("cascade"),
	unique("agent_evaluator_relations_unique").on(table.tenantId, table.projectId, table.agentId, table.evaluatorId)
]);
/**
* Links agents to dataset run configs. Many-to-many relationship that
* allows one dataset run config to use multiple agents, and one agent to be used
* by multiple dataset run configs.
*
* Includes: datasetRunConfigId, agentId, and timestamps
*/
const datasetRunConfigAgentRelations = pgTable("dataset_run_config_agent_relations", {
	...projectScoped,
	datasetRunConfigId: varchar("dataset_run_config_id", { length: 256 }).notNull(),
	agentId: varchar("agent_id", { length: 256 }).notNull(),
	...timestamps
}, (table) => [
	primaryKey({ columns: [
		table.tenantId,
		table.projectId,
		table.id
	] }),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.datasetRunConfigId
		],
		foreignColumns: [
			datasetRunConfig.tenantId,
			datasetRunConfig.projectId,
			datasetRunConfig.id
		],
		name: "dataset_run_config_agent_relations_dataset_run_config_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.agentId
		],
		foreignColumns: [
			agents.tenantId,
			agents.projectId,
			agents.id
		],
		name: "dataset_run_config_agent_relations_agent_fk"
	}).onDelete("cascade")
]);
/**
* Links evaluators to dataset run configs. Many-to-many relationship that
* allows one dataset run config to use multiple evaluators, and one evaluator
* to be used by multiple dataset run configs.
*
* Includes: datasetRunConfigId, evaluatorId, and timestamps
*/
const datasetRunConfigEvaluatorRelations = pgTable("dataset_run_config_evaluator_relations", {
	...projectScoped,
	datasetRunConfigId: varchar("dataset_run_config_id", { length: 256 }).notNull(),
	evaluatorId: varchar("evaluator_id", { length: 256 }).notNull(),
	...timestamps
}, (table) => [
	primaryKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.id
		],
		name: "drc_evaluator_rel_pk"
	}),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.datasetRunConfigId
		],
		foreignColumns: [
			datasetRunConfig.tenantId,
			datasetRunConfig.projectId,
			datasetRunConfig.id
		],
		name: "drc_evaluator_rel_config_fk"
	}).onDelete("cascade"),
	foreignKey({
		columns: [
			table.tenantId,
			table.projectId,
			table.evaluatorId
		],
		foreignColumns: [
			evaluator.tenantId,
			evaluator.projectId,
			evaluator.id
		],
		name: "drc_evaluator_rel_evaluator_fk"
	}).onDelete("cascade"),
	unique("drc_evaluator_unique").on(table.tenantId, table.projectId, table.datasetRunConfigId, table.evaluatorId)
]);
const agentDatasetRelationsRelations = relations(agentDatasetRelations, ({ one }) => ({
	agent: one(agents, {
		fields: [
			agentDatasetRelations.tenantId,
			agentDatasetRelations.projectId,
			agentDatasetRelations.agentId
		],
		references: [
			agents.tenantId,
			agents.projectId,
			agents.id
		]
	}),
	dataset: one(dataset, {
		fields: [
			agentDatasetRelations.tenantId,
			agentDatasetRelations.projectId,
			agentDatasetRelations.datasetId
		],
		references: [
			dataset.tenantId,
			dataset.projectId,
			dataset.id
		]
	})
}));
const agentEvaluatorRelationsRelations = relations(agentEvaluatorRelations, ({ one }) => ({
	agent: one(agents, {
		fields: [
			agentEvaluatorRelations.tenantId,
			agentEvaluatorRelations.projectId,
			agentEvaluatorRelations.agentId
		],
		references: [
			agents.tenantId,
			agents.projectId,
			agents.id
		]
	}),
	evaluator: one(evaluator, {
		fields: [
			agentEvaluatorRelations.tenantId,
			agentEvaluatorRelations.projectId,
			agentEvaluatorRelations.evaluatorId
		],
		references: [
			evaluator.tenantId,
			evaluator.projectId,
			evaluator.id
		]
	})
}));

//#endregion
export { agentDatasetRelations, agentDatasetRelationsRelations, agentEvaluatorRelations, agentEvaluatorRelationsRelations, agentRelations, agentToolRelationsRelations, agents, artifactComponents, artifactComponentsRelations, contextConfigs, contextConfigsRelations, credentialReferences, credentialReferencesRelations, dataComponents, dataComponentsRelations, dataset, datasetItem, datasetRunConfig, datasetRunConfigAgentRelations, datasetRunConfigEvaluatorRelations, evaluationJobConfig, evaluationJobConfigEvaluatorRelations, evaluationRunConfig, evaluationRunConfigEvaluationSuiteConfigRelations, evaluationSuiteConfig, evaluationSuiteConfigEvaluatorRelations, evaluator, externalAgents, externalAgentsRelations, functionTools, functionToolsRelations, functions, functionsRelations, manage_schema_exports, projects, projectsRelations, skillFiles, skillFilesRelations, skills, skillsRelations, subAgentArtifactComponents, subAgentArtifactComponentsRelations, subAgentDataComponents, subAgentDataComponentsRelations, subAgentExternalAgentRelations, subAgentExternalAgentRelationsRelations, subAgentFunctionToolRelations, subAgentFunctionToolRelationsRelations, subAgentRelations, subAgentRelationsRelations, subAgentSkills, subAgentSkillsRelations, subAgentTeamAgentRelations, subAgentTeamAgentRelationsRelations, subAgentToolRelations, subAgents, subAgentsRelations, tools, toolsRelations, triggerUsers, triggers, webhookDestinationAgents, webhookDestinationAgentsRelations, webhookDestinationEvaluators, webhookDestinationEvaluatorsRelations, webhookDestinations, webhookDestinationsRelations };