' .'' .''; public function params(): array { return [ 'title' => ParamSpec::at(1), 'message' => ParamSpec::markdown(2), 'style' => ParamSpec::at(3, 'block'), ]; } public function block(Call $call): bool { return $this->style($call) === 'block'; } private function style(Call $call): string { $style = trim((string) $call->param('style')); return in_array($style, self::STYLES, true) ? $style : 'block'; } private function title(Call $call, RenderContext $ctx): string { $title = trim((string) $call->param('title')); return $title !== '' ? $title : (string) __('labels.ai_generated', [], $ctx->lang($call->scope)); } /** * @return array */ public function props(Call $call, RenderContext $ctx): array { return ['title' => $this->title($call, $ctx), 'style' => $this->style($call)]; } public function children(Call $call, RenderContext $ctx): ?Document { return $call->slot('message'); } private function message(Call $call, RenderContext $ctx): string { $slot = $call->slot('message'); return $slot === null ? '' : trim($ctx->renderString($slot)); } public function text(Call $call, RenderContext $ctx): string { $message = $this->message($call, $ctx); $title = $this->title($call, $ctx); return $message === '' ? "[{$title}]" : "[{$title}] {$message}"; } /** * 是界面提示而不是正文:prompt 里不出现。 */ public function plain(Call $call, RenderContext $ctx, Format $format): string { return $format === Format::Prompt ? '' : $this->text($call, $ctx); } /** * 只用 span(block 样式靠 CSS 显示成块),写在句子中间、脚注里都不会切断外层结构。 */ public function html(Call $call, RenderContext $ctx): string { $slot = $call->slot('message'); $message = $slot !== null && $ctx->renderer instanceof HtmlRenderer ? $ctx->renderer->inlineSafe($slot, $ctx) : e($this->message($call, $ctx)); $title = e($this->title($call, $ctx)); $messageHtml = $message === '' ? '' : ''.$message.''; if ($this->style($call) === 'tag') { return ''.self::ICON.'AI' .''.$title.''.$messageHtml.'' .''; } return '' .''.self::ICON.$title.''.$messageHtml .''; } public function markdown(Call $call, RenderContext $ctx): string { $title = $this->title($call, $ctx); $message = $this->message($call, $ctx); if ($this->style($call) === 'tag') { return '⚠ AI'; } return "\n\n> ⚠ **{$title}**".($message === '' ? '' : "\n>\n> ".str_replace("\n", "\n> ", $message))."\n\n"; } }