@aiden-ade/sandbox-agent 0.1.0 → 0.1.1

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/index.cjs +112 -10
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -900,9 +900,9 @@ var require_browser = __commonJS({
900
900
  }
901
901
  });
902
902
 
903
- // ../../node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js
903
+ // ../../node_modules/has-flag/index.js
904
904
  var require_has_flag = __commonJS({
905
- "../../node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js"(exports2, module2) {
905
+ "../../node_modules/has-flag/index.js"(exports2, module2) {
906
906
  "use strict";
907
907
  module2.exports = (flag, argv = process.argv) => {
908
908
  const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
@@ -913,9 +913,9 @@ var require_has_flag = __commonJS({
913
913
  }
914
914
  });
915
915
 
916
- // ../../node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js
916
+ // ../../node_modules/supports-color/index.js
917
917
  var require_supports_color = __commonJS({
918
- "../../node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js"(exports2, module2) {
918
+ "../../node_modules/supports-color/index.js"(exports2, module2) {
919
919
  "use strict";
920
920
  var os = require("os");
921
921
  var tty = require("tty");
@@ -5472,6 +5472,99 @@ function createGeminiCliBackend(command = "gemini", defaultArgs = []) {
5472
5472
  parseStructuredLine: parseGeminiStructuredLine
5473
5473
  });
5474
5474
  }
5475
+ function parseOpencodeStructuredLine(line, context, state) {
5476
+ const presenter = context.presenter;
5477
+ let parsed = null;
5478
+ try {
5479
+ parsed = JSON.parse(line);
5480
+ } catch {
5481
+ if (line.trim().length > 0) {
5482
+ state.summary += `${line}
5483
+ `;
5484
+ void presenter.onAssistantText(`${line}
5485
+ `);
5486
+ }
5487
+ return;
5488
+ }
5489
+ const type = typeof parsed.type === "string" ? parsed.type : "";
5490
+ if (!type) return;
5491
+ const sessionID = typeof parsed.sessionID === "string" ? parsed.sessionID : void 0;
5492
+ if (sessionID) {
5493
+ state.runtimeSessionId = sessionID;
5494
+ }
5495
+ const part = typeof parsed.part === "object" && parsed.part !== null ? parsed.part : null;
5496
+ switch (type) {
5497
+ case "step_start": {
5498
+ state.iterations += 1;
5499
+ void presenter.onLog(`[opencode] Step ${state.iterations} started`);
5500
+ break;
5501
+ }
5502
+ case "text": {
5503
+ const text = part && typeof part.text === "string" ? part.text : "";
5504
+ if (text) {
5505
+ state.summary += text;
5506
+ void presenter.onAssistantText(text);
5507
+ }
5508
+ break;
5509
+ }
5510
+ case "tool_use":
5511
+ case "tool.execute": {
5512
+ const toolName = part && typeof part.name === "string" ? part.name : "OpenCode Tool";
5513
+ const toolId = part && typeof part.id === "string" ? part.id : `opencode-tool-${Date.now()}`;
5514
+ void presenter.onToolUse(toolName, part ?? {}, toolId);
5515
+ break;
5516
+ }
5517
+ case "tool_result":
5518
+ case "tool.result": {
5519
+ const toolId = part && typeof part.id === "string" ? part.id : `opencode-tool-${Date.now()}`;
5520
+ const output = part && typeof part.output === "string" ? part.output : JSON.stringify(part);
5521
+ void presenter.onToolResult?.(toolId, output);
5522
+ break;
5523
+ }
5524
+ case "step_finish": {
5525
+ if (part && typeof part.tokens === "object" && part.tokens !== null) {
5526
+ const tokens = part.tokens;
5527
+ state.usage = {
5528
+ inputTokens: tokens.input ?? 0,
5529
+ outputTokens: tokens.output ?? 0
5530
+ };
5531
+ }
5532
+ break;
5533
+ }
5534
+ case "session.error":
5535
+ case "error": {
5536
+ const message = typeof parsed.message === "string" ? parsed.message : part && typeof part.message === "string" ? part.message : "";
5537
+ if (message) {
5538
+ void presenter.onLog(`[opencode/error] ${message}`);
5539
+ state.error = message;
5540
+ }
5541
+ break;
5542
+ }
5543
+ default:
5544
+ break;
5545
+ }
5546
+ }
5547
+ function createOpencodeCliBackend(command = "opencode", defaultArgs = []) {
5548
+ return createGenericCliBackend({
5549
+ kind: "opencode_cli",
5550
+ supportTier: "structured",
5551
+ command,
5552
+ args: [],
5553
+ buildArgs: (context, prompt) => {
5554
+ const args = ["run", "--format", "json"];
5555
+ const resumeId = context.config.runtimeSessionId?.trim() || context.config.providerSessionId?.trim();
5556
+ if (resumeId) args.push("--session", resumeId);
5557
+ const model2 = context.config.selectedModel?.trim();
5558
+ if (model2 && model2.includes("/")) args.push("--model", model2);
5559
+ return [...args, ...defaultArgs, prompt];
5560
+ },
5561
+ augmentPrompt: (context) => {
5562
+ const base = buildPromptWithSystem(context.config, context.promptText);
5563
+ return context.config.mode === "plan" ? buildPlanModePrefix(base) : base;
5564
+ },
5565
+ parseStructuredLine: parseOpencodeStructuredLine
5566
+ });
5567
+ }
5475
5568
  function createGenericCliPassthroughBackend(command, defaultArgs = []) {
5476
5569
  return createGenericCliBackend({
5477
5570
  kind: "generic_cli",
@@ -5582,6 +5675,7 @@ var CoreAgent = class {
5582
5675
  case "claude_cli":
5583
5676
  case "codex_app_server":
5584
5677
  case "gemini_cli":
5678
+ case "opencode_cli":
5585
5679
  return "structured";
5586
5680
  case "generic_cli":
5587
5681
  default:
@@ -5642,7 +5736,7 @@ var CoreAgent = class {
5642
5736
  const env = this.buildCliEnvironment();
5643
5737
  const runtimeCommand = runtimeConfig.runtimeCommand || this.runtime.runtimeCommand;
5644
5738
  const runtimeArgs = runtimeConfig.runtimeArgs || this.runtime.runtimeArgs || [];
5645
- const backend = backendKind2 === "claude_cli" ? createClaudeCliBackend(runtimeCommand || "claude", runtimeArgs) : backendKind2 === "codex_app_server" ? createCodexRuntimeBackend(runtimeCommand || "codex", runtimeArgs) : backendKind2 === "gemini_cli" ? createGeminiCliBackend(runtimeCommand || "gemini", runtimeArgs) : createGenericCliPassthroughBackend(runtimeCommand || "generic-cli", runtimeArgs);
5739
+ const backend = backendKind2 === "claude_cli" ? createClaudeCliBackend(runtimeCommand || "claude", runtimeArgs) : backendKind2 === "codex_app_server" ? createCodexRuntimeBackend(runtimeCommand || "codex", runtimeArgs) : backendKind2 === "gemini_cli" ? createGeminiCliBackend(runtimeCommand || "gemini", runtimeArgs) : backendKind2 === "opencode_cli" ? createOpencodeCliBackend(runtimeCommand || "opencode", runtimeArgs) : createGenericCliPassthroughBackend(runtimeCommand || "generic-cli", runtimeArgs);
5646
5740
  const result = await backend.run({
5647
5741
  presenter: this.presenter,
5648
5742
  config: runtimeConfig,
@@ -9398,7 +9492,7 @@ var WSClient = class {
9398
9492
  console.warn(`[WSClient] Connection error: ${error.message}`);
9399
9493
  });
9400
9494
  this.socket.on("user_message", (data) => {
9401
- callbacks.onUserMessage({ text: data.text, providerSessionId: data.providerSessionId });
9495
+ callbacks.onUserMessage({ text: data.text, providerSessionId: data.providerSessionId, backendKind: data.backendKind, selectedModel: data.selectedModel });
9402
9496
  });
9403
9497
  this.socket.on("stop", () => {
9404
9498
  callbacks.onStop();
@@ -9414,7 +9508,7 @@ var WSClient = class {
9414
9508
  };
9415
9509
 
9416
9510
  // src/version.ts
9417
- var AGENT_VERSION = "0.1.0";
9511
+ var AGENT_VERSION = "0.1.1";
9418
9512
 
9419
9513
  // src/updater.ts
9420
9514
  var import_node_child_process2 = require("child_process");
@@ -9503,6 +9597,8 @@ async function runSandbox(config) {
9503
9597
  const presenter = new WebPresenter(wsClient, config.sessionId);
9504
9598
  presenter.setSuppressSessionLifecycle(true);
9505
9599
  let lastProviderSessionId = config.providerSessionId;
9600
+ let activeBackendKind = config.backendKind || "claude_cli";
9601
+ let activeModel = config.model;
9506
9602
  while (!stopped) {
9507
9603
  if (pendingUpdate) {
9508
9604
  await performUpdate(wsClient, pendingUpdate, lastProviderSessionId);
@@ -9510,7 +9606,7 @@ async function runSandbox(config) {
9510
9606
  }
9511
9607
  if (currentTask?.trim()) {
9512
9608
  const agent = new CoreAgent(presenter, {
9513
- backendKind: config.backendKind || "claude_cli"
9609
+ backendKind: activeBackendKind
9514
9610
  });
9515
9611
  currentAgent = agent;
9516
9612
  let result;
@@ -9520,8 +9616,8 @@ async function runSandbox(config) {
9520
9616
  maxIterations: config.maxIterations || 50,
9521
9617
  projectPath: config.projectPath,
9522
9618
  cwd: config.projectPath,
9523
- backendKind: config.backendKind || "claude_cli",
9524
- selectedModel: config.model,
9619
+ backendKind: activeBackendKind,
9620
+ selectedModel: activeModel,
9525
9621
  providerSessionId: lastProviderSessionId ?? void 0
9526
9622
  });
9527
9623
  } catch (error) {
@@ -9553,6 +9649,12 @@ async function runSandbox(config) {
9553
9649
  if (nextPayload.providerSessionId) {
9554
9650
  lastProviderSessionId = nextPayload.providerSessionId;
9555
9651
  }
9652
+ if (nextPayload.backendKind) {
9653
+ activeBackendKind = nextPayload.backendKind;
9654
+ }
9655
+ if (nextPayload.selectedModel) {
9656
+ activeModel = nextPayload.selectedModel;
9657
+ }
9556
9658
  }
9557
9659
  presenter.setSuppressSessionLifecycle(false);
9558
9660
  wsClient.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiden-ade/sandbox-agent",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "aiden-agent": "./dist/index.cjs"