import { snapshotConfigSchema } from './chunk-Z6C7SDXA.js';
import { ruleGroupSchema } from './chunk-JA4UAHWP.js';
import { defaultOptionsSchema } from './chunk-TKP6FJQ3.js';
import { createPagePaginationSchema, paginationInfoSchema } from './chunk-2YY3EMMS.js';
import { z } from 'zod/v4';

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

export { conditionalFieldSchema, createStoredAgentBodySchema, createStoredAgentResponseSchema, deleteStoredAgentResponseSchema, getStoredAgentResponseSchema, instructionsSchema, listStoredAgentsQuerySchema, listStoredAgentsResponseSchema, modelConfigSchema, previewInstructionsBodySchema, previewInstructionsResponseSchema, processorGraphEntrySchema, processorGraphStepSchema, processorPhaseSchema, scorerConfigSchema, semanticRecallSchema, serializedMemoryConfigSchema, serializedObservationConfigSchema, serializedObservationalMemoryConfigObjectSchema, serializedObservationalMemoryConfigSchema, serializedReflectionConfigSchema, snapshotConfigSchema2 as snapshotConfigSchema, storedAgentIdPathParams, storedAgentSchema, storedProcessorGraphSchema, titleGenerationSchema, toolConfigSchema, toolsConfigSchema, updateStoredAgentBodySchema, updateStoredAgentResponseSchema };
//# sourceMappingURL=chunk-AIRSK4QU.js.map
//# sourceMappingURL=chunk-AIRSK4QU.js.map