@hilbras/sdk 3.4.4 → 3.5.0

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.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @hilbras/sdk — Next.js runtime surface
3
+ *
4
+ * Minimal structural types for the pieces of `next/server` these helpers use.
5
+ *
6
+ * The SDK cannot import from `next/server`: `next` is an optional peer
7
+ * dependency, and the published package must typecheck and build in a project
8
+ * that has never installed Next. Declaring the surface here keeps the build
9
+ * self-contained.
10
+ *
11
+ * Every member below is structurally satisfied by the real Next types, so a
12
+ * Next `NextRequest`/`NextResponse` is assignable to these without a cast, and
13
+ * a real Next route accepts a handler typed against them. That is the whole
14
+ * point of declaring the *shape* rather than the nominal class.
15
+ */
16
+ /**
17
+ * Build the minimal `NextResponse` surface at runtime.
18
+ *
19
+ * `NextResponse.json` and `NextResponse.next` return objects that the Next
20
+ * runtime converts into a real response. Outside Next — in a unit test, or in
21
+ * an app using the Web `Response` — the standard constructors do the same job,
22
+ * so they are used as the fallback and keep the SDK free of a hard Next
23
+ * dependency at runtime too.
24
+ */
25
+ export function createNextResponseShim() {
26
+ return {
27
+ json(body, init) {
28
+ // A plain `Response` already exposes `.status` and `.headers`, which is
29
+ // everything these helpers and their tests read. `Object.assign` cannot
30
+ // be used to graft on a `status` property: `Response.status` is a
31
+ // getter-only accessor on the prototype, so assignment throws.
32
+ return new Response(JSON.stringify(body), {
33
+ status: init?.status ?? 200,
34
+ headers: { "Content-Type": "application/json", ...(init?.headers ?? {}) },
35
+ });
36
+ },
37
+ next() {
38
+ return new Response(null, { status: 200 });
39
+ },
40
+ };
41
+ }
@@ -5,7 +5,7 @@
5
5
  * Uses the HilbrasClient to generate streaming responses with full protocol support.
6
6
  */
7
7
  import { createSSEResponse } from "../../utils/sse-writer.js";
8
- import { createFrameworkClientPool, errorResponse, readJsonBody, requireArray, requireString, } from "../shared/handler-core.js";
8
+ import { createFrameworkClientPool, errorResponse, isRequestPhaseError, readJsonBody, resolveChatFields, resolveCompletionFields, resolveLimits, } from "../shared/handler-core.js";
9
9
  /**
10
10
  * Create a streaming chat endpoint for Next.js.
11
11
  *
@@ -26,29 +26,36 @@ export function createChatHandler(options) {
26
26
  model: options.model,
27
27
  apiKey: options.apiKey,
28
28
  });
29
+ const limits = resolveLimits(options.limits);
30
+ const trustClientFields = options.trustClientFields ?? true;
29
31
  async function POST(req) {
30
32
  try {
31
- const body = await readJsonBody(req);
32
- const messages = requireArray(body, "messages");
33
- const model = typeof body.model === "string" && body.model.length > 0
34
- ? body.model
35
- : options.model;
33
+ const body = await readJsonBody(req, limits);
34
+ const fields = resolveChatFields(body, {
35
+ model: options.model,
36
+ tools: options.tools,
37
+ maxSteps: options.maxSteps,
38
+ trustClientFields,
39
+ limits,
40
+ });
36
41
  // Resolving the client before responding means a bad provider or model
37
42
  // produces a real error status instead of an HTTP 200 whose body carries
38
43
  // the failure.
39
- const client = pool.get(model);
44
+ const client = pool.get(fields.model);
40
45
  const providerName = pool.providerName;
46
+ const effective = { ...fields, provider: providerName };
47
+ await options.onRequest?.({ request: req, body, effective });
41
48
  const allMessages = [
42
49
  ...(options.systemPrompt ? [{ role: "system", content: options.systemPrompt }] : []),
43
- ...messages,
50
+ ...fields.messages,
44
51
  ];
45
- if (body.stream === false) {
52
+ if (!effective.stream) {
46
53
  const result = await client.complete({
47
54
  provider: providerName,
48
- model,
55
+ model: fields.model,
49
56
  messages: allMessages,
50
- temperature: typeof body.temperature === "number" ? body.temperature : undefined,
51
- maxTokens: typeof body.maxTokens === "number" ? body.maxTokens : undefined,
57
+ temperature: fields.temperature,
58
+ maxTokens: fields.maxTokens,
52
59
  signal: req.signal,
53
60
  });
54
61
  return Response.json({
@@ -58,17 +65,23 @@ export function createChatHandler(options) {
58
65
  }
59
66
  const chunks = client.streamText({
60
67
  provider: providerName,
61
- model,
68
+ model: fields.model,
62
69
  messages: allMessages,
63
- temperature: typeof body.temperature === "number" ? body.temperature : undefined,
64
- maxTokens: typeof body.maxTokens === "number" ? body.maxTokens : undefined,
65
- tools: body.tools ?? options.tools,
66
- maxSteps: typeof body.maxSteps === "number" ? body.maxSteps : options.maxSteps,
70
+ temperature: fields.temperature,
71
+ maxTokens: fields.maxTokens,
72
+ tools: fields.tools,
73
+ maxSteps: fields.maxSteps,
67
74
  signal: req.signal,
68
75
  });
69
76
  return createSSEResponse(chunks);
70
77
  }
71
78
  catch (error) {
79
+ if (options.onError) {
80
+ await options.onError(error, {
81
+ request: req,
82
+ phase: isRequestPhaseError(error) ? "request" : "provider",
83
+ });
84
+ }
72
85
  return errorResponse(error);
73
86
  }
74
87
  }
@@ -87,20 +100,25 @@ export function createCompletionHandler(options) {
87
100
  model: options.model,
88
101
  apiKey: options.apiKey,
89
102
  });
103
+ const limits = resolveLimits(options.limits);
104
+ const trustClientFields = options.trustClientFields ?? true;
90
105
  async function POST(req) {
91
106
  try {
92
- const body = await readJsonBody(req);
93
- const prompt = requireString(body, "prompt");
94
- const model = typeof body.model === "string" && body.model.length > 0
95
- ? body.model
96
- : options.model;
97
- const client = pool.get(model);
107
+ const body = await readJsonBody(req, limits);
108
+ const fields = resolveCompletionFields(body, {
109
+ model: options.model,
110
+ trustClientFields,
111
+ limits,
112
+ });
113
+ const client = pool.get(fields.model);
114
+ const effective = { ...fields, provider: pool.providerName };
115
+ await options.onRequest?.({ request: req, body, effective });
98
116
  const result = await client.complete({
99
117
  provider: pool.providerName,
100
- model,
101
- messages: [{ role: "user", content: prompt }],
102
- temperature: typeof body.temperature === "number" ? body.temperature : undefined,
103
- maxTokens: typeof body.maxTokens === "number" ? body.maxTokens : undefined,
118
+ model: fields.model,
119
+ messages: [{ role: "user", content: fields.prompt }],
120
+ temperature: fields.temperature,
121
+ maxTokens: fields.maxTokens,
104
122
  signal: req.signal,
105
123
  });
106
124
  return Response.json({
@@ -109,6 +127,12 @@ export function createCompletionHandler(options) {
109
127
  });
110
128
  }
111
129
  catch (error) {
130
+ if (options.onError) {
131
+ await options.onError(error, {
132
+ request: req,
133
+ phase: isRequestPhaseError(error) ? "request" : "provider",
134
+ });
135
+ }
112
136
  return errorResponse(error);
113
137
  }
114
138
  }
@@ -1,7 +1,27 @@
1
1
  /**
2
2
  * @hilbras/nextjs — Server Client
3
3
  *
4
- * Create a HilbrasClient for Server Components and Server Actions.
4
+ * @deprecated This module is a non-functional stub and will be removed in
5
+ * 4.0.0. `ServerHilbrasClient.streamResponse` never calls a provider: it
6
+ * echoes each user message back character by character, and ignores `apiKey`,
7
+ * `baseUrl`, `adapter`, `provider` and `model` entirely. It is kept only so an
8
+ * existing import resolves.
9
+ *
10
+ * Use `new HilbrasClient()` directly:
11
+ *
12
+ * ```ts
13
+ * import { HilbrasClient } from "@hilbras/sdk";
14
+ *
15
+ * const client = new HilbrasClient();
16
+ * client.addProviderFromCatalog("openai", "gpt-4o", process.env.OPENAI_API_KEY!);
17
+ *
18
+ * export async function POST(req: Request) {
19
+ * const { messages } = await req.json();
20
+ * return client.streamText({ provider: "OpenAI", model: "gpt-4o", messages });
21
+ * }
22
+ * ```
23
+ *
24
+ * Or, for a route handler with no client plumbing, use `createChatHandler`.
5
25
  */
6
26
  export interface ServerClientOptions {
7
27
  /** API key (defaults to env vars) */
@@ -49,6 +69,9 @@ export declare class ServerHilbrasClient {
49
69
  constructor(options?: ServerClientOptions);
50
70
  /**
51
71
  * Create a streaming response for Next.js App Router.
72
+ *
73
+ * @deprecated Returns a simulated echo of the request, not a provider
74
+ * response. Removed in 4.0.0 — see the module deprecation notice.
52
75
  */
53
76
  streamResponse(params: {
54
77
  messages: Array<{
@@ -1,7 +1,27 @@
1
1
  /**
2
2
  * @hilbras/nextjs — Server Client
3
3
  *
4
- * Create a HilbrasClient for Server Components and Server Actions.
4
+ * @deprecated This module is a non-functional stub and will be removed in
5
+ * 4.0.0. `ServerHilbrasClient.streamResponse` never calls a provider: it
6
+ * echoes each user message back character by character, and ignores `apiKey`,
7
+ * `baseUrl`, `adapter`, `provider` and `model` entirely. It is kept only so an
8
+ * existing import resolves.
9
+ *
10
+ * Use `new HilbrasClient()` directly:
11
+ *
12
+ * ```ts
13
+ * import { HilbrasClient } from "@hilbras/sdk";
14
+ *
15
+ * const client = new HilbrasClient();
16
+ * client.addProviderFromCatalog("openai", "gpt-4o", process.env.OPENAI_API_KEY!);
17
+ *
18
+ * export async function POST(req: Request) {
19
+ * const { messages } = await req.json();
20
+ * return client.streamText({ provider: "OpenAI", model: "gpt-4o", messages });
21
+ * }
22
+ * ```
23
+ *
24
+ * Or, for a route handler with no client plumbing, use `createChatHandler`.
5
25
  */
6
26
  /**
7
27
  * Create a HilbrasClient for server-side use.
@@ -41,6 +61,9 @@ export class ServerHilbrasClient {
41
61
  }
42
62
  /**
43
63
  * Create a streaming response for Next.js App Router.
64
+ *
65
+ * @deprecated Returns a simulated echo of the request, not a provider
66
+ * response. Removed in 4.0.0 — see the module deprecation notice.
44
67
  */
45
68
  async streamResponse(params) {
46
69
  const { messages, model, provider, systemPrompt } = params;
@@ -5,7 +5,7 @@
5
5
  * Uses the HilbrasClient to generate streaming responses with full protocol support.
6
6
  */
7
7
  import { createSSEResponse } from "../../utils/sse-writer.js";
8
- import { createFrameworkClientPool, errorResponse, readJsonBody, requireArray, requireString, } from "../shared/handler-core.js";
8
+ import { createFrameworkClientPool, errorResponse, isRequestPhaseError, readJsonBody, resolveChatFields, resolveCompletionFields, resolveLimits, } from "../shared/handler-core.js";
9
9
  /**
10
10
  * Create a streaming chat action for Remix.
11
11
  *
@@ -26,20 +26,35 @@ export function createChatAction(options) {
26
26
  model: options.model,
27
27
  apiKey: options.apiKey,
28
28
  });
29
+ const limits = resolveLimits(options.limits);
30
+ // This adapter never read `model`/`tools`/`maxSteps` from the body in v3.4, so
31
+ // its default is `false`. Defaulting to `true` would have widened the
32
+ // caller's influence over a route that did not previously have any.
33
+ const trustClientFields = options.trustClientFields ?? false;
29
34
  const action = async ({ request }) => {
30
35
  try {
31
- const body = await readJsonBody(request);
32
- const messages = requireArray(body, "messages");
33
- const client = pool.get(options.model);
36
+ const body = await readJsonBody(request, limits);
37
+ const fields = resolveChatFields(body, {
38
+ model: options.model,
39
+ tools: options.tools,
40
+ maxSteps: options.maxSteps,
41
+ trustClientFields,
42
+ limits,
43
+ });
44
+ const client = pool.get(fields.model);
34
45
  const providerName = pool.providerName;
46
+ const effective = { ...fields, provider: providerName };
47
+ await options.onRequest?.({ request, body, effective });
35
48
  const allMessages = options.systemPrompt
36
- ? [{ role: "system", content: options.systemPrompt }, ...messages]
37
- : messages;
38
- if (body.stream === false) {
49
+ ? [{ role: "system", content: options.systemPrompt }, ...fields.messages]
50
+ : fields.messages;
51
+ if (!effective.stream) {
39
52
  const result = await client.complete({
40
53
  provider: providerName,
41
- model: options.model,
54
+ model: fields.model,
42
55
  messages: allMessages,
56
+ temperature: fields.temperature,
57
+ maxTokens: fields.maxTokens,
43
58
  signal: request.signal,
44
59
  });
45
60
  return new Response(JSON.stringify({
@@ -51,15 +66,23 @@ export function createChatAction(options) {
51
66
  }
52
67
  const chunks = client.streamText({
53
68
  provider: providerName,
54
- model: options.model,
69
+ model: fields.model,
55
70
  messages: allMessages,
56
- tools: options.tools,
57
- maxSteps: options.maxSteps,
71
+ temperature: fields.temperature,
72
+ maxTokens: fields.maxTokens,
73
+ tools: fields.tools,
74
+ maxSteps: fields.maxSteps,
58
75
  signal: request.signal,
59
76
  });
60
77
  return createSSEResponse(chunks);
61
78
  }
62
79
  catch (error) {
80
+ if (options.onError) {
81
+ await options.onError(error, {
82
+ request,
83
+ phase: isRequestPhaseError(error) ? "request" : "provider",
84
+ });
85
+ }
63
86
  return errorResponse(error);
64
87
  }
65
88
  };
@@ -77,15 +100,28 @@ export function createCompletionAction(options) {
77
100
  model: options.model,
78
101
  apiKey: options.apiKey,
79
102
  });
103
+ const limits = resolveLimits(options.limits);
104
+ // This adapter never read `model`/`tools`/`maxSteps` from the body in v3.4, so
105
+ // its default is `false`. Defaulting to `true` would have widened the
106
+ // caller's influence over a route that did not previously have any.
107
+ const trustClientFields = options.trustClientFields ?? false;
80
108
  const action = async ({ request }) => {
81
109
  try {
82
- const body = await readJsonBody(request);
83
- const prompt = requireString(body, "prompt");
84
- const client = pool.get(options.model);
110
+ const body = await readJsonBody(request, limits);
111
+ const fields = resolveCompletionFields(body, {
112
+ model: options.model,
113
+ trustClientFields,
114
+ limits,
115
+ });
116
+ const client = pool.get(fields.model);
117
+ const effective = { ...fields, provider: pool.providerName };
118
+ await options.onRequest?.({ request, body, effective });
85
119
  const result = await client.complete({
86
120
  provider: pool.providerName,
87
- model: options.model,
88
- messages: [{ role: "user", content: prompt }],
121
+ model: fields.model,
122
+ messages: [{ role: "user", content: fields.prompt }],
123
+ temperature: fields.temperature,
124
+ maxTokens: fields.maxTokens,
89
125
  signal: request.signal,
90
126
  });
91
127
  return new Response(JSON.stringify({
@@ -96,6 +132,12 @@ export function createCompletionAction(options) {
96
132
  });
97
133
  }
98
134
  catch (error) {
135
+ if (options.onError) {
136
+ await options.onError(error, {
137
+ request,
138
+ phase: isRequestPhaseError(error) ? "request" : "provider",
139
+ });
140
+ }
99
141
  return errorResponse(error);
100
142
  }
101
143
  };
@@ -4,4 +4,5 @@
4
4
  * Actions and hooks for Remix.
5
5
  */
6
6
  export { createChatAction, createCompletionAction, type ActionOptions, type ChatMessage } from "./actions.js";
7
+ export type { FrameworkErrorContext, FrameworkHandlerLimits, FrameworkRequestContext, } from "../shared/handler-core.js";
7
8
  export { createChatHook, type UseChatOptions, type UseChatReturn, type Message } from "./hooks.js";
@@ -15,6 +15,7 @@
15
15
  * and how to build a `Response`.
16
16
  */
17
17
  import { HilbrasClient } from "../../client/client.js";
18
+ import type { Tool } from "../../types/tools.js";
18
19
  /** Options common to every framework handler factory. */
19
20
  export interface FrameworkHandlerBaseOptions {
20
21
  /** Catalog provider id or display name, e.g. `"openai"` or `"OpenAI"`. */
@@ -28,7 +29,102 @@ export interface FrameworkHandlerBaseOptions {
28
29
  * catalog `envKey` (for example `OPENAI_API_KEY`).
29
30
  */
30
31
  apiKey?: string;
32
+ /**
33
+ * Whether fields in the request body may override the factory's own options.
34
+ *
35
+ * `true` (the default, and the v3.4 behaviour) lets a caller choose
36
+ * `body.model`, `body.temperature`, `body.maxTokens`, `body.tools` and
37
+ * `body.maxSteps`. `false` ignores all of them and uses only the values
38
+ * configured on the factory, which is what a public route wants.
39
+ *
40
+ * The default flips to `false` in 4.0.0.
41
+ */
42
+ trustClientFields?: boolean;
43
+ /** Bounded request limits. Every field is individually overridable. */
44
+ limits?: Partial<FrameworkHandlerLimits>;
45
+ /**
46
+ * Called once per request after the body is validated and before any provider
47
+ * call. Throw to reject the request; `errorResponse` maps the thrown error, so
48
+ * a `RequestValidationError` carrying 401 or 403 becomes that status and
49
+ * anything else becomes a generic 500.
50
+ *
51
+ * This is the authentication and authorization extension point.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * createChatHandler({
56
+ * provider: "openai",
57
+ * model: "gpt-4o",
58
+ * onRequest({ request }) {
59
+ * if (request.headers.get("authorization") !== `Bearer ${process.env.SESSION}`) {
60
+ * throw new RequestValidationError("Unauthorized", undefined, 401);
61
+ * }
62
+ * },
63
+ * });
64
+ * ```
65
+ */
66
+ onRequest?: (context: FrameworkRequestContext) => void | Promise<void>;
67
+ /**
68
+ * Called for every request that fails, including one rejected by `onRequest`.
69
+ * This is where the server-side log belongs: `errorResponse` deliberately
70
+ * withholds detail from the response body, so without this hook a provider
71
+ * error is invisible to the operator.
72
+ */
73
+ onError?: (error: unknown, context: FrameworkErrorContext) => void | Promise<void>;
74
+ }
75
+ /** What an `onRequest` hook receives. */
76
+ export interface FrameworkRequestContext {
77
+ /** The incoming request. */
78
+ request: Request;
79
+ /** The parsed JSON body. */
80
+ body: Record<string, unknown>;
81
+ /**
82
+ * The fields the handler will actually use, after `trustClientFields` and the
83
+ * limits have been applied. A hook that authorizes per-model should read this
84
+ * rather than `body`, because these are the values that reach the provider.
85
+ */
86
+ effective: FrameworkEffectiveFields;
87
+ }
88
+ /** The resolved request parameters, after allowlist and limit handling. */
89
+ export interface FrameworkEffectiveFields {
90
+ model: string;
91
+ provider: string;
92
+ messages?: unknown[];
93
+ prompt?: string;
94
+ tools?: Tool[];
95
+ maxSteps?: number;
96
+ maxTokens?: number;
97
+ temperature?: number;
98
+ stream: boolean;
31
99
  }
100
+ /** What an `onError` hook receives. */
101
+ export interface FrameworkErrorContext {
102
+ request: Request;
103
+ /** `"request"` for a caller or validation failure, `"provider"` otherwise. */
104
+ phase: "request" | "provider";
105
+ }
106
+ /**
107
+ * Bounds on what a single request may ask for.
108
+ *
109
+ * The defaults are deliberately generous — no realistic chat request reaches
110
+ * them — so enabling them does not change the behaviour of an existing route,
111
+ * while still bounding the worst case an unauthenticated caller can force.
112
+ */
113
+ export interface FrameworkHandlerLimits {
114
+ /** Maximum request body size in bytes. Default 1 MiB. */
115
+ maxBodyBytes: number;
116
+ /** Maximum messages in a chat request. Default 200. */
117
+ maxMessages: number;
118
+ /** Maximum tools in a chat request. Default 64. */
119
+ maxTools: number;
120
+ /** Upper clamp applied to `maxSteps`. Default 25. */
121
+ maxStepsClamp: number;
122
+ /** Upper clamp applied to `maxTokens`. Default 32768. */
123
+ maxTokensClamp: number;
124
+ /** Inclusive clamp applied to `temperature`. Default `[0, 2]`. */
125
+ temperatureClamp: [number, number];
126
+ }
127
+ export declare const DEFAULT_HANDLER_LIMITS: Readonly<FrameworkHandlerLimits>;
32
128
  /** Resolve a provider spelling to its canonical catalog id. */
33
129
  export declare function resolveCatalogProviderId(provider: string): string;
34
130
  /**
@@ -61,17 +157,62 @@ export declare function createFrameworkClientPool(options: {
61
157
  apiKey?: string;
62
158
  client?: HilbrasClient;
63
159
  }): FrameworkClientPool;
160
+ /** Merge caller-supplied limits over the defaults. */
161
+ export declare function resolveLimits(overrides?: Partial<FrameworkHandlerLimits>): FrameworkHandlerLimits;
162
+ /**
163
+ * Read the request body as text, rejecting anything over `maxBodyBytes`.
164
+ *
165
+ * `content-length` is consulted first because it is free, but it is only a hint:
166
+ * a request with no header, or a lying one, is still measured by reading the
167
+ * body. The host normally caps `Content-Length` for us, so it cannot be relied
168
+ * on to reject an oversized body before it is buffered.
169
+ */
170
+ export declare function readBodyText(request: Request, limits?: FrameworkHandlerLimits): Promise<string>;
64
171
  /**
65
- * Read and parse a JSON request body.
172
+ * Read and parse a JSON request body, enforcing `maxBodyBytes`.
66
173
  *
67
174
  * Malformed JSON previously threw a bare `SyntaxError` out of the handler, so
68
175
  * the response depended entirely on the host framework's error handling.
69
176
  */
70
- export declare function readJsonBody(request: Request): Promise<Record<string, unknown>>;
177
+ export declare function readJsonBody(request: Request, limits?: FrameworkHandlerLimits): Promise<Record<string, unknown>>;
71
178
  /** Read a required non-empty string field from a parsed body. */
72
179
  export declare function requireString(body: Record<string, unknown>, field: string): string;
73
180
  /** Read a required array field from a parsed body. */
74
181
  export declare function requireArray(body: Record<string, unknown>, field: string): unknown[];
182
+ /**
183
+ * Resolve the fields a chat request may contribute.
184
+ *
185
+ * This is the single place that decides what a caller is allowed to influence,
186
+ * which is why all four chat-shaped handlers share it. `trustClientFields`
187
+ * selects *whether* the body is consulted; the limits bound *how far* it is
188
+ * trusted.
189
+ */
190
+ export declare function resolveChatFields(body: Record<string, unknown>, options: {
191
+ model: string;
192
+ tools?: Tool[];
193
+ maxSteps?: number;
194
+ trustClientFields: boolean;
195
+ limits: FrameworkHandlerLimits;
196
+ }): Omit<FrameworkEffectiveFields, "provider">;
197
+ /**
198
+ * Resolve the fields a completion request may contribute.
199
+ *
200
+ * `stream` is resolved but not yet acted on: the completion handlers answer with
201
+ * a JSON body either way, so a caller sending `stream: true` is served the same
202
+ * documented shape rather than a half-implemented stream.
203
+ */
204
+ export declare function resolveCompletionFields(body: Record<string, unknown>, options: {
205
+ model: string;
206
+ trustClientFields: boolean;
207
+ limits: FrameworkHandlerLimits;
208
+ }): Omit<FrameworkEffectiveFields, "provider" | "messages" | "tools" | "maxSteps">;
209
+ /**
210
+ * Classify an error for the `onError` hook.
211
+ *
212
+ * A validation failure — including one raised by `onRequest` — is the caller's
213
+ * fault and is not worth an error-level log; anything else is.
214
+ */
215
+ export declare function isRequestPhaseError(error: unknown): boolean;
75
216
  /**
76
217
  * Map a thrown error to an HTTP response.
77
218
  *