Skip to content

Commit

Permalink
refactor(stream-text): unexport chunk header prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Feb 15, 2025
1 parent 83a65ca commit 0f75b9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 0 additions & 3 deletions packages/stream-text/src/const.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { AssistantMessage, FinishReason, Message, ToolCall, Usage } from '@xsai/shared-chat'

// eslint-disable-next-line @masknet/string-no-data-url
export const chunkHeaderPrefix = 'data:'

export interface StreamTextChoice {
finish_reason?: FinishReason | null
index: number
Expand Down
8 changes: 5 additions & 3 deletions packages/stream-text/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { StreamTextChunkResult } from './const'

import { chunkHeaderPrefix } from './const'
/** @internal */
// eslint-disable-next-line @masknet/string-no-data-url
const CHUNK_HEADER_PREFIX = 'data:'

export const parseChunk = (text: string): [StreamTextChunkResult | undefined, boolean] | never => {
if (!text || !text.startsWith(chunkHeaderPrefix))
if (!text || !text.startsWith(CHUNK_HEADER_PREFIX))
return [undefined, false]

// Extract content after "data:" prefix
const content = text.slice(chunkHeaderPrefix.length)
const content = text.slice(CHUNK_HEADER_PREFIX.length)
// Remove leading single space if present
const data = content.startsWith(' ') ? content.slice(1) : content

Expand Down

0 comments on commit 0f75b9d

Please sign in to comment.