@opencow-ai/opencow-agent-sdk 0.4.9 → 0.4.10
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 +89 -25
- package/dist/client.js +80 -16
- package/dist/sdk.js +80 -16
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -85609,6 +85609,32 @@ function buildOpenAIRequestBody(params, ctx) {
|
|
|
85609
85609
|
}
|
|
85610
85610
|
return body;
|
|
85611
85611
|
}
|
|
85612
|
+
function normalizeDsmlSentinelPrefix(value) {
|
|
85613
|
+
return value.replace(/|/g, "|").replace(/\s+/g, "");
|
|
85614
|
+
}
|
|
85615
|
+
function isDsmlFunctionCallSentinelPrefix(value) {
|
|
85616
|
+
const normalized = normalizeDsmlSentinelPrefix(value);
|
|
85617
|
+
return normalized.length > 0 && DSML_FUNCTION_CALL_SENTINEL.startsWith(normalized);
|
|
85618
|
+
}
|
|
85619
|
+
function findTrailingDsmlSentinelCandidateStart(text) {
|
|
85620
|
+
const lt = text.lastIndexOf("<");
|
|
85621
|
+
if (lt === -1)
|
|
85622
|
+
return null;
|
|
85623
|
+
return isDsmlFunctionCallSentinelPrefix(text.slice(lt)) ? lt : null;
|
|
85624
|
+
}
|
|
85625
|
+
function findBufferedTextFlushBoundary(text) {
|
|
85626
|
+
const sentinelStart = findTrailingDsmlSentinelCandidateStart(text);
|
|
85627
|
+
if (sentinelStart === null)
|
|
85628
|
+
return text.length;
|
|
85629
|
+
return text.slice(0, sentinelStart).trimEnd().length;
|
|
85630
|
+
}
|
|
85631
|
+
function findDsmlFunctionCallSentinel(text) {
|
|
85632
|
+
const re = /<\s*[||]\s*DSML\s*[||]\s*function_calls\b/;
|
|
85633
|
+
const match = re.exec(text);
|
|
85634
|
+
if (!match || match.index === undefined)
|
|
85635
|
+
return null;
|
|
85636
|
+
return { start: match.index, end: match.index + match[0].length };
|
|
85637
|
+
}
|
|
85612
85638
|
async function* openaiStreamToAnthropic(response, model) {
|
|
85613
85639
|
const messageId = makeMessageId2();
|
|
85614
85640
|
let contentBlockIndex = 0;
|
|
@@ -85619,6 +85645,50 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
85619
85645
|
let lastStopReason = null;
|
|
85620
85646
|
let hasEmittedFinalUsage = false;
|
|
85621
85647
|
let hasProcessedFinishReason = false;
|
|
85648
|
+
let pendingTextBuffer = "";
|
|
85649
|
+
const emitBufferedText = (mode) => {
|
|
85650
|
+
const events = [];
|
|
85651
|
+
if (!pendingTextBuffer)
|
|
85652
|
+
return events;
|
|
85653
|
+
const sentinel = findDsmlFunctionCallSentinel(pendingTextBuffer);
|
|
85654
|
+
if (sentinel) {
|
|
85655
|
+
const visible2 = pendingTextBuffer.slice(0, sentinel.start).trimEnd();
|
|
85656
|
+
pendingTextBuffer = pendingTextBuffer.slice(sentinel.end);
|
|
85657
|
+
if (visible2) {
|
|
85658
|
+
events.push(...emitTextDeltaEvents(visible2));
|
|
85659
|
+
}
|
|
85660
|
+
if (pendingTextBuffer) {
|
|
85661
|
+
events.push(...emitBufferedText(mode));
|
|
85662
|
+
}
|
|
85663
|
+
return events;
|
|
85664
|
+
}
|
|
85665
|
+
const emitUntil = mode === "final" ? pendingTextBuffer.length : mode === "before_tool_call" ? findTrailingDsmlSentinelCandidateStart(pendingTextBuffer) ?? pendingTextBuffer.length : findBufferedTextFlushBoundary(pendingTextBuffer);
|
|
85666
|
+
if (emitUntil <= 0)
|
|
85667
|
+
return events;
|
|
85668
|
+
const visible = pendingTextBuffer.slice(0, emitUntil);
|
|
85669
|
+
pendingTextBuffer = pendingTextBuffer.slice(emitUntil);
|
|
85670
|
+
if (visible) {
|
|
85671
|
+
events.push(...emitTextDeltaEvents(visible));
|
|
85672
|
+
}
|
|
85673
|
+
return events;
|
|
85674
|
+
};
|
|
85675
|
+
const emitTextDeltaEvents = (text) => {
|
|
85676
|
+
const events = [];
|
|
85677
|
+
if (!hasEmittedContentStart) {
|
|
85678
|
+
events.push({
|
|
85679
|
+
type: "content_block_start",
|
|
85680
|
+
index: contentBlockIndex,
|
|
85681
|
+
content_block: { type: "text", text: "" }
|
|
85682
|
+
});
|
|
85683
|
+
hasEmittedContentStart = true;
|
|
85684
|
+
}
|
|
85685
|
+
events.push({
|
|
85686
|
+
type: "content_block_delta",
|
|
85687
|
+
index: contentBlockIndex,
|
|
85688
|
+
delta: { type: "text_delta", text }
|
|
85689
|
+
});
|
|
85690
|
+
return events;
|
|
85691
|
+
};
|
|
85622
85692
|
yield {
|
|
85623
85693
|
type: "message_start",
|
|
85624
85694
|
message: {
|
|
@@ -85726,21 +85796,13 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
85726
85796
|
hasClosedReasoning = true;
|
|
85727
85797
|
}
|
|
85728
85798
|
if (delta.content != null) {
|
|
85729
|
-
|
|
85730
|
-
|
|
85731
|
-
|
|
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
|
-
};
|
|
85799
|
+
pendingTextBuffer += delta.content;
|
|
85800
|
+
for (const event of emitBufferedText("streaming"))
|
|
85801
|
+
yield event;
|
|
85742
85802
|
}
|
|
85743
85803
|
if (delta.tool_calls) {
|
|
85804
|
+
for (const event of emitBufferedText("before_tool_call"))
|
|
85805
|
+
yield event;
|
|
85744
85806
|
for (const tc of delta.tool_calls) {
|
|
85745
85807
|
if (tc.id && tc.function?.name) {
|
|
85746
85808
|
if (hasEmittedContentStart) {
|
|
@@ -85807,6 +85869,8 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
85807
85869
|
};
|
|
85808
85870
|
hasClosedReasoning = true;
|
|
85809
85871
|
}
|
|
85872
|
+
for (const event of emitBufferedText("final"))
|
|
85873
|
+
yield event;
|
|
85810
85874
|
if (hasEmittedContentStart) {
|
|
85811
85875
|
yield {
|
|
85812
85876
|
type: "content_block_stop",
|
|
@@ -86179,7 +86243,7 @@ function createOpenAIShimClient(options) {
|
|
|
86179
86243
|
messages: beta.messages
|
|
86180
86244
|
};
|
|
86181
86245
|
}
|
|
86182
|
-
var GITHUB_MODELS_DEFAULT_BASE = "https://models.github.ai/inference", GITHUB_API_VERSION = "2022-11-28", GITHUB_429_MAX_RETRIES = 3, GITHUB_429_BASE_DELAY_SEC = 1, GITHUB_429_MAX_DELAY_SEC = 32, OpenAIShimStream;
|
|
86246
|
+
var GITHUB_MODELS_DEFAULT_BASE = "https://models.github.ai/inference", GITHUB_API_VERSION = "2022-11-28", GITHUB_429_MAX_RETRIES = 3, GITHUB_429_BASE_DELAY_SEC = 1, GITHUB_429_MAX_DELAY_SEC = 32, DSML_FUNCTION_CALL_SENTINEL = "<|DSML|function_calls", OpenAIShimStream;
|
|
86183
86247
|
var init_shim2 = __esm(() => {
|
|
86184
86248
|
init_sdk();
|
|
86185
86249
|
init_envUtils();
|
|
@@ -94436,7 +94500,7 @@ function printStartupScreen() {
|
|
|
94436
94500
|
const sLen = ` ● ${sL} Ready — type /help to begin`.length;
|
|
94437
94501
|
out.push(boxRow(sRow, W2, sLen));
|
|
94438
94502
|
out.push(`${rgb(...BORDER)}╚${"═".repeat(W2 - 2)}╝${RESET}`);
|
|
94439
|
-
out.push(` ${DIM}${rgb(...DIMCOL)}opencow ${RESET}${rgb(...ACCENT)}v${"0.4.
|
|
94503
|
+
out.push(` ${DIM}${rgb(...DIMCOL)}opencow ${RESET}${rgb(...ACCENT)}v${"0.4.10"}${RESET}`);
|
|
94440
94504
|
out.push("");
|
|
94441
94505
|
process.stdout.write(out.join(`
|
|
94442
94506
|
`) + `
|
|
@@ -244306,7 +244370,7 @@ function getAnthropicEnvMetadata() {
|
|
|
244306
244370
|
function getBuildAgeMinutes() {
|
|
244307
244371
|
if (false)
|
|
244308
244372
|
;
|
|
244309
|
-
const buildTime = new Date("2026-06-
|
|
244373
|
+
const buildTime = new Date("2026-06-23T14:32:49.206Z").getTime();
|
|
244310
244374
|
if (isNaN(buildTime))
|
|
244311
244375
|
return;
|
|
244312
244376
|
return Math.floor((Date.now() - buildTime) / 60000);
|
|
@@ -479669,7 +479733,7 @@ function buildPrimarySection() {
|
|
|
479669
479733
|
}, undefined, false, undefined, this);
|
|
479670
479734
|
return [{
|
|
479671
479735
|
label: "Version",
|
|
479672
|
-
value: "0.4.
|
|
479736
|
+
value: "0.4.10"
|
|
479673
479737
|
}, {
|
|
479674
479738
|
label: "Session name",
|
|
479675
479739
|
value: nameValue
|
|
@@ -535991,7 +536055,7 @@ var init_bridge_kick = __esm(() => {
|
|
|
535991
536055
|
var call58 = async () => {
|
|
535992
536056
|
return {
|
|
535993
536057
|
type: "text",
|
|
535994
|
-
value: `${"99.0.0"} (built ${"2026-06-
|
|
536058
|
+
value: `${"99.0.0"} (built ${"2026-06-23T14:32:49.206Z"})`
|
|
535995
536059
|
};
|
|
535996
536060
|
}, version2, version_default;
|
|
535997
536061
|
var init_version = __esm(() => {
|
|
@@ -558101,7 +558165,7 @@ function WelcomeV2() {
|
|
|
558101
558165
|
dimColor: true,
|
|
558102
558166
|
children: [
|
|
558103
558167
|
"v",
|
|
558104
|
-
"0.4.
|
|
558168
|
+
"0.4.10",
|
|
558105
558169
|
" "
|
|
558106
558170
|
]
|
|
558107
558171
|
}, undefined, true, undefined, this)
|
|
@@ -558301,7 +558365,7 @@ function WelcomeV2() {
|
|
|
558301
558365
|
dimColor: true,
|
|
558302
558366
|
children: [
|
|
558303
558367
|
"v",
|
|
558304
|
-
"0.4.
|
|
558368
|
+
"0.4.10",
|
|
558305
558369
|
" "
|
|
558306
558370
|
]
|
|
558307
558371
|
}, undefined, true, undefined, this)
|
|
@@ -558527,7 +558591,7 @@ function AppleTerminalWelcomeV2(t0) {
|
|
|
558527
558591
|
dimColor: true,
|
|
558528
558592
|
children: [
|
|
558529
558593
|
"v",
|
|
558530
|
-
"0.4.
|
|
558594
|
+
"0.4.10",
|
|
558531
558595
|
" "
|
|
558532
558596
|
]
|
|
558533
558597
|
}, undefined, true, undefined, this);
|
|
@@ -558781,7 +558845,7 @@ function AppleTerminalWelcomeV2(t0) {
|
|
|
558781
558845
|
dimColor: true,
|
|
558782
558846
|
children: [
|
|
558783
558847
|
"v",
|
|
558784
|
-
"0.4.
|
|
558848
|
+
"0.4.10",
|
|
558785
558849
|
" "
|
|
558786
558850
|
]
|
|
558787
558851
|
}, undefined, true, undefined, this);
|
|
@@ -579638,7 +579702,7 @@ Usage: claude --remote "your task description"`, () => gracefulShutdown(1));
|
|
|
579638
579702
|
pendingHookMessages
|
|
579639
579703
|
}, renderAndRun);
|
|
579640
579704
|
}
|
|
579641
|
-
}).version("0.4.
|
|
579705
|
+
}).version("0.4.10 (OpenCow)", "-v, --version", "Output the version number");
|
|
579642
579706
|
program2.option("-w, --worktree [name]", "Create a new git worktree for this session (optionally specify a name)");
|
|
579643
579707
|
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
579708
|
if (canUserConfigureAdvisor()) {
|
|
@@ -580284,7 +580348,7 @@ if (false) {}
|
|
|
580284
580348
|
async function main2() {
|
|
580285
580349
|
const args = process.argv.slice(2);
|
|
580286
580350
|
if (args.length === 1 && (args[0] === "--version" || args[0] === "-v" || args[0] === "-V")) {
|
|
580287
|
-
console.log(`${"0.4.
|
|
580351
|
+
console.log(`${"0.4.10"} (OpenCow)`);
|
|
580288
580352
|
return;
|
|
580289
580353
|
}
|
|
580290
580354
|
if (args.includes("--provider")) {
|
|
@@ -580402,4 +580466,4 @@ async function main2() {
|
|
|
580402
580466
|
}
|
|
580403
580467
|
main2();
|
|
580404
580468
|
|
|
580405
|
-
//# debugId=
|
|
580469
|
+
//# debugId=10DA61343644BBA264756E2164756E21
|
package/dist/client.js
CHANGED
|
@@ -96433,6 +96433,32 @@ function buildOpenAIRequestBody(params, ctx) {
|
|
|
96433
96433
|
}
|
|
96434
96434
|
return body;
|
|
96435
96435
|
}
|
|
96436
|
+
function normalizeDsmlSentinelPrefix(value) {
|
|
96437
|
+
return value.replace(/|/g, "|").replace(/\s+/g, "");
|
|
96438
|
+
}
|
|
96439
|
+
function isDsmlFunctionCallSentinelPrefix(value) {
|
|
96440
|
+
const normalized = normalizeDsmlSentinelPrefix(value);
|
|
96441
|
+
return normalized.length > 0 && DSML_FUNCTION_CALL_SENTINEL.startsWith(normalized);
|
|
96442
|
+
}
|
|
96443
|
+
function findTrailingDsmlSentinelCandidateStart(text) {
|
|
96444
|
+
const lt = text.lastIndexOf("<");
|
|
96445
|
+
if (lt === -1)
|
|
96446
|
+
return null;
|
|
96447
|
+
return isDsmlFunctionCallSentinelPrefix(text.slice(lt)) ? lt : null;
|
|
96448
|
+
}
|
|
96449
|
+
function findBufferedTextFlushBoundary(text) {
|
|
96450
|
+
const sentinelStart = findTrailingDsmlSentinelCandidateStart(text);
|
|
96451
|
+
if (sentinelStart === null)
|
|
96452
|
+
return text.length;
|
|
96453
|
+
return text.slice(0, sentinelStart).trimEnd().length;
|
|
96454
|
+
}
|
|
96455
|
+
function findDsmlFunctionCallSentinel(text) {
|
|
96456
|
+
const re = /<\s*[||]\s*DSML\s*[||]\s*function_calls\b/;
|
|
96457
|
+
const match = re.exec(text);
|
|
96458
|
+
if (!match || match.index === undefined)
|
|
96459
|
+
return null;
|
|
96460
|
+
return { start: match.index, end: match.index + match[0].length };
|
|
96461
|
+
}
|
|
96436
96462
|
async function* openaiStreamToAnthropic(response, model) {
|
|
96437
96463
|
const messageId = makeMessageId2();
|
|
96438
96464
|
let contentBlockIndex = 0;
|
|
@@ -96443,6 +96469,50 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
96443
96469
|
let lastStopReason = null;
|
|
96444
96470
|
let hasEmittedFinalUsage = false;
|
|
96445
96471
|
let hasProcessedFinishReason = false;
|
|
96472
|
+
let pendingTextBuffer = "";
|
|
96473
|
+
const emitBufferedText = (mode) => {
|
|
96474
|
+
const events = [];
|
|
96475
|
+
if (!pendingTextBuffer)
|
|
96476
|
+
return events;
|
|
96477
|
+
const sentinel = findDsmlFunctionCallSentinel(pendingTextBuffer);
|
|
96478
|
+
if (sentinel) {
|
|
96479
|
+
const visible2 = pendingTextBuffer.slice(0, sentinel.start).trimEnd();
|
|
96480
|
+
pendingTextBuffer = pendingTextBuffer.slice(sentinel.end);
|
|
96481
|
+
if (visible2) {
|
|
96482
|
+
events.push(...emitTextDeltaEvents(visible2));
|
|
96483
|
+
}
|
|
96484
|
+
if (pendingTextBuffer) {
|
|
96485
|
+
events.push(...emitBufferedText(mode));
|
|
96486
|
+
}
|
|
96487
|
+
return events;
|
|
96488
|
+
}
|
|
96489
|
+
const emitUntil = mode === "final" ? pendingTextBuffer.length : mode === "before_tool_call" ? findTrailingDsmlSentinelCandidateStart(pendingTextBuffer) ?? pendingTextBuffer.length : findBufferedTextFlushBoundary(pendingTextBuffer);
|
|
96490
|
+
if (emitUntil <= 0)
|
|
96491
|
+
return events;
|
|
96492
|
+
const visible = pendingTextBuffer.slice(0, emitUntil);
|
|
96493
|
+
pendingTextBuffer = pendingTextBuffer.slice(emitUntil);
|
|
96494
|
+
if (visible) {
|
|
96495
|
+
events.push(...emitTextDeltaEvents(visible));
|
|
96496
|
+
}
|
|
96497
|
+
return events;
|
|
96498
|
+
};
|
|
96499
|
+
const emitTextDeltaEvents = (text) => {
|
|
96500
|
+
const events = [];
|
|
96501
|
+
if (!hasEmittedContentStart) {
|
|
96502
|
+
events.push({
|
|
96503
|
+
type: "content_block_start",
|
|
96504
|
+
index: contentBlockIndex,
|
|
96505
|
+
content_block: { type: "text", text: "" }
|
|
96506
|
+
});
|
|
96507
|
+
hasEmittedContentStart = true;
|
|
96508
|
+
}
|
|
96509
|
+
events.push({
|
|
96510
|
+
type: "content_block_delta",
|
|
96511
|
+
index: contentBlockIndex,
|
|
96512
|
+
delta: { type: "text_delta", text }
|
|
96513
|
+
});
|
|
96514
|
+
return events;
|
|
96515
|
+
};
|
|
96446
96516
|
yield {
|
|
96447
96517
|
type: "message_start",
|
|
96448
96518
|
message: {
|
|
@@ -96550,21 +96620,13 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
96550
96620
|
hasClosedReasoning = true;
|
|
96551
96621
|
}
|
|
96552
96622
|
if (delta.content != null) {
|
|
96553
|
-
|
|
96554
|
-
|
|
96555
|
-
|
|
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
|
-
};
|
|
96623
|
+
pendingTextBuffer += delta.content;
|
|
96624
|
+
for (const event of emitBufferedText("streaming"))
|
|
96625
|
+
yield event;
|
|
96566
96626
|
}
|
|
96567
96627
|
if (delta.tool_calls) {
|
|
96628
|
+
for (const event of emitBufferedText("before_tool_call"))
|
|
96629
|
+
yield event;
|
|
96568
96630
|
for (const tc of delta.tool_calls) {
|
|
96569
96631
|
if (tc.id && tc.function?.name) {
|
|
96570
96632
|
if (hasEmittedContentStart) {
|
|
@@ -96631,6 +96693,8 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
96631
96693
|
};
|
|
96632
96694
|
hasClosedReasoning = true;
|
|
96633
96695
|
}
|
|
96696
|
+
for (const event of emitBufferedText("final"))
|
|
96697
|
+
yield event;
|
|
96634
96698
|
if (hasEmittedContentStart) {
|
|
96635
96699
|
yield {
|
|
96636
96700
|
type: "content_block_stop",
|
|
@@ -97003,7 +97067,7 @@ function createOpenAIShimClient(options) {
|
|
|
97003
97067
|
messages: beta.messages
|
|
97004
97068
|
};
|
|
97005
97069
|
}
|
|
97006
|
-
var GITHUB_MODELS_DEFAULT_BASE = "https://models.github.ai/inference", GITHUB_API_VERSION = "2022-11-28", GITHUB_429_MAX_RETRIES = 3, GITHUB_429_BASE_DELAY_SEC = 1, GITHUB_429_MAX_DELAY_SEC = 32, OpenAIShimStream;
|
|
97070
|
+
var GITHUB_MODELS_DEFAULT_BASE = "https://models.github.ai/inference", GITHUB_API_VERSION = "2022-11-28", GITHUB_429_MAX_RETRIES = 3, GITHUB_429_BASE_DELAY_SEC = 1, GITHUB_429_MAX_DELAY_SEC = 32, DSML_FUNCTION_CALL_SENTINEL = "<|DSML|function_calls", OpenAIShimStream;
|
|
97007
97071
|
var init_shim2 = __esm(() => {
|
|
97008
97072
|
init_sdk();
|
|
97009
97073
|
init_envUtils();
|
|
@@ -282588,7 +282652,7 @@ function getAnthropicEnvMetadata() {
|
|
|
282588
282652
|
function getBuildAgeMinutes() {
|
|
282589
282653
|
if (false)
|
|
282590
282654
|
;
|
|
282591
|
-
const buildTime = new Date("2026-06-
|
|
282655
|
+
const buildTime = new Date("2026-06-23T14:32:49.206Z").getTime();
|
|
282592
282656
|
if (isNaN(buildTime))
|
|
282593
282657
|
return;
|
|
282594
282658
|
return Math.floor((Date.now() - buildTime) / 60000);
|
|
@@ -335938,4 +336002,4 @@ export {
|
|
|
335938
336002
|
AbortError2 as AbortError
|
|
335939
336003
|
};
|
|
335940
336004
|
|
|
335941
|
-
//# debugId=
|
|
336005
|
+
//# debugId=F1D1A50370F2E48F64756E2164756E21
|
package/dist/sdk.js
CHANGED
|
@@ -96433,6 +96433,32 @@ function buildOpenAIRequestBody(params, ctx) {
|
|
|
96433
96433
|
}
|
|
96434
96434
|
return body;
|
|
96435
96435
|
}
|
|
96436
|
+
function normalizeDsmlSentinelPrefix(value) {
|
|
96437
|
+
return value.replace(/|/g, "|").replace(/\s+/g, "");
|
|
96438
|
+
}
|
|
96439
|
+
function isDsmlFunctionCallSentinelPrefix(value) {
|
|
96440
|
+
const normalized = normalizeDsmlSentinelPrefix(value);
|
|
96441
|
+
return normalized.length > 0 && DSML_FUNCTION_CALL_SENTINEL.startsWith(normalized);
|
|
96442
|
+
}
|
|
96443
|
+
function findTrailingDsmlSentinelCandidateStart(text) {
|
|
96444
|
+
const lt = text.lastIndexOf("<");
|
|
96445
|
+
if (lt === -1)
|
|
96446
|
+
return null;
|
|
96447
|
+
return isDsmlFunctionCallSentinelPrefix(text.slice(lt)) ? lt : null;
|
|
96448
|
+
}
|
|
96449
|
+
function findBufferedTextFlushBoundary(text) {
|
|
96450
|
+
const sentinelStart = findTrailingDsmlSentinelCandidateStart(text);
|
|
96451
|
+
if (sentinelStart === null)
|
|
96452
|
+
return text.length;
|
|
96453
|
+
return text.slice(0, sentinelStart).trimEnd().length;
|
|
96454
|
+
}
|
|
96455
|
+
function findDsmlFunctionCallSentinel(text) {
|
|
96456
|
+
const re = /<\s*[||]\s*DSML\s*[||]\s*function_calls\b/;
|
|
96457
|
+
const match = re.exec(text);
|
|
96458
|
+
if (!match || match.index === undefined)
|
|
96459
|
+
return null;
|
|
96460
|
+
return { start: match.index, end: match.index + match[0].length };
|
|
96461
|
+
}
|
|
96436
96462
|
async function* openaiStreamToAnthropic(response, model) {
|
|
96437
96463
|
const messageId = makeMessageId2();
|
|
96438
96464
|
let contentBlockIndex = 0;
|
|
@@ -96443,6 +96469,50 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
96443
96469
|
let lastStopReason = null;
|
|
96444
96470
|
let hasEmittedFinalUsage = false;
|
|
96445
96471
|
let hasProcessedFinishReason = false;
|
|
96472
|
+
let pendingTextBuffer = "";
|
|
96473
|
+
const emitBufferedText = (mode) => {
|
|
96474
|
+
const events = [];
|
|
96475
|
+
if (!pendingTextBuffer)
|
|
96476
|
+
return events;
|
|
96477
|
+
const sentinel = findDsmlFunctionCallSentinel(pendingTextBuffer);
|
|
96478
|
+
if (sentinel) {
|
|
96479
|
+
const visible2 = pendingTextBuffer.slice(0, sentinel.start).trimEnd();
|
|
96480
|
+
pendingTextBuffer = pendingTextBuffer.slice(sentinel.end);
|
|
96481
|
+
if (visible2) {
|
|
96482
|
+
events.push(...emitTextDeltaEvents(visible2));
|
|
96483
|
+
}
|
|
96484
|
+
if (pendingTextBuffer) {
|
|
96485
|
+
events.push(...emitBufferedText(mode));
|
|
96486
|
+
}
|
|
96487
|
+
return events;
|
|
96488
|
+
}
|
|
96489
|
+
const emitUntil = mode === "final" ? pendingTextBuffer.length : mode === "before_tool_call" ? findTrailingDsmlSentinelCandidateStart(pendingTextBuffer) ?? pendingTextBuffer.length : findBufferedTextFlushBoundary(pendingTextBuffer);
|
|
96490
|
+
if (emitUntil <= 0)
|
|
96491
|
+
return events;
|
|
96492
|
+
const visible = pendingTextBuffer.slice(0, emitUntil);
|
|
96493
|
+
pendingTextBuffer = pendingTextBuffer.slice(emitUntil);
|
|
96494
|
+
if (visible) {
|
|
96495
|
+
events.push(...emitTextDeltaEvents(visible));
|
|
96496
|
+
}
|
|
96497
|
+
return events;
|
|
96498
|
+
};
|
|
96499
|
+
const emitTextDeltaEvents = (text) => {
|
|
96500
|
+
const events = [];
|
|
96501
|
+
if (!hasEmittedContentStart) {
|
|
96502
|
+
events.push({
|
|
96503
|
+
type: "content_block_start",
|
|
96504
|
+
index: contentBlockIndex,
|
|
96505
|
+
content_block: { type: "text", text: "" }
|
|
96506
|
+
});
|
|
96507
|
+
hasEmittedContentStart = true;
|
|
96508
|
+
}
|
|
96509
|
+
events.push({
|
|
96510
|
+
type: "content_block_delta",
|
|
96511
|
+
index: contentBlockIndex,
|
|
96512
|
+
delta: { type: "text_delta", text }
|
|
96513
|
+
});
|
|
96514
|
+
return events;
|
|
96515
|
+
};
|
|
96446
96516
|
yield {
|
|
96447
96517
|
type: "message_start",
|
|
96448
96518
|
message: {
|
|
@@ -96550,21 +96620,13 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
96550
96620
|
hasClosedReasoning = true;
|
|
96551
96621
|
}
|
|
96552
96622
|
if (delta.content != null) {
|
|
96553
|
-
|
|
96554
|
-
|
|
96555
|
-
|
|
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
|
-
};
|
|
96623
|
+
pendingTextBuffer += delta.content;
|
|
96624
|
+
for (const event of emitBufferedText("streaming"))
|
|
96625
|
+
yield event;
|
|
96566
96626
|
}
|
|
96567
96627
|
if (delta.tool_calls) {
|
|
96628
|
+
for (const event of emitBufferedText("before_tool_call"))
|
|
96629
|
+
yield event;
|
|
96568
96630
|
for (const tc of delta.tool_calls) {
|
|
96569
96631
|
if (tc.id && tc.function?.name) {
|
|
96570
96632
|
if (hasEmittedContentStart) {
|
|
@@ -96631,6 +96693,8 @@ async function* openaiStreamToAnthropic(response, model) {
|
|
|
96631
96693
|
};
|
|
96632
96694
|
hasClosedReasoning = true;
|
|
96633
96695
|
}
|
|
96696
|
+
for (const event of emitBufferedText("final"))
|
|
96697
|
+
yield event;
|
|
96634
96698
|
if (hasEmittedContentStart) {
|
|
96635
96699
|
yield {
|
|
96636
96700
|
type: "content_block_stop",
|
|
@@ -97003,7 +97067,7 @@ function createOpenAIShimClient(options) {
|
|
|
97003
97067
|
messages: beta.messages
|
|
97004
97068
|
};
|
|
97005
97069
|
}
|
|
97006
|
-
var GITHUB_MODELS_DEFAULT_BASE = "https://models.github.ai/inference", GITHUB_API_VERSION = "2022-11-28", GITHUB_429_MAX_RETRIES = 3, GITHUB_429_BASE_DELAY_SEC = 1, GITHUB_429_MAX_DELAY_SEC = 32, OpenAIShimStream;
|
|
97070
|
+
var GITHUB_MODELS_DEFAULT_BASE = "https://models.github.ai/inference", GITHUB_API_VERSION = "2022-11-28", GITHUB_429_MAX_RETRIES = 3, GITHUB_429_BASE_DELAY_SEC = 1, GITHUB_429_MAX_DELAY_SEC = 32, DSML_FUNCTION_CALL_SENTINEL = "<|DSML|function_calls", OpenAIShimStream;
|
|
97007
97071
|
var init_shim2 = __esm(() => {
|
|
97008
97072
|
init_sdk();
|
|
97009
97073
|
init_envUtils();
|
|
@@ -282588,7 +282652,7 @@ function getAnthropicEnvMetadata() {
|
|
|
282588
282652
|
function getBuildAgeMinutes() {
|
|
282589
282653
|
if (false)
|
|
282590
282654
|
;
|
|
282591
|
-
const buildTime = new Date("2026-06-
|
|
282655
|
+
const buildTime = new Date("2026-06-23T14:32:49.206Z").getTime();
|
|
282592
282656
|
if (isNaN(buildTime))
|
|
282593
282657
|
return;
|
|
282594
282658
|
return Math.floor((Date.now() - buildTime) / 60000);
|
|
@@ -335938,4 +336002,4 @@ export {
|
|
|
335938
336002
|
AbortError2 as AbortError
|
|
335939
336003
|
};
|
|
335940
336004
|
|
|
335941
|
-
//# debugId=
|
|
336005
|
+
//# debugId=432C8411F9337F1F64756E2164756E21
|