New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@pkgai/sse-parser

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pkgai/sse-parser

<!-- automd:badges color="orange" license licenseBranch bundlephobia packagephobia name="@pkgai/sse-parser" -->

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

@pkgai/sse-parser

npm version npm downloads bundle size install size license

SSE EventStream 数据解析器

安装

# ✨ Auto-detect
npx nypm install @pkgai/sse-parser

# npm
npm install @pkgai/sse-parser

# yarn
yarn add @pkgai/sse-parser

# pnpm
pnpm install @pkgai/sse-parser

# bun
bun install @pkgai/sse-parser

# deno
deno install @pkgai/sse-parser

ReadableStream

import { readableStream } from '@pkgai/sse-parser'

const response =await fetch('https://openai-like/v1/chat/completions',{
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer {API_KEY}',
  },
  body: JSON.stringify({
    model: 'qwq-32b',
    messages: [
      {
        role: 'user',
        content: '9.9和9.11谁大',
      },
    ],
    stream: true,
    stream_options: {
      include_usage: true,
    },
  })
})

for await (const chunk of readableStream(response.body!)) {
  console.log(chunk)
  // data: 
  console.log(chunk.data)
  // event:
  console.log(chunk.event)
}

Response

import { response } from '@pkgai/sse-parser'

const res =await fetch('https://openai-like/v1/chat/completions',{
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer {API_KEY}',
  },
  body: JSON.stringify({
    model: 'qwq-32b',
    messages: [
      {
        role: 'user',
        content: '9.9和9.11谁大',
      },
    ],
    stream: true,
    stream_options: {
      include_usage: true,
    },
  })
})

for await (const chunk of response(res)) {
  console.log(chunk)
  // data: 
  console.log(chunk.data)
  // event:
  console.log(chunk.event)
}

EventSourceStream

ReadableStream<Uint8Array> 转换为 ReadableStream<EventSourceMessage>

import { EventSourceStream } from '@pkgai/sse-parser'

const readableStream = getReadableStream()
readableStream.pipeThrough(new EventSourceStream())

贡献者

Published under the MIT license. Made by @Colourlessglow and community 💛

🤖 auto updated with automd

Keywords

event-source

FAQs

Package last updated on 18 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts