perf: add preloadSchemas() and warm wire schemas eagerly on workerd (#2483)
This commit is contained in:
parent
8e1d2e92b1
commit
3f07a325c6
2 changed files with 550 additions and 14 deletions
|
|
@ -106,5 +106,11 @@ export { fromJsonSchema } from './fromJsonSchema';
|
|||
export type { InputRequiredOptions } from '@modelcontextprotocol/core-internal';
|
||||
export { withInputRequired } from '@modelcontextprotocol/core-internal';
|
||||
|
||||
// Explicit opt-in to eager wire-schema construction, for platforms that bill
|
||||
// request CPU but not module evaluation (isolate-based edge/serverless
|
||||
// runtimes). The package's workerd build calls it automatically at module
|
||||
// scope; other builds stay lazy unless the application calls it itself.
|
||||
export { preloadSchemas } from '@modelcontextprotocol/core-internal';
|
||||
|
||||
// re-export curated public API from core
|
||||
export * from '@modelcontextprotocol/core-internal/public';
|
||||
|
|
|
|||
|
|
@ -3,8 +3,17 @@
|
|||
*
|
||||
* This file is selected via package.json export conditions when running in workerd.
|
||||
*/
|
||||
import { preloadSchemas } from '@modelcontextprotocol/core-internal';
|
||||
|
||||
export { CfWorkerJsonSchemaValidator as DefaultJsonSchemaValidator } from '@modelcontextprotocol/core-internal/validators/cfWorker';
|
||||
|
||||
// Platform asymmetry: isolate platforms like workerd evaluate module scope
|
||||
// during deployment/isolate warm-up, outside any request's billed CPU, while
|
||||
// lazy construction would land inside the first request each fresh isolate
|
||||
// serves. Node and browser shims stay lazy — there, module evaluation is
|
||||
// process/page startup and boot latency is the cost that matters.
|
||||
preloadSchemas();
|
||||
|
||||
/**
|
||||
* Whether `fetch()` may throw `TypeError` due to CORS. CORS is a browser-only concept —
|
||||
* in Cloudflare Workers, a `TypeError` from `fetch` is always a real network/configuration
|
||||
|
|
|
|||
Loading…
Reference in a new issue