@farm.js/plugin 0.1.28 → 0.1.29
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rsc/entries/rsc.d.ts.map +1 -1
- package/dist/rsc/entries/rsc.js +211 -9
- package/dist/rsc/index.d.ts +19 -0
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/index.js +58 -4
- package/dist/rsc/middleware-config-module.d.ts +3 -0
- package/dist/rsc/middleware-config-module.d.ts.map +1 -1
- package/dist/rsc/middleware-config-module.js +25 -18
- package/dist/rsc/types.d.ts +5 -0
- package/dist/rsc/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAYhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAquC1D"}
|
package/dist/rsc/entries/rsc.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
const require_ = createRequire(import.meta.url);
|
|
3
|
+
/** Core's production source for the \`mcp\` plugin, so both servers merge config the same way. */
|
|
4
|
+
function generateMCPPluginSource() {
|
|
5
|
+
const { generateNativeMCPPluginSource } = require_("@farm.js/core/internal/production-runtime");
|
|
6
|
+
return generateNativeMCPPluginSource({ enabled: true });
|
|
7
|
+
}
|
|
1
8
|
/**
|
|
2
9
|
* Generates the terminal middleware-result handling shared by the RSC entry
|
|
3
10
|
* and its executable contract tests.
|
|
@@ -46,11 +53,17 @@ export function generateRscEntry(ctx) {
|
|
|
46
53
|
const middlewareConfigImports = (ctx.middlewareConfigPaths ?? [])
|
|
47
54
|
.map((configPath, index) => `import * as FarmMiddlewareConfigModule${index} from ${JSON.stringify(configPath.replace(/\\/g, "/"))};`)
|
|
48
55
|
.join("\n");
|
|
56
|
+
const mcpConfigImports = (ctx.mcpConfigPaths ?? [])
|
|
57
|
+
.map((configPath, index) => `import * as FarmMCPConfigModule${index} from ${JSON.stringify(configPath.replace(/\\/g, "/"))};`)
|
|
58
|
+
.join("\n");
|
|
59
|
+
const mcpSource = ctx.mcpConfigPaths?.length ? generateMCPPluginSource() : null;
|
|
49
60
|
const middlewareConfigValues = (ctx.middlewareConfigPaths ?? []).map((_configPath, index) => `(FarmMiddlewareConfigModule${index}.default || FarmMiddlewareConfigModule${index})`);
|
|
50
61
|
let code = `
|
|
51
62
|
import React from 'react';
|
|
52
63
|
import ServerErrorFallback from '/.farm/rsc-entries/error-fallback.tsx';
|
|
53
64
|
${middlewareConfigImports}
|
|
65
|
+
${mcpConfigImports}
|
|
66
|
+
${mcpSource ? `${mcpSource.importSource}\nimport { mergePluginAPIRoutes } from '@farm.js/core/api/runtime';` : ""}
|
|
54
67
|
import { registerAPIRouteShape } from '@farm.js/core/api/runtime';
|
|
55
68
|
import {
|
|
56
69
|
renderToReadableStream,
|
|
@@ -104,6 +117,20 @@ const farmDeploymentId = ${JSON.stringify(ctx.deploymentId)};
|
|
|
104
117
|
const farmApiBasePath = ${JSON.stringify(ctx.apiBasePath ?? "/api")};
|
|
105
118
|
const farmMarkdownConfig = ${JSON.stringify(ctx.markdown ?? { enabled: false, expose: [], cache: false, includeMetadata: true })};
|
|
106
119
|
`;
|
|
120
|
+
if (ctx.llmsTxt?.enabled) {
|
|
121
|
+
code += `import {
|
|
122
|
+
collectFarmLlmsTxtPages,
|
|
123
|
+
createFarmDefaultLlmsTxt,
|
|
124
|
+
createFarmLlmsFullRenderer,
|
|
125
|
+
createFarmLlmsMarkdownReader,
|
|
126
|
+
createFarmMetadataRouteResponse,
|
|
127
|
+
renderFarmLlmsFullTxt,
|
|
128
|
+
} from '@farm.js/core/internal/production-runtime';
|
|
129
|
+
|
|
130
|
+
const farmLlmsTxtConfig = ${JSON.stringify(ctx.llmsTxt)};
|
|
131
|
+
const farmLlmsFullRenderer = createFarmLlmsFullRenderer({ revalidate: farmLlmsTxtConfig.revalidate });
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
107
134
|
if (ctx.actionsEnabled) {
|
|
108
135
|
code += `import {
|
|
109
136
|
createServerActionRequestErrorResponse,
|
|
@@ -115,6 +142,56 @@ const farmMarkdownConfig = ${JSON.stringify(ctx.markdown ?? { enabled: false, ex
|
|
|
115
142
|
} from '@farm.js/core/server-action-security';
|
|
116
143
|
|
|
117
144
|
const serverActionSecurity = ${JSON.stringify(ctx.serverActions)};
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
147
|
+
// In development, a page, layout, loading or error file that fails to load
|
|
148
|
+
// fails only the routes that use it. Eager globs would fail the whole entry,
|
|
149
|
+
// so every route returned the same error until the file was fixed. The
|
|
150
|
+
// modules still load once, in order, before the first request. Middleware
|
|
151
|
+
// and API routes stay eager: skipping a broken auth middleware would leave
|
|
152
|
+
// its routes unprotected. Production keeps eager globs, where a broken
|
|
153
|
+
// import already fails the build.
|
|
154
|
+
const isolateRouteModules = ctx.development === true;
|
|
155
|
+
const uiRouteGlob = (pattern) => isolateRouteModules
|
|
156
|
+
? `await loadFarmDevRouteModules(import.meta.glob(${JSON.stringify(pattern)}))`
|
|
157
|
+
: `import.meta.glob(${JSON.stringify(pattern)}, { eager: true })`;
|
|
158
|
+
if (isolateRouteModules) {
|
|
159
|
+
code += `
|
|
160
|
+
const farmRouteLoadErrors = new Map();
|
|
161
|
+
|
|
162
|
+
async function loadFarmDevRouteModules(loaders) {
|
|
163
|
+
const modules = {};
|
|
164
|
+
for (const [filePath, load] of Object.entries(loaders)) {
|
|
165
|
+
try {
|
|
166
|
+
modules[filePath] = await load();
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error('[Farm.js] Could not load ' + filePath + ':', error);
|
|
169
|
+
const failed = {
|
|
170
|
+
default: function FarmRouteLoadFailure() {
|
|
171
|
+
throw error;
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
farmRouteLoadErrors.set(failed, error);
|
|
175
|
+
modules[filePath] = failed;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return modules;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The load error of a module the matched route renders with, if any. */
|
|
182
|
+
function findFarmRouteLoadError(matched) {
|
|
183
|
+
if (farmRouteLoadErrors.size === 0) return undefined;
|
|
184
|
+
const routeModules = [
|
|
185
|
+
pages[matched.pattern],
|
|
186
|
+
...getRouteModules(matched.pattern, layouts, 'layout'),
|
|
187
|
+
...getRouteModules(matched.pattern, loadings, 'loading'),
|
|
188
|
+
...getRouteModules(matched.pattern, errors, 'error'),
|
|
189
|
+
];
|
|
190
|
+
for (const module of routeModules) {
|
|
191
|
+
if (farmRouteLoadErrors.has(module)) return farmRouteLoadErrors.get(module);
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
118
195
|
`;
|
|
119
196
|
}
|
|
120
197
|
// Auto-discover pages, layouts, and middleware using Vite's glob import
|
|
@@ -145,10 +222,10 @@ function applyActionResponseHeaders(headers, request) {
|
|
|
145
222
|
|
|
146
223
|
// Auto-discover all route modules. Every glob remains a literal so Vite can analyze it.
|
|
147
224
|
${routeSourceRoots
|
|
148
|
-
.map((root, index) => `const pages${index} =
|
|
149
|
-
const layouts${index} =
|
|
150
|
-
const loadings${index} =
|
|
151
|
-
const errors${index} =
|
|
225
|
+
.map((root, index) => `const pages${index} = ${uiRouteGlob(`${root.glob}/**/page.{tsx,jsx,ts,js}`)};
|
|
226
|
+
const layouts${index} = ${uiRouteGlob(`${root.glob}/**/layout.{tsx,jsx,ts,js}`)};
|
|
227
|
+
const loadings${index} = ${uiRouteGlob(`${root.glob}/**/loading.{tsx,jsx,ts,js}`)};
|
|
228
|
+
const errors${index} = ${uiRouteGlob(`${root.glob}/**/error.{tsx,jsx,ts,js}`)};
|
|
152
229
|
const middlewares${index} = import.meta.glob(${JSON.stringify(`${root.glob}/**/middleware.{tsx,jsx,ts,js}`)}, { eager: true });
|
|
153
230
|
const apiRouteModules${index} = import.meta.glob(${JSON.stringify(`${root.glob}/api/**/route.{tsx,jsx,ts,js}`)}, { eager: true });
|
|
154
231
|
const routeDefinitionModules${index} = import.meta.glob(${JSON.stringify(root.sourceGlob === root.glob
|
|
@@ -292,7 +369,39 @@ function registerApiRouteSources(fileModules, definitionModules, sourceCount) {
|
|
|
292
369
|
}
|
|
293
370
|
|
|
294
371
|
registerApiRouteSources(apiRouteModules, routeDefinitionModules, ${routeSourceRoots.length});
|
|
295
|
-
|
|
372
|
+
${mcpSource
|
|
373
|
+
? `
|
|
374
|
+
// mcp: the same plugin core's production server mounts, built from the mcp
|
|
375
|
+
// config read from each config file, layers first.
|
|
376
|
+
const farmNativeMCPPlugin = (() => {
|
|
377
|
+
const farmRuntimeConfigs = [${(ctx.mcpConfigPaths ?? [])
|
|
378
|
+
.map((_path, index) => `(FarmMCPConfigModule${index}.default || FarmMCPConfigModule${index})`)
|
|
379
|
+
.join(", ")}];
|
|
380
|
+
${mcpSource.registerSource}
|
|
381
|
+
return farmNativeMCPPlugin;
|
|
382
|
+
})();
|
|
383
|
+
if (farmNativeMCPPlugin) {
|
|
384
|
+
const mountedRoutes = [...apiRouteMap.values()].map((route) => ({
|
|
385
|
+
path: route.path,
|
|
386
|
+
methods: [...route.methods],
|
|
387
|
+
endpoints: { ...route.handlers },
|
|
388
|
+
}));
|
|
389
|
+
// Rejects a plugin route that would replace an app endpoint.
|
|
390
|
+
for (const route of mergePluginAPIRoutes(mountedRoutes, [farmNativeMCPPlugin])) {
|
|
391
|
+
for (const method of route.pluginMethods ?? []) {
|
|
392
|
+
let target = apiRouteMap.get(route.path);
|
|
393
|
+
if (!target) {
|
|
394
|
+
target = { path: route.path, methods: [], handlers: {}, files: {}, sources: {} };
|
|
395
|
+
apiRouteMap.set(route.path, target);
|
|
396
|
+
}
|
|
397
|
+
target.methods.push(method);
|
|
398
|
+
target.handlers[method] = route.endpoints[method];
|
|
399
|
+
target.files[method] = 'plugin:' + farmNativeMCPPlugin.name;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
`
|
|
404
|
+
: ""}
|
|
296
405
|
async function handleAPIRequest(request) {
|
|
297
406
|
const url = new URL(request.url);
|
|
298
407
|
const match = matchAPIRouteAtBasePath(apiRouteMap, url.pathname, farmApiBasePath);
|
|
@@ -585,7 +694,12 @@ async function handleFarmRequest(request, context) {
|
|
|
585
694
|
if (apiResponse) {
|
|
586
695
|
return applyProductionMiddlewareHeaders(apiResponse, middlewareHeaders);
|
|
587
696
|
}
|
|
588
|
-
|
|
697
|
+
${ctx.llmsTxt?.enabled
|
|
698
|
+
? `// agent.llmsTxt: answered after middleware, so its redirects and headers apply.
|
|
699
|
+
const llmsResponse = await handleFarmLlmsTxtRequest(request, context);
|
|
700
|
+
if (llmsResponse) return applyProductionMiddlewareHeaders(llmsResponse, middlewareHeaders);
|
|
701
|
+
`
|
|
702
|
+
: ""}if (isFarmAPIPathname(url.pathname, farmApiBasePath) || isFarmAPIPathname(url.pathname)) {
|
|
589
703
|
return applyProductionMiddlewareHeaders(new Response(
|
|
590
704
|
JSON.stringify({ error: 'API route not found', pathname: url.pathname }),
|
|
591
705
|
{ status: 404, headers: { 'Content-Type': 'application/json' } },
|
|
@@ -755,7 +869,11 @@ async function handleFarmRequest(request, context) {
|
|
|
755
869
|
}
|
|
756
870
|
|
|
757
871
|
const { Page, pattern, params, pageMetadata } = matched;
|
|
758
|
-
|
|
872
|
+
${isolateRouteModules
|
|
873
|
+
? `const routeLoadError = findFarmRouteLoadError(matched);
|
|
874
|
+
if (routeLoadError) throw routeLoadError;
|
|
875
|
+
`
|
|
876
|
+
: ""}const LayoutModules = getLayoutModules(pattern);
|
|
759
877
|
const metadata = mergeDocumentMetadata(
|
|
760
878
|
...LayoutModules.map((layoutModule) => layoutModule.metadata),
|
|
761
879
|
pageMetadata,
|
|
@@ -914,7 +1032,11 @@ async function handleFarmRequest(request, context) {
|
|
|
914
1032
|
)
|
|
915
1033
|
);
|
|
916
1034
|
} catch (err) {
|
|
917
|
-
|
|
1035
|
+
${isolateRouteModules
|
|
1036
|
+
? `// A file that failed to load: show the dev error page, not error.tsx.
|
|
1037
|
+
if ([...farmRouteLoadErrors.values()].includes(err)) throw err;
|
|
1038
|
+
`
|
|
1039
|
+
: ""}const redirect = getFarmRedirectError(err);
|
|
918
1040
|
if (redirect) return new Response(null, { status: redirect.status, headers: { location: redirect.url, 'cache-control': 'no-store' } });
|
|
919
1041
|
if (isFarmNotFoundError(err)) return new Response('Not Found', { status: 404, headers: { 'cache-control': 'no-store' } });
|
|
920
1042
|
console.error('[RSC] Handler error:', err);
|
|
@@ -1000,7 +1122,87 @@ async function handleFarmRequest(request, context) {
|
|
|
1000
1122
|
}
|
|
1001
1123
|
}
|
|
1002
1124
|
|
|
1003
|
-
|
|
1125
|
+
${ctx.llmsTxt?.enabled
|
|
1126
|
+
? `/**
|
|
1127
|
+
* agent.llmsTxt, built the same way as core's production server: /llms.txt
|
|
1128
|
+
* lists the app's static pages and links to their Markdown mirrors, and
|
|
1129
|
+
* /llms-full.txt inlines each mirror.
|
|
1130
|
+
*/
|
|
1131
|
+
function createFarmLlmsTxtContext(request, context, full) {
|
|
1132
|
+
const origin = new URL(request.url).origin;
|
|
1133
|
+
const pages = collectFarmLlmsTxtPages(
|
|
1134
|
+
pageRoutes.map(({ module, segments }) => ({
|
|
1135
|
+
// Dynamic routes have no single URL, so the collector skips them.
|
|
1136
|
+
pattern: '/' + segments
|
|
1137
|
+
.map((part) => (part.isDynamic ? '[' + part.segment + ']' : part.segment))
|
|
1138
|
+
.join('/'),
|
|
1139
|
+
metadata: module && module.metadata,
|
|
1140
|
+
})),
|
|
1141
|
+
{
|
|
1142
|
+
origin,
|
|
1143
|
+
markdown: farmMarkdownConfig,
|
|
1144
|
+
include: farmLlmsTxtConfig.include,
|
|
1145
|
+
exclude: farmLlmsTxtConfig.exclude,
|
|
1146
|
+
},
|
|
1147
|
+
);
|
|
1148
|
+
const rootLayout = getRouteModules('/page.tsx', layouts, 'layout')[0];
|
|
1149
|
+
return {
|
|
1150
|
+
defaults: createFarmDefaultLlmsTxt({
|
|
1151
|
+
origin,
|
|
1152
|
+
pages,
|
|
1153
|
+
config: farmLlmsTxtConfig,
|
|
1154
|
+
rootMetadata: rootLayout && rootLayout.metadata,
|
|
1155
|
+
}),
|
|
1156
|
+
// Pages are read in-process through the full handler with a fresh request,
|
|
1157
|
+
// so the caller's cookies never shape the file. HEAD reads nothing.
|
|
1158
|
+
markdown: full && request.method.toUpperCase() !== 'HEAD'
|
|
1159
|
+
? createFarmLlmsMarkdownReader((page) => handler(page, context))
|
|
1160
|
+
: async () => null,
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
async function handleFarmLlmsTxtRequest(request, context) {
|
|
1165
|
+
const { origin, pathname } = new URL(request.url);
|
|
1166
|
+
const kind = pathname === '/llms.txt'
|
|
1167
|
+
? 'llms'
|
|
1168
|
+
: farmLlmsTxtConfig.full && pathname === '/llms-full.txt' ? 'llms-full' : null;
|
|
1169
|
+
if (!kind) return null;
|
|
1170
|
+
const method = request.method.toUpperCase();
|
|
1171
|
+
if (method !== 'GET' && method !== 'HEAD') {
|
|
1172
|
+
return new Response(null, { status: 405, headers: { Allow: 'GET, HEAD' } });
|
|
1173
|
+
}
|
|
1174
|
+
const llmsContext = createFarmLlmsTxtContext(request, context, kind === 'llms-full');
|
|
1175
|
+
// A page that times out is left out, and that response is neither reused nor cached.
|
|
1176
|
+
let complete = true;
|
|
1177
|
+
const renderFull = (shared) =>
|
|
1178
|
+
renderFarmLlmsFullTxt(llmsContext.defaults, {
|
|
1179
|
+
origin,
|
|
1180
|
+
readMarkdown: llmsContext.markdown,
|
|
1181
|
+
onIncomplete: () => {
|
|
1182
|
+
complete = false;
|
|
1183
|
+
if (shared) shared.incomplete();
|
|
1184
|
+
},
|
|
1185
|
+
});
|
|
1186
|
+
// HEAD reads no pages, so it neither waits for nor fills the shared render.
|
|
1187
|
+
const body = kind === 'llms'
|
|
1188
|
+
? llmsContext.defaults
|
|
1189
|
+
: method === 'HEAD'
|
|
1190
|
+
? await renderFull()
|
|
1191
|
+
: await farmLlmsFullRenderer(origin, renderFull, (settled) => {
|
|
1192
|
+
complete = settled;
|
|
1193
|
+
});
|
|
1194
|
+
const response = createFarmMetadataRouteResponse(
|
|
1195
|
+
kind,
|
|
1196
|
+
body,
|
|
1197
|
+
{ revalidate: complete ? farmLlmsTxtConfig.revalidate : 0 },
|
|
1198
|
+
{ method, request },
|
|
1199
|
+
);
|
|
1200
|
+
if (!complete) response.headers.set('cache-control', 'no-store');
|
|
1201
|
+
return response;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
`
|
|
1205
|
+
: ""}/**
|
|
1004
1206
|
* Serves a page's Markdown mirror (\`/page.md\` or \`Accept: text/markdown\`) by
|
|
1005
1207
|
* rendering the page through the normal request path, so middleware and sign-in
|
|
1006
1208
|
* gates apply; every other request renders as usual, and HTML pages advertise
|
package/dist/rsc/index.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ import type { FarmMiddlewareConfig } from "@farm.js/core/middleware";
|
|
|
29
29
|
import type { FarmServerConfig } from "@farm.js/core/internal/production-runtime";
|
|
30
30
|
import type { FarmLayerEntry, ResolvedFarmLayer } from "@farm.js/core/server";
|
|
31
31
|
import { type FarmMarkdownUserConfig } from "@farm.js/core/markdown";
|
|
32
|
+
import type { FarmLlmsTxtUserConfig } from "@farm.js/core/internal/production-runtime";
|
|
33
|
+
import type { FarmMCPUserConfig } from "@farm.js/core/server";
|
|
32
34
|
export type { FarmRscPluginOptions, EntryContext };
|
|
33
35
|
export { buildRscNitro, waitForRscManifest, waitForRscOutputs } from "./nitro-build.js";
|
|
34
36
|
export type { BuildRscNitroOptions } from "./nitro-build.js";
|
|
@@ -84,6 +86,23 @@ export interface FarmRscConfig {
|
|
|
84
86
|
* @default true
|
|
85
87
|
*/
|
|
86
88
|
md?: FarmMarkdownUserConfig | boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Agent-facing files. `llmsTxt` serves `/llms.txt`, an index of the app's
|
|
91
|
+
* static pages that links to their Markdown mirrors, and with `full: true`
|
|
92
|
+
* also `/llms-full.txt`, which inlines them. Same options as core's
|
|
93
|
+
* `agent.llmsTxt`; `false` turns it off.
|
|
94
|
+
* @default { llmsTxt: { full: false } }
|
|
95
|
+
*/
|
|
96
|
+
agent?: {
|
|
97
|
+
llmsTxt?: boolean | FarmLlmsTxtUserConfig;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* An MCP endpoint for agents, with the same options as core's top-level
|
|
101
|
+
* `mcp`. Requires `@farm.js/mcp`. Declare it directly in this config object:
|
|
102
|
+
* the server reads it, and only the bindings it uses, from this file.
|
|
103
|
+
* `oauth` is not supported in RSC apps yet.
|
|
104
|
+
*/
|
|
105
|
+
mcp?: FarmMCPUserConfig;
|
|
87
106
|
}
|
|
88
107
|
/**
|
|
89
108
|
* Define a Farm.js RSC configuration
|
package/dist/rsc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rsc/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAIL,KAAK,MAAM,EACX,KAAK,UAAU,EAChB,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC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CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC;IACtC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAA;KAAE,CAAC;IACtD;;;;;OAKG;IACH,GAAG,CAAC,EAAE,iBAAiB,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,aAAkB,GAAG,UAAU,CA0DnE;AA2ZD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,EAAE,CAikC5E"}
|
package/dist/rsc/index.js
CHANGED
|
@@ -37,7 +37,7 @@ import { transformAutomaticOptimizedBoundaries } from "./automatic-optimized-bou
|
|
|
37
37
|
import { resolveRscBuildOutputPath } from "./build-paths.js";
|
|
38
38
|
import { assertRscPackageCompatibility } from "./compatibility.js";
|
|
39
39
|
import { sendRscDevelopmentResponse } from "./dev-response.js";
|
|
40
|
-
import { loadRscMiddlewareConfigModule } from "./middleware-config-module.js";
|
|
40
|
+
import { loadRscConfigPropertyModule, loadRscMiddlewareConfigModule, } from "./middleware-config-module.js";
|
|
41
41
|
import fs from "fs/promises";
|
|
42
42
|
import path from "path";
|
|
43
43
|
import { devServableFileExists } from "../dev-static.js";
|
|
@@ -51,8 +51,8 @@ const { FARM_VERSION } = require_("@farm.js/core/version");
|
|
|
51
51
|
const { farmMiddlewarePlugin } = require_("@farm.js/core/middleware");
|
|
52
52
|
const { resolveServerActionsConfig, validateServerActionRequest, createServerActionRequestErrorResponse, } = require_("@farm.js/core/server-action-security");
|
|
53
53
|
const { normalizeFarmDeploymentId } = require_("@farm.js/core/deployment");
|
|
54
|
-
const { getFarmLayerAliases, getFarmSourceRoots, resolveFarmLayers } = require_("@farm.js/core/server");
|
|
55
|
-
const { readNodeRequestBody, resolveFarmServerConfig, resolveFarmI18nConfig, createFarmRequestBodyErrorResponse, createDefaultErrorMarkup, } = require_("@farm.js/core/internal/production-runtime");
|
|
54
|
+
const { getFarmLayerAliases, getFarmSourceRoots, resolveFarmLayers, resolveFarmMCPConfig, resolveFarmMCPPlugin, } = require_("@farm.js/core/server");
|
|
55
|
+
const { readNodeRequestBody, resolveFarmServerConfig, resolveFarmI18nConfig, createFarmRequestBodyErrorResponse, createDefaultErrorMarkup, resolveFarmLlmsTxtConfig, } = require_("@farm.js/core/internal/production-runtime");
|
|
56
56
|
const { isFarmAPIPathname } = require_("@farm.js/core/api/runtime");
|
|
57
57
|
const { resolveFarmAPIConfig, resolveFarmAPIServerBasePath } = require_("@farm.js/core/api");
|
|
58
58
|
const { getResolvedEnv } = require_("@farm.js/core/env");
|
|
@@ -83,6 +83,8 @@ export function defineConfig(config = {}) {
|
|
|
83
83
|
deploymentId: config.deploymentId,
|
|
84
84
|
generateBuildId: config.generateBuildId,
|
|
85
85
|
md: config.md,
|
|
86
|
+
agent: config.agent,
|
|
87
|
+
mcp: config.mcp,
|
|
86
88
|
// Vite server configuration
|
|
87
89
|
server: {
|
|
88
90
|
...config.server,
|
|
@@ -101,6 +103,8 @@ export function defineConfig(config = {}) {
|
|
|
101
103
|
srcDir: config.srcDir ?? "src",
|
|
102
104
|
debug,
|
|
103
105
|
bodySizeLimit: config.server?.bodySizeLimit,
|
|
106
|
+
// The dev API server mounts the MCP endpoint, as core's does.
|
|
107
|
+
...(config.mcp ? { plugins: ({ root }) => resolveRscMCPPlugins(config.mcp, root) } : {}),
|
|
104
108
|
}),
|
|
105
109
|
farmRsc({
|
|
106
110
|
debug,
|
|
@@ -182,6 +186,7 @@ const VIRTUAL_HYDRATE_ENTRY = "virtual:@farm.js/rsc/hydrate";
|
|
|
182
186
|
const OPTIMIZED_BOUNDARY_ADAPTER = "@farm.js/plugin/rsc/optimized-boundary";
|
|
183
187
|
const STRATA_PACKAGE = "@farming-labs/strata";
|
|
184
188
|
const RSC_MIDDLEWARE_CONFIG_QUERY = "?farm-rsc-middleware";
|
|
189
|
+
const RSC_MCP_CONFIG_QUERY = "?farm-rsc-mcp";
|
|
185
190
|
const FARM_CORE_PACKAGE_ROOT = path.resolve(path.dirname(require_.resolve("@farm.js/core")), "..");
|
|
186
191
|
const FARM_CONFIG_FILENAMES = [
|
|
187
192
|
"farm.config.ts",
|
|
@@ -226,6 +231,19 @@ async function findFarmConfigPath(root) {
|
|
|
226
231
|
}
|
|
227
232
|
return null;
|
|
228
233
|
}
|
|
234
|
+
/** Resolves `mcp` for an RSC app, rejecting what the RSC server cannot serve yet. */
|
|
235
|
+
function resolveRscMCPConfig(input) {
|
|
236
|
+
const config = resolveFarmMCPConfig(input);
|
|
237
|
+
if (config.enabled && config.oauth) {
|
|
238
|
+
throw new Error("[Farm.js] mcp.oauth is not supported in RSC apps yet: the RSC server does not serve " +
|
|
239
|
+
"the protected-resource metadata. Remove oauth, or validate tokens in mcp.authorize.");
|
|
240
|
+
}
|
|
241
|
+
return config;
|
|
242
|
+
}
|
|
243
|
+
async function resolveRscMCPPlugins(input, root) {
|
|
244
|
+
const plugin = await resolveFarmMCPPlugin(resolveRscMCPConfig(input), { root });
|
|
245
|
+
return plugin ? [plugin] : [];
|
|
246
|
+
}
|
|
229
247
|
async function resolveMiddlewareConfigPaths(root, layers) {
|
|
230
248
|
const paths = (layers ?? []).flatMap((layer) => layer.configFile ? [path.resolve(layer.configFile)] : []);
|
|
231
249
|
const projectConfigPath = await findFarmConfigPath(root);
|
|
@@ -466,6 +484,7 @@ export default function farmRsc(options = {}) {
|
|
|
466
484
|
let entryContext;
|
|
467
485
|
let rscBuildRoot;
|
|
468
486
|
const middlewareConfigModules = new Map();
|
|
487
|
+
let mcpConfigCandidates = null;
|
|
469
488
|
// Store for debugging
|
|
470
489
|
const debug = options.debug ?? false;
|
|
471
490
|
const automaticDeploymentId = `build-${Date.now()}`;
|
|
@@ -559,10 +578,38 @@ export default function farmRsc(options = {}) {
|
|
|
559
578
|
name: "@farm.js/plugin/rsc:middleware-config",
|
|
560
579
|
enforce: "pre",
|
|
561
580
|
resolveId(id) {
|
|
562
|
-
if (!id.endsWith(RSC_MIDDLEWARE_CONFIG_QUERY))
|
|
581
|
+
if (!id.endsWith(RSC_MIDDLEWARE_CONFIG_QUERY) && !id.endsWith(RSC_MCP_CONFIG_QUERY)) {
|
|
563
582
|
return null;
|
|
583
|
+
}
|
|
564
584
|
return id.replace(/\\/g, "/");
|
|
565
585
|
},
|
|
586
|
+
// The MCP config is read from the Vite config file too, whose path is
|
|
587
|
+
// only known here. Entries are generated on load, after this runs.
|
|
588
|
+
async configResolved(resolved) {
|
|
589
|
+
if (!mcpConfigCandidates || !entryContext)
|
|
590
|
+
return;
|
|
591
|
+
const configPaths = [...mcpConfigCandidates];
|
|
592
|
+
if (resolved.configFile)
|
|
593
|
+
configPaths.push(path.resolve(resolved.configFile));
|
|
594
|
+
const mcpConfigPaths = [];
|
|
595
|
+
for (const configPath of new Set(configPaths)) {
|
|
596
|
+
const extracted = await loadRscConfigPropertyModule(configPath, "mcp");
|
|
597
|
+
if (extracted.kind === "unsupported") {
|
|
598
|
+
throw new Error(`[Farm.js] Cannot read mcp for the RSC server from ${configPath}: ${extracted.reason}. ` +
|
|
599
|
+
"Declare mcp directly in defineConfig({ mcp: ... }).");
|
|
600
|
+
}
|
|
601
|
+
if (extracted.kind === "absent")
|
|
602
|
+
continue;
|
|
603
|
+
const moduleId = `${configPath.replace(/\\/g, "/")}${RSC_MCP_CONFIG_QUERY}`;
|
|
604
|
+
middlewareConfigModules.set(moduleId, extracted.code);
|
|
605
|
+
mcpConfigPaths.push(moduleId);
|
|
606
|
+
}
|
|
607
|
+
if (mcpConfigPaths.length === 0) {
|
|
608
|
+
throw new Error("[Farm.js] The RSC server could not find the mcp config. " +
|
|
609
|
+
"Declare mcp directly in defineConfig({ mcp: ... }) in your Vite or Farm config file.");
|
|
610
|
+
}
|
|
611
|
+
entryContext.mcpConfigPaths = mcpConfigPaths;
|
|
612
|
+
},
|
|
566
613
|
load(id) {
|
|
567
614
|
return middlewareConfigModules.get(id.replace(/\\/g, "/")) ?? null;
|
|
568
615
|
},
|
|
@@ -627,6 +674,11 @@ export default function farmRsc(options = {}) {
|
|
|
627
674
|
Object.assign(c, layerResolution.config);
|
|
628
675
|
}
|
|
629
676
|
middlewareConfigModules.clear();
|
|
677
|
+
// The config files mcp is read from at runtime; the Vite config file is
|
|
678
|
+
// added once it is known, in configResolved.
|
|
679
|
+
mcpConfigCandidates = resolveRscMCPConfig(c.mcp).enabled
|
|
680
|
+
? await resolveMiddlewareConfigPaths(root, c.layers)
|
|
681
|
+
: null;
|
|
630
682
|
const middlewareConfigPaths = [];
|
|
631
683
|
if (hasFarmMiddlewareConfig(c.middleware)) {
|
|
632
684
|
const configPaths = await resolveMiddlewareConfigPaths(root, c.layers);
|
|
@@ -709,6 +761,8 @@ export default function farmRsc(options = {}) {
|
|
|
709
761
|
}),
|
|
710
762
|
deploymentId,
|
|
711
763
|
markdown: resolveMarkdownConfig(c.md),
|
|
764
|
+
// Core's default for an app without docs: llms.txt on, llms-full.txt off.
|
|
765
|
+
llmsTxt: resolveFarmLlmsTxtConfig(c.agent?.llmsTxt ?? { full: false }),
|
|
712
766
|
// Resolved the same way core resolves it for the config, so RSC and
|
|
713
767
|
// non-RSC apps match middleware against the same pathname.
|
|
714
768
|
i18n: resolveFarmI18nConfig(c.i18n, {
|
|
@@ -14,6 +14,9 @@ type ExtractionResult = {
|
|
|
14
14
|
reason: string;
|
|
15
15
|
};
|
|
16
16
|
export declare function extractRscMiddlewareConfigModule(source: string, program: AstNode): ExtractionResult;
|
|
17
|
+
/** Extracts `key` from the default-exported config, as a module that exports `{ [key] }`. */
|
|
18
|
+
export declare function extractRscConfigPropertyModule(source: string, program: AstNode, key: "middleware" | "mcp"): ExtractionResult;
|
|
17
19
|
export declare function loadRscMiddlewareConfigModule(configPath: string): Promise<ExtractionResult>;
|
|
20
|
+
export declare function loadRscConfigPropertyModule(configPath: string, key: "middleware" | "mcp"): Promise<ExtractionResult>;
|
|
18
21
|
export {};
|
|
19
22
|
//# sourceMappingURL=middleware-config-module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware-config-module.d.ts","sourceRoot":"","sources":["../../src/rsc/middleware-config-module.ts"],"names":[],"mappings":"AAQA,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AASF,KAAK,gBAAgB,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware-config-module.d.ts","sourceRoot":"","sources":["../../src/rsc/middleware-config-module.ts"],"names":[],"mappings":"AAQA,KAAK,OAAO,GAAG;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AASF,KAAK,gBAAgB,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAgQ5C,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,GACf,gBAAgB,CAElB;AAED,6FAA6F;AAC7F,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,YAAY,GAAG,KAAK,GACxB,gBAAgB,CA+IlB;AAiBD,wBAAsB,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAEjG;AAED,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,YAAY,GAAG,KAAK,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAuB3B"}
|
|
@@ -202,7 +202,7 @@ function resolveConfigObject(node, variableInitializers, configHelpers, seen = n
|
|
|
202
202
|
* leave the guard with a different matcher than the config it came from. Fail
|
|
203
203
|
* on those instead of producing a module that disagrees with the config.
|
|
204
204
|
*/
|
|
205
|
-
function unsupportedStatementReason(statement, source) {
|
|
205
|
+
function unsupportedStatementReason(statement, source, key) {
|
|
206
206
|
switch (statement.type) {
|
|
207
207
|
case "ImportDeclaration":
|
|
208
208
|
if ((statement.specifiers ?? []).length > 0)
|
|
@@ -224,10 +224,14 @@ function unsupportedStatementReason(statement, source) {
|
|
|
224
224
|
const text = source.slice(statement.start, statement.end).replace(/\s+/g, " ").trim();
|
|
225
225
|
const snippet = text.length > 80 ? `${text.slice(0, 77)}...` : text;
|
|
226
226
|
return statement.type === "ImportDeclaration"
|
|
227
|
-
? `the side-effect import \`${snippet}\` would not run with the extracted
|
|
228
|
-
: `the top-level statement \`${snippet}\` would not run with the extracted
|
|
227
|
+
? `the side-effect import \`${snippet}\` would not run with the extracted ${key}`
|
|
228
|
+
: `the top-level statement \`${snippet}\` would not run with the extracted ${key}`;
|
|
229
229
|
}
|
|
230
230
|
export function extractRscMiddlewareConfigModule(source, program) {
|
|
231
|
+
return extractRscConfigPropertyModule(source, program, "middleware");
|
|
232
|
+
}
|
|
233
|
+
/** Extracts `key` from the default-exported config, as a module that exports `{ [key] }`. */
|
|
234
|
+
export function extractRscConfigPropertyModule(source, program, key) {
|
|
231
235
|
const body = program.body ?? [];
|
|
232
236
|
const bindings = new Map();
|
|
233
237
|
const variableInitializers = new Map();
|
|
@@ -235,7 +239,7 @@ export function extractRscMiddlewareConfigModule(source, program) {
|
|
|
235
239
|
let defaultExport = null;
|
|
236
240
|
let order = 0;
|
|
237
241
|
for (const statement of body) {
|
|
238
|
-
const unsupported = unsupportedStatementReason(statement, source);
|
|
242
|
+
const unsupported = unsupportedStatementReason(statement, source, key);
|
|
239
243
|
if (unsupported)
|
|
240
244
|
return { kind: "unsupported", reason: unsupported };
|
|
241
245
|
if (statement.type === "ImportDeclaration") {
|
|
@@ -313,33 +317,33 @@ export function extractRscMiddlewareConfigModule(source, program) {
|
|
|
313
317
|
};
|
|
314
318
|
}
|
|
315
319
|
const properties = configObject.properties ?? [];
|
|
316
|
-
let
|
|
317
|
-
let
|
|
320
|
+
let keyProperty = null;
|
|
321
|
+
let keyIndex = -1;
|
|
318
322
|
for (const [index, property] of properties.entries()) {
|
|
319
|
-
if (property.type === "Property" && propertyName(property) ===
|
|
320
|
-
|
|
321
|
-
|
|
323
|
+
if (property.type === "Property" && propertyName(property) === key) {
|
|
324
|
+
keyProperty = property;
|
|
325
|
+
keyIndex = index;
|
|
322
326
|
}
|
|
323
327
|
}
|
|
324
|
-
if (!
|
|
328
|
+
if (!keyProperty) {
|
|
325
329
|
if (properties.some((property) => property.type === "SpreadElement")) {
|
|
326
330
|
return {
|
|
327
331
|
kind: "unsupported",
|
|
328
|
-
reason:
|
|
332
|
+
reason: `${key} may be supplied through a config spread`,
|
|
329
333
|
};
|
|
330
334
|
}
|
|
331
335
|
return { kind: "absent" };
|
|
332
336
|
}
|
|
333
|
-
if (properties.slice(
|
|
337
|
+
if (properties.slice(keyIndex + 1).some((property) => property.type === "SpreadElement")) {
|
|
334
338
|
return {
|
|
335
339
|
kind: "unsupported",
|
|
336
|
-
reason:
|
|
340
|
+
reason: `a config spread after ${key} may override it`,
|
|
337
341
|
};
|
|
338
342
|
}
|
|
339
|
-
const
|
|
343
|
+
const keyValue = keyProperty.value;
|
|
340
344
|
const candidateNames = new Set(bindings.keys());
|
|
341
345
|
const selectedBindings = new Set();
|
|
342
|
-
const pending = [...referencedTopLevelNames(
|
|
346
|
+
const pending = [...referencedTopLevelNames(keyValue, candidateNames)];
|
|
343
347
|
while (pending.length > 0) {
|
|
344
348
|
const name = pending.pop();
|
|
345
349
|
const binding = bindings.get(name);
|
|
@@ -355,10 +359,10 @@ export function extractRscMiddlewareConfigModule(source, program) {
|
|
|
355
359
|
const declarations = [...selectedBindings]
|
|
356
360
|
.sort((a, b) => a.order - b.order)
|
|
357
361
|
.map((binding) => binding.render());
|
|
358
|
-
const
|
|
362
|
+
const valueSource = source.slice(keyValue.start, keyValue.end);
|
|
359
363
|
return {
|
|
360
364
|
kind: "module",
|
|
361
|
-
code: `${declarations.join("\n")}${declarations.length ? "\n" : ""}export default {
|
|
365
|
+
code: `${declarations.join("\n")}${declarations.length ? "\n" : ""}export default { ${key}: ${valueSource} };\n`,
|
|
362
366
|
};
|
|
363
367
|
}
|
|
364
368
|
function sourceLang(file) {
|
|
@@ -376,6 +380,9 @@ function sourceLang(file) {
|
|
|
376
380
|
}
|
|
377
381
|
}
|
|
378
382
|
export async function loadRscMiddlewareConfigModule(configPath) {
|
|
383
|
+
return loadRscConfigPropertyModule(configPath, "middleware");
|
|
384
|
+
}
|
|
385
|
+
export async function loadRscConfigPropertyModule(configPath, key) {
|
|
379
386
|
const [{ readFile }, vite] = await Promise.all([import("node:fs/promises"), import("vite")]);
|
|
380
387
|
const source = await readFile(configPath, "utf8");
|
|
381
388
|
const lang = sourceLang(configPath);
|
|
@@ -392,5 +399,5 @@ export async function loadRscMiddlewareConfigModule(configPath) {
|
|
|
392
399
|
jsx: "automatic",
|
|
393
400
|
loader: lang,
|
|
394
401
|
});
|
|
395
|
-
return
|
|
402
|
+
return extractRscConfigPropertyModule(transformed.code, vite.parseAst(transformed.code), key);
|
|
396
403
|
}
|
package/dist/rsc/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FarmMarkdownResolvedConfig } from "@farm.js/core/markdown";
|
|
2
|
+
import type { ResolvedFarmLlmsTxtConfig } from "@farm.js/core/internal/production-runtime";
|
|
2
3
|
import type { ResolvedFarmI18nConfig } from "@farm.js/core/i18n";
|
|
3
4
|
import type { FarmServerActionsConfig, ResolvedFarmServerActionsConfig } from "@farm.js/core/server-action-security";
|
|
4
5
|
/**
|
|
@@ -93,8 +94,12 @@ export interface EntryContext {
|
|
|
93
94
|
* Farm's normal config merge order.
|
|
94
95
|
*/
|
|
95
96
|
middlewareConfigPaths?: string[];
|
|
97
|
+
/** Modules that export `{ mcp }`, read from the app's config files, in layer order. */
|
|
98
|
+
mcpConfigPaths?: string[];
|
|
96
99
|
/** Resolved Markdown mirror settings (core's `md`): `.md` pages and `Accept: text/markdown`. */
|
|
97
100
|
markdown?: FarmMarkdownResolvedConfig;
|
|
101
|
+
/** Resolved `agent.llmsTxt`: the generated `/llms.txt` and `/llms-full.txt`. */
|
|
102
|
+
llmsTxt?: ResolvedFarmLlmsTxtConfig;
|
|
98
103
|
/** Whether debug mode is enabled */
|
|
99
104
|
debug: boolean;
|
|
100
105
|
/** True only for the Vite serve command, never for a production build. */
|
package/dist/rsc/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/rsc/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EACV,uBAAuB,EACvB,+BAA+B,EAChC,MAAM,sCAAsC,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,yDAAyD;IACzD,aAAa,CAAC,EAAE,uBAAuB,CAAC;IAExC,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;IACH,OAAO,CAAC,EAAE;QACR,wCAAwC;QACxC,GAAG,CAAC,EAAE,MAAM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AAY,CAAC;IAEzB,wFAAwF;IACxF,WAAW,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAEjC,yEAAyE;IACzE,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IAEF,0DAA0D;IAC1D,WAAW,CAAC,EAAE;QACZ,EAAE,EAAE,OAAO,CAAC;QACZ,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IAEF,6CAA6C;IAC7C,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB,QAAQ,CAAC,OAAO,EAAE;YAChB,qCAAqC;YACrC,OAAO,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC;YAEhC,6CAA6C;YAC7C,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAEhE,kDAAkD;YAClD,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;SAC5D,CAAC;KACH;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "Official plugins for Farm.js framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Farm.js Team",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"nitro": "3.0.260903-beta",
|
|
63
63
|
"picocolors": "^1.0.0",
|
|
64
64
|
"rsc-html-stream": "^0.0.4",
|
|
65
|
-
"@farm.js/core": "0.1.
|
|
65
|
+
"@farm.js/core": "0.1.29"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/node": "^22.20.5",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"react-dom": "19.2.8",
|
|
84
84
|
"react-server-dom-webpack": "19.2.8",
|
|
85
85
|
"vite": ">=6.0.0",
|
|
86
|
-
"@farm.js/core": "0.1.
|
|
86
|
+
"@farm.js/core": "0.1.29"
|
|
87
87
|
},
|
|
88
88
|
"peerDependenciesMeta": {
|
|
89
89
|
"@vitejs/plugin-rsc": {
|