const require_chunk = require('./chunk-DWy1uDak.cjs');
const require_errors = require('./errors-BtJEw2Z-.cjs');
const require_logging = require('./logging-CkAJKyq2.cjs');
const require_errors$1 = require('./errors-Bmqdg5Q6.cjs');
const zod = require_chunk.__toESM(require("zod"));
const ai = require_chunk.__toESM(require("ai"));

//#region src/internal/agents/tools/utils.ts
/**
* Standard response schema for all embedded agent tools.
* Tools return either an error message or the result data, never both.
*/
const AgentToolResponseSchema = zod.z.object({
	error: zod.z.string().optional().describe("Error message if the operation failed"),
	result: zod.z.unknown().optional().describe("The successful result data")
});
/**
* Handles errors from agent tool execution and returns appropriate error messages.
*
* SECURITY: Only returns trusted error messages to prevent prompt injection.
* We trust: Sentry API errors, our own UserInputError messages, and system templates.
*/
function handleAgentToolError(error) {
	if (error instanceof require_errors.UserInputError) {
		require_logging.logWarn(error, {
			loggerScope: ["agent-tools", "user-input"],
			contexts: { agentTool: { errorType: "UserInputError" } }
		});
		return { error: `Input Error: ${error.message}. You may be able to resolve this by addressing the concern and trying again.` };
	}
	if (error instanceof require_errors$1.ApiClientError) {
		const message = error.toUserMessage();
		require_logging.logWarn(message, {
			loggerScope: ["agent-tools", "api-client"],
			contexts: { agentTool: {
				errorType: error.name,
				status: error.status ?? null
			} }
		});
		return { error: `Input Error: ${message}. You may be able to resolve this by addressing the concern and trying again.` };
	}
	if (error instanceof require_errors$1.ApiServerError) {
		const eventId$1 = require_logging.logIssue(error);
		const statusText = error.status ? ` (${error.status})` : "";
		return { error: `Server Error${statusText}: ${error.message}. Event ID: ${eventId$1}. This is a system error that cannot be resolved by retrying.` };
	}
	const eventId = require_logging.logIssue(error);
	return { error: `System Error: An unexpected error occurred. Event ID: ${eventId}. This is a system error that cannot be resolved by retrying.` };
}
/**
* Creates an embedded agent tool with automatic error handling and schema wrapping.
*
* This wrapper:
* - Maintains the same API as the AI SDK's tool() function
* - Automatically wraps the result schema with error/result structure
* - Handles all error types and returns them as structured responses
* - Preserves type inference from the original tool implementation
*
* @example
* ```typescript
* export function createMyTool(apiService: SentryApiService) {
*   return agentTool({
*     description: "My tool description",
*     parameters: z.object({ param: z.string() }),
*     execute: async (params) => {
*       // Tool implementation that might throw errors
*       const result = await apiService.someMethod(params);
*       return result; // Original return type preserved
*     }
*   });
* }
* ```
*/
function agentTool(config) {
	return (0, ai.tool)({
		description: config.description,
		parameters: config.parameters,
		execute: async (params) => {
			try {
				const result = await config.execute(params);
				return { result };
			} catch (error) {
				return handleAgentToolError(error);
			}
		}
	});
}

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