@alisio/plugin-opencode 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
@@ -341,12 +341,23 @@ export class OpenCodeGatewayProvider {
341
341
  if (choice.finish_reason)
342
342
  finish = choice.finish_reason;
343
343
  }
344
- if (finish !== "stop" && finish !== "tool_calls")
344
+ if (finish !== "stop" && finish !== "tool_calls" && finish !== "length")
345
345
  throw new Error(`OpenCode chat response incomplete: ${finish ?? "stream ended"}`);
346
346
  const completed = [...calls.entries()].sort(([a], [b]) => a - b).map(([, call]) => call);
347
347
  if (completed.some((call) => !call.id || !call.name))
348
348
  throw new Error("Incomplete tool call");
349
- yield { type: "completed", message: { role: "assistant", text, calls: completed }, usage };
349
+ if (finish === "length" && !text.trim())
350
+ throw new Error("OpenCode chat response cut off by max output tokens before any usable content; raise limits.maxOutputTokens");
351
+ yield {
352
+ type: "completed",
353
+ message: {
354
+ role: "assistant",
355
+ text,
356
+ calls: completed,
357
+ ...(finish === "length" ? { truncated: true } : {}),
358
+ },
359
+ usage,
360
+ };
350
361
  }
351
362
  responsesInput(messages) {
352
363
  const input = [];
@@ -397,8 +408,39 @@ export class OpenCodeGatewayProvider {
397
408
  yield { type: "text_delta", delta: event.delta };
398
409
  if (event.type === "response.reasoning_summary_text.delta")
399
410
  yield { type: "reasoning_delta", delta: event.delta };
400
- if (["response.failed", "response.incomplete", "error"].includes(event.type))
411
+ if (["response.failed", "error"].includes(event.type))
401
412
  throw new Error(`OpenCode Responses request failed: ${event.type}`);
413
+ if (event.type === "response.incomplete") {
414
+ complete = true;
415
+ const output = event.response.output;
416
+ const calls = output
417
+ .filter((item) => item.type === "function_call")
418
+ .map((item) => ({ id: item.call_id, name: item.name, arguments: item.arguments }));
419
+ const text = output
420
+ .filter((item) => item.type === "message")
421
+ .flatMap((item) => item.content ?? [])
422
+ .filter((item) => item.type === "output_text")
423
+ .map((item) => item.text)
424
+ .join("");
425
+ if (!text.trim())
426
+ throw new Error("OpenCode Responses response cut off by max output tokens before any usable content; raise limits.maxOutputTokens");
427
+ if (calls.some((call) => !call.id || !call.name))
428
+ throw new Error("Incomplete tool call");
429
+ const u = event.response.usage;
430
+ yield {
431
+ type: "completed",
432
+ message: { role: "assistant", text, calls, providerData: output, truncated: true },
433
+ usage: u
434
+ ? {
435
+ input: u.input_tokens ?? 0,
436
+ output: u.output_tokens ?? 0,
437
+ ...(typeof u.input_tokens_details?.cached_tokens === "number"
438
+ ? { cachedInput: u.input_tokens_details.cached_tokens }
439
+ : {}),
440
+ }
441
+ : undefined,
442
+ };
443
+ }
402
444
  if (event.type === "response.completed") {
403
445
  complete = true;
404
446
  const output = event.response.output;
@@ -541,7 +583,8 @@ export class OpenCodeGatewayProvider {
541
583
  stopReason = event.delta?.stop_reason ?? stopReason;
542
584
  }
543
585
  }
544
- if (stopReason !== "end_turn" && stopReason !== "tool_use")
586
+ const truncated = stopReason === "max_tokens";
587
+ if (!truncated && stopReason !== "end_turn" && stopReason !== "tool_use")
545
588
  throw new Error(`OpenCode Messages response incomplete: ${stopReason ?? "stream ended"}`);
546
589
  const calls = [];
547
590
  for (let index = 0; index < blocks.length; index++) {
@@ -550,7 +593,24 @@ export class OpenCodeGatewayProvider {
550
593
  continue;
551
594
  const args = argumentParts.get(index) || JSON.stringify(block.input ?? {});
552
595
  calls.push({ id: block.id, name: block.name, arguments: args });
553
- block.input = JSON.parse(args || "{}");
596
+ try {
597
+ block.input = JSON.parse(args || "{}");
598
+ }
599
+ catch {
600
+ if (!truncated)
601
+ throw new Error("Incomplete tool call");
602
+ throw new Error(`OpenCode Messages response incomplete: tool call arguments cut off for ${block.name}`);
603
+ }
604
+ }
605
+ if (truncated) {
606
+ if (!text.trim())
607
+ throw new Error("OpenCode Messages response cut off by max output tokens before any usable content; raise limits.maxOutputTokens");
608
+ yield {
609
+ type: "completed",
610
+ message: { role: "assistant", text, calls, providerData: blocks, truncated: true },
611
+ usage: { input, output },
612
+ };
613
+ return;
554
614
  }
555
615
  yield {
556
616
  type: "completed",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alisio/plugin-opencode",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.5",
4
4
  "description": "Built-in OpenCode Console (Zen) 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",