@alisio/plugin-opencode-go 0.1.0-alpha.2 → 0.1.0-alpha.5

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.
Files changed (2) hide show
  1. package/dist/provider.js +65 -5
  2. package/package.json +3 -3
package/dist/provider.js CHANGED
@@ -256,12 +256,23 @@ export class OpenCodeGatewayProvider {
256
256
  if (choice.finish_reason)
257
257
  finish = choice.finish_reason;
258
258
  }
259
- if (finish !== "stop" && finish !== "tool_calls")
259
+ if (finish !== "stop" && finish !== "tool_calls" && finish !== "length")
260
260
  throw new Error(`OpenCode chat response incomplete: ${finish ?? "stream ended"}`);
261
261
  const completed = [...calls.entries()].sort(([a], [b]) => a - b).map(([, call]) => call);
262
262
  if (completed.some((call) => !call.id || !call.name))
263
263
  throw new Error("Incomplete tool call");
264
- yield { type: "completed", message: { role: "assistant", text, calls: completed }, usage };
264
+ if (finish === "length" && !text.trim())
265
+ throw new Error("OpenCode chat response cut off by max output tokens before any usable content; raise limits.maxOutputTokens");
266
+ yield {
267
+ type: "completed",
268
+ message: {
269
+ role: "assistant",
270
+ text,
271
+ calls: completed,
272
+ ...(finish === "length" ? { truncated: true } : {}),
273
+ },
274
+ usage,
275
+ };
265
276
  }
266
277
  responsesInput(messages) {
267
278
  const input = [];
@@ -312,8 +323,39 @@ export class OpenCodeGatewayProvider {
312
323
  yield { type: "text_delta", delta: event.delta };
313
324
  if (event.type === "response.reasoning_summary_text.delta")
314
325
  yield { type: "reasoning_delta", delta: event.delta };
315
- if (["response.failed", "response.incomplete", "error"].includes(event.type))
326
+ if (["response.failed", "error"].includes(event.type))
316
327
  throw new Error(`OpenCode Responses request failed: ${event.type}`);
328
+ if (event.type === "response.incomplete") {
329
+ complete = true;
330
+ const output = event.response.output;
331
+ const calls = output
332
+ .filter((item) => item.type === "function_call")
333
+ .map((item) => ({ id: item.call_id, name: item.name, arguments: item.arguments }));
334
+ const text = output
335
+ .filter((item) => item.type === "message")
336
+ .flatMap((item) => item.content ?? [])
337
+ .filter((item) => item.type === "output_text")
338
+ .map((item) => item.text)
339
+ .join("");
340
+ if (!text.trim())
341
+ throw new Error("OpenCode Responses response cut off by max output tokens before any usable content; raise limits.maxOutputTokens");
342
+ if (calls.some((call) => !call.id || !call.name))
343
+ throw new Error("Incomplete tool call");
344
+ const u = event.response.usage;
345
+ yield {
346
+ type: "completed",
347
+ message: { role: "assistant", text, calls, providerData: output, truncated: true },
348
+ usage: u
349
+ ? {
350
+ input: u.input_tokens ?? 0,
351
+ output: u.output_tokens ?? 0,
352
+ ...(typeof u.input_tokens_details?.cached_tokens === "number"
353
+ ? { cachedInput: u.input_tokens_details.cached_tokens }
354
+ : {}),
355
+ }
356
+ : undefined,
357
+ };
358
+ }
317
359
  if (event.type === "response.completed") {
318
360
  complete = true;
319
361
  const output = event.response.output;
@@ -456,7 +498,8 @@ export class OpenCodeGatewayProvider {
456
498
  stopReason = event.delta?.stop_reason ?? stopReason;
457
499
  }
458
500
  }
459
- if (stopReason !== "end_turn" && stopReason !== "tool_use")
501
+ const truncated = stopReason === "max_tokens";
502
+ if (!truncated && stopReason !== "end_turn" && stopReason !== "tool_use")
460
503
  throw new Error(`OpenCode Messages response incomplete: ${stopReason ?? "stream ended"}`);
461
504
  const calls = [];
462
505
  for (let index = 0; index < blocks.length; index++) {
@@ -465,7 +508,24 @@ export class OpenCodeGatewayProvider {
465
508
  continue;
466
509
  const args = argumentParts.get(index) || JSON.stringify(block.input ?? {});
467
510
  calls.push({ id: block.id, name: block.name, arguments: args });
468
- block.input = JSON.parse(args || "{}");
511
+ try {
512
+ block.input = JSON.parse(args || "{}");
513
+ }
514
+ catch {
515
+ if (!truncated)
516
+ throw new Error("Incomplete tool call");
517
+ throw new Error(`OpenCode Messages response incomplete: tool call arguments cut off for ${block.name}`);
518
+ }
519
+ }
520
+ if (truncated) {
521
+ if (!text.trim())
522
+ throw new Error("OpenCode Messages response cut off by max output tokens before any usable content; raise limits.maxOutputTokens");
523
+ yield {
524
+ type: "completed",
525
+ message: { role: "assistant", text, calls, providerData: blocks, truncated: true },
526
+ usage: { input, output },
527
+ };
528
+ return;
469
529
  }
470
530
  yield {
471
531
  type: "completed",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alisio/plugin-opencode-go",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.5",
4
4
  "description": "Built-in OpenCode Go model provider for Alisio.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,10 +21,10 @@
21
21
  "node": ">=22.16"
22
22
  },
23
23
  "peerDependencies": {
24
- "@alisio/sdk": "^0.1.0-alpha.2"
24
+ "@alisio/sdk": "^0.1.0-alpha.5"
25
25
  },
26
26
  "devDependencies": {
27
- "@alisio/sdk": "0.1.0-alpha.2"
27
+ "@alisio/sdk": "0.1.0-alpha.5"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public",