// src/testing/mock-stream.ts
var encoder = new TextEncoder();
function createMockSSEStream(frames, options) {
  var _a;
  const delayMs = (_a = options == null ? void 0 : options.delayMs) != null ? _a : 100;
  const prefix = (options == null ? void 0 : options.eventName) ? `event: ${options.eventName}
` : "";
  let index = 0;
  return new ReadableStream({
    async pull(controller) {
      if (index >= frames.length) {
        controller.close();
        return;
      }
      await new Promise((resolve) => setTimeout(resolve, delayMs));
      const payload = JSON.stringify(frames[index]);
      controller.enqueue(encoder.encode(`${prefix}data: ${payload}

`));
      index += 1;
    }
  });
}
function buildAssistantTurnFrames(options) {
  var _a, _b;
  const { executionId, text } = options;
  const turnId = (_a = options.turnId) != null ? _a : "turn-1";
  const chunkSize = Math.max(1, (_b = options.chunkSize) != null ? _b : 32);
  const frames = [{ type: "agent_turn_start", executionId, turnId }];
  for (let i = 0; i < text.length; i += chunkSize) {
    frames.push({
      type: "agent_turn_delta",
      executionId,
      turnId,
      delta: text.slice(i, i + chunkSize)
    });
  }
  frames.push({ type: "agent_turn_complete", executionId, turnId });
  return frames;
}
function createMockSSEResponse(frames, options) {
  var _a;
  const stream = createMockSSEStream(frames, options);
  return new Response(stream, {
    status: (_a = options == null ? void 0 : options.status) != null ? _a : 200,
    headers: {
      "Content-Type": "text/event-stream",
      ...options == null ? void 0 : options.headers
    }
  });
}
export {
  buildAssistantTurnFrames,
  createMockSSEResponse,
  createMockSSEStream
};
