TrafficLog class

Prints HTTP request/response traffic in a human-readable form.

The logger is not const because it holds a small mutable flag (_promptPrintedOnce). The first call to systemPrompt prints the prompt in full; later calls truncate it, so the console remains readable while still showing the entire security contract at least once.

When to use

Anywhere a reader needs to audit the interaction between the demo and the AI. The logger is the "show me the bytes on the wire" tool: every prompt, every request body, every response body, every usage block.

How it works

The interpreters call the logger's methods in this order for each complete:

  1. systemPrompt — the system prompt that will be sent.
  2. request — the HTTP envelope (endpoint, model, sentence, body).
  3. response — the HTTP status and raw body.
  4. parsed or refused — the classified reply.

If the port throws, error is called instead of steps 3–4.

Non-obvious

  • The logger writes to stdout directly. It has no buffer, no flush, no file target. For a demo, that is what we want. For a production system, replace _out with a structured logger call.
  • The prompt is printed in full the first time, then truncated. The first call prints all lines. Every subsequent call prints the first 12 lines and appends ... (N more lines — same prompt as scenario 1). That keeps the console readable while guaranteeing the reader sees the full security contract at least once.
  • silent: true suppresses all output. Useful for tests. The logger still runs its truncation logic so the first non-silent call behaves correctly.

Example

final log = TrafficLog();
log.systemPrompt(systemPrompt({'add', 'remove', 'clear'}));
log.request(
  endpoint: 'https://api.deepseek.com/chat/completions',
  model: 'deepseek-flash',
  sentence: 'add 3',
  body: '{"model":"deepseek-flash",...}',
);

Constructors

TrafficLog({bool silent = false})
Creates a TrafficLog.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
silent bool
When true, the logger suppresses output. Useful when running tests or when the caller wants only the parsed result.
final

Methods

error(Object e) → void
Prints an exception from the interpreter or its parser.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parsed(TissueCommand cmd) → void
Prints the parsed verb, args, and confidence.
refused(String reason) → void
Prints a rejection reason.
request({required String endpoint, required String model, required String sentence, required String body}) → void
Prints the HTTP request envelope.
response({required int status, required String body}) → void
Prints the HTTP response status and body.
systemPrompt(String prompt) → void
Prints the system prompt that will be sent.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited