agentbox-sdk 0.1.306 → 0.1.307

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.
@@ -1,5 +1,5 @@
1
- import { o as AgentProviderName, h as AgentOptions, t as AgentRunConfig, s as AgentRun, r as AgentResult, a2 as RawAgentEvent, b as AgentAttachRequest, y as AttachedRun } from '../types-DiZSjZma.js';
2
- export { a as AgentApprovalMode, c as AgentCommandConfig, d as AgentCostData, e as AgentExecutionRequest, f as AgentLocalMcpConfig, g as AgentMcpConfig, i as AgentOptionsBase, j as AgentOptionsMap, k as AgentPermissionDecision, l as AgentPermissionKind, m as AgentPermissionResponse, n as AgentProviderAdapter, p as AgentReasoningEffort, q as AgentRemoteMcpConfig, u as AgentRunSink, v as AgentSetupRequest, w as AgentSkillConfig, x as AgentSubAgentConfig, C as ClaudeCodeAgentOptions, z as ClaudeCodeHookConfig, B as ClaudeCodeHookEvent, D as ClaudeCodeHookHandler, E as ClaudeCodeHookMatcherGroup, F as ClaudeCodeHooksConfig, G as ClaudeCodeProviderOptions, H as CodexAgentOptions, I as CodexCommandHook, J as CodexHookEvent, K as CodexHookMatcherGroup, L as CodexHooksConfig, M as CodexProviderOptions, N as DataContent, O as EmbeddedSkillConfig, P as FilePart, Q as ImagePart, X as OpenCodeAgentOptions, Y as OpenCodePluginConfig, Z as OpenCodePluginEvent, _ as OpenCodePluginHookConfig, $ as OpenCodeProviderOptions, a4 as RepoSkillConfig, aa as TextPart, ae as UserContent, af as UserContentPart } from '../types-DiZSjZma.js';
1
+ import { o as AgentProviderName, h as AgentOptions, t as AgentRunConfig, s as AgentRun, r as AgentResult, a2 as RawAgentEvent, b as AgentAttachRequest, y as AttachedRun } from '../types-CZdyLzA4.js';
2
+ export { a as AgentApprovalMode, c as AgentCommandConfig, d as AgentCostData, e as AgentExecutionRequest, f as AgentLocalMcpConfig, g as AgentMcpConfig, i as AgentOptionsBase, j as AgentOptionsMap, k as AgentPermissionDecision, l as AgentPermissionKind, m as AgentPermissionResponse, n as AgentProviderAdapter, p as AgentReasoningEffort, q as AgentRemoteMcpConfig, u as AgentRunSink, v as AgentSetupRequest, w as AgentSkillConfig, x as AgentSubAgentConfig, C as ClaudeCodeAgentOptions, z as ClaudeCodeHookConfig, B as ClaudeCodeHookEvent, D as ClaudeCodeHookHandler, E as ClaudeCodeHookMatcherGroup, F as ClaudeCodeHooksConfig, G as ClaudeCodeProviderOptions, H as CodexAgentOptions, I as CodexCommandHook, J as CodexHookEvent, K as CodexHookMatcherGroup, L as CodexHooksConfig, M as CodexProviderOptions, N as DataContent, O as EmbeddedSkillConfig, P as FilePart, Q as ImagePart, X as OpenCodeAgentOptions, Y as OpenCodePluginConfig, Z as OpenCodePluginEvent, _ as OpenCodePluginHookConfig, $ as OpenCodeProviderOptions, a4 as RepoSkillConfig, aa as TextPart, ae as UserContent, af as UserContentPart } from '../types-CZdyLzA4.js';
3
3
  import { S as Sandbox } from '../Sandbox-K6VNqKeo.js';
4
4
  export { AgentProvider } from '../enums.js';
5
5
  import 'e2b';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Agent
3
- } from "../chunk-7CLAJTFC.js";
3
+ } from "../chunk-7GOUX3OB.js";
4
4
  import "../chunk-ZDSHOGJ4.js";
5
5
  import {
6
6
  AGENT_RESERVED_PORTS,
@@ -1129,6 +1129,32 @@ async function createSetupTarget(provider, setupId, options) {
1129
1129
  });
1130
1130
  }
1131
1131
 
1132
+ // src/agents/config/rtk.ts
1133
+ var RTK_INIT_ARGS_BY_PROVIDER = {
1134
+ [AgentProvider.ClaudeCode]: "--auto-patch",
1135
+ [AgentProvider.Codex]: "--codex",
1136
+ [AgentProvider.OpenCode]: "--opencode --auto-patch"
1137
+ };
1138
+ function rtkRedirectEnv(target) {
1139
+ const layout = target.layout;
1140
+ const common = { RTK_TELEMETRY_DISABLED: "1" };
1141
+ switch (target.provider) {
1142
+ case AgentProvider.ClaudeCode:
1143
+ return { ...common, RTK_CLAUDE_DIR: layout.claudeDir };
1144
+ case AgentProvider.Codex:
1145
+ return { ...common, CODEX_HOME: layout.codexDir };
1146
+ case AgentProvider.OpenCode:
1147
+ return { ...common, HOME: layout.rootDir };
1148
+ }
1149
+ }
1150
+ async function activateRtk(target) {
1151
+ const args = RTK_INIT_ARGS_BY_PROVIDER[target.provider];
1152
+ const env = rtkRedirectEnv(target);
1153
+ const dirsToEnsure = [target.layout.claudeDir, target.layout.codexDir].map((d) => `'${d}'`).join(" ");
1154
+ const cmd = `mkdir -p ${dirsToEnsure} && rtk init -g ${args}`.trim();
1155
+ await target.runCommand(cmd, env);
1156
+ }
1157
+
1132
1158
  // src/agents/config/setup-manifest.ts
1133
1159
  import { createHash } from "crypto";
1134
1160
  import path5 from "path";
@@ -1500,11 +1526,17 @@ function mergeUsage(target, source) {
1500
1526
  );
1501
1527
  addIfNumber(target, "cache_read_input_tokens", source.cached_input_tokens);
1502
1528
  addIfNumber(target, "cache_read_input_tokens", source.cachedInputTokens);
1529
+ addIfNumber(target, "cache_read_input_tokens", source.cacheReadInputTokens);
1503
1530
  addIfNumber(
1504
1531
  target,
1505
1532
  "cache_creation_input_tokens",
1506
1533
  source.cache_creation_input_tokens
1507
1534
  );
1535
+ addIfNumber(
1536
+ target,
1537
+ "cache_creation_input_tokens",
1538
+ source.cacheCreationInputTokens
1539
+ );
1508
1540
  addIfNumber(target, "cache_creation_input_tokens", source.cacheWrite);
1509
1541
  const cache = asRecord(source.cache);
1510
1542
  if (cache) {
@@ -1541,6 +1573,8 @@ function extractClaudeCostData(events) {
1541
1573
  for (const value of Object.values(modelUsage)) {
1542
1574
  mergeUsage(usage, asRecord(value));
1543
1575
  }
1576
+ } else {
1577
+ mergeUsage(usage, asRecord(event.usage));
1544
1578
  }
1545
1579
  return compactCostData({
1546
1580
  ...totalCost !== void 0 ? { total_cost_usd: totalCost } : {},
@@ -2128,6 +2162,7 @@ var ClaudeCodeAgentAdapter = class {
2128
2162
  { path: settingsPath, content: JSON.stringify(hookSettings, null, 2) },
2129
2163
  { path: mcpConfigPath, content: mcpConfigJson }
2130
2164
  ];
2165
+ const enableRtk = options.enableRtk === true;
2131
2166
  const daemonInfo = {
2132
2167
  port: DAEMON_PORT,
2133
2168
  healthPath: "/__version",
@@ -2136,7 +2171,8 @@ var ClaudeCodeAgentAdapter = class {
2136
2171
  const setupId = computeSetupId({
2137
2172
  artifacts,
2138
2173
  installCommands,
2139
- daemon: daemonInfo
2174
+ daemon: daemonInfo,
2175
+ extras: [`enableRtk:${enableRtk}`]
2140
2176
  });
2141
2177
  if (await preflightSetup(target, setupId, daemonInfo)) {
2142
2178
  debugClaude("claude-code setup() preflight hit \u2014 skipping");
@@ -2151,6 +2187,9 @@ var ClaudeCodeAgentAdapter = class {
2151
2187
  ),
2152
2188
  ensureClaudeCodeDaemon(options, env)
2153
2189
  ]);
2190
+ if (enableRtk) {
2191
+ await time(debugClaude, "activateRtk", () => activateRtk(target));
2192
+ }
2154
2193
  await markSetupComplete(target, setupId);
2155
2194
  });
2156
2195
  }
@@ -3150,6 +3189,7 @@ async function setupCodex(request) {
3150
3189
  });
3151
3190
  const { artifacts: serverArtifacts } = buildArtifactsFor(sharedTarget);
3152
3191
  const { artifacts: skillArtifacts2, installCommands: installCommands2 } = await prepareSkillArtifacts(provider, options.skills, target2.layout);
3192
+ const enableRtk2 = options.enableRtk === true;
3153
3193
  const daemonInfo = {
3154
3194
  port: REMOTE_CODEX_APP_SERVER_PORT,
3155
3195
  healthPath: "/readyz"
@@ -3157,7 +3197,8 @@ async function setupCodex(request) {
3157
3197
  const setupId2 = computeSetupId({
3158
3198
  artifacts: [...serverArtifacts, ...skillArtifacts2],
3159
3199
  installCommands: installCommands2,
3160
- daemon: daemonInfo
3200
+ daemon: daemonInfo,
3201
+ extras: [`enableRtk:${enableRtk2}`]
3161
3202
  });
3162
3203
  if (await preflightSetup(sharedTarget, setupId2, daemonInfo)) {
3163
3204
  debugCodex("codex remote setup() preflight hit \u2014 skipping");
@@ -3220,6 +3261,9 @@ async function setupCodex(request) {
3220
3261
  await target2.cleanup().catch(() => void 0);
3221
3262
  throw error;
3222
3263
  }
3264
+ if (enableRtk2) {
3265
+ await time(debugCodex, "activateRtk", () => activateRtk(sharedTarget));
3266
+ }
3223
3267
  await markSetupComplete(sharedTarget, setupId2);
3224
3268
  return;
3225
3269
  }
@@ -3227,9 +3271,11 @@ async function setupCodex(request) {
3227
3271
  const { artifacts: skillArtifacts, installCommands } = await prepareSkillArtifacts(provider, options.skills, target.layout);
3228
3272
  const { artifacts: configArtifacts } = buildArtifactsFor(target);
3229
3273
  const allArtifacts = [...skillArtifacts, ...configArtifacts];
3274
+ const enableRtk = options.enableRtk === true;
3230
3275
  const setupId = computeSetupId({
3231
3276
  artifacts: allArtifacts,
3232
- installCommands
3277
+ installCommands,
3278
+ extras: [`enableRtk:${enableRtk}`]
3233
3279
  });
3234
3280
  if (await preflightSetup(target, setupId)) {
3235
3281
  debugCodex("codex local setup() preflight hit \u2014 skipping");
@@ -3242,6 +3288,9 @@ async function setupCodex(request) {
3242
3288
  throw error;
3243
3289
  }
3244
3290
  await applyDifferentialSetup(target, allArtifacts, installCommands);
3291
+ if (enableRtk) {
3292
+ await time(debugCodex, "activateRtk", () => activateRtk(target));
3293
+ }
3245
3294
  await markSetupComplete(target, setupId);
3246
3295
  }
3247
3296
  async function createRuntime(request, inputParts) {
@@ -3846,10 +3895,7 @@ async function ensureSandboxOpenCodeServer(request) {
3846
3895
  target.layout.opencodeDir
3847
3896
  );
3848
3897
  const configPath = path10.join(target.layout.opencodeDir, "agentbox.json");
3849
- const openCodeConfig = buildOpenCodeConfig(
3850
- options,
3851
- interactiveApproval
3852
- );
3898
+ const openCodeConfig = buildOpenCodeConfig(options, interactiveApproval);
3853
3899
  const allArtifacts = [
3854
3900
  ...skillArtifacts,
3855
3901
  ...pluginArtifacts,
@@ -3858,11 +3904,13 @@ async function ensureSandboxOpenCodeServer(request) {
3858
3904
  content: JSON.stringify(openCodeConfig, null, 2)
3859
3905
  }
3860
3906
  ];
3907
+ const enableRtk = options.enableRtk === true;
3861
3908
  const daemonInfo = { port, healthPath: "/global/health" };
3862
3909
  const setupId = computeSetupId({
3863
3910
  artifacts: allArtifacts,
3864
3911
  installCommands,
3865
- daemon: daemonInfo
3912
+ daemon: daemonInfo,
3913
+ extras: [`enableRtk:${enableRtk}`]
3866
3914
  });
3867
3915
  if (await preflightSetup(target, setupId, daemonInfo)) {
3868
3916
  debugOpencode("opencode setup() preflight hit \u2014 skipping");
@@ -3874,6 +3922,9 @@ async function ensureSandboxOpenCodeServer(request) {
3874
3922
  OPENCODE_DISABLE_DEFAULT_PLUGINS: "true"
3875
3923
  };
3876
3924
  await applyDifferentialSetup(target, allArtifacts, installCommands);
3925
+ if (enableRtk) {
3926
+ await time(debugOpencode, "activateRtk", () => activateRtk(target));
3927
+ }
3877
3928
  const binary = options.provider?.binary ?? "opencode";
3878
3929
  const pidFilePath = path10.posix.join(
3879
3930
  target.layout.rootDir,
@@ -4408,9 +4459,7 @@ var OpenCodeAgentAdapter = class {
4408
4459
  if (response.ok || response.status === 204) {
4409
4460
  return;
4410
4461
  }
4411
- lastError = new Error(
4412
- `POST ${url} returned ${response.status}`
4413
- );
4462
+ lastError = new Error(`POST ${url} returned ${response.status}`);
4414
4463
  } catch (error) {
4415
4464
  lastError = error;
4416
4465
  }
@@ -4520,14 +4569,10 @@ var OpenCodeAgentAdapter = class {
4520
4569
  });
4521
4570
  } else if (sseSilent) {
4522
4571
  sink.fail(
4523
- new Error(
4524
- "opencode SSE went silent before the session reached idle"
4525
- )
4572
+ new Error("opencode SSE went silent before the session reached idle")
4526
4573
  );
4527
4574
  } else {
4528
- sink.fail(
4529
- new Error("opencode run ended without a terminal signal")
4530
- );
4575
+ sink.fail(new Error("opencode run ended without a terminal signal"));
4531
4576
  }
4532
4577
  } finally {
4533
4578
  sseAbort.abort();
@@ -1,4 +1,4 @@
1
- export { A as AISDKEvent, R as MessageCompletedEvent, S as MessageInjectedEvent, T as MessageStartedEvent, U as NormalizedAgentEvent, V as NormalizedAgentEventBase, W as NormalizedAgentEventType, a0 as PermissionRequestedEvent, a1 as PermissionResolvedEvent, a2 as RawAgentEvent, a3 as ReasoningDeltaEvent, a5 as RunCancelledEvent, a6 as RunCompletedEvent, a7 as RunErrorEvent, a8 as RunStartedEvent, a9 as TextDeltaEvent, ab as ToolCallCompletedEvent, ac as ToolCallDeltaEvent, ad as ToolCallStartedEvent, ag as createNormalizedEvent, ah as normalizeRawAgentEvent, ai as toAISDKEvent, aj as toAISDKStream } from '../types-DiZSjZma.js';
1
+ export { A as AISDKEvent, R as MessageCompletedEvent, S as MessageInjectedEvent, T as MessageStartedEvent, U as NormalizedAgentEvent, V as NormalizedAgentEventBase, W as NormalizedAgentEventType, a0 as PermissionRequestedEvent, a1 as PermissionResolvedEvent, a2 as RawAgentEvent, a3 as ReasoningDeltaEvent, a5 as RunCancelledEvent, a6 as RunCompletedEvent, a7 as RunErrorEvent, a8 as RunStartedEvent, a9 as TextDeltaEvent, ab as ToolCallCompletedEvent, ac as ToolCallDeltaEvent, ad as ToolCallStartedEvent, ag as createNormalizedEvent, ah as normalizeRawAgentEvent, ai as toAISDKEvent, aj as toAISDKStream } from '../types-CZdyLzA4.js';
2
2
  import { AgentProvider } from '../enums.js';
3
3
  import '../Sandbox-K6VNqKeo.js';
4
4
  import 'e2b';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AISDKEvent, a as AgentApprovalMode, b as AgentAttachRequest, c as AgentCommandConfig, d as AgentCostData, e as AgentExecutionRequest, f as AgentLocalMcpConfig, g as AgentMcpConfig, h as AgentOptions, i as AgentOptionsBase, j as AgentOptionsMap, k as AgentPermissionDecision, l as AgentPermissionKind, m as AgentPermissionResponse, n as AgentProviderAdapter, o as AgentProviderName, p as AgentReasoningEffort, q as AgentRemoteMcpConfig, r as AgentResult, s as AgentRun, t as AgentRunConfig, u as AgentRunSink, v as AgentSetupRequest, w as AgentSkillConfig, x as AgentSubAgentConfig, y as AttachedRun, C as ClaudeCodeAgentOptions, z as ClaudeCodeHookConfig, B as ClaudeCodeHookEvent, D as ClaudeCodeHookHandler, E as ClaudeCodeHookMatcherGroup, F as ClaudeCodeHooksConfig, G as ClaudeCodeProviderOptions, H as CodexAgentOptions, I as CodexCommandHook, J as CodexHookEvent, K as CodexHookMatcherGroup, L as CodexHooksConfig, M as CodexProviderOptions, N as DataContent, O as EmbeddedSkillConfig, P as FilePart, Q as ImagePart, R as MessageCompletedEvent, S as MessageInjectedEvent, T as MessageStartedEvent, U as NormalizedAgentEvent, V as NormalizedAgentEventBase, W as NormalizedAgentEventType, X as OpenCodeAgentOptions, Y as OpenCodePluginConfig, Z as OpenCodePluginEvent, _ as OpenCodePluginHookConfig, $ as OpenCodeProviderOptions, a0 as PermissionRequestedEvent, a1 as PermissionResolvedEvent, a2 as RawAgentEvent, a3 as ReasoningDeltaEvent, a4 as RepoSkillConfig, a5 as RunCancelledEvent, a6 as RunCompletedEvent, a7 as RunErrorEvent, a8 as RunStartedEvent, a9 as TextDeltaEvent, aa as TextPart, ab as ToolCallCompletedEvent, ac as ToolCallDeltaEvent, ad as ToolCallStartedEvent, ae as UserContent, af as UserContentPart, ag as createNormalizedEvent, ah as normalizeRawAgentEvent, ai as toAISDKEvent, aj as toAISDKStream } from './types-DiZSjZma.js';
1
+ export { A as AISDKEvent, a as AgentApprovalMode, b as AgentAttachRequest, c as AgentCommandConfig, d as AgentCostData, e as AgentExecutionRequest, f as AgentLocalMcpConfig, g as AgentMcpConfig, h as AgentOptions, i as AgentOptionsBase, j as AgentOptionsMap, k as AgentPermissionDecision, l as AgentPermissionKind, m as AgentPermissionResponse, n as AgentProviderAdapter, o as AgentProviderName, p as AgentReasoningEffort, q as AgentRemoteMcpConfig, r as AgentResult, s as AgentRun, t as AgentRunConfig, u as AgentRunSink, v as AgentSetupRequest, w as AgentSkillConfig, x as AgentSubAgentConfig, y as AttachedRun, C as ClaudeCodeAgentOptions, z as ClaudeCodeHookConfig, B as ClaudeCodeHookEvent, D as ClaudeCodeHookHandler, E as ClaudeCodeHookMatcherGroup, F as ClaudeCodeHooksConfig, G as ClaudeCodeProviderOptions, H as CodexAgentOptions, I as CodexCommandHook, J as CodexHookEvent, K as CodexHookMatcherGroup, L as CodexHooksConfig, M as CodexProviderOptions, N as DataContent, O as EmbeddedSkillConfig, P as FilePart, Q as ImagePart, R as MessageCompletedEvent, S as MessageInjectedEvent, T as MessageStartedEvent, U as NormalizedAgentEvent, V as NormalizedAgentEventBase, W as NormalizedAgentEventType, X as OpenCodeAgentOptions, Y as OpenCodePluginConfig, Z as OpenCodePluginEvent, _ as OpenCodePluginHookConfig, $ as OpenCodeProviderOptions, a0 as PermissionRequestedEvent, a1 as PermissionResolvedEvent, a2 as RawAgentEvent, a3 as ReasoningDeltaEvent, a4 as RepoSkillConfig, a5 as RunCancelledEvent, a6 as RunCompletedEvent, a7 as RunErrorEvent, a8 as RunStartedEvent, a9 as TextDeltaEvent, aa as TextPart, ab as ToolCallCompletedEvent, ac as ToolCallDeltaEvent, ad as ToolCallStartedEvent, ae as UserContent, af as UserContentPart, ag as createNormalizedEvent, ah as normalizeRawAgentEvent, ai as toAISDKEvent, aj as toAISDKStream } from './types-CZdyLzA4.js';
2
2
  export { AGENT_RESERVED_PORTS, Agent, collectAllAgentReservedPorts } from './agents/index.js';
3
3
  export { A as AsyncCommandHandle, C as CommandEvent, a as CommandOptions, b as CommandResult, D as DaytonaProviderOptions, c as DaytonaSandboxOptions, E as E2bProviderOptions, d as E2bSandboxOptions, G as GitCloneOptions, L as LocalDockerProviderOptions, e as LocalDockerSandboxOptions, M as ModalProviderOptions, f as ModalSandboxOptions, S as Sandbox, g as SandboxDescriptor, h as SandboxListOptions, i as SandboxOptions, j as SandboxOptionsBase, k as SandboxOptionsMap, l as SandboxProviderName, m as SandboxRaw, n as SandboxRawMap, o as SandboxResourceSpec, T as TarballEntry, V as VercelGitSource, p as VercelProviderOptions, q as VercelSandboxOptions } from './Sandbox-K6VNqKeo.js';
4
4
  export { SandboxAdapter, buildGitCloneCommand } from './sandboxes/index.js';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Agent
3
- } from "./chunk-7CLAJTFC.js";
3
+ } from "./chunk-7GOUX3OB.js";
4
4
  import {
5
5
  ProviderLogAssembler,
6
6
  createNormalizedEvent,
@@ -345,6 +345,19 @@ interface AgentOptionsBase {
345
345
  sandbox?: Sandbox;
346
346
  cwd?: string;
347
347
  env?: Record<string, string>;
348
+ /**
349
+ * When `true`, wire RTK (rust-token-killer, https://github.com/rtk-ai/rtk)
350
+ * into the agent so its bash commands flow through `rtk rewrite` to trim
351
+ * output and save tokens. The `rtk` binary must be installed on PATH
352
+ * inside the sandbox (or on the host, for non-sandbox runs).
353
+ *
354
+ * Activation happens during {@link Agent.setup}: agentbox shells out to
355
+ * `rtk init -g [...]` with environment variables that redirect RTK's
356
+ * writes into the agentbox-managed config layout (so the hook persists
357
+ * past the agent CLI's own settings rewrites). Idempotent — `rtk init`
358
+ * is a no-op when already active. Toggle invalidates the setup cache.
359
+ */
360
+ enableRtk?: boolean;
348
361
  approvalMode?: AgentApprovalMode;
349
362
  mcps?: AgentMcpConfig[];
350
363
  skills?: AgentSkillConfig[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentbox-sdk",
3
- "version": "0.1.306",
3
+ "version": "0.1.307",
4
4
  "description": "Swappable coding agents and sandbox providers for Bun and TypeScript.",
5
5
  "license": "MIT",
6
6
  "repository": {