var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result) __defProp(target, key, result);
  return result;
};
import { OptionalProps } from "@mikro-orm/core";
import {
  Entity,
  Index,
  PrimaryKey,
  Property
} from "@mikro-orm/decorators/legacy";
OptionalProps;
let AiAgentPromptOverride = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], AiAgentPromptOverride.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], AiAgentPromptOverride.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], AiAgentPromptOverride.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "agent_id", type: "text" })
], AiAgentPromptOverride.prototype, "agentId", 2);
__decorateClass([
  Property({ name: "version", type: "int" })
], AiAgentPromptOverride.prototype, "version", 2);
__decorateClass([
  Property({ name: "sections", type: "jsonb" })
], AiAgentPromptOverride.prototype, "sections", 2);
__decorateClass([
  Property({ name: "notes", type: "text", nullable: true })
], AiAgentPromptOverride.prototype, "notes", 2);
__decorateClass([
  Property({ name: "created_by_user_id", type: "uuid", nullable: true })
], AiAgentPromptOverride.prototype, "createdByUserId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], AiAgentPromptOverride.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], AiAgentPromptOverride.prototype, "updatedAt", 2);
AiAgentPromptOverride = __decorateClass([
  Entity({ tableName: "ai_agent_prompt_overrides" }),
  Index({
    name: "ai_agent_prompt_overrides_tenant_org_agent_version_uq",
    expression: 'create unique index "ai_agent_prompt_overrides_tenant_org_agent_version_uq" on "ai_agent_prompt_overrides" ("tenant_id", "organization_id", "agent_id", "version") where "organization_id" is not null'
  }),
  Index({
    name: "ai_agent_prompt_overrides_tenant_agent_version_null_org_uq",
    expression: 'create unique index "ai_agent_prompt_overrides_tenant_agent_version_null_org_uq" on "ai_agent_prompt_overrides" ("tenant_id", "agent_id", "version") where "organization_id" is null'
  }),
  Index({
    name: "ai_agent_prompt_overrides_tenant_agent_idx",
    properties: ["tenantId", "agentId"]
  }),
  Index({
    name: "ai_agent_prompt_overrides_tenant_org_agent_version_idx",
    expression: 'create index "ai_agent_prompt_overrides_tenant_org_agent_version_idx" on "ai_agent_prompt_overrides" ("tenant_id", "organization_id", "agent_id", "version" desc)'
  })
], AiAgentPromptOverride);
OptionalProps;
let AiPendingAction = class {
  constructor() {
    this.fieldDiff = [];
    this.attachmentIds = [];
    this.queueMode = "inline";
    this.createdAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], AiPendingAction.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], AiPendingAction.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], AiPendingAction.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "agent_id", type: "text" })
], AiPendingAction.prototype, "agentId", 2);
__decorateClass([
  Property({ name: "tool_name", type: "text" })
], AiPendingAction.prototype, "toolName", 2);
__decorateClass([
  Property({ name: "conversation_id", type: "text", nullable: true })
], AiPendingAction.prototype, "conversationId", 2);
__decorateClass([
  Property({ name: "target_entity_type", type: "text", nullable: true })
], AiPendingAction.prototype, "targetEntityType", 2);
__decorateClass([
  Property({ name: "target_record_id", type: "text", nullable: true })
], AiPendingAction.prototype, "targetRecordId", 2);
__decorateClass([
  Property({ name: "normalized_input", type: "jsonb" })
], AiPendingAction.prototype, "normalizedInput", 2);
__decorateClass([
  Property({ name: "field_diff", type: "jsonb", default: [] })
], AiPendingAction.prototype, "fieldDiff", 2);
__decorateClass([
  Property({ name: "records", type: "jsonb", nullable: true })
], AiPendingAction.prototype, "records", 2);
__decorateClass([
  Property({ name: "failed_records", type: "jsonb", nullable: true })
], AiPendingAction.prototype, "failedRecords", 2);
__decorateClass([
  Property({ name: "side_effects_summary", type: "text", nullable: true })
], AiPendingAction.prototype, "sideEffectsSummary", 2);
__decorateClass([
  Property({ name: "record_version", type: "text", nullable: true })
], AiPendingAction.prototype, "recordVersion", 2);
__decorateClass([
  Property({ name: "attachment_ids", type: "jsonb", default: [] })
], AiPendingAction.prototype, "attachmentIds", 2);
__decorateClass([
  Property({ name: "idempotency_key", type: "text" })
], AiPendingAction.prototype, "idempotencyKey", 2);
__decorateClass([
  Property({ name: "created_by_user_id", type: "uuid" })
], AiPendingAction.prototype, "createdByUserId", 2);
__decorateClass([
  Property({ name: "status", type: "text" })
], AiPendingAction.prototype, "status", 2);
__decorateClass([
  Property({ name: "queue_mode", type: "text", default: "inline" })
], AiPendingAction.prototype, "queueMode", 2);
__decorateClass([
  Property({ name: "execution_result", type: "jsonb", nullable: true })
], AiPendingAction.prototype, "executionResult", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], AiPendingAction.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "expires_at", type: Date })
], AiPendingAction.prototype, "expiresAt", 2);
__decorateClass([
  Property({ name: "resolved_at", type: Date, nullable: true })
], AiPendingAction.prototype, "resolvedAt", 2);
__decorateClass([
  Property({ name: "resolved_by_user_id", type: "uuid", nullable: true })
], AiPendingAction.prototype, "resolvedByUserId", 2);
AiPendingAction = __decorateClass([
  Entity({ tableName: "ai_pending_actions" }),
  Index({
    name: "ai_pending_actions_tenant_org_idempotency_uq",
    expression: 'create unique index "ai_pending_actions_tenant_org_idempotency_uq" on "ai_pending_actions" ("tenant_id", "organization_id", "idempotency_key") where "organization_id" is not null'
  }),
  Index({
    name: "ai_pending_actions_tenant_idem_null_org_uq",
    expression: 'create unique index "ai_pending_actions_tenant_idem_null_org_uq" on "ai_pending_actions" ("tenant_id", "idempotency_key") where "organization_id" is null'
  }),
  Index({
    name: "ai_pending_actions_tenant_org_status_expires_idx",
    properties: ["tenantId", "organizationId", "status", "expiresAt"]
  }),
  Index({
    name: "ai_pending_actions_tenant_org_agent_status_idx",
    properties: ["tenantId", "organizationId", "agentId", "status"]
  })
], AiPendingAction);
OptionalProps;
let AiAgentRuntimeOverride = class {
  constructor() {
    this.allowedOverrideModelsByProvider = {};
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], AiAgentRuntimeOverride.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], AiAgentRuntimeOverride.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], AiAgentRuntimeOverride.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "agent_id", type: "string", columnType: "varchar(128)", nullable: true })
], AiAgentRuntimeOverride.prototype, "agentId", 2);
__decorateClass([
  Property({ name: "provider_id", type: "string", columnType: "varchar(64)", nullable: true })
], AiAgentRuntimeOverride.prototype, "providerId", 2);
__decorateClass([
  Property({ name: "model_id", type: "string", columnType: "varchar(256)", nullable: true })
], AiAgentRuntimeOverride.prototype, "modelId", 2);
__decorateClass([
  Property({ name: "base_url", type: "string", columnType: "varchar(2048)", nullable: true })
], AiAgentRuntimeOverride.prototype, "baseUrl", 2);
__decorateClass([
  Property({ name: "allowed_override_providers", type: "jsonb", nullable: true })
], AiAgentRuntimeOverride.prototype, "allowedOverrideProviders", 2);
__decorateClass([
  Property({ name: "allowed_override_models_by_provider", type: "jsonb", default: "{}" })
], AiAgentRuntimeOverride.prototype, "allowedOverrideModelsByProvider", 2);
__decorateClass([
  Property({ name: "updated_by_user_id", type: "uuid", nullable: true })
], AiAgentRuntimeOverride.prototype, "updatedByUserId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], AiAgentRuntimeOverride.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], AiAgentRuntimeOverride.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], AiAgentRuntimeOverride.prototype, "deletedAt", 2);
__decorateClass([
  Property({ name: "loop_disabled", type: "boolean", nullable: true })
], AiAgentRuntimeOverride.prototype, "loopDisabled", 2);
__decorateClass([
  Property({ name: "loop_max_steps", type: "int", nullable: true })
], AiAgentRuntimeOverride.prototype, "loopMaxSteps", 2);
__decorateClass([
  Property({ name: "loop_max_tool_calls", type: "int", nullable: true })
], AiAgentRuntimeOverride.prototype, "loopMaxToolCalls", 2);
__decorateClass([
  Property({ name: "loop_max_wall_clock_ms", type: "int", nullable: true })
], AiAgentRuntimeOverride.prototype, "loopMaxWallClockMs", 2);
__decorateClass([
  Property({ name: "loop_max_tokens", type: "int", nullable: true })
], AiAgentRuntimeOverride.prototype, "loopMaxTokens", 2);
__decorateClass([
  Property({ name: "loop_stop_when_json", type: "jsonb", nullable: true })
], AiAgentRuntimeOverride.prototype, "loopStopWhenJson", 2);
__decorateClass([
  Property({ name: "loop_active_tools_json", type: "jsonb", nullable: true })
], AiAgentRuntimeOverride.prototype, "loopActiveToolsJson", 2);
AiAgentRuntimeOverride = __decorateClass([
  Entity({ tableName: "ai_agent_runtime_overrides" }),
  Index({
    name: "ai_agent_runtime_overrides_tenant_org_agent_uq",
    expression: 'create unique index "ai_agent_runtime_overrides_tenant_org_agent_uq" on "ai_agent_runtime_overrides" ("tenant_id", "organization_id", "agent_id") where "deleted_at" is null and "organization_id" is not null and "agent_id" is not null'
  }),
  Index({
    name: "ai_agent_runtime_overrides_tenant_agent_null_org_uq",
    expression: 'create unique index "ai_agent_runtime_overrides_tenant_agent_null_org_uq" on "ai_agent_runtime_overrides" ("tenant_id", "agent_id") where "deleted_at" is null and "organization_id" is null and "agent_id" is not null'
  }),
  Index({
    name: "ai_agent_runtime_overrides_tenant_null_agent_null_org_uq",
    expression: 'create unique index "ai_agent_runtime_overrides_tenant_null_agent_null_org_uq" on "ai_agent_runtime_overrides" ("tenant_id") where "deleted_at" is null and "organization_id" is null and "agent_id" is null'
  }),
  Index({
    name: "ai_agent_runtime_overrides_tenant_org_null_agent_uq",
    expression: 'create unique index "ai_agent_runtime_overrides_tenant_org_null_agent_uq" on "ai_agent_runtime_overrides" ("tenant_id", "organization_id") where "deleted_at" is null and "organization_id" is not null and "agent_id" is null'
  }),
  Index({
    name: "ai_agent_runtime_overrides_tenant_idx",
    properties: ["tenantId"]
  })
], AiAgentRuntimeOverride);
OptionalProps;
let AiTokenUsageEvent = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], AiTokenUsageEvent.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], AiTokenUsageEvent.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], AiTokenUsageEvent.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "user_id", type: "uuid" })
], AiTokenUsageEvent.prototype, "userId", 2);
__decorateClass([
  Property({ name: "agent_id", type: "text" })
], AiTokenUsageEvent.prototype, "agentId", 2);
__decorateClass([
  Property({ name: "module_id", type: "text" })
], AiTokenUsageEvent.prototype, "moduleId", 2);
__decorateClass([
  Property({ name: "session_id", type: "uuid" })
], AiTokenUsageEvent.prototype, "sessionId", 2);
__decorateClass([
  Property({ name: "turn_id", type: "uuid" })
], AiTokenUsageEvent.prototype, "turnId", 2);
__decorateClass([
  Property({ name: "step_index", type: "int" })
], AiTokenUsageEvent.prototype, "stepIndex", 2);
__decorateClass([
  Property({ name: "provider_id", type: "text" })
], AiTokenUsageEvent.prototype, "providerId", 2);
__decorateClass([
  Property({ name: "model_id", type: "text" })
], AiTokenUsageEvent.prototype, "modelId", 2);
__decorateClass([
  Property({ name: "input_tokens", type: "int" })
], AiTokenUsageEvent.prototype, "inputTokens", 2);
__decorateClass([
  Property({ name: "output_tokens", type: "int" })
], AiTokenUsageEvent.prototype, "outputTokens", 2);
__decorateClass([
  Property({ name: "cached_input_tokens", type: "int", nullable: true })
], AiTokenUsageEvent.prototype, "cachedInputTokens", 2);
__decorateClass([
  Property({ name: "reasoning_tokens", type: "int", nullable: true })
], AiTokenUsageEvent.prototype, "reasoningTokens", 2);
__decorateClass([
  Property({ name: "finish_reason", type: "text", nullable: true })
], AiTokenUsageEvent.prototype, "finishReason", 2);
__decorateClass([
  Property({ name: "loop_abort_reason", type: "text", nullable: true })
], AiTokenUsageEvent.prototype, "loopAbortReason", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], AiTokenUsageEvent.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], AiTokenUsageEvent.prototype, "updatedAt", 2);
AiTokenUsageEvent = __decorateClass([
  Entity({ tableName: "ai_token_usage_events" }),
  Index({
    name: "ai_token_usage_events_tenant_created_idx",
    properties: ["tenantId", "createdAt"]
  }),
  Index({
    name: "ai_token_usage_events_tenant_agent_created_idx",
    properties: ["tenantId", "agentId", "createdAt"]
  }),
  Index({
    name: "ai_token_usage_events_tenant_model_created_idx",
    properties: ["tenantId", "modelId", "createdAt"]
  }),
  Index({
    name: "ai_token_usage_events_tenant_session_turn_step_idx",
    properties: ["tenantId", "sessionId", "turnId", "stepIndex"]
  })
], AiTokenUsageEvent);
OptionalProps;
let AiTokenUsageDaily = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], AiTokenUsageDaily.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], AiTokenUsageDaily.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], AiTokenUsageDaily.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "day", type: "string", columnType: "date" })
], AiTokenUsageDaily.prototype, "day", 2);
__decorateClass([
  Property({ name: "agent_id", type: "text" })
], AiTokenUsageDaily.prototype, "agentId", 2);
__decorateClass([
  Property({ name: "model_id", type: "text" })
], AiTokenUsageDaily.prototype, "modelId", 2);
__decorateClass([
  Property({ name: "provider_id", type: "text" })
], AiTokenUsageDaily.prototype, "providerId", 2);
__decorateClass([
  Property({ name: "input_tokens", type: "string", columnType: "bigint" })
], AiTokenUsageDaily.prototype, "inputTokens", 2);
__decorateClass([
  Property({ name: "output_tokens", type: "string", columnType: "bigint" })
], AiTokenUsageDaily.prototype, "outputTokens", 2);
__decorateClass([
  Property({ name: "cached_input_tokens", type: "string", columnType: "bigint" })
], AiTokenUsageDaily.prototype, "cachedInputTokens", 2);
__decorateClass([
  Property({ name: "reasoning_tokens", type: "string", columnType: "bigint" })
], AiTokenUsageDaily.prototype, "reasoningTokens", 2);
__decorateClass([
  Property({ name: "step_count", type: "string", columnType: "bigint" })
], AiTokenUsageDaily.prototype, "stepCount", 2);
__decorateClass([
  Property({ name: "turn_count", type: "string", columnType: "bigint" })
], AiTokenUsageDaily.prototype, "turnCount", 2);
__decorateClass([
  Property({ name: "session_count", type: "string", columnType: "bigint" })
], AiTokenUsageDaily.prototype, "sessionCount", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], AiTokenUsageDaily.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], AiTokenUsageDaily.prototype, "updatedAt", 2);
AiTokenUsageDaily = __decorateClass([
  Entity({ tableName: "ai_token_usage_daily" }),
  Index({
    name: "ai_token_usage_daily_tenant_day_agent_model_org_uq",
    expression: 'create unique index "ai_token_usage_daily_tenant_day_agent_model_org_uq" on "ai_token_usage_daily" ("tenant_id", "day", "agent_id", "model_id", "organization_id") where "organization_id" is not null'
  }),
  Index({
    name: "ai_token_usage_daily_tenant_day_agent_model_null_org_uq",
    expression: 'create unique index "ai_token_usage_daily_tenant_day_agent_model_null_org_uq" on "ai_token_usage_daily" ("tenant_id", "day", "agent_id", "model_id") where "organization_id" is null'
  }),
  Index({
    name: "ai_token_usage_daily_tenant_day_idx",
    properties: ["tenantId", "day"]
  })
], AiTokenUsageDaily);
OptionalProps;
let AiTenantModelAllowlist = class {
  constructor() {
    this.allowedModelsByProvider = {};
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], AiTenantModelAllowlist.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], AiTenantModelAllowlist.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], AiTenantModelAllowlist.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "allowed_providers", type: "jsonb", nullable: true })
], AiTenantModelAllowlist.prototype, "allowedProviders", 2);
__decorateClass([
  Property({ name: "allowed_models_by_provider", type: "jsonb", default: "{}" })
], AiTenantModelAllowlist.prototype, "allowedModelsByProvider", 2);
__decorateClass([
  Property({ name: "updated_by_user_id", type: "uuid", nullable: true })
], AiTenantModelAllowlist.prototype, "updatedByUserId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], AiTenantModelAllowlist.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], AiTenantModelAllowlist.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], AiTenantModelAllowlist.prototype, "deletedAt", 2);
AiTenantModelAllowlist = __decorateClass([
  Entity({ tableName: "ai_tenant_model_allowlists" }),
  Index({
    name: "ai_tenant_model_allowlists_tenant_org_uq",
    expression: 'create unique index "ai_tenant_model_allowlists_tenant_org_uq" on "ai_tenant_model_allowlists" ("tenant_id", "organization_id") where "deleted_at" is null and "organization_id" is not null'
  }),
  Index({
    name: "ai_tenant_model_allowlists_tenant_null_org_uq",
    expression: 'create unique index "ai_tenant_model_allowlists_tenant_null_org_uq" on "ai_tenant_model_allowlists" ("tenant_id") where "deleted_at" is null and "organization_id" is null'
  }),
  Index({
    name: "ai_tenant_model_allowlists_tenant_idx",
    properties: ["tenantId"]
  })
], AiTenantModelAllowlist);
OptionalProps;
let AiAgentMutationPolicyOverride = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], AiAgentMutationPolicyOverride.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], AiAgentMutationPolicyOverride.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], AiAgentMutationPolicyOverride.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "agent_id", type: "text" })
], AiAgentMutationPolicyOverride.prototype, "agentId", 2);
__decorateClass([
  Property({ name: "mutation_policy", type: "text" })
], AiAgentMutationPolicyOverride.prototype, "mutationPolicy", 2);
__decorateClass([
  Property({ name: "notes", type: "text", nullable: true })
], AiAgentMutationPolicyOverride.prototype, "notes", 2);
__decorateClass([
  Property({ name: "created_by_user_id", type: "uuid", nullable: true })
], AiAgentMutationPolicyOverride.prototype, "createdByUserId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], AiAgentMutationPolicyOverride.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], AiAgentMutationPolicyOverride.prototype, "updatedAt", 2);
AiAgentMutationPolicyOverride = __decorateClass([
  Entity({ tableName: "ai_agent_mutation_policy_overrides" }),
  Index({
    name: "ai_agent_mutation_policy_overrides_tenant_org_agent_uq",
    expression: 'create unique index "ai_agent_mutation_policy_overrides_tenant_org_agent_uq" on "ai_agent_mutation_policy_overrides" ("tenant_id", "organization_id", "agent_id") where "organization_id" is not null'
  }),
  Index({
    name: "ai_agent_mutation_policy_overrides_tenant_agent_null_org_uq",
    expression: 'create unique index "ai_agent_mutation_policy_overrides_tenant_agent_null_org_uq" on "ai_agent_mutation_policy_overrides" ("tenant_id", "agent_id") where "organization_id" is null'
  }),
  Index({
    name: "ai_agent_mutation_policy_overrides_tenant_agent_idx",
    properties: ["tenantId", "agentId"]
  })
], AiAgentMutationPolicyOverride);
OptionalProps;
let AiChatConversation = class {
  constructor() {
    this.status = "open";
    this.visibility = "private";
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], AiChatConversation.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], AiChatConversation.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], AiChatConversation.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "conversation_id", type: "text" })
], AiChatConversation.prototype, "conversationId", 2);
__decorateClass([
  Property({ name: "agent_id", type: "text" })
], AiChatConversation.prototype, "agentId", 2);
__decorateClass([
  Property({ name: "owner_user_id", type: "uuid" })
], AiChatConversation.prototype, "ownerUserId", 2);
__decorateClass([
  Property({ name: "title", type: "text", nullable: true })
], AiChatConversation.prototype, "title", 2);
__decorateClass([
  Property({ name: "status", type: "text", default: "open" })
], AiChatConversation.prototype, "status", 2);
__decorateClass([
  Property({ name: "visibility", type: "text", default: "private" })
], AiChatConversation.prototype, "visibility", 2);
__decorateClass([
  Property({ name: "page_context", type: "jsonb", nullable: true })
], AiChatConversation.prototype, "pageContext", 2);
__decorateClass([
  Property({ name: "last_message_at", type: Date, nullable: true })
], AiChatConversation.prototype, "lastMessageAt", 2);
__decorateClass([
  Property({ name: "imported_from_local_at", type: Date, nullable: true })
], AiChatConversation.prototype, "importedFromLocalAt", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], AiChatConversation.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], AiChatConversation.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], AiChatConversation.prototype, "deletedAt", 2);
AiChatConversation = __decorateClass([
  Entity({ tableName: "ai_chat_conversations" }),
  Index({
    name: "ai_chat_conversations_tenant_org_conv_uq",
    expression: 'create unique index "ai_chat_conversations_tenant_org_conv_uq" on "ai_chat_conversations" ("tenant_id", "organization_id", "conversation_id") where "organization_id" is not null and "deleted_at" is null'
  }),
  Index({
    name: "ai_chat_conversations_tenant_conv_null_org_uq",
    expression: 'create unique index "ai_chat_conversations_tenant_conv_null_org_uq" on "ai_chat_conversations" ("tenant_id", "conversation_id") where "organization_id" is null and "deleted_at" is null'
  }),
  Index({
    name: "ai_chat_conversations_tenant_org_owner_agent_idx",
    properties: ["tenantId", "organizationId", "ownerUserId", "agentId", "status", "lastMessageAt"]
  }),
  Index({
    name: "ai_chat_conversations_tenant_org_deleted_idx",
    properties: ["tenantId", "organizationId", "deletedAt"]
  })
], AiChatConversation);
OptionalProps;
let AiChatConversationParticipant = class {
  constructor() {
    this.role = "owner";
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], AiChatConversationParticipant.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], AiChatConversationParticipant.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], AiChatConversationParticipant.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "conversation_id", type: "text" })
], AiChatConversationParticipant.prototype, "conversationId", 2);
__decorateClass([
  Property({ name: "user_id", type: "uuid" })
], AiChatConversationParticipant.prototype, "userId", 2);
__decorateClass([
  Property({ name: "role", type: "text", default: "owner" })
], AiChatConversationParticipant.prototype, "role", 2);
__decorateClass([
  Property({ name: "last_read_at", type: Date, nullable: true })
], AiChatConversationParticipant.prototype, "lastReadAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], AiChatConversationParticipant.prototype, "deletedAt", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], AiChatConversationParticipant.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], AiChatConversationParticipant.prototype, "updatedAt", 2);
AiChatConversationParticipant = __decorateClass([
  Entity({ tableName: "ai_chat_conversation_participants" }),
  Index({
    name: "ai_chat_conv_participants_tenant_org_conv_user_uq",
    expression: 'create unique index "ai_chat_conv_participants_tenant_org_conv_user_uq" on "ai_chat_conversation_participants" ("tenant_id", "organization_id", "conversation_id", "user_id") where "organization_id" is not null'
  }),
  Index({
    name: "ai_chat_conv_participants_tenant_conv_user_null_org_uq",
    expression: 'create unique index "ai_chat_conv_participants_tenant_conv_user_null_org_uq" on "ai_chat_conversation_participants" ("tenant_id", "conversation_id", "user_id") where "organization_id" is null'
  }),
  Index({
    name: "ai_chat_conv_participants_tenant_org_user_conv_idx",
    properties: ["tenantId", "organizationId", "userId", "conversationId"]
  })
], AiChatConversationParticipant);
OptionalProps;
let AiChatMessage = class {
  constructor() {
    this.createdAt = /* @__PURE__ */ new Date();
    this.updatedAt = /* @__PURE__ */ new Date();
  }
};
__decorateClass([
  PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
], AiChatMessage.prototype, "id", 2);
__decorateClass([
  Property({ name: "tenant_id", type: "uuid" })
], AiChatMessage.prototype, "tenantId", 2);
__decorateClass([
  Property({ name: "organization_id", type: "uuid", nullable: true })
], AiChatMessage.prototype, "organizationId", 2);
__decorateClass([
  Property({ name: "conversation_id", type: "text" })
], AiChatMessage.prototype, "conversationId", 2);
__decorateClass([
  Property({ name: "client_message_id", type: "text", nullable: true })
], AiChatMessage.prototype, "clientMessageId", 2);
__decorateClass([
  Property({ name: "role", type: "text" })
], AiChatMessage.prototype, "role", 2);
__decorateClass([
  Property({ name: "content", type: "text" })
], AiChatMessage.prototype, "content", 2);
__decorateClass([
  Property({ name: "ui_parts", type: "jsonb", nullable: true })
], AiChatMessage.prototype, "uiParts", 2);
__decorateClass([
  Property({ name: "attachment_ids", type: "jsonb", nullable: true })
], AiChatMessage.prototype, "attachmentIds", 2);
__decorateClass([
  Property({ name: "files_metadata", type: "jsonb", nullable: true })
], AiChatMessage.prototype, "filesMetadata", 2);
__decorateClass([
  Property({ name: "model", type: "text", nullable: true })
], AiChatMessage.prototype, "model", 2);
__decorateClass([
  Property({ name: "metadata", type: "jsonb", nullable: true })
], AiChatMessage.prototype, "metadata", 2);
__decorateClass([
  Property({ name: "created_by_user_id", type: "uuid", nullable: true })
], AiChatMessage.prototype, "createdByUserId", 2);
__decorateClass([
  Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
], AiChatMessage.prototype, "createdAt", 2);
__decorateClass([
  Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
], AiChatMessage.prototype, "updatedAt", 2);
__decorateClass([
  Property({ name: "deleted_at", type: Date, nullable: true })
], AiChatMessage.prototype, "deletedAt", 2);
AiChatMessage = __decorateClass([
  Entity({ tableName: "ai_chat_messages" }),
  Index({
    name: "ai_chat_messages_tenant_org_conv_client_id_uq",
    expression: 'create unique index "ai_chat_messages_tenant_org_conv_client_id_uq" on "ai_chat_messages" ("tenant_id", "organization_id", "conversation_id", "client_message_id") where "organization_id" is not null and "client_message_id" is not null and "deleted_at" is null'
  }),
  Index({
    name: "ai_chat_messages_tenant_conv_client_id_null_org_uq",
    expression: 'create unique index "ai_chat_messages_tenant_conv_client_id_null_org_uq" on "ai_chat_messages" ("tenant_id", "conversation_id", "client_message_id") where "organization_id" is null and "client_message_id" is not null and "deleted_at" is null'
  }),
  Index({
    name: "ai_chat_messages_tenant_org_conv_created_idx",
    properties: ["tenantId", "organizationId", "conversationId", "createdAt"]
  }),
  Index({
    name: "ai_chat_messages_tenant_org_deleted_idx",
    properties: ["tenantId", "organizationId", "deletedAt"]
  })
], AiChatMessage);
export {
  AiAgentMutationPolicyOverride,
  AiAgentPromptOverride,
  AiAgentRuntimeOverride,
  AiChatConversation,
  AiChatConversationParticipant,
  AiChatMessage,
  AiPendingAction,
  AiTenantModelAllowlist,
  AiTokenUsageDaily,
  AiTokenUsageEvent
};
//# sourceMappingURL=entities.js.map
