Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
standardSchemaToJsonSchema,
validateStandardSchema,
} from "./standard-schema";
import { z } from "zod/v4";

export type {
StandardSchemaV1,
Expand Down Expand Up @@ -187,6 +188,20 @@ export type AppOptions = ProtocolOptions & {
* @default false
*/
strict?: boolean;
/**
* Allow code paths that require CSP `unsafe-eval` (e.g. `new Function()`).
*
* Views typically run under a strict CSP without `unsafe-eval`. Zod's JIT
* object parser uses `new Function()` and throws on the first message parse
* under such a policy. By default (`allowUnsafeEval: false`) the
* {@link App `App`} constructor sets `z.config({ jitless: true })` so the
* SDK works out of the box under the spec's default CSP. Set
* `allowUnsafeEval: true` to skip that and keep the faster JIT path when
* the host's CSP permits `unsafe-eval`.
*
* @default false
*/
allowUnsafeEval?: boolean;
};

type RequestHandlerExtra = Parameters<
Expand Down Expand Up @@ -403,6 +418,10 @@ export class App extends ProtocolWithEvents<
) {
super(options);

if (!options.allowUnsafeEval) {
z.config({ jitless: true });
}

this.setRequestHandler(PingRequestSchema, (request) => {
console.log("Received ping:", request.params);
return {};
Expand Down
Loading