@farming-labs/svelte 0.1.72 → 0.1.74

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/server.js +30 -22
  2. package/package.json +2 -2
package/dist/server.js CHANGED
@@ -30,7 +30,7 @@
30
30
  import fs from "node:fs";
31
31
  import path from "node:path";
32
32
  import matter from "gray-matter";
33
- import { applySidebarFolderIndexBehavior, buildDocsAgentDiscoverySpec, createDocsAgentTraceContext, createDocsAgentTraceId, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, findDocsMarkdownPage, isDocsAgentDiscoveryRequest, isDocsSkillRequest, normalizeDocsRelated, performDocsSearch, renderDocsMarkdownDocument, renderDocsSkillDocument, stripGeneratedAgentProvenance, resolveDocsAgentMdxContent, resolvePageSidebarFolderIndexBehavior, resolveSearchRequestConfig, resolveDocsI18n, resolveDocsLlmsTxtFormat, resolveDocsLocale, resolveDocsMarkdownRequest, resolveDocsPath, resolvePageReadingTime, resolveReadingTimeOptions, resolveDocsSkillFormat, } from "@farming-labs/docs";
33
+ import { applySidebarFolderIndexBehavior, buildDocsAskAIContext, buildDocsAgentDiscoverySpec, createDocsAgentTraceContext, createDocsAgentTraceId, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, formatDocsAskAIPackageHints, findDocsMarkdownPage, isDocsAgentDiscoveryRequest, isDocsSkillRequest, normalizeDocsRelated, performDocsSearch, renderDocsMarkdownDocument, renderDocsSkillDocument, stripGeneratedAgentProvenance, resolveDocsAgentMdxContent, resolvePageSidebarFolderIndexBehavior, resolveAskAISearchRequestConfig, resolveSearchRequestConfig, resolveDocsI18n, resolveDocsLlmsTxtFormat, resolveDocsLocale, resolveDocsMarkdownRequest, resolveDocsPath, resolvePageReadingTime, resolveReadingTimeOptions, resolveDocsSkillFormat, } from "@farming-labs/docs";
34
34
  import { createDocsMcpHttpHandler, resolveDocsMcpConfig, serializeDocsIconRegistry, serializeOpenDocsProviders, } from "@farming-labs/docs/server";
35
35
  import { loadDocsNavTree, loadDocsContent, flattenNavTree } from "./content.js";
36
36
  import { renderMarkdown } from "./markdown.js";
@@ -548,20 +548,6 @@ export function createDocsServer(config = {}) {
548
548
  searchIndexByEntry.set(key, index);
549
549
  return index;
550
550
  }
551
- function searchByQuery(query, ctx) {
552
- const index = getSearchIndex(ctx);
553
- return index
554
- .map((page) => {
555
- const titleMatch = page.title.toLowerCase().includes(query) ? 10 : 0;
556
- const words = query.split(/\s+/);
557
- const contentMatch = words.reduce((score, word) => {
558
- return score + (page.content.toLowerCase().includes(word) ? 1 : 0);
559
- }, 0);
560
- return { ...page, score: titleMatch + contentMatch };
561
- })
562
- .filter((r) => r.score > 0)
563
- .sort((a, b) => b.score - a.score);
564
- }
565
551
  // ─── llms.txt content builder ────────────────────────────────
566
552
  const llmsSiteTitle = typeof config.nav === "object" &&
567
553
  typeof config.nav?.title === "string"
@@ -748,12 +734,16 @@ export function createDocsServer(config = {}) {
748
734
  function buildDefaultSystemPrompt() {
749
735
  const lines = [
750
736
  `You are a helpful documentation assistant${projectName ? ` for ${projectName}` : ""}.`,
751
- "Answer questions based on the provided documentation context.",
737
+ "Answer only from the provided documentation context.",
738
+ "Prefer exact code/config snippets from the context when the question asks how to implement something.",
739
+ "Cite the relevant documentation URL when you use a source.",
740
+ "Use only URLs exactly as they appear in the context; do not invent placeholder domains.",
741
+ 'Never use placeholder package names or imports such as "your-auth-library", "your-package", "your-sdk", "replace-me", or "example-library". If the exact package or import is not in the context, do not include an import snippet.',
752
742
  "Be concise and accurate. If the answer is not in the context, say so honestly.",
753
743
  "Use markdown formatting for code examples and links.",
754
744
  ];
755
745
  if (packageName) {
756
- lines.push(`When showing import examples, always use "${packageName}" as the package name.`);
746
+ lines.push(`When showing import examples, use "${packageName}" as the package name and prefer exact imports copied from the documentation context.`);
757
747
  }
758
748
  if (docsUrl) {
759
749
  lines.push(`When linking to documentation pages, use "${docsUrl}" as the base URL (e.g. ${docsUrl}/docs/get-started).`);
@@ -935,7 +925,24 @@ export function createDocsServer(config = {}) {
935
925
  maxResults,
936
926
  },
937
927
  });
938
- const scored = searchByQuery(lastUserMessage.content.toLowerCase(), ctx).slice(0, maxResults);
928
+ const retrieval = await buildDocsAskAIContext({
929
+ pages: getSearchIndex(ctx),
930
+ query: lastUserMessage.content,
931
+ search: resolveAskAISearchRequestConfig({
932
+ search: config.search,
933
+ useMcp: aiConfig.useMcp,
934
+ mcpEndpoint: mcpConfig.route,
935
+ mcpEnabled: mcpConfig.enabled,
936
+ mcpSearchEnabled: mcpConfig.tools.searchDocs,
937
+ requestUrl: event.request.url,
938
+ }),
939
+ locale: ctx.locale,
940
+ pathname: requestUrl.searchParams.get("pathname") ?? undefined,
941
+ siteTitle: llmsTitle,
942
+ baseUrl: requestUrl.origin,
943
+ limit: maxResults,
944
+ });
945
+ const scored = retrieval.results;
939
946
  await emitTrace({
940
947
  type: "retrieval.result",
941
948
  name: "docs-index",
@@ -954,14 +961,15 @@ export function createDocsServer(config = {}) {
954
961
  const promptStartedAt = Date.now();
955
962
  const promptStartedAtIso = new Date().toISOString();
956
963
  const promptSpanId = createDocsAgentTraceId("span");
957
- const contextParts = scored.map((doc) => `## ${doc.title}\nURL: ${doc.url}\n${doc.description ? `Description: ${doc.description}\n` : ""}\n${doc.content}`);
958
- const context = contextParts.join("\n\n---\n\n");
964
+ const context = retrieval.context;
959
965
  const systemPrompt = aiConfig.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
966
+ const packageHintsPrompt = formatDocsAskAIPackageHints(retrieval.packageHints, packageName);
967
+ const fullSystemPrompt = [systemPrompt, packageHintsPrompt].filter(Boolean).join("\n\n");
960
968
  const systemMessage = {
961
969
  role: "system",
962
970
  content: context
963
- ? `${systemPrompt}\n\n---\n\nDocumentation context:\n\n${context}`
964
- : systemPrompt,
971
+ ? `${fullSystemPrompt}\n\n---\n\nDocumentation context:\n\n${context}`
972
+ : fullSystemPrompt,
965
973
  };
966
974
  const llmMessages = [
967
975
  systemMessage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/svelte",
3
- "version": "0.1.72",
3
+ "version": "0.1.74",
4
4
  "description": "SvelteKit adapter for @farming-labs/docs — content loading and navigation utilities",
5
5
  "keywords": [
6
6
  "docs",
@@ -56,7 +56,7 @@
56
56
  "devDependencies": {
57
57
  "@types/node": "^22.10.0",
58
58
  "typescript": "^5.9.3",
59
- "@farming-labs/docs": "0.1.72"
59
+ "@farming-labs/docs": "0.1.74"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "@farming-labs/docs": "*"