@blockrun/clawrouter 0.11.4 → 0.11.6
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/README.md +24 -0
- package/dist/cli.js +135 -39
- package/dist/cli.js.map +1 -1
- package/dist/index.js +73 -39
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/scripts/reinstall.sh +14 -12
- package/scripts/update.sh +6 -0
package/dist/index.js
CHANGED
|
@@ -5481,13 +5481,13 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5481
5481
|
const raw = modelMatch[1];
|
|
5482
5482
|
const IMAGE_MODEL_ALIASES = {
|
|
5483
5483
|
"dall-e-3": "openai/dall-e-3",
|
|
5484
|
-
|
|
5485
|
-
|
|
5484
|
+
dalle3: "openai/dall-e-3",
|
|
5485
|
+
dalle: "openai/dall-e-3",
|
|
5486
5486
|
"gpt-image": "openai/gpt-image-1",
|
|
5487
5487
|
"gpt-image-1": "openai/gpt-image-1",
|
|
5488
|
-
|
|
5488
|
+
flux: "black-forest/flux-1.1-pro",
|
|
5489
5489
|
"flux-pro": "black-forest/flux-1.1-pro",
|
|
5490
|
-
|
|
5490
|
+
banana: "google/nano-banana",
|
|
5491
5491
|
"nano-banana": "google/nano-banana",
|
|
5492
5492
|
"banana-pro": "google/nano-banana-pro",
|
|
5493
5493
|
"nano-banana-pro": "google/nano-banana-pro"
|
|
@@ -5528,32 +5528,51 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5528
5528
|
"Cache-Control": "no-cache",
|
|
5529
5529
|
Connection: "keep-alive"
|
|
5530
5530
|
});
|
|
5531
|
-
res.write(
|
|
5531
|
+
res.write(
|
|
5532
|
+
`data: ${JSON.stringify({ id: completionId, object: "chat.completion.chunk", created: timestamp, model: "clawrouter/image", choices: [{ index: 0, delta: { role: "assistant", content: errorText }, finish_reason: null }] })}
|
|
5532
5533
|
|
|
5533
|
-
`
|
|
5534
|
-
|
|
5534
|
+
`
|
|
5535
|
+
);
|
|
5536
|
+
res.write(
|
|
5537
|
+
`data: ${JSON.stringify({ id: completionId, object: "chat.completion.chunk", created: timestamp, model: "clawrouter/image", choices: [{ index: 0, delta: {}, finish_reason: "stop" }] })}
|
|
5535
5538
|
|
|
5536
|
-
`
|
|
5539
|
+
`
|
|
5540
|
+
);
|
|
5537
5541
|
res.write("data: [DONE]\n\n");
|
|
5538
5542
|
res.end();
|
|
5539
5543
|
} else {
|
|
5540
5544
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
5541
|
-
res.end(
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5545
|
+
res.end(
|
|
5546
|
+
JSON.stringify({
|
|
5547
|
+
id: completionId,
|
|
5548
|
+
object: "chat.completion",
|
|
5549
|
+
created: timestamp,
|
|
5550
|
+
model: "clawrouter/image",
|
|
5551
|
+
choices: [
|
|
5552
|
+
{
|
|
5553
|
+
index: 0,
|
|
5554
|
+
message: { role: "assistant", content: errorText },
|
|
5555
|
+
finish_reason: "stop"
|
|
5556
|
+
}
|
|
5557
|
+
],
|
|
5558
|
+
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 }
|
|
5559
|
+
})
|
|
5560
|
+
);
|
|
5549
5561
|
}
|
|
5550
5562
|
console.log(`[ClawRouter] /imagegen command \u2192 showing usage help`);
|
|
5551
5563
|
return;
|
|
5552
5564
|
}
|
|
5553
|
-
console.log(
|
|
5565
|
+
console.log(
|
|
5566
|
+
`[ClawRouter] /imagegen command \u2192 ${imageModel} (${imageSize}): ${imagePrompt.slice(0, 80)}...`
|
|
5567
|
+
);
|
|
5554
5568
|
try {
|
|
5555
5569
|
const imageUpstreamUrl = `${apiBase}/v1/images/generations`;
|
|
5556
|
-
const imageBody = JSON.stringify({
|
|
5570
|
+
const imageBody = JSON.stringify({
|
|
5571
|
+
model: imageModel,
|
|
5572
|
+
prompt: imagePrompt,
|
|
5573
|
+
size: imageSize,
|
|
5574
|
+
n: 1
|
|
5575
|
+
});
|
|
5557
5576
|
const imageResponse = await payFetch(imageUpstreamUrl, {
|
|
5558
5577
|
method: "POST",
|
|
5559
5578
|
headers: { "content-type": "application/json", "user-agent": USER_AGENT },
|
|
@@ -5578,8 +5597,12 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5578
5597
|
const hostedUrl = await uploadDataUriToHost(img.url);
|
|
5579
5598
|
lines.push(hostedUrl);
|
|
5580
5599
|
} catch (uploadErr) {
|
|
5581
|
-
console.error(
|
|
5582
|
-
|
|
5600
|
+
console.error(
|
|
5601
|
+
`[ClawRouter] /imagegen: failed to upload data URI: ${uploadErr instanceof Error ? uploadErr.message : String(uploadErr)}`
|
|
5602
|
+
);
|
|
5603
|
+
lines.push(
|
|
5604
|
+
"Image generated but upload failed. Try again or use --model dall-e-3."
|
|
5605
|
+
);
|
|
5583
5606
|
}
|
|
5584
5607
|
} else {
|
|
5585
5608
|
lines.push(img.url);
|
|
@@ -5600,33 +5623,47 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5600
5623
|
"Cache-Control": "no-cache",
|
|
5601
5624
|
Connection: "keep-alive"
|
|
5602
5625
|
});
|
|
5603
|
-
res.write(
|
|
5626
|
+
res.write(
|
|
5627
|
+
`data: ${JSON.stringify({ id: completionId, object: "chat.completion.chunk", created: timestamp, model: "clawrouter/image", choices: [{ index: 0, delta: { role: "assistant", content: responseText }, finish_reason: null }] })}
|
|
5604
5628
|
|
|
5605
|
-
`
|
|
5606
|
-
|
|
5629
|
+
`
|
|
5630
|
+
);
|
|
5631
|
+
res.write(
|
|
5632
|
+
`data: ${JSON.stringify({ id: completionId, object: "chat.completion.chunk", created: timestamp, model: "clawrouter/image", choices: [{ index: 0, delta: {}, finish_reason: "stop" }] })}
|
|
5607
5633
|
|
|
5608
|
-
`
|
|
5634
|
+
`
|
|
5635
|
+
);
|
|
5609
5636
|
res.write("data: [DONE]\n\n");
|
|
5610
5637
|
res.end();
|
|
5611
5638
|
} else {
|
|
5612
5639
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
5613
|
-
res.end(
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5640
|
+
res.end(
|
|
5641
|
+
JSON.stringify({
|
|
5642
|
+
id: completionId,
|
|
5643
|
+
object: "chat.completion",
|
|
5644
|
+
created: timestamp,
|
|
5645
|
+
model: "clawrouter/image",
|
|
5646
|
+
choices: [
|
|
5647
|
+
{
|
|
5648
|
+
index: 0,
|
|
5649
|
+
message: { role: "assistant", content: responseText },
|
|
5650
|
+
finish_reason: "stop"
|
|
5651
|
+
}
|
|
5652
|
+
],
|
|
5653
|
+
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 }
|
|
5654
|
+
})
|
|
5655
|
+
);
|
|
5621
5656
|
}
|
|
5622
5657
|
} catch (err) {
|
|
5623
5658
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
5624
5659
|
console.error(`[ClawRouter] /imagegen error: ${errMsg}`);
|
|
5625
5660
|
if (!res.headersSent) {
|
|
5626
5661
|
res.writeHead(500, { "Content-Type": "application/json" });
|
|
5627
|
-
res.end(
|
|
5628
|
-
|
|
5629
|
-
|
|
5662
|
+
res.end(
|
|
5663
|
+
JSON.stringify({
|
|
5664
|
+
error: { message: `Image generation failed: ${errMsg}`, type: "image_error" }
|
|
5665
|
+
})
|
|
5666
|
+
);
|
|
5630
5667
|
}
|
|
5631
5668
|
}
|
|
5632
5669
|
return;
|
|
@@ -5735,10 +5772,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5735
5772
|
const lastAssistantMsg = [...parsedMessages].reverse().find((m) => m.role === "assistant");
|
|
5736
5773
|
const toolCallNames = Array.isArray(lastAssistantMsg?.tool_calls) ? lastAssistantMsg.tool_calls.map((tc) => tc.function?.name).filter(Boolean) : void 0;
|
|
5737
5774
|
const contentHash = hashRequestContent(prompt, toolCallNames);
|
|
5738
|
-
const shouldEscalate = sessionStore.recordRequestHash(
|
|
5739
|
-
effectiveSessionId,
|
|
5740
|
-
contentHash
|
|
5741
|
-
);
|
|
5775
|
+
const shouldEscalate = sessionStore.recordRequestHash(effectiveSessionId, contentHash);
|
|
5742
5776
|
if (shouldEscalate) {
|
|
5743
5777
|
const activeTierConfigs = (() => {
|
|
5744
5778
|
if (routingDecision.reasoning?.includes("agentic") && routerOpts.config.agenticTiers) {
|