"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var transform_exports = {};
__export(transform_exports, {
  transformComputerUseDataToDump: () => transformComputerUseDataToDump
});
module.exports = __toCommonJS(transform_exports);
var import_buffer = __toESM(require("buffer"));
var import_browser = __toESM(require("process/browser"));
var import_console_browserify = __toESM(require("console-browserify"));
var buffer = {
  Buffer: import_buffer.default
};
const addBase64ImagePrefix = (base64) => {
  if (!base64)
    return "";
  return base64.startsWith("data:") ? base64 : `data:image/png;base64,${base64}`;
};
function transformComputerUseDataToDump(data) {
  return {
    groupName: data.instruction,
    groupDescription: "",
    executions: [
      {
        sdkVersion: data.version,
        model_name: data.modelName,
        logTime: data.logTime,
        name: data.instruction,
        tasks: data.conversations.map((conv) => {
          var _a;
          if (conv.from === "human" && conv.value === "<image>") {
            return {
              status: "finished",
              type: "screenshot",
              timing: conv.timing,
              pageContext: {
                screenshotBase64: addBase64ImagePrefix(
                  conv.screenshotBase64 || ""
                ),
                screenshotBase64WithElementMarker: addBase64ImagePrefix(
                  conv.screenshotBase64WithElementMarker || ""
                ),
                size: ((_a = conv.screenshotContext) == null ? void 0 : _a.size) || { width: 0, height: 0 }
              },
              recorder: [
                {
                  type: "screenshot",
                  ts: conv.timing.start,
                  screenshot: addBase64ImagePrefix(
                    conv.screenshotBase64 || ""
                  ),
                  timing: "before screenshot"
                }
              ]
            };
          }
          if (conv.from === "gpt") {
            return {
              status: "finished",
              type: "Action",
              timing: conv.timing,
              recorder: [
                ...conv.screenshotBase64 ? [
                  {
                    type: "screenshot",
                    ts: conv.timing.start,
                    screenshot: addBase64ImagePrefix(
                      conv.screenshotBase64 || ""
                    ),
                    timing: "before screenshot"
                  }
                ] : [],
                ...conv.screenshotBase64WithElementMarker ? [
                  {
                    type: "screenshot",
                    ts: conv.timing.start,
                    screenshot: addBase64ImagePrefix(
                      conv.screenshotBase64WithElementMarker || ""
                    ),
                    timing: "after screenshot"
                  }
                ] : []
              ]
            };
          }
          return null;
        }).filter(
          (task) => task !== null
        )
      }
    ],
    attributes: {}
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  transformComputerUseDataToDump
});
