'use strict';

var chunkCXL3KPGO_cjs = require('./chunk-CXL3KPGO.cjs');
var chunkMCYD5LW7_cjs = require('./chunk-MCYD5LW7.cjs');
var z2 = require('zod');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var z2__default = /*#__PURE__*/_interopDefault(z2);

var semanticRecallSchema = z2__default.default.object({
  topK: z2__default.default.number().describe("Number of semantically similar messages to retrieve"),
  messageRange: z2__default.default.union([
    z2__default.default.number(),
    z2__default.default.object({
      before: z2__default.default.number(),
      after: z2__default.default.number()
    })
  ]).describe("Amount of surrounding context to include with each retrieved message"),
  scope: z2__default.default.enum(["thread", "resource"]).optional().describe("Scope for semantic search queries"),
  threshold: z2__default.default.number().min(0).max(1).optional().describe("Minimum similarity score threshold"),
  indexName: z2__default.default.string().optional().describe("Index name for the vector store")
});
var titleGenerationSchema = z2__default.default.union([
  z2__default.default.boolean(),
  z2__default.default.object({
    model: z2__default.default.string().describe("Model ID in format provider/model-name (ModelRouterModelId)"),
    instructions: z2__default.default.string().optional().describe("Custom instructions for title generation")
  })
]);
var serializedObservationConfigSchema = z2__default.default.object({
  model: z2__default.default.string().optional().describe("Observer model ID"),
  messageTokens: z2__default.default.number().optional().describe("Token threshold that triggers observation"),
  modelSettings: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional().describe("Model settings (temperature, etc.)"),
  providerOptions: z2__default.default.record(z2__default.default.string(), z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional()).optional().describe("Provider-specific options"),
  maxTokensPerBatch: z2__default.default.number().optional().describe("Maximum tokens per batch"),
  bufferTokens: z2__default.default.union([z2__default.default.number(), z2__default.default.literal(false)]).optional().describe("Async buffering interval or false"),
  bufferActivation: z2__default.default.number().optional().describe("Ratio of buffered observations to activate"),
  blockAfter: z2__default.default.number().optional().describe("Token threshold for synchronous blocking")
});
var serializedReflectionConfigSchema = z2__default.default.object({
  model: z2__default.default.string().optional().describe("Reflector model ID"),
  observationTokens: z2__default.default.number().optional().describe("Token threshold that triggers reflection"),
  modelSettings: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional().describe("Model settings (temperature, etc.)"),
  providerOptions: z2__default.default.record(z2__default.default.string(), z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional()).optional().describe("Provider-specific options"),
  blockAfter: z2__default.default.number().optional().describe("Token threshold for synchronous blocking"),
  bufferActivation: z2__default.default.number().optional().describe("Ratio for async reflection buffering")
});
var serializedObservationalMemoryConfigObjectSchema = z2__default.default.object({
  model: z2__default.default.string().optional().describe("Model ID for both Observer and Reflector"),
  scope: z2__default.default.enum(["resource", "thread"]).optional().describe("Memory scope"),
  shareTokenBudget: z2__default.default.boolean().optional().describe("Share token budget between messages and observations"),
  observation: serializedObservationConfigSchema.optional().describe("Observation step configuration"),
  reflection: serializedReflectionConfigSchema.optional().describe("Reflection step configuration")
});
var serializedObservationalMemoryConfigSchema = z2__default.default.union([
  z2__default.default.boolean(),
  serializedObservationalMemoryConfigObjectSchema
]);
var serializedMemoryConfigSchema = z2__default.default.object({
  vector: z2__default.default.union([z2__default.default.string(), z2__default.default.literal(false)]).optional().describe("Vector database identifier or false to disable"),
  options: z2__default.default.object({
    readOnly: z2__default.default.boolean().optional(),
    lastMessages: z2__default.default.union([z2__default.default.number(), z2__default.default.literal(false)]).optional(),
    semanticRecall: z2__default.default.union([z2__default.default.boolean(), semanticRecallSchema]).optional(),
    generateTitle: titleGenerationSchema.optional()
  }).optional().describe("Memory behavior configuration, excluding workingMemory and threads"),
  embedder: z2__default.default.string().optional().describe('Embedding model ID in the format "provider/model" (e.g., "openai/text-embedding-3-small")'),
  embedderOptions: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional().describe("Options to pass to the embedder, omitting telemetry"),
  observationalMemory: serializedObservationalMemoryConfigSchema.optional().describe("Serialized observational memory configuration")
}).refine(
  (data) => {
    const semanticRecall = data.options?.semanticRecall;
    const semanticRecallEnabled = semanticRecall === true || typeof semanticRecall === "object" && semanticRecall !== null;
    if (semanticRecallEnabled) {
      const hasVector = typeof data.vector === "string" && data.vector.length > 0;
      const hasEmbedder = typeof data.embedder === "string" && data.embedder.length > 0;
      return hasVector && hasEmbedder;
    }
    return true;
  },
  {
    message: "Semantic recall requires both vector and embedder to be configured",
    path: ["options", "semanticRecall"]
  }
);

// src/server/schemas/stored-agents.ts
var storedAgentIdPathParams = z2__default.default.object({
  storedAgentId: z2__default.default.string().describe("Unique identifier for the stored agent")
});
var storageOrderBySchema = z2__default.default.object({
  field: z2__default.default.enum(["createdAt", "updatedAt"]).optional(),
  direction: z2__default.default.enum(["ASC", "DESC"]).optional()
});
var listStoredAgentsQuerySchema = chunkMCYD5LW7_cjs.createPagePaginationSchema(100).extend({
  orderBy: storageOrderBySchema.optional(),
  authorId: z2__default.default.string().optional().describe("Filter agents by author identifier"),
  metadata: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional().describe("Filter agents by metadata key-value pairs")
});
var scorerConfigSchema = z2__default.default.object({
  sampling: z2__default.default.union([
    z2__default.default.object({ type: z2__default.default.literal("none") }),
    z2__default.default.object({ type: z2__default.default.literal("ratio"), rate: z2__default.default.number().min(0).max(1) })
  ]).optional()
});
var ruleSchema = z2__default.default.object({
  field: z2__default.default.string(),
  operator: z2__default.default.enum([
    "equals",
    "not_equals",
    "contains",
    "not_contains",
    "greater_than",
    "less_than",
    "greater_than_or_equal",
    "less_than_or_equal",
    "in",
    "not_in",
    "exists",
    "not_exists"
  ]),
  value: z2__default.default.unknown()
});
var ruleGroupDepth2 = z2__default.default.object({
  operator: z2__default.default.enum(["AND", "OR"]),
  conditions: z2__default.default.array(ruleSchema)
});
var ruleGroupDepth1 = z2__default.default.object({
  operator: z2__default.default.enum(["AND", "OR"]),
  conditions: z2__default.default.array(z2__default.default.union([ruleSchema, ruleGroupDepth2]))
});
var ruleGroupSchema = z2__default.default.object({
  operator: z2__default.default.enum(["AND", "OR"]),
  conditions: z2__default.default.array(z2__default.default.union([ruleSchema, ruleGroupDepth1]))
});
var agentInstructionBlockSchema = z2__default.default.discriminatedUnion("type", [
  z2__default.default.object({ type: z2__default.default.literal("text"), content: z2__default.default.string() }),
  z2__default.default.object({ type: z2__default.default.literal("prompt_block_ref"), id: z2__default.default.string() }),
  z2__default.default.object({ type: z2__default.default.literal("prompt_block"), content: z2__default.default.string(), rules: ruleGroupSchema.optional() })
]);
function conditionalFieldSchema(valueSchema) {
  const variantSchema = z2__default.default.object({
    value: valueSchema,
    rules: ruleGroupSchema.optional()
  });
  return z2__default.default.union([valueSchema, z2__default.default.array(variantSchema)]);
}
var instructionsSchema = z2__default.default.union([z2__default.default.string(), z2__default.default.array(agentInstructionBlockSchema)]).describe("System instructions for the agent (string or array of instruction blocks)");
var modelConfigSchema = z2__default.default.object({
  provider: z2__default.default.string().describe("Model provider (e.g., openai, anthropic)"),
  name: z2__default.default.string().describe("Model name (e.g., gpt-4o, claude-3-opus)")
}).passthrough();
var toolsConfigSchema = z2__default.default.record(z2__default.default.string(), z2__default.default.object({ description: z2__default.default.string().optional() }));
var mcpClientToolsConfigSchema = z2__default.default.object({
  tools: z2__default.default.record(z2__default.default.string(), z2__default.default.object({ description: z2__default.default.string().optional() })).optional()
});
var snapshotConfigSchema = z2__default.default.object({
  name: z2__default.default.string().describe("Name of the agent"),
  description: z2__default.default.string().optional().describe("Description of the agent"),
  instructions: instructionsSchema,
  model: conditionalFieldSchema(modelConfigSchema).describe(
    "Model configuration \u2014 static value or array of conditional variants"
  ),
  tools: conditionalFieldSchema(toolsConfigSchema).optional().describe("Tool keys mapped to per-tool config \u2014 static or conditional"),
  defaultOptions: conditionalFieldSchema(chunkCXL3KPGO_cjs.defaultOptionsSchema).optional().describe("Default options for generate/stream calls \u2014 static or conditional"),
  workflows: conditionalFieldSchema(z2__default.default.array(z2__default.default.string())).optional().describe("Array of workflow keys \u2014 static or conditional"),
  agents: conditionalFieldSchema(z2__default.default.array(z2__default.default.string())).optional().describe("Array of agent keys \u2014 static or conditional"),
  integrationTools: conditionalFieldSchema(z2__default.default.record(z2__default.default.string(), mcpClientToolsConfigSchema)).optional().describe("Map of tool provider IDs to their tool configurations \u2014 static or conditional"),
  mcpClients: conditionalFieldSchema(z2__default.default.record(z2__default.default.string(), mcpClientToolsConfigSchema)).optional().describe("Map of stored MCP client IDs to their tool configurations \u2014 static or conditional"),
  inputProcessors: conditionalFieldSchema(z2__default.default.array(z2__default.default.string())).optional().describe("Array of processor keys \u2014 static or conditional"),
  outputProcessors: conditionalFieldSchema(z2__default.default.array(z2__default.default.string())).optional().describe("Array of processor keys \u2014 static or conditional"),
  memory: conditionalFieldSchema(serializedMemoryConfigSchema).optional().describe("Memory configuration \u2014 static or conditional"),
  scorers: conditionalFieldSchema(z2__default.default.record(z2__default.default.string(), scorerConfigSchema)).optional().describe("Scorer keys with optional sampling config \u2014 static or conditional"),
  requestContextSchema: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional().describe("JSON Schema defining valid request context variables for conditional rule evaluation")
});
var agentMetadataSchema = z2__default.default.object({
  authorId: z2__default.default.string().optional().describe("Author identifier for multi-tenant filtering"),
  metadata: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional().describe("Additional metadata for the agent")
});
var createStoredAgentBodySchema = z2__default.default.object({
  id: z2__default.default.string().optional().describe("Unique identifier for the agent. If not provided, derived from name."),
  authorId: z2__default.default.string().optional().describe("Author identifier for multi-tenant filtering"),
  metadata: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional().describe("Additional metadata for the agent")
}).merge(snapshotConfigSchema);
var snapshotConfigUpdateSchema = snapshotConfigSchema.extend({
  memory: z2__default.default.union([conditionalFieldSchema(serializedMemoryConfigSchema), z2__default.default.null()]).optional().describe("Memory configuration \u2014 static, conditional, or null to disable memory")
});
var updateStoredAgentBodySchema = agentMetadataSchema.partial().merge(snapshotConfigUpdateSchema.partial());
var storedAgentSchema = z2__default.default.object({
  // Thin agent record fields
  id: z2__default.default.string(),
  status: z2__default.default.string().describe("Agent status: draft or published"),
  activeVersionId: z2__default.default.string().optional(),
  authorId: z2__default.default.string().optional(),
  metadata: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional(),
  createdAt: z2__default.default.coerce.date(),
  updatedAt: z2__default.default.coerce.date(),
  // Version snapshot config fields (resolved from active version)
  name: z2__default.default.string().describe("Name of the agent"),
  description: z2__default.default.string().optional().describe("Description of the agent"),
  instructions: instructionsSchema,
  model: conditionalFieldSchema(modelConfigSchema).describe(
    "Model configuration \u2014 static value or array of conditional variants"
  ),
  tools: conditionalFieldSchema(toolsConfigSchema).optional().describe("Tool keys mapped to per-tool config \u2014 static or conditional"),
  defaultOptions: conditionalFieldSchema(chunkCXL3KPGO_cjs.defaultOptionsSchema).optional().describe("Default options for generate/stream calls \u2014 static or conditional"),
  workflows: conditionalFieldSchema(z2__default.default.array(z2__default.default.string())).optional().describe("Array of workflow keys \u2014 static or conditional"),
  agents: conditionalFieldSchema(z2__default.default.array(z2__default.default.string())).optional().describe("Array of agent keys \u2014 static or conditional"),
  integrationTools: conditionalFieldSchema(z2__default.default.record(z2__default.default.string(), mcpClientToolsConfigSchema)).optional().describe("Map of tool provider IDs to their tool configurations \u2014 static or conditional"),
  mcpClients: conditionalFieldSchema(z2__default.default.record(z2__default.default.string(), mcpClientToolsConfigSchema)).optional().describe("Map of stored MCP client IDs to their tool configurations \u2014 static or conditional"),
  inputProcessors: conditionalFieldSchema(z2__default.default.array(z2__default.default.string())).optional().describe("Array of processor keys \u2014 static or conditional"),
  outputProcessors: conditionalFieldSchema(z2__default.default.array(z2__default.default.string())).optional().describe("Array of processor keys \u2014 static or conditional"),
  memory: conditionalFieldSchema(serializedMemoryConfigSchema).optional().describe("Memory configuration \u2014 static or conditional"),
  scorers: conditionalFieldSchema(z2__default.default.record(z2__default.default.string(), scorerConfigSchema)).optional().describe("Scorer keys with optional sampling config \u2014 static or conditional"),
  requestContextSchema: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional().describe("JSON Schema defining valid request context variables")
});
var listStoredAgentsResponseSchema = chunkMCYD5LW7_cjs.paginationInfoSchema.extend({
  agents: z2__default.default.array(storedAgentSchema)
});
var getStoredAgentResponseSchema = storedAgentSchema;
var createStoredAgentResponseSchema = storedAgentSchema;
var updateStoredAgentResponseSchema = z2__default.default.union([
  // Thin agent record (no version config)
  z2__default.default.object({
    id: z2__default.default.string(),
    status: z2__default.default.string(),
    activeVersionId: z2__default.default.string().optional(),
    authorId: z2__default.default.string().optional(),
    metadata: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional(),
    createdAt: z2__default.default.coerce.date(),
    updatedAt: z2__default.default.coerce.date()
  }),
  // Resolved agent (thin record + version config)
  storedAgentSchema
]);
var deleteStoredAgentResponseSchema = z2__default.default.object({
  success: z2__default.default.boolean(),
  message: z2__default.default.string()
});
var previewInstructionsBodySchema = z2__default.default.object({
  blocks: z2__default.default.array(agentInstructionBlockSchema).describe("Array of instruction blocks to resolve"),
  context: z2__default.default.record(z2__default.default.string(), z2__default.default.unknown()).optional().default({}).describe("Request context for variable interpolation and rule evaluation")
});
var previewInstructionsResponseSchema = z2__default.default.object({
  result: z2__default.default.string().describe("The resolved instructions string")
});

exports.conditionalFieldSchema = conditionalFieldSchema;
exports.createStoredAgentBodySchema = createStoredAgentBodySchema;
exports.createStoredAgentResponseSchema = createStoredAgentResponseSchema;
exports.deleteStoredAgentResponseSchema = deleteStoredAgentResponseSchema;
exports.getStoredAgentResponseSchema = getStoredAgentResponseSchema;
exports.instructionsSchema = instructionsSchema;
exports.listStoredAgentsQuerySchema = listStoredAgentsQuerySchema;
exports.listStoredAgentsResponseSchema = listStoredAgentsResponseSchema;
exports.modelConfigSchema = modelConfigSchema;
exports.previewInstructionsBodySchema = previewInstructionsBodySchema;
exports.previewInstructionsResponseSchema = previewInstructionsResponseSchema;
exports.scorerConfigSchema = scorerConfigSchema;
exports.serializedMemoryConfigSchema = serializedMemoryConfigSchema;
exports.storedAgentIdPathParams = storedAgentIdPathParams;
exports.toolsConfigSchema = toolsConfigSchema;
exports.updateStoredAgentBodySchema = updateStoredAgentBodySchema;
exports.updateStoredAgentResponseSchema = updateStoredAgentResponseSchema;
//# sourceMappingURL=chunk-LPSPYBX3.cjs.map
//# sourceMappingURL=chunk-LPSPYBX3.cjs.map