vibes-diy 14.3.340 → 14.3.341

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.
@@ -357574,6 +357574,35 @@ init_esm();
357574
357574
  init_out4();
357575
357575
  init_lazy_type();
357576
357576
 
357577
+ // ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/backend-path-finding.ts
357578
+ init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
357579
+ init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
357580
+ init_performance2();
357581
+ var SAME_ORIGIN_API = /(["'`])(\/api\/[^"'`\s$?#]*)/;
357582
+ function maskComments(source) {
357583
+ return source.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/(^|\s)\/\/[^\n]*/g, "$1");
357584
+ }
357585
+ __name(maskComments, "maskComments");
357586
+ function isClientCode(path3) {
357587
+ return /\.(jsx?|tsx?)$/.test(path3) && path3 !== "/backend.js" && path3 !== "/access.js";
357588
+ }
357589
+ __name(isClientCode, "isClientCode");
357590
+ function sameOriginApiFinding(args3) {
357591
+ if (args3.backendHandlers.includes("fetch") === false) return void 0;
357592
+ for (const file2 of args3.changes) {
357593
+ if (isClientCode(file2.path) === false) continue;
357594
+ const match4 = SAME_ORIGIN_API.exec(maskComments(file2.contents));
357595
+ if (match4 !== null) return { path: file2.path, literal: match4[2] };
357596
+ }
357597
+ return void 0;
357598
+ }
357599
+ __name(sameOriginApiFinding, "sameOriginApiFinding");
357600
+ function sameOriginApiMessage(finding) {
357601
+ const fixed = finding.literal.replace(/^\/api\//, "/_api/");
357602
+ 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.`;
357603
+ }
357604
+ __name(sameOriginApiMessage, "sameOriginApiMessage");
357605
+
357577
357606
  // ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/work-tools.ts
357578
357607
  init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_process();
357579
357608
  init_virtual_unenv_global_polyfill_cloudflare_unenv_preset_node_console();
@@ -360737,6 +360766,8 @@ async function validateAgentFiles(vctx, args3) {
360737
360766
  "backend",
360738
360767
  "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
360768
  );
360769
+ const apiPath = sameOriginApiFinding({ backendHandlers: parsed3.handlers, changes: args3.changes });
360770
+ if (apiPath !== void 0) return refuse12("backend", sameOriginApiMessage(apiPath));
360740
360771
  }
360741
360772
  const access3 = args3.vfs.get("/access.js");
360742
360773
  if (access3 !== void 0 && args3.changes.some((file2) => file2.path === "/access.js")) {
@@ -366402,7 +366433,7 @@ async function resendChatSectionsPrevMsg(args3) {
366402
366433
  __name(resendChatSectionsPrevMsg, "resendChatSectionsPrevMsg");
366403
366434
  async function* readChatReplaySections(vctx, args3) {
366404
366435
  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.map((row) => ({ ...row, blocks: expandChatSectionBlocks(row.blocks) }));
366436
+ const sections = rows;
366406
366437
  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
366438
  and(
366408
366439
  eq(vctx.sql.tables.promptContexts.chatId, args3.chatId),
@@ -366430,7 +366461,7 @@ async function* readChatReplaySections(vctx, args3) {
366430
366461
  const receipts = args3.promptIds === void 0 ? /* @__PURE__ */ new Set() : receiptReplayTurnIds(sections.map((section) => ({ promptId: section.promptId, blocks: section.blocks })));
366431
366462
  const openedReceipts = /* @__PURE__ */ new Set();
366432
366463
  for (const section of sections) {
366433
- const { filtered: parsedBlocks, warning } = parseArrayWarning(section.blocks, PromptAndBlockMsgs);
366464
+ const { filtered: parsedBlocks, warning } = parseArrayWarning(expandChatSectionBlocks(section.blocks), PromptAndBlockMsgs);
366434
366465
  const blocks = parsedBlocks.filter((block) => !isPromptResearch(block));
366435
366466
  if (warning.length > 0) {
366436
366467
  ensureLogger(vctx.sthis, "resendChatSectionsPrevMsg").Warn().Any({ parseErrors: warning }).Msg("skip");
@@ -367811,6 +367842,102 @@ function historySectionMsgs(blocks) {
367811
367842
  return { msgs, warning };
367812
367843
  }
367813
367844
  __name(historySectionMsgs, "historySectionMsgs");
367845
+ function isCodeSummaryMsg(msg) {
367846
+ return typeof msg === "object" && msg !== null && msg.type === "history.code.summary";
367847
+ }
367848
+ __name(isCodeSummaryMsg, "isCodeSummaryMsg");
367849
+ var HISTORY_PAGE_ROWS = 200;
367850
+ async function readChatHistory(vctx, chatId, opts) {
367851
+ const t3 = vctx.sql.tables.chatSections;
367852
+ const pageRows = opts.pageRows ?? HISTORY_PAGE_ROWS;
367853
+ const reducer = historyReducer(opts.compact);
367854
+ 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)));
367855
+ keys.sort(compareSectionKeys);
367856
+ for (let start2 = 0; start2 < keys.length; start2 += pageRows) {
367857
+ const pageKeys = keys.slice(start2, start2 + pageRows);
367858
+ const want = new Set(pageKeys.map(sectionKey));
367859
+ const rows = await vctx.sql.db.select({ promptId: t3.promptId, blockSeq: t3.blockSeq, blocks: t3.blocks }).from(t3).where(
367860
+ and(
367861
+ eq(t3.chatId, chatId),
367862
+ inArray(t3.promptId, [...new Set(pageKeys.map((k4) => k4.promptId))]),
367863
+ inArray(t3.blockSeq, [...new Set(pageKeys.map((k4) => k4.blockSeq))])
367864
+ )
367865
+ );
367866
+ const byKey = /* @__PURE__ */ new Map();
367867
+ for (const row of rows) {
367868
+ const key = sectionKey(row);
367869
+ if (want.has(key)) byKey.set(key, row.blocks);
367870
+ }
367871
+ for (const k4 of pageKeys) {
367872
+ const { msgs, warning } = historySectionMsgs(byKey.get(sectionKey(k4)));
367873
+ if (warning.length > 0) opts.onWarning?.(warning);
367874
+ for (const msg of msgs) reducer.push(msg);
367875
+ }
367876
+ }
367877
+ return reducer.done();
367878
+ }
367879
+ __name(readChatHistory, "readChatHistory");
367880
+ function sectionKey(k4) {
367881
+ return `${k4.promptId}\0${k4.blockSeq}`;
367882
+ }
367883
+ __name(sectionKey, "sectionKey");
367884
+ function compareSectionKeys(a4, b4) {
367885
+ if (a4.created !== b4.created) return a4.created < b4.created ? -1 : 1;
367886
+ if (a4.promptId !== b4.promptId) return a4.promptId < b4.promptId ? -1 : 1;
367887
+ return a4.blockSeq - b4.blockSeq;
367888
+ }
367889
+ __name(compareSectionKeys, "compareSectionKeys");
367890
+ function keepForHistory(msg) {
367891
+ return isPromptReq(msg) || isToplevelLine(msg) || isCodeBegin(msg) || isCodeEnd(msg) || isCodeLine(msg) || isCodeLinesMsg(msg) || isPromptAgentEvidence(msg) && msg.evidence.kind === "active";
367892
+ }
367893
+ __name(keepForHistory, "keepForHistory");
367894
+ function historyReducer(compact) {
367895
+ const out = [];
367896
+ let inBlock = false;
367897
+ let summary;
367898
+ function line3(text3) {
367899
+ summary ??= { lineCount: 0, hunkCount: 0 };
367900
+ summary.lineCount++;
367901
+ const trimmed2 = text3.trim();
367902
+ if (trimmed2 === "<<<<<<< SEARCH") summary.hunkCount++;
367903
+ if (summary.firstNonBlank === void 0 && trimmed2.length > 0) summary.firstNonBlank = trimmed2;
367904
+ }
367905
+ __name(line3, "line");
367906
+ function flush3() {
367907
+ if (summary === void 0) return;
367908
+ out.push({ type: "history.code.summary", ...summary });
367909
+ summary = void 0;
367910
+ }
367911
+ __name(flush3, "flush");
367912
+ return {
367913
+ push(msg) {
367914
+ if (!keepForHistory(msg)) return;
367915
+ if (compact && inBlock) {
367916
+ if (isCodeLinesMsg(msg)) {
367917
+ for (const l3 of msg.lines) line3(l3);
367918
+ return;
367919
+ }
367920
+ if (isCodeLine(msg)) {
367921
+ line3(msg.line);
367922
+ return;
367923
+ }
367924
+ }
367925
+ if (compact && isCodeBegin(msg)) {
367926
+ flush3();
367927
+ inBlock = true;
367928
+ } else if (compact && isCodeEnd(msg)) {
367929
+ flush3();
367930
+ inBlock = false;
367931
+ }
367932
+ out.push(msg);
367933
+ },
367934
+ done() {
367935
+ flush3();
367936
+ return out;
367937
+ }
367938
+ };
367939
+ }
367940
+ __name(historyReducer, "historyReducer");
367814
367941
 
367815
367942
  // ../../home/runner/work/vibes.diy/vibes.diy/vibes.diy/api/svc/intern/prompt-assembly.ts
367816
367943
  function escapeAttrValue(value2) {
@@ -367864,6 +367991,14 @@ function reconstructConversationMessages(sectionMsgs, opts = {}) {
367864
367991
  for (const line3 of msg.lines) codeLine(line3);
367865
367992
  continue;
367866
367993
  }
367994
+ if (isCodeSummaryMsg(msg)) {
367995
+ if (blockBuffer) {
367996
+ blockBuffer.lineCount += msg.lineCount;
367997
+ blockBuffer.hunkCount += msg.hunkCount;
367998
+ if (!blockBuffer.firstNonBlank && msg.firstNonBlank !== void 0) blockBuffer.firstNonBlank = msg.firstNonBlank;
367999
+ }
368000
+ continue;
368001
+ }
367867
368002
  switch (true) {
367868
368003
  case isPromptReq(msg): {
367869
368004
  const users = msg.request.messages.filter(isUserChatMessage);
@@ -368080,8 +368215,13 @@ __name(loadChatOwnerAndResearch, "loadChatOwnerAndResearch");
368080
368215
  async function assemblePromptPayload(vctx, args3) {
368081
368216
  const { chatId, model, newUserMessages } = args3;
368082
368217
  const [sSections, sTimeline, sStored, sOwner, sActive] = await Promise.all([
368218
+ // Paged and reduced as it is read, so a long chat's rows are never all in
368219
+ // memory at once (history-section-msgs.ts `readChatHistory`).
368083
368220
  settleRead(
368084
- vctx.sql.db.select().from(vctx.sql.tables.chatSections).where(and(eq(vctx.sql.tables.chatSections.chatId, chatId), ne(vctx.sql.tables.chatSections.blockSeq, RESEARCH_BLOCK_SEQ))).orderBy(vctx.sql.tables.chatSections.created)
368221
+ readChatHistory(vctx, chatId, {
368222
+ compact: args3.slots?.compaction !== "off",
368223
+ onWarning: /* @__PURE__ */ __name((parseErrors) => ensureLogger(vctx.sthis, "assemblePromptPayload").Warn().Any({ parseErrors }).Msg("skip"), "onWarning")
368224
+ })
368085
368225
  ),
368086
368226
  // #6870: the timeline is metadata; only the versions rendered below (the
368087
368227
  // slot sources and a `selected` version) have their contents fetched.
@@ -368091,16 +368231,7 @@ async function assemblePromptPayload(vctx, args3) {
368091
368231
  settleRead(loadActiveSettings(vctx, chatId))
368092
368232
  ]);
368093
368233
  if (sSections.isErr()) return Result.Err(sSections.Err());
368094
- const sections = sSections.Ok().value;
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
- }
368234
+ const allSectionMsgs = sSections.Ok().value;
368104
368235
  if (sTimeline.isErr()) return Result.Err(sTimeline.Err());
368105
368236
  const timelineResult = sTimeline.Ok().value;
368106
368237
  if (timelineResult.isErr()) return Result.Err(timelineResult);
@@ -377109,24 +377240,17 @@ function messagesCarryRefusedUrl(newUserMessages) {
377109
377240
  __name(messagesCarryRefusedUrl, "messagesCarryRefusedUrl");
377110
377241
  async function assembleAgentPayload(vctx, args3) {
377111
377242
  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 = vctx.sql.db.select().from(vctx.sql.tables.chatSections).where(and(eq(vctx.sql.tables.chatSections.chatId, args3.chatId), ne(vctx.sql.tables.chatSections.blockSeq, RESEARCH_BLOCK_SEQ))).orderBy(vctx.sql.tables.chatSections.created).then((rows) => rows);
377243
+ const pSections = readChatHistory(vctx, args3.chatId, {
377244
+ compact: true,
377245
+ onWarning: /* @__PURE__ */ __name((parseErrors) => ensureLogger(vctx.sthis, "assembleAgentPayload").Warn().Any({ parseErrors }).Msg("skip"), "onWarning")
377246
+ });
377113
377247
  const pTimeline = loadVersionTimeline(vctx, args3.chatId);
377114
377248
  void pSections.catch(() => void 0);
377115
377249
  const chatOwner = await pChatOwner;
377116
377250
  if (chatOwner !== void 0 && chatOwner.userId !== args3.userId) {
377117
377251
  return Result.Err("chat_not_owned");
377118
377252
  }
377119
- const sections = await pSections;
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
- }
377253
+ const allSectionMsgs = await pSections;
377130
377254
  const { messages: reconstructed } = reconstructConversationMessages(allSectionMsgs, { compact: true });
377131
377255
  const alternativeLabel = alternativeReadyLabel(allSectionMsgs);
377132
377256
  const alternative = alternativeLabel === void 0 ? [] : [alternativeContextLine(alternativeLabel)];
@@ -148,6 +148,7 @@
148
148
  "vibes.diy/api/svc/intern/backend-notify-callback.ts",
149
149
  "vibes.diy/api/svc/intern/backend-notify-op.ts",
150
150
  "vibes.diy/api/svc/intern/backend-onchange-policy.ts",
151
+ "vibes.diy/api/svc/intern/backend-path-finding.ts",
151
152
  "vibes.diy/api/svc/intern/backend-policy-version.ts",
152
153
  "vibes.diy/api/svc/intern/backend-put-state.ts",
153
154
  "vibes.diy/api/svc/intern/backend-stripe-callback.ts",
@@ -2824,6 +2825,7 @@
2824
2825
  "vibes.diy/api/svc/intern/backend-log-rate.ts",
2825
2826
  "vibes.diy/api/svc/intern/backend-notify-callback.ts",
2826
2827
  "vibes.diy/api/svc/intern/backend-onchange-policy.ts",
2828
+ "vibes.diy/api/svc/intern/backend-path-finding.ts",
2827
2829
  "vibes.diy/api/svc/intern/backend-put-state.ts",
2828
2830
  "vibes.diy/api/svc/intern/backend-stripe-callback.ts",
2829
2831
  "vibes.diy/api/svc/intern/backend-youtube-callback.ts",