mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
"use strict";
|
|
|
|
/* Reports exactly what crossed the boundary — the differential harness
|
|
* byte-compares this against Node running the same code natively. */
|
|
function generate(options) {
|
|
const parts = [];
|
|
parts.push("model=" + options.model);
|
|
if (options.headers) {
|
|
parts.push("ct=" + options.headers["content-type"]);
|
|
parts.push("xt=" + options.headers["x-title"]);
|
|
}
|
|
if ("payload" in options) {
|
|
if (options.payload instanceof Uint8Array) {
|
|
parts.push("payload=u8[" + options.payload.length + "]:" + options.payload[0] + "," + options.payload[1]);
|
|
} else {
|
|
parts.push("payload=str:" + options.payload);
|
|
}
|
|
}
|
|
if ("source" in options) {
|
|
if (options.source instanceof Uint8Array) {
|
|
parts.push("source=u8[" + options.source.length + "]");
|
|
} else if (options.source instanceof URL) {
|
|
parts.push("source=url:" + options.source.href + " proto=" + options.source.protocol + " path=" + options.source.pathname + " str=" + String(options.source));
|
|
} else {
|
|
parts.push("source=?");
|
|
}
|
|
}
|
|
if ("tag" in options) {
|
|
parts.push("tag=" + typeof options.tag + ":" + String(options.tag));
|
|
}
|
|
const wantFiles = options.prompt !== "nofiles";
|
|
return {
|
|
text: parts.join(" "),
|
|
count: parts.length,
|
|
files: wantFiles
|
|
? [
|
|
{ mediaType: "audio/mp3", size: 3 },
|
|
{ mediaType: "image/png", size: 7 },
|
|
{ mediaType: "image/webp", size: 9 },
|
|
]
|
|
: undefined,
|
|
headers: wantFiles ? { "x-id": "resp-42", kind: "gen" } : undefined,
|
|
};
|
|
}
|
|
|
|
module.exports = { generate };
|