//#region src/utils/mock-provider.ts
function extractLastUserMessage(prompt) {
	for (let i = prompt.length - 1; i >= 0; i--) {
		const msg = prompt[i];
		if (msg.role === "user") {
			for (const part of msg.content) if (part.type === "text") return part.text.length > 200 ? `${part.text.slice(0, 200)}...` : part.text;
		}
	}
	return "(no user message)";
}
function countInputChars(prompt) {
	let chars = 0;
	for (const msg of prompt) if ("content" in msg) {
		if (typeof msg.content === "string") chars += msg.content.length;
		else if (Array.isArray(msg.content)) {
			for (const part of msg.content) if ("text" in part) chars += part.text.length;
		}
	}
	return chars;
}
function buildMockResponse(modelName, prompt) {
	const lastUserMessage = extractLastUserMessage(prompt);
	const timestamp = (/* @__PURE__ */ new Date()).toISOString();
	return [
		"Mock response.",
		`Model: mock/${modelName}`,
		`Input messages: ${prompt.length}`,
		`Last user message: "${lastUserMessage}"`,
		`Timestamp: ${timestamp}`
	].join("\n");
}
var MockLanguageModel = class {
	specificationVersion = "v2";
	defaultObjectGenerationMode = void 0;
	supportsImageUrls = false;
	supportedUrls = {};
	provider = "mock";
	modelId;
	constructor(modelId) {
		this.modelId = modelId;
	}
	async doGenerate(options) {
		const responseText = buildMockResponse(this.modelId, options.prompt);
		const inputTokens = Math.ceil(countInputChars(options.prompt) / 4);
		const outputTokens = Math.ceil(responseText.length / 4);
		return {
			content: [{
				type: "text",
				text: responseText
			}],
			finishReason: "stop",
			usage: {
				inputTokens,
				outputTokens,
				totalTokens: inputTokens + outputTokens
			},
			rawCall: {
				rawPrompt: options.prompt,
				rawSettings: {}
			},
			warnings: []
		};
	}
	async doStream(options) {
		const responseText = buildMockResponse(this.modelId, options.prompt);
		const lines = responseText.split("\n");
		const inputTokens = Math.ceil(countInputChars(options.prompt) / 4);
		const outputTokens = Math.ceil(responseText.length / 4);
		return {
			stream: new ReadableStream({ async start(controller) {
				controller.enqueue({
					type: "stream-start",
					warnings: []
				});
				const textId = "mock-text-0";
				controller.enqueue({
					type: "text-start",
					id: textId
				});
				for (let i = 0; i < lines.length; i++) {
					const delta = i < lines.length - 1 ? `${lines[i]}\n` : lines[i];
					controller.enqueue({
						type: "text-delta",
						id: textId,
						delta
					});
					if (i < lines.length - 1) await new Promise((resolve) => setTimeout(resolve, 5));
				}
				controller.enqueue({
					type: "text-end",
					id: textId
				});
				controller.enqueue({
					type: "finish",
					finishReason: "stop",
					usage: {
						inputTokens,
						outputTokens,
						totalTokens: inputTokens + outputTokens
					}
				});
				controller.close();
			} }),
			rawCall: {
				rawPrompt: options.prompt,
				rawSettings: {}
			},
			warnings: []
		};
	}
};
function createMockModel(modelId) {
	return new MockLanguageModel(modelId);
}

//#endregion
export { MockLanguageModel, createMockModel };