vibes-diy 14.3.369 → 14.3.370
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.
|
@@ -172637,6 +172637,129 @@ var init_use_picture_src = __esm({
|
|
|
172637
172637
|
}
|
|
172638
172638
|
});
|
|
172639
172639
|
|
|
172640
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/base/components/story-share.ts
|
|
172641
|
+
function storyLinkFor(link3, loc) {
|
|
172642
|
+
if (link3 !== void 0 && link3 !== "") return link3;
|
|
172643
|
+
if (loc === void 0) return "";
|
|
172644
|
+
return publicVibeBase(loc.host) ?? loc.origin;
|
|
172645
|
+
}
|
|
172646
|
+
function printedLink(link3) {
|
|
172647
|
+
return link3.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
172648
|
+
}
|
|
172649
|
+
function fitPicture(w3, h5) {
|
|
172650
|
+
const maxW = STORY_WIDTH - 120;
|
|
172651
|
+
const maxH = STORY_HEIGHT - 520;
|
|
172652
|
+
const scale = Math.min(maxW / w3, maxH / h5);
|
|
172653
|
+
const dw = Math.round(w3 * scale);
|
|
172654
|
+
const dh = Math.round(h5 * scale);
|
|
172655
|
+
return { x: Math.round((STORY_WIDTH - dw) / 2), y: Math.round(200 + (maxH - dh) / 2), w: dw, h: dh };
|
|
172656
|
+
}
|
|
172657
|
+
function storyShareSupported(nav = typeof navigator === "undefined" ? void 0 : navigator) {
|
|
172658
|
+
if (nav === void 0 || typeof nav.canShare !== "function" || typeof nav.share !== "function") return false;
|
|
172659
|
+
if (typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches === false) return false;
|
|
172660
|
+
try {
|
|
172661
|
+
return nav.canShare({ files: [new File([new Uint8Array(1)], "story.jpg", { type: "image/jpeg" })] });
|
|
172662
|
+
} catch {
|
|
172663
|
+
return false;
|
|
172664
|
+
}
|
|
172665
|
+
}
|
|
172666
|
+
function roundedRect(ctx, x3, y3, w3, h5, r2) {
|
|
172667
|
+
ctx.beginPath();
|
|
172668
|
+
ctx.moveTo(x3 + r2, y3);
|
|
172669
|
+
ctx.arcTo(x3 + w3, y3, x3 + w3, y3 + h5, r2);
|
|
172670
|
+
ctx.arcTo(x3 + w3, y3 + h5, x3, y3 + h5, r2);
|
|
172671
|
+
ctx.arcTo(x3, y3 + h5, x3, y3, r2);
|
|
172672
|
+
ctx.arcTo(x3, y3, x3 + w3, y3, r2);
|
|
172673
|
+
ctx.closePath();
|
|
172674
|
+
}
|
|
172675
|
+
async function buildStoryFile(src2, link3) {
|
|
172676
|
+
const res = await fetch(src2, { credentials: "include" });
|
|
172677
|
+
if (!res.ok) return void 0;
|
|
172678
|
+
const bmp = await createImageBitmap(await res.blob());
|
|
172679
|
+
const canvas = document.createElement("canvas");
|
|
172680
|
+
canvas.width = STORY_WIDTH;
|
|
172681
|
+
canvas.height = STORY_HEIGHT;
|
|
172682
|
+
const ctx = canvas.getContext("2d");
|
|
172683
|
+
if (ctx === null) return void 0;
|
|
172684
|
+
const cover = Math.max(STORY_WIDTH / bmp.width, STORY_HEIGHT / bmp.height);
|
|
172685
|
+
const cw = bmp.width * cover;
|
|
172686
|
+
const ch = bmp.height * cover;
|
|
172687
|
+
ctx.fillStyle = "#111";
|
|
172688
|
+
ctx.fillRect(0, 0, STORY_WIDTH, STORY_HEIGHT);
|
|
172689
|
+
ctx.filter = "blur(48px) brightness(0.55)";
|
|
172690
|
+
ctx.drawImage(bmp, (STORY_WIDTH - cw) / 2 - 60, (STORY_HEIGHT - ch) / 2 - 60, cw + 120, ch + 120);
|
|
172691
|
+
ctx.filter = "none";
|
|
172692
|
+
ctx.fillStyle = "rgba(0,0,0,0.25)";
|
|
172693
|
+
ctx.fillRect(0, 0, STORY_WIDTH, STORY_HEIGHT);
|
|
172694
|
+
const box = fitPicture(bmp.width, bmp.height);
|
|
172695
|
+
ctx.save();
|
|
172696
|
+
ctx.shadowColor = "rgba(0,0,0,0.45)";
|
|
172697
|
+
ctx.shadowBlur = 48;
|
|
172698
|
+
ctx.shadowOffsetY = 16;
|
|
172699
|
+
roundedRect(ctx, box.x, box.y, box.w, box.h, 36);
|
|
172700
|
+
ctx.fillStyle = "#000";
|
|
172701
|
+
ctx.fill();
|
|
172702
|
+
ctx.restore();
|
|
172703
|
+
ctx.save();
|
|
172704
|
+
roundedRect(ctx, box.x, box.y, box.w, box.h, 36);
|
|
172705
|
+
ctx.clip();
|
|
172706
|
+
ctx.drawImage(bmp, box.x, box.y, box.w, box.h);
|
|
172707
|
+
ctx.restore();
|
|
172708
|
+
bmp.close();
|
|
172709
|
+
const text3 = printedLink(link3);
|
|
172710
|
+
if (text3 !== "") {
|
|
172711
|
+
let size = 44;
|
|
172712
|
+
const font = /* @__PURE__ */ __name((px2) => `600 ${px2}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`, "font");
|
|
172713
|
+
ctx.font = font(size);
|
|
172714
|
+
while (ctx.measureText(text3).width > STORY_WIDTH - 200 && size > 22) {
|
|
172715
|
+
size -= 2;
|
|
172716
|
+
ctx.font = font(size);
|
|
172717
|
+
}
|
|
172718
|
+
const tw = ctx.measureText(text3).width;
|
|
172719
|
+
const ph = size + 44;
|
|
172720
|
+
const pw = tw + 80;
|
|
172721
|
+
const py = Math.min(STORY_HEIGHT - 220, box.y + box.h + 70);
|
|
172722
|
+
roundedRect(ctx, (STORY_WIDTH - pw) / 2, py, pw, ph, ph / 2);
|
|
172723
|
+
ctx.fillStyle = "rgba(255,255,255,0.92)";
|
|
172724
|
+
ctx.fill();
|
|
172725
|
+
ctx.fillStyle = "#111";
|
|
172726
|
+
ctx.textAlign = "center";
|
|
172727
|
+
ctx.textBaseline = "middle";
|
|
172728
|
+
ctx.fillText(text3, STORY_WIDTH / 2, py + ph / 2 + 1);
|
|
172729
|
+
}
|
|
172730
|
+
const blob2 = await new Promise((resolve3) => canvas.toBlob(resolve3, "image/jpeg", 0.9));
|
|
172731
|
+
if (blob2 === null) return void 0;
|
|
172732
|
+
return new File([blob2], "story.jpg", { type: "image/jpeg" });
|
|
172733
|
+
}
|
|
172734
|
+
async function shareStory(file2, link3, nav = navigator) {
|
|
172735
|
+
if (link3 !== "") nav.clipboard?.writeText(link3).catch(() => void 0);
|
|
172736
|
+
try {
|
|
172737
|
+
await nav.share({ files: [file2] });
|
|
172738
|
+
return "shared";
|
|
172739
|
+
} catch (err) {
|
|
172740
|
+
return err?.name === "AbortError" ? "cancelled" : "failed";
|
|
172741
|
+
}
|
|
172742
|
+
}
|
|
172743
|
+
var STORY_WIDTH, STORY_HEIGHT;
|
|
172744
|
+
var init_story_share = __esm({
|
|
172745
|
+
"../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/base/components/story-share.ts"() {
|
|
172746
|
+
"use strict";
|
|
172747
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
172748
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
172749
|
+
init_performance2();
|
|
172750
|
+
init_runtime2();
|
|
172751
|
+
STORY_WIDTH = 1080;
|
|
172752
|
+
STORY_HEIGHT = 1920;
|
|
172753
|
+
__name(storyLinkFor, "storyLinkFor");
|
|
172754
|
+
__name(printedLink, "printedLink");
|
|
172755
|
+
__name(fitPicture, "fitPicture");
|
|
172756
|
+
__name(storyShareSupported, "storyShareSupported");
|
|
172757
|
+
__name(roundedRect, "roundedRect");
|
|
172758
|
+
__name(buildStoryFile, "buildStoryFile");
|
|
172759
|
+
__name(shareStory, "shareStory");
|
|
172760
|
+
}
|
|
172761
|
+
});
|
|
172762
|
+
|
|
172640
172763
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/base/components/ImgGen.tsx
|
|
172641
172764
|
function promptToId(prompt) {
|
|
172642
172765
|
let hash2 = 2166136261;
|
|
@@ -172655,6 +172778,8 @@ function ImgGen({
|
|
|
172655
172778
|
alt,
|
|
172656
172779
|
style,
|
|
172657
172780
|
showControls = true,
|
|
172781
|
+
shareToStory = false,
|
|
172782
|
+
storyLink,
|
|
172658
172783
|
model,
|
|
172659
172784
|
imgGen: imgGen2,
|
|
172660
172785
|
useFireproof: useFireproof2,
|
|
@@ -172842,7 +172967,7 @@ function ImgGen({
|
|
|
172842
172967
|
},
|
|
172843
172968
|
"Error: ",
|
|
172844
172969
|
error64.message
|
|
172845
|
-
), needsTap === true && /* @__PURE__ */ import_react4.default.createElement("div", { style: { position: "absolute", top: 8, left: 8, zIndex: 11 } }, playgroundButton), showControls && /* @__PURE__ */ import_react4.default.createElement(
|
|
172970
|
+
), needsTap === true && /* @__PURE__ */ import_react4.default.createElement("div", { style: { position: "absolute", top: 8, left: 8, zIndex: 11 } }, playgroundButton), shareToStory && inCapture === false && previewUrl === void 0 && picture.src !== void 0 && /* @__PURE__ */ import_react4.default.createElement(StoryButton, { src: picture.src, link: storyLink }), showControls && /* @__PURE__ */ import_react4.default.createElement(
|
|
172846
172971
|
"div",
|
|
172847
172972
|
{
|
|
172848
172973
|
style: {
|
|
@@ -172858,7 +172983,85 @@ function ImgGen({
|
|
|
172858
172983
|
inCapture === false && /* @__PURE__ */ import_react4.default.createElement("button", { onClick: handleTapGeneration, disabled: loading, style: btnStyle, title: "Regenerate" }, "\u21BB")
|
|
172859
172984
|
));
|
|
172860
172985
|
}
|
|
172861
|
-
|
|
172986
|
+
function StoryButton({ src: src2, link: link3 }) {
|
|
172987
|
+
const [supported] = (0, import_react4.useState)(() => storyShareSupported());
|
|
172988
|
+
const [file2, setFile] = (0, import_react4.useState)(void 0);
|
|
172989
|
+
const [note, setNote] = (0, import_react4.useState)(void 0);
|
|
172990
|
+
const ref3 = (0, import_react4.useRef)(null);
|
|
172991
|
+
const href = storyLinkFor(link3, typeof location === "undefined" ? void 0 : location);
|
|
172992
|
+
(0, import_react4.useEffect)(() => {
|
|
172993
|
+
setFile(void 0);
|
|
172994
|
+
const el2 = ref3.current;
|
|
172995
|
+
if (!supported || el2 === null) return;
|
|
172996
|
+
let live = true;
|
|
172997
|
+
let started = false;
|
|
172998
|
+
const build2 = /* @__PURE__ */ __name(() => {
|
|
172999
|
+
if (started) return;
|
|
173000
|
+
started = true;
|
|
173001
|
+
buildStoryFile(src2, href).then((f3) => {
|
|
173002
|
+
if (live && f3 !== void 0 && navigator.canShare({ files: [f3] })) setFile(f3);
|
|
173003
|
+
}).catch(() => void 0);
|
|
173004
|
+
}, "build");
|
|
173005
|
+
if (typeof IntersectionObserver === "undefined") {
|
|
173006
|
+
build2();
|
|
173007
|
+
return () => {
|
|
173008
|
+
live = false;
|
|
173009
|
+
};
|
|
173010
|
+
}
|
|
173011
|
+
const io = new IntersectionObserver((entries) => {
|
|
173012
|
+
if (entries.some((e3) => e3.isIntersecting)) {
|
|
173013
|
+
io.disconnect();
|
|
173014
|
+
build2();
|
|
173015
|
+
}
|
|
173016
|
+
});
|
|
173017
|
+
io.observe(el2);
|
|
173018
|
+
return () => {
|
|
173019
|
+
live = false;
|
|
173020
|
+
io.disconnect();
|
|
173021
|
+
};
|
|
173022
|
+
}, [supported, src2, href]);
|
|
173023
|
+
const onTap = (0, import_react4.useCallback)(() => {
|
|
173024
|
+
if (file2 === void 0) return;
|
|
173025
|
+
if (href !== "") setNote("Link copied. Paste it in a link sticker.");
|
|
173026
|
+
void shareStory(file2, href).then((r2) => {
|
|
173027
|
+
if (r2 === "failed") setNote("The share sheet didn't open here.");
|
|
173028
|
+
setTimeout(() => setNote(void 0), 4e3);
|
|
173029
|
+
});
|
|
173030
|
+
}, [file2, href]);
|
|
173031
|
+
if (!supported) return null;
|
|
173032
|
+
return /* @__PURE__ */ import_react4.default.createElement(
|
|
173033
|
+
"div",
|
|
173034
|
+
{
|
|
173035
|
+
style: {
|
|
173036
|
+
position: "absolute",
|
|
173037
|
+
bottom: 8,
|
|
173038
|
+
left: 8,
|
|
173039
|
+
display: "flex",
|
|
173040
|
+
flexDirection: "column",
|
|
173041
|
+
alignItems: "flex-start",
|
|
173042
|
+
gap: 4,
|
|
173043
|
+
zIndex: 11
|
|
173044
|
+
}
|
|
173045
|
+
},
|
|
173046
|
+
note !== void 0 && /* @__PURE__ */ import_react4.default.createElement("div", { role: "status", style: { ...btnStyle, cursor: "default", fontSize: 12, padding: "4px 8px" } }, note),
|
|
173047
|
+
/* @__PURE__ */ import_react4.default.createElement(
|
|
173048
|
+
"button",
|
|
173049
|
+
{
|
|
173050
|
+
ref: ref3,
|
|
173051
|
+
type: "button",
|
|
173052
|
+
"data-imggen-story": true,
|
|
173053
|
+
onClick: onTap,
|
|
173054
|
+
disabled: file2 === void 0,
|
|
173055
|
+
"aria-busy": file2 === void 0,
|
|
173056
|
+
style: { ...storyBtnStyle, opacity: file2 === void 0 ? 0.6 : 1 },
|
|
173057
|
+
title: "Add to your story"
|
|
173058
|
+
},
|
|
173059
|
+
/* @__PURE__ */ import_react4.default.createElement("span", { "aria-hidden": "true", style: { fontSize: 16, lineHeight: 1 } }, "\u2295"),
|
|
173060
|
+
"Add to story"
|
|
173061
|
+
)
|
|
173062
|
+
);
|
|
173063
|
+
}
|
|
173064
|
+
var import_react4, GENERATED_IMAGE_NAME, btnStyle, capturePlaceholderStyle, playgroundBtnStyle, storyBtnStyle;
|
|
172862
173065
|
var init_ImgGen = __esm({
|
|
172863
173066
|
"../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/base/components/ImgGen.tsx"() {
|
|
172864
173067
|
"use strict";
|
|
@@ -172871,9 +173074,11 @@ var init_ImgGen = __esm({
|
|
|
172871
173074
|
init_use_img_gen();
|
|
172872
173075
|
init_use_picture_src();
|
|
172873
173076
|
init_local_pictures();
|
|
173077
|
+
init_story_share();
|
|
172874
173078
|
GENERATED_IMAGE_NAME = "Generated image";
|
|
172875
173079
|
__name(promptToId, "promptToId");
|
|
172876
173080
|
__name(ImgGen, "ImgGen");
|
|
173081
|
+
__name(StoryButton, "StoryButton");
|
|
172877
173082
|
btnStyle = {
|
|
172878
173083
|
background: "rgba(0,0,0,0.6)",
|
|
172879
173084
|
color: "#fff",
|
|
@@ -172902,6 +173107,18 @@ var init_ImgGen = __esm({
|
|
|
172902
173107
|
fontSize: 15,
|
|
172903
173108
|
lineHeight: 1.2
|
|
172904
173109
|
};
|
|
173110
|
+
storyBtnStyle = {
|
|
173111
|
+
...btnStyle,
|
|
173112
|
+
display: "inline-flex",
|
|
173113
|
+
alignItems: "center",
|
|
173114
|
+
gap: 6,
|
|
173115
|
+
padding: "8px 12px",
|
|
173116
|
+
borderRadius: 999,
|
|
173117
|
+
fontSize: 14,
|
|
173118
|
+
fontWeight: 600,
|
|
173119
|
+
background: "linear-gradient(45deg, #f09433 0%, #dc2743 50%, #bc1888 100%)",
|
|
173120
|
+
boxShadow: "0 1px 4px rgba(0,0,0,0.3)"
|
|
173121
|
+
};
|
|
172905
173122
|
}
|
|
172906
173123
|
});
|
|
172907
173124
|
|
|
@@ -173653,7 +173870,16 @@ var init_url_state = __esm({
|
|
|
173653
173870
|
});
|
|
173654
173871
|
|
|
173655
173872
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/vibe/runtime/short-self-link.ts
|
|
173656
|
-
|
|
173873
|
+
function publicVibeBase(host) {
|
|
173874
|
+
return publicBaseFor(host);
|
|
173875
|
+
}
|
|
173876
|
+
function publicBaseFor(host) {
|
|
173877
|
+
const label = host.split(":")[0]?.split(".")[0] ?? "";
|
|
173878
|
+
const m = VIBE_LABEL_RE.exec(label);
|
|
173879
|
+
if (m === null) return void 0;
|
|
173880
|
+
return `${PUBLIC_ORIGIN}/vibe/${m[2].toLowerCase()}/${m[1].toLowerCase()}`;
|
|
173881
|
+
}
|
|
173882
|
+
var SHORT_LINK_STRIP_PARAMS, PUBLIC_ORIGIN, VIBE_LABEL_RE;
|
|
173657
173883
|
var init_short_self_link = __esm({
|
|
173658
173884
|
"../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/vibe/runtime/short-self-link.ts"() {
|
|
173659
173885
|
"use strict";
|
|
@@ -173677,6 +173903,10 @@ var init_short_self_link = __esm({
|
|
|
173677
173903
|
"preview",
|
|
173678
173904
|
".stable-entry."
|
|
173679
173905
|
]);
|
|
173906
|
+
PUBLIC_ORIGIN = "https://vibes.diy";
|
|
173907
|
+
VIBE_LABEL_RE = /^([a-z0-9][a-z0-9-]*?)--([a-z0-9][a-z0-9-]+)$/i;
|
|
173908
|
+
__name(publicVibeBase, "publicVibeBase");
|
|
173909
|
+
__name(publicBaseFor, "publicBaseFor");
|
|
173680
173910
|
}
|
|
173681
173911
|
});
|
|
173682
173912
|
|
|
@@ -182698,6 +182928,7 @@ var init_runtime2 = __esm({
|
|
|
182698
182928
|
init_use_env();
|
|
182699
182929
|
init_create_vibe();
|
|
182700
182930
|
init_github_install_url();
|
|
182931
|
+
init_short_self_link();
|
|
182701
182932
|
}
|
|
182702
182933
|
});
|
|
182703
182934
|
|
|
@@ -329411,7 +329642,7 @@ init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
|
329411
329642
|
init_performance2();
|
|
329412
329643
|
init_esm();
|
|
329413
329644
|
async function persistPutRevision(vctx, p3) {
|
|
329414
|
-
const { ownerHandle, appSlug, dbName, docId, doc, userId, now: now3, accessResult, accessFnCid, baseSeq, createIfHeadSeq } = p3;
|
|
329645
|
+
const { ownerHandle, appSlug, dbName, docId, doc, userId, now: now3, accessResult, accessFnCid, baseSeq, createIfHeadSeq, ifRev } = p3;
|
|
329415
329646
|
const t3 = vctx.sql.tables.appDocuments;
|
|
329416
329647
|
const storeAccessOutput = accessResult && !("forbidden" in accessResult) && accessFnCid ? {
|
|
329417
329648
|
tOutputs: vctx.sql.tables.accessFnOutputs,
|
|
@@ -329502,7 +329733,7 @@ async function persistPutRevision(vctx, p3) {
|
|
|
329502
329733
|
},
|
|
329503
329734
|
onAbsorb,
|
|
329504
329735
|
sidecar,
|
|
329505
|
-
...createIfHeadSeq === void 0 ? {} : { ifHeadSeqInInsert: createIfHeadSeq }
|
|
329736
|
+
...ifRev !== void 0 ? { ifRev } : createIfHeadSeq === void 0 ? {} : { ifHeadSeqInInsert: createIfHeadSeq }
|
|
329506
329737
|
});
|
|
329507
329738
|
return { alloc, absorbed: alloc.absorbed, storeAccessOutput, grantUpsertErr, noopRefreshedStaleOutput };
|
|
329508
329739
|
}
|
|
@@ -330805,7 +331036,7 @@ async function getDocForCaller(vctx, args3) {
|
|
|
330805
331036
|
docId: row.docId,
|
|
330806
331037
|
svc: vctx.params.vibes.svc
|
|
330807
331038
|
});
|
|
330808
|
-
return { kind: "ok", docId: row.docId, doc };
|
|
331039
|
+
return { kind: "ok", docId: row.docId, doc, rev: Number(row.seq) };
|
|
330809
331040
|
}
|
|
330810
331041
|
__name(getDocForCaller, "getDocForCaller");
|
|
330811
331042
|
var getDocEvento = {
|
|
@@ -334640,11 +334871,14 @@ async function putDocForCallerAttempt(vctx, callerArgs, attempt) {
|
|
|
334640
334871
|
now: now3,
|
|
334641
334872
|
accessResult,
|
|
334642
334873
|
accessFnCid: afbRow?.accessFnCid,
|
|
334643
|
-
|
|
334874
|
+
// An `ifRev` caller already said what must be there (null = nothing live), which covers the
|
|
334875
|
+
// must-still-be-absent create; the allocator takes one guard or the other, never both.
|
|
334876
|
+
...args3.ifRev !== void 0 ? { ifRev: args3.ifRev } : createIfHeadSeq === void 0 ? {} : { createIfHeadSeq }
|
|
334644
334877
|
});
|
|
334645
334878
|
} catch (err) {
|
|
334646
334879
|
if (err instanceof SeqConflictError) {
|
|
334647
|
-
if (
|
|
334880
|
+
if (args3.ifRev === void 0 && createIfHeadSeq !== void 0 && attempt === 0)
|
|
334881
|
+
return putDocForCallerAttempt(vctx, callerArgs, attempt + 1);
|
|
334648
334882
|
return {
|
|
334649
334883
|
kind: "denied",
|
|
334650
334884
|
code: "conflict",
|
|
@@ -336194,30 +336428,30 @@ function reminderClaimKey(r2) {
|
|
|
336194
336428
|
return `reminder:${r2.id}:${r2.dueAt}`;
|
|
336195
336429
|
}
|
|
336196
336430
|
__name(reminderClaimKey, "reminderClaimKey");
|
|
336431
|
+
function parseRemindersDoc(doc) {
|
|
336432
|
+
const parsed3 = agentRemindersDoc(doc);
|
|
336433
|
+
return parsed3 instanceof type.errors ? void 0 : parsed3;
|
|
336434
|
+
}
|
|
336435
|
+
__name(parseRemindersDoc, "parseRemindersDoc");
|
|
336197
336436
|
async function readRemindersDoc(vctx, actor) {
|
|
336198
|
-
const r2 = await readAgentDoc({
|
|
336199
|
-
vctx,
|
|
336200
|
-
actor,
|
|
336201
|
-
docId: AGENT_REMINDERS_DOC_ID,
|
|
336202
|
-
parse: /* @__PURE__ */ __name((doc) => {
|
|
336203
|
-
const parsed3 = agentRemindersDoc(doc);
|
|
336204
|
-
return parsed3 instanceof type.errors ? void 0 : parsed3;
|
|
336205
|
-
}, "parse")
|
|
336206
|
-
});
|
|
336437
|
+
const r2 = await readAgentDoc({ vctx, actor, docId: AGENT_REMINDERS_DOC_ID, parse: parseRemindersDoc });
|
|
336207
336438
|
if (r2.isErr()) return Result.Err(r2);
|
|
336208
336439
|
return Result.Ok(r2.Ok() ?? { type: "reminders", reminders: [] });
|
|
336209
336440
|
}
|
|
336210
336441
|
__name(readRemindersDoc, "readRemindersDoc");
|
|
336211
|
-
function
|
|
336212
|
-
|
|
336442
|
+
async function readRemindersDocRev(vctx, actor) {
|
|
336443
|
+
const r2 = await readAgentDocRev({ vctx, actor, docId: AGENT_REMINDERS_DOC_ID, parse: parseRemindersDoc });
|
|
336444
|
+
if (r2.isErr()) return Result.Err(r2);
|
|
336445
|
+
const { doc, rev } = r2.Ok();
|
|
336446
|
+
return Result.Ok({ doc: doc ?? { type: "reminders", reminders: [] }, rev });
|
|
336213
336447
|
}
|
|
336214
|
-
__name(
|
|
336448
|
+
__name(readRemindersDocRev, "readRemindersDocRev");
|
|
336215
336449
|
var localLocks = /* @__PURE__ */ new Map();
|
|
336216
336450
|
function remindersLockKey(actor) {
|
|
336217
336451
|
return `agent-reminders:${actor.userId}:${actor.ownerHandle}`;
|
|
336218
336452
|
}
|
|
336219
336453
|
__name(remindersLockKey, "remindersLockKey");
|
|
336220
|
-
async function underRemindersLock(
|
|
336454
|
+
async function underRemindersLock(actor, fn4) {
|
|
336221
336455
|
const key = remindersLockKey(actor);
|
|
336222
336456
|
const before = localLocks.get(key) ?? Promise.resolve();
|
|
336223
336457
|
let release3 = /* @__PURE__ */ __name(() => void 0, "release");
|
|
@@ -336226,32 +336460,29 @@ async function underRemindersLock(vctx, actor, fn4) {
|
|
|
336226
336460
|
localLocks.set(key, queued);
|
|
336227
336461
|
await before;
|
|
336228
336462
|
try {
|
|
336229
|
-
|
|
336230
|
-
return await vctx.sql.db.transaction(async (tx) => {
|
|
336231
|
-
const pgTx = tx;
|
|
336232
|
-
await pgTx.execute(sql`SELECT pg_advisory_xact_lock(hashtextextended(${key}, 0))`);
|
|
336233
|
-
return await fn4({ ...vctx, sql: { ...vctx.sql, db: tx } });
|
|
336234
|
-
});
|
|
336463
|
+
return await fn4();
|
|
336235
336464
|
} finally {
|
|
336236
336465
|
release3();
|
|
336237
336466
|
if (localLocks.get(key) === queued) localLocks.delete(key);
|
|
336238
336467
|
}
|
|
336239
336468
|
}
|
|
336240
336469
|
__name(underRemindersLock, "underRemindersLock");
|
|
336470
|
+
var REMINDERS_WRITE_ATTEMPTS = 5;
|
|
336241
336471
|
async function updateReminders(vctx, actor, change) {
|
|
336242
336472
|
const r2 = await exception2Result(
|
|
336243
|
-
() => underRemindersLock(
|
|
336244
|
-
|
|
336245
|
-
|
|
336246
|
-
async (locked) => {
|
|
336247
|
-
const rFresh = await readRemindersDoc(locked, actor);
|
|
336473
|
+
() => underRemindersLock(actor, async () => {
|
|
336474
|
+
for (let attempt = 1; ; attempt++) {
|
|
336475
|
+
const rFresh = await readRemindersDocRev(vctx, actor);
|
|
336248
336476
|
if (rFresh.isErr()) return { ok: false, err: rFresh };
|
|
336249
|
-
const {
|
|
336477
|
+
const { doc, rev } = rFresh.Ok();
|
|
336478
|
+
const { next: next3, out } = await change(doc);
|
|
336250
336479
|
if (next3 === void 0) return { ok: true, out };
|
|
336251
|
-
const rPut = await
|
|
336252
|
-
|
|
336480
|
+
const rPut = await writeAgentDoc({ vctx, actor, docId: AGENT_REMINDERS_DOC_ID, doc: { ...next3 }, ifRev: rev });
|
|
336481
|
+
if (rPut.isOk()) return { ok: true, out };
|
|
336482
|
+
if (rPut.Err().message !== AGENT_DOC_CONFLICT || attempt >= REMINDERS_WRITE_ATTEMPTS) return { ok: false, err: rPut };
|
|
336483
|
+
vctx.logger.Info().Any("attempt", attempt).Msg("reminders-write-conflict-retry");
|
|
336253
336484
|
}
|
|
336254
|
-
)
|
|
336485
|
+
})
|
|
336255
336486
|
);
|
|
336256
336487
|
if (r2.isErr()) return Result.Err(r2);
|
|
336257
336488
|
const done2 = r2.Ok();
|
|
@@ -336323,7 +336554,8 @@ async function claimDueReminders(vctx, args3) {
|
|
|
336323
336554
|
const { actor, lane, now: now3 } = args3;
|
|
336324
336555
|
const settles = args3.settles === true;
|
|
336325
336556
|
const nowIso2 = now3.toISOString();
|
|
336326
|
-
|
|
336557
|
+
const won = [];
|
|
336558
|
+
const mine = /* @__PURE__ */ new Set();
|
|
336327
336559
|
const r2 = await updateReminders(vctx, actor, async (doc) => {
|
|
336328
336560
|
const kept = (doc.handed ?? []).filter((h5) => Date.parse(h5.expiresAt) + REMINDER_SETTLE_GRACE_MS >= now3.getTime());
|
|
336329
336561
|
const live = kept.filter((h5) => Date.parse(h5.expiresAt) >= now3.getTime());
|
|
@@ -336333,7 +336565,7 @@ async function claimDueReminders(vctx, args3) {
|
|
|
336333
336565
|
const again = settles ? live.filter((h5) => h5.lane === lane && h5.reader === args3.reader).map(handedAlert) : [];
|
|
336334
336566
|
const due = doc.reminders.filter((x3) => reminderDueFor(x3, lane, now3));
|
|
336335
336567
|
const { handed: _old, recent: _recent, ...rest } = doc;
|
|
336336
|
-
if (due.length === 0) {
|
|
336568
|
+
if (due.length === 0 && won.length === 0) {
|
|
336337
336569
|
const pruned = kept.length !== (doc.handed ?? []).length;
|
|
336338
336570
|
return { out: again, ...pruned ? { next: { ...rest, ...withHanded(kept), ...withRecent(doc, [], now3) } } : {} };
|
|
336339
336571
|
}
|
|
@@ -336355,7 +336587,8 @@ async function claimDueReminders(vctx, args3) {
|
|
|
336355
336587
|
continue;
|
|
336356
336588
|
}
|
|
336357
336589
|
moved.add(x3.id);
|
|
336358
|
-
if (
|
|
336590
|
+
if (rClaim.Ok()) mine.add(reminderClaimKey(x3));
|
|
336591
|
+
if (!rClaim.Ok() && !mine.has(reminderClaimKey(x3))) {
|
|
336359
336592
|
vctx.logger.Info().Str("reminderId", x3.id).Str("lane", lane).Msg("reminder-claim-lost");
|
|
336360
336593
|
continue;
|
|
336361
336594
|
}
|
|
@@ -336379,7 +336612,13 @@ async function claimDueReminders(vctx, args3) {
|
|
|
336379
336612
|
at: nowIso2
|
|
336380
336613
|
});
|
|
336381
336614
|
alerts.push(handedAlert(h5));
|
|
336382
|
-
won
|
|
336615
|
+
if (!won.some((w3) => w3.h.alertId === h5.alertId)) won.push({ h: h5, recent: recent[recent.length - 1] });
|
|
336616
|
+
}
|
|
336617
|
+
for (const w3 of won) {
|
|
336618
|
+
if (alerts.some((a4) => a4.id === w3.h.alertId)) continue;
|
|
336619
|
+
alerts.push(handedAlert(w3.h));
|
|
336620
|
+
if (settles && !handed.some((x3) => x3.alertId === w3.h.alertId)) handed.push(w3.h);
|
|
336621
|
+
if (!(doc.recent ?? []).some((x3) => x3.alertId === w3.h.alertId)) recent.push(w3.recent);
|
|
336383
336622
|
}
|
|
336384
336623
|
const reminders = doc.reminders.flatMap((x3) => {
|
|
336385
336624
|
if (!moved.has(x3.id)) return [x3];
|
|
@@ -336394,7 +336633,7 @@ async function claimDueReminders(vctx, args3) {
|
|
|
336394
336633
|
});
|
|
336395
336634
|
if (r2.isErr()) {
|
|
336396
336635
|
vctx.logger.Warn().Err(r2).Str("lane", lane).Any("won", won.length).Msg("reminders-claim-pass-failed");
|
|
336397
|
-
return won;
|
|
336636
|
+
return won.map((w3) => handedAlert(w3.h));
|
|
336398
336637
|
}
|
|
336399
336638
|
return r2.Ok();
|
|
336400
336639
|
}
|
|
@@ -336765,17 +337004,40 @@ async function readAgentDoc({
|
|
|
336765
337004
|
return Result.Ok(parse13(answer13.doc));
|
|
336766
337005
|
}
|
|
336767
337006
|
__name(readAgentDoc, "readAgentDoc");
|
|
337007
|
+
async function readAgentDocRev({
|
|
337008
|
+
vctx,
|
|
337009
|
+
actor,
|
|
337010
|
+
docId,
|
|
337011
|
+
parse: parse13
|
|
337012
|
+
}) {
|
|
337013
|
+
const r2 = await exception2Result(() => getDocForCaller(vctx, { ...agentDbCaller(actor), docId }));
|
|
337014
|
+
if (r2.isErr()) return Result.Err(r2);
|
|
337015
|
+
const answer13 = r2.Ok();
|
|
337016
|
+
if (answer13.kind === "denied") return Result.Err(`agent doc read refused (${docId}): ${answer13.message}`);
|
|
337017
|
+
if (answer13.kind !== "ok") return Result.Ok({ doc: void 0, rev: null });
|
|
337018
|
+
return Result.Ok({ doc: parse13(answer13.doc), rev: answer13.rev });
|
|
337019
|
+
}
|
|
337020
|
+
__name(readAgentDocRev, "readAgentDocRev");
|
|
337021
|
+
var AGENT_DOC_CONFLICT = "agent-doc-conflict";
|
|
336768
337022
|
async function writeAgentDoc({
|
|
336769
337023
|
vctx,
|
|
336770
337024
|
actor,
|
|
336771
337025
|
docId,
|
|
336772
|
-
doc
|
|
337026
|
+
doc,
|
|
337027
|
+
ifRev
|
|
336773
337028
|
}) {
|
|
336774
337029
|
const r2 = await exception2Result(
|
|
336775
|
-
() => putDocForCaller(vctx, {
|
|
337030
|
+
() => putDocForCaller(vctx, {
|
|
337031
|
+
...agentDbCaller(actor),
|
|
337032
|
+
fanOutDocChanged: remoteDocChangedFanOut,
|
|
337033
|
+
docId,
|
|
337034
|
+
doc,
|
|
337035
|
+
...ifRev === void 0 ? {} : { ifRev }
|
|
337036
|
+
})
|
|
336776
337037
|
);
|
|
336777
337038
|
if (r2.isErr()) return Result.Err(r2);
|
|
336778
337039
|
const answer13 = r2.Ok();
|
|
337040
|
+
if (answer13.kind === "denied" && answer13.code === "conflict" && ifRev !== void 0) return Result.Err(AGENT_DOC_CONFLICT);
|
|
336779
337041
|
if (answer13.kind !== "ok") return Result.Err(`agent doc write refused (${docId}): ${answer13.message}`);
|
|
336780
337042
|
return Result.Ok(void 0);
|
|
336781
337043
|
}
|
|
@@ -364370,6 +364632,7 @@ var RUNTIME_EXPORTS = [
|
|
|
364370
364632
|
"postHotSwapOkToParent",
|
|
364371
364633
|
"prepareCallAIPrompt",
|
|
364372
364634
|
"promoteHotSwap",
|
|
364635
|
+
"publicVibeBase",
|
|
364373
364636
|
"readCallAIUserActivation",
|
|
364374
364637
|
"reconcileSoftSocialGraphWithViewer",
|
|
364375
364638
|
"recordEnvBaselinesFromMessage",
|
|
@@ -861,6 +861,7 @@
|
|
|
861
861
|
"vibes.diy/base/components/ImgGen.tsx",
|
|
862
862
|
"vibes.diy/base/components/ViewerTagView.tsx",
|
|
863
863
|
"vibes.diy/base/components/handle-known-cache.ts",
|
|
864
|
+
"vibes.diy/base/components/story-share.ts",
|
|
864
865
|
"vibes.diy/base/components/use-handle-lookup-items.ts",
|
|
865
866
|
"vibes.diy/base/hooks/img-gen/index.ts",
|
|
866
867
|
"vibes.diy/base/hooks/img-gen/local-pictures.ts",
|
|
@@ -3567,6 +3568,7 @@
|
|
|
3567
3568
|
"vibes.diy/base/components/ImgGen.tsx",
|
|
3568
3569
|
"vibes.diy/base/components/ViewerTagView.tsx",
|
|
3569
3570
|
"vibes.diy/base/components/handle-known-cache.ts",
|
|
3571
|
+
"vibes.diy/base/components/story-share.ts",
|
|
3570
3572
|
"vibes.diy/base/components/use-handle-lookup-items.ts",
|
|
3571
3573
|
"vibes.diy/base/hooks/img-gen/index.ts",
|
|
3572
3574
|
"vibes.diy/base/hooks/img-gen/local-pictures.ts",
|