@opencow-ai/opencow-agent-sdk 0.4.9 → 0.4.11

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.
package/dist/cli.mjs CHANGED
@@ -83971,6 +83971,71 @@ var init_geminiAuth = __esm(() => {
83971
83971
  }, {}), GEMINI_ADC_CACHE_TTL_MS);
83972
83972
  });
83973
83973
 
83974
+ // src/providers/shared/dsmlSentinel.ts
83975
+ function normalizeDsmlSentinel(value) {
83976
+ return value.replace(/|/g, "|").replace(/\s+/g, "");
83977
+ }
83978
+ function isDsmlFunctionCallSentinelPrefix(value) {
83979
+ const normalized = normalizeDsmlSentinel(value);
83980
+ return normalized.length > 0 && DSML_FUNCTION_CALL_SENTINEL.startsWith(normalized);
83981
+ }
83982
+ function findDsmlFunctionCallSentinel(text) {
83983
+ const re = /<\s*[||]\s*DSML\s*[||]\s*function_calls\b/;
83984
+ const match = re.exec(text);
83985
+ if (!match || match.index === undefined)
83986
+ return null;
83987
+ return { start: match.index, end: match.index + match[0].length };
83988
+ }
83989
+ function findTrailingDsmlCandidateStart(text) {
83990
+ for (let i2 = 0;i2 < text.length; i2++) {
83991
+ if (isDsmlFunctionCallSentinelPrefix(text.slice(i2))) {
83992
+ return i2;
83993
+ }
83994
+ }
83995
+ return null;
83996
+ }
83997
+ function createDsmlFunctionCallTextFilter() {
83998
+ let pending = "";
83999
+ const drain = (final) => {
84000
+ let output = "";
84001
+ while (pending) {
84002
+ const sentinel = findDsmlFunctionCallSentinel(pending);
84003
+ if (sentinel) {
84004
+ output += pending.slice(0, sentinel.start).trimEnd();
84005
+ pending = pending.slice(sentinel.end);
84006
+ continue;
84007
+ }
84008
+ if (final) {
84009
+ output += pending;
84010
+ pending = "";
84011
+ break;
84012
+ }
84013
+ const candidateStart = findTrailingDsmlCandidateStart(pending);
84014
+ if (candidateStart === null) {
84015
+ output += pending;
84016
+ pending = "";
84017
+ break;
84018
+ }
84019
+ output += pending.slice(0, candidateStart).trimEnd();
84020
+ pending = pending.slice(candidateStart);
84021
+ break;
84022
+ }
84023
+ return output;
84024
+ };
84025
+ return {
84026
+ push(text) {
84027
+ if (!text)
84028
+ return "";
84029
+ pending += text;
84030
+ return drain(false);
84031
+ },
84032
+ flush() {
84033
+ return drain(true);
84034
+ }
84035
+ };
84036
+ }
84037
+ var DSML_FUNCTION_CALL_SENTINEL = "<|DSML|function_calls";
84038
+
83974
84039
  // src/providers/shared/geminiCredentials.ts
83975
84040
  var exports_geminiCredentials = {};
83976
84041
  __export(exports_geminiCredentials, {
@@ -84957,9 +85022,21 @@ async function* codexStreamToAnthropic(response, model) {
84957
85022
  let nextContentBlockIndex = 0;
84958
85023
  let sawToolUse = false;
84959
85024
  let finalResponse;
85025
+ const dsmlTextFilter = createDsmlFunctionCallTextFilter();
84960
85026
  const closeActiveTextBlock = async function* () {
84961
85027
  if (activeTextBlockIndex === null)
84962
85028
  return;
85029
+ const flushedText = dsmlTextFilter.flush();
85030
+ if (flushedText) {
85031
+ yield {
85032
+ type: "content_block_delta",
85033
+ index: activeTextBlockIndex,
85034
+ delta: {
85035
+ type: "text_delta",
85036
+ text: flushedText
85037
+ }
85038
+ };
85039
+ }
84963
85040
  yield {
84964
85041
  type: "content_block_stop",
84965
85042
  index: activeTextBlockIndex
@@ -85071,14 +85148,17 @@ async function* codexStreamToAnthropic(response, model) {
85071
85148
  if (event.event === "response.output_text.delta") {
85072
85149
  yield* startTextBlockIfNeeded();
85073
85150
  if (activeTextBlockIndex !== null) {
85074
- yield {
85075
- type: "content_block_delta",
85076
- index: activeTextBlockIndex,
85077
- delta: {
85078
- type: "text_delta",
85079
- text: payload.delta ?? ""
85080
- }
85081
- };
85151
+ const filteredText = dsmlTextFilter.push(payload.delta ?? "");
85152
+ if (filteredText) {
85153
+ yield {
85154
+ type: "content_block_delta",
85155
+ index: activeTextBlockIndex,
85156
+ delta: {
85157
+ type: "text_delta",
85158
+ text: filteredText
85159
+ }
85160
+ };
85161
+ }
85082
85162
  }
85083
85163
  continue;
85084
85164
  }
@@ -85619,6 +85699,36 @@ async function* openaiStreamToAnthropic(response, model) {
85619
85699
  let lastStopReason = null;
85620
85700
  let hasEmittedFinalUsage = false;
85621
85701
  let hasProcessedFinishReason = false;
85702
+ let pendingTextBuffer = "";
85703
+ const dsmlTextFilter = createDsmlFunctionCallTextFilter();
85704
+ const emitBufferedText = (mode) => {
85705
+ const events = [];
85706
+ if (!pendingTextBuffer && mode !== "final")
85707
+ return events;
85708
+ const visible = mode === "final" ? dsmlTextFilter.push(pendingTextBuffer) + dsmlTextFilter.flush() : dsmlTextFilter.push(pendingTextBuffer);
85709
+ pendingTextBuffer = "";
85710
+ if (visible) {
85711
+ events.push(...emitTextDeltaEvents(visible));
85712
+ }
85713
+ return events;
85714
+ };
85715
+ const emitTextDeltaEvents = (text) => {
85716
+ const events = [];
85717
+ if (!hasEmittedContentStart) {
85718
+ events.push({
85719
+ type: "content_block_start",
85720
+ index: contentBlockIndex,
85721
+ content_block: { type: "text", text: "" }
85722
+ });
85723
+ hasEmittedContentStart = true;
85724
+ }
85725
+ events.push({
85726
+ type: "content_block_delta",
85727
+ index: contentBlockIndex,
85728
+ delta: { type: "text_delta", text }
85729
+ });
85730
+ return events;
85731
+ };
85622
85732
  yield {
85623
85733
  type: "message_start",
85624
85734
  message: {
@@ -85726,21 +85836,13 @@ async function* openaiStreamToAnthropic(response, model) {
85726
85836
  hasClosedReasoning = true;
85727
85837
  }
85728
85838
  if (delta.content != null) {
85729
- if (!hasEmittedContentStart) {
85730
- yield {
85731
- type: "content_block_start",
85732
- index: contentBlockIndex,
85733
- content_block: { type: "text", text: "" }
85734
- };
85735
- hasEmittedContentStart = true;
85736
- }
85737
- yield {
85738
- type: "content_block_delta",
85739
- index: contentBlockIndex,
85740
- delta: { type: "text_delta", text: delta.content }
85741
- };
85839
+ pendingTextBuffer += delta.content;
85840
+ for (const event of emitBufferedText("streaming"))
85841
+ yield event;
85742
85842
  }
85743
85843
  if (delta.tool_calls) {
85844
+ for (const event of emitBufferedText("before_tool_call"))
85845
+ yield event;
85744
85846
  for (const tc of delta.tool_calls) {
85745
85847
  if (tc.id && tc.function?.name) {
85746
85848
  if (hasEmittedContentStart) {
@@ -85807,6 +85909,8 @@ async function* openaiStreamToAnthropic(response, model) {
85807
85909
  };
85808
85910
  hasClosedReasoning = true;
85809
85911
  }
85912
+ for (const event of emitBufferedText("final"))
85913
+ yield event;
85810
85914
  if (hasEmittedContentStart) {
85811
85915
  yield {
85812
85916
  type: "content_block_stop",
@@ -94436,7 +94540,7 @@ function printStartupScreen() {
94436
94540
  const sLen = ` ● ${sL} Ready — type /help to begin`.length;
94437
94541
  out.push(boxRow(sRow, W2, sLen));
94438
94542
  out.push(`${rgb(...BORDER)}╚${"═".repeat(W2 - 2)}╝${RESET}`);
94439
- out.push(` ${DIM}${rgb(...DIMCOL)}opencow ${RESET}${rgb(...ACCENT)}v${"0.4.9"}${RESET}`);
94543
+ out.push(` ${DIM}${rgb(...DIMCOL)}opencow ${RESET}${rgb(...ACCENT)}v${"0.4.11"}${RESET}`);
94440
94544
  out.push("");
94441
94545
  process.stdout.write(out.join(`
94442
94546
  `) + `
@@ -244306,7 +244410,7 @@ function getAnthropicEnvMetadata() {
244306
244410
  function getBuildAgeMinutes() {
244307
244411
  if (false)
244308
244412
  ;
244309
- const buildTime = new Date("2026-06-23T13:05:35.394Z").getTime();
244413
+ const buildTime = new Date("2026-06-24T03:20:56.844Z").getTime();
244310
244414
  if (isNaN(buildTime))
244311
244415
  return;
244312
244416
  return Math.floor((Date.now() - buildTime) / 60000);
@@ -307734,6 +307838,7 @@ ${deferredToolList}
307734
307838
  const STALL_THRESHOLD_MS2 = 30000;
307735
307839
  let totalStallTime = 0;
307736
307840
  let stallCount = 0;
307841
+ const dsmlTextFilters = new Map;
307737
307842
  for await (const part of stream4) {
307738
307843
  resetStreamIdleTimer();
307739
307844
  const now = Date.now();
@@ -307800,6 +307905,7 @@ ${deferredToolList}
307800
307905
  ...part.content_block,
307801
307906
  text: ""
307802
307907
  };
307908
+ dsmlTextFilters.set(part.index, createDsmlFunctionCallTextFilter());
307803
307909
  break;
307804
307910
  case "thinking":
307805
307911
  contentBlocks[part.index] = {
@@ -307859,7 +307965,13 @@ ${deferredToolList}
307859
307965
  });
307860
307966
  throw new Error("Content block is not a text block");
307861
307967
  }
307862
- contentBlock.text += delta.text;
307968
+ {
307969
+ const filter2 = dsmlTextFilters.get(part.index) ?? createDsmlFunctionCallTextFilter();
307970
+ dsmlTextFilters.set(part.index, filter2);
307971
+ const visibleText = filter2.push(delta.text);
307972
+ delta.text = visibleText;
307973
+ contentBlock.text += visibleText;
307974
+ }
307863
307975
  break;
307864
307976
  case "signature_delta":
307865
307977
  if (false) {}
@@ -307908,6 +308020,11 @@ ${deferredToolList}
307908
308020
  });
307909
308021
  throw new Error("Message not found");
307910
308022
  }
308023
+ const filter2 = dsmlTextFilters.get(part.index);
308024
+ if (filter2 && contentBlock.type === "text") {
308025
+ contentBlock.text += filter2.flush();
308026
+ dsmlTextFilters.delete(part.index);
308027
+ }
307911
308028
  const m = {
307912
308029
  message: {
307913
308030
  ...partialMessage,
@@ -479669,7 +479786,7 @@ function buildPrimarySection() {
479669
479786
  }, undefined, false, undefined, this);
479670
479787
  return [{
479671
479788
  label: "Version",
479672
- value: "0.4.9"
479789
+ value: "0.4.11"
479673
479790
  }, {
479674
479791
  label: "Session name",
479675
479792
  value: nameValue
@@ -535991,7 +536108,7 @@ var init_bridge_kick = __esm(() => {
535991
536108
  var call58 = async () => {
535992
536109
  return {
535993
536110
  type: "text",
535994
- value: `${"99.0.0"} (built ${"2026-06-23T13:05:35.394Z"})`
536111
+ value: `${"99.0.0"} (built ${"2026-06-24T03:20:56.844Z"})`
535995
536112
  };
535996
536113
  }, version2, version_default;
535997
536114
  var init_version = __esm(() => {
@@ -558101,7 +558218,7 @@ function WelcomeV2() {
558101
558218
  dimColor: true,
558102
558219
  children: [
558103
558220
  "v",
558104
- "0.4.9",
558221
+ "0.4.11",
558105
558222
  " "
558106
558223
  ]
558107
558224
  }, undefined, true, undefined, this)
@@ -558301,7 +558418,7 @@ function WelcomeV2() {
558301
558418
  dimColor: true,
558302
558419
  children: [
558303
558420
  "v",
558304
- "0.4.9",
558421
+ "0.4.11",
558305
558422
  " "
558306
558423
  ]
558307
558424
  }, undefined, true, undefined, this)
@@ -558527,7 +558644,7 @@ function AppleTerminalWelcomeV2(t0) {
558527
558644
  dimColor: true,
558528
558645
  children: [
558529
558646
  "v",
558530
- "0.4.9",
558647
+ "0.4.11",
558531
558648
  " "
558532
558649
  ]
558533
558650
  }, undefined, true, undefined, this);
@@ -558781,7 +558898,7 @@ function AppleTerminalWelcomeV2(t0) {
558781
558898
  dimColor: true,
558782
558899
  children: [
558783
558900
  "v",
558784
- "0.4.9",
558901
+ "0.4.11",
558785
558902
  " "
558786
558903
  ]
558787
558904
  }, undefined, true, undefined, this);
@@ -579638,7 +579755,7 @@ Usage: claude --remote "your task description"`, () => gracefulShutdown(1));
579638
579755
  pendingHookMessages
579639
579756
  }, renderAndRun);
579640
579757
  }
579641
- }).version("0.4.9 (OpenCow)", "-v, --version", "Output the version number");
579758
+ }).version("0.4.11 (OpenCow)", "-v, --version", "Output the version number");
579642
579759
  program2.option("-w, --worktree [name]", "Create a new git worktree for this session (optionally specify a name)");
579643
579760
  program2.option("--tmux", "Create a tmux session for the worktree (requires --worktree). Uses iTerm2 native panes when available; use --tmux=classic for traditional tmux.");
579644
579761
  if (canUserConfigureAdvisor()) {
@@ -580284,7 +580401,7 @@ if (false) {}
580284
580401
  async function main2() {
580285
580402
  const args = process.argv.slice(2);
580286
580403
  if (args.length === 1 && (args[0] === "--version" || args[0] === "-v" || args[0] === "-V")) {
580287
- console.log(`${"0.4.9"} (OpenCow)`);
580404
+ console.log(`${"0.4.11"} (OpenCow)`);
580288
580405
  return;
580289
580406
  }
580290
580407
  if (args.includes("--provider")) {
@@ -580402,4 +580519,4 @@ async function main2() {
580402
580519
  }
580403
580520
  main2();
580404
580521
 
580405
- //# debugId=56C6FA588ED1DECD64756E2164756E21
580522
+ //# debugId=A3FE6F2E9266C7E764756E2164756E21
package/dist/client.js CHANGED
@@ -94790,6 +94790,71 @@ var init_geminiAuth = __esm(() => {
94790
94790
  }, {}), GEMINI_ADC_CACHE_TTL_MS);
94791
94791
  });
94792
94792
 
94793
+ // src/providers/shared/dsmlSentinel.ts
94794
+ function normalizeDsmlSentinel(value) {
94795
+ return value.replace(/|/g, "|").replace(/\s+/g, "");
94796
+ }
94797
+ function isDsmlFunctionCallSentinelPrefix(value) {
94798
+ const normalized = normalizeDsmlSentinel(value);
94799
+ return normalized.length > 0 && DSML_FUNCTION_CALL_SENTINEL.startsWith(normalized);
94800
+ }
94801
+ function findDsmlFunctionCallSentinel(text) {
94802
+ const re = /<\s*[||]\s*DSML\s*[||]\s*function_calls\b/;
94803
+ const match = re.exec(text);
94804
+ if (!match || match.index === undefined)
94805
+ return null;
94806
+ return { start: match.index, end: match.index + match[0].length };
94807
+ }
94808
+ function findTrailingDsmlCandidateStart(text) {
94809
+ for (let i2 = 0;i2 < text.length; i2++) {
94810
+ if (isDsmlFunctionCallSentinelPrefix(text.slice(i2))) {
94811
+ return i2;
94812
+ }
94813
+ }
94814
+ return null;
94815
+ }
94816
+ function createDsmlFunctionCallTextFilter() {
94817
+ let pending = "";
94818
+ const drain = (final) => {
94819
+ let output = "";
94820
+ while (pending) {
94821
+ const sentinel = findDsmlFunctionCallSentinel(pending);
94822
+ if (sentinel) {
94823
+ output += pending.slice(0, sentinel.start).trimEnd();
94824
+ pending = pending.slice(sentinel.end);
94825
+ continue;
94826
+ }
94827
+ if (final) {
94828
+ output += pending;
94829
+ pending = "";
94830
+ break;
94831
+ }
94832
+ const candidateStart = findTrailingDsmlCandidateStart(pending);
94833
+ if (candidateStart === null) {
94834
+ output += pending;
94835
+ pending = "";
94836
+ break;
94837
+ }
94838
+ output += pending.slice(0, candidateStart).trimEnd();
94839
+ pending = pending.slice(candidateStart);
94840
+ break;
94841
+ }
94842
+ return output;
94843
+ };
94844
+ return {
94845
+ push(text) {
94846
+ if (!text)
94847
+ return "";
94848
+ pending += text;
94849
+ return drain(false);
94850
+ },
94851
+ flush() {
94852
+ return drain(true);
94853
+ }
94854
+ };
94855
+ }
94856
+ var DSML_FUNCTION_CALL_SENTINEL = "<|DSML|function_calls";
94857
+
94793
94858
  // src/providers/shared/geminiCredentials.ts
94794
94859
  function readGeminiAccessToken() {
94795
94860
  if (isBareMode())
@@ -95706,9 +95771,21 @@ async function* codexStreamToAnthropic(response, model) {
95706
95771
  let nextContentBlockIndex = 0;
95707
95772
  let sawToolUse = false;
95708
95773
  let finalResponse;
95774
+ const dsmlTextFilter = createDsmlFunctionCallTextFilter();
95709
95775
  const closeActiveTextBlock = async function* () {
95710
95776
  if (activeTextBlockIndex === null)
95711
95777
  return;
95778
+ const flushedText = dsmlTextFilter.flush();
95779
+ if (flushedText) {
95780
+ yield {
95781
+ type: "content_block_delta",
95782
+ index: activeTextBlockIndex,
95783
+ delta: {
95784
+ type: "text_delta",
95785
+ text: flushedText
95786
+ }
95787
+ };
95788
+ }
95712
95789
  yield {
95713
95790
  type: "content_block_stop",
95714
95791
  index: activeTextBlockIndex
@@ -95820,14 +95897,17 @@ async function* codexStreamToAnthropic(response, model) {
95820
95897
  if (event.event === "response.output_text.delta") {
95821
95898
  yield* startTextBlockIfNeeded();
95822
95899
  if (activeTextBlockIndex !== null) {
95823
- yield {
95824
- type: "content_block_delta",
95825
- index: activeTextBlockIndex,
95826
- delta: {
95827
- type: "text_delta",
95828
- text: payload.delta ?? ""
95829
- }
95830
- };
95900
+ const filteredText = dsmlTextFilter.push(payload.delta ?? "");
95901
+ if (filteredText) {
95902
+ yield {
95903
+ type: "content_block_delta",
95904
+ index: activeTextBlockIndex,
95905
+ delta: {
95906
+ type: "text_delta",
95907
+ text: filteredText
95908
+ }
95909
+ };
95910
+ }
95831
95911
  }
95832
95912
  continue;
95833
95913
  }
@@ -96443,6 +96523,36 @@ async function* openaiStreamToAnthropic(response, model) {
96443
96523
  let lastStopReason = null;
96444
96524
  let hasEmittedFinalUsage = false;
96445
96525
  let hasProcessedFinishReason = false;
96526
+ let pendingTextBuffer = "";
96527
+ const dsmlTextFilter = createDsmlFunctionCallTextFilter();
96528
+ const emitBufferedText = (mode) => {
96529
+ const events = [];
96530
+ if (!pendingTextBuffer && mode !== "final")
96531
+ return events;
96532
+ const visible = mode === "final" ? dsmlTextFilter.push(pendingTextBuffer) + dsmlTextFilter.flush() : dsmlTextFilter.push(pendingTextBuffer);
96533
+ pendingTextBuffer = "";
96534
+ if (visible) {
96535
+ events.push(...emitTextDeltaEvents(visible));
96536
+ }
96537
+ return events;
96538
+ };
96539
+ const emitTextDeltaEvents = (text) => {
96540
+ const events = [];
96541
+ if (!hasEmittedContentStart) {
96542
+ events.push({
96543
+ type: "content_block_start",
96544
+ index: contentBlockIndex,
96545
+ content_block: { type: "text", text: "" }
96546
+ });
96547
+ hasEmittedContentStart = true;
96548
+ }
96549
+ events.push({
96550
+ type: "content_block_delta",
96551
+ index: contentBlockIndex,
96552
+ delta: { type: "text_delta", text }
96553
+ });
96554
+ return events;
96555
+ };
96446
96556
  yield {
96447
96557
  type: "message_start",
96448
96558
  message: {
@@ -96550,21 +96660,13 @@ async function* openaiStreamToAnthropic(response, model) {
96550
96660
  hasClosedReasoning = true;
96551
96661
  }
96552
96662
  if (delta.content != null) {
96553
- if (!hasEmittedContentStart) {
96554
- yield {
96555
- type: "content_block_start",
96556
- index: contentBlockIndex,
96557
- content_block: { type: "text", text: "" }
96558
- };
96559
- hasEmittedContentStart = true;
96560
- }
96561
- yield {
96562
- type: "content_block_delta",
96563
- index: contentBlockIndex,
96564
- delta: { type: "text_delta", text: delta.content }
96565
- };
96663
+ pendingTextBuffer += delta.content;
96664
+ for (const event of emitBufferedText("streaming"))
96665
+ yield event;
96566
96666
  }
96567
96667
  if (delta.tool_calls) {
96668
+ for (const event of emitBufferedText("before_tool_call"))
96669
+ yield event;
96568
96670
  for (const tc of delta.tool_calls) {
96569
96671
  if (tc.id && tc.function?.name) {
96570
96672
  if (hasEmittedContentStart) {
@@ -96631,6 +96733,8 @@ async function* openaiStreamToAnthropic(response, model) {
96631
96733
  };
96632
96734
  hasClosedReasoning = true;
96633
96735
  }
96736
+ for (const event of emitBufferedText("final"))
96737
+ yield event;
96634
96738
  if (hasEmittedContentStart) {
96635
96739
  yield {
96636
96740
  type: "content_block_stop",
@@ -282588,7 +282692,7 @@ function getAnthropicEnvMetadata() {
282588
282692
  function getBuildAgeMinutes() {
282589
282693
  if (false)
282590
282694
  ;
282591
- const buildTime = new Date("2026-06-23T13:05:35.394Z").getTime();
282695
+ const buildTime = new Date("2026-06-24T03:20:56.844Z").getTime();
282592
282696
  if (isNaN(buildTime))
282593
282697
  return;
282594
282698
  return Math.floor((Date.now() - buildTime) / 60000);
@@ -293872,6 +293976,7 @@ ${deferredToolList}
293872
293976
  const STALL_THRESHOLD_MS2 = 30000;
293873
293977
  let totalStallTime = 0;
293874
293978
  let stallCount = 0;
293979
+ const dsmlTextFilters = new Map;
293875
293980
  for await (const part of stream4) {
293876
293981
  resetStreamIdleTimer();
293877
293982
  const now = Date.now();
@@ -293938,6 +294043,7 @@ ${deferredToolList}
293938
294043
  ...part.content_block,
293939
294044
  text: ""
293940
294045
  };
294046
+ dsmlTextFilters.set(part.index, createDsmlFunctionCallTextFilter());
293941
294047
  break;
293942
294048
  case "thinking":
293943
294049
  contentBlocks[part.index] = {
@@ -293997,7 +294103,13 @@ ${deferredToolList}
293997
294103
  });
293998
294104
  throw new Error("Content block is not a text block");
293999
294105
  }
294000
- contentBlock.text += delta.text;
294106
+ {
294107
+ const filter2 = dsmlTextFilters.get(part.index) ?? createDsmlFunctionCallTextFilter();
294108
+ dsmlTextFilters.set(part.index, filter2);
294109
+ const visibleText = filter2.push(delta.text);
294110
+ delta.text = visibleText;
294111
+ contentBlock.text += visibleText;
294112
+ }
294001
294113
  break;
294002
294114
  case "signature_delta":
294003
294115
  if (false) {}
@@ -294046,6 +294158,11 @@ ${deferredToolList}
294046
294158
  });
294047
294159
  throw new Error("Message not found");
294048
294160
  }
294161
+ const filter2 = dsmlTextFilters.get(part.index);
294162
+ if (filter2 && contentBlock.type === "text") {
294163
+ contentBlock.text += filter2.flush();
294164
+ dsmlTextFilters.delete(part.index);
294165
+ }
294049
294166
  const m = {
294050
294167
  message: {
294051
294168
  ...partialMessage,
@@ -335938,4 +336055,4 @@ export {
335938
336055
  AbortError2 as AbortError
335939
336056
  };
335940
336057
 
335941
- //# debugId=D5A0C61CA530F61064756E2164756E21
336058
+ //# debugId=7376AE95E91B9BFD64756E2164756E21
@@ -0,0 +1,5 @@
1
+ export interface DsmlFunctionCallTextFilter {
2
+ push(text: string): string;
3
+ flush(): string;
4
+ }
5
+ export declare function createDsmlFunctionCallTextFilter(): DsmlFunctionCallTextFilter;
package/dist/sdk.js CHANGED
@@ -94790,6 +94790,71 @@ var init_geminiAuth = __esm(() => {
94790
94790
  }, {}), GEMINI_ADC_CACHE_TTL_MS);
94791
94791
  });
94792
94792
 
94793
+ // src/providers/shared/dsmlSentinel.ts
94794
+ function normalizeDsmlSentinel(value) {
94795
+ return value.replace(/|/g, "|").replace(/\s+/g, "");
94796
+ }
94797
+ function isDsmlFunctionCallSentinelPrefix(value) {
94798
+ const normalized = normalizeDsmlSentinel(value);
94799
+ return normalized.length > 0 && DSML_FUNCTION_CALL_SENTINEL.startsWith(normalized);
94800
+ }
94801
+ function findDsmlFunctionCallSentinel(text) {
94802
+ const re = /<\s*[||]\s*DSML\s*[||]\s*function_calls\b/;
94803
+ const match = re.exec(text);
94804
+ if (!match || match.index === undefined)
94805
+ return null;
94806
+ return { start: match.index, end: match.index + match[0].length };
94807
+ }
94808
+ function findTrailingDsmlCandidateStart(text) {
94809
+ for (let i2 = 0;i2 < text.length; i2++) {
94810
+ if (isDsmlFunctionCallSentinelPrefix(text.slice(i2))) {
94811
+ return i2;
94812
+ }
94813
+ }
94814
+ return null;
94815
+ }
94816
+ function createDsmlFunctionCallTextFilter() {
94817
+ let pending = "";
94818
+ const drain = (final) => {
94819
+ let output = "";
94820
+ while (pending) {
94821
+ const sentinel = findDsmlFunctionCallSentinel(pending);
94822
+ if (sentinel) {
94823
+ output += pending.slice(0, sentinel.start).trimEnd();
94824
+ pending = pending.slice(sentinel.end);
94825
+ continue;
94826
+ }
94827
+ if (final) {
94828
+ output += pending;
94829
+ pending = "";
94830
+ break;
94831
+ }
94832
+ const candidateStart = findTrailingDsmlCandidateStart(pending);
94833
+ if (candidateStart === null) {
94834
+ output += pending;
94835
+ pending = "";
94836
+ break;
94837
+ }
94838
+ output += pending.slice(0, candidateStart).trimEnd();
94839
+ pending = pending.slice(candidateStart);
94840
+ break;
94841
+ }
94842
+ return output;
94843
+ };
94844
+ return {
94845
+ push(text) {
94846
+ if (!text)
94847
+ return "";
94848
+ pending += text;
94849
+ return drain(false);
94850
+ },
94851
+ flush() {
94852
+ return drain(true);
94853
+ }
94854
+ };
94855
+ }
94856
+ var DSML_FUNCTION_CALL_SENTINEL = "<|DSML|function_calls";
94857
+
94793
94858
  // src/providers/shared/geminiCredentials.ts
94794
94859
  function readGeminiAccessToken() {
94795
94860
  if (isBareMode())
@@ -95706,9 +95771,21 @@ async function* codexStreamToAnthropic(response, model) {
95706
95771
  let nextContentBlockIndex = 0;
95707
95772
  let sawToolUse = false;
95708
95773
  let finalResponse;
95774
+ const dsmlTextFilter = createDsmlFunctionCallTextFilter();
95709
95775
  const closeActiveTextBlock = async function* () {
95710
95776
  if (activeTextBlockIndex === null)
95711
95777
  return;
95778
+ const flushedText = dsmlTextFilter.flush();
95779
+ if (flushedText) {
95780
+ yield {
95781
+ type: "content_block_delta",
95782
+ index: activeTextBlockIndex,
95783
+ delta: {
95784
+ type: "text_delta",
95785
+ text: flushedText
95786
+ }
95787
+ };
95788
+ }
95712
95789
  yield {
95713
95790
  type: "content_block_stop",
95714
95791
  index: activeTextBlockIndex
@@ -95820,14 +95897,17 @@ async function* codexStreamToAnthropic(response, model) {
95820
95897
  if (event.event === "response.output_text.delta") {
95821
95898
  yield* startTextBlockIfNeeded();
95822
95899
  if (activeTextBlockIndex !== null) {
95823
- yield {
95824
- type: "content_block_delta",
95825
- index: activeTextBlockIndex,
95826
- delta: {
95827
- type: "text_delta",
95828
- text: payload.delta ?? ""
95829
- }
95830
- };
95900
+ const filteredText = dsmlTextFilter.push(payload.delta ?? "");
95901
+ if (filteredText) {
95902
+ yield {
95903
+ type: "content_block_delta",
95904
+ index: activeTextBlockIndex,
95905
+ delta: {
95906
+ type: "text_delta",
95907
+ text: filteredText
95908
+ }
95909
+ };
95910
+ }
95831
95911
  }
95832
95912
  continue;
95833
95913
  }
@@ -96443,6 +96523,36 @@ async function* openaiStreamToAnthropic(response, model) {
96443
96523
  let lastStopReason = null;
96444
96524
  let hasEmittedFinalUsage = false;
96445
96525
  let hasProcessedFinishReason = false;
96526
+ let pendingTextBuffer = "";
96527
+ const dsmlTextFilter = createDsmlFunctionCallTextFilter();
96528
+ const emitBufferedText = (mode) => {
96529
+ const events = [];
96530
+ if (!pendingTextBuffer && mode !== "final")
96531
+ return events;
96532
+ const visible = mode === "final" ? dsmlTextFilter.push(pendingTextBuffer) + dsmlTextFilter.flush() : dsmlTextFilter.push(pendingTextBuffer);
96533
+ pendingTextBuffer = "";
96534
+ if (visible) {
96535
+ events.push(...emitTextDeltaEvents(visible));
96536
+ }
96537
+ return events;
96538
+ };
96539
+ const emitTextDeltaEvents = (text) => {
96540
+ const events = [];
96541
+ if (!hasEmittedContentStart) {
96542
+ events.push({
96543
+ type: "content_block_start",
96544
+ index: contentBlockIndex,
96545
+ content_block: { type: "text", text: "" }
96546
+ });
96547
+ hasEmittedContentStart = true;
96548
+ }
96549
+ events.push({
96550
+ type: "content_block_delta",
96551
+ index: contentBlockIndex,
96552
+ delta: { type: "text_delta", text }
96553
+ });
96554
+ return events;
96555
+ };
96446
96556
  yield {
96447
96557
  type: "message_start",
96448
96558
  message: {
@@ -96550,21 +96660,13 @@ async function* openaiStreamToAnthropic(response, model) {
96550
96660
  hasClosedReasoning = true;
96551
96661
  }
96552
96662
  if (delta.content != null) {
96553
- if (!hasEmittedContentStart) {
96554
- yield {
96555
- type: "content_block_start",
96556
- index: contentBlockIndex,
96557
- content_block: { type: "text", text: "" }
96558
- };
96559
- hasEmittedContentStart = true;
96560
- }
96561
- yield {
96562
- type: "content_block_delta",
96563
- index: contentBlockIndex,
96564
- delta: { type: "text_delta", text: delta.content }
96565
- };
96663
+ pendingTextBuffer += delta.content;
96664
+ for (const event of emitBufferedText("streaming"))
96665
+ yield event;
96566
96666
  }
96567
96667
  if (delta.tool_calls) {
96668
+ for (const event of emitBufferedText("before_tool_call"))
96669
+ yield event;
96568
96670
  for (const tc of delta.tool_calls) {
96569
96671
  if (tc.id && tc.function?.name) {
96570
96672
  if (hasEmittedContentStart) {
@@ -96631,6 +96733,8 @@ async function* openaiStreamToAnthropic(response, model) {
96631
96733
  };
96632
96734
  hasClosedReasoning = true;
96633
96735
  }
96736
+ for (const event of emitBufferedText("final"))
96737
+ yield event;
96634
96738
  if (hasEmittedContentStart) {
96635
96739
  yield {
96636
96740
  type: "content_block_stop",
@@ -282588,7 +282692,7 @@ function getAnthropicEnvMetadata() {
282588
282692
  function getBuildAgeMinutes() {
282589
282693
  if (false)
282590
282694
  ;
282591
- const buildTime = new Date("2026-06-23T13:05:35.394Z").getTime();
282695
+ const buildTime = new Date("2026-06-24T03:20:56.844Z").getTime();
282592
282696
  if (isNaN(buildTime))
282593
282697
  return;
282594
282698
  return Math.floor((Date.now() - buildTime) / 60000);
@@ -293872,6 +293976,7 @@ ${deferredToolList}
293872
293976
  const STALL_THRESHOLD_MS2 = 30000;
293873
293977
  let totalStallTime = 0;
293874
293978
  let stallCount = 0;
293979
+ const dsmlTextFilters = new Map;
293875
293980
  for await (const part of stream4) {
293876
293981
  resetStreamIdleTimer();
293877
293982
  const now = Date.now();
@@ -293938,6 +294043,7 @@ ${deferredToolList}
293938
294043
  ...part.content_block,
293939
294044
  text: ""
293940
294045
  };
294046
+ dsmlTextFilters.set(part.index, createDsmlFunctionCallTextFilter());
293941
294047
  break;
293942
294048
  case "thinking":
293943
294049
  contentBlocks[part.index] = {
@@ -293997,7 +294103,13 @@ ${deferredToolList}
293997
294103
  });
293998
294104
  throw new Error("Content block is not a text block");
293999
294105
  }
294000
- contentBlock.text += delta.text;
294106
+ {
294107
+ const filter2 = dsmlTextFilters.get(part.index) ?? createDsmlFunctionCallTextFilter();
294108
+ dsmlTextFilters.set(part.index, filter2);
294109
+ const visibleText = filter2.push(delta.text);
294110
+ delta.text = visibleText;
294111
+ contentBlock.text += visibleText;
294112
+ }
294001
294113
  break;
294002
294114
  case "signature_delta":
294003
294115
  if (false) {}
@@ -294046,6 +294158,11 @@ ${deferredToolList}
294046
294158
  });
294047
294159
  throw new Error("Message not found");
294048
294160
  }
294161
+ const filter2 = dsmlTextFilters.get(part.index);
294162
+ if (filter2 && contentBlock.type === "text") {
294163
+ contentBlock.text += filter2.flush();
294164
+ dsmlTextFilters.delete(part.index);
294165
+ }
294049
294166
  const m = {
294050
294167
  message: {
294051
294168
  ...partialMessage,
@@ -335938,4 +336055,4 @@ export {
335938
336055
  AbortError2 as AbortError
335939
336056
  };
335940
336057
 
335941
- //# debugId=71BD791C80C9F42F64756E2164756E21
336058
+ //# debugId=7DBFD07CC9AC2F7C64756E2164756E21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencow-ai/opencow-agent-sdk",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "description": "Claude Code opened to any LLM — OpenAI, Gemini, DeepSeek, Ollama, and 200+ models",
5
5
  "type": "module",
6
6
  "main": "./dist/sdk.js",