@farming-labs/theme 0.1.137 → 0.1.138

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.
Files changed (2) hide show
  1. package/dist/docs-api.mjs +48 -6
  2. package/package.json +2 -2
package/dist/docs-api.mjs CHANGED
@@ -1301,8 +1301,13 @@ function safeUrlOrigin(value) {
1301
1301
  return value;
1302
1302
  }
1303
1303
  }
1304
+ function getRequestAnalyticsProperties(request) {
1305
+ const userAgent = request.headers.get("user-agent")?.trim();
1306
+ return userAgent ? { userAgent } : {};
1307
+ }
1304
1308
  async function handleAskAI(request, indexes, aiConfig, search, analytics, observability, analyticsContext = {}) {
1305
1309
  const url = new URL(request.url);
1310
+ const requestAnalyticsProperties = getRequestAnalyticsProperties(request);
1306
1311
  const requestStartedAt = Date.now();
1307
1312
  const trace = createDocsAgentTraceContext("ask-ai");
1308
1313
  const runSpanId = createDocsAgentTraceId("span");
@@ -1373,6 +1378,7 @@ async function handleAskAI(request, indexes, aiConfig, search, analytics, observ
1373
1378
  path: url.pathname,
1374
1379
  locale: analyticsContext.locale,
1375
1380
  properties: {
1381
+ ...requestAnalyticsProperties,
1376
1382
  reason: "invalid_json",
1377
1383
  durationMs: Math.max(0, Date.now() - requestStartedAt)
1378
1384
  }
@@ -1389,6 +1395,7 @@ async function handleAskAI(request, indexes, aiConfig, search, analytics, observ
1389
1395
  path: url.pathname,
1390
1396
  locale: analyticsContext.locale,
1391
1397
  properties: {
1398
+ ...requestAnalyticsProperties,
1392
1399
  reason: "missing_messages",
1393
1400
  durationMs: Math.max(0, Date.now() - requestStartedAt)
1394
1401
  }
@@ -1405,6 +1412,7 @@ async function handleAskAI(request, indexes, aiConfig, search, analytics, observ
1405
1412
  path: url.pathname,
1406
1413
  locale: analyticsContext.locale,
1407
1414
  properties: {
1415
+ ...requestAnalyticsProperties,
1408
1416
  reason: "missing_user_message",
1409
1417
  messageCount: messages.length,
1410
1418
  durationMs: Math.max(0, Date.now() - requestStartedAt)
@@ -1515,6 +1523,7 @@ async function handleAskAI(request, indexes, aiConfig, search, analytics, observ
1515
1523
  locale: analyticsContext.locale,
1516
1524
  input: { question: query },
1517
1525
  properties: {
1526
+ ...requestAnalyticsProperties,
1518
1527
  reason: "missing_api_key",
1519
1528
  messageCount: messages.length,
1520
1529
  questionLength: query.length,
@@ -1540,6 +1549,7 @@ async function handleAskAI(request, indexes, aiConfig, search, analytics, observ
1540
1549
  locale: analyticsContext.locale,
1541
1550
  input: { question: query },
1542
1551
  properties: {
1552
+ ...requestAnalyticsProperties,
1543
1553
  messageCount: messages.length,
1544
1554
  questionLength: query.length,
1545
1555
  retrievedCount: scored.length,
@@ -1603,6 +1613,7 @@ async function handleAskAI(request, indexes, aiConfig, search, analytics, observ
1603
1613
  locale: analyticsContext.locale,
1604
1614
  input: { question: query },
1605
1615
  properties: {
1616
+ ...requestAnalyticsProperties,
1606
1617
  reason: "llm_fetch_error",
1607
1618
  messageCount: messages.length,
1608
1619
  questionLength: query.length,
@@ -1648,6 +1659,7 @@ async function handleAskAI(request, indexes, aiConfig, search, analytics, observ
1648
1659
  locale: analyticsContext.locale,
1649
1660
  input: { question: query },
1650
1661
  properties: {
1662
+ ...requestAnalyticsProperties,
1651
1663
  reason: "llm_error",
1652
1664
  status: llmResponse.status,
1653
1665
  messageCount: messages.length,
@@ -1675,6 +1687,7 @@ async function handleAskAI(request, indexes, aiConfig, search, analytics, observ
1675
1687
  locale: analyticsContext.locale,
1676
1688
  input: { question: query },
1677
1689
  properties: {
1690
+ ...requestAnalyticsProperties,
1678
1691
  messageCount: messages.length,
1679
1692
  questionLength: query.length,
1680
1693
  retrievedCount: scored.length,
@@ -2074,6 +2087,7 @@ function createDocsAPI(options) {
2074
2087
  async GET(request) {
2075
2088
  const ctx = resolveContextFromRequest(request);
2076
2089
  const url = new URL(request.url);
2090
+ const requestAnalyticsProperties = getRequestAnalyticsProperties(request);
2077
2091
  if (resolveAgentSpecRequest(url)) {
2078
2092
  await emitDocsAnalyticsEvent(analytics, {
2079
2093
  type: "agent_spec_request",
@@ -2081,7 +2095,10 @@ function createDocsAPI(options) {
2081
2095
  url: request.url,
2082
2096
  path: url.pathname,
2083
2097
  locale: ctx.locale,
2084
- properties: { method: "GET" }
2098
+ properties: {
2099
+ ...requestAnalyticsProperties,
2100
+ method: "GET"
2101
+ }
2085
2102
  });
2086
2103
  return Response.json(buildAgentSpec({
2087
2104
  origin: url.origin,
@@ -2130,7 +2147,10 @@ function createDocsAPI(options) {
2130
2147
  url: request.url,
2131
2148
  path: url.pathname,
2132
2149
  locale: ctx.locale,
2133
- properties: { method: "GET" }
2150
+ properties: {
2151
+ ...requestAnalyticsProperties,
2152
+ method: "GET"
2153
+ }
2134
2154
  });
2135
2155
  return new Response(JSON.stringify(agentFeedbackConfig.schema, null, 2), { headers: {
2136
2156
  "Content-Type": "application/schema+json; charset=utf-8",
@@ -2145,7 +2165,10 @@ function createDocsAPI(options) {
2145
2165
  url: request.url,
2146
2166
  path: url.pathname,
2147
2167
  locale: ctx.locale,
2148
- properties: { method: "GET" }
2168
+ properties: {
2169
+ ...requestAnalyticsProperties,
2170
+ method: "GET"
2171
+ }
2149
2172
  });
2150
2173
  return new Response(readRootAgentsDocument(root) ?? renderAgentsDocument({
2151
2174
  origin: url.origin,
@@ -2170,7 +2193,10 @@ function createDocsAPI(options) {
2170
2193
  url: request.url,
2171
2194
  path: url.pathname,
2172
2195
  locale: ctx.locale,
2173
- properties: { method: "GET" }
2196
+ properties: {
2197
+ ...requestAnalyticsProperties,
2198
+ method: "GET"
2199
+ }
2174
2200
  });
2175
2201
  return new Response(readRootSkillDocument(root) ?? renderSkillDocument({
2176
2202
  origin: url.origin,
@@ -2232,6 +2258,7 @@ function createDocsAPI(options) {
2232
2258
  path: url.pathname,
2233
2259
  locale: ctx.locale,
2234
2260
  properties: {
2261
+ ...requestAnalyticsProperties,
2235
2262
  requestedPath: markdownRequest.requestedPath,
2236
2263
  delivery: markdownRequest.delivery,
2237
2264
  found: false
@@ -2244,6 +2271,7 @@ function createDocsAPI(options) {
2244
2271
  path: url.pathname,
2245
2272
  locale: ctx.locale,
2246
2273
  properties: {
2274
+ ...requestAnalyticsProperties,
2247
2275
  requestedPath: markdownRequest.requestedPath,
2248
2276
  delivery: markdownRequest.delivery,
2249
2277
  found: false
@@ -2279,6 +2307,7 @@ function createDocsAPI(options) {
2279
2307
  path: url.pathname,
2280
2308
  locale: ctx.locale,
2281
2309
  properties: {
2310
+ ...requestAnalyticsProperties,
2282
2311
  requestedPath: markdownRequest.requestedPath,
2283
2312
  delivery: markdownRequest.delivery,
2284
2313
  found: true,
@@ -2292,6 +2321,7 @@ function createDocsAPI(options) {
2292
2321
  path: url.pathname,
2293
2322
  locale: ctx.locale,
2294
2323
  properties: {
2324
+ ...requestAnalyticsProperties,
2295
2325
  requestedPath: markdownRequest.requestedPath,
2296
2326
  delivery: markdownRequest.delivery,
2297
2327
  found: true,
@@ -2339,6 +2369,7 @@ function createDocsAPI(options) {
2339
2369
  path: url.pathname,
2340
2370
  locale: ctx.locale,
2341
2371
  properties: {
2372
+ ...requestAnalyticsProperties,
2342
2373
  format: llmsRequest.format,
2343
2374
  section: llmsRequest.section?.route,
2344
2375
  contentLength: selected.content.length
@@ -2368,6 +2399,7 @@ function createDocsAPI(options) {
2368
2399
  locale: ctx.locale,
2369
2400
  input: { query },
2370
2401
  properties: {
2402
+ ...requestAnalyticsProperties,
2371
2403
  queryLength: query.length,
2372
2404
  resultCount: results.length,
2373
2405
  pathname: url.searchParams.get("pathname") ?? void 0,
@@ -2378,6 +2410,7 @@ function createDocsAPI(options) {
2378
2410
  },
2379
2411
  async POST(request) {
2380
2412
  const url = new URL(request.url);
2413
+ const requestAnalyticsProperties = getRequestAnalyticsProperties(request);
2381
2414
  const agentFeedbackRequest = resolveAgentFeedbackRequest(url, agentFeedbackConfig);
2382
2415
  if (agentFeedbackRequest) {
2383
2416
  if (agentFeedbackRequest.kind === "schema") return Response.json({ error: "Method Not Allowed" }, {
@@ -2391,7 +2424,10 @@ function createDocsAPI(options) {
2391
2424
  source: "server",
2392
2425
  url: request.url,
2393
2426
  path: url.pathname,
2394
- properties: { reason: "invalid_body" }
2427
+ properties: {
2428
+ ...requestAnalyticsProperties,
2429
+ reason: "invalid_body"
2430
+ }
2395
2431
  });
2396
2432
  return parsed.response;
2397
2433
  }
@@ -2403,6 +2439,7 @@ function createDocsAPI(options) {
2403
2439
  url: request.url,
2404
2440
  path: url.pathname,
2405
2441
  properties: {
2442
+ ...requestAnalyticsProperties,
2406
2443
  reason: "invalid_payload",
2407
2444
  error: payloadError
2408
2445
  }
@@ -2416,6 +2453,7 @@ function createDocsAPI(options) {
2416
2453
  url: request.url,
2417
2454
  path: url.pathname,
2418
2455
  properties: {
2456
+ ...requestAnalyticsProperties,
2419
2457
  handled: false,
2420
2458
  payloadKeys: Object.keys(parsed.data.payload),
2421
2459
  hasContext: Boolean(parsed.data.context)
@@ -2433,6 +2471,7 @@ function createDocsAPI(options) {
2433
2471
  url: request.url,
2434
2472
  path: url.pathname,
2435
2473
  properties: {
2474
+ ...requestAnalyticsProperties,
2436
2475
  handled: true,
2437
2476
  payloadKeys: Object.keys(parsed.data.payload),
2438
2477
  hasContext: Boolean(parsed.data.context)
@@ -2449,7 +2488,10 @@ function createDocsAPI(options) {
2449
2488
  source: "server",
2450
2489
  url: request.url,
2451
2490
  path: url.pathname,
2452
- properties: { reason: "disabled" }
2491
+ properties: {
2492
+ ...requestAnalyticsProperties,
2493
+ reason: "disabled"
2494
+ }
2453
2495
  });
2454
2496
  return Response.json({ error: "AI is not enabled. Set `ai: { enabled: true }` in your docs.config to enable it." }, { status: 404 });
2455
2497
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.1.137",
3
+ "version": "0.1.138",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -139,7 +139,7 @@
139
139
  "tsdown": "^0.20.3",
140
140
  "typescript": "^5.9.3",
141
141
  "vitest": "^3.2.4",
142
- "@farming-labs/docs": "0.1.137"
142
+ "@farming-labs/docs": "0.1.138"
143
143
  },
144
144
  "peerDependencies": {
145
145
  "@farming-labs/docs": ">=0.0.1",