@canonry/canonry 7.53.0 → 7.55.0
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.
- package/assets/agent-workspace/skills/canonry/references/canonry-cli.md +13 -0
- package/assets/assets/AgentSetupPage-Dr7UsGcq.js +17 -0
- package/assets/assets/AuditHistoryPanel-Dg9ZNNQw.js +1 -0
- package/assets/assets/BacklinksPage-DSgwyFCi.js +1 -0
- package/assets/assets/{HistoryPage-D2DOk7ms.js → HistoryPage-DaX20IWP.js} +1 -1
- package/assets/assets/MeasurementPropertyPage-FGhKdZAP.js +4 -0
- package/assets/assets/ProjectPage-BTJYS9gc.js +7 -0
- package/assets/assets/RunsPage-D06GJ47B.js +1 -0
- package/assets/assets/SettingsPage-MSgC8Zrc.js +1 -0
- package/assets/assets/SiteHealthSection-4PXTNjon.js +2 -0
- package/assets/assets/ToneBadge-AoUA_EpE.js +60 -0
- package/assets/assets/TrafficPage-DikPWmaU.js +40 -0
- package/assets/assets/TrafficSourceDetailPage-C1hfimWW.js +1 -0
- package/assets/assets/account-context-CHtJm4fz.js +1 -0
- package/assets/assets/card-BO6dtEV9.js +1 -0
- package/assets/assets/extract-error-message-Q9pkEqUE.js +1 -0
- package/assets/assets/{format-helpers-B_2jkVGI.js → format-helpers-Gj1ekh6p.js} +1 -1
- package/assets/assets/{index-DgS5TTSb.css → index-B8W65ejO.css} +1 -1
- package/assets/assets/index-BBfEsbxI.js +56 -0
- package/assets/assets/query-client-C22j0Z7h.js +1 -0
- package/assets/assets/react-query-BLKqSvlU.js +1 -0
- package/assets/assets/{react-sigma_core.esm.min-Bjux3j_1.js → react-sigma_core.esm.min-j5DWE8Rk.js} +1 -1
- package/assets/assets/service-2DEngBCR.js +1 -0
- package/assets/demo-og.png +0 -0
- package/assets/index.html +8 -7
- package/dist/{ads-S4S74OXM.js → ads-A5S2NQBZ.js} +3 -3
- package/dist/{agent-JZWKCI5V.js → agent-BV7G7QN7.js} +7 -7
- package/dist/{agent-ask-N2DG5ZLZ.js → agent-ask-5ALAHZ6T.js} +3 -3
- package/dist/{agent-conversations-7UDNE7YI.js → agent-conversations-MJPQCJYR.js} +3 -3
- package/dist/{agent-memory-I74OWTU7.js → agent-memory-Z3VPA5KH.js} +3 -3
- package/dist/{agent-providers-MEMCZPGE.js → agent-providers-FP3LAZPG.js} +3 -3
- package/dist/{agent-transcript-Z7VTL7PY.js → agent-transcript-4GXCOC73.js} +3 -3
- package/dist/{analytics-4NUSNTKT.js → analytics-TOLSUYSN.js} +3 -3
- package/dist/{apply-OZKQK3YF.js → apply-EU5JAFVZ.js} +3 -3
- package/dist/{backfill-PLY2NOOY.js → backfill-3263IYJH.js} +9 -9
- package/dist/{backlinks-2CMRJFWO.js → backlinks-XQ5JTN6W.js} +3 -3
- package/dist/{bing-RD3DDESD.js → bing-LYHRD7BF.js} +3 -3
- package/dist/{bootstrap-JOYV4SWM.js → bootstrap-AKWTIMMH.js} +17 -9
- package/dist/{cdp-LUGL3CT6.js → cdp-N4PQJWGQ.js} +7 -7
- package/dist/{chunk-QNU7IIO7.js → chunk-2OB7YQEZ.js} +324 -324
- package/dist/{chunk-U7JJKXLA.js → chunk-4LVJFSPH.js} +5 -5
- package/dist/{chunk-C5GCRQ66.js → chunk-6WTSWWP6.js} +2 -2
- package/dist/{chunk-LGU3O5YP.js → chunk-75CFTTBF.js} +2 -2
- package/dist/{chunk-NKSASP4U.js → chunk-B37SDIGU.js} +1 -1
- package/dist/{chunk-N3WQHLDI.js → chunk-BQKKAPMW.js} +13 -1
- package/dist/{chunk-BQT7VLGM.js → chunk-D234NBWI.js} +1 -1
- package/dist/{chunk-DFQHGWPB.js → chunk-EIG2V6UI.js} +1 -1
- package/dist/{chunk-3DO3CS7Y.js → chunk-F5XONXGH.js} +4 -4
- package/dist/{chunk-BH274VEO.js → chunk-GFRIXUDK.js} +36 -2
- package/dist/{chunk-LYCYSM6O.js → chunk-H6EQMYGT.js} +1 -1
- package/dist/{chunk-23UZNTF4.js → chunk-J7VN3FZ3.js} +1 -1
- package/dist/{chunk-IWQGZQHE.js → chunk-K5MBEK4S.js} +8 -8
- package/dist/{chunk-6VSKBVB3.js → chunk-LCTYTGSE.js} +3 -3
- package/dist/{chunk-ZXH5IFIA.js → chunk-MARVEIWH.js} +4 -4
- package/dist/{chunk-SZG7S7TE.js → chunk-OHVXKFQI.js} +1 -1
- package/dist/{chunk-2GAXZAQJ.js → chunk-OMXWBR2R.js} +7227 -6562
- package/dist/{chunk-JZARXJV6.js → chunk-PRNO5TLE.js} +456 -249
- package/dist/{chunk-6ZCZRZ66.js → chunk-QFKDFU73.js} +2 -2
- package/dist/chunk-R4AFXPM4.js +959 -0
- package/dist/{chunk-O3OTW7F4.js → chunk-RHCDUPD6.js} +2 -2
- package/dist/{chunk-P4SXRRB4.js → chunk-RHO7UNXA.js} +298 -110
- package/dist/{chunk-N6MS4VG2.js → chunk-SKZVEZZK.js} +7 -2
- package/dist/{chunk-2XDGFHPM.js → chunk-T63KVDWY.js} +3 -3
- package/dist/{chunk-F55ER5RQ.js → chunk-VB47PTY7.js} +3 -3
- package/dist/{chunk-QARV5HVI.js → chunk-VCTP2RG6.js} +5 -5
- package/dist/{chunk-RVBGFWJ3.js → chunk-VF7XGX2I.js} +1 -1
- package/dist/{chunk-QXJ356KK.js → chunk-VMCVLESK.js} +4 -4
- package/dist/{chunk-WNXKW3NS.js → chunk-WDJMIIY2.js} +1 -1
- package/dist/{chunk-2HWY4NRQ.js → chunk-XJVCTI2N.js} +3 -3
- package/dist/{chunk-XTIP5WSA.js → chunk-Y2YBRLSS.js} +3 -3
- package/dist/{chunk-VEH4YLWR.js → chunk-YOZ35ZTT.js} +1 -1
- package/dist/{chunk-2EYBZYDG.js → chunk-ZA7D7CCN.js} +2 -2
- package/dist/{chunk-BGZL5RCP.js → chunk-ZILJZNMQ.js} +1 -1
- package/dist/{citations-GMLBTNLW.js → citations-JK3ZMAR7.js} +3 -3
- package/dist/{cli-catalog-WKUCQEWA.js → cli-catalog-P2I6IYNI.js} +3 -3
- package/dist/{cli-commands-YCHQWUNK.js → cli-commands-U6NDGGK2.js} +7 -7
- package/dist/cli.js +13 -13
- package/dist/{competitor-QNPVJFEI.js → competitor-5CJPM36M.js} +3 -3
- package/dist/{content-NFTC74HD.js → content-5FEDXNHR.js} +3 -3
- package/dist/{dashboard-TMUQT5H5.js → dashboard-ME7MBJTX.js} +6 -6
- package/dist/{demo-O5SPVLZZ.js → demo-J3QCDV43.js} +1 -1
- package/dist/{demo-server-WKZ53RGK.js → demo-server-FJLSYQXZ.js} +49 -16
- package/dist/{discover-LTTO7KHN.js → discover-EAISVTA6.js} +3 -3
- package/dist/{discover-eval-QRDNMDUE.js → discover-eval-JIBKK44Q.js} +3 -3
- package/dist/{doctor-SFL5FOW4.js → doctor-HSQYOZ4C.js} +3 -3
- package/dist/{evidence-J6WZ767P.js → evidence-PSYAWKPP.js} +3 -3
- package/dist/{export-cmd-D3JDTBDV.js → export-cmd-MWJN6H7W.js} +3 -3
- package/dist/{ga-N56LXQUN.js → ga-WSQWECYY.js} +3 -3
- package/dist/{gbp-7WVJYWDR.js → gbp-OD26AEPF.js} +3 -3
- package/dist/{google-YLRVXYVJ.js → google-FMJ7IWAF.js} +4 -4
- package/dist/{google-marketing-4DGX3RBB.js → google-marketing-66JL4V24.js} +1 -1
- package/dist/{health-cmd-PK3BASF6.js → health-cmd-2RO5LAI4.js} +3 -3
- package/dist/{history-UWTEZ626.js → history-X6CNPW7G.js} +3 -3
- package/dist/index.d.ts +449 -14
- package/dist/index.js +24 -23
- package/dist/{init-RBI2IOBY.js → init-EDSKLFUY.js} +11 -11
- package/dist/{insights-ZUC5XHFD.js → insights-6IWWA6JU.js} +3 -3
- package/dist/intelligence-service-N334P6FH.js +15 -0
- package/dist/{keys-NOG3M76V.js → keys-ABXAPISY.js} +3 -3
- package/dist/{keyword-HD57L76I.js → keyword-LERAVMI3.js} +3 -3
- package/dist/{logs-VAB7ITBS.js → logs-BTAB5SNZ.js} +3 -3
- package/dist/{mcp-HYHIL5FB.js → mcp-5E42RT6R.js} +2 -2
- package/dist/mcp.js +9 -9
- package/dist/{measurement-plan-GEHOHCH3.js → measurement-plan-MRZRNBJG.js} +5 -5
- package/dist/{notify-VQ2ZDGN4.js → notify-YQYGC5UZ.js} +3 -3
- package/dist/{organic-evidence-6TX627YW.js → organic-evidence-6QT4YT3K.js} +3 -3
- package/dist/{overview-XBO7WYAV.js → overview-EHZ3FTS2.js} +4 -4
- package/dist/{project-DR6744WZ.js → project-RNLV2ARE.js} +3 -3
- package/dist/{query-OGVTCPG5.js → query-IM2RXI4L.js} +3 -3
- package/dist/{research-B2TGKSMC.js → research-4FALR336.js} +25 -10
- package/dist/{results-export-K7PAYPWQ.js → results-export-4ETSRUGO.js} +3 -3
- package/dist/{run-Y6LUMCVL.js → run-QL7226N7.js} +4 -4
- package/dist/{schedule-PNAUJ5FX.js → schedule-GJE634VO.js} +3 -3
- package/dist/{search-PMVOGL4U.js → search-7OQL67R6.js} +3 -3
- package/dist/{serve-PQHXSS5T.js → serve-VJ3M7FAT.js} +25 -24
- package/dist/{session-S5NDMMKF.js → session-5M54TVY5.js} +12 -12
- package/dist/{settings-AL7E7QUK.js → settings-2QOL7YBM.js} +15 -3
- package/dist/{skills-GQOOTDR7.js → skills-GPLAAU3I.js} +2 -2
- package/dist/{snapshot-W3FXRTZM.js → snapshot-5YMJFRJS.js} +8 -6
- package/dist/{src-WZLTQFCH.js → src-YF3JLURF.js} +2 -2
- package/dist/{status-MBJVN4W5.js → status-WGWC6FLN.js} +33 -5
- package/dist/{technical-aeo-Y4RFST72.js → technical-aeo-RNMLD7OL.js} +3 -3
- package/dist/{telemetry-VK6F5QSZ.js → telemetry-7U3ZICU4.js} +4 -4
- package/dist/{tools-W3AQY5TY.js → tools-CSKTZTKT.js} +11 -11
- package/dist/{traffic-ER4I6V3B.js → traffic-QIAXLW6J.js} +5 -5
- package/dist/{users-KZK2OF4L.js → users-I6X5P5AO.js} +3 -3
- package/dist/{visibility-stats-CR7BUG5G.js → visibility-stats-33OUKQQL.js} +3 -3
- package/dist/{wordpress-DG5JUCAC.js → wordpress-3IO3O27D.js} +3 -3
- package/package.json +2 -1
- package/assets/assets/AccessControls-B-5YUuLE.js +0 -1
- package/assets/assets/AuditHistoryPanel-BkCUPvPv.js +0 -1
- package/assets/assets/BacklinksPage-BMgHZKuw.js +0 -1
- package/assets/assets/MeasurementPropertyPage-Bwv8nKS7.js +0 -4
- package/assets/assets/ProjectPage-CsJfGPx3.js +0 -7
- package/assets/assets/RunsPage-DSHDuj9b.js +0 -1
- package/assets/assets/SettingsPage-BDRdWk5X.js +0 -1
- package/assets/assets/SiteHealthSection-DV06NTxC.js +0 -2
- package/assets/assets/TrafficPage-CBMMwRfw.js +0 -40
- package/assets/assets/TrafficSourceDetailPage-Czpt0S7j.js +0 -1
- package/assets/assets/card-CVejjbhs.js +0 -60
- package/assets/assets/extract-error-message-Co6zPipR.js +0 -1
- package/assets/assets/index-BnS2Vuv0.js +0 -40
- package/assets/assets/query-client-BKJLgjJd.js +0 -1
- package/assets/assets/react-query-ltP1RErY.js +0 -1
- package/assets/assets/service-CDsqgNrS.js +0 -1
- package/dist/intelligence-service-JXXB43RB.js +0 -15
|
@@ -6,14 +6,14 @@ import {
|
|
|
6
6
|
isSelfTraffic,
|
|
7
7
|
normalizeCloudflareWorkerEvent,
|
|
8
8
|
verifyRequestSignature
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-YOZ35ZTT.js";
|
|
10
10
|
import {
|
|
11
11
|
currentOutcomeAttribution,
|
|
12
12
|
getRequestContext,
|
|
13
13
|
registerRequestContext,
|
|
14
14
|
requestAuditIdentity,
|
|
15
15
|
sanitizeRequestContext
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-EIG2V6UI.js";
|
|
17
17
|
import {
|
|
18
18
|
SentimentIdempotencyConflict,
|
|
19
19
|
SentimentRepository,
|
|
@@ -142,7 +142,7 @@ import {
|
|
|
142
142
|
userSessions,
|
|
143
143
|
users,
|
|
144
144
|
writeNegativeReviewMaxStars
|
|
145
|
-
} from "./chunk-
|
|
145
|
+
} from "./chunk-GFRIXUDK.js";
|
|
146
146
|
import {
|
|
147
147
|
ADS_ACTIVATE_SCOPE,
|
|
148
148
|
ADS_ACTIVATION_ABSOLUTE_MAX_ENTITIES,
|
|
@@ -274,6 +274,7 @@ import {
|
|
|
274
274
|
MeasurementPortfolioLists,
|
|
275
275
|
MeasurementRunScopeError,
|
|
276
276
|
MentionIdentities,
|
|
277
|
+
OPENROUTER_ROUTE_FAMILY,
|
|
277
278
|
OPERATIONAL_LOG_FIELDS_HEADER,
|
|
278
279
|
OPERATIONAL_LOG_OPT_IN_CONTEXT_FIELDS,
|
|
279
280
|
OPERATION_ACCESS_HEADER,
|
|
@@ -289,7 +290,9 @@ import {
|
|
|
289
290
|
PROVIDER_ACCOUNT_RETRY_HOURS,
|
|
290
291
|
PROVIDER_NAMES,
|
|
291
292
|
ProviderDispatchModes,
|
|
293
|
+
ProviderKinds,
|
|
292
294
|
ProviderNames,
|
|
295
|
+
ProviderWorkflows,
|
|
293
296
|
READ_ONLY_SCOPE,
|
|
294
297
|
RESEARCH_RUN_SCOPE,
|
|
295
298
|
RUN_FILL_MAX_AGE_MS,
|
|
@@ -669,12 +672,12 @@ import {
|
|
|
669
672
|
internalError,
|
|
670
673
|
intersectScopes,
|
|
671
674
|
isBrowserProvider,
|
|
675
|
+
isEligibleFor,
|
|
672
676
|
isFetchTransportError,
|
|
673
677
|
isGa4AiAssistantChannel,
|
|
674
678
|
isListingMarketplace,
|
|
675
679
|
isLocationRedirectStatus,
|
|
676
680
|
isNegativeReviewRating,
|
|
677
|
-
isOpenRouterRoute,
|
|
678
681
|
isProviderAccountFailure,
|
|
679
682
|
isProviderAvailable,
|
|
680
683
|
isReadOnlyKey,
|
|
@@ -693,6 +696,7 @@ import {
|
|
|
693
696
|
locationContextSchema,
|
|
694
697
|
logQuerySchema,
|
|
695
698
|
loginRequestSchema,
|
|
699
|
+
makesInstallMeasurable,
|
|
696
700
|
mapWithConcurrency,
|
|
697
701
|
marketPinAliasClaims,
|
|
698
702
|
matchOperationTemplate,
|
|
@@ -831,7 +835,6 @@ import {
|
|
|
831
835
|
notificationEventSchema,
|
|
832
836
|
onboardingTelemetryEventSchema,
|
|
833
837
|
openRouterRouteModel,
|
|
834
|
-
openRouterRouteName,
|
|
835
838
|
operationAccess,
|
|
836
839
|
operationInProgress,
|
|
837
840
|
operationalLogListDtoSchema,
|
|
@@ -869,6 +872,7 @@ import {
|
|
|
869
872
|
providerError,
|
|
870
873
|
providerReloadRequestSchema,
|
|
871
874
|
providerReloadResponseDtoSchema,
|
|
875
|
+
providerRouteName,
|
|
872
876
|
providerSummaryEntryDtoSchema,
|
|
873
877
|
providersFailing,
|
|
874
878
|
qualifiedNameIncludesName,
|
|
@@ -910,6 +914,7 @@ import {
|
|
|
910
914
|
resolveNegativeReviewMaxStars,
|
|
911
915
|
resolveProjectQualifiedAliases,
|
|
912
916
|
resolveProviderModel,
|
|
917
|
+
resolveProviderRoute,
|
|
913
918
|
resolveRunDispatchModes,
|
|
914
919
|
resolveSnapshotRequestQueries,
|
|
915
920
|
restrictedWriteScopes,
|
|
@@ -919,6 +924,7 @@ import {
|
|
|
919
924
|
retrievedSourceSchema,
|
|
920
925
|
retryAfterDelayMs,
|
|
921
926
|
roundRatio,
|
|
927
|
+
routeFamiliesOf,
|
|
922
928
|
runAdmissionDtoSchema,
|
|
923
929
|
runCompletenessDtoSchema,
|
|
924
930
|
runDetailDtoSchema,
|
|
@@ -1068,7 +1074,7 @@ import {
|
|
|
1068
1074
|
wordpressSchemaDeployResultDtoSchema,
|
|
1069
1075
|
wordpressSchemaStatusResultDtoSchema,
|
|
1070
1076
|
wordpressStatusDtoSchema
|
|
1071
|
-
} from "./chunk-
|
|
1077
|
+
} from "./chunk-OMXWBR2R.js";
|
|
1072
1078
|
|
|
1073
1079
|
// ../api-routes/src/user-session.ts
|
|
1074
1080
|
import crypto2 from "crypto";
|
|
@@ -6541,6 +6547,114 @@ function registerAgentConversationRoutes(app, opts) {
|
|
|
6541
6547
|
});
|
|
6542
6548
|
}
|
|
6543
6549
|
|
|
6550
|
+
// ../api-routes/src/egress-policy.ts
|
|
6551
|
+
import net from "net";
|
|
6552
|
+
function blockedAddressReason(value, options = {}) {
|
|
6553
|
+
const address = stripZoneId(stripIpv6Brackets(value));
|
|
6554
|
+
if (options.allowLoopback && isLoopbackAddress(address)) return null;
|
|
6555
|
+
const family = net.isIP(address);
|
|
6556
|
+
if (family === 4) return blockedIpv4Reason(ipv4Octets(address));
|
|
6557
|
+
if (family === 6) {
|
|
6558
|
+
const bytes = ipv6Bytes(address);
|
|
6559
|
+
return bytes ? blockedIpv6Reason(bytes) : "which could not be read as an address";
|
|
6560
|
+
}
|
|
6561
|
+
return "which is not an IP address";
|
|
6562
|
+
}
|
|
6563
|
+
function isLoopbackAddress(value) {
|
|
6564
|
+
const address = stripZoneId(stripIpv6Brackets(value));
|
|
6565
|
+
const family = net.isIP(address);
|
|
6566
|
+
if (family === 4) return ipv4Octets(address)[0] === 127;
|
|
6567
|
+
if (family !== 6) return false;
|
|
6568
|
+
const bytes = ipv6Bytes(address);
|
|
6569
|
+
if (!bytes) return false;
|
|
6570
|
+
const mapped = mappedIpv4(bytes);
|
|
6571
|
+
if (mapped) return mapped[0] === 127;
|
|
6572
|
+
return bytes.slice(0, 15).every((byte) => byte === 0) && bytes[15] === 1;
|
|
6573
|
+
}
|
|
6574
|
+
function stripIpv6Brackets(value) {
|
|
6575
|
+
return value.startsWith("[") && value.endsWith("]") ? value.slice(1, -1) : value;
|
|
6576
|
+
}
|
|
6577
|
+
function stripZoneId(address) {
|
|
6578
|
+
return address.split("%")[0];
|
|
6579
|
+
}
|
|
6580
|
+
function ipv4Octets(address) {
|
|
6581
|
+
return address.split(".").map((part) => Number.parseInt(part, 10));
|
|
6582
|
+
}
|
|
6583
|
+
function blockedIpv4Reason(octets) {
|
|
6584
|
+
const [first, second] = octets;
|
|
6585
|
+
if (first === 0) return "which is unspecified space";
|
|
6586
|
+
if (first === 127) return "which is loopback";
|
|
6587
|
+
if (first === 10 || first === 172 && second >= 16 && second <= 31 || first === 192 && second === 168) {
|
|
6588
|
+
return "which is private space";
|
|
6589
|
+
}
|
|
6590
|
+
if (first === 100 && second >= 64 && second <= 127) return "which is carrier-grade NAT space";
|
|
6591
|
+
if (first === 169 && second === 254) return "which is link-local";
|
|
6592
|
+
if (first >= 224 && first <= 239) return "which is multicast";
|
|
6593
|
+
if (first === 192 && second === 0 && octets[2] === 0 || first === 198 && (second === 18 || second === 19) || first >= 240) {
|
|
6594
|
+
return "which is reserved";
|
|
6595
|
+
}
|
|
6596
|
+
return null;
|
|
6597
|
+
}
|
|
6598
|
+
function blockedIpv6Reason(bytes) {
|
|
6599
|
+
const first = bytes[0];
|
|
6600
|
+
if (first === 0) {
|
|
6601
|
+
const nat64 = nat64Ipv4(bytes);
|
|
6602
|
+
if (nat64) return blockedIpv4Reason(nat64) === null ? null : `which is the NAT64 form of ${nat64.join(".")}`;
|
|
6603
|
+
const mapped = mappedIpv4(bytes);
|
|
6604
|
+
return mapped ? `which is the IPv6 form of ${mapped.join(".")}` : "which is reserved IPv6 space";
|
|
6605
|
+
}
|
|
6606
|
+
if (first === 1 && bytes.slice(1, 8).every((byte) => byte === 0)) return "which is reserved IPv6 space";
|
|
6607
|
+
if (first === 255) return "which is multicast";
|
|
6608
|
+
if ((first & 254) === 252) return "which is unique-local";
|
|
6609
|
+
if (first === 254 && (bytes[1] & 192) === 128) return "which is link-local";
|
|
6610
|
+
if (first === 254 && (bytes[1] & 192) === 192) return "which is reserved site-local space";
|
|
6611
|
+
if (first === 32 && bytes[1] === 1 && bytes[2] === 0 && bytes[3] === 0) return "which is a Teredo tunnel";
|
|
6612
|
+
if (first === 32 && bytes[1] === 2) return "which is a 6to4 tunnel";
|
|
6613
|
+
if (first === 32 && bytes[1] === 1 && bytes[2] === 0 && bytes[3] === 2 && bytes[4] === 0 && bytes[5] === 0) {
|
|
6614
|
+
return "which is reserved IPv6 space";
|
|
6615
|
+
}
|
|
6616
|
+
return null;
|
|
6617
|
+
}
|
|
6618
|
+
function mappedIpv4(bytes) {
|
|
6619
|
+
const isMapped = bytes.slice(0, 10).every((byte) => byte === 0) && bytes[10] === 255 && bytes[11] === 255;
|
|
6620
|
+
return isMapped ? [bytes[12], bytes[13], bytes[14], bytes[15]] : null;
|
|
6621
|
+
}
|
|
6622
|
+
var NAT64_WELL_KNOWN_PREFIX = [0, 100, 255, 155, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
6623
|
+
function nat64Ipv4(bytes) {
|
|
6624
|
+
const isNat64 = NAT64_WELL_KNOWN_PREFIX.every((byte, index) => bytes[index] === byte);
|
|
6625
|
+
return isNat64 ? [bytes[12], bytes[13], bytes[14], bytes[15]] : null;
|
|
6626
|
+
}
|
|
6627
|
+
function ipv6Bytes(address) {
|
|
6628
|
+
if (!net.isIPv6(address)) return null;
|
|
6629
|
+
const halves = address.split("::");
|
|
6630
|
+
if (halves.length > 2) return null;
|
|
6631
|
+
const expand = (text) => {
|
|
6632
|
+
if (text === "") return [];
|
|
6633
|
+
const groups2 = [];
|
|
6634
|
+
const chunks = text.split(":");
|
|
6635
|
+
for (const [index, chunk] of chunks.entries()) {
|
|
6636
|
+
if (index === chunks.length - 1 && chunk.includes(".")) {
|
|
6637
|
+
const octets = ipv4Octets(chunk);
|
|
6638
|
+
groups2.push(octets[0] << 8 | octets[1], octets[2] << 8 | octets[3]);
|
|
6639
|
+
continue;
|
|
6640
|
+
}
|
|
6641
|
+
groups2.push(Number.parseInt(chunk, 16));
|
|
6642
|
+
}
|
|
6643
|
+
return groups2;
|
|
6644
|
+
};
|
|
6645
|
+
const head = expand(halves[0]);
|
|
6646
|
+
const tail = halves.length === 2 ? expand(halves[1]) : [];
|
|
6647
|
+
const missing = 8 - head.length - tail.length;
|
|
6648
|
+
if (halves.length === 1 ? missing !== 0 : missing < 0) return null;
|
|
6649
|
+
const groups = [...head, ...new Array(halves.length === 2 ? missing : 0).fill(0), ...tail];
|
|
6650
|
+
const bytes = new Uint8Array(16);
|
|
6651
|
+
for (const [index, group] of groups.entries()) {
|
|
6652
|
+
bytes[index * 2] = group >> 8;
|
|
6653
|
+
bytes[index * 2 + 1] = group & 255;
|
|
6654
|
+
}
|
|
6655
|
+
return bytes;
|
|
6656
|
+
}
|
|
6657
|
+
|
|
6544
6658
|
// ../api-routes/src/index.ts
|
|
6545
6659
|
import rateLimit from "@fastify/rate-limit";
|
|
6546
6660
|
import fs8 from "fs";
|
|
@@ -7736,6 +7850,7 @@ function registerOAuthRoutesIn(app, opts) {
|
|
|
7736
7850
|
}
|
|
7737
7851
|
);
|
|
7738
7852
|
const { db, issuer } = opts;
|
|
7853
|
+
const authorizationPath = opts.authorizationPath ?? "/oauth/authorize";
|
|
7739
7854
|
const resourcePaths = opts.resourcePaths;
|
|
7740
7855
|
const canonicalPath = resourcePaths[0] ?? "/api/v1/mcp";
|
|
7741
7856
|
const resourceUrl = `${issuer}${canonicalPath}`;
|
|
@@ -7745,7 +7860,7 @@ function registerOAuthRoutesIn(app, opts) {
|
|
|
7745
7860
|
function authorizationServerMetadata() {
|
|
7746
7861
|
return {
|
|
7747
7862
|
issuer,
|
|
7748
|
-
authorization_endpoint: `${issuer}
|
|
7863
|
+
authorization_endpoint: `${issuer}${authorizationPath}`,
|
|
7749
7864
|
token_endpoint: `${issuer}/oauth/token`,
|
|
7750
7865
|
revocation_endpoint: `${issuer}/oauth/revoke`,
|
|
7751
7866
|
// RFC 7591. The current MCP revision calls DCR deprecated and prefers
|
|
@@ -7776,7 +7891,19 @@ function registerOAuthRoutesIn(app, opts) {
|
|
|
7776
7891
|
}));
|
|
7777
7892
|
}
|
|
7778
7893
|
app.get("/.well-known/oauth-authorization-server", async () => authorizationServerMetadata());
|
|
7779
|
-
|
|
7894
|
+
if (authorizationPath !== "/oauth/authorize") {
|
|
7895
|
+
for (const suffix of ["", "/consent"]) {
|
|
7896
|
+
app.route({
|
|
7897
|
+
method: suffix ? ["POST"] : ["GET", "POST"],
|
|
7898
|
+
url: `/oauth/authorize${suffix}`,
|
|
7899
|
+
handler: async (request, reply) => {
|
|
7900
|
+
const query = request.url.includes("?") ? request.url.slice(request.url.indexOf("?")) : "";
|
|
7901
|
+
return reply.redirect(`${authorizationPath}${suffix}${query}`, 307);
|
|
7902
|
+
}
|
|
7903
|
+
});
|
|
7904
|
+
}
|
|
7905
|
+
}
|
|
7906
|
+
app.get(authorizationPath, async (request, reply) => {
|
|
7780
7907
|
const q = request.query;
|
|
7781
7908
|
const clientId = q.client_id;
|
|
7782
7909
|
const redirectUri = q.redirect_uri;
|
|
@@ -7811,7 +7938,7 @@ function registerOAuthRoutesIn(app, opts) {
|
|
|
7811
7938
|
csrf: consentToken(user.id, clientId, redirectUri, grantedScope)
|
|
7812
7939
|
}));
|
|
7813
7940
|
});
|
|
7814
|
-
app.post(
|
|
7941
|
+
app.post(`${authorizationPath}/consent`, async (request, reply) => {
|
|
7815
7942
|
assertCookieWriteOrigin(request);
|
|
7816
7943
|
const q = request.query;
|
|
7817
7944
|
const body = request.body ?? {};
|
|
@@ -7921,7 +8048,7 @@ function registerOAuthRoutesIn(app, opts) {
|
|
|
7921
8048
|
token_endpoint_auth_method: "none"
|
|
7922
8049
|
});
|
|
7923
8050
|
});
|
|
7924
|
-
app.post(
|
|
8051
|
+
app.post(authorizationPath, async (request, reply) => {
|
|
7925
8052
|
assertCookieWriteOrigin(request);
|
|
7926
8053
|
const body = request.body ?? {};
|
|
7927
8054
|
const name = body.name?.trim();
|
|
@@ -8628,29 +8755,67 @@ function connectionRoute(app, subjectOf, handler) {
|
|
|
8628
8755
|
}
|
|
8629
8756
|
|
|
8630
8757
|
// ../api-routes/src/provider-models.ts
|
|
8631
|
-
function
|
|
8758
|
+
function providerRouteFamilies(adapters) {
|
|
8759
|
+
return routeFamiliesOf(adapters);
|
|
8760
|
+
}
|
|
8761
|
+
function assertProviderRouteScope(request, selected, authorized, families) {
|
|
8632
8762
|
const saved = new Set(authorized.map((name) => name.trim().toLowerCase()));
|
|
8633
|
-
if (selected.some((name) =>
|
|
8763
|
+
if (selected.some((name) => resolveProviderRoute(name.trim().toLowerCase(), families) && !saved.has(name.trim().toLowerCase()))) {
|
|
8634
8764
|
requireScope(request, SETTINGS_WRITE_SCOPE);
|
|
8635
8765
|
}
|
|
8636
8766
|
}
|
|
8767
|
+
var assertOpenRouterRouteScope = assertProviderRouteScope;
|
|
8768
|
+
function invalidProviderSelections(names, available, adapters, workflow) {
|
|
8769
|
+
const families = providerRouteFamilies(adapters);
|
|
8770
|
+
return names.filter((name) => {
|
|
8771
|
+
if (!isSweepProvider(name, families) || !isProviderAvailable(name, available, families)) return true;
|
|
8772
|
+
const adapter = adapters ? providerAdapterForName(name, adapters) : void 0;
|
|
8773
|
+
return adapter !== void 0 && !isEligibleFor(adapter, workflow, "explicit");
|
|
8774
|
+
});
|
|
8775
|
+
}
|
|
8776
|
+
function providerEligibleFor(name, adapters, workflow, selection) {
|
|
8777
|
+
const families = providerRouteFamilies(adapters);
|
|
8778
|
+
if (!isSweepProvider(name, families)) return false;
|
|
8779
|
+
const adapter = adapters ? providerAdapterForName(name, adapters) : void 0;
|
|
8780
|
+
return adapter === void 0 ? selection === "explicit" : isEligibleFor(adapter, workflow, selection);
|
|
8781
|
+
}
|
|
8782
|
+
function pinnedRouteSelection(name, families) {
|
|
8783
|
+
return resolveProviderRoute(name, families)?.selection;
|
|
8784
|
+
}
|
|
8637
8785
|
function providerAdapterForName(name, adapters) {
|
|
8638
8786
|
const direct = adapters.find((adapter) => adapter.name === name);
|
|
8639
8787
|
if (direct) return direct;
|
|
8640
|
-
const
|
|
8641
|
-
const connection =
|
|
8642
|
-
if (!connection || !
|
|
8788
|
+
const route = resolveProviderRoute(name, providerRouteFamilies(adapters));
|
|
8789
|
+
const connection = route && adapters.find((adapter) => adapter.name === route.connection);
|
|
8790
|
+
if (!connection || !route) return void 0;
|
|
8791
|
+
if (route.family.selectionKind === "profile") {
|
|
8792
|
+
const profile = connection.profiles?.find((item2) => item2.id === route.selection);
|
|
8793
|
+
if (!profile) return void 0;
|
|
8794
|
+
return {
|
|
8795
|
+
...connection,
|
|
8796
|
+
name,
|
|
8797
|
+
displayName: `${profile.displayName} \xB7 ${connection.displayName}`,
|
|
8798
|
+
modelConfigurable: false,
|
|
8799
|
+
defaultModel: profile.id,
|
|
8800
|
+
knownModels: [{ id: profile.id, displayName: profile.displayName, tier: "standard" }],
|
|
8801
|
+
modelValidationPattern: new RegExp(`^${escapeRegExp(profile.id)}$`),
|
|
8802
|
+
modelValidationHint: `The ${connection.displayName} route pins its profile; select another route to change it.`,
|
|
8803
|
+
capabilities: { textGeneration: false, groundedAnswer: true, workflows: [...profile.workflows] },
|
|
8804
|
+
profiles: [profile]
|
|
8805
|
+
};
|
|
8806
|
+
}
|
|
8807
|
+
const model = route.selection;
|
|
8643
8808
|
connection.modelValidationPattern.lastIndex = 0;
|
|
8644
8809
|
if (!connection.modelValidationPattern.test(model)) return void 0;
|
|
8645
8810
|
const known = connection.knownModels.find((entry) => entry.id === model);
|
|
8646
8811
|
return {
|
|
8647
8812
|
...connection,
|
|
8648
8813
|
name,
|
|
8649
|
-
displayName: `${known?.displayName ?? model} via
|
|
8814
|
+
displayName: `${known?.displayName ?? model} via ${connection.displayName}`,
|
|
8650
8815
|
modelConfigurable: false,
|
|
8651
8816
|
defaultModel: model,
|
|
8652
8817
|
knownModels: known ? [known] : [],
|
|
8653
|
-
modelValidationHint:
|
|
8818
|
+
modelValidationHint: `The ${connection.displayName} route pins its model; select another route to change it.`
|
|
8654
8819
|
};
|
|
8655
8820
|
}
|
|
8656
8821
|
function validateProviderModels(models, adapters) {
|
|
@@ -8668,9 +8833,11 @@ function validateProviderModels(models, adapters) {
|
|
|
8668
8833
|
validProviders: adapters.map((item2) => item2.name)
|
|
8669
8834
|
});
|
|
8670
8835
|
}
|
|
8671
|
-
const
|
|
8836
|
+
const route = resolveProviderRoute(provider, providerRouteFamilies(adapters));
|
|
8837
|
+
const pinned = route?.selection;
|
|
8672
8838
|
if (pinned && rawModel.trim() !== pinned) {
|
|
8673
|
-
|
|
8839
|
+
const connection = adapters.find((item2) => item2.name === route.connection)?.displayName ?? route.connection;
|
|
8840
|
+
throw validationError(`${connection} route "${provider}" pins ${route.family.selectionKind} "${pinned}". Select another route to change it.`, { provider, model: rawModel, pinnedModel: pinned });
|
|
8674
8841
|
}
|
|
8675
8842
|
if (!adapter.modelConfigurable && !pinned) {
|
|
8676
8843
|
throw validationError(`Provider "${provider}" does not support project model overrides.`, {
|
|
@@ -8726,6 +8893,21 @@ function pruneProviderDispatchModes(modes, providers, revisionProviders) {
|
|
|
8726
8893
|
|
|
8727
8894
|
// ../api-routes/src/settings.ts
|
|
8728
8895
|
var SETTINGS_WRITE_SCOPE = "settings.write";
|
|
8896
|
+
function descriptorFields(adapter) {
|
|
8897
|
+
if (!adapter.kind && !adapter.routes && !adapter.profiles) return {};
|
|
8898
|
+
return {
|
|
8899
|
+
...adapter.kind ? { kind: adapter.kind } : {},
|
|
8900
|
+
connection: adapter.routes?.connection ?? adapter.name,
|
|
8901
|
+
selectionKind: adapter.routes?.selectionKind ?? null,
|
|
8902
|
+
...adapter.profiles ? { profiles: adapter.profiles } : {},
|
|
8903
|
+
...adapter.capabilities?.workflows ? { workflows: [...adapter.capabilities.workflows] } : {},
|
|
8904
|
+
...adapter.capabilities ? { textGeneration: adapter.capabilities.textGeneration } : {},
|
|
8905
|
+
...adapter.settingsFields ? { settingsFields: adapter.settingsFields } : {},
|
|
8906
|
+
...adapter.keyCheck ? { keyCheck: adapter.keyCheck } : {},
|
|
8907
|
+
...adapter.keyUrl ? { keyUrl: adapter.keyUrl } : {},
|
|
8908
|
+
...adapter.vendorDocsUrl ? { vendorDocsUrl: adapter.vendorDocsUrl } : {}
|
|
8909
|
+
};
|
|
8910
|
+
}
|
|
8729
8911
|
async function settingsRoutes(app, opts) {
|
|
8730
8912
|
app.get("/settings", async (request) => {
|
|
8731
8913
|
requireAdminSession(request);
|
|
@@ -8734,6 +8916,7 @@ async function settingsRoutes(app, opts) {
|
|
|
8734
8916
|
providerCatalog: (await Promise.all((opts.providerAdapters ?? []).map(async (adapter) => {
|
|
8735
8917
|
const configured = opts.providerSummary?.some((provider) => provider.name === adapter.name && provider.configured);
|
|
8736
8918
|
const discovered = configured && opts.getProviderModels ? await opts.getProviderModels(adapter.name) : [];
|
|
8919
|
+
const knownModels = discovered.length ? discovered : adapter.knownModels;
|
|
8737
8920
|
const descriptor = {
|
|
8738
8921
|
name: adapter.name,
|
|
8739
8922
|
displayName: adapter.displayName,
|
|
@@ -8742,19 +8925,40 @@ async function settingsRoutes(app, opts) {
|
|
|
8742
8925
|
defaultModel: adapter.defaultModel,
|
|
8743
8926
|
// Catalog entries can carry Aero's model metadata (limits, prices,
|
|
8744
8927
|
// tool support); the documented choice shape is id, name and tier.
|
|
8745
|
-
knownModels:
|
|
8928
|
+
knownModels: knownModels.map(({ id, displayName, tier }) => ({ id, displayName, tier })),
|
|
8746
8929
|
modelValidationPattern: {
|
|
8747
8930
|
source: adapter.modelValidationPattern.source,
|
|
8748
8931
|
flags: adapter.modelValidationPattern.flags
|
|
8749
8932
|
},
|
|
8750
|
-
modelValidationHint: adapter.modelValidationHint
|
|
8933
|
+
modelValidationHint: adapter.modelValidationHint,
|
|
8934
|
+
...descriptorFields(adapter)
|
|
8751
8935
|
};
|
|
8752
|
-
|
|
8753
|
-
|
|
8754
|
-
|
|
8755
|
-
|
|
8756
|
-
|
|
8757
|
-
|
|
8936
|
+
const family = routeFamiliesOf(opts.providerAdapters).find((item2) => item2.connection === adapter.name);
|
|
8937
|
+
if (!family) return [descriptor];
|
|
8938
|
+
const selections = family.selectionKind === "profile" ? (adapter.profiles ?? []).map((profile) => profile.id) : knownModels.map((model) => model.id);
|
|
8939
|
+
const routeAdapters = selections.flatMap((selection) => {
|
|
8940
|
+
let routeName;
|
|
8941
|
+
try {
|
|
8942
|
+
routeName = providerRouteName(family, selection);
|
|
8943
|
+
} catch {
|
|
8944
|
+
return [];
|
|
8945
|
+
}
|
|
8946
|
+
const route = providerAdapterForName(routeName, [{ ...adapter, knownModels }]);
|
|
8947
|
+
if (!route) return [];
|
|
8948
|
+
const fields = descriptorFields(route);
|
|
8949
|
+
return [{
|
|
8950
|
+
...descriptor,
|
|
8951
|
+
...fields,
|
|
8952
|
+
name: route.name,
|
|
8953
|
+
displayName: route.displayName,
|
|
8954
|
+
modelConfigurable: false,
|
|
8955
|
+
defaultModel: route.defaultModel,
|
|
8956
|
+
knownModels: route.knownModels,
|
|
8957
|
+
modelValidationPattern: { source: route.modelValidationPattern.source, flags: route.modelValidationPattern.flags },
|
|
8958
|
+
modelValidationHint: route.modelValidationHint,
|
|
8959
|
+
// A route is a target, not a connection: it selects nothing further and holds no key.
|
|
8960
|
+
...Object.keys(fields).length > 0 ? { selectionKind: null, settingsFields: void 0, keyCheck: void 0 } : {}
|
|
8961
|
+
}];
|
|
8758
8962
|
});
|
|
8759
8963
|
return [descriptor, ...routeAdapters];
|
|
8760
8964
|
}))).flat(),
|
|
@@ -8812,6 +9016,10 @@ async function settingsRoutes(app, opts) {
|
|
|
8812
9016
|
throw validationError("apiKey is required");
|
|
8813
9017
|
}
|
|
8814
9018
|
}
|
|
9019
|
+
if (adapterInfo.kind === ProviderKinds["answer-service"]) {
|
|
9020
|
+
if (baseUrl !== void 0) throw validationError(`${adapterInfo.displayName} uses a fixed endpoint; baseUrl is not accepted.`, { provider: name });
|
|
9021
|
+
if (model !== void 0) throw validationError(`${adapterInfo.displayName} has no connection model; choose profiles per project instead.`, { provider: name });
|
|
9022
|
+
}
|
|
8815
9023
|
if (model !== void 0) {
|
|
8816
9024
|
if (!adapterInfo.modelValidationPattern.test(model)) {
|
|
8817
9025
|
throw validationError(
|
|
@@ -10276,14 +10484,15 @@ function resolveRunProviderSelection(input) {
|
|
|
10276
10484
|
return resolveRunnableProviderSelection(input).selectedProviders;
|
|
10277
10485
|
}
|
|
10278
10486
|
function resolveRunnableProviderSelection(input) {
|
|
10487
|
+
const families = input.routeFamilies ?? void 0;
|
|
10279
10488
|
const availableProviders = normalizeProviders(input.runnableProviders ?? []);
|
|
10280
10489
|
const requested = normalizeProviders(input.requestedProviders ?? []);
|
|
10281
10490
|
const project = normalizeProviders(input.projectProviders ?? []);
|
|
10282
|
-
const selectedProviders = requested.length > 0 ? requested : project.length > 0 ? project : availableProviders.filter(isSweepProvider);
|
|
10491
|
+
const selectedProviders = requested.length > 0 ? requested : project.length > 0 ? project : availableProviders.filter((provider) => isSweepProvider(provider, families));
|
|
10283
10492
|
return {
|
|
10284
10493
|
availableProviders,
|
|
10285
10494
|
selectedProviders,
|
|
10286
|
-
runnableProviders: selectedProviders.filter((provider) => isSweepProvider(provider) && isProviderAvailable(provider, availableProviders)),
|
|
10495
|
+
runnableProviders: selectedProviders.filter((provider) => isSweepProvider(provider, families) && isProviderAvailable(provider, availableProviders, families)),
|
|
10287
10496
|
selectionSource: requested.length > 0 ? "request" : project.length > 0 ? "project" : "instance"
|
|
10288
10497
|
};
|
|
10289
10498
|
}
|
|
@@ -10291,7 +10500,8 @@ function providerRoster(tx, params) {
|
|
|
10291
10500
|
return resolveRunProviderSelection({
|
|
10292
10501
|
requestedProviders: params.providers,
|
|
10293
10502
|
projectProviders: tx.select({ providers: projects.providers }).from(projects).where(eq19(projects.id, params.projectId)).get()?.providers ?? [],
|
|
10294
|
-
runnableProviders: params.runnableProviders
|
|
10503
|
+
runnableProviders: params.runnableProviders,
|
|
10504
|
+
routeFamilies: params.routeFamilies
|
|
10295
10505
|
});
|
|
10296
10506
|
}
|
|
10297
10507
|
function effectiveModels(tx, params, providers) {
|
|
@@ -10299,7 +10509,7 @@ function effectiveModels(tx, params, providers) {
|
|
|
10299
10509
|
const instance = params.providerModels ?? {};
|
|
10300
10510
|
const resolved = {};
|
|
10301
10511
|
for (const provider of providers) {
|
|
10302
|
-
const model =
|
|
10512
|
+
const model = resolveProviderRoute(provider, params.routeFamilies ?? void 0)?.selection ?? overrides[provider] ?? instance[provider];
|
|
10303
10513
|
if (model) resolved[provider] = resolveProviderModel(provider, model);
|
|
10304
10514
|
}
|
|
10305
10515
|
return resolved;
|
|
@@ -10335,7 +10545,7 @@ function executionSlotIdentity(node, providers, models) {
|
|
|
10335
10545
|
providers.map((provider) => [provider, models.get(provider) ?? null])
|
|
10336
10546
|
])).digest("hex");
|
|
10337
10547
|
}
|
|
10338
|
-
function materializeV2ExecutionNodes(nodes, instanceModels) {
|
|
10548
|
+
function materializeV2ExecutionNodes(nodes, instanceModels, routeFamilies) {
|
|
10339
10549
|
const expectedSlots = [];
|
|
10340
10550
|
const providers = /* @__PURE__ */ new Set();
|
|
10341
10551
|
const models = /* @__PURE__ */ new Map();
|
|
@@ -10347,9 +10557,10 @@ function materializeV2ExecutionNodes(nodes, instanceModels) {
|
|
|
10347
10557
|
const declared = nodeProviderModels(node);
|
|
10348
10558
|
const resolved = /* @__PURE__ */ new Map();
|
|
10349
10559
|
for (const provider of nodeProviders) {
|
|
10350
|
-
const
|
|
10560
|
+
const route = resolveProviderRoute(provider, routeFamilies);
|
|
10561
|
+
const pinned = route?.selection;
|
|
10351
10562
|
if (pinned && declared.has(provider) && declared.get(provider) !== pinned) {
|
|
10352
|
-
throw validationError(
|
|
10563
|
+
throw validationError(`${route.connection === ProviderNames.openrouter ? "OpenRouter" : "The"} route "${provider}" cannot override its pinned ${route.family.selectionKind}.`);
|
|
10353
10564
|
}
|
|
10354
10565
|
const model = pinned ?? declared.get(provider) ?? instanceModels[provider];
|
|
10355
10566
|
if (model) resolved.set(provider, model);
|
|
@@ -10456,7 +10667,7 @@ function measurementStampV2(plan, versionId, params) {
|
|
|
10456
10667
|
"The published measurement plan has no execution nodes, so this run would measure nothing. Publish a revision with at least one property assigned to a question."
|
|
10457
10668
|
);
|
|
10458
10669
|
}
|
|
10459
|
-
const materialized = materializeV2ExecutionNodes(nodes, params.providerModels ?? {});
|
|
10670
|
+
const materialized = materializeV2ExecutionNodes(nodes, params.providerModels ?? {}, params.routeFamilies ?? void 0);
|
|
10460
10671
|
const requested = normalizeProviders(params.providers ?? []);
|
|
10461
10672
|
if (requested.length && requested.join("\0") !== materialized.providers.join("\0")) {
|
|
10462
10673
|
throw validationError(
|
|
@@ -10481,7 +10692,7 @@ function measurementStamp(tx, params) {
|
|
|
10481
10692
|
if (!active) {
|
|
10482
10693
|
if (!measurementRunScopeIsEmpty(params.measurementScope)) {
|
|
10483
10694
|
throw validationError(
|
|
10484
|
-
"This project has no published measurement plan, so there is nothing for a group or target scope to point at. Publish a plan first, or run a full
|
|
10695
|
+
"This project has no published measurement plan, so there is nothing for a group or target scope to point at. Publish a plan first, or run a full AI Visibility check."
|
|
10485
10696
|
);
|
|
10486
10697
|
}
|
|
10487
10698
|
return null;
|
|
@@ -10604,15 +10815,18 @@ function queueProviderAdmission(db, params, stamp, now) {
|
|
|
10604
10815
|
now,
|
|
10605
10816
|
providers: () => providersARunWouldCall(
|
|
10606
10817
|
stamp?.identity.providers ?? providerRoster(db, params),
|
|
10607
|
-
params.runnableProviders
|
|
10608
|
-
|
|
10818
|
+
params.runnableProviders,
|
|
10819
|
+
params.routeFamilies
|
|
10820
|
+
),
|
|
10821
|
+
routeFamilies: params.routeFamilies
|
|
10609
10822
|
}) : { skipped: {} };
|
|
10610
10823
|
}
|
|
10611
|
-
function providersARunWouldCall(roster, runnable) {
|
|
10824
|
+
function providersARunWouldCall(roster, runnable, routeFamilies) {
|
|
10612
10825
|
const listed = normalizeProviders(roster);
|
|
10613
10826
|
if (runnable == null) return listed;
|
|
10827
|
+
const families = routeFamilies ?? void 0;
|
|
10614
10828
|
const available = normalizeProviders(runnable);
|
|
10615
|
-
return listed.filter((provider) => isSweepProvider(provider) && isProviderAvailable(provider, available));
|
|
10829
|
+
return listed.filter((provider) => isSweepProvider(provider, families) && isProviderAvailable(provider, available, families));
|
|
10616
10830
|
}
|
|
10617
10831
|
var PROVIDER_ACCOUNT_LOOKBACK = PROVIDER_ACCOUNT_FAILURE_STREAK * 5;
|
|
10618
10832
|
function providerSettingsChangeCouldFix(action, diff) {
|
|
@@ -10629,6 +10843,8 @@ function providerSettingsChangeCouldFix(action, diff) {
|
|
|
10629
10843
|
}
|
|
10630
10844
|
}
|
|
10631
10845
|
function heldProviderAccounts(db, params) {
|
|
10846
|
+
const families = params.routeFamilies ?? void 0;
|
|
10847
|
+
const connectionOf = (name) => providerConnectionName(name, families);
|
|
10632
10848
|
const held = /* @__PURE__ */ new Map();
|
|
10633
10849
|
const recent = db.select({
|
|
10634
10850
|
id: runs.id,
|
|
@@ -10650,7 +10866,7 @@ function heldProviderAccounts(db, params) {
|
|
|
10650
10866
|
const answered2 = (runId, provider) => db.select({ id: querySnapshots.id }).from(querySnapshots).where(and13(eq19(querySnapshots.runId, runId), provider === ProviderNames.openrouter ? or3(eq19(querySnapshots.provider, provider), like2(querySnapshots.provider, "openrouter:%")) : eq19(querySnapshots.provider, provider))).limit(1).get() !== void 0;
|
|
10651
10867
|
const finished = (run) => Date.parse(run.finishedAt ?? run.createdAt);
|
|
10652
10868
|
const now = Date.parse(params.now);
|
|
10653
|
-
const accounts = [...new Set(calling.map(
|
|
10869
|
+
const accounts = [...new Set(calling.map(connectionOf))];
|
|
10654
10870
|
for (const provider of accounts) {
|
|
10655
10871
|
let count9 = 0;
|
|
10656
10872
|
let newest = null;
|
|
@@ -10663,7 +10879,7 @@ function heldProviderAccounts(db, params) {
|
|
|
10663
10879
|
ended = true;
|
|
10664
10880
|
break;
|
|
10665
10881
|
}
|
|
10666
|
-
const accountEntries = Object.entries(run.providers).filter(([name]) =>
|
|
10882
|
+
const accountEntries = Object.entries(run.providers).filter(([name]) => connectionOf(name) === provider).map(([, entry2]) => entry2);
|
|
10667
10883
|
const entry = accountEntries.find((entry2) => !entry2.skipped && !isProviderAccountFailure(entry2.code)) ?? accountEntries.find((entry2) => !entry2.skipped) ?? accountEntries[0];
|
|
10668
10884
|
if (!entry) {
|
|
10669
10885
|
if (run.status !== RunStatuses.failed && answered2(run.id, provider)) {
|
|
@@ -10673,7 +10889,7 @@ function heldProviderAccounts(db, params) {
|
|
|
10673
10889
|
continue;
|
|
10674
10890
|
}
|
|
10675
10891
|
if (entry.skipped) {
|
|
10676
|
-
vouched = Object.entries(run.skippedProviders ?? {}).find(([name]) =>
|
|
10892
|
+
vouched = Object.entries(run.skippedProviders ?? {}).find(([name]) => connectionOf(name) === provider)?.[1] ?? null;
|
|
10677
10893
|
if (vouched) break;
|
|
10678
10894
|
continue;
|
|
10679
10895
|
}
|
|
@@ -10710,7 +10926,7 @@ function heldProviderAccounts(db, params) {
|
|
|
10710
10926
|
}
|
|
10711
10927
|
}
|
|
10712
10928
|
return new Map(calling.flatMap((provider) => {
|
|
10713
|
-
const streak = held.get(
|
|
10929
|
+
const streak = held.get(connectionOf(provider));
|
|
10714
10930
|
return streak ? [[provider, streak]] : [];
|
|
10715
10931
|
}));
|
|
10716
10932
|
}
|
|
@@ -10730,26 +10946,27 @@ function providerAccountAdmission(db, params) {
|
|
|
10730
10946
|
if (params.force || params.trigger === RunTriggers.probe) return { skipped: {} };
|
|
10731
10947
|
let calling = null;
|
|
10732
10948
|
const providers = () => calling ??= normalizeProviders(params.providers());
|
|
10733
|
-
const held = heldProviderAccounts(db, { projectId: params.projectId, now: params.now, providers });
|
|
10949
|
+
const held = heldProviderAccounts(db, { projectId: params.projectId, now: params.now, providers, routeFamilies: params.routeFamilies });
|
|
10734
10950
|
if (held.size === 0) return { skipped: {} };
|
|
10735
10951
|
if (providers().every((provider) => held.has(provider))) return { refused: providerAccountFailures(held) };
|
|
10736
10952
|
return { skipped: Object.fromEntries(held) };
|
|
10737
10953
|
}
|
|
10738
|
-
function sweepProviders(db, projectId, runnable, selection) {
|
|
10954
|
+
function sweepProviders(db, projectId, runnable, selection, routeFamilies) {
|
|
10739
10955
|
const planProviders = activeRevisionProviders(db, projectId);
|
|
10740
|
-
if (planProviders.length > 0) return providersARunWouldCall(planProviders, runnable);
|
|
10956
|
+
if (planProviders.length > 0) return providersARunWouldCall(planProviders, runnable, routeFamilies);
|
|
10741
10957
|
const schedule = db.select({ providers: schedules.providers, enabled: schedules.enabled }).from(schedules).where(and13(eq19(schedules.projectId, projectId), eq19(schedules.kind, RunKinds["answer-visibility"]))).get();
|
|
10742
10958
|
const project = db.select({ providers: projects.providers }).from(projects).where(eq19(projects.id, projectId)).get();
|
|
10743
10959
|
return providersARunWouldCall(resolveRunProviderSelection({
|
|
10744
10960
|
requestedProviders: selection === RunTriggers.scheduled && schedule?.enabled ? schedule.providers : null,
|
|
10745
10961
|
projectProviders: project?.providers ?? [],
|
|
10746
|
-
runnableProviders: runnable
|
|
10747
|
-
|
|
10962
|
+
runnableProviders: runnable,
|
|
10963
|
+
routeFamilies
|
|
10964
|
+
}), runnable, routeFamilies);
|
|
10748
10965
|
}
|
|
10749
10966
|
function runAdmissionState(db, params) {
|
|
10750
10967
|
let calling = null;
|
|
10751
|
-
const providers = () => calling ??= sweepProviders(db, params.projectId, params.runnableProviders, params.selection ?? RunTriggers.scheduled);
|
|
10752
|
-
const held = heldProviderAccounts(db, { projectId: params.projectId, now: params.now, providers });
|
|
10968
|
+
const providers = () => calling ??= sweepProviders(db, params.projectId, params.runnableProviders, params.selection ?? RunTriggers.scheduled, params.routeFamilies);
|
|
10969
|
+
const held = heldProviderAccounts(db, { projectId: params.projectId, now: params.now, providers, routeFamilies: params.routeFamilies });
|
|
10753
10970
|
const refused = held.size > 0 && providers().every((provider) => held.has(provider));
|
|
10754
10971
|
return {
|
|
10755
10972
|
refused,
|
|
@@ -10929,6 +11146,7 @@ function redactNotificationDiff(value) {
|
|
|
10929
11146
|
|
|
10930
11147
|
// ../api-routes/src/projects.ts
|
|
10931
11148
|
async function projectRoutes(app, opts) {
|
|
11149
|
+
const routeFamilies = providerRouteFamilies(opts.providerAdapters);
|
|
10932
11150
|
const notifyProjectCreated = (projectId, projectName) => {
|
|
10933
11151
|
try {
|
|
10934
11152
|
opts.onProjectCreated?.(projectId, projectName);
|
|
@@ -10962,7 +11180,7 @@ async function projectRoutes(app, opts) {
|
|
|
10962
11180
|
}
|
|
10963
11181
|
const validNames = opts.providerAdapters?.map((adapter) => adapter.name) ?? [];
|
|
10964
11182
|
if (validNames.length && body.providers?.length) {
|
|
10965
|
-
const invalid = body.providers
|
|
11183
|
+
const invalid = invalidProviderSelections(body.providers, validNames, opts.providerAdapters, ProviderWorkflows["visibility-sweep"]);
|
|
10966
11184
|
if (invalid.length) {
|
|
10967
11185
|
throw validationError(`Invalid provider(s): ${invalid.join(", ")}. Must be one of: ${validNames.join(", ")}`, {
|
|
10968
11186
|
invalidProviders: invalid,
|
|
@@ -10971,7 +11189,7 @@ async function projectRoutes(app, opts) {
|
|
|
10971
11189
|
}
|
|
10972
11190
|
}
|
|
10973
11191
|
const nextProviders = body.providers ?? [];
|
|
10974
|
-
|
|
11192
|
+
assertProviderRouteScope(request, nextProviders, [], routeFamilies);
|
|
10975
11193
|
const providerModels = pruneProviderModelsForProviders(
|
|
10976
11194
|
validateProviderModels(body.providerModels ?? {}, opts.providerAdapters),
|
|
10977
11195
|
nextProviders
|
|
@@ -11049,7 +11267,7 @@ async function projectRoutes(app, opts) {
|
|
|
11049
11267
|
const prepareProjectUpdate = (request, body, existing) => {
|
|
11050
11268
|
const validNames = opts.providerAdapters?.map((adapter) => adapter.name) ?? [];
|
|
11051
11269
|
if (validNames.length && body.providers?.length) {
|
|
11052
|
-
const invalid = body.providers
|
|
11270
|
+
const invalid = invalidProviderSelections(body.providers, validNames, opts.providerAdapters, ProviderWorkflows["visibility-sweep"]);
|
|
11053
11271
|
if (invalid.length) {
|
|
11054
11272
|
throw validationError(`Invalid provider(s): ${invalid.join(", ")}. Must be one of: ${validNames.join(", ")}`, {
|
|
11055
11273
|
invalidProviders: invalid,
|
|
@@ -11058,7 +11276,7 @@ async function projectRoutes(app, opts) {
|
|
|
11058
11276
|
}
|
|
11059
11277
|
}
|
|
11060
11278
|
const nextProviders = body.providers ?? [];
|
|
11061
|
-
|
|
11279
|
+
assertProviderRouteScope(request, nextProviders, existing?.providers ?? [], routeFamilies);
|
|
11062
11280
|
const providerModels = pruneProviderModelsForProviders(
|
|
11063
11281
|
validateProviderModels(body.providerModels ?? {}, opts.providerAdapters),
|
|
11064
11282
|
nextProviders
|
|
@@ -12440,7 +12658,7 @@ import { and as and19, eq as eq26 } from "drizzle-orm";
|
|
|
12440
12658
|
// ../api-routes/src/snapshot-evidence-fingerprint.ts
|
|
12441
12659
|
import { createHash as createHash2 } from "crypto";
|
|
12442
12660
|
function snapshotEvidenceFingerprint(snapshots) {
|
|
12443
|
-
const canonical = [...snapshots].sort((left, right) => left.id.localeCompare(right.id)).map(({ dispatchMode: _dispatchMode, providerBatchId: _providerBatchId, stopReason: _stopReason, usage: _usage, mentionIdentity, wrongSubjectTargetKeys, ...evidence }) => JSON.stringify({
|
|
12661
|
+
const canonical = [...snapshots].sort((left, right) => left.id.localeCompare(right.id)).map(({ dispatchMode: _dispatchMode, providerBatchId: _providerBatchId, stopReason: _stopReason, usage: _usage, answerEvidence: _answerEvidence, mentionIdentity, wrongSubjectTargetKeys, ...evidence }) => JSON.stringify({
|
|
12444
12662
|
...evidence,
|
|
12445
12663
|
...mentionIdentity === null ? {} : { mentionIdentity },
|
|
12446
12664
|
...wrongSubjectTargetKeys === null ? {} : { wrongSubjectTargetKeys }
|
|
@@ -14499,7 +14717,7 @@ function evaluateRunFill(db, run, input = {}) {
|
|
|
14499
14717
|
if (run.trigger === RunTriggers.probe || run.measurementScope !== null || run.queries !== null) {
|
|
14500
14718
|
return refuse(
|
|
14501
14719
|
RunFillRefusalCodes.scoped_or_probe,
|
|
14502
|
-
"This run is a spot check that measured a slice on purpose. Only a full
|
|
14720
|
+
"This run is a spot check that measured a slice on purpose. Only a full AI Visibility check can be filled."
|
|
14503
14721
|
);
|
|
14504
14722
|
}
|
|
14505
14723
|
if (!slots.readable || slots.hasUnboundSnapshot) {
|
|
@@ -14512,7 +14730,7 @@ function evaluateRunFill(db, run, input = {}) {
|
|
|
14512
14730
|
if (run.status !== "partial") {
|
|
14513
14731
|
return refuse(
|
|
14514
14732
|
RunFillRefusalCodes.status_not_partial,
|
|
14515
|
-
`Run ${run.id} is ${run.status}. Only a partial run can be filled; run a new
|
|
14733
|
+
`Run ${run.id} is ${run.status}. Only a partial run can be filled; run a new AI Visibility check instead.`
|
|
14516
14734
|
);
|
|
14517
14735
|
}
|
|
14518
14736
|
const active = activePlanVersionRow(db, run.projectId);
|
|
@@ -14528,14 +14746,14 @@ function evaluateRunFill(db, run, input = {}) {
|
|
|
14528
14746
|
if (Number.isFinite(anchoredAt) && now - anchoredAt > RUN_FILL_MAX_AGE_MS) {
|
|
14529
14747
|
return refuse(
|
|
14530
14748
|
RunFillRefusalCodes.too_old,
|
|
14531
|
-
`Run ${run.id} ${age.basis} more than 24 hours ago. Answers captured now would not describe the same moment; run a new
|
|
14749
|
+
`Run ${run.id} ${age.basis} more than 24 hours ago. Answers captured now would not describe the same moment; run a new AI Visibility check instead.`
|
|
14532
14750
|
);
|
|
14533
14751
|
}
|
|
14534
14752
|
const newer = newerFullSweep(db, run);
|
|
14535
14753
|
if (newer) {
|
|
14536
14754
|
return refuse(
|
|
14537
14755
|
RunFillRefusalCodes.superseded,
|
|
14538
|
-
`A newer
|
|
14756
|
+
`A newer AI Visibility check (${newer.id}) exists and is what every report reads; fill that one instead if it is partial.`
|
|
14539
14757
|
);
|
|
14540
14758
|
}
|
|
14541
14759
|
const missingByProvider = /* @__PURE__ */ new Map();
|
|
@@ -14575,12 +14793,12 @@ function evaluateRunFill(db, run, input = {}) {
|
|
|
14575
14793
|
if (retired.length) {
|
|
14576
14794
|
return refuse(
|
|
14577
14795
|
RunFillRefusalCodes.model_retired,
|
|
14578
|
-
`This run measured ${retired.join(", ")} on a model the provider has since retired, and the replacement is a different engine. Filling it now would mix two engines in one run; run a new
|
|
14796
|
+
`This run measured ${retired.join(", ")} on a model the provider has since retired, and the replacement is a different engine. Filling it now would mix two engines in one run; run a new AI Visibility check instead.`
|
|
14579
14797
|
);
|
|
14580
14798
|
}
|
|
14581
14799
|
if (input.runnableProviders) {
|
|
14582
14800
|
const runnable = input.runnableProviders.map(normalizeProvider);
|
|
14583
|
-
const absent = providers.filter((provider) => !isProviderAvailable(provider, runnable));
|
|
14801
|
+
const absent = providers.filter((provider) => !isProviderAvailable(provider, runnable, input.routeFamilies ?? void 0));
|
|
14584
14802
|
if (absent.length) {
|
|
14585
14803
|
return refuse(
|
|
14586
14804
|
RunFillRefusalCodes.provider_not_configured,
|
|
@@ -14592,7 +14810,7 @@ function evaluateRunFill(db, run, input = {}) {
|
|
|
14592
14810
|
const period2 = new Date(now).toISOString().slice(0, 10);
|
|
14593
14811
|
const neededByConnection = /* @__PURE__ */ new Map();
|
|
14594
14812
|
for (const provider of providers) {
|
|
14595
|
-
const connection = providerConnectionName(provider);
|
|
14813
|
+
const connection = providerConnectionName(provider, input.routeFamilies ?? void 0);
|
|
14596
14814
|
neededByConnection.set(connection, (neededByConnection.get(connection) ?? 0) + (missingByProvider.get(provider)?.length ?? 0));
|
|
14597
14815
|
}
|
|
14598
14816
|
for (const [provider, needed] of neededByConnection) {
|
|
@@ -14687,6 +14905,7 @@ function queueRunFill(db, runId, input = {}) {
|
|
|
14687
14905
|
|
|
14688
14906
|
// ../api-routes/src/runs.ts
|
|
14689
14907
|
async function runRoutes(app, opts) {
|
|
14908
|
+
const routeFamilies = providerRouteFamilies(opts.providerAdapters);
|
|
14690
14909
|
app.post("/projects/:name/runs", async (request, reply) => {
|
|
14691
14910
|
const project = resolveProject(app.db, request.params.name);
|
|
14692
14911
|
const body = parseRunTriggerRequest(request.body ?? {});
|
|
@@ -14698,7 +14917,7 @@ async function runRoutes(app, opts) {
|
|
|
14698
14917
|
const normalized = rawProviders.map((p) => p.trim().toLowerCase()).filter(Boolean);
|
|
14699
14918
|
const validNames = opts.validProviderNames ?? [];
|
|
14700
14919
|
if (validNames.length) {
|
|
14701
|
-
const invalid = normalized
|
|
14920
|
+
const invalid = invalidProviderSelections(normalized, validNames, opts.providerAdapters, ProviderWorkflows["visibility-sweep"]);
|
|
14702
14921
|
if (invalid.length) {
|
|
14703
14922
|
throw validationError(`Invalid provider(s): ${invalid.join(", ")}. Must be one of: ${validNames.join(", ")}`, {
|
|
14704
14923
|
invalidProviders: invalid,
|
|
@@ -14710,12 +14929,12 @@ async function runRoutes(app, opts) {
|
|
|
14710
14929
|
}
|
|
14711
14930
|
const providers = rawProviders?.length ? rawProviders : void 0;
|
|
14712
14931
|
const revisionProviders = activeRevisionProviders(app.db, project.id);
|
|
14713
|
-
|
|
14932
|
+
assertProviderRouteScope(request, providers ?? [], [...project.providers, ...revisionProviders], routeFamilies);
|
|
14714
14933
|
const shouldPreflight = trigger !== RunTriggers.probe && opts.getRunnableProviderNames !== void 0;
|
|
14715
14934
|
const trackedRows2 = body.queries?.length || shouldPreflight ? app.db.select({ query: queries.query }).from(queries).where(eq32(queries.projectId, project.id)).all() : [];
|
|
14716
14935
|
if (body.measurementScope !== void 0 && measurementRunScopeIsEmpty(body.measurementScope)) {
|
|
14717
14936
|
throw validationError(
|
|
14718
|
-
"The measurement scope names nothing to measure. Name at least one group or target, or leave the scope out entirely to run a full
|
|
14937
|
+
"The measurement scope names nothing to measure. Name at least one group or target, or leave the scope out entirely to run a full AI Visibility check."
|
|
14719
14938
|
);
|
|
14720
14939
|
}
|
|
14721
14940
|
if (hasActiveMeasurementPlan(app.db, project.id) && (body.location || body.allLocations || body.noLocation)) {
|
|
@@ -14752,6 +14971,7 @@ async function runRoutes(app, opts) {
|
|
|
14752
14971
|
projectProviders: scopedRevisionProviders.length > 0 ? scopedRevisionProviders : project.providers,
|
|
14753
14972
|
requestedProviders: providers,
|
|
14754
14973
|
runnableProviderNames: opts.getRunnableProviderNames(),
|
|
14974
|
+
routeFamilies,
|
|
14755
14975
|
trackedQueryCount: measuresAPlan ? 1 : trackedRows2.length
|
|
14756
14976
|
});
|
|
14757
14977
|
if (preflightError) throw preflightError;
|
|
@@ -14785,7 +15005,8 @@ async function runRoutes(app, opts) {
|
|
|
14785
15005
|
providers: resolveRunnableProviderSelection({
|
|
14786
15006
|
requestedProviders: providers,
|
|
14787
15007
|
projectProviders: project.providers,
|
|
14788
|
-
runnableProviders: opts.getRunnableProviderNames?.()
|
|
15008
|
+
runnableProviders: opts.getRunnableProviderNames?.(),
|
|
15009
|
+
routeFamilies
|
|
14789
15010
|
}).selectedProviders,
|
|
14790
15011
|
expectedSlots: null,
|
|
14791
15012
|
scoped: queriesColumn !== null,
|
|
@@ -14812,9 +15033,10 @@ async function runRoutes(app, opts) {
|
|
|
14812
15033
|
const roster = resolveRunnableProviderSelection({
|
|
14813
15034
|
requestedProviders: providers,
|
|
14814
15035
|
projectProviders: project.providers,
|
|
14815
|
-
runnableProviders: runnable
|
|
15036
|
+
runnableProviders: runnable,
|
|
15037
|
+
routeFamilies
|
|
14816
15038
|
}).selectedProviders;
|
|
14817
|
-
return providersARunWouldCall(roster, runnable);
|
|
15039
|
+
return providersARunWouldCall(roster, runnable, routeFamilies);
|
|
14818
15040
|
}
|
|
14819
15041
|
});
|
|
14820
15042
|
if (admission.refused) return { conflict: false, refused: admission.refused };
|
|
@@ -14868,6 +15090,7 @@ async function runRoutes(app, opts) {
|
|
|
14868
15090
|
queries: queriesColumn,
|
|
14869
15091
|
providers,
|
|
14870
15092
|
runnableProviders: opts.getRunnableProviderNames?.(),
|
|
15093
|
+
routeFamilies,
|
|
14871
15094
|
providerModels: opts.getEffectiveProviderModels?.(),
|
|
14872
15095
|
measurementScope: body.measurementScope ?? null,
|
|
14873
15096
|
dispatchMode: body.dispatchMode ?? null,
|
|
@@ -14914,7 +15137,8 @@ async function runRoutes(app, opts) {
|
|
|
14914
15137
|
const admissionParams = {
|
|
14915
15138
|
projectId: project.id,
|
|
14916
15139
|
now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
14917
|
-
runnableProviders: opts.getRunnableProviderNames?.()
|
|
15140
|
+
runnableProviders: opts.getRunnableProviderNames?.(),
|
|
15141
|
+
routeFamilies
|
|
14918
15142
|
};
|
|
14919
15143
|
const admission = runAdmissionState(app.db, admissionParams);
|
|
14920
15144
|
const manualAdmission = runAdmissionState(app.db, { ...admissionParams, selection: RunTriggers.manual });
|
|
@@ -14938,6 +15162,7 @@ async function runRoutes(app, opts) {
|
|
|
14938
15162
|
projectId: project.id,
|
|
14939
15163
|
now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
14940
15164
|
runnableProviders: opts.getRunnableProviderNames?.(),
|
|
15165
|
+
routeFamilies,
|
|
14941
15166
|
selection
|
|
14942
15167
|
}));
|
|
14943
15168
|
});
|
|
@@ -14978,7 +15203,7 @@ async function runRoutes(app, opts) {
|
|
|
14978
15203
|
const normalized = rawProviders.map((p) => p.trim().toLowerCase()).filter(Boolean);
|
|
14979
15204
|
const validNames = opts.validProviderNames ?? [];
|
|
14980
15205
|
if (validNames.length) {
|
|
14981
|
-
const invalid = normalized
|
|
15206
|
+
const invalid = invalidProviderSelections(normalized, validNames, opts.providerAdapters, ProviderWorkflows["visibility-sweep"]);
|
|
14982
15207
|
if (invalid.length) {
|
|
14983
15208
|
throw validationError(`Invalid provider(s): ${invalid.join(", ")}. Must be one of: ${validNames.join(", ")}`, {
|
|
14984
15209
|
invalidProviders: invalid,
|
|
@@ -15033,7 +15258,7 @@ async function runRoutes(app, opts) {
|
|
|
15033
15258
|
const dispatchable = [];
|
|
15034
15259
|
for (const entry of eligible) {
|
|
15035
15260
|
try {
|
|
15036
|
-
|
|
15261
|
+
assertProviderRouteScope(request, providers ?? [], [...entry.project.providers, ...entry.revisionProviders], routeFamilies);
|
|
15037
15262
|
assertMeasurementRunStampable(app.db, {
|
|
15038
15263
|
createdAt: now,
|
|
15039
15264
|
projectId: entry.project.id,
|
|
@@ -15042,6 +15267,7 @@ async function runRoutes(app, opts) {
|
|
|
15042
15267
|
location: entry.resolvedLocation?.label ?? null,
|
|
15043
15268
|
providers,
|
|
15044
15269
|
runnableProviders: runnableProviderNames,
|
|
15270
|
+
routeFamilies,
|
|
15045
15271
|
providerModels: opts.getEffectiveProviderModels?.(),
|
|
15046
15272
|
dispatchMode,
|
|
15047
15273
|
batchEligibleProviders,
|
|
@@ -15070,6 +15296,7 @@ async function runRoutes(app, opts) {
|
|
|
15070
15296
|
// against is what it was actually asked to do.
|
|
15071
15297
|
providers,
|
|
15072
15298
|
runnableProviders: runnableProviderNames,
|
|
15299
|
+
routeFamilies,
|
|
15073
15300
|
providerModels: opts.getEffectiveProviderModels?.(),
|
|
15074
15301
|
dispatchMode,
|
|
15075
15302
|
batchEligibleProviders,
|
|
@@ -15133,6 +15360,7 @@ async function runRoutes(app, opts) {
|
|
|
15133
15360
|
const input = {
|
|
15134
15361
|
providers: parsed.data.providers,
|
|
15135
15362
|
runnableProviders: opts.getRunnableProviderNames?.() ?? null,
|
|
15363
|
+
routeFamilies,
|
|
15136
15364
|
dailyLimits: opts.getProviderDailyLimits?.() ?? null
|
|
15137
15365
|
};
|
|
15138
15366
|
if (parsed.data.dryRun) {
|
|
@@ -15163,6 +15391,7 @@ async function runRoutes(app, opts) {
|
|
|
15163
15391
|
assertProjectScope(request, run.projectId);
|
|
15164
15392
|
return reply.send(readRunCompleteness(app.db, run, {
|
|
15165
15393
|
runnableProviders: opts.getRunnableProviderNames?.() ?? null,
|
|
15394
|
+
routeFamilies,
|
|
15166
15395
|
dailyLimits: opts.getProviderDailyLimits?.() ?? null
|
|
15167
15396
|
}));
|
|
15168
15397
|
});
|
|
@@ -15180,7 +15409,8 @@ function answerVisibilityPreflightError(input) {
|
|
|
15180
15409
|
const selection = resolveRunnableProviderSelection({
|
|
15181
15410
|
requestedProviders: input.requestedProviders,
|
|
15182
15411
|
projectProviders: input.projectProviders,
|
|
15183
|
-
runnableProviders: input.runnableProviderNames
|
|
15412
|
+
runnableProviders: input.runnableProviderNames,
|
|
15413
|
+
routeFamilies: input.routeFamilies
|
|
15184
15414
|
});
|
|
15185
15415
|
if (selection.runnableProviders.length > 0) return null;
|
|
15186
15416
|
return noProvider(input.projectName, {
|
|
@@ -15313,6 +15543,7 @@ function loadRunDetail(app, run) {
|
|
|
15313
15543
|
dispatchMode: querySnapshots.dispatchMode,
|
|
15314
15544
|
stopReason: querySnapshots.stopReason,
|
|
15315
15545
|
usage: querySnapshots.usage,
|
|
15546
|
+
answerEvidence: querySnapshots.answerEvidence,
|
|
15316
15547
|
rawResponse: querySnapshots.rawResponse,
|
|
15317
15548
|
createdAt: querySnapshots.createdAt
|
|
15318
15549
|
}).from(querySnapshots).leftJoin(queries, eq32(querySnapshots.queryId, queries.id)).where(eq32(querySnapshots.runId, run.id)).all();
|
|
@@ -15366,6 +15597,8 @@ function loadRunDetail(app, run) {
|
|
|
15366
15597
|
groundingSources: rawParsed.groundingSources,
|
|
15367
15598
|
searchQueries: rawParsed.searchQueries,
|
|
15368
15599
|
retrievedSources: rawParsed.retrievedSources,
|
|
15600
|
+
// Only answer services record evidence; other rows keep their exact shape.
|
|
15601
|
+
...s.answerEvidence ? { evidence: s.answerEvidence } : {},
|
|
15369
15602
|
createdAt: s.createdAt
|
|
15370
15603
|
};
|
|
15371
15604
|
});
|
|
@@ -15468,7 +15701,7 @@ function compileContextForProject(app, project, opts) {
|
|
|
15468
15701
|
const trackedQueries = app.db.select({ id: queries.id, query: queries.query }).from(queries).where(eq33(queries.projectId, project.id)).all();
|
|
15469
15702
|
const defaultContext = project.defaultLocation ? project.locations.find((location) => location.label === project.defaultLocation) ?? null : null;
|
|
15470
15703
|
const projectProviders = normalizedProviderNames(project.providers);
|
|
15471
|
-
const selectedProviders = projectProviders.length > 0 ? projectProviders : normalizedProviderNames(opts.getRunnableProviderNames?.() ?? []);
|
|
15704
|
+
const selectedProviders = projectProviders.length > 0 ? projectProviders : normalizedProviderNames(opts.getRunnableProviderNames?.() ?? []).filter((name) => isSweepProvider(name, opts.providerRouteFamilies));
|
|
15472
15705
|
return {
|
|
15473
15706
|
canonicalDomain: project.canonicalDomain,
|
|
15474
15707
|
ownedDomains: project.ownedDomains,
|
|
@@ -16079,116 +16312,6 @@ import { promisify as promisify2 } from "util";
|
|
|
16079
16312
|
import http from "http";
|
|
16080
16313
|
import https from "https";
|
|
16081
16314
|
import net2 from "net";
|
|
16082
|
-
|
|
16083
|
-
// ../api-routes/src/egress-policy.ts
|
|
16084
|
-
import net from "net";
|
|
16085
|
-
function blockedAddressReason(value, options = {}) {
|
|
16086
|
-
const address = stripZoneId(stripIpv6Brackets(value));
|
|
16087
|
-
if (options.allowLoopback && isLoopbackAddress(address)) return null;
|
|
16088
|
-
const family = net.isIP(address);
|
|
16089
|
-
if (family === 4) return blockedIpv4Reason(ipv4Octets(address));
|
|
16090
|
-
if (family === 6) {
|
|
16091
|
-
const bytes = ipv6Bytes(address);
|
|
16092
|
-
return bytes ? blockedIpv6Reason(bytes) : "which could not be read as an address";
|
|
16093
|
-
}
|
|
16094
|
-
return "which is not an IP address";
|
|
16095
|
-
}
|
|
16096
|
-
function isLoopbackAddress(value) {
|
|
16097
|
-
const address = stripZoneId(stripIpv6Brackets(value));
|
|
16098
|
-
const family = net.isIP(address);
|
|
16099
|
-
if (family === 4) return ipv4Octets(address)[0] === 127;
|
|
16100
|
-
if (family !== 6) return false;
|
|
16101
|
-
const bytes = ipv6Bytes(address);
|
|
16102
|
-
if (!bytes) return false;
|
|
16103
|
-
const mapped = mappedIpv4(bytes);
|
|
16104
|
-
if (mapped) return mapped[0] === 127;
|
|
16105
|
-
return bytes.slice(0, 15).every((byte) => byte === 0) && bytes[15] === 1;
|
|
16106
|
-
}
|
|
16107
|
-
function stripIpv6Brackets(value) {
|
|
16108
|
-
return value.startsWith("[") && value.endsWith("]") ? value.slice(1, -1) : value;
|
|
16109
|
-
}
|
|
16110
|
-
function stripZoneId(address) {
|
|
16111
|
-
return address.split("%")[0];
|
|
16112
|
-
}
|
|
16113
|
-
function ipv4Octets(address) {
|
|
16114
|
-
return address.split(".").map((part) => Number.parseInt(part, 10));
|
|
16115
|
-
}
|
|
16116
|
-
function blockedIpv4Reason(octets) {
|
|
16117
|
-
const [first, second] = octets;
|
|
16118
|
-
if (first === 0) return "which is unspecified space";
|
|
16119
|
-
if (first === 127) return "which is loopback";
|
|
16120
|
-
if (first === 10 || first === 172 && second >= 16 && second <= 31 || first === 192 && second === 168) {
|
|
16121
|
-
return "which is private space";
|
|
16122
|
-
}
|
|
16123
|
-
if (first === 100 && second >= 64 && second <= 127) return "which is carrier-grade NAT space";
|
|
16124
|
-
if (first === 169 && second === 254) return "which is link-local";
|
|
16125
|
-
if (first >= 224 && first <= 239) return "which is multicast";
|
|
16126
|
-
if (first === 192 && second === 0 && octets[2] === 0 || first === 198 && (second === 18 || second === 19) || first >= 240) {
|
|
16127
|
-
return "which is reserved";
|
|
16128
|
-
}
|
|
16129
|
-
return null;
|
|
16130
|
-
}
|
|
16131
|
-
function blockedIpv6Reason(bytes) {
|
|
16132
|
-
const first = bytes[0];
|
|
16133
|
-
if (first === 0) {
|
|
16134
|
-
const nat64 = nat64Ipv4(bytes);
|
|
16135
|
-
if (nat64) return blockedIpv4Reason(nat64) === null ? null : `which is the NAT64 form of ${nat64.join(".")}`;
|
|
16136
|
-
const mapped = mappedIpv4(bytes);
|
|
16137
|
-
return mapped ? `which is the IPv6 form of ${mapped.join(".")}` : "which is reserved IPv6 space";
|
|
16138
|
-
}
|
|
16139
|
-
if (first === 1 && bytes.slice(1, 8).every((byte) => byte === 0)) return "which is reserved IPv6 space";
|
|
16140
|
-
if (first === 255) return "which is multicast";
|
|
16141
|
-
if ((first & 254) === 252) return "which is unique-local";
|
|
16142
|
-
if (first === 254 && (bytes[1] & 192) === 128) return "which is link-local";
|
|
16143
|
-
if (first === 254 && (bytes[1] & 192) === 192) return "which is reserved site-local space";
|
|
16144
|
-
if (first === 32 && bytes[1] === 1 && bytes[2] === 0 && bytes[3] === 0) return "which is a Teredo tunnel";
|
|
16145
|
-
if (first === 32 && bytes[1] === 2) return "which is a 6to4 tunnel";
|
|
16146
|
-
if (first === 32 && bytes[1] === 1 && bytes[2] === 0 && bytes[3] === 2 && bytes[4] === 0 && bytes[5] === 0) {
|
|
16147
|
-
return "which is reserved IPv6 space";
|
|
16148
|
-
}
|
|
16149
|
-
return null;
|
|
16150
|
-
}
|
|
16151
|
-
function mappedIpv4(bytes) {
|
|
16152
|
-
const isMapped = bytes.slice(0, 10).every((byte) => byte === 0) && bytes[10] === 255 && bytes[11] === 255;
|
|
16153
|
-
return isMapped ? [bytes[12], bytes[13], bytes[14], bytes[15]] : null;
|
|
16154
|
-
}
|
|
16155
|
-
var NAT64_WELL_KNOWN_PREFIX = [0, 100, 255, 155, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
16156
|
-
function nat64Ipv4(bytes) {
|
|
16157
|
-
const isNat64 = NAT64_WELL_KNOWN_PREFIX.every((byte, index) => bytes[index] === byte);
|
|
16158
|
-
return isNat64 ? [bytes[12], bytes[13], bytes[14], bytes[15]] : null;
|
|
16159
|
-
}
|
|
16160
|
-
function ipv6Bytes(address) {
|
|
16161
|
-
if (!net.isIPv6(address)) return null;
|
|
16162
|
-
const halves = address.split("::");
|
|
16163
|
-
if (halves.length > 2) return null;
|
|
16164
|
-
const expand = (text) => {
|
|
16165
|
-
if (text === "") return [];
|
|
16166
|
-
const groups2 = [];
|
|
16167
|
-
const chunks = text.split(":");
|
|
16168
|
-
for (const [index, chunk] of chunks.entries()) {
|
|
16169
|
-
if (index === chunks.length - 1 && chunk.includes(".")) {
|
|
16170
|
-
const octets = ipv4Octets(chunk);
|
|
16171
|
-
groups2.push(octets[0] << 8 | octets[1], octets[2] << 8 | octets[3]);
|
|
16172
|
-
continue;
|
|
16173
|
-
}
|
|
16174
|
-
groups2.push(Number.parseInt(chunk, 16));
|
|
16175
|
-
}
|
|
16176
|
-
return groups2;
|
|
16177
|
-
};
|
|
16178
|
-
const head = expand(halves[0]);
|
|
16179
|
-
const tail = halves.length === 2 ? expand(halves[1]) : [];
|
|
16180
|
-
const missing = 8 - head.length - tail.length;
|
|
16181
|
-
if (halves.length === 1 ? missing !== 0 : missing < 0) return null;
|
|
16182
|
-
const groups = [...head, ...new Array(halves.length === 2 ? missing : 0).fill(0), ...tail];
|
|
16183
|
-
const bytes = new Uint8Array(16);
|
|
16184
|
-
for (const [index, group] of groups.entries()) {
|
|
16185
|
-
bytes[index * 2] = group >> 8;
|
|
16186
|
-
bytes[index * 2 + 1] = group & 255;
|
|
16187
|
-
}
|
|
16188
|
-
return bytes;
|
|
16189
|
-
}
|
|
16190
|
-
|
|
16191
|
-
// ../api-routes/src/measurement-sitemap-fetch.ts
|
|
16192
16315
|
var gunzipAsync = promisify2(gunzip);
|
|
16193
16316
|
var DEFAULT_MEASUREMENT_SITEMAP_LIMITS = {
|
|
16194
16317
|
timeoutMs: 1e4,
|
|
@@ -16687,6 +16810,17 @@ function frozenMeasurementDraftExecutionKeys(authoring) {
|
|
|
16687
16810
|
}
|
|
16688
16811
|
return keys;
|
|
16689
16812
|
}
|
|
16813
|
+
function sweepIneligibleMessage(provider, adapters) {
|
|
16814
|
+
if (!adapters) return null;
|
|
16815
|
+
const adapter = providerAdapterForName(provider, adapters);
|
|
16816
|
+
if (!adapter || isEligibleFor(adapter, ProviderWorkflows["visibility-sweep"], "explicit")) return null;
|
|
16817
|
+
return `${adapter.displayName} (${provider}) does not run visibility sweeps; choose a profile that does.`;
|
|
16818
|
+
}
|
|
16819
|
+
function routedProviderMessage(provider, families) {
|
|
16820
|
+
const connection = (families ?? [OPENROUTER_ROUTE_FAMILY]).find((family) => provider === family.connection || provider.startsWith(`${family.connection}:`));
|
|
16821
|
+
if (!connection || connection.connection === "openrouter") return "OpenRouter measurement requires a fixed model route.";
|
|
16822
|
+
return `Measurement through ${connection.connection} requires one of its ${connection.selectionKind} routes.`;
|
|
16823
|
+
}
|
|
16690
16824
|
function compileMeasurementDraft(authoring, context) {
|
|
16691
16825
|
const { checks, sink, failed } = createChecks();
|
|
16692
16826
|
let canonicalHost = "";
|
|
@@ -16841,10 +16975,13 @@ function compileMeasurementDraft(authoring, context) {
|
|
|
16841
16975
|
models[normalized] = model;
|
|
16842
16976
|
}
|
|
16843
16977
|
for (const provider of providers) {
|
|
16844
|
-
if (!isSweepProvider(provider)) sink.fail("invalid-provider-model",
|
|
16845
|
-
const
|
|
16846
|
-
if (
|
|
16847
|
-
|
|
16978
|
+
if (!isSweepProvider(provider, context.routeFamilies)) sink.fail("invalid-provider-model", routedProviderMessage(provider, context.routeFamilies), [...path8, "providers"]);
|
|
16979
|
+
const ineligible = sweepIneligibleMessage(provider, context.providerAdapters);
|
|
16980
|
+
if (ineligible) sink.fail("invalid-provider-model", ineligible, [...path8, "providers"]);
|
|
16981
|
+
const route = resolveProviderRoute(provider, context.routeFamilies);
|
|
16982
|
+
if (!route) continue;
|
|
16983
|
+
const pinned = route.selection;
|
|
16984
|
+
if (models[provider] && models[provider] !== pinned) sink.fail("invalid-provider-model", `${route.connection === "openrouter" ? "OpenRouter route" : "Route"} "${provider}" pins ${route.family.selectionKind} "${pinned}".`, [...path8, "models", provider]);
|
|
16848
16985
|
models[provider] = pinned;
|
|
16849
16986
|
}
|
|
16850
16987
|
const labels = sortedUnique(override?.locations ?? authoring.defaultContext.locations);
|
|
@@ -16875,10 +17012,13 @@ function compileMeasurementDraft(authoring, context) {
|
|
|
16875
17012
|
models[normalized] = model;
|
|
16876
17013
|
}
|
|
16877
17014
|
for (const provider of providers) {
|
|
16878
|
-
if (!isSweepProvider(provider)) sink.fail("invalid-provider-model",
|
|
16879
|
-
const
|
|
16880
|
-
if (
|
|
16881
|
-
|
|
17015
|
+
if (!isSweepProvider(provider, context.routeFamilies)) sink.fail("invalid-provider-model", routedProviderMessage(provider, context.routeFamilies), [...path8, "providers"]);
|
|
17016
|
+
const ineligible = sweepIneligibleMessage(provider, context.providerAdapters);
|
|
17017
|
+
if (ineligible) sink.fail("invalid-provider-model", ineligible, [...path8, "providers"]);
|
|
17018
|
+
const route = resolveProviderRoute(provider, context.routeFamilies);
|
|
17019
|
+
if (!route) continue;
|
|
17020
|
+
const pinned = route.selection;
|
|
17021
|
+
if (models[provider] && models[provider] !== pinned) sink.fail("invalid-provider-model", `${route.connection === "openrouter" ? "OpenRouter route" : "Route"} "${provider}" pins ${route.family.selectionKind} "${pinned}".`, [...path8, "models", provider]);
|
|
16882
17022
|
models[provider] = pinned;
|
|
16883
17023
|
}
|
|
16884
17024
|
const identity = exact.executionNodeKey === void 0 ? {} : { executionNodeKey: exact.executionNodeKey };
|
|
@@ -18782,13 +18922,15 @@ function storedPlanExecutionProviders(plan) {
|
|
|
18782
18922
|
function trackedQueriesFor(db, projectId) {
|
|
18783
18923
|
return db.select({ id: queries.id, query: queries.query }).from(queries).where(eq34(queries.projectId, projectId)).all();
|
|
18784
18924
|
}
|
|
18785
|
-
function compileContextFor(db, project) {
|
|
18925
|
+
function compileContextFor(db, project, opts) {
|
|
18786
18926
|
return {
|
|
18787
18927
|
canonicalDomain: project.canonicalDomain,
|
|
18788
18928
|
ownedDomains: project.ownedDomains,
|
|
18789
18929
|
brandNames: effectiveBrandNames(project),
|
|
18790
18930
|
locations: project.locations,
|
|
18791
|
-
trackedQueries: trackedQueriesFor(db, project.id)
|
|
18931
|
+
trackedQueries: trackedQueriesFor(db, project.id),
|
|
18932
|
+
...opts.providerRouteFamilies ? { routeFamilies: opts.providerRouteFamilies } : {},
|
|
18933
|
+
...opts.providerAdapters ? { providerAdapters: opts.providerAdapters } : {}
|
|
18792
18934
|
};
|
|
18793
18935
|
}
|
|
18794
18936
|
function actionContextFor(db, project) {
|
|
@@ -18827,7 +18969,8 @@ function formatDraftMatcher(matcher) {
|
|
|
18827
18969
|
function draftProviderNames(project, opts) {
|
|
18828
18970
|
return resolveRunProviderSelection({
|
|
18829
18971
|
projectProviders: project.providers,
|
|
18830
|
-
runnableProviders: opts.getRunnableProviderNames?.()
|
|
18972
|
+
runnableProviders: opts.getRunnableProviderNames?.(),
|
|
18973
|
+
routeFamilies: opts.providerRouteFamilies
|
|
18831
18974
|
});
|
|
18832
18975
|
}
|
|
18833
18976
|
function draftModels(project, providers) {
|
|
@@ -19138,7 +19281,8 @@ async function measurementDraftRoutes(app, opts = {}) {
|
|
|
19138
19281
|
// the exact provider-selection decision enforced by run preflight.
|
|
19139
19282
|
answerVisibilityProviderReady: resolveRunnableProviderSelection({
|
|
19140
19283
|
projectProviders: project.providers,
|
|
19141
|
-
runnableProviders: opts.getRunnableProviderNames?.()
|
|
19284
|
+
runnableProviders: opts.getRunnableProviderNames?.(),
|
|
19285
|
+
routeFamilies: opts.providerRouteFamilies
|
|
19142
19286
|
}).runnableProviders.length > 0,
|
|
19143
19287
|
activeRevision: active?.revision ?? null,
|
|
19144
19288
|
activeSchemaVersion,
|
|
@@ -19335,7 +19479,7 @@ async function measurementDraftRoutes(app, opts = {}) {
|
|
|
19335
19479
|
assertDraftEtag(row, ifMatch);
|
|
19336
19480
|
const before = parseStoredAuthoring(row.authoringJson);
|
|
19337
19481
|
const result = applyDraftAction(action, before, request.body, actionContextFor(app.db, gate.project));
|
|
19338
|
-
|
|
19482
|
+
assertProviderRouteScope(request, draftExecutionProviders(result.authoring), [...gate.project.providers, ...draftExecutionProviders(before)], opts.providerRouteFamilies);
|
|
19339
19483
|
const changed = authoringIdentity(result.authoring) !== authoringIdentity(before);
|
|
19340
19484
|
const etagVersion = changed ? row.etagVersion + 1 : row.etagVersion;
|
|
19341
19485
|
const response = mutationResponse(etagVersion, changed, result.warnings, result.authoring);
|
|
@@ -19392,7 +19536,7 @@ async function measurementDraftRoutes(app, opts = {}) {
|
|
|
19392
19536
|
const before = parseStoredAuthoring(row.authoringJson);
|
|
19393
19537
|
const result = applyAssignmentsToAuthoring(before, parsed.data, actionContextFor(app.db, project));
|
|
19394
19538
|
assertMeasurementDraftAuthoringLimits(before, result.authoring);
|
|
19395
|
-
const context = compileContextFor(app.db, project);
|
|
19539
|
+
const context = compileContextFor(app.db, project, opts);
|
|
19396
19540
|
const current = compileMeasurementDraftAssignmentExecution(authoringForCompile(before, project, opts), context);
|
|
19397
19541
|
const candidate = compileMeasurementDraftAssignmentExecution(authoringForCompile(result.authoring, project, opts), context);
|
|
19398
19542
|
if (!current.ok || !candidate.ok) {
|
|
@@ -19427,7 +19571,7 @@ async function measurementDraftRoutes(app, opts = {}) {
|
|
|
19427
19571
|
const before = parseStoredAuthoring(row.authoringJson);
|
|
19428
19572
|
const result = routeMarketsInAuthoring(before, parsed.data, actionContextFor(app.db, project));
|
|
19429
19573
|
assertMeasurementDraftAuthoringLimits(before, result.authoring);
|
|
19430
|
-
const context = compileContextFor(app.db, project);
|
|
19574
|
+
const context = compileContextFor(app.db, project, opts);
|
|
19431
19575
|
const current = compileMeasurementDraftAssignmentExecution(authoringForCompile(before, project, opts), context);
|
|
19432
19576
|
const candidate = compileMeasurementDraftAssignmentExecution(authoringForCompile(result.authoring, project, opts), context);
|
|
19433
19577
|
if (!current.ok || !candidate.ok) {
|
|
@@ -19552,7 +19696,7 @@ async function measurementDraftRoutes(app, opts = {}) {
|
|
|
19552
19696
|
requireScope(request, MEASUREMENT_PLAN_WRITE_SCOPE);
|
|
19553
19697
|
const project = resolveProject(app.db, request.params.name);
|
|
19554
19698
|
const authoring = authoringForCompile(parseStoredAuthoring(requireDraft(project).authoringJson), project, opts);
|
|
19555
|
-
const compiled = compileMeasurementDraft(authoring, compileContextFor(app.db, project));
|
|
19699
|
+
const compiled = compileMeasurementDraft(authoring, compileContextFor(app.db, project, opts));
|
|
19556
19700
|
if (!compiled.ok) return { ok: false, compiledChecksum: null, checks: compiled.checks };
|
|
19557
19701
|
return {
|
|
19558
19702
|
ok: true,
|
|
@@ -19568,7 +19712,7 @@ async function measurementDraftRoutes(app, opts = {}) {
|
|
|
19568
19712
|
requireScope(request, MEASUREMENT_PLAN_WRITE_SCOPE);
|
|
19569
19713
|
const project = resolveProject(app.db, request.params.name);
|
|
19570
19714
|
const authoring = authoringForCompile(parseStoredAuthoring(requireDraft(project).authoringJson), project, opts);
|
|
19571
|
-
const compiled = compileMeasurementDraft(authoring, compileContextFor(app.db, project));
|
|
19715
|
+
const compiled = compileMeasurementDraft(authoring, compileContextFor(app.db, project, opts));
|
|
19572
19716
|
if (!compiled.ok) return { ok: false, compiledChecksum: null, checks: compiled.checks, diff: null };
|
|
19573
19717
|
const active = activePlanVersionRow(app.db, project.id);
|
|
19574
19718
|
const comparable = active && active.schemaVersion === 2 ? parseV2Plan(active) : null;
|
|
@@ -19596,7 +19740,7 @@ async function measurementDraftRoutes(app, opts = {}) {
|
|
|
19596
19740
|
const parsed = measurementDraftPublishRequestSchema.safeParse(request.body);
|
|
19597
19741
|
if (!parsed.success) throw validationError('Invalid "publish" payload', { issues: parsed.error.issues });
|
|
19598
19742
|
const ifMatch = requireIfMatch(request);
|
|
19599
|
-
const context = compileContextFor(app.db, gate.project);
|
|
19743
|
+
const context = compileContextFor(app.db, gate.project, opts);
|
|
19600
19744
|
const now = /* @__PURE__ */ new Date();
|
|
19601
19745
|
let pinEffect = null;
|
|
19602
19746
|
const settled = app.db.transaction((tx) => {
|
|
@@ -19629,10 +19773,11 @@ async function measurementDraftRoutes(app, opts = {}) {
|
|
|
19629
19773
|
throw validationError("The measurement draft does not compile.", { checks: compiled.checks });
|
|
19630
19774
|
}
|
|
19631
19775
|
const activeProviders = active ? storedPlanExecutionProviders(parseStoredMeasurementPlanAnyVersion(active.canonicalJson)) : [];
|
|
19632
|
-
|
|
19776
|
+
assertProviderRouteScope(
|
|
19633
19777
|
request,
|
|
19634
19778
|
compiled.plan.executionNodes.flatMap((node) => node.context.providers),
|
|
19635
|
-
[...gate.project.providers, ...activeProviders]
|
|
19779
|
+
[...gate.project.providers, ...activeProviders],
|
|
19780
|
+
opts.providerRouteFamilies
|
|
19636
19781
|
);
|
|
19637
19782
|
if (compiled.plan.compiledChecksum !== parsed.data.expectedCompiledChecksum) {
|
|
19638
19783
|
throw measurementCompiledChecksumConflict(parsed.data.expectedCompiledChecksum, compiled.plan.compiledChecksum);
|
|
@@ -23982,7 +24127,8 @@ function stableNewQueryId(projectId, normalizedText) {
|
|
|
23982
24127
|
function providerNames(project, opts) {
|
|
23983
24128
|
return resolveRunProviderSelection({
|
|
23984
24129
|
projectProviders: project.providers,
|
|
23985
|
-
runnableProviders: opts.getRunnableProviderNames?.()
|
|
24130
|
+
runnableProviders: opts.getRunnableProviderNames?.(),
|
|
24131
|
+
routeFamilies: opts.providerRouteFamilies
|
|
23986
24132
|
});
|
|
23987
24133
|
}
|
|
23988
24134
|
function modelMap(project, providers) {
|
|
@@ -23997,20 +24143,21 @@ function simpleDispatchEngines(project, opts) {
|
|
|
23997
24143
|
const runnable = opts.getRunnableProviderNames?.();
|
|
23998
24144
|
const selected = resolveRunProviderSelection({
|
|
23999
24145
|
projectProviders: project.providers,
|
|
24000
|
-
runnableProviders: runnable
|
|
24146
|
+
runnableProviders: runnable,
|
|
24147
|
+
routeFamilies: opts.providerRouteFamilies
|
|
24001
24148
|
});
|
|
24002
|
-
const available = runnable === void 0 ? null :
|
|
24149
|
+
const available = runnable === void 0 ? null : runnable.map((provider) => provider.trim().toLocaleLowerCase("en")).filter(Boolean);
|
|
24003
24150
|
const summaries = new Map((opts.providerSummary ?? []).map((summary3) => [
|
|
24004
24151
|
summary3.name.trim().toLocaleLowerCase("en"),
|
|
24005
24152
|
summary3
|
|
24006
24153
|
]));
|
|
24007
24154
|
const overrides = project.providerModels;
|
|
24008
|
-
return selected.filter((provider) => available === null || available.
|
|
24155
|
+
return selected.filter((provider) => available === null || isProviderAvailable(provider, available, opts.providerRouteFamilies)).map((provider) => ({
|
|
24009
24156
|
provider,
|
|
24010
24157
|
// `undefined` is materially different from an intentionally blank model
|
|
24011
24158
|
// override/configuration, just as it is in JobRunner, which also resolves
|
|
24012
24159
|
// a retired override to the id that answers now.
|
|
24013
|
-
requestedModel: resolvedOverride(provider, overrides[provider]) ?? summaries.get(provider)?.model ?? null
|
|
24160
|
+
requestedModel: resolvedOverride(provider, overrides[provider]) ?? resolveProviderRoute(provider, opts.providerRouteFamilies)?.selection ?? summaries.get(provider)?.model ?? null
|
|
24014
24161
|
})).sort((left, right) => compareText(left.provider, right.provider));
|
|
24015
24162
|
}
|
|
24016
24163
|
function resolvedOverride(provider, model) {
|
|
@@ -25950,6 +26097,7 @@ var ApplyPreviewRollback = class extends Error {
|
|
|
25950
26097
|
preview;
|
|
25951
26098
|
};
|
|
25952
26099
|
async function applyRoutes(app, opts) {
|
|
26100
|
+
const routeFamilies = providerRouteFamilies(opts?.providerAdapters);
|
|
25953
26101
|
const allowLoopback = opts?.allowLoopbackWebhooks === true;
|
|
25954
26102
|
const notifyProjectCreated = (projectId, projectName) => {
|
|
25955
26103
|
try {
|
|
@@ -25973,7 +26121,7 @@ async function applyRoutes(app, opts) {
|
|
|
25973
26121
|
...config.spec.schedule?.providers ?? []
|
|
25974
26122
|
];
|
|
25975
26123
|
if (allProviders.length) {
|
|
25976
|
-
const invalid = allProviders
|
|
26124
|
+
const invalid = invalidProviderSelections(allProviders, validNames, opts?.providerAdapters, ProviderWorkflows["visibility-sweep"]);
|
|
25977
26125
|
if (invalid.length) {
|
|
25978
26126
|
throw validationError(`Invalid provider(s): ${[...new Set(invalid)].join(", ")}. Must be one of: ${validNames.join(", ")}`, {
|
|
25979
26127
|
invalidProviders: [...new Set(invalid)],
|
|
@@ -26046,7 +26194,7 @@ async function applyRoutes(app, opts) {
|
|
|
26046
26194
|
notificationPlan = planNotificationSet(storedNotifications, config.spec.notifications);
|
|
26047
26195
|
}
|
|
26048
26196
|
assertProviderModelScope(request, target?.providerModels ?? {}, providerModels, specProviders);
|
|
26049
|
-
|
|
26197
|
+
assertProviderRouteScope(request, [...specProviders, ...config.spec.schedule?.providers ?? []], target?.providers ?? [], routeFamilies);
|
|
26050
26198
|
const competitorPreview = planCompetitorSet(
|
|
26051
26199
|
target ? readStoredCompetitors(app.db, target.id) : [],
|
|
26052
26200
|
competitorWrites,
|
|
@@ -27265,7 +27413,7 @@ async function analyticsRoutes(app) {
|
|
|
27265
27413
|
const latestOutsideWindow = latestRuns?.find((run) => cutoff && run.createdAt < cutoff);
|
|
27266
27414
|
if (latestOutsideWindow) {
|
|
27267
27415
|
throw validationError(
|
|
27268
|
-
`The latest
|
|
27416
|
+
`The latest AI Visibility check (run "${latestOutsideWindow.id}") is older than the ${window} window. Omit window, or widen it, to read it.`
|
|
27269
27417
|
);
|
|
27270
27418
|
}
|
|
27271
27419
|
const windowRuns = app.db.select().from(runs).where(and36(
|
|
@@ -29704,7 +29852,7 @@ function buildOrganicEvidence(db, projectName, periodDays) {
|
|
|
29704
29852
|
if (visibility && visibility.ageDays > 30) {
|
|
29705
29853
|
limitations.push({
|
|
29706
29854
|
code: "stale-visibility-sweep",
|
|
29707
|
-
detail: `The latest
|
|
29855
|
+
detail: `The latest AI Visibility check is ${Math.floor(visibility.ageDays)} days old and may not represent current model behavior.`
|
|
29708
29856
|
});
|
|
29709
29857
|
}
|
|
29710
29858
|
return {
|
|
@@ -30669,7 +30817,9 @@ var CSV_COLUMNS = [
|
|
|
30669
30817
|
"recommended_competitors_json",
|
|
30670
30818
|
"answer_text",
|
|
30671
30819
|
"grounding_sources_json",
|
|
30672
|
-
"search_queries_json"
|
|
30820
|
+
"search_queries_json",
|
|
30821
|
+
// Vendor-neutral evidence (search answer services); empty for engines.
|
|
30822
|
+
"answer_evidence_json"
|
|
30673
30823
|
];
|
|
30674
30824
|
function parseFormat(value) {
|
|
30675
30825
|
if (value === void 0 || value === "" || value === "json") return "json";
|
|
@@ -30755,7 +30905,8 @@ function renderResultsExportCsv(report) {
|
|
|
30755
30905
|
JSON.stringify(record2.recommendedCompetitors),
|
|
30756
30906
|
record2.answerText,
|
|
30757
30907
|
JSON.stringify(record2.groundingSources),
|
|
30758
|
-
JSON.stringify(record2.searchQueries)
|
|
30908
|
+
JSON.stringify(record2.searchQueries),
|
|
30909
|
+
record2.answerEvidence ? JSON.stringify(record2.answerEvidence) : null
|
|
30759
30910
|
].map(csvCell).join(","));
|
|
30760
30911
|
return [CSV_COLUMNS.join(","), ...rows].join("\r\n") + "\r\n";
|
|
30761
30912
|
}
|
|
@@ -30803,7 +30954,8 @@ async function resultsExportRoutes(app) {
|
|
|
30803
30954
|
competitorOverlap: querySnapshots.competitorOverlap,
|
|
30804
30955
|
recommendedCompetitors: querySnapshots.recommendedCompetitors,
|
|
30805
30956
|
answerText: querySnapshots.answerText,
|
|
30806
|
-
rawResponse: querySnapshots.rawResponse
|
|
30957
|
+
rawResponse: querySnapshots.rawResponse,
|
|
30958
|
+
answerEvidence: querySnapshots.answerEvidence
|
|
30807
30959
|
}).from(querySnapshots).innerJoin(runs, eq54(querySnapshots.runId, runs.id)).leftJoin(queries, eq54(querySnapshots.queryId, queries.id)).where(and46(...conditions)).orderBy(asc9(runs.createdAt), asc9(runs.id), asc9(querySnapshots.createdAt), asc9(querySnapshots.id)).all();
|
|
30808
30960
|
const records = rows.map((row) => {
|
|
30809
30961
|
const evidence = readEvidence(row.rawResponse);
|
|
@@ -30837,7 +30989,8 @@ async function resultsExportRoutes(app) {
|
|
|
30837
30989
|
recommendedCompetitors: row.recommendedCompetitors,
|
|
30838
30990
|
answerText: row.answerText,
|
|
30839
30991
|
groundingSources: evidence.groundingSources,
|
|
30840
|
-
searchQueries: evidence.searchQueries
|
|
30992
|
+
searchQueries: evidence.searchQueries,
|
|
30993
|
+
answerEvidence: row.answerEvidence ?? null
|
|
30841
30994
|
};
|
|
30842
30995
|
});
|
|
30843
30996
|
const dto = {
|
|
@@ -30906,7 +31059,8 @@ async function compositeRoutes(app, options) {
|
|
|
30906
31059
|
const admissionParams = {
|
|
30907
31060
|
projectId: project.id,
|
|
30908
31061
|
now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30909
|
-
runnableProviders: options.getRunnableProviderNames?.()
|
|
31062
|
+
runnableProviders: options.getRunnableProviderNames?.(),
|
|
31063
|
+
routeFamilies: options.providerRouteFamilies
|
|
30910
31064
|
};
|
|
30911
31065
|
const admission = runAdmissionState(app.db, admissionParams);
|
|
30912
31066
|
const manualAdmission = runAdmissionState(app.db, { ...admissionParams, selection: RunTriggers.manual });
|
|
@@ -31390,7 +31544,7 @@ function buildRunStatusScore(allRuns) {
|
|
|
31390
31544
|
value: "None",
|
|
31391
31545
|
delta: "No runs yet",
|
|
31392
31546
|
tone: "neutral",
|
|
31393
|
-
description: "
|
|
31547
|
+
description: "Run an AI Visibility check to start tracking.",
|
|
31394
31548
|
tooltip,
|
|
31395
31549
|
trend: []
|
|
31396
31550
|
};
|
|
@@ -31439,7 +31593,7 @@ function buildAttentionItems(insightRows, allRuns) {
|
|
|
31439
31593
|
id: "stale_visibility",
|
|
31440
31594
|
tone: "caution",
|
|
31441
31595
|
title: "Stale visibility data",
|
|
31442
|
-
detail: `Last
|
|
31596
|
+
detail: `Last AI Visibility check was ${latestVisRun.createdAt}; integration syncs have run since.`,
|
|
31443
31597
|
actionLabel: "Stale",
|
|
31444
31598
|
href: "#runs"
|
|
31445
31599
|
});
|
|
@@ -40993,6 +41147,7 @@ async function userRoutes(app) {
|
|
|
40993
41147
|
|
|
40994
41148
|
// ../api-routes/src/snapshot.ts
|
|
40995
41149
|
async function snapshotRoutes(app, opts) {
|
|
41150
|
+
const routeFamilies = providerRouteFamilies(opts.providerAdapters);
|
|
40996
41151
|
app.post("/snapshot", async (request) => {
|
|
40997
41152
|
const parsed = snapshotRequestSchema.safeParse(request.body);
|
|
40998
41153
|
if (!parsed.success) {
|
|
@@ -41011,7 +41166,7 @@ async function snapshotRoutes(app, opts) {
|
|
|
41011
41166
|
queries: resolveSnapshotRequestQueries(parsed.data)
|
|
41012
41167
|
};
|
|
41013
41168
|
delete input.phrases;
|
|
41014
|
-
|
|
41169
|
+
assertProviderRouteScope(request, input.providers ?? [], [], routeFamilies);
|
|
41015
41170
|
try {
|
|
41016
41171
|
return await opts.onSnapshotRequested(input);
|
|
41017
41172
|
} catch (err) {
|
|
@@ -41171,6 +41326,7 @@ function parseExpectedUpdatedAtParam(raw) {
|
|
|
41171
41326
|
return parsed.data;
|
|
41172
41327
|
}
|
|
41173
41328
|
async function scheduleRoutes(app, opts) {
|
|
41329
|
+
const routeFamilies = providerRouteFamilies(opts.providerAdapters);
|
|
41174
41330
|
app.put("/projects/:name/schedule", async (request, reply) => {
|
|
41175
41331
|
const project = resolveProject(app.db, request.params.name);
|
|
41176
41332
|
const parsedBody = scheduleUpsertRequestSchema.safeParse(request.body);
|
|
@@ -41206,7 +41362,7 @@ async function scheduleRoutes(app, opts) {
|
|
|
41206
41362
|
}
|
|
41207
41363
|
const validNames = opts.validProviderNames ?? [];
|
|
41208
41364
|
if (validNames.length && providers?.length) {
|
|
41209
|
-
const invalid = providers
|
|
41365
|
+
const invalid = invalidProviderSelections(providers, validNames, opts.providerAdapters, ProviderWorkflows["visibility-sweep"]);
|
|
41210
41366
|
if (invalid.length) {
|
|
41211
41367
|
throw validationError(`Invalid provider(s): ${invalid.join(", ")}. Must be one of: ${validNames.join(", ")}`, {
|
|
41212
41368
|
invalidProviders: invalid,
|
|
@@ -41214,7 +41370,7 @@ async function scheduleRoutes(app, opts) {
|
|
|
41214
41370
|
});
|
|
41215
41371
|
}
|
|
41216
41372
|
}
|
|
41217
|
-
|
|
41373
|
+
assertProviderRouteScope(request, providers ?? [], project.providers, routeFamilies);
|
|
41218
41374
|
if (!isValidTimezone(timezone)) {
|
|
41219
41375
|
throw validationError(`Invalid timezone: ${timezone}`);
|
|
41220
41376
|
}
|
|
@@ -65361,23 +65517,26 @@ var providersConfiguredCheck = {
|
|
|
65361
65517
|
remediation: null
|
|
65362
65518
|
};
|
|
65363
65519
|
}
|
|
65364
|
-
const
|
|
65365
|
-
const
|
|
65520
|
+
const engines = summary3.filter(makesInstallMeasurable);
|
|
65521
|
+
const configured = engines.filter((entry) => entry.configured).map((entry) => entry.name);
|
|
65522
|
+
const answerServices = summary3.filter((entry) => !makesInstallMeasurable(entry) && entry.configured).map((entry) => entry.name);
|
|
65523
|
+
const servicesNote = answerServices.length > 0 ? ` Search answer services configured (used only where a project picks one of their profiles): ${answerServices.join(", ")}.` : "";
|
|
65524
|
+
const total = engines.length;
|
|
65366
65525
|
if (configured.length === 0) {
|
|
65367
65526
|
return {
|
|
65368
65527
|
status: CheckStatuses.warn,
|
|
65369
65528
|
code: "providers.none-configured",
|
|
65370
|
-
summary:
|
|
65529
|
+
summary: `No answer-engine provider is configured. Page Health remains available; AI Visibility is disabled.${servicesNote}`,
|
|
65371
65530
|
remediation: "To enable AI Visibility, run `canonry settings provider <name> --api-key <key>` while the server is running, or set a provider environment variable and rerun `canonry bootstrap`. Bootstrap reloads a matching running local server; if it is offline, start it to use the saved settings.",
|
|
65372
|
-
details: { available:
|
|
65531
|
+
details: { available: engines.map((entry) => entry.name), ...answerServices.length > 0 ? { answerServices } : {} }
|
|
65373
65532
|
};
|
|
65374
65533
|
}
|
|
65375
65534
|
return {
|
|
65376
65535
|
status: CheckStatuses.ok,
|
|
65377
65536
|
code: "providers.configured",
|
|
65378
|
-
summary: `${configured.length} of ${total} providers configured: ${configured.join(", ")}
|
|
65537
|
+
summary: `${configured.length} of ${total} providers configured: ${configured.join(", ")}.${servicesNote}`,
|
|
65379
65538
|
remediation: null,
|
|
65380
|
-
details: { configured, total }
|
|
65539
|
+
details: { configured, total, ...answerServices.length > 0 ? { answerServices } : {} }
|
|
65381
65540
|
};
|
|
65382
65541
|
}
|
|
65383
65542
|
};
|
|
@@ -66902,14 +67061,14 @@ async function statusRoutes(app, opts) {
|
|
|
66902
67061
|
if (requested) {
|
|
66903
67062
|
const project = resolveProject(opts.db, requested);
|
|
66904
67063
|
if (scopedId && project.id !== scopedId) throw forbidden("This project is outside the API key scope.");
|
|
66905
|
-
const result = { generatedAt: (/* @__PURE__ */ new Date()).toISOString(), summary: { projects: 1, ok: 0, failing: 0, warning: 0, stale: 0, neverSynced: 0 }, projects: [projectStatus(opts, project)] };
|
|
67064
|
+
const result = { generatedAt: (/* @__PURE__ */ new Date()).toISOString(), ...opts.getMcpHealth ? { mcp: opts.getMcpHealth() } : {}, summary: { projects: 1, ok: 0, failing: 0, warning: 0, stale: 0, neverSynced: 0 }, projects: [projectStatus(opts, project)] };
|
|
66906
67065
|
const status = result.projects[0].state;
|
|
66907
67066
|
result.summary[status === "never-synced" ? "neverSynced" : status]++;
|
|
66908
67067
|
if (request.query.problems === "true") result.projects = result.projects.map((item2) => ({ ...item2, integrations: item2.integrations.filter((row) => row.state !== "ok") }));
|
|
66909
67068
|
return instanceStatusDtoSchema.parse(result);
|
|
66910
67069
|
}
|
|
66911
67070
|
const projectsRows = (scopedId ? opts.db.select().from(projects).where(eq91(projects.id, scopedId)) : opts.db.select().from(projects)).all();
|
|
66912
|
-
const output = { generatedAt: (/* @__PURE__ */ new Date()).toISOString(), summary: { projects: projectsRows.length, ok: 0, failing: 0, warning: 0, stale: 0, neverSynced: 0 }, projects: projectsRows.map((project) => projectStatus(opts, project)) };
|
|
67071
|
+
const output = { generatedAt: (/* @__PURE__ */ new Date()).toISOString(), ...opts.getMcpHealth ? { mcp: opts.getMcpHealth() } : {}, summary: { projects: projectsRows.length, ok: 0, failing: 0, warning: 0, stale: 0, neverSynced: 0 }, projects: projectsRows.map((project) => projectStatus(opts, project)) };
|
|
66913
67072
|
for (const project of output.projects) {
|
|
66914
67073
|
const key = project.state === "never-synced" ? "neverSynced" : project.state;
|
|
66915
67074
|
output.summary[key] = (output.summary[key] ?? 0) + 1;
|
|
@@ -70219,6 +70378,7 @@ import { and as and80, count as count8, desc as desc44, eq as eq96, gte as gte25
|
|
|
70219
70378
|
var sameLocation = (a, b) => a.label === b.label && a.city === b.city && a.region === b.region && a.country === b.country && a.timezone === b.timezone;
|
|
70220
70379
|
var BATCH_RECEIPT_PREFIX = "__canonry_research_batch__:";
|
|
70221
70380
|
async function researchRoutes(app, opts) {
|
|
70381
|
+
const routeFamilies = providerRouteFamilies(opts.providerAdapters);
|
|
70222
70382
|
const viewerDailyRunLimit = opts.viewerDailyRunLimit ?? DEFAULT_VIEWER_RESEARCH_DAILY_RUN_LIMIT;
|
|
70223
70383
|
if (!Number.isInteger(viewerDailyRunLimit) || viewerDailyRunLimit <= 0) {
|
|
70224
70384
|
throw new Error("viewerDailyRunLimit must be a positive integer");
|
|
@@ -70244,10 +70404,11 @@ async function researchRoutes(app, opts) {
|
|
|
70244
70404
|
const adapters = opts.providerAdapters ?? [];
|
|
70245
70405
|
const configured = new Set(opts.getConfiguredProviderNames?.() ?? opts.configuredProviderNames ?? []);
|
|
70246
70406
|
const authorizedProviders = researchProjectProviders(app, project.id, project.providers);
|
|
70247
|
-
const
|
|
70407
|
+
const implicitlyEligible = (name) => providerEligibleFor(name, adapters, ProviderWorkflows.research, "implicit");
|
|
70408
|
+
const providerName = input.provider ?? authorizedProviders.find((name) => implicitlyEligible(name) && isProviderAvailable(name, [...configured], routeFamilies) && providerAdapterForName(name, adapters)?.mode === "api") ?? adapters.find((adapter2) => adapter2.mode === "api" && implicitlyEligible(adapter2.name) && configured.has(adapter2.name))?.name;
|
|
70248
70409
|
const adapter = providerName ? providerAdapterForName(providerName, adapters) : void 0;
|
|
70249
|
-
if (!providerName || !adapter || adapter.mode !== "api" || !isSweepProvider(providerName) || isBrowserProvider(providerName) || !isProviderAvailable(providerName, [...configured])) throw validationError("Research requires a configured API provider.", { provider: input.provider, validProviders: authorizedProviders.filter((name) => isProviderAvailable(name, [...configured]) && providerAdapterForName(name, adapters)?.mode === "api") });
|
|
70250
|
-
|
|
70410
|
+
if (!providerName || !adapter || adapter.mode !== "api" || !isSweepProvider(providerName, routeFamilies) || isBrowserProvider(providerName) || !isProviderAvailable(providerName, [...configured], routeFamilies) || !providerEligibleFor(providerName, adapters, ProviderWorkflows.research, "explicit")) throw validationError("Research requires a configured API provider.", { provider: input.provider, validProviders: authorizedProviders.filter((name) => isProviderAvailable(name, [...configured], routeFamilies) && providerAdapterForName(name, adapters)?.mode === "api") });
|
|
70411
|
+
assertProviderRouteScope(request, [providerName], authorizedProviders, routeFamilies);
|
|
70251
70412
|
if (input.model) {
|
|
70252
70413
|
adapter.modelValidationPattern.lastIndex = 0;
|
|
70253
70414
|
if (!adapter.modelConfigurable && input.model !== adapter.defaultModel || !adapter.modelValidationPattern.test(input.model)) throw validationError(`Invalid model "${input.model}" for provider "${providerName}".`, { provider: providerName, model: input.model, hint: adapter.modelValidationHint });
|
|
@@ -70258,7 +70419,7 @@ async function researchRoutes(app, opts) {
|
|
|
70258
70419
|
if (location && !project.locations.some((item2) => sameLocation(item2, location))) throw validationError("Research location must exactly match a configured project location.", { location });
|
|
70259
70420
|
const template = input.template ? resolveResearchTemplate(app, project.id, input.template, scope, location) : null;
|
|
70260
70421
|
const requestedModel2 = input.model ?? null;
|
|
70261
|
-
const resolvedModel = resolveProviderModel(providerName,
|
|
70422
|
+
const resolvedModel = resolveProviderModel(providerName, pinnedRouteSelection(providerName, routeFamilies) ?? requestedModel2 ?? (project.providerModels[providerName] || opts.getEffectiveProviderModels?.()[providerName] || adapter.defaultModel));
|
|
70262
70423
|
adapter.modelValidationPattern.lastIndex = 0;
|
|
70263
70424
|
if (!adapter.modelValidationPattern.test(resolvedModel)) throw validationError('Invalid resolved model "' + resolvedModel + '" for provider "' + providerName + '".', { provider: providerName, model: resolvedModel, hint: adapter.modelValidationHint });
|
|
70264
70425
|
if (deduplicateResearchQueries(input.queries).length !== input.queries.length) throw validationError("Research queries must be unique within a batch.");
|
|
@@ -70325,7 +70486,7 @@ async function researchRoutes(app, opts) {
|
|
|
70325
70486
|
if (!opts.onResearchRunRequested) throw missingDependency("Research execution is not available on this deployment.", { reason: "no-research-handler" });
|
|
70326
70487
|
const active = activeMeasurementPlan(app.db, project.id);
|
|
70327
70488
|
const prepared = input.runs.map((run) => prepareBatchRun(app, opts, project, active, run));
|
|
70328
|
-
|
|
70489
|
+
assertProviderRouteScope(request, prepared.map((run) => run.providerName), researchProjectProviders(app, project.id, project.providers), routeFamilies);
|
|
70329
70490
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
70330
70491
|
const initiatedBy = researchPrincipal(request);
|
|
70331
70492
|
const decision = app.db.transaction((tx) => {
|
|
@@ -70397,24 +70558,33 @@ async function researchRoutes(app, opts) {
|
|
|
70397
70558
|
const effectiveModels2 = opts.getEffectiveProviderModels?.() ?? {};
|
|
70398
70559
|
const adapters = opts.providerAdapters ?? [];
|
|
70399
70560
|
const savedProviders = researchProjectProviders(app, project.id, project.providers);
|
|
70561
|
+
const profileRoutes = adapters.flatMap((adapter) => (adapter.profiles ?? []).filter((profile) => profile.workflows.includes(ProviderWorkflows.research)).map((profile) => profile.route));
|
|
70400
70562
|
const catalog = [...new Map([
|
|
70401
|
-
...adapters.filter((adapter) => isSweepProvider(adapter.name)),
|
|
70402
|
-
...savedProviders.filter((name) =>
|
|
70563
|
+
...adapters.filter((adapter) => isSweepProvider(adapter.name, routeFamilies)),
|
|
70564
|
+
...[...savedProviders, ...profileRoutes].filter((name) => resolveProviderRoute(name, routeFamilies)).flatMap((name) => {
|
|
70403
70565
|
const adapter = providerAdapterForName(name, adapters);
|
|
70404
|
-
return adapter ? [adapter] : [];
|
|
70566
|
+
return adapter && providerEligibleFor(name, adapters, ProviderWorkflows.research, "explicit") ? [adapter] : [];
|
|
70405
70567
|
})
|
|
70406
70568
|
].map((adapter) => [adapter.name, adapter])).values()];
|
|
70407
|
-
const providers = catalog.filter((adapter) => adapter.mode === "api" && !isBrowserProvider(adapter.name) && isProviderAvailable(adapter.name, [...configured])).map((adapter) => {
|
|
70569
|
+
const providers = catalog.filter((adapter) => adapter.mode === "api" && !isBrowserProvider(adapter.name) && isProviderAvailable(adapter.name, [...configured], routeFamilies)).map((adapter) => {
|
|
70570
|
+
const pinned = pinnedRouteSelection(adapter.name, routeFamilies);
|
|
70408
70571
|
const defaultModel = resolveProviderModel(adapter.name, project.providerModels[adapter.name] || effectiveModels2[adapter.name] || adapter.defaultModel);
|
|
70409
|
-
const cached = opts.getCachedProviderModels?.(providerConnectionName(adapter.name)) ?? [];
|
|
70572
|
+
const cached = opts.getCachedProviderModels?.(providerConnectionName(adapter.name, routeFamilies)) ?? [];
|
|
70410
70573
|
const candidates = cached.length ? cached : adapter.knownModels;
|
|
70411
|
-
const models =
|
|
70574
|
+
const models = pinned ? candidates.filter((model) => model.id === defaultModel) : candidates;
|
|
70412
70575
|
return {
|
|
70413
70576
|
name: adapter.name,
|
|
70414
70577
|
displayName: adapter.displayName,
|
|
70415
70578
|
modelConfigurable: adapter.modelConfigurable,
|
|
70416
70579
|
defaultModel,
|
|
70417
|
-
knownModels: [...new Map([{ id: defaultModel, displayName: defaultModel }, ...models].map((model) => [model.id, { id: model.id, displayName: model.displayName }])).values()]
|
|
70580
|
+
knownModels: [...new Map([{ id: defaultModel, displayName: defaultModel }, ...models].map((model) => [model.id, { id: model.id, displayName: model.displayName }])).values()],
|
|
70581
|
+
// Only routed options carry identity fields; engine options keep their shape.
|
|
70582
|
+
...adapter.kind ? {
|
|
70583
|
+
kind: adapter.kind,
|
|
70584
|
+
connection: providerConnectionName(adapter.name, routeFamilies),
|
|
70585
|
+
selectionKind: resolveProviderRoute(adapter.name, routeFamilies)?.family.selectionKind ?? null,
|
|
70586
|
+
...adapter.profiles ? { profiles: adapter.profiles } : {}
|
|
70587
|
+
} : {}
|
|
70418
70588
|
};
|
|
70419
70589
|
});
|
|
70420
70590
|
const canRun = canRunResearch(request, opts.allowViewers ?? false);
|
|
@@ -70481,7 +70651,8 @@ function prepareBatchRun(app, opts, project, active, input) {
|
|
|
70481
70651
|
const configured = new Set(opts.getConfiguredProviderNames?.() ?? opts.configuredProviderNames ?? []);
|
|
70482
70652
|
const providerName = input.provider;
|
|
70483
70653
|
const adapter = providerName ? providerAdapterForName(providerName, adapters) : void 0;
|
|
70484
|
-
|
|
70654
|
+
const routeFamilies = providerRouteFamilies(adapters);
|
|
70655
|
+
if (!adapter || adapter.mode !== "api" || !isSweepProvider(providerName, routeFamilies) || isBrowserProvider(providerName) || !isProviderAvailable(providerName, [...configured], routeFamilies) || !providerEligibleFor(providerName, adapters, ProviderWorkflows.research, "explicit")) {
|
|
70485
70656
|
throw validationError("Research requires a configured API provider.", { provider: providerName, validProviders: adapters.filter((a) => a.mode === "api" && configured.has(a.name)).map((a) => a.name) });
|
|
70486
70657
|
}
|
|
70487
70658
|
adapter.modelValidationPattern.lastIndex = 0;
|
|
@@ -70561,7 +70732,32 @@ function serializeRun(row) {
|
|
|
70561
70732
|
return { id: row.id, projectId: row.projectId, status: row.status, provider: row.provider, requestedModel: row.requestedModel, resolvedModel: row.resolvedModel, location: row.location ?? null, scope: row.scope ?? null, template: row.template ?? null, totalQueries: row.totalQueries, completedQueries: row.completedQueries, failedQueries: row.failedQueries, error: row.error, initiatedBy: row.initiatedBy ?? null, startedAt: row.startedAt, finishedAt: row.finishedAt, createdAt: row.createdAt };
|
|
70562
70733
|
}
|
|
70563
70734
|
function serializeQuery(row) {
|
|
70564
|
-
return {
|
|
70735
|
+
return {
|
|
70736
|
+
id: row.id,
|
|
70737
|
+
position: row.position,
|
|
70738
|
+
query: row.queryText,
|
|
70739
|
+
queryClass: row.queryClass ?? null,
|
|
70740
|
+
status: row.status,
|
|
70741
|
+
requestedModel: row.requestedModel,
|
|
70742
|
+
resolvedModel: row.resolvedModel,
|
|
70743
|
+
servedModel: row.servedModel,
|
|
70744
|
+
answerText: row.answerText,
|
|
70745
|
+
groundingSources: row.groundingSources,
|
|
70746
|
+
citedDomains: row.citedDomains,
|
|
70747
|
+
searchQueries: row.searchQueries,
|
|
70748
|
+
retrievedSources: row.retrievedSources ?? null,
|
|
70749
|
+
namedCompetitors: row.namedCompetitors,
|
|
70750
|
+
citedCompetitorDomains: row.citedCompetitorDomains,
|
|
70751
|
+
answerMentioned: row.answerMentioned,
|
|
70752
|
+
citationState: row.citationState,
|
|
70753
|
+
error: row.error,
|
|
70754
|
+
startedAt: row.startedAt,
|
|
70755
|
+
finishedAt: row.finishedAt,
|
|
70756
|
+
createdAt: row.createdAt,
|
|
70757
|
+
// Only answer services record evidence; every other row keeps its exact shape.
|
|
70758
|
+
...row.answerEvidence ? { evidence: row.answerEvidence, citationMeasured: row.status === ResearchQueryStatuses.completed && row.answerEvidence.citationMeasurable } : {},
|
|
70759
|
+
...row.upstreamJobId ? { upstreamJobId: row.upstreamJobId } : {}
|
|
70760
|
+
};
|
|
70565
70761
|
}
|
|
70566
70762
|
function researchPrincipal(request) {
|
|
70567
70763
|
const principal = request.principal;
|
|
@@ -70768,6 +70964,7 @@ async function apiRoutes(app, opts) {
|
|
|
70768
70964
|
});
|
|
70769
70965
|
await api.register(userRoutes);
|
|
70770
70966
|
await api.register(openApiRoutes, { ...opts.openApiInfo, routePrefix: opts.routePrefix });
|
|
70967
|
+
const providerRouteFamilies2 = routeFamiliesOf(opts.providerAdapters);
|
|
70771
70968
|
await api.register(projectRoutes, {
|
|
70772
70969
|
onProjectDeleting: opts.onProjectDeleting,
|
|
70773
70970
|
onProjectDeleted: opts.onProjectDeleted,
|
|
@@ -70799,10 +70996,12 @@ async function apiRoutes(app, opts) {
|
|
|
70799
70996
|
validProviderNames: opts.providerAdapters?.map((a) => a.name),
|
|
70800
70997
|
getRunnableProviderNames: opts.getRunnableProviderNames,
|
|
70801
70998
|
getEffectiveProviderModels: opts.getEffectiveProviderModels,
|
|
70802
|
-
getBatchEligibleProviderNames: opts.getBatchEligibleProviderNames
|
|
70999
|
+
getBatchEligibleProviderNames: opts.getBatchEligibleProviderNames,
|
|
71000
|
+
providerAdapters: opts.providerAdapters
|
|
70803
71001
|
});
|
|
70804
71002
|
await api.register(measurementPlanRoutes, {
|
|
70805
71003
|
getRunnableProviderNames: opts.getRunnableProviderNames,
|
|
71004
|
+
providerRouteFamilies: providerRouteFamilies2,
|
|
70806
71005
|
onCompetitorAliasesChanged: opts.onCompetitorAliasesChanged,
|
|
70807
71006
|
onCompetitorAutoAliasRescan: opts.onCompetitorAutoAliasRescan
|
|
70808
71007
|
});
|
|
@@ -70811,6 +71010,8 @@ async function apiRoutes(app, opts) {
|
|
|
70811
71010
|
});
|
|
70812
71011
|
await api.register(measurementDraftRoutes, {
|
|
70813
71012
|
getRunnableProviderNames: opts.getRunnableProviderNames,
|
|
71013
|
+
providerRouteFamilies: providerRouteFamilies2,
|
|
71014
|
+
providerAdapters: opts.providerAdapters,
|
|
70814
71015
|
onCompetitorAliasesChanged: opts.onCompetitorAliasesChanged,
|
|
70815
71016
|
onCompetitorAutoAliasRescan: opts.onCompetitorAutoAliasRescan
|
|
70816
71017
|
});
|
|
@@ -70822,6 +71023,7 @@ async function apiRoutes(app, opts) {
|
|
|
70822
71023
|
await api.register(visibilityReportRoutes);
|
|
70823
71024
|
await api.register(queryTrackingRoutes, {
|
|
70824
71025
|
getRunnableProviderNames: opts.getRunnableProviderNames,
|
|
71026
|
+
providerRouteFamilies: providerRouteFamilies2,
|
|
70825
71027
|
providerSummary: opts.providerSummary
|
|
70826
71028
|
});
|
|
70827
71029
|
await api.register(applyRoutes, {
|
|
@@ -70850,7 +71052,7 @@ async function apiRoutes(app, opts) {
|
|
|
70850
71052
|
await api.register(citationRoutes);
|
|
70851
71053
|
await api.register(visibilityStatsRoutes);
|
|
70852
71054
|
await api.register(resultsExportRoutes);
|
|
70853
|
-
await api.register(compositeRoutes, { sentiment: opts.sentiment, getRunnableProviderNames: opts.getRunnableProviderNames });
|
|
71055
|
+
await api.register(compositeRoutes, { sentiment: opts.sentiment, getRunnableProviderNames: opts.getRunnableProviderNames, providerRouteFamilies: providerRouteFamilies2 });
|
|
70854
71056
|
await api.register(contentRoutes, {
|
|
70855
71057
|
explainContentRecommendation: opts.explainContentRecommendation,
|
|
70856
71058
|
briefContentRecommendation: opts.briefContentRecommendation,
|
|
@@ -70869,11 +71071,13 @@ async function apiRoutes(app, opts) {
|
|
|
70869
71071
|
});
|
|
70870
71072
|
await api.register(keysRoutes);
|
|
70871
71073
|
await api.register(snapshotRoutes, {
|
|
70872
|
-
onSnapshotRequested: opts.onSnapshotRequested
|
|
71074
|
+
onSnapshotRequested: opts.onSnapshotRequested,
|
|
71075
|
+
providerAdapters: opts.providerAdapters
|
|
70873
71076
|
});
|
|
70874
71077
|
await api.register(scheduleRoutes, {
|
|
70875
71078
|
onScheduleUpdated: opts.onScheduleUpdated,
|
|
70876
|
-
validProviderNames: opts.providerAdapters?.map((a) => a.name)
|
|
71079
|
+
validProviderNames: opts.providerAdapters?.map((a) => a.name),
|
|
71080
|
+
providerAdapters: opts.providerAdapters
|
|
70877
71081
|
});
|
|
70878
71082
|
await api.register(notificationRoutes, {
|
|
70879
71083
|
allowLoopbackWebhooks: opts.allowLoopbackWebhooks
|
|
@@ -71035,6 +71239,7 @@ async function apiRoutes(app, opts) {
|
|
|
71035
71239
|
});
|
|
71036
71240
|
await api.register(statusRoutes, {
|
|
71037
71241
|
db: opts.db,
|
|
71242
|
+
getMcpHealth: opts.getMcpHealth,
|
|
71038
71243
|
googleConnectionStore: opts.googleConnectionStore,
|
|
71039
71244
|
bingConnectionStore: opts.bingConnectionStore,
|
|
71040
71245
|
ga4CredentialStore: opts.ga4CredentialStore,
|
|
@@ -71286,6 +71491,8 @@ export {
|
|
|
71286
71491
|
writeAuditLog,
|
|
71287
71492
|
auditFromRequest,
|
|
71288
71493
|
registerAgentConversationRoutes,
|
|
71494
|
+
blockedAddressReason,
|
|
71495
|
+
stripIpv6Brackets,
|
|
71289
71496
|
measurementSlotKey,
|
|
71290
71497
|
measurementRunSlotState,
|
|
71291
71498
|
measurementRunCompleteness,
|