Add AI Client connector (XWPENG-20) - #1967
Conversation
51dfd34 to
496a047
Compare
Register a bundled Stream connector that listens to wp_ai_client_before/ after_generate_result and writes activity records with provider, model, token counts (input/output/thought), duration, and extended metadata. - Single opt-in toggle (log_prompt_and_response_text) for full prompt/ response capture, disabled by default with PII warning - wp_stream_ai_client_log_prompt / log_response filters for redaction - List table first-line summary preview for multiline entries - PHPUnit coverage for logging, toggles, filters, and graceful no-op - Docs, changelog, connectors.md regen; gitignore .ai/ local tooling
496a047 to
f4132b0
Compare
bartoszgadomski
left a comment
There was a problem hiding this comment.
Nice work @shadyvb! I left inline comments, please take a look.
… and PII warnings match Stream's existing patterns. Truncated summaries now show an ellipsis, log templates stay translatable without early escaping, and operators are warned that stored prompt text may be forwarded to alerts or webhooks.
…display. The connector deliberately renders tokens as %4$d/%6$d/%5$d; align PHPUnit expectations with that summary format so CI passes.
Resolve changelog conflict by keeping [Unreleased] AI Client entries above the 4.4.0 release notes from develop.
bartoszgadomski
left a comment
There was a problem hiding this comment.
Follow-up notes after the review-response commits.
|
|
||
| When WordPress 7.0+ provides the AI Client event dispatcher (`WP_AI_Client_Event_Dispatcher`), Stream logs each AI generation as an activity record under **AI Client → Prompts → Generated**. If the dispatcher is not available, the connector registers no hooks and has no effect. | ||
|
|
||
| By default, Stream stores metadata for every generation: operation, provider, model, input/output/thought token counts, duration, finish reason, and other extended fields when present. The activity summary shows a one-line preview (for example, `chat via openai/gpt-4o (tokens: 120/0/45) in 842ms`). Multiline summaries display only the first line in the list table; open a record to see the full text. |
There was a problem hiding this comment.
Leftover docs: this still describes the counts as input/output/thought, but the summary template (and the PHPUnit assertion) renders input/thought/output. The example 120/0/45 already matches that display order.
Please align the prose with the deliberate %4$d/%6$d/%5$d format, e.g. “input/thought/output token counts” and a short note that the three numbers in the preview are input, thought, then output.
|
|
||
| By default, Stream stores metadata for every generation: operation, provider, model, input/output/thought token counts, duration, finish reason, and other extended fields when present. The activity summary shows a one-line preview (for example, `chat via openai/gpt-4o (tokens: 120/0/45) in 842ms`). Multiline summaries display only the first line in the list table; open a record to see the full text. | ||
|
|
||
| Prompt and response text are **not** logged by default. To opt in, enable **Log Prompt and Response text** under **Stream → Settings → AI Client**. When enabled, prompt and response text are appended to the activity summary (not stored in meta, which is size-limited). **Privacy Warning:** This content may include personally identifiable information (PII). Ensure your privacy policy covers AI data collection before enabling. |
There was a problem hiding this comment.
Leftover docs: the Settings checkbox warning now covers Slack/IFTTT (and the redaction filters), but this readme.txt PII paragraph still only talks about storage.
Please mirror the settings copy here so operators who never open Stream → Settings still see that prompt/response text may be forwarded to configured alerts or webhooks, and that wp_stream_ai_client_log_prompt / wp_stream_ai_client_log_response are the redaction point.
| * Injects the AI Client settings section into Stream's settings fields array. | ||
| * | ||
| * Adds opt-in checkbox — log_prompt_and_response_text — under | ||
| * a dedicated "AI Client" section in Stream → Settings. Both default to off. |
There was a problem hiding this comment.
Leftover docs: this still says “Both default to off”, but there is only one checkbox (log_prompt_and_response_text). Looks like a leftover from an earlier two-toggle design — please drop “Both”.
| '<strong>%s</strong> %s %s', | ||
| esc_html__( 'Privacy Warning:', 'stream' ), | ||
| esc_html__( 'This content may include personally identifiable information (PII). Ensure your privacy policy covers AI data collection before enabling.', 'stream' ), | ||
| esc_html__( 'When enabled, prompt and response text are stored in the record summary and may be forwarded verbatim to any configured Stream alerts or webhooks (e.g. Slack, IFTTT). Use the wp_stream_ai_client_log_prompt and wp_stream_ai_client_log_response filters to redact or omit text before it is stored.', 'stream' ) |
There was a problem hiding this comment.
“Verbatim” overstates what Stream actually persists.
With this setting on, prompt/response text is written into summary via log(), then DB::sanitize_record() runs wp_strip_all_tags() on every scalar field before insert (classes/class-db.php). Markup, List<T>-style generics, and anything that looks like an HTML tag is altered or removed, so the stored (and alert-forwarded) text is not a byte-for-byte copy of the generation.
That sanitizer is existing Stream behavior, not new in this PR — but this connector is the first to put user-authored bodies in summary, and this warning is the first to promise they are stored and forwarded verbatim.
Please either soften the wording (e.g. that HTML is stripped on insert) or document the limitation next to the opt-in. Same note belongs in readme.txt if you add the alerts sentence there.
Fixes XWPENG-20.
Adds a bundled AI Client connector to Stream that listens to WordPress AI Client
before/after_generate_resulthooks and writes audit records for each generation. Records include acting user, timestamp, provider, model, input/output/thinking token counts, duration, finish reason, and extended metadata. Full prompt and response text capture is supported via a single opt-in setting (log_prompt_and_response_text), disabled by default with a PII warning. Developer filterswp_stream_ai_client_log_promptandwp_stream_ai_client_log_responseallow redaction or omission of stored text. The Stream list table shows only the first line of multiline summaries so token/metadata rows stay scannable when prompt/response logging is enabled.Checklist
contributing.md).Release Changelog
Release Checklist
developbranch.readme.txt.stream.php.Stable taginreadme.txt.classes/class-plugin.php.Test plan
wp_stream_ai_client_log_prompt/wp_stream_ai_client_log_responseto redact text; confirm stored values reflect the filter output.WP_AI_Client_Event_Dispatcher, confirm Stream loads with no fatals and no AI records are written.vendor/bin/phpunit --filter Connector_AI_Clientandvendor/bin/phpunit --filter Test_List_Table.