vibes-diy 14.3.340 → 14.3.342
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/cli/cmd-evento.d.ts +450 -450
- package/cli/cmds/app/look-style-edits.js +2 -7
- package/cli/cmds/run/backend-worker/run-backend-entry.js +1368 -891
- package/cli/cmds/run/bundle-inputs.json +6 -0
- package/cli/cmds/run/run-bundle.js +2367 -1883
- package/package.json +8 -8
|
@@ -30191,6 +30191,19 @@ function housePreset() {
|
|
|
30191
30191
|
if (house === void 0) throw new Error("style-presets: the house preset is missing, and the pouf rooms borrow its regime");
|
|
30192
30192
|
return house;
|
|
30193
30193
|
}
|
|
30194
|
+
function poufSeedEqualsPreset(seed, preset) {
|
|
30195
|
+
if (seed === void 0 || preset === void 0) return false;
|
|
30196
|
+
if (seed.up !== void 0 || seed.down !== void 0) return false;
|
|
30197
|
+
return preset.lead === seed.lead && preset.locked === seed.locked && preset.tone === seed.tone && preset.gap === seed.gap;
|
|
30198
|
+
}
|
|
30199
|
+
function poufPresetOfSeed(seed) {
|
|
30200
|
+
const slugs = [...POUF_ROOM_SLUGS, ...POUF_BOLD_PRESETS.map((p3) => p3.slug)];
|
|
30201
|
+
return slugs.find((slug) => poufSeedEqualsPreset(seed, getStylePreset(slug)?.palette.pouf));
|
|
30202
|
+
}
|
|
30203
|
+
function poufRoomOfSeed(seed) {
|
|
30204
|
+
const slug = poufPresetOfSeed(seed);
|
|
30205
|
+
return slug?.endsWith("-bold") === true ? slug.slice(0, -"-bold".length) : slug;
|
|
30206
|
+
}
|
|
30194
30207
|
var STYLE_PRESETS, FLOOR_PRESET_SLUG, STAMPABLE_STYLE_PRESETS, HOUSE_COLORWAY_SLUGS, POUF_ROOM_SLUGS, POUF_ROOM_ACCENT_PINS, POUF_STYLE_PRESETS, POUF_BOLD_TONE, POUF_BOLD_PRESETS;
|
|
30195
30208
|
var init_style_presets = __esm({
|
|
30196
30209
|
"../../home/runner/work/vibes.diy/vibes.diy/prompts/pkg/themes/style-presets.ts"() {
|
|
@@ -30475,6 +30488,9 @@ var init_style_presets = __esm({
|
|
|
30475
30488
|
}
|
|
30476
30489
|
};
|
|
30477
30490
|
});
|
|
30491
|
+
__name(poufSeedEqualsPreset, "poufSeedEqualsPreset");
|
|
30492
|
+
__name(poufPresetOfSeed, "poufPresetOfSeed");
|
|
30493
|
+
__name(poufRoomOfSeed, "poufRoomOfSeed");
|
|
30478
30494
|
}
|
|
30479
30495
|
});
|
|
30480
30496
|
|
|
@@ -126528,14 +126544,14 @@ function styleClassesOf(source) {
|
|
|
126528
126544
|
function scriptOf(source) {
|
|
126529
126545
|
let out = "";
|
|
126530
126546
|
let last = 0;
|
|
126531
|
-
const
|
|
126547
|
+
const blank4 = /* @__PURE__ */ __name((text3) => text3.replace(/[^\n\r]/g, " "), "blank");
|
|
126532
126548
|
for (const match4 of source.matchAll(SCRIPT_RE)) {
|
|
126533
126549
|
const start2 = match4.index + match4[0].indexOf(">") + 1;
|
|
126534
126550
|
const end = start2 + match4[1].length;
|
|
126535
|
-
out +=
|
|
126551
|
+
out += blank4(source.slice(last, start2)) + source.slice(start2, end);
|
|
126536
126552
|
last = end;
|
|
126537
126553
|
}
|
|
126538
|
-
return out +
|
|
126554
|
+
return out + blank4(source.slice(last));
|
|
126539
126555
|
}
|
|
126540
126556
|
function loadOxc() {
|
|
126541
126557
|
try {
|
|
@@ -176568,6 +176584,16 @@ var init_bare_specifier_rewrite = __esm({
|
|
|
176568
176584
|
}
|
|
176569
176585
|
});
|
|
176570
176586
|
|
|
176587
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/vibe/runtime/typing-hold.ts
|
|
176588
|
+
var init_typing_hold = __esm({
|
|
176589
|
+
"../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/vibe/runtime/typing-hold.ts"() {
|
|
176590
|
+
"use strict";
|
|
176591
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
176592
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
176593
|
+
init_performance2();
|
|
176594
|
+
}
|
|
176595
|
+
});
|
|
176596
|
+
|
|
176571
176597
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/vibe/runtime/register-dependencies.ts
|
|
176572
176598
|
function getRegisteredVibeApi() {
|
|
176573
176599
|
return _registeredApi;
|
|
@@ -176643,6 +176669,7 @@ var init_register_dependencies = __esm({
|
|
|
176643
176669
|
init_runtime_build();
|
|
176644
176670
|
init_bare_specifier_rewrite();
|
|
176645
176671
|
init_lazy_type();
|
|
176672
|
+
init_typing_hold();
|
|
176646
176673
|
VibeSandboxApi = class {
|
|
176647
176674
|
static {
|
|
176648
176675
|
__name(this, "VibeSandboxApi");
|
|
@@ -202131,7 +202158,7 @@ function createBlockStream(streamId, innerStreamId, createId) {
|
|
|
202131
202158
|
if (pendingBlanks.length > 0) {
|
|
202132
202159
|
const blanks = pendingBlanks;
|
|
202133
202160
|
pendingBlanks = [];
|
|
202134
|
-
for (const
|
|
202161
|
+
for (const blank4 of blanks) emitToplevelLine(controller, blank4);
|
|
202135
202162
|
}
|
|
202136
202163
|
}
|
|
202137
202164
|
__name(flushPendingAsToplevel, "flushPendingAsToplevel");
|
|
@@ -204301,7 +204328,7 @@ var setAppStyleToolInput = lazyType(
|
|
|
204301
204328
|
);
|
|
204302
204329
|
var agentToolRefusalReason = lazyType(
|
|
204303
204330
|
() => type(
|
|
204304
|
-
"'busy' | 'stale-base' | 'out-of-scope' | 'ambiguous-handle' | 'not-owner' | 'invalid-input' | 'failed' | 'no-app-in-scope' | 'unchanged' | 'already-created' | 'claim-unavailable' | 'address-taken' | 'under-one-build' | 'guest-first-version' | 'own-pass-offered'"
|
|
204331
|
+
"'busy' | 'stale-base' | 'out-of-scope' | 'ambiguous-handle' | 'not-owner' | 'invalid-input' | 'failed' | 'no-app-in-scope' | 'unchanged' | 'already-created' | 'claim-unavailable' | 'address-taken' | 'under-one-build' | 'guest-first-version' | 'own-pass-offered' | 'finish-ask'"
|
|
204305
204332
|
)
|
|
204306
204333
|
);
|
|
204307
204334
|
var agentToolRefusal = lazyType(
|
|
@@ -214734,7 +214761,7 @@ function line(text3, opts) {
|
|
|
214734
214761
|
}
|
|
214735
214762
|
__name(line, "line");
|
|
214736
214763
|
var FAILED = "That change didn't land";
|
|
214737
|
-
var SKIPPED_PASS = /* @__PURE__ */ new Set(["under-one-build", "guest-first-version", "own-pass-offered"]);
|
|
214764
|
+
var SKIPPED_PASS = /* @__PURE__ */ new Set(["under-one-build", "guest-first-version", "own-pass-offered", "finish-ask"]);
|
|
214738
214765
|
function changeFailed(name) {
|
|
214739
214766
|
return name !== void 0 && MUTATING.has(name) ? line(FAILED, { outcome: true }) : void 0;
|
|
214740
214767
|
}
|
|
@@ -251136,7 +251163,7 @@ var REGEX_PRECEDING_KEYWORDS = /* @__PURE__ */ new Set([
|
|
|
251136
251163
|
]);
|
|
251137
251164
|
function maskNonCode(source) {
|
|
251138
251165
|
const chars2 = source.split("");
|
|
251139
|
-
const
|
|
251166
|
+
const blank4 = /* @__PURE__ */ __name((from4, to2) => {
|
|
251140
251167
|
for (let k4 = from4; k4 < to2 && k4 < chars2.length; k4++) {
|
|
251141
251168
|
if (chars2[k4] !== "\n") chars2[k4] = " ";
|
|
251142
251169
|
}
|
|
@@ -251149,7 +251176,7 @@ function maskNonCode(source) {
|
|
|
251149
251176
|
if (ch === "/" && source[i3 + 1] === "/") {
|
|
251150
251177
|
let j3 = i3 + 2;
|
|
251151
251178
|
while (j3 < source.length && source[j3] !== "\n") j3++;
|
|
251152
|
-
|
|
251179
|
+
blank4(i3, j3);
|
|
251153
251180
|
i3 = j3;
|
|
251154
251181
|
continue;
|
|
251155
251182
|
}
|
|
@@ -251157,7 +251184,7 @@ function maskNonCode(source) {
|
|
|
251157
251184
|
let j3 = i3 + 2;
|
|
251158
251185
|
while (j3 < source.length && !(source[j3] === "*" && source[j3 + 1] === "/")) j3++;
|
|
251159
251186
|
j3 = Math.min(j3 + 2, source.length);
|
|
251160
|
-
|
|
251187
|
+
blank4(i3, j3);
|
|
251161
251188
|
i3 = j3;
|
|
251162
251189
|
continue;
|
|
251163
251190
|
}
|
|
@@ -251169,7 +251196,7 @@ function maskNonCode(source) {
|
|
|
251169
251196
|
}
|
|
251170
251197
|
if (ch === "`") {
|
|
251171
251198
|
const end = skipTemplate(source, i3);
|
|
251172
|
-
|
|
251199
|
+
blank4(i3, end);
|
|
251173
251200
|
i3 = end;
|
|
251174
251201
|
prevIsValue = true;
|
|
251175
251202
|
prevIsDot = false;
|
|
@@ -251179,7 +251206,7 @@ function maskNonCode(source) {
|
|
|
251179
251206
|
if (!prevIsValue) {
|
|
251180
251207
|
const end = skipRegex(source, i3);
|
|
251181
251208
|
if (end !== void 0) {
|
|
251182
|
-
|
|
251209
|
+
blank4(i3, end);
|
|
251183
251210
|
i3 = end;
|
|
251184
251211
|
prevIsValue = true;
|
|
251185
251212
|
prevIsDot = false;
|
|
@@ -259988,7 +260015,7 @@ init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
|
259988
260015
|
init_performance2();
|
|
259989
260016
|
function codeView(src2) {
|
|
259990
260017
|
const out = src2.split("");
|
|
259991
|
-
const
|
|
260018
|
+
const blank4 = /* @__PURE__ */ __name((i4) => {
|
|
259992
260019
|
if (out[i4] !== "\n") out[i4] = " ";
|
|
259993
260020
|
}, "blank");
|
|
259994
260021
|
const templates2 = [];
|
|
@@ -259997,8 +260024,8 @@ function codeView(src2) {
|
|
|
259997
260024
|
function scanTemplate() {
|
|
259998
260025
|
while (i3 < src2.length) {
|
|
259999
260026
|
if (src2[i3] === "\\") {
|
|
260000
|
-
|
|
260001
|
-
|
|
260027
|
+
blank4(i3);
|
|
260028
|
+
blank4(i3 + 1);
|
|
260002
260029
|
i3 += 2;
|
|
260003
260030
|
} else if (src2[i3] === "`") {
|
|
260004
260031
|
i3++;
|
|
@@ -260009,7 +260036,7 @@ function codeView(src2) {
|
|
|
260009
260036
|
i3 += 2;
|
|
260010
260037
|
return;
|
|
260011
260038
|
} else {
|
|
260012
|
-
|
|
260039
|
+
blank4(i3);
|
|
260013
260040
|
i3++;
|
|
260014
260041
|
}
|
|
260015
260042
|
}
|
|
@@ -260020,19 +260047,19 @@ function codeView(src2) {
|
|
|
260020
260047
|
const next3 = src2[i3 + 1];
|
|
260021
260048
|
switch (true) {
|
|
260022
260049
|
case (c3 === "/" && next3 === "/"):
|
|
260023
|
-
while (i3 < src2.length && src2[i3] !== "\n")
|
|
260050
|
+
while (i3 < src2.length && src2[i3] !== "\n") blank4(i3++);
|
|
260024
260051
|
break;
|
|
260025
260052
|
case (c3 === "/" && next3 === "*"): {
|
|
260026
260053
|
const close = src2.indexOf("*/", i3 + 2);
|
|
260027
260054
|
const end = close < 0 ? src2.length : close + 2;
|
|
260028
|
-
while (i3 < end)
|
|
260055
|
+
while (i3 < end) blank4(i3++);
|
|
260029
260056
|
break;
|
|
260030
260057
|
}
|
|
260031
260058
|
case (c3 === '"' || c3 === "'"):
|
|
260032
260059
|
i3++;
|
|
260033
260060
|
while (i3 < src2.length && src2[i3] !== c3 && src2[i3] !== "\n") {
|
|
260034
|
-
if (src2[i3] === "\\")
|
|
260035
|
-
|
|
260061
|
+
if (src2[i3] === "\\") blank4(i3++);
|
|
260062
|
+
blank4(i3++);
|
|
260036
260063
|
}
|
|
260037
260064
|
i3++;
|
|
260038
260065
|
break;
|
|
@@ -263597,7 +263624,7 @@ init_esm();
|
|
|
263597
263624
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
263598
263625
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
263599
263626
|
init_performance2();
|
|
263600
|
-
var AGENT_SESSION_INSTRUCTION_VERSION = "2026-11-16.
|
|
263627
|
+
var AGENT_SESSION_INSTRUCTION_VERSION = "2026-11-16.4";
|
|
263601
263628
|
var GROUP_READY_SHAPE = "each person's own records live on a channel named by their handle, granted on every write they make, so the app opens on their tree with nothing to create first, while a second or shared thing is its own document the person's own action writes; the rules key on user.userHandle, the tree's handle or that object's own creator, and the records are shaped so a friend can be let in later by a member record, so the app owner stands where everyone else stands.";
|
|
263602
263629
|
var INVITE_SCREEN_WHEN = "The invite screen, the platform's HandleInput writing a membership into the person's tree or object, is part of the first build when the ask names other people, sharing, a group, a team, a family, a we or an our, or a person by name, and when the app is a person's own collection, where adding a friend is how the collection is shared";
|
|
263603
263630
|
var SHARING_BASELINE = "Sharing is the baseline: every first build that is not privacy-sensitive ships a way to share on its first screen, specified asks and asks that name nobody else included, and the shape follows what one record is \u2014 a record a person keeps for their own life (a check-in, an entry, a line in a list) belongs to a collection that is private to its person and shared whole by the add-a-friend control on the first screen, which grants the friend it names the collection's channel; a piece made for readers (a post, an article, a gallery piece) carries a one-tap publish that puts it on its own channel, shared with everyone who can open the app, the drafting ritual readers already know; a thing made to be seen the moment it exists (a character in a cast, a caption) lands on an always-on shared channel everyone who opens the app can see. The person's own words move the dial: asking to pick which items each friend sees adds that choice to the add-a-friend control, and asking for drafts or publish brings the per-item step to any record. The create_vibe brief names the shape. A collection's add-a-friend control is its first-screen share; in the other two shapes the invite screen may wait for an option. Only a privacy-sensitive app keeps its sharing off until the person turns it on.";
|
|
@@ -263607,6 +263634,8 @@ var KNOWN_VALUES_DIRECT_CONTROLS = "Known values stay direct controls.";
|
|
|
263607
263634
|
var FIRST_SCREEN_ORDER = "The first phone screen holds, in this order: the heading with the one way to add beside or under it, then the view the person asked for or the records at the size the view draws them, then Ask where the app has it, then the share control with its one who-can-see line. The view this turn's ask names \u2014 a table, a grid, a total, a board \u2014 leads that screen directly under the heading, above every form, settings card and reminder, unless the person said where it goes; a reminder, setting or share they ask for keeps its own place below, and at the top means the top of the opening screen, not of a detail view. The way to add is compact: a lead button that opens the form in a Dialog or Sheet, a single-line entry, or the sentence composer; a whole form stands open only while there is nothing yet to show, its sparkle beside its submit. While the viewer is still resolving, the add keeps its place in the heading as a skeleton or a disabled button, never an empty slot. Where the app has Ask, Ask is one quiet row under the records, or the composer's second action where the composer is the way to add. The share, add-a-friend or invite button with its one line is the footer row that closes the content, and the invite screen opens from it; reminders, settings and rosters wait behind a quiet button under the content. A game's canvas or board fills the screen, its heading and controls over it or beside it, and the look carries onto the play area and every overlay, hotbar and button: its palette, type and shapes, never a stock game palette. A limiting word in the ask \u2014 just, only, simple \u2014 keeps that kit and shrinks it further into the background.";
|
|
263608
263635
|
var PHONE_GAME_CONTROLS_LINE = "This is a game played on a phone: the whole play area is the controller \u2014 the thumb swipes, holds and drags right on the game, which fills the screen.";
|
|
263609
263636
|
var FORM_SPARKLE_LINE = "Every form ships with its sparkle in this first version: the Add form, the edit view, the composer and a one-field form naming a thing (a team, a dish, an entry) each carry one quiet sparkle button beside their submit that fills the fields with a callAI suggestion sized to each field (a name is a few words, a note a sentence or two), and the form's own submit saves. The one form without a sparkle is the owner's form for where money goes (a payment handle, a $Cashtag, a bank or account number), whose fields start empty for the owner to type. A field that asks who the person is (their own name on a sign-up or guest list, their email or phone) is theirs to type too: the sparkle leaves it empty, and a form holding only that field carries no sparkle.";
|
|
263637
|
+
var BROWSER_APP_ASK_LINE = 'When the ask names a desktop program, a phone app or software to install, the app is made as one that opens from its own link, and those words say so in a clause: "Making your <app> as an app that opens in your browser", or for a phone app "Making your <app> as an app that opens on your phone from its own link".';
|
|
263638
|
+
var FIRST_BUILD_SAYS_WHAT_IS_MADE = `On a first build, the words before create_vibe say what will be made in the person's terms, and a control they mention is one the brief asks for. ${BROWSER_APP_ASK_LINE}`;
|
|
263610
263639
|
var REPLY_FOLD = `A reply that runs past about three short sentences, as one often does after tool calls or a build, opens with a summary of one or two plain sentences that stands on its own: what happened, and the one link or question that matters most. Then comes a line holding only ${AGENT_FOLD_MARKER}, then the full reply, shaped by every rule here. The summary is what a phone receives as a text message, and the web page shows the full reply under a More button, so the summary carries that link or question itself. A reply of three short sentences or fewer is its own summary and goes out whole, just as it is. Words written before a tool call go out as their own text the moment the call starts, so keep them to one short sentence of what you are about to do; the result comes in the reply after.`;
|
|
263611
263640
|
var AGENT_SESSION_INSTRUCTION = `You are the Vibes agent, the builder talking with the person whose app this is.
|
|
263612
263641
|
When asked who you are or which model you use, introduce yourself as the Vibes DIY assistant and explain that Vibes DIY chooses models for the work and may change them.
|
|
@@ -263669,12 +263698,15 @@ Open a turn with words: before your first tool call, say one short present-tense
|
|
|
263669
263698
|
what you are about to make, in the person's terms \u2014 "Setting up your trip planner" \u2014 so the work
|
|
263670
263699
|
is named the moment it starts. It says what is beginning and nothing about how it ends. A turn
|
|
263671
263700
|
that simply answers needs no line in front of it: the answer is already the first thing said.
|
|
263701
|
+
On a first build, the words before create_vibe say what will be made in the person's terms, and a control they mention is one the brief asks for. When the ask names a desktop program, a phone app or software to install, the app is made as one that opens from its own link, and those words say so in a clause: "Making your <app> as an app that opens in your browser", or for a phone app "Making your <app> as an app that opens on your phone from its own link".
|
|
263672
263702
|
|
|
263673
263703
|
Acknowledge new requests promptly and use each returned result to choose
|
|
263674
263704
|
the next action. Call a change done after its successful result.
|
|
263675
263705
|
Match each claim to the evidence in hand. Accepted work is underway, staged files are drafts,
|
|
263676
263706
|
a successful commit confirms a save, and a release confirms publication. Reading files establishes
|
|
263677
263707
|
what code is present; exercising behavior establishes what works. Name remaining functional checks.
|
|
263708
|
+
A count of what a build wrote, such as questions, words or recipes, is one a report or a read you already made gave
|
|
263709
|
+
you; the opening line and the reply otherwise name the batch in words, a new batch of questions.
|
|
263678
263710
|
After interruption, inspect the current outcome before retrying. The runtime retains context at idle.
|
|
263679
263711
|
A dispatched change has its name reserved and its build on the way; the words saved, done, in, ready
|
|
263680
263712
|
and live belong to the reply you write after the commit or build result arrives.
|
|
@@ -263798,9 +263830,16 @@ behavior are code changes; a mixed ask can use both, with style first. Report th
|
|
|
263798
263830
|
An app whose code wears its own skin \u2014 a reskin's SKIN string on its data-reskin wrapper, or a
|
|
263799
263831
|
THEME_CSS block \u2014 sets its colours and fonts in that string, nearer the page than the Look tab's look.
|
|
263800
263832
|
A design brought to an app with its own skin is edit_vibe in the same turn: palette, fonts or tokens,
|
|
263801
|
-
the build
|
|
263802
|
-
|
|
263803
|
-
|
|
263833
|
+
the build writes a new skin from that design in the one skin string's place, so the person sees their
|
|
263834
|
+
design on the first try.
|
|
263835
|
+
A brought design replaces the earlier skin whole: the new skin is drawn from the design alone, so the
|
|
263836
|
+
earlier skin's stripes, borders, hard shadows, glow and the chrome it added (a title bar, a menu bar)
|
|
263837
|
+
leave with its colours and come back only where the design asks for them, while the app's components,
|
|
263838
|
+
controls and records stay as they are, and the edit_vibe brief says the skin is replaced whole.
|
|
263839
|
+
A change to one colour or one face of the skin is an edit to that value in the skin string, and the
|
|
263840
|
+
skin keeps its shapes and chrome: "make the accent this colour" or "use this font for headings" moves
|
|
263841
|
+
that one value. Read the entry file when a design arrives, whether or not this chat built the app, to
|
|
263842
|
+
see which kind it is, since a build can write a skin its brief did not name; an app without a skin of its
|
|
263804
263843
|
own takes the design through set_app_style.
|
|
263805
263844
|
An appearance the Look tab has no setting for \u2014 "make it look like a 90s Mac app", "make it feel like a
|
|
263806
263845
|
newspaper", a named style or mood, square black borders, a texture, a marquee \u2014 is edit_vibe with skills
|
|
@@ -264732,6 +264771,9 @@ function purgeRootHtmlCacheSameColo(vctx, ownerHandle, appSlug) {
|
|
|
264732
264771
|
}
|
|
264733
264772
|
__name(purgeRootHtmlCacheSameColo, "purgeRootHtmlCacheSameColo");
|
|
264734
264773
|
|
|
264774
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/public/ensure-app-settings.ts
|
|
264775
|
+
init_style_presets();
|
|
264776
|
+
|
|
264735
264777
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/mint-style.ts
|
|
264736
264778
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
264737
264779
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
@@ -265932,6 +265974,23 @@ Colours: ${THEME_SLUGS.join(", ")}`;
|
|
|
265932
265974
|
}
|
|
265933
265975
|
[res.settings, res.error] = await sqlPromoteDraftStyle(vctx, res, settings);
|
|
265934
265976
|
if (res.error === void 0) {
|
|
265977
|
+
const published = res.settings.entry.settings;
|
|
265978
|
+
const themeSlug = published.theme ?? "";
|
|
265979
|
+
const room = poufRoomOfSeed(published.style?.palette?.pouf);
|
|
265980
|
+
const stored = published.colorTheme === "pouf" ? "home" : published.colorTheme;
|
|
265981
|
+
if (room !== void 0 && room !== stored && hasLookColorways(themeSlug) && validateColorwayPinForLook(room, themeSlug).ok) {
|
|
265982
|
+
const [named3, nameError] = await sqlUpsertMulti({
|
|
265983
|
+
vctx,
|
|
265984
|
+
res,
|
|
265985
|
+
settings: res.settings.entries,
|
|
265986
|
+
ops: { upserts: [{ type: "active.colorTheme", colorTheme: room }] }
|
|
265987
|
+
});
|
|
265988
|
+
if (nameError === void 0) {
|
|
265989
|
+
res.settings = named3;
|
|
265990
|
+
} else {
|
|
265991
|
+
vctx.logger.Warn().Str("code", nameError).Str("room", room).Str("appSlug", req2.appSlug).Msg("style-publish: room name not stored; the published style is live");
|
|
265992
|
+
}
|
|
265993
|
+
}
|
|
265935
265994
|
purgeRootHtmlCacheSameColo(vctx, req2.ownerHandle, req2.appSlug);
|
|
265936
265995
|
}
|
|
265937
265996
|
break;
|
|
@@ -288443,6 +288502,7 @@ function turnSummaryInputFrom(msgs) {
|
|
|
288443
288502
|
const requests = [];
|
|
288444
288503
|
const lines = [];
|
|
288445
288504
|
const files = [];
|
|
288505
|
+
let landedAt;
|
|
288446
288506
|
for (const msg of msgs) {
|
|
288447
288507
|
if (isPromptReq(msg)) {
|
|
288448
288508
|
const text3 = personPromptText(msg);
|
|
@@ -288450,28 +288510,58 @@ function turnSummaryInputFrom(msgs) {
|
|
|
288450
288510
|
} else if (isToplevelLine(msg)) {
|
|
288451
288511
|
const line3 = msg.line.trim();
|
|
288452
288512
|
if (line3 === "" || FILE_HEADER.test(line3) || OPTION_LINE.test(line3)) continue;
|
|
288453
|
-
lines.push(line3);
|
|
288513
|
+
lines.push({ text: line3, at: timeOf(msg.timestamp) });
|
|
288454
288514
|
} else if (isCodeBegin(msg)) {
|
|
288455
288515
|
if (msg.path !== void 0) addFile(files, msg.path);
|
|
288456
288516
|
} else if (isPromptAgentEvidence(msg) && msg.evidence.kind === "result") {
|
|
288457
288517
|
const text3 = msg.evidence.text ?? "";
|
|
288458
288518
|
const saved = SAVED_FILES.exec(text3);
|
|
288459
288519
|
if (saved !== null) for (const path3 of saved[1].split(",")) addFile(files, path3);
|
|
288460
|
-
|
|
288520
|
+
const committed = committedPaths(text3);
|
|
288521
|
+
for (const path3 of committed) addFile(files, path3);
|
|
288522
|
+
if (saved !== null || committed.length > 0) {
|
|
288523
|
+
const at5 = timeOf(msg.timestamp);
|
|
288524
|
+
landedAt = landedAt === void 0 ? at5 : Math.min(landedAt, at5);
|
|
288525
|
+
}
|
|
288461
288526
|
}
|
|
288462
288527
|
}
|
|
288463
|
-
const
|
|
288464
|
-
const
|
|
288465
|
-
|
|
288528
|
+
const firstLanding = landedAt;
|
|
288529
|
+
const before = firstLanding === void 0 ? [] : lines.filter((l3) => l3.at < firstLanding);
|
|
288530
|
+
const after = firstLanding === void 0 ? lines : lines.filter((l3) => l3.at >= firstLanding);
|
|
288531
|
+
const prose = tailKept(after.map((l3) => l3.text).join("\n"));
|
|
288532
|
+
const plan = tailKept(before.map((l3) => l3.text).join("\n"));
|
|
288533
|
+
if (prose === "" && plan === "" && files.length === 0) return void 0;
|
|
288466
288534
|
const kept = requests.slice(0, TURN_SUMMARY_MAX_REQUESTS);
|
|
288467
288535
|
const share = Math.floor(TURN_SUMMARY_REQUEST_CHARS / Math.max(kept.length, 1));
|
|
288468
288536
|
return {
|
|
288469
288537
|
requests: kept.map((text3) => text3.slice(0, share)),
|
|
288470
288538
|
prose,
|
|
288539
|
+
...plan === "" ? {} : { plan },
|
|
288471
288540
|
files: files.slice(0, TURN_SUMMARY_MAX_FILES)
|
|
288472
288541
|
};
|
|
288473
288542
|
}
|
|
288474
288543
|
__name(turnSummaryInputFrom, "turnSummaryInputFrom");
|
|
288544
|
+
function timeOf(value2) {
|
|
288545
|
+
const ms = value2 instanceof Date ? value2.getTime() : typeof value2 === "string" ? Date.parse(value2) : NaN;
|
|
288546
|
+
return Number.isNaN(ms) ? 0 : ms;
|
|
288547
|
+
}
|
|
288548
|
+
__name(timeOf, "timeOf");
|
|
288549
|
+
function tailKept(text3) {
|
|
288550
|
+
return text3.length > TURN_SUMMARY_PROSE_CHARS ? `\u2026${text3.slice(-TURN_SUMMARY_PROSE_CHARS)}` : text3;
|
|
288551
|
+
}
|
|
288552
|
+
__name(tailKept, "tailKept");
|
|
288553
|
+
function countsIn(text3) {
|
|
288554
|
+
return new Set([...text3.matchAll(/\d[\d,]*/g)].map((m) => m[0].replace(/,/g, "")).filter((n3) => n3.length >= 2));
|
|
288555
|
+
}
|
|
288556
|
+
__name(countsIn, "countsIn");
|
|
288557
|
+
function unreportedCount(line3, input3) {
|
|
288558
|
+
if (input3.plan === void 0) return void 0;
|
|
288559
|
+
const given = countsIn(input3.requests.join("\n"));
|
|
288560
|
+
const reported2 = countsIn(input3.prose);
|
|
288561
|
+
const aimed = [...countsIn(input3.plan)].filter((n3) => given.has(n3) === false && reported2.has(n3) === false);
|
|
288562
|
+
return [...countsIn(line3)].find((n3) => aimed.includes(n3));
|
|
288563
|
+
}
|
|
288564
|
+
__name(unreportedCount, "unreportedCount");
|
|
288475
288565
|
function joinedTurnRequests(turns2, sessionId) {
|
|
288476
288566
|
return turns2.filter(
|
|
288477
288567
|
(turn) => turn.promptId !== sessionId && turn.msgs.some(
|
|
@@ -288484,7 +288574,8 @@ var TURN_SUMMARY_SYSTEM = [
|
|
|
288484
288574
|
"You write the one line shown above the chat box in Vibes DIY, an app builder, after a turn finishes.",
|
|
288485
288575
|
"Say what this turn made or changed in the person's app, as a finished fact: one sentence, at most 90 characters, plain words.",
|
|
288486
288576
|
'Name the good thing that now exists or now works ("Your trivia game now keeps score for each team").',
|
|
288487
|
-
"Leave out caveats, plans, and anything missing
|
|
288577
|
+
"Leave out caveats, plans, and anything still missing.",
|
|
288578
|
+
`A number in the line comes from the assistant's reply (the reply written after the work landed, when the turn below shows a plan); when only the request or the plan gives one, name what was made in words ("Added a new batch of trivia questions").`,
|
|
288488
288579
|
'If the turn changed nothing, say what it explained or offered, as a good thing ("Explained how laps are timed").',
|
|
288489
288580
|
'Use only facts from the turn below. No file names, no quotes, no emoji, no markdown, never "the assistant". Reply with the line only.'
|
|
288490
288581
|
].join("\n");
|
|
@@ -288502,7 +288593,10 @@ function turnSummaryMessages(input3) {
|
|
|
288502
288593
|
const parts = [
|
|
288503
288594
|
askedPart(input3.requests),
|
|
288504
288595
|
input3.files.length === 0 ? "Files changed: none" : `Files changed: ${input3.files.join(", ")}`,
|
|
288505
|
-
input3.
|
|
288596
|
+
...input3.plan === void 0 ? [] : [`What the assistant set out to do, said before the work landed (a plan, not a result):
|
|
288597
|
+
${input3.plan}`],
|
|
288598
|
+
input3.prose === "" ? "The assistant wrote no reply." : input3.plan === void 0 ? `The assistant's reply:
|
|
288599
|
+
${input3.prose}` : `The assistant's reply after the work landed:
|
|
288506
288600
|
${input3.prose}`
|
|
288507
288601
|
];
|
|
288508
288602
|
return [
|
|
@@ -288546,6 +288640,8 @@ async function requestTurnSummary(llm, input3, signal) {
|
|
|
288546
288640
|
if (body instanceof type.errors) return Result.Err(`turn summary: reply: ${body.summary}`);
|
|
288547
288641
|
const text3 = readTurnSummary(body.choices[0]?.message.content ?? "");
|
|
288548
288642
|
if (text3 === void 0) return Result.Err("turn summary: empty reply");
|
|
288643
|
+
const unreported = unreportedCount(text3, input3);
|
|
288644
|
+
if (unreported !== void 0) return Result.Err(`turn summary: count ${unreported} was aimed for, not reported`);
|
|
288549
288645
|
return Result.Ok({
|
|
288550
288646
|
text: text3,
|
|
288551
288647
|
...body.usage === void 0 ? {} : {
|
|
@@ -293638,6 +293734,11 @@ async function ownsNoHandle(ctx, userId) {
|
|
|
293638
293734
|
return row === void 0;
|
|
293639
293735
|
}
|
|
293640
293736
|
__name(ownsNoHandle, "ownsNoHandle");
|
|
293737
|
+
async function ownedByGuest(ctx, handle) {
|
|
293738
|
+
const row = await ctx.sql.db.select({ userId: ctx.sql.tables.handleBinding.userId }).from(ctx.sql.tables.handleBinding).where(eq(ctx.sql.tables.handleBinding.handle, handle)).limit(1).then((r2) => r2[0]);
|
|
293739
|
+
return row !== void 0 && isGuestPrincipal(row.userId);
|
|
293740
|
+
}
|
|
293741
|
+
__name(ownedByGuest, "ownedByGuest");
|
|
293641
293742
|
async function recordSignupAttribution(ctx, input3) {
|
|
293642
293743
|
const r2 = await exception2Result(async () => {
|
|
293643
293744
|
if (input3.userId.length === 0) return;
|
|
@@ -293647,6 +293748,7 @@ async function recordSignupAttribution(ctx, input3) {
|
|
|
293647
293748
|
const existing = await ctx.sql.db.select({ userId: tSignup.userId }).from(tSignup).where(eq(tSignup.userId, input3.userId)).limit(1).then((r3) => r3[0]);
|
|
293648
293749
|
if (existing !== void 0) return;
|
|
293649
293750
|
if (await ownsNoHandle(ctx, input3.userId) === false) return;
|
|
293751
|
+
if (await ownedByGuest(ctx, input3.ownerHandle)) return;
|
|
293650
293752
|
const signedUpAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
293651
293753
|
const inserted = await ctx.sql.db.insert(tSignup).values({
|
|
293652
293754
|
userId: input3.userId,
|
|
@@ -306873,12 +306975,23 @@ __name(resolveVideo, "resolveVideo");
|
|
|
306873
306975
|
async function earliestUpload(vctx, cid) {
|
|
306874
306976
|
const u3 = vctx.sql.tables.assetUploads;
|
|
306875
306977
|
return exception2Result(
|
|
306876
|
-
() => vctx.sql.db.select({ created: u3.created, mimeType: u3.mimeType }).from(u3).where(eq(u3.cid, cid)).orderBy(asc(u3.created)).limit(1).then((r2) => r2[0])
|
|
306978
|
+
() => vctx.sql.db.select({ created: u3.created, mimeType: u3.mimeType, userId: u3.userId }).from(u3).where(eq(u3.cid, cid)).orderBy(asc(u3.created)).limit(1).then((r2) => r2[0])
|
|
306877
306979
|
);
|
|
306878
306980
|
}
|
|
306879
306981
|
__name(earliestUpload, "earliestUpload");
|
|
306880
306982
|
async function resolveServableAsset(vctx, a4) {
|
|
306881
|
-
|
|
306983
|
+
const first = await resolveOnce(vctx, a4);
|
|
306984
|
+
if (first.hold === void 0) {
|
|
306985
|
+
if (first.asset.state === "error") {
|
|
306986
|
+
reportHold(vctx, a4, { outcome: "error", waitMs: 0, uploaderId: first.uploaderId });
|
|
306987
|
+
}
|
|
306988
|
+
return first.asset;
|
|
306989
|
+
}
|
|
306990
|
+
return holdForVerdict(vctx, a4, { ...first, hold: first.hold });
|
|
306991
|
+
}
|
|
306992
|
+
__name(resolveServableAsset, "resolveServableAsset");
|
|
306993
|
+
async function resolveOnce(vctx, a4) {
|
|
306994
|
+
if (vctx.sthis.env.get("ASSET_SAFETY_ENABLED") !== "true") return { asset: pass(a4, "disabled") };
|
|
306882
306995
|
let first;
|
|
306883
306996
|
let firstRead = false;
|
|
306884
306997
|
let kind;
|
|
@@ -306886,7 +306999,7 @@ async function resolveServableAsset(vctx, a4) {
|
|
|
306886
306999
|
const rFirst = await earliestUpload(vctx, a4.cid);
|
|
306887
307000
|
if (rFirst.isErr()) {
|
|
306888
307001
|
vctx.logger.Warn().Err(rFirst).Str("cid", a4.cid).Msg("asset-safety-upload-read-failed");
|
|
306889
|
-
return placeholder("error");
|
|
307002
|
+
return { asset: placeholder("error") };
|
|
306890
307003
|
}
|
|
306891
307004
|
first = rFirst.Ok();
|
|
306892
307005
|
firstRead = true;
|
|
@@ -306895,59 +307008,144 @@ async function resolveServableAsset(vctx, a4) {
|
|
|
306895
307008
|
} else {
|
|
306896
307009
|
kind = mediaKind(a4.mime);
|
|
306897
307010
|
}
|
|
306898
|
-
if (kind === "other") return pass(a4, "not-image");
|
|
306899
|
-
if (kind === "video") return resolveVideo(vctx, a4, firstRead ? { first } : void 0);
|
|
307011
|
+
if (kind === "other") return { asset: pass(a4, "not-image") };
|
|
307012
|
+
if (kind === "video") return { asset: await resolveVideo(vctx, a4, firstRead ? { first } : void 0) };
|
|
306900
307013
|
const s2 = vctx.sql.tables.assetSafety;
|
|
306901
307014
|
const rRow = await exception2Result(
|
|
306902
307015
|
() => vctx.sql.db.select().from(s2).where(eq(s2.cid, a4.cid)).limit(1).then((r2) => r2[0])
|
|
306903
307016
|
);
|
|
306904
307017
|
if (rRow.isErr()) {
|
|
306905
307018
|
vctx.logger.Warn().Err(rRow).Str("cid", a4.cid).Msg("asset-safety-row-read-failed");
|
|
306906
|
-
return placeholder("error");
|
|
307019
|
+
return { asset: placeholder("error") };
|
|
306907
307020
|
}
|
|
306908
307021
|
const row = rRow.Ok();
|
|
306909
307022
|
if (row === void 0) {
|
|
306910
|
-
if (a4.platformRender === true) return pass(a4, "platform");
|
|
307023
|
+
if (a4.platformRender === true) return { asset: pass(a4, "platform") };
|
|
306911
307024
|
if (!firstRead) {
|
|
306912
307025
|
const rFirst = await earliestUpload(vctx, a4.cid);
|
|
306913
307026
|
if (rFirst.isErr()) {
|
|
306914
307027
|
vctx.logger.Warn().Err(rFirst).Str("cid", a4.cid).Msg("asset-safety-upload-read-failed");
|
|
306915
|
-
return placeholder("error");
|
|
307028
|
+
return { asset: placeholder("error") };
|
|
306916
307029
|
}
|
|
306917
307030
|
first = rFirst.Ok();
|
|
306918
307031
|
}
|
|
306919
307032
|
const cutoff = vctx.sthis.env.get("ASSET_SAFETY_CUTOFF_ISO") ?? "";
|
|
306920
|
-
if (first !== void 0 && cutoff !== "" && first.created < cutoff) return pass(a4, "grandfathered");
|
|
306921
|
-
return placeholder("pending");
|
|
307033
|
+
if (first !== void 0 && cutoff !== "" && first.created < cutoff) return { asset: pass(a4, "grandfathered") };
|
|
307034
|
+
if (first === void 0) return { asset: placeholder("pending") };
|
|
307035
|
+
return { asset: placeholder("pending"), hold: { since: first.created }, uploaderId: first.userId };
|
|
306922
307036
|
}
|
|
306923
307037
|
if (row.verdict === "low") {
|
|
306924
|
-
if (row.cdnCid === null || row.cdnCid === void 0) return pass(a4, "low");
|
|
307038
|
+
if (row.cdnCid === null || row.cdnCid === void 0) return { asset: pass(a4, "low") };
|
|
306925
307039
|
return {
|
|
306926
|
-
|
|
306927
|
-
|
|
306928
|
-
|
|
306929
|
-
|
|
306930
|
-
|
|
307040
|
+
asset: {
|
|
307041
|
+
uri: row.cdnCid,
|
|
307042
|
+
mime: row.cdnMime ?? a4.mime,
|
|
307043
|
+
cacheControl: renditionCacheControl(a4),
|
|
307044
|
+
state: "low",
|
|
307045
|
+
etag: `"${row.cdnCid}"`
|
|
307046
|
+
}
|
|
306931
307047
|
};
|
|
306932
307048
|
}
|
|
306933
307049
|
const state4 = row.verdict === "pending" ? "pending" : row.verdict === "error" ? "error" : "high";
|
|
306934
307050
|
if (state4 !== "high") {
|
|
306935
|
-
if (a4.platformRender === true) return pass(a4, "platform");
|
|
307051
|
+
if (a4.platformRender === true) return { asset: pass(a4, "platform") };
|
|
306936
307052
|
if (!firstRead) {
|
|
306937
307053
|
const rFirst = await earliestUpload(vctx, a4.cid);
|
|
306938
307054
|
if (rFirst.isErr()) {
|
|
306939
307055
|
vctx.logger.Warn().Err(rFirst).Str("cid", a4.cid).Msg("asset-safety-upload-read-failed");
|
|
306940
|
-
return placeholder("error");
|
|
307056
|
+
return { asset: placeholder("error") };
|
|
306941
307057
|
}
|
|
306942
307058
|
first = rFirst.Ok();
|
|
306943
307059
|
}
|
|
306944
307060
|
const cutoff = vctx.sthis.env.get("ASSET_SAFETY_CUTOFF_ISO") ?? "";
|
|
306945
|
-
if (first !== void 0 && cutoff !== "" && first.created < cutoff) return pass(a4, "grandfathered");
|
|
306946
|
-
}
|
|
306947
|
-
|
|
306948
|
-
|
|
307061
|
+
if (first !== void 0 && cutoff !== "" && first.created < cutoff) return { asset: pass(a4, "grandfathered") };
|
|
307062
|
+
}
|
|
307063
|
+
const asset = row.placeholderCid === null || row.placeholderCid === void 0 ? placeholder(state4) : hold(row.placeholderCid, row.placeholderMime ?? "image/webp", state4);
|
|
307064
|
+
const uploaderId = first?.userId;
|
|
307065
|
+
if (state4 !== "pending") return uploaderId === void 0 ? { asset } : { asset, uploaderId };
|
|
307066
|
+
return { asset, hold: { since: row.created }, ...uploaderId === void 0 ? {} : { uploaderId } };
|
|
307067
|
+
}
|
|
307068
|
+
__name(resolveOnce, "resolveOnce");
|
|
307069
|
+
var DEFAULT_HOLD_MS = 6e4;
|
|
307070
|
+
var HOLD_FRESH_MS = 10 * 6e4;
|
|
307071
|
+
var HOLD_FIRST_POLL_MS = 250;
|
|
307072
|
+
var HOLD_MAX_POLL_MS = 2e3;
|
|
307073
|
+
function holdMsFrom(env3) {
|
|
307074
|
+
const raw = env3.get("ASSET_SAFETY_HOLD_MS");
|
|
307075
|
+
if (raw === void 0 || raw.trim() === "") return DEFAULT_HOLD_MS;
|
|
307076
|
+
const n3 = Number(raw);
|
|
307077
|
+
return Number.isFinite(n3) && n3 >= 0 ? n3 : DEFAULT_HOLD_MS;
|
|
306949
307078
|
}
|
|
306950
|
-
__name(
|
|
307079
|
+
__name(holdMsFrom, "holdMsFrom");
|
|
307080
|
+
async function readVerdict(vctx, cid) {
|
|
307081
|
+
const s2 = vctx.sql.tables.assetSafety;
|
|
307082
|
+
const r2 = await exception2Result(
|
|
307083
|
+
() => vctx.sql.db.select({ verdict: s2.verdict }).from(s2).where(eq(s2.cid, cid)).limit(1).then((rows) => rows[0])
|
|
307084
|
+
);
|
|
307085
|
+
return r2.isOk() ? r2.Ok()?.verdict : void 0;
|
|
307086
|
+
}
|
|
307087
|
+
__name(readVerdict, "readVerdict");
|
|
307088
|
+
async function holdForVerdict(vctx, a4, first) {
|
|
307089
|
+
const uploaderId = first.uploaderId;
|
|
307090
|
+
const holdMs = holdMsFrom(vctx.sthis.env);
|
|
307091
|
+
const startedAt = Date.now();
|
|
307092
|
+
const sinceMs = Date.parse(first.hold.since);
|
|
307093
|
+
const age = Number.isFinite(sinceMs) ? startedAt - sinceMs : Number.POSITIVE_INFINITY;
|
|
307094
|
+
if (holdMs === 0 || age > HOLD_FRESH_MS) {
|
|
307095
|
+
reportHold(vctx, a4, { outcome: holdMs === 0 ? "timeout" : "stale", waitMs: 0, uploaderId });
|
|
307096
|
+
return first.asset;
|
|
307097
|
+
}
|
|
307098
|
+
const sleep2 = vctx.holdSleep ?? ((ms) => new Promise((r2) => setTimeout(r2, ms)));
|
|
307099
|
+
let every = HOLD_FIRST_POLL_MS;
|
|
307100
|
+
for (; ; ) {
|
|
307101
|
+
const left = holdMs - (Date.now() - startedAt);
|
|
307102
|
+
if (left <= 0) break;
|
|
307103
|
+
await sleep2(Math.min(every, left));
|
|
307104
|
+
const verdict = await readVerdict(vctx, a4.cid);
|
|
307105
|
+
if (verdict !== void 0 && verdict !== "pending") break;
|
|
307106
|
+
every = Math.min(every * 2, HOLD_MAX_POLL_MS);
|
|
307107
|
+
}
|
|
307108
|
+
const final = await resolveOnce(vctx, a4);
|
|
307109
|
+
const waitMs2 = Date.now() - startedAt;
|
|
307110
|
+
const state4 = final.asset.state;
|
|
307111
|
+
const outcome = state4 === "pending" ? "timeout" : state4 === "high" ? "blocked" : state4 === "error" ? "error" : "cleared";
|
|
307112
|
+
reportHold(vctx, a4, { outcome, waitMs: waitMs2, uploaderId: final.uploaderId ?? uploaderId });
|
|
307113
|
+
return final.asset;
|
|
307114
|
+
}
|
|
307115
|
+
__name(holdForVerdict, "holdForVerdict");
|
|
307116
|
+
var GREY_SQUARE_OUTCOMES = ["timeout", "stale", "error"];
|
|
307117
|
+
function reportHold(vctx, a4, r2) {
|
|
307118
|
+
const placeholderServed = GREY_SQUARE_OUTCOMES.includes(r2.outcome);
|
|
307119
|
+
vctx.logger.Info().Str("cid", a4.cid).Str("outcome", r2.outcome).Uint64("waitMs", r2.waitMs).Bool("placeholder", placeholderServed).Msg("asset-safety-hold");
|
|
307120
|
+
const uploaderId = r2.uploaderId;
|
|
307121
|
+
const analyticsFetch = vctx.analyticsFetch;
|
|
307122
|
+
if (uploaderId === void 0 || analyticsFetch === void 0) return;
|
|
307123
|
+
if ((vctx.posthogKey ?? "") === "" || (vctx.posthogHost ?? "") === "") return;
|
|
307124
|
+
const task = (async () => {
|
|
307125
|
+
const countries = await readStampedGeoCountries(vctx.sql, [uploaderId]);
|
|
307126
|
+
const country = countries.get(uploaderId);
|
|
307127
|
+
const actx = {
|
|
307128
|
+
logger: vctx.logger,
|
|
307129
|
+
analyticsFetch,
|
|
307130
|
+
...vctx.posthogKey === void 0 ? {} : { posthogKey: vctx.posthogKey },
|
|
307131
|
+
...vctx.posthogHost === void 0 ? {} : { posthogHost: vctx.posthogHost },
|
|
307132
|
+
...country === void 0 ? {} : { analyticsCountry: country }
|
|
307133
|
+
};
|
|
307134
|
+
await capturePostHogServerEvent(actx, {
|
|
307135
|
+
event: "asset_safety_hold",
|
|
307136
|
+
distinctId: uploaderId,
|
|
307137
|
+
properties: {
|
|
307138
|
+
outcome: r2.outcome,
|
|
307139
|
+
wait_ms: r2.waitMs,
|
|
307140
|
+
placeholder: placeholderServed,
|
|
307141
|
+
mime: a4.mime
|
|
307142
|
+
}
|
|
307143
|
+
});
|
|
307144
|
+
})().catch(() => {
|
|
307145
|
+
});
|
|
307146
|
+
vctx.waitUntil?.(task);
|
|
307147
|
+
}
|
|
307148
|
+
__name(reportHold, "reportHold");
|
|
306951
307149
|
function dataUriBody(uri) {
|
|
306952
307150
|
return decodeURIComponent(uri.slice(uri.indexOf(",") + 1));
|
|
306953
307151
|
}
|
|
@@ -353320,6 +353518,7 @@ var MERCURY_CARDS_SHAPE = `As a <role>, I <action on a named record>, so that <o
|
|
|
353320
353518
|
Data: <Record>{<field>, <field>, ...}
|
|
353321
353519
|
Rule: <a value this card depends on and how it comes about, said loosely in one plain English sentence a friend would understand>`;
|
|
353322
353520
|
var MERCURY_ASK_WORDS_RULE = `Keep the ask's genre and capability words exactly as the person wrote them \u2014 3D, first-person, email, a named recipient, a schedule, a fixed number of people \u2014 in the preamble and the cards.`;
|
|
353521
|
+
var MERCURY_DEVICE_ASK_RULE = `Every app opens from its own link, and nearly every preamble simply says what you're making for them. Only when the person asks for a desktop program, a phone app or software to install does the preamble's sentence after what you're making say how it opens: "it opens in your browser from its own link", or for a phone app "it opens on your phone from its own link". That device word alone gives way, in the preamble and the cards; every other word of the ask stays exactly as the person wrote it.`;
|
|
353323
353522
|
var MERCURY_TYPED_DATA_RULE = `When the person typed data \u2014 items, amounts, names, a list \u2014 the cards carry every piece of it verbatim, quantities included ("half a bag" stays "half a bag").`;
|
|
353324
353523
|
var MERCURY_CARDS_RULES = `Rules:
|
|
353325
353524
|
- Use the person's own nouns for records, roles and actions.
|
|
@@ -353327,7 +353526,8 @@ var MERCURY_CARDS_RULES = `Rules:
|
|
|
353327
353526
|
- A line that rests on your assumption and not on the person's words ends with (guess). A line the person's words settle carries no label.
|
|
353328
353527
|
- ${MERCURY_ASK_WORDS_RULE}
|
|
353329
353528
|
- ${MERCURY_TYPED_DATA_RULE}
|
|
353330
|
-
- ${MERCURY_SELF_HOSTED_HTTPS_RULE}
|
|
353529
|
+
- ${MERCURY_SELF_HOSTED_HTTPS_RULE}
|
|
353530
|
+
- ${MERCURY_DEVICE_ASK_RULE}`;
|
|
353331
353531
|
function mercuryMintMenu(look) {
|
|
353332
353532
|
return look === void 0 ? {} : { look, looks: [...MINTABLE_LOOKS] };
|
|
353333
353533
|
}
|
|
@@ -357574,6 +357774,69 @@ init_esm();
|
|
|
357574
357774
|
init_out4();
|
|
357575
357775
|
init_lazy_type();
|
|
357576
357776
|
|
|
357777
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/backend-path-finding.ts
|
|
357778
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
357779
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
357780
|
+
init_performance2();
|
|
357781
|
+
var SAME_ORIGIN_API = /(["'`])(\/api\/[^"'`\s$?#]*)/;
|
|
357782
|
+
function maskComments(source) {
|
|
357783
|
+
return source.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/(^|\s)\/\/[^\n]*/g, "$1");
|
|
357784
|
+
}
|
|
357785
|
+
__name(maskComments, "maskComments");
|
|
357786
|
+
function blank2(text3) {
|
|
357787
|
+
return text3.replace(/[^\n]/g, " ");
|
|
357788
|
+
}
|
|
357789
|
+
__name(blank2, "blank");
|
|
357790
|
+
function blankComments(source) {
|
|
357791
|
+
return source.replace(/\/\*[\s\S]*?\*\//g, blank2).replace(/(^|\s)(\/\/[^\n]*)/g, (_m, lead, c3) => lead + blank2(c3));
|
|
357792
|
+
}
|
|
357793
|
+
__name(blankComments, "blankComments");
|
|
357794
|
+
function isClientCode(path3) {
|
|
357795
|
+
return /\.(jsx?|tsx?)$/.test(path3) && path3 !== "/backend.js" && path3 !== "/access.js";
|
|
357796
|
+
}
|
|
357797
|
+
__name(isClientCode, "isClientCode");
|
|
357798
|
+
function sameOriginApiFinding(args3) {
|
|
357799
|
+
if (args3.backendHandlers.includes("fetch") === false) return void 0;
|
|
357800
|
+
for (const file2 of args3.changes) {
|
|
357801
|
+
if (isClientCode(file2.path) === false) continue;
|
|
357802
|
+
const match4 = SAME_ORIGIN_API.exec(maskComments(file2.contents));
|
|
357803
|
+
if (match4 !== null) return { path: file2.path, literal: match4[2] };
|
|
357804
|
+
}
|
|
357805
|
+
return void 0;
|
|
357806
|
+
}
|
|
357807
|
+
__name(sameOriginApiFinding, "sameOriginApiFinding");
|
|
357808
|
+
function sameOriginApiMessage(finding) {
|
|
357809
|
+
const fixed = finding.literal.replace(/^\/api\//, "/_api/");
|
|
357810
|
+
return `${finding.path}: calls "${finding.literal}", but backend.js answers at the app's /_api/ URL, so this call gets the app's HTML page and no data. Call "${fixed}" instead.`;
|
|
357811
|
+
}
|
|
357812
|
+
__name(sameOriginApiMessage, "sameOriginApiMessage");
|
|
357813
|
+
var FETCH_SAME_ORIGIN_API = /(\bfetch\(\s*)(["'`])\/api\//g;
|
|
357814
|
+
function repairSameOriginApiCalls(args3) {
|
|
357815
|
+
const backend = args3.vfs.get("/backend.js");
|
|
357816
|
+
if (backend === void 0 || parseBackendConfig(backend).handlers.includes("fetch") === false)
|
|
357817
|
+
return { vfs: args3.vfs, notes: [] };
|
|
357818
|
+
let out;
|
|
357819
|
+
const notes = [];
|
|
357820
|
+
for (const path3 of args3.changedPaths) {
|
|
357821
|
+
const source = args3.vfs.get(path3);
|
|
357822
|
+
if (source === void 0 || isClientCode(path3) === false) continue;
|
|
357823
|
+
const masked = blankComments(source);
|
|
357824
|
+
const starts = [];
|
|
357825
|
+
for (const match4 of masked.matchAll(FETCH_SAME_ORIGIN_API)) {
|
|
357826
|
+
starts.push((match4.index ?? 0) + match4[1].length + 1);
|
|
357827
|
+
}
|
|
357828
|
+
if (starts.length === 0) continue;
|
|
357829
|
+
let repaired = source;
|
|
357830
|
+
for (const start2 of [...starts].reverse())
|
|
357831
|
+
repaired = `${repaired.slice(0, start2)}/_api/${repaired.slice(start2 + "/api/".length)}`;
|
|
357832
|
+
out ??= new Map(args3.vfs);
|
|
357833
|
+
out.set(path3, repaired);
|
|
357834
|
+
notes.push(`${path3}: fetch("/api/\u2026") rewritten to "/_api/\u2026" (${starts.length} ${starts.length === 1 ? "call" : "calls"})`);
|
|
357835
|
+
}
|
|
357836
|
+
return out === void 0 ? { vfs: args3.vfs, notes: [] } : { vfs: out, notes };
|
|
357837
|
+
}
|
|
357838
|
+
__name(repairSameOriginApiCalls, "repairSameOriginApiCalls");
|
|
357839
|
+
|
|
357577
357840
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/work-tools.ts
|
|
357578
357841
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
357579
357842
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
@@ -359106,7 +359369,7 @@ function createFetchUrlToolExecutor(context2, options = {}) {
|
|
|
359106
359369
|
});
|
|
359107
359370
|
const lookChars = look === void 0 ? 0 : JSON.stringify(look).length + 16;
|
|
359108
359371
|
const bounded = boundToolText(distilled.text, MAX_TOOL_TEXT_CHARS - lookChars);
|
|
359109
|
-
const
|
|
359372
|
+
const blank4 = isBlankHtml(distilled);
|
|
359110
359373
|
return Result.Ok(
|
|
359111
359374
|
serialize2({
|
|
359112
359375
|
ok: true,
|
|
@@ -359120,7 +359383,7 @@ function createFetchUrlToolExecutor(context2, options = {}) {
|
|
|
359120
359383
|
truncated: distilled.truncated || bounded.truncated,
|
|
359121
359384
|
...look === void 0 ? {} : { look },
|
|
359122
359385
|
text: bounded.text,
|
|
359123
|
-
...
|
|
359386
|
+
...blank4 ? { blank: true, notice: look === void 0 ? BLANK_PAGE_NOTICE : BLANK_PAGE_WITH_LOOK_NOTICE } : {}
|
|
359124
359387
|
})
|
|
359125
359388
|
);
|
|
359126
359389
|
}, "executor");
|
|
@@ -360737,6 +361000,8 @@ async function validateAgentFiles(vctx, args3) {
|
|
|
360737
361000
|
"backend",
|
|
360738
361001
|
"backend.js runs through a top-level `export async function fetch(request, ctx)`, `scheduled`, `onChange` or an `export const tools = { \u2026 }`; this file exports none of them, so nothing would answer."
|
|
360739
361002
|
);
|
|
361003
|
+
const apiPath = sameOriginApiFinding({ backendHandlers: parsed3.handlers, changes: args3.changes });
|
|
361004
|
+
if (apiPath !== void 0) return refuse12("backend", sameOriginApiMessage(apiPath));
|
|
360740
361005
|
}
|
|
360741
361006
|
const access3 = args3.vfs.get("/access.js");
|
|
360742
361007
|
if (access3 !== void 0 && args3.changes.some((file2) => file2.path === "/access.js")) {
|
|
@@ -363832,10 +364097,10 @@ var NOT_NAME_WORDS = /* @__PURE__ */ new Set([
|
|
|
363832
364097
|
...US_STATES.flatMap((s2) => s2.split(" "))
|
|
363833
364098
|
]);
|
|
363834
364099
|
var NAME_RE = /\b([A-Z][a-z]+(?:[-'][A-Z][a-z]+)?)\s+(?:[A-Z]\.\s+)?([A-Z][a-z]+(?:[-'][A-Z][a-z]+)?)\b/g;
|
|
363835
|
-
function
|
|
364100
|
+
function blank3(text3, re4) {
|
|
363836
364101
|
return text3.replace(re4, (m) => " ".repeat(m.length));
|
|
363837
364102
|
}
|
|
363838
|
-
__name(
|
|
364103
|
+
__name(blank3, "blank");
|
|
363839
364104
|
function matches2(text3, re4) {
|
|
363840
364105
|
return Array.from(text3.matchAll(re4), (m) => m[0]);
|
|
363841
364106
|
}
|
|
@@ -363896,9 +364161,9 @@ function detailKinds(text3) {
|
|
|
363896
364161
|
}
|
|
363897
364162
|
__name(detailKinds, "detailKinds");
|
|
363898
364163
|
function hasPersonName(text3) {
|
|
363899
|
-
let masked =
|
|
363900
|
-
masked =
|
|
363901
|
-
masked =
|
|
364164
|
+
let masked = blank3(text3, ENTITY_RE);
|
|
364165
|
+
masked = blank3(masked, STREET_RE);
|
|
364166
|
+
masked = blank3(masked, REGISTERED_IN_RE);
|
|
363902
364167
|
for (const m of masked.matchAll(NAME_RE)) {
|
|
363903
364168
|
const [first, last] = [m[1], m[2]];
|
|
363904
364169
|
if (NOT_NAME_WORDS.has(first) || NOT_NAME_WORDS.has(last)) continue;
|
|
@@ -366402,7 +366667,7 @@ async function resendChatSectionsPrevMsg(args3) {
|
|
|
366402
366667
|
__name(resendChatSectionsPrevMsg, "resendChatSectionsPrevMsg");
|
|
366403
366668
|
async function* readChatReplaySections(vctx, args3) {
|
|
366404
366669
|
const rows = await vctx.sql.db.select().from(vctx.sql.tables.chatSections).where(selectedChatTurns(vctx, args3.chatId, args3.promptIds)).orderBy(vctx.sql.tables.chatSections.created, vctx.sql.tables.chatSections.promptId, vctx.sql.tables.chatSections.blockSeq);
|
|
366405
|
-
const sections = rows
|
|
366670
|
+
const sections = rows;
|
|
366406
366671
|
const promptContextRows = await vctx.sql.db.select({ promptId: vctx.sql.tables.promptContexts.promptId, ref: vctx.sql.tables.promptContexts.ref }).from(vctx.sql.tables.promptContexts).where(
|
|
366407
366672
|
and(
|
|
366408
366673
|
eq(vctx.sql.tables.promptContexts.chatId, args3.chatId),
|
|
@@ -366430,7 +366695,7 @@ async function* readChatReplaySections(vctx, args3) {
|
|
|
366430
366695
|
const receipts = args3.promptIds === void 0 ? /* @__PURE__ */ new Set() : receiptReplayTurnIds(sections.map((section) => ({ promptId: section.promptId, blocks: section.blocks })));
|
|
366431
366696
|
const openedReceipts = /* @__PURE__ */ new Set();
|
|
366432
366697
|
for (const section of sections) {
|
|
366433
|
-
const { filtered: parsedBlocks, warning } = parseArrayWarning(section.blocks, PromptAndBlockMsgs);
|
|
366698
|
+
const { filtered: parsedBlocks, warning } = parseArrayWarning(expandChatSectionBlocks(section.blocks), PromptAndBlockMsgs);
|
|
366434
366699
|
const blocks = parsedBlocks.filter((block) => !isPromptResearch(block));
|
|
366435
366700
|
if (warning.length > 0) {
|
|
366436
366701
|
ensureLogger(vctx.sthis, "resendChatSectionsPrevMsg").Warn().Any({ parseErrors: warning }).Msg("skip");
|
|
@@ -367811,6 +368076,102 @@ function historySectionMsgs(blocks) {
|
|
|
367811
368076
|
return { msgs, warning };
|
|
367812
368077
|
}
|
|
367813
368078
|
__name(historySectionMsgs, "historySectionMsgs");
|
|
368079
|
+
function isCodeSummaryMsg(msg) {
|
|
368080
|
+
return typeof msg === "object" && msg !== null && msg.type === "history.code.summary";
|
|
368081
|
+
}
|
|
368082
|
+
__name(isCodeSummaryMsg, "isCodeSummaryMsg");
|
|
368083
|
+
var HISTORY_PAGE_ROWS = 200;
|
|
368084
|
+
async function readChatHistory(vctx, chatId, opts) {
|
|
368085
|
+
const t3 = vctx.sql.tables.chatSections;
|
|
368086
|
+
const pageRows = opts.pageRows ?? HISTORY_PAGE_ROWS;
|
|
368087
|
+
const reducer = historyReducer(opts.compact);
|
|
368088
|
+
const keys = await vctx.sql.db.select({ promptId: t3.promptId, blockSeq: t3.blockSeq, created: t3.created }).from(t3).where(and(eq(t3.chatId, chatId), ne(t3.blockSeq, RESEARCH_BLOCK_SEQ)));
|
|
368089
|
+
keys.sort(compareSectionKeys);
|
|
368090
|
+
for (let start2 = 0; start2 < keys.length; start2 += pageRows) {
|
|
368091
|
+
const pageKeys = keys.slice(start2, start2 + pageRows);
|
|
368092
|
+
const want = new Set(pageKeys.map(sectionKey));
|
|
368093
|
+
const rows = await vctx.sql.db.select({ promptId: t3.promptId, blockSeq: t3.blockSeq, blocks: t3.blocks }).from(t3).where(
|
|
368094
|
+
and(
|
|
368095
|
+
eq(t3.chatId, chatId),
|
|
368096
|
+
inArray(t3.promptId, [...new Set(pageKeys.map((k4) => k4.promptId))]),
|
|
368097
|
+
inArray(t3.blockSeq, [...new Set(pageKeys.map((k4) => k4.blockSeq))])
|
|
368098
|
+
)
|
|
368099
|
+
);
|
|
368100
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
368101
|
+
for (const row of rows) {
|
|
368102
|
+
const key = sectionKey(row);
|
|
368103
|
+
if (want.has(key)) byKey.set(key, row.blocks);
|
|
368104
|
+
}
|
|
368105
|
+
for (const k4 of pageKeys) {
|
|
368106
|
+
const { msgs, warning } = historySectionMsgs(byKey.get(sectionKey(k4)));
|
|
368107
|
+
if (warning.length > 0) opts.onWarning?.(warning);
|
|
368108
|
+
for (const msg of msgs) reducer.push(msg);
|
|
368109
|
+
}
|
|
368110
|
+
}
|
|
368111
|
+
return reducer.done();
|
|
368112
|
+
}
|
|
368113
|
+
__name(readChatHistory, "readChatHistory");
|
|
368114
|
+
function sectionKey(k4) {
|
|
368115
|
+
return `${k4.promptId}\0${k4.blockSeq}`;
|
|
368116
|
+
}
|
|
368117
|
+
__name(sectionKey, "sectionKey");
|
|
368118
|
+
function compareSectionKeys(a4, b4) {
|
|
368119
|
+
if (a4.created !== b4.created) return a4.created < b4.created ? -1 : 1;
|
|
368120
|
+
if (a4.promptId !== b4.promptId) return a4.promptId < b4.promptId ? -1 : 1;
|
|
368121
|
+
return a4.blockSeq - b4.blockSeq;
|
|
368122
|
+
}
|
|
368123
|
+
__name(compareSectionKeys, "compareSectionKeys");
|
|
368124
|
+
function keepForHistory(msg) {
|
|
368125
|
+
return isPromptReq(msg) || isToplevelLine(msg) || isCodeBegin(msg) || isCodeEnd(msg) || isCodeLine(msg) || isCodeLinesMsg(msg) || isPromptAgentEvidence(msg) && msg.evidence.kind === "active";
|
|
368126
|
+
}
|
|
368127
|
+
__name(keepForHistory, "keepForHistory");
|
|
368128
|
+
function historyReducer(compact) {
|
|
368129
|
+
const out = [];
|
|
368130
|
+
let inBlock = false;
|
|
368131
|
+
let summary;
|
|
368132
|
+
function line3(text3) {
|
|
368133
|
+
summary ??= { lineCount: 0, hunkCount: 0 };
|
|
368134
|
+
summary.lineCount++;
|
|
368135
|
+
const trimmed2 = text3.trim();
|
|
368136
|
+
if (trimmed2 === "<<<<<<< SEARCH") summary.hunkCount++;
|
|
368137
|
+
if (summary.firstNonBlank === void 0 && trimmed2.length > 0) summary.firstNonBlank = trimmed2;
|
|
368138
|
+
}
|
|
368139
|
+
__name(line3, "line");
|
|
368140
|
+
function flush3() {
|
|
368141
|
+
if (summary === void 0) return;
|
|
368142
|
+
out.push({ type: "history.code.summary", ...summary });
|
|
368143
|
+
summary = void 0;
|
|
368144
|
+
}
|
|
368145
|
+
__name(flush3, "flush");
|
|
368146
|
+
return {
|
|
368147
|
+
push(msg) {
|
|
368148
|
+
if (!keepForHistory(msg)) return;
|
|
368149
|
+
if (compact && inBlock) {
|
|
368150
|
+
if (isCodeLinesMsg(msg)) {
|
|
368151
|
+
for (const l3 of msg.lines) line3(l3);
|
|
368152
|
+
return;
|
|
368153
|
+
}
|
|
368154
|
+
if (isCodeLine(msg)) {
|
|
368155
|
+
line3(msg.line);
|
|
368156
|
+
return;
|
|
368157
|
+
}
|
|
368158
|
+
}
|
|
368159
|
+
if (compact && isCodeBegin(msg)) {
|
|
368160
|
+
flush3();
|
|
368161
|
+
inBlock = true;
|
|
368162
|
+
} else if (compact && isCodeEnd(msg)) {
|
|
368163
|
+
flush3();
|
|
368164
|
+
inBlock = false;
|
|
368165
|
+
}
|
|
368166
|
+
out.push(msg);
|
|
368167
|
+
},
|
|
368168
|
+
done() {
|
|
368169
|
+
flush3();
|
|
368170
|
+
return out;
|
|
368171
|
+
}
|
|
368172
|
+
};
|
|
368173
|
+
}
|
|
368174
|
+
__name(historyReducer, "historyReducer");
|
|
367814
368175
|
|
|
367815
368176
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/prompt-assembly.ts
|
|
367816
368177
|
function escapeAttrValue(value2) {
|
|
@@ -367864,6 +368225,14 @@ function reconstructConversationMessages(sectionMsgs, opts = {}) {
|
|
|
367864
368225
|
for (const line3 of msg.lines) codeLine(line3);
|
|
367865
368226
|
continue;
|
|
367866
368227
|
}
|
|
368228
|
+
if (isCodeSummaryMsg(msg)) {
|
|
368229
|
+
if (blockBuffer) {
|
|
368230
|
+
blockBuffer.lineCount += msg.lineCount;
|
|
368231
|
+
blockBuffer.hunkCount += msg.hunkCount;
|
|
368232
|
+
if (!blockBuffer.firstNonBlank && msg.firstNonBlank !== void 0) blockBuffer.firstNonBlank = msg.firstNonBlank;
|
|
368233
|
+
}
|
|
368234
|
+
continue;
|
|
368235
|
+
}
|
|
367867
368236
|
switch (true) {
|
|
367868
368237
|
case isPromptReq(msg): {
|
|
367869
368238
|
const users = msg.request.messages.filter(isUserChatMessage);
|
|
@@ -368080,8 +368449,13 @@ __name(loadChatOwnerAndResearch, "loadChatOwnerAndResearch");
|
|
|
368080
368449
|
async function assemblePromptPayload(vctx, args3) {
|
|
368081
368450
|
const { chatId, model, newUserMessages } = args3;
|
|
368082
368451
|
const [sSections, sTimeline, sStored, sOwner, sActive] = await Promise.all([
|
|
368452
|
+
// Paged and reduced as it is read, so a long chat's rows are never all in
|
|
368453
|
+
// memory at once (history-section-msgs.ts `readChatHistory`).
|
|
368083
368454
|
settleRead(
|
|
368084
|
-
|
|
368455
|
+
readChatHistory(vctx, chatId, {
|
|
368456
|
+
compact: args3.slots?.compaction !== "off",
|
|
368457
|
+
onWarning: /* @__PURE__ */ __name((parseErrors) => ensureLogger(vctx.sthis, "assemblePromptPayload").Warn().Any({ parseErrors }).Msg("skip"), "onWarning")
|
|
368458
|
+
})
|
|
368085
368459
|
),
|
|
368086
368460
|
// #6870: the timeline is metadata; only the versions rendered below (the
|
|
368087
368461
|
// slot sources and a `selected` version) have their contents fetched.
|
|
@@ -368091,16 +368465,7 @@ async function assemblePromptPayload(vctx, args3) {
|
|
|
368091
368465
|
settleRead(loadActiveSettings(vctx, chatId))
|
|
368092
368466
|
]);
|
|
368093
368467
|
if (sSections.isErr()) return Result.Err(sSections.Err());
|
|
368094
|
-
const
|
|
368095
|
-
const allSectionMsgs = [];
|
|
368096
|
-
for (const rowSection of sections) {
|
|
368097
|
-
const { msgs: parsedSectionMsgs, warning: sectionWarning } = historySectionMsgs(rowSection.blocks);
|
|
368098
|
-
const sectionMsgs = parsedSectionMsgs.filter((block) => !isPromptResearch(block) && !isPromptStatus(block));
|
|
368099
|
-
if (sectionWarning.length > 0) {
|
|
368100
|
-
ensureLogger(vctx.sthis, "assemblePromptPayload").Warn().Any({ parseErrors: sectionWarning }).Msg("skip");
|
|
368101
|
-
}
|
|
368102
|
-
allSectionMsgs.push(...sectionMsgs);
|
|
368103
|
-
}
|
|
368468
|
+
const allSectionMsgs = sSections.Ok().value;
|
|
368104
368469
|
if (sTimeline.isErr()) return Result.Err(sTimeline.Err());
|
|
368105
368470
|
const timelineResult = sTimeline.Ok().value;
|
|
368106
368471
|
if (timelineResult.isErr()) return Result.Err(timelineResult);
|
|
@@ -370425,6 +370790,7 @@ async function handlePromptContext({
|
|
|
370425
370790
|
resolvedFileSystem = synthesized.files;
|
|
370426
370791
|
importSynthNotes = synthesized.notes;
|
|
370427
370792
|
importSynthUnknownLook = synthesized.unknownLookExports;
|
|
370793
|
+
resolvedFileSystem = repairBackendApiPaths(vctx, promptId, resolvedFileSystem, [...changedPaths]);
|
|
370428
370794
|
const stagedSources = /* @__PURE__ */ __name((files) => files.filter((file2) => file2.type === "code-block").filter((file2) => file2.filename.startsWith("/~~") === false), "stagedSources");
|
|
370429
370795
|
const stagedChanges = /* @__PURE__ */ __name((files) => stagedSources(files).filter((file2) => changedPaths.has(file2.filename)).map((file2) => ({ path: file2.filename, contents: file2.content })), "stagedChanges");
|
|
370430
370796
|
let sources = stagedSources(resolvedFileSystem);
|
|
@@ -370832,6 +371198,21 @@ async function readColorTheme(vctx, ownerHandle, appSlug) {
|
|
|
370832
371198
|
return rEntries.Ok().filter(isActiveColorTheme).at(-1)?.colorTheme;
|
|
370833
371199
|
}
|
|
370834
371200
|
__name(readColorTheme, "readColorTheme");
|
|
371201
|
+
function repairBackendApiPaths(vctx, promptId, files, changedPaths) {
|
|
371202
|
+
const sources = /* @__PURE__ */ new Map();
|
|
371203
|
+
for (const file2 of files) {
|
|
371204
|
+
if (file2.type === "code-block" && file2.filename.startsWith("/~~") === false) sources.set(file2.filename, file2.content);
|
|
371205
|
+
}
|
|
371206
|
+
const repaired = repairSameOriginApiCalls({ vfs: sources, changedPaths });
|
|
371207
|
+
if (repaired.notes.length === 0) return files;
|
|
371208
|
+
vctx.logger.Info().Str("promptId", promptId).Any("notes", repaired.notes).Msg("backend-api-path-repaired");
|
|
371209
|
+
return files.map((file2) => {
|
|
371210
|
+
if (file2.type !== "code-block") return file2;
|
|
371211
|
+
const content = repaired.vfs.get(file2.filename);
|
|
371212
|
+
return content === void 0 || content === file2.content ? file2 : { ...file2, content };
|
|
371213
|
+
});
|
|
371214
|
+
}
|
|
371215
|
+
__name(repairBackendApiPaths, "repairBackendApiPaths");
|
|
370835
371216
|
|
|
370836
371217
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/public/handler-llm-request.ts
|
|
370837
371218
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
@@ -377109,24 +377490,17 @@ function messagesCarryRefusedUrl(newUserMessages) {
|
|
|
377109
377490
|
__name(messagesCarryRefusedUrl, "messagesCarryRefusedUrl");
|
|
377110
377491
|
async function assembleAgentPayload(vctx, args3) {
|
|
377111
377492
|
const pChatOwner = vctx.sql.db.select({ userId: vctx.sql.tables.chatContexts.userId }).from(vctx.sql.tables.chatContexts).where(eq(vctx.sql.tables.chatContexts.chatId, args3.chatId)).limit(1).then((rows) => rows[0]);
|
|
377112
|
-
const pSections =
|
|
377493
|
+
const pSections = readChatHistory(vctx, args3.chatId, {
|
|
377494
|
+
compact: true,
|
|
377495
|
+
onWarning: /* @__PURE__ */ __name((parseErrors) => ensureLogger(vctx.sthis, "assembleAgentPayload").Warn().Any({ parseErrors }).Msg("skip"), "onWarning")
|
|
377496
|
+
});
|
|
377113
377497
|
const pTimeline = loadVersionTimeline(vctx, args3.chatId);
|
|
377114
377498
|
void pSections.catch(() => void 0);
|
|
377115
377499
|
const chatOwner = await pChatOwner;
|
|
377116
377500
|
if (chatOwner !== void 0 && chatOwner.userId !== args3.userId) {
|
|
377117
377501
|
return Result.Err("chat_not_owned");
|
|
377118
377502
|
}
|
|
377119
|
-
const
|
|
377120
|
-
const allSectionMsgs = [];
|
|
377121
|
-
for (const rowSection of sections) {
|
|
377122
|
-
const { msgs: filtered, warning } = historySectionMsgs(rowSection.blocks);
|
|
377123
|
-
if (warning.length > 0) {
|
|
377124
|
-
ensureLogger(vctx.sthis, "assembleAgentPayload").Warn().Any({ parseErrors: warning }).Msg("skip");
|
|
377125
|
-
}
|
|
377126
|
-
allSectionMsgs.push(
|
|
377127
|
-
...filtered.filter((block) => !isPromptResearch(block) && !isPromptStatus(block) && !isPromptProgressLabel(block))
|
|
377128
|
-
);
|
|
377129
|
-
}
|
|
377503
|
+
const allSectionMsgs = await pSections;
|
|
377130
377504
|
const { messages: reconstructed } = reconstructConversationMessages(allSectionMsgs, { compact: true });
|
|
377131
377505
|
const alternativeLabel = alternativeReadyLabel(allSectionMsgs);
|
|
377132
377506
|
const alternative = alternativeLabel === void 0 ? [] : [alternativeContextLine(alternativeLabel)];
|
|
@@ -379995,6 +380369,892 @@ function createAgentRestoreTool(vctx, args3) {
|
|
|
379995
380369
|
}
|
|
379996
380370
|
__name(createAgentRestoreTool, "createAgentRestoreTool");
|
|
379997
380371
|
|
|
380372
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/unfinished-first-ask.ts
|
|
380373
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
380374
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
380375
|
+
init_performance2();
|
|
380376
|
+
|
|
380377
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/mercury-first-build-seam.ts
|
|
380378
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
380379
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
380380
|
+
init_performance2();
|
|
380381
|
+
init_esm();
|
|
380382
|
+
|
|
380383
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/server-first-build.ts
|
|
380384
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
380385
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
380386
|
+
init_performance2();
|
|
380387
|
+
|
|
380388
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/first-build-classifier.ts
|
|
380389
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
380390
|
+
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
380391
|
+
init_performance2();
|
|
380392
|
+
init_esm();
|
|
380393
|
+
init_out4();
|
|
380394
|
+
init_lazy_type();
|
|
380395
|
+
var FIRST_BUILD_CLASSIFIER_MODEL = "google/gemini-3.5-flash-lite";
|
|
380396
|
+
var FIRST_BUILD_CLASSIFIER_REASONING = { effort: "minimal" };
|
|
380397
|
+
var FIRST_BUILD_CLASSIFIER_CAP_MS = 5e3;
|
|
380398
|
+
var FIRST_BUILD_CLASSIFIER_HEDGE_AFTER_MS = 2500;
|
|
380399
|
+
var ASK_CLASSIFIER_INPUT_MAX_CHARS = 500;
|
|
380400
|
+
var ASK_CLASSIFIER_MAX_TOKENS = 256;
|
|
380401
|
+
var ALWAYS_PRESENT_SKILLS = /* @__PURE__ */ new Set(["fireproof", "image-gen", "use-vibe", "use-viewer"]);
|
|
380402
|
+
var SERVER_FIRST_BUILD_ACCESS_SKILL = "access";
|
|
380403
|
+
var SKILL_LINE_MAX_CHARS = 110;
|
|
380404
|
+
function shortDescription(description) {
|
|
380405
|
+
const flat = description.replace(/\s+/g, " ").trim();
|
|
380406
|
+
if (flat.length <= SKILL_LINE_MAX_CHARS) return flat;
|
|
380407
|
+
const cut = flat.slice(0, SKILL_LINE_MAX_CHARS);
|
|
380408
|
+
const space = cut.lastIndexOf(" ");
|
|
380409
|
+
return `${space > 40 ? cut.slice(0, space) : cut}\u2026`;
|
|
380410
|
+
}
|
|
380411
|
+
__name(shortDescription, "shortDescription");
|
|
380412
|
+
async function firstBuildSkillMenu(opts) {
|
|
380413
|
+
const catalog = await getLlmCatalog();
|
|
380414
|
+
return catalog.filter((c3) => onSkillMenu(c3)).filter((c3) => ALWAYS_PRESENT_SKILLS.has(c3.name) === false && c3.name !== SERVER_FIRST_BUILD_ACCESS_SKILL).filter((c3) => skillAllowedOnLook(c3.name, opts.look)).map((c3) => `- ${c3.name}: ${shortDescription(c3.description)}`).join("\n");
|
|
380415
|
+
}
|
|
380416
|
+
__name(firstBuildSkillMenu, "firstBuildSkillMenu");
|
|
380417
|
+
var CLASSIFIER_INTRO = "Read one message a person sent to an app builder and fill the schema.";
|
|
380418
|
+
var BUILD_RULE = "build: true when the message describes an app, tool, game, page, tracker or anything else to make \u2014 however short \u2014 and when it names a subject to learn, explore or practise (teach me about volcanoes, explain compound interest, how to bake bread): that subject is the app. build: false for a greeting, a question about the builder itself, or a message with no subject at all.";
|
|
380419
|
+
function firstBuildClassifierMessage(personWords, skillMenu) {
|
|
380420
|
+
return [
|
|
380421
|
+
CLASSIFIER_INTRO,
|
|
380422
|
+
BUILD_RULE,
|
|
380423
|
+
'skills: the names from the list below that the app needs, exactly as written; an empty list when none fit. "backend" for schedules, email, fetching, notifications and server work; "callai" for record intake by sentence, a chat reply, a suggestion or any text the page asks the model for itself. Access rules ride every build already.',
|
|
380424
|
+
"pairs: three title/slug pairs ranked by fit \u2014 a Title Case title of one to four words, and a kebab-case slug made from it.",
|
|
380425
|
+
"iconDescription: one short line naming what the app's icon shows, such as 'a fox on a record player'.",
|
|
380426
|
+
"keepsToThemselves: true when the message keeps the app to the person who asked \u2014 just for me, private to me, single-user, no sharing; false otherwise (a private chef or private lessons app serves customers), a diary or health app included unless its words say so.",
|
|
380427
|
+
'nature: "sensitive" for private record-keeping (a diary, health, money), for records a professional keeps about the people they serve, shared with a team or not (client, patient, case, student or tenant notes), and for every keepsToThemselves message; "open" for a light toy anyone can play with, or a message asking for no access control or for anyone to edit; "collaborative" for everything else. When a message both keeps the app to the person and asks for no access control, keepsToThemselves decides and nature is sensitive.',
|
|
380428
|
+
"",
|
|
380429
|
+
"Skills:",
|
|
380430
|
+
skillMenu,
|
|
380431
|
+
"",
|
|
380432
|
+
"Message:",
|
|
380433
|
+
personWords
|
|
380434
|
+
].join("\n");
|
|
380435
|
+
}
|
|
380436
|
+
__name(firstBuildClassifierMessage, "firstBuildClassifierMessage");
|
|
380437
|
+
var firstBuildClassifierSchema = {
|
|
380438
|
+
name: "first_build",
|
|
380439
|
+
required: ["build", "skills", "pairs", "iconDescription", "nature", "keepsToThemselves"],
|
|
380440
|
+
properties: {
|
|
380441
|
+
build: { type: "boolean" },
|
|
380442
|
+
skills: { type: "array", items: { type: "string" } },
|
|
380443
|
+
pairs: {
|
|
380444
|
+
type: "array",
|
|
380445
|
+
items: { type: "object", properties: { title: { type: "string" }, slug: { type: "string" } } }
|
|
380446
|
+
},
|
|
380447
|
+
iconDescription: { type: "string" },
|
|
380448
|
+
nature: { type: "string", enum: ["sensitive", "collaborative", "open"] },
|
|
380449
|
+
keepsToThemselves: { type: "boolean" }
|
|
380450
|
+
}
|
|
380451
|
+
};
|
|
380452
|
+
function askClassifierMessage(personWords) {
|
|
380453
|
+
return [CLASSIFIER_INTRO, BUILD_RULE, "", "Message:", personWords.slice(0, ASK_CLASSIFIER_INPUT_MAX_CHARS)].join("\n");
|
|
380454
|
+
}
|
|
380455
|
+
__name(askClassifierMessage, "askClassifierMessage");
|
|
380456
|
+
var askClassifierSchema = {
|
|
380457
|
+
name: "app_ask",
|
|
380458
|
+
required: ["build"],
|
|
380459
|
+
properties: { build: { type: "boolean" } }
|
|
380460
|
+
};
|
|
380461
|
+
var firstBuildParsed = lazyType(
|
|
380462
|
+
() => type({
|
|
380463
|
+
build: "boolean",
|
|
380464
|
+
"skills?": "string[]",
|
|
380465
|
+
"pairs?": type({ "title?": "string", "slug?": "string" }).array(),
|
|
380466
|
+
"iconDescription?": "string",
|
|
380467
|
+
"nature?": "string",
|
|
380468
|
+
"keepsToThemselves?": "boolean"
|
|
380469
|
+
})
|
|
380470
|
+
);
|
|
380471
|
+
var askParsed = lazyType(() => type({ build: "boolean" }));
|
|
380472
|
+
function parseFirstBuildVerdict(raw, meta3) {
|
|
380473
|
+
const parsed3 = firstBuildParsed(raw);
|
|
380474
|
+
if (parsed3 instanceof type.errors) return Result.Err(`first-build classifier: schema validation failed: ${parsed3.summary}`);
|
|
380475
|
+
const pairs2 = (parsed3.pairs ?? []).flatMap((p3) => {
|
|
380476
|
+
const title2 = (p3.title ?? "").trim();
|
|
380477
|
+
const slug = (p3.slug ?? "").trim();
|
|
380478
|
+
return title2.length > 0 && slug.length > 0 ? [{ title: title2, slug }] : [];
|
|
380479
|
+
});
|
|
380480
|
+
const icon = (parsed3.iconDescription ?? "").trim();
|
|
380481
|
+
const keepsToThemselves2 = parsed3.keepsToThemselves === true;
|
|
380482
|
+
const nature = keepsToThemselves2 ? "sensitive" : AppNature(parsed3.nature);
|
|
380483
|
+
return Result.Ok({
|
|
380484
|
+
build: parsed3.build,
|
|
380485
|
+
skills: (parsed3.skills ?? []).map((s2) => s2.trim()).filter((s2) => s2.length > 0),
|
|
380486
|
+
pairs: pairs2,
|
|
380487
|
+
...icon.length === 0 ? {} : { iconDescription: icon },
|
|
380488
|
+
...nature instanceof type.errors ? {} : { nature },
|
|
380489
|
+
keepsToThemselves: keepsToThemselves2,
|
|
380490
|
+
model: meta3.model,
|
|
380491
|
+
...meta3.usage === void 0 ? {} : { usage: meta3.usage },
|
|
380492
|
+
elapsedMs: meta3.elapsedMs
|
|
380493
|
+
});
|
|
380494
|
+
}
|
|
380495
|
+
__name(parseFirstBuildVerdict, "parseFirstBuildVerdict");
|
|
380496
|
+
function parseAskVerdict(raw, meta3) {
|
|
380497
|
+
const parsed3 = askParsed(raw);
|
|
380498
|
+
if (parsed3 instanceof type.errors) return Result.Err(`ask classifier: schema validation failed: ${parsed3.summary}`);
|
|
380499
|
+
return Result.Ok({
|
|
380500
|
+
build: parsed3.build,
|
|
380501
|
+
model: meta3.model,
|
|
380502
|
+
...meta3.usage === void 0 ? {} : { usage: meta3.usage },
|
|
380503
|
+
elapsedMs: meta3.elapsedMs
|
|
380504
|
+
});
|
|
380505
|
+
}
|
|
380506
|
+
__name(parseAskVerdict, "parseAskVerdict");
|
|
380507
|
+
function serverFirstBuildBrief(personWords, o4) {
|
|
380508
|
+
return [
|
|
380509
|
+
`This first build is group-ready: ${GROUP_READY_SHAPE}`,
|
|
380510
|
+
`${INVITE_SCREEN_WHEN}; every other first build leaves it as an option for later.`,
|
|
380511
|
+
// Owner policy 2026-10-12: the viral baseline — a way to share ships on the first screen. Owner
|
|
380512
|
+
// direction 2026-10-15: its shape follows what one record is (a collection shared by adding a
|
|
380513
|
+
// friend, a piece published, a thing on an always-on channel).
|
|
380514
|
+
SHARING_BASELINE,
|
|
380515
|
+
// Owner decision 2026-10-08: a just-for-me app keeps its rules — one collection per person,
|
|
380516
|
+
// shared whole by its add-a-friend control (owner direction 2026-10-15).
|
|
380517
|
+
...o4.keepsToThemselves ? [ONE_TREE_PER_PERSON] : [],
|
|
380518
|
+
`Sample content: ${SEED_DEMO_RULE}`,
|
|
380519
|
+
KNOWN_VALUES_DIRECT_CONTROLS,
|
|
380520
|
+
`The person asked: "${personWords}". Plan the app from their words.`
|
|
380521
|
+
].join("\n");
|
|
380522
|
+
}
|
|
380523
|
+
__name(serverFirstBuildBrief, "serverFirstBuildBrief");
|
|
380524
|
+
function serverFirstBuildSkills(verdict) {
|
|
380525
|
+
const picked = verdict.skills.filter((s2) => s2 !== SERVER_FIRST_BUILD_ACCESS_SKILL);
|
|
380526
|
+
return verdict.skills.includes(SERVER_FIRST_BUILD_ACCESS_SKILL) ? [...verdict.skills] : [...picked, SERVER_FIRST_BUILD_ACCESS_SKILL];
|
|
380527
|
+
}
|
|
380528
|
+
__name(serverFirstBuildSkills, "serverFirstBuildSkills");
|
|
380529
|
+
function createVibeInputFromVerdict(personWords, verdict) {
|
|
380530
|
+
return {
|
|
380531
|
+
prompt: personWords,
|
|
380532
|
+
enrichedPrompt: serverFirstBuildBrief(personWords, { keepsToThemselves: verdict.keepsToThemselves }),
|
|
380533
|
+
skills: serverFirstBuildSkills(verdict),
|
|
380534
|
+
pairs: verdict.pairs.map((p3) => ({ ...p3 })),
|
|
380535
|
+
...verdict.iconDescription === void 0 ? {} : { iconDescription: verdict.iconDescription },
|
|
380536
|
+
...verdict.nature === void 0 ? {} : { nature: verdict.nature }
|
|
380537
|
+
};
|
|
380538
|
+
}
|
|
380539
|
+
__name(createVibeInputFromVerdict, "createVibeInputFromVerdict");
|
|
380540
|
+
function numberField(o4, key) {
|
|
380541
|
+
const v3 = o4[key];
|
|
380542
|
+
return typeof v3 === "number" && Number.isFinite(v3) ? v3 : void 0;
|
|
380543
|
+
}
|
|
380544
|
+
__name(numberField, "numberField");
|
|
380545
|
+
function readEcho(json6, echo) {
|
|
380546
|
+
if (typeof json6 !== "object" || json6 === null) return;
|
|
380547
|
+
const body = json6;
|
|
380548
|
+
if (typeof body.model === "string") echo.model = body.model;
|
|
380549
|
+
const choice = Array.isArray(body.choices) ? body.choices[0] : void 0;
|
|
380550
|
+
if (typeof choice === "object" && choice !== null) {
|
|
380551
|
+
const finish = choice.finish_reason;
|
|
380552
|
+
if (typeof finish === "string") echo.finishReason = finish;
|
|
380553
|
+
}
|
|
380554
|
+
const usage = body.usage;
|
|
380555
|
+
if (typeof usage !== "object" || usage === null) return;
|
|
380556
|
+
const u3 = usage;
|
|
380557
|
+
const prompt = numberField(u3, "prompt_tokens");
|
|
380558
|
+
const completion2 = numberField(u3, "completion_tokens");
|
|
380559
|
+
if (prompt === void 0 || completion2 === void 0) return;
|
|
380560
|
+
const cost = numberField(u3, "cost");
|
|
380561
|
+
echo.usage = {
|
|
380562
|
+
prompt_tokens: prompt,
|
|
380563
|
+
completion_tokens: completion2,
|
|
380564
|
+
total_tokens: numberField(u3, "total_tokens") ?? prompt + completion2,
|
|
380565
|
+
...cost === void 0 ? {} : { cost }
|
|
380566
|
+
};
|
|
380567
|
+
}
|
|
380568
|
+
__name(readEcho, "readEcho");
|
|
380569
|
+
function classifierFetch(inner, signal, echo) {
|
|
380570
|
+
return async (input3, init2) => {
|
|
380571
|
+
const body = typeof init2?.body === "string" ? init2.body : void 0;
|
|
380572
|
+
const rBody = body === void 0 ? void 0 : exception2Result(() => JSON.parse(body));
|
|
380573
|
+
const patchedBody = rBody !== void 0 && rBody.isOk() ? JSON.stringify({ ...rBody.Ok(), reasoning: { ...FIRST_BUILD_CLASSIFIER_REASONING }, usage: { include: true } }) : body;
|
|
380574
|
+
const rRes = await exception2Result(
|
|
380575
|
+
() => inner(input3, { ...init2, ...patchedBody === void 0 ? {} : { body: patchedBody }, signal })
|
|
380576
|
+
);
|
|
380577
|
+
if (rRes.isErr()) {
|
|
380578
|
+
echo.networkError = rRes.Err().message;
|
|
380579
|
+
throw rRes.Err();
|
|
380580
|
+
}
|
|
380581
|
+
const res = rRes.Ok();
|
|
380582
|
+
echo.status = res.status;
|
|
380583
|
+
const rJson = await exception2Result(() => res.clone().json());
|
|
380584
|
+
if (rJson.isOk()) readEcho(rJson.Ok(), echo);
|
|
380585
|
+
return res;
|
|
380586
|
+
};
|
|
380587
|
+
}
|
|
380588
|
+
__name(classifierFetch, "classifierFetch");
|
|
380589
|
+
async function classifyFirstBuild(vctx, args3) {
|
|
380590
|
+
return runClassifier(vctx, args3, {
|
|
380591
|
+
call: "first-build",
|
|
380592
|
+
message: /* @__PURE__ */ __name(async (words) => firstBuildClassifierMessage(words, await firstBuildSkillMenu({ look: MINT_LOOK })), "message"),
|
|
380593
|
+
schema: { ...firstBuildClassifierSchema, required: [...firstBuildClassifierSchema.required] },
|
|
380594
|
+
parse: parseFirstBuildVerdict
|
|
380595
|
+
});
|
|
380596
|
+
}
|
|
380597
|
+
__name(classifyFirstBuild, "classifyFirstBuild");
|
|
380598
|
+
async function classifyAsk(vctx, args3) {
|
|
380599
|
+
return runClassifier(vctx, args3, {
|
|
380600
|
+
call: "ask",
|
|
380601
|
+
message: /* @__PURE__ */ __name(async (words) => askClassifierMessage(words), "message"),
|
|
380602
|
+
schema: { ...askClassifierSchema, required: [...askClassifierSchema.required] },
|
|
380603
|
+
maxTokens: ASK_CLASSIFIER_MAX_TOKENS,
|
|
380604
|
+
parse: parseAskVerdict
|
|
380605
|
+
});
|
|
380606
|
+
}
|
|
380607
|
+
__name(classifyAsk, "classifyAsk");
|
|
380608
|
+
async function runClassifier(vctx, args3, spec) {
|
|
380609
|
+
if (args3.personWords.trim().length === 0) return Result.Err("first-build classifier: no words to classify");
|
|
380610
|
+
const startedAt = Date.now();
|
|
380611
|
+
const rRun = await exception2Result(() => classify3(vctx, { args: args3, spec, startedAt }));
|
|
380612
|
+
const run = rRun.isOk() ? rRun.Ok() : {
|
|
380613
|
+
verdict: Result.Err(rRun.Err()),
|
|
380614
|
+
record: { call: spec.call, outcome: "error", elapsedMs: Date.now() - startedAt, attempts: 0, error: rRun.Err().message },
|
|
380615
|
+
model: FIRST_BUILD_CLASSIFIER_MODEL
|
|
380616
|
+
};
|
|
380617
|
+
vctx.logger.Info().Any("event", {
|
|
380618
|
+
chatId: args3.chatId,
|
|
380619
|
+
...run.record,
|
|
380620
|
+
...run.record.error === void 0 ? {} : { error: run.record.error.slice(0, 200) }
|
|
380621
|
+
}).Msg("first-build-classified");
|
|
380622
|
+
const row = recordFirstClassifyRow(vctx, {
|
|
380623
|
+
chatId: args3.chatId,
|
|
380624
|
+
userId: args3.userId,
|
|
380625
|
+
model: run.model,
|
|
380626
|
+
usage: run.usage,
|
|
380627
|
+
classify: run.record
|
|
380628
|
+
});
|
|
380629
|
+
if (vctx.waitUntil === void 0) await row;
|
|
380630
|
+
else vctx.waitUntil(row);
|
|
380631
|
+
return run.verdict;
|
|
380632
|
+
}
|
|
380633
|
+
__name(runClassifier, "runClassifier");
|
|
380634
|
+
function transientFailure(echo) {
|
|
380635
|
+
if (echo.status !== void 0) return echo.status === 429 || echo.status >= 500;
|
|
380636
|
+
return echo.networkError !== void 0;
|
|
380637
|
+
}
|
|
380638
|
+
__name(transientFailure, "transientFailure");
|
|
380639
|
+
function answered2xx(echo) {
|
|
380640
|
+
return echo.status !== void 0 && echo.status >= 200 && echo.status < 300;
|
|
380641
|
+
}
|
|
380642
|
+
__name(answered2xx, "answered2xx");
|
|
380643
|
+
async function sendOnce(vctx, o4) {
|
|
380644
|
+
const controller = new AbortController();
|
|
380645
|
+
o4.cancel.addEventListener("abort", () => controller.abort(), { once: true });
|
|
380646
|
+
const echo = {};
|
|
380647
|
+
let timedOut = false;
|
|
380648
|
+
let timer;
|
|
380649
|
+
const timeout = new Promise((_3, reject) => {
|
|
380650
|
+
timer = setTimeout(() => {
|
|
380651
|
+
timedOut = true;
|
|
380652
|
+
controller.abort();
|
|
380653
|
+
reject(new Error(`first-build classifier timed out after ${o4.boundMs}ms`));
|
|
380654
|
+
}, o4.boundMs);
|
|
380655
|
+
});
|
|
380656
|
+
const rCall = await exception2Result(
|
|
380657
|
+
() => Promise.race([
|
|
380658
|
+
callAi2(o4.message, {
|
|
380659
|
+
model: FIRST_BUILD_CLASSIFIER_MODEL,
|
|
380660
|
+
endpoint: vctx.params.llm.url,
|
|
380661
|
+
apiKey: vctx.params.llm.apiKey,
|
|
380662
|
+
// The injectable inference seam (#2481), so the wire request is mockable and fail-closed in
|
|
380663
|
+
// tests, wrapped to add the no-thinking switch and read the status and usage back.
|
|
380664
|
+
mock: { fetch: classifierFetch(vctx.inferenceFetch, controller.signal, echo) },
|
|
380665
|
+
// A fallback model would be a different arm than the one measured; the one re-send is ours.
|
|
380666
|
+
skipRetry: true,
|
|
380667
|
+
schema: o4.spec.schema,
|
|
380668
|
+
...o4.spec.maxTokens === void 0 ? {} : { maxTokens: o4.spec.maxTokens }
|
|
380669
|
+
}),
|
|
380670
|
+
timeout
|
|
380671
|
+
])
|
|
380672
|
+
).finally(() => clearTimeout(timer));
|
|
380673
|
+
if (timedOut) return { kind: "timeout", error: `first-build classifier timed out after ${o4.boundMs}ms`, echo };
|
|
380674
|
+
if (rCall.isErr()) {
|
|
380675
|
+
const finish = echo.finishReason === void 0 ? "" : ` (finish_reason: ${echo.finishReason})`;
|
|
380676
|
+
const error64 = `${rCall.Err().message}${finish}`;
|
|
380677
|
+
if (answered2xx(echo)) return { kind: "undecodable", error: error64, echo };
|
|
380678
|
+
return { kind: "error", error: error64, echo, transient: transientFailure(echo) };
|
|
380679
|
+
}
|
|
380680
|
+
return { kind: "ok", raw: rCall.Ok(), echo };
|
|
380681
|
+
}
|
|
380682
|
+
__name(sendOnce, "sendOnce");
|
|
380683
|
+
async function beforeCap(p3, leftMs) {
|
|
380684
|
+
if (leftMs <= 0) return { late: true };
|
|
380685
|
+
let timer;
|
|
380686
|
+
const late = new Promise((resolve3) => {
|
|
380687
|
+
timer = setTimeout(/* @__PURE__ */ __name(function capPassed() {
|
|
380688
|
+
resolve3({ late: true });
|
|
380689
|
+
}, "capPassed"), leftMs);
|
|
380690
|
+
});
|
|
380691
|
+
const settled = await Promise.race([p3.then((value2) => ({ late: false, value: value2 })), late]);
|
|
380692
|
+
clearTimeout(timer);
|
|
380693
|
+
return settled;
|
|
380694
|
+
}
|
|
380695
|
+
__name(beforeCap, "beforeCap");
|
|
380696
|
+
async function classify3(vctx, o4) {
|
|
380697
|
+
const { args: args3, spec, startedAt } = o4;
|
|
380698
|
+
const ended = /* @__PURE__ */ __name((out, verdict2, echo = {}) => ({
|
|
380699
|
+
verdict: verdict2,
|
|
380700
|
+
record: { call: spec.call, elapsedMs: Date.now() - startedAt, ...out },
|
|
380701
|
+
model: echo.model ?? FIRST_BUILD_CLASSIFIER_MODEL,
|
|
380702
|
+
...echo.usage === void 0 ? {} : { usage: echo.usage }
|
|
380703
|
+
}), "ended");
|
|
380704
|
+
const capMs = args3.capMs ?? FIRST_BUILD_CLASSIFIER_CAP_MS;
|
|
380705
|
+
const attemptMs = args3.timeoutMs ?? capMs;
|
|
380706
|
+
const left = /* @__PURE__ */ __name(() => capMs - (Date.now() - startedAt), "left");
|
|
380707
|
+
const lateBeforeSend = /* @__PURE__ */ __name((step) => {
|
|
380708
|
+
const error64 = `first-build classifier: ${step} ran past the ${capMs}ms cap before the first send`;
|
|
380709
|
+
return ended({ outcome: "timeout", attempts: 0, error: error64 }, Result.Err(error64));
|
|
380710
|
+
}, "lateBeforeSend");
|
|
380711
|
+
if (vctx.billing.enforceEnabled) {
|
|
380712
|
+
const check6 = await beforeCap(vctx.billing.checkCredits({ userId: args3.userId }), left());
|
|
380713
|
+
if (check6.late) return lateBeforeSend("the credit check");
|
|
380714
|
+
if (check6.value.isOk() && check6.value.Ok().allowed === false) {
|
|
380715
|
+
const error64 = "first-build classifier: no credits remaining";
|
|
380716
|
+
return ended({ outcome: "no-credits", attempts: 0, error: error64 }, Result.Err(error64));
|
|
380717
|
+
}
|
|
380718
|
+
}
|
|
380719
|
+
const message5 = await beforeCap(spec.message(args3.personWords), left());
|
|
380720
|
+
if (message5.late) return lateBeforeSend("the message");
|
|
380721
|
+
if (left() <= 0) return lateBeforeSend("the steps before the send");
|
|
380722
|
+
const sends = await sendWithHedge(vctx, {
|
|
380723
|
+
message: message5.value,
|
|
380724
|
+
spec,
|
|
380725
|
+
left,
|
|
380726
|
+
attemptMs,
|
|
380727
|
+
hedgeAfterMs: args3.hedgeAfterMs ?? FIRST_BUILD_CLASSIFIER_HEDGE_AFTER_MS
|
|
380728
|
+
});
|
|
380729
|
+
const { sent, attempts } = sends;
|
|
380730
|
+
const hedged = sends.hedged ? { hedged: true } : {};
|
|
380731
|
+
const status = sent.echo.status === void 0 ? {} : { status: sent.echo.status };
|
|
380732
|
+
if (sent.kind === "timeout")
|
|
380733
|
+
return ended({ outcome: "timeout", attempts, ...hedged, error: sent.error, ...status }, Result.Err(sent.error));
|
|
380734
|
+
if (sent.kind === "undecodable")
|
|
380735
|
+
return ended({ outcome: "parse", attempts, ...hedged, error: sent.error, ...status }, Result.Err(sent.error), sent.echo);
|
|
380736
|
+
if (sent.kind === "error")
|
|
380737
|
+
return ended({ outcome: "error", attempts, ...hedged, error: sent.error, ...status }, Result.Err(sent.error), sent.echo);
|
|
380738
|
+
const served = sent.echo.model ?? FIRST_BUILD_CLASSIFIER_MODEL;
|
|
380739
|
+
const raw = sent.raw;
|
|
380740
|
+
const rParsed = typeof raw === "string" ? exception2Result(() => JSON.parse(raw)) : Result.Err("first-build classifier: callAI returned non-string");
|
|
380741
|
+
const verdict = rParsed.isErr() ? Result.Err(`first-build classifier: JSON parse failed: ${rParsed.Err().message}`) : spec.parse(rParsed.Ok(), {
|
|
380742
|
+
model: served,
|
|
380743
|
+
...sent.echo.usage === void 0 ? {} : { usage: sent.echo.usage },
|
|
380744
|
+
elapsedMs: Date.now() - startedAt
|
|
380745
|
+
});
|
|
380746
|
+
if (verdict.isErr())
|
|
380747
|
+
return ended({ outcome: "parse", attempts, ...hedged, error: verdict.Err().message, ...status }, verdict, sent.echo);
|
|
380748
|
+
return ended({ outcome: "ok", attempts, ...hedged, build: verdict.Ok().build, ...status }, verdict, sent.echo);
|
|
380749
|
+
}
|
|
380750
|
+
__name(classify3, "classify");
|
|
380751
|
+
function worthResending(sent) {
|
|
380752
|
+
return sent.kind === "timeout" || sent.kind === "error" && sent.transient;
|
|
380753
|
+
}
|
|
380754
|
+
__name(worthResending, "worthResending");
|
|
380755
|
+
async function sendWithHedge(vctx, o4) {
|
|
380756
|
+
const cancel = new AbortController();
|
|
380757
|
+
const launch = /* @__PURE__ */ __name(() => sendOnce(vctx, { message: o4.message, spec: o4.spec, boundMs: Math.min(o4.attemptMs, o4.left()), cancel: cancel.signal }), "launch");
|
|
380758
|
+
const first = launch();
|
|
380759
|
+
const atMark = await beforeCap(first, Math.min(o4.hedgeAfterMs, o4.left()));
|
|
380760
|
+
if (atMark.late === false) {
|
|
380761
|
+
const sent2 = atMark.value;
|
|
380762
|
+
if (worthResending(sent2) === false || o4.left() <= 0) return { sent: sent2, attempts: 1, hedged: false };
|
|
380763
|
+
return { sent: await launch(), attempts: 2, hedged: false };
|
|
380764
|
+
}
|
|
380765
|
+
if (o4.left() <= 0) return { sent: await first, attempts: 1, hedged: false };
|
|
380766
|
+
const second = launch();
|
|
380767
|
+
const sent = await new Promise((resolve3) => {
|
|
380768
|
+
let out = 2;
|
|
380769
|
+
for (const p3 of [first, second]) {
|
|
380770
|
+
void p3.then(/* @__PURE__ */ __name(function sendEnded(r2) {
|
|
380771
|
+
out -= 1;
|
|
380772
|
+
if (r2.kind === "ok" || out === 0) resolve3(r2);
|
|
380773
|
+
}, "sendEnded"));
|
|
380774
|
+
}
|
|
380775
|
+
});
|
|
380776
|
+
cancel.abort();
|
|
380777
|
+
return { sent, attempts: 2, hedged: true };
|
|
380778
|
+
}
|
|
380779
|
+
__name(sendWithHedge, "sendWithHedge");
|
|
380780
|
+
async function recordFirstClassifyRow(vctx, o4) {
|
|
380781
|
+
const zero = { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 };
|
|
380782
|
+
const rInsert = await exception2Result(
|
|
380783
|
+
() => vctx.sql.db.insert(vctx.sql.tables.promptContexts).values({
|
|
380784
|
+
userId: o4.userId,
|
|
380785
|
+
chatId: o4.chatId,
|
|
380786
|
+
promptId: vctx.sthis.nextId(12).str,
|
|
380787
|
+
nethash: vctx.netHash(),
|
|
380788
|
+
promptTokens: 0,
|
|
380789
|
+
completionTokens: 0,
|
|
380790
|
+
totalTokens: 0,
|
|
380791
|
+
ref: {
|
|
380792
|
+
type: "prompt.usage.sql",
|
|
380793
|
+
usage: { given: o4.usage === void 0 ? [] : [{ ...o4.usage, model: o4.model }], calculated: zero },
|
|
380794
|
+
model: o4.model,
|
|
380795
|
+
step: "first-classify",
|
|
380796
|
+
classify: { ...o4.classify }
|
|
380797
|
+
},
|
|
380798
|
+
created: (/* @__PURE__ */ new Date()).toISOString()
|
|
380799
|
+
})
|
|
380800
|
+
);
|
|
380801
|
+
if (rInsert.isErr()) {
|
|
380802
|
+
vctx.logger.Warn().Err(rInsert).Str("chatId", o4.chatId).Msg("first-build-classify-row-failed");
|
|
380803
|
+
}
|
|
380804
|
+
}
|
|
380805
|
+
__name(recordFirstClassifyRow, "recordFirstClassifyRow");
|
|
380806
|
+
|
|
380807
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/server-first-build.ts
|
|
380808
|
+
var SERVER_FIRST_BUILD_EVIDENCE_NAME = "server-first-build";
|
|
380809
|
+
async function runServerFirstBuild(vctx, o4) {
|
|
380810
|
+
const record2 = /* @__PURE__ */ __name(async (body) => {
|
|
380811
|
+
const written = await o4.evidence({ kind: "receipt", name: SERVER_FIRST_BUILD_EVIDENCE_NAME, text: JSON.stringify(body) });
|
|
380812
|
+
if (written.isErr()) {
|
|
380813
|
+
vctx.logger.Warn().Err(written).Str("chatId", o4.firstTurn.chatId).Msg("server-first-build-evidence-failed");
|
|
380814
|
+
}
|
|
380815
|
+
}, "record");
|
|
380816
|
+
const rVerdict = await o4.verdict;
|
|
380817
|
+
if (rVerdict.isErr()) {
|
|
380818
|
+
vctx.logger.Warn().Err(rVerdict).Str("chatId", o4.firstTurn.chatId).Msg("server-first-build-classifier-failed");
|
|
380819
|
+
await record2({ dispatched: false, reason: "classifier-failed", error: rVerdict.Err().message });
|
|
380820
|
+
return { dispatched: false, reason: "classifier-failed" };
|
|
380821
|
+
}
|
|
380822
|
+
const verdict = rVerdict.Ok();
|
|
380823
|
+
const classifier = { model: verdict.model, elapsedMs: verdict.elapsedMs };
|
|
380824
|
+
if (verdict.build === false) {
|
|
380825
|
+
await record2({ dispatched: false, reason: "not-a-build", classifier });
|
|
380826
|
+
return { dispatched: false, reason: "not-a-build" };
|
|
380827
|
+
}
|
|
380828
|
+
const r2 = await runCreateVibeTool(vctx, {
|
|
380829
|
+
actor: o4.actor,
|
|
380830
|
+
input: createVibeInputFromVerdict(o4.personWords, verdict),
|
|
380831
|
+
// The classifier is a model too: the words check in code still decides a just-for-me app.
|
|
380832
|
+
personWords: o4.personWords,
|
|
380833
|
+
dispatcher: o4.dispatcher,
|
|
380834
|
+
firstTurn: o4.firstTurn,
|
|
380835
|
+
offerAddressRetry: false
|
|
380836
|
+
});
|
|
380837
|
+
if (r2.isErr()) {
|
|
380838
|
+
vctx.logger.Warn().Any("event", { chatId: o4.firstTurn.chatId, refusal: r2.Err().refusal }).Msg("server-first-build-create-refused");
|
|
380839
|
+
await record2({ dispatched: false, reason: "create-refused", refusal: r2.Err().refusal, classifier });
|
|
380840
|
+
return { dispatched: false, reason: "create-refused" };
|
|
380841
|
+
}
|
|
380842
|
+
await record2({ dispatched: true, appSlug: r2.Ok().appSlug, receipt: r2.Ok(), classifier });
|
|
380843
|
+
vctx.logger.Info().Any("event", { chatId: r2.Ok().chatId, appSlug: r2.Ok().appSlug, classifierMs: verdict.elapsedMs }).Msg("server-first-build-dispatched");
|
|
380844
|
+
return { dispatched: true, chatId: r2.Ok().chatId, appSlug: r2.Ok().appSlug };
|
|
380845
|
+
}
|
|
380846
|
+
__name(runServerFirstBuild, "runServerFirstBuild");
|
|
380847
|
+
|
|
380848
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/mercury-first-build-seam.ts
|
|
380849
|
+
var MERCURY_SEAM_SOURCE = "mercury";
|
|
380850
|
+
async function runMercurySeam(vctx, o4) {
|
|
380851
|
+
const read2 = {};
|
|
380852
|
+
const record2 = /* @__PURE__ */ __name(async (body) => {
|
|
380853
|
+
const written = await o4.evidence({
|
|
380854
|
+
kind: "receipt",
|
|
380855
|
+
name: SERVER_FIRST_BUILD_EVIDENCE_NAME,
|
|
380856
|
+
text: JSON.stringify({
|
|
380857
|
+
...body,
|
|
380858
|
+
source: MERCURY_SEAM_SOURCE,
|
|
380859
|
+
...read2.askVerdict === void 0 ? {} : { askVerdict: read2.askVerdict },
|
|
380860
|
+
...o4.planner === void 0 ? {} : { planner: o4.planner },
|
|
380861
|
+
...o4.format === void 0 ? {} : { format: o4.format },
|
|
380862
|
+
...o4.productionSwitch === true ? { productionSwitch: true } : {},
|
|
380863
|
+
...o4.race === void 0 ? {} : { race: o4.race.receipt() }
|
|
380864
|
+
})
|
|
380865
|
+
});
|
|
380866
|
+
if (written.isErr()) vctx.logger.Warn().Err(written).Str("chatId", o4.firstTurn.chatId).Msg("mercury-seam-evidence-failed");
|
|
380867
|
+
}, "record");
|
|
380868
|
+
const rMercury = await o4.pending;
|
|
380869
|
+
o4.race?.mercurySettled(rMercury.isOk());
|
|
380870
|
+
if (o4.race !== void 0 && o4.race.winner() === "opus") {
|
|
380871
|
+
await record2({
|
|
380872
|
+
dispatched: false,
|
|
380873
|
+
reason: "opus-won",
|
|
380874
|
+
...rMercury.isErr() ? { error: rMercury.Err().message } : {},
|
|
380875
|
+
...rMercury.isErr() && rMercury.Err() instanceof MercuryStageError ? { cause: rMercury.Err().fallbackCause } : {}
|
|
380876
|
+
});
|
|
380877
|
+
return { dispatched: false, reason: "opus-won" };
|
|
380878
|
+
}
|
|
380879
|
+
if (rMercury.isErr()) {
|
|
380880
|
+
const err = rMercury.Err();
|
|
380881
|
+
const fallback = err instanceof MercuryStageError ? {
|
|
380882
|
+
cause: err.fallbackCause,
|
|
380883
|
+
...err.detail.call === void 0 ? {} : { call: err.detail.call },
|
|
380884
|
+
sends: err.detail.sends,
|
|
380885
|
+
retries: err.detail.retries,
|
|
380886
|
+
elapsedMs: err.detail.elapsedMs
|
|
380887
|
+
} : { cause: "error" };
|
|
380888
|
+
vctx.logger.Warn().Any("event", {
|
|
380889
|
+
chatId: o4.firstTurn.chatId,
|
|
380890
|
+
error: err.message,
|
|
380891
|
+
...fallback,
|
|
380892
|
+
...o4.productionSwitch === true ? { productionSwitch: true } : {}
|
|
380893
|
+
}).Msg("mercury-first-build-fallback");
|
|
380894
|
+
await record2({ dispatched: false, reason: "mercury-failed", error: err.message, ...fallback });
|
|
380895
|
+
return { dispatched: false, reason: "mercury-failed" };
|
|
380896
|
+
}
|
|
380897
|
+
const mercury = rMercury.Ok();
|
|
380898
|
+
const summary = {
|
|
380899
|
+
elapsedMs: mercury.elapsedMs,
|
|
380900
|
+
shape: mercury.shape.appShape,
|
|
380901
|
+
coreAction: mercury.shape.coreAction,
|
|
380902
|
+
skills: mercury.input.skills ?? [],
|
|
380903
|
+
// The font Mercury picked (#6990 lab 8), as gated; the receipt's own `font` says whether the mint wore it.
|
|
380904
|
+
...typeof mercury.input.font === "string" ? { font: mercury.input.font } : {},
|
|
380905
|
+
sends: mercury.sends,
|
|
380906
|
+
retries: mercury.retries,
|
|
380907
|
+
// Where the person's opening words came from, and their length.
|
|
380908
|
+
preambleFrom: mercury.preambleFrom,
|
|
380909
|
+
preambleChars: mercury.preamble.length,
|
|
380910
|
+
// The FIM waves (#6990 labs 28–29, `mercury-cards-fim-first-build`): the harness reads `fim.status`.
|
|
380911
|
+
...mercury.fim === void 0 ? {} : { fim: mercury.fim }
|
|
380912
|
+
};
|
|
380913
|
+
const rAsk = o4.askVerdict === void 0 ? void 0 : await boundedAskVerdict(o4.askVerdict, o4.askVerdictWaitMs);
|
|
380914
|
+
read2.askVerdict = askVerdictReceipt(rAsk);
|
|
380915
|
+
if (rAsk !== void 0 && rAsk.isOk() && rAsk.Ok().build === false && o4.race?.winner() === void 0) {
|
|
380916
|
+
vctx.logger.Info().Any("event", { chatId: o4.firstTurn.chatId }).Msg("mercury-first-build-not-a-build");
|
|
380917
|
+
await record2({ dispatched: false, reason: "not-a-build", mercury: summary });
|
|
380918
|
+
return { dispatched: false, reason: "not-a-build" };
|
|
380919
|
+
}
|
|
380920
|
+
if (o4.race !== void 0 && o4.race.claimMercury() === false) {
|
|
380921
|
+
await record2({ dispatched: false, reason: "opus-won", mercury: summary });
|
|
380922
|
+
return { dispatched: false, reason: "opus-won" };
|
|
380923
|
+
}
|
|
380924
|
+
const takesFirstLook = LOOKS[productionMintLook(mercury.input)].firstLook;
|
|
380925
|
+
const early = o4.shellEarly === void 0 || takesFirstLook === false ? void 0 : await earlyShellIntoBrief(o4.shellEarly, mercury.input);
|
|
380926
|
+
const input3 = early === void 0 ? mercury.input : early.input;
|
|
380927
|
+
const earlyRefused = early === void 0 ? {} : { shellEarly: early.receipt({}) };
|
|
380928
|
+
const createArgs = {
|
|
380929
|
+
actor: o4.actor,
|
|
380930
|
+
input: input3,
|
|
380931
|
+
dispatcher: o4.dispatcher,
|
|
380932
|
+
firstTurn: o4.firstTurn
|
|
380933
|
+
};
|
|
380934
|
+
const first = await runCreateVibeTool(vctx, { ...createArgs, offerAddressRetry: true });
|
|
380935
|
+
const addressRetried = first.isErr() && first.Err().refusal.reason === "address-taken";
|
|
380936
|
+
const r2 = addressRetried ? await runCreateVibeTool(vctx, createArgs) : first;
|
|
380937
|
+
if (r2.isErr()) {
|
|
380938
|
+
o4.race?.settleMercury({ dispatched: false });
|
|
380939
|
+
vctx.logger.Warn().Any("event", { chatId: o4.firstTurn.chatId, refusal: r2.Err().refusal }).Msg("mercury-first-build-create-refused");
|
|
380940
|
+
await record2({
|
|
380941
|
+
dispatched: false,
|
|
380942
|
+
reason: "create-refused",
|
|
380943
|
+
refusal: r2.Err().refusal,
|
|
380944
|
+
mercury: summary,
|
|
380945
|
+
...earlyRefused,
|
|
380946
|
+
...addressRetried ? { addressRetried: true } : {}
|
|
380947
|
+
});
|
|
380948
|
+
return { dispatched: false, reason: "create-refused", ...earlyRefused };
|
|
380949
|
+
}
|
|
380950
|
+
o4.race?.settleMercury({
|
|
380951
|
+
dispatched: true,
|
|
380952
|
+
receipt: r2.Ok(),
|
|
380953
|
+
preamble: mercury.preamble
|
|
380954
|
+
});
|
|
380955
|
+
const shellEarly = early === void 0 ? {} : {
|
|
380956
|
+
shellEarly: early.receipt({
|
|
380957
|
+
...early.picks.colorway !== void 0 && r2.Ok().colorway === early.picks.colorway ? { colorway: early.picks.colorway } : {},
|
|
380958
|
+
...early.picks.font !== void 0 && r2.Ok().font === early.picks.font ? { font: early.picks.font } : {},
|
|
380959
|
+
// The mint adopts a catalog archetype whenever the first look named one (`drawGenerationVariety`).
|
|
380960
|
+
...early.picks.archetype === void 0 ? {} : { archetype: early.picks.archetype }
|
|
380961
|
+
})
|
|
380962
|
+
};
|
|
380963
|
+
if (o4.keepText === true && mercury.rowPromptId !== void 0 && typeof input3.enrichedPrompt === "string")
|
|
380964
|
+
await recordMercuryDispatched(vctx, {
|
|
380965
|
+
chatId: o4.firstTurn.chatId,
|
|
380966
|
+
promptId: mercury.rowPromptId,
|
|
380967
|
+
enrichedPrompt: input3.enrichedPrompt,
|
|
380968
|
+
...shellEarly
|
|
380969
|
+
});
|
|
380970
|
+
await record2({
|
|
380971
|
+
dispatched: true,
|
|
380972
|
+
appSlug: r2.Ok().appSlug,
|
|
380973
|
+
receipt: r2.Ok(),
|
|
380974
|
+
mercury: summary,
|
|
380975
|
+
...shellEarly,
|
|
380976
|
+
...addressRetried ? { addressRetried: true } : {}
|
|
380977
|
+
});
|
|
380978
|
+
vctx.logger.Info().Any("event", {
|
|
380979
|
+
chatId: r2.Ok().chatId,
|
|
380980
|
+
appSlug: r2.Ok().appSlug,
|
|
380981
|
+
mercuryMs: mercury.elapsedMs,
|
|
380982
|
+
addressRetried,
|
|
380983
|
+
...read2.askVerdict === void 0 ? {} : { askVerdict: read2.askVerdict },
|
|
380984
|
+
...o4.productionSwitch === true ? { productionSwitch: true } : {}
|
|
380985
|
+
}).Msg("mercury-first-build-dispatched");
|
|
380986
|
+
return {
|
|
380987
|
+
dispatched: true,
|
|
380988
|
+
chatId: r2.Ok().chatId,
|
|
380989
|
+
appSlug: r2.Ok().appSlug,
|
|
380990
|
+
preamble: mercury.preamble,
|
|
380991
|
+
...addressRetried ? { addressRetried: true } : {},
|
|
380992
|
+
...shellEarly
|
|
380993
|
+
};
|
|
380994
|
+
}
|
|
380995
|
+
__name(runMercurySeam, "runMercurySeam");
|
|
380996
|
+
var ASK_VERDICT_WAIT_MS = 3e3;
|
|
380997
|
+
function askVerdictReceipt(r2) {
|
|
380998
|
+
if (r2 === void 0) return void 0;
|
|
380999
|
+
if (r2.isErr()) return "none";
|
|
381000
|
+
return r2.Ok().build ? "build" : "not-a-build";
|
|
381001
|
+
}
|
|
381002
|
+
__name(askVerdictReceipt, "askVerdictReceipt");
|
|
381003
|
+
async function boundedAskVerdict(verdict, waitMs2 = ASK_VERDICT_WAIT_MS) {
|
|
381004
|
+
let timer;
|
|
381005
|
+
const late = new Promise((resolve3) => {
|
|
381006
|
+
timer = setTimeout(/* @__PURE__ */ __name(function noVerdict() {
|
|
381007
|
+
resolve3(Result.Err(`ask verdict: no answer within ${waitMs2}ms`));
|
|
381008
|
+
}, "noVerdict"), waitMs2);
|
|
381009
|
+
});
|
|
381010
|
+
const settled = await Promise.race([verdict, late]);
|
|
381011
|
+
clearTimeout(timer);
|
|
381012
|
+
return settled;
|
|
381013
|
+
}
|
|
381014
|
+
__name(boundedAskVerdict, "boundedAskVerdict");
|
|
381015
|
+
async function earlyShellIntoBrief(o4, mercuryInput) {
|
|
381016
|
+
const now3 = o4.now ?? Date.now;
|
|
381017
|
+
const waitMs2 = Math.max(0, o4.turnStartedAt + (o4.adoptMs ?? SHELL_EARLY_ADOPT_MS) - now3());
|
|
381018
|
+
let timer;
|
|
381019
|
+
const late = new Promise((resolve3) => {
|
|
381020
|
+
timer = setTimeout(/* @__PURE__ */ __name(function giveUp() {
|
|
381021
|
+
resolve3("late");
|
|
381022
|
+
}, "giveUp"), waitMs2);
|
|
381023
|
+
});
|
|
381024
|
+
const settled = await Promise.race([o4.pending, late]);
|
|
381025
|
+
clearTimeout(timer);
|
|
381026
|
+
const msFromTurnStart = now3() - o4.turnStartedAt;
|
|
381027
|
+
if (settled === "late") {
|
|
381028
|
+
return {
|
|
381029
|
+
input: mercuryInput,
|
|
381030
|
+
picks: {},
|
|
381031
|
+
receipt: /* @__PURE__ */ __name((adopted) => ({
|
|
381032
|
+
ms: msFromTurnStart,
|
|
381033
|
+
msFromTurnStart,
|
|
381034
|
+
outcome: "late",
|
|
381035
|
+
chars: 0,
|
|
381036
|
+
chrome: false,
|
|
381037
|
+
picks: {},
|
|
381038
|
+
picksDropped: 0,
|
|
381039
|
+
adopted,
|
|
381040
|
+
handoff: "soft"
|
|
381041
|
+
}), "receipt")
|
|
381042
|
+
};
|
|
381043
|
+
}
|
|
381044
|
+
const receipt = /* @__PURE__ */ __name((adopted) => ({
|
|
381045
|
+
ms: settled.ms,
|
|
381046
|
+
msFromTurnStart,
|
|
381047
|
+
outcome: settled.outcome,
|
|
381048
|
+
chars: settled.chars,
|
|
381049
|
+
chrome: settled.chrome,
|
|
381050
|
+
picks: settled.picks,
|
|
381051
|
+
picksDropped: settled.picksDropped,
|
|
381052
|
+
adopted,
|
|
381053
|
+
handoff: "soft"
|
|
381054
|
+
}), "receipt");
|
|
381055
|
+
const brief2 = mercuryInput.enrichedPrompt;
|
|
381056
|
+
if (settled.outcome !== "usable" || settled.code === void 0 || typeof brief2 !== "string" || brief2.length === 0) {
|
|
381057
|
+
return { input: mercuryInput, picks: {}, receipt };
|
|
381058
|
+
}
|
|
381059
|
+
const font = settled.picks.font ?? mercuryInput.font;
|
|
381060
|
+
return {
|
|
381061
|
+
input: {
|
|
381062
|
+
...mercuryInput,
|
|
381063
|
+
enrichedPrompt: withFirstLook(brief2, settled.code, firstLookLineFor(mercuryInput.skills)),
|
|
381064
|
+
...settled.picks.colorway === void 0 ? {} : { colorway: settled.picks.colorway },
|
|
381065
|
+
...font === void 0 ? {} : { font }
|
|
381066
|
+
},
|
|
381067
|
+
picks: settled.picks,
|
|
381068
|
+
receipt
|
|
381069
|
+
};
|
|
381070
|
+
}
|
|
381071
|
+
__name(earlyShellIntoBrief, "earlyShellIntoBrief");
|
|
381072
|
+
function withPreambleFirst(stream, preamble) {
|
|
381073
|
+
let sent = false;
|
|
381074
|
+
return stream.pipeThrough(
|
|
381075
|
+
new TransformStream({
|
|
381076
|
+
transform(msg, controller) {
|
|
381077
|
+
if (sent === false && isSseLine(msg)) {
|
|
381078
|
+
sent = true;
|
|
381079
|
+
controller.enqueue({
|
|
381080
|
+
...msg,
|
|
381081
|
+
chunk: {
|
|
381082
|
+
id: msg.chunk.id,
|
|
381083
|
+
provider: msg.chunk.provider,
|
|
381084
|
+
model: msg.chunk.model,
|
|
381085
|
+
object: msg.chunk.object,
|
|
381086
|
+
created: msg.chunk.created,
|
|
381087
|
+
choices: [
|
|
381088
|
+
{
|
|
381089
|
+
index: 0,
|
|
381090
|
+
delta: { role: "assistant", content: `${preamble}
|
|
381091
|
+
|
|
381092
|
+
` },
|
|
381093
|
+
finish_reason: null,
|
|
381094
|
+
native_finish_reason: null
|
|
381095
|
+
}
|
|
381096
|
+
]
|
|
381097
|
+
}
|
|
381098
|
+
});
|
|
381099
|
+
}
|
|
381100
|
+
controller.enqueue(msg);
|
|
381101
|
+
}
|
|
381102
|
+
})
|
|
381103
|
+
);
|
|
381104
|
+
}
|
|
381105
|
+
__name(withPreambleFirst, "withPreambleFirst");
|
|
381106
|
+
function withMercuryUsageRounds(stream, o4) {
|
|
381107
|
+
let sent = false;
|
|
381108
|
+
let streamId;
|
|
381109
|
+
let taken = 0;
|
|
381110
|
+
let lastFrom;
|
|
381111
|
+
function enqueueRounds(controller, from4) {
|
|
381112
|
+
const all = o4.rounds();
|
|
381113
|
+
for (const round2 of all.slice(taken)) {
|
|
381114
|
+
controller.enqueue({
|
|
381115
|
+
type: "sse.line",
|
|
381116
|
+
streamId: from4.streamId,
|
|
381117
|
+
chunkNr: 0,
|
|
381118
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
381119
|
+
chunk: {
|
|
381120
|
+
id: from4.id,
|
|
381121
|
+
provider: from4.provider,
|
|
381122
|
+
model: round2.model,
|
|
381123
|
+
object: from4.object,
|
|
381124
|
+
created: from4.created,
|
|
381125
|
+
choices: [],
|
|
381126
|
+
usage: { ...round2 }
|
|
381127
|
+
}
|
|
381128
|
+
});
|
|
381129
|
+
}
|
|
381130
|
+
taken = all.length;
|
|
381131
|
+
}
|
|
381132
|
+
__name(enqueueRounds, "enqueueRounds");
|
|
381133
|
+
async function emit2(controller, from4) {
|
|
381134
|
+
sent = true;
|
|
381135
|
+
lastFrom = from4;
|
|
381136
|
+
await o4.settled;
|
|
381137
|
+
enqueueRounds(controller, from4);
|
|
381138
|
+
}
|
|
381139
|
+
__name(emit2, "emit");
|
|
381140
|
+
function close(controller, fallback) {
|
|
381141
|
+
if (o4.closing === void 0 || o4.closing.closed) return;
|
|
381142
|
+
enqueueRounds(controller, lastFrom ?? fallback);
|
|
381143
|
+
o4.closing.closed = true;
|
|
381144
|
+
}
|
|
381145
|
+
__name(close, "close");
|
|
381146
|
+
function synthetic(forStream) {
|
|
381147
|
+
return {
|
|
381148
|
+
streamId: forStream,
|
|
381149
|
+
id: `mercury-usage-${forStream}`,
|
|
381150
|
+
provider: "mercury",
|
|
381151
|
+
object: "chat.completion.chunk",
|
|
381152
|
+
created: Math.floor(Date.now() / 1e3)
|
|
381153
|
+
};
|
|
381154
|
+
}
|
|
381155
|
+
__name(synthetic, "synthetic");
|
|
381156
|
+
return stream.pipeThrough(
|
|
381157
|
+
new TransformStream({
|
|
381158
|
+
async transform(msg, controller) {
|
|
381159
|
+
streamId = msg.streamId;
|
|
381160
|
+
if (isSseEnd(msg)) {
|
|
381161
|
+
if (sent === false) await emit2(controller, synthetic(msg.streamId));
|
|
381162
|
+
close(controller, synthetic(msg.streamId));
|
|
381163
|
+
}
|
|
381164
|
+
controller.enqueue(msg);
|
|
381165
|
+
if (sent || isSseLine(msg) === false) return;
|
|
381166
|
+
await emit2(controller, {
|
|
381167
|
+
streamId: msg.streamId,
|
|
381168
|
+
id: msg.chunk.id,
|
|
381169
|
+
provider: msg.chunk.provider,
|
|
381170
|
+
object: msg.chunk.object,
|
|
381171
|
+
created: msg.chunk.created
|
|
381172
|
+
});
|
|
381173
|
+
},
|
|
381174
|
+
async flush(controller) {
|
|
381175
|
+
if (streamId === void 0) return;
|
|
381176
|
+
if (sent === false) await emit2(controller, synthetic(streamId));
|
|
381177
|
+
close(controller, synthetic(streamId));
|
|
381178
|
+
}
|
|
381179
|
+
})
|
|
381180
|
+
);
|
|
381181
|
+
}
|
|
381182
|
+
__name(withMercuryUsageRounds, "withMercuryUsageRounds");
|
|
381183
|
+
|
|
381184
|
+
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/unfinished-first-ask.ts
|
|
381185
|
+
var UNFINISHED_MAX_CHARS = 24;
|
|
381186
|
+
var UNFINISHED_MAX_WORDS = 3;
|
|
381187
|
+
var CONVERSATIONAL_OPENERS = /* @__PURE__ */ new Set([
|
|
381188
|
+
"hi",
|
|
381189
|
+
"hii",
|
|
381190
|
+
"hey",
|
|
381191
|
+
"heya",
|
|
381192
|
+
"hello",
|
|
381193
|
+
"hallo",
|
|
381194
|
+
"hola",
|
|
381195
|
+
"yo",
|
|
381196
|
+
"sup",
|
|
381197
|
+
"howdy",
|
|
381198
|
+
"gm",
|
|
381199
|
+
"morning",
|
|
381200
|
+
"thanks",
|
|
381201
|
+
"thank",
|
|
381202
|
+
"thx",
|
|
381203
|
+
"ty",
|
|
381204
|
+
"ok",
|
|
381205
|
+
"okay",
|
|
381206
|
+
"test",
|
|
381207
|
+
"testing",
|
|
381208
|
+
"help",
|
|
381209
|
+
"what",
|
|
381210
|
+
"whats",
|
|
381211
|
+
"what's",
|
|
381212
|
+
"who",
|
|
381213
|
+
"why",
|
|
381214
|
+
"how",
|
|
381215
|
+
"when",
|
|
381216
|
+
"where",
|
|
381217
|
+
"which",
|
|
381218
|
+
"can",
|
|
381219
|
+
"could",
|
|
381220
|
+
"is",
|
|
381221
|
+
"are",
|
|
381222
|
+
"do",
|
|
381223
|
+
"does"
|
|
381224
|
+
]);
|
|
381225
|
+
function readsUnfinished(words) {
|
|
381226
|
+
const text3 = words.trim();
|
|
381227
|
+
if (text3 === "" || text3.length > UNFINISHED_MAX_CHARS || /[\r\n]/.test(text3)) return false;
|
|
381228
|
+
if (/[\p{L}\p{N}]$/u.test(text3) === false) return false;
|
|
381229
|
+
if (text3.includes("?")) return false;
|
|
381230
|
+
const tokens2 = text3.split(/\s+/);
|
|
381231
|
+
if (tokens2.length > UNFINISHED_MAX_WORDS) return false;
|
|
381232
|
+
return CONVERSATIONAL_OPENERS.has(tokens2[0].toLowerCase().replace(/[^\p{L}']/gu, "")) === false;
|
|
381233
|
+
}
|
|
381234
|
+
__name(readsUnfinished, "readsUnfinished");
|
|
381235
|
+
async function shouldAskToFinish(i3) {
|
|
381236
|
+
if (i3.askVerdict === void 0 || readsUnfinished(i3.personWords) === false) return false;
|
|
381237
|
+
const r2 = await boundedAskVerdict(i3.askVerdict, i3.waitMs);
|
|
381238
|
+
return r2.isOk() && r2.Ok().build === false;
|
|
381239
|
+
}
|
|
381240
|
+
__name(shouldAskToFinish, "shouldAskToFinish");
|
|
381241
|
+
function finishAskGate(i3) {
|
|
381242
|
+
let verdict;
|
|
381243
|
+
return () => {
|
|
381244
|
+
if (i3.personSpokeAgain()) return Promise.resolve(false);
|
|
381245
|
+
verdict ??= i3.read();
|
|
381246
|
+
return verdict;
|
|
381247
|
+
};
|
|
381248
|
+
}
|
|
381249
|
+
__name(finishAskGate, "finishAskGate");
|
|
381250
|
+
function chatHasEarlierTurn(i3) {
|
|
381251
|
+
const said2 = i3.messages.filter((m) => m.role !== "system" && isRequestFrameMessage(m) === false).length;
|
|
381252
|
+
return said2 > i3.incoming;
|
|
381253
|
+
}
|
|
381254
|
+
__name(chatHasEarlierTurn, "chatHasEarlierTurn");
|
|
381255
|
+
var FINISH_ASK_REASON = "finish-ask";
|
|
381256
|
+
var FINISH_ASK_MESSAGE = "Their message reads like the start of a sentence, so nothing is built yet. Reply with one short, warm question that invites them to keep going \u2014 what they'd like to make, in their own words \u2014 and stop there. Their words are already back in the composer for them to finish. Call create_vibe once they say what to make.";
|
|
381257
|
+
|
|
379998
381258
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/agent-belt.ts
|
|
379999
381259
|
var DIRECT_WRITE_CODEGEN_PROPERTY = {
|
|
380000
381260
|
type: "boolean",
|
|
@@ -380248,6 +381508,8 @@ function createAgentBelt(vctx, args3) {
|
|
|
380248
381508
|
const rArgs = parseArgs4(input3.call.arguments);
|
|
380249
381509
|
if (rArgs.isErr())
|
|
380250
381510
|
return refused2(CREATE_VIBE_TOOL_NAME, { ok: false, reason: "invalid-input", message: rArgs.Err().message });
|
|
381511
|
+
if (firstTurnCreated === false && await args3.firstTurn?.finishAsk?.() === true)
|
|
381512
|
+
return refused2(CREATE_VIBE_TOOL_NAME, { ok: false, reason: FINISH_ASK_REASON, message: FINISH_ASK_MESSAGE });
|
|
380251
381513
|
const joined = firstTurnCreated ? void 0 : await args3.firstTurn?.joinRunning?.();
|
|
380252
381514
|
if (joined !== void 0) {
|
|
380253
381515
|
firstTurnCreated = true;
|
|
@@ -386988,425 +388250,6 @@ function createAccountAgentBelt(vctx, args3) {
|
|
|
386988
388250
|
}
|
|
386989
388251
|
__name(createAccountAgentBelt, "createAccountAgentBelt");
|
|
386990
388252
|
|
|
386991
|
-
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/first-build-classifier.ts
|
|
386992
|
-
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
386993
|
-
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
386994
|
-
init_performance2();
|
|
386995
|
-
init_esm();
|
|
386996
|
-
init_out4();
|
|
386997
|
-
init_lazy_type();
|
|
386998
|
-
var FIRST_BUILD_CLASSIFIER_MODEL = "google/gemini-3.5-flash-lite";
|
|
386999
|
-
var FIRST_BUILD_CLASSIFIER_REASONING = { effort: "minimal" };
|
|
387000
|
-
var FIRST_BUILD_CLASSIFIER_CAP_MS = 5e3;
|
|
387001
|
-
var FIRST_BUILD_CLASSIFIER_HEDGE_AFTER_MS = 2500;
|
|
387002
|
-
var ASK_CLASSIFIER_INPUT_MAX_CHARS = 500;
|
|
387003
|
-
var ASK_CLASSIFIER_MAX_TOKENS = 256;
|
|
387004
|
-
var ALWAYS_PRESENT_SKILLS = /* @__PURE__ */ new Set(["fireproof", "image-gen", "use-vibe", "use-viewer"]);
|
|
387005
|
-
var SERVER_FIRST_BUILD_ACCESS_SKILL = "access";
|
|
387006
|
-
var SKILL_LINE_MAX_CHARS = 110;
|
|
387007
|
-
function shortDescription(description) {
|
|
387008
|
-
const flat = description.replace(/\s+/g, " ").trim();
|
|
387009
|
-
if (flat.length <= SKILL_LINE_MAX_CHARS) return flat;
|
|
387010
|
-
const cut = flat.slice(0, SKILL_LINE_MAX_CHARS);
|
|
387011
|
-
const space = cut.lastIndexOf(" ");
|
|
387012
|
-
return `${space > 40 ? cut.slice(0, space) : cut}\u2026`;
|
|
387013
|
-
}
|
|
387014
|
-
__name(shortDescription, "shortDescription");
|
|
387015
|
-
async function firstBuildSkillMenu(opts) {
|
|
387016
|
-
const catalog = await getLlmCatalog();
|
|
387017
|
-
return catalog.filter((c3) => onSkillMenu(c3)).filter((c3) => ALWAYS_PRESENT_SKILLS.has(c3.name) === false && c3.name !== SERVER_FIRST_BUILD_ACCESS_SKILL).filter((c3) => skillAllowedOnLook(c3.name, opts.look)).map((c3) => `- ${c3.name}: ${shortDescription(c3.description)}`).join("\n");
|
|
387018
|
-
}
|
|
387019
|
-
__name(firstBuildSkillMenu, "firstBuildSkillMenu");
|
|
387020
|
-
var CLASSIFIER_INTRO = "Read one message a person sent to an app builder and fill the schema.";
|
|
387021
|
-
var BUILD_RULE = "build: true when the message describes an app, tool, game, page, tracker or anything else to make \u2014 however short \u2014 and when it names a subject to learn, explore or practise (teach me about volcanoes, explain compound interest, how to bake bread): that subject is the app. build: false for a greeting, a question about the builder itself, or a message with no subject at all.";
|
|
387022
|
-
function firstBuildClassifierMessage(personWords, skillMenu) {
|
|
387023
|
-
return [
|
|
387024
|
-
CLASSIFIER_INTRO,
|
|
387025
|
-
BUILD_RULE,
|
|
387026
|
-
'skills: the names from the list below that the app needs, exactly as written; an empty list when none fit. "backend" for schedules, email, fetching, notifications and server work; "callai" for record intake by sentence, a chat reply, a suggestion or any text the page asks the model for itself. Access rules ride every build already.',
|
|
387027
|
-
"pairs: three title/slug pairs ranked by fit \u2014 a Title Case title of one to four words, and a kebab-case slug made from it.",
|
|
387028
|
-
"iconDescription: one short line naming what the app's icon shows, such as 'a fox on a record player'.",
|
|
387029
|
-
"keepsToThemselves: true when the message keeps the app to the person who asked \u2014 just for me, private to me, single-user, no sharing; false otherwise (a private chef or private lessons app serves customers), a diary or health app included unless its words say so.",
|
|
387030
|
-
'nature: "sensitive" for private record-keeping (a diary, health, money), for records a professional keeps about the people they serve, shared with a team or not (client, patient, case, student or tenant notes), and for every keepsToThemselves message; "open" for a light toy anyone can play with, or a message asking for no access control or for anyone to edit; "collaborative" for everything else. When a message both keeps the app to the person and asks for no access control, keepsToThemselves decides and nature is sensitive.',
|
|
387031
|
-
"",
|
|
387032
|
-
"Skills:",
|
|
387033
|
-
skillMenu,
|
|
387034
|
-
"",
|
|
387035
|
-
"Message:",
|
|
387036
|
-
personWords
|
|
387037
|
-
].join("\n");
|
|
387038
|
-
}
|
|
387039
|
-
__name(firstBuildClassifierMessage, "firstBuildClassifierMessage");
|
|
387040
|
-
var firstBuildClassifierSchema = {
|
|
387041
|
-
name: "first_build",
|
|
387042
|
-
required: ["build", "skills", "pairs", "iconDescription", "nature", "keepsToThemselves"],
|
|
387043
|
-
properties: {
|
|
387044
|
-
build: { type: "boolean" },
|
|
387045
|
-
skills: { type: "array", items: { type: "string" } },
|
|
387046
|
-
pairs: {
|
|
387047
|
-
type: "array",
|
|
387048
|
-
items: { type: "object", properties: { title: { type: "string" }, slug: { type: "string" } } }
|
|
387049
|
-
},
|
|
387050
|
-
iconDescription: { type: "string" },
|
|
387051
|
-
nature: { type: "string", enum: ["sensitive", "collaborative", "open"] },
|
|
387052
|
-
keepsToThemselves: { type: "boolean" }
|
|
387053
|
-
}
|
|
387054
|
-
};
|
|
387055
|
-
function askClassifierMessage(personWords) {
|
|
387056
|
-
return [CLASSIFIER_INTRO, BUILD_RULE, "", "Message:", personWords.slice(0, ASK_CLASSIFIER_INPUT_MAX_CHARS)].join("\n");
|
|
387057
|
-
}
|
|
387058
|
-
__name(askClassifierMessage, "askClassifierMessage");
|
|
387059
|
-
var askClassifierSchema = {
|
|
387060
|
-
name: "app_ask",
|
|
387061
|
-
required: ["build"],
|
|
387062
|
-
properties: { build: { type: "boolean" } }
|
|
387063
|
-
};
|
|
387064
|
-
var firstBuildParsed = lazyType(
|
|
387065
|
-
() => type({
|
|
387066
|
-
build: "boolean",
|
|
387067
|
-
"skills?": "string[]",
|
|
387068
|
-
"pairs?": type({ "title?": "string", "slug?": "string" }).array(),
|
|
387069
|
-
"iconDescription?": "string",
|
|
387070
|
-
"nature?": "string",
|
|
387071
|
-
"keepsToThemselves?": "boolean"
|
|
387072
|
-
})
|
|
387073
|
-
);
|
|
387074
|
-
var askParsed = lazyType(() => type({ build: "boolean" }));
|
|
387075
|
-
function parseFirstBuildVerdict(raw, meta3) {
|
|
387076
|
-
const parsed3 = firstBuildParsed(raw);
|
|
387077
|
-
if (parsed3 instanceof type.errors) return Result.Err(`first-build classifier: schema validation failed: ${parsed3.summary}`);
|
|
387078
|
-
const pairs2 = (parsed3.pairs ?? []).flatMap((p3) => {
|
|
387079
|
-
const title2 = (p3.title ?? "").trim();
|
|
387080
|
-
const slug = (p3.slug ?? "").trim();
|
|
387081
|
-
return title2.length > 0 && slug.length > 0 ? [{ title: title2, slug }] : [];
|
|
387082
|
-
});
|
|
387083
|
-
const icon = (parsed3.iconDescription ?? "").trim();
|
|
387084
|
-
const keepsToThemselves2 = parsed3.keepsToThemselves === true;
|
|
387085
|
-
const nature = keepsToThemselves2 ? "sensitive" : AppNature(parsed3.nature);
|
|
387086
|
-
return Result.Ok({
|
|
387087
|
-
build: parsed3.build,
|
|
387088
|
-
skills: (parsed3.skills ?? []).map((s2) => s2.trim()).filter((s2) => s2.length > 0),
|
|
387089
|
-
pairs: pairs2,
|
|
387090
|
-
...icon.length === 0 ? {} : { iconDescription: icon },
|
|
387091
|
-
...nature instanceof type.errors ? {} : { nature },
|
|
387092
|
-
keepsToThemselves: keepsToThemselves2,
|
|
387093
|
-
model: meta3.model,
|
|
387094
|
-
...meta3.usage === void 0 ? {} : { usage: meta3.usage },
|
|
387095
|
-
elapsedMs: meta3.elapsedMs
|
|
387096
|
-
});
|
|
387097
|
-
}
|
|
387098
|
-
__name(parseFirstBuildVerdict, "parseFirstBuildVerdict");
|
|
387099
|
-
function parseAskVerdict(raw, meta3) {
|
|
387100
|
-
const parsed3 = askParsed(raw);
|
|
387101
|
-
if (parsed3 instanceof type.errors) return Result.Err(`ask classifier: schema validation failed: ${parsed3.summary}`);
|
|
387102
|
-
return Result.Ok({
|
|
387103
|
-
build: parsed3.build,
|
|
387104
|
-
model: meta3.model,
|
|
387105
|
-
...meta3.usage === void 0 ? {} : { usage: meta3.usage },
|
|
387106
|
-
elapsedMs: meta3.elapsedMs
|
|
387107
|
-
});
|
|
387108
|
-
}
|
|
387109
|
-
__name(parseAskVerdict, "parseAskVerdict");
|
|
387110
|
-
function serverFirstBuildBrief(personWords, o4) {
|
|
387111
|
-
return [
|
|
387112
|
-
`This first build is group-ready: ${GROUP_READY_SHAPE}`,
|
|
387113
|
-
`${INVITE_SCREEN_WHEN}; every other first build leaves it as an option for later.`,
|
|
387114
|
-
// Owner policy 2026-10-12: the viral baseline — a way to share ships on the first screen. Owner
|
|
387115
|
-
// direction 2026-10-15: its shape follows what one record is (a collection shared by adding a
|
|
387116
|
-
// friend, a piece published, a thing on an always-on channel).
|
|
387117
|
-
SHARING_BASELINE,
|
|
387118
|
-
// Owner decision 2026-10-08: a just-for-me app keeps its rules — one collection per person,
|
|
387119
|
-
// shared whole by its add-a-friend control (owner direction 2026-10-15).
|
|
387120
|
-
...o4.keepsToThemselves ? [ONE_TREE_PER_PERSON] : [],
|
|
387121
|
-
`Sample content: ${SEED_DEMO_RULE}`,
|
|
387122
|
-
KNOWN_VALUES_DIRECT_CONTROLS,
|
|
387123
|
-
`The person asked: "${personWords}". Plan the app from their words.`
|
|
387124
|
-
].join("\n");
|
|
387125
|
-
}
|
|
387126
|
-
__name(serverFirstBuildBrief, "serverFirstBuildBrief");
|
|
387127
|
-
function serverFirstBuildSkills(verdict) {
|
|
387128
|
-
const picked = verdict.skills.filter((s2) => s2 !== SERVER_FIRST_BUILD_ACCESS_SKILL);
|
|
387129
|
-
return verdict.skills.includes(SERVER_FIRST_BUILD_ACCESS_SKILL) ? [...verdict.skills] : [...picked, SERVER_FIRST_BUILD_ACCESS_SKILL];
|
|
387130
|
-
}
|
|
387131
|
-
__name(serverFirstBuildSkills, "serverFirstBuildSkills");
|
|
387132
|
-
function createVibeInputFromVerdict(personWords, verdict) {
|
|
387133
|
-
return {
|
|
387134
|
-
prompt: personWords,
|
|
387135
|
-
enrichedPrompt: serverFirstBuildBrief(personWords, { keepsToThemselves: verdict.keepsToThemselves }),
|
|
387136
|
-
skills: serverFirstBuildSkills(verdict),
|
|
387137
|
-
pairs: verdict.pairs.map((p3) => ({ ...p3 })),
|
|
387138
|
-
...verdict.iconDescription === void 0 ? {} : { iconDescription: verdict.iconDescription },
|
|
387139
|
-
...verdict.nature === void 0 ? {} : { nature: verdict.nature }
|
|
387140
|
-
};
|
|
387141
|
-
}
|
|
387142
|
-
__name(createVibeInputFromVerdict, "createVibeInputFromVerdict");
|
|
387143
|
-
function numberField(o4, key) {
|
|
387144
|
-
const v3 = o4[key];
|
|
387145
|
-
return typeof v3 === "number" && Number.isFinite(v3) ? v3 : void 0;
|
|
387146
|
-
}
|
|
387147
|
-
__name(numberField, "numberField");
|
|
387148
|
-
function readEcho(json6, echo) {
|
|
387149
|
-
if (typeof json6 !== "object" || json6 === null) return;
|
|
387150
|
-
const body = json6;
|
|
387151
|
-
if (typeof body.model === "string") echo.model = body.model;
|
|
387152
|
-
const choice = Array.isArray(body.choices) ? body.choices[0] : void 0;
|
|
387153
|
-
if (typeof choice === "object" && choice !== null) {
|
|
387154
|
-
const finish = choice.finish_reason;
|
|
387155
|
-
if (typeof finish === "string") echo.finishReason = finish;
|
|
387156
|
-
}
|
|
387157
|
-
const usage = body.usage;
|
|
387158
|
-
if (typeof usage !== "object" || usage === null) return;
|
|
387159
|
-
const u3 = usage;
|
|
387160
|
-
const prompt = numberField(u3, "prompt_tokens");
|
|
387161
|
-
const completion2 = numberField(u3, "completion_tokens");
|
|
387162
|
-
if (prompt === void 0 || completion2 === void 0) return;
|
|
387163
|
-
const cost = numberField(u3, "cost");
|
|
387164
|
-
echo.usage = {
|
|
387165
|
-
prompt_tokens: prompt,
|
|
387166
|
-
completion_tokens: completion2,
|
|
387167
|
-
total_tokens: numberField(u3, "total_tokens") ?? prompt + completion2,
|
|
387168
|
-
...cost === void 0 ? {} : { cost }
|
|
387169
|
-
};
|
|
387170
|
-
}
|
|
387171
|
-
__name(readEcho, "readEcho");
|
|
387172
|
-
function classifierFetch(inner, signal, echo) {
|
|
387173
|
-
return async (input3, init2) => {
|
|
387174
|
-
const body = typeof init2?.body === "string" ? init2.body : void 0;
|
|
387175
|
-
const rBody = body === void 0 ? void 0 : exception2Result(() => JSON.parse(body));
|
|
387176
|
-
const patchedBody = rBody !== void 0 && rBody.isOk() ? JSON.stringify({ ...rBody.Ok(), reasoning: { ...FIRST_BUILD_CLASSIFIER_REASONING }, usage: { include: true } }) : body;
|
|
387177
|
-
const rRes = await exception2Result(
|
|
387178
|
-
() => inner(input3, { ...init2, ...patchedBody === void 0 ? {} : { body: patchedBody }, signal })
|
|
387179
|
-
);
|
|
387180
|
-
if (rRes.isErr()) {
|
|
387181
|
-
echo.networkError = rRes.Err().message;
|
|
387182
|
-
throw rRes.Err();
|
|
387183
|
-
}
|
|
387184
|
-
const res = rRes.Ok();
|
|
387185
|
-
echo.status = res.status;
|
|
387186
|
-
const rJson = await exception2Result(() => res.clone().json());
|
|
387187
|
-
if (rJson.isOk()) readEcho(rJson.Ok(), echo);
|
|
387188
|
-
return res;
|
|
387189
|
-
};
|
|
387190
|
-
}
|
|
387191
|
-
__name(classifierFetch, "classifierFetch");
|
|
387192
|
-
async function classifyFirstBuild(vctx, args3) {
|
|
387193
|
-
return runClassifier(vctx, args3, {
|
|
387194
|
-
call: "first-build",
|
|
387195
|
-
message: /* @__PURE__ */ __name(async (words) => firstBuildClassifierMessage(words, await firstBuildSkillMenu({ look: MINT_LOOK })), "message"),
|
|
387196
|
-
schema: { ...firstBuildClassifierSchema, required: [...firstBuildClassifierSchema.required] },
|
|
387197
|
-
parse: parseFirstBuildVerdict
|
|
387198
|
-
});
|
|
387199
|
-
}
|
|
387200
|
-
__name(classifyFirstBuild, "classifyFirstBuild");
|
|
387201
|
-
async function classifyAsk(vctx, args3) {
|
|
387202
|
-
return runClassifier(vctx, args3, {
|
|
387203
|
-
call: "ask",
|
|
387204
|
-
message: /* @__PURE__ */ __name(async (words) => askClassifierMessage(words), "message"),
|
|
387205
|
-
schema: { ...askClassifierSchema, required: [...askClassifierSchema.required] },
|
|
387206
|
-
maxTokens: ASK_CLASSIFIER_MAX_TOKENS,
|
|
387207
|
-
parse: parseAskVerdict
|
|
387208
|
-
});
|
|
387209
|
-
}
|
|
387210
|
-
__name(classifyAsk, "classifyAsk");
|
|
387211
|
-
async function runClassifier(vctx, args3, spec) {
|
|
387212
|
-
if (args3.personWords.trim().length === 0) return Result.Err("first-build classifier: no words to classify");
|
|
387213
|
-
const startedAt = Date.now();
|
|
387214
|
-
const rRun = await exception2Result(() => classify3(vctx, { args: args3, spec, startedAt }));
|
|
387215
|
-
const run = rRun.isOk() ? rRun.Ok() : {
|
|
387216
|
-
verdict: Result.Err(rRun.Err()),
|
|
387217
|
-
record: { call: spec.call, outcome: "error", elapsedMs: Date.now() - startedAt, attempts: 0, error: rRun.Err().message },
|
|
387218
|
-
model: FIRST_BUILD_CLASSIFIER_MODEL
|
|
387219
|
-
};
|
|
387220
|
-
vctx.logger.Info().Any("event", {
|
|
387221
|
-
chatId: args3.chatId,
|
|
387222
|
-
...run.record,
|
|
387223
|
-
...run.record.error === void 0 ? {} : { error: run.record.error.slice(0, 200) }
|
|
387224
|
-
}).Msg("first-build-classified");
|
|
387225
|
-
const row = recordFirstClassifyRow(vctx, {
|
|
387226
|
-
chatId: args3.chatId,
|
|
387227
|
-
userId: args3.userId,
|
|
387228
|
-
model: run.model,
|
|
387229
|
-
usage: run.usage,
|
|
387230
|
-
classify: run.record
|
|
387231
|
-
});
|
|
387232
|
-
if (vctx.waitUntil === void 0) await row;
|
|
387233
|
-
else vctx.waitUntil(row);
|
|
387234
|
-
return run.verdict;
|
|
387235
|
-
}
|
|
387236
|
-
__name(runClassifier, "runClassifier");
|
|
387237
|
-
function transientFailure(echo) {
|
|
387238
|
-
if (echo.status !== void 0) return echo.status === 429 || echo.status >= 500;
|
|
387239
|
-
return echo.networkError !== void 0;
|
|
387240
|
-
}
|
|
387241
|
-
__name(transientFailure, "transientFailure");
|
|
387242
|
-
function answered2xx(echo) {
|
|
387243
|
-
return echo.status !== void 0 && echo.status >= 200 && echo.status < 300;
|
|
387244
|
-
}
|
|
387245
|
-
__name(answered2xx, "answered2xx");
|
|
387246
|
-
async function sendOnce(vctx, o4) {
|
|
387247
|
-
const controller = new AbortController();
|
|
387248
|
-
o4.cancel.addEventListener("abort", () => controller.abort(), { once: true });
|
|
387249
|
-
const echo = {};
|
|
387250
|
-
let timedOut = false;
|
|
387251
|
-
let timer;
|
|
387252
|
-
const timeout = new Promise((_3, reject) => {
|
|
387253
|
-
timer = setTimeout(() => {
|
|
387254
|
-
timedOut = true;
|
|
387255
|
-
controller.abort();
|
|
387256
|
-
reject(new Error(`first-build classifier timed out after ${o4.boundMs}ms`));
|
|
387257
|
-
}, o4.boundMs);
|
|
387258
|
-
});
|
|
387259
|
-
const rCall = await exception2Result(
|
|
387260
|
-
() => Promise.race([
|
|
387261
|
-
callAi2(o4.message, {
|
|
387262
|
-
model: FIRST_BUILD_CLASSIFIER_MODEL,
|
|
387263
|
-
endpoint: vctx.params.llm.url,
|
|
387264
|
-
apiKey: vctx.params.llm.apiKey,
|
|
387265
|
-
// The injectable inference seam (#2481), so the wire request is mockable and fail-closed in
|
|
387266
|
-
// tests, wrapped to add the no-thinking switch and read the status and usage back.
|
|
387267
|
-
mock: { fetch: classifierFetch(vctx.inferenceFetch, controller.signal, echo) },
|
|
387268
|
-
// A fallback model would be a different arm than the one measured; the one re-send is ours.
|
|
387269
|
-
skipRetry: true,
|
|
387270
|
-
schema: o4.spec.schema,
|
|
387271
|
-
...o4.spec.maxTokens === void 0 ? {} : { maxTokens: o4.spec.maxTokens }
|
|
387272
|
-
}),
|
|
387273
|
-
timeout
|
|
387274
|
-
])
|
|
387275
|
-
).finally(() => clearTimeout(timer));
|
|
387276
|
-
if (timedOut) return { kind: "timeout", error: `first-build classifier timed out after ${o4.boundMs}ms`, echo };
|
|
387277
|
-
if (rCall.isErr()) {
|
|
387278
|
-
const finish = echo.finishReason === void 0 ? "" : ` (finish_reason: ${echo.finishReason})`;
|
|
387279
|
-
const error64 = `${rCall.Err().message}${finish}`;
|
|
387280
|
-
if (answered2xx(echo)) return { kind: "undecodable", error: error64, echo };
|
|
387281
|
-
return { kind: "error", error: error64, echo, transient: transientFailure(echo) };
|
|
387282
|
-
}
|
|
387283
|
-
return { kind: "ok", raw: rCall.Ok(), echo };
|
|
387284
|
-
}
|
|
387285
|
-
__name(sendOnce, "sendOnce");
|
|
387286
|
-
async function beforeCap(p3, leftMs) {
|
|
387287
|
-
if (leftMs <= 0) return { late: true };
|
|
387288
|
-
let timer;
|
|
387289
|
-
const late = new Promise((resolve3) => {
|
|
387290
|
-
timer = setTimeout(/* @__PURE__ */ __name(function capPassed() {
|
|
387291
|
-
resolve3({ late: true });
|
|
387292
|
-
}, "capPassed"), leftMs);
|
|
387293
|
-
});
|
|
387294
|
-
const settled = await Promise.race([p3.then((value2) => ({ late: false, value: value2 })), late]);
|
|
387295
|
-
clearTimeout(timer);
|
|
387296
|
-
return settled;
|
|
387297
|
-
}
|
|
387298
|
-
__name(beforeCap, "beforeCap");
|
|
387299
|
-
async function classify3(vctx, o4) {
|
|
387300
|
-
const { args: args3, spec, startedAt } = o4;
|
|
387301
|
-
const ended = /* @__PURE__ */ __name((out, verdict2, echo = {}) => ({
|
|
387302
|
-
verdict: verdict2,
|
|
387303
|
-
record: { call: spec.call, elapsedMs: Date.now() - startedAt, ...out },
|
|
387304
|
-
model: echo.model ?? FIRST_BUILD_CLASSIFIER_MODEL,
|
|
387305
|
-
...echo.usage === void 0 ? {} : { usage: echo.usage }
|
|
387306
|
-
}), "ended");
|
|
387307
|
-
const capMs = args3.capMs ?? FIRST_BUILD_CLASSIFIER_CAP_MS;
|
|
387308
|
-
const attemptMs = args3.timeoutMs ?? capMs;
|
|
387309
|
-
const left = /* @__PURE__ */ __name(() => capMs - (Date.now() - startedAt), "left");
|
|
387310
|
-
const lateBeforeSend = /* @__PURE__ */ __name((step) => {
|
|
387311
|
-
const error64 = `first-build classifier: ${step} ran past the ${capMs}ms cap before the first send`;
|
|
387312
|
-
return ended({ outcome: "timeout", attempts: 0, error: error64 }, Result.Err(error64));
|
|
387313
|
-
}, "lateBeforeSend");
|
|
387314
|
-
if (vctx.billing.enforceEnabled) {
|
|
387315
|
-
const check6 = await beforeCap(vctx.billing.checkCredits({ userId: args3.userId }), left());
|
|
387316
|
-
if (check6.late) return lateBeforeSend("the credit check");
|
|
387317
|
-
if (check6.value.isOk() && check6.value.Ok().allowed === false) {
|
|
387318
|
-
const error64 = "first-build classifier: no credits remaining";
|
|
387319
|
-
return ended({ outcome: "no-credits", attempts: 0, error: error64 }, Result.Err(error64));
|
|
387320
|
-
}
|
|
387321
|
-
}
|
|
387322
|
-
const message5 = await beforeCap(spec.message(args3.personWords), left());
|
|
387323
|
-
if (message5.late) return lateBeforeSend("the message");
|
|
387324
|
-
if (left() <= 0) return lateBeforeSend("the steps before the send");
|
|
387325
|
-
const sends = await sendWithHedge(vctx, {
|
|
387326
|
-
message: message5.value,
|
|
387327
|
-
spec,
|
|
387328
|
-
left,
|
|
387329
|
-
attemptMs,
|
|
387330
|
-
hedgeAfterMs: args3.hedgeAfterMs ?? FIRST_BUILD_CLASSIFIER_HEDGE_AFTER_MS
|
|
387331
|
-
});
|
|
387332
|
-
const { sent, attempts } = sends;
|
|
387333
|
-
const hedged = sends.hedged ? { hedged: true } : {};
|
|
387334
|
-
const status = sent.echo.status === void 0 ? {} : { status: sent.echo.status };
|
|
387335
|
-
if (sent.kind === "timeout")
|
|
387336
|
-
return ended({ outcome: "timeout", attempts, ...hedged, error: sent.error, ...status }, Result.Err(sent.error));
|
|
387337
|
-
if (sent.kind === "undecodable")
|
|
387338
|
-
return ended({ outcome: "parse", attempts, ...hedged, error: sent.error, ...status }, Result.Err(sent.error), sent.echo);
|
|
387339
|
-
if (sent.kind === "error")
|
|
387340
|
-
return ended({ outcome: "error", attempts, ...hedged, error: sent.error, ...status }, Result.Err(sent.error), sent.echo);
|
|
387341
|
-
const served = sent.echo.model ?? FIRST_BUILD_CLASSIFIER_MODEL;
|
|
387342
|
-
const raw = sent.raw;
|
|
387343
|
-
const rParsed = typeof raw === "string" ? exception2Result(() => JSON.parse(raw)) : Result.Err("first-build classifier: callAI returned non-string");
|
|
387344
|
-
const verdict = rParsed.isErr() ? Result.Err(`first-build classifier: JSON parse failed: ${rParsed.Err().message}`) : spec.parse(rParsed.Ok(), {
|
|
387345
|
-
model: served,
|
|
387346
|
-
...sent.echo.usage === void 0 ? {} : { usage: sent.echo.usage },
|
|
387347
|
-
elapsedMs: Date.now() - startedAt
|
|
387348
|
-
});
|
|
387349
|
-
if (verdict.isErr())
|
|
387350
|
-
return ended({ outcome: "parse", attempts, ...hedged, error: verdict.Err().message, ...status }, verdict, sent.echo);
|
|
387351
|
-
return ended({ outcome: "ok", attempts, ...hedged, build: verdict.Ok().build, ...status }, verdict, sent.echo);
|
|
387352
|
-
}
|
|
387353
|
-
__name(classify3, "classify");
|
|
387354
|
-
function worthResending(sent) {
|
|
387355
|
-
return sent.kind === "timeout" || sent.kind === "error" && sent.transient;
|
|
387356
|
-
}
|
|
387357
|
-
__name(worthResending, "worthResending");
|
|
387358
|
-
async function sendWithHedge(vctx, o4) {
|
|
387359
|
-
const cancel = new AbortController();
|
|
387360
|
-
const launch = /* @__PURE__ */ __name(() => sendOnce(vctx, { message: o4.message, spec: o4.spec, boundMs: Math.min(o4.attemptMs, o4.left()), cancel: cancel.signal }), "launch");
|
|
387361
|
-
const first = launch();
|
|
387362
|
-
const atMark = await beforeCap(first, Math.min(o4.hedgeAfterMs, o4.left()));
|
|
387363
|
-
if (atMark.late === false) {
|
|
387364
|
-
const sent2 = atMark.value;
|
|
387365
|
-
if (worthResending(sent2) === false || o4.left() <= 0) return { sent: sent2, attempts: 1, hedged: false };
|
|
387366
|
-
return { sent: await launch(), attempts: 2, hedged: false };
|
|
387367
|
-
}
|
|
387368
|
-
if (o4.left() <= 0) return { sent: await first, attempts: 1, hedged: false };
|
|
387369
|
-
const second = launch();
|
|
387370
|
-
const sent = await new Promise((resolve3) => {
|
|
387371
|
-
let out = 2;
|
|
387372
|
-
for (const p3 of [first, second]) {
|
|
387373
|
-
void p3.then(/* @__PURE__ */ __name(function sendEnded(r2) {
|
|
387374
|
-
out -= 1;
|
|
387375
|
-
if (r2.kind === "ok" || out === 0) resolve3(r2);
|
|
387376
|
-
}, "sendEnded"));
|
|
387377
|
-
}
|
|
387378
|
-
});
|
|
387379
|
-
cancel.abort();
|
|
387380
|
-
return { sent, attempts: 2, hedged: true };
|
|
387381
|
-
}
|
|
387382
|
-
__name(sendWithHedge, "sendWithHedge");
|
|
387383
|
-
async function recordFirstClassifyRow(vctx, o4) {
|
|
387384
|
-
const zero = { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 };
|
|
387385
|
-
const rInsert = await exception2Result(
|
|
387386
|
-
() => vctx.sql.db.insert(vctx.sql.tables.promptContexts).values({
|
|
387387
|
-
userId: o4.userId,
|
|
387388
|
-
chatId: o4.chatId,
|
|
387389
|
-
promptId: vctx.sthis.nextId(12).str,
|
|
387390
|
-
nethash: vctx.netHash(),
|
|
387391
|
-
promptTokens: 0,
|
|
387392
|
-
completionTokens: 0,
|
|
387393
|
-
totalTokens: 0,
|
|
387394
|
-
ref: {
|
|
387395
|
-
type: "prompt.usage.sql",
|
|
387396
|
-
usage: { given: o4.usage === void 0 ? [] : [{ ...o4.usage, model: o4.model }], calculated: zero },
|
|
387397
|
-
model: o4.model,
|
|
387398
|
-
step: "first-classify",
|
|
387399
|
-
classify: { ...o4.classify }
|
|
387400
|
-
},
|
|
387401
|
-
created: (/* @__PURE__ */ new Date()).toISOString()
|
|
387402
|
-
})
|
|
387403
|
-
);
|
|
387404
|
-
if (rInsert.isErr()) {
|
|
387405
|
-
vctx.logger.Warn().Err(rInsert).Str("chatId", o4.chatId).Msg("first-build-classify-row-failed");
|
|
387406
|
-
}
|
|
387407
|
-
}
|
|
387408
|
-
__name(recordFirstClassifyRow, "recordFirstClassifyRow");
|
|
387409
|
-
|
|
387410
388253
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/retire-offer-options.ts
|
|
387411
388254
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
387412
388255
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
@@ -388873,390 +389716,6 @@ __name(linkParkedBuildToParent, "linkParkedBuildToParent");
|
|
|
388873
389716
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/public/agent-turn-action.ts
|
|
388874
389717
|
init_esm();
|
|
388875
389718
|
|
|
388876
|
-
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/server-first-build.ts
|
|
388877
|
-
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
388878
|
-
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
388879
|
-
init_performance2();
|
|
388880
|
-
var SERVER_FIRST_BUILD_EVIDENCE_NAME = "server-first-build";
|
|
388881
|
-
async function runServerFirstBuild(vctx, o4) {
|
|
388882
|
-
const record2 = /* @__PURE__ */ __name(async (body) => {
|
|
388883
|
-
const written = await o4.evidence({ kind: "receipt", name: SERVER_FIRST_BUILD_EVIDENCE_NAME, text: JSON.stringify(body) });
|
|
388884
|
-
if (written.isErr()) {
|
|
388885
|
-
vctx.logger.Warn().Err(written).Str("chatId", o4.firstTurn.chatId).Msg("server-first-build-evidence-failed");
|
|
388886
|
-
}
|
|
388887
|
-
}, "record");
|
|
388888
|
-
const rVerdict = await o4.verdict;
|
|
388889
|
-
if (rVerdict.isErr()) {
|
|
388890
|
-
vctx.logger.Warn().Err(rVerdict).Str("chatId", o4.firstTurn.chatId).Msg("server-first-build-classifier-failed");
|
|
388891
|
-
await record2({ dispatched: false, reason: "classifier-failed", error: rVerdict.Err().message });
|
|
388892
|
-
return { dispatched: false, reason: "classifier-failed" };
|
|
388893
|
-
}
|
|
388894
|
-
const verdict = rVerdict.Ok();
|
|
388895
|
-
const classifier = { model: verdict.model, elapsedMs: verdict.elapsedMs };
|
|
388896
|
-
if (verdict.build === false) {
|
|
388897
|
-
await record2({ dispatched: false, reason: "not-a-build", classifier });
|
|
388898
|
-
return { dispatched: false, reason: "not-a-build" };
|
|
388899
|
-
}
|
|
388900
|
-
const r2 = await runCreateVibeTool(vctx, {
|
|
388901
|
-
actor: o4.actor,
|
|
388902
|
-
input: createVibeInputFromVerdict(o4.personWords, verdict),
|
|
388903
|
-
// The classifier is a model too: the words check in code still decides a just-for-me app.
|
|
388904
|
-
personWords: o4.personWords,
|
|
388905
|
-
dispatcher: o4.dispatcher,
|
|
388906
|
-
firstTurn: o4.firstTurn,
|
|
388907
|
-
offerAddressRetry: false
|
|
388908
|
-
});
|
|
388909
|
-
if (r2.isErr()) {
|
|
388910
|
-
vctx.logger.Warn().Any("event", { chatId: o4.firstTurn.chatId, refusal: r2.Err().refusal }).Msg("server-first-build-create-refused");
|
|
388911
|
-
await record2({ dispatched: false, reason: "create-refused", refusal: r2.Err().refusal, classifier });
|
|
388912
|
-
return { dispatched: false, reason: "create-refused" };
|
|
388913
|
-
}
|
|
388914
|
-
await record2({ dispatched: true, appSlug: r2.Ok().appSlug, receipt: r2.Ok(), classifier });
|
|
388915
|
-
vctx.logger.Info().Any("event", { chatId: r2.Ok().chatId, appSlug: r2.Ok().appSlug, classifierMs: verdict.elapsedMs }).Msg("server-first-build-dispatched");
|
|
388916
|
-
return { dispatched: true, chatId: r2.Ok().chatId, appSlug: r2.Ok().appSlug };
|
|
388917
|
-
}
|
|
388918
|
-
__name(runServerFirstBuild, "runServerFirstBuild");
|
|
388919
|
-
|
|
388920
|
-
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/mercury-first-build-seam.ts
|
|
388921
|
-
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
388922
|
-
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
388923
|
-
init_performance2();
|
|
388924
|
-
init_esm();
|
|
388925
|
-
var MERCURY_SEAM_SOURCE = "mercury";
|
|
388926
|
-
async function runMercurySeam(vctx, o4) {
|
|
388927
|
-
const read2 = {};
|
|
388928
|
-
const record2 = /* @__PURE__ */ __name(async (body) => {
|
|
388929
|
-
const written = await o4.evidence({
|
|
388930
|
-
kind: "receipt",
|
|
388931
|
-
name: SERVER_FIRST_BUILD_EVIDENCE_NAME,
|
|
388932
|
-
text: JSON.stringify({
|
|
388933
|
-
...body,
|
|
388934
|
-
source: MERCURY_SEAM_SOURCE,
|
|
388935
|
-
...read2.askVerdict === void 0 ? {} : { askVerdict: read2.askVerdict },
|
|
388936
|
-
...o4.planner === void 0 ? {} : { planner: o4.planner },
|
|
388937
|
-
...o4.format === void 0 ? {} : { format: o4.format },
|
|
388938
|
-
...o4.productionSwitch === true ? { productionSwitch: true } : {},
|
|
388939
|
-
...o4.race === void 0 ? {} : { race: o4.race.receipt() }
|
|
388940
|
-
})
|
|
388941
|
-
});
|
|
388942
|
-
if (written.isErr()) vctx.logger.Warn().Err(written).Str("chatId", o4.firstTurn.chatId).Msg("mercury-seam-evidence-failed");
|
|
388943
|
-
}, "record");
|
|
388944
|
-
const rMercury = await o4.pending;
|
|
388945
|
-
o4.race?.mercurySettled(rMercury.isOk());
|
|
388946
|
-
if (o4.race !== void 0 && o4.race.winner() === "opus") {
|
|
388947
|
-
await record2({
|
|
388948
|
-
dispatched: false,
|
|
388949
|
-
reason: "opus-won",
|
|
388950
|
-
...rMercury.isErr() ? { error: rMercury.Err().message } : {},
|
|
388951
|
-
...rMercury.isErr() && rMercury.Err() instanceof MercuryStageError ? { cause: rMercury.Err().fallbackCause } : {}
|
|
388952
|
-
});
|
|
388953
|
-
return { dispatched: false, reason: "opus-won" };
|
|
388954
|
-
}
|
|
388955
|
-
if (rMercury.isErr()) {
|
|
388956
|
-
const err = rMercury.Err();
|
|
388957
|
-
const fallback = err instanceof MercuryStageError ? {
|
|
388958
|
-
cause: err.fallbackCause,
|
|
388959
|
-
...err.detail.call === void 0 ? {} : { call: err.detail.call },
|
|
388960
|
-
sends: err.detail.sends,
|
|
388961
|
-
retries: err.detail.retries,
|
|
388962
|
-
elapsedMs: err.detail.elapsedMs
|
|
388963
|
-
} : { cause: "error" };
|
|
388964
|
-
vctx.logger.Warn().Any("event", {
|
|
388965
|
-
chatId: o4.firstTurn.chatId,
|
|
388966
|
-
error: err.message,
|
|
388967
|
-
...fallback,
|
|
388968
|
-
...o4.productionSwitch === true ? { productionSwitch: true } : {}
|
|
388969
|
-
}).Msg("mercury-first-build-fallback");
|
|
388970
|
-
await record2({ dispatched: false, reason: "mercury-failed", error: err.message, ...fallback });
|
|
388971
|
-
return { dispatched: false, reason: "mercury-failed" };
|
|
388972
|
-
}
|
|
388973
|
-
const mercury = rMercury.Ok();
|
|
388974
|
-
const summary = {
|
|
388975
|
-
elapsedMs: mercury.elapsedMs,
|
|
388976
|
-
shape: mercury.shape.appShape,
|
|
388977
|
-
coreAction: mercury.shape.coreAction,
|
|
388978
|
-
skills: mercury.input.skills ?? [],
|
|
388979
|
-
// The font Mercury picked (#6990 lab 8), as gated; the receipt's own `font` says whether the mint wore it.
|
|
388980
|
-
...typeof mercury.input.font === "string" ? { font: mercury.input.font } : {},
|
|
388981
|
-
sends: mercury.sends,
|
|
388982
|
-
retries: mercury.retries,
|
|
388983
|
-
// Where the person's opening words came from, and their length.
|
|
388984
|
-
preambleFrom: mercury.preambleFrom,
|
|
388985
|
-
preambleChars: mercury.preamble.length,
|
|
388986
|
-
// The FIM waves (#6990 labs 28–29, `mercury-cards-fim-first-build`): the harness reads `fim.status`.
|
|
388987
|
-
...mercury.fim === void 0 ? {} : { fim: mercury.fim }
|
|
388988
|
-
};
|
|
388989
|
-
const rAsk = o4.askVerdict === void 0 ? void 0 : await boundedAskVerdict(o4.askVerdict, o4.askVerdictWaitMs);
|
|
388990
|
-
read2.askVerdict = askVerdictReceipt(rAsk);
|
|
388991
|
-
if (rAsk !== void 0 && rAsk.isOk() && rAsk.Ok().build === false && o4.race?.winner() === void 0) {
|
|
388992
|
-
vctx.logger.Info().Any("event", { chatId: o4.firstTurn.chatId }).Msg("mercury-first-build-not-a-build");
|
|
388993
|
-
await record2({ dispatched: false, reason: "not-a-build", mercury: summary });
|
|
388994
|
-
return { dispatched: false, reason: "not-a-build" };
|
|
388995
|
-
}
|
|
388996
|
-
if (o4.race !== void 0 && o4.race.claimMercury() === false) {
|
|
388997
|
-
await record2({ dispatched: false, reason: "opus-won", mercury: summary });
|
|
388998
|
-
return { dispatched: false, reason: "opus-won" };
|
|
388999
|
-
}
|
|
389000
|
-
const takesFirstLook = LOOKS[productionMintLook(mercury.input)].firstLook;
|
|
389001
|
-
const early = o4.shellEarly === void 0 || takesFirstLook === false ? void 0 : await earlyShellIntoBrief(o4.shellEarly, mercury.input);
|
|
389002
|
-
const input3 = early === void 0 ? mercury.input : early.input;
|
|
389003
|
-
const earlyRefused = early === void 0 ? {} : { shellEarly: early.receipt({}) };
|
|
389004
|
-
const createArgs = {
|
|
389005
|
-
actor: o4.actor,
|
|
389006
|
-
input: input3,
|
|
389007
|
-
dispatcher: o4.dispatcher,
|
|
389008
|
-
firstTurn: o4.firstTurn
|
|
389009
|
-
};
|
|
389010
|
-
const first = await runCreateVibeTool(vctx, { ...createArgs, offerAddressRetry: true });
|
|
389011
|
-
const addressRetried = first.isErr() && first.Err().refusal.reason === "address-taken";
|
|
389012
|
-
const r2 = addressRetried ? await runCreateVibeTool(vctx, createArgs) : first;
|
|
389013
|
-
if (r2.isErr()) {
|
|
389014
|
-
o4.race?.settleMercury({ dispatched: false });
|
|
389015
|
-
vctx.logger.Warn().Any("event", { chatId: o4.firstTurn.chatId, refusal: r2.Err().refusal }).Msg("mercury-first-build-create-refused");
|
|
389016
|
-
await record2({
|
|
389017
|
-
dispatched: false,
|
|
389018
|
-
reason: "create-refused",
|
|
389019
|
-
refusal: r2.Err().refusal,
|
|
389020
|
-
mercury: summary,
|
|
389021
|
-
...earlyRefused,
|
|
389022
|
-
...addressRetried ? { addressRetried: true } : {}
|
|
389023
|
-
});
|
|
389024
|
-
return { dispatched: false, reason: "create-refused", ...earlyRefused };
|
|
389025
|
-
}
|
|
389026
|
-
o4.race?.settleMercury({
|
|
389027
|
-
dispatched: true,
|
|
389028
|
-
receipt: r2.Ok(),
|
|
389029
|
-
preamble: mercury.preamble
|
|
389030
|
-
});
|
|
389031
|
-
const shellEarly = early === void 0 ? {} : {
|
|
389032
|
-
shellEarly: early.receipt({
|
|
389033
|
-
...early.picks.colorway !== void 0 && r2.Ok().colorway === early.picks.colorway ? { colorway: early.picks.colorway } : {},
|
|
389034
|
-
...early.picks.font !== void 0 && r2.Ok().font === early.picks.font ? { font: early.picks.font } : {},
|
|
389035
|
-
// The mint adopts a catalog archetype whenever the first look named one (`drawGenerationVariety`).
|
|
389036
|
-
...early.picks.archetype === void 0 ? {} : { archetype: early.picks.archetype }
|
|
389037
|
-
})
|
|
389038
|
-
};
|
|
389039
|
-
if (o4.keepText === true && mercury.rowPromptId !== void 0 && typeof input3.enrichedPrompt === "string")
|
|
389040
|
-
await recordMercuryDispatched(vctx, {
|
|
389041
|
-
chatId: o4.firstTurn.chatId,
|
|
389042
|
-
promptId: mercury.rowPromptId,
|
|
389043
|
-
enrichedPrompt: input3.enrichedPrompt,
|
|
389044
|
-
...shellEarly
|
|
389045
|
-
});
|
|
389046
|
-
await record2({
|
|
389047
|
-
dispatched: true,
|
|
389048
|
-
appSlug: r2.Ok().appSlug,
|
|
389049
|
-
receipt: r2.Ok(),
|
|
389050
|
-
mercury: summary,
|
|
389051
|
-
...shellEarly,
|
|
389052
|
-
...addressRetried ? { addressRetried: true } : {}
|
|
389053
|
-
});
|
|
389054
|
-
vctx.logger.Info().Any("event", {
|
|
389055
|
-
chatId: r2.Ok().chatId,
|
|
389056
|
-
appSlug: r2.Ok().appSlug,
|
|
389057
|
-
mercuryMs: mercury.elapsedMs,
|
|
389058
|
-
addressRetried,
|
|
389059
|
-
...read2.askVerdict === void 0 ? {} : { askVerdict: read2.askVerdict },
|
|
389060
|
-
...o4.productionSwitch === true ? { productionSwitch: true } : {}
|
|
389061
|
-
}).Msg("mercury-first-build-dispatched");
|
|
389062
|
-
return {
|
|
389063
|
-
dispatched: true,
|
|
389064
|
-
chatId: r2.Ok().chatId,
|
|
389065
|
-
appSlug: r2.Ok().appSlug,
|
|
389066
|
-
preamble: mercury.preamble,
|
|
389067
|
-
...addressRetried ? { addressRetried: true } : {},
|
|
389068
|
-
...shellEarly
|
|
389069
|
-
};
|
|
389070
|
-
}
|
|
389071
|
-
__name(runMercurySeam, "runMercurySeam");
|
|
389072
|
-
var ASK_VERDICT_WAIT_MS = 3e3;
|
|
389073
|
-
function askVerdictReceipt(r2) {
|
|
389074
|
-
if (r2 === void 0) return void 0;
|
|
389075
|
-
if (r2.isErr()) return "none";
|
|
389076
|
-
return r2.Ok().build ? "build" : "not-a-build";
|
|
389077
|
-
}
|
|
389078
|
-
__name(askVerdictReceipt, "askVerdictReceipt");
|
|
389079
|
-
async function boundedAskVerdict(verdict, waitMs2 = ASK_VERDICT_WAIT_MS) {
|
|
389080
|
-
let timer;
|
|
389081
|
-
const late = new Promise((resolve3) => {
|
|
389082
|
-
timer = setTimeout(/* @__PURE__ */ __name(function noVerdict() {
|
|
389083
|
-
resolve3(Result.Err(`ask verdict: no answer within ${waitMs2}ms`));
|
|
389084
|
-
}, "noVerdict"), waitMs2);
|
|
389085
|
-
});
|
|
389086
|
-
const settled = await Promise.race([verdict, late]);
|
|
389087
|
-
clearTimeout(timer);
|
|
389088
|
-
return settled;
|
|
389089
|
-
}
|
|
389090
|
-
__name(boundedAskVerdict, "boundedAskVerdict");
|
|
389091
|
-
async function earlyShellIntoBrief(o4, mercuryInput) {
|
|
389092
|
-
const now3 = o4.now ?? Date.now;
|
|
389093
|
-
const waitMs2 = Math.max(0, o4.turnStartedAt + (o4.adoptMs ?? SHELL_EARLY_ADOPT_MS) - now3());
|
|
389094
|
-
let timer;
|
|
389095
|
-
const late = new Promise((resolve3) => {
|
|
389096
|
-
timer = setTimeout(/* @__PURE__ */ __name(function giveUp() {
|
|
389097
|
-
resolve3("late");
|
|
389098
|
-
}, "giveUp"), waitMs2);
|
|
389099
|
-
});
|
|
389100
|
-
const settled = await Promise.race([o4.pending, late]);
|
|
389101
|
-
clearTimeout(timer);
|
|
389102
|
-
const msFromTurnStart = now3() - o4.turnStartedAt;
|
|
389103
|
-
if (settled === "late") {
|
|
389104
|
-
return {
|
|
389105
|
-
input: mercuryInput,
|
|
389106
|
-
picks: {},
|
|
389107
|
-
receipt: /* @__PURE__ */ __name((adopted) => ({
|
|
389108
|
-
ms: msFromTurnStart,
|
|
389109
|
-
msFromTurnStart,
|
|
389110
|
-
outcome: "late",
|
|
389111
|
-
chars: 0,
|
|
389112
|
-
chrome: false,
|
|
389113
|
-
picks: {},
|
|
389114
|
-
picksDropped: 0,
|
|
389115
|
-
adopted,
|
|
389116
|
-
handoff: "soft"
|
|
389117
|
-
}), "receipt")
|
|
389118
|
-
};
|
|
389119
|
-
}
|
|
389120
|
-
const receipt = /* @__PURE__ */ __name((adopted) => ({
|
|
389121
|
-
ms: settled.ms,
|
|
389122
|
-
msFromTurnStart,
|
|
389123
|
-
outcome: settled.outcome,
|
|
389124
|
-
chars: settled.chars,
|
|
389125
|
-
chrome: settled.chrome,
|
|
389126
|
-
picks: settled.picks,
|
|
389127
|
-
picksDropped: settled.picksDropped,
|
|
389128
|
-
adopted,
|
|
389129
|
-
handoff: "soft"
|
|
389130
|
-
}), "receipt");
|
|
389131
|
-
const brief2 = mercuryInput.enrichedPrompt;
|
|
389132
|
-
if (settled.outcome !== "usable" || settled.code === void 0 || typeof brief2 !== "string" || brief2.length === 0) {
|
|
389133
|
-
return { input: mercuryInput, picks: {}, receipt };
|
|
389134
|
-
}
|
|
389135
|
-
const font = settled.picks.font ?? mercuryInput.font;
|
|
389136
|
-
return {
|
|
389137
|
-
input: {
|
|
389138
|
-
...mercuryInput,
|
|
389139
|
-
enrichedPrompt: withFirstLook(brief2, settled.code, firstLookLineFor(mercuryInput.skills)),
|
|
389140
|
-
...settled.picks.colorway === void 0 ? {} : { colorway: settled.picks.colorway },
|
|
389141
|
-
...font === void 0 ? {} : { font }
|
|
389142
|
-
},
|
|
389143
|
-
picks: settled.picks,
|
|
389144
|
-
receipt
|
|
389145
|
-
};
|
|
389146
|
-
}
|
|
389147
|
-
__name(earlyShellIntoBrief, "earlyShellIntoBrief");
|
|
389148
|
-
function withPreambleFirst(stream, preamble) {
|
|
389149
|
-
let sent = false;
|
|
389150
|
-
return stream.pipeThrough(
|
|
389151
|
-
new TransformStream({
|
|
389152
|
-
transform(msg, controller) {
|
|
389153
|
-
if (sent === false && isSseLine(msg)) {
|
|
389154
|
-
sent = true;
|
|
389155
|
-
controller.enqueue({
|
|
389156
|
-
...msg,
|
|
389157
|
-
chunk: {
|
|
389158
|
-
id: msg.chunk.id,
|
|
389159
|
-
provider: msg.chunk.provider,
|
|
389160
|
-
model: msg.chunk.model,
|
|
389161
|
-
object: msg.chunk.object,
|
|
389162
|
-
created: msg.chunk.created,
|
|
389163
|
-
choices: [
|
|
389164
|
-
{
|
|
389165
|
-
index: 0,
|
|
389166
|
-
delta: { role: "assistant", content: `${preamble}
|
|
389167
|
-
|
|
389168
|
-
` },
|
|
389169
|
-
finish_reason: null,
|
|
389170
|
-
native_finish_reason: null
|
|
389171
|
-
}
|
|
389172
|
-
]
|
|
389173
|
-
}
|
|
389174
|
-
});
|
|
389175
|
-
}
|
|
389176
|
-
controller.enqueue(msg);
|
|
389177
|
-
}
|
|
389178
|
-
})
|
|
389179
|
-
);
|
|
389180
|
-
}
|
|
389181
|
-
__name(withPreambleFirst, "withPreambleFirst");
|
|
389182
|
-
function withMercuryUsageRounds(stream, o4) {
|
|
389183
|
-
let sent = false;
|
|
389184
|
-
let streamId;
|
|
389185
|
-
let taken = 0;
|
|
389186
|
-
let lastFrom;
|
|
389187
|
-
function enqueueRounds(controller, from4) {
|
|
389188
|
-
const all = o4.rounds();
|
|
389189
|
-
for (const round2 of all.slice(taken)) {
|
|
389190
|
-
controller.enqueue({
|
|
389191
|
-
type: "sse.line",
|
|
389192
|
-
streamId: from4.streamId,
|
|
389193
|
-
chunkNr: 0,
|
|
389194
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
389195
|
-
chunk: {
|
|
389196
|
-
id: from4.id,
|
|
389197
|
-
provider: from4.provider,
|
|
389198
|
-
model: round2.model,
|
|
389199
|
-
object: from4.object,
|
|
389200
|
-
created: from4.created,
|
|
389201
|
-
choices: [],
|
|
389202
|
-
usage: { ...round2 }
|
|
389203
|
-
}
|
|
389204
|
-
});
|
|
389205
|
-
}
|
|
389206
|
-
taken = all.length;
|
|
389207
|
-
}
|
|
389208
|
-
__name(enqueueRounds, "enqueueRounds");
|
|
389209
|
-
async function emit2(controller, from4) {
|
|
389210
|
-
sent = true;
|
|
389211
|
-
lastFrom = from4;
|
|
389212
|
-
await o4.settled;
|
|
389213
|
-
enqueueRounds(controller, from4);
|
|
389214
|
-
}
|
|
389215
|
-
__name(emit2, "emit");
|
|
389216
|
-
function close(controller, fallback) {
|
|
389217
|
-
if (o4.closing === void 0 || o4.closing.closed) return;
|
|
389218
|
-
enqueueRounds(controller, lastFrom ?? fallback);
|
|
389219
|
-
o4.closing.closed = true;
|
|
389220
|
-
}
|
|
389221
|
-
__name(close, "close");
|
|
389222
|
-
function synthetic(forStream) {
|
|
389223
|
-
return {
|
|
389224
|
-
streamId: forStream,
|
|
389225
|
-
id: `mercury-usage-${forStream}`,
|
|
389226
|
-
provider: "mercury",
|
|
389227
|
-
object: "chat.completion.chunk",
|
|
389228
|
-
created: Math.floor(Date.now() / 1e3)
|
|
389229
|
-
};
|
|
389230
|
-
}
|
|
389231
|
-
__name(synthetic, "synthetic");
|
|
389232
|
-
return stream.pipeThrough(
|
|
389233
|
-
new TransformStream({
|
|
389234
|
-
async transform(msg, controller) {
|
|
389235
|
-
streamId = msg.streamId;
|
|
389236
|
-
if (isSseEnd(msg)) {
|
|
389237
|
-
if (sent === false) await emit2(controller, synthetic(msg.streamId));
|
|
389238
|
-
close(controller, synthetic(msg.streamId));
|
|
389239
|
-
}
|
|
389240
|
-
controller.enqueue(msg);
|
|
389241
|
-
if (sent || isSseLine(msg) === false) return;
|
|
389242
|
-
await emit2(controller, {
|
|
389243
|
-
streamId: msg.streamId,
|
|
389244
|
-
id: msg.chunk.id,
|
|
389245
|
-
provider: msg.chunk.provider,
|
|
389246
|
-
object: msg.chunk.object,
|
|
389247
|
-
created: msg.chunk.created
|
|
389248
|
-
});
|
|
389249
|
-
},
|
|
389250
|
-
async flush(controller) {
|
|
389251
|
-
if (streamId === void 0) return;
|
|
389252
|
-
if (sent === false) await emit2(controller, synthetic(streamId));
|
|
389253
|
-
close(controller, synthetic(streamId));
|
|
389254
|
-
}
|
|
389255
|
-
})
|
|
389256
|
-
);
|
|
389257
|
-
}
|
|
389258
|
-
__name(withMercuryUsageRounds, "withMercuryUsageRounds");
|
|
389259
|
-
|
|
389260
389719
|
// ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/agent-top-level-first-look.ts
|
|
389261
389720
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
|
|
389262
389721
|
init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
|
|
@@ -389455,6 +389914,9 @@ function createFirstBuildRace(o4) {
|
|
|
389455
389914
|
return true;
|
|
389456
389915
|
},
|
|
389457
389916
|
decided,
|
|
389917
|
+
mercuryHolds() {
|
|
389918
|
+
return state4 === "mercury-claimed" || state4 === "mercury";
|
|
389919
|
+
},
|
|
389458
389920
|
winner() {
|
|
389459
389921
|
if (state4 === "mercury") return "mercury";
|
|
389460
389922
|
if (state4 === "opus") return "opus";
|
|
@@ -391066,8 +391528,22 @@ function createAgentTurnAction(args3) {
|
|
|
391066
391528
|
);
|
|
391067
391529
|
}
|
|
391068
391530
|
__name(raceRound, "raceRound");
|
|
391069
|
-
|
|
391070
|
-
|
|
391531
|
+
let personSpokeAgain = false;
|
|
391532
|
+
const finishAskEligible = origFlags.nonInteractive !== true && origFlags.byText !== true && chatHasEarlierTurn({
|
|
391533
|
+
messages: agentPayload.messages,
|
|
391534
|
+
incoming: orig.prompt.messages.filter(isChatMessage).length
|
|
391535
|
+
}) === false;
|
|
391536
|
+
const finishAsk = mercuryAskVerdict === void 0 || finishAskEligible === false ? void 0 : finishAskGate({
|
|
391537
|
+
personSpokeAgain: /* @__PURE__ */ __name(() => personSpokeAgain, "personSpokeAgain"),
|
|
391538
|
+
read: /* @__PURE__ */ __name(() => shouldAskToFinish({ personWords, askVerdict: mercuryAskVerdict }).then((asks) => {
|
|
391539
|
+
const ask2 = asks && race?.mercuryHolds() !== true;
|
|
391540
|
+
if (ask2) vctx.logger.Info().Any("event", { chatId: req2.chatId }).Msg("first-build-finish-ask");
|
|
391541
|
+
return ask2;
|
|
391542
|
+
}), "read")
|
|
391543
|
+
});
|
|
391544
|
+
const beltFirstTurnBase = firstTurnMint === void 0 || finishAsk === void 0 ? firstTurnMint : { ...firstTurnMint, finishAsk };
|
|
391545
|
+
const beltFirstTurn = beltFirstTurnBase === void 0 || race === void 0 ? beltFirstTurnBase : {
|
|
391546
|
+
...beltFirstTurnBase,
|
|
391071
391547
|
joinRunning: /* @__PURE__ */ __name(async () => {
|
|
391072
391548
|
const decision = await race.agentCreate();
|
|
391073
391549
|
if (decision.kind !== "join") return void 0;
|
|
@@ -391490,6 +391966,7 @@ function createAgentTurnAction(args3) {
|
|
|
391490
391966
|
// #8912: a person's message the loop takes here starts a new turn for the per-turn tool caps.
|
|
391491
391967
|
next: /* @__PURE__ */ __name(() => nextAgentSessionMessages(liveSession.session, evidence, () => {
|
|
391492
391968
|
buildAskAnswered = true;
|
|
391969
|
+
personSpokeAgain = true;
|
|
391493
391970
|
liveSession.notePersonTurn();
|
|
391494
391971
|
}), "next"),
|
|
391495
391972
|
head: /* @__PURE__ */ __name(() => liveSession.session.head(), "head"),
|