@clawos-dev/clawd 0.2.18-beta.23.1cf3327 → 0.2.18
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.cjs +36 -13
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -15963,25 +15963,48 @@ function tryParseBase64DataUrl(url) {
|
|
|
15963
15963
|
if (!m) return null;
|
|
15964
15964
|
return { mediaType: m[1], data: m[2] };
|
|
15965
15965
|
}
|
|
15966
|
+
var IMAGE_EXT_MIME = {
|
|
15967
|
+
png: "image/png",
|
|
15968
|
+
jpg: "image/jpeg",
|
|
15969
|
+
jpeg: "image/jpeg",
|
|
15970
|
+
gif: "image/gif",
|
|
15971
|
+
webp: "image/webp"
|
|
15972
|
+
};
|
|
15973
|
+
function tryParseHttpImageUrl(url) {
|
|
15974
|
+
if (!/^https?:\/\//i.test(url)) return null;
|
|
15975
|
+
const pathOnly = url.split(/[?#]/, 1)[0];
|
|
15976
|
+
const ext = pathOnly.split(".").pop()?.toLowerCase();
|
|
15977
|
+
if (!ext || !(ext in IMAGE_EXT_MIME)) return null;
|
|
15978
|
+
return { url };
|
|
15979
|
+
}
|
|
15966
15980
|
function buildStdinContent(rawText) {
|
|
15967
15981
|
const blocks = [];
|
|
15968
15982
|
let leftover = rawText;
|
|
15969
15983
|
for (const match of rawText.matchAll(ATTACHMENT_RE)) {
|
|
15970
15984
|
const [marker, kind, url] = match;
|
|
15971
15985
|
const dataUrl = tryParseBase64DataUrl(url);
|
|
15972
|
-
if (
|
|
15973
|
-
|
|
15974
|
-
|
|
15975
|
-
|
|
15976
|
-
|
|
15977
|
-
|
|
15978
|
-
|
|
15979
|
-
|
|
15980
|
-
|
|
15981
|
-
|
|
15982
|
-
|
|
15983
|
-
|
|
15984
|
-
|
|
15986
|
+
if (dataUrl) {
|
|
15987
|
+
if (kind === "image" && dataUrl.mediaType.startsWith("image/")) {
|
|
15988
|
+
blocks.push({
|
|
15989
|
+
type: "image",
|
|
15990
|
+
source: { type: "base64", media_type: dataUrl.mediaType, data: dataUrl.data }
|
|
15991
|
+
});
|
|
15992
|
+
leftover = leftover.replace(marker, "");
|
|
15993
|
+
} else if (kind === "file" && dataUrl.mediaType === "application/pdf") {
|
|
15994
|
+
blocks.push({
|
|
15995
|
+
type: "document",
|
|
15996
|
+
source: { type: "base64", media_type: "application/pdf", data: dataUrl.data }
|
|
15997
|
+
});
|
|
15998
|
+
leftover = leftover.replace(marker, "");
|
|
15999
|
+
}
|
|
16000
|
+
continue;
|
|
16001
|
+
}
|
|
16002
|
+
if (kind === "image") {
|
|
16003
|
+
const httpImg = tryParseHttpImageUrl(url);
|
|
16004
|
+
if (httpImg) {
|
|
16005
|
+
blocks.push({ type: "image", source: { type: "url", url: httpImg.url } });
|
|
16006
|
+
leftover = leftover.replace(marker, "");
|
|
16007
|
+
}
|
|
15985
16008
|
}
|
|
15986
16009
|
}
|
|
15987
16010
|
const trimmed = leftover.trim();
|
package/package.json
CHANGED