const require_chunk = require('./chunk-DWy1uDak.cjs');
const require_errors = require('./errors-BtJEw2Z-.cjs');
const require_callEmbeddedAgent = require('./callEmbeddedAgent-KKTSTD7W.cjs');
const require_otel_semantics = require('./otel-semantics-onvZv7i9.cjs');
const require_whoami = require('./whoami-DBSqcCGl.cjs');
const require_utils = require('./utils-C5DuiZoe.cjs');
const require_config = require('./config-CllFlx5w.cjs');
const zod = require_chunk.__toESM(require("zod"));

//#region src/tools/search-events/agent.ts
const outputSchema = zod.z.object({
	dataset: zod.z.enum([
		"spans",
		"errors",
		"logs"
	]).describe("Which dataset to use for the query"),
	query: zod.z.string().default("").nullish().describe("The Sentry query string for filtering results"),
	fields: zod.z.array(zod.z.string()).describe("Array of field names to return in results."),
	sort: zod.z.string().describe("Sort parameter for results."),
	timeRange: zod.z.union([zod.z.object({ statsPeriod: zod.z.string().describe("Relative time period like '1h', '24h', '7d'") }), zod.z.object({
		start: zod.z.string().describe("ISO 8601 start time"),
		end: zod.z.string().describe("ISO 8601 end time")
	})]).nullish().describe("Time range for filtering events. Use either statsPeriod for relative time or start/end for absolute time."),
	explanation: zod.z.string().describe("Brief explanation of how you translated this query.")
}).refine((data) => {
	if (!data.sort || !data.fields || data.fields.length === 0) return true;
	const sortField = data.sort.startsWith("-") ? data.sort.substring(1) : data.sort;
	return data.fields.includes(sortField);
}, { message: "Sort field must be included in the fields array. Sentry requires that any field used for sorting must also be explicitly selected. Add the sort field to the fields array or choose a different sort field that's already included." });
/**
* Search events agent - single entry point for translating natural language queries to Sentry search syntax
* This returns both the translated query result AND the tool calls made by the agent
*/
async function searchEventsAgent(options) {
	if (!process.env.OPENAI_API_KEY) throw new require_errors.ConfigurationError("OPENAI_API_KEY environment variable is required for semantic search");
	const datasetAttributesTool = require_utils.createDatasetAttributesTool({
		apiService: options.apiService,
		organizationSlug: options.organizationSlug,
		projectId: options.projectId
	});
	const otelLookupTool = require_otel_semantics.createOtelLookupTool({
		apiService: options.apiService,
		organizationSlug: options.organizationSlug,
		projectId: options.projectId
	});
	const whoamiTool = require_whoami.createWhoamiTool({ apiService: options.apiService });
	return await require_callEmbeddedAgent.callEmbeddedAgent({
		system: require_config.systemPrompt,
		prompt: options.query,
		tools: {
			datasetAttributes: datasetAttributesTool,
			otelSemantics: otelLookupTool,
			whoami: whoamiTool
		},
		schema: outputSchema
	});
}

//#endregion
Object.defineProperty(exports, 'searchEventsAgent', {
  enumerable: true,
  get: function () {
    return searchEventsAgent;
  }
});
//# sourceMappingURL=agent-DzfX6_dM.cjs.map