agentbox-sdk 0.1.306 → 0.1.308

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-T3RBNOSE.js";
4
4
  import "../chunk-ZDSHOGJ4.js";
5
5
  import {
6
6
  AGENT_RESERVED_PORTS,
@@ -1129,6 +1129,39 @@ 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
+ try {
1156
+ await target.runCommand(cmd, env);
1157
+ } catch (error) {
1158
+ const message = error instanceof Error ? error.message : String(error);
1159
+ console.warn(
1160
+ `[rtk] activation failed for ${target.provider}; agent will run without the token-saving proxy: ${message}`
1161
+ );
1162
+ }
1163
+ }
1164
+
1132
1165
  // src/agents/config/setup-manifest.ts
1133
1166
  import { createHash } from "crypto";
1134
1167
  import path5 from "path";
@@ -1500,11 +1533,17 @@ function mergeUsage(target, source) {
1500
1533
  );
1501
1534
  addIfNumber(target, "cache_read_input_tokens", source.cached_input_tokens);
1502
1535
  addIfNumber(target, "cache_read_input_tokens", source.cachedInputTokens);
1536
+ addIfNumber(target, "cache_read_input_tokens", source.cacheReadInputTokens);
1503
1537
  addIfNumber(
1504
1538
  target,
1505
1539
  "cache_creation_input_tokens",
1506
1540
  source.cache_creation_input_tokens
1507
1541
  );
1542
+ addIfNumber(
1543
+ target,
1544
+ "cache_creation_input_tokens",
1545
+ source.cacheCreationInputTokens
1546
+ );
1508
1547
  addIfNumber(target, "cache_creation_input_tokens", source.cacheWrite);
1509
1548
  const cache = asRecord(source.cache);
1510
1549
  if (cache) {
@@ -1541,6 +1580,8 @@ function extractClaudeCostData(events) {
1541
1580
  for (const value of Object.values(modelUsage)) {
1542
1581
  mergeUsage(usage, asRecord(value));
1543
1582
  }
1583
+ } else {
1584
+ mergeUsage(usage, asRecord(event.usage));
1544
1585
  }
1545
1586
  return compactCostData({
1546
1587
  ...totalCost !== void 0 ? { total_cost_usd: totalCost } : {},
@@ -2128,6 +2169,7 @@ var ClaudeCodeAgentAdapter = class {
2128
2169
  { path: settingsPath, content: JSON.stringify(hookSettings, null, 2) },
2129
2170
  { path: mcpConfigPath, content: mcpConfigJson }
2130
2171
  ];
2172
+ const enableRtk = options.enableRtk === true;
2131
2173
  const daemonInfo = {
2132
2174
  port: DAEMON_PORT,
2133
2175
  healthPath: "/__version",
@@ -2136,7 +2178,8 @@ var ClaudeCodeAgentAdapter = class {
2136
2178
  const setupId = computeSetupId({
2137
2179
  artifacts,
2138
2180
  installCommands,
2139
- daemon: daemonInfo
2181
+ daemon: daemonInfo,
2182
+ extras: [`enableRtk:${enableRtk}`]
2140
2183
  });
2141
2184
  if (await preflightSetup(target, setupId, daemonInfo)) {
2142
2185
  debugClaude("claude-code setup() preflight hit \u2014 skipping");
@@ -2151,6 +2194,9 @@ var ClaudeCodeAgentAdapter = class {
2151
2194
  ),
2152
2195
  ensureClaudeCodeDaemon(options, env)
2153
2196
  ]);
2197
+ if (enableRtk) {
2198
+ await time(debugClaude, "activateRtk", () => activateRtk(target));
2199
+ }
2154
2200
  await markSetupComplete(target, setupId);
2155
2201
  });
2156
2202
  }
@@ -3150,6 +3196,7 @@ async function setupCodex(request) {
3150
3196
  });
3151
3197
  const { artifacts: serverArtifacts } = buildArtifactsFor(sharedTarget);
3152
3198
  const { artifacts: skillArtifacts2, installCommands: installCommands2 } = await prepareSkillArtifacts(provider, options.skills, target2.layout);
3199
+ const enableRtk2 = options.enableRtk === true;
3153
3200
  const daemonInfo = {
3154
3201
  port: REMOTE_CODEX_APP_SERVER_PORT,
3155
3202
  healthPath: "/readyz"
@@ -3157,7 +3204,8 @@ async function setupCodex(request) {
3157
3204
  const setupId2 = computeSetupId({
3158
3205
  artifacts: [...serverArtifacts, ...skillArtifacts2],
3159
3206
  installCommands: installCommands2,
3160
- daemon: daemonInfo
3207
+ daemon: daemonInfo,
3208
+ extras: [`enableRtk:${enableRtk2}`]
3161
3209
  });
3162
3210
  if (await preflightSetup(sharedTarget, setupId2, daemonInfo)) {
3163
3211
  debugCodex("codex remote setup() preflight hit \u2014 skipping");
@@ -3220,6 +3268,9 @@ async function setupCodex(request) {
3220
3268
  await target2.cleanup().catch(() => void 0);
3221
3269
  throw error;
3222
3270
  }
3271
+ if (enableRtk2) {
3272
+ await time(debugCodex, "activateRtk", () => activateRtk(sharedTarget));
3273
+ }
3223
3274
  await markSetupComplete(sharedTarget, setupId2);
3224
3275
  return;
3225
3276
  }
@@ -3227,9 +3278,11 @@ async function setupCodex(request) {
3227
3278
  const { artifacts: skillArtifacts, installCommands } = await prepareSkillArtifacts(provider, options.skills, target.layout);
3228
3279
  const { artifacts: configArtifacts } = buildArtifactsFor(target);
3229
3280
  const allArtifacts = [...skillArtifacts, ...configArtifacts];
3281
+ const enableRtk = options.enableRtk === true;
3230
3282
  const setupId = computeSetupId({
3231
3283
  artifacts: allArtifacts,
3232
- installCommands
3284
+ installCommands,
3285
+ extras: [`enableRtk:${enableRtk}`]
3233
3286
  });
3234
3287
  if (await preflightSetup(target, setupId)) {
3235
3288
  debugCodex("codex local setup() preflight hit \u2014 skipping");
@@ -3242,6 +3295,9 @@ async function setupCodex(request) {
3242
3295
  throw error;
3243
3296
  }
3244
3297
  await applyDifferentialSetup(target, allArtifacts, installCommands);
3298
+ if (enableRtk) {
3299
+ await time(debugCodex, "activateRtk", () => activateRtk(target));
3300
+ }
3245
3301
  await markSetupComplete(target, setupId);
3246
3302
  }
3247
3303
  async function createRuntime(request, inputParts) {
@@ -3846,10 +3902,7 @@ async function ensureSandboxOpenCodeServer(request) {
3846
3902
  target.layout.opencodeDir
3847
3903
  );
3848
3904
  const configPath = path10.join(target.layout.opencodeDir, "agentbox.json");
3849
- const openCodeConfig = buildOpenCodeConfig(
3850
- options,
3851
- interactiveApproval
3852
- );
3905
+ const openCodeConfig = buildOpenCodeConfig(options, interactiveApproval);
3853
3906
  const allArtifacts = [
3854
3907
  ...skillArtifacts,
3855
3908
  ...pluginArtifacts,
@@ -3858,11 +3911,13 @@ async function ensureSandboxOpenCodeServer(request) {
3858
3911
  content: JSON.stringify(openCodeConfig, null, 2)
3859
3912
  }
3860
3913
  ];
3914
+ const enableRtk = options.enableRtk === true;
3861
3915
  const daemonInfo = { port, healthPath: "/global/health" };
3862
3916
  const setupId = computeSetupId({
3863
3917
  artifacts: allArtifacts,
3864
3918
  installCommands,
3865
- daemon: daemonInfo
3919
+ daemon: daemonInfo,
3920
+ extras: [`enableRtk:${enableRtk}`]
3866
3921
  });
3867
3922
  if (await preflightSetup(target, setupId, daemonInfo)) {
3868
3923
  debugOpencode("opencode setup() preflight hit \u2014 skipping");
@@ -3874,6 +3929,9 @@ async function ensureSandboxOpenCodeServer(request) {
3874
3929
  OPENCODE_DISABLE_DEFAULT_PLUGINS: "true"
3875
3930
  };
3876
3931
  await applyDifferentialSetup(target, allArtifacts, installCommands);
3932
+ if (enableRtk) {
3933
+ await time(debugOpencode, "activateRtk", () => activateRtk(target));
3934
+ }
3877
3935
  const binary = options.provider?.binary ?? "opencode";
3878
3936
  const pidFilePath = path10.posix.join(
3879
3937
  target.layout.rootDir,
@@ -4408,9 +4466,7 @@ var OpenCodeAgentAdapter = class {
4408
4466
  if (response.ok || response.status === 204) {
4409
4467
  return;
4410
4468
  }
4411
- lastError = new Error(
4412
- `POST ${url} returned ${response.status}`
4413
- );
4469
+ lastError = new Error(`POST ${url} returned ${response.status}`);
4414
4470
  } catch (error) {
4415
4471
  lastError = error;
4416
4472
  }
@@ -4520,14 +4576,10 @@ var OpenCodeAgentAdapter = class {
4520
4576
  });
4521
4577
  } else if (sseSilent) {
4522
4578
  sink.fail(
4523
- new Error(
4524
- "opencode SSE went silent before the session reached idle"
4525
- )
4579
+ new Error("opencode SSE went silent before the session reached idle")
4526
4580
  );
4527
4581
  } else {
4528
- sink.fail(
4529
- new Error("opencode run ended without a terminal signal")
4530
- );
4582
+ sink.fail(new Error("opencode run ended without a terminal signal"));
4531
4583
  }
4532
4584
  } finally {
4533
4585
  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-T3RBNOSE.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.308",
4
4
  "description": "Swappable coding agents and sandbox providers for Bun and TypeScript.",
5
5
  "license": "MIT",
6
6
  "repository": {