/** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** Header carrying the reflection secret on v1 requests. */ declare const REFLECTION_SECRET_HEADER = "x-genkit-reflection-secret"; /** Default interface for the v1 server. */ declare const DEFAULT_REFLECTION_HOST = "127.0.0.1"; /** First port tried when no exact port is configured. */ declare const DEFAULT_REFLECTION_PORT = 3100; /** * JSON-RPC error code the CLI returns when a v2 `register` fails auth. * Terminal: the runtime must not reconnect, the secret will not change. */ declare const REFLECTION_AUTH_ERROR_CODE = -32001; /** * Either an exact port (0 lets the OS pick) or a probe upward from * {@link DEFAULT_REFLECTION_PORT}, used only when nobody chose a port. */ type ReflectionPort = { kind: 'pinned'; port: number; } | { kind: 'probe'; }; /** * How the reflection API runs, if at all. * * `disabled` and `off` differ by who decided. `disabled` is an explicit kill * switch (`GENKIT_REFLECTION_ENABLED=false`) that even a direct * `ReflectionServer.start()` honours. `off` only means nothing in the * environment asked for a server, so an explicit start still runs one with * defaults. */ type ReflectionConfig = { kind: 'disabled'; } | { kind: 'off'; } | ReflectionServerConfig; /** How a running reflection API connects: dial out (v2) or listen (v1). */ type ReflectionServerConfig = { kind: 'v2'; url: string; secret?: string; } | { kind: 'v1'; host: string; port: ReflectionPort; secret?: string; }; /** Minimal view of the environment, so this stays testable and platform-free. */ type ReflectionEnv = Record; /** * Resolves the port for the v1 server. Whoever chose a port, the environment * or the code, gets exactly that port; only an unchosen port is probed. * * Code values: `undefined` is unset, `0` lets the OS pick (same as * `GENKIT_REFLECTION_PORT=0` and `net.Server.listen`), 1..65535 is exact. * Anything else throws, even when the environment port wins, so a bad value * fails regardless of deployment. */ declare function resolveReflectionPort(envPort: number | undefined, optionPort: number | undefined): ReflectionPort; /** * Resolves how the reflection API should run. * * Whether it runs: * - `GENKIT_REFLECTION_ENABLED=false` turns it off, even under dev. * - `GENKIT_REFLECTION_ENABLED=true` turns it on in any environment. * - Unset, it runs only under `GENKIT_ENV=dev`, as it always has. * * How it runs, once on: `GENKIT_REFLECTION_V2_SERVER` dials out; otherwise the * v1 server listens on `GENKIT_REFLECTION_HOST`/`GENKIT_REFLECTION_PORT`. * Those are settings, not on-switches: a stray value in a production env does * not expose the API, and is not even parsed while reflection is off. * * The environment port beats `options.port` on purpose: whoever set the * variable is typically the supervisor that already published that port. * `options.port` is validated even when unused so a bad value fails early. * * @hidden */ declare function resolveReflectionConfig(env: ReflectionEnv, options?: { port?: number; }): ReflectionConfig; /** * The "how it runs" half of {@link resolveReflectionConfig}, without the * on/off decision. For callers that already decided to run a server, such as * a direct `ReflectionServer.start()`. */ declare function resolveReflectionServerConfig(env: ReflectionEnv, options?: { port?: number; }): ReflectionServerConfig; /** * Host to advertise in the runtime discovery file for a server bound to * `host`. A wildcard bind is reachable on loopback, and `0.0.0.0` is not a * valid destination everywhere, so it is advertised as `127.0.0.1`. IPv6 * literals are bracketed for use in a URL. */ declare function advertisedReflectionHost(host: string): string; /** * Whether a host is loopback, and so unreachable from other machines. Only * `localhost` and literal loopback IPs count; a hostname like * `127.internal.example` may resolve anywhere. */ declare function isLoopbackHost(host: string): boolean; /** * Constant-time secret comparison over sha256 digests, which gives equal-length * inputs without leaking the expected length. */ declare function secretsEqual(a: string, b: string): boolean; export { DEFAULT_REFLECTION_HOST, DEFAULT_REFLECTION_PORT, REFLECTION_AUTH_ERROR_CODE, REFLECTION_SECRET_HEADER, type ReflectionConfig, type ReflectionEnv, type ReflectionPort, type ReflectionServerConfig, advertisedReflectionHost, isLoopbackHost, resolveReflectionConfig, resolveReflectionPort, resolveReflectionServerConfig, secretsEqual };