@faapi/faapi 0.0.0-canary.4e89b9b → 0.0.0-canary.991c0b8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -54,6 +54,17 @@ interface SseEvent {
54
54
  interface SseWriter {
55
55
  /** 推送一个 SSE 事件 */
56
56
  send(event: SseEvent): void;
57
+ /**
58
+ * 直接写入原始字节/字符串,不做任何 SSE 序列化
59
+ *
60
+ * 用于透传上游已有的 SSE 原文(如 LLM 中转平台逐 chunk 转发 OpenAI 响应)。
61
+ * 调用方负责保证内容符合 HTML5 SSE 规范;`send` 会再次加 `data: ` 前缀,
62
+ * 不适用于原文透传场景。
63
+ *
64
+ * 接受 string 或 Uint8Array(Buffer 是 Uint8Array 子类,自然兼容)。
65
+ * 与 `send` 一致:close/aborted 后静默忽略,不抛错。
66
+ */
67
+ sendRaw(chunk: string | Uint8Array): void;
57
68
  /** 推送一个 error 事件并关闭流(用于流式输出中报错的优雅终止) */
58
69
  sendError(error: unknown): void;
59
70
  /** 关闭流(多次调用安全) */
package/dist/index.js CHANGED
@@ -1161,6 +1161,11 @@ function createSseWriter() {
1161
1161
  const text = encodeSseEvent(event);
1162
1162
  controller.enqueue(encoder.encode(text));
1163
1163
  },
1164
+ sendRaw(chunk) {
1165
+ if (closed || !controller) return;
1166
+ const bytes = typeof chunk === "string" ? encoder.encode(chunk) : chunk;
1167
+ controller.enqueue(bytes);
1168
+ },
1164
1169
  sendError(error) {
1165
1170
  if (closed || !controller) return;
1166
1171
  const message = error instanceof Error ? error.message : String(error);