import { t as schemaValidationDefaults } from "./defaults.js";
import { E as messages, F as subAgentExternalAgentRelations, J as tasks, K as taskRelations, N as subAgentDataComponents, O as projects, S as functions, U as subAgentToolRelations, V as subAgentTeamAgentRelations, W as subAgents, X as tools, b as functionTools, c as contextCache, f as conversations, g as dataComponents, i as apiKeys, j as subAgentArtifactComponents, m as credentialReferences, o as artifactComponents, r as agents, u as contextConfigs, v as externalAgents, w as ledgerArtifacts, z as subAgentRelations } from "./schema.js";
import { a as VALID_RELATION_TYPES, i as TOOL_STATUS_VALUES, n as MCPServerType, r as MCPTransportType, t as CredentialStoreType } from "./utility.js";
import { z } from "@hono/zod-openapi";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import Ajv from "ajv";

//#region src/validation/drizzle-schema-helpers.ts
const MIN_ID_LENGTH = 1;
const MAX_ID_LENGTH = 255;
const URL_SAFE_ID_PATTERN = /^[a-zA-Z0-9\-_.]+$/;
const resourceIdSchema = z.string().min(MIN_ID_LENGTH).max(MAX_ID_LENGTH).describe("Resource identifier").regex(URL_SAFE_ID_PATTERN, { message: "ID must contain only letters, numbers, hyphens, underscores, and dots" }).openapi({
	description: "Resource identifier",
	example: "resource_789"
});
resourceIdSchema.meta({ description: "Resource identifier" });
const FIELD_MODIFIERS = {
	id: (schema) => {
		const modified = schema.min(MIN_ID_LENGTH).max(MAX_ID_LENGTH).describe("Resource identifier").regex(URL_SAFE_ID_PATTERN, { message: "ID must contain only letters, numbers, hyphens, underscores, and dots" }).openapi({
			description: "Resource identifier",
			example: "resource_789"
		});
		modified.meta({ description: "Resource identifier" });
		return modified;
	},
	name: (_schema) => {
		const modified = z.string().describe("Name");
		modified.meta({ description: "Name" });
		return modified;
	},
	description: (_schema) => {
		const modified = z.string().describe("Description");
		modified.meta({ description: "Description" });
		return modified;
	},
	tenantId: (schema) => {
		const modified = schema.describe("Tenant identifier");
		modified.meta({ description: "Tenant identifier" });
		return modified;
	},
	projectId: (schema) => {
		const modified = schema.describe("Project identifier");
		modified.meta({ description: "Project identifier" });
		return modified;
	},
	agentId: (schema) => {
		const modified = schema.describe("Agent identifier");
		modified.meta({ description: "Agent identifier" });
		return modified;
	},
	subAgentId: (schema) => {
		const modified = schema.describe("Sub-agent identifier");
		modified.meta({ description: "Sub-agent identifier" });
		return modified;
	},
	createdAt: (schema) => {
		const modified = schema.describe("Creation timestamp");
		modified.meta({ description: "Creation timestamp" });
		return modified;
	},
	updatedAt: (schema) => {
		const modified = schema.describe("Last update timestamp");
		modified.meta({ description: "Last update timestamp" });
		return modified;
	}
};
function createSelectSchemaWithModifiers(table, overrides) {
	const tableColumns = table._?.columns;
	if (!tableColumns) return createSelectSchema(table, overrides);
	const tableFieldNames = Object.keys(tableColumns);
	const modifiers = {};
	for (const fieldName of tableFieldNames) {
		const fieldNameStr = String(fieldName);
		if (fieldNameStr in FIELD_MODIFIERS) modifiers[fieldNameStr] = FIELD_MODIFIERS[fieldNameStr];
	}
	return createSelectSchema(table, {
		...modifiers,
		...overrides
	});
}
function createInsertSchemaWithModifiers(table, overrides) {
	const tableColumns = table._?.columns;
	if (!tableColumns) return createInsertSchema(table, overrides);
	const tableFieldNames = Object.keys(tableColumns);
	const modifiers = {};
	for (const fieldName of tableFieldNames) {
		const fieldNameStr = String(fieldName);
		if (fieldNameStr in FIELD_MODIFIERS) modifiers[fieldNameStr] = FIELD_MODIFIERS[fieldNameStr];
	}
	return createInsertSchema(table, {
		...modifiers,
		...overrides
	});
}
const createSelectSchema$1 = createSelectSchemaWithModifiers;
const createInsertSchema$1 = createInsertSchemaWithModifiers;
/**
* Registers all field schemas in an object schema that match known field names.
* This ensures metadata persists through transformations like .partial() and .omit().
* For the 'id' field, also applies full validation constraints via .openapi().
*
* This function registers each field schema instance in the global registry using .meta(),
* and ensures OpenAPI metadata is set via .openapi() for proper documentation generation.
*
* Note: This modifies the schemas in place by registering them in the global registry.
* The schema shape itself is not modified, but the field schemas are registered.
*/
function registerFieldSchemas(schema) {
	if (!(schema instanceof z.ZodObject)) return schema;
	const shape = schema.shape;
	const fieldMetadata = {
		id: { description: "Resource identifier" },
		name: { description: "Name" },
		description: { description: "Description" },
		tenantId: { description: "Tenant identifier" },
		projectId: { description: "Project identifier" },
		agentId: { description: "Agent identifier" },
		subAgentId: { description: "Sub-agent identifier" },
		createdAt: { description: "Creation timestamp" },
		updatedAt: { description: "Last update timestamp" }
	};
	for (const [fieldName, fieldSchema] of Object.entries(shape)) if (fieldName in fieldMetadata && fieldSchema) {
		let zodFieldSchema = fieldSchema;
		let innerSchema = null;
		if (zodFieldSchema instanceof z.ZodOptional) {
			innerSchema = zodFieldSchema._def.innerType;
			zodFieldSchema = innerSchema;
		}
		zodFieldSchema.meta(fieldMetadata[fieldName]);
		if (fieldName === "id" && zodFieldSchema instanceof z.ZodString) zodFieldSchema.openapi({
			description: "Resource identifier",
			minLength: MIN_ID_LENGTH,
			maxLength: MAX_ID_LENGTH,
			pattern: URL_SAFE_ID_PATTERN.source,
			example: "resource_789"
		});
		else if (zodFieldSchema instanceof z.ZodString) zodFieldSchema.openapi({ description: fieldMetadata[fieldName].description });
		if (innerSchema && fieldSchema instanceof z.ZodOptional) fieldSchema.meta(fieldMetadata[fieldName]);
	}
	return schema;
}

//#endregion
//#region src/validation/schemas.ts
const { AGENT_EXECUTION_TRANSFER_COUNT_MAX, AGENT_EXECUTION_TRANSFER_COUNT_MIN, CONTEXT_FETCHER_HTTP_TIMEOUT_MS_DEFAULT, STATUS_UPDATE_MAX_INTERVAL_SECONDS, STATUS_UPDATE_MAX_NUM_EVENTS, SUB_AGENT_TURN_GENERATION_STEPS_MAX, SUB_AGENT_TURN_GENERATION_STEPS_MIN, VALIDATION_AGENT_PROMPT_MAX_CHARS, VALIDATION_SUB_AGENT_PROMPT_MAX_CHARS } = schemaValidationDefaults;
const StopWhenSchema = z.object({
	transferCountIs: z.number().min(AGENT_EXECUTION_TRANSFER_COUNT_MIN).max(AGENT_EXECUTION_TRANSFER_COUNT_MAX).optional().describe("The maximum number of transfers to trigger the stop condition."),
	stepCountIs: z.number().min(SUB_AGENT_TURN_GENERATION_STEPS_MIN).max(SUB_AGENT_TURN_GENERATION_STEPS_MAX).optional().describe("The maximum number of steps to trigger the stop condition.")
}).openapi("StopWhen");
const AgentStopWhenSchema = StopWhenSchema.pick({ transferCountIs: true }).openapi("AgentStopWhen");
const SubAgentStopWhenSchema = StopWhenSchema.pick({ stepCountIs: true }).openapi("SubAgentStopWhen");
const pageNumber = z.coerce.number().min(1).default(1).openapi("PaginationPageQueryParam");
const limitNumber = z.coerce.number().min(1).max(100).default(10).openapi("PaginationLimitQueryParam");
const ModelSettingsSchema = z.object({
	model: z.string().optional().describe("The model to use for the project."),
	providerOptions: z.record(z.string(), z.any()).optional().describe("The provider options to use for the project.")
}).openapi("ModelSettings");
const ModelSchema = z.object({
	base: ModelSettingsSchema.optional(),
	structuredOutput: ModelSettingsSchema.optional(),
	summarizer: ModelSettingsSchema.optional()
}).openapi("Model");
const ProjectModelSchema = z.object({
	base: ModelSettingsSchema,
	structuredOutput: ModelSettingsSchema.optional(),
	summarizer: ModelSettingsSchema.optional()
}).openapi("ProjectModel");
const FunctionToolConfigSchema = z.object({
	name: z.string(),
	description: z.string(),
	inputSchema: z.record(z.string(), z.unknown()),
	dependencies: z.record(z.string(), z.string()).optional(),
	execute: z.union([z.function(), z.string()])
});
const createApiSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true
});
const createApiInsertSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true
});
const createApiUpdateSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true
}).partial();
const createAgentScopedApiSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true,
	agentId: true
});
const createAgentScopedApiInsertSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true,
	agentId: true
});
const createAgentScopedApiUpdateSchema = (schema) => schema.omit({
	tenantId: true,
	projectId: true,
	agentId: true
}).partial();
const SubAgentSelectSchema = createSelectSchema$1(subAgents);
const SubAgentInsertSchema = createInsertSchema$1(subAgents).extend({
	id: resourceIdSchema,
	models: ModelSchema.optional()
});
const SubAgentUpdateSchema = SubAgentInsertSchema.partial();
const SubAgentApiSelectSchema = createAgentScopedApiSchema(SubAgentSelectSchema).openapi("SubAgent");
const SubAgentApiInsertSchema = createAgentScopedApiInsertSchema(SubAgentInsertSchema).openapi("SubAgentCreate");
const SubAgentApiUpdateSchema = createAgentScopedApiUpdateSchema(SubAgentUpdateSchema).openapi("SubAgentUpdate");
const SubAgentRelationSelectSchema = createSelectSchema$1(subAgentRelations);
const SubAgentRelationInsertSchema = createInsertSchema$1(subAgentRelations).extend({
	id: resourceIdSchema,
	agentId: resourceIdSchema,
	sourceSubAgentId: resourceIdSchema,
	targetSubAgentId: resourceIdSchema.optional(),
	externalSubAgentId: resourceIdSchema.optional(),
	teamSubAgentId: resourceIdSchema.optional()
});
const SubAgentRelationUpdateSchema = SubAgentRelationInsertSchema.partial();
const SubAgentRelationApiSelectSchema = createAgentScopedApiSchema(SubAgentRelationSelectSchema).openapi("SubAgentRelation");
const SubAgentRelationApiInsertSchema = createAgentScopedApiInsertSchema(SubAgentRelationInsertSchema).extend({ relationType: z.enum(VALID_RELATION_TYPES) }).refine((data) => {
	return [
		data.targetSubAgentId != null,
		data.externalSubAgentId != null,
		data.teamSubAgentId != null
	].filter(Boolean).length === 1;
}, {
	message: "Must specify exactly one of targetSubAgentId, externalSubAgentId, or teamSubAgentId",
	path: [
		"targetSubAgentId",
		"externalSubAgentId",
		"teamSubAgentId"
	]
}).openapi("SubAgentRelationCreate");
const SubAgentRelationApiUpdateSchema = createAgentScopedApiUpdateSchema(SubAgentRelationUpdateSchema).extend({ relationType: z.enum(VALID_RELATION_TYPES).optional() }).refine((data) => {
	const count = [
		data.targetSubAgentId != null,
		data.externalSubAgentId != null,
		data.teamSubAgentId != null
	].filter(Boolean).length;
	if (count === 0) return true;
	return count === 1;
}, {
	message: "Must specify exactly one of targetSubAgentId, externalSubAgentId, or teamSubAgentId when updating sub-agent relationships",
	path: [
		"targetSubAgentId",
		"externalSubAgentId",
		"teamSubAgentId"
	]
}).openapi("SubAgentRelationUpdate");
const SubAgentRelationQuerySchema = z.object({
	sourceSubAgentId: z.string().optional(),
	targetSubAgentId: z.string().optional(),
	externalSubAgentId: z.string().optional(),
	teamSubAgentId: z.string().optional()
});
const ExternalSubAgentRelationInsertSchema = createInsertSchema$1(subAgentRelations).extend({
	id: resourceIdSchema,
	agentId: resourceIdSchema,
	sourceSubAgentId: resourceIdSchema,
	externalSubAgentId: resourceIdSchema
});
const ExternalSubAgentRelationApiInsertSchema = createApiInsertSchema(ExternalSubAgentRelationInsertSchema);
const AgentSelectSchema = createSelectSchema$1(agents);
const AgentInsertSchema = createInsertSchema$1(agents).extend({
	id: resourceIdSchema,
	name: z.string().trim().nonempty()
});
const AgentUpdateSchema = AgentInsertSchema.partial();
const AgentApiSelectSchema = createApiSchema(AgentSelectSchema).openapi("Agent");
const AgentApiInsertSchema = createApiInsertSchema(AgentInsertSchema).extend({ id: resourceIdSchema }).openapi("AgentCreate");
const AgentApiUpdateSchema = createApiUpdateSchema(AgentUpdateSchema).openapi("AgentUpdate");
const TaskSelectSchema = createSelectSchema$1(tasks);
const TaskInsertSchema = createInsertSchema$1(tasks).extend({
	id: resourceIdSchema,
	conversationId: resourceIdSchema.optional()
});
const TaskUpdateSchema = TaskInsertSchema.partial();
const TaskApiSelectSchema = createApiSchema(TaskSelectSchema);
const TaskApiInsertSchema = createApiInsertSchema(TaskInsertSchema);
const TaskApiUpdateSchema = createApiUpdateSchema(TaskUpdateSchema);
const TaskRelationSelectSchema = createSelectSchema$1(taskRelations);
const TaskRelationInsertSchema = createInsertSchema$1(taskRelations).extend({
	id: resourceIdSchema,
	parentTaskId: resourceIdSchema,
	childTaskId: resourceIdSchema
});
const TaskRelationUpdateSchema = TaskRelationInsertSchema.partial();
const TaskRelationApiSelectSchema = createApiSchema(TaskRelationSelectSchema);
const TaskRelationApiInsertSchema = createApiInsertSchema(TaskRelationInsertSchema);
const TaskRelationApiUpdateSchema = createApiUpdateSchema(TaskRelationUpdateSchema);
const imageUrlSchema = z.string().optional().refine((url) => {
	if (!url) return true;
	if (url.startsWith("data:image/")) {
		const base64Part = url.split(",")[1];
		if (!base64Part) return false;
		return base64Part.length < 14e5;
	}
	try {
		const parsed = new URL(url);
		return parsed.protocol === "http:" || parsed.protocol === "https:";
	} catch {
		return false;
	}
}, { message: "Image URL must be a valid HTTP(S) URL or a base64 data URL (max 1MB)" });
const McpTransportConfigSchema = z.object({
	type: z.enum(MCPTransportType),
	requestInit: z.record(z.string(), z.unknown()).optional(),
	eventSourceInit: z.record(z.string(), z.unknown()).optional(),
	reconnectionOptions: z.any().optional().openapi({
		type: "object",
		description: "Reconnection options for streamable HTTP transport"
	}),
	sessionId: z.string().optional()
}).openapi("McpTransportConfig");
const ToolStatusSchema = z.enum(TOOL_STATUS_VALUES);
const McpToolDefinitionSchema = z.object({
	name: z.string(),
	description: z.string().optional(),
	inputSchema: z.record(z.string(), z.unknown()).optional()
});
const ToolSelectSchema = createSelectSchema$1(tools);
const ToolInsertSchema = createInsertSchema$1(tools).extend({
	id: resourceIdSchema,
	imageUrl: imageUrlSchema,
	config: z.object({
		type: z.literal("mcp"),
		mcp: z.object({
			server: z.object({ url: z.url() }),
			transport: z.object({
				type: z.enum(MCPTransportType),
				requestInit: z.record(z.string(), z.unknown()).optional(),
				eventSourceInit: z.record(z.string(), z.unknown()).optional(),
				reconnectionOptions: z.any().optional().openapi({
					type: "object",
					description: "Reconnection options for streamable HTTP transport"
				}),
				sessionId: z.string().optional()
			}).optional(),
			activeTools: z.array(z.string()).optional()
		})
	})
});
const ConversationSelectSchema = createSelectSchema$1(conversations);
const ConversationInsertSchema = createInsertSchema$1(conversations).extend({
	id: resourceIdSchema,
	contextConfigId: resourceIdSchema.optional()
});
const ConversationUpdateSchema = ConversationInsertSchema.partial();
const ConversationApiSelectSchema = createApiSchema(ConversationSelectSchema).openapi("Conversation");
const ConversationApiInsertSchema = createApiInsertSchema(ConversationInsertSchema).openapi("ConversationCreate");
const ConversationApiUpdateSchema = createApiUpdateSchema(ConversationUpdateSchema).openapi("ConversationUpdate");
const MessageSelectSchema = createSelectSchema$1(messages);
const MessageInsertSchema = createInsertSchema$1(messages).extend({
	id: resourceIdSchema,
	conversationId: resourceIdSchema,
	taskId: resourceIdSchema.optional()
});
const MessageUpdateSchema = MessageInsertSchema.partial();
const MessageApiSelectSchema = createApiSchema(MessageSelectSchema).openapi("Message");
const MessageApiInsertSchema = createApiInsertSchema(MessageInsertSchema).openapi("MessageCreate");
const MessageApiUpdateSchema = createApiUpdateSchema(MessageUpdateSchema).openapi("MessageUpdate");
const ContextCacheSelectSchema = createSelectSchema$1(contextCache);
const ContextCacheInsertSchema = createInsertSchema$1(contextCache);
const ContextCacheUpdateSchema = ContextCacheInsertSchema.partial();
const ContextCacheApiSelectSchema = createApiSchema(ContextCacheSelectSchema);
const ContextCacheApiInsertSchema = createApiInsertSchema(ContextCacheInsertSchema);
const ContextCacheApiUpdateSchema = createApiUpdateSchema(ContextCacheUpdateSchema);
const DataComponentSelectSchema = createSelectSchema$1(dataComponents);
const DataComponentInsertSchema = createInsertSchema$1(dataComponents).extend({ id: resourceIdSchema });
const DataComponentBaseSchema = DataComponentInsertSchema.omit({
	createdAt: true,
	updatedAt: true
});
const DataComponentUpdateSchema = DataComponentInsertSchema.partial();
const DataComponentApiSelectSchema = createApiSchema(DataComponentSelectSchema).openapi("DataComponent");
const DataComponentApiInsertSchema = createApiInsertSchema(DataComponentInsertSchema).openapi("DataComponentCreate");
const DataComponentApiUpdateSchema = createApiUpdateSchema(DataComponentUpdateSchema).openapi("DataComponentUpdate");
const SubAgentDataComponentSelectSchema = createSelectSchema$1(subAgentDataComponents);
const SubAgentDataComponentInsertSchema = createInsertSchema$1(subAgentDataComponents);
const SubAgentDataComponentUpdateSchema = SubAgentDataComponentInsertSchema.partial();
const SubAgentDataComponentApiSelectSchema = createAgentScopedApiSchema(SubAgentDataComponentSelectSchema);
const SubAgentDataComponentApiInsertSchema = SubAgentDataComponentInsertSchema.omit({
	tenantId: true,
	projectId: true,
	id: true,
	createdAt: true
});
const SubAgentDataComponentApiUpdateSchema = createAgentScopedApiUpdateSchema(SubAgentDataComponentUpdateSchema);
const ArtifactComponentSelectSchema = createSelectSchema$1(artifactComponents);
const ArtifactComponentInsertSchema = createInsertSchema$1(artifactComponents).extend({ id: resourceIdSchema });
const ArtifactComponentUpdateSchema = ArtifactComponentInsertSchema.partial();
const ArtifactComponentApiSelectSchema = createApiSchema(ArtifactComponentSelectSchema).openapi("ArtifactComponent");
const ArtifactComponentApiInsertSchema = ArtifactComponentInsertSchema.omit({
	tenantId: true,
	projectId: true,
	createdAt: true,
	updatedAt: true
}).openapi("ArtifactComponentCreate");
const ArtifactComponentApiUpdateSchema = createApiUpdateSchema(ArtifactComponentUpdateSchema).openapi("ArtifactComponentUpdate");
const SubAgentArtifactComponentSelectSchema = createSelectSchema$1(subAgentArtifactComponents);
const SubAgentArtifactComponentInsertSchema = createInsertSchema$1(subAgentArtifactComponents).extend({
	id: resourceIdSchema,
	subAgentId: resourceIdSchema,
	artifactComponentId: resourceIdSchema
});
const SubAgentArtifactComponentUpdateSchema = SubAgentArtifactComponentInsertSchema.partial();
const SubAgentArtifactComponentApiSelectSchema = createAgentScopedApiSchema(SubAgentArtifactComponentSelectSchema);
const SubAgentArtifactComponentApiInsertSchema = SubAgentArtifactComponentInsertSchema.omit({
	tenantId: true,
	projectId: true,
	id: true,
	createdAt: true
});
const SubAgentArtifactComponentApiUpdateSchema = createAgentScopedApiUpdateSchema(SubAgentArtifactComponentUpdateSchema);
const ExternalAgentSelectSchema = createSelectSchema$1(externalAgents).extend({ credentialReferenceId: z.string().nullable().optional() });
const ExternalAgentInsertSchema = createInsertSchema$1(externalAgents).extend({ id: resourceIdSchema });
const ExternalAgentUpdateSchema = ExternalAgentInsertSchema.partial();
const ExternalAgentApiSelectSchema = createApiSchema(ExternalAgentSelectSchema).openapi("ExternalAgent");
const ExternalAgentApiInsertSchema = createApiInsertSchema(ExternalAgentInsertSchema).openapi("ExternalAgentCreate");
const ExternalAgentApiUpdateSchema = createApiUpdateSchema(ExternalAgentUpdateSchema).openapi("ExternalAgentUpdate");
const AllAgentSchema = z.discriminatedUnion("type", [SubAgentApiSelectSchema.extend({ type: z.literal("internal") }), ExternalAgentApiSelectSchema.extend({ type: z.literal("external") })]);
const ApiKeySelectSchema = createSelectSchema$1(apiKeys);
const ApiKeyInsertSchema = createInsertSchema$1(apiKeys).extend({
	id: resourceIdSchema,
	agentId: resourceIdSchema
});
const ApiKeyUpdateSchema = ApiKeyInsertSchema.partial().omit({
	tenantId: true,
	projectId: true,
	id: true,
	publicId: true,
	keyHash: true,
	keyPrefix: true,
	createdAt: true
});
const ApiKeyApiSelectSchema = ApiKeySelectSchema.omit({
	tenantId: true,
	projectId: true,
	keyHash: true
}).openapi("ApiKey");
const ApiKeyApiCreationResponseSchema = z.object({ data: z.object({
	apiKey: ApiKeyApiSelectSchema,
	key: z.string().describe("The full API key (shown only once)")
}) });
const ApiKeyApiInsertSchema = ApiKeyInsertSchema.omit({
	tenantId: true,
	projectId: true,
	id: true,
	publicId: true,
	keyHash: true,
	keyPrefix: true,
	lastUsedAt: true
}).openapi("ApiKeyCreate");
const ApiKeyApiUpdateSchema = ApiKeyUpdateSchema.openapi("ApiKeyUpdate");
const CredentialReferenceSelectSchema = createSelectSchema$1(credentialReferences);
const CredentialReferenceInsertSchema = createInsertSchema$1(credentialReferences).extend({
	id: resourceIdSchema,
	type: z.string(),
	credentialStoreId: resourceIdSchema,
	retrievalParams: z.record(z.string(), z.unknown()).nullish()
});
const CredentialReferenceUpdateSchema = CredentialReferenceInsertSchema.partial();
const CredentialReferenceApiSelectSchema = createApiSchema(CredentialReferenceSelectSchema).extend({
	type: z.enum(CredentialStoreType),
	tools: z.array(ToolSelectSchema).optional(),
	externalAgents: z.array(ExternalAgentSelectSchema).optional()
}).openapi("CredentialReference");
const CredentialReferenceApiInsertSchema = createApiInsertSchema(CredentialReferenceInsertSchema).extend({ type: z.enum(CredentialStoreType) }).openapi("CredentialReferenceCreate");
const CredentialReferenceApiUpdateSchema = createApiUpdateSchema(CredentialReferenceUpdateSchema).extend({ type: z.enum(CredentialStoreType).optional() }).openapi("CredentialReferenceUpdate");
const CredentialStoreSchema = z.object({
	id: z.string().describe("Unique identifier of the credential store"),
	type: z.enum(CredentialStoreType),
	available: z.boolean().describe("Whether the store is functional and ready to use"),
	reason: z.string().nullable().describe("Reason why store is not available, if applicable")
}).openapi("CredentialStore");
const CredentialStoreListResponseSchema = z.object({ data: z.array(CredentialStoreSchema).describe("List of credential stores") }).openapi("CredentialStoreListResponse");
const CreateCredentialInStoreRequestSchema = z.object({
	key: z.string().describe("The credential key"),
	value: z.string().describe("The credential value"),
	metadata: z.record(z.string(), z.string()).nullish().describe("The metadata for the credential")
}).openapi("CreateCredentialInStoreRequest");
const CreateCredentialInStoreResponseSchema = z.object({ data: z.object({
	key: z.string().describe("The credential key"),
	storeId: z.string().describe("The store ID where credential was created"),
	createdAt: z.string().describe("ISO timestamp of creation")
}) }).openapi("CreateCredentialInStoreResponse");
const RelatedAgentInfoSchema = z.object({
	id: z.string(),
	name: z.string(),
	description: z.string().nullable()
}).openapi("RelatedAgentInfo");
const ComponentAssociationSchema = z.object({
	subAgentId: z.string(),
	createdAt: z.string()
}).openapi("ComponentAssociation");
const OAuthLoginQuerySchema = z.object({
	tenantId: z.string().min(1, "Tenant ID is required"),
	projectId: z.string().min(1, "Project ID is required"),
	toolId: z.string().min(1, "Tool ID is required")
}).openapi("OAuthLoginQuery");
const OAuthCallbackQuerySchema = z.object({
	code: z.string().min(1, "Authorization code is required"),
	state: z.string().min(1, "State parameter is required"),
	error: z.string().optional(),
	error_description: z.string().optional()
}).openapi("OAuthCallbackQuery");
const McpToolSchema = ToolInsertSchema.extend({
	imageUrl: imageUrlSchema,
	availableTools: z.array(McpToolDefinitionSchema).optional(),
	status: ToolStatusSchema.default("unknown"),
	version: z.string().optional(),
	expiresAt: z.string().optional(),
	createdBy: z.string().optional(),
	relationshipId: z.string().optional()
}).openapi("McpTool");
const MCPToolConfigSchema = McpToolSchema.omit({
	config: true,
	tenantId: true,
	projectId: true,
	status: true,
	version: true,
	createdAt: true,
	updatedAt: true,
	credentialReferenceId: true
}).extend({
	tenantId: z.string().optional(),
	projectId: z.string().optional(),
	description: z.string().optional(),
	serverUrl: z.url(),
	activeTools: z.array(z.string()).optional(),
	mcpType: z.enum(MCPServerType).optional(),
	transport: McpTransportConfigSchema.optional(),
	credential: CredentialReferenceApiInsertSchema.optional()
});
const ToolUpdateSchema = ToolInsertSchema.partial();
const ToolApiSelectSchema = createApiSchema(ToolSelectSchema).openapi("Tool");
const ToolApiInsertSchema = createApiInsertSchema(ToolInsertSchema).openapi("ToolCreate");
const ToolApiUpdateSchema = createApiUpdateSchema(ToolUpdateSchema).openapi("ToolUpdate");
const FunctionToolSelectSchema = createSelectSchema$1(functionTools);
const FunctionToolInsertSchema = createInsertSchema$1(functionTools).extend({ id: resourceIdSchema });
const FunctionToolUpdateSchema = FunctionToolInsertSchema.partial();
const FunctionToolApiSelectSchema = createApiSchema(FunctionToolSelectSchema).openapi("FunctionTool");
const FunctionToolApiInsertSchema = createAgentScopedApiInsertSchema(FunctionToolInsertSchema).openapi("FunctionToolCreate");
const FunctionToolApiUpdateSchema = createApiUpdateSchema(FunctionToolUpdateSchema).openapi("FunctionToolUpdate");
const FunctionSelectSchema = createSelectSchema$1(functions);
const FunctionInsertSchema = createInsertSchema$1(functions).extend({ id: resourceIdSchema });
const FunctionUpdateSchema = FunctionInsertSchema.partial();
const FunctionApiSelectSchema = createApiSchema(FunctionSelectSchema).openapi("Function");
const FunctionApiInsertSchema = createApiInsertSchema(FunctionInsertSchema).openapi("FunctionCreate");
const FunctionApiUpdateSchema = createApiUpdateSchema(FunctionUpdateSchema).openapi("FunctionUpdate");
const FetchConfigSchema = z.object({
	url: z.string().min(1, "URL is required"),
	method: z.enum([
		"GET",
		"POST",
		"PUT",
		"DELETE",
		"PATCH"
	]).optional().default("GET"),
	headers: z.record(z.string(), z.string()).optional(),
	body: z.record(z.string(), z.unknown()).optional(),
	transform: z.string().optional(),
	requiredToFetch: z.array(z.string()).optional(),
	timeout: z.number().min(0).optional().default(CONTEXT_FETCHER_HTTP_TIMEOUT_MS_DEFAULT).optional()
}).openapi("FetchConfig");
const FetchDefinitionSchema = z.object({
	id: z.string().min(1, "Fetch definition ID is required"),
	name: z.string().optional(),
	trigger: z.enum(["initialization", "invocation"]),
	fetchConfig: FetchConfigSchema,
	responseSchema: z.any().optional(),
	defaultValue: z.any().optional().openapi({ description: "Default value if fetch fails" }),
	credential: CredentialReferenceApiInsertSchema.optional()
}).openapi("FetchDefinition");
const ContextConfigSelectSchema = createSelectSchema$1(contextConfigs).extend({ headersSchema: z.any().optional().openapi({
	type: "object",
	description: "JSON Schema for validating request headers"
}) });
const ContextConfigInsertSchema = createInsertSchema$1(contextConfigs).extend({
	id: resourceIdSchema.optional(),
	headersSchema: z.any().nullable().optional().openapi({
		type: "object",
		description: "JSON Schema for validating request headers"
	}),
	contextVariables: z.any().nullable().optional().openapi({
		type: "object",
		description: "Context variables configuration with fetch definitions"
	})
}).omit({
	createdAt: true,
	updatedAt: true
});
const ContextConfigUpdateSchema = ContextConfigInsertSchema.partial();
const ContextConfigApiSelectSchema = createApiSchema(ContextConfigSelectSchema).omit({ agentId: true }).openapi("ContextConfig");
const ContextConfigApiInsertSchema = createApiInsertSchema(ContextConfigInsertSchema).omit({ agentId: true }).openapi("ContextConfigCreate");
const ContextConfigApiUpdateSchema = createApiUpdateSchema(ContextConfigUpdateSchema).omit({ agentId: true }).openapi("ContextConfigUpdate");
const SubAgentToolRelationSelectSchema = createSelectSchema$1(subAgentToolRelations);
const SubAgentToolRelationInsertSchema = createInsertSchema$1(subAgentToolRelations).extend({
	id: resourceIdSchema,
	subAgentId: resourceIdSchema,
	toolId: resourceIdSchema,
	selectedTools: z.array(z.string()).nullish(),
	headers: z.record(z.string(), z.string()).nullish(),
	toolPolicies: z.record(z.string(), z.object({ needsApproval: z.boolean().optional() })).nullish()
});
const SubAgentToolRelationUpdateSchema = SubAgentToolRelationInsertSchema.partial();
const SubAgentToolRelationApiSelectSchema = createAgentScopedApiSchema(SubAgentToolRelationSelectSchema).openapi("SubAgentToolRelation");
const SubAgentToolRelationApiInsertSchema = createAgentScopedApiInsertSchema(SubAgentToolRelationInsertSchema).openapi("SubAgentToolRelationCreate");
const SubAgentToolRelationApiUpdateSchema = createAgentScopedApiUpdateSchema(SubAgentToolRelationUpdateSchema).openapi("SubAgentToolRelationUpdate");
const SubAgentExternalAgentRelationSelectSchema = createSelectSchema$1(subAgentExternalAgentRelations);
const SubAgentExternalAgentRelationInsertSchema = createInsertSchema$1(subAgentExternalAgentRelations).extend({
	id: resourceIdSchema,
	subAgentId: resourceIdSchema,
	externalAgentId: resourceIdSchema,
	headers: z.record(z.string(), z.string()).nullish()
});
const SubAgentExternalAgentRelationUpdateSchema = SubAgentExternalAgentRelationInsertSchema.partial();
const SubAgentExternalAgentRelationApiSelectSchema = createAgentScopedApiSchema(SubAgentExternalAgentRelationSelectSchema).openapi("SubAgentExternalAgentRelation");
const SubAgentExternalAgentRelationApiInsertSchema = createAgentScopedApiInsertSchema(SubAgentExternalAgentRelationInsertSchema).omit({
	id: true,
	subAgentId: true
}).openapi("SubAgentExternalAgentRelationCreate");
const SubAgentExternalAgentRelationApiUpdateSchema = createAgentScopedApiUpdateSchema(SubAgentExternalAgentRelationUpdateSchema).openapi("SubAgentExternalAgentRelationUpdate");
const SubAgentTeamAgentRelationSelectSchema = createSelectSchema$1(subAgentTeamAgentRelations);
const SubAgentTeamAgentRelationInsertSchema = createInsertSchema$1(subAgentTeamAgentRelations).extend({
	id: resourceIdSchema,
	subAgentId: resourceIdSchema,
	targetAgentId: resourceIdSchema,
	headers: z.record(z.string(), z.string()).nullish()
});
const SubAgentTeamAgentRelationUpdateSchema = SubAgentTeamAgentRelationInsertSchema.partial();
const SubAgentTeamAgentRelationApiSelectSchema = createAgentScopedApiSchema(SubAgentTeamAgentRelationSelectSchema).openapi("SubAgentTeamAgentRelation");
const SubAgentTeamAgentRelationApiInsertSchema = createAgentScopedApiInsertSchema(SubAgentTeamAgentRelationInsertSchema).omit({
	id: true,
	subAgentId: true
}).openapi("SubAgentTeamAgentRelationCreate");
const SubAgentTeamAgentRelationApiUpdateSchema = createAgentScopedApiUpdateSchema(SubAgentTeamAgentRelationUpdateSchema).openapi("SubAgentTeamAgentRelationUpdate");
const LedgerArtifactSelectSchema = createSelectSchema$1(ledgerArtifacts);
const LedgerArtifactInsertSchema = createInsertSchema$1(ledgerArtifacts);
const LedgerArtifactUpdateSchema = LedgerArtifactInsertSchema.partial();
const LedgerArtifactApiSelectSchema = createApiSchema(LedgerArtifactSelectSchema);
const LedgerArtifactApiInsertSchema = createApiInsertSchema(LedgerArtifactInsertSchema);
const LedgerArtifactApiUpdateSchema = createApiUpdateSchema(LedgerArtifactUpdateSchema);
const StatusComponentSchema = z.object({
	type: z.string(),
	description: z.string().optional(),
	detailsSchema: z.object({
		type: z.literal("object"),
		properties: z.record(z.string(), z.any()),
		required: z.array(z.string()).optional()
	}).optional()
}).openapi("StatusComponent");
const StatusUpdateSchema = z.object({
	enabled: z.boolean().optional(),
	numEvents: z.number().min(1).max(STATUS_UPDATE_MAX_NUM_EVENTS).optional(),
	timeInSeconds: z.number().min(1).max(STATUS_UPDATE_MAX_INTERVAL_SECONDS).optional(),
	prompt: z.string().max(VALIDATION_SUB_AGENT_PROMPT_MAX_CHARS, `Custom prompt cannot exceed ${VALIDATION_SUB_AGENT_PROMPT_MAX_CHARS} characters`).optional(),
	statusComponents: z.array(StatusComponentSchema).optional()
}).openapi("StatusUpdate");
const CanUseItemSchema = z.object({
	agentToolRelationId: z.string().optional(),
	toolId: z.string(),
	toolSelection: z.array(z.string()).nullish(),
	headers: z.record(z.string(), z.string()).nullish(),
	toolPolicies: z.record(z.string(), z.object({ needsApproval: z.boolean().optional() })).nullish()
}).openapi("CanUseItem");
const canDelegateToExternalAgentSchema = z.object({
	externalAgentId: z.string(),
	subAgentExternalAgentRelationId: z.string().optional(),
	headers: z.record(z.string(), z.string()).nullish()
}).openapi("CanDelegateToExternalAgent");
const canDelegateToTeamAgentSchema = z.object({
	agentId: z.string(),
	subAgentTeamAgentRelationId: z.string().optional(),
	headers: z.record(z.string(), z.string()).nullish()
}).openapi("CanDelegateToTeamAgent");
const TeamAgentSchema = z.object({
	id: z.string(),
	name: z.string(),
	description: z.string()
}).openapi("TeamAgent");
const FullAgentAgentInsertSchema = SubAgentApiInsertSchema.extend({
	type: z.literal("internal"),
	canUse: z.array(CanUseItemSchema),
	dataComponents: z.array(z.string()).optional(),
	artifactComponents: z.array(z.string()).optional(),
	canTransferTo: z.array(z.string()).optional(),
	prompt: z.string().trim().optional(),
	canDelegateTo: z.array(z.union([
		z.string(),
		canDelegateToExternalAgentSchema,
		canDelegateToTeamAgentSchema
	])).optional()
}).openapi("FullAgentAgentInsert");
const AgentWithinContextOfProjectSchema = AgentApiInsertSchema.extend({
	subAgents: z.record(z.string(), FullAgentAgentInsertSchema),
	tools: z.record(z.string(), ToolApiInsertSchema).optional(),
	externalAgents: z.record(z.string(), ExternalAgentApiInsertSchema).optional(),
	teamAgents: z.record(z.string(), TeamAgentSchema).optional(),
	functionTools: z.record(z.string(), FunctionToolApiInsertSchema).optional(),
	functions: z.record(z.string(), FunctionApiInsertSchema).optional(),
	contextConfig: z.optional(ContextConfigApiInsertSchema),
	statusUpdates: z.optional(StatusUpdateSchema),
	models: ModelSchema.optional(),
	stopWhen: AgentStopWhenSchema.optional(),
	prompt: z.string().max(VALIDATION_AGENT_PROMPT_MAX_CHARS, `Agent prompt cannot exceed ${VALIDATION_AGENT_PROMPT_MAX_CHARS} characters`).optional()
}).openapi("AgentWithinContextOfProject");
const PaginationSchema = z.object({
	page: pageNumber,
	limit: limitNumber,
	total: z.number(),
	pages: z.number()
}).openapi("Pagination");
const ListResponseSchema = (itemSchema) => z.object({
	data: z.array(itemSchema),
	pagination: PaginationSchema
});
const SingleResponseSchema = (itemSchema) => z.object({ data: itemSchema });
const ErrorResponseSchema = z.object({
	error: z.string(),
	message: z.string().optional(),
	details: z.any().optional().openapi({ description: "Additional error details" })
}).openapi("ErrorResponse");
const ExistsResponseSchema = z.object({ exists: z.boolean() }).openapi("ExistsResponse");
const RemovedResponseSchema = z.object({
	message: z.string(),
	removed: z.boolean()
}).openapi("RemovedResponse");
const ProjectSelectSchema = registerFieldSchemas(createSelectSchema$1(projects).extend({
	models: ProjectModelSchema.nullable(),
	stopWhen: StopWhenSchema.nullable()
}));
const ProjectInsertSchema = createInsertSchema$1(projects).extend({
	models: ProjectModelSchema,
	stopWhen: StopWhenSchema.optional()
}).omit({
	createdAt: true,
	updatedAt: true
});
const ProjectUpdateSchema = ProjectInsertSchema.partial().omit({
	id: true,
	tenantId: true
});
const ProjectApiSelectSchema = ProjectSelectSchema.omit({ tenantId: true }).openapi("Project");
const ProjectApiInsertSchema = ProjectInsertSchema.omit({ tenantId: true }).openapi("ProjectCreate");
const ProjectApiUpdateSchema = ProjectUpdateSchema.openapi("ProjectUpdate");
const FullProjectDefinitionSchema = ProjectApiInsertSchema.extend({
	agents: z.record(z.string(), AgentWithinContextOfProjectSchema),
	tools: z.record(z.string(), ToolApiInsertSchema),
	functionTools: z.record(z.string(), FunctionToolApiInsertSchema).optional(),
	functions: z.record(z.string(), FunctionApiInsertSchema).optional(),
	dataComponents: z.record(z.string(), DataComponentApiInsertSchema).optional(),
	artifactComponents: z.record(z.string(), ArtifactComponentApiInsertSchema).optional(),
	externalAgents: z.record(z.string(), ExternalAgentApiInsertSchema).optional(),
	statusUpdates: z.optional(StatusUpdateSchema),
	credentialReferences: z.record(z.string(), CredentialReferenceApiInsertSchema).optional(),
	createdAt: z.string().optional(),
	updatedAt: z.string().optional()
}).openapi("FullProjectDefinition");
const ProjectResponse = z.object({ data: ProjectApiSelectSchema }).openapi("ProjectResponse");
const SubAgentResponse = z.object({ data: SubAgentApiSelectSchema }).openapi("SubAgentResponse");
const AgentResponse = z.object({ data: AgentApiSelectSchema }).openapi("AgentResponse");
const ToolResponse = z.object({ data: ToolApiSelectSchema }).openapi("ToolResponse");
const ExternalAgentResponse = z.object({ data: ExternalAgentApiSelectSchema }).openapi("ExternalAgentResponse");
const ContextConfigResponse = z.object({ data: ContextConfigApiSelectSchema }).openapi("ContextConfigResponse");
const ApiKeyResponse = z.object({ data: ApiKeyApiSelectSchema }).openapi("ApiKeyResponse");
const CredentialReferenceResponse = z.object({ data: CredentialReferenceApiSelectSchema }).openapi("CredentialReferenceResponse");
const FunctionResponse = z.object({ data: FunctionApiSelectSchema }).openapi("FunctionResponse");
const FunctionToolResponse = z.object({ data: FunctionToolApiSelectSchema }).openapi("FunctionToolResponse");
const DataComponentResponse = z.object({ data: DataComponentApiSelectSchema }).openapi("DataComponentResponse");
const ArtifactComponentResponse = z.object({ data: ArtifactComponentApiSelectSchema }).openapi("ArtifactComponentResponse");
const SubAgentRelationResponse = z.object({ data: SubAgentRelationApiSelectSchema }).openapi("SubAgentRelationResponse");
const SubAgentToolRelationResponse = z.object({ data: SubAgentToolRelationApiSelectSchema }).openapi("SubAgentToolRelationResponse");
const ConversationResponse = z.object({ data: ConversationApiSelectSchema }).openapi("ConversationResponse");
const MessageResponse = z.object({ data: MessageApiSelectSchema }).openapi("MessageResponse");
const ProjectListResponse = z.object({
	data: z.array(ProjectApiSelectSchema),
	pagination: PaginationSchema
}).openapi("ProjectListResponse");
const SubAgentListResponse = z.object({
	data: z.array(SubAgentApiSelectSchema),
	pagination: PaginationSchema
}).openapi("SubAgentListResponse");
const AgentListResponse = z.object({
	data: z.array(AgentApiSelectSchema),
	pagination: PaginationSchema
}).openapi("AgentListResponse");
const ToolListResponse = z.object({
	data: z.array(ToolApiSelectSchema),
	pagination: PaginationSchema
}).openapi("ToolListResponse");
const ExternalAgentListResponse = z.object({
	data: z.array(ExternalAgentApiSelectSchema),
	pagination: PaginationSchema
}).openapi("ExternalAgentListResponse");
const ContextConfigListResponse = z.object({
	data: z.array(ContextConfigApiSelectSchema),
	pagination: PaginationSchema
}).openapi("ContextConfigListResponse");
const ApiKeyListResponse = z.object({
	data: z.array(ApiKeyApiSelectSchema),
	pagination: PaginationSchema
}).openapi("ApiKeyListResponse");
const CredentialReferenceListResponse = z.object({
	data: z.array(CredentialReferenceApiSelectSchema),
	pagination: PaginationSchema
}).openapi("CredentialReferenceListResponse");
const FunctionListResponse = z.object({
	data: z.array(FunctionApiSelectSchema),
	pagination: PaginationSchema
}).openapi("FunctionListResponse");
const FunctionToolListResponse = z.object({
	data: z.array(FunctionToolApiSelectSchema),
	pagination: PaginationSchema
}).openapi("FunctionToolListResponse");
const DataComponentListResponse = z.object({
	data: z.array(DataComponentApiSelectSchema),
	pagination: PaginationSchema
}).openapi("DataComponentListResponse");
const ArtifactComponentListResponse = z.object({
	data: z.array(ArtifactComponentApiSelectSchema),
	pagination: PaginationSchema
}).openapi("ArtifactComponentListResponse");
const SubAgentRelationListResponse = z.object({
	data: z.array(SubAgentRelationApiSelectSchema),
	pagination: PaginationSchema
}).openapi("SubAgentRelationListResponse");
const SubAgentToolRelationListResponse = z.object({
	data: z.array(SubAgentToolRelationApiSelectSchema),
	pagination: PaginationSchema
}).openapi("SubAgentToolRelationListResponse");
const ConversationListResponse = z.object({
	data: z.array(ConversationApiSelectSchema),
	pagination: PaginationSchema
}).openapi("ConversationListResponse");
const MessageListResponse = z.object({
	data: z.array(MessageApiSelectSchema),
	pagination: PaginationSchema
}).openapi("MessageListResponse");
const SubAgentDataComponentResponse = z.object({ data: SubAgentDataComponentApiSelectSchema }).openapi("SubAgentDataComponentResponse");
const SubAgentArtifactComponentResponse = z.object({ data: SubAgentArtifactComponentApiSelectSchema }).openapi("SubAgentArtifactComponentResponse");
const SubAgentDataComponentListResponse = z.object({
	data: z.array(SubAgentDataComponentApiSelectSchema),
	pagination: PaginationSchema
}).openapi("SubAgentDataComponentListResponse");
const SubAgentArtifactComponentListResponse = z.object({
	data: z.array(SubAgentArtifactComponentApiSelectSchema),
	pagination: PaginationSchema
}).openapi("SubAgentArtifactComponentListResponse");
const FullProjectDefinitionResponse = z.object({ data: FullProjectDefinitionSchema }).openapi("FullProjectDefinitionResponse");
const AgentWithinContextOfProjectResponse = z.object({ data: AgentWithinContextOfProjectSchema }).openapi("AgentWithinContextOfProjectResponse");
const RelatedAgentInfoListResponse = z.object({
	data: z.array(RelatedAgentInfoSchema),
	pagination: PaginationSchema
}).openapi("RelatedAgentInfoListResponse");
const ComponentAssociationListResponse = z.object({ data: z.array(ComponentAssociationSchema) }).openapi("ComponentAssociationListResponse");
const McpToolResponse = z.object({ data: McpToolSchema }).openapi("McpToolResponse");
const McpToolListResponse = z.object({
	data: z.array(McpToolSchema),
	pagination: PaginationSchema
}).openapi("McpToolListResponse");
const SubAgentTeamAgentRelationResponse = z.object({ data: SubAgentTeamAgentRelationApiSelectSchema }).openapi("SubAgentTeamAgentRelationResponse");
const SubAgentTeamAgentRelationListResponse = z.object({
	data: z.array(SubAgentTeamAgentRelationApiSelectSchema),
	pagination: PaginationSchema
}).openapi("SubAgentTeamAgentRelationListResponse");
const SubAgentExternalAgentRelationResponse = z.object({ data: SubAgentExternalAgentRelationApiSelectSchema }).openapi("SubAgentExternalAgentRelationResponse");
const SubAgentExternalAgentRelationListResponse = z.object({
	data: z.array(SubAgentExternalAgentRelationApiSelectSchema),
	pagination: PaginationSchema
}).openapi("SubAgentExternalAgentRelationListResponse");
const DataComponentArrayResponse = z.object({ data: z.array(DataComponentApiSelectSchema) }).openapi("DataComponentArrayResponse");
const ArtifactComponentArrayResponse = z.object({ data: z.array(ArtifactComponentApiSelectSchema) }).openapi("ArtifactComponentArrayResponse");
const HeadersScopeSchema = z.object({
	"x-inkeep-tenant-id": z.string().optional().openapi({
		description: "Tenant identifier",
		example: "tenant_123"
	}),
	"x-inkeep-project-id": z.string().optional().openapi({
		description: "Project identifier",
		example: "project_456"
	}),
	"x-inkeep-agent-id": z.string().optional().openapi({
		description: "Agent identifier",
		example: "agent_789"
	})
});
const TenantId = z.string().openapi("TenantIdPathParam", {
	param: {
		name: "tenantId",
		in: "path"
	},
	description: "Tenant identifier",
	example: "tenant_123"
});
const ProjectId = z.string().openapi("ProjectIdPathParam", {
	param: {
		name: "projectId",
		in: "path"
	},
	description: "Project identifier",
	example: "project_456"
});
const AgentId = z.string().openapi("AgentIdPathParam", {
	param: {
		name: "agentId",
		in: "path"
	},
	description: "Agent identifier",
	example: "agent_789"
});
const SubAgentId = z.string().openapi("SubAgentIdPathParam", {
	param: {
		name: "subAgentId",
		in: "path"
	},
	description: "Sub-agent identifier",
	example: "sub_agent_123"
});
const TenantParamsSchema = z.object({ tenantId: TenantId });
const TenantIdParamsSchema = TenantParamsSchema.extend({ id: resourceIdSchema });
const TenantProjectParamsSchema = TenantParamsSchema.extend({ projectId: ProjectId });
const TenantProjectIdParamsSchema = TenantProjectParamsSchema.extend({ id: resourceIdSchema });
const TenantProjectAgentParamsSchema = TenantProjectParamsSchema.extend({ agentId: AgentId });
const TenantProjectAgentIdParamsSchema = TenantProjectAgentParamsSchema.extend({ id: resourceIdSchema });
const TenantProjectAgentSubAgentParamsSchema = TenantProjectAgentParamsSchema.extend({ subAgentId: SubAgentId });
const TenantProjectAgentSubAgentIdParamsSchema = TenantProjectAgentSubAgentParamsSchema.extend({ id: resourceIdSchema });
const PaginationQueryParamsSchema = z.object({
	page: pageNumber,
	limit: limitNumber
}).openapi("PaginationQueryParams");
const PrebuiltMCPServerSchema = z.object({
	id: z.string().describe("Unique identifier for the MCP server"),
	name: z.string().describe("Display name of the MCP server"),
	url: z.url().describe("URL endpoint for the MCP server"),
	transport: z.enum(MCPTransportType).describe("Transport protocol type"),
	imageUrl: z.url().optional().describe("Logo/icon URL for the MCP server"),
	isOpen: z.boolean().optional().describe("Whether the MCP server is open (doesn't require authentication)"),
	category: z.string().optional().describe("Category of the MCP server (e.g., communication, project_management)"),
	description: z.string().optional().describe("Brief description of what the MCP server does"),
	thirdPartyConnectAccountUrl: z.url().optional().describe("URL to connect to the third party account")
});
const MCPCatalogListResponse = z.object({ data: z.array(PrebuiltMCPServerSchema) }).openapi("MCPCatalogListResponse");
const ThirdPartyMCPServerResponse = z.object({ data: PrebuiltMCPServerSchema.nullable() }).openapi("ThirdPartyMCPServerResponse");

//#endregion
//#region src/validation/props-validation.ts
/**
* Validates that a props object is a valid JSON Schema
* Uses AJV to validate the schema structure without resolving references
*/
function validatePropsAsJsonSchema(props) {
	if (!props || typeof props === "object" && Object.keys(props).length === 0) return {
		isValid: true,
		errors: []
	};
	if (typeof props !== "object" || Array.isArray(props)) return {
		isValid: false,
		errors: [{
			field: "props",
			message: "Props must be a valid JSON Schema object",
			value: props
		}]
	};
	if (!props.type) return {
		isValid: false,
		errors: [{
			field: "props.type",
			message: "JSON Schema must have a \"type\" field"
		}]
	};
	if (props.type !== "object") return {
		isValid: false,
		errors: [{
			field: "props.type",
			message: "JSON Schema type must be \"object\" for component props",
			value: props.type
		}]
	};
	if (!props.properties || typeof props.properties !== "object") return {
		isValid: false,
		errors: [{
			field: "props.properties",
			message: "JSON Schema must have a \"properties\" object"
		}]
	};
	if (props.required !== void 0 && !Array.isArray(props.required)) return {
		isValid: false,
		errors: [{
			field: "props.required",
			message: "If present, \"required\" must be an array"
		}]
	};
	try {
		const schemaToValidate = { ...props };
		delete schemaToValidate.$schema;
		const schemaValidator = new Ajv({
			strict: false,
			validateSchema: true,
			addUsedSchema: false
		});
		if (!schemaValidator.validateSchema(schemaToValidate)) return {
			isValid: false,
			errors: (schemaValidator.errors || []).map((error) => ({
				field: `props${error.instancePath || ""}`,
				message: error.message || "Invalid schema"
			}))
		};
		return {
			isValid: true,
			errors: []
		};
	} catch (error) {
		return {
			isValid: false,
			errors: [{
				field: "props",
				message: `Schema validation failed: ${error instanceof Error ? error.message : "Unknown error"}`
			}]
		};
	}
}

//#endregion
export { ConversationListResponse as $, SubAgentApiUpdateSchema as $n, SubAgentToolRelationUpdateSchema as $r, FunctionToolInsertSchema as $t, ArtifactComponentSelectSchema as A, ToolStatusSchema as Ai, OAuthCallbackQuerySchema as An, SubAgentRelationListResponse as Ar, ExternalAgentInsertSchema as At, ContextCacheUpdateSchema as B, ProjectModelSchema as Bn, SubAgentTeamAgentRelationApiUpdateSchema as Br, FullProjectDefinitionResponse as Bt, ArtifactComponentApiInsertSchema as C, ToolApiInsertSchema as Ci, MessageInsertSchema as Cn, SubAgentExternalAgentRelationUpdateSchema as Cr, DataComponentSelectSchema as Ct, ArtifactComponentInsertSchema as D, ToolListResponse as Di, MessageUpdateSchema as Dn, SubAgentRelationApiSelectSchema as Dr, ExternalAgentApiInsertSchema as Dt, ArtifactComponentArrayResponse as E, ToolInsertSchema as Ei, MessageSelectSchema as En, SubAgentRelationApiInsertSchema as Er, ExistsResponseSchema as Et, ContextCacheApiInsertSchema as F, MIN_ID_LENGTH as Fi, ProjectApiInsertSchema as Fn, SubAgentResponse as Fr, ExternalSubAgentRelationApiInsertSchema as Ft, ContextConfigListResponse as G, RelatedAgentInfoSchema as Gn, SubAgentTeamAgentRelationUpdateSchema as Gr, FunctionInsertSchema as Gt, ContextConfigApiSelectSchema as H, ProjectSelectSchema as Hn, SubAgentTeamAgentRelationListResponse as Hr, FunctionApiInsertSchema as Ht, ContextCacheApiSelectSchema as I, URL_SAFE_ID_PATTERN as Ii, ProjectApiSelectSchema as In, SubAgentSelectSchema as Ir, ExternalSubAgentRelationInsertSchema as It, ContextConfigUpdateSchema as J, StatusComponentSchema as Jn, SubAgentToolRelationApiUpdateSchema as Jr, FunctionSelectSchema as Jt, ContextConfigResponse as K, RemovedResponseSchema as Kn, SubAgentToolRelationApiInsertSchema as Kr, FunctionListResponse as Kt, ContextCacheApiUpdateSchema as L, resourceIdSchema as Li, ProjectApiUpdateSchema as Ln, SubAgentStopWhenSchema as Lr, FetchConfigSchema as Lt, CanUseItemSchema as M, canDelegateToExternalAgentSchema as Mi, PaginationQueryParamsSchema as Mn, SubAgentRelationResponse as Mr, ExternalAgentResponse as Mt, ComponentAssociationListResponse as N, canDelegateToTeamAgentSchema as Ni, PaginationSchema as Nn, SubAgentRelationSelectSchema as Nr, ExternalAgentSelectSchema as Nt, ArtifactComponentListResponse as O, ToolResponse as Oi, ModelSchema as On, SubAgentRelationApiUpdateSchema as Or, ExternalAgentApiSelectSchema as Ot, ComponentAssociationSchema as P, MAX_ID_LENGTH as Pi, PrebuiltMCPServerSchema as Pn, SubAgentRelationUpdateSchema as Pr, ExternalAgentUpdateSchema as Pt, ConversationInsertSchema as Q, SubAgentApiSelectSchema as Qn, SubAgentToolRelationSelectSchema as Qr, FunctionToolConfigSchema as Qt, ContextCacheInsertSchema as R, ProjectInsertSchema as Rn, SubAgentTeamAgentRelationApiInsertSchema as Rr, FetchDefinitionSchema as Rt, ApiKeyUpdateSchema as S, ThirdPartyMCPServerResponse as Si, MessageApiUpdateSchema as Sn, SubAgentExternalAgentRelationSelectSchema as Sr, DataComponentResponse as St, ArtifactComponentApiUpdateSchema as T, ToolApiUpdateSchema as Ti, MessageResponse as Tn, SubAgentListResponse as Tr, ErrorResponseSchema as Tt, ContextConfigApiUpdateSchema as U, ProjectUpdateSchema as Un, SubAgentTeamAgentRelationResponse as Ur, FunctionApiSelectSchema as Ut, ContextConfigApiInsertSchema as V, ProjectResponse as Vn, SubAgentTeamAgentRelationInsertSchema as Vr, FullProjectDefinitionSchema as Vt, ContextConfigInsertSchema as W, RelatedAgentInfoListResponse as Wn, SubAgentTeamAgentRelationSelectSchema as Wr, FunctionApiUpdateSchema as Wt, ConversationApiSelectSchema as X, StopWhenSchema as Xn, SubAgentToolRelationListResponse as Xr, FunctionToolApiSelectSchema as Xt, ConversationApiInsertSchema as Y, StatusUpdateSchema as Yn, SubAgentToolRelationInsertSchema as Yr, FunctionToolApiInsertSchema as Yt, ConversationApiUpdateSchema as Z, SubAgentApiInsertSchema as Zn, SubAgentToolRelationResponse as Zr, FunctionToolApiUpdateSchema as Zt, ApiKeyApiUpdateSchema as _, TenantProjectAgentParamsSchema as _i, McpToolResponse as _n, SubAgentExternalAgentRelationApiSelectSchema as _r, DataComponentApiUpdateSchema as _t, AgentInsertSchema as a, TaskRelationApiInsertSchema as ai, HeadersScopeSchema as an, SubAgentArtifactComponentResponse as ar, CredentialReferenceApiInsertSchema as at, ApiKeyResponse as b, TenantProjectIdParamsSchema as bi, MessageApiInsertSchema as bn, SubAgentExternalAgentRelationListResponse as br, DataComponentInsertSchema as bt, AgentSelectSchema as c, TaskRelationInsertSchema as ci, LedgerArtifactApiUpdateSchema as cn, SubAgentDataComponentApiInsertSchema as cr, CredentialReferenceInsertSchema as ct, AgentWithinContextOfProjectResponse as d, TaskSelectSchema as di, LedgerArtifactUpdateSchema as dn, SubAgentDataComponentInsertSchema as dr, CredentialReferenceSelectSchema as dt, SubAgentUpdateSchema as ei, FunctionToolListResponse as en, SubAgentArtifactComponentApiInsertSchema as er, ConversationResponse as et, AgentWithinContextOfProjectSchema as f, TaskUpdateSchema as fi, ListResponseSchema as fn, SubAgentDataComponentListResponse as fr, CredentialReferenceUpdateSchema as ft, ApiKeyApiSelectSchema as g, TenantProjectAgentIdParamsSchema as gi, McpToolListResponse as gn, SubAgentExternalAgentRelationApiInsertSchema as gr, DataComponentApiSelectSchema as gt, ApiKeyApiInsertSchema as h, TenantParamsSchema as hi, McpToolDefinitionSchema as hn, SubAgentDataComponentUpdateSchema as hr, DataComponentApiInsertSchema as ht, AgentApiUpdateSchema as i, TaskInsertSchema as ii, FunctionUpdateSchema as in, SubAgentArtifactComponentListResponse as ir, CreateCredentialInStoreResponseSchema as it, ArtifactComponentUpdateSchema as j, ToolUpdateSchema as ji, OAuthLoginQuerySchema as jn, SubAgentRelationQuerySchema as jr, ExternalAgentListResponse as jt, ArtifactComponentResponse as k, ToolSelectSchema as ki, ModelSettingsSchema as kn, SubAgentRelationInsertSchema as kr, ExternalAgentApiUpdateSchema as kt, AgentStopWhenSchema as l, TaskRelationSelectSchema as li, LedgerArtifactInsertSchema as ln, SubAgentDataComponentApiSelectSchema as lr, CredentialReferenceListResponse as lt, ApiKeyApiCreationResponseSchema as m, TenantIdParamsSchema as mi, MCPToolConfigSchema as mn, SubAgentDataComponentSelectSchema as mr, CredentialStoreSchema as mt, AgentApiInsertSchema as n, TaskApiSelectSchema as ni, FunctionToolSelectSchema as nn, SubAgentArtifactComponentApiUpdateSchema as nr, ConversationUpdateSchema as nt, AgentListResponse as o, TaskRelationApiSelectSchema as oi, LedgerArtifactApiInsertSchema as on, SubAgentArtifactComponentSelectSchema as or, CredentialReferenceApiSelectSchema as ot, AllAgentSchema as p, TeamAgentSchema as pi, MCPCatalogListResponse as pn, SubAgentDataComponentResponse as pr, CredentialStoreListResponseSchema as pt, ContextConfigSelectSchema as q, SingleResponseSchema as qn, SubAgentToolRelationApiSelectSchema as qr, FunctionResponse as qt, AgentApiSelectSchema as r, TaskApiUpdateSchema as ri, FunctionToolUpdateSchema as rn, SubAgentArtifactComponentInsertSchema as rr, CreateCredentialInStoreRequestSchema as rt, AgentResponse as s, TaskRelationApiUpdateSchema as si, LedgerArtifactApiSelectSchema as sn, SubAgentArtifactComponentUpdateSchema as sr, CredentialReferenceApiUpdateSchema as st, validatePropsAsJsonSchema as t, TaskApiInsertSchema as ti, FunctionToolResponse as tn, SubAgentArtifactComponentApiSelectSchema as tr, ConversationSelectSchema as tt, AgentUpdateSchema as u, TaskRelationUpdateSchema as ui, LedgerArtifactSelectSchema as un, SubAgentDataComponentApiUpdateSchema as ur, CredentialReferenceResponse as ut, ApiKeyInsertSchema as v, TenantProjectAgentSubAgentIdParamsSchema as vi, McpToolSchema as vn, SubAgentExternalAgentRelationApiUpdateSchema as vr, DataComponentArrayResponse as vt, ArtifactComponentApiSelectSchema as w, ToolApiSelectSchema as wi, MessageListResponse as wn, SubAgentInsertSchema as wr, DataComponentUpdateSchema as wt, ApiKeySelectSchema as x, TenantProjectParamsSchema as xi, MessageApiSelectSchema as xn, SubAgentExternalAgentRelationResponse as xr, DataComponentListResponse as xt, ApiKeyListResponse as y, TenantProjectAgentSubAgentParamsSchema as yi, McpTransportConfigSchema as yn, SubAgentExternalAgentRelationInsertSchema as yr, DataComponentBaseSchema as yt, ContextCacheSelectSchema as z, ProjectListResponse as zn, SubAgentTeamAgentRelationApiSelectSchema as zr, FullAgentAgentInsertSchema as zt };
//# sourceMappingURL=props-validation.js.map