@bxb1337/windsurf-fast-context 1.0.2 → 1.0.3

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.
@@ -5,6 +5,8 @@ const node_zlib_1 = require("node:zlib");
5
5
  const protobuf_js_1 = require("../protocol/protobuf.js");
6
6
  const TOOL_CALL_PREFIX = '[TOOL_CALLS]';
7
7
  const ARGS_PREFIX = '[ARGS]';
8
+ const STOP_TOKEN = '</s>';
9
+ const EMPTY_TOOL_CALLS_PATTERN = /TOOL_CALLS\d*<\/s>\s*\{\}/g;
8
10
  function pushText(parts, text) {
9
11
  if (text.length > 0) {
10
12
  parts.push({ type: 'text', text });
@@ -189,7 +191,9 @@ function decodeResponseText(buffer) {
189
191
  return pickBestExtractedText(extracted);
190
192
  }
191
193
  function convertResponse(buffer) {
192
- const responseText = decodeResponseText(buffer);
194
+ let responseText = decodeResponseText(buffer);
195
+ responseText = responseText.replace(EMPTY_TOOL_CALLS_PATTERN, '');
196
+ responseText = responseText.replace(STOP_TOKEN, '');
193
197
  const parts = [];
194
198
  let cursor = 0;
195
199
  let toolCallCount = 0;
@@ -62,4 +62,19 @@ const response_converter_js_1 = require("./response-converter.js");
62
62
  const result = (0, response_converter_js_1.convertResponse)(compressed);
63
63
  (0, vitest_1.expect)(result).toEqual([{ type: 'text', text: 'hello from gzip' }]);
64
64
  });
65
+ (0, vitest_1.it)('strips empty TOOL_CALLS markers with stop token', () => {
66
+ const input = 'Hello world TOOL_CALLS0</s>{}';
67
+ const result = (0, response_converter_js_1.convertResponse)(Buffer.from(input, 'utf8'));
68
+ (0, vitest_1.expect)(result).toEqual([{ type: 'text', text: 'Hello world ' }]);
69
+ });
70
+ (0, vitest_1.it)('strips standalone stop token', () => {
71
+ const input = 'Hello world</s>';
72
+ const result = (0, response_converter_js_1.convertResponse)(Buffer.from(input, 'utf8'));
73
+ (0, vitest_1.expect)(result).toEqual([{ type: 'text', text: 'Hello world' }]);
74
+ });
75
+ (0, vitest_1.it)('handles TOOL_CALLS with number prefix before stop token', () => {
76
+ const input = 'Text before TOOL_CALLS1</s>{} text after';
77
+ const result = (0, response_converter_js_1.convertResponse)(Buffer.from(input, 'utf8'));
78
+ (0, vitest_1.expect)(result).toEqual([{ type: 'text', text: 'Text before text after' }]);
79
+ });
65
80
  });
@@ -2,6 +2,8 @@ import { gunzipSync } from 'node:zlib';
2
2
  import { extractStrings } from '../protocol/protobuf.js';
3
3
  const TOOL_CALL_PREFIX = '[TOOL_CALLS]';
4
4
  const ARGS_PREFIX = '[ARGS]';
5
+ const STOP_TOKEN = '</s>';
6
+ const EMPTY_TOOL_CALLS_PATTERN = /TOOL_CALLS\d*<\/s>\s*\{\}/g;
5
7
  function pushText(parts, text) {
6
8
  if (text.length > 0) {
7
9
  parts.push({ type: 'text', text });
@@ -186,7 +188,9 @@ function decodeResponseText(buffer) {
186
188
  return pickBestExtractedText(extracted);
187
189
  }
188
190
  export function convertResponse(buffer) {
189
- const responseText = decodeResponseText(buffer);
191
+ let responseText = decodeResponseText(buffer);
192
+ responseText = responseText.replace(EMPTY_TOOL_CALLS_PATTERN, '');
193
+ responseText = responseText.replace(STOP_TOKEN, '');
190
194
  const parts = [];
191
195
  let cursor = 0;
192
196
  let toolCallCount = 0;
@@ -60,4 +60,19 @@ describe('convertResponse', () => {
60
60
  const result = convertResponse(compressed);
61
61
  expect(result).toEqual([{ type: 'text', text: 'hello from gzip' }]);
62
62
  });
63
+ it('strips empty TOOL_CALLS markers with stop token', () => {
64
+ const input = 'Hello world TOOL_CALLS0</s>{}';
65
+ const result = convertResponse(Buffer.from(input, 'utf8'));
66
+ expect(result).toEqual([{ type: 'text', text: 'Hello world ' }]);
67
+ });
68
+ it('strips standalone stop token', () => {
69
+ const input = 'Hello world</s>';
70
+ const result = convertResponse(Buffer.from(input, 'utf8'));
71
+ expect(result).toEqual([{ type: 'text', text: 'Hello world' }]);
72
+ });
73
+ it('handles TOOL_CALLS with number prefix before stop token', () => {
74
+ const input = 'Text before TOOL_CALLS1</s>{} text after';
75
+ const result = convertResponse(Buffer.from(input, 'utf8'));
76
+ expect(result).toEqual([{ type: 'text', text: 'Text before text after' }]);
77
+ });
63
78
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bxb1337/windsurf-fast-context",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "AI SDK V3 provider for Windsurf's Devstral code search API",
5
5
  "type": "module",
6
6
  "scripts": {