@vibes.diy/vibe-runtime 14.3.355 → 14.3.356
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/backend-tools.d.ts +1 -0
- package/firefly-files-read.js +18 -2
- package/firefly-files-write.d.ts +1 -0
- package/firefly-files-write.js +21 -1
- package/package.json +4 -4
- package/parse-backend-config.js +16 -3
package/backend-tools.d.ts
CHANGED
package/firefly-files-read.js
CHANGED
|
@@ -55,11 +55,27 @@ export function decorateFiles(doc, fetcher = defaultFetcher, local) {
|
|
|
55
55
|
}
|
|
56
56
|
return { ...doc, _files: next };
|
|
57
57
|
}
|
|
58
|
+
const READ_RETRY_DELAYS_MS = [250, 750];
|
|
59
|
+
async function fetchWithRetry(fetcher, url) {
|
|
60
|
+
for (let attempt = 0;; attempt++) {
|
|
61
|
+
const last = attempt >= READ_RETRY_DELAYS_MS.length;
|
|
62
|
+
const r = await fetcher(url, { credentials: "include" }).then((res) => ({ res }), (err) => ({ err }));
|
|
63
|
+
if ("res" in r && (r.res.status < 500 || last))
|
|
64
|
+
return r.res;
|
|
65
|
+
if ("err" in r && last)
|
|
66
|
+
throw r.err;
|
|
67
|
+
await new Promise((resolve) => setTimeout(resolve, READ_RETRY_DELAYS_MS[attempt]));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
58
70
|
async function fetchAsFile(fetcher, url, name, type, lastModified) {
|
|
59
|
-
const r = await fetcher
|
|
71
|
+
const r = await fetchWithRetry(fetcher, url);
|
|
60
72
|
if (!r.ok) {
|
|
61
73
|
throw new Error(`fetch _files ${url}: ${r.status} ${r.statusText}`);
|
|
62
74
|
}
|
|
63
75
|
const blob = await r.blob();
|
|
64
|
-
return new File([blob], name, { type, lastModified });
|
|
76
|
+
return new File([blob], name, { type: servedType(type, blob.type), lastModified });
|
|
77
|
+
}
|
|
78
|
+
function servedType(stored, served) {
|
|
79
|
+
const s = served.split(";")[0].trim().toLowerCase();
|
|
80
|
+
return s.startsWith("image/") && s !== stored.split(";")[0].trim().toLowerCase() ? s : stored;
|
|
65
81
|
}
|
package/firefly-files-write.d.ts
CHANGED
|
@@ -18,4 +18,5 @@ export interface UploadFilesOpts {
|
|
|
18
18
|
readonly concurrency?: number;
|
|
19
19
|
}
|
|
20
20
|
export declare function stripLocalFileUrls<T>(doc: T, assetOrigin: string | undefined): T;
|
|
21
|
+
export declare function relabelImage(entry: File | Blob): Promise<File | Blob>;
|
|
21
22
|
export declare function uploadFiles<T>(doc: T, uploader: AssetUploader, opts?: UploadFilesOpts): Promise<T>;
|
package/firefly-files-write.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ASSET_MAGIC, headMatchesMagic } from "@vibes.diy/api-types/asset-magic";
|
|
1
2
|
import { noteOwnUpload } from "./own-uploads.js";
|
|
2
3
|
const DEFAULT_CONCURRENCY = 3;
|
|
3
4
|
function stripFileAccessors(entry) {
|
|
@@ -40,6 +41,24 @@ export function stripLocalFileUrls(doc, assetOrigin) {
|
|
|
40
41
|
}
|
|
41
42
|
return changed ? { ...doc, _files: next } : doc;
|
|
42
43
|
}
|
|
44
|
+
function sniffImage(head) {
|
|
45
|
+
for (const [mime, magic] of ASSET_MAGIC) {
|
|
46
|
+
if (mime.startsWith("image/") && headMatchesMagic(head, magic))
|
|
47
|
+
return mime;
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
export async function relabelImage(entry) {
|
|
52
|
+
const declared = entry.type.split(";")[0].trim().toLowerCase();
|
|
53
|
+
if (!declared.startsWith("image/"))
|
|
54
|
+
return entry;
|
|
55
|
+
const sniffed = sniffImage(new Uint8Array(await entry.slice(0, 16).arrayBuffer()));
|
|
56
|
+
if (sniffed === undefined || sniffed === declared)
|
|
57
|
+
return entry;
|
|
58
|
+
return entry instanceof File
|
|
59
|
+
? new File([entry], entry.name, { type: sniffed, lastModified: entry.lastModified })
|
|
60
|
+
: new Blob([entry], { type: sniffed });
|
|
61
|
+
}
|
|
43
62
|
export async function uploadFiles(doc, uploader, opts = {}) {
|
|
44
63
|
const files = doc?._files;
|
|
45
64
|
if (!files || typeof files !== "object")
|
|
@@ -66,7 +85,8 @@ export async function uploadFiles(doc, uploader, opts = {}) {
|
|
|
66
85
|
const idx = cursor++;
|
|
67
86
|
if (idx >= pending.length)
|
|
68
87
|
return;
|
|
69
|
-
const { key
|
|
88
|
+
const { key } = pending[idx];
|
|
89
|
+
const entry = await relabelImage(pending[idx].entry);
|
|
70
90
|
const r = await uploader.putAsset(entry, entry.type || undefined);
|
|
71
91
|
if (r.isErr()) {
|
|
72
92
|
throw new Error(`uploadFiles[${key}]: ${r.Err().message ?? String(r.Err())}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibes.diy/vibe-runtime",
|
|
3
|
-
"version": "14.3.
|
|
3
|
+
"version": "14.3.356",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@adviser/cement": "~0.5.37",
|
|
39
|
-
"@vibes.diy/api-types": "14.3.
|
|
40
|
-
"@vibes.diy/base": "14.3.
|
|
41
|
-
"@vibes.diy/vibe-types": "14.3.
|
|
39
|
+
"@vibes.diy/api-types": "14.3.356",
|
|
40
|
+
"@vibes.diy/base": "14.3.356",
|
|
41
|
+
"@vibes.diy/vibe-types": "14.3.356",
|
|
42
42
|
"arktype": "~2.2.9",
|
|
43
43
|
"charwise": "~3.0.1",
|
|
44
44
|
"es-module-lexer": "~3.0.4",
|
package/parse-backend-config.js
CHANGED
|
@@ -925,9 +925,9 @@ function githubPermissionsAt(githubObj, key) {
|
|
|
925
925
|
}
|
|
926
926
|
const TOOLS_LANE = {
|
|
927
927
|
subject: "tools",
|
|
928
|
-
shadowable: ["description", "for", "input", "handler", "write", "db", "set", "key", "type", "optional", "enum"],
|
|
928
|
+
shadowable: ["description", "for", "input", "handler", "write", "offer", "db", "set", "key", "type", "optional", "enum"],
|
|
929
929
|
};
|
|
930
|
-
const TOOL_KEYS = ["description", "for", "input", "handler", "write"];
|
|
930
|
+
const TOOL_KEYS = ["description", "for", "input", "handler", "write", "offer"];
|
|
931
931
|
const TOOL_FIELD_KEYS = ["type", "description", "optional", "enum"];
|
|
932
932
|
const TOOL_WRITE_KEYS = ["db", "set", "key"];
|
|
933
933
|
const TOOLS_SHAPE = 'tools must be `export const tools = { vote: { description: "…", input: { choice: "string" }, handler(input, ctx) { … } } }` with static literals';
|
|
@@ -1226,9 +1226,18 @@ function extractTool(tools, key) {
|
|
|
1226
1226
|
errors.push(...w.errors);
|
|
1227
1227
|
run = w.value;
|
|
1228
1228
|
}
|
|
1229
|
+
let offer = false;
|
|
1230
|
+
if (keys.keys.has("offer")) {
|
|
1231
|
+
const start = keys.keys.get("offer")?.valueStart;
|
|
1232
|
+
const v = start === undefined ? undefined : literalValue(valueTextAt(tool, start));
|
|
1233
|
+
if (typeof v !== "boolean")
|
|
1234
|
+
errors.push(`${TOOLS_SHAPE} — ${where}.offer must be true or false`);
|
|
1235
|
+
else
|
|
1236
|
+
offer = v;
|
|
1237
|
+
}
|
|
1229
1238
|
if (errors.length > 0 || description === undefined || run === undefined)
|
|
1230
1239
|
return { errors };
|
|
1231
|
-
return { value: { name, description, for: audience, input, run }, errors };
|
|
1240
|
+
return { value: { name, description, for: audience, input, run, ...(offer ? { offer: true } : {}) }, errors };
|
|
1232
1241
|
}
|
|
1233
1242
|
function extractTools(src) {
|
|
1234
1243
|
if (exportsName(src.code, "tools") === false)
|
|
@@ -1258,6 +1267,10 @@ function extractTools(src) {
|
|
|
1258
1267
|
if (t.value !== undefined)
|
|
1259
1268
|
decls.push(t.value);
|
|
1260
1269
|
}
|
|
1270
|
+
const offered = decls.filter((d) => d.offer === true);
|
|
1271
|
+
if (offered.length > 1) {
|
|
1272
|
+
errors.push(`${TOOLS_SHAPE} — ${offered.map((d) => `tools.${d.name}`).join(" and ")} both say offer: true; at most one tool may be the offer, the one the agent asks about after posting this vibe's picture`);
|
|
1273
|
+
}
|
|
1261
1274
|
if (errors.length > 0)
|
|
1262
1275
|
return { errors };
|
|
1263
1276
|
return { value: decls, errors };
|