show streamed time to first text in wp ai-chat-bedrock usage
wp ai-chat-bedrock usage, in its default per-day mode, now ends with one Time to first text line for streamed answers. The line uses the existing first-token counters, which the dashboard already shows. It gives the number of answers measured, the average in ms and the median band (under 1 s, 1 to 2 s, 2 to 5 s, 5 to 10 s, or 10 s and over). It covers the --days window, capped at the 30-day retention period: --days=90 prints '30 days' and --days=1 prints '1 day'. With no measurements, after a reset, or when the stored count is missing or invalid, it reads 'unknown, no streamed answers recorded.' and never shows 0 ms. A missing or invalid sum prints 'average unknown'. Missing or invalid band counters print 'median unknown'. The table, Total and Prompt cache lines are unchanged. --by-model prints no latency line, and wp help ai-chat-bedrock usage describes the new line. The plugin is now version 1.66.0. Controller-run results: before the change, the new feature test failed 13 of its 14 cases, because the latency line did not exist yet. On commit a540596 the controller ran four checks and all passed. The feature test passed all 14 cases. bin/prerelease.sh passed with 62 suites, including cli.php and usage.php, plus the JS script tests, phpcs, version consistency at 1.66.0 and readme limits (changelog 4924 of 5000 characters). tests/tooling.php passed. bin/build-package.py built ai-chat-for-amazon-bedrock.1.66.0.zip with 122 files. I made no edits or runs at this stage; this text only describes those results.
Use it
Prerequisites: a WordPress site with AI Chat for Amazon Bedrock 1.66.0 active, and WP-CLI run as a user who can manage the site.
Normal use (real data from streamed chat answers):
wp ai-chat-bedrock usage --days=7
...existing per-day table, Total line and optional Prompt cache line...
Time to first text (streamed, 7 days): 12 answers, average 1840 ms, median 1 to 2 s.
(The figures above are illustrative, not measured.)
On a site with no streamed answers yet:
Time to first text (streamed, 7 days): unknown, no streamed answers recorded.
Other modes:
wp ai-chat-bedrock usage --days=90 (the line reads '(streamed, 30 days)')
wp ai-chat-bedrock usage --days=1 (today only)
wp ai-chat-bedrock usage --by-model (unchanged, no latency line)
wp help ai-chat-bedrock usage
Optional manual example with SYNTHETIC data. Use a staging site only, because this writes to the real counters there:
wp eval 'foreach ( array( 800, 1500, 2500 ) as $ms ) { AI_Chat_Bedrock_Usage::record_first_token( $ms ); }'
wp ai-chat-bedrock usage --days=1
If there was no other streamed traffic today, the last line should read: Time to first text (streamed, 1 day): 3 answers, average 1600 ms, median 1 to 2 s.
The controller did not run this manual example; the automated tests seed the counters directly. No input file is needed.Scope
Only the default per-day mode prints the line. There is no JSON output, no latency per model or per day, no percentiles beyond the median band, and no thresholds or alerts. Non-streamed answers are not covered. Latency is measured on the server, from the start of the Bedrock request to the first text. It leaves out page load and the visitor's network, and it reflects this site only, not AWS service health. If band counters are only partly present, the line shows whatever band the existing summary returns. Strings are untranslated plain English, like the rest of the command. The tests use WP_CLI and option stubs with synthetic seeded counters. Passing them shows that the formatting and the unknown-value handling work, not that the measurements are accurate or the bands well chosen. Not verified: the prerelease Plugin Check, Live integration and Translation template stages were skipped because no --wp-cli was given, core-ai-library.php was skipped, and the command has not been run on a real WP-CLI install. The existing JS script tests ran inside prerelease. This feature changes no UI, and no one did a visual or screenshot review of it.
Upgrade and rollback
Update to 1.66.0. This version sets the plugin header, AI_CHAT_BEDROCK_VERSION, the readme Stable tag, the changelog entry and the upgrade notice. The readme FAQ and docs/faq.md now describe the CLI line and its 30-day limit. Nothing in storage or options changes; the line only reads the existing daily first-token counters. Scripts that parse this command's output should expect one extra final line in the default mode. To roll back, reinstall 1.65.x. The CLI line goes away, and the counters and the dashboard figure stay, with no data lost.