veryfront 0.1.150 → 0.1.152

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.
@@ -732,14 +732,14 @@ function buildAnthropicGenerateResult(payload: unknown): {
732
732
  };
733
733
  }
734
734
 
735
- function parseAnthropicSseChunk(chunk: string): {
735
+ function parseSseChunk(chunk: string): {
736
736
  events: Array<unknown | "[DONE]">;
737
737
  remainder: string;
738
738
  } {
739
- const blocks = chunk.split("\n\n");
739
+ const blocks = chunk.split(/\r?\n\r?\n/);
740
740
  const remainder = blocks.pop() ?? "";
741
741
  const events = blocks.flatMap((block) => {
742
- const dataLines = block.split("\n")
742
+ const dataLines = block.split(/\r?\n/)
743
743
  .filter((line) => line.startsWith("data:"))
744
744
  .map((line) => line.slice(5).trimStart());
745
745
 
@@ -773,7 +773,7 @@ async function* streamAnthropicCompatibleParts(
773
773
 
774
774
  for await (const chunk of stream) {
775
775
  buffer += decoder.decode(chunk, { stream: true });
776
- const parsed = parseAnthropicSseChunk(buffer);
776
+ const parsed = parseSseChunk(buffer);
777
777
  buffer = parsed.remainder;
778
778
 
779
779
  for (const event of parsed.events) {
@@ -912,7 +912,7 @@ async function* streamAnthropicCompatibleParts(
912
912
  }
913
913
 
914
914
  if (buffer.trim().length > 0) {
915
- const parsed = parseAnthropicSseChunk(`${buffer}\n\n`);
915
+ const parsed = parseSseChunk(`${buffer}\n\n`);
916
916
  for (const event of parsed.events) {
917
917
  if (event === "[DONE]") {
918
918
  continue;
@@ -1313,7 +1313,7 @@ async function* streamGoogleCompatibleParts(
1313
1313
 
1314
1314
  for await (const chunk of stream) {
1315
1315
  buffer += decoder.decode(chunk, { stream: true });
1316
- const parsed = parseOpenAISseChunk(buffer);
1316
+ const parsed = parseSseChunk(buffer);
1317
1317
  buffer = parsed.remainder;
1318
1318
 
1319
1319
  for (const event of parsed.events) {
@@ -1367,7 +1367,7 @@ async function* streamGoogleCompatibleParts(
1367
1367
  }
1368
1368
 
1369
1369
  if (buffer.trim().length > 0) {
1370
- const parsed = parseOpenAISseChunk(`${buffer}\n\n`);
1370
+ const parsed = parseSseChunk(`${buffer}\n\n`);
1371
1371
  for (const event of parsed.events) {
1372
1372
  if (event === "[DONE]") {
1373
1373
  continue;
@@ -1430,36 +1430,6 @@ function buildOpenAIGenerateResult(payload: unknown): {
1430
1430
  };
1431
1431
  }
1432
1432
 
1433
- function parseOpenAISseChunk(chunk: string): {
1434
- events: Array<unknown | "[DONE]">;
1435
- remainder: string;
1436
- } {
1437
- const blocks = chunk.split("\n\n");
1438
- const remainder = blocks.pop() ?? "";
1439
- const events = blocks.flatMap((block) => {
1440
- const dataLines = block.split("\n")
1441
- .filter((line) => line.startsWith("data:"))
1442
- .map((line) => line.slice(5).trimStart());
1443
-
1444
- if (!dataLines.length) {
1445
- return [];
1446
- }
1447
-
1448
- const payload = dataLines.join("\n").trim();
1449
- if (payload === "[DONE]") {
1450
- return ["[DONE]" as const];
1451
- }
1452
-
1453
- try {
1454
- return [JSON.parse(payload) as unknown];
1455
- } catch {
1456
- return [];
1457
- }
1458
- });
1459
-
1460
- return { events, remainder };
1461
- }
1462
-
1463
1433
  async function* streamOpenAICompatibleParts(
1464
1434
  stream: ReadableStream<Uint8Array>,
1465
1435
  ): AsyncIterable<unknown> {
@@ -1471,7 +1441,7 @@ async function* streamOpenAICompatibleParts(
1471
1441
 
1472
1442
  for await (const chunk of stream) {
1473
1443
  buffer += decoder.decode(chunk, { stream: true });
1474
- const parsed = parseOpenAISseChunk(buffer);
1444
+ const parsed = parseSseChunk(buffer);
1475
1445
  buffer = parsed.remainder;
1476
1446
 
1477
1447
  for (const event of parsed.events) {
@@ -1545,7 +1515,7 @@ async function* streamOpenAICompatibleParts(
1545
1515
  }
1546
1516
 
1547
1517
  if (buffer.trim().length > 0) {
1548
- const parsed = parseOpenAISseChunk(`${buffer}\n\n`);
1518
+ const parsed = parseSseChunk(`${buffer}\n\n`);
1549
1519
  for (const event of parsed.events) {
1550
1520
  if (event === "[DONE]") {
1551
1521
  continue;
@@ -1,3 +1,3 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
- export const VERSION = "0.1.150";
3
+ export const VERSION = "0.1.152";