@caspian2026/agent-sdk 0.0.27 → 0.0.28

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.
@@ -53934,7 +53934,7 @@ var init_auth = __esm(() => {
53934
53934
 
53935
53935
  // src/utils/userAgent.ts
53936
53936
  function getAgentUserAgent() {
53937
- return `claude-code/${"0.0.27"}`;
53937
+ return `claude-code/${"0.0.28"}`;
53938
53938
  }
53939
53939
 
53940
53940
  // src/utils/workloadContext.ts
@@ -53953,7 +53953,7 @@ function getUserAgent() {
53953
53953
  const clientApp = process.env.CLAUDE_AGENT_SDK_CLIENT_APP ? `, client-app/${process.env.CLAUDE_AGENT_SDK_CLIENT_APP}` : "";
53954
53954
  const workload = getWorkload();
53955
53955
  const workloadSuffix = workload ? `, workload/${workload}` : "";
53956
- return `claude-cli/${"0.0.27"} (${process.env.USER_TYPE}, ${process.env.AGENT_ENTRYPOINT ?? "cli"}${agentSdkVersion}${clientApp}${workloadSuffix})`;
53956
+ return `claude-cli/${"0.0.28"} (${process.env.USER_TYPE}, ${process.env.AGENT_ENTRYPOINT ?? "cli"}${agentSdkVersion}${clientApp}${workloadSuffix})`;
53957
53957
  }
53958
53958
  function getMCPUserAgent() {
53959
53959
  const parts = [];
@@ -53967,7 +53967,7 @@ function getMCPUserAgent() {
53967
53967
  parts.push(`client-app/${process.env.CLAUDE_AGENT_SDK_CLIENT_APP}`);
53968
53968
  }
53969
53969
  const suffix = parts.length > 0 ? ` (${parts.join(", ")})` : "";
53970
- return `claude-code/${"0.0.27"}${suffix}`;
53970
+ return `claude-code/${"0.0.28"}${suffix}`;
53971
53971
  }
53972
53972
  function getWebFetchUserAgent() {
53973
53973
  return `Claude-User (${getAgentUserAgent()}; +https://support.anthropic.com/)`;
@@ -54041,7 +54041,7 @@ var init_user = __esm(() => {
54041
54041
  deviceId,
54042
54042
  sessionId: getSessionId(),
54043
54043
  email: getEmail(),
54044
- appVersion: "0.0.27",
54044
+ appVersion: "0.0.28",
54045
54045
  platform: getHostPlatformForAnalytics(),
54046
54046
  organizationUuid,
54047
54047
  accountUuid,
@@ -88407,7 +88407,7 @@ function getAttributionHeader(fingerprint) {
88407
88407
  if (baseUrl && !baseUrl.includes("anthropic.com")) {
88408
88408
  return "";
88409
88409
  }
88410
- const version2 = `${"0.0.27"}.${fingerprint}`;
88410
+ const version2 = `${"0.0.28"}.${fingerprint}`;
88411
88411
  const entrypoint = process.env.AGENT_ENTRYPOINT ?? "unknown";
88412
88412
  const cch = "";
88413
88413
  const workload = getWorkload();
@@ -116161,7 +116161,7 @@ var init_metadata = __esm(() => {
116161
116161
  COMPOUND_OPERATOR_REGEX = /\s*(?:&&|\|\||[;|])\s*/;
116162
116162
  WHITESPACE_REGEX = /\s+/;
116163
116163
  getVersionBase = memoize_default(() => {
116164
- const match = "0.0.27".match(/^\d+\.\d+\.\d+(?:-[a-z]+)?/);
116164
+ const match = "0.0.28".match(/^\d+\.\d+\.\d+(?:-[a-z]+)?/);
116165
116165
  return match ? match[0] : undefined;
116166
116166
  });
116167
116167
  buildEnvContext = memoize_default(async () => {
@@ -116201,9 +116201,9 @@ var init_metadata = __esm(() => {
116201
116201
  isGithubAction: isEnvTruthy(process.env.GITHUB_ACTIONS),
116202
116202
  isAgentAction: isEnvTruthy(process.env.AGENT_ACTION),
116203
116203
  isClaudeAiAuth: false,
116204
- version: "0.0.27",
116204
+ version: "0.0.28",
116205
116205
  versionBase: getVersionBase(),
116206
- buildTime: "2026-09-22T01:31:36.031Z",
116206
+ buildTime: "2026-09-24T06:21:39.468Z",
116207
116207
  deploymentEnvironment: env3.detectDeploymentEnvironment(),
116208
116208
  ...isEnvTruthy(process.env.GITHUB_ACTIONS) && {
116209
116209
  githubEventName: process.env.GITHUB_EVENT_NAME,
@@ -269011,7 +269011,7 @@ function getTelemetryAttributes() {
269011
269011
  attributes["session.id"] = sessionId;
269012
269012
  }
269013
269013
  if (shouldIncludeAttribute("OTEL_METRICS_INCLUDE_VERSION")) {
269014
- attributes["app.version"] = "0.0.27";
269014
+ attributes["app.version"] = "0.0.28";
269015
269015
  }
269016
269016
  const oauthAccount = getOauthAccountInfo2();
269017
269017
  if (oauthAccount) {
@@ -277277,6 +277277,50 @@ async function* all3(generators, concurrencyCap = Infinity) {
277277
277277
  }
277278
277278
  }
277279
277279
  }
277280
+ async function* orderedAll(generators, concurrencyCap = Infinity) {
277281
+ const NO_ERROR = Symbol("NO_ERROR");
277282
+ const buffers = generators.map(() => []);
277283
+ const errors5 = generators.map(() => NO_ERROR);
277284
+ const finished7 = generators.map(() => false);
277285
+ const finishedSignals = generators.map(() => {
277286
+ let resolve23;
277287
+ const promise2 = new Promise((r) => {
277288
+ resolve23 = r;
277289
+ });
277290
+ return { promise: promise2, resolve: resolve23 };
277291
+ });
277292
+ const runners = generators.map((gen, index) => async function* () {
277293
+ try {
277294
+ for await (const value of gen) {
277295
+ buffers[index].push(value);
277296
+ }
277297
+ } catch (err2) {
277298
+ errors5[index] = err2;
277299
+ } finally {
277300
+ finished7[index] = true;
277301
+ finishedSignals[index].resolve();
277302
+ }
277303
+ }());
277304
+ const drive = (async () => {
277305
+ for await (const _2 of all3(runners, concurrencyCap)) {}
277306
+ })();
277307
+ drive.catch((err2) => {
277308
+ logForDebugging(`[orderedAll] drive loop failed unexpectedly: ${err2}`, {
277309
+ level: "error"
277310
+ });
277311
+ });
277312
+ for (let i3 = 0;i3 < generators.length; i3++) {
277313
+ if (!finished7[i3]) {
277314
+ await finishedSignals[i3].promise;
277315
+ }
277316
+ for (const value of buffers[i3]) {
277317
+ yield value;
277318
+ }
277319
+ if (errors5[i3] !== NO_ERROR) {
277320
+ throw errors5[i3];
277321
+ }
277322
+ }
277323
+ }
277280
277324
  async function toArray2(generator) {
277281
277325
  const result = [];
277282
277326
  for await (const a2 of generator) {
@@ -277286,6 +277330,7 @@ async function toArray2(generator) {
277286
277330
  }
277287
277331
  var NO_VALUE;
277288
277332
  var init_generators = __esm(() => {
277333
+ init_debug();
277289
277334
  NO_VALUE = Symbol("NO_VALUE");
277290
277335
  });
277291
277336
 
@@ -277370,7 +277415,7 @@ async function* runToolsSerially(toolUseMessages, assistantMessages, canUseTool,
277370
277415
  }
277371
277416
  }
277372
277417
  async function* runToolsConcurrently(toolUseMessages, assistantMessages, canUseTool, toolUseContext) {
277373
- yield* all3(toolUseMessages.map(async function* (toolUse) {
277418
+ yield* orderedAll(toolUseMessages.map(async function* (toolUse) {
277374
277419
  toolUseContext.setInProgressToolUseIDs((prev) => new Set(prev).add(toolUse.id));
277375
277420
  yield* runToolUse(toolUse, assistantMessages.find((_2) => Array.isArray(_2.message.content) && _2.message.content.some((_3) => _3.type === "tool_use" && _3.id === toolUse.id)), canUseTool, toolUseContext);
277376
277421
  markToolUseAsComplete(toolUseContext, toolUse.id);
@@ -311392,6 +311437,13 @@ function getOpenAICustomHeaders() {
311392
311437
  }
311393
311438
  return customHeaders;
311394
311439
  }
311440
+ function getClientConfigKey() {
311441
+ return JSON.stringify([
311442
+ process.env.OPENAI_BASE_URL ?? "",
311443
+ process.env.OPENAI_API_KEY ?? "",
311444
+ getOpenAICustomHeaders()
311445
+ ]);
311446
+ }
311395
311447
  function getOpenAIRequestTimeoutMs() {
311396
311448
  const configured = Number.parseInt(process.env.API_TIMEOUT_MS || "", 10);
311397
311449
  return Number.isFinite(configured) && configured > 0 ? configured : DEFAULT_OPENAI_TIMEOUT_MS;
@@ -311401,8 +311453,10 @@ function getOpenAIMaxRetries() {
311401
311453
  return Number.isFinite(configured) && configured >= 0 ? configured : DEFAULT_OPENAI_MAX_RETRIES;
311402
311454
  }
311403
311455
  function getOpenAIClient(options) {
311404
- if (cachedClient && !options?.fetchOverride)
311456
+ const configKey = getClientConfigKey();
311457
+ if (cachedClient && cachedClientConfigKey === configKey && !options?.fetchOverride) {
311405
311458
  return cachedClient;
311459
+ }
311406
311460
  const apiKey = process.env.OPENAI_API_KEY || "";
311407
311461
  const baseURL = process.env.OPENAI_BASE_URL;
311408
311462
  const client2 = new OpenAI({
@@ -311419,10 +311473,11 @@ function getOpenAIClient(options) {
311419
311473
  });
311420
311474
  if (!options?.fetchOverride) {
311421
311475
  cachedClient = client2;
311476
+ cachedClientConfigKey = configKey;
311422
311477
  }
311423
311478
  return client2;
311424
311479
  }
311425
- var cachedClient = null, DEFAULT_OPENAI_TIMEOUT_MS, DEFAULT_OPENAI_MAX_RETRIES = 2;
311480
+ var cachedClient = null, cachedClientConfigKey = null, DEFAULT_OPENAI_TIMEOUT_MS, DEFAULT_OPENAI_MAX_RETRIES = 2;
311426
311481
  var init_client6 = __esm(() => {
311427
311482
  init_openai();
311428
311483
  init_proxy();
@@ -311503,6 +311558,11 @@ function anthropicToolChoiceToOpenAI(toolChoice) {
311503
311558
  return;
311504
311559
  }
311505
311560
  }
311561
+ function anthropicParallelToolCalls(toolChoice) {
311562
+ if (!toolChoice || typeof toolChoice !== "object")
311563
+ return;
311564
+ return toolChoice.disable_parallel_tool_use === true ? false : undefined;
311565
+ }
311506
311566
 
311507
311567
  // src/services/api/openai/modelMapping.ts
311508
311568
  function getModelFamily(model) {
@@ -311577,7 +311637,7 @@ function computeFingerprint(messageText, version2) {
311577
311637
  }
311578
311638
  function computeFingerprintFromMessages(messages) {
311579
311639
  const firstMessageText = extractFirstMessageText(messages);
311580
- return computeFingerprint(firstMessageText, "0.0.27");
311640
+ return computeFingerprint(firstMessageText, "0.0.28");
311581
311641
  }
311582
311642
  var FINGERPRINT_SALT = "59cf53e54c78";
311583
311643
  var init_fingerprint = () => {};
@@ -311766,7 +311826,7 @@ async function sideQuery(opts) {
311766
311826
  betas.push(STRUCTURED_OUTPUTS_BETA_HEADER);
311767
311827
  }
311768
311828
  const messageText = extractFirstUserMessageText(messages);
311769
- const fingerprint = computeFingerprint(messageText, "0.0.27");
311829
+ const fingerprint = computeFingerprint(messageText, "0.0.28");
311770
311830
  const attributionHeader = getAttributionHeader(fingerprint);
311771
311831
  const systemBlocks = [
311772
311832
  attributionHeader ? { type: "text", text: attributionHeader } : null,
@@ -313237,7 +313297,7 @@ async function setupSdkMcpClients(sdkMcpConfigs, sendMcpMessage) {
313237
313297
  const client2 = new Client({
313238
313298
  name: "claude-code",
313239
313299
  title: "Claude Code",
313240
- version: "0.0.27",
313300
+ version: "0.0.28",
313241
313301
  description: "Anthropic's agentic coding tool",
313242
313302
  websiteUrl: PRODUCT_URL
313243
313303
  }, {
@@ -313568,7 +313628,7 @@ var init_client7 = __esm(() => {
313568
313628
  const client2 = new Client({
313569
313629
  name: "claude-code",
313570
313630
  title: "Claude Code",
313571
- version: "0.0.27",
313631
+ version: "0.0.28",
313572
313632
  description: "Anthropic's agentic coding tool",
313573
313633
  websiteUrl: PRODUCT_URL
313574
313634
  }, {
@@ -390382,6 +390442,8 @@ class StreamingToolExecutor {
390382
390442
  const progressMessage = tool.pendingProgress.shift();
390383
390443
  yield { message: progressMessage, newContext: this.toolUseContext };
390384
390444
  }
390445
+ }
390446
+ for (const tool of this.tools) {
390385
390447
  if (tool.status === "yielded") {
390386
390448
  continue;
390387
390449
  }
@@ -390391,7 +390453,7 @@ class StreamingToolExecutor {
390391
390453
  yield { message, newContext: this.toolUseContext };
390392
390454
  }
390393
390455
  markToolUseAsComplete2(this.toolUseContext, tool.id);
390394
- } else if (tool.status === "executing" && !tool.isConcurrencySafe) {
390456
+ } else {
390395
390457
  break;
390396
390458
  }
390397
390459
  }
@@ -390423,7 +390485,12 @@ class StreamingToolExecutor {
390423
390485
  }
390424
390486
  }
390425
390487
  hasCompletedResults() {
390426
- return this.tools.some((t) => t.status === "completed");
390488
+ for (const t of this.tools) {
390489
+ if (t.status === "yielded")
390490
+ continue;
390491
+ return t.status === "completed";
390492
+ }
390493
+ return false;
390427
390494
  }
390428
390495
  hasExecutingTools() {
390429
390496
  return this.tools.some((t) => t.status === "executing");
@@ -392248,7 +392315,7 @@ function getAnthropicEnvMetadata() {
392248
392315
  function getBuildAgeMinutes() {
392249
392316
  if (false)
392250
392317
  ;
392251
- const buildTime = new Date("2026-09-22T01:31:36.031Z").getTime();
392318
+ const buildTime = new Date("2026-09-24T06:21:39.468Z").getTime();
392252
392319
  if (isNaN(buildTime))
392253
392320
  return;
392254
392321
  return Math.floor((Date.now() - buildTime) / 60000);
@@ -414316,7 +414383,7 @@ function Feedback({
414316
414383
  platform: env3.platform,
414317
414384
  gitRepo: envInfo.isGit,
414318
414385
  terminal: env3.terminal,
414319
- version: "0.0.27",
414386
+ version: "0.0.28",
414320
414387
  transcript: normalizeMessagesForAPI(messages),
414321
414388
  errors: sanitizedErrors,
414322
414389
  lastApiRequest: getLastAPIRequest(),
@@ -414501,7 +414568,7 @@ function Feedback({
414501
414568
  ", ",
414502
414569
  env3.terminal,
414503
414570
  ", v",
414504
- "0.0.27"
414571
+ "0.0.28"
414505
414572
  ]
414506
414573
  }, undefined, true, undefined, this)
414507
414574
  ]
@@ -414607,7 +414674,7 @@ ${sanitizedDescription}
414607
414674
  ` + `**Environment Info**
414608
414675
  ` + `- Platform: ${env3.platform}
414609
414676
  ` + `- Terminal: ${env3.terminal}
414610
- ` + `- Version: ${"0.0.27"}
414677
+ ` + `- Version: ${"0.0.28"}
414611
414678
  ` + `- Feedback ID: ${feedbackId}
414612
414679
  ` + `
414613
414680
  **Errors**
@@ -417572,7 +417639,7 @@ function detectLinuxGlobPatternWarnings() {
417572
417639
  }
417573
417640
  async function getDoctorDiagnostic() {
417574
417641
  const installationType = await getCurrentInstallationType();
417575
- const version2 = typeof MACRO !== "undefined" ? "0.0.27" : "unknown";
417642
+ const version2 = typeof MACRO !== "undefined" ? "0.0.28" : "unknown";
417576
417643
  const installationPath = await getInstallationPath();
417577
417644
  const invokedBinary = getInvokedBinary();
417578
417645
  const multipleInstallations = await detectMultipleInstallations();
@@ -418361,7 +418428,7 @@ function buildPrimarySection() {
418361
418428
  children: "/rename to add a name"
418362
418429
  }, undefined, false, undefined, this);
418363
418430
  return [
418364
- { label: "Version", value: "0.0.27" },
418431
+ { label: "Version", value: "0.0.28" },
418365
418432
  { label: "Session name", value: nameValue },
418366
418433
  { label: "Session ID", value: sessionId },
418367
418434
  { label: "cwd", value: getCwd() },
@@ -421442,7 +421509,7 @@ function Config({
421442
421509
  }
421443
421510
  }, undefined, false, undefined, this)
421444
421511
  }, undefined, false, undefined, this) : showSubmenu === "ChannelDowngrade" ? /* @__PURE__ */ jsx_dev_runtime173.jsxDEV(ChannelDowngradeDialog, {
421445
- currentVersion: "0.0.27",
421512
+ currentVersion: "0.0.28",
421446
421513
  onChoice: (choice) => {
421447
421514
  setShowSubmenu(null);
421448
421515
  setTabsHidden(false);
@@ -421454,7 +421521,7 @@ function Config({
421454
421521
  autoUpdatesChannel: "stable"
421455
421522
  };
421456
421523
  if (choice === "stay") {
421457
- newSettings.minimumVersion = "0.0.27";
421524
+ newSettings.minimumVersion = "0.0.28";
421458
421525
  }
421459
421526
  updateSettingsForSource("userSettings", newSettings);
421460
421527
  setSettingsData((prev) => ({
@@ -426769,7 +426836,7 @@ function HelpV2({ onClose, commands }) {
426769
426836
  color: "professionalBlue",
426770
426837
  children: [
426771
426838
  /* @__PURE__ */ jsx_dev_runtime199.jsxDEV(Tabs, {
426772
- title: process.env.USER_TYPE === "ant" ? "/help" : `Claude Code v${"0.0.27"}`,
426839
+ title: process.env.USER_TYPE === "ant" ? "/help" : `Claude Code v${"0.0.28"}`,
426773
426840
  color: "professionalBlue",
426774
426841
  defaultTab: "general",
426775
426842
  children: tabs
@@ -439187,7 +439254,7 @@ function getAllReleaseNotes(changelogContent = getStoredChangelogFromMemory()) {
439187
439254
  return [];
439188
439255
  }
439189
439256
  }
439190
- function checkForReleaseNotesSync(lastSeenVersion, currentVersion = "0.0.27") {
439257
+ function checkForReleaseNotesSync(lastSeenVersion, currentVersion = "0.0.28") {
439191
439258
  if (process.env.USER_TYPE === "ant") {
439192
439259
  const changelog = "";
439193
439260
  if (changelog) {
@@ -441222,7 +441289,7 @@ function getRecentActivitySync() {
441222
441289
  return cachedActivity;
441223
441290
  }
441224
441291
  function getLogoDisplayData() {
441225
- const version2 = process.env.DEMO_VERSION ?? "0.0.27";
441292
+ const version2 = process.env.DEMO_VERSION ?? "0.0.28";
441226
441293
  const serverUrl = getDirectConnectServerUrl();
441227
441294
  const displayPath = process.env.DEMO_VERSION ? "/code/claude" : getDisplayPath(getCwd());
441228
441295
  const cwd2 = serverUrl ? `${displayPath} in ${serverUrl.replace(/^https?:\/\//, "")}` : displayPath;
@@ -442130,13 +442197,13 @@ function LogoV2() {
442130
442197
  const { hasReleaseNotes } = checkForReleaseNotesSync(config5.lastReleaseNotesSeen);
442131
442198
  import_react159.useEffect(() => {
442132
442199
  const currentConfig = getGlobalConfig();
442133
- if (currentConfig.lastReleaseNotesSeen === "0.0.27") {
442200
+ if (currentConfig.lastReleaseNotesSeen === "0.0.28") {
442134
442201
  return;
442135
442202
  }
442136
442203
  saveGlobalConfig((current) => {
442137
- if (current.lastReleaseNotesSeen === "0.0.27")
442204
+ if (current.lastReleaseNotesSeen === "0.0.28")
442138
442205
  return current;
442139
- return { ...current, lastReleaseNotesSeen: "0.0.27" };
442206
+ return { ...current, lastReleaseNotesSeen: "0.0.28" };
442140
442207
  });
442141
442208
  if (showOnboarding) {
442142
442209
  incrementProjectOnboardingSeenCount();
@@ -458856,7 +458923,7 @@ async function captureMemoryDiagnostics(trigger, dumpNumber = 0) {
458856
458923
  smapsRollup,
458857
458924
  platform: process.platform,
458858
458925
  nodeVersion: process.version,
458859
- ccVersion: "0.0.27"
458926
+ ccVersion: "0.0.28"
458860
458927
  };
458861
458928
  }
458862
458929
  async function performHeapDump(trigger = "manual", dumpNumber = 0) {
@@ -459118,7 +459185,7 @@ var init_bridge_kick = __esm(() => {
459118
459185
  var call54 = async () => {
459119
459186
  return {
459120
459187
  type: "text",
459121
- value: `${"0.0.27"} (built ${"2026-09-22T01:31:36.031Z"})`
459188
+ value: `${"0.0.28"} (built ${"2026-09-24T06:21:39.468Z"})`
459122
459189
  };
459123
459190
  }, version2, version_default;
459124
459191
  var init_version = __esm(() => {
@@ -466387,7 +466454,7 @@ function generateHtmlReport(data, insights) {
466387
466454
  </html>`;
466388
466455
  }
466389
466456
  function buildExportData(data, insights, facets, remoteStats) {
466390
- const version3 = typeof MACRO !== "undefined" ? "0.0.27" : "unknown";
466457
+ const version3 = typeof MACRO !== "undefined" ? "0.0.28" : "unknown";
466391
466458
  const remote_hosts_collected = remoteStats?.hosts.filter((h2) => h2.sessionCount > 0).map((h2) => h2.name);
466392
466459
  const facets_summary = {
466393
466460
  total: facets.size,
@@ -470513,7 +470580,7 @@ var init_sessionStorage = __esm(() => {
470513
470580
  init_settings2();
470514
470581
  init_slowOperations();
470515
470582
  init_uuid();
470516
- VERSION6 = typeof MACRO !== "undefined" ? "0.0.27" : "unknown";
470583
+ VERSION6 = typeof MACRO !== "undefined" ? "0.0.28" : "unknown";
470517
470584
  MAX_TOMBSTONE_REWRITE_BYTES = 50 * 1024 * 1024;
470518
470585
  SKIP_FIRST_PROMPT_PATTERN2 = /^(?:\s*<[a-z][\w-]*[\s>]|\[Request interrupted by user[^\]]*\])/;
470519
470586
  EPHEMERAL_PROGRESS_TYPES = new Set([
@@ -471707,7 +471774,7 @@ var init_filesystem = __esm(() => {
471707
471774
  });
471708
471775
  getBundledSkillsRoot = memoize_default(function getBundledSkillsRoot2() {
471709
471776
  const nonce = randomBytes16(16).toString("hex");
471710
- return join128(getClaudeTempDir(), "bundled-skills", "0.0.27", nonce);
471777
+ return join128(getClaudeTempDir(), "bundled-skills", "0.0.28", nonce);
471711
471778
  });
471712
471779
  getResolvedWorkingDirPaths = memoize_default(getPathsForPermissionCheck);
471713
471780
  });
@@ -477327,15 +477394,29 @@ function anthropicMessagesToOpenAI(messages, systemPrompt, options) {
477327
477394
  }
477328
477395
  }
477329
477396
  }
477397
+ let lastToolCallOrder = [];
477330
477398
  for (let i3 = 0;i3 < messages.length; i3++) {
477331
477399
  const msg = messages[i3];
477332
477400
  switch (msg.type) {
477333
- case "user":
477401
+ case "user": {
477402
+ if (isToolResultRunUserMessage(msg)) {
477403
+ const run = [];
477404
+ let j2 = i3;
477405
+ while (j2 < messages.length && (isToolResultRunUserMessage(messages[j2]) || run.length > 0 && isMetaSidecarMessage(messages[j2]))) {
477406
+ run.push(messages[j2]);
477407
+ j2++;
477408
+ }
477409
+ result.push(...convertToolResultRun(run, lastToolCallOrder));
477410
+ i3 = j2 - 1;
477411
+ break;
477412
+ }
477334
477413
  result.push(...convertInternalUserMessage(msg));
477335
477414
  break;
477415
+ }
477336
477416
  case "assistant":
477337
477417
  const preserveReasoning = enableThinking && !isBeforeAnyTurnBoundary(i3, turnBoundaries);
477338
477418
  result.push(...convertInternalAssistantMessage(msg, preserveReasoning));
477419
+ lastToolCallOrder = getToolUseIds(msg);
477339
477420
  break;
477340
477421
  default:
477341
477422
  break;
@@ -477343,6 +477424,108 @@ function anthropicMessagesToOpenAI(messages, systemPrompt, options) {
477343
477424
  }
477344
477425
  return result;
477345
477426
  }
477427
+ function isToolResultRunUserMessage(msg) {
477428
+ if (msg.type !== "user")
477429
+ return false;
477430
+ const content = msg.message.content;
477431
+ if (!Array.isArray(content) || content.length === 0)
477432
+ return false;
477433
+ const first = content[0];
477434
+ return typeof first === "object" && first !== null && "type" in first && first.type === "tool_result";
477435
+ }
477436
+ function isMetaSidecarMessage(msg) {
477437
+ if (msg.type !== "user")
477438
+ return false;
477439
+ if (!msg.isMeta)
477440
+ return false;
477441
+ const content = msg.message.content;
477442
+ if (typeof content === "string")
477443
+ return true;
477444
+ if (!Array.isArray(content) || content.length === 0)
477445
+ return false;
477446
+ return content.every((b3) => typeof b3 === "object" && b3 !== null && ("type" in b3) ? b3.type !== "tool_result" : true);
477447
+ }
477448
+ function getToolUseIds(msg) {
477449
+ const content = msg.message.content;
477450
+ if (!Array.isArray(content))
477451
+ return [];
477452
+ const ids = [];
477453
+ for (const block of content) {
477454
+ if (typeof block === "object" && block !== null && "type" in block && block.type === "tool_use") {
477455
+ ids.push(block.id);
477456
+ }
477457
+ }
477458
+ return ids;
477459
+ }
477460
+ function convertToolResultRun(run, toolCallOrder) {
477461
+ const result = [];
477462
+ const entries = [];
477463
+ let current;
477464
+ let seq = 0;
477465
+ for (const msg of run) {
477466
+ const content = msg.message.content;
477467
+ if (typeof content === "string" || !Array.isArray(content)) {
477468
+ if (msg.isMeta && current) {
477469
+ current.sidecarParts.push({ type: "text", text: content });
477470
+ }
477471
+ continue;
477472
+ }
477473
+ for (const block of content) {
477474
+ if (typeof block !== "object" || block === null || !("type" in block))
477475
+ continue;
477476
+ if (block.type === "tool_result") {
477477
+ const { toolMessage, imageParts } = convertToolResult(block);
477478
+ const order = toolCallOrder.indexOf(block.tool_use_id);
477479
+ current = {
477480
+ order: order === -1 ? Number.MAX_SAFE_INTEGER : order,
477481
+ seq: seq++,
477482
+ toolMessage,
477483
+ imageParts,
477484
+ sidecarParts: []
477485
+ };
477486
+ entries.push(current);
477487
+ } else if (current) {
477488
+ const part = convertSidecarBlock(block);
477489
+ if (part)
477490
+ current.sidecarParts.push(part);
477491
+ }
477492
+ }
477493
+ }
477494
+ entries.sort((a2, b3) => a2.order - b3.order || a2.seq - b3.seq);
477495
+ const syntheticParts = [];
477496
+ for (const entry of entries) {
477497
+ result.push(entry.toolMessage);
477498
+ syntheticParts.push(...entry.imageParts, ...entry.sidecarParts);
477499
+ }
477500
+ if (syntheticParts.length > 0) {
477501
+ result.push({
477502
+ role: "user",
477503
+ content: syntheticParts
477504
+ });
477505
+ }
477506
+ return result;
477507
+ }
477508
+ function convertSidecarBlock(block) {
477509
+ const b3 = block;
477510
+ if (b3.type === "text" && typeof b3.text === "string") {
477511
+ return { type: "text", text: b3.text };
477512
+ }
477513
+ if (b3.type === "image" && b3.source) {
477514
+ if (b3.source.type === "base64" && b3.source.data) {
477515
+ return {
477516
+ type: "image_url",
477517
+ image_url: { url: `data:${b3.source.media_type ?? "image/png"};base64,${b3.source.data}` }
477518
+ };
477519
+ }
477520
+ if (b3.source.type === "url" && b3.source.url) {
477521
+ return { type: "image_url", image_url: { url: b3.source.url } };
477522
+ }
477523
+ }
477524
+ if (b3.type === "document") {
477525
+ return { type: "text", text: "[document attachment omitted: not transferable to this API.]" };
477526
+ }
477527
+ return;
477528
+ }
477346
477529
  function systemPromptToText(systemPrompt) {
477347
477530
  if (!systemPrompt || systemPrompt.length === 0)
477348
477531
  return "";
@@ -477388,15 +477571,22 @@ function convertInternalUserMessage(msg) {
477388
477571
  image_url: { url: block.source.url }
477389
477572
  });
477390
477573
  }
477574
+ } else if (block.type === "document") {
477575
+ textParts.push("[document attachment omitted: document content is not transferable to this API. If its content matters, try re-reading the file with the Read tool's pages parameter; otherwise inform the user the document cannot be viewed.]");
477391
477576
  }
477392
477577
  }
477393
- const toolFollowUpMessages = [];
477578
+ const relocatedImageParts = [];
477394
477579
  for (const tr of toolResults) {
477395
- const [toolMessage, ...followUpMessages] = convertToolResult(tr);
477580
+ const { toolMessage, imageParts: imageParts2 } = convertToolResult(tr);
477396
477581
  result.push(toolMessage);
477397
- toolFollowUpMessages.push(...followUpMessages);
477582
+ relocatedImageParts.push(...imageParts2);
477583
+ }
477584
+ if (relocatedImageParts.length > 0) {
477585
+ result.push({
477586
+ role: "user",
477587
+ content: relocatedImageParts
477588
+ });
477398
477589
  }
477399
- result.push(...toolFollowUpMessages);
477400
477590
  if (textParts.length > 0 || imageParts.length > 0) {
477401
477591
  if (imageParts.length > 0) {
477402
477592
  const contentParts = [];
@@ -477422,6 +477612,7 @@ function convertInternalUserMessage(msg) {
477422
477612
  }
477423
477613
  function convertToolResult(block) {
477424
477614
  const textParts = [];
477615
+ const imageParts = [];
477425
477616
  if (typeof block.content === "string") {
477426
477617
  textParts.push(block.content);
477427
477618
  } else if (Array.isArray(block.content)) {
@@ -477435,18 +477626,39 @@ function convertToolResult(block) {
477435
477626
  continue;
477436
477627
  }
477437
477628
  if (c6.type === "image") {
477438
- textParts.push("[image returned by tool]");
477629
+ const imageIndex = imageParts.filter((p) => p.type === "image_url").length + 1;
477630
+ const anchor = `[tool-result attachment tool_use_id=${JSON.stringify(block.tool_use_id)} image=${imageIndex}]`;
477631
+ let url3;
477632
+ let note;
477633
+ if (c6.source.type === "base64") {
477634
+ const mediaType = c6.source.media_type ?? "image/png";
477635
+ url3 = `data:${mediaType};base64,${c6.source.data}`;
477636
+ note = `${anchor} (${mediaType}): attached in the following user message`;
477637
+ } else if (c6.source.type === "url") {
477638
+ url3 = c6.source.url;
477639
+ note = `${anchor}: attached in the following user message`;
477640
+ } else {
477641
+ textParts.push(`${anchor}: image not transferable to this API`);
477642
+ continue;
477643
+ }
477644
+ imageParts.push({ type: "text", text: anchor });
477645
+ imageParts.push({ type: "image_url", image_url: { url: url3 } });
477646
+ textParts.push(note);
477439
477647
  } else if (c6.type === "document") {
477440
477648
  textParts.push("[document returned by tool]");
477441
477649
  }
477442
477650
  }
477443
477651
  }
477444
- return [{
477445
- role: "tool",
477446
- tool_call_id: block.tool_use_id,
477447
- content: textParts.filter(Boolean).join(`
477448
- `) || ""
477449
- }];
477652
+ const textContent = textParts.filter(Boolean).join(`
477653
+ `) || "(tool returned no output)";
477654
+ return {
477655
+ toolMessage: {
477656
+ role: "tool",
477657
+ tool_call_id: block.tool_use_id,
477658
+ content: block.is_error ? `<tool_error>${textContent || "(tool failed with no output)"}</tool_error>` : textContent
477659
+ },
477660
+ imageParts
477661
+ };
477450
477662
  }
477451
477663
  function convertInternalAssistantMessage(msg, preserveReasoning = false) {
477452
477664
  const content = msg.message.content;
@@ -477698,8 +477910,40 @@ async function* adaptOpenAIStreamToAnthropic(stream4, model) {
477698
477910
  index: idx
477699
477911
  };
477700
477912
  }
477913
+ if (!started) {
477914
+ yield {
477915
+ type: "message_start",
477916
+ message: {
477917
+ id: messageId,
477918
+ type: "message",
477919
+ role: "assistant",
477920
+ content: [],
477921
+ model,
477922
+ stop_reason: null,
477923
+ stop_sequence: null,
477924
+ usage: {
477925
+ input_tokens: 0,
477926
+ output_tokens: 0,
477927
+ cache_creation_input_tokens: 0,
477928
+ cache_read_input_tokens: 0
477929
+ }
477930
+ }
477931
+ };
477932
+ yield {
477933
+ type: "message_delta",
477934
+ delta: { stop_reason: "end_turn", stop_sequence: null },
477935
+ usage: {
477936
+ input_tokens: 0,
477937
+ output_tokens: 0,
477938
+ cache_read_input_tokens: 0,
477939
+ cache_creation_input_tokens: 0
477940
+ }
477941
+ };
477942
+ yield { type: "message_stop" };
477943
+ return;
477944
+ }
477701
477945
  if (pendingFinishReason !== null) {
477702
- const stopReason = pendingFinishReason === "length" ? "max_tokens" : pendingHasToolCalls ? "tool_use" : mapFinishReason(pendingFinishReason);
477946
+ const stopReason = pendingFinishReason === "length" ? "max_tokens" : pendingFinishReason === "content_filter" ? "content_filter" : pendingHasToolCalls ? "tool_use" : mapFinishReason(pendingFinishReason);
477703
477947
  yield {
477704
477948
  type: "message_delta",
477705
477949
  delta: {
@@ -477727,7 +477971,7 @@ function mapFinishReason(reason) {
477727
477971
  case "length":
477728
477972
  return "max_tokens";
477729
477973
  case "content_filter":
477730
- return "end_turn";
477974
+ return "content_filter";
477731
477975
  default:
477732
477976
  return "end_turn";
477733
477977
  }
@@ -477740,7 +477984,9 @@ __export(exports_openai, {
477740
477984
  resolveOpenAIMaxTokens: () => resolveOpenAIMaxTokens,
477741
477985
  queryModelOpenAI: () => queryModelOpenAI,
477742
477986
  isOpenAIThinkingEnabled: () => isOpenAIThinkingEnabled,
477743
- buildOpenAIRequestBody: () => buildOpenAIRequestBody
477987
+ isOpenAIDebugDumpEnabled: () => isOpenAIDebugDumpEnabled,
477988
+ buildOpenAIRequestBody: () => buildOpenAIRequestBody,
477989
+ assembleFinalAssistantOutputs: () => assembleFinalAssistantOutputs
477744
477990
  });
477745
477991
  import { randomUUID as randomUUID28 } from "crypto";
477746
477992
  function isOpenAIThinkingEnabled(model) {
@@ -477752,14 +477998,24 @@ function isOpenAIThinkingEnabled(model) {
477752
477998
  return modelLower.includes("deepseek");
477753
477999
  }
477754
478000
  function buildOpenAIRequestBody(params) {
477755
- const { model, messages, tools, toolChoice, enableThinking, maxTokens, temperatureOverride } = params;
478001
+ const {
478002
+ model,
478003
+ messages,
478004
+ tools,
478005
+ toolChoice,
478006
+ parallelToolCalls,
478007
+ enableThinking,
478008
+ maxTokens,
478009
+ temperatureOverride
478010
+ } = params;
477756
478011
  return {
477757
478012
  model,
477758
478013
  messages,
477759
478014
  max_tokens: maxTokens,
477760
478015
  ...tools.length > 0 && {
477761
478016
  tools,
477762
- ...toolChoice && { tool_choice: toolChoice }
478017
+ ...toolChoice && { tool_choice: toolChoice },
478018
+ ...parallelToolCalls !== undefined && { parallel_tool_calls: parallelToolCalls }
477763
478019
  },
477764
478020
  stream: true,
477765
478021
  stream_options: { include_usage: true },
@@ -477773,6 +478029,9 @@ function buildOpenAIRequestBody(params) {
477773
478029
  }
477774
478030
  };
477775
478031
  }
478032
+ function isOpenAIDebugDumpEnabled() {
478033
+ return isEnvTruthy(process.env.AGENT_DEBUG_OPENAI_DUMP);
478034
+ }
477776
478035
  function resolveOpenAIMaxTokens(upperLimit, maxOutputTokensOverride) {
477777
478036
  return maxOutputTokensOverride ?? (process.env.OPENAI_MAX_TOKENS ? parseInt(process.env.OPENAI_MAX_TOKENS, 10) || undefined : undefined) ?? (process.env.AGENT_MAX_OUTPUT_TOKENS ? parseInt(process.env.AGENT_MAX_OUTPUT_TOKENS, 10) || undefined : undefined) ?? upperLimit;
477778
478037
  }
@@ -477799,6 +478058,7 @@ function isOpenAIConvertibleMessage(msg) {
477799
478058
  function assembleFinalAssistantOutputs(params) {
477800
478059
  const { partialMessage, contentBlocks, tools, agentId, usage, stopReason, maxTokens } = params;
477801
478060
  const outputs2 = [];
478061
+ const persistedStopReason = stopReason === "content_filter" ? "end_turn" : stopReason;
477802
478062
  const allBlocks = Object.keys(contentBlocks).sort((a2, b3) => Number(a2) - Number(b3)).map((k2) => contentBlocks[Number(k2)]).filter(Boolean);
477803
478063
  if (allBlocks.length > 0) {
477804
478064
  outputs2.push({
@@ -477806,7 +478066,7 @@ function assembleFinalAssistantOutputs(params) {
477806
478066
  ...partialMessage,
477807
478067
  content: normalizeContentFromAPI(allBlocks, tools, agentId),
477808
478068
  usage,
477809
- stop_reason: stopReason,
478069
+ stop_reason: persistedStopReason,
477810
478070
  stop_sequence: null
477811
478071
  },
477812
478072
  requestId: undefined,
@@ -477821,6 +478081,12 @@ function assembleFinalAssistantOutputs(params) {
477821
478081
  apiError: "max_output_tokens",
477822
478082
  error: "max_output_tokens"
477823
478083
  }));
478084
+ } else if (stopReason === "content_filter") {
478085
+ outputs2.push(createAssistantAPIErrorMessage({
478086
+ content: "Output truncated: the provider's content filter rejected part of this response. " + "Try rephrasing the request or continuing in a new direction.",
478087
+ apiError: "api_error",
478088
+ error: "server_error"
478089
+ }));
477824
478090
  }
477825
478091
  return outputs2;
477826
478092
  }
@@ -477874,6 +478140,7 @@ async function* queryModelOpenAI(messages, systemPrompt, tools, signal, options)
477874
478140
  const openaiTools = anthropicToolsToOpenAI(standardTools);
477875
478141
  diagnosticToolCount = openaiTools.length;
477876
478142
  const openaiToolChoice = anthropicToolChoiceToOpenAI(options.toolChoice);
478143
+ const openaiParallelToolCalls = anthropicParallelToolCalls(options.toolChoice);
477877
478144
  if (useToolSearch) {
477878
478145
  const includedDeferredTools = filteredTools.filter((t) => deferredToolNames.has(t.name)).length;
477879
478146
  logForDebugging(`[OpenAI] Tool search enabled: ${includedDeferredTools}/${deferredToolNames.size} deferred tools included, total tools=${openaiTools.length}`);
@@ -477905,6 +478172,7 @@ async function* queryModelOpenAI(messages, systemPrompt, tools, signal, options)
477905
478172
  messages: openaiMessages,
477906
478173
  tools: openaiTools,
477907
478174
  toolChoice: openaiToolChoice,
478175
+ parallelToolCalls: openaiParallelToolCalls,
477908
478176
  enableThinking,
477909
478177
  maxTokens,
477910
478178
  temperatureOverride: options.temperatureOverride
@@ -478027,38 +478295,39 @@ async function* queryModelOpenAI(messages, systemPrompt, tools, signal, options)
478027
478295
  yield output;
478028
478296
  }
478029
478297
  }
478030
- try {
478031
- const { writeFileSync: writeFileSync9, mkdirSync: mkdirSync7 } = await import("node:fs");
478032
- const { join: join131 } = await import("node:path");
478033
- const { tmpdir: tmpdir13 } = await import("node:os");
478034
- const debugDir = join131(tmpdir13(), "claude-code-debug");
478035
- mkdirSync7(debugDir, { recursive: true });
478036
- const debugFile = join131(debugDir, `openai-${debugTimestamp}.json`);
478037
- const allBlocks = Object.keys(contentBlocks).sort((a2, b3) => Number(a2) - Number(b3)).map((k2) => contentBlocks[Number(k2)]).filter(Boolean);
478038
- const debugPayload = {
478039
- timestamp: new Date(debugTimestamp).toISOString(),
478040
- model: openaiModel,
478041
- request: debugRequestData,
478042
- response: {
478043
- stop_reason: stopReason,
478044
- usage,
478045
- content_blocks: allBlocks.map((b3) => {
478046
- if (b3.type === "text")
478047
- return { type: "text", text: b3.text };
478048
- if (b3.type === "thinking")
478049
- return { type: "thinking", thinking_preview: b3.thinking?.substring(0, 200) };
478050
- if (b3.type === "tool_use")
478051
- return { type: "tool_use", name: b3.name, input_preview: typeof b3.input === "string" ? b3.input.substring(0, 500) : b3.input };
478052
- return { type: b3.type };
478053
- }),
478054
- duration_ms: Date.now() - start
478055
- }
478056
- };
478057
- writeFileSync9(debugFile, JSON.stringify(debugPayload, null, 2), "utf-8");
478058
- logForDebugging(`[DEBUG] OpenAI request+response dumped to ${debugFile}`);
478059
- } catch (e) {
478060
- logForDebugging(`[DEBUG] Failed to dump OpenAI debug file: ${e}`);
478061
- }
478298
+ if (isOpenAIDebugDumpEnabled())
478299
+ try {
478300
+ const { writeFileSync: writeFileSync9, mkdirSync: mkdirSync7 } = await import("node:fs");
478301
+ const { join: join131 } = await import("node:path");
478302
+ const { tmpdir: tmpdir13 } = await import("node:os");
478303
+ const debugDir = join131(tmpdir13(), "claude-code-debug");
478304
+ mkdirSync7(debugDir, { recursive: true });
478305
+ const debugFile = join131(debugDir, `openai-${debugTimestamp}.json`);
478306
+ const allBlocks = Object.keys(contentBlocks).sort((a2, b3) => Number(a2) - Number(b3)).map((k2) => contentBlocks[Number(k2)]).filter(Boolean);
478307
+ const debugPayload = {
478308
+ timestamp: new Date(debugTimestamp).toISOString(),
478309
+ model: openaiModel,
478310
+ request: debugRequestData,
478311
+ response: {
478312
+ stop_reason: stopReason,
478313
+ usage,
478314
+ content_blocks: allBlocks.map((b3) => {
478315
+ if (b3.type === "text")
478316
+ return { type: "text", text: b3.text };
478317
+ if (b3.type === "thinking")
478318
+ return { type: "thinking", thinking_preview: b3.thinking?.substring(0, 200) };
478319
+ if (b3.type === "tool_use")
478320
+ return { type: "tool_use", name: b3.name, input_preview: typeof b3.input === "string" ? b3.input.substring(0, 500) : b3.input };
478321
+ return { type: b3.type };
478322
+ }),
478323
+ duration_ms: Date.now() - start
478324
+ }
478325
+ };
478326
+ writeFileSync9(debugFile, JSON.stringify(debugPayload, null, 2), "utf-8");
478327
+ logForDebugging(`[DEBUG] OpenAI request+response dumped to ${debugFile}`);
478328
+ } catch (e) {
478329
+ logForDebugging(`[DEBUG] Failed to dump OpenAI debug file: ${e}`);
478330
+ }
478062
478331
  } catch (error50) {
478063
478332
  const errorMessage2 = error50 instanceof Error ? error50.message : String(error50);
478064
478333
  const errorRecord = error50 && typeof error50 === "object" ? error50 : undefined;
@@ -481918,7 +482187,7 @@ function buildSystemInitMessage(inputs) {
481918
482187
  slash_commands: inputs.commands.filter((c6) => c6.userInvocable !== false).map((c6) => c6.name),
481919
482188
  apiKeySource: getAnthropicApiKeyWithSource().source,
481920
482189
  betas: getSdkBetas(),
481921
- claude_code_version: "0.0.27",
482190
+ claude_code_version: "0.0.28",
481922
482191
  output_style: outputStyle2,
481923
482192
  agents: inputs.agents.map((agent) => agent.agentType),
481924
482193
  skills: inputs.skills.filter((s) => s.userInvocable !== false).map((skill) => skill.name),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caspian2026/agent-sdk",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "AI-powered agent SDK for the terminal",
5
5
  "type": "module",
6
6
  "engines": {