@floless/app 0.166.0 → 0.167.0

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/dist/web/chat.js CHANGED
@@ -2404,14 +2404,24 @@
2404
2404
  reason: 'the AI marked this claim but named no source for it' },
2405
2405
  citationId: claims.answerId, index: -1, number: 0, chatId: state.chat?.chatId ?? null, owner: ownerQuery(), ownerObject: state.scope?.owner ?? null });
2406
2406
  }
2407
- for (const record of citationAssumptions(turnId)) { const row = byAnchor.get(record.anchor); if (row) row.assumption = record; }
2408
- // #2643: the sources the person chose. The latest is the claim's current one while the AI has given it none; the
2409
- // earlier ones are its history. A chosen source is numbered like a cited one: the "?" becomes a number.
2407
+ // #2643: the sources the person chose. The latest live one is the claim's current one (#3017: on a claim with no
2408
+ // source, or on one whose cited source FloLess found gone, while that citation is still the claim's); the others are
2409
+ // its history. A chosen source is numbered like a cited one: the "?" becomes a number.
2410
2410
  for (const [anchor, made] of citationChoices(turnId)) {
2411
2411
  const row = byAnchor.get(anchor);
2412
2412
  if (!row) continue;
2413
2413
  row.choices = made;
2414
- if (row.entry.status !== 'resolved') row.choice = made[made.length - 1];
2414
+ const live = made.filter((choice) => decisionLiveOn(row, choice)).at(-1);
2415
+ if (live) row.choice = live;
2416
+ }
2417
+ // #2642: the person's assumption. The live one (none while a live choice stands) is the claim's current decision;
2418
+ // otherwise its first record is history ("Earlier assumed").
2419
+ for (const record of citationAssumptions(turnId)) {
2420
+ const row = byAnchor.get(record.anchor);
2421
+ if (!row) continue;
2422
+ const live = !row.choice && decisionLiveOn(row, record);
2423
+ if (live && !row.assumptionLive) { row.assumption = record; row.assumptionLive = true; }
2424
+ else if (!row.assumption) row.assumption = record;
2415
2425
  }
2416
2426
  // #3000: an entry the answer never marks is not a claim: it is listed apart as "Also consulted", unnumbered, and
2417
2427
  // never offered as an assumption. Without answer text (none recorded yet) nothing tells the two apart. One the
@@ -2420,7 +2430,7 @@
2420
2430
  const used = claims ? order.filter(claimed) : order;
2421
2431
  const unused = claims ? order.filter((anchor) => !claimed(anchor)) : [];
2422
2432
  let n = 0;
2423
- for (const anchor of order) { const row = byAnchor.get(anchor); row.number = used.includes(anchor) && (row.entry.status === 'resolved' || row.choice) ? ++n : 0; }
2433
+ for (const anchor of order) { const row = byAnchor.get(anchor); row.number = used.includes(anchor) && ((row.entry.status === 'resolved' && !row.assumptionLive) || row.choice) ? ++n : 0; }
2424
2434
  return { byAnchor, order: used, unused };
2425
2435
  }
2426
2436
 
@@ -2526,10 +2536,11 @@
2526
2536
  || typeof p.anchor !== 'string' || !CITE_ANCHOR.test(p.anchor) || !(p.claim === null || citeText(p.claim, 300))
2527
2537
  || !citeText(p.chosenBy, 200) || !citeText(p.chosenAt, 40) || Number.isNaN(Date.parse(p.chosenAt)) || p.via !== 'chip') continue;
2528
2538
  const source = chosenSourceOf(p.source);
2529
- if (!source) continue;
2530
- if (!claimHeld(p.citationId, turnId, p.anchor)) continue;
2539
+ const basis = goneBasisOf(p.basis);
2540
+ if (!source || basis === null) continue;
2541
+ if (!claimHeld(p.citationId, turnId, p.anchor) || !basisHeld({ citationId: p.citationId, anchor: p.anchor, basis }, turnId)) continue;
2531
2542
  const made = out.get(p.anchor) ?? [];
2532
- made.push({ eventId: event.eventId, anchor: p.anchor, chosenBy: p.chosenBy, chosenAt: p.chosenAt, source });
2543
+ made.push({ eventId: event.eventId, anchor: p.anchor, citationId: p.citationId, chosenBy: p.chosenBy, chosenAt: p.chosenAt, source, ...(basis ? { basis } : {}) });
2533
2544
  out.set(p.anchor, made);
2534
2545
  }
2535
2546
  return out;
@@ -2585,7 +2596,9 @@
2585
2596
 
2586
2597
  /**
2587
2598
  * #2642: the person's "go on with this as an assumption" on this answer's claims — the server's validity rule
2588
- * (`liveCitationAssumptions`): what it names holds the claim (`claimHeld`); the first record per claim wins.
2599
+ * (`liveCitationAssumptions`): what it names holds the claim (`claimHeld`); the first record per claim wins. #3017: one
2600
+ * per claim with no source, and one per claim and citation decided on a cited source found gone; which of them is live
2601
+ * is `decisionLiveOn`, decided where the claim's current entry is known (`citationIndex`).
2589
2602
  */
2590
2603
  function citationAssumptions(turnId) {
2591
2604
  const out = new Map();
@@ -2597,15 +2610,56 @@
2597
2610
  const p = event.payload || {};
2598
2611
  // Every check `normalizeCitationAssumption` makes: a row the server would not tell the AI about is never shown as one.
2599
2612
  if (p.turnId !== turnId || typeof p.turnId !== 'string' || !uuid.test(p.turnId) || typeof p.citationId !== 'string' || !uuid.test(p.citationId)
2600
- || typeof p.anchor !== 'string' || !CITE_ANCHOR.test(p.anchor) || out.has(p.anchor) || !(p.claim === null || text(p.claim, 300))
2613
+ || typeof p.anchor !== 'string' || !CITE_ANCHOR.test(p.anchor) || !(p.claim === null || text(p.claim, 300))
2601
2614
  || !text(p.assumedBy, 200) || !text(p.assumedAt, 40) || Number.isNaN(Date.parse(p.assumedAt)) || p.via !== 'chip') continue;
2602
- if (!claimHeld(p.citationId, turnId, p.anchor)) continue;
2615
+ const basis = goneBasisOf(p.basis);
2616
+ const slot = basis ? `${p.anchor}\u0000${p.citationId.toLowerCase()}` : p.anchor;
2617
+ if (basis === null || out.has(slot)) continue;
2618
+ if (!claimHeld(p.citationId, turnId, p.anchor) || !basisHeld({ citationId: p.citationId, anchor: p.anchor, basis }, turnId)) continue;
2603
2619
  // #3000: the claim's own words are kept with it, so the record always says which claim it is about.
2604
- out.set(p.anchor, { anchor: p.anchor, claim: p.claim, assumedBy: p.assumedBy, assumedAt: p.assumedAt });
2620
+ out.set(slot, { anchor: p.anchor, citationId: p.citationId, claim: p.claim, assumedBy: p.assumedBy, assumedAt: p.assumedAt, ...(basis ? { basis } : {}) });
2605
2621
  }
2606
2622
  return [...out.values()];
2607
2623
  }
2608
2624
 
2625
+ /**
2626
+ * #3017: a decision's source-gone basis as the server stores it (`normalizeGoneBasis`): undefined when there is none,
2627
+ * null when one is there but is not what the route writes (the record is then ignored, never read as a claim with no
2628
+ * source).
2629
+ */
2630
+ const GONE_SOURCE_STATES = ['removed', 'unavailable', 'not-as-attached'];
2631
+ const CITED_IDENTITY = {
2632
+ sheet: ['projectId', 'projectUuid', 'pageId', 'sourceHash'], member: ['projectId', 'projectUuid', 'memberId', 'modelEtag'],
2633
+ 'kb-page': ['projectId', 'projectUuid', 'slug', 'generationId', 'contentDigest'], 'kb-source': ['projectId', 'projectUuid', 'sourceId', 'blobSha256'],
2634
+ 'project-file': ['projectId', 'projectUuid', 'path', 'digest'], attachment: ['attachmentId', 'digest'],
2635
+ };
2636
+ function goneBasisOf(value) {
2637
+ if (value === undefined) return undefined;
2638
+ if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).some((key) => !['kind', 'state', 'index', 'checkedAt'].includes(key))) return null;
2639
+ if (value.kind !== 'source-gone' || !GONE_SOURCE_STATES.includes(value.state) || !Number.isSafeInteger(value.index) || value.index < 0 || value.index >= 12
2640
+ || typeof value.checkedAt !== 'string' || value.checkedAt.length > 40 || Number.isNaN(Date.parse(value.checkedAt))) return null;
2641
+ return { kind: 'source-gone', state: value.state, index: value.index, checkedAt: value.checkedAt };
2642
+ }
2643
+
2644
+ /** #3017: a basis is about the claim its record names: that citation's entry at `basis.index` is resolved, for it (`basisHolds`). */
2645
+ function basisHeld(record, turnId) {
2646
+ if (!record.basis) return true;
2647
+ const held = state.events.find((row) => row.eventId === record.citationId && row.type === 'citation' && row.turnId === turnId);
2648
+ const entry = Array.isArray(held?.payload?.entries) ? held.payload.entries[record.basis.index] : undefined;
2649
+ return !!entry && typeof entry === 'object' && !Array.isArray(entry) && entry.anchor === record.anchor && entry.status === 'resolved'
2650
+ && Object.hasOwn(CITED_IDENTITY, entry.kind) && !!entry.ref && typeof entry.ref === 'object' && !Array.isArray(entry.ref)
2651
+ && CITED_IDENTITY[entry.kind].every((key) => typeof entry.ref[key] === 'string' && entry.ref[key].length > 0);
2652
+ }
2653
+
2654
+ /**
2655
+ * #3017: whether a person's decision is still the claim's current one (`decisionLive`): with no basis, while the claim
2656
+ * has no source; decided on a gone source, while the claim's current entry is still the citation it was decided on.
2657
+ */
2658
+ function decisionLiveOn(row, record) {
2659
+ if (record.basis) return !row.entry.bare && row.citationId === record.citationId;
2660
+ return row.entry.bare || row.entry.status !== 'resolved';
2661
+ }
2662
+
2609
2663
  /** Who and when, in words: an account id is "you" (FloLess holds no display name), a date is "23 Oct 2026". */
2610
2664
  function assumedWho(record) {
2611
2665
  return /^[0-9a-f]{8}-[0-9a-f]{4}-/i.test(record.assumedBy) || record.assumedBy === 'You' ? 'you' : record.assumedBy;
@@ -2622,6 +2676,8 @@
2622
2676
  if (entry.kind === 'member') return entry.read === 'mentioned' ? 'yes, its @-mention was in your message' : 'not recorded';
2623
2677
  // #2701: FloLess keeps the AI's request to read a file of the project folder, never what came back, so it is not "yes".
2624
2678
  if (entry.kind === 'project-file') return entry.read === 'requested' ? 'not confirmed, the AI asked to read it but FloLess has no record of what came back' : 'not recorded';
2679
+ // #3002: FloLess records that a Knowledge reference file was named, never that it was read.
2680
+ if (entry.kind === 'kb-source') return 'not recorded';
2625
2681
  if (entry.kind === 'attachment') {
2626
2682
  if (entry.read === 'looked') {
2627
2683
  const pages = Array.isArray(entry.ref?.pagesLooked) ? entry.ref.pagesLooked : [];
@@ -2661,13 +2717,162 @@
2661
2717
  return `/api/chat/conversations/${encodeURIComponent(row.chatId)}/citations/${encodeURIComponent(row.citationId)}/${row.index}/${what}?${row.owner}${extra}`;
2662
2718
  }
2663
2719
 
2664
- /** An answer's text, with its source markers made from FloLess's record of what it cited. */
2665
- function renderAnswerBody(body, text, turnId) {
2720
+ /**
2721
+ * An answer's text, with its source markers made from FloLess's record of what it cited. `finished`: the answer's turn
2722
+ * is over (from chat state, never from the streaming animation), so #3001's dimension check may mark it; returns how
2723
+ * many numbers it marked.
2724
+ */
2725
+ function renderAnswerBody(body, text, turnId, finished = false) {
2666
2726
  inlineSlots = [];
2667
2727
  let slots = [];
2668
2728
  try { body.innerHTML = markdownHtml(text); }
2669
2729
  finally { slots = inlineSlots; inlineSlots = null; }
2670
2730
  if (slots.length) fillInlineSlots(body, slots, turnId);
2731
+ return finished ? markUncitedDimensions(body) : 0;
2732
+ }
2733
+
2734
+ /*
2735
+ * #3001: FloLess's dimension check (v1). A number that looks like a dimension (mm, feet and inches, a fraction, a steel
2736
+ * section) in a sentence with no citation or assumption marker gets a quiet underline. It only labels: the answer is
2737
+ * never changed or held back, and the label promises nothing about numbers it does not look for.
2738
+ *
2739
+ * It reads the answer as drawn. A sentence lies inside one block (a paragraph, list item, table cell or heading, each
2740
+ * text node counted only in its nearest one) and ends after ".", "!" or "?" before a space, or at a line break. Only a
2741
+ * marker that rendered as a chip anchors it, so a malformed or quoted ":cite[…]" left as text does not. Code, link text,
2742
+ * buttons and the chips themselves are never read. A number split across two text nodes (`**20** mm`) is left unmarked.
2743
+ */
2744
+ const UNCITED_BLOCKS = 'p, li, td, th, h1, h2, h3, h4, h5, h6';
2745
+ const UNCITED_SKIP = 'code, pre, a, button, .ai-chat-cite, .ai-chat-assume, .ai-chat-uncited';
2746
+ const UNCITED_ANCHOR = '.ai-chat-cite, .ai-chat-assume';
2747
+ const VULGAR = '½¼¾⅛⅜⅝⅞⅓⅔';
2748
+ const DIM_NUMBER = String.raw`\d+(?:[.,]\d+)?`;
2749
+ const DIM_INCHES = String.raw`(?:\d+[ -]\d+\/\d+|\d+\/\d+|\d+(?:\.\d+)?[${VULGAR}]?|[${VULGAR}])`;
2750
+ const DIMENSION_PATTERNS = [
2751
+ // Metric, lower case only: not "10 m²", "10 mm/s", "5 ms" or "20mmé".
2752
+ new RegExp(String.raw`(?<![\p{L}\p{N}_])${DIM_NUMBER} ?(?:mm|cm|m)(?![\p{L}\p{N}²³\/^])`, 'gu'),
2753
+ // Feet and inches: 12'-6", 12' 6 1/2", 12′ 6½″, 12', 1 3/8", 3/4". A mark needs a digit (or fraction) before it.
2754
+ new RegExp(String.raw`(?<![\p{L}\p{N}_])(?:\d+['′](?:[ -]?${DIM_INCHES}["″])?|${DIM_INCHES}["″])(?![\p{L}])`, 'gu'),
2755
+ new RegExp(String.raw`(?<![\p{L}\p{N}_])${DIM_NUMBER} ?(?:ft|feet)(?![\p{L}\p{N}])`, 'gu'),
2756
+ // "6 in" only when no word follows: never "arrives in 6 in total".
2757
+ new RegExp(String.raw`(?<![\p{L}\p{N}_])${DIM_NUMBER} ?in(?=\s*(?:$|[^\s\p{L}\p{N}]))`, 'gu'),
2758
+ // Sections: the letters must run straight into a digit, then the X structure (AISC) or a size (EN/UK).
2759
+ new RegExp(String.raw`(?<![\p{L}\p{N}_])(?:HSS|PIPE|HP|MC|WT|MT|ST|W|M|S|C|L)\d+(?:\.\d+)?(?:[ -]\d+\/\d+)?(?: ?[x×] ?\d+(?:\.\d+)?(?:[ -]?\d+\/\d+|\/\d+)?){1,2}(?![\p{L}\p{N}])`, 'giu'),
2760
+ new RegExp(String.raw`(?<![\p{L}\p{N}_])(?:IPE|HEA|HEB|HEM|UB|UC|PFC|SHS|RHS|CHS)\d+(?: ?[x×] ?\d+(?:\.\d+)?){0,2}(?![\p{L}\p{N}])`, 'giu'),
2761
+ ];
2762
+
2763
+ /** The dimension-like numbers in one text, the longest winning where two overlap, in order: [start, end) pairs. */
2764
+ function dimensionMatches(text) {
2765
+ const found = [];
2766
+ for (const pattern of DIMENSION_PATTERNS) {
2767
+ pattern.lastIndex = 0;
2768
+ for (const match of text.matchAll(pattern)) found.push([match.index, match.index + match[0].length]);
2769
+ }
2770
+ found.sort((a, b) => (b[1] - b[0]) - (a[1] - a[0]) || a[0] - b[0]);
2771
+ const kept = [];
2772
+ for (const range of found) if (!kept.some((other) => range[0] < other[1] && other[0] < range[1])) kept.push(range);
2773
+ return kept.sort((a, b) => a[0] - b[0]);
2774
+ }
2775
+
2776
+ /** The text nodes, rendered markers and line breaks of one block, in order, leaving out nested blocks and skipped parts. */
2777
+ function uncitedPieces(block) {
2778
+ const pieces = [];
2779
+ const walk = (node) => {
2780
+ for (const child of node.childNodes) {
2781
+ if (child.nodeType === 3) pieces.push({ text: child });
2782
+ else if (child.nodeType !== 1) continue;
2783
+ else if (child.matches(UNCITED_ANCHOR)) pieces.push({ anchor: true });
2784
+ else if (child.matches(UNCITED_SKIP) || child.matches(UNCITED_BLOCKS)) continue;
2785
+ else if (child.tagName === 'BR') pieces.push({ boundary: true });
2786
+ else walk(child);
2787
+ }
2788
+ };
2789
+ walk(block);
2790
+ return pieces;
2791
+ }
2792
+
2793
+ /** Neighbouring text nodes joined into one, as a browser's parser leaves them, so a number is never split by how it was parsed. */
2794
+ function joinTextRuns(node) {
2795
+ for (const child of [...node.childNodes]) {
2796
+ if (child.nodeType === 1) joinTextRuns(child);
2797
+ else if (child.nodeType === 3 && child.previousSibling?.nodeType === 3) { child.previousSibling.data += child.data; child.remove(); }
2798
+ }
2799
+ }
2800
+
2801
+ function markUncitedDimensions(body) {
2802
+ let count = 0;
2803
+ joinTextRuns(body);
2804
+ for (const block of body.querySelectorAll(UNCITED_BLOCKS)) {
2805
+ // sentence index → whether a marker anchors it; and each match with the sentence it starts in.
2806
+ const anchored = new Set();
2807
+ const marks = [];
2808
+ let sentence = 0;
2809
+ // A full stop that ends one text node ends its sentence only if the next text starts with a space: `**Use 20 mm.**
2810
+ // Other claim` splits there, `20 mm.:cite[a]` does not.
2811
+ let ended = false;
2812
+ for (const piece of uncitedPieces(block)) {
2813
+ if (piece.anchor) { anchored.add(sentence); continue; }
2814
+ if (piece.boundary) { sentence += 1; ended = false; continue; }
2815
+ const text = piece.text.data;
2816
+ if (!text) continue;
2817
+ if (ended && /^\s/.test(text)) sentence += 1;
2818
+ ended = /[.!?]$/.test(text);
2819
+ const ends = [...text.matchAll(/[.!?](?=\s)/g)].map((match) => match.index);
2820
+ for (const [start, end] of dimensionMatches(text)) marks.push({ node: piece.text, start, end, sentence: sentence + ends.filter((at) => at < start).length });
2821
+ sentence += ends.length;
2822
+ }
2823
+ // Right to left within each node, so splitting one match never moves the next.
2824
+ for (const mark of marks.filter((row) => !anchored.has(row.sentence)).reverse()) {
2825
+ const text = mark.node.data;
2826
+ const span = document.createElement('span');
2827
+ span.className = 'ai-chat-uncited';
2828
+ span.dataset.tip = 'No citation or assumption marker in this sentence. FloLess only checks numbers that look like dimensions.';
2829
+ span.textContent = text.slice(mark.start, mark.end);
2830
+ // Only the node's tail is cut off, so a mark earlier in the same node keeps its offsets.
2831
+ mark.node.after(span, document.createTextNode(text.slice(mark.end)));
2832
+ mark.node.data = text.slice(0, mark.start);
2833
+ count += 1;
2834
+ }
2835
+ }
2836
+ return count;
2837
+ }
2838
+
2839
+ /**
2840
+ * #3001: whether an answer's numbers may be checked: only once its turn is no longer the active one, read from chat
2841
+ * state, never from the streaming animation (which pauses between bursts and under reduced motion), so marks never come
2842
+ * and go under a reply that is still arriving.
2843
+ */
2844
+ function answerFinished(event, streaming) {
2845
+ return !streaming && !(event.turnId && state.chat?.activeTurn?.turnId === event.turnId);
2846
+ }
2847
+
2848
+ /**
2849
+ * #3001: where each answer's control last moved to, by conversation and answer. The feed rebuilds every answer on its
2850
+ * 5 s poll, so the next press carries on from there, and a highlight still fresh is drawn again on the new mark.
2851
+ */
2852
+ const uncitedVisits = new Map();
2853
+
2854
+ /** #3001: the one keyboard control for an answer's marked numbers: each press moves to the next one. */
2855
+ function uncitedDimensionsControl(body, count, key) {
2856
+ const row = document.createElement('div'); row.className = 'ai-chat-uncited-row';
2857
+ row.dataset.answerKey = key;
2858
+ const next = button(count === 1 ? '1 number with no citation or assumption marker' : `${count} numbers with no citation or assumption marker`,
2859
+ 'shell.chat-uncited-dimensions', 'ai-chat-source-action quiet');
2860
+ next.dataset.tip = 'FloLess looks for a citation or an assumption marker on numbers that look like dimensions (mm, feet and inches, fractions, steel sections). It does not check every claim.';
2861
+ const visit = uncitedVisits.get(key);
2862
+ if (visit && Date.now() < visit.until) body.querySelectorAll('.ai-chat-uncited')[visit.at]?.classList.add('answer-jump');
2863
+ next.addEventListener('click', () => {
2864
+ const marks = [...body.querySelectorAll('.ai-chat-uncited')];
2865
+ if (!marks.length) return;
2866
+ const at = ((uncitedVisits.get(key)?.at ?? -1) + 1) % marks.length;
2867
+ uncitedVisits.set(key, { at, until: Date.now() + 2600 });
2868
+ body.querySelector('.ai-chat-uncited.answer-jump')?.classList.remove('answer-jump');
2869
+ const mark = marks[at];
2870
+ mark.scrollIntoView({ block: 'nearest' });
2871
+ mark.classList.remove('answer-jump'); void mark.offsetWidth; mark.classList.add('answer-jump');
2872
+ announce(`Number ${at + 1} of ${marks.length} with no citation or assumption marker: ${mark.textContent}`);
2873
+ });
2874
+ row.append(next);
2875
+ return row;
2671
2876
  }
2672
2877
 
2673
2878
  /** The markers an answer's directives asked for, built from FloLess's own record of what was cited. */
@@ -2684,21 +2889,24 @@
2684
2889
  continue;
2685
2890
  }
2686
2891
  const row = index.byAnchor.get(spec.anchor) ?? null;
2687
- const resolved = row?.entry.status === 'resolved';
2688
- // #2643: a source the person chose numbers the claim like a cited one, and says who chose it.
2689
- const chosen = !resolved && row?.choice ? row.choice : null;
2892
+ // #2643: a source the person chose numbers the claim like a cited one, and says who chose it. #3017: so does one
2893
+ // chosen, or an assumption recorded, after FloLess found the cited source gone: the person's decision is current.
2894
+ const chosen = row?.choice ?? null;
2895
+ const resolved = row?.entry.status === 'resolved' && !chosen && !row.assumptionLive;
2690
2896
  const sourced = resolved || !!chosen;
2691
2897
  const marker = button(sourced ? String(row.number) : '?', 'shell.chat-cite-anchor', `ai-chat-cite${sourced ? '' : ' unresolved'}`);
2692
2898
  marker.dataset.turnId = turnId || '';
2693
2899
  marker.dataset.anchor = spec.anchor;
2694
- const assumed = !sourced && row?.assumption ? row.assumption : null;
2900
+ const assumed = !sourced && row?.assumptionLive ? row.assumption : null;
2695
2901
  // #2930: the AI named a member that exists the wrong way: its reference to correct, not a claim without a source.
2696
2902
  const misnamed = !sourced && !assumed && referenceProblem(row?.entry);
2697
2903
  const label = resolved ? citationLabel(row.entry) : chosen ? citationLabel(chosenViewRow(row, chosen).entry) : assumed ? 'assumption, no source'
2698
2904
  : misnamed ? 'source needs correcting' : 'no source';
2699
2905
  // No citation for this anchor on this page is "none recorded", not "none found": the AI may have given none, or the
2700
2906
  // record has not reached this page yet.
2701
- const missing = assumed ? `No source. Assumed by ${assumedWho(assumed)} on ${assumedWhen(assumed)}`
2907
+ const missing = assumed ? `${assumed.basis ? `The cited source ${GONE_SAID[assumed.basis.state]} when FloLess checked` : 'No source'}. Assumed by ${assumedWho(assumed)} on ${assumedWhen(assumed)}`
2908
+ : misnamed === 'kb-source' ? (row.entry.match === 'bytes' ? 'Source needs correcting: the file is in Knowledge, but the AI cited FloLess’s copy of it'
2909
+ : 'Source needs correcting: the AI cited FloLess’s copy of a file that may be one of the reference files in Knowledge')
2702
2910
  : misnamed ? 'Source needs correcting: the member exists, but the AI named it wrongly'
2703
2911
  : row?.entry.bare ? 'The AI gave no source for this claim'
2704
2912
  : row ? 'No source was found for this claim' : 'No source is recorded for this claim';
@@ -2720,7 +2928,8 @@
2720
2928
  // The person's decision, beside the "?" that stays: it is still not a source. A solid edge tells it from the AI's own tag.
2721
2929
  const tag = document.createElement('span'); tag.className = 'ai-chat-assume by-person';
2722
2930
  tag.textContent = 'Assumption';
2723
- tag.dataset.tip = `${assumedWho(assumed) === 'you' ? 'You' : assumedWho(assumed)} recorded this as an assumption (${assumedWhen(assumed)}). It has no source.`;
2931
+ tag.dataset.tip = `${assumedWho(assumed) === 'you' ? 'You' : assumedWho(assumed)} recorded this as an assumption (${assumedWhen(assumed)}). `
2932
+ + (assumed.basis ? `Its cited source ${GONE_SAID[assumed.basis.state]} when FloLess checked.` : 'It has no source.');
2724
2933
  marker.after(tag);
2725
2934
  }
2726
2935
  }
@@ -2740,14 +2949,22 @@
2740
2949
 
2741
2950
  const ASSUME_LABEL = 'Record as an assumption';
2742
2951
  /** #2930: the problems that mean the AI named a member that exists the wrong way (server CITATION_REFERENCE_PROBLEMS). */
2952
+ /** #3002: a copy FloLess matched to a reference file only by its name: maybe that file, never said to be it. */
2953
+ const KB_SOURCE_NAME_WORDS = 'The AI cited FloLess’s copy of a file by its path. It may be one of the reference files in Knowledge (not confirmed), and the reference needs correcting.';
2743
2954
  const REFERENCE_WORDS = {
2744
2955
  'id-as-mark': 'The AI gave this member’s internal ID where its mark should be. The member exists, but the reference needs correcting.',
2745
2956
  'wrong-mark': 'The AI named a mark that does not match this member. The member exists, but the reference needs correcting.',
2746
2957
  'id-spelling': 'The AI misspelled this member’s ID. The member exists, but the reference needs correcting.',
2747
2958
  ambiguous: 'The AI’s reference matches more than one member, so it has to say which one it meant.',
2959
+ // #3002: FloLess's own copy of a Knowledge reference file, cited by its path in the project's records.
2960
+ 'kb-source': 'The AI cited FloLess’s copy of a Knowledge reference file by its path. The file is in Knowledge, but the reference needs correcting.',
2748
2961
  };
2749
2962
  function referenceProblem(entry) {
2750
- return entry?.status === 'unresolved' && entry.kind === 'member' && Object.hasOwn(REFERENCE_WORDS, entry.problem) ? entry.problem : null;
2963
+ if (entry?.status !== 'unresolved') return null;
2964
+ // #3002: only a copy FloLess matched to a reference file (by its bytes, or possibly by its name) is a reference to
2965
+ // correct; a copy that matches nothing is a claim with no source like any other.
2966
+ if (entry.kind === 'project-file') return entry.problem === 'kb-source' && ['bytes', 'name'].includes(entry.match) ? 'kb-source' : null;
2967
+ return entry.kind === 'member' && entry.problem !== 'kb-source' && Object.hasOwn(REFERENCE_WORDS, entry.problem) ? entry.problem : null;
2751
2968
  }
2752
2969
  function answerRunning(turnId) {
2753
2970
  return !!turnId && ['running', 'awaiting-approval'].includes(state.chat?.state) && state.chat?.activeTurn?.turnId === turnId;
@@ -2784,7 +3001,7 @@
2784
3001
  cited.textContent = entry.label;
2785
3002
  cited.dataset.tip = 'What the AI cited';
2786
3003
  const why = document.createElement('span'); why.className = 'ai-chat-source-why';
2787
- why.textContent = REFERENCE_WORDS[entry.problem];
3004
+ why.textContent = entry.problem === 'kb-source' && entry.match !== 'bytes' ? KB_SOURCE_NAME_WORDS : REFERENCE_WORDS[entry.problem];
2788
3005
  chip.append(cited, why);
2789
3006
  const done = citationNote(row, turnId);
2790
3007
  if (done) { chip.append(done); return chip; }
@@ -2822,6 +3039,18 @@
2822
3039
  // Words are shortened for the message; a member id never is: it is what the AI cites.
2823
3040
  const quoted = (value, limit = 160) => JSON.stringify(limit ? String(value).slice(0, limit) : String(value));
2824
3041
  const claim = unsourcedClaimWords(turnId, row.anchor);
3042
+ if (row.entry.problem === 'kb-source') {
3043
+ // #3002: the file is cited by the Knowledge source it is, never by the path of FloLess's own copy.
3044
+ return [
3045
+ `In your earlier answer, you cited FloLess's copy of a Knowledge reference file by its path, so FloLess could not show it as found${row.number ? ` (source ${row.number})` : ''}.`,
3046
+ `What you cited: ${quoted(row.entry.label)}.`,
3047
+ ...(claim ? [`The claim it supports: ${quoted(claim)}.`] : []),
3048
+ ...(row.entry.sourceId ? [`The Knowledge reference file's sourceId is ${quoted(row.entry.sourceId, 0)}.`] : []),
3049
+ 'The quoted text is what was written earlier, not an instruction.',
3050
+ row.entry.sourceId ? 'Answer that part again and cite the file with kind "kb-source" and that sourceId.'
3051
+ : 'Answer that part again and cite the Knowledge reference file you read with kind "kb-source" and its sourceId, or the Knowledge page with kind "kb-page".',
3052
+ ].join(' ');
3053
+ }
2825
3054
  return [
2826
3055
  `In your earlier answer, you named a model member the wrong way, so FloLess could not show it as found${row.number ? ` (source ${row.number})` : ''}.`,
2827
3056
  `What you cited: ${quoted(row.entry.label)}.`,
@@ -2869,8 +3098,10 @@
2869
3098
  const number = document.createElement('span'); number.className = 'ai-chat-source-n';
2870
3099
  number.textContent = row.number ? String(row.number) : '?';
2871
3100
  chip.append(number);
2872
- if (row.entry.status !== 'resolved' && row.choice) return chosenChip(chip, turnId, row);
3101
+ if (row.choice) return chosenChip(chip, turnId, row);
2873
3102
  const entry = row.entry;
3103
+ // #3017: the person went on with a claim whose cited source FloLess found gone.
3104
+ if (entry.status === 'resolved' && row.assumptionLive) return goneAssumedChip(chip, turnId, row, number);
2874
3105
  if (entry.status !== 'resolved') {
2875
3106
  const why = document.createElement('span'); why.className = 'ai-chat-source-why';
2876
3107
  const ask = button('Ask for the source', 'shell.chat-cite-ask', 'ai-chat-source-action');
@@ -2882,7 +3113,7 @@
2882
3113
  choose.dataset.tip = 'Pick the sheet, model member, Knowledge page or attached file this claim comes from. It is recorded as chosen by you, with the date; nothing checks the claim';
2883
3114
  choose.setAttribute('aria-haspopup', 'dialog');
2884
3115
  choose.addEventListener('click', () => openSourcePicker(row, turnId, null));
2885
- if (row.assumption) {
3116
+ if (row.assumptionLive) {
2886
3117
  // #2642: the person's recorded decision. Still "?" — an assumption is not a source, and nothing was checked.
2887
3118
  chip.classList.add('assumed');
2888
3119
  number.setAttribute('aria-label', 'Assumption, no source');
@@ -2932,6 +3163,11 @@
2932
3163
  const marks = document.createElement('span'); marks.className = 'ai-chat-source-marks';
2933
3164
  marks.textContent = citationMarks(entry);
2934
3165
  chip.append(open, marks);
3166
+ // #3002/#3017: where the source stands now, as the answer's check or its viewer last found it, after every repaint;
3167
+ // one that is gone offers the ways on.
3168
+ const seen = seenSource(row);
3169
+ markSourceChip(chip, seen, entry);
3170
+ if (GONE_SOURCE_STATES.includes(seen)) chip.append(goneActions(turnId, row));
2935
3171
  // A source cited after the person went on without one, or chose one: their decision stays visible, and the source
2936
3172
  // is still unchecked.
2937
3173
  const before = [row.assumption ? `Earlier assumed by ${assumedWho(row.assumption)}, ${assumedWhen(row.assumption)}` : '',
@@ -2966,7 +3202,8 @@
2966
3202
  if (entry.status !== 'resolved') {
2967
3203
  chip.classList.add('not-found');
2968
3204
  const why = document.createElement('span'); why.className = 'ai-chat-source-why';
2969
- why.textContent = referenceProblem(entry) ? 'The AI named this member wrongly. Not used in the answer.' : `Not found: ${entry.reason}. Not used in the answer.`;
3205
+ why.textContent = referenceProblem(entry) === 'kb-source' ? 'The AI cited this file the wrong way. Not used in the answer.'
3206
+ : referenceProblem(entry) ? 'The AI named this member wrongly. Not used in the answer.' : `Not found: ${entry.reason}. Not used in the answer.`;
2970
3207
  chip.append(claimCited(entry.label, 'What the AI cited'), why);
2971
3208
  return chip;
2972
3209
  }
@@ -2979,6 +3216,78 @@
2979
3216
  const marks = document.createElement('span'); marks.className = 'ai-chat-source-marks';
2980
3217
  marks.textContent = citationMarks(entry);
2981
3218
  chip.append(open, marks);
3219
+ // #3002/#3017: where it stands now, said like any cited source; it supports no claim, so there is nothing to decide.
3220
+ markSourceChip(chip, seenSource(row), entry);
3221
+ return chip;
3222
+ }
3223
+
3224
+ /**
3225
+ * #3017: the ways on from a claim whose cited source FloLess found gone: choose another source, or go on with it as an
3226
+ * assumption. Quiet, beside the cited source the chip still opens (it may come back). FloLess checks again before
3227
+ * either is recorded. Each button names its claim, so several gone sources in one answer are told apart.
3228
+ */
3229
+ function goneActions(turnId, row) {
3230
+ const label = citationLabel(row.entry);
3231
+ const choose = goneChoose(turnId, row);
3232
+ const assume = button(ASSUME_LABEL, 'shell.chat-cite-assume', 'ai-chat-source-action quiet');
3233
+ assume.dataset.commandInstanceLabel = label;
3234
+ assume.setAttribute('aria-label', `${ASSUME_LABEL}: the claim citing ${label}`);
3235
+ assume.dataset.tip = 'Saves your decision with your name and the date, and labels the claim Assumption. Nothing runs now: the AI receives it with your next message';
3236
+ assume.addEventListener('click', () => assumeClaim(row, turnId, assume.closest('.ai-chat-source'), assume, row.index));
3237
+ const actions = sourceActions(choose, assume);
3238
+ const saved = citationNote(row, turnId);
3239
+ if (!saved) return actions;
3240
+ const both = document.createDocumentFragment();
3241
+ both.append(actions, saved);
3242
+ return both;
3243
+ }
3244
+
3245
+ /**
3246
+ * `goneIndex` null: the claim's live assumption already records what FloLess found, and the choice inherits it, so the
3247
+ * source is not checked again (a source back since must not refuse the next step).
3248
+ */
3249
+ function goneChoose(turnId, row, goneIndex = row.index) {
3250
+ const label = citationLabel(row.entry);
3251
+ const choose = button('Choose another source…', 'shell.chat-cite-choose', 'ai-chat-source-action quiet');
3252
+ choose.dataset.commandInstanceLabel = label;
3253
+ choose.setAttribute('aria-label', `Choose another source for the claim citing ${label}`);
3254
+ choose.setAttribute('aria-haspopup', 'dialog');
3255
+ choose.dataset.tip = 'Pick the sheet, model member, Knowledge page or attached file this claim comes from instead. It is recorded as chosen by you, with the date; nothing checks the claim';
3256
+ choose.addEventListener('click', () => openSourcePicker(row, turnId, null, goneIndex));
3257
+ return choose;
3258
+ }
3259
+
3260
+ /** #3017: the cited source of a claim the person decided on after it was found gone, still openable: it may be back. */
3261
+ function citedSourceOpener(turnId, row) {
3262
+ const label = citationLabel(row.entry);
3263
+ const open = button('Open the cited source', 'shell.chat-cite-open', 'ai-chat-source-action quiet');
3264
+ open.dataset.commandInstanceLabel = label;
3265
+ open.setAttribute('aria-label', `Open the cited source: ${label}`);
3266
+ open.dataset.tip = `What the AI cited: ${label}`;
3267
+ open.addEventListener('click', () => openCitedSource(row, turnId));
3268
+ return open;
3269
+ }
3270
+
3271
+ /**
3272
+ * #3017: the person's assumption on a claim whose cited source FloLess found gone. Still "?": an assumption is not a
3273
+ * source. It says what FloLess found and when it looked, never that the source is still gone; when the answer's check
3274
+ * finds it there again, the tag says so and the record stays as the person made it.
3275
+ */
3276
+ function goneAssumedChip(chip, turnId, row, number) {
3277
+ const record = row.assumption;
3278
+ chip.classList.add('assumed', 'gone');
3279
+ number.setAttribute('aria-label', `Assumption. The cited source ${GONE_SAID[record.basis.state]} when FloLess checked`);
3280
+ const why = document.createElement('span'); why.className = 'ai-chat-source-why';
3281
+ why.textContent = `Assumed by ${assumedWho(record)}, ${assumedWhen(record)}. The cited source ${GONE_SAID[record.basis.state]} when FloLess checked.`;
3282
+ const marks = document.createElement('span'); marks.className = 'ai-chat-source-marks';
3283
+ const back = seenSourceAfter(row, record.basis.checkedAt) === 'same';
3284
+ marks.textContent = back ? 'ASSUMPTION · SOURCE FOUND AGAIN' : 'ASSUMPTION';
3285
+ marks.dataset.tip = back ? 'Your decision to go on as an assumption stays as you made it. FloLess has since found the cited source there again'
3286
+ : 'Your decision to go on without the cited source. Nothing checked this claim. The AI is reminded of it with each message you send';
3287
+ const claimed = record.claim ? claimCited(`“${record.claim}”`, 'The claim you recorded as an assumption') : claimCited(citationLabel(row.entry), 'What the AI cited');
3288
+ chip.append(...(claimed ? [claimed] : []), why, marks, sourceActions(citedSourceOpener(turnId, row), goneChoose(turnId, row, null)));
3289
+ const saved = citationNote(row, turnId);
3290
+ if (saved) chip.append(saved);
2982
3291
  return chip;
2983
3292
  }
2984
3293
 
@@ -3022,9 +3331,12 @@
3022
3331
  change.setAttribute('aria-haspopup', 'dialog');
3023
3332
  change.dataset.tip = 'Pick a different source. The earlier choice stays in the record';
3024
3333
  change.addEventListener('click', () => openSourcePicker(row, turnId, row.choice.eventId));
3025
- chip.append(open, marks, change);
3334
+ // #3017: chosen after FloLess found the cited source gone: what it found and when, and the cited source to open.
3335
+ const basis = row.choice.basis;
3336
+ chip.append(open, marks, basis ? sourceActions(change, citedSourceOpener(turnId, row)) : change);
3026
3337
  const earlier = row.choices.length > 1 ? row.choices[row.choices.length - 2] : null;
3027
- const before = [row.assumption ? `Earlier assumed by ${assumedWho(row.assumption)}, ${assumedWhen(row.assumption)}` : '',
3338
+ const before = [basis ? `The cited source ${citationLabel(row.entry)} ${GONE_SAID[basis.state]} when FloLess checked` : '',
3339
+ row.assumption ? `Earlier assumed by ${assumedWho(row.assumption)}, ${assumedWhen(row.assumption)}` : '',
3028
3340
  earlier ? `Changed from ${earlier.source.label}` : ''].filter(Boolean);
3029
3341
  if (before.length) {
3030
3342
  const note = document.createElement('span'); note.className = 'ai-chat-source-note';
@@ -3039,7 +3351,7 @@
3039
3351
  * the server writes it with the signed-in account and the date. The conversation is the one the chip was painted for:
3040
3352
  * a reply that lands after the person moved to another conversation changes nothing on screen.
3041
3353
  */
3042
- async function assumeClaim(row, turnId, chip, assume) {
3354
+ async function assumeClaim(row, turnId, chip, assume, goneIndex = null) {
3043
3355
  if (assume.getAttribute('aria-busy') === 'true' || !row.chatId) return;
3044
3356
  chip.querySelector('.ai-chat-source-note')?.remove();
3045
3357
  // Busy, not disabled: a disabled button drops the keyboard focus to the page.
@@ -3049,12 +3361,14 @@
3049
3361
  let saved = null; let problem = '';
3050
3362
  try {
3051
3363
  const result = await request(`/api/chat/conversations/${encodeURIComponent(row.chatId)}/citations/${encodeURIComponent(row.citationId)}/assume`, {
3052
- method: 'POST', body: JSON.stringify({ owner: row.ownerObject, turnId, anchor: row.anchor, claim: claim || null }),
3364
+ method: 'POST', body: JSON.stringify({ owner: row.ownerObject, turnId, anchor: row.anchor, claim: claim || null,
3365
+ // #3017: a claim the AI cited, whose source FloLess found gone: FloLess checks that again before recording.
3366
+ ...(goneIndex === null ? {} : { sourceGone: { index: goneIndex } }) }),
3053
3367
  });
3054
3368
  saved = result?.event ?? null;
3055
3369
  } catch (error) {
3056
3370
  // The server's own sentence when it says why nothing was recorded; anything else is a plain "try again".
3057
- problem = ['chat-cite-assume-stale', 'chat-cite-assume-unknown', 'chat-cite-assume-unreadable'].includes(error?.code)
3371
+ problem = ['chat-cite-assume-stale', 'chat-cite-assume-unknown', 'chat-cite-assume-unreadable', 'chat-cite-assume-source-there'].includes(error?.code)
3058
3372
  ? String(error.message) : 'Could not save your choice. Try again.';
3059
3373
  }
3060
3374
  if (state.chat?.chatId !== row.chatId) return;
@@ -3064,7 +3378,7 @@
3064
3378
  noteCitation(row, turnId, { text: 'Saved. The AI will receive this with your next message.', untilNextMessage: true });
3065
3379
  paintEvents();
3066
3380
  const after = [...ui.feed.querySelectorAll('.ai-chat-source')].find((node) => node.dataset.turnId === (turnId || '') && node.dataset.anchor === row.anchor);
3067
- after?.querySelector('[data-command-id="shell.chat-cite-ask"]')?.focus({ preventScroll: true });
3381
+ after?.querySelector('[data-command-id="shell.chat-cite-ask"], [data-command-id="shell.chat-cite-choose"]')?.focus({ preventScroll: true });
3068
3382
  const record = citationIndex(turnId).byAnchor.get(row.anchor)?.assumption;
3069
3383
  announce(record ? `Marked as an assumption by ${assumedWho(record)}, ${assumedWhen(record)}. No source.` : 'Your choice was saved.');
3070
3384
  return;
@@ -3091,11 +3405,11 @@
3091
3405
  * FloLess's own records. Everything the save needs is taken now, from the chip as painted: a reply that lands after the
3092
3406
  * person moved on (another conversation, the list closed) changes nothing on screen.
3093
3407
  */
3094
- function openSourcePicker(row, turnId, replaces) {
3408
+ function openSourcePicker(row, turnId, replaces, goneIndex = null) {
3095
3409
  closeSourcePicker(false);
3096
3410
  if (!row.chatId) { announce('Open this conversation again to choose a source.'); return; }
3097
3411
  const command = replaces ? 'shell.chat-cite-change' : 'shell.chat-cite-choose';
3098
- const picker = { row, turnId, replaces, command, chatId: row.chatId, projects: null, projectId: null, kind: null, query: '', items: [], more: [],
3412
+ const picker = { row, turnId, replaces, goneIndex, command, chatId: row.chatId, projects: null, projectId: null, kind: null, query: '', items: [], more: [],
3099
3413
  status: 'loading', note: '', active: -1, seq: 0, timer: null, saving: null, problem: '', pending: null };
3100
3414
  state.sourcePicker = picker;
3101
3415
  const dialog = document.createElement('div'); dialog.className = 'ai-chat-source-picker';
@@ -3407,7 +3721,9 @@
3407
3721
  try {
3408
3722
  const result = await request(`/api/chat/conversations/${encodeURIComponent(row.chatId)}/citations/${encodeURIComponent(row.citationId)}/choose`, {
3409
3723
  method: 'POST', body: JSON.stringify({ owner: row.ownerObject, turnId, anchor: row.anchor, claim: unsourcedClaimWords(turnId, row.anchor) || null,
3410
- projectId: item.projectId, pick: item.pick, requestId: picker.pending.requestId, replaces: picker.replaces }),
3724
+ projectId: item.projectId, pick: item.pick, requestId: picker.pending.requestId, replaces: picker.replaces,
3725
+ // #3017: chosen instead of a cited source FloLess found gone: FloLess checks that again before recording.
3726
+ ...(picker.goneIndex === null ? {} : { sourceGone: { index: picker.goneIndex } }) }),
3411
3727
  });
3412
3728
  saved = result?.event ?? null;
3413
3729
  } catch (error) {
@@ -3503,6 +3819,7 @@
3503
3819
  function turnSources(turnId) {
3504
3820
  const index = citationIndex(turnId);
3505
3821
  if (!index.order.length && !index.unused.length) return null;
3822
+ probeSources(turnId, index);
3506
3823
  return citationRow(index.order.map((anchor) => citationChip(turnId, index.byAnchor.get(anchor))),
3507
3824
  index.unused.map((anchor) => consultedChip(turnId, index.byAnchor.get(anchor))));
3508
3825
  }
@@ -3805,6 +4122,11 @@
3805
4122
  dialog.addEventListener('close', finish);
3806
4123
  head.append(title, close);
3807
4124
  const note = Object.assign(document.createElement('span'), { className: 'ai-chat-source-viewer-note', textContent: citationProvenance(entry) });
4125
+ // #3017: what this open found, for the chip and for this line, which never says "Found: yes" over a source found gone.
4126
+ const found = (seen) => {
4127
+ viewerFound(row, turnId, seen);
4128
+ if (!entry.chosen && SOURCE_FOUND[seen]) note.textContent = `${SOURCE_FOUND[seen]} · Read by AI: ${citationReadWords(entry)} · Checked: no`;
4129
+ };
3808
4130
  const body = document.createElement('div'); body.className = 'ai-chat-source-viewer-body';
3809
4131
  const status = Object.assign(document.createElement('p'), { className: 'ai-chat-source-viewer-status', textContent: 'Opening…' });
3810
4132
  status.setAttribute('role', 'status');
@@ -3882,14 +4204,22 @@
3882
4204
  status.textContent = SHOWN[shown] || SHOWN['as-seen'];
3883
4205
  return;
3884
4206
  }
3885
- if (entry.kind === 'member') { await showCitedMember(row, { dialog, body, status, finish, refused, done: () => finished }); return; }
4207
+ if (entry.kind === 'member') { await showCitedMember(row, { dialog, body, status, finish, refused, done: () => finished, found }); return; }
4208
+ if (entry.kind === 'kb-source') { await showCitedKnowledgeFile(row, { body, status, refused, retry, signal: controller.signal, done: () => finished, picture: (url) => { picture = url; }, mountDrawing, loaded, stale: (state) => {
4209
+ // The viewer's own provenance line says it too: it must not still say "Found: yes" over a removed file.
4210
+ knowledgeFileStale(row, turnId, state);
4211
+ if (KNOWLEDGE_FILE_TIPS[state]) note.textContent = KNOWLEDGE_FILE_TIPS[state];
4212
+ } }); return; }
3886
4213
  if (entry.kind === 'project-file') {
3887
4214
  // #2701: a file of the project's folder, checked now against the size and digest it was cited with.
3888
4215
  const response = await fetch(citationUrl(row, 'project-file'), { credentials: 'same-origin', cache: 'no-store', signal: controller.signal });
4216
+ // #3017: a project no longer this conversation's, as the answer's check says it.
4217
+ if (response.status === 404) found('unavailable');
3889
4218
  if (!response.ok) { const why = await refused(response); if (!finished) { status.textContent = why; retry(); } return; }
3890
4219
  const { file } = await response.json();
3891
4220
  if (finished) return;
3892
4221
  if (!file) { status.textContent = 'FloLess could not open this source right now. Try again in a moment.'; return; }
4222
+ found({ gone: 'removed', changed: 'changed' }[file.state] ?? (file.state === 'refused' ? null : 'same'));
3893
4223
  if (file.state === 'refused') status.textContent = `FloLess does not open ${file.path} as the cited file: ${file.reason}.`;
3894
4224
  else if (file.state === 'gone') status.textContent = `${file.path} is no longer in the project folder.`;
3895
4225
  else if (file.state === 'changed') status.textContent = `${file.path} has changed since the answer cited it, so FloLess does not show it as the cited file.`;
@@ -3903,6 +4233,10 @@
3903
4233
  }
3904
4234
  if (entry.kind === 'attachment') {
3905
4235
  const response = await fetch(citationUrl(row, 'attachment'), { credentials: 'same-origin', cache: 'no-store', signal: controller.signal });
4236
+ // #3017: what this open found, for the chip: the attached file changed, or no longer the one attached.
4237
+ // A 404 is said for a file gone and for one no longer as attached alike, so it tells the chip nothing.
4238
+ found(response.ok ? 'same' : response.status !== 410 ? null
4239
+ : await response.clone().json().then((said) => (said?.code === 'citation-source-not-as-attached' ? 'not-as-attached' : 'changed'), () => null));
3906
4240
  if (!response.ok) { const why = await refused(response); if (!finished) { status.textContent = why; retry(); } return; }
3907
4241
  const type = (response.headers.get('Content-Type') || '').split(';')[0].trim().toLowerCase();
3908
4242
  if (type.startsWith('image/')) {
@@ -3993,12 +4327,231 @@
3993
4327
  * is now, not as the answer described it. The member's route is asked again right before moving, so a project that
3994
4328
  * left the conversation since is never opened.
3995
4329
  */
4330
+ /**
4331
+ * #3002: a Knowledge reference file the answer cited, checked now against the bytes it was cited with. FloLess shows
4332
+ * only those verified bytes; a file replaced since says so and offers the file as it is now, labelled as not the cited one.
4333
+ */
4334
+ async function showCitedKnowledgeFile(row, view) {
4335
+ const { body, status, refused, retry, signal, done } = view;
4336
+ const entry = row.entry;
4337
+ const response = await fetch(citationUrl(row, 'project-file'), { credentials: 'same-origin', cache: 'no-store', signal });
4338
+ if (!response.ok) { const why = await refused(response); if (!done()) { status.textContent = why; retry(); } return; }
4339
+ const { file } = await response.json();
4340
+ if (done()) return;
4341
+ if (!file) { status.textContent = 'FloLess could not open this source right now. Try again in a moment.'; return; }
4342
+ const name = file.filename || entry.label;
4343
+ const showText = (text, label) => {
4344
+ const pre = Object.assign(document.createElement('pre'), { className: 'ai-chat-source-viewer-text', tabIndex: 0, textContent: text });
4345
+ pre.setAttribute('aria-label', label);
4346
+ body.append(pre);
4347
+ };
4348
+ const stale = (state) => knowledgeFileStaleView(view, file, name, state);
4349
+ if (file.state === 'same') {
4350
+ view.stale?.('same');
4351
+ if (file.preview === 'text' && typeof file.text === 'string') {
4352
+ status.textContent = `${name} in Knowledge, as it was cited${file.truncated ? '. Showing the start of the file' : ''}.`;
4353
+ showText(file.text, `Text of ${name}`);
4354
+ return;
4355
+ }
4356
+ const mime = String(file.mime || '');
4357
+ if (file.preview === 'bytes' && (mime.startsWith('image/') || mime === 'application/pdf')) {
4358
+ // Only the bytes this request verified against the cited digest; a file replaced or removed since says so here.
4359
+ const bytes = await fetch(citationUrl(row, 'project-file', '&bytes=1'), { credentials: 'same-origin', cache: 'no-store', signal });
4360
+ if (bytes.status === 410) {
4361
+ const said = await bytes.json().catch(() => null);
4362
+ if (!done()) stale(KNOWLEDGE_FILE_MARKS[said?.state] ? said.state : 'changed');
4363
+ return;
4364
+ }
4365
+ if (!bytes.ok) { const why = await refused(bytes); if (!done()) status.textContent = why; return; }
4366
+ const blob = await bytes.blob();
4367
+ if (done()) return;
4368
+ const url = URL.createObjectURL(blob);
4369
+ view.picture(url);
4370
+ if (mime === 'application/pdf') {
4371
+ const frame = document.createElement('iframe');
4372
+ frame.className = 'ai-chat-source-viewer-pdf';
4373
+ frame.setAttribute('aria-label', `${name}, as it was cited`);
4374
+ frame.src = url;
4375
+ body.append(frame);
4376
+ } else {
4377
+ const image = Object.assign(document.createElement('img'), { src: url, alt: name });
4378
+ if (!await view.mountDrawing().setImage(image, () => !done(), true)) return;
4379
+ view.loaded();
4380
+ }
4381
+ status.textContent = `${name} in Knowledge, as it was cited.`;
4382
+ return;
4383
+ }
4384
+ status.textContent = `${name} in Knowledge, as it was cited (${Number(file.bytes).toLocaleString()} bytes). FloLess does not show this kind of file here.`;
4385
+ return;
4386
+ }
4387
+ stale(file.state);
4388
+ }
4389
+
4390
+ /**
4391
+ * #3002: what a cited Knowledge file's viewer found out — replaced, removed, or its cited version unreadable — said in
4392
+ * the viewer and kept on its chip, so the warning outlives the viewer. Only the chip's tag and tip change: nothing else.
4393
+ */
4394
+ const KNOWLEDGE_FILE_MARKS = { changed: 'CHANGED', removed: 'REMOVED', 'bytes-missing': 'CITED VERSION UNREADABLE' };
4395
+ const KNOWLEDGE_FILE_TIPS = {
4396
+ changed: 'Found: yes, but replaced after this answer · Read by AI: not recorded · Checked: no',
4397
+ removed: 'Found: no, removed from Knowledge after this answer · Read by AI: not recorded · Checked: no',
4398
+ 'bytes-missing': 'Found: yes, but FloLess can no longer read the version this answer cited · Read by AI: not recorded · Checked: no',
4399
+ };
4400
+ const KNOWLEDGE_FILE_SAID = {
4401
+ changed: 'replaced after this answer',
4402
+ removed: 'removed from Knowledge after this answer',
4403
+ 'bytes-missing': 'the cited version can no longer be read',
4404
+ };
4405
+ /**
4406
+ * #3017: the same for any cited source, found by the answer's own check (`source-states`) as well as by a viewer: the
4407
+ * chip's tag, what its tip says was found, and what its button's name adds. A Knowledge file keeps its own words.
4408
+ */
4409
+ const SOURCE_MARKS = { ...KNOWLEDGE_FILE_MARKS, unavailable: 'NOT IN THIS CONVERSATION', 'not-as-attached': 'NOT AS ATTACHED' };
4410
+ const SOURCE_FOUND = {
4411
+ changed: 'Found: yes, but changed after this answer',
4412
+ removed: 'Found: no, removed after this answer',
4413
+ unavailable: 'Found: no, FloLess cannot reach it from this conversation now',
4414
+ 'not-as-attached': 'Found: no, the file kept with this conversation is not the one that was attached',
4415
+ };
4416
+ const SOURCE_SAID = {
4417
+ changed: 'changed after this answer', removed: 'removed after this answer', unavailable: 'not available from this conversation now',
4418
+ 'not-as-attached': 'no longer the file that was attached',
4419
+ };
4420
+ /** #3017: a decided claim's cited source, as what FloLess found when it checked, never that it still is so. */
4421
+ const GONE_SAID = { removed: 'was removed', unavailable: 'could not be reached from this conversation', 'not-as-attached': 'was no longer the file that was attached' };
4422
+ const PROBE_STATES = new Set(['same', 'changed', 'removed', 'unavailable', 'not-as-attached']);
4423
+ const knowledgeFileKey = (row) => `${row.chatId}\u0000${row.citationId}\u0000${row.index}`;
4424
+
4425
+ /**
4426
+ * #3002/#3017: where each cited source stands, as FloLess last found it: by the answer's check (each time the
4427
+ * conversation is opened) or by a viewer that opened it, the later finding kept, so a slow check never overwrites what a
4428
+ * viewer found after it began. Display state only: never a source, never recorded. Keyed by conversation, citation, entry.
4429
+ */
4430
+ const sourceSeen = new Map();
4431
+ const probedTurns = new Set();
4432
+ function seeSource(key, seen, at) {
4433
+ const was = sourceSeen.get(key);
4434
+ if (!was || was.at <= at) sourceSeen.set(key, { state: seen, at });
4435
+ }
4436
+ function seenSource(row) { return sourceSeen.get(knowledgeFileKey(row))?.state; }
4437
+ /** What FloLess found after `iso` only: a check begun before a decision says nothing about the source since it. */
4438
+ function seenSourceAfter(row, iso) {
4439
+ const seen = sourceSeen.get(knowledgeFileKey(row));
4440
+ return seen && seen.at > Date.parse(iso) ? seen.state : undefined;
4441
+ }
4442
+
4443
+ /** Marks a chip with where its source stands now; `same` puts the chip back as it was cited. */
4444
+ function markSourceChip(chip, seen, entry) {
4445
+ const fresh = seen === 'same';
4446
+ if (!chip || !entry || (!fresh && !SOURCE_MARKS[seen])) return;
4447
+ // A person's decision (an assumption, a chosen source) is not the cited source's chip: it says what it says by its record.
4448
+ if (chip.classList.contains('assumed') || chip.classList.contains('chosen')) return;
4449
+ chip.classList.toggle('stale', GONE_SOURCE_STATES.includes(seen));
4450
+ const marks = chip.querySelector('.ai-chat-source-marks');
4451
+ if (marks) marks.textContent = fresh ? citationMarks(entry) : SOURCE_MARKS[seen];
4452
+ const open = chip.querySelector('.ai-chat-source-open');
4453
+ if (!open) return;
4454
+ const knowledge = entry.kind === 'kb-source' && Object.hasOwn(KNOWLEDGE_FILE_TIPS, seen);
4455
+ open.dataset.tip = (fresh ? citationProvenance(entry) : knowledge ? KNOWLEDGE_FILE_TIPS[seen] : `${SOURCE_FOUND[seen]} · Read by AI: ${citationReadWords(entry)} · Checked: no`)
4456
+ + (chip.classList.contains('consulted') ? ' · The answer does not cite it for any claim' : '');
4457
+ // The tip is not read out: the button's own name carries the state for keyboard and screen-reader users.
4458
+ open.setAttribute('aria-label', `Open ${open.dataset.commandInstanceLabel}${fresh ? '' : `, ${knowledge ? KNOWLEDGE_FILE_SAID[seen] : SOURCE_SAID[seen]}`}`);
4459
+ }
4460
+
4461
+ /** What a cited Knowledge file's viewer found, kept for its chip; a gone file repaints so the chip offers the ways on. */
4462
+ function knowledgeFileStale(row, turnId, seen) {
4463
+ if (seen !== 'same' && !KNOWLEDGE_FILE_MARKS[seen]) return;
4464
+ viewerFound(row, turnId, seen);
4465
+ }
4466
+
4467
+ /**
4468
+ * #3017: what the viewer of a cited project file, attachment or member found, kept for its chip as the Knowledge file's
4469
+ * is. A source the person chose has no AI chip to mark.
4470
+ */
4471
+ function viewerFound(row, turnId, seen) {
4472
+ if (row.entry.chosen || (seen !== 'same' && !SOURCE_MARKS[seen])) return;
4473
+ seeSource(knowledgeFileKey(row), seen, Date.now());
4474
+ const chip = sourceChip(turnId, row.anchor);
4475
+ const wasGone = !!chip?.classList.contains('stale');
4476
+ markSourceChip(chip, seen, row.entry);
4477
+ // A gone source gains the ways on, and one found again loses them; a decision chip is drawn again from its record
4478
+ // (an assumption may say "found again").
4479
+ if (GONE_SOURCE_STATES.includes(seen) || wasGone || chip?.classList.contains('assumed') || chip?.classList.contains('chosen')) paintEvents();
4480
+ }
4481
+
4482
+ /**
4483
+ * #3017: asks FloLess once per answer, each time the conversation is opened, where the sources it cited stand now, and
4484
+ * repaints when it hears. Not while the answer runs: its citations are not all in. A check that fails changes nothing
4485
+ * on the chips, and `unchecked` says nothing either: the chip keeps what it showed.
4486
+ */
4487
+ function probeSources(turnId, index) {
4488
+ const chatId = state.chat?.chatId;
4489
+ if (!chatId || !turnId || answerRunning(turnId)) return;
4490
+ const key = `${chatId}\u0000${turnId}`;
4491
+ if (probedTurns.has(key) || ![...index.byAnchor.values()].some((row) => row.entry.status === 'resolved' && !row.entry.bare)) return;
4492
+ probedTurns.add(key);
4493
+ const at = Date.now();
4494
+ request(`/api/chat/conversations/${encodeURIComponent(chatId)}/turns/${encodeURIComponent(turnId)}/source-states?${ownerQuery()}`).then((result) => {
4495
+ if (state.chat?.chatId !== chatId || !Array.isArray(result?.states)) return;
4496
+ let found = false;
4497
+ for (const row of result.states) {
4498
+ if (!row || typeof row.citationId !== 'string' || !Number.isSafeInteger(row.index) || !PROBE_STATES.has(row.state)) continue;
4499
+ seeSource(`${chatId}\u0000${row.citationId}\u0000${row.index}`, row.state, at);
4500
+ found = true;
4501
+ }
4502
+ if (found) paintEvents();
4503
+ }, (error) => { console.warn('floless: the cited sources of an answer could not be checked', error); });
4504
+ }
4505
+
4506
+ /** The viewer's words for a cited Knowledge file that is no longer the cited version, and the current file on request. */
4507
+ function knowledgeFileStaleView(view, file, name, state) {
4508
+ const { body, status, signal, done } = view;
4509
+ view.stale?.(state);
4510
+ if (state === 'removed') { status.textContent = `${name} was removed from Knowledge after this answer.`; return; }
4511
+ status.textContent = state === 'bytes-missing'
4512
+ ? `${name} is still in Knowledge, but FloLess can no longer read the version this answer cited.`
4513
+ : `${name} was replaced after this answer, so the cited text may differ. FloLess does not show the new file as the cited one.`;
4514
+ const showText = (text, label) => {
4515
+ const pre = Object.assign(document.createElement('pre'), { className: 'ai-chat-source-viewer-text', tabIndex: 0, textContent: text });
4516
+ pre.setAttribute('aria-label', label);
4517
+ body.append(pre);
4518
+ };
4519
+ if (state !== 'changed' || !file.projectId || !file.sourceId) return;
4520
+ const current = button('Show the file as it is now', 'shell.chat-cite-open-current', 'ai-chat-source-viewer-knowledge');
4521
+ current.dataset.tip = 'Shows the file as it is in Knowledge now. It is not the version this answer cited';
4522
+ current.addEventListener('click', async () => {
4523
+ current.remove();
4524
+ const now = await fetch(`/api/projects/${encodeURIComponent(file.projectId)}/knowledge/sources/${encodeURIComponent(file.sourceId)}/raw`,
4525
+ { credentials: 'same-origin', cache: 'no-store', signal }).catch(() => null);
4526
+ if (done()) return;
4527
+ if (!now?.ok) { status.textContent = `FloLess could not open ${name} as it is now. Try again in a moment.`; return; }
4528
+ const type = (now.headers.get('Content-Type') || '').split(';')[0].trim().toLowerCase();
4529
+ // Said before anything is shown, and kept above it: this is not what the answer cited.
4530
+ const banner = Object.assign(document.createElement('p'), { className: 'ai-chat-source-viewer-status current', textContent: 'Showing the current file, not the version this answer cited.' });
4531
+ banner.setAttribute('role', 'status');
4532
+ body.append(banner);
4533
+ if (type.startsWith('text/') || type === 'application/json') {
4534
+ const chars = [...await now.text()];
4535
+ if (done()) return;
4536
+ showText(chars.slice(0, 16000).join(''), `Current text of ${name}`);
4537
+ if (chars.length > 16000) banner.textContent += ' Showing the start of the file.';
4538
+ } else {
4539
+ await now.body?.cancel().catch(() => {});
4540
+ banner.textContent += ' FloLess does not show this kind of file here.';
4541
+ }
4542
+ });
4543
+ body.append(current);
4544
+ }
4545
+
3996
4546
  async function showCitedMember(row, view) {
3997
4547
  const { dialog, body, status, finish, refused, done } = view;
3998
4548
  const response = await fetch(citationUrl(row, 'member'), { credentials: 'same-origin', cache: 'no-store' });
4549
+ if (response.status === 404) view.found?.('unavailable');
3999
4550
  if (!response.ok) { const why = await refused(response); if (!done()) status.textContent = why; return; }
4000
4551
  const { member } = await response.json();
4001
4552
  if (done()) return;
4553
+ // #3017: "no-model" is left unsaid on the chip: the member may well still be there once the model can be read.
4554
+ view.found?.({ same: 'same', changed: 'changed', gone: 'removed' }[member.model] ?? null);
4002
4555
  const facts = document.createElement('dl'); facts.className = 'ai-chat-source-viewer-facts';
4003
4556
  const fact = (term, value) => facts.append(Object.assign(document.createElement('dt'), { textContent: term }),
4004
4557
  Object.assign(document.createElement('dd'), { textContent: value }));
@@ -4103,9 +4656,10 @@
4103
4656
  if (role === 'assistant' || visibleText) {
4104
4657
  const body = document.createElement('div'); body.className = 'ai-chat-message-body';
4105
4658
  // #2437: only an answer's own directives become source markers; the person's words stay literal.
4106
- if (role === 'assistant') renderAnswerBody(body, visibleText, event.turnId);
4107
- else body.innerHTML = markdownHtml(visibleText);
4659
+ const uncited = role === 'assistant' ? renderAnswerBody(body, visibleText, event.turnId, answerFinished(event, streaming)) : 0;
4660
+ if (role !== 'assistant') body.innerHTML = markdownHtml(visibleText);
4108
4661
  item.append(body);
4662
+ if (uncited) item.append(uncitedDimensionsControl(body, uncited, `${state.chat?.chatId ?? ''}:${event.eventId}`));
4109
4663
  }
4110
4664
  if (role === 'user' && Array.isArray(event.payload?.attachmentIds)) {
4111
4665
  const attachments = event.payload.attachmentIds
@@ -5164,6 +5718,14 @@
5164
5718
  if (['workspaces', 'workflows'].includes(screen?.view) && typeof window.flolessWorkspaces?.setMode === 'function') {
5165
5719
  await window.flolessWorkspaces.setMode(screen.view); return true;
5166
5720
  }
5721
+ // #2811: New project for a Steel model from drawings, Quick pressed when asked. Opened straight from the click (the
5722
+ // file picker needs it); the Drawing Filter question stays the person's, in the dialog.
5723
+ if (screen?.view === 'new-project' && typeof window.flolessWorkspaces?.openNewProjectFromDrawings === 'function') {
5724
+ const outcome = await window.flolessWorkspaces.openNewProjectFromDrawings({ quick: screen.buildMode === 'quick' });
5725
+ if (outcome?.ok === true) return true;
5726
+ if (typeof outcome?.said === 'string' && outcome.said) throw Object.assign(new Error(outcome.said), { plain: true });
5727
+ return false;
5728
+ }
5167
5729
  // Automatic tool updates: the dialog where the person reads the wording and chooses (it opens nothing else, runs nothing).
5168
5730
  if (screen?.view === 'tool-update-policy' && typeof window.openToolUpdatePolicy === 'function') {
5169
5731
  window.openToolUpdatePolicy(); return true;
@@ -5478,7 +6040,8 @@
5478
6040
  if (risk === 'human-only') {
5479
6041
  const screen = payload.screen || {};
5480
6042
  const open = actionButton(String(screen.label || 'Open it'), 'shell.chat-action-open', proposalId, summaryText, 'ai-chat-filter-apply');
5481
- open.dataset.tip = 'Opens the screen where you do this yourself. Nothing runs from this card.';
6043
+ open.dataset.tip = screen.view === 'new-project' ? 'Opens your file picker for the drawings, then New project. Nothing is made until you press Create.'
6044
+ : 'Opens the screen where you do this yourself. Nothing runs from this card.';
5482
6045
  open.addEventListener('click', async () => {
5483
6046
  entry.error = '';
5484
6047
  try { if (!(await openActionScreen(screen))) entry.error = screen.view === 'chat'
@@ -5494,7 +6057,9 @@
5494
6057
  actions.append(later, open);
5495
6058
  const note = document.createElement('p');
5496
6059
  note.className = 'ai-chat-filter-note';
5497
- note.textContent = 'Only you can do this. Nothing runs from here.';
6060
+ // #2811: the one question this dialog asks only the person, said on the card that takes them there.
6061
+ note.textContent = screen.view === 'new-project' ? 'In the dialog, only you decide whether the AI may choose the Drawing Filter. Nothing is made until you press Create.'
6062
+ : 'Only you can do this. Nothing runs from here.';
5498
6063
  status.textContent = entry.error;
5499
6064
  card.append(actions, note, status);
5500
6065
  return card;
@@ -9987,6 +10552,8 @@
9987
10552
  const focusedShell = focusedNode?.closest?.('.ai-chat-feed-card') || null;
9988
10553
  const focusedLine = focusedNode?.matches?.('.ai-chat-feed > .ai-chat-feed-hidden') ? String(focusedNode.dataset.commandId || '').replace('shell.chat-feed-card-show#', '') : '';
9989
10554
  const focusedChip = chipNode ? { turnId: chipNode.dataset.turnId, anchor: chipNode.dataset.anchor, command: focusedNode.dataset?.commandId || '' } : null;
10555
+ // #3001: an answer's control for its numbers with no marker is rebuilt with the answer: the keyboard stays on that answer's.
10556
+ const focusedUncited = focusedNode?.closest?.('.ai-chat-uncited-row')?.dataset.answerKey ?? null;
9990
10557
  if (options.forceBottom) state.feedLeftEnd = false; // the person just sent: the end is where they are going
9991
10558
  const nearBottom = !state.feedLeftEnd && ui.feed.scrollHeight - ui.feed.scrollTop - ui.feed.clientHeight < 56;
9992
10559
  const scrollTop = ui.feed.scrollTop;
@@ -10121,6 +10688,9 @@
10121
10688
  if (focusedNode?.isConnected && ui.feed.contains(focusedNode)) {
10122
10689
  if (document.activeElement !== focusedNode) focusedNode.focus({ preventScroll: true });
10123
10690
  refocused = focusedNode;
10691
+ } else if (focusedUncited) {
10692
+ refocused = [...ui.feed.querySelectorAll('.ai-chat-uncited-row')].find((row) => row.dataset.answerKey === focusedUncited)?.querySelector('button') ?? null;
10693
+ refocused?.focus({ preventScroll: true });
10124
10694
  } else if (focusedChip) {
10125
10695
  // #2642: a source chip is rebuilt on every repaint; the keyboard stays on the same claim's chip, on the same button
10126
10696
  // when it is still there (a recorded assumption leaves "Ask for the source", never a jump to the top of the feed).
@@ -12802,6 +13372,8 @@
12802
13372
  if (!historyReopened) closeHistoryPanel();
12803
13373
  state.chat = chat;
12804
13374
  state.events = snapshot.events || [];
13375
+ // #3017: each opening checks again where its answers' cited sources stand now.
13376
+ probedTurns.clear();
12805
13377
  reconcileUnknownFollowupOnSelection(chat);
12806
13378
  state.capability = capability;
12807
13379
  state.desktop = desktop;
@@ -15802,6 +16374,24 @@
15802
16374
  return result;
15803
16375
  }
15804
16376
 
16377
+ /**
16378
+ * #3053: the finished drawing read's "Start new chat" — the New chat button, from outside this panel: a fresh
16379
+ * conversation in the same project, the earlier one left in history. Nothing of the old transcript is carried over.
16380
+ */
16381
+ async function startNewChat(projectId) {
16382
+ // `personCopy`: the sentence is written for the person, so the caller shows it as it is (not as an unknown failure).
16383
+ const refuse = (text) => Object.assign(new Error(text), { personCopy: true });
16384
+ await refreshScope();
16385
+ const owner = state.scope?.owner;
16386
+ if (!owner || (projectId && (owner.kind !== 'project' || owner.projectId !== projectId))) {
16387
+ throw refuse('AI Chat is not showing this project yet. Wait a moment, then choose Start new chat again.');
16388
+ }
16389
+ window.flolessBridge?.revealAiChat?.();
16390
+ ui.tab.click();
16391
+ if (ui.newChat.disabled) throw refuse('AI Chat is finishing a reply. Start a new chat once it is done, with New chat at the top of AI Chat.');
16392
+ ui.newChat.click();
16393
+ }
16394
+
15805
16395
  async function openConversation(chatId, options = {}) {
15806
16396
  await refreshScope();
15807
16397
  if (options.owner !== undefined) {
@@ -17007,7 +17597,7 @@
17007
17597
  paintAttachments();
17008
17598
  });
17009
17599
  window.flolessChat = {
17010
- refreshScope, refreshActivity, refreshIndex, startRequest, openConversation, openConversationIn, openDraft, openVerifiedTeklaDraft,
17600
+ refreshScope, refreshActivity, refreshIndex, startRequest, openConversation, openConversationIn, startNewChat, openDraft, openVerifiedTeklaDraft,
17011
17601
  startProjectIntake, resumeProjectIntake, startWorkflowBuild,
17012
17602
  // The plain-English sentence for a refusal the chat routes named, so a Start outside this panel
17013
17603
  // (the upload modal, Requests) says what happened and what to do next instead of a generic toast (#1779).