{
  "info": {
    "_postman_id": "20bd4075-5075-40dd-a97a-a25055870524",
    "name": "Replicant Space Starter",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "_exporter_id": "37941122"
  },
  "item": [
    {
      "name": "My Account",
      "item": [
        {
          "name": "Register New Account",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "auth": {
              "type": "noauth"
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"email\": \"you@example.com\",\n    \"name\": \"player\",\n    \"timezone\": \"Europe/London\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/accounts",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "accounts"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Recover Existing",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "// Extract api_token from response and store as collection variable for reuse",
                  "pm.test(\"Status code is 201\", function () {",
                  "  pm.response.to.have.status(201);",
                  "});",
                  "",
                  "pm.test(\"Response contains api_token\", function () {",
                  "  const json = pm.response.json();",
                  "  pm.expect(json).to.have.property(\"api_token\");",
                  "  pm.expect(json.api_token).to.be.a(\"string\").and.to.have.length.greaterThan(0);",
                  "",
                  "  // Save token at collection scope so other requests can inherit/use it",
                  "  pm.collectionVariables.set(\"bearerToken\", json.api_token);",
                  "});",
                  "",
                  "pm.test(\"Response contains replicant_code\", function () {",
                  "  const json = pm.response.json();",
                  "  pm.expect(json).to.have.property(\"replicant\");",
                  "  pm.expect(json.replicant).to.be.an(\"object\");",
                  "  pm.expect(json.replicant).to.have.property(\"replicant_code\");",
                  "  pm.expect(json.replicant.replicant_code)",
                  "    .to.be.a(\"string\")",
                  "    .and.to.have.length.greaterThan(0);",
                  "",
                  "  // Save replicant code at collection scope for reuse",
                  "  pm.collectionVariables.set(\"replicantCode\", json.replicant.replicant_code);",
                  "});",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "auth": {
              "type": "noauth"
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"email\": \"you@example.com\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/accounts/recover",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "accounts",
                "recover"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Set Webhook",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "// Extract api_token from response and store as collection variable for reuse",
                  "pm.test(\"Status code is 201\", function () {",
                  "  pm.response.to.have.status(201);",
                  "});",
                  "",
                  "pm.test(\"Response contains api_token\", function () {",
                  "  const json = pm.response.json();",
                  "  pm.expect(json).to.have.property(\"api_token\");",
                  "  pm.expect(json.api_token).to.be.a(\"string\").and.to.have.length.greaterThan(0);",
                  "",
                  "  // Save token at collection scope so other requests can inherit/use it",
                  "  pm.collectionVariables.set(\"bearerToken\", json.api_token);",
                  "});",
                  "",
                  "pm.test(\"Response contains replicant_code\", function () {",
                  "  const json = pm.response.json();",
                  "  pm.expect(json).to.have.property(\"replicant\");",
                  "  pm.expect(json.replicant).to.be.an(\"object\");",
                  "  pm.expect(json.replicant).to.have.property(\"replicant_code\");",
                  "  pm.expect(json.replicant.replicant_code)",
                  "    .to.be.a(\"string\")",
                  "    .and.to.have.length.greaterThan(0);",
                  "",
                  "  // Save replicant code at collection scope for reuse",
                  "  pm.collectionVariables.set(\"replicantCode\", json.replicant.replicant_code);",
                  "});",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"url\": \"https://webhooks.replicant.space/webhook/....\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/accounts/webhook",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "accounts",
                "webhook"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Info",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/accounts/me",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "accounts",
                "me"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Delete account",
          "request": {
            "method": "DELETE",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/accounts/me",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "accounts",
                "me"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Blueprints",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "/*",
                  "Visualizer: Blueprints Table",
                  "- Displays all device blueprints in a table",
                  "- Dynamically generates resource columns from response data",
                  "*/",
                  "",
                  "var template = `",
                  "<style>",
                  "  .blueprints-table {",
                  "    width: 100%;",
                  "    border-collapse: collapse;",
                  "    font-family: Arial, Helvetica, sans-serif;",
                  "    font-size: 13px;",
                  "  }",
                  "  .blueprints-table th, .blueprints-table td {",
                  "    border: 1px solid #ddd;",
                  "    padding: 8px;",
                  "    text-align: left;",
                  "  }",
                  "  .blueprints-table th {",
                  "    background-color: #4a90d9;",
                  "    color: white;",
                  "    font-weight: bold;",
                  "  }",
                  "  .blueprints-table tr:nth-child(even) {",
                  "    background-color: #f9f9f9;",
                  "  }",
                  "  .blueprints-table tr:hover {",
                  "    background-color: #f1f1f1;",
                  "  }",
                  "</style>",
                  "<div style=\"padding: 16px;\">",
                  "  <h3 style=\"text-align:center; font-family: Arial, Helvetica, sans-serif;\">Device Blueprints</h3>",
                  "  <table class=\"blueprints-table\">",
                  "    <thead>",
                  "      <tr>",
                  "        {{#each columns}}",
                  "        <th>{{this}}</th>",
                  "        {{/each}}",
                  "      </tr>",
                  "    </thead>",
                  "    <tbody>",
                  "      {{#each rows}}",
                  "      <tr>",
                  "        {{#each ../columns}}",
                  "        <td>{{lookup .. this}}</td>",
                  "        {{/each}}",
                  "      </tr>",
                  "      {{/each}}",
                  "    </tbody>",
                  "  </table>",
                  "</div>",
                  "`;",
                  "",
                  "function constructVisualizerPayload() {",
                  "    var response = pm.response.json();",
                  "    var blueprints = response.blueprints || [];",
                  "    ",
                  "    // Base columns",
                  "    var baseColumns = ['device_type', 'print_time', 'features'];",
                  "    ",
                  "    // Collect all unique resource keys across all blueprints",
                  "    var resourceKeysSet = {};",
                  "    blueprints.forEach(function(bp) {",
                  "        if (bp.resources && typeof bp.resources === 'object') {",
                  "            Object.keys(bp.resources).forEach(function(key) {",
                  "                resourceKeysSet[key] = true;",
                  "            });",
                  "        }",
                  "    });",
                  "    ",
                  "    // Sort resource keys alphabetically for stable order",
                  "    var resourceKeys = Object.keys(resourceKeysSet).sort();",
                  "    ",
                  "    // Build columns array: base columns + resource columns",
                  "    var columns = baseColumns.concat(resourceKeys);",
                  "    ",
                  "    // Build rows",
                  "    var rows = blueprints.map(function(bp) {",
                  "        var row = {};",
                  "        ",
                  "        // Base fields",
                  "        row['device_type'] = bp.device_type || '';",
                  "        row['print_time'] = bp.print_time !== undefined ? bp.print_time : '';",
                  "        row['features'] = Array.isArray(bp.features) ? bp.features.join(', ') : '';",
                  "        ",
                  "        // Resource fields - blank if missing",
                  "        resourceKeys.forEach(function(key) {",
                  "            if (bp.resources && bp.resources[key] !== undefined) {",
                  "                row[key] = bp.resources[key];",
                  "            } else {",
                  "                row[key] = '';",
                  "            }",
                  "        });",
                  "        ",
                  "        return row;",
                  "    });",
                  "    ",
                  "    return {",
                  "        columns: columns,",
                  "        rows: rows",
                  "    };",
                  "}",
                  "",
                  "pm.visualizer.set(template, constructVisualizerPayload());"
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/blueprints",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "blueprints"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Achievements",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "// Visualization Script",
                  "const template = `",
                  "<style>",
                  "  body { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Arial, sans-serif; color: #111; }",
                  "  .summary { display: flex; flex-wrap: wrap; gap: 15px; margin-bottom: 15px; padding: 12px; background: #f0f4f8; border-radius: 6px; }",
                  "  .summary-item { text-align: center; min-width: 100px; }",
                  "  .summary-item .value { font-size: 20px; font-weight: 700; color: #2563eb; }",
                  "  .summary-item .label { font-size: 11px; color: #555; text-transform: uppercase; }",
                  "  .filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 15px; align-items: center; }",
                  "  .filters input[type=\"text\"] { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; min-width: 200px; }",
                  "  .filters select { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; }",
                  "  .filters label { display: flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; }",
                  "  .meta { margin: 0 0 10px 0; font-size: 12px; color: #555; }",
                  "  table { width: 100%; border-collapse: collapse; table-layout: fixed; }",
                  "  th, td { border: 1px solid #e5e5e5; padding: 8px; vertical-align: top; }",
                  "  th { background: #f7f7f7; text-align: left; font-weight: 600; }",
                  "  td { word-break: break-word; }",
                  "  .nowrap { white-space: nowrap; }",
                  "  .muted { color: #777; }",
                  "  .earned-yes { color: #16a34a; font-weight: 600; }",
                  "  .earned-no { color: #dc2626; }",
                  "</style>",
                  "",
                  "<div class=\"summary\" id=\"summary\"></div>",
                  "",
                  "<div class=\"filters\">",
                  "  <input type=\"text\" id=\"searchBox\" placeholder=\"Search title, key, category, description...\" />",
                  "  <select id=\"categoryFilter\"><option value=\"\">All Categories</option></select>",
                  "  <label><input type=\"checkbox\" id=\"earnedToggle\" /> Show only earned</label>",
                  "</div>",
                  "",
                  "<div class=\"meta\">Showing: <strong id=\"rowCount\">0</strong> achievements</div>",
                  "",
                  "<table>",
                  "  <thead>",
                  "    <tr>",
                  "      <th>Title</th>",
                  "      <th>Achievement Key</th>",
                  "      <th>Category</th>",
                  "      <th class=\"nowrap\">XP Reward</th>",
                  "      <th class=\"nowrap\">Earned</th>",
                  "      <th class=\"nowrap\">Hidden</th>",
                  "      <th class=\"nowrap\">Awarded At</th>",
                  "      <th>Description</th>",
                  "    </tr>",
                  "  </thead>",
                  "  <tbody id=\"tableBody\"></tbody>",
                  "</table>",
                  "",
                  "<script>",
                  "  pm.getData(function (err, value) {",
                  "    var data = value.rows || [];",
                  "    var stats = value.stats || {};",
                  "    ",
                  "    // Render summary",
                  "    var summaryHtml = ",
                  "      '<div class=\"summary-item\"><div class=\"value\">' + stats.total + '</div><div class=\"label\">Total</div></div>' +",
                  "      '<div class=\"summary-item\"><div class=\"value\">' + stats.earned + '</div><div class=\"label\">Earned</div></div>' +",
                  "      '<div class=\"summary-item\"><div class=\"value\">' + stats.hidden + '</div><div class=\"label\">Hidden</div></div>' +",
                  "      '<div class=\"summary-item\"><div class=\"value\">' + stats.totalXpEarned + '</div><div class=\"label\">XP Earned</div></div>' +",
                  "      '<div class=\"summary-item\"><div class=\"value\">' + stats.maxXp + '</div><div class=\"label\">Max XP</div></div>';",
                  "    document.getElementById('summary').innerHTML = summaryHtml;",
                  "    ",
                  "    // Populate category dropdown",
                  "    var categories = value.categories || [];",
                  "    var catSelect = document.getElementById('categoryFilter');",
                  "    for (var i = 0; i < categories.length; i++) {",
                  "      var opt = document.createElement('option');",
                  "      opt.value = categories[i];",
                  "      opt.textContent = categories[i];",
                  "      catSelect.appendChild(opt);",
                  "    }",
                  "    ",
                  "    function renderTable(rows) {",
                  "      var html = '';",
                  "      for (var i = 0; i < rows.length; i++) {",
                  "        var r = rows[i];",
                  "        var earnedClass = r.earned === 'true' ? 'earned-yes' : 'earned-no';",
                  "        html += '<tr>' +",
                  "          '<td>' + r.title + '</td>' +",
                  "          '<td>' + r.achievement_key + '</td>' +",
                  "          '<td>' + r.category + '</td>' +",
                  "          '<td class=\"nowrap\">' + r.xp_reward + '</td>' +",
                  "          '<td class=\"nowrap ' + earnedClass + '\">' + r.earned + '</td>' +",
                  "          '<td class=\"nowrap\">' + r.hidden + '</td>' +",
                  "          '<td class=\"nowrap\">' + r.achieved_at + '</td>' +",
                  "          '<td>' + r.description + '</td>' +",
                  "        '</tr>';",
                  "      }",
                  "      document.getElementById('tableBody').innerHTML = html;",
                  "      document.getElementById('rowCount').textContent = rows.length;",
                  "    }",
                  "    ",
                  "    function applyFilters() {",
                  "      var search = document.getElementById('searchBox').value.toLowerCase();",
                  "      var cat = document.getElementById('categoryFilter').value;",
                  "      var earnedOnly = document.getElementById('earnedToggle').checked;",
                  "      ",
                  "      var filtered = data.filter(function(r) {",
                  "        var matchSearch = !search || ",
                  "          r.title.toLowerCase().indexOf(search) !== -1 ||",
                  "          r.achievement_key.toLowerCase().indexOf(search) !== -1 ||",
                  "          r.category.toLowerCase().indexOf(search) !== -1 ||",
                  "          r.description.toLowerCase().indexOf(search) !== -1;",
                  "        var matchCat = !cat || r.category === cat;",
                  "        var matchEarned = !earnedOnly || r.earned === 'true';",
                  "        return matchSearch && matchCat && matchEarned;",
                  "      });",
                  "      renderTable(filtered);",
                  "    }",
                  "    ",
                  "    document.getElementById('searchBox').addEventListener('input', applyFilters);",
                  "    document.getElementById('categoryFilter').addEventListener('change', applyFilters);",
                  "    document.getElementById('earnedToggle').addEventListener('change', applyFilters);",
                  "    ",
                  "    renderTable(data);",
                  "  });",
                  "</script>",
                  "`;",
                  "",
                  "function createPayload() {",
                  "  var json;",
                  "  try {",
                  "    json = pm.response.json();",
                  "  } catch (e) {",
                  "    return {",
                  "      rows: [],",
                  "      categories: [],",
                  "      stats: { total: 0, earned: 0, hidden: 0, totalXpEarned: 0, maxXp: 0 }",
                  "    };",
                  "  }",
                  "",
                  "  var list = Array.isArray(json && json.achievements) ? json.achievements : [];",
                  "",
                  "  var toText = function(v) {",
                  "    if (v === null || v === undefined) return '—';",
                  "    if (typeof v === 'string') return v.trim() === '' ? '—' : v;",
                  "    if (typeof v === 'number') return String(v);",
                  "    if (typeof v === 'boolean') return v ? 'true' : 'false';",
                  "    return String(v);",
                  "  };",
                  "",
                  "  var rows = list.map(function(item) {",
                  "    return {",
                  "      title: toText(item.title),",
                  "      achievement_key: toText(item.achievement_key),",
                  "      category: toText(item.category),",
                  "      xp_reward: toText(item.xp_reward),",
                  "      earned: item.earned === true ? 'true' : 'false',",
                  "      hidden: item.hidden === true ? 'true' : 'false',",
                  "      achieved_at: toText(item.achieved_at),",
                  "      description: toText(item.description)",
                  "    };",
                  "  });",
                  "",
                  "  // Extract unique categories",
                  "  var catSet = {};",
                  "  list.forEach(function(item) {",
                  "    if (item.category) catSet[item.category] = true;",
                  "  });",
                  "  var categories = Object.keys(catSet).sort();",
                  "",
                  "  // Calculate stats",
                  "  var total = list.length;",
                  "  var earned = 0;",
                  "  var hidden = 0;",
                  "  var totalXpEarned = 0;",
                  "  var maxXp = 0;",
                  "",
                  "  list.forEach(function(item) {",
                  "    if (item.earned === true) {",
                  "      earned++;",
                  "      totalXpEarned += (typeof item.xp_reward === 'number' ? item.xp_reward : 0);",
                  "    }",
                  "    if (item.hidden === true) hidden++;",
                  "    if (typeof item.xp_reward === 'number' && item.xp_reward > maxXp) {",
                  "      maxXp = item.xp_reward;",
                  "    }",
                  "  });",
                  "",
                  "  return {",
                  "    rows: rows,",
                  "    categories: categories,",
                  "    stats: {",
                  "      total: total,",
                  "      earned: earned,",
                  "      hidden: hidden,",
                  "      totalXpEarned: totalXpEarned,",
                  "      maxXp: maxXp",
                  "    }",
                  "  };",
                  "}",
                  "",
                  "pm.visualizer.set(template, createPayload());"
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/accounts/achievements",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "accounts",
                "achievements"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Reputation",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "/*",
                  "Visualizer: Blueprints Table",
                  "- Displays all device blueprints in a table",
                  "- Dynamically generates resource columns from response data",
                  "*/",
                  "",
                  "var template = `",
                  "<style>",
                  "  .blueprints-table {",
                  "    width: 100%;",
                  "    border-collapse: collapse;",
                  "    font-family: Arial, Helvetica, sans-serif;",
                  "    font-size: 13px;",
                  "  }",
                  "  .blueprints-table th, .blueprints-table td {",
                  "    border: 1px solid #ddd;",
                  "    padding: 8px;",
                  "    text-align: left;",
                  "  }",
                  "  .blueprints-table th {",
                  "    background-color: #4a90d9;",
                  "    color: white;",
                  "    font-weight: bold;",
                  "  }",
                  "  .blueprints-table tr:nth-child(even) {",
                  "    background-color: #f9f9f9;",
                  "  }",
                  "  .blueprints-table tr:hover {",
                  "    background-color: #f1f1f1;",
                  "  }",
                  "</style>",
                  "<div style=\"padding: 16px;\">",
                  "  <h3 style=\"text-align:center; font-family: Arial, Helvetica, sans-serif;\">Device Blueprints</h3>",
                  "  <table class=\"blueprints-table\">",
                  "    <thead>",
                  "      <tr>",
                  "        {{#each columns}}",
                  "        <th>{{this}}</th>",
                  "        {{/each}}",
                  "      </tr>",
                  "    </thead>",
                  "    <tbody>",
                  "      {{#each rows}}",
                  "      <tr>",
                  "        {{#each ../columns}}",
                  "        <td>{{lookup .. this}}</td>",
                  "        {{/each}}",
                  "      </tr>",
                  "      {{/each}}",
                  "    </tbody>",
                  "  </table>",
                  "</div>",
                  "`;",
                  "",
                  "function constructVisualizerPayload() {",
                  "    var response = pm.response.json();",
                  "    var blueprints = response.blueprints || [];",
                  "    ",
                  "    // Base columns",
                  "    var baseColumns = ['device_type', 'print_time', 'features'];",
                  "    ",
                  "    // Collect all unique resource keys across all blueprints",
                  "    var resourceKeysSet = {};",
                  "    blueprints.forEach(function(bp) {",
                  "        if (bp.resources && typeof bp.resources === 'object') {",
                  "            Object.keys(bp.resources).forEach(function(key) {",
                  "                resourceKeysSet[key] = true;",
                  "            });",
                  "        }",
                  "    });",
                  "    ",
                  "    // Sort resource keys alphabetically for stable order",
                  "    var resourceKeys = Object.keys(resourceKeysSet).sort();",
                  "    ",
                  "    // Build columns array: base columns + resource columns",
                  "    var columns = baseColumns.concat(resourceKeys);",
                  "    ",
                  "    // Build rows",
                  "    var rows = blueprints.map(function(bp) {",
                  "        var row = {};",
                  "        ",
                  "        // Base fields",
                  "        row['device_type'] = bp.device_type || '';",
                  "        row['print_time'] = bp.print_time !== undefined ? bp.print_time : '';",
                  "        row['features'] = Array.isArray(bp.features) ? bp.features.join(', ') : '';",
                  "        ",
                  "        // Resource fields - blank if missing",
                  "        resourceKeys.forEach(function(key) {",
                  "            if (bp.resources && bp.resources[key] !== undefined) {",
                  "                row[key] = bp.resources[key];",
                  "            } else {",
                  "                row[key] = '';",
                  "            }",
                  "        });",
                  "        ",
                  "        return row;",
                  "    });",
                  "    ",
                  "    return {",
                  "        columns: columns,",
                  "        rows: rows",
                  "    };",
                  "}",
                  "",
                  "pm.visualizer.set(template, constructVisualizerPayload());"
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/accounts/reputation",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "accounts",
                "reputation"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Known Species",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "/*",
                  "Visualizer: Blueprints Table",
                  "- Displays all device blueprints in a table",
                  "- Dynamically generates resource columns from response data",
                  "*/",
                  "",
                  "var template = `",
                  "<style>",
                  "  .blueprints-table {",
                  "    width: 100%;",
                  "    border-collapse: collapse;",
                  "    font-family: Arial, Helvetica, sans-serif;",
                  "    font-size: 13px;",
                  "  }",
                  "  .blueprints-table th, .blueprints-table td {",
                  "    border: 1px solid #ddd;",
                  "    padding: 8px;",
                  "    text-align: left;",
                  "  }",
                  "  .blueprints-table th {",
                  "    background-color: #4a90d9;",
                  "    color: white;",
                  "    font-weight: bold;",
                  "  }",
                  "  .blueprints-table tr:nth-child(even) {",
                  "    background-color: #f9f9f9;",
                  "  }",
                  "  .blueprints-table tr:hover {",
                  "    background-color: #f1f1f1;",
                  "  }",
                  "</style>",
                  "<div style=\"padding: 16px;\">",
                  "  <h3 style=\"text-align:center; font-family: Arial, Helvetica, sans-serif;\">Device Blueprints</h3>",
                  "  <table class=\"blueprints-table\">",
                  "    <thead>",
                  "      <tr>",
                  "        {{#each columns}}",
                  "        <th>{{this}}</th>",
                  "        {{/each}}",
                  "      </tr>",
                  "    </thead>",
                  "    <tbody>",
                  "      {{#each rows}}",
                  "      <tr>",
                  "        {{#each ../columns}}",
                  "        <td>{{lookup .. this}}</td>",
                  "        {{/each}}",
                  "      </tr>",
                  "      {{/each}}",
                  "    </tbody>",
                  "  </table>",
                  "</div>",
                  "`;",
                  "",
                  "function constructVisualizerPayload() {",
                  "    var response = pm.response.json();",
                  "    var blueprints = response.blueprints || [];",
                  "    ",
                  "    // Base columns",
                  "    var baseColumns = ['device_type', 'print_time', 'features'];",
                  "    ",
                  "    // Collect all unique resource keys across all blueprints",
                  "    var resourceKeysSet = {};",
                  "    blueprints.forEach(function(bp) {",
                  "        if (bp.resources && typeof bp.resources === 'object') {",
                  "            Object.keys(bp.resources).forEach(function(key) {",
                  "                resourceKeysSet[key] = true;",
                  "            });",
                  "        }",
                  "    });",
                  "    ",
                  "    // Sort resource keys alphabetically for stable order",
                  "    var resourceKeys = Object.keys(resourceKeysSet).sort();",
                  "    ",
                  "    // Build columns array: base columns + resource columns",
                  "    var columns = baseColumns.concat(resourceKeys);",
                  "    ",
                  "    // Build rows",
                  "    var rows = blueprints.map(function(bp) {",
                  "        var row = {};",
                  "        ",
                  "        // Base fields",
                  "        row['device_type'] = bp.device_type || '';",
                  "        row['print_time'] = bp.print_time !== undefined ? bp.print_time : '';",
                  "        row['features'] = Array.isArray(bp.features) ? bp.features.join(', ') : '';",
                  "        ",
                  "        // Resource fields - blank if missing",
                  "        resourceKeys.forEach(function(key) {",
                  "            if (bp.resources && bp.resources[key] !== undefined) {",
                  "                row[key] = bp.resources[key];",
                  "            } else {",
                  "                row[key] = '';",
                  "            }",
                  "        });",
                  "        ",
                  "        return row;",
                  "    });",
                  "    ",
                  "    return {",
                  "        columns: columns,",
                  "        rows: rows",
                  "    };",
                  "}",
                  "",
                  "pm.visualizer.set(template, constructVisualizerPayload());"
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/species",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "species"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Change Settings",
          "request": {
            "method": "PATCH",
            "header": [],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"name\": \"Your Name\",\n    \"timezone\": \"Europe/London\",\n    \"message_notify\": {\n        \"email\": false,\n        \"webhook\": true,\n        \"preferences\": {\n            \"ami\": true,\n            \"devices\": true,\n            \"location_events\": true,\n            \"mining\": true,\n            \"multiplayer\": true,\n            \"printing\": true,\n            \"progression\": true,\n            \"scanning\": true,\n            \"trade\": true,\n            \"travel\": true\n        }\n    },\n    \"bobnet_channels\": [\n        \"#general\",\n        \"#trade\"\n    ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/accounts/me",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "accounts",
                "me"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Messages",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "var template = `\r",
                  "<style>\r",
                  "  :root {\r",
                  "    --border: #e6e6e6;\r",
                  "    --muted: #6b7280;\r",
                  "    --bg: #ffffff;\r",
                  "    --rowHover: #f8fafc;\r",
                  "    --unreadBg: #eef6ff;\r",
                  "    --pillBg: #f3f4f6;\r",
                  "  }\r",
                  "  body { font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif; color:#111827; }\r",
                  "  .wrap { max-width: 980px; margin: 0 auto; }\r",
                  "  .header { display:flex; align-items:baseline; justify-content:space-between; margin-bottom: 10px; }\r",
                  "  .title { font-size: 18px; font-weight: 600; }\r",
                  "  .meta { color: var(--muted); font-size: 12px; }\r",
                  "  .list { border:1px solid var(--border); border-radius: 10px; overflow:hidden; background: var(--bg); }\r",
                  "  .row {\r",
                  "    display:grid;\r",
                  "    grid-template-columns: 170px 120px 1fr;\r",
                  "    gap: 14px;\r",
                  "    padding: 12px 14px;\r",
                  "    border-top:1px solid var(--border);\r",
                  "  }\r",
                  "  .row:first-child { border-top:0; }\r",
                  "  .row:hover { background: var(--rowHover); }\r",
                  "  .row.unread { background: var(--unreadBg); }\r",
                  "  .date { color: var(--muted); font-size: 12px; white-space: nowrap; }\r",
                  "  .type { font-size: 12px; }\r",
                  "  .pill {\r",
                  "    display:inline-block;\r",
                  "    padding: 2px 8px;\r",
                  "    border-radius: 999px;\r",
                  "    background: var(--pillBg);\r",
                  "    border: 1px solid var(--border);\r",
                  "    color:#111827;\r",
                  "  }\r",
                  "  .content { min-width:0; }\r",
                  "  .subject { font-weight: 600; margin: 0 0 4px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\r",
                  "  .snippet { margin:0; color:#111827; opacity: 0.85; display:-webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }\r",
                  "  .empty { padding: 18px; color: var(--muted); }\r",
                  "  .topbar {\r",
                  "    display:flex; gap: 10px; align-items:center; justify-content:space-between;\r",
                  "    padding: 10px 12px; border-bottom: 1px solid var(--border); background:#fbfbfc;\r",
                  "  }\r",
                  "  .counts { font-size: 12px; color: var(--muted); }\r",
                  "</style>\r",
                  "\r",
                  "<div class=\"wrap\">\r",
                  "  <div class=\"header\">\r",
                  "    <div class=\"title\">Inbox</div>\r",
                  "    <div class=\"meta\">\r",
                  "      Unread: {{response.unread_message_count}}\r",
                  "      {{#if response.next_cursor}} • Next cursor: {{response.next_cursor}}{{/if}}\r",
                  "    </div>\r",
                  "  </div>\r",
                  "\r",
                  "  <div class=\"list\">\r",
                  "    <div class=\"topbar\">\r",
                  "      <div class=\"counts\">\r",
                  "        Showing {{meta.total}} message(s)\r",
                  "      </div>\r",
                  "      <div class=\"counts\">\r",
                  "        {{#if meta.filteredUnreadOnly}}\r",
                  "          Filter: unread_only=true\r",
                  "        {{else}}\r",
                  "          Filter: all messages\r",
                  "        {{/if}}\r",
                  "      </div>\r",
                  "    </div>\r",
                  "\r",
                  "    {{#if meta.hasMessages}}\r",
                  "      {{#each response.messages}}\r",
                  "        <div class=\"row {{#unless is_read}}unread{{/unless}}\">\r",
                  "          <div class=\"date\">{{created_at_display}}</div>\r",
                  "          <div class=\"type\"><span class=\"pill\">{{message_type}}</span></div>\r",
                  "          <div class=\"content\">\r",
                  "            <p class=\"subject\">{{title}}</p>\r",
                  "            <p class=\"snippet\">{{body}}</p>\r",
                  "          </div>\r",
                  "        </div>\r",
                  "      {{/each}}\r",
                  "    {{else}}\r",
                  "      <div class=\"empty\">No messages found.</div>\r",
                  "    {{/if}}\r",
                  "  </div>\r",
                  "</div>\r",
                  "`;\r",
                  "\r",
                  "function toDisplayDate(iso) {\r",
                  "  if (!iso) return \"\";\r",
                  "  // Keep it simple & consistent across runtimes\r",
                  "  // Example: 2026-02-27T14:59:07Z -> 2026-02-27 14:59:07Z\r",
                  "  return String(iso).replace(\"T\", \" \");\r",
                  "}\r",
                  "\r",
                  "function constructVisualizerPayload() {\r",
                  "  var json = {};\r",
                  "  try { json = pm.response.json(); } catch (e) { json = {}; }\r",
                  "\r",
                  "  var messages = Array.isArray(json.messages) ? json.messages : [];\r",
                  "  messages = messages.map(function (m) {\r",
                  "    return Object.assign({}, m, { created_at_display: toDisplayDate(m.created_at) });\r",
                  "  });\r",
                  "\r",
                  "  var unreadOnlyParam = (pm.request.url && pm.request.url.query)\r",
                  "    ? pm.request.url.query.find(function(q){ return q && q.key === \"unread_only\"; })\r",
                  "    : null;\r",
                  "\r",
                  "  var filteredUnreadOnly = unreadOnlyParam ? String(unreadOnlyParam.value) === \"true\" : false;\r",
                  "\r",
                  "  return {\r",
                  "    response: Object.assign({}, json, { messages: messages }),\r",
                  "    meta: {\r",
                  "      total: messages.length,\r",
                  "      hasMessages: messages.length > 0,\r",
                  "      filteredUnreadOnly: filteredUnreadOnly\r",
                  "    }\r",
                  "  };\r",
                  "}\r",
                  "\r",
                  "pm.visualizer.set(template, constructVisualizerPayload());"
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/messages",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "messages"
              ],
              "query": [
                {
                  "key": "unread_only",
                  "value": "true",
                  "disabled": true
                },
                {
                  "key": "latest",
                  "value": "true",
                  "disabled": true
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "Mark Messages Read",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"ids\": [\n        1\n    ]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/messages/read",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "messages",
                "read"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Mark All Messages Read",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"mark_all\": true\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/messages/read",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "messages",
                "read"
              ]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "Replicant",
      "item": [
        {
          "name": "Info",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Reputation",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/reputation",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "reputation"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Rename",
          "request": {
            "method": "PATCH",
            "header": [],
            "body": {
              "mode": "raw",
              "raw": "{\r\n    \"name\": \"Player1\"\r\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Event Log",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "// Visualize Replicant Events as an HTML table with toggleable payload and persistent filters",
                  "const template = `",
                  "<style>",
                  "  body { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Arial, sans-serif; color: #333; margin: 16px; }",
                  "  h2 { margin-bottom: 12px; }",
                  "  .filters { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }",
                  "  .filter-group { display: flex; flex-direction: column; gap: 4px; }",
                  "  .filter-group label { font-size: 12px; font-weight: 600; color: #555; text-transform: uppercase; letter-spacing: 0.04em; }",
                  "  .filter-group select { padding: 6px 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; min-width: 180px; background: #fff; cursor: pointer; }",
                  "  .filter-group select:focus { outline: none; border-color: #0066cc; box-shadow: 0 0 0 2px rgba(0,102,204,0.15); }",
                  "  .reset-btn { margin-top: 18px; padding: 6px 14px; background: #f0f0f0; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; cursor: pointer; color: #333; }",
                  "  .reset-btn:hover { background: #e0e0e0; }",
                  "  .count-label { margin-top: 18px; font-size: 13px; color: #666; }",
                  "  table { width: 100%; border-collapse: collapse; font-size: 14px; }",
                  "  th, td { border: 1px solid #ddd; padding: 10px 12px; text-align: left; vertical-align: top; }",
                  "  th { background: #f4f4f4; font-weight: 600; }",
                  "  tr:nth-child(even) { background: #fafafa; }",
                  "  .payload-cell { cursor: pointer; }",
                  "  .payload-toggle { color: #0066cc; text-decoration: underline; font-size: 12px; }",
                  "  .payload-content { display: none; margin-top: 8px; background: #f9f9f9; padding: 8px; border-radius: 4px; white-space: pre-wrap; font-family: monospace; font-size: 12px; max-height: 300px; overflow: auto; }",
                  "  .payload-content.expanded { display: block; }",
                  "  .no-results { padding: 24px; text-align: center; color: #888; font-style: italic; }",
                  "</style>",
                  "",
                  "<h2>Events</h2>",
                  "",
                  "<div class=\"filters\">",
                  "  <div class=\"filter-group\">",
                  "    <label for=\"deviceTypeFilter\">Device Type</label>",
                  "    <select id=\"deviceTypeFilter\" onchange=\"applyFilters()\">",
                  "      <option value=\"\">All Device Types</option>",
                  "      {{#each deviceTypes}}",
                  "      <option value=\"{{this}}\">{{this}}</option>",
                  "      {{/each}}",
                  "    </select>",
                  "  </div>",
                  "  <div class=\"filter-group\">",
                  "    <label for=\"eventTypeFilter\">Event Type</label>",
                  "    <select id=\"eventTypeFilter\" onchange=\"applyFilters()\">",
                  "      <option value=\"\">All Event Types</option>",
                  "      {{#each eventTypes}}",
                  "      <option value=\"{{this}}\">{{this}}</option>",
                  "      {{/each}}",
                  "    </select>",
                  "  </div>",
                  "  <button class=\"reset-btn\" onclick=\"resetFilters()\">Reset Filters</button>",
                  "  <span class=\"count-label\" id=\"countLabel\"></span>",
                  "</div>",
                  "",
                  "<table id=\"eventsTable\">",
                  "  <thead>",
                  "    <tr>",
                  "      <th>ID</th>",
                  "      <th>Created At</th>",
                  "      <th>Device Code</th>",
                  "      <th>Device Type</th>",
                  "      <th>Event Type</th>",
                  "      <th>Message</th>",
                  "      <th>Payload</th>",
                  "    </tr>",
                  "  </thead>",
                  "  <tbody id=\"eventsBody\">",
                  "    {{#each events}}",
                  "    <tr data-device-type=\"{{device_type}}\" data-event-type=\"{{event_type}}\">",
                  "      <td>{{id}}</td>",
                  "      <td>{{created_at}}</td>",
                  "      <td>{{device_code}}</td>",
                  "      <td>{{device_type}}</td>",
                  "      <td>{{event_type}}</td>",
                  "      <td>{{message}}</td>",
                  "      <td class=\"payload-cell\" onclick=\"togglePayload(this)\">",
                  "        <span class=\"payload-toggle\">Click to expand</span>",
                  "        <div class=\"payload-content\">{{payloadJson}}</div>",
                  "      </td>",
                  "    </tr>",
                  "    {{/each}}",
                  "  </tbody>",
                  "</table>",
                  "",
                  "<script>",
                  "var STORAGE_KEY_DEVICE = 'eventLog_filter_deviceType';",
                  "var STORAGE_KEY_EVENT  = 'eventLog_filter_eventType';",
                  "",
                  "function applyFilters() {",
                  "  var deviceVal = document.getElementById('deviceTypeFilter').value;",
                  "  var eventVal  = document.getElementById('eventTypeFilter').value;",
                  "",
                  "  try { localStorage.setItem(STORAGE_KEY_DEVICE, deviceVal); } catch(e) {}",
                  "  try { localStorage.setItem(STORAGE_KEY_EVENT,  eventVal);  } catch(e) {}",
                  "",
                  "  var rows = document.querySelectorAll('#eventsBody tr');",
                  "  var visible = 0;",
                  "  rows.forEach(function(row) {",
                  "    var dt = row.getAttribute('data-device-type') || '';",
                  "    var et = row.getAttribute('data-event-type')  || '';",
                  "    var show = (!deviceVal || dt === deviceVal) && (!eventVal || et === eventVal);",
                  "    row.style.display = show ? '' : 'none';",
                  "    if (show) visible++;",
                  "  });",
                  "",
                  "  var total = rows.length;",
                  "  var label = document.getElementById('countLabel');",
                  "  if (label) {",
                  "    label.textContent = (deviceVal || eventVal)",
                  "      ? ('Showing ' + visible + ' of ' + total + ' events')",
                  "      : (total + ' events');",
                  "  }",
                  "}",
                  "",
                  "function resetFilters() {",
                  "  document.getElementById('deviceTypeFilter').value = '';",
                  "  document.getElementById('eventTypeFilter').value  = '';",
                  "  try { localStorage.removeItem(STORAGE_KEY_DEVICE); } catch(e) {}",
                  "  try { localStorage.removeItem(STORAGE_KEY_EVENT);  } catch(e) {}",
                  "  applyFilters();",
                  "}",
                  "",
                  "function restoreFilters() {",
                  "  var deviceVal = '';",
                  "  var eventVal  = '';",
                  "  try { deviceVal = localStorage.getItem(STORAGE_KEY_DEVICE) || ''; } catch(e) {}",
                  "  try { eventVal  = localStorage.getItem(STORAGE_KEY_EVENT)  || ''; } catch(e) {}",
                  "",
                  "  var deviceSel = document.getElementById('deviceTypeFilter');",
                  "  var eventSel  = document.getElementById('eventTypeFilter');",
                  "",
                  "  if (deviceVal) {",
                  "    for (var i = 0; i < deviceSel.options.length; i++) {",
                  "      if (deviceSel.options[i].value === deviceVal) { deviceSel.value = deviceVal; break; }",
                  "    }",
                  "  }",
                  "  if (eventVal) {",
                  "    for (var i = 0; i < eventSel.options.length; i++) {",
                  "      if (eventSel.options[i].value === eventVal) { eventSel.value = eventVal; break; }",
                  "    }",
                  "  }",
                  "",
                  "  applyFilters();",
                  "}",
                  "",
                  "function togglePayload(cell) {",
                  "  var content = cell.querySelector('.payload-content');",
                  "  var toggle  = cell.querySelector('.payload-toggle');",
                  "  if (content.classList.contains('expanded')) {",
                  "    content.classList.remove('expanded');",
                  "    toggle.textContent = 'Click to expand';",
                  "  } else {",
                  "    content.classList.add('expanded');",
                  "    toggle.textContent = 'Click to collapse';",
                  "  }",
                  "}",
                  "",
                  "// Restore saved filter state on every render",
                  "restoreFilters();",
                  "</script>",
                  "`;",
                  "",
                  "function constructVisualizerPayload() {",
                  "  var data;",
                  "  try {",
                  "    data = pm.response.json();",
                  "  } catch (e) {",
                  "    return { events: [], eventCount: 0, deviceTypes: [], eventTypes: [] };",
                  "  }",
                  "",
                  "  var events = Array.isArray(data.events) ? data.events : [];",
                  "",
                  "  var deviceTypeSet = {};",
                  "  var eventTypeSet  = {};",
                  "",
                  "  var mappedEvents = events.map(function(evt) {",
                  "    var dt = evt.device_type || '';",
                  "    var et = evt.event_type  || '';",
                  "    if (dt) deviceTypeSet[dt] = true;",
                  "    if (et) eventTypeSet[et]  = true;",
                  "    return {",
                  "      id:          evt.id !== undefined ? evt.id : '',",
                  "      created_at:  evt.created_at  || '',",
                  "      device_code: evt.device_code || 'N/A',",
                  "      device_type: dt || 'N/A',",
                  "      event_type:  et || '',",
                  "      message:     evt.message || '',",
                  "      payloadJson: JSON.stringify(evt.payload, null, 2)",
                  "    };",
                  "  });",
                  "",
                  "  var deviceTypes = Object.keys(deviceTypeSet).sort();",
                  "  var eventTypes  = Object.keys(eventTypeSet).sort();",
                  "",
                  "  return {",
                  "    events:      mappedEvents,",
                  "    eventCount:  mappedEvents.length,",
                  "    deviceTypes: deviceTypes,",
                  "    eventTypes:  eventTypes",
                  "  };",
                  "}",
                  "",
                  "pm.visualizer.set(template, constructVisualizerPayload());",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/events?latest=true",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "events"
              ],
              "query": [
                {
                  "key": "exclude_mining_cycles",
                  "value": "true",
                  "disabled": true
                },
                {
                  "key": "latest",
                  "value": "true"
                },
                {
                  "key": "exclude_ami_evaluations",
                  "value": "true",
                  "disabled": true
                },
                {
                  "key": "device_type",
                  "value": "cargo_vessel",
                  "disabled": true
                },
                {
                  "key": "event_type",
                  "value": "transport_delivered",
                  "disabled": true
                },
                {
                  "key": "device",
                  "value": "E9D67256",
                  "disabled": true
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "Nearest Stars",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/stars?per_page=10&page=1",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "stars"
              ],
              "query": [
                {
                  "key": "per_page",
                  "value": "10"
                },
                {
                  "key": "page",
                  "value": "1"
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "My Devices",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "// Visualization Script",
                  "// Visualize response.devices as an HTML table with filters for device_type and location",
                  "const template = `",
                  "<style>",
                  "  body { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif; }",
                  "  .meta { margin: 0 0 10px 0; color: #555; font-size: 12px; }",
                  "  .row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }",
                  "  .control { display: flex; flex-direction: column; gap: 4px; }",
                  "  label { font-size: 12px; color: #333; }",
                  "  select, input {",
                  "    font-size: 12px;",
                  "    padding: 6px 8px;",
                  "    border: 1px solid #ddd;",
                  "    border-radius: 6px;",
                  "    background: #fff;",
                  "    min-width: 220px;",
                  "  }",
                  "  button {",
                  "    font-size: 12px;",
                  "    padding: 6px 10px;",
                  "    border: 1px solid #ddd;",
                  "    border-radius: 6px;",
                  "    background: #f7f7f7;",
                  "    cursor: pointer;",
                  "  }",
                  "  button:hover { background: #f0f0f0; }",
                  "",
                  "  table { border-collapse: collapse; width: 100%; }",
                  "  thead th {",
                  "    position: sticky;",
                  "    top: 0;",
                  "    background: #f7f7f7;",
                  "    border-bottom: 2px solid #ddd;",
                  "    text-align: left;",
                  "    padding: 8px;",
                  "    font-size: 12px;",
                  "    white-space: nowrap;",
                  "  }",
                  "  tbody td {",
                  "    border-bottom: 1px solid #eee;",
                  "    padding: 8px;",
                  "    font-size: 12px;",
                  "    vertical-align: top;",
                  "  }",
                  "  tbody tr:hover { background: #fafafa; }",
                  "  .muted { color: #888; }",
                  "  .code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace; }",
                  "</style>",
                  "",
                  "{{#if error}}",
                  "  <div class=\"meta\">Unable to render devices table: <span class=\"code\">{{error}}</span></div>",
                  "{{else}}",
                  "  <div class=\"row\">",
                  "    <div class=\"control\">",
                  "      <label for=\"typeFilter\">Device type</label>",
                  "      <select id=\"typeFilter\">",
                  "        <option value=\"\">All</option>",
                  "        {{#each deviceTypes}}",
                  "          <option value=\"{{this}}\">{{this}}</option>",
                  "        {{/each}}",
                  "      </select>",
                  "    </div>",
                  "",
                  "    <div class=\"control\">",
                  "      <label for=\"locationFilter\">Location</label>",
                  "      <select id=\"locationFilter\">",
                  "        <option value=\"\">All</option>",
                  "        {{#each locationOptions}}",
                  "          <option value=\"{{value}}\">{{label}}</option>",
                  "        {{/each}}",
                  "      </select>",
                  "    </div>",
                  "",
                  "    <div class=\"control\">",
                  "      <label>&nbsp;</label>",
                  "      <button id=\"resetBtn\" type=\"button\">Reset</button>",
                  "    </div>",
                  "",
                  "    <div class=\"control\" style=\"margin-left:auto;\">",
                  "      <label>Showing</label>",
                  "      <div class=\"meta\" id=\"countMeta\"></div>",
                  "    </div>",
                  "  </div>",
                  "",
                  "  <table>",
                  "    <thead>",
                  "      <tr>",
                  "        <th>device_code</th>",
                  "        <th>device_type</th>",
                  "        <th>features</th>",
                  "        <th>location</th>",
                  "        <th>operational_capacity</th>",
                  "        <th>status</th>",
                  "        <th>stowed_in_device_code</th>",
                  "      </tr>",
                  "    </thead>",
                  "    <tbody id=\"devicesBody\"></tbody>",
                  "  </table>",
                  "",
                  "  <script>",
                  "    function escapeHtml(val) {",
                  "      return String(val)",
                  "        .replace(/&/g, \"&amp;\")",
                  "        .replace(/</g, \"&lt;\")",
                  "        .replace(/>/g, \"&gt;\")",
                  "        .replace(/\\\"/g, \"&quot;\")",
                  "        .replace(/'/g, \"&#039;\");",
                  "    }",
                  "",
                  "    function renderRows(devices) {",
                  "      var tbody = document.getElementById('devicesBody');",
                  "      var meta = document.getElementById('countMeta');",
                  "",
                  "      meta.innerHTML = 'Devices: <strong>' + devices.length + '</strong>';",
                  "      tbody.innerHTML = devices.map(function(d) {",
                  "        return (",
                  "          '<tr>' +",
                  "            '<td class=\"code\">' + escapeHtml(d.device_code) + '</td>' +",
                  "            '<td>' + escapeHtml(d.device_type) + '</td>' +",
                  "            '<td>' + escapeHtml(d.features) + '</td>' +",
                  "            '<td>' + escapeHtml(d.location) + '</td>' +",
                  "            '<td>' + escapeHtml(d.operational_capacity) + '</td>' +",
                  "            '<td>' + escapeHtml(d.status) + '</td>' +",
                  "            '<td class=\"code\">' + escapeHtml(d.stowed_in_device_code) + '</td>' +",
                  "          '</tr>'",
                  "        );",
                  "      }).join('');",
                  "    }",
                  "",
                  "    function isPrefixOption(val) {",
                  "      // encoded as \"prefix:ABCD\"",
                  "      return typeof val === 'string' && val.indexOf('prefix:') === 0;",
                  "    }",
                  "",
                  "    pm.getData(function (err, value) {",
                  "      if (err) {",
                  "        document.getElementById('countMeta').textContent = 'Error loading data';",
                  "        return;",
                  "      }",
                  "",
                  "      var allDevices = (value && value.devices) ? value.devices : [];",
                  "      var typeSel = document.getElementById('typeFilter');",
                  "      var locSel = document.getElementById('locationFilter');",
                  "      var resetBtn = document.getElementById('resetBtn');",
                  "",
                  "      function applyFilters() {",
                  "        var type = typeSel.value;",
                  "        var loc = locSel.value;",
                  "",
                  "        var filtered = allDevices.filter(function(d) {",
                  "          var okType = !type || d.device_type === type;",
                  "",
                  "          var okLoc = true;",
                  "          if (loc) {",
                  "            if (isPrefixOption(loc)) {",
                  "              var prefix = loc.slice('prefix:'.length);",
                  "              okLoc = typeof d.location === 'string' && d.location.indexOf(prefix) === 0;",
                  "            } else {",
                  "              // exact match (existing behavior)",
                  "              okLoc = d.location === loc;",
                  "            }",
                  "          }",
                  "",
                  "          return okType && okLoc;",
                  "        });",
                  "",
                  "        renderRows(filtered);",
                  "      }",
                  "",
                  "      typeSel.addEventListener('change', applyFilters);",
                  "      locSel.addEventListener('change', applyFilters);",
                  "      resetBtn.addEventListener('click', function() {",
                  "        typeSel.value = '';",
                  "        locSel.value = '';",
                  "        applyFilters();",
                  "      });",
                  "",
                  "      // initial",
                  "      applyFilters();",
                  "    });",
                  "  </script>",
                  "{{/if}}",
                  "`;",
                  "",
                  "function constructVisualizerPayload() {",
                  "  try {",
                  "    const json = pm.response.json();",
                  "    const devicesRaw = Array.isArray(json?.devices) ? json.devices : [];",
                  "",
                  "    // Normalize for rendering + filtering (use string tokens for nulls)",
                  "    const devices = devicesRaw.map(d => ({",
                  "      device_code: d?.device_code ?? \"\",",
                  "      device_type: d?.device_type ?? \"\",",
                  "      features: Array.isArray(d?.features) ? d.features.join(\", \") : \"\",",
                  "      location: (d?.location === null || typeof d?.location === \"undefined\") ? \"(null)\" : String(d.location),",
                  "      operational_capacity: (d?.operational_capacity === null || typeof d?.operational_capacity === \"undefined\") ? \"\" : String(d.operational_capacity),",
                  "      status: d?.status ?? \"\",",
                  "      stowed_in_device_code: (d?.stowed_in_device_code === null || typeof d?.stowed_in_device_code === \"undefined\") ? \"\" : String(d.stowed_in_device_code)",
                  "    }));",
                  "",
                  "    // Build distinct filter option lists",
                  "    const deviceTypes = Array.from(new Set(devices.map(d => d.device_type).filter(Boolean))).sort();",
                  "    const locations = Array.from(new Set(devices.map(d => d.location).filter(Boolean))).sort();",
                  "",
                  "    // Prefixes derived from location codes:",
                  "    // - string before first dash",
                  "    // - or first 4 letters if no dash",
                  "    // Always produce 4-character prefixes (uppercased), and list unique.",
                  "    const prefixes = Array.from(new Set(",
                  "      locations",
                  "        .filter(loc => loc && loc !== '(null)')",
                  "        .map(loc => {",
                  "          const s = String(loc);",
                  "          const beforeDash = s.split('-')[0];",
                  "          const rawPrefix = (beforeDash && beforeDash.length) ? beforeDash : s;",
                  "          const p = rawPrefix.slice(0, 4);",
                  "          return p.length === 4 ? p.toUpperCase() : null;",
                  "        })",
                  "        .filter(Boolean)",
                  "    )).sort();",
                  "",
                  "    const locationOptions = [",
                  "      // Prefix options at top",
                  "      ...prefixes.map(p => ({ value: `prefix:${p}`, label: `${p}*` })),",
                  "      // Exact locations next",
                  "      ...locations.map(l => ({ value: l, label: l }))",
                  "    ];",
                  "",
                  "    return { devices, deviceTypes, locationOptions };",
                  "  } catch (e) {",
                  "    return { error: String(e) };",
                  "  }",
                  "}",
                  "",
                  "pm.visualizer.set(template, constructVisualizerPayload());",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  "// Guard against unresolved/empty variables that can cause \"Could not send request\" / \"socket hang up\"",
                  "// and expose the resolved URL for quick debugging.",
                  "",
                  "(function () {",
                  "  const baseUrl = pm.variables.get('baseUrl');",
                  "  const replicantCode = pm.variables.get('replicantCode');",
                  "",
                  "  const resolvedUrl = pm.variables.replaceIn(pm.request.url.toString());",
                  "",
                  "  // Always log the resolved URL (visible in Postman Console)",
                  "  console.log('[My Devices] Resolved URL:', resolvedUrl);",
                  "",
                  "  // Hard fail early if required vars are missing/blank",
                  "  const missing = [];",
                  "  if (!baseUrl || String(baseUrl).trim() === '') missing.push('baseUrl');",
                  "  if (!replicantCode || String(replicantCode).trim() === '') missing.push('replicantCode');",
                  "",
                  "  if (missing.length) {",
                  "    throw new Error(`[My Devices] Missing required variable(s): ${missing.join(', ')}. Check active environment / collection variables.`);",
                  "  }",
                  "",
                  "  // Basic sanity checks",
                  "  if (!/^https?:\\/\\//i.test(String(baseUrl).trim())) {",
                  "    throw new Error('[My Devices] baseUrl must include protocol (http:// or https://).');",
                  "  }",
                  "})();",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/devices",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "devices"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Scan System",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/scan",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "scan"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Scan System Devices",
          "request": {
            "method": "GET",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/scan/devices",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "scan",
                "devices"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Start Mining",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"resource_type\": \"structural\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/mine",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "mine"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Stop Mining",
          "request": {
            "method": "DELETE",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/mine",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "mine"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Travel",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"destination\": \"SOL\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/travel",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "travel"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Cancel Travel",
          "request": {
            "method": "DELETE",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/travel",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "travel"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Print Device",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"device_type\": \"mining_drone\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/print",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "print"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Cancel Print",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json",
                "type": "text"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n    \"command\": \"cancel\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/replicants/{{replicantCode}}/print",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "replicants",
                "{{replicantCode}}",
                "print"
              ]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "Location",
      "item": [
        {
          "name": "Info",
          "protocolProfileBehavior": {
            "disableBodyPruning": true
          },
          "request": {
            "method": "GET",
            "header": [],
            "body": {
              "mode": "raw",
              "raw": ""
            },
            "url": {
              "raw": "{{baseUrl}}/locations/SOL-1",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "locations",
                "SOL-1"
              ],
              "query": [
                {
                  "key": "replicant",
                  "value": "{{replicantCode}}",
                  "disabled": true
                }
              ]
            }
          },
          "response": []
        },
        {
          "name": "Overview",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "",
                  "const template = `",
                  "<!DOCTYPE html>",
                  "<html>",
                  "<head>",
                  "<style>",
                  "  body {",
                  "    font-family: Arial, sans-serif;",
                  "    padding: 12px;",
                  "    background: #f9f9f9;",
                  "  }",
                  "  h2 {",
                  "    color: #333;",
                  "    margin-bottom: 10px;",
                  "  }",
                  "  table {",
                  "    border-collapse: collapse;",
                  "    width: 100%;",
                  "    background: #fff;",
                  "    box-shadow: 0 1px 4px rgba(0,0,0,0.1);",
                  "    border-radius: 6px;",
                  "    overflow: hidden;",
                  "  }",
                  "  th {",
                  "    background: #4a90d9;",
                  "    color: #fff;",
                  "    padding: 10px 14px;",
                  "    text-align: left;",
                  "    cursor: pointer;",
                  "    user-select: none;",
                  "    white-space: nowrap;",
                  "  }",
                  "  th:hover {",
                  "    background: #357abd;",
                  "  }",
                  "  th .sort-arrow {",
                  "    margin-left: 6px;",
                  "    font-size: 0.8em;",
                  "    opacity: 0.8;",
                  "  }",
                  "  td {",
                  "    padding: 8px 14px;",
                  "    border-bottom: 1px solid #eee;",
                  "    color: #444;",
                  "  }",
                  "  tr:last-child td {",
                  "    border-bottom: none;",
                  "  }",
                  "  tr:nth-child(even) {",
                  "    background: #f4f8ff;",
                  "  }",
                  "  tr:hover td {",
                  "    background: #e8f0fe;",
                  "  }",
                  "  .error-msg {",
                  "    color: #c0392b;",
                  "    background: #fdecea;",
                  "    border: 1px solid #f5c6cb;",
                  "    padding: 12px 16px;",
                  "    border-radius: 4px;",
                  "    font-size: 0.95em;",
                  "  }",
                  "  .numeric {",
                  "    text-align: right;",
                  "  }",
                  "</style>",
                  "</head>",
                  "<body>",
                  "  <h2>Locations Overview</h2>",
                  "  {{#if error}}",
                  "    <div class=\"error-msg\">{{error}}</div>",
                  "  {{else}}",
                  "  <table id=\"locTable\">",
                  "    <thead>",
                  "      <tr>",
                  "        <th onclick=\"sortTable(0)\" data-col=\"0\">Location <span class=\"sort-arrow\" id=\"arrow-0\">▲</span></th>",
                  "        <th onclick=\"sortTable(1)\" data-col=\"1\" class=\"numeric\">Devices <span class=\"sort-arrow\" id=\"arrow-1\"></span></th>",
                  "        <th onclick=\"sortTable(2)\" data-col=\"2\" class=\"numeric\">Replicants <span class=\"sort-arrow\" id=\"arrow-2\"></span></th>",
                  "        <th onclick=\"sortTable(3)\" data-col=\"3\" class=\"numeric\">Resource Sites <span class=\"sort-arrow\" id=\"arrow-3\"></span></th>",
                  "        <th onclick=\"sortTable(4)\" data-col=\"4\" class=\"numeric\">Resources <span class=\"sort-arrow\" id=\"arrow-4\"></span></th>",
                  "      </tr>",
                  "    </thead>",
                  "    <tbody id=\"tableBody\">",
                  "      {{#each rows}}",
                  "      <tr>",
                  "        <td>{{location}}</td>",
                  "        <td class=\"numeric\">{{devices}}</td>",
                  "        <td class=\"numeric\">{{replicants}}</td>",
                  "        <td class=\"numeric\">{{resource_sites}}</td>",
                  "        <td class=\"numeric\">{{resources}}</td>",
                  "      </tr>",
                  "      {{/each}}",
                  "    </tbody>",
                  "  </table>",
                  "  {{/if}}",
                  "",
                  "  <script>",
                  "    var currentCol = 0;",
                  "    var ascending = true;",
                  "",
                  "    function sortTable(col) {",
                  "      if (currentCol === col) {",
                  "        ascending = !ascending;",
                  "      } else {",
                  "        currentCol = col;",
                  "        ascending = true;",
                  "      }",
                  "      updateArrows();",
                  "",
                  "      var tbody = document.getElementById('tableBody');",
                  "      var rows = Array.from(tbody.querySelectorAll('tr'));",
                  "",
                  "      rows.sort(function(a, b) {",
                  "        var aVal = a.cells[col].textContent.trim();",
                  "        var bVal = b.cells[col].textContent.trim();",
                  "        var aNum = parseFloat(aVal.replace(/,/g, ''));",
                  "        var bNum = parseFloat(bVal.replace(/,/g, ''));",
                  "        var isNumeric = !isNaN(aNum) && !isNaN(bNum);",
                  "        var cmp = isNumeric ? (aNum - bNum) : aVal.localeCompare(bVal);",
                  "        return ascending ? cmp : -cmp;",
                  "      });",
                  "",
                  "      rows.forEach(function(row) { tbody.appendChild(row); });",
                  "    }",
                  "",
                  "    function updateArrows() {",
                  "      for (var i = 0; i < 5; i++) {",
                  "        var el = document.getElementById('arrow-' + i);",
                  "        if (el) el.textContent = '';",
                  "      }",
                  "      var active = document.getElementById('arrow-' + currentCol);",
                  "      if (active) active.textContent = ascending ? '▲' : '▼';",
                  "    }",
                  "  </script>",
                  "</body>",
                  "</html>",
                  "`;",
                  "",
                  "let vizData;",
                  "",
                  "try {",
                  "    const body = pm.response.json();",
                  "",
                  "    if (!body || typeof body.locations !== 'object' || body.locations === null) {",
                  "        vizData = { error: 'No valid \"locations\" object found in the response.', rows: [] };",
                  "    } else {",
                  "        const rows = Object.entries(body.locations).map(([name, loc]) => ({",
                  "            location: name,",
                  "            devices: (loc && loc.devices != null) ? loc.devices : 0,",
                  "            replicants: (loc && loc.replicants != null) ? loc.replicants : 0,",
                  "            resource_sites: (loc && loc.resource_sites != null) ? loc.resource_sites : 0,",
                  "            resources: (loc && loc.resources != null) ? loc.resources : 0",
                  "        }));",
                  "",
                  "        // Default sort: location ascending",
                  "        rows.sort((a, b) => a.location.localeCompare(b.location));",
                  "",
                  "        vizData = { rows, error: null };",
                  "    }",
                  "} catch (e) {",
                  "    vizData = { error: 'Could not parse response: ' + e.message, rows: [] };",
                  "}",
                  "",
                  "pm.visualizer.set(template, vizData);",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "prerequest",
              "script": {
                "exec": [],
                "type": "text/javascript"
              }
            }
          ],
          "protocolProfileBehavior": {
            "disableBodyPruning": true
          },
          "request": {
            "method": "GET",
            "header": [],
            "body": {
              "mode": "raw",
              "raw": ""
            },
            "url": {
              "raw": "{{baseUrl}}/locations",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "locations"
              ]
            }
          },
          "response": []
        },
        {
          "name": "Inventory",
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "exec": [
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            },
            {
              "listen": "test",
              "script": {
                "exec": [
                  "// Visualize System Inventory response",
                  "const template = `",
                  "<style>",
                  "  body { font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Arial, sans-serif; color: #111; }",
                  "  .star { margin: 0 0 12px; font-size: 18px; }",
                  "  .location { margin: 18px 0 8px; font-size: 15px; }",
                  "  table { width: 100%; border-collapse: collapse; margin: 8px 0 18px; }",
                  "  th, td { border: 1px solid #ddd; padding: 10px 14px; text-align: left; }",
                  "  th { background: #f6f6f6; }",
                  "  td.qty { text-align: right; font-variant-numeric: tabular-nums; }",
                  "</style>",
                  "",
                  "<h2 class=\"star\">Star: {{star}}</h2>",
                  "",
                  "{{#each locations}}",
                  "  <h3 class=\"location\">Location: {{location}}</h3>",
                  "  <table>",
                  "    <thead>",
                  "      <tr>",
                  "        <th>Resource Type</th>",
                  "        <th style=\"text-align:right;\">Quantity</th>",
                  "      </tr>",
                  "    </thead>",
                  "    <tbody>",
                  "      {{#each items}}",
                  "        <tr>",
                  "          <td>{{resource_type}}</td>",
                  "          <td class=\"qty\">{{quantity}}</td>",
                  "        </tr>",
                  "      {{/each}}",
                  "    </tbody>",
                  "  </table>",
                  "{{/each}}",
                  "`;",
                  "",
                  "function constructVisualizerPayload() {",
                  "  let data;",
                  "  try {",
                  "    data = pm.response.json();",
                  "  } catch (e) {",
                  "    return { star: \"(non-JSON response)\", locations: [] };",
                  "  }",
                  "",
                  "  const locations = Array.isArray(data?.locations) ? data.locations : [];",
                  "",
                  "  const mappedLocations = locations.map((loc) => {",
                  "    const items = Array.isArray(loc?.items) ? loc.items : [];",
                  "",
                  "    // Precompute sorted resources (alphabetical by resource_type)",
                  "    const sortedItems = items",
                  "      .map((it) => ({",
                  "        resource_type: String(it?.resource_type ?? \"\"),",
                  "        quantity: it?.quantity ?? null,",
                  "      }))",
                  "      .sort((a, b) => a.resource_type.localeCompare(b.resource_type));",
                  "",
                  "    return {",
                  "      location: String(loc?.location ?? \"\"),",
                  "      items: sortedItems,",
                  "    };",
                  "  });",
                  "",
                  "  return {",
                  "    star: String(data?.star ?? \"\"),",
                  "    locations: mappedLocations,",
                  "  };",
                  "}",
                  "",
                  "pm.visualizer.set(template, constructVisualizerPayload());",
                  ""
                ],
                "type": "text/javascript",
                "packages": {},
                "requests": {}
              }
            }
          ],
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/locations/SOL-1/inventory",
              "host": [
                "{{baseUrl}}"
              ],
              "path": [
                "locations",
                "SOL-1",
                "inventory"
              ]
            }
          },
          "response": []
        }
      ]
    },
    {
      "name": "Devices",
      "item": [
        {
          "name": "General",
          "item": [
            {
              "name": "Info",
              "protocolProfileBehavior": {
                "disableBodyPruning": true
              },
              "request": {
                "method": "GET",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "formdata",
                  "formdata": []
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Deploy",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"deploy\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Stow",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"stow\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Deactivate",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"deactivate\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Travel",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"travel\",\n    \"destination\": \"ALNITAKON-1\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            }
          ]
        },
        {
          "name": "Mining Drones",
          "item": [
            {
              "name": "Start Mining",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"start_mining\",\n    \"resource_type\": \"structural\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Retarget",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"retarget\",\n    \"resource_type\": \"structural\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Stop Mining",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"deactivate\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            }
          ]
        },
        {
          "name": "Survey Drones",
          "item": [
            {
              "name": "Scan Location",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"scan\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Search For Resource Site",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"search\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            }
          ]
        },
        {
          "name": "Maintenance Drones",
          "item": [
            {
              "name": "Repair Device",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"repair\",\n    \"device\": \"ABCDEFGH\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Stop Repair",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"stop_repair\",\n    \"device\": \"ABCDEFGH\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Set Directive - Maintenance Patrol",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"set_directive\",\n    \"directive\": \"patrol\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            }
          ]
        },
        {
          "name": "Transport Drones",
          "item": [
            {
              "name": "Collect Resources",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"collect_resources\",\n    \"resources\": {\n        \"rares\": 20\n    }\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Deposit Resources",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"deposit_resources\",\n    \"resources\": {\n        \"rares\": 20\n    }\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            },
            {
              "name": "Deposit All",
              "request": {
                "method": "POST",
                "header": [
                  {
                    "key": "Content-Type",
                    "value": "application/json",
                    "type": "text"
                  }
                ],
                "body": {
                  "mode": "raw",
                  "raw": "{\n    \"command\": \"deposit_resources\"\n}",
                  "options": {
                    "raw": {
                      "language": "json"
                    }
                  }
                },
                "url": {
                  "raw": "{{baseUrl}}/devices/ABCDEFGH",
                  "host": [
                    "{{baseUrl}}"
                  ],
                  "path": [
                    "devices",
                    "ABCDEFGH"
                  ]
                }
              },
              "response": []
            }
          ]
        }
      ]
    }
  ],
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{bearerToken}}",
        "type": "string"
      }
    ]
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "packages": {},
        "requests": {},
        "exec": [
          ""
        ]
      }
    },
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "packages": {},
        "requests": {},
        "exec": [
          ""
        ]
      }
    }
  ],
  "variable": [
    {
      "key": "baseUrl",
      "value": "https://api.replicant.space/v1"
    },
    {
      "key": "bearerToken",
      "value": ""
    },
    {
      "key": "replicantCode",
      "value": ""
    }
  ]
}