'use strict';

var chunkUH3MHVDF_cjs = require('./chunk-UH3MHVDF.cjs');
var chunk24YYB3J7_cjs = require('./chunk-24YYB3J7.cjs');
var chunkPFKYMKIH_cjs = require('./chunk-PFKYMKIH.cjs');
var chunkDIG2K5CV_cjs = require('./chunk-DIG2K5CV.cjs');
var v4 = require('zod/v4');

var semanticRecallSchema = v4.z.object({
  topK: v4.z.number().describe("Number of semantically similar messages to retrieve"),
  messageRange: v4.z.union([
    v4.z.number(),
    v4.z.object({
      before: v4.z.number(),
      after: v4.z.number()
    })
  ]).describe("Amount of surrounding context to include with each retrieved message"),
  scope: v4.z.enum(["thread", "resource"]).optional().describe("Scope for semantic search queries"),
  threshold: v4.z.number().min(0).max(1).optional().describe("Minimum similarity score threshold"),
  indexName: v4.z.string().optional().describe("Index name for the vector store")
});
var titleGenerationSchema = v4.z.union([
  v4.z.boolean(),
  v4.z.object({
    model: v4.z.string().describe("Model ID in format provider/model-name (ModelRouterModelId)"),
    instructions: v4.z.string().optional().describe("Custom instructions for title generation")
  })
]);
var serializedObservationConfigSchema = v4.z.object({
  model: v4.z.string().optional().describe("Observer model ID"),
  messageTokens: v4.z.number().optional().describe("Token threshold that triggers observation"),
  modelSettings: v4.z.record(v4.z.string(), v4.z.unknown()).optional().describe("Model settings (temperature, etc.)"),
  providerOptions: v4.z.record(v4.z.string(), v4.z.record(v4.z.string(), v4.z.unknown()).optional()).optional().describe("Provider-specific options"),
  maxTokensPerBatch: v4.z.number().optional().describe("Maximum tokens per batch"),
  bufferTokens: v4.z.union([v4.z.number(), v4.z.literal(false)]).optional().describe("Async buffering interval or false"),
  bufferActivation: v4.z.number().optional().describe("Ratio of buffered observations to activate"),
  blockAfter: v4.z.number().optional().describe("Token threshold for synchronous blocking")
});
var serializedReflectionConfigSchema = v4.z.object({
  model: v4.z.string().optional().describe("Reflector model ID"),
  observationTokens: v4.z.number().optional().describe("Token threshold that triggers reflection"),
  modelSettings: v4.z.record(v4.z.string(), v4.z.unknown()).optional().describe("Model settings (temperature, etc.)"),
  providerOptions: v4.z.record(v4.z.string(), v4.z.record(v4.z.string(), v4.z.unknown()).optional()).optional().describe("Provider-specific options"),
  blockAfter: v4.z.number().optional().describe("Token threshold for synchronous blocking"),
  bufferActivation: v4.z.number().optional().describe("Ratio for async reflection buffering")
});
var serializedObservationalMemoryConfigObjectSchema = v4.z.object({
  model: v4.z.string().optional().describe("Model ID for both Observer and Reflector"),
  scope: v4.z.enum(["resource", "thread"]).optional().describe("Memory scope"),
  shareTokenBudget: v4.z.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 = v4.z.union([
  v4.z.boolean(),
  serializedObservationalMemoryConfigObjectSchema
]);
var serializedMemoryConfigSchema = v4.z.object({
  vector: v4.z.union([v4.z.string(), v4.z.literal(false)]).optional().describe("Vector database identifier or false to disable"),
  options: v4.z.object({
    readOnly: v4.z.boolean().optional(),
    lastMessages: v4.z.union([v4.z.number(), v4.z.literal(false)]).optional(),
    semanticRecall: v4.z.union([v4.z.boolean(), semanticRecallSchema]).optional(),
    generateTitle: titleGenerationSchema.optional()
  }).optional().describe("Memory behavior configuration, excluding workingMemory and threads"),
  embedder: v4.z.string().optional().describe('Embedding model ID in the format "provider/model" (e.g., "openai/text-embedding-3-small")'),
  embedderOptions: v4.z.record(v4.z.string(), v4.z.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"]
  }
);
var storedAgentIdPathParams = v4.z.object({
  storedAgentId: v4.z.string().describe("Unique identifier for the stored agent")
});
var storageOrderBySchema = v4.z.object({
  field: v4.z.enum(["createdAt", "updatedAt"]).optional(),
  direction: v4.z.enum(["ASC", "DESC"]).optional()
});
var listStoredAgentsQuerySchema = chunkDIG2K5CV_cjs.createPagePaginationSchema(100).extend({
  orderBy: storageOrderBySchema.optional(),
  status: v4.z.enum(["draft", "published", "archived"]).optional().default("published").describe("Filter agents by status (defaults to published)"),
  authorId: v4.z.string().optional().describe("Filter agents by author identifier"),
  metadata: v4.z.record(v4.z.string(), v4.z.unknown()).optional().describe("Filter agents by metadata key-value pairs")
});
var scorerConfigSchema = v4.z.object({
  description: v4.z.string().optional(),
  sampling: v4.z.union([
    v4.z.object({ type: v4.z.literal("none") }),
    v4.z.object({ type: v4.z.literal("ratio"), rate: v4.z.number().min(0).max(1) })
  ]).optional(),
  rules: chunk24YYB3J7_cjs.ruleGroupSchema.optional()
});
var agentInstructionBlockSchema = v4.z.discriminatedUnion("type", [
  v4.z.object({ type: v4.z.literal("text"), content: v4.z.string() }),
  v4.z.object({ type: v4.z.literal("prompt_block_ref"), id: v4.z.string() }),
  v4.z.object({ type: v4.z.literal("prompt_block"), content: v4.z.string(), rules: chunk24YYB3J7_cjs.ruleGroupSchema.optional() })
]);
function conditionalFieldSchema(valueSchema) {
  const variantSchema = v4.z.object({
    value: valueSchema,
    rules: chunk24YYB3J7_cjs.ruleGroupSchema.optional()
  });
  return v4.z.union([valueSchema, v4.z.array(variantSchema)]);
}
var instructionsSchema = v4.z.union([v4.z.string(), v4.z.array(agentInstructionBlockSchema)]).describe("System instructions for the agent (string or array of instruction blocks)");
var modelConfigSchema = v4.z.object({
  provider: v4.z.string().describe("Model provider (e.g., openai, anthropic)"),
  name: v4.z.string().describe("Model name (e.g., gpt-4o, claude-3-opus)")
}).passthrough();
var toolConfigSchema = v4.z.object({ description: v4.z.string().optional(), rules: chunk24YYB3J7_cjs.ruleGroupSchema.optional() });
var toolsConfigSchema = v4.z.record(v4.z.string(), toolConfigSchema);
var mcpClientToolsConfigSchema = v4.z.object({
  tools: v4.z.record(v4.z.string(), toolConfigSchema).optional()
});
var skillConfigSchema = v4.z.object({
  description: v4.z.string().optional(),
  instructions: v4.z.string().optional(),
  pin: v4.z.string().optional(),
  strategy: v4.z.enum(["latest", "live"]).optional()
});
var skillsConfigSchema = v4.z.record(v4.z.string(), skillConfigSchema);
var workspaceRefSchema = v4.z.discriminatedUnion("type", [
  v4.z.object({ type: v4.z.literal("id"), workspaceId: v4.z.string() }),
  v4.z.object({ type: v4.z.literal("inline"), config: chunkUH3MHVDF_cjs.snapshotConfigSchema })
]);
var processorPhaseSchema = v4.z.enum([
  "processInput",
  "processInputStep",
  "processOutputStream",
  "processOutputResult",
  "processOutputStep"
]);
var processorGraphStepSchema = v4.z.object({
  id: v4.z.string().describe("Unique ID for this step within the graph"),
  providerId: v4.z.string().describe("ProcessorProvider ID that creates this processor"),
  config: v4.z.record(v4.z.string(), v4.z.unknown()).describe("Configuration matching the provider configSchema"),
  enabledPhases: v4.z.array(processorPhaseSchema).min(1).describe("Which processor phases to enable")
});
var processorGraphEntryDepth3 = v4.z.discriminatedUnion("type", [
  v4.z.object({ type: v4.z.literal("step"), step: processorGraphStepSchema })
]);
var processorGraphEntryDepth2 = v4.z.discriminatedUnion("type", [
  v4.z.object({ type: v4.z.literal("step"), step: processorGraphStepSchema }),
  v4.z.object({ type: v4.z.literal("parallel"), branches: v4.z.array(v4.z.array(processorGraphEntryDepth3)) }),
  v4.z.object({
    type: v4.z.literal("conditional"),
    conditions: v4.z.array(
      v4.z.object({
        steps: v4.z.array(processorGraphEntryDepth3),
        rules: chunk24YYB3J7_cjs.ruleGroupSchema.optional()
      })
    )
  })
]);
var processorGraphEntrySchema = v4.z.discriminatedUnion("type", [
  v4.z.object({ type: v4.z.literal("step"), step: processorGraphStepSchema }),
  v4.z.object({ type: v4.z.literal("parallel"), branches: v4.z.array(v4.z.array(processorGraphEntryDepth2)) }),
  v4.z.object({
    type: v4.z.literal("conditional"),
    conditions: v4.z.array(
      v4.z.object({
        steps: v4.z.array(processorGraphEntryDepth2),
        rules: chunk24YYB3J7_cjs.ruleGroupSchema.optional()
      })
    )
  })
]);
var storedProcessorGraphSchema = v4.z.object({
  steps: v4.z.array(processorGraphEntrySchema).describe("Ordered list of processor graph entries")
});
var snapshotConfigSchema2 = v4.z.object({
  name: v4.z.string().describe("Name of the agent"),
  description: v4.z.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(chunkPFKYMKIH_cjs.defaultOptionsSchema).optional().describe("Default options for generate/stream calls \u2014 static or conditional"),
  workflows: conditionalFieldSchema(v4.z.record(v4.z.string(), toolConfigSchema)).optional().describe("Workflow keys with optional per-workflow config \u2014 static or conditional"),
  agents: conditionalFieldSchema(v4.z.record(v4.z.string(), toolConfigSchema)).optional().describe("Agent keys with optional per-agent config \u2014 static or conditional"),
  integrationTools: conditionalFieldSchema(v4.z.record(v4.z.string(), mcpClientToolsConfigSchema)).optional().describe("Map of tool provider IDs to their tool configurations \u2014 static or conditional"),
  mcpClients: conditionalFieldSchema(v4.z.record(v4.z.string(), mcpClientToolsConfigSchema)).optional().describe("Map of stored MCP client IDs to their tool configurations \u2014 static or conditional"),
  inputProcessors: conditionalFieldSchema(storedProcessorGraphSchema).optional().describe("Input processor graph \u2014 static or conditional"),
  outputProcessors: conditionalFieldSchema(storedProcessorGraphSchema).optional().describe("Output processor graph \u2014 static or conditional"),
  memory: conditionalFieldSchema(serializedMemoryConfigSchema).optional().describe("Memory configuration \u2014 static or conditional"),
  scorers: conditionalFieldSchema(v4.z.record(v4.z.string(), scorerConfigSchema)).optional().describe("Scorer keys with optional sampling config \u2014 static or conditional"),
  skills: conditionalFieldSchema(skillsConfigSchema).optional().describe("Skill IDs mapped to per-skill config \u2014 static or conditional"),
  workspace: conditionalFieldSchema(workspaceRefSchema).optional().describe("Workspace reference (stored ID or inline config) \u2014 static or conditional"),
  requestContextSchema: v4.z.record(v4.z.string(), v4.z.unknown()).optional().describe("JSON Schema defining valid request context variables for conditional rule evaluation")
});
var agentMetadataSchema = v4.z.object({
  authorId: v4.z.string().optional().describe("Author identifier for multi-tenant filtering"),
  metadata: v4.z.record(v4.z.string(), v4.z.unknown()).optional().describe("Additional metadata for the agent")
});
var createStoredAgentBodySchema = v4.z.object({
  id: v4.z.string().optional().describe("Unique identifier for the agent. If not provided, derived from name."),
  authorId: v4.z.string().optional().describe("Author identifier for multi-tenant filtering"),
  metadata: v4.z.record(v4.z.string(), v4.z.unknown()).optional().describe("Additional metadata for the agent")
}).merge(snapshotConfigSchema2);
var snapshotConfigUpdateSchema = snapshotConfigSchema2.extend({
  memory: v4.z.union([conditionalFieldSchema(serializedMemoryConfigSchema), v4.z.null()]).optional().describe("Memory configuration \u2014 static, conditional, or null to disable memory")
});
var updateStoredAgentBodySchema = agentMetadataSchema.partial().merge(snapshotConfigUpdateSchema.partial()).extend({
  changeMessage: v4.z.string().trim().max(500).optional().describe("Optional message describing the changes for the auto-created version")
});
var storedAgentSchema = v4.z.object({
  // Thin agent record fields
  id: v4.z.string(),
  status: v4.z.string().describe("Agent status: draft or published"),
  activeVersionId: v4.z.string().optional(),
  authorId: v4.z.string().optional(),
  metadata: v4.z.record(v4.z.string(), v4.z.unknown()).optional(),
  createdAt: v4.z.coerce.date(),
  updatedAt: v4.z.coerce.date(),
  // Version snapshot config fields (resolved from active version)
  name: v4.z.string().describe("Name of the agent"),
  description: v4.z.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(chunkPFKYMKIH_cjs.defaultOptionsSchema).optional().describe("Default options for generate/stream calls \u2014 static or conditional"),
  workflows: conditionalFieldSchema(v4.z.record(v4.z.string(), toolConfigSchema)).optional().describe("Workflow keys with optional per-workflow config \u2014 static or conditional"),
  agents: conditionalFieldSchema(v4.z.record(v4.z.string(), toolConfigSchema)).optional().describe("Agent keys with optional per-agent config \u2014 static or conditional"),
  integrationTools: conditionalFieldSchema(v4.z.record(v4.z.string(), mcpClientToolsConfigSchema)).optional().describe("Map of tool provider IDs to their tool configurations \u2014 static or conditional"),
  mcpClients: conditionalFieldSchema(v4.z.record(v4.z.string(), mcpClientToolsConfigSchema)).optional().describe("Map of stored MCP client IDs to their tool configurations \u2014 static or conditional"),
  inputProcessors: conditionalFieldSchema(storedProcessorGraphSchema).optional().describe("Input processor graph \u2014 static or conditional"),
  outputProcessors: conditionalFieldSchema(storedProcessorGraphSchema).optional().describe("Output processor graph \u2014 static or conditional"),
  memory: conditionalFieldSchema(serializedMemoryConfigSchema).optional().describe("Memory configuration \u2014 static or conditional"),
  scorers: conditionalFieldSchema(v4.z.record(v4.z.string(), scorerConfigSchema)).optional().describe("Scorer keys with optional sampling config \u2014 static or conditional"),
  skills: conditionalFieldSchema(skillsConfigSchema).optional().describe("Skill IDs mapped to per-skill config \u2014 static or conditional"),
  workspace: conditionalFieldSchema(workspaceRefSchema).optional().describe("Workspace reference (stored ID or inline config) \u2014 static or conditional"),
  requestContextSchema: v4.z.record(v4.z.string(), v4.z.unknown()).optional().describe("JSON Schema defining valid request context variables")
});
var listStoredAgentsResponseSchema = chunkDIG2K5CV_cjs.paginationInfoSchema.extend({
  agents: v4.z.array(storedAgentSchema)
});
var getStoredAgentResponseSchema = storedAgentSchema;
var createStoredAgentResponseSchema = storedAgentSchema;
var updateStoredAgentResponseSchema = v4.z.union([
  // Thin agent record (no version config)
  v4.z.object({
    id: v4.z.string(),
    status: v4.z.string(),
    activeVersionId: v4.z.string().optional(),
    authorId: v4.z.string().optional(),
    metadata: v4.z.record(v4.z.string(), v4.z.unknown()).optional(),
    createdAt: v4.z.coerce.date(),
    updatedAt: v4.z.coerce.date()
  }),
  // Resolved agent (thin record + version config)
  storedAgentSchema
]);
var deleteStoredAgentResponseSchema = v4.z.object({
  success: v4.z.boolean(),
  message: v4.z.string()
});
var previewInstructionsBodySchema = v4.z.object({
  blocks: v4.z.array(agentInstructionBlockSchema).describe("Array of instruction blocks to resolve"),
  context: v4.z.record(v4.z.string(), v4.z.unknown()).optional().default({}).describe("Request context for variable interpolation and rule evaluation")
});
var previewInstructionsResponseSchema = v4.z.object({
  result: v4.z.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.processorGraphEntrySchema = processorGraphEntrySchema;
exports.processorGraphStepSchema = processorGraphStepSchema;
exports.processorPhaseSchema = processorPhaseSchema;
exports.scorerConfigSchema = scorerConfigSchema;
exports.semanticRecallSchema = semanticRecallSchema;
exports.serializedMemoryConfigSchema = serializedMemoryConfigSchema;
exports.serializedObservationConfigSchema = serializedObservationConfigSchema;
exports.serializedObservationalMemoryConfigObjectSchema = serializedObservationalMemoryConfigObjectSchema;
exports.serializedObservationalMemoryConfigSchema = serializedObservationalMemoryConfigSchema;
exports.serializedReflectionConfigSchema = serializedReflectionConfigSchema;
exports.snapshotConfigSchema = snapshotConfigSchema2;
exports.storedAgentIdPathParams = storedAgentIdPathParams;
exports.storedAgentSchema = storedAgentSchema;
exports.storedProcessorGraphSchema = storedProcessorGraphSchema;
exports.titleGenerationSchema = titleGenerationSchema;
exports.toolConfigSchema = toolConfigSchema;
exports.toolsConfigSchema = toolsConfigSchema;
exports.updateStoredAgentBodySchema = updateStoredAgentBodySchema;
exports.updateStoredAgentResponseSchema = updateStoredAgentResponseSchema;
//# sourceMappingURL=chunk-WYLVJSGR.cjs.map
//# sourceMappingURL=chunk-WYLVJSGR.cjs.map