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:
- systemPrompt — the system prompt that will be sent.
- request — the HTTP envelope (endpoint, model, sentence, body).
- response — the HTTP status and raw body.
- parsed or refused — the classified reply.
If the port throws, error is called instead of steps 3–4.
Non-obvious
- The logger writes to
stdoutdirectly. It has no buffer, no flush, no file target. For a demo, that is what we want. For a production system, replace_outwith 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: truesuppresses 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
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