githits 0.2.0 → 0.2.2

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  version
3
- } from "./chunk-fa4571ch.js";
3
+ } from "./chunk-g6ay6x9v.js";
4
4
 
5
5
  // src/services/auth-service.ts
6
6
  import { createServer } from "node:http";
@@ -602,14 +602,22 @@ function debugLog(area, payload) {
602
602
  process.stderr.write(`${text}
603
603
  `);
604
604
  }
605
+ function isDebugAreaEnabled(area) {
606
+ return isAreaEnabled(area);
607
+ }
605
608
  function isAreaEnabled(area) {
606
609
  const raw = process.env.GITHITS_DEBUG;
607
610
  if (!raw || raw === "")
608
611
  return false;
609
- if (raw === "*")
610
- return true;
611
612
  const scopes = raw.split(",").map((s) => s.trim()).filter(Boolean);
612
- return scopes.includes(area) || scopes.includes("*");
613
+ if (scopes.includes(area))
614
+ return true;
615
+ if (isExplicitOnlyArea(area))
616
+ return false;
617
+ return scopes.includes("*");
618
+ }
619
+ function isExplicitOnlyArea(area) {
620
+ return area === "code-nav-wire";
613
621
  }
614
622
 
615
623
  // src/shared/request-headers.ts
@@ -1199,84 +1207,6 @@ class CodeNavigationBackendError extends Error {
1199
1207
  this.name = "CodeNavigationBackendError";
1200
1208
  }
1201
1209
  }
1202
-
1203
- class InvalidSearchSymbolsRequestError extends Error {
1204
- constructor(message) {
1205
- super(message);
1206
- this.name = "InvalidSearchSymbolsRequestError";
1207
- }
1208
- }
1209
- var SEARCH_SYMBOLS_QUERY = `
1210
- query SearchSymbols(
1211
- $registry: Registry
1212
- $packageName: String
1213
- $repoUrl: String
1214
- $gitRef: String
1215
- $query: String
1216
- $keywords: [String!]
1217
- $matchMode: MatchMode
1218
- $kind: SymbolKind
1219
- $category: SymbolCategory
1220
- $filePath: String
1221
- $version: String
1222
- $limit: Int
1223
- $fileIntent: FileIntent
1224
- $waitTimeoutMs: Int
1225
- ) {
1226
- searchSymbols(
1227
- registry: $registry
1228
- packageName: $packageName
1229
- repoUrl: $repoUrl
1230
- gitRef: $gitRef
1231
- query: $query
1232
- keywords: $keywords
1233
- matchMode: $matchMode
1234
- kind: $kind
1235
- category: $category
1236
- filePath: $filePath
1237
- version: $version
1238
- limit: $limit
1239
- fileIntent: $fileIntent
1240
- mode: DETAILED
1241
- waitTimeoutMs: $waitTimeoutMs
1242
- ) {
1243
- results {
1244
- name
1245
- filePath
1246
- startLine
1247
- endLine
1248
- preview
1249
- code
1250
- language
1251
- symbolRef
1252
- qualifiedPath
1253
- kind
1254
- category
1255
- arity
1256
- isPublic
1257
- containedSymbols
1258
- }
1259
- totalMatches
1260
- hasMore
1261
- indexedVersion
1262
- resolution {
1263
- requestedVersion
1264
- requestedRef
1265
- resolvedRef
1266
- commitSha
1267
- }
1268
- diagnostics {
1269
- hint
1270
- }
1271
- warning
1272
- codeIndexState
1273
- indexingRef
1274
- availableVersions {
1275
- version
1276
- ref
1277
- }
1278
- }
1279
- }`;
1280
1210
  var UNIFIED_SEARCH_QUERY = `
1281
1211
  query UnifiedSearch(
1282
1212
  $targets: [SearchPackageInput!]!
@@ -1320,8 +1250,11 @@ query UnifiedSearch(
1320
1250
  packageName
1321
1251
  version
1322
1252
  pageId
1253
+ sourceKind
1254
+ sourceUrl
1323
1255
  repoUrl
1324
1256
  gitRef
1257
+ requestedRef
1325
1258
  filePath
1326
1259
  startLine
1327
1260
  endLine
@@ -1400,8 +1333,11 @@ query UnifiedSearchStatus($searchRef: String!, $includeResults: Boolean!) {
1400
1333
  packageName
1401
1334
  version
1402
1335
  pageId
1336
+ sourceKind
1337
+ sourceUrl
1403
1338
  repoUrl
1404
1339
  gitRef
1340
+ requestedRef
1405
1341
  filePath
1406
1342
  startLine
1407
1343
  endLine
@@ -1437,45 +1373,57 @@ query UnifiedSearchStatus($searchRef: String!, $includeResults: Boolean!) {
1437
1373
  }
1438
1374
  }
1439
1375
  }`;
1376
+ function debugUnifiedSearchRequest(variables) {
1377
+ if (!isDebugAreaEnabled("code-nav"))
1378
+ return;
1379
+ const serialised = serialiseForDebug(variables);
1380
+ const filters = asRecord(serialised.filters);
1381
+ debugLog("code-nav", {
1382
+ event: "request",
1383
+ operation: "search",
1384
+ targetCount: Array.isArray(serialised.targets) ? serialised.targets.length : 0,
1385
+ sources: Array.isArray(serialised.sources) ? serialised.sources : [],
1386
+ hasFilters: filters !== undefined,
1387
+ filterKeys: filters ? Object.keys(filters).sort() : [],
1388
+ fileIntent: filters && typeof filters.fileIntent === "string" ? filters.fileIntent : "omitted",
1389
+ allowPartialResults: serialised.allowPartialResults === true,
1390
+ presentVariableKeys: Object.keys(serialised).sort(),
1391
+ hasLimit: typeof serialised.limit === "number",
1392
+ hasOffset: typeof serialised.offset === "number",
1393
+ waitTimeoutMs: typeof serialised.waitTimeoutMs === "number" ? serialised.waitTimeoutMs : undefined
1394
+ });
1395
+ }
1396
+ function debugGraphqlWireRequest(operation, graphqlQuery, variables) {
1397
+ if (!isDebugAreaEnabled("code-nav-wire"))
1398
+ return;
1399
+ debugLog("code-nav-wire", {
1400
+ event: "wire-request",
1401
+ operation,
1402
+ graphqlQuery,
1403
+ variables: serialiseForDebug(variables)
1404
+ });
1405
+ }
1406
+ function serialiseForDebug(value) {
1407
+ try {
1408
+ const text = JSON.stringify(value);
1409
+ if (!text)
1410
+ return {};
1411
+ const parsed = JSON.parse(text);
1412
+ return asRecord(parsed) ?? {};
1413
+ } catch {
1414
+ return {};
1415
+ }
1416
+ }
1417
+ function asRecord(value) {
1418
+ if (value && typeof value === "object" && !Array.isArray(value)) {
1419
+ return value;
1420
+ }
1421
+ return;
1422
+ }
1440
1423
  var availableVersionSchema = z.object({
1441
1424
  version: z.string().nullable().optional(),
1442
1425
  ref: z.string()
1443
1426
  });
1444
- var searchSymbolsResultEntrySchema = z.object({
1445
- name: z.string().nullable().optional(),
1446
- filePath: z.string().nullable().optional(),
1447
- startLine: z.number().int().nullable().optional(),
1448
- endLine: z.number().int().nullable().optional(),
1449
- preview: z.string().nullable().optional(),
1450
- code: z.string().nullable().optional(),
1451
- language: z.string().nullable().optional(),
1452
- symbolRef: z.string().nullable().optional(),
1453
- qualifiedPath: z.string().nullable().optional(),
1454
- kind: z.string().nullable().optional(),
1455
- category: z.string().nullable().optional(),
1456
- arity: z.number().int().nullable().optional(),
1457
- isPublic: z.boolean().nullable().optional(),
1458
- containedSymbols: z.number().int().nullable().optional()
1459
- });
1460
- var searchSymbolsResponseSchema = z.object({
1461
- results: z.array(searchSymbolsResultEntrySchema),
1462
- totalMatches: z.number().int(),
1463
- hasMore: z.boolean(),
1464
- indexedVersion: z.string().nullable().optional(),
1465
- resolution: z.object({
1466
- requestedVersion: z.string().nullable().optional(),
1467
- requestedRef: z.string().nullable().optional(),
1468
- resolvedRef: z.string().nullable().optional(),
1469
- commitSha: z.string().nullable().optional()
1470
- }).nullable().optional(),
1471
- diagnostics: z.object({
1472
- hint: z.string().nullable().optional()
1473
- }).nullable().optional(),
1474
- warning: z.string().nullable().optional(),
1475
- codeIndexState: z.string(),
1476
- indexingRef: z.string().nullable().optional(),
1477
- availableVersions: z.array(availableVersionSchema).nullable().optional()
1478
- });
1479
1427
  var unifiedSearchSourceSchema = z.enum(["AUTO", "DOCS", "CODE", "SYMBOL"]);
1480
1428
  var unifiedSearchResultTypeSchema = z.enum([
1481
1429
  "DOCUMENTATION_PAGE",
@@ -1488,8 +1436,11 @@ var unifiedSearchLocatorSchema = z.object({
1488
1436
  packageName: z.string().nullable().optional(),
1489
1437
  version: z.string().nullable().optional(),
1490
1438
  pageId: z.string().nullable().optional(),
1439
+ sourceKind: z.string().nullable().optional(),
1440
+ sourceUrl: z.string().nullable().optional(),
1491
1441
  repoUrl: z.string().nullable().optional(),
1492
1442
  gitRef: z.string().nullable().optional(),
1443
+ requestedRef: z.string().nullable().optional(),
1493
1444
  filePath: z.string().nullable().optional(),
1494
1445
  startLine: z.number().int().nullable().optional(),
1495
1446
  endLine: z.number().int().nullable().optional(),
@@ -1873,12 +1824,6 @@ query GrepRepo(
1873
1824
  }
1874
1825
  }`;
1875
1826
  }
1876
- var graphQLResponseSchema = z.object({
1877
- data: z.object({
1878
- searchSymbols: searchSymbolsResponseSchema.nullable().optional()
1879
- }).nullable().optional(),
1880
- errors: z.array(graphQLErrorSchema).optional()
1881
- });
1882
1827
  var unifiedSearchGraphQLResponseSchema = z.object({
1883
1828
  data: z.object({
1884
1829
  search: asyncUnifiedSearchResultSchema.nullable().optional()
@@ -1917,40 +1862,35 @@ class CodeNavigationServiceImpl {
1917
1862
  executeWithToken: (token) => this.executeUnifiedSearchStatus(token, searchRef)
1918
1863
  });
1919
1864
  }
1920
- async searchSymbols(params) {
1921
- return executeWithTokenRefresh({
1922
- getToken: () => this.tokenProvider.getToken(),
1923
- forceRefresh: () => this.tokenProvider.forceRefresh(),
1924
- shouldRefresh: (error) => error instanceof AuthenticationError,
1925
- executeWithToken: (token) => this.executeSearchSymbols(token, params)
1926
- });
1927
- }
1928
1865
  async executeUnifiedSearch(token, params) {
1929
1866
  if (params.targets.length === 0) {
1930
1867
  throw new CodeNavigationValidationError("At least one search target is required.");
1931
1868
  }
1932
1869
  let response;
1870
+ const variables = {
1871
+ targets: params.targets.map((target) => ({
1872
+ registry: target.registry,
1873
+ name: target.packageName,
1874
+ version: target.version,
1875
+ repoUrl: target.repoUrl,
1876
+ gitRef: target.gitRef
1877
+ })),
1878
+ query: params.query,
1879
+ sources: params.sources,
1880
+ filters: params.filters,
1881
+ allowPartialResults: params.allowPartialResults ?? false,
1882
+ limit: params.limit,
1883
+ offset: params.offset,
1884
+ waitTimeoutMs: params.waitTimeoutMs
1885
+ };
1886
+ debugUnifiedSearchRequest(variables);
1887
+ debugGraphqlWireRequest("search", UNIFIED_SEARCH_QUERY, variables);
1933
1888
  try {
1934
1889
  response = await postPkgseerGraphql({
1935
1890
  endpointUrl: this.codeNavigationUrl,
1936
1891
  token,
1937
1892
  query: UNIFIED_SEARCH_QUERY,
1938
- variables: {
1939
- targets: params.targets.map((target) => ({
1940
- registry: target.registry,
1941
- name: target.packageName,
1942
- version: target.version,
1943
- repoUrl: target.repoUrl,
1944
- gitRef: target.gitRef
1945
- })),
1946
- query: params.query,
1947
- sources: params.sources,
1948
- filters: params.filters,
1949
- allowPartialResults: params.allowPartialResults ?? false,
1950
- limit: params.limit,
1951
- offset: params.offset,
1952
- waitTimeoutMs: params.waitTimeoutMs
1953
- },
1893
+ variables,
1954
1894
  fetchFn: this.fetchFn
1955
1895
  });
1956
1896
  } catch (cause) {
@@ -2027,93 +1967,6 @@ class CodeNavigationServiceImpl {
2027
1967
  progress
2028
1968
  };
2029
1969
  }
2030
- async executeSearchSymbols(token, params) {
2031
- if (!params.query && (!params.keywords || params.keywords.length === 0)) {
2032
- throw new InvalidSearchSymbolsRequestError("Either query or keywords must be provided.");
2033
- }
2034
- let response;
2035
- try {
2036
- response = await postPkgseerGraphql({
2037
- endpointUrl: this.codeNavigationUrl,
2038
- token,
2039
- query: SEARCH_SYMBOLS_QUERY,
2040
- variables: {
2041
- registry: params.target.registry,
2042
- packageName: params.target.packageName,
2043
- repoUrl: params.target.repoUrl,
2044
- gitRef: params.target.gitRef,
2045
- query: params.query,
2046
- keywords: params.keywords,
2047
- matchMode: params.matchMode,
2048
- kind: params.kind,
2049
- category: params.category,
2050
- filePath: params.filePath,
2051
- version: params.target.version,
2052
- limit: params.limit,
2053
- fileIntent: params.fileIntent,
2054
- waitTimeoutMs: params.waitTimeoutMs
2055
- },
2056
- fetchFn: this.fetchFn
2057
- });
2058
- } catch (cause) {
2059
- if (cause instanceof PkgseerTransportError) {
2060
- throw new CodeNavigationNetworkError("Could not reach the code navigation service. Check your connection or set GITHITS_CODE_NAV_URL.", { cause });
2061
- }
2062
- throw cause;
2063
- }
2064
- if (response.status < 200 || response.status >= 300) {
2065
- throw this.createHttpError(response);
2066
- }
2067
- const parsed = graphQLResponseSchema.safeParse(response.parsedBody);
2068
- if (!parsed.success) {
2069
- throw new MalformedCodeNavigationResponseError("Malformed response from code navigation service.");
2070
- }
2071
- if (parsed.data.errors && parsed.data.errors.length > 0) {
2072
- throw this.createGraphQLError(parsed.data.errors);
2073
- }
2074
- const data = parsed.data.data?.searchSymbols;
2075
- if (!data) {
2076
- throw new MalformedCodeNavigationResponseError("Malformed response from code navigation service.");
2077
- }
2078
- if (data.codeIndexState === "INDEXING") {
2079
- throw new CodeNavigationIndexingError(this.createIndexingMessage(data.indexingRef ?? undefined), data.indexingRef ?? undefined, data.availableVersions?.map((entry) => ({
2080
- version: entry.version ?? undefined,
2081
- ref: entry.ref
2082
- })));
2083
- }
2084
- if (data.codeIndexState === "UNRESOLVABLE") {
2085
- throw new CodeNavigationUnresolvableError("The requested target or version could not be resolved.");
2086
- }
2087
- return {
2088
- results: data.results.map((entry) => ({
2089
- name: entry.name ?? undefined,
2090
- filePath: entry.filePath ?? undefined,
2091
- startLine: entry.startLine ?? undefined,
2092
- endLine: entry.endLine ?? undefined,
2093
- preview: entry.preview ?? undefined,
2094
- code: entry.code ?? undefined,
2095
- language: entry.language ?? undefined,
2096
- symbolRef: entry.symbolRef ?? undefined,
2097
- qualifiedPath: entry.qualifiedPath ?? undefined,
2098
- kind: entry.kind ?? undefined,
2099
- category: entry.category ?? undefined,
2100
- arity: entry.arity ?? undefined,
2101
- isPublic: entry.isPublic ?? undefined,
2102
- containedSymbols: entry.containedSymbols ?? undefined
2103
- })),
2104
- totalMatches: data.totalMatches,
2105
- hasMore: data.hasMore,
2106
- version: data.indexedVersion ?? undefined,
2107
- resolution: data.resolution ? {
2108
- requestedVersion: data.resolution.requestedVersion ?? undefined,
2109
- requestedRef: data.resolution.requestedRef ?? undefined,
2110
- resolvedRef: data.resolution.resolvedRef ?? undefined,
2111
- commitSha: data.resolution.commitSha ?? undefined
2112
- } : undefined,
2113
- hint: data.diagnostics?.hint ?? undefined,
2114
- warning: data.warning ?? undefined
2115
- };
2116
- }
2117
1970
  createHttpError(response) {
2118
1971
  const status = response.status;
2119
1972
  const detail = parseDetail2(response.responseBody);
@@ -2250,8 +2103,11 @@ class CodeNavigationServiceImpl {
2250
2103
  packageName: entry.locator.packageName ?? undefined,
2251
2104
  version: entry.locator.version ?? undefined,
2252
2105
  pageId: entry.locator.pageId ?? undefined,
2106
+ sourceKind: entry.locator.sourceKind ?? undefined,
2107
+ sourceUrl: entry.locator.sourceUrl ?? undefined,
2253
2108
  repoUrl: entry.locator.repoUrl ?? undefined,
2254
2109
  gitRef: entry.locator.gitRef ?? undefined,
2110
+ requestedRef: entry.locator.requestedRef ?? undefined,
2255
2111
  filePath: entry.locator.filePath ?? undefined,
2256
2112
  startLine: entry.locator.startLine ?? undefined,
2257
2113
  endLine: entry.locator.endLine ?? undefined,
@@ -3171,7 +3027,7 @@ var graphQLErrorSchema2 = z2.object({
3171
3027
  message: z2.string(),
3172
3028
  extensions: z2.record(z2.string(), z2.unknown()).optional()
3173
3029
  });
3174
- var graphQLResponseSchema2 = z2.object({
3030
+ var graphQLResponseSchema = z2.object({
3175
3031
  data: z2.object({
3176
3032
  packageSummary: packageSummaryResponseSchema.nullable().optional()
3177
3033
  }).nullable().optional(),
@@ -3539,6 +3395,141 @@ query PackageChangelog(
3539
3395
  }
3540
3396
  }
3541
3397
  }`;
3398
+ var packageDocSourceKindSchema = z2.enum(["CRAWLED", "REPOSITORY"]);
3399
+ var packageDocPageSummarySchema = z2.object({
3400
+ id: z2.string().nullable().optional(),
3401
+ title: z2.string().nullable().optional(),
3402
+ slug: z2.string().nullable().optional(),
3403
+ order: z2.number().int().nullable().optional(),
3404
+ linkName: z2.string().nullable().optional(),
3405
+ lastUpdatedAt: z2.string().nullable().optional(),
3406
+ sourceKind: packageDocSourceKindSchema.nullable().optional(),
3407
+ sourceUrl: z2.string().nullable().optional(),
3408
+ repoUrl: z2.string().nullable().optional(),
3409
+ gitRef: z2.string().nullable().optional(),
3410
+ requestedRef: z2.string().nullable().optional(),
3411
+ filePath: z2.string().nullable().optional()
3412
+ });
3413
+ var packageDocsPageInfoSchema = z2.object({
3414
+ hasNextPage: z2.boolean(),
3415
+ endCursor: z2.string().nullable().optional(),
3416
+ totalCount: z2.number().int().nullable().optional()
3417
+ }).nullable().optional();
3418
+ var packageDocsListResponseSchema = z2.object({
3419
+ registry: z2.string().nullable().optional(),
3420
+ packageName: z2.string().nullable().optional(),
3421
+ version: z2.string().nullable().optional(),
3422
+ stale: z2.boolean().nullable().optional(),
3423
+ pages: z2.array(packageDocPageSummarySchema).nullable().optional(),
3424
+ pageInfo: packageDocsPageInfoSchema
3425
+ });
3426
+ var packageDocSourceSchema = z2.object({
3427
+ url: z2.string().nullable().optional(),
3428
+ label: z2.string().nullable().optional()
3429
+ }).nullable().optional();
3430
+ var packageDocPageSchema = z2.object({
3431
+ id: z2.string().nullable().optional(),
3432
+ title: z2.string().nullable().optional(),
3433
+ content: z2.string().nullable().optional(),
3434
+ contentFormat: z2.string().nullable().optional(),
3435
+ breadcrumbs: z2.array(z2.string()).nullable().optional(),
3436
+ linkName: z2.string().nullable().optional(),
3437
+ lastUpdatedAt: z2.string().nullable().optional(),
3438
+ sourceKind: packageDocSourceKindSchema.nullable().optional(),
3439
+ source: packageDocSourceSchema,
3440
+ repoUrl: z2.string().nullable().optional(),
3441
+ gitRef: z2.string().nullable().optional(),
3442
+ requestedRef: z2.string().nullable().optional(),
3443
+ filePath: z2.string().nullable().optional(),
3444
+ baseUrl: z2.string().nullable().optional()
3445
+ }).nullable().optional();
3446
+ var packageDocResultResponseSchema = z2.object({
3447
+ registry: z2.string().nullable().optional(),
3448
+ packageName: z2.string().nullable().optional(),
3449
+ version: z2.string().nullable().optional(),
3450
+ sourceKind: packageDocSourceKindSchema.nullable().optional(),
3451
+ page: packageDocPageSchema
3452
+ });
3453
+ var packageDocsListGraphQLResponseSchema = z2.object({
3454
+ data: z2.object({
3455
+ listPackageDocs: packageDocsListResponseSchema.nullable().optional()
3456
+ }).nullable().optional(),
3457
+ errors: z2.array(graphQLErrorSchema2).optional()
3458
+ });
3459
+ var packageDocReadGraphQLResponseSchema = z2.object({
3460
+ data: z2.object({
3461
+ getDocPage: packageDocResultResponseSchema.nullable().optional()
3462
+ }).nullable().optional(),
3463
+ errors: z2.array(graphQLErrorSchema2).optional()
3464
+ });
3465
+ var LIST_PACKAGE_DOCS_QUERY = `
3466
+ query ListPackageDocs(
3467
+ $registry: Registry!
3468
+ $packageName: String!
3469
+ $version: String
3470
+ $limit: Int
3471
+ $after: String
3472
+ ) {
3473
+ listPackageDocs(
3474
+ registry: $registry
3475
+ packageName: $packageName
3476
+ version: $version
3477
+ limit: $limit
3478
+ after: $after
3479
+ ) {
3480
+ registry
3481
+ packageName
3482
+ version
3483
+ stale
3484
+ pages {
3485
+ id
3486
+ title
3487
+ slug
3488
+ order
3489
+ linkName
3490
+ lastUpdatedAt
3491
+ sourceKind
3492
+ sourceUrl
3493
+ repoUrl
3494
+ gitRef
3495
+ requestedRef
3496
+ filePath
3497
+ }
3498
+ pageInfo {
3499
+ hasNextPage
3500
+ endCursor
3501
+ totalCount
3502
+ }
3503
+ }
3504
+ }`;
3505
+ var READ_PACKAGE_DOC_QUERY = `
3506
+ query ReadPackageDoc($pageId: String!) {
3507
+ getDocPage(pageId: $pageId) {
3508
+ registry
3509
+ packageName
3510
+ version
3511
+ sourceKind
3512
+ page {
3513
+ id
3514
+ title
3515
+ content
3516
+ contentFormat
3517
+ breadcrumbs
3518
+ linkName
3519
+ lastUpdatedAt
3520
+ sourceKind
3521
+ source {
3522
+ url
3523
+ label
3524
+ }
3525
+ repoUrl
3526
+ gitRef
3527
+ requestedRef
3528
+ filePath
3529
+ baseUrl
3530
+ }
3531
+ }
3532
+ }`;
3542
3533
 
3543
3534
  class PackageIntelligenceServiceImpl {
3544
3535
  endpointUrl;
@@ -3579,7 +3570,7 @@ class PackageIntelligenceServiceImpl {
3579
3570
  if (response.status < 200 || response.status >= 300) {
3580
3571
  throw this.createHttpError(response);
3581
3572
  }
3582
- const parsed = graphQLResponseSchema2.safeParse(response.parsedBody);
3573
+ const parsed = graphQLResponseSchema.safeParse(response.parsedBody);
3583
3574
  if (!parsed.success) {
3584
3575
  throw new MalformedPackageIntelligenceResponseError("Malformed response from the package-intelligence service.");
3585
3576
  }
@@ -3983,6 +3974,148 @@ class PackageIntelligenceServiceImpl {
3983
3974
  entries
3984
3975
  };
3985
3976
  }
3977
+ async listPackageDocs(params) {
3978
+ return withTelemetrySpan("pkg-intel.docs.list", () => executeWithTokenRefresh({
3979
+ getToken: () => this.tokenProvider.getToken(),
3980
+ forceRefresh: () => this.tokenProvider.forceRefresh(),
3981
+ shouldRefresh: (error) => error instanceof AuthenticationError,
3982
+ executeWithToken: (token) => this.executeListPackageDocs(token, params)
3983
+ }));
3984
+ }
3985
+ async executeListPackageDocs(token, params) {
3986
+ let response;
3987
+ try {
3988
+ response = await postPkgseerGraphql({
3989
+ endpointUrl: this.endpointUrl,
3990
+ token,
3991
+ query: LIST_PACKAGE_DOCS_QUERY,
3992
+ variables: {
3993
+ registry: params.registry,
3994
+ packageName: params.packageName,
3995
+ version: params.version,
3996
+ limit: params.limit,
3997
+ after: params.after
3998
+ },
3999
+ fetchFn: this.fetchFn
4000
+ });
4001
+ } catch (cause) {
4002
+ if (cause instanceof PkgseerTransportError) {
4003
+ throw new PackageIntelligenceNetworkError("Could not reach the package intelligence service. Check your connection or set GITHITS_CODE_NAV_URL.", { cause });
4004
+ }
4005
+ throw cause;
4006
+ }
4007
+ if (response.status < 200 || response.status >= 300) {
4008
+ throw this.createHttpError(response);
4009
+ }
4010
+ const parsed = packageDocsListGraphQLResponseSchema.safeParse(response.parsedBody);
4011
+ if (!parsed.success) {
4012
+ throw new MalformedPackageIntelligenceResponseError("Malformed response from the package-intelligence service.");
4013
+ }
4014
+ if (parsed.data.errors && parsed.data.errors.length > 0) {
4015
+ throw promoteGenericVersionNotFound(this.createGraphQLError(parsed.data.errors), params);
4016
+ }
4017
+ const data = parsed.data.data?.listPackageDocs;
4018
+ if (!data) {
4019
+ throw new MalformedPackageIntelligenceResponseError("Empty response from the package-intelligence service.");
4020
+ }
4021
+ return this.normalisePackageDocsList(data);
4022
+ }
4023
+ normalisePackageDocsList(data) {
4024
+ return {
4025
+ registry: data.registry ?? undefined,
4026
+ packageName: data.packageName ?? undefined,
4027
+ version: data.version ?? undefined,
4028
+ stale: data.stale ?? undefined,
4029
+ pages: data.pages?.map((page) => ({
4030
+ id: page.id ?? undefined,
4031
+ title: page.title ?? undefined,
4032
+ slug: page.slug ?? undefined,
4033
+ order: page.order ?? undefined,
4034
+ linkName: page.linkName ?? undefined,
4035
+ lastUpdatedAt: page.lastUpdatedAt ?? undefined,
4036
+ sourceKind: page.sourceKind ?? undefined,
4037
+ sourceUrl: page.sourceUrl ?? undefined,
4038
+ repoUrl: page.repoUrl ?? undefined,
4039
+ gitRef: page.gitRef ?? undefined,
4040
+ requestedRef: page.requestedRef ?? undefined,
4041
+ filePath: page.filePath ?? undefined
4042
+ })) ?? [],
4043
+ pageInfo: data.pageInfo ? {
4044
+ hasNextPage: data.pageInfo.hasNextPage,
4045
+ endCursor: data.pageInfo.endCursor ?? undefined,
4046
+ totalCount: data.pageInfo.totalCount ?? undefined
4047
+ } : undefined
4048
+ };
4049
+ }
4050
+ async readPackageDoc(params) {
4051
+ return withTelemetrySpan("pkg-intel.docs.read", () => executeWithTokenRefresh({
4052
+ getToken: () => this.tokenProvider.getToken(),
4053
+ forceRefresh: () => this.tokenProvider.forceRefresh(),
4054
+ shouldRefresh: (error) => error instanceof AuthenticationError,
4055
+ executeWithToken: (token) => this.executeReadPackageDoc(token, params)
4056
+ }));
4057
+ }
4058
+ async executeReadPackageDoc(token, params) {
4059
+ let response;
4060
+ try {
4061
+ response = await postPkgseerGraphql({
4062
+ endpointUrl: this.endpointUrl,
4063
+ token,
4064
+ query: READ_PACKAGE_DOC_QUERY,
4065
+ variables: {
4066
+ pageId: params.pageId
4067
+ },
4068
+ fetchFn: this.fetchFn
4069
+ });
4070
+ } catch (cause) {
4071
+ if (cause instanceof PkgseerTransportError) {
4072
+ throw new PackageIntelligenceNetworkError("Could not reach the package intelligence service. Check your connection or set GITHITS_CODE_NAV_URL.", { cause });
4073
+ }
4074
+ throw cause;
4075
+ }
4076
+ if (response.status < 200 || response.status >= 300) {
4077
+ throw this.createHttpError(response);
4078
+ }
4079
+ const parsed = packageDocReadGraphQLResponseSchema.safeParse(response.parsedBody);
4080
+ if (!parsed.success) {
4081
+ throw new MalformedPackageIntelligenceResponseError("Malformed response from the package-intelligence service.");
4082
+ }
4083
+ if (parsed.data.errors && parsed.data.errors.length > 0) {
4084
+ throw this.createGraphQLError(parsed.data.errors);
4085
+ }
4086
+ const data = parsed.data.data?.getDocPage;
4087
+ if (!data) {
4088
+ throw new MalformedPackageIntelligenceResponseError("Empty response from the package-intelligence service.");
4089
+ }
4090
+ return this.normalisePackageDocResult(data);
4091
+ }
4092
+ normalisePackageDocResult(data) {
4093
+ return {
4094
+ registry: data.registry ?? undefined,
4095
+ packageName: data.packageName ?? undefined,
4096
+ version: data.version ?? undefined,
4097
+ sourceKind: data.sourceKind ?? undefined,
4098
+ page: data.page ? {
4099
+ id: data.page.id ?? undefined,
4100
+ title: data.page.title ?? undefined,
4101
+ content: data.page.content ?? undefined,
4102
+ contentFormat: data.page.contentFormat ?? undefined,
4103
+ breadcrumbs: data.page.breadcrumbs ?? undefined,
4104
+ linkName: data.page.linkName ?? undefined,
4105
+ lastUpdatedAt: data.page.lastUpdatedAt ?? undefined,
4106
+ sourceKind: data.page.sourceKind ?? undefined,
4107
+ source: data.page.source ? {
4108
+ url: data.page.source.url ?? undefined,
4109
+ label: data.page.source.label ?? undefined
4110
+ } : undefined,
4111
+ repoUrl: data.page.repoUrl ?? undefined,
4112
+ gitRef: data.page.gitRef ?? undefined,
4113
+ requestedRef: data.page.requestedRef ?? undefined,
4114
+ filePath: data.page.filePath ?? undefined,
4115
+ baseUrl: data.page.baseUrl ?? undefined
4116
+ } : undefined
4117
+ };
4118
+ }
3986
4119
  }
3987
4120
  function parseDetail3(body) {
3988
4121
  if (!body)
@@ -4300,4 +4433,4 @@ async function loadStartupTokens(mcpUrl) {
4300
4433
  });
4301
4434
  }
4302
4435
 
4303
- export { getCodeNavigationCapability, debugLog, setMcpClientVersionProvider, setClientMode, isTelemetryEnabled, withTelemetrySpan, startTelemetrySpan, endTelemetrySpan, flushTelemetry, AuthenticationError, CodeNavigationAccessError, CodeNavigationGraphQLError, CodeNavigationIndexingError, CodeNavigationUnresolvableError, MalformedCodeNavigationResponseError, CodeNavigationTargetNotFoundError, CodeNavigationFileNotFoundError, CodeNavigationVersionNotFoundError, CodeNavigationValidationError, CodeNavigationFeatureFlagRequiredError, CodeNavigationNetworkError, CodeNavigationBackendError, getCodeNavigationUrl, isCodeNavigationCliOverrideEnabled, ExecServiceImpl, FileSystemServiceImpl, PackageIntelligenceAccessError, PackageIntelligenceFeatureFlagRequiredError, PackageIntelligenceNetworkError, PackageIntelligenceBackendError, PackageIntelligenceGraphQLError, PackageIntelligenceTargetNotFoundError, PackageIntelligenceValidationError, PackageIntelligenceVersionNotFoundError, MalformedPackageIntelligenceResponseError, PackageIntelligenceChangelogSourceNotFoundError, PromptServiceImpl, refreshExpiredToken, createContainer, resolveStartupCodeNavigationCapability, resolveStartupCodeNavigationRegistrationState };
4436
+ export { getCodeNavigationCapability, debugLog, setMcpClientVersionProvider, setClientMode, isTelemetryEnabled, withTelemetrySpan, startTelemetrySpan, endTelemetrySpan, flushTelemetry, AuthenticationError, CodeNavigationAccessError, CodeNavigationGraphQLError, CodeNavigationIndexingError, CodeNavigationUnresolvableError, MalformedCodeNavigationResponseError, CodeNavigationTargetNotFoundError, CodeNavigationFileNotFoundError, CodeNavigationVersionNotFoundError, CodeNavigationValidationError, CodeNavigationFeatureFlagRequiredError, CodeNavigationNetworkError, CodeNavigationBackendError, getCodeNavigationUrl, getEnvApiToken, isCodeNavigationCliOverrideEnabled, ExecServiceImpl, FileSystemServiceImpl, PackageIntelligenceAccessError, PackageIntelligenceFeatureFlagRequiredError, PackageIntelligenceNetworkError, PackageIntelligenceBackendError, PackageIntelligenceGraphQLError, PackageIntelligenceTargetNotFoundError, PackageIntelligenceValidationError, PackageIntelligenceVersionNotFoundError, MalformedPackageIntelligenceResponseError, PackageIntelligenceChangelogSourceNotFoundError, PromptServiceImpl, refreshExpiredToken, createContainer, resolveStartupCodeNavigationCapability, resolveStartupCodeNavigationRegistrationState };