@assistant-ui/mcp-docs-server 0.1.31 → 0.1.32
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/.docs/organized/code-examples/waterfall.md +8 -8
- package/.docs/organized/code-examples/with-a2a.md +10 -10
- package/.docs/organized/code-examples/with-ag-ui.md +11 -11
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +13 -13
- package/.docs/organized/code-examples/with-artifacts.md +13 -13
- package/.docs/organized/code-examples/with-assistant-transport.md +10 -10
- package/.docs/organized/code-examples/with-browser-extension.md +345 -0
- package/.docs/organized/code-examples/with-chain-of-thought.md +54 -17
- package/.docs/organized/code-examples/with-cloud-standalone.md +13 -13
- package/.docs/organized/code-examples/with-cloud.md +13 -13
- package/.docs/organized/code-examples/with-custom-thread-list.md +13 -13
- package/.docs/organized/code-examples/with-elevenlabs-conversational.md +17 -16
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +17 -16
- package/.docs/organized/code-examples/with-expo.md +24 -24
- package/.docs/organized/code-examples/with-external-store.md +10 -10
- package/.docs/organized/code-examples/with-ffmpeg.md +13 -13
- package/.docs/organized/code-examples/with-generative-ui.md +210 -13
- package/.docs/organized/code-examples/with-google-adk.md +10 -10
- package/.docs/organized/code-examples/with-heat-graph.md +8 -8
- package/.docs/organized/code-examples/with-image-generation.md +454 -0
- package/.docs/organized/code-examples/with-interactables.md +13 -13
- package/.docs/organized/code-examples/with-langchain.md +12 -12
- package/.docs/organized/code-examples/with-langgraph.md +15 -12
- package/.docs/organized/code-examples/with-livekit.md +18 -17
- package/.docs/organized/code-examples/with-mcp.md +748 -0
- package/.docs/organized/code-examples/with-opencode.md +11 -11
- package/.docs/organized/code-examples/with-parent-id-grouping.md +11 -11
- package/.docs/organized/code-examples/with-react-hook-form.md +14 -14
- package/.docs/organized/code-examples/with-react-ink.md +4 -4
- package/.docs/organized/code-examples/with-react-router.md +15 -15
- package/.docs/organized/code-examples/with-resumable-stream.md +660 -0
- package/.docs/organized/code-examples/with-store.md +8 -8
- package/.docs/organized/code-examples/with-tanstack.md +14 -14
- package/.docs/organized/code-examples/with-tap-runtime.md +11 -10
- package/.docs/raw/docs/(docs)/cli.mdx +1 -0
- package/.docs/raw/docs/(docs)/index.mdx +2 -2
- package/.docs/raw/docs/(docs)/installation.mdx +1 -1
- package/.docs/raw/docs/(reference)/api-reference/adapters/attachments.mdx +26 -24
- package/.docs/raw/docs/(reference)/api-reference/adapters/feedback.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/index.mdx +20 -12
- package/.docs/raw/docs/(reference)/api-reference/adapters/model.mdx +44 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/persistence.mdx +37 -16
- package/.docs/raw/docs/(reference)/api-reference/adapters/runtime.mdx +12 -23
- package/.docs/raw/docs/(reference)/api-reference/adapters/suggestions.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/context-providers/assistant-runtime-provider.mdx +37 -8
- package/.docs/raw/docs/(reference)/api-reference/context-providers/index.mdx +11 -9
- package/.docs/raw/docs/(reference)/api-reference/context-providers/scoped-providers.mdx +64 -0
- package/.docs/raw/docs/(reference)/api-reference/external-store/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/external-store/message-conversion.mdx +52 -0
- package/.docs/raw/docs/(reference)/api-reference/external-store/runtime.mdx +36 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/composer-triggers.mdx +98 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/index.mdx +18 -13
- package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +18 -57
- package/.docs/raw/docs/(reference)/api-reference/hooks/primitives.mdx +640 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/runtimes.mdx +15 -28
- package/.docs/raw/docs/(reference)/api-reference/hooks/state.mdx +64 -18
- package/.docs/raw/docs/(reference)/api-reference/hooks/utilities.mdx +434 -0
- package/.docs/raw/docs/(reference)/api-reference/integrations/cloud-ai-sdk.mdx +24 -0
- package/.docs/raw/docs/(reference)/api-reference/integrations/index.mdx +11 -12
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-ai-sdk.mdx +79 -0
- package/.docs/raw/docs/(reference)/api-reference/model-context/context.mdx +52 -0
- package/.docs/raw/docs/(reference)/api-reference/model-context/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/model-context/registry.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/overview.mdx +110 -131
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar-more.mdx +78 -221
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar.mdx +127 -242
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +39 -20
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-modal.mdx +66 -87
- package/.docs/raw/docs/(reference)/api-reference/primitives/attachment.mdx +50 -58
- package/.docs/raw/docs/(reference)/api-reference/primitives/branch-picker.mdx +80 -48
- package/.docs/raw/docs/(reference)/api-reference/primitives/chain-of-thought.mdx +67 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +323 -461
- package/.docs/raw/docs/(reference)/api-reference/primitives/error.mdx +36 -43
- package/.docs/raw/docs/(reference)/api-reference/primitives/index.mdx +29 -24
- package/.docs/raw/docs/(reference)/api-reference/primitives/message-part.mdx +63 -245
- package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +175 -591
- package/.docs/raw/docs/(reference)/api-reference/primitives/queue-item.mdx +65 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/selection-toolbar.mdx +35 -22
- package/.docs/raw/docs/(reference)/api-reference/primitives/suggestion.mdx +57 -140
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item-more.mdx +70 -161
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item.mdx +84 -108
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +77 -96
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +173 -349
- package/.docs/raw/docs/(reference)/api-reference/runtimes/assistant-runtime.mdx +9 -21
- package/.docs/raw/docs/(reference)/api-reference/runtimes/attachment-runtime.mdx +10 -21
- package/.docs/raw/docs/(reference)/api-reference/runtimes/composer-runtime.mdx +15 -70
- package/.docs/raw/docs/(reference)/api-reference/runtimes/index.mdx +18 -13
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-part-runtime.mdx +25 -28
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-runtime.mdx +11 -63
- package/.docs/raw/docs/(reference)/api-reference/runtimes/queue-state.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-item-runtime.mdx +11 -48
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +10 -47
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-runtime.mdx +18 -30
- package/.docs/raw/docs/(reference)/api-reference/tools/component-tools.mdx +68 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/index.mdx +39 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/rendering.mdx +79 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/status.mdx +42 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/toolkits.mdx +92 -0
- package/.docs/raw/docs/(reference)/api-reference/transport/assistant-transport.mdx +48 -0
- package/.docs/raw/docs/(reference)/api-reference/transport/frame.mdx +62 -0
- package/.docs/raw/docs/(reference)/api-reference/transport/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/utilities/index.mdx +19 -0
- package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +131 -0
- package/.docs/raw/docs/(reference)/api-reference/voice/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/voice/session.mdx +54 -0
- package/.docs/raw/docs/(reference)/api-reference/voice/speech-dictation.mdx +36 -0
- package/.docs/raw/docs/cloud/ai-sdk.mdx +1 -1
- package/.docs/raw/docs/cloud/index.mdx +2 -2
- package/.docs/raw/docs/guides/attachments.mdx +4 -4
- package/.docs/raw/docs/guides/branching.mdx +1 -1
- package/.docs/raw/docs/guides/chain-of-thought.mdx +5 -5
- package/.docs/raw/docs/guides/context-api.mdx +4 -4
- package/.docs/raw/docs/guides/dictation.mdx +2 -2
- package/.docs/raw/docs/guides/editing.mdx +1 -1
- package/.docs/raw/docs/guides/generative-ui.mdx +142 -0
- package/.docs/raw/docs/guides/image-generation.mdx +74 -0
- package/.docs/raw/docs/guides/index.mdx +2 -2
- package/.docs/raw/docs/guides/interactables.mdx +2 -2
- package/.docs/raw/docs/guides/latex.mdx +2 -2
- package/.docs/raw/docs/guides/mcp-apps.mdx +231 -0
- package/.docs/raw/docs/guides/mentions.mdx +2 -2
- package/.docs/raw/docs/guides/message-timing.mdx +38 -5
- package/.docs/raw/docs/guides/multi-agent.mdx +2 -2
- package/.docs/raw/docs/guides/quoting.mdx +1 -1
- package/.docs/raw/docs/guides/resumable-stream-deployment.mdx +212 -0
- package/.docs/raw/docs/guides/resumable-stream-stores.mdx +152 -0
- package/.docs/raw/docs/guides/resumable-streams.mdx +210 -0
- package/.docs/raw/docs/guides/slash-commands.mdx +1 -1
- package/.docs/raw/docs/guides/speech.mdx +2 -2
- package/.docs/raw/docs/guides/suggestions.mdx +88 -4
- package/.docs/raw/docs/guides/tool-ui.mdx +2 -2
- package/.docs/raw/docs/guides/tools.mdx +66 -5
- package/.docs/raw/docs/guides/voice.mdx +2 -2
- package/.docs/raw/docs/ink/adapters.mdx +37 -1
- package/.docs/raw/docs/ink/custom-backend.mdx +59 -8
- package/.docs/raw/docs/ink/index.mdx +10 -11
- package/.docs/raw/docs/ink/primitives.mdx +349 -8
- package/.docs/raw/docs/integrations/auth/better-auth.mdx +1 -1
- package/.docs/raw/docs/integrations/auth/clerk.mdx +1 -1
- package/.docs/raw/docs/integrations/auth/next-auth.mdx +1 -1
- package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +2 -2
- package/.docs/raw/docs/integrations/frameworks/cloudflare-agents/overview.mdx +282 -0
- package/.docs/raw/docs/integrations/frameworks/mastra/overview.mdx +2 -2
- package/.docs/raw/docs/integrations/frameworks/mastra/separate-server.mdx +1 -1
- package/.docs/raw/docs/integrations/gateways/index.mdx +9 -4
- package/.docs/raw/docs/integrations/index.mdx +15 -3
- package/.docs/raw/docs/integrations/observability/langfuse.mdx +8 -1
- package/.docs/raw/docs/integrations/observability/langsmith.mdx +8 -4
- package/.docs/raw/docs/integrations/tools/react-mcp.mdx +337 -0
- package/.docs/raw/docs/primitives/composer.mdx +53 -0
- package/.docs/raw/docs/primitives/index.mdx +2 -2
- package/.docs/raw/docs/primitives/suggestion.mdx +9 -0
- package/.docs/raw/docs/react-native/hooks.mdx +2 -2
- package/.docs/raw/docs/react-native/index.mdx +4 -4
- package/.docs/raw/docs/runtimes/a2a/client-and-hooks.mdx +4 -4
- package/.docs/raw/docs/runtimes/a2a/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/ag-ui/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +32 -1
- package/.docs/raw/docs/runtimes/ai-sdk/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +7 -2
- package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +1 -1
- package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +7 -0
- package/.docs/raw/docs/runtimes/custom/data-stream.mdx +27 -2
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +9 -1
- package/.docs/raw/docs/runtimes/custom/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/google-adk/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/langchain.mdx +2 -2
- package/.docs/raw/docs/runtimes/langgraph/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/opencode/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/opencode/quickstart.mdx +1 -1
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +12 -5
- package/.docs/raw/docs/ui/composer-trigger-popover.mdx +11 -1
- package/.docs/raw/docs/ui/mcp-config.mdx +102 -0
- package/.docs/raw/docs/ui/model-selector.mdx +8 -8
- package/.docs/raw/docs/ui/sources.mdx +17 -0
- package/.docs/raw/docs/ui/streamdown.mdx +34 -2
- package/.docs/raw/docs/ui/thread-list.mdx +2 -2
- package/.docs/raw/docs/ui/thread.mdx +2 -2
- package/README.md +14 -72
- package/dist/constants.d.ts +12 -9
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +13 -9
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -24
- package/dist/index.js.map +1 -1
- package/dist/prepare-docs/code-examples.d.ts +4 -1
- package/dist/prepare-docs/code-examples.d.ts.map +1 -1
- package/dist/prepare-docs/code-examples.js +109 -121
- package/dist/prepare-docs/code-examples.js.map +1 -1
- package/dist/prepare-docs/copy-raw.d.ts +4 -1
- package/dist/prepare-docs/copy-raw.d.ts.map +1 -1
- package/dist/prepare-docs/copy-raw.js +45 -42
- package/dist/prepare-docs/copy-raw.js.map +1 -1
- package/dist/prepare-docs/prepare.d.ts +1 -2
- package/dist/prepare-docs/prepare.js +17 -17
- package/dist/prepare-docs/prepare.js.map +1 -1
- package/dist/stdio.d.ts +1 -3
- package/dist/stdio.js +6 -3
- package/dist/stdio.js.map +1 -1
- package/dist/tools/docs.d.ts +20 -15
- package/dist/tools/docs.d.ts.map +1 -1
- package/dist/tools/docs.js +140 -161
- package/dist/tools/docs.js.map +1 -1
- package/dist/tools/examples.d.ts +20 -15
- package/dist/tools/examples.d.ts.map +1 -1
- package/dist/tools/examples.js +74 -86
- package/dist/tools/examples.js.map +1 -1
- package/dist/tools/tests/test-setup.d.ts +5 -2
- package/dist/tools/tests/test-setup.d.ts.map +1 -1
- package/dist/tools/tests/test-setup.js +21 -28
- package/dist/tools/tests/test-setup.js.map +1 -1
- package/dist/utils/logger.d.ts +8 -5
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +17 -17
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/mcp-format.d.ts +8 -5
- package/dist/utils/mcp-format.d.ts.map +1 -1
- package/dist/utils/mcp-format.js +9 -9
- package/dist/utils/mcp-format.js.map +1 -1
- package/dist/utils/mdx.d.ts +8 -6
- package/dist/utils/mdx.d.ts.map +1 -1
- package/dist/utils/mdx.js +22 -22
- package/dist/utils/mdx.js.map +1 -1
- package/dist/utils/paths.d.ts +9 -6
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +66 -76
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/security.d.ts +4 -1
- package/dist/utils/security.d.ts.map +1 -1
- package/dist/utils/security.js +19 -40
- package/dist/utils/security.js.map +1 -1
- package/package.json +5 -5
- package/.docs/raw/docs/(reference)/api-reference/adapters/feedback-speech.mdx +0 -41
- package/.docs/raw/docs/(reference)/api-reference/context-providers/text-message-part-provider.mdx +0 -40
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-data-stream.mdx +0 -260
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-hook-form.mdx +0 -103
- package/.docs/raw/docs/(reference)/api-reference/integrations/vercel-ai-sdk.mdx +0 -254
- package/dist/prepare-docs/prepare.d.ts.map +0 -1
- package/dist/stdio.d.ts.map +0 -1
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/deprecation-policy.mdx +0 -0
- /package/.docs/raw/docs/{(reference) → migrations}/react-compatibility.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/react-langgraph-v0-7.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/v0-11.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/v0-12.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/v0-14.mdx +0 -0
package/dist/tools/examples.js
CHANGED
|
@@ -1,95 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readFile, readdir, lstat } from "node:fs/promises";
|
|
3
|
-
import { join, extname } from "node:path";
|
|
4
|
-
import { CODE_EXAMPLES_PATH, MAX_FILE_SIZE } from "../constants.js";
|
|
1
|
+
import { CODE_EXAMPLES_PATH } from "../constants.js";
|
|
5
2
|
import { logger } from "../utils/logger.js";
|
|
6
3
|
import { formatMCPResponse } from "../utils/mcp-format.js";
|
|
7
4
|
import { sanitizePath } from "../utils/security.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
5
|
+
import { extname, join } from "node:path";
|
|
6
|
+
import { z } from "zod/v3";
|
|
7
|
+
import { lstat, readFile, readdir } from "node:fs/promises";
|
|
8
|
+
//#region src/tools/examples.ts
|
|
9
|
+
const examplesInputSchema = z.object({ example: z.string().optional().describe("Example name (e.g., \"with-ai-sdk-v6\"). Leave empty to list all examples.") });
|
|
14
10
|
async function listCodeExamples() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
logger.error("Failed to list code examples", error);
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
11
|
+
try {
|
|
12
|
+
return (await readdir(CODE_EXAMPLES_PATH)).filter((file) => extname(file) === ".md").map((file) => file.replace(".md", "")).sort();
|
|
13
|
+
} catch (error) {
|
|
14
|
+
logger.error("Failed to list code examples", error);
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
26
17
|
}
|
|
27
18
|
async function readCodeExample(exampleName) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
logger.error(`Failed to read example: ${exampleName}`, error);
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
19
|
+
try {
|
|
20
|
+
const filePath = join(CODE_EXAMPLES_PATH, `${sanitizePath(exampleName)}.md`);
|
|
21
|
+
const stats = await lstat(filePath);
|
|
22
|
+
if (stats.isSymbolicLink()) {
|
|
23
|
+
logger.warn(`Attempted to read symlink: ${filePath}`);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (stats.size > 10485760) {
|
|
27
|
+
logger.warn(`File size exceeds limit: ${filePath} (${stats.size} bytes)`);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return await readFile(filePath, "utf-8");
|
|
31
|
+
} catch (error) {
|
|
32
|
+
logger.error(`Failed to read example: ${exampleName}`, error);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
47
35
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
},
|
|
36
|
+
const examplesTools = {
|
|
37
|
+
name: "assistantUIExamples",
|
|
38
|
+
description: "List available examples or retrieve complete code for a specific example",
|
|
39
|
+
parameters: examplesInputSchema.shape,
|
|
40
|
+
execute: async ({ example }) => {
|
|
41
|
+
try {
|
|
42
|
+
if (!example) {
|
|
43
|
+
logger.info("Listing all available examples");
|
|
44
|
+
const examples = await listCodeExamples();
|
|
45
|
+
if (examples.length === 0) return formatMCPResponse({
|
|
46
|
+
error: "No examples found. Please run documentation preparation first.",
|
|
47
|
+
hint: "Run: pnpm prepare-docs"
|
|
48
|
+
});
|
|
49
|
+
return formatMCPResponse({
|
|
50
|
+
type: "list",
|
|
51
|
+
examples,
|
|
52
|
+
total: examples.length,
|
|
53
|
+
hint: "Use example parameter to get complete code for any example"
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
logger.info(`Retrieving example: ${example}`);
|
|
57
|
+
const content = await readCodeExample(example);
|
|
58
|
+
if (!content) {
|
|
59
|
+
const availableExamples = await listCodeExamples();
|
|
60
|
+
return formatMCPResponse({
|
|
61
|
+
error: `Example not found: ${example}`,
|
|
62
|
+
availableExamples,
|
|
63
|
+
hint: "Use without example parameter to list all available examples"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return formatMCPResponse({
|
|
67
|
+
type: "example",
|
|
68
|
+
name: example,
|
|
69
|
+
content
|
|
70
|
+
});
|
|
71
|
+
} catch (error) {
|
|
72
|
+
logger.error("Failed to retrieve examples", error);
|
|
73
|
+
return formatMCPResponse({
|
|
74
|
+
error: "Failed to retrieve examples",
|
|
75
|
+
message: error instanceof Error ? error.message : String(error)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
94
79
|
};
|
|
80
|
+
//#endregion
|
|
81
|
+
export { examplesTools };
|
|
82
|
+
|
|
95
83
|
//# sourceMappingURL=examples.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"examples.js","
|
|
1
|
+
{"version":3,"file":"examples.js","names":[],"sources":["../../src/tools/examples.ts"],"sourcesContent":["import { z } from \"zod/v3\";\nimport { readFile, readdir, lstat } from \"node:fs/promises\";\nimport { join, extname } from \"node:path\";\nimport { CODE_EXAMPLES_PATH, MAX_FILE_SIZE } from \"../constants.js\";\nimport { logger } from \"../utils/logger.js\";\nimport { formatMCPResponse } from \"../utils/mcp-format.js\";\nimport { sanitizePath } from \"../utils/security.js\";\n\nconst examplesInputSchema = z.object({\n example: z\n .string()\n .optional()\n .describe(\n 'Example name (e.g., \"with-ai-sdk-v6\"). Leave empty to list all examples.',\n ),\n});\n\nasync function listCodeExamples(): Promise<string[]> {\n try {\n const files = await readdir(CODE_EXAMPLES_PATH);\n return files\n .filter((file) => extname(file) === \".md\")\n .map((file) => file.replace(\".md\", \"\"))\n .sort();\n } catch (error) {\n logger.error(\"Failed to list code examples\", error);\n return [];\n }\n}\n\nasync function readCodeExample(exampleName: string): Promise<string | null> {\n try {\n const sanitized = sanitizePath(exampleName);\n const filePath = join(CODE_EXAMPLES_PATH, `${sanitized}.md`);\n\n const stats = await lstat(filePath);\n if (stats.isSymbolicLink()) {\n logger.warn(`Attempted to read symlink: ${filePath}`);\n return null;\n }\n\n if (stats.size > MAX_FILE_SIZE) {\n logger.warn(`File size exceeds limit: ${filePath} (${stats.size} bytes)`);\n return null;\n }\n\n const content = await readFile(filePath, \"utf-8\");\n return content;\n } catch (error) {\n logger.error(`Failed to read example: ${exampleName}`, error);\n return null;\n }\n}\n\nexport const examplesTools = {\n name: \"assistantUIExamples\",\n description:\n \"List available examples or retrieve complete code for a specific example\",\n parameters: examplesInputSchema.shape,\n execute: async ({ example }: z.infer<typeof examplesInputSchema>) => {\n try {\n if (!example) {\n logger.info(\"Listing all available examples\");\n const examples = await listCodeExamples();\n\n if (examples.length === 0) {\n return formatMCPResponse({\n error:\n \"No examples found. Please run documentation preparation first.\",\n hint: \"Run: pnpm prepare-docs\",\n });\n }\n\n return formatMCPResponse({\n type: \"list\",\n examples,\n total: examples.length,\n hint: \"Use example parameter to get complete code for any example\",\n });\n }\n\n logger.info(`Retrieving example: ${example}`);\n const content = await readCodeExample(example);\n\n if (!content) {\n const availableExamples = await listCodeExamples();\n return formatMCPResponse({\n error: `Example not found: ${example}`,\n availableExamples,\n hint: \"Use without example parameter to list all available examples\",\n });\n }\n\n return formatMCPResponse({\n type: \"example\",\n name: example,\n content,\n });\n } catch (error) {\n logger.error(\"Failed to retrieve examples\", error);\n return formatMCPResponse({\n error: \"Failed to retrieve examples\",\n message: error instanceof Error ? error.message : String(error),\n });\n }\n },\n};\n"],"mappings":";;;;;;;;AAQA,MAAM,sBAAsB,EAAE,OAAO,EACnC,SAAS,EACN,OAAO,EACP,SAAS,EACT,SACC,4EACF,EACJ,CAAC;AAED,eAAe,mBAAsC;CACnD,IAAI;EAEF,QAAO,MADa,QAAQ,kBAAkB,GAE3C,QAAQ,SAAS,QAAQ,IAAI,MAAM,KAAK,EACxC,KAAK,SAAS,KAAK,QAAQ,OAAO,EAAE,CAAC,EACrC,KAAK;CACV,SAAS,OAAO;EACd,OAAO,MAAM,gCAAgC,KAAK;EAClD,OAAO,CAAC;CACV;AACF;AAEA,eAAe,gBAAgB,aAA6C;CAC1E,IAAI;EAEF,MAAM,WAAW,KAAK,oBAAoB,GADxB,aAAa,WACsB,EAAE,IAAI;EAE3D,MAAM,QAAQ,MAAM,MAAM,QAAQ;EAClC,IAAI,MAAM,eAAe,GAAG;GAC1B,OAAO,KAAK,8BAA8B,UAAU;GACpD,OAAO;EACT;EAEA,IAAI,MAAM,OAAA,UAAsB;GAC9B,OAAO,KAAK,4BAA4B,SAAS,IAAI,MAAM,KAAK,QAAQ;GACxE,OAAO;EACT;EAGA,OAAO,MADe,SAAS,UAAU,OAAO;CAElD,SAAS,OAAO;EACd,OAAO,MAAM,2BAA2B,eAAe,KAAK;EAC5D,OAAO;CACT;AACF;AAEA,MAAa,gBAAgB;CAC3B,MAAM;CACN,aACE;CACF,YAAY,oBAAoB;CAChC,SAAS,OAAO,EAAE,cAAmD;EACnE,IAAI;GACF,IAAI,CAAC,SAAS;IACZ,OAAO,KAAK,gCAAgC;IAC5C,MAAM,WAAW,MAAM,iBAAiB;IAExC,IAAI,SAAS,WAAW,GACtB,OAAO,kBAAkB;KACvB,OACE;KACF,MAAM;IACR,CAAC;IAGH,OAAO,kBAAkB;KACvB,MAAM;KACN;KACA,OAAO,SAAS;KAChB,MAAM;IACR,CAAC;GACH;GAEA,OAAO,KAAK,uBAAuB,SAAS;GAC5C,MAAM,UAAU,MAAM,gBAAgB,OAAO;GAE7C,IAAI,CAAC,SAAS;IACZ,MAAM,oBAAoB,MAAM,iBAAiB;IACjD,OAAO,kBAAkB;KACvB,OAAO,sBAAsB;KAC7B;KACA,MAAM;IACR,CAAC;GACH;GAEA,OAAO,kBAAkB;IACvB,MAAM;IACN,MAAM;IACN;GACF,CAAC;EACH,SAAS,OAAO;GACd,OAAO,MAAM,+BAA+B,KAAK;GACjD,OAAO,kBAAkB;IACvB,OAAO;IACP,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GAChE,CAAC;EACH;CACF;AACF"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/tools/tests/test-setup.d.ts
|
|
2
|
+
declare const testContext: {
|
|
3
|
+
callTool: (name: string, args: any) => Promise<any>;
|
|
3
4
|
};
|
|
5
|
+
//#endregion
|
|
6
|
+
export { testContext };
|
|
4
7
|
//# sourceMappingURL=test-setup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-setup.d.ts","
|
|
1
|
+
{"version":3,"file":"test-setup.d.ts","names":[],"sources":["../../../src/tools/tests/test-setup.ts"],"mappings":";cAYa,WAAA;2BACkB,IAAA,UAAW,OAAA;AAAA"}
|
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
import { beforeAll } from "vitest";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
1
|
import { PACKAGE_DIR } from "../../constants.js";
|
|
5
2
|
import { docsTools } from "../docs.js";
|
|
6
3
|
import { examplesTools } from "../examples.js";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { beforeAll } from "vitest";
|
|
7
|
+
//#region src/tools/tests/test-setup.ts
|
|
7
8
|
const tools = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
export const testContext = {
|
|
12
|
-
callTool: async (name, args) => {
|
|
13
|
-
const tool = tools[name];
|
|
14
|
-
if (!tool) {
|
|
15
|
-
throw new Error(`Tool ${name} not found`);
|
|
16
|
-
}
|
|
17
|
-
const result = await tool.execute(args);
|
|
18
|
-
const text = result.content?.[0]?.text;
|
|
19
|
-
if (text === undefined) {
|
|
20
|
-
throw new Error(`Tool ${name} returned no content`);
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
return JSON.parse(text);
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
throw new Error(`Tool ${name} returned invalid JSON. Output: ${text}\nParse error: ${error instanceof Error ? error.message : String(error)}`);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
9
|
+
assistantUIDocs: docsTools,
|
|
10
|
+
assistantUIExamples: examplesTools
|
|
29
11
|
};
|
|
12
|
+
const testContext = { callTool: async (name, args) => {
|
|
13
|
+
const tool = tools[name];
|
|
14
|
+
if (!tool) throw new Error(`Tool ${name} not found`);
|
|
15
|
+
const text = (await tool.execute(args)).content?.[0]?.text;
|
|
16
|
+
if (text === void 0) throw new Error(`Tool ${name} returned no content`);
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(text);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw new Error(`Tool ${name} returned invalid JSON. Output: ${text}\nParse error: ${error instanceof Error ? error.message : String(error)}`);
|
|
21
|
+
}
|
|
22
|
+
} };
|
|
30
23
|
beforeAll(() => {
|
|
31
|
-
|
|
32
|
-
if (!existsSync(docsPath)) {
|
|
33
|
-
throw new Error("Documentation not prepared. Run: pnpm build");
|
|
34
|
-
}
|
|
24
|
+
if (!existsSync(join(PACKAGE_DIR, ".docs"))) throw new Error("Documentation not prepared. Run: pnpm build");
|
|
35
25
|
});
|
|
26
|
+
//#endregion
|
|
27
|
+
export { testContext };
|
|
28
|
+
|
|
36
29
|
//# sourceMappingURL=test-setup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-setup.js","
|
|
1
|
+
{"version":3,"file":"test-setup.js","names":[],"sources":["../../../src/tools/tests/test-setup.ts"],"sourcesContent":["import { beforeAll } from \"vitest\";\nimport { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { PACKAGE_DIR } from \"../../constants.js\";\nimport { docsTools } from \"../docs.js\";\nimport { examplesTools } from \"../examples.js\";\n\nconst tools = {\n assistantUIDocs: docsTools,\n assistantUIExamples: examplesTools,\n};\n\nexport const testContext = {\n callTool: async (name: string, args: any) => {\n const tool = tools[name as keyof typeof tools];\n if (!tool) {\n throw new Error(`Tool ${name} not found`);\n }\n const result = await tool.execute(args);\n\n const text = result.content?.[0]?.text;\n if (text === undefined) {\n throw new Error(`Tool ${name} returned no content`);\n }\n try {\n return JSON.parse(text);\n } catch (error) {\n throw new Error(\n `Tool ${name} returned invalid JSON. Output: ${text}\\nParse error: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n },\n};\n\nbeforeAll(() => {\n const docsPath = join(PACKAGE_DIR, \".docs\");\n if (!existsSync(docsPath)) {\n throw new Error(\"Documentation not prepared. Run: pnpm build\");\n }\n});\n"],"mappings":";;;;;;;AAOA,MAAM,QAAQ;CACZ,iBAAiB;CACjB,qBAAqB;AACvB;AAEA,MAAa,cAAc,EACzB,UAAU,OAAO,MAAc,SAAc;CAC3C,MAAM,OAAO,MAAM;CACnB,IAAI,CAAC,MACH,MAAM,IAAI,MAAM,QAAQ,KAAK,WAAW;CAI1C,MAAM,QAAO,MAFQ,KAAK,QAAQ,IAAI,GAElB,UAAU,IAAI;CAClC,IAAI,SAAS,KAAA,GACX,MAAM,IAAI,MAAM,QAAQ,KAAK,qBAAqB;CAEpD,IAAI;EACF,OAAO,KAAK,MAAM,IAAI;CACxB,SAAS,OAAO;EACd,MAAM,IAAI,MACR,QAAQ,KAAK,kCAAkC,KAAK,iBAAiB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,GAC5H;CACF;AACF,EACF;AAEA,gBAAgB;CAEd,IAAI,CAAC,WADY,KAAK,aAAa,OACZ,CAAC,GACtB,MAAM,IAAI,MAAM,6CAA6C;AAEjE,CAAC"}
|
package/dist/utils/logger.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region src/utils/logger.d.ts
|
|
2
|
+
declare const logger: {
|
|
3
|
+
debug: (message: string, ...args: any[]) => void;
|
|
4
|
+
info: (message: string, ...args: any[]) => void;
|
|
5
|
+
error: (message: string, ...args: any[]) => void;
|
|
6
|
+
warn: (message: string, ...args: any[]) => void;
|
|
6
7
|
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { logger };
|
|
7
10
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","
|
|
1
|
+
{"version":3,"file":"logger.d.ts","names":[],"sources":["../../src/utils/logger.ts"],"mappings":";cAEa,MAAA;8BACY,IAAA;6BAKD,IAAA;8BAKC,IAAA;6BAGD,IAAA;AAAA"}
|
package/dist/utils/logger.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { IS_PREPARE_MODE } from "../constants.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
warn: (message, ...args) => {
|
|
17
|
-
console.warn(`[WARN] ${message}`, ...args);
|
|
18
|
-
},
|
|
2
|
+
//#region src/utils/logger.ts
|
|
3
|
+
const logger = {
|
|
4
|
+
debug: (message, ...args) => {
|
|
5
|
+
if (process.env.DEBUG) console.debug(`[DEBUG] ${message}`, ...args);
|
|
6
|
+
},
|
|
7
|
+
info: (message, ...args) => {
|
|
8
|
+
if (IS_PREPARE_MODE) console.log(`[INFO] ${message}`, ...args);
|
|
9
|
+
},
|
|
10
|
+
error: (message, ...args) => {
|
|
11
|
+
console.error(`[ERROR] ${message}`, ...args);
|
|
12
|
+
},
|
|
13
|
+
warn: (message, ...args) => {
|
|
14
|
+
console.warn(`[WARN] ${message}`, ...args);
|
|
15
|
+
}
|
|
19
16
|
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { logger };
|
|
19
|
+
|
|
20
20
|
//# sourceMappingURL=logger.js.map
|
package/dist/utils/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","
|
|
1
|
+
{"version":3,"file":"logger.js","names":[],"sources":["../../src/utils/logger.ts"],"sourcesContent":["import { IS_PREPARE_MODE } from \"../constants.js\";\n\nexport const logger = {\n debug: (message: string, ...args: any[]) => {\n if (process.env.DEBUG) {\n console.debug(`[DEBUG] ${message}`, ...args);\n }\n },\n info: (message: string, ...args: any[]) => {\n if (IS_PREPARE_MODE) {\n console.log(`[INFO] ${message}`, ...args);\n }\n },\n error: (message: string, ...args: any[]) => {\n console.error(`[ERROR] ${message}`, ...args);\n },\n warn: (message: string, ...args: any[]) => {\n console.warn(`[WARN] ${message}`, ...args);\n },\n};\n"],"mappings":";;AAEA,MAAa,SAAS;CACpB,QAAQ,SAAiB,GAAG,SAAgB;EAC1C,IAAI,QAAQ,IAAI,OACd,QAAQ,MAAM,WAAW,WAAW,GAAG,IAAI;CAE/C;CACA,OAAO,SAAiB,GAAG,SAAgB;EACzC,IAAI,iBACF,QAAQ,IAAI,UAAU,WAAW,GAAG,IAAI;CAE5C;CACA,QAAQ,SAAiB,GAAG,SAAgB;EAC1C,QAAQ,MAAM,WAAW,WAAW,GAAG,IAAI;CAC7C;CACA,OAAO,SAAiB,GAAG,SAAgB;EACzC,QAAQ,KAAK,UAAU,WAAW,GAAG,IAAI;CAC3C;AACF"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region src/utils/mcp-format.d.ts
|
|
2
|
+
declare function formatMCPResponse(data: any): {
|
|
3
|
+
content: Array<{
|
|
4
|
+
type: "text";
|
|
5
|
+
text: string;
|
|
6
|
+
}>;
|
|
6
7
|
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { formatMCPResponse };
|
|
7
10
|
//# sourceMappingURL=mcp-format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-format.d.ts","
|
|
1
|
+
{"version":3,"file":"mcp-format.d.ts","names":[],"sources":["../../src/utils/mcp-format.ts"],"mappings":";iBAAgB,iBAAA,CAAkB,IAAA;EAChC,OAAA,EAAS,KAAK;IAAG,IAAA;IAAc,IAAA;EAAA;AAAA"}
|
package/dist/utils/mcp-format.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
},
|
|
8
|
-
],
|
|
9
|
-
};
|
|
1
|
+
//#region src/utils/mcp-format.ts
|
|
2
|
+
function formatMCPResponse(data) {
|
|
3
|
+
return { content: [{
|
|
4
|
+
type: "text",
|
|
5
|
+
text: typeof data === "string" ? data : JSON.stringify(data, null, 2)
|
|
6
|
+
}] };
|
|
10
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { formatMCPResponse };
|
|
10
|
+
|
|
11
11
|
//# sourceMappingURL=mcp-format.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-format.js","
|
|
1
|
+
{"version":3,"file":"mcp-format.js","names":[],"sources":["../../src/utils/mcp-format.ts"],"sourcesContent":["export function formatMCPResponse(data: any): {\n content: Array<{ type: \"text\"; text: string }>;\n} {\n return {\n content: [\n {\n type: \"text\",\n text: typeof data === \"string\" ? data : JSON.stringify(data, null, 2),\n },\n ],\n };\n}\n"],"mappings":";AAAA,SAAgB,kBAAkB,MAEhC;CACA,OAAO,EACL,SAAS,CACP;EACE,MAAM;EACN,MAAM,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,MAAM,MAAM,CAAC;CACtE,CACF,EACF;AACF"}
|
package/dist/utils/mdx.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
//#region src/utils/mdx.d.ts
|
|
1
2
|
interface MDXContent {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
content: string;
|
|
4
|
+
frontmatter: Record<string, any>;
|
|
5
|
+
excerpt?: string;
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
declare function readMDXFile(filePath: string): Promise<MDXContent | null>;
|
|
8
|
+
declare function formatMDXContent(mdxContent: MDXContent): string;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { formatMDXContent, readMDXFile };
|
|
9
11
|
//# sourceMappingURL=mdx.d.ts.map
|
package/dist/utils/mdx.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdx.d.ts","
|
|
1
|
+
{"version":3,"file":"mdx.d.ts","names":[],"sources":["../../src/utils/mdx.ts"],"mappings":";UAIU,UAAA;EACR,OAAA;EACA,WAAA,EAAa,MAAM;EACnB,OAAA;AAAA;AAAA,iBAGoB,WAAA,CACpB,QAAA,WACC,OAAO,CAAC,UAAA;AAAA,iBAsBK,gBAAA,CAAiB,UAAsB,EAAV,UAAU"}
|
package/dist/utils/mdx.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
+
import { logger } from "./logger.js";
|
|
1
2
|
import { readFile } from "node:fs/promises";
|
|
2
3
|
import matter from "gray-matter";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
catch (error) {
|
|
19
|
-
logger.error(`Failed to read MDX file: ${filePath}`, error);
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
4
|
+
//#region src/utils/mdx.ts
|
|
5
|
+
async function readMDXFile(filePath) {
|
|
6
|
+
try {
|
|
7
|
+
const { content, data } = matter(await readFile(filePath, "utf-8"));
|
|
8
|
+
const excerptMatch = content.match(/^(.+?)(?:\n\n|$)/);
|
|
9
|
+
const excerpt = excerptMatch?.[1] !== void 0 ? excerptMatch[1].replace(/^#+ /, "") : void 0;
|
|
10
|
+
return {
|
|
11
|
+
content,
|
|
12
|
+
frontmatter: data,
|
|
13
|
+
...excerpt !== void 0 && { excerpt }
|
|
14
|
+
};
|
|
15
|
+
} catch (error) {
|
|
16
|
+
logger.error(`Failed to read MDX file: ${filePath}`, error);
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
22
19
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
function formatMDXContent(mdxContent) {
|
|
21
|
+
const { content, frontmatter } = mdxContent;
|
|
22
|
+
return matter.stringify(content, frontmatter);
|
|
26
23
|
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { formatMDXContent, readMDXFile };
|
|
26
|
+
|
|
27
27
|
//# sourceMappingURL=mdx.js.map
|
package/dist/utils/mdx.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mdx.js","
|
|
1
|
+
{"version":3,"file":"mdx.js","names":[],"sources":["../../src/utils/mdx.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport matter from \"gray-matter\";\nimport { logger } from \"./logger.js\";\n\ninterface MDXContent {\n content: string;\n frontmatter: Record<string, any>;\n excerpt?: string;\n}\n\nexport async function readMDXFile(\n filePath: string,\n): Promise<MDXContent | null> {\n try {\n const fileContent = await readFile(filePath, \"utf-8\");\n const { content, data } = matter(fileContent);\n\n const excerptMatch = content.match(/^(.+?)(?:\\n\\n|$)/);\n const excerpt =\n excerptMatch?.[1] !== undefined\n ? excerptMatch[1].replace(/^#+ /, \"\")\n : undefined;\n\n return {\n content,\n frontmatter: data,\n ...(excerpt !== undefined && { excerpt }),\n };\n } catch (error) {\n logger.error(`Failed to read MDX file: ${filePath}`, error);\n return null;\n }\n}\n\nexport function formatMDXContent(mdxContent: MDXContent): string {\n const { content, frontmatter } = mdxContent;\n\n return matter.stringify(content, frontmatter);\n}\n"],"mappings":";;;;AAUA,eAAsB,YACpB,UAC4B;CAC5B,IAAI;EAEF,MAAM,EAAE,SAAS,SAAS,OAAO,MADP,SAAS,UAAU,OAAO,CACR;EAE5C,MAAM,eAAe,QAAQ,MAAM,kBAAkB;EACrD,MAAM,UACJ,eAAe,OAAO,KAAA,IAClB,aAAa,GAAG,QAAQ,QAAQ,EAAE,IAClC,KAAA;EAEN,OAAO;GACL;GACA,aAAa;GACb,GAAI,YAAY,KAAA,KAAa,EAAE,QAAQ;EACzC;CACF,SAAS,OAAO;EACd,OAAO,MAAM,4BAA4B,YAAY,KAAK;EAC1D,OAAO;CACT;AACF;AAEA,SAAgB,iBAAiB,YAAgC;CAC/D,MAAM,EAAE,SAAS,gBAAgB;CAEjC,OAAO,OAAO,UAAU,SAAS,WAAW;AAC9C"}
|
package/dist/utils/paths.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/utils/paths.d.ts
|
|
2
|
+
declare function listDirContents(dirPath: string): Promise<{
|
|
3
|
+
directories: string[];
|
|
4
|
+
files: string[];
|
|
4
5
|
}>;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
declare function getAvailablePaths(): Promise<string[]>;
|
|
7
|
+
declare function findNearestPaths(requestedPath: string, availablePaths: string[]): string[];
|
|
8
|
+
declare function pathExists(path: string): Promise<boolean>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { findNearestPaths, getAvailablePaths, listDirContents, pathExists };
|
|
8
11
|
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","
|
|
1
|
+
{"version":3,"file":"paths.d.ts","names":[],"sources":["../../src/utils/paths.ts"],"mappings":";iBAYsB,eAAA,CAAgB,OAAA,WAAkB,OAAO;EAC7D,WAAA;EACA,KAAA;AAAA;AAAA,iBA4BoB,iBAAA,CAAA,GAAqB,OAAO;AAAA,iBA0BlC,gBAAA,CACd,aAAA,UACA,cAAwB;AAAA,iBAoCJ,UAAA,CAAW,IAAA,WAAe,OAAO"}
|