@ngotrnghia1811/opencode-windsurf-auth 0.1.1 → 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.
- package/dist/chat-request.d.ts +1 -0
- package/dist/chat-request.js +3 -3
- package/dist/models.js +1 -1
- package/dist/windsurf-provider.js +65 -1
- package/package.json +1 -1
package/dist/chat-request.d.ts
CHANGED
package/dist/chat-request.js
CHANGED
|
@@ -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,
|
|
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
|
@@ -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
|
|
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");
|