@canonry/canonry 7.52.0 → 7.54.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 +24 -1
- 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-aOd198dT.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-BWnMmkiO.js → format-helpers-Gj1ekh6p.js} +1 -1
- package/assets/assets/index-B8W65ejO.css +1 -0
- 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-hGyOC4V_.js → react-sigma_core.esm.min-j5DWE8Rk.js} +1 -1
- package/assets/assets/service-2DEngBCR.js +1 -0
- package/assets/index.html +9 -7
- package/dist/{ads-MREK2AGL.js → ads-A5S2NQBZ.js} +3 -3
- package/dist/{agent-4RUZ3MC4.js → agent-BV7G7QN7.js} +7 -7
- package/dist/{agent-ask-YLTYBEYH.js → agent-ask-5ALAHZ6T.js} +3 -3
- package/dist/{agent-conversations-QA6IKDGR.js → agent-conversations-MJPQCJYR.js} +3 -3
- package/dist/{agent-memory-MEQAJOB3.js → agent-memory-Z3VPA5KH.js} +3 -3
- package/dist/{agent-providers-AXYPDJHL.js → agent-providers-FP3LAZPG.js} +3 -3
- package/dist/{agent-transcript-SMNQNYCD.js → agent-transcript-4GXCOC73.js} +3 -3
- package/dist/{analytics-4OR64IGV.js → analytics-TOLSUYSN.js} +3 -3
- package/dist/{apply-CQXCFXAH.js → apply-EU5JAFVZ.js} +3 -3
- package/dist/{backfill-TMXCNVOB.js → backfill-3263IYJH.js} +9 -9
- package/dist/{backlinks-6KFAQGYV.js → backlinks-XQ5JTN6W.js} +3 -3
- package/dist/{bing-HFCACTAC.js → bing-LYHRD7BF.js} +3 -3
- package/dist/{bootstrap-SQVQXOJC.js → bootstrap-AKWTIMMH.js} +17 -9
- package/dist/{cdp-IACL7EXU.js → cdp-N4PQJWGQ.js} +7 -7
- package/dist/{chunk-K5I45PZI.js → chunk-2SY2FYFW.js} +556 -255
- package/dist/{chunk-KXAOMTXN.js → chunk-4LVJFSPH.js} +5 -5
- package/dist/{chunk-GNKOBKPW.js → chunk-5P7DSHNK.js} +4 -4
- package/dist/{chunk-6BPZHNDC.js → chunk-6WTSWWP6.js} +2 -2
- package/dist/{chunk-MJNUSPO4.js → chunk-75CFTTBF.js} +2 -2
- package/dist/{chunk-TALC5DX5.js → chunk-B37SDIGU.js} +1 -1
- package/dist/chunk-BQKKAPMW.js +1211 -0
- package/dist/{chunk-LK2BG6EX.js → chunk-D234NBWI.js} +11 -1
- package/dist/{chunk-QLPLENDT.js → chunk-EIG2V6UI.js} +1 -1
- package/dist/{chunk-MKAC7HKH.js → chunk-GFRIXUDK.js} +38 -4
- package/dist/{chunk-BBOHY2DQ.js → chunk-H6EQMYGT.js} +1 -1
- package/dist/{chunk-EGIZNSDA.js → chunk-J7VN3FZ3.js} +1 -1
- package/dist/{chunk-DSNSD5J3.js → chunk-K5MBEK4S.js} +19 -9
- package/dist/{chunk-SNFBJKAW.js → chunk-LCTYTGSE.js} +3 -3
- package/dist/{chunk-5N6245R7.js → chunk-MARVEIWH.js} +4 -4
- package/dist/{chunk-7XE2IRBG.js → chunk-OHVXKFQI.js} +1 -1
- package/dist/{chunk-O4RMPA6H.js → chunk-OMXWBR2R.js} +7294 -6533
- package/dist/{chunk-O77IBNVO.js → chunk-PFPTUCMG.js} +326 -324
- package/dist/{chunk-YSEC6TIB.js → chunk-PRNO5TLE.js} +1206 -405
- package/dist/{chunk-7244X3K6.js → chunk-QFKDFU73.js} +2 -2
- package/dist/chunk-R4AFXPM4.js +959 -0
- package/dist/{chunk-V5D4XNWV.js → chunk-RHCDUPD6.js} +39 -2
- package/dist/{chunk-AWCWIQAU.js → chunk-SKZVEZZK.js} +231 -5
- package/dist/{chunk-RVUCY4ZV.js → chunk-T63KVDWY.js} +6 -4
- package/dist/{chunk-IIOEAJTV.js → chunk-VB47PTY7.js} +3 -3
- package/dist/{chunk-ILDT4LPB.js → chunk-VCTP2RG6.js} +26 -240
- package/dist/{chunk-JY3RLZGB.js → chunk-VF7XGX2I.js} +1 -1
- package/dist/{chunk-I6KNMZ77.js → chunk-VMCVLESK.js} +4 -4
- package/dist/{chunk-R2J4SNKF.js → chunk-WDJMIIY2.js} +1 -1
- package/dist/{chunk-BU3VAG5J.js → chunk-XJVCTI2N.js} +3 -3
- package/dist/{chunk-HEGXGCGL.js → chunk-Y2YBRLSS.js} +3 -3
- package/dist/{chunk-Y4GK7GCV.js → chunk-YOZ35ZTT.js} +1 -1
- package/dist/{chunk-BYOK6Z4F.js → chunk-ZA7D7CCN.js} +2 -2
- package/dist/{chunk-FC4XND45.js → chunk-ZILJZNMQ.js} +1 -1
- package/dist/{citations-NSBBWRZ4.js → citations-JK3ZMAR7.js} +3 -3
- package/dist/{cli-catalog-OFWJMNMD.js → cli-catalog-P2I6IYNI.js} +3 -3
- package/dist/{cli-commands-WVBL337U.js → cli-commands-YDRKG6OC.js} +7 -7
- package/dist/cli.js +13 -13
- package/dist/{competitor-V4OHORBC.js → competitor-5CJPM36M.js} +3 -3
- package/dist/{content-RUXRI5IC.js → content-5FEDXNHR.js} +3 -3
- package/dist/{dashboard-JXB2YAQJ.js → dashboard-ME7MBJTX.js} +6 -6
- package/dist/{demo-55ZNUOXU.js → demo-N7MEASQP.js} +1 -1
- package/dist/{demo-server-XO7PHM4I.js → demo-server-IGTBANDC.js} +11 -11
- package/dist/{discover-JJQ564HS.js → discover-EAISVTA6.js} +3 -3
- package/dist/{discover-eval-KLEKZ6U4.js → discover-eval-JIBKK44Q.js} +3 -3
- package/dist/{doctor-JAMQZCMZ.js → doctor-HSQYOZ4C.js} +3 -3
- package/dist/{evidence-YRSB7GFE.js → evidence-PSYAWKPP.js} +3 -3
- package/dist/{export-cmd-MHML4OYU.js → export-cmd-MWJN6H7W.js} +3 -3
- package/dist/{ga-LSXPE2MN.js → ga-WSQWECYY.js} +3 -3
- package/dist/{gbp-RMKMLOC7.js → gbp-OD26AEPF.js} +3 -3
- package/dist/{google-JQ4T6JTQ.js → google-FMJ7IWAF.js} +4 -4
- package/dist/{google-marketing-J6SEODYC.js → google-marketing-66JL4V24.js} +1 -1
- package/dist/{health-cmd-MV2JM2C3.js → health-cmd-2RO5LAI4.js} +3 -3
- package/dist/{history-SRRH7A2E.js → history-X6CNPW7G.js} +3 -3
- package/dist/index.d.ts +518 -50
- package/dist/index.js +24 -23
- package/dist/{init-ZJZFUERV.js → init-25III66S.js} +11 -11
- package/dist/{insights-PMMGNWZH.js → insights-6IWWA6JU.js} +3 -3
- package/dist/intelligence-service-N334P6FH.js +15 -0
- package/dist/{keys-TS7NZANS.js → keys-ABXAPISY.js} +3 -3
- package/dist/{keyword-VNCKDUGC.js → keyword-LERAVMI3.js} +3 -3
- package/dist/{logs-VH3WOTZJ.js → logs-BTAB5SNZ.js} +3 -3
- package/dist/{mcp-DG2RROB3.js → mcp-5E42RT6R.js} +2 -2
- package/dist/mcp.js +9 -9
- package/dist/{measurement-plan-4T35TUGG.js → measurement-plan-MRZRNBJG.js} +5 -5
- package/dist/{notify-BWHUSKL7.js → notify-YQYGC5UZ.js} +3 -3
- package/dist/{organic-evidence-QX4SXXJP.js → organic-evidence-6QT4YT3K.js} +3 -3
- package/dist/{overview-7IHUTKUV.js → overview-EHZ3FTS2.js} +4 -4
- package/dist/{project-JXLSWDE2.js → project-RNLV2ARE.js} +3 -3
- package/dist/{query-S75EL25H.js → query-IM2RXI4L.js} +3 -3
- package/dist/{research-KFTV3IP4.js → research-4FALR336.js} +25 -10
- package/dist/{results-export-GTKVBU34.js → results-export-4ETSRUGO.js} +3 -3
- package/dist/{run-26HDIRHF.js → run-QL7226N7.js} +4 -4
- package/dist/{schedule-N6G4SVHQ.js → schedule-GJE634VO.js} +3 -3
- package/dist/{search-MI32EPYM.js → search-7OQL67R6.js} +3 -3
- package/dist/{serve-XLGE42AG.js → serve-UN2OEK2Q.js} +25 -24
- package/dist/{session-W5DXWIYM.js → session-5M54TVY5.js} +16 -15
- package/dist/{settings-T7WI2UVE.js → settings-2QOL7YBM.js} +15 -3
- package/dist/{skills-F3WPKPTK.js → skills-GPLAAU3I.js} +2 -2
- package/dist/{snapshot-PD3EAVEX.js → snapshot-5YMJFRJS.js} +8 -6
- package/dist/{src-XDUXMJC3.js → src-YF3JLURF.js} +2 -2
- package/dist/{status-PUH7JFZ4.js → status-WGWC6FLN.js} +33 -5
- package/dist/{technical-aeo-AUFWWJIP.js → technical-aeo-RNMLD7OL.js} +3 -3
- package/dist/{telemetry-XBYT7G2K.js → telemetry-7U3ZICU4.js} +4 -4
- package/dist/{tools-GVHIRWSN.js → tools-CSKTZTKT.js} +11 -11
- package/dist/{traffic-B3HW2ZWG.js → traffic-QIAXLW6J.js} +5 -5
- package/dist/{users-M5HNQZYI.js → users-I6X5P5AO.js} +3 -3
- package/dist/{visibility-stats-Y7GJKMHN.js → visibility-stats-33OUKQQL.js} +3 -3
- package/dist/{wordpress-GCIURYPN.js → wordpress-3IO3O27D.js} +3 -3
- package/package.json +3 -1
- package/assets/assets/AccessControls-CteIuEGI.js +0 -1
- package/assets/assets/AuditHistoryPanel-DqJGiLsf.js +0 -1
- package/assets/assets/BacklinksPage-DotWEPQt.js +0 -1
- package/assets/assets/MeasurementPropertyPage-CuaKVK8x.js +0 -4
- package/assets/assets/ProjectPage-O9oufMgi.js +0 -8
- package/assets/assets/RunsPage-DIXMrc-N.js +0 -1
- package/assets/assets/SettingsPage-BuGb6AGa.js +0 -1
- package/assets/assets/SiteHealthSection-CweaKjCo.js +0 -2
- package/assets/assets/TrafficPage-B7MaQalp.js +0 -40
- package/assets/assets/TrafficSourceDetailPage-BPtjnF9s.js +0 -1
- package/assets/assets/card-DoV-8Txo.js +0 -60
- package/assets/assets/extract-error-message-DKQJJlZ-.js +0 -1
- package/assets/assets/index-CsPsaUr7.css +0 -1
- package/assets/assets/index-Z63c4PeO.js +0 -39
- package/assets/assets/query-client-vB35tVTz.js +0 -1
- package/assets/assets/react-query-BI0567qs.js +0 -1
- package/assets/assets/service-c4YvpVKX.js +0 -1
- package/dist/chunk-OFL4PTYU.js +0 -644
- package/dist/intelligence-service-KCSU6ZUJ.js +0 -15
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
answerServiceAdapters,
|
|
3
|
+
answerServiceDescriptors
|
|
4
|
+
} from "./chunk-R4AFXPM4.js";
|
|
5
|
+
import {
|
|
3
6
|
AeroLlmUsageFeatures,
|
|
4
7
|
aeroTurnStatus,
|
|
5
8
|
aeroTurnUsage,
|
|
6
9
|
aeroViewPrompt,
|
|
7
|
-
agentProviderApiKeyEnvVar,
|
|
8
|
-
agentProvidersByPriority,
|
|
9
10
|
buildAeroViewTool,
|
|
10
|
-
buildAgentProvidersResponse,
|
|
11
11
|
buildApiKeyResolver,
|
|
12
12
|
buildSkillDocTools,
|
|
13
|
-
coerceAgentProvider,
|
|
14
|
-
completeOnce,
|
|
15
13
|
configureAeroRuntime,
|
|
16
14
|
createAeroSession,
|
|
17
15
|
describeAgentPin,
|
|
18
16
|
detectAgentProvider,
|
|
19
|
-
getAgentProvider,
|
|
20
|
-
isAgentModelAvailable,
|
|
21
17
|
isRunFailureMessage,
|
|
22
18
|
isSystemMessage,
|
|
23
19
|
loadAeroSystemPrompt,
|
|
@@ -28,19 +24,17 @@ import {
|
|
|
28
24
|
resolveAgentEnabled,
|
|
29
25
|
resolveAgentProactiveEnabled,
|
|
30
26
|
resolveAgentReasoning,
|
|
31
|
-
resolveApiKeyFor,
|
|
32
27
|
resolveConfiguredAgentProvider,
|
|
33
|
-
resolveModelForCapability,
|
|
34
28
|
resolveSessionProviderAndModel,
|
|
35
29
|
setAeroSystemPrompt
|
|
36
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-VCTP2RG6.js";
|
|
37
31
|
import {
|
|
38
32
|
AeroToolProfiles,
|
|
39
33
|
AeroToolScopes,
|
|
40
34
|
buildAeroStateTools,
|
|
41
35
|
isAeroToolProfile,
|
|
42
36
|
truncateToolResult
|
|
43
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-MARVEIWH.js";
|
|
44
38
|
import {
|
|
45
39
|
getGoogleAuthConfig,
|
|
46
40
|
getGoogleConnection,
|
|
@@ -59,7 +53,7 @@ import {
|
|
|
59
53
|
removeCloudflareTrafficConnection,
|
|
60
54
|
removeCloudflareTrafficConnectionBySourceId,
|
|
61
55
|
upsertCloudflareTrafficConnection
|
|
62
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-WDJMIIY2.js";
|
|
63
57
|
import {
|
|
64
58
|
claudeAdapter,
|
|
65
59
|
embedQueries,
|
|
@@ -68,8 +62,9 @@ import {
|
|
|
68
62
|
geminiAdapter,
|
|
69
63
|
museAdapter,
|
|
70
64
|
openaiAdapter,
|
|
65
|
+
openrouterAdapter,
|
|
71
66
|
perplexityAdapter
|
|
72
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-SKZVEZZK.js";
|
|
73
68
|
import {
|
|
74
69
|
classifyUsageSurface,
|
|
75
70
|
createApiUsageTelemetry,
|
|
@@ -81,7 +76,7 @@ import {
|
|
|
81
76
|
startOutcomeTimer,
|
|
82
77
|
trackFeatureCompleted,
|
|
83
78
|
trackInstallState
|
|
84
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-VMCVLESK.js";
|
|
85
80
|
import {
|
|
86
81
|
isLoopbackBindHost
|
|
87
82
|
} from "./chunk-TSENU4GG.js";
|
|
@@ -89,7 +84,7 @@ import {
|
|
|
89
84
|
isApiProviderRegistrable,
|
|
90
85
|
isCdpProviderRegistrable,
|
|
91
86
|
registeredProviderNames
|
|
92
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-VF7XGX2I.js";
|
|
93
88
|
import {
|
|
94
89
|
checkLatestVersionForServer,
|
|
95
90
|
getOrCreateAnonymousId,
|
|
@@ -100,46 +95,62 @@ import {
|
|
|
100
95
|
recordDashboardEvent,
|
|
101
96
|
setTelemetryPreference,
|
|
102
97
|
trackEvent
|
|
103
|
-
} from "./chunk-
|
|
98
|
+
} from "./chunk-QFKDFU73.js";
|
|
104
99
|
import {
|
|
105
100
|
createCanonryMcpServer
|
|
106
|
-
} from "./chunk-
|
|
101
|
+
} from "./chunk-LCTYTGSE.js";
|
|
107
102
|
import {
|
|
108
103
|
CANONRY_MCP_TIERS,
|
|
109
104
|
CANONRY_MCP_TOOLKIT_NAMES
|
|
110
105
|
} from "./chunk-4MJYGB56.js";
|
|
111
106
|
import {
|
|
112
107
|
ApiClient
|
|
113
|
-
} from "./chunk-
|
|
108
|
+
} from "./chunk-RHCDUPD6.js";
|
|
114
109
|
import {
|
|
110
|
+
AGENT_PROVIDERS,
|
|
115
111
|
adapterSupportsBatch,
|
|
112
|
+
aeroModels,
|
|
113
|
+
agentProviderApiKeyEnvVar,
|
|
114
|
+
agentProvidersByPriority,
|
|
116
115
|
batchEligibleProviderNames,
|
|
116
|
+
buildAgentProvidersResponse,
|
|
117
|
+
coerceAgentProvider,
|
|
118
|
+
completeOnce,
|
|
117
119
|
dashboardManagedRunKindsSchema,
|
|
120
|
+
getAgentProvider,
|
|
118
121
|
getConfigPath,
|
|
122
|
+
getSharedProviderExecutionGate,
|
|
123
|
+
isAgentModelAvailable,
|
|
124
|
+
isAgentModelUnchecked,
|
|
119
125
|
loadConfig,
|
|
120
126
|
loadConfigRaw,
|
|
127
|
+
openRouterModels,
|
|
121
128
|
providerConfigFromEntry,
|
|
122
129
|
providersWithUnsupportedBatch,
|
|
130
|
+
refreshAgentModels,
|
|
131
|
+
resolveApiKeyFor,
|
|
132
|
+
resolveModelForCapability,
|
|
123
133
|
resolveOperatorApiKeyIds,
|
|
124
134
|
resolveSentimentInstallConfig,
|
|
125
135
|
saveConfig,
|
|
126
136
|
saveConfigPatch,
|
|
127
|
-
sentimentInstallReadiness
|
|
128
|
-
|
|
137
|
+
sentimentInstallReadiness,
|
|
138
|
+
updateSharedProviderExecutionGate
|
|
139
|
+
} from "./chunk-BQKKAPMW.js";
|
|
129
140
|
import {
|
|
130
141
|
getBundledSkillSnapshots
|
|
131
|
-
} from "./chunk-
|
|
142
|
+
} from "./chunk-B37SDIGU.js";
|
|
132
143
|
import {
|
|
133
144
|
computeFactorAverages,
|
|
134
145
|
deleteSiteCrawlGraphLayout,
|
|
135
146
|
persistSiteCrawlGraphLayout,
|
|
136
147
|
prepareSiteCrawlGraphLayout,
|
|
137
148
|
recordedSharePct
|
|
138
|
-
} from "./chunk-
|
|
149
|
+
} from "./chunk-ZA7D7CCN.js";
|
|
139
150
|
import {
|
|
140
151
|
CanonryMcpToolNames,
|
|
141
152
|
canonryMcpTools
|
|
142
|
-
} from "./chunk-
|
|
153
|
+
} from "./chunk-T63KVDWY.js";
|
|
143
154
|
import {
|
|
144
155
|
PACKAGE_VERSION
|
|
145
156
|
} from "./chunk-AOJU5LKX.js";
|
|
@@ -151,11 +162,11 @@ import {
|
|
|
151
162
|
addLogListener,
|
|
152
163
|
createFastifyLogger,
|
|
153
164
|
createLogger
|
|
154
|
-
} from "./chunk-
|
|
165
|
+
} from "./chunk-4LVJFSPH.js";
|
|
155
166
|
import {
|
|
156
167
|
computeCitedCompetitorDomains,
|
|
157
168
|
determineCitationState
|
|
158
|
-
} from "./chunk-
|
|
169
|
+
} from "./chunk-ZILJZNMQ.js";
|
|
159
170
|
import {
|
|
160
171
|
BingApiError,
|
|
161
172
|
CC_CACHE_DIR,
|
|
@@ -182,6 +193,7 @@ import {
|
|
|
182
193
|
auditFromRequest,
|
|
183
194
|
backfillProjectAnswerMentions,
|
|
184
195
|
backfillProjectAnswerMentionsInChunks,
|
|
196
|
+
blockedAddressReason,
|
|
185
197
|
buildLocationProfileFields,
|
|
186
198
|
captureSimpleMeasurementDefinition,
|
|
187
199
|
ccReleasePaths,
|
|
@@ -265,13 +277,14 @@ import {
|
|
|
265
277
|
sentimentClassifierInput,
|
|
266
278
|
sentimentHash,
|
|
267
279
|
serializeUserSessionCookie,
|
|
280
|
+
stripIpv6Brackets,
|
|
268
281
|
syncRunClaimKey,
|
|
269
282
|
toAlertView,
|
|
270
283
|
webhookOutcomeTarget,
|
|
271
284
|
webhookResponseReason,
|
|
272
285
|
webhookTargetRefusalReason,
|
|
273
286
|
writeAuditLog
|
|
274
|
-
} from "./chunk-
|
|
287
|
+
} from "./chunk-PRNO5TLE.js";
|
|
275
288
|
import {
|
|
276
289
|
OperationalLogStore,
|
|
277
290
|
SentimentIdempotencyConflict,
|
|
@@ -353,7 +366,7 @@ import {
|
|
|
353
366
|
siteLivenessState,
|
|
354
367
|
trafficSources,
|
|
355
368
|
usageCounters
|
|
356
|
-
} from "./chunk-
|
|
369
|
+
} from "./chunk-GFRIXUDK.js";
|
|
357
370
|
import {
|
|
358
371
|
AGENT_MEMORY_VALUE_MAX_BYTES,
|
|
359
372
|
AI_ENGINE_DOMAINS,
|
|
@@ -383,10 +396,16 @@ import {
|
|
|
383
396
|
GoogleAdsSnapshotKinds,
|
|
384
397
|
GoogleMarketingProviders,
|
|
385
398
|
GtmSnapshotKinds,
|
|
399
|
+
HostedMcpStatuses,
|
|
400
|
+
HostedMcpUnavailableReasons,
|
|
386
401
|
INTEGRATION_NAMES,
|
|
402
|
+
IncompleteAnswerError,
|
|
387
403
|
IntegrationNames,
|
|
404
|
+
LlmCapabilities,
|
|
405
|
+
LocationTreatmentStatuses,
|
|
388
406
|
MEASUREMENT_CHANGES_NOISE_ANSWERS,
|
|
389
407
|
MEASUREMENT_PLAN_V2_SCHEMA_VERSION,
|
|
408
|
+
McpTransportStatuses,
|
|
390
409
|
MemorySources,
|
|
391
410
|
ONBOARDING_FLOW_VERSION,
|
|
392
411
|
OPERATION_ACCESS_HEADER,
|
|
@@ -404,6 +423,7 @@ import {
|
|
|
404
423
|
ProviderDispatchModes,
|
|
405
424
|
ProviderNames,
|
|
406
425
|
ProviderReloadErrorReasons,
|
|
426
|
+
ProviderWorkflows,
|
|
407
427
|
ROUTE_CAPABLE_CITED_URL_PROVIDERS,
|
|
408
428
|
RUN_FILL_PROVIDER_BREAKER,
|
|
409
429
|
ResearchQueryStatuses,
|
|
@@ -411,6 +431,9 @@ import {
|
|
|
411
431
|
RunKinds,
|
|
412
432
|
RunStatuses,
|
|
413
433
|
RunTriggers,
|
|
434
|
+
SENTIMENT_MODEL,
|
|
435
|
+
SENTIMENT_OPENROUTER_MODEL,
|
|
436
|
+
SENTIMENT_OPENROUTER_SERVED_MODEL,
|
|
414
437
|
SITE_AUDIT_DEFAULT_PAGE_LIMIT,
|
|
415
438
|
SITE_AUDIT_MAX_EDGE_LIMIT,
|
|
416
439
|
SITE_AUDIT_MAX_PAGE_LIMIT,
|
|
@@ -424,6 +447,7 @@ import {
|
|
|
424
447
|
USAGE_TELEMETRY_HEADERS,
|
|
425
448
|
UserRoles,
|
|
426
449
|
actionConfidenceLabel,
|
|
450
|
+
adapterConnectionName,
|
|
427
451
|
adsAccountDtoSchema,
|
|
428
452
|
adsConversionEventSettingListResponseSchema,
|
|
429
453
|
adsConversionPixelListResponseSchema,
|
|
@@ -433,6 +457,7 @@ import {
|
|
|
433
457
|
agentMemoryUpsertRequestSchema,
|
|
434
458
|
agentPromptRequestSchema,
|
|
435
459
|
answerProseForMentions,
|
|
460
|
+
answerServiceCatalogFields,
|
|
436
461
|
asRecord,
|
|
437
462
|
authInvalid,
|
|
438
463
|
authRequired,
|
|
@@ -445,6 +470,7 @@ import {
|
|
|
445
470
|
buildSnapshotUsage,
|
|
446
471
|
businessProfileReviewsCover,
|
|
447
472
|
calendarRecurrenceSchema,
|
|
473
|
+
canGenerateText,
|
|
448
474
|
canonicalSentimentJson,
|
|
449
475
|
canonicalizeGtmAccountId,
|
|
450
476
|
canonicalizeGtmContainerId,
|
|
@@ -500,16 +526,21 @@ import {
|
|
|
500
526
|
gtmRawSnapshotDtoSchema,
|
|
501
527
|
gtmWorkspaceListResponseSchema,
|
|
502
528
|
hasCurrentSentimentTemplate,
|
|
529
|
+
hasDirectCitedUrls,
|
|
503
530
|
hostMatchesAnyDomain,
|
|
504
531
|
hostMatchesDomain,
|
|
505
532
|
hostOf,
|
|
506
533
|
inclusiveDayCount,
|
|
507
534
|
isBrowserProvider,
|
|
535
|
+
isCitationMeasurable,
|
|
536
|
+
isEligibleFor,
|
|
508
537
|
isNegativeReviewRating,
|
|
538
|
+
isOpenRouterRoute,
|
|
509
539
|
isReadOnlyKey,
|
|
510
540
|
isRetryableHttpError,
|
|
511
541
|
isSearchLocationIgnored,
|
|
512
542
|
isSelfLink,
|
|
543
|
+
isSweepProvider,
|
|
513
544
|
isVertexGroundingRedirect,
|
|
514
545
|
mapWithConcurrency,
|
|
515
546
|
matcherMatchesText,
|
|
@@ -533,6 +564,7 @@ import {
|
|
|
533
564
|
parseOriginList,
|
|
534
565
|
parseRunError,
|
|
535
566
|
percentOf,
|
|
567
|
+
providerConnectionName,
|
|
536
568
|
providerError,
|
|
537
569
|
providerSupportsLocationContext,
|
|
538
570
|
quotaExceeded,
|
|
@@ -541,10 +573,13 @@ import {
|
|
|
541
573
|
reportMonthsForDoctor,
|
|
542
574
|
resolveNegativeReviewMaxStars,
|
|
543
575
|
resolveProviderModel,
|
|
576
|
+
resolveProviderRoute,
|
|
544
577
|
resolveSnapshotRequestQueries,
|
|
545
578
|
retryAfterDelayMs,
|
|
579
|
+
routeFamiliesOf,
|
|
546
580
|
sentimentClassifierInputSchema,
|
|
547
581
|
sentimentClassifierOutputSchema,
|
|
582
|
+
sentimentEvaluatorProvider,
|
|
548
583
|
sentimentSelectionSchema,
|
|
549
584
|
serializeForInlineScript,
|
|
550
585
|
serializeRunError,
|
|
@@ -566,7 +601,7 @@ import {
|
|
|
566
601
|
winnabilityClassLabel,
|
|
567
602
|
withRetry,
|
|
568
603
|
withSkippedProviders
|
|
569
|
-
} from "./chunk-
|
|
604
|
+
} from "./chunk-OMXWBR2R.js";
|
|
570
605
|
|
|
571
606
|
// src/google-marketing-runtime.ts
|
|
572
607
|
import crypto2 from "crypto";
|
|
@@ -958,10 +993,10 @@ function findRequestId(value, depth = 0) {
|
|
|
958
993
|
}
|
|
959
994
|
return void 0;
|
|
960
995
|
}
|
|
961
|
-
const
|
|
962
|
-
const direct = safeRequestId(
|
|
996
|
+
const record = value;
|
|
997
|
+
const direct = safeRequestId(record.requestId) ?? safeRequestId(record.request_id);
|
|
963
998
|
if (direct) return direct;
|
|
964
|
-
for (const nested of Object.values(
|
|
999
|
+
for (const nested of Object.values(record)) {
|
|
965
1000
|
const found = findRequestId(nested, depth + 1);
|
|
966
1001
|
if (found) return found;
|
|
967
1002
|
}
|
|
@@ -3253,7 +3288,7 @@ import { createRequire } from "module";
|
|
|
3253
3288
|
import crypto26 from "crypto";
|
|
3254
3289
|
import fs5 from "fs";
|
|
3255
3290
|
import path5 from "path";
|
|
3256
|
-
import { isIP } from "net";
|
|
3291
|
+
import { isIP as isIP2 } from "net";
|
|
3257
3292
|
import { fileURLToPath } from "url";
|
|
3258
3293
|
import { setImmediate as yieldToEventLoop4 } from "timers/promises";
|
|
3259
3294
|
import { and as and25, eq as eq31, isNotNull as isNotNull5, isNull as isNull5, lte as lte2, max, ne as ne4, or as or3, sql as sql13 } from "drizzle-orm";
|
|
@@ -3263,11 +3298,9 @@ import { createHash } from "crypto";
|
|
|
3263
3298
|
|
|
3264
3299
|
// ../integration-typesafe/src/client.ts
|
|
3265
3300
|
var TYPESAFE_URL = "https://api.typesafe.ai/v1/systemone";
|
|
3266
|
-
|
|
3267
|
-
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
3268
|
-
}
|
|
3301
|
+
var JEV_MODEL = SENTIMENT_MODEL;
|
|
3269
3302
|
function usageFrom(value) {
|
|
3270
|
-
const usage =
|
|
3303
|
+
const usage = asRecord(asRecord(value)?.usage);
|
|
3271
3304
|
const input = usage?.input_tokens;
|
|
3272
3305
|
const output = usage?.output_tokens;
|
|
3273
3306
|
if (typeof input === "number" && Number.isSafeInteger(input) && input >= 0 && typeof output === "number" && Number.isSafeInteger(output) && output >= 0) {
|
|
@@ -3280,6 +3313,7 @@ function failure(code, message, retryable = false, retryAfterMs = null, usage =
|
|
|
3280
3313
|
}
|
|
3281
3314
|
async function fetchOnce2(request, options) {
|
|
3282
3315
|
if (options.signal?.aborted) return failure("canceled", "Classification was canceled before dispatch.");
|
|
3316
|
+
if (request.model !== JEV_MODEL) return failure("model-mismatch", "The direct TypeSafe evaluator requires its pinned model.");
|
|
3283
3317
|
if (!options.apiKey.trim()) return failure("credential-missing", "TypeSafe credentials are unavailable.");
|
|
3284
3318
|
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
3285
3319
|
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > 12e4) {
|
|
@@ -3315,12 +3349,12 @@ async function fetchOnce2(request, options) {
|
|
|
3315
3349
|
const code = response.status === 401 || response.status === 403 ? "provider-authorization" : response.status === 413 ? "provider-context-limit" : response.status === 429 ? "provider-rate-limit" : retryable ? "provider-unavailable" : "provider-rejected";
|
|
3316
3350
|
return failure(code, `TypeSafe returned HTTP ${response.status}.`, retryable, retryAfterDelayMs(statusError), usage);
|
|
3317
3351
|
}
|
|
3318
|
-
const parsed =
|
|
3352
|
+
const parsed = asRecord(body);
|
|
3319
3353
|
const model = typeof parsed?.model === "string" ? parsed.model : null;
|
|
3320
3354
|
if (model !== null && model !== request.model) {
|
|
3321
3355
|
return failure("model-mismatch", "TypeSafe returned a different evaluator model.", false, null, usage, model);
|
|
3322
3356
|
}
|
|
3323
|
-
const answers =
|
|
3357
|
+
const answers = asRecord(parsed?.answers);
|
|
3324
3358
|
if (!model || !answers || usage.kind !== "reported") {
|
|
3325
3359
|
return failure("response-contract", "TypeSafe returned an incomplete evaluation response.", false, null, usage, model);
|
|
3326
3360
|
}
|
|
@@ -3415,8 +3449,8 @@ function buildJevSentimentRequest(input) {
|
|
|
3415
3449
|
return { ok: true, request, estimate };
|
|
3416
3450
|
}
|
|
3417
3451
|
function parseChoice(value, question) {
|
|
3418
|
-
const answer =
|
|
3419
|
-
const probabilities =
|
|
3452
|
+
const answer = asRecord(value);
|
|
3453
|
+
const probabilities = asRecord(answer?.probabilities);
|
|
3420
3454
|
if (answer?.type !== "choice" || typeof answer.choice !== "string" || !Object.hasOwn(question.criteria, answer.choice) || !probabilities) return null;
|
|
3421
3455
|
const expected = Object.keys(question.criteria);
|
|
3422
3456
|
if (Object.keys(probabilities).length !== expected.length || expected.some((key) => typeof probabilities[key] !== "number" || !Number.isFinite(probabilities[key]) || probabilities[key] < 0 || probabilities[key] > 1)) return null;
|
|
@@ -3426,13 +3460,16 @@ function parseChoice(value, question) {
|
|
|
3426
3460
|
return { choice: answer.choice, confidence: typeof answer.confidence === "number" ? answer.confidence : null };
|
|
3427
3461
|
}
|
|
3428
3462
|
function createTypeSafeClassifier(options) {
|
|
3463
|
+
return createJevSentimentClassifier((request, signal) => requestJev(request, { ...options, signal }));
|
|
3464
|
+
}
|
|
3465
|
+
function createJevSentimentClassifier(dispatch) {
|
|
3429
3466
|
return { async classify(rawInput, callOptions) {
|
|
3430
3467
|
const valid = sentimentClassifierInputSchema.safeParse(rawInput);
|
|
3431
3468
|
if (!valid.success) return { kind: "failed", outcome: SentimentOutcomes.failed, returnedModel: null, usage: UNKNOWN_USAGE, error: { code: "input-contract", message: "The classifier input does not match its frozen contract.", retryable: false, retryAfterMs: null } };
|
|
3432
3469
|
const input = valid.data;
|
|
3433
3470
|
const built = buildJevSentimentRequest(input);
|
|
3434
3471
|
if (!built.ok) return { kind: "abstained", outcome: built.outcome, reason: built.reason, returnedModel: null, usage: UNKNOWN_USAGE };
|
|
3435
|
-
const response = await
|
|
3472
|
+
const response = await dispatch(built.request, callOptions?.signal);
|
|
3436
3473
|
if (!response.ok) return { kind: "failed", outcome: SentimentOutcomes.failed, returnedModel: response.returnedModel, usage: response.usage, error: response.error };
|
|
3437
3474
|
const parsed = Object.fromEntries(Object.entries(built.request.questions).map(([id, question]) => [id, parseChoice(response.answers[id], question)]));
|
|
3438
3475
|
const spans = new Map(input.sentences.map((span) => [span.id, span]));
|
|
@@ -3443,7 +3480,7 @@ function createTypeSafeClassifier(options) {
|
|
|
3443
3480
|
return span ? [{ ...span }] : null;
|
|
3444
3481
|
};
|
|
3445
3482
|
const abstain = (outcome, reason) => ({ kind: "abstained", outcome, reason, returnedModel: response.returnedModel, usage: response.usage });
|
|
3446
|
-
if (!parsed.identity || !parsed.judgment || !parsed.stance) return { kind: "failed", outcome: SentimentOutcomes.failed, returnedModel: response.returnedModel, usage: response.usage, error: { code: "response-contract", message: "
|
|
3483
|
+
if (!parsed.identity || !parsed.judgment || !parsed.stance) return { kind: "failed", outcome: SentimentOutcomes.failed, returnedModel: response.returnedModel, usage: response.usage, error: { code: "response-contract", message: "Jev returned a malformed headline decision.", retryable: false, retryAfterMs: null } };
|
|
3447
3484
|
if (parsed.identity.choice === "absent") return abstain(SentimentOutcomes["subject-not-mentioned"], "The known intended subject is not discussed in the answer.");
|
|
3448
3485
|
if (parsed.identity.choice === "wrong") return abstain(SentimentOutcomes["wrong-subject"], "The answer refers to another subject.");
|
|
3449
3486
|
if (parsed.identity.choice !== "correct") return abstain(SentimentOutcomes["ambiguous-subject"], "The intended subject cannot be resolved unambiguously.");
|
|
@@ -3466,6 +3503,70 @@ var SENTIMENT_CHALLENGE_GATES = {
|
|
|
3466
3503
|
"caveated-favorable": { outcome: SentimentOutcomes.favorable, target: 0.9 }
|
|
3467
3504
|
};
|
|
3468
3505
|
|
|
3506
|
+
// src/sentiment-openrouter.ts
|
|
3507
|
+
var OPENROUTER_SYSTEM_ONE_URL = "https://openrouter.ai/api/v1/systemone";
|
|
3508
|
+
var UNKNOWN_USAGE2 = { kind: "unknown", inputTokens: null, outputTokens: null };
|
|
3509
|
+
function createConfiguredSentimentClassifier(configuration, registry, reload) {
|
|
3510
|
+
if (configuration.provider !== "openrouter") return createTypeSafeClassifier({ apiKey: configuration.apiKey });
|
|
3511
|
+
return createJevSentimentClassifier(async (request, signal) => {
|
|
3512
|
+
const failure2 = (code, retryable = false, usage = UNKNOWN_USAGE2, returnedModel = null, retryAfterMs = null) => ({
|
|
3513
|
+
ok: false,
|
|
3514
|
+
returnedModel,
|
|
3515
|
+
usage,
|
|
3516
|
+
error: { code, message: "The OpenRouter sentiment evaluator did not return a usable pinned result.", retryable, retryAfterMs }
|
|
3517
|
+
});
|
|
3518
|
+
if (request.model !== SENTIMENT_OPENROUTER_MODEL) return failure2("model-mismatch");
|
|
3519
|
+
const model = aeroModels.getModelOfType("classifier", "openrouter", SENTIMENT_OPENROUTER_MODEL);
|
|
3520
|
+
if (!model) return failure2("unsupported-model");
|
|
3521
|
+
const quota = registry?.get("openrouter")?.config.quotaPolicy;
|
|
3522
|
+
const gate = getSharedProviderExecutionGate("openrouter", quota?.maxConcurrency ?? configuration.maxConcurrency, quota?.maxRequestsPerMinute ?? configuration.maxRequestsPerMinute);
|
|
3523
|
+
return gate.run(async () => {
|
|
3524
|
+
const active = reload?.() ?? configuration;
|
|
3525
|
+
const readiness = sentimentInstallReadiness(active);
|
|
3526
|
+
if (!readiness.ready) return failure2(readiness.reason ?? "invalid-config", true);
|
|
3527
|
+
if (active.provider !== configuration.provider || active.model !== request.model) return failure2("evaluator-route-changed", true);
|
|
3528
|
+
const observed = { body: null };
|
|
3529
|
+
const observedFetch = async (url, init) => {
|
|
3530
|
+
const endpoint = typeof url === "string" ? url : url instanceof URL ? url.href : url.url;
|
|
3531
|
+
if (endpoint !== OPENROUTER_SYSTEM_ONE_URL) throw new Error("Unsupported sentiment transport endpoint.");
|
|
3532
|
+
const response = await fetch(OPENROUTER_SYSTEM_ONE_URL, { ...init, redirect: "error" });
|
|
3533
|
+
observed.status = response.status;
|
|
3534
|
+
observed.retryAfter = response.headers.get("retry-after") ?? void 0;
|
|
3535
|
+
try {
|
|
3536
|
+
observed.body = asRecord(await response.clone().json());
|
|
3537
|
+
} catch {
|
|
3538
|
+
observed.body = null;
|
|
3539
|
+
}
|
|
3540
|
+
return response;
|
|
3541
|
+
};
|
|
3542
|
+
const result = await aeroModels.classify(model, { state: request.state, questions: request.questions }, {
|
|
3543
|
+
apiKey: active.apiKey,
|
|
3544
|
+
signal,
|
|
3545
|
+
maxRetries: 0,
|
|
3546
|
+
timeoutMs: 3e4,
|
|
3547
|
+
headers: { "User-Agent": "canonry" },
|
|
3548
|
+
fetch: observedFetch
|
|
3549
|
+
});
|
|
3550
|
+
const responseBody = observed.body;
|
|
3551
|
+
const returnedModel = typeof responseBody?.model === "string" ? responseBody.model : null;
|
|
3552
|
+
const counts = asRecord(responseBody?.usage);
|
|
3553
|
+
const input = counts?.input_tokens;
|
|
3554
|
+
const output = counts?.output_tokens;
|
|
3555
|
+
const usage = typeof input === "number" && Number.isSafeInteger(input) && input >= 0 && typeof output === "number" && Number.isSafeInteger(output) && output >= 0 ? { kind: "reported", inputTokens: input, outputTokens: output } : UNKNOWN_USAGE2;
|
|
3556
|
+
if (result.stopReason !== "stop") {
|
|
3557
|
+
if (signal?.aborted) return failure2("canceled", false, usage, returnedModel);
|
|
3558
|
+
const { status, retryAfter } = observed;
|
|
3559
|
+
const httpError = { status, retryAfter };
|
|
3560
|
+
const code = status === 401 || status === 403 ? "provider-authorization" : status === 413 ? "provider-context-limit" : status === 429 ? "provider-rate-limit" : status && status >= 400 ? isRetryableHttpError(httpError) ? "provider-unavailable" : "provider-rejected" : status ? "response-contract" : "provider-network";
|
|
3561
|
+
return failure2(code, isRetryableHttpError(httpError), usage, returnedModel, retryAfterDelayMs(httpError));
|
|
3562
|
+
}
|
|
3563
|
+
if (returnedModel !== SENTIMENT_OPENROUTER_SERVED_MODEL) return failure2("model-mismatch", false, usage, returnedModel);
|
|
3564
|
+
if (usage.kind !== "reported") return failure2("response-contract", false, usage, returnedModel);
|
|
3565
|
+
return { ok: true, returnedModel, usage, answers: result.answers };
|
|
3566
|
+
}, signal).catch(() => signal?.aborted ? failure2(signal.reason instanceof DOMException && signal.reason.name === "TimeoutError" ? "provider-timeout" : "canceled", signal.reason instanceof DOMException && signal.reason.name === "TimeoutError") : failure2("provider-network", true));
|
|
3567
|
+
});
|
|
3568
|
+
}
|
|
3569
|
+
|
|
3469
3570
|
// src/sentiment-worker.ts
|
|
3470
3571
|
import { createHash as createHash3, randomUUID } from "crypto";
|
|
3471
3572
|
import { and, asc, eq, gt } from "drizzle-orm";
|
|
@@ -3523,7 +3624,7 @@ var SentimentWorker = class {
|
|
|
3523
3624
|
service() {
|
|
3524
3625
|
return new SentimentService(this.db, { install: () => {
|
|
3525
3626
|
const config = this.options.configuration();
|
|
3526
|
-
return { ...sentimentInstallReadiness(config), model: config.model };
|
|
3627
|
+
return { ...sentimentInstallReadiness(config), model: config.model, provider: config.provider };
|
|
3527
3628
|
}, previewSecret: this.owner, now: this.options.now });
|
|
3528
3629
|
}
|
|
3529
3630
|
/** The completion callback is merely a wakeup; receipts make a missed callback recoverable. */
|
|
@@ -3538,7 +3639,7 @@ var SentimentWorker = class {
|
|
|
3538
3639
|
const receipts = this.db.select().from(sentimentCompletionReceipts).where(and(eq(sentimentCompletionReceipts.projectId, settings.projectId), gt(sentimentCompletionReceipts.sequence, start))).orderBy(asc(sentimentCompletionReceipts.sequence)).all();
|
|
3539
3640
|
if (!receipts.length) continue;
|
|
3540
3641
|
const definition = service.definition(settings.evaluationDefinitionId);
|
|
3541
|
-
if (!hasCurrentSentimentTemplate(definition)) continue;
|
|
3642
|
+
if (!hasCurrentSentimentTemplate(definition) || sentimentEvaluatorProvider(definition) !== configuration.provider || definition.requestedModel !== configuration.model) continue;
|
|
3542
3643
|
let reconciled = start;
|
|
3543
3644
|
try {
|
|
3544
3645
|
for (const receipt of receipts) {
|
|
@@ -3640,6 +3741,11 @@ var SentimentWorker = class {
|
|
|
3640
3741
|
report({ status: OutcomeStatuses.skipped, reasonCode: OutcomeReasonCodes.NOT_CONNECTED });
|
|
3641
3742
|
return;
|
|
3642
3743
|
}
|
|
3744
|
+
if (sentimentEvaluatorProvider(input.definition) !== config.provider || input.definition.requestedModel !== config.model) {
|
|
3745
|
+
this.repository.failWork({ workItemId: work.id, owner, now: this.now(), errorCode: "EVALUATOR_ROUTE_CHANGED", retryAt: new Date(Date.parse(this.now()) + 6e4).toISOString() });
|
|
3746
|
+
report({ status: OutcomeStatuses.skipped, reasonCode: OutcomeReasonCodes.NOT_CONNECTED });
|
|
3747
|
+
return;
|
|
3748
|
+
}
|
|
3643
3749
|
const settings = this.repository.getSettings(work.projectId);
|
|
3644
3750
|
if (!settings?.enabled || settings.enablementEpoch !== work.enablementEpoch) {
|
|
3645
3751
|
this.repository.cancelProject(work.projectId, this.now());
|
|
@@ -3677,8 +3783,9 @@ var SentimentWorker = class {
|
|
|
3677
3783
|
result = { kind: "failed", outcome: "failed", returnedModel: null, usage: { kind: "unknown", inputTokens: null, outputTokens: null }, error: { code: "CLASSIFIER_TRANSPORT_ERROR", message: "The classifier attempt did not return a usable response.", retryable: true, retryAfterMs: null } };
|
|
3678
3784
|
}
|
|
3679
3785
|
const now = this.now();
|
|
3680
|
-
const
|
|
3681
|
-
|
|
3786
|
+
const evaluatorProvider = sentimentEvaluatorProvider(input.definition);
|
|
3787
|
+
const usage = result.usage.inputTokens !== null && result.usage.outputTokens !== null ? { inputTokens: result.usage.inputTokens, outputTokens: result.usage.outputTokens, ...evaluatorProvider === "typesafe" ? { costMillicents: Math.round(result.usage.inputTokens * 42e-4) } : {} } : void 0;
|
|
3788
|
+
this.repository.finishAttempt({ attemptId: attempt.id, now, provider: evaluatorProvider, returnedModel: result.returnedModel, usageStatus: result.usage.kind, usage, safeFailure: result.kind === "failed" ? result.error.code : null });
|
|
3682
3789
|
const counts = { attempts: attempt.attemptNumber, ...usage ? { inputTokens: usage.inputTokens, outputTokens: usage.outputTokens } : {} };
|
|
3683
3790
|
if (result.kind === "failed") {
|
|
3684
3791
|
const failure2 = transportError ? outcomeFailure(transportError.error) : { reasonCode: CLASSIFIER_FAILURE_REASONS[result.error.code] ?? OutcomeReasonCodes.UNKNOWN };
|
|
@@ -3745,7 +3852,9 @@ function loadSentimentInstallConfig() {
|
|
|
3745
3852
|
const document = parse(fs.readFileSync(getConfigPath(), "utf8"));
|
|
3746
3853
|
const sentiment = isRecord(document) ? document.sentiment : void 0;
|
|
3747
3854
|
if (!isRecord(document) || sentiment != null && !isRecord(sentiment)) return invalidSentimentInstallConfig();
|
|
3748
|
-
|
|
3855
|
+
const providers = isRecord(document.providers) ? document.providers : void 0;
|
|
3856
|
+
const openrouter = providers && isRecord(providers.openrouter) ? providers.openrouter.apiKey : void 0;
|
|
3857
|
+
return resolveSentimentInstallConfig(process.env, sentiment ?? void 0, { openrouter: typeof openrouter === "string" ? openrouter : void 0 });
|
|
3749
3858
|
} catch {
|
|
3750
3859
|
return invalidSentimentInstallConfig();
|
|
3751
3860
|
}
|
|
@@ -4963,7 +5072,7 @@ var UI_EVENT_HOUR_CAPACITY = 600;
|
|
|
4963
5072
|
function createUiTelemetryGate(options = {}) {
|
|
4964
5073
|
const now = options.now ?? Date.now;
|
|
4965
5074
|
const enabled = options.enabled ?? isTelemetryEnabled;
|
|
4966
|
-
const
|
|
5075
|
+
const record = options.record ?? recordDashboardEvent;
|
|
4967
5076
|
const buckets = [
|
|
4968
5077
|
{ capacity: UI_EVENT_MINUTE_CAPACITY, perMs: UI_EVENT_MINUTE_CAPACITY / 6e4, tokens: UI_EVENT_MINUTE_CAPACITY },
|
|
4969
5078
|
{ capacity: UI_EVENT_HOUR_CAPACITY, perMs: UI_EVENT_HOUR_CAPACITY / 36e5, tokens: UI_EVENT_HOUR_CAPACITY }
|
|
@@ -4977,7 +5086,7 @@ function createUiTelemetryGate(options = {}) {
|
|
|
4977
5086
|
for (const bucket of buckets) bucket.tokens = Math.min(bucket.capacity, bucket.tokens + elapsed * bucket.perMs);
|
|
4978
5087
|
if (buckets.some((bucket) => bucket.tokens < 1)) return false;
|
|
4979
5088
|
for (const bucket of buckets) bucket.tokens -= 1;
|
|
4980
|
-
|
|
5089
|
+
record(event);
|
|
4981
5090
|
return true;
|
|
4982
5091
|
};
|
|
4983
5092
|
}
|
|
@@ -4988,7 +5097,7 @@ function nonBlank(value) {
|
|
|
4988
5097
|
return trimmed ? trimmed : void 0;
|
|
4989
5098
|
}
|
|
4990
5099
|
function resolveBuildCommit(env = process.env) {
|
|
4991
|
-
const embedded = true ? "
|
|
5100
|
+
const embedded = true ? "8a7aeb563a46919b478a60a2e42295365042c4db" : void 0;
|
|
4992
5101
|
return nonBlank(embedded) ?? nonBlank(env.CANONRY_COMMIT);
|
|
4993
5102
|
}
|
|
4994
5103
|
function resolveInstanceIdentity(env = process.env) {
|
|
@@ -5008,6 +5117,12 @@ import { and as and3, asc as asc2, count, desc, eq as eq3, inArray, isNotNull, i
|
|
|
5008
5117
|
|
|
5009
5118
|
// src/run-telemetry.ts
|
|
5010
5119
|
import crypto4 from "crypto";
|
|
5120
|
+
function telemetryConnectionName(name) {
|
|
5121
|
+
const connection = providerConnectionName(name);
|
|
5122
|
+
if (connection !== name || isBrowserProvider(name)) return connection;
|
|
5123
|
+
const separator = name.indexOf(":");
|
|
5124
|
+
return separator > 0 ? name.slice(0, separator) : name;
|
|
5125
|
+
}
|
|
5011
5126
|
function extractRegistrableHost(input) {
|
|
5012
5127
|
if (!input) return null;
|
|
5013
5128
|
const trimmed = input.trim();
|
|
@@ -5035,7 +5150,7 @@ function buildRunCompletedProps(input) {
|
|
|
5035
5150
|
const props = {
|
|
5036
5151
|
status: input.status,
|
|
5037
5152
|
providerCount: input.providerCount,
|
|
5038
|
-
providers: [...input.providers],
|
|
5153
|
+
providers: [...new Set(input.providers.map(telemetryConnectionName))],
|
|
5039
5154
|
queryCount: input.queryCount,
|
|
5040
5155
|
durationMs: totalMs
|
|
5041
5156
|
};
|
|
@@ -5048,7 +5163,7 @@ function buildRunCompletedProps(input) {
|
|
|
5048
5163
|
return props;
|
|
5049
5164
|
}
|
|
5050
5165
|
function runUsageProps(answers) {
|
|
5051
|
-
const counted = answers.filter((answer) => KNOWN_PROVIDERS.has(answer.provider));
|
|
5166
|
+
const counted = answers.map((answer) => ({ ...answer, provider: telemetryConnectionName(answer.provider) })).filter((answer) => KNOWN_PROVIDERS.has(answer.provider));
|
|
5052
5167
|
if (counted.length === 0) return {};
|
|
5053
5168
|
const providerCalls = {};
|
|
5054
5169
|
for (const answer of [...counted].sort((left, right) => compareText(left.provider, right.provider))) {
|
|
@@ -5068,9 +5183,17 @@ function runUsageProps(answers) {
|
|
|
5068
5183
|
return { providerCalls, usage };
|
|
5069
5184
|
}
|
|
5070
5185
|
function providerLatencyProps(latencies) {
|
|
5186
|
+
const byConnection = /* @__PURE__ */ new Map();
|
|
5187
|
+
for (const [provider, values] of latencies ?? []) {
|
|
5188
|
+
const connection = telemetryConnectionName(provider);
|
|
5189
|
+
if (!KNOWN_PROVIDERS.has(connection)) continue;
|
|
5190
|
+
const samples = byConnection.get(connection) ?? [];
|
|
5191
|
+
samples.push(...values);
|
|
5192
|
+
byConnection.set(connection, samples);
|
|
5193
|
+
}
|
|
5071
5194
|
const providerLatencyMs = {};
|
|
5072
|
-
for (const [provider, values] of [...
|
|
5073
|
-
const middle =
|
|
5195
|
+
for (const [provider, values] of [...byConnection].sort(([left], [right]) => compareText(left, right))) {
|
|
5196
|
+
const middle = median(values);
|
|
5074
5197
|
if (middle !== null) providerLatencyMs[provider] = Math.max(0, Math.round(middle));
|
|
5075
5198
|
}
|
|
5076
5199
|
return Object.keys(providerLatencyMs).length > 0 ? { providerLatencyMs } : {};
|
|
@@ -5103,32 +5226,42 @@ var MAX_NESTED_KEYS = 12;
|
|
|
5103
5226
|
function buildProviderOutcomeProps(providers, providerErrors, skippedProviders = []) {
|
|
5104
5227
|
if (providerErrors.size === 0 && skippedProviders.length === 0) return {};
|
|
5105
5228
|
const skipped = new Set(skippedProviders);
|
|
5106
|
-
const
|
|
5229
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
5230
|
+
for (const provider of /* @__PURE__ */ new Set([...providers, ...providerErrors.keys(), ...skipped])) {
|
|
5231
|
+
const name = telemetryConnectionName(provider);
|
|
5232
|
+
grouped.set(name, [...grouped.get(name) ?? [], provider]);
|
|
5233
|
+
}
|
|
5107
5234
|
const providerOutcomes = {};
|
|
5108
5235
|
const providerHttpStatus = {};
|
|
5109
|
-
for (const name of
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
}
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
providerOutcomes[name] = "ok";
|
|
5236
|
+
for (const [name, routes] of [...grouped].slice(0, MAX_NESTED_KEYS)) {
|
|
5237
|
+
const failures = routes.flatMap((route) => {
|
|
5238
|
+
const message2 = providerErrors.get(route);
|
|
5239
|
+
return !skipped.has(route) && message2 !== void 0 ? [{ message: message2, code: classifyProviderErrorMessage(message2) }] : [];
|
|
5240
|
+
});
|
|
5241
|
+
if (failures.length === 0) {
|
|
5242
|
+
providerOutcomes[name] = routes.every((route) => skipped.has(route)) ? "skipped" : "ok";
|
|
5117
5243
|
continue;
|
|
5118
5244
|
}
|
|
5119
|
-
|
|
5245
|
+
const code = mostActionableProviderErrorCode(failures.map((failure2) => failure2.code));
|
|
5246
|
+
const message = failures.find((failure2) => failure2.code === code).message;
|
|
5247
|
+
providerOutcomes[name] = code;
|
|
5120
5248
|
const status = extractProviderHttpStatus(message);
|
|
5121
5249
|
if (status !== void 0) providerHttpStatus[name] = status;
|
|
5122
5250
|
}
|
|
5123
5251
|
return Object.keys(providerHttpStatus).length > 0 ? { providerOutcomes, providerHttpStatus } : { providerOutcomes };
|
|
5124
5252
|
}
|
|
5125
5253
|
function buildRunRefusedProps(input) {
|
|
5126
|
-
const outcomes =
|
|
5254
|
+
const outcomes = /* @__PURE__ */ new Map();
|
|
5255
|
+
for (const [provider, code] of Object.entries(input.providers)) {
|
|
5256
|
+
const name = telemetryConnectionName(provider);
|
|
5257
|
+
const previous = outcomes.get(name);
|
|
5258
|
+
outcomes.set(name, previous === void 0 ? code : mostActionableProviderErrorCode([previous, code]));
|
|
5259
|
+
}
|
|
5127
5260
|
const props = {
|
|
5128
5261
|
reason: "providers_failing",
|
|
5129
5262
|
providerCount: Object.keys(input.providers).length,
|
|
5130
|
-
providers:
|
|
5131
|
-
providerOutcomes: Object.fromEntries(outcomes),
|
|
5263
|
+
providers: [...outcomes.keys()],
|
|
5264
|
+
providerOutcomes: Object.fromEntries([...outcomes].slice(0, MAX_NESTED_KEYS)),
|
|
5132
5265
|
trigger: input.trigger
|
|
5133
5266
|
};
|
|
5134
5267
|
const domainHash = hashDomain(input.canonicalDomain ?? null);
|
|
@@ -5164,83 +5297,6 @@ function failureStreakSampling(status, priorStreak, runId) {
|
|
|
5164
5297
|
};
|
|
5165
5298
|
}
|
|
5166
5299
|
|
|
5167
|
-
// src/provider-execution-gate.ts
|
|
5168
|
-
var ProviderExecutionGate = class {
|
|
5169
|
-
constructor(maxConcurrency, maxPerMinute) {
|
|
5170
|
-
this.maxConcurrency = maxConcurrency;
|
|
5171
|
-
this.maxPerMinute = maxPerMinute;
|
|
5172
|
-
}
|
|
5173
|
-
maxConcurrency;
|
|
5174
|
-
maxPerMinute;
|
|
5175
|
-
window = [];
|
|
5176
|
-
waiters = [];
|
|
5177
|
-
rateTimer;
|
|
5178
|
-
dispatching = false;
|
|
5179
|
-
inFlight = 0;
|
|
5180
|
-
updatePolicy(maxConcurrency, maxPerMinute) {
|
|
5181
|
-
this.maxConcurrency = maxConcurrency;
|
|
5182
|
-
this.maxPerMinute = maxPerMinute;
|
|
5183
|
-
this.dispatchQueued();
|
|
5184
|
-
}
|
|
5185
|
-
async run(task) {
|
|
5186
|
-
return new Promise((resolve, reject) => {
|
|
5187
|
-
this.waiters.push(() => {
|
|
5188
|
-
void this.execute(task, resolve, reject);
|
|
5189
|
-
});
|
|
5190
|
-
this.dispatchQueued();
|
|
5191
|
-
});
|
|
5192
|
-
}
|
|
5193
|
-
async execute(task, resolve, reject) {
|
|
5194
|
-
try {
|
|
5195
|
-
resolve(await task());
|
|
5196
|
-
} catch (error) {
|
|
5197
|
-
reject(error);
|
|
5198
|
-
} finally {
|
|
5199
|
-
this.inFlight--;
|
|
5200
|
-
this.dispatchQueued();
|
|
5201
|
-
}
|
|
5202
|
-
}
|
|
5203
|
-
dispatchQueued() {
|
|
5204
|
-
if (this.dispatching) return;
|
|
5205
|
-
if (this.rateTimer !== void 0) {
|
|
5206
|
-
clearTimeout(this.rateTimer);
|
|
5207
|
-
this.rateTimer = void 0;
|
|
5208
|
-
}
|
|
5209
|
-
this.dispatching = true;
|
|
5210
|
-
try {
|
|
5211
|
-
while (this.waiters.length > 0 && this.inFlight < Math.max(1, this.maxConcurrency)) {
|
|
5212
|
-
const now = Date.now();
|
|
5213
|
-
const windowStart = now - 6e4;
|
|
5214
|
-
while (this.window.length > 0 && this.window[0] < windowStart) this.window.shift();
|
|
5215
|
-
if (this.window.length >= this.maxPerMinute) break;
|
|
5216
|
-
this.window.push(now);
|
|
5217
|
-
this.inFlight++;
|
|
5218
|
-
this.waiters.shift()();
|
|
5219
|
-
}
|
|
5220
|
-
} finally {
|
|
5221
|
-
this.dispatching = false;
|
|
5222
|
-
}
|
|
5223
|
-
if (this.waiters.length > 0 && this.inFlight < Math.max(1, this.maxConcurrency)) {
|
|
5224
|
-
this.rateTimer = setTimeout(() => {
|
|
5225
|
-
this.rateTimer = void 0;
|
|
5226
|
-
this.dispatchQueued();
|
|
5227
|
-
}, this.window[0] + 6e4 - Date.now() + 50);
|
|
5228
|
-
}
|
|
5229
|
-
}
|
|
5230
|
-
};
|
|
5231
|
-
var sharedGates = /* @__PURE__ */ new Map();
|
|
5232
|
-
function getSharedProviderExecutionGate(providerName, maxConcurrency, maxPerMinute) {
|
|
5233
|
-
const key = providerName.trim().toLocaleLowerCase("en");
|
|
5234
|
-
const existing = sharedGates.get(key);
|
|
5235
|
-
if (existing) return existing;
|
|
5236
|
-
const gate = new ProviderExecutionGate(maxConcurrency, maxPerMinute);
|
|
5237
|
-
sharedGates.set(key, gate);
|
|
5238
|
-
return gate;
|
|
5239
|
-
}
|
|
5240
|
-
function updateSharedProviderExecutionGate(providerName, maxConcurrency, maxPerMinute) {
|
|
5241
|
-
getSharedProviderExecutionGate(providerName, maxConcurrency, maxPerMinute).updatePolicy(maxConcurrency, maxPerMinute);
|
|
5242
|
-
}
|
|
5243
|
-
|
|
5244
5300
|
// src/usage-quota.ts
|
|
5245
5301
|
import crypto5 from "crypto";
|
|
5246
5302
|
import { and as and2, eq as eq2, lte, sql } from "drizzle-orm";
|
|
@@ -5283,7 +5339,7 @@ var RESOLUTION_TIMEOUT_MS = 5e3;
|
|
|
5283
5339
|
var MAX_VERTEX_PROXY_HOPS = 3;
|
|
5284
5340
|
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
5285
5341
|
function isRouteCapableProvider(provider) {
|
|
5286
|
-
return ROUTE_CAPABLE_CITED_URL_PROVIDERS.includes(provider);
|
|
5342
|
+
return isOpenRouterRoute(provider) || ROUTE_CAPABLE_CITED_URL_PROVIDERS.includes(provider);
|
|
5287
5343
|
}
|
|
5288
5344
|
function parseHttpUrl(value, base) {
|
|
5289
5345
|
try {
|
|
@@ -5324,7 +5380,7 @@ async function resolveVertexGroundingRedirect(value, opts = {}) {
|
|
|
5324
5380
|
}
|
|
5325
5381
|
async function captureCitedUrls(provider, sources, opts = {}) {
|
|
5326
5382
|
const sourceCount = sources.length;
|
|
5327
|
-
if (!isRouteCapableProvider(provider)) {
|
|
5383
|
+
if (!(opts.directCitedSources ?? isRouteCapableProvider(provider))) {
|
|
5328
5384
|
return {
|
|
5329
5385
|
citedUrls: null,
|
|
5330
5386
|
captureStatus: "unsupported",
|
|
@@ -5400,6 +5456,10 @@ function planlessDispatchColumns(registeredProvider, raw) {
|
|
|
5400
5456
|
})
|
|
5401
5457
|
};
|
|
5402
5458
|
}
|
|
5459
|
+
function isRequestedLocationUnapplied(providerName, raw, retrievalStatus) {
|
|
5460
|
+
if (raw.evidence) return raw.evidence.location.status !== LocationTreatmentStatuses.applied;
|
|
5461
|
+
return isOpenRouterRoute(providerName) || isSearchLocationIgnored(providerName, retrievalStatus);
|
|
5462
|
+
}
|
|
5403
5463
|
var HOUR_MS = 60 * 60 * 1e3;
|
|
5404
5464
|
var RUN_HOLDING_BATCH_STATUSES = [
|
|
5405
5465
|
ProviderBatchStatuses.submitting,
|
|
@@ -5511,8 +5571,7 @@ function resolvePlanExecution(run, projectQueries) {
|
|
|
5511
5571
|
return {
|
|
5512
5572
|
manifest,
|
|
5513
5573
|
unitsByProvider,
|
|
5514
|
-
nodeCount: nodes.size
|
|
5515
|
-
maxUnitsPerProvider: Math.max(0, ...[...unitsByProvider.values()].map((units) => units.length))
|
|
5574
|
+
nodeCount: nodes.size
|
|
5516
5575
|
};
|
|
5517
5576
|
}
|
|
5518
5577
|
function resolveProviderFanout() {
|
|
@@ -5700,6 +5759,7 @@ var JobRunner = class {
|
|
|
5700
5759
|
let activeProviders = [];
|
|
5701
5760
|
let projectQueries = [];
|
|
5702
5761
|
let planExecution = null;
|
|
5762
|
+
const planIneligibleProviders = /* @__PURE__ */ new Set();
|
|
5703
5763
|
let runTrigger;
|
|
5704
5764
|
let canonicalDomain;
|
|
5705
5765
|
let recording;
|
|
@@ -5760,7 +5820,11 @@ var JobRunner = class {
|
|
|
5760
5820
|
if (planExecution) {
|
|
5761
5821
|
const plan = planExecution;
|
|
5762
5822
|
const manifestProviders = [...plan.unitsByProvider.keys()];
|
|
5763
|
-
|
|
5823
|
+
const registered = manifestProviders.map((name) => this.registry.get(name)).filter((entry) => entry !== void 0);
|
|
5824
|
+
activeProviders = registered.filter((entry) => isEligibleFor(entry.adapter, ProviderWorkflows["visibility-sweep"], "explicit"));
|
|
5825
|
+
for (const entry of registered) {
|
|
5826
|
+
if (!activeProviders.includes(entry)) planIneligibleProviders.add(entry.adapter.name);
|
|
5827
|
+
}
|
|
5764
5828
|
} else {
|
|
5765
5829
|
const projectProviders = providerOverride ?? project.providers;
|
|
5766
5830
|
activeProviders = this.registry.getForProject(projectProviders).map((entry) => {
|
|
@@ -5799,10 +5863,10 @@ var JobRunner = class {
|
|
|
5799
5863
|
...runTrigger ? { trigger: runTrigger } : {},
|
|
5800
5864
|
...canonicalDomain ? { canonicalDomain } : {}
|
|
5801
5865
|
};
|
|
5802
|
-
const queriesPerProvider = planExecution?.maxUnitsPerProvider ?? projectQueries.length;
|
|
5803
5866
|
const todayPeriod = getCurrentUsageDay();
|
|
5804
5867
|
for (const p of calledProviders) {
|
|
5805
|
-
const
|
|
5868
|
+
const queriesPerProvider = planExecution ? planExecution.unitsByProvider.get(p.adapter.name)?.length ?? 0 : projectQueries.length;
|
|
5869
|
+
const providerScope = `${projectId}:${adapterConnectionName(p.adapter)}`;
|
|
5806
5870
|
const limit = p.config.quotaPolicy.maxRequestsPerDay;
|
|
5807
5871
|
const quota = reserveDailyQueryQuota(this.db, { scope: providerScope, period: todayPeriod, count: queriesPerProvider, limit });
|
|
5808
5872
|
if (!quota.reserved) {
|
|
@@ -5817,7 +5881,7 @@ var JobRunner = class {
|
|
|
5817
5881
|
executionGates.set(
|
|
5818
5882
|
provider.adapter.name,
|
|
5819
5883
|
getSharedProviderExecutionGate(
|
|
5820
|
-
provider.adapter
|
|
5884
|
+
adapterConnectionName(provider.adapter),
|
|
5821
5885
|
provider.config.quotaPolicy.maxConcurrency,
|
|
5822
5886
|
provider.config.quotaPolicy.maxRequestsPerMinute
|
|
5823
5887
|
)
|
|
@@ -5870,7 +5934,7 @@ var JobRunner = class {
|
|
|
5870
5934
|
};
|
|
5871
5935
|
let citedUrlCapture;
|
|
5872
5936
|
try {
|
|
5873
|
-
citedUrlCapture = await captureCitedUrls(providerName, rawGroundingSources);
|
|
5937
|
+
citedUrlCapture = await captureCitedUrls(providerName, rawGroundingSources, raw.evidence ? { directCitedSources: hasDirectCitedUrls(raw.evidence) } : {});
|
|
5874
5938
|
} catch (err) {
|
|
5875
5939
|
citedUrlCapture = {
|
|
5876
5940
|
citedUrls: [],
|
|
@@ -5903,7 +5967,7 @@ var JobRunner = class {
|
|
|
5903
5967
|
allBrandNames,
|
|
5904
5968
|
competitorAliases
|
|
5905
5969
|
);
|
|
5906
|
-
const answerLocation = runLocation &&
|
|
5970
|
+
const answerLocation = runLocation && isRequestedLocationUnapplied(providerName, raw, normalized.retrievalStatus) ? { location: null, requestedContext: runLocation, supportedContext: { status: "ignored" } } : { location: runLocation?.label ?? null };
|
|
5907
5971
|
let screenshotRelPath = null;
|
|
5908
5972
|
if (raw.screenshotPath && fs3.existsSync(raw.screenshotPath)) {
|
|
5909
5973
|
const snapshotId = crypto6.randomUUID();
|
|
@@ -5947,6 +6011,7 @@ var JobRunner = class {
|
|
|
5947
6011
|
apiResponse: raw.rawResponse
|
|
5948
6012
|
}),
|
|
5949
6013
|
...planlessDispatchColumns(registeredProvider, raw),
|
|
6014
|
+
answerEvidence: raw.evidence ?? null,
|
|
5950
6015
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5951
6016
|
}).run();
|
|
5952
6017
|
} else {
|
|
@@ -5984,6 +6049,7 @@ var JobRunner = class {
|
|
|
5984
6049
|
apiResponse: raw.rawResponse
|
|
5985
6050
|
}),
|
|
5986
6051
|
...planlessDispatchColumns(registeredProvider, raw),
|
|
6052
|
+
answerEvidence: raw.evidence ?? null,
|
|
5987
6053
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5988
6054
|
}).run();
|
|
5989
6055
|
}
|
|
@@ -6113,7 +6179,7 @@ var JobRunner = class {
|
|
|
6113
6179
|
if (dispatched >= units.length || providerErrors.has(providerName) || providerName in skipped) continue;
|
|
6114
6180
|
providerErrors.set(
|
|
6115
6181
|
providerName,
|
|
6116
|
-
`No ${provider} provider was available to this worker, so ${units.length - dispatched} expected measurement(s) did not run.`
|
|
6182
|
+
planIneligibleProviders.has(providerName) ? `${provider} does not run visibility sweeps, so ${units.length - dispatched} expected measurement(s) did not run.` : `No ${provider} provider was available to this worker, so ${units.length - dispatched} expected measurement(s) did not run.`
|
|
6117
6183
|
);
|
|
6118
6184
|
}
|
|
6119
6185
|
}
|
|
@@ -6176,7 +6242,7 @@ var JobRunner = class {
|
|
|
6176
6242
|
trackEvent("run.aborted", {
|
|
6177
6243
|
reason: abortReason2,
|
|
6178
6244
|
providerCount: executionContext.providerCount,
|
|
6179
|
-
providers: executionContext.providers,
|
|
6245
|
+
providers: [...new Set(executionContext.providers.map(telemetryConnectionName))],
|
|
6180
6246
|
queryCount: executionContext.queryCount,
|
|
6181
6247
|
durationMs: Date.now() - startTime,
|
|
6182
6248
|
...executionContext.trigger ? { trigger: executionContext.trigger } : {},
|
|
@@ -6998,15 +7064,16 @@ var JobRunner = class {
|
|
|
6998
7064
|
const activeProviders = [];
|
|
6999
7065
|
for (const provider of unitsByProvider.keys()) {
|
|
7000
7066
|
const registered = this.registry.get(provider);
|
|
7001
|
-
if (registered)
|
|
7002
|
-
else providerErrors.set(provider,
|
|
7067
|
+
if (!registered) providerErrors.set(provider, `No ${provider} provider is configured on this instance, so its missing answers did not run.`);
|
|
7068
|
+
else if (!isEligibleFor(registered.adapter, ProviderWorkflows["visibility-sweep"], "explicit")) providerErrors.set(provider, `${provider} does not run visibility sweeps, so its missing answers did not run.`);
|
|
7069
|
+
else activeProviders.push(registered);
|
|
7003
7070
|
}
|
|
7004
7071
|
const todayPeriod = getCurrentUsageDay();
|
|
7005
7072
|
const dispatchable = [];
|
|
7006
7073
|
for (const registered of activeProviders) {
|
|
7007
7074
|
const name = registered.adapter.name;
|
|
7008
7075
|
const count4 = unitsByProvider.get(name)?.length ?? 0;
|
|
7009
|
-
const scope = `${projectId}:${
|
|
7076
|
+
const scope = `${projectId}:${adapterConnectionName(registered.adapter)}`;
|
|
7010
7077
|
const limit = registered.config.quotaPolicy.maxRequestsPerDay;
|
|
7011
7078
|
const quota = reserveDailyQueryQuota(this.db, { scope, period: todayPeriod, count: count4, limit });
|
|
7012
7079
|
if (!quota.reserved) {
|
|
@@ -7021,7 +7088,7 @@ var JobRunner = class {
|
|
|
7021
7088
|
executionGates.set(
|
|
7022
7089
|
registered.adapter.name,
|
|
7023
7090
|
getSharedProviderExecutionGate(
|
|
7024
|
-
registered.adapter
|
|
7091
|
+
adapterConnectionName(registered.adapter),
|
|
7025
7092
|
registered.config.quotaPolicy.maxConcurrency,
|
|
7026
7093
|
registered.config.quotaPolicy.maxRequestsPerMinute
|
|
7027
7094
|
)
|
|
@@ -7214,7 +7281,7 @@ var JobRunner = class {
|
|
|
7214
7281
|
const providerName = adapter.name;
|
|
7215
7282
|
const { domains: competitorDomains, aliases: competitorAliases } = ctx.competitorsFor(unit.executionId);
|
|
7216
7283
|
const requestedContext = unit.context;
|
|
7217
|
-
const supportedContext = requestedContext && providerSupportsLocationContext(adapter) ? { status: "applied", resolved: requestedContext } : null;
|
|
7284
|
+
const supportedContext = requestedContext && raw.evidence ? raw.evidence.location.status === LocationTreatmentStatuses.applied ? { status: "applied", resolved: requestedContext } : { status: "ignored" } : requestedContext && providerSupportsLocationContext(adapter) ? { status: "applied", resolved: requestedContext } : requestedContext && isOpenRouterRoute(providerName) ? { status: "ignored" } : null;
|
|
7218
7285
|
this.throwIfRunCancelled(ctx.runId);
|
|
7219
7286
|
const providerResult = adapter.normalizeResult(raw);
|
|
7220
7287
|
const rawGroundingSources = providerResult.groundingSources;
|
|
@@ -7224,7 +7291,7 @@ var JobRunner = class {
|
|
|
7224
7291
|
};
|
|
7225
7292
|
let citedUrlCapture;
|
|
7226
7293
|
try {
|
|
7227
|
-
citedUrlCapture = await captureCitedUrls(providerName, rawGroundingSources);
|
|
7294
|
+
citedUrlCapture = await captureCitedUrls(providerName, rawGroundingSources, raw.evidence ? { directCitedSources: hasDirectCitedUrls(raw.evidence) } : {});
|
|
7228
7295
|
} catch (err) {
|
|
7229
7296
|
citedUrlCapture = {
|
|
7230
7297
|
citedUrls: [],
|
|
@@ -7318,6 +7385,7 @@ var JobRunner = class {
|
|
|
7318
7385
|
tier: dispatch.pricingTier,
|
|
7319
7386
|
overrides: registeredProvider.config.pricing
|
|
7320
7387
|
}),
|
|
7388
|
+
answerEvidence: raw.evidence ?? null,
|
|
7321
7389
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
7322
7390
|
};
|
|
7323
7391
|
return {
|
|
@@ -10427,8 +10495,10 @@ async function executeDiscoveryRun(opts) {
|
|
|
10427
10495
|
canonicalDomains,
|
|
10428
10496
|
competitorDomains: projectCompetitors
|
|
10429
10497
|
};
|
|
10498
|
+
const classifierConfig = opts.getClassifierConfig?.() ?? opts.classifierConfig;
|
|
10499
|
+
await refreshAgentModels(classifierConfig?.classification?.provider);
|
|
10430
10500
|
notConfigured = true;
|
|
10431
|
-
const deps = buildDefaultDeps(opts.registry);
|
|
10501
|
+
const deps = buildDefaultDeps(opts.registry, classifierConfig);
|
|
10432
10502
|
notConfigured = false;
|
|
10433
10503
|
const result = await executeDiscovery({
|
|
10434
10504
|
db: opts.db,
|
|
@@ -10484,7 +10554,7 @@ async function executeDiscoveryRun(opts) {
|
|
|
10484
10554
|
});
|
|
10485
10555
|
}
|
|
10486
10556
|
}
|
|
10487
|
-
function buildDefaultDeps(registry) {
|
|
10557
|
+
function buildDefaultDeps(registry, classifierConfig) {
|
|
10488
10558
|
const gemini = registry.get("gemini");
|
|
10489
10559
|
if (!gemini) {
|
|
10490
10560
|
throw new Error("Gemini provider is not configured. Add a Gemini API key (or Vertex project) before running discovery.");
|
|
@@ -10494,6 +10564,9 @@ function buildDefaultDeps(registry) {
|
|
|
10494
10564
|
throw new Error("Gemini provider is missing both apiKey and vertexProject \u2014 cannot run discovery.");
|
|
10495
10565
|
}
|
|
10496
10566
|
const adapter = gemini.adapter;
|
|
10567
|
+
const classifierProvider = classifierConfig?.classification?.provider ?? AgentProviderIds.gemini;
|
|
10568
|
+
const classifierModel = classifierConfig?.classification ? resolveModelForCapability(classifierProvider, LlmCapabilities.classify, classifierConfig.classification.model) : void 0;
|
|
10569
|
+
const classifierKey = resolveApiKeyFor(classifierProvider, classifierConfig ?? { providers: { gemini: { apiKey: cfg.apiKey } } });
|
|
10497
10570
|
function seedProviderFor(name) {
|
|
10498
10571
|
if (name === "gemini") return { adapter, config: cfg };
|
|
10499
10572
|
const entry = registry.get(name);
|
|
@@ -10574,8 +10647,20 @@ function buildDefaultDeps(registry) {
|
|
|
10574
10647
|
},
|
|
10575
10648
|
async classifyDomains(input) {
|
|
10576
10649
|
const prompt = buildClassificationPrompt(input);
|
|
10577
|
-
|
|
10578
|
-
|
|
10650
|
+
if (!classifierModel) {
|
|
10651
|
+
if (!canGenerateText(adapter)) throw new Error(`${adapter.displayName} cannot generate text for domain classification.`);
|
|
10652
|
+
const text2 = await adapter.generateText(prompt, cfg);
|
|
10653
|
+
return { classifications: parseClassificationResponse(text2, input.domains), evaluator: { provider: "gemini", requestedModel: cfg.model ?? adapter.modelRegistry.defaultModel, servedModel: null, promptVersion: "domain-category-v1" } };
|
|
10654
|
+
}
|
|
10655
|
+
if (!classifierKey) throw new Error("The configured domain classifier has no API key.");
|
|
10656
|
+
const quota = registry.get(classifierProvider)?.config.quotaPolicy ?? cfg.quotaPolicy;
|
|
10657
|
+
const generate = () => completeOnce(classifierModel, {
|
|
10658
|
+
messages: [{ role: "user", content: prompt, timestamp: Date.now() }]
|
|
10659
|
+
}, { apiKey: classifierKey });
|
|
10660
|
+
const response = classifierProvider === AgentProviderIds.openrouter ? await generate() : await getSharedProviderExecutionGate(classifierProvider, quota.maxConcurrency, quota.maxRequestsPerMinute).run(generate);
|
|
10661
|
+
if (response.stopReason === "error" || response.stopReason === "aborted") throw new Error("The domain classifier did not complete.");
|
|
10662
|
+
const text = response.content.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
10663
|
+
return { classifications: parseClassificationResponse(text, input.domains), evaluator: { provider: classifierProvider, requestedModel: classifierModel.id, servedModel: response.responseModel ?? null, promptVersion: "domain-category-v1" } };
|
|
10579
10664
|
}
|
|
10580
10665
|
};
|
|
10581
10666
|
}
|
|
@@ -10898,7 +10983,7 @@ function abortReason(signal) {
|
|
|
10898
10983
|
function throwIfAborted(signal) {
|
|
10899
10984
|
if (signal?.aborted) throw abortReason(signal);
|
|
10900
10985
|
}
|
|
10901
|
-
function
|
|
10986
|
+
function stripIpv6Brackets2(hostname) {
|
|
10902
10987
|
return hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
|
|
10903
10988
|
}
|
|
10904
10989
|
function buildSiteAuditRootRequestOptions(target) {
|
|
@@ -10915,7 +11000,7 @@ function buildSiteAuditRootRequestOptions(target) {
|
|
|
10915
11000
|
"User-Agent": USER_AGENT
|
|
10916
11001
|
}
|
|
10917
11002
|
};
|
|
10918
|
-
if (secure) requestOptions.servername =
|
|
11003
|
+
if (secure) requestOptions.servername = stripIpv6Brackets2(target.url.hostname);
|
|
10919
11004
|
return requestOptions;
|
|
10920
11005
|
}
|
|
10921
11006
|
async function requestPinnedSiteAuditRoot(target, options) {
|
|
@@ -11901,23 +11986,51 @@ var ProviderRegistry = class {
|
|
|
11901
11986
|
updateSharedProviderExecutionGate(adapter.name, config.quotaPolicy.maxConcurrency, config.quotaPolicy.maxRequestsPerMinute);
|
|
11902
11987
|
}
|
|
11903
11988
|
}
|
|
11989
|
+
/**
|
|
11990
|
+
* A registered provider, or the registration a route key runs as: the
|
|
11991
|
+
* route's connection supplies the key, quota and gate, and its selection
|
|
11992
|
+
* is pinned as the model.
|
|
11993
|
+
*/
|
|
11904
11994
|
get(name) {
|
|
11905
|
-
|
|
11995
|
+
const registered = this.providers.get(name);
|
|
11996
|
+
if (registered) return registered;
|
|
11997
|
+
const route = resolveProviderRoute(name, this.routeFamilies());
|
|
11998
|
+
const connection = route ? this.providers.get(route.connection) : void 0;
|
|
11999
|
+
if (!connection || !route) return void 0;
|
|
12000
|
+
return {
|
|
12001
|
+
config: { ...connection.config, provider: name, model: route.selection },
|
|
12002
|
+
adapter: connection.adapter.forRoute ? connection.adapter.forRoute(route) : derivedRouteAdapter(connection.adapter, route)
|
|
12003
|
+
};
|
|
12004
|
+
}
|
|
12005
|
+
/** Route families of the registered connections (OpenRouter is always known). */
|
|
12006
|
+
routeFamilies() {
|
|
12007
|
+
return routeFamiliesOf(this.getAll().map((provider) => provider.adapter));
|
|
12008
|
+
}
|
|
12009
|
+
/** The connection that owns a provider key's credentials, quota and gate. */
|
|
12010
|
+
connectionOf(name) {
|
|
12011
|
+
const provider = this.get(name);
|
|
12012
|
+
return provider ? adapterConnectionName(provider.adapter) : name;
|
|
11906
12013
|
}
|
|
11907
12014
|
getAll() {
|
|
11908
12015
|
return [...this.providers.values()];
|
|
11909
12016
|
}
|
|
11910
|
-
|
|
12017
|
+
/**
|
|
12018
|
+
* The engines a project's sweep runs. An empty list means every configured
|
|
12019
|
+
* answer engine, and nothing else: a gateway or a hosted answer service is
|
|
12020
|
+
* only ever measured when a project names one of its routes.
|
|
12021
|
+
*/
|
|
12022
|
+
getForProject(projectProviders, workflow = ProviderWorkflows["visibility-sweep"]) {
|
|
12023
|
+
const families = this.routeFamilies();
|
|
11911
12024
|
if (projectProviders.length === 0) {
|
|
11912
|
-
return this.getAll();
|
|
12025
|
+
return this.getAll().filter((provider) => isSweepProvider(provider.adapter.name, families) && isEligibleFor(provider.adapter, workflow, "implicit"));
|
|
11913
12026
|
}
|
|
11914
12027
|
const result = [];
|
|
11915
12028
|
const seen = /* @__PURE__ */ new Set();
|
|
11916
12029
|
for (const name of projectProviders) {
|
|
11917
12030
|
if (seen.has(name)) continue;
|
|
11918
12031
|
seen.add(name);
|
|
11919
|
-
const provider = this.
|
|
11920
|
-
if (provider) {
|
|
12032
|
+
const provider = this.get(name);
|
|
12033
|
+
if (provider && isSweepProvider(provider.adapter.name, families) && isEligibleFor(provider.adapter, workflow, "explicit")) {
|
|
11921
12034
|
result.push(provider);
|
|
11922
12035
|
}
|
|
11923
12036
|
}
|
|
@@ -11927,9 +12040,10 @@ var ProviderRegistry = class {
|
|
|
11927
12040
|
getBrowserProviders() {
|
|
11928
12041
|
return this.getAll().filter((p) => isBrowserProvider(p.adapter.name));
|
|
11929
12042
|
}
|
|
11930
|
-
/**
|
|
12043
|
+
/** Configured API answer engines (the implicit set; routed connections are excluded). */
|
|
11931
12044
|
getApiProviders() {
|
|
11932
|
-
|
|
12045
|
+
const families = this.routeFamilies();
|
|
12046
|
+
return this.getAll().filter((p) => !isBrowserProvider(p.adapter.name) && isSweepProvider(p.adapter.name, families) && isEligibleFor(p.adapter, ProviderWorkflows["visibility-sweep"], "implicit"));
|
|
11933
12047
|
}
|
|
11934
12048
|
get size() {
|
|
11935
12049
|
return this.providers.size;
|
|
@@ -11945,6 +12059,15 @@ var ProviderRegistry = class {
|
|
|
11945
12059
|
return results;
|
|
11946
12060
|
}
|
|
11947
12061
|
};
|
|
12062
|
+
function derivedRouteAdapter(adapter, route) {
|
|
12063
|
+
return {
|
|
12064
|
+
...adapter,
|
|
12065
|
+
name: route.name,
|
|
12066
|
+
displayName: `${route.selection} \xB7 ${adapter.displayName}`,
|
|
12067
|
+
modelRegistry: { ...adapter.modelRegistry, defaultModel: route.selection },
|
|
12068
|
+
parseTrackedQueryResponse: adapter.parseTrackedQueryResponse ? (body, requestedModel) => ({ ...adapter.parseTrackedQueryResponse(body, requestedModel), provider: route.name }) : void 0
|
|
12069
|
+
};
|
|
12070
|
+
}
|
|
11948
12071
|
|
|
11949
12072
|
// src/install-state-telemetry.ts
|
|
11950
12073
|
import { and as and15, count as count2, eq as eq18, gte as gte2, inArray as inArray7, isNotNull as isNotNull2, isNull as isNull2, ne as ne3, sql as sql7 } from "drizzle-orm";
|
|
@@ -12015,8 +12138,10 @@ function buildInstallState(sources, now, startedAt) {
|
|
|
12015
12138
|
if (isCdpProviderRegistrable(config.cdp)) connected.add(IntegrationNames.cdp);
|
|
12016
12139
|
const providerCalls = /* @__PURE__ */ new Map();
|
|
12017
12140
|
const addCalls = (provider, calls) => {
|
|
12018
|
-
if (!provider ||
|
|
12019
|
-
|
|
12141
|
+
if (!provider || calls <= 0) return;
|
|
12142
|
+
const connection = providerConnectionName(provider);
|
|
12143
|
+
if (!KNOWN_PROVIDERS2.has(connection)) return;
|
|
12144
|
+
providerCalls.set(connection, (providerCalls.get(connection) ?? 0) + calls);
|
|
12020
12145
|
};
|
|
12021
12146
|
const usagePath = (field) => sql7`json_extract(${querySnapshots.usage}, ${`$.${field}`})`;
|
|
12022
12147
|
const answers = db.select({
|
|
@@ -12191,7 +12316,7 @@ function configuredProviderEntries(config, apiAdapters, cdpAdapter) {
|
|
|
12191
12316
|
registered.push(resolveRegistration(adapter, providerConfigFromEntry(
|
|
12192
12317
|
adapter.name,
|
|
12193
12318
|
entry,
|
|
12194
|
-
resolveProviderQuotaPolicy(entry.quota, DEFAULT_PROVIDER_QUOTA)
|
|
12319
|
+
resolveProviderQuotaPolicy(entry.quota, adapter.defaultQuota ?? DEFAULT_PROVIDER_QUOTA)
|
|
12195
12320
|
)));
|
|
12196
12321
|
}
|
|
12197
12322
|
}
|
|
@@ -12240,8 +12365,8 @@ var RETRY_MS = 60 * 1e3;
|
|
|
12240
12365
|
var TIMEOUT_MS2 = 3e3;
|
|
12241
12366
|
function createProviderModelCatalog(registry) {
|
|
12242
12367
|
const cache = /* @__PURE__ */ new Map();
|
|
12243
|
-
const read = async (name) => {
|
|
12244
|
-
const provider = registry.get(name);
|
|
12368
|
+
const read = async (name, unregistered) => {
|
|
12369
|
+
const provider = registry.get(name) ?? unregistered?.();
|
|
12245
12370
|
if (!provider) {
|
|
12246
12371
|
cache.delete(name);
|
|
12247
12372
|
return [];
|
|
@@ -12283,14 +12408,21 @@ function createProviderModelCatalog(registry) {
|
|
|
12283
12408
|
});
|
|
12284
12409
|
return current.pending;
|
|
12285
12410
|
};
|
|
12286
|
-
const cached = (name) => {
|
|
12287
|
-
const provider = registry.get(name);
|
|
12411
|
+
const cached = (name, unregistered) => {
|
|
12412
|
+
const provider = registry.get(name) ?? unregistered?.();
|
|
12288
12413
|
if (!provider) return [];
|
|
12289
12414
|
const entry = cache.get(name);
|
|
12290
12415
|
const identity = createHash5("sha256").update(JSON.stringify(provider.config)).digest("hex");
|
|
12291
12416
|
return (entry?.identity === identity ? entry.models : void 0) ?? provider.adapter.modelRegistry.knownModels;
|
|
12292
12417
|
};
|
|
12293
|
-
return Object.assign(read, {
|
|
12418
|
+
return Object.assign((name) => read(name), {
|
|
12419
|
+
cached: (name) => cached(name),
|
|
12420
|
+
/** The same reads, falling back to `unregistered` when the registry has no connection under the name. */
|
|
12421
|
+
orUnregistered: (unregistered) => ({
|
|
12422
|
+
read: (name) => read(name, unregistered),
|
|
12423
|
+
cached: (name) => cached(name, unregistered)
|
|
12424
|
+
})
|
|
12425
|
+
});
|
|
12294
12426
|
}
|
|
12295
12427
|
|
|
12296
12428
|
// src/scheduler.ts
|
|
@@ -12793,6 +12925,7 @@ var Scheduler = class {
|
|
|
12793
12925
|
location: locationLabel,
|
|
12794
12926
|
providers,
|
|
12795
12927
|
runnableProviders: this.callbacks.getRunnableProviderNames?.(),
|
|
12928
|
+
routeFamilies: this.callbacks.getProviderRouteFamilies?.(),
|
|
12796
12929
|
providerModels: this.callbacks.getEffectiveProviderModels?.(),
|
|
12797
12930
|
batchEligibleProviders: this.callbacks.getBatchEligibleProviderNames?.() ?? null,
|
|
12798
12931
|
// A skipped slot is otherwise invisible: no run row, nothing in the
|
|
@@ -13115,9 +13248,9 @@ function gaRefreshDays(now = /* @__PURE__ */ new Date()) {
|
|
|
13115
13248
|
return Math.max(30, reach);
|
|
13116
13249
|
}
|
|
13117
13250
|
function queuedRun(result) {
|
|
13118
|
-
const
|
|
13119
|
-
const runId =
|
|
13120
|
-
const runStatus =
|
|
13251
|
+
const record = asRecord(result);
|
|
13252
|
+
const runId = record?.runId ?? record?.id;
|
|
13253
|
+
const runStatus = record?.status;
|
|
13121
13254
|
return {
|
|
13122
13255
|
runId: typeof runId === "string" ? runId : null,
|
|
13123
13256
|
runStatus: typeof runStatus === "string" ? runStatus : null
|
|
@@ -15090,6 +15223,8 @@ ${lines.join("\n")}
|
|
|
15090
15223
|
* that names no provider returns to it.
|
|
15091
15224
|
*/
|
|
15092
15225
|
async acquireForTurn(projectName, preferences) {
|
|
15226
|
+
preferences?.signal?.throwIfAborted();
|
|
15227
|
+
await refreshAgentModels(this.turnProvider(projectName, preferences), preferences?.signal);
|
|
15093
15228
|
preferences?.signal?.throwIfAborted();
|
|
15094
15229
|
if (this.acquisitions.has(projectName)) throw agentBusy(projectName);
|
|
15095
15230
|
const agent = this.getOrCreate(projectName, preferences);
|
|
@@ -15226,11 +15361,31 @@ ${lines.join("\n")}
|
|
|
15226
15361
|
const stored = coerceAgentProvider(current.provider ?? void 0);
|
|
15227
15362
|
const provider = preferences?.provider ?? pinned ?? stored ?? detectAgentProvider(this.opts.config);
|
|
15228
15363
|
if (!provider) throw new Error(missingProviderMessage());
|
|
15229
|
-
const carried = !preferences?.provider && !pinned && provider === current.provider && current.modelId && isAgentModelAvailable(provider, current.modelId) ? current.modelId : void 0;
|
|
15364
|
+
const carried = !preferences?.provider && !pinned && provider === current.provider && current.modelId && (isAgentModelAvailable(provider, current.modelId) || isAgentModelUnchecked(provider, current.modelId) && !!resolveApiKeyFor(provider, this.opts.config)) ? current.modelId : void 0;
|
|
15230
15365
|
const pinnedModelId = provider === pinned ? this.opts.config.agent?.model ?? void 0 : void 0;
|
|
15231
15366
|
const modelId = preferences?.modelId ?? pinnedModelId ?? carried ?? getAgentProvider(provider).defaultModel;
|
|
15232
15367
|
return { provider, modelId };
|
|
15233
15368
|
}
|
|
15369
|
+
/** The provider the next turn would run on; undefined when none can (the turn then fails as before). */
|
|
15370
|
+
turnProvider(projectName, preferences) {
|
|
15371
|
+
return this.nextTurnModel(projectName, preferences)?.provider;
|
|
15372
|
+
}
|
|
15373
|
+
/**
|
|
15374
|
+
* The provider and model the next turn would run on, resolved exactly as the
|
|
15375
|
+
* turn resolves them: a request's choice, then the `agent.provider` pin, then
|
|
15376
|
+
* the conversation's stored model, then the provider default. With no
|
|
15377
|
+
* preferences this is what the dashboard shows when the operator has picked
|
|
15378
|
+
* nothing. Null when no provider can run.
|
|
15379
|
+
*/
|
|
15380
|
+
nextTurnModel(projectName, preferences) {
|
|
15381
|
+
const projectId = this.tryResolveProjectId(projectName);
|
|
15382
|
+
const row = projectId ? this.loadRow(projectId) : null;
|
|
15383
|
+
try {
|
|
15384
|
+
return this.resolveTurnModel(preferences, { provider: row?.modelProvider, modelId: row?.modelId });
|
|
15385
|
+
} catch {
|
|
15386
|
+
return null;
|
|
15387
|
+
}
|
|
15388
|
+
}
|
|
15234
15389
|
alignModel(projectName, agent, preferences) {
|
|
15235
15390
|
const projectId = this.tryResolveProjectId(projectName);
|
|
15236
15391
|
if (!projectId) return;
|
|
@@ -15241,7 +15396,7 @@ ${lines.join("\n")}
|
|
|
15241
15396
|
const { provider: nextProvider, modelId: nextModelId } = this.resolveTurnModel(preferences, { provider: row.modelProvider, modelId: row.modelId });
|
|
15242
15397
|
if (nextProvider === currentProvider && nextModelId === currentModelId) return;
|
|
15243
15398
|
agent.state.model = resolveAeroModel(nextProvider, nextModelId);
|
|
15244
|
-
agent.state.thinkingLevel = resolveAgentReasoning(process.env, this.opts.config, nextProvider);
|
|
15399
|
+
agent.state.thinkingLevel = resolveAgentReasoning(process.env, this.opts.config, nextProvider, agent.state.model.id);
|
|
15245
15400
|
this.opts.db.update(agentSessions).set({
|
|
15246
15401
|
modelProvider: nextProvider,
|
|
15247
15402
|
modelId: nextModelId,
|
|
@@ -15436,12 +15591,13 @@ ${lines.join("\n")}
|
|
|
15436
15591
|
}
|
|
15437
15592
|
insertRow(params) {
|
|
15438
15593
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
15594
|
+
const modelProvider = params.provider ?? params.modelProvider ?? AgentProviderIds.claude;
|
|
15439
15595
|
this.opts.db.insert(agentSessions).values({
|
|
15440
15596
|
id: params.id ?? crypto23.randomUUID(),
|
|
15441
15597
|
projectId: params.projectId,
|
|
15442
15598
|
systemPrompt: params.systemPrompt,
|
|
15443
|
-
modelProvider
|
|
15444
|
-
modelId: params.modelId ??
|
|
15599
|
+
modelProvider,
|
|
15600
|
+
modelId: params.modelId ?? getAgentProvider(coerceAgentProvider(modelProvider) ?? AgentProviderIds.claude).defaultModel,
|
|
15445
15601
|
messages: JSON.stringify(withoutPersistedToolDetails(params.messages)),
|
|
15446
15602
|
followUpQueue: JSON.stringify(params.followUpQueue),
|
|
15447
15603
|
createdAt: now,
|
|
@@ -15585,7 +15741,7 @@ var ViewerAeroSessions = class {
|
|
|
15585
15741
|
let handedOff = false;
|
|
15586
15742
|
try {
|
|
15587
15743
|
const client = new ApiClient(this.opts.selfApiUrl, minted.raw, { skipProbe: true, surface: "aero" });
|
|
15588
|
-
const agent = this.sessions.get(key)?.agent ?? this.createAgent(project, client);
|
|
15744
|
+
const agent = this.sessions.get(key)?.agent ?? await this.createAgent(project, client, preferences.signal);
|
|
15589
15745
|
agent.state.messages = trimViewerTranscript(agent.state.messages.filter((message) => message.role !== "system"));
|
|
15590
15746
|
const view = { client, projectName: project.name, basePath: this.opts.config.basePath, context: preferences.context };
|
|
15591
15747
|
const evidence = preferences.context ? await readAeroViewEvidence(view) : void 0;
|
|
@@ -15619,8 +15775,9 @@ var ViewerAeroSessions = class {
|
|
|
15619
15775
|
}
|
|
15620
15776
|
}
|
|
15621
15777
|
}
|
|
15622
|
-
createAgent(project, client) {
|
|
15778
|
+
async createAgent(project, client, signal) {
|
|
15623
15779
|
const { provider, modelId } = resolveSessionProviderAndModel(this.opts.config);
|
|
15780
|
+
await refreshAgentModels(provider, signal);
|
|
15624
15781
|
return createAeroSession({
|
|
15625
15782
|
projectName: project.name,
|
|
15626
15783
|
client,
|
|
@@ -15675,6 +15832,7 @@ var ViewerAeroSessions = class {
|
|
|
15675
15832
|
|
|
15676
15833
|
// src/mcp-http.ts
|
|
15677
15834
|
import crypto25 from "crypto";
|
|
15835
|
+
import { isIP } from "net";
|
|
15678
15836
|
import { eq as eq27 } from "drizzle-orm";
|
|
15679
15837
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
15680
15838
|
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
@@ -15710,11 +15868,49 @@ function mcpTransportPaths() {
|
|
|
15710
15868
|
}
|
|
15711
15869
|
return paths;
|
|
15712
15870
|
}
|
|
15713
|
-
function mcpHttpHealth(app, apiPrefix) {
|
|
15871
|
+
function mcpHttpHealth(app, apiPrefix, hosted) {
|
|
15714
15872
|
const available = mcpTransportPaths().every(
|
|
15715
15873
|
(path6) => ["POST", "GET", "DELETE"].every((method) => app.hasRoute({ method, url: `${apiPrefix}${path6}` }))
|
|
15716
15874
|
);
|
|
15717
|
-
|
|
15875
|
+
const status = available ? McpTransportStatuses.available : McpTransportStatuses.unavailable;
|
|
15876
|
+
if (!hosted) return { status };
|
|
15877
|
+
const unavailable = (reason) => ({
|
|
15878
|
+
status,
|
|
15879
|
+
hosted: { status: HostedMcpStatuses.unavailable, reason }
|
|
15880
|
+
});
|
|
15881
|
+
if (!available) return unavailable(HostedMcpUnavailableReasons["transport-unavailable"]);
|
|
15882
|
+
if (!hosted.publicUrl) return unavailable(HostedMcpUnavailableReasons["public-url-required"]);
|
|
15883
|
+
let publicUrl;
|
|
15884
|
+
try {
|
|
15885
|
+
publicUrl = new URL(hosted.publicUrl);
|
|
15886
|
+
} catch {
|
|
15887
|
+
return unavailable(HostedMcpUnavailableReasons["public-url-required"]);
|
|
15888
|
+
}
|
|
15889
|
+
if (publicUrl.username || publicUrl.password || publicUrl.search || publicUrl.hash) {
|
|
15890
|
+
return unavailable(HostedMcpUnavailableReasons["public-url-required"]);
|
|
15891
|
+
}
|
|
15892
|
+
if (publicUrl.protocol !== "https:") return unavailable(HostedMcpUnavailableReasons["https-required"]);
|
|
15893
|
+
const hostname = stripIpv6Brackets(publicUrl.hostname).toLowerCase().replace(/\.$/, "");
|
|
15894
|
+
if (hostname === "localhost" || hostname.endsWith(".localhost") || hostname.endsWith(".local") || (isIP(hostname) !== 0 ? blockedAddressReason(hostname) !== null : !hostname.includes("."))) {
|
|
15895
|
+
return unavailable(HostedMcpUnavailableReasons["public-host-required"]);
|
|
15896
|
+
}
|
|
15897
|
+
const publicBasePath = publicUrl.pathname.replace(/\/$/, "");
|
|
15898
|
+
const mountedBasePath = apiPrefix.slice(0, -"/api/v1".length);
|
|
15899
|
+
if (publicBasePath !== mountedBasePath) return unavailable(HostedMcpUnavailableReasons["public-path-mismatch"]);
|
|
15900
|
+
const oauthRoutes = [
|
|
15901
|
+
["GET", hosted.authorizationPath],
|
|
15902
|
+
["POST", hosted.authorizationPath],
|
|
15903
|
+
["POST", `${hosted.authorizationPath}/consent`],
|
|
15904
|
+
["POST", "/oauth/token"],
|
|
15905
|
+
["POST", "/oauth/register"],
|
|
15906
|
+
["GET", "/.well-known/oauth-authorization-server"],
|
|
15907
|
+
["GET", `/.well-known/oauth-protected-resource${apiPrefix}/mcp`]
|
|
15908
|
+
];
|
|
15909
|
+
if (!oauthRoutes.every(([method, url]) => app.hasRoute({ method, url }))) {
|
|
15910
|
+
return unavailable(HostedMcpUnavailableReasons["oauth-unavailable"]);
|
|
15911
|
+
}
|
|
15912
|
+
if (!hosted.hasAccounts) return unavailable(HostedMcpUnavailableReasons["account-required"]);
|
|
15913
|
+
return { status, hosted: { status: HostedMcpStatuses.ready, url: `${publicUrl.origin}${apiPrefix}/mcp` } };
|
|
15718
15914
|
}
|
|
15719
15915
|
function registerMcpHttpRoutes(scope, opts) {
|
|
15720
15916
|
const sessions = /* @__PURE__ */ new Map();
|
|
@@ -16042,8 +16238,9 @@ function registerAgentRoutes(app, opts) {
|
|
|
16042
16238
|
requireInstanceAdministrator(request);
|
|
16043
16239
|
const project = resolveProject(opts.db, request.params.name);
|
|
16044
16240
|
const row = opts.db.select().from(agentSessions).where(eq28(agentSessions.projectId, project.id)).get();
|
|
16241
|
+
const nextTurn = opts.sessionRegistry.nextTurnModel(project.name);
|
|
16045
16242
|
if (!row) {
|
|
16046
|
-
return { conversationId: null, messages: [], modelProvider: null, modelId: null, updatedAt: null };
|
|
16243
|
+
return { conversationId: null, messages: [], modelProvider: null, modelId: null, nextTurn, updatedAt: null };
|
|
16047
16244
|
}
|
|
16048
16245
|
const messages = parseJsonColumn(row.messages, []);
|
|
16049
16246
|
return {
|
|
@@ -16052,6 +16249,7 @@ function registerAgentRoutes(app, opts) {
|
|
|
16052
16249
|
isStreaming: opts.sessionRegistry.isBusy(project.name),
|
|
16053
16250
|
modelProvider: row.modelProvider,
|
|
16054
16251
|
modelId: row.modelId,
|
|
16252
|
+
nextTurn,
|
|
16055
16253
|
updatedAt: row.updatedAt
|
|
16056
16254
|
};
|
|
16057
16255
|
}
|
|
@@ -16061,7 +16259,7 @@ function registerAgentRoutes(app, opts) {
|
|
|
16061
16259
|
async (request) => {
|
|
16062
16260
|
requireInstanceAdministrator(request);
|
|
16063
16261
|
resolveProject(opts.db, request.params.name);
|
|
16064
|
-
return buildAgentProvidersResponse(opts.sessionRegistry.getConfig());
|
|
16262
|
+
return buildAgentProvidersResponse(opts.sessionRegistry.getConfig(), { models: true });
|
|
16065
16263
|
}
|
|
16066
16264
|
);
|
|
16067
16265
|
app.delete(
|
|
@@ -16292,6 +16490,7 @@ function pickExplainProvider(config, providerOverride) {
|
|
|
16292
16490
|
function createRecommendationExplainer(opts) {
|
|
16293
16491
|
return async (input) => {
|
|
16294
16492
|
const provider = pickExplainProvider(opts.config, input.providerOverride);
|
|
16493
|
+
await refreshAgentModels(provider);
|
|
16295
16494
|
const model = resolveModelForCapability(provider, "analyze", input.modelOverride);
|
|
16296
16495
|
const prompt = buildRecommendationPrompt({
|
|
16297
16496
|
projectName: input.projectName,
|
|
@@ -16370,6 +16569,7 @@ function parseBrief(text, recommendation) {
|
|
|
16370
16569
|
function createRecommendationBriefSynthesizer(opts) {
|
|
16371
16570
|
return async (input) => {
|
|
16372
16571
|
const provider = pickExplainProvider(opts.config, input.providerOverride);
|
|
16572
|
+
await refreshAgentModels(provider);
|
|
16373
16573
|
const model = resolveModelForCapability(provider, "analyze", input.modelOverride);
|
|
16374
16574
|
const apiKey = resolveApiKeyFor(provider, opts.config);
|
|
16375
16575
|
const prompt = buildBriefPrompt({
|
|
@@ -16529,9 +16729,14 @@ var SnapshotService = class {
|
|
|
16529
16729
|
const manualCompetitors = normalizeStringList(input.competitors ?? []);
|
|
16530
16730
|
const requestedNames = input.providers === void 0 ? void 0 : [...new Set(input.providers)];
|
|
16531
16731
|
const mode = input.providerMode ?? SnapshotProviderModes.all;
|
|
16532
|
-
const
|
|
16732
|
+
const families = this.registry.routeFamilies();
|
|
16733
|
+
const providers = requestedNames === void 0 ? this.registry.getAll().filter((provider) => isSweepProvider(provider.adapter.name, families) && isEligibleFor(provider.adapter, ProviderWorkflows.snapshot, "implicit") && (mode === SnapshotProviderModes.all || provider.adapter.mode === mode)) : requestedNames.map((name) => {
|
|
16533
16734
|
const provider = this.registry.get(name);
|
|
16534
16735
|
if (!provider) throw validationError(`Snapshot provider "${name}" is not configured`);
|
|
16736
|
+
if (!isSweepProvider(name, families)) throw validationError(`Select a concrete ${provider.adapter.displayName} model or profile for the snapshot`);
|
|
16737
|
+
if (!isEligibleFor(provider.adapter, ProviderWorkflows.snapshot, "explicit")) {
|
|
16738
|
+
throw validationError(`Snapshot provider "${name}" does not run snapshots`);
|
|
16739
|
+
}
|
|
16535
16740
|
if (mode !== SnapshotProviderModes.all && provider.adapter.mode !== mode) {
|
|
16536
16741
|
throw validationError(`Snapshot provider "${name}" does not match providerMode "${mode}"`);
|
|
16537
16742
|
}
|
|
@@ -16543,9 +16748,9 @@ var SnapshotService = class {
|
|
|
16543
16748
|
}
|
|
16544
16749
|
throw new Error("No providers configured. Add at least one provider API key before running canonry snapshot.");
|
|
16545
16750
|
}
|
|
16546
|
-
const analysisProvider = pickAnalysisProvider(providers.filter((provider) => provider.adapter.mode === SnapshotProviderModes.api));
|
|
16751
|
+
const analysisProvider = pickAnalysisProvider(providers.filter((provider) => provider.adapter.mode === SnapshotProviderModes.api && canGenerateText(provider.adapter)));
|
|
16547
16752
|
if (!analysisProvider && manualQueries.length === 0) {
|
|
16548
|
-
throw validationError("Automatic category-query generation requires a selected API provider. Include
|
|
16753
|
+
throw validationError("Automatic category-query generation requires a selected API provider that can generate text. Include one or pass manual queries via --queries.");
|
|
16549
16754
|
}
|
|
16550
16755
|
const homepageUrl = `https://${domain}`;
|
|
16551
16756
|
const [siteText, audit] = await Promise.all([
|
|
@@ -16626,7 +16831,7 @@ var SnapshotService = class {
|
|
|
16626
16831
|
if (ctx.analysisProvider && ctx.siteText) {
|
|
16627
16832
|
const prompt = buildProfilePrompt(ctx);
|
|
16628
16833
|
try {
|
|
16629
|
-
const raw = await ctx.analysisProvider
|
|
16834
|
+
const raw = await generateAnalysisText(ctx.analysisProvider, prompt);
|
|
16630
16835
|
const parsed = parseJsonObject(raw);
|
|
16631
16836
|
const parsedQueries = ctx.manualQueries.length > 0 ? ctx.manualQueries : normalizeStringList(parsed.queries ?? []).slice(0, SNAPSHOT_QUERY_COUNT);
|
|
16632
16837
|
if (ctx.manualQueries.length === 0 && parsedQueries.length === 0) {
|
|
@@ -16666,7 +16871,7 @@ var SnapshotService = class {
|
|
|
16666
16871
|
gates2.set(
|
|
16667
16872
|
provider.adapter.name,
|
|
16668
16873
|
getSharedProviderExecutionGate(
|
|
16669
|
-
provider.adapter
|
|
16874
|
+
adapterConnectionName(provider.adapter),
|
|
16670
16875
|
provider.config.quotaPolicy.maxConcurrency,
|
|
16671
16876
|
provider.config.quotaPolicy.maxRequestsPerMinute
|
|
16672
16877
|
)
|
|
@@ -16695,12 +16900,14 @@ var SnapshotService = class {
|
|
|
16695
16900
|
targetDomain: ctx.domain
|
|
16696
16901
|
});
|
|
16697
16902
|
const answerVisibilityDomains = [ctx.domain];
|
|
16903
|
+
const citationMeasured = isCitationMeasurable(normalized);
|
|
16698
16904
|
return {
|
|
16699
16905
|
provider: provider.adapter.name,
|
|
16700
16906
|
displayName: provider.adapter.displayName,
|
|
16701
16907
|
model: raw.model,
|
|
16702
16908
|
mentioned: determineAnswerMentioned(normalized.answerText, [ctx.companyName], answerVisibilityDomains),
|
|
16703
|
-
|
|
16909
|
+
// Search results the answer is not tied to never make a domain cited.
|
|
16910
|
+
cited: citationMeasured && citesTargetDomain(normalized.citedDomains, normalized.groundingSources, ctx.domain),
|
|
16704
16911
|
describedAccurately: "unknown",
|
|
16705
16912
|
accuracyNotes: null,
|
|
16706
16913
|
incorrectClaims: [],
|
|
@@ -16709,7 +16916,8 @@ var SnapshotService = class {
|
|
|
16709
16916
|
groundingSources: normalized.groundingSources,
|
|
16710
16917
|
searchQueries: uniqueStrings2(normalized.searchQueries),
|
|
16711
16918
|
answerText: normalized.answerText,
|
|
16712
|
-
error: null
|
|
16919
|
+
error: null,
|
|
16920
|
+
...raw.evidence ? { evidence: raw.evidence, citationMeasured } : {}
|
|
16713
16921
|
};
|
|
16714
16922
|
} catch (err) {
|
|
16715
16923
|
return {
|
|
@@ -16725,8 +16933,10 @@ var SnapshotService = class {
|
|
|
16725
16933
|
citedDomains: [],
|
|
16726
16934
|
groundingSources: [],
|
|
16727
16935
|
searchQueries: [],
|
|
16728
|
-
answerText: "",
|
|
16729
|
-
error: describeError(err)
|
|
16936
|
+
answerText: err instanceof IncompleteAnswerError ? err.answerText ?? "" : "",
|
|
16937
|
+
error: describeError(err),
|
|
16938
|
+
// An incomplete answer keeps its evidence for inspection; it is never scored.
|
|
16939
|
+
...err instanceof IncompleteAnswerError ? { evidence: err.evidence, citationMeasured: false } : {}
|
|
16730
16940
|
};
|
|
16731
16941
|
}
|
|
16732
16942
|
});
|
|
@@ -16762,7 +16972,7 @@ var SnapshotService = class {
|
|
|
16762
16972
|
responses,
|
|
16763
16973
|
manualCompetitors: ctx.manualCompetitors
|
|
16764
16974
|
});
|
|
16765
|
-
const raw = await ctx.analysisProvider
|
|
16975
|
+
const raw = await generateAnalysisText(ctx.analysisProvider, prompt);
|
|
16766
16976
|
const parsed = parseJsonObject(raw);
|
|
16767
16977
|
return {
|
|
16768
16978
|
assessments: (parsed.assessments ?? []).filter((assessment) => assessment.query && assessment.provider).map((assessment) => {
|
|
@@ -16791,6 +17001,10 @@ var SnapshotService = class {
|
|
|
16791
17001
|
}
|
|
16792
17002
|
}
|
|
16793
17003
|
};
|
|
17004
|
+
async function generateAnalysisText(provider, prompt) {
|
|
17005
|
+
if (!canGenerateText(provider.adapter)) throw new Error(`${provider.adapter.displayName} cannot generate text`);
|
|
17006
|
+
return provider.adapter.generateText(prompt, provider.config);
|
|
17007
|
+
}
|
|
16794
17008
|
function pickAnalysisProvider(providers) {
|
|
16795
17009
|
return [...providers].sort((a, b) => {
|
|
16796
17010
|
const aIndex = ANALYSIS_PROVIDER_PRIORITY.indexOf(a.adapter.name);
|
|
@@ -16895,7 +17109,9 @@ function buildSnapshotSummary(companyName, queries2, providers, queryResults, au
|
|
|
16895
17109
|
const successfulResults = allResults.filter((result) => !result.error);
|
|
16896
17110
|
const failedComparisons = allResults.length - successfulResults.length;
|
|
16897
17111
|
const mentionCount = successfulResults.filter((result) => result.mentioned).length;
|
|
16898
|
-
const
|
|
17112
|
+
const citationMeasured = successfulResults.filter((result) => result.citationMeasured !== false);
|
|
17113
|
+
const citationCount = citationMeasured.filter((result) => result.cited).length;
|
|
17114
|
+
const citationComparisons = citationMeasured.length;
|
|
16899
17115
|
const totalComparisons = successfulResults.length;
|
|
16900
17116
|
const competitorCounts = /* @__PURE__ */ new Map();
|
|
16901
17117
|
for (const result of successfulResults) {
|
|
@@ -16919,6 +17135,7 @@ function buildSnapshotSummary(companyName, queries2, providers, queryResults, au
|
|
|
16919
17135
|
totalComparisons,
|
|
16920
17136
|
mentionCount,
|
|
16921
17137
|
citationCount,
|
|
17138
|
+
citationComparisons,
|
|
16922
17139
|
topCompetitors,
|
|
16923
17140
|
visibilityGap: buildVisibilityGap(
|
|
16924
17141
|
companyName,
|
|
@@ -16927,25 +17144,33 @@ function buildSnapshotSummary(companyName, queries2, providers, queryResults, au
|
|
|
16927
17144
|
totalComparisons,
|
|
16928
17145
|
mentionCount,
|
|
16929
17146
|
citationCount,
|
|
17147
|
+
citationComparisons,
|
|
16930
17148
|
failedComparisons
|
|
16931
17149
|
),
|
|
16932
17150
|
whatThisMeans: combinedWhatThisMeans,
|
|
16933
17151
|
recommendedActions
|
|
16934
17152
|
};
|
|
16935
17153
|
}
|
|
16936
|
-
function buildVisibilityGap(companyName, queryCount, providerCount, totalComparisons, mentionCount, citationCount, failedComparisons) {
|
|
17154
|
+
function buildVisibilityGap(companyName, queryCount, providerCount, totalComparisons, mentionCount, citationCount, citationComparisons, failedComparisons) {
|
|
16937
17155
|
const successfulLabel = `${totalComparisons} successful provider response${totalComparisons === 1 ? "" : "s"}`;
|
|
16938
17156
|
const failureSuffix = failedComparisons > 0 ? ` ${failedComparisons} provider response${failedComparisons === 1 ? "" : "s"} failed.` : "";
|
|
17157
|
+
const unmeasured = totalComparisons - citationComparisons;
|
|
17158
|
+
const unmeasuredSuffix = unmeasured > 0 && citationComparisons > 0 ? ` Citation was not measured in ${unmeasured} of them, because those providers do not tie their sources to the answer.` : "";
|
|
16939
17159
|
if (totalComparisons === 0) {
|
|
16940
17160
|
return `No providers returned successful answers across ${queryCount} category queries and ${providerCount} providers.${failureSuffix}`.trim();
|
|
16941
17161
|
}
|
|
16942
17162
|
if (mentionCount === 0) {
|
|
16943
17163
|
return `${companyName} was not mentioned in any of the ${successfulLabel} across ${queryCount} category queries and ${providerCount} providers.${failureSuffix}`.trim();
|
|
16944
17164
|
}
|
|
16945
|
-
|
|
16946
|
-
|
|
17165
|
+
const mentioned = `${companyName} was mentioned in ${mentionCount}/${successfulLabel}`;
|
|
17166
|
+
if (citationComparisons === 0) {
|
|
17167
|
+
return `${mentioned}. Citation was not measured, because ${totalComparisons === 1 ? "that provider does" : "those providers do"} not tie ${totalComparisons === 1 ? "its" : "their"} sources to the answer.${failureSuffix}`.trim();
|
|
17168
|
+
}
|
|
17169
|
+
const citedPart = citationCount === 0 ? `never linked or cited directly in the ${citationComparisons} where citation was measured` : `cited in ${citationCount}/${citationComparisons}${unmeasured > 0 ? " where citation was measured" : ""}`;
|
|
17170
|
+
if (citationCount === 0 && unmeasured === 0) {
|
|
17171
|
+
return `${mentioned}, but never linked or cited directly.${failureSuffix}`.trim();
|
|
16947
17172
|
}
|
|
16948
|
-
return `${
|
|
17173
|
+
return `${mentioned}${citationCount === 0 ? ", but " : " and "}${citedPart}.${unmeasuredSuffix}${failureSuffix}`.trim();
|
|
16949
17174
|
}
|
|
16950
17175
|
function buildFallbackRecommendedActions(audit) {
|
|
16951
17176
|
const weakestFactors = [...audit.factors].sort((a, b) => a.score - b.score || a.name.localeCompare(b.name)).slice(0, 3).map((factor) => `Improve ${factor.name.toLowerCase()}: ${formatAuditFactorScore(factor)}`);
|
|
@@ -17040,7 +17265,8 @@ function clipText(value, length) {
|
|
|
17040
17265
|
// src/research-runner.ts
|
|
17041
17266
|
import { and as and23, eq as eq29, inArray as inArray12, sql as sql11 } from "drizzle-orm";
|
|
17042
17267
|
var unfinishedResearchQueryStatuses = [ResearchQueryStatuses.queued, ResearchQueryStatuses.running];
|
|
17043
|
-
function finalResearchRunStatus(completed, failed) {
|
|
17268
|
+
function finalResearchRunStatus(completed, failed, waiting) {
|
|
17269
|
+
if (waiting > 0) return ResearchRunStatuses["waiting-upstream"];
|
|
17044
17270
|
if (failed === 0) return ResearchRunStatuses.completed;
|
|
17045
17271
|
return completed > 0 ? ResearchRunStatuses.partial : ResearchRunStatuses.failed;
|
|
17046
17272
|
}
|
|
@@ -17067,8 +17293,12 @@ async function executeResearchRun(db, registry, runId, projectId, options = {})
|
|
|
17067
17293
|
fatalReason = { reasonCode: OutcomeReasonCodes.NOT_CONNECTED };
|
|
17068
17294
|
throw new Error("Configured API provider is unavailable.");
|
|
17069
17295
|
}
|
|
17296
|
+
if (!isEligibleFor(provider.adapter, ProviderWorkflows.research, "explicit")) {
|
|
17297
|
+
fatalReason = { reasonCode: OutcomeReasonCodes.NOT_CONNECTED };
|
|
17298
|
+
throw new Error(`${provider.adapter.displayName} does not run research queries.`);
|
|
17299
|
+
}
|
|
17070
17300
|
const period = getCurrentUsageDay();
|
|
17071
|
-
const scope = `${projectId}:${
|
|
17301
|
+
const scope = `${projectId}:${adapterConnectionName(provider.adapter)}`;
|
|
17072
17302
|
const quota = reserveDailyQueryQuota(db, {
|
|
17073
17303
|
scope,
|
|
17074
17304
|
period,
|
|
@@ -17088,7 +17318,7 @@ async function executeResearchRun(db, registry, runId, projectId, options = {})
|
|
|
17088
17318
|
const domains = effectiveDomains(project);
|
|
17089
17319
|
const brands = effectiveBrandNames(project);
|
|
17090
17320
|
const config = { ...provider.config, model: run.resolvedModel };
|
|
17091
|
-
const gate = getSharedProviderExecutionGate(
|
|
17321
|
+
const gate = getSharedProviderExecutionGate(adapterConnectionName(provider.adapter), provider.config.quotaPolicy.maxConcurrency, provider.config.quotaPolicy.maxRequestsPerMinute);
|
|
17092
17322
|
await mapWithConcurrency(rows, Math.max(1, provider.config.quotaPolicy.maxConcurrency), async (row) => {
|
|
17093
17323
|
try {
|
|
17094
17324
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -17118,13 +17348,15 @@ async function executeResearchRun(db, registry, runId, projectId, options = {})
|
|
|
17118
17348
|
namedCompetitors,
|
|
17119
17349
|
citedCompetitorDomains,
|
|
17120
17350
|
answerMentioned: determineAnswerMentioned(normalized.answerText, brands, domains),
|
|
17121
|
-
|
|
17351
|
+
// Sources the answer is not tied to cannot say whether a domain was cited.
|
|
17352
|
+
citationState: isCitationMeasurable(normalized) ? determineCitationState(normalized, domains) : null,
|
|
17122
17353
|
rawResponse: raw.rawResponse,
|
|
17354
|
+
answerEvidence: raw.evidence ?? null,
|
|
17123
17355
|
finishedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
17124
17356
|
}).where(and23(eq29(researchRunQueries.id, row.id), eq29(researchRunQueries.status, ResearchQueryStatuses.running))).run();
|
|
17125
17357
|
if (completed.changes === 1) incrementResearchProgress(db, runId, "completedQueries");
|
|
17126
17358
|
} catch (error) {
|
|
17127
|
-
queryFailure ??= error;
|
|
17359
|
+
if (!(error instanceof IncompleteAnswerError && error.resumable)) queryFailure ??= error;
|
|
17128
17360
|
try {
|
|
17129
17361
|
markResearchQueryFailed(db, runId, row.id, error);
|
|
17130
17362
|
} catch (persistenceError) {
|
|
@@ -17145,13 +17377,14 @@ async function executeResearchRun(db, registry, runId, projectId, options = {})
|
|
|
17145
17377
|
if (reservation && reserved > dispatched) {
|
|
17146
17378
|
releaseDailyQueryQuota(db, { ...reservation, count: reserved - dispatched });
|
|
17147
17379
|
}
|
|
17380
|
+
const telemetryProvider = providerConnectionName(run.provider);
|
|
17148
17381
|
trackFeatureCompleted({
|
|
17149
17382
|
feature: "research",
|
|
17150
17383
|
operation: "run",
|
|
17151
17384
|
status: researchOutcomeStatus(final.status),
|
|
17152
17385
|
// Batches re-dispatched at boot are the server's own; any other batch reports who asked.
|
|
17153
17386
|
...options.trigger ? { trigger: options.trigger, ...options.trigger === OutcomeTriggers.startup ? { surface: OutcomeSurfaces.system } : {} } : requested ?? { trigger: OutcomeTriggers.manual },
|
|
17154
|
-
...PROVIDER_NAMES.includes(
|
|
17387
|
+
...PROVIDER_NAMES.includes(telemetryProvider) ? { provider: telemetryProvider } : {},
|
|
17155
17388
|
...final.status === ResearchRunStatuses.completed ? {} : fatalReason ?? classifyProviderOutcomeError(queryFailure),
|
|
17156
17389
|
durationBucket: elapsed(),
|
|
17157
17390
|
counts: { queries: final.total, snapshots: final.completed, failures: final.failed }
|
|
@@ -17159,15 +17392,35 @@ async function executeResearchRun(db, registry, runId, projectId, options = {})
|
|
|
17159
17392
|
}
|
|
17160
17393
|
}
|
|
17161
17394
|
function researchOutcomeStatus(status) {
|
|
17162
|
-
|
|
17163
|
-
|
|
17395
|
+
switch (status) {
|
|
17396
|
+
case ResearchRunStatuses.completed:
|
|
17397
|
+
return OutcomeStatuses.succeeded;
|
|
17398
|
+
// Everything this dispatch could finish is in; the rest waits on upstream jobs.
|
|
17399
|
+
case ResearchRunStatuses.partial:
|
|
17400
|
+
case ResearchRunStatuses["waiting-upstream"]:
|
|
17401
|
+
return OutcomeStatuses.partial;
|
|
17402
|
+
case ResearchRunStatuses.failed:
|
|
17403
|
+
return OutcomeStatuses.failed;
|
|
17404
|
+
}
|
|
17164
17405
|
}
|
|
17165
17406
|
function incrementResearchProgress(db, runId, column) {
|
|
17166
17407
|
db.update(researchRuns).set({ [column]: sql11`${researchRuns[column]} + 1` }).where(eq29(researchRuns.id, runId)).run();
|
|
17167
17408
|
}
|
|
17168
17409
|
function markResearchQueryFailed(db, runId, queryId, error) {
|
|
17169
17410
|
const message = describeError(error);
|
|
17170
|
-
const
|
|
17411
|
+
const unfinished = and23(eq29(researchRunQueries.id, queryId), inArray12(researchRunQueries.status, unfinishedResearchQueryStatuses));
|
|
17412
|
+
if (error instanceof IncompleteAnswerError && error.resumable) {
|
|
17413
|
+
db.update(researchRunQueries).set({
|
|
17414
|
+
status: ResearchQueryStatuses["waiting-upstream"],
|
|
17415
|
+
upstreamJobId: error.evidence.completion.upstreamJobId,
|
|
17416
|
+
answerEvidence: error.evidence,
|
|
17417
|
+
searchQueries: error.evidence.searchQueries,
|
|
17418
|
+
error: null
|
|
17419
|
+
}).where(unfinished).run();
|
|
17420
|
+
return;
|
|
17421
|
+
}
|
|
17422
|
+
const incomplete = error instanceof IncompleteAnswerError ? { answerEvidence: error.evidence, answerText: error.answerText, rawResponse: error.rawResponse, searchQueries: error.evidence.searchQueries } : {};
|
|
17423
|
+
const failed = db.update(researchRunQueries).set({ status: ResearchQueryStatuses.failed, error: message, ...incomplete, finishedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(unfinished).run();
|
|
17171
17424
|
if (failed.changes === 1) incrementResearchProgress(db, runId, "failedQueries");
|
|
17172
17425
|
}
|
|
17173
17426
|
function markUnfinishedResearchQueriesFailed(db, runId, error) {
|
|
@@ -17177,13 +17430,15 @@ function finalizeResearchRun(db, runId, fatalError) {
|
|
|
17177
17430
|
const rows = db.select({ status: researchRunQueries.status }).from(researchRunQueries).where(eq29(researchRunQueries.researchRunId, runId)).all();
|
|
17178
17431
|
const completed = rows.filter((row) => row.status === ResearchQueryStatuses.completed).length;
|
|
17179
17432
|
const failed = rows.filter((row) => row.status === ResearchQueryStatuses.failed).length;
|
|
17180
|
-
const
|
|
17433
|
+
const waiting = rows.filter((row) => row.status === ResearchQueryStatuses["waiting-upstream"]).length;
|
|
17434
|
+
const status = finalResearchRunStatus(completed, failed, waiting);
|
|
17181
17435
|
db.update(researchRuns).set({
|
|
17182
17436
|
status,
|
|
17183
17437
|
completedQueries: completed,
|
|
17184
17438
|
failedQueries: failed,
|
|
17185
17439
|
error: fatalError ?? (failed === rows.length ? "Every research query failed." : null),
|
|
17186
|
-
|
|
17440
|
+
// A run waiting on upstream jobs has not finished.
|
|
17441
|
+
finishedAt: waiting > 0 ? null : (/* @__PURE__ */ new Date()).toISOString()
|
|
17187
17442
|
}).where(eq29(researchRuns.id, runId)).run();
|
|
17188
17443
|
return { status, total: rows.length, completed, failed };
|
|
17189
17444
|
}
|
|
@@ -17539,6 +17794,9 @@ function resolveDashboardRequirePassword(env, config) {
|
|
|
17539
17794
|
function resolveDashboardShowResourceLinks(env, config) {
|
|
17540
17795
|
return parseBooleanEnv(env.CANONRY_DASHBOARD_SHOW_RESOURCE_LINKS) ?? config.dashboard?.showResourceLinks ?? true;
|
|
17541
17796
|
}
|
|
17797
|
+
function resolveDashboardShowLocalAgentSetup(env, config) {
|
|
17798
|
+
return parseBooleanEnv(env.CANONRY_DASHBOARD_SHOW_LOCAL_AGENT_SETUP) ?? config.dashboard?.showLocalAgentSetup ?? true;
|
|
17799
|
+
}
|
|
17542
17800
|
function resolveDashboardManagedRunKinds(env, config) {
|
|
17543
17801
|
const configured = dashboardManagedRunKindsSchema.safeParse(config.dashboard?.managedRunKinds);
|
|
17544
17802
|
if (!configured.success) {
|
|
@@ -17578,8 +17836,29 @@ var API_ADAPTERS = [
|
|
|
17578
17836
|
claudeAdapter,
|
|
17579
17837
|
localAdapter,
|
|
17580
17838
|
perplexityAdapter,
|
|
17581
|
-
museAdapter
|
|
17839
|
+
museAdapter,
|
|
17840
|
+
openrouterAdapter,
|
|
17841
|
+
...answerServiceAdapters
|
|
17582
17842
|
];
|
|
17843
|
+
var PROVIDER_ROUTE_FAMILIES = routeFamiliesOf(API_ADAPTERS);
|
|
17844
|
+
var ANSWER_SERVICE_CATALOG = new Map(answerServiceDescriptors.map((descriptor) => [descriptor.id, answerServiceCatalogFields(descriptor)]));
|
|
17845
|
+
function providerAdapterInfo(adapter) {
|
|
17846
|
+
return {
|
|
17847
|
+
name: adapter.name,
|
|
17848
|
+
displayName: adapter.displayName,
|
|
17849
|
+
mode: adapter.mode,
|
|
17850
|
+
// An answer service takes a key only; its routes pin their profiles.
|
|
17851
|
+
modelConfigurable: adapter.mode === "api" && adapter.kind !== "answer-service",
|
|
17852
|
+
defaultModel: adapter.modelRegistry.defaultModel,
|
|
17853
|
+
knownModels: adapter.modelRegistry.knownModels,
|
|
17854
|
+
modelValidationPattern: adapter.modelRegistry.validationPattern,
|
|
17855
|
+
modelValidationHint: adapter.modelRegistry.validationHint,
|
|
17856
|
+
...adapter.kind ? { kind: adapter.kind } : {},
|
|
17857
|
+
...adapter.capabilities ? { capabilities: adapter.capabilities } : {},
|
|
17858
|
+
...adapter.routes ? { routes: adapter.routes } : {},
|
|
17859
|
+
...ANSWER_SERVICE_CATALOG.get(adapter.name)
|
|
17860
|
+
};
|
|
17861
|
+
}
|
|
17583
17862
|
var BROWSER_ADAPTERS = [cdpChatgptAdapter];
|
|
17584
17863
|
var adapterMap = Object.fromEntries(
|
|
17585
17864
|
API_ADAPTERS.map((a) => [a.name, a])
|
|
@@ -17612,7 +17891,8 @@ function providerSummaries(registry, config, includeBrowser = false) {
|
|
|
17612
17891
|
defaultModel: adapter.modelRegistry.defaultModel,
|
|
17613
17892
|
configured: Boolean(registry.get(adapter.name)),
|
|
17614
17893
|
quota: registry.get(adapter.name)?.config.quotaPolicy,
|
|
17615
|
-
vertexConfigured: adapter.name === ProviderNames.gemini ? Boolean(config.providers?.gemini?.vertexProject) : void 0
|
|
17894
|
+
vertexConfigured: adapter.name === ProviderNames.gemini ? Boolean(config.providers?.gemini?.vertexProject) : void 0,
|
|
17895
|
+
...adapter.kind ? { kind: adapter.kind } : {}
|
|
17616
17896
|
}));
|
|
17617
17897
|
}
|
|
17618
17898
|
function runtimePathIdentity(runtimePath) {
|
|
@@ -17738,7 +18018,7 @@ function applyLegacyCredentials(rows, config) {
|
|
|
17738
18018
|
function isLoopbackPeerAddress(address) {
|
|
17739
18019
|
if (!address) return false;
|
|
17740
18020
|
const normalized = address.toLowerCase().replace(/^::ffff:(?=\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)/, "");
|
|
17741
|
-
return
|
|
18021
|
+
return isIP2(normalized) !== 0 && isLoopbackBindHost(normalized);
|
|
17742
18022
|
}
|
|
17743
18023
|
function isDirectLocalRequest(request) {
|
|
17744
18024
|
if (request.raw.httpVersion !== "1.1") return false;
|
|
@@ -17769,7 +18049,7 @@ function configuresExternalAccess(trustProxy, basePath, ...configuredUrls) {
|
|
|
17769
18049
|
}
|
|
17770
18050
|
function isAllowedHost(host, allowedHosts) {
|
|
17771
18051
|
const normalized = host.trim().toLowerCase().replace(/^\[|\]$/g, "");
|
|
17772
|
-
return allowedHosts.has(normalized) ||
|
|
18052
|
+
return allowedHosts.has(normalized) || isIP2(normalized) !== 0;
|
|
17773
18053
|
}
|
|
17774
18054
|
function buildAllowedHosts(bindHost, ...configuredUrls) {
|
|
17775
18055
|
const allowed = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1"]);
|
|
@@ -18497,6 +18777,7 @@ async function createServer(opts) {
|
|
|
18497
18777
|
// Same source of truth the HTTP routes use, so a scheduled sweep resolves
|
|
18498
18778
|
// "all configured providers" exactly as a hand-triggered one does.
|
|
18499
18779
|
getRunnableProviderNames: () => registry.getAll().map((provider) => provider.adapter.name),
|
|
18780
|
+
getProviderRouteFamilies: () => PROVIDER_ROUTE_FAMILIES,
|
|
18500
18781
|
getEffectiveProviderModels: () => effectiveProviderModels(registry),
|
|
18501
18782
|
getBatchEligibleProviderNames: () => batchEligibleProviderNames(registry),
|
|
18502
18783
|
onTrafficSyncRequested: (projectName, sourceId) => {
|
|
@@ -18630,8 +18911,8 @@ async function createServer(opts) {
|
|
|
18630
18911
|
getConnection: (projectName) => {
|
|
18631
18912
|
return getCloudRunConnection(opts.config, projectName);
|
|
18632
18913
|
},
|
|
18633
|
-
upsertConnection: (
|
|
18634
|
-
const updated = upsertCloudRunConnection(opts.config,
|
|
18914
|
+
upsertConnection: (record) => {
|
|
18915
|
+
const updated = upsertCloudRunConnection(opts.config, record);
|
|
18635
18916
|
saveConfigPatch(opts.config);
|
|
18636
18917
|
return updated;
|
|
18637
18918
|
},
|
|
@@ -18645,8 +18926,8 @@ async function createServer(opts) {
|
|
|
18645
18926
|
getConnection: (projectName) => {
|
|
18646
18927
|
return getWordpressTrafficConnection(opts.config, projectName);
|
|
18647
18928
|
},
|
|
18648
|
-
upsertConnection: (
|
|
18649
|
-
const updated = upsertWordpressTrafficConnection(opts.config,
|
|
18929
|
+
upsertConnection: (record) => {
|
|
18930
|
+
const updated = upsertWordpressTrafficConnection(opts.config, record);
|
|
18650
18931
|
saveConfigPatch(opts.config);
|
|
18651
18932
|
return updated;
|
|
18652
18933
|
},
|
|
@@ -18663,8 +18944,8 @@ async function createServer(opts) {
|
|
|
18663
18944
|
getConnection: (projectName) => {
|
|
18664
18945
|
return getVercelTrafficConnection(opts.config, projectName);
|
|
18665
18946
|
},
|
|
18666
|
-
upsertConnection: (
|
|
18667
|
-
const updated = upsertVercelTrafficConnection(opts.config,
|
|
18947
|
+
upsertConnection: (record) => {
|
|
18948
|
+
const updated = upsertVercelTrafficConnection(opts.config, record);
|
|
18668
18949
|
saveConfigPatch(opts.config);
|
|
18669
18950
|
return updated;
|
|
18670
18951
|
},
|
|
@@ -18681,8 +18962,8 @@ async function createServer(opts) {
|
|
|
18681
18962
|
getConnectionBySourceId: (sourceId) => {
|
|
18682
18963
|
return getCloudflareTrafficConnectionBySourceId(opts.config, sourceId);
|
|
18683
18964
|
},
|
|
18684
|
-
upsertConnection: (
|
|
18685
|
-
const updated = upsertCloudflareTrafficConnection(opts.config,
|
|
18965
|
+
upsertConnection: (record) => {
|
|
18966
|
+
const updated = upsertCloudflareTrafficConnection(opts.config, record);
|
|
18686
18967
|
saveConfigPatch(opts.config);
|
|
18687
18968
|
return updated;
|
|
18688
18969
|
},
|
|
@@ -18750,7 +19031,7 @@ async function createServer(opts) {
|
|
|
18750
19031
|
}
|
|
18751
19032
|
};
|
|
18752
19033
|
const rawBasePath = process.env.CANONRY_BASE_PATH ?? opts.config.basePath;
|
|
18753
|
-
const normalizedBasePath = rawBasePath ? "/" + rawBasePath.replace(/^\//, "").replace(/\/?$/, "/") : void 0;
|
|
19034
|
+
const normalizedBasePath = rawBasePath && rawBasePath !== "/" ? "/" + rawBasePath.replace(/^\//, "").replace(/\/?$/, "/") : void 0;
|
|
18754
19035
|
const basePath = normalizedBasePath === "/" ? void 0 : normalizedBasePath;
|
|
18755
19036
|
const embedCsp = embed.enabled ? frameAncestorsHeaderValue(embed.allowedOrigins) : void 0;
|
|
18756
19037
|
const unsupportedProjectTabs = unsupportedEmbedProjectTabs(embed.projectTabs);
|
|
@@ -18765,6 +19046,7 @@ async function createServer(opts) {
|
|
|
18765
19046
|
}
|
|
18766
19047
|
const dashboardRequirePassword = resolveDashboardRequirePassword(process.env, opts.config);
|
|
18767
19048
|
const dashboardShowResourceLinks = resolveDashboardShowResourceLinks(process.env, opts.config);
|
|
19049
|
+
const dashboardShowLocalAgentSetup = resolveDashboardShowLocalAgentSetup(process.env, opts.config);
|
|
18768
19050
|
const dashboardShowUpdateNotification = resolveDashboardShowUpdateNotification(process.env, opts.config);
|
|
18769
19051
|
const dashboardOnboardingMode = resolveDashboardOnboardingMode(process.env, opts.config);
|
|
18770
19052
|
const researchAllowViewers = resolveResearchAllowViewers(process.env, opts.config);
|
|
@@ -18774,6 +19056,12 @@ async function createServer(opts) {
|
|
|
18774
19056
|
"Dashboard password gate resolved"
|
|
18775
19057
|
);
|
|
18776
19058
|
const apiPrefix = basePath ? `${basePath}api/v1` : "/api/v1";
|
|
19059
|
+
const authorizationPath = `${basePath ?? "/"}oauth/authorize`;
|
|
19060
|
+
const getMcpHealth = () => mcpHttpHealth(app, apiPrefix, {
|
|
19061
|
+
publicUrl: opts.config.publicUrl,
|
|
19062
|
+
hasAccounts: anyUsersExist(opts.db),
|
|
19063
|
+
authorizationPath
|
|
19064
|
+
});
|
|
18777
19065
|
const credentialChecker = createCredentialChecker({
|
|
18778
19066
|
db: opts.db,
|
|
18779
19067
|
trustProxyConfigured: trustProxy !== false
|
|
@@ -19086,7 +19374,7 @@ async function createServer(opts) {
|
|
|
19086
19374
|
};
|
|
19087
19375
|
const sentimentWorker = new SentimentWorker(opts.db, {
|
|
19088
19376
|
configuration: loadSentimentInstallConfig,
|
|
19089
|
-
classifier: (configuration) =>
|
|
19377
|
+
classifier: (configuration) => createConfiguredSentimentClassifier(configuration, registry, loadSentimentInstallConfig),
|
|
19090
19378
|
prepare: (input) => {
|
|
19091
19379
|
const built = buildJevSentimentRequest(input);
|
|
19092
19380
|
return built.ok ? { ok: true, estimatedInputTokens: built.estimate.inputTokens } : built;
|
|
@@ -19218,6 +19506,17 @@ async function createServer(opts) {
|
|
|
19218
19506
|
await sentimentPoller.settled();
|
|
19219
19507
|
});
|
|
19220
19508
|
const providerModelCatalog = createProviderModelCatalog(registry);
|
|
19509
|
+
const aeroOpenRouterCatalog = providerModelCatalog.orUnregistered(() => {
|
|
19510
|
+
const apiKey = resolveApiKeyFor(ProviderNames.openrouter, opts.config);
|
|
19511
|
+
return apiKey ? { adapter: openrouterAdapter, config: { provider: ProviderNames.openrouter, apiKey, quotaPolicy: DEFAULT_PROVIDER_QUOTA } } : void 0;
|
|
19512
|
+
});
|
|
19513
|
+
const disconnectOpenRouterModels = openRouterModels.connect({
|
|
19514
|
+
read: () => aeroOpenRouterCatalog.read(ProviderNames.openrouter),
|
|
19515
|
+
cached: () => aeroOpenRouterCatalog.cached(ProviderNames.openrouter)
|
|
19516
|
+
});
|
|
19517
|
+
app.addHook("onClose", async () => {
|
|
19518
|
+
disconnectOpenRouterModels();
|
|
19519
|
+
});
|
|
19221
19520
|
const recordProviderChange = (name, before, after, auditContext) => {
|
|
19222
19521
|
const beforeConfig = summarizeProviderConfig(before);
|
|
19223
19522
|
const afterConfig = summarizeProviderConfig(after);
|
|
@@ -19254,7 +19553,7 @@ async function createServer(opts) {
|
|
|
19254
19553
|
sentiment: {
|
|
19255
19554
|
install: () => {
|
|
19256
19555
|
const configuration = loadSentimentInstallConfig();
|
|
19257
|
-
return { ...sentimentInstallReadiness(configuration), model: configuration.model };
|
|
19556
|
+
return { ...sentimentInstallReadiness(configuration), model: configuration.model, provider: configuration.provider };
|
|
19258
19557
|
},
|
|
19259
19558
|
previewSecret: opts.config.apiKey,
|
|
19260
19559
|
estimate: (input) => {
|
|
@@ -19328,6 +19627,7 @@ async function createServer(opts) {
|
|
|
19328
19627
|
// Local-only Aero agent routes. Registered here so they inherit api-routes'
|
|
19329
19628
|
// auth plugin — bare `registerAgentRoutes(app, ...)` would skip auth.
|
|
19330
19629
|
credentials: credentialChecker,
|
|
19630
|
+
getMcpHealth,
|
|
19331
19631
|
oauthResourceUrl: publicOrigin ? `${publicOrigin}${`${basePath ?? "/"}api/v1/mcp`.replace("//", "/")}` : void 0,
|
|
19332
19632
|
registerAuthenticatedRoutes: async (scope) => {
|
|
19333
19633
|
registerMcpHttpRoutes(scope, {
|
|
@@ -19511,6 +19811,7 @@ async function createServer(opts) {
|
|
|
19511
19811
|
executeDiscoveryRun({
|
|
19512
19812
|
db: opts.db,
|
|
19513
19813
|
registry,
|
|
19814
|
+
getClassifierConfig: () => loadConfig(runtimeConfigPath),
|
|
19514
19815
|
runId: input.runId,
|
|
19515
19816
|
sessionId: input.sessionId,
|
|
19516
19817
|
projectId: input.projectId,
|
|
@@ -19586,16 +19887,7 @@ async function createServer(opts) {
|
|
|
19586
19887
|
providerSummary,
|
|
19587
19888
|
getProviderModels: providerModelCatalog,
|
|
19588
19889
|
getCachedProviderModels: providerModelCatalog.cached,
|
|
19589
|
-
providerAdapters: [...API_ADAPTERS, ...BROWSER_ADAPTERS].map(
|
|
19590
|
-
name: a.name,
|
|
19591
|
-
displayName: a.displayName,
|
|
19592
|
-
mode: a.mode,
|
|
19593
|
-
modelConfigurable: a.mode === "api",
|
|
19594
|
-
defaultModel: a.modelRegistry.defaultModel,
|
|
19595
|
-
knownModels: a.modelRegistry.knownModels,
|
|
19596
|
-
modelValidationPattern: a.modelRegistry.validationPattern,
|
|
19597
|
-
modelValidationHint: a.modelRegistry.validationHint
|
|
19598
|
-
})),
|
|
19890
|
+
providerAdapters: [...API_ADAPTERS, ...BROWSER_ADAPTERS].map(providerAdapterInfo),
|
|
19599
19891
|
googleSettingsSummary,
|
|
19600
19892
|
bingSettingsSummary,
|
|
19601
19893
|
bingConnectionStore,
|
|
@@ -19685,17 +19977,20 @@ async function createServer(opts) {
|
|
|
19685
19977
|
onProviderUpdate: (providerName, apiKey, model, baseUrl, incomingQuota, auditContext) => {
|
|
19686
19978
|
const name = providerName;
|
|
19687
19979
|
if (!adapterMap[name]) return null;
|
|
19980
|
+
const adapterDefaultQuota = adapterMap[name].defaultQuota ?? DEFAULT_QUOTA;
|
|
19981
|
+
const answerService = adapterMap[name].kind === "answer-service";
|
|
19688
19982
|
if (!opts.config.providers) opts.config.providers = {};
|
|
19689
19983
|
const existing = opts.config.providers[name];
|
|
19690
19984
|
const previousProvider = registry.get(name) ?? (existing ? {
|
|
19691
19985
|
adapter: adapterMap[name],
|
|
19692
|
-
config: providerConfigFromEntry(name, existing, resolveProviderQuotaPolicy(existing.quota,
|
|
19986
|
+
config: providerConfigFromEntry(name, existing, resolveProviderQuotaPolicy(existing.quota, adapterDefaultQuota))
|
|
19693
19987
|
} : void 0);
|
|
19694
|
-
const mergedQuota = incomingQuota ? { ...existing?.quota ??
|
|
19988
|
+
const mergedQuota = incomingQuota ? { ...existing?.quota ?? adapterDefaultQuota, ...incomingQuota } : existing?.quota;
|
|
19695
19989
|
opts.config.providers[name] = {
|
|
19696
19990
|
apiKey: apiKey || existing?.apiKey,
|
|
19697
|
-
|
|
19698
|
-
|
|
19991
|
+
// An answer service's endpoint is fixed and its routes pin profiles.
|
|
19992
|
+
baseUrl: answerService ? void 0 : baseUrl || existing?.baseUrl,
|
|
19993
|
+
model: answerService ? void 0 : model || existing?.model,
|
|
19699
19994
|
quota: mergedQuota,
|
|
19700
19995
|
// Preserve Vertex AI config (Gemini provider) — these are set via
|
|
19701
19996
|
// config file or env vars, not through the dashboard update payload
|
|
@@ -19713,7 +20008,7 @@ async function createServer(opts) {
|
|
|
19713
20008
|
app.log.error({ err }, "Failed to save config");
|
|
19714
20009
|
return null;
|
|
19715
20010
|
}
|
|
19716
|
-
const quota = resolveProviderQuotaPolicy(opts.config.providers[name].quota,
|
|
20011
|
+
const quota = resolveProviderQuotaPolicy(opts.config.providers[name].quota, adapterDefaultQuota);
|
|
19717
20012
|
registry.register(adapterMap[name], providerConfigFromEntry(name, opts.config.providers[name], quota));
|
|
19718
20013
|
providerSummary.splice(0, providerSummary.length, ...providerSummaries(registry, opts.config));
|
|
19719
20014
|
const entry = providerSummary.find((provider) => provider.name === name);
|
|
@@ -19848,6 +20143,8 @@ async function createServer(opts) {
|
|
|
19848
20143
|
const provider = registry.get(providerName);
|
|
19849
20144
|
if (!provider)
|
|
19850
20145
|
throw new Error(`Provider "${providerName}" is not configured`);
|
|
20146
|
+
if (!canGenerateText(provider.adapter))
|
|
20147
|
+
throw validationError(`${provider.adapter.displayName} cannot generate queries. Choose a provider that generates text.`);
|
|
19851
20148
|
const siteText = await fetchSiteText(project.domain);
|
|
19852
20149
|
const prompt = buildQueryGenerationPrompt({
|
|
19853
20150
|
domain: project.domain,
|
|
@@ -19879,6 +20176,9 @@ async function createServer(opts) {
|
|
|
19879
20176
|
if (!dashboardShowResourceLinks) {
|
|
19880
20177
|
dashboardConfig.showResourceLinks = false;
|
|
19881
20178
|
}
|
|
20179
|
+
if (!dashboardShowLocalAgentSetup) {
|
|
20180
|
+
dashboardConfig.showLocalAgentSetup = false;
|
|
20181
|
+
}
|
|
19882
20182
|
if (!dashboardShowUpdateNotification) {
|
|
19883
20183
|
dashboardConfig.showUpdateNotification = false;
|
|
19884
20184
|
}
|
|
@@ -19994,7 +20294,7 @@ async function createServer(opts) {
|
|
|
19994
20294
|
status: "ok",
|
|
19995
20295
|
service: "canonry",
|
|
19996
20296
|
version: PKG_VERSION,
|
|
19997
|
-
mcp:
|
|
20297
|
+
mcp: getMcpHealth(),
|
|
19998
20298
|
...buildCommit ? { commit: buildCommit } : {},
|
|
19999
20299
|
...instance ? { instance } : {},
|
|
20000
20300
|
...basePath ? { basePath: basePath.replace(/\/$/, "") } : {},
|
|
@@ -20005,6 +20305,7 @@ async function createServer(opts) {
|
|
|
20005
20305
|
registerOAuthRoutes(app, {
|
|
20006
20306
|
db: opts.db,
|
|
20007
20307
|
issuer: publicOrigin,
|
|
20308
|
+
authorizationPath,
|
|
20008
20309
|
resourcePaths: mcpTransportPaths().map(
|
|
20009
20310
|
(suffix) => `${basePath ?? "/"}api/v1${suffix}`.replace("//", "/")
|
|
20010
20311
|
),
|
|
@@ -20028,7 +20329,7 @@ async function createServer(opts) {
|
|
|
20028
20329
|
return serializeUserSessionCookie({
|
|
20029
20330
|
value: token,
|
|
20030
20331
|
path: basePath ?? "/",
|
|
20031
|
-
secure:
|
|
20332
|
+
secure: sessionCookieSecure
|
|
20032
20333
|
});
|
|
20033
20334
|
}
|
|
20034
20335
|
});
|