const require_chunk = require('./chunk-DWy1uDak.cjs');
const require_openai_provider = require('./openai-provider-DhSY7kTj.cjs');
const ai = require_chunk.__toESM(require("ai"));

//#region src/internal/agents/callEmbeddedAgent.ts
/**
* Call an embedded agent with tool call capture
* This is the standard way to call embedded AI agents within MCP tools
*
* Error handling:
* - Errors are re-thrown for the calling agent to handle
* - Each agent can implement its own error handling strategy
*/
async function callEmbeddedAgent({ system, prompt, tools, schema }) {
	const capturedToolCalls = [];
	const result = await (0, ai.generateText)({
		model: require_openai_provider.getOpenAIModel(),
		system,
		prompt,
		tools,
		maxSteps: 5,
		temperature: 1,
		experimental_output: ai.Output.object({ schema }),
		onStepFinish: (event) => {
			if (event.toolCalls && event.toolCalls.length > 0) for (const toolCall of event.toolCalls) capturedToolCalls.push({
				toolName: toolCall.toolName,
				args: toolCall.args
			});
		}
	});
	if (!result.experimental_output) throw new Error("Failed to generate output");
	return {
		result: result.experimental_output,
		toolCalls: capturedToolCalls
	};
}

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