MockGPT · 模拟模型与调试
Kit · 可选业务库 · 返回本层目录
| 符号 | 类别 | 用途 |
|---|---|---|
CallRecord | interface | Detached snapshot of one accepted call, exposed through MockGPT.records. |
createMockHandler | function | Create a bare Node request listener backed by the mock. |
createMockServer | function | Create a self-contained mock HTTP server with explicit listen/close control. No UI or static assets are served: only the model routes answer, everything else is a 404. |
encodeModelResponse | function | Optional app-owned codec; validation and encoding consume the same snapshots. Thin public wrapper over encodeModel: re-validates identity arguments and re-snapshots both the request and the model output, so callers that build replies themselves get identical validation and cannot mutate the mock's state afterwards. |
Generated | type | What a rule may produce: plain data, or a descriptor that changes transport behaviour. |
GenerationContext | interface | Everything a rule or generator may read for one accepted call. The context is frozen; the only mutable side channel is report, and only while the call is still pending. |
GenerationInput | interface | Input of MockGPT.generate. Normalized exactly like an HTTP request body, so a rule matches identically through both entry points; only model and messages are required. |
GenerationOptions | interface | Per-call options of MockGPT.generate. |
Generator | type | A rule's output: either a fixed value (deep-copied and frozen when the instance is built) or a function evaluated per call. A function may be async and is awaited under cancellation. |
generatorNames | constant | |
generators | constant | |
HandlerOptions | interface | Options shared by the standalone server and the bare request handler. |
HttpFault | interface | A simulated HTTP-level failure returned instead of a model reply. |
isPublicAddress | function | Decide whether an address is an acceptable public destination. |
JsonValue | type | Any value accepted by the package's JSON snapshot rules: strings, finite numbers, booleans, null, arrays and plain objects. |
LoadedPage | interface | A fetched page body plus the metadata needed for decoding and diagnostics. |
Message | type | One entry of an OpenAI chat conversation. The runtime validates role against the OpenAI role set and validates the outer shape of content; every other field is retained verbatim so vendor extensions flow through. |
MockGPT | class | Configurable mock model instance. Create one per test or per mock server. |
MockGPTError | class | Error type carrying a stable machine-readable code plus optional HTTP status and details. The HTTP adapter maps status onto the response and serializes code/details into the OpenAI-style error body, so codes are part of the public contract. |
MockGPTOptions | interface | Construction options of a MockGPT instance. |
ModelOutput | interface | The model-authored part of a reply, before it becomes JSON or SSE frames. |
ModelRequest | interface | A normalized /chat/completions request, produced by snapshotRequest. Optional undefined fields have already been dropped and stream is already defaulted, so rules always observe the same shape regardless of whether the caller used generate or the injected fetch. |
OutputOptions | interface | Transport-level knobs of a generated response. All values are simulated: they affect framing and timing of the mock reply, not real model behaviour. |
ResponseDescription | class | Wrapper that distinguishes a transport instruction from ordinary generator data. kind: 'model' carries a ModelOutput, 'http' an HttpFault response, and 'reject' a message used to simulate a network failure. Instances are recognized by brand rather than by instanceof alone, so descriptors survive crossing the ESM/CJS boundary. |
responses | constant | |
routes | constant | |
Rule | interface | One ordered matching rule of a MockGPT instance. |
ServerOptions | interface | Options of createMockServer, adding shutdown behaviour. |
sources | constant | |
TextOptions | interface | Common options of the text generators. |
TextSource | type | Text supplied to a text generator. A function may be async; it receives the per-call context so a source can depend on the prompt or on the call index. |
ToolCall | interface | A tool call the mocked assistant emits instead of executing. |
Usage | interface | Token accounting reported by the OpenAI API; validated for internal consistency. |
WebOptions | interface | Configuration of sources.web. |
WebProfile | type | Name of an entry in webHeaderProfiles. |