wpmind/modules/api-gateway/includes/Stream/StreamResult.php
LinuxJoy 29459364a8 feat: API Gateway Phase 6+7 — SSE 流式处理 + 错误处理 + 审计日志
Phase 6 (SSE 流式处理):
- CancellationToken: 客户端断开检测
- SseConcurrencyGuard: 全局+Key 并发槽位管理
- UpstreamStreamClient: 上游 Provider 流式代理
- SseStreamController: SSE 生命周期编排
- RouteMiddleware: 集成 SSE 流式分支

Phase 7 (错误处理+审计):
- ErrorMapper: WP_Error → OpenAI 错误格式映射 (14种)
- ErrorMiddleware: 异常捕获 + OpenAI 兼容错误响应
- LogMiddleware: 审计日志写入 + 用量统计 upsert

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-08 20:37:10 +08:00

56 lines
1.2 KiB
PHP

<?php
/**
* Stream Result DTO
*
* Immutable data transfer object for stream completion results.
*
* @package WPMind\Modules\ApiGateway\Stream
* @since 1.0.0
*/
declare(strict_types=1);
namespace WPMind\Modules\ApiGateway\Stream;
/**
* Class StreamResult
*
* Read-only value object returned after a streaming operation
* completes, carrying token usage and finish metadata.
*/
final class StreamResult {
/**
* Total tokens consumed during the stream.
*
* @var int
*/
public readonly int $tokens_used;
/**
* Reason the stream finished (e.g. 'stop', 'length', 'error').
*
* @var string
*/
public readonly string $finish_reason;
/**
* Error message if the stream ended abnormally, null otherwise.
*
* @var string|null
*/
public readonly ?string $error;
/**
* Constructor.
*
* @param int $tokens_used Total tokens consumed.
* @param string $finish_reason Reason the stream finished.
* @param string|null $error Error message or null.
*/
public function __construct( int $tokens_used, string $finish_reason, ?string $error = null ) {
$this->tokens_used = $tokens_used;
$this->finish_reason = $finish_reason;
$this->error = $error;
}
}