@farming-labs/svelte 0.1.72 → 0.1.73
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/dist/server.js +23 -22
- 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, 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
|
|
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,
|
|
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,17 @@ export function createDocsServer(config = {}) {
|
|
|
935
925
|
maxResults,
|
|
936
926
|
},
|
|
937
927
|
});
|
|
938
|
-
const
|
|
928
|
+
const retrieval = await buildDocsAskAIContext({
|
|
929
|
+
pages: getSearchIndex(ctx),
|
|
930
|
+
query: lastUserMessage.content,
|
|
931
|
+
search: resolveSearchRequestConfig(config.search, event.request.url),
|
|
932
|
+
locale: ctx.locale,
|
|
933
|
+
pathname: requestUrl.searchParams.get("pathname") ?? undefined,
|
|
934
|
+
siteTitle: llmsTitle,
|
|
935
|
+
baseUrl: requestUrl.origin,
|
|
936
|
+
limit: maxResults,
|
|
937
|
+
});
|
|
938
|
+
const scored = retrieval.results;
|
|
939
939
|
await emitTrace({
|
|
940
940
|
type: "retrieval.result",
|
|
941
941
|
name: "docs-index",
|
|
@@ -954,14 +954,15 @@ export function createDocsServer(config = {}) {
|
|
|
954
954
|
const promptStartedAt = Date.now();
|
|
955
955
|
const promptStartedAtIso = new Date().toISOString();
|
|
956
956
|
const promptSpanId = createDocsAgentTraceId("span");
|
|
957
|
-
const
|
|
958
|
-
const context = contextParts.join("\n\n---\n\n");
|
|
957
|
+
const context = retrieval.context;
|
|
959
958
|
const systemPrompt = aiConfig.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
|
|
959
|
+
const packageHintsPrompt = formatDocsAskAIPackageHints(retrieval.packageHints, packageName);
|
|
960
|
+
const fullSystemPrompt = [systemPrompt, packageHintsPrompt].filter(Boolean).join("\n\n");
|
|
960
961
|
const systemMessage = {
|
|
961
962
|
role: "system",
|
|
962
963
|
content: context
|
|
963
|
-
? `${
|
|
964
|
-
:
|
|
964
|
+
? `${fullSystemPrompt}\n\n---\n\nDocumentation context:\n\n${context}`
|
|
965
|
+
: fullSystemPrompt,
|
|
965
966
|
};
|
|
966
967
|
const llmMessages = [
|
|
967
968
|
systemMessage,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/svelte",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.73",
|
|
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.
|
|
59
|
+
"@farming-labs/docs": "0.1.73"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@farming-labs/docs": "*"
|