@resolveio/server-lib 20.14.5 → 20.14.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1145,6 +1145,119 @@ function buildAssistantContext(input, userContext) {
1145
1145
  }
1146
1146
  return lines.join('\n');
1147
1147
  }
1148
+ var cachedClientRouteIndex = null;
1149
+ function normalizeRouteKey(value) {
1150
+ var trimmed = normalizeOptionalString(value);
1151
+ if (!trimmed) {
1152
+ return '';
1153
+ }
1154
+ var withSlash = trimmed.startsWith('/') ? trimmed : "/".concat(trimmed);
1155
+ return withSlash.replace(/\/+$/, '');
1156
+ }
1157
+ function normalizeRouteMatchKey(value) {
1158
+ return normalizeRouteKey(value).toLowerCase();
1159
+ }
1160
+ function buildClientRouteIndex() {
1161
+ var e_2, _a;
1162
+ var _b;
1163
+ var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
1164
+ var set = new Set();
1165
+ var map = new Map();
1166
+ try {
1167
+ for (var routes_1 = __values(routes), routes_1_1 = routes_1.next(); !routes_1_1.done; routes_1_1 = routes_1.next()) {
1168
+ var route = routes_1_1.value;
1169
+ var normalized = normalizeRouteKey(route);
1170
+ if (!normalized) {
1171
+ continue;
1172
+ }
1173
+ var matchKey = normalized.toLowerCase();
1174
+ set.add(matchKey);
1175
+ if (!map.has(matchKey)) {
1176
+ map.set(matchKey, normalized);
1177
+ }
1178
+ }
1179
+ }
1180
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1181
+ finally {
1182
+ try {
1183
+ if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
1184
+ }
1185
+ finally { if (e_2) throw e_2.error; }
1186
+ }
1187
+ return { set: set, map: map, size: routes.length };
1188
+ }
1189
+ function getClientRouteIndex() {
1190
+ var _a;
1191
+ var routes = ((_a = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _a === void 0 ? void 0 : _a.call(resolveio_server_app_1.ResolveIOServer)) || [];
1192
+ if (cachedClientRouteIndex && cachedClientRouteIndex.size === routes.length) {
1193
+ return cachedClientRouteIndex;
1194
+ }
1195
+ cachedClientRouteIndex = buildClientRouteIndex();
1196
+ return cachedClientRouteIndex;
1197
+ }
1198
+ function splitRouteSuffix(value) {
1199
+ var matchIndex = value.search(/[?#]/);
1200
+ if (matchIndex === -1) {
1201
+ return { base: value, suffix: '' };
1202
+ }
1203
+ return { base: value.slice(0, matchIndex), suffix: value.slice(matchIndex) };
1204
+ }
1205
+ function isClientRoute(value, index) {
1206
+ var normalized = normalizeRouteMatchKey(value);
1207
+ if (!normalized) {
1208
+ return false;
1209
+ }
1210
+ if (index.set.has(normalized)) {
1211
+ return true;
1212
+ }
1213
+ var parts = normalized.split('/').filter(Boolean);
1214
+ while (parts.length > 1) {
1215
+ parts.pop();
1216
+ var prefix = "/".concat(parts.join('/'));
1217
+ if (index.set.has(prefix)) {
1218
+ return true;
1219
+ }
1220
+ }
1221
+ return false;
1222
+ }
1223
+ function getCanonicalRoute(value, index) {
1224
+ var normalized = normalizeRouteMatchKey(value);
1225
+ if (!normalized) {
1226
+ return null;
1227
+ }
1228
+ return index.map.get(normalized) || null;
1229
+ }
1230
+ function swapTwoSegmentRoute(value) {
1231
+ var normalized = normalizeRouteKey(value);
1232
+ if (!normalized) {
1233
+ return null;
1234
+ }
1235
+ var parts = normalized.split('/').filter(Boolean);
1236
+ if (parts.length !== 2) {
1237
+ return null;
1238
+ }
1239
+ return "/".concat(parts[1], "/").concat(parts[0]);
1240
+ }
1241
+ function normalizeAssistantRoutes(value) {
1242
+ var index = getClientRouteIndex();
1243
+ if (!index.set.size) {
1244
+ return value;
1245
+ }
1246
+ var routePattern = /\/[a-z0-9][a-z0-9/_-]*(?:\?[a-z0-9=&%._-]+)?(?:#[a-z0-9._-]+)?/gi;
1247
+ return value.replace(routePattern, function (match) {
1248
+ var _a = splitRouteSuffix(match), base = _a.base, suffix = _a.suffix;
1249
+ if (isClientRoute(base, index)) {
1250
+ var canonical_1 = getCanonicalRoute(base, index);
1251
+ return canonical_1 ? "".concat(canonical_1).concat(suffix) : match;
1252
+ }
1253
+ var swapped = swapTwoSegmentRoute(base);
1254
+ if (!swapped || !isClientRoute(swapped, index)) {
1255
+ return match;
1256
+ }
1257
+ var canonical = getCanonicalRoute(swapped, index) || swapped;
1258
+ return "".concat(canonical).concat(suffix);
1259
+ });
1260
+ }
1148
1261
  function sanitizeAssistantResponse(value) {
1149
1262
  var raw = normalizeOptionalString(value);
1150
1263
  if (!raw) {
@@ -1179,10 +1292,10 @@ function sanitizeAssistantResponse(value) {
1179
1292
  if (!cleaned) {
1180
1293
  return 'I can’t share code, but I can point you to files or explain behavior at a high level.';
1181
1294
  }
1182
- return cleaned;
1295
+ return normalizeAssistantRoutes(cleaned);
1183
1296
  }
1184
1297
  function evaluateAssistantGuardrails(message) {
1185
- var e_2, _a;
1298
+ var e_3, _a;
1186
1299
  var normalized = String(message || '').toLowerCase();
1187
1300
  var patterns = [
1188
1301
  {
@@ -1228,12 +1341,12 @@ function evaluateAssistantGuardrails(message) {
1228
1341
  }
1229
1342
  }
1230
1343
  }
1231
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1344
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1232
1345
  finally {
1233
1346
  try {
1234
1347
  if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
1235
1348
  }
1236
- finally { if (e_2) throw e_2.error; }
1349
+ finally { if (e_3) throw e_3.error; }
1237
1350
  }
1238
1351
  return null;
1239
1352
  }
@@ -1397,8 +1510,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
1397
1510
  }
1398
1511
  function readAttachmentContents(attachments) {
1399
1512
  return __awaiter(this, void 0, void 0, function () {
1400
- var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_3_1;
1401
- var e_3, _b;
1513
+ var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_4_1;
1514
+ var e_4, _b;
1402
1515
  return __generator(this, function (_c) {
1403
1516
  switch (_c.label) {
1404
1517
  case 0:
@@ -1477,14 +1590,14 @@ function readAttachmentContents(attachments) {
1477
1590
  return [3 /*break*/, 2];
1478
1591
  case 10: return [3 /*break*/, 13];
1479
1592
  case 11:
1480
- e_3_1 = _c.sent();
1481
- e_3 = { error: e_3_1 };
1593
+ e_4_1 = _c.sent();
1594
+ e_4 = { error: e_4_1 };
1482
1595
  return [3 /*break*/, 13];
1483
1596
  case 12:
1484
1597
  try {
1485
1598
  if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
1486
1599
  }
1487
- finally { if (e_3) throw e_3.error; }
1600
+ finally { if (e_4) throw e_4.error; }
1488
1601
  return [7 /*endfinally*/];
1489
1602
  case 13: return [2 /*return*/, {
1490
1603
  promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
@@ -1637,7 +1750,7 @@ function estimateUsage(messages, responseText, model) {
1637
1750
  };
1638
1751
  }
1639
1752
  function evaluateGuardrails(message) {
1640
- var e_4, _a;
1753
+ var e_5, _a;
1641
1754
  var normalized = String(message || '').toLowerCase();
1642
1755
  var patterns = [
1643
1756
  { pattern: /\b(source\s*code|full\s*code|entire\s*code|repo\s*dump|repository|git\s*clone)\b/i, reason: 'Code access is restricted.' },
@@ -1659,12 +1772,12 @@ function evaluateGuardrails(message) {
1659
1772
  }
1660
1773
  }
1661
1774
  }
1662
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1775
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1663
1776
  finally {
1664
1777
  try {
1665
1778
  if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
1666
1779
  }
1667
- finally { if (e_4) throw e_4.error; }
1780
+ finally { if (e_5) throw e_5.error; }
1668
1781
  }
1669
1782
  return null;
1670
1783
  }