"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/testing.ts
var testing_exports = {};
__export(testing_exports, {
  buildAssistantTurnFrames: () => buildAssistantTurnFrames,
  createMockSSEResponse: () => createMockSSEResponse,
  createMockSSEStream: () => createMockSSEStream
});
module.exports = __toCommonJS(testing_exports);

// 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
    }
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildAssistantTurnFrames,
  createMockSSEResponse,
  createMockSSEStream
});
