@ngotrnghia1811/opencode-windsurf-auth 0.1.0 → 0.1.2

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.
@@ -19,6 +19,7 @@ export interface GetChatMessageInput {
19
19
  parametersJsonSchema: string;
20
20
  }>;
21
21
  modelId: string;
22
+ maxOutputTokens: number;
22
23
  sessionId?: string;
23
24
  }
24
25
  export declare function encodeGetChatMessageRequest(input: GetChatMessageInput): Uint8Array;
@@ -68,10 +68,10 @@ function encodeTool(name, description, parametersJsonSchema) {
68
68
  return concat(encodeStringField(1, name), encodeStringField(2, description), encodeStringField(3, parametersJsonSchema));
69
69
  }
70
70
  /** Build the model_params sub-message (f8). */
71
- function encodeModelParams() {
71
+ function encodeModelParams(maxOutputTokens) {
72
72
  return concat(encodeVarintField(1, 1), // f1: unk1 (=1)
73
73
  encodeVarintField(2, 128000), // f2: max_context_tokens
74
- encodeVarintField(3, 400), // f3: max_output_tokens
74
+ encodeVarintField(3, maxOutputTokens), // f3: max_output_tokens
75
75
  encodeFixed64Field(5, 1.0), // f5: temperature
76
76
  encodeVarintField(7, 40), // f7: top_k
77
77
  encodeFixed64Field(8, 0.95));
@@ -103,7 +103,7 @@ export function encodeGetChatMessageRequest(input) {
103
103
  // f7: unk7 = 5
104
104
  encodeVarintField(7, 5),
105
105
  // f8: model_params
106
- encodeMessageField(8, encodeModelParams()),
106
+ encodeMessageField(8, encodeModelParams(input.maxOutputTokens)),
107
107
  // f10: tools[] (repeated)
108
108
  ...input.tools.map((t) => encodeMessageField(10, encodeTool(t.name, t.description, t.parametersJsonSchema))),
109
109
  // f15: unk15
package/dist/models.js CHANGED
@@ -27,7 +27,7 @@ const BASE_MODEL = {
27
27
  },
28
28
  limit: {
29
29
  context: 128_000,
30
- output: 8_192,
30
+ output: 32_000,
31
31
  },
32
32
  status: "active",
33
33
  options: {},
@@ -37,7 +37,7 @@ const BASE_MODEL = {
37
37
  const windsurfModel = (key, name, apiId, inputCost, outputCost, reasoning = false) => ({
38
38
  ...BASE_MODEL,
39
39
  id: `windsurf/${key}`,
40
- name: `Windsurf ${name}`,
40
+ name: `ws ${name}`,
41
41
  capabilities: { ...BASE_MODEL.capabilities, reasoning },
42
42
  cost: { input: inputCost, output: outputCost, cache: { read: 0, write: 0 } },
43
43
  api: { id: apiId, url: "", npm: PROVIDER_NPM() },
@@ -186,19 +186,83 @@ async function streamViaDirectConnect(controller, options, modelId, tracker, sig
186
186
  messages,
187
187
  tools,
188
188
  modelId,
189
+ maxOutputTokens: options.maxOutputTokens ?? 4096,
189
190
  });
190
191
  let reasoningStarted = false;
191
192
  let textStarted = false;
192
193
  let finished = false;
193
194
  const toolCalls = new Map();
194
195
  let toolCallStarted = false;
196
+ // Build lookup from tool name → JSON Schema properties for coercion.
197
+ // Windsurf models sometimes emit nested JSON arrays/objects as JSON-encoded
198
+ // strings rather than native values (e.g. {"questions": "[...]"}), which
199
+ // causes downstream Zod validation to fail. This map lets flushToolCall
200
+ // un-wrap those values transparently.
201
+ const toolSchemaMap = new Map();
202
+ for (const t of options.tools ?? []) {
203
+ if (t.type !== "function")
204
+ continue;
205
+ const ft = t;
206
+ const schema = ft.inputSchema;
207
+ const props = schema?.properties;
208
+ if (props && typeof props === "object" && !Array.isArray(props)) {
209
+ toolSchemaMap.set(ft.name, props);
210
+ }
211
+ }
195
212
  const events = streamGetChatMessage(body, signal);
196
213
  function flushToolCall(id) {
197
214
  const tc = toolCalls.get(id);
198
215
  if (!tc)
199
216
  return;
200
217
  toolCalls.delete(id);
201
- const input = tc.argsChunks.join("");
218
+ const rawInput = tc.argsChunks.join("");
219
+ let input = rawInput;
220
+ try {
221
+ const parsed = JSON.parse(rawInput);
222
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
223
+ const props = toolSchemaMap.get(tc.name);
224
+ if (props) {
225
+ let modified = false;
226
+ for (const key of Object.keys(props)) {
227
+ const value = parsed[key];
228
+ if (typeof value !== "string")
229
+ continue;
230
+ const schemaType = props[key].type;
231
+ if (!schemaType)
232
+ continue;
233
+ const wantsArray = schemaType === "array" ||
234
+ (Array.isArray(schemaType) && schemaType.includes("array"));
235
+ const wantsObject = schemaType === "object" ||
236
+ (Array.isArray(schemaType) && schemaType.includes("object"));
237
+ if (!wantsArray && !wantsObject)
238
+ continue;
239
+ try {
240
+ const inner = JSON.parse(value);
241
+ if (wantsArray && Array.isArray(inner)) {
242
+ parsed[key] = inner;
243
+ modified = true;
244
+ }
245
+ else if (wantsObject &&
246
+ inner !== null &&
247
+ typeof inner === "object" &&
248
+ !Array.isArray(inner)) {
249
+ parsed[key] = inner;
250
+ modified = true;
251
+ }
252
+ }
253
+ catch {
254
+ // inner parse failed — leave original string value
255
+ }
256
+ }
257
+ if (modified) {
258
+ input = JSON.stringify(parsed);
259
+ }
260
+ }
261
+ }
262
+ }
263
+ catch {
264
+ // outer parse failed — emit raw joined string unchanged
265
+ }
202
266
  controller.enqueue({ type: "tool-input-end", id });
203
267
  controller.enqueue({ type: "tool-call", toolCallId: id, toolName: tc.name, input });
204
268
  trackContent(tracker, "tool-call");
package/package.json CHANGED
@@ -1,14 +1,21 @@
1
1
  {
2
2
  "name": "@ngotrnghia1811/opencode-windsurf-auth",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "keywords": ["opencode", "windsurf", "llm", "provider", "plugin", "ai"],
8
+ "keywords": [
9
+ "opencode",
10
+ "windsurf",
11
+ "llm",
12
+ "provider",
13
+ "plugin",
14
+ "ai"
15
+ ],
9
16
  "repository": {
10
17
  "type": "git",
11
- "url": "https://github.com/ngotrnghia1811/opencode-windsurf-auth"
18
+ "url": "git+https://github.com/ngotrnghia1811/opencode-windsurf-auth.git"
12
19
  },
13
20
  "main": "./dist/index.js",
14
21
  "types": "./dist/index.d.ts",