fwdloop 0.14.0 → 0.16.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/bin/fwdloop +106 -31
- package/package.json +2 -2
- package/src/authoring.js +26 -11
- package/src/checked.js +9 -5
- package/src/closers.js +5 -0
- package/src/config.js +66 -4
- package/src/declaration.js +27 -1
- package/src/draft-steps.js +79 -0
- package/src/drafter.js +54 -15
- package/src/flow.js +220 -5
- package/src/flowmodel.js +30 -0
- package/src/input-facts.js +12 -3
- package/src/keysfile.js +51 -16
- package/src/model-step.js +13 -11
- package/src/monthly.js +9 -1
- package/src/panel/author.js +89 -24
- package/src/panel/authorcard.js +80 -20
- package/src/panel/authorflows.js +72 -21
- package/src/panel/authorresume.js +11 -10
- package/src/panel/authorstart.js +29 -19
- package/src/panel/data.js +62 -21
- package/src/panel/index.html +662 -185
- package/src/panel/resume.js +3 -3
- package/src/panel/server.js +5 -4
- package/src/panel/settings.js +138 -80
- package/src/panel/spawn.js +15 -9
- package/src/provider.js +136 -178
- package/src/providershapes.js +7 -7
- package/src/runner.js +47 -23
- package/src/signed-diff.js +71 -0
- package/src/thinking.js +55 -0
- package/types/authoring.d.ts +20 -7
- package/types/checked.d.ts +6 -4
- package/types/closers.d.ts +2 -0
- package/types/config.d.ts +9 -1
- package/types/draft-steps.d.ts +14 -0
- package/types/drafter.d.ts +13 -10
- package/types/flow.d.ts +42 -2
- package/types/flowmodel.d.ts +16 -0
- package/types/input-facts.d.ts +6 -1
- package/types/keysfile.d.ts +23 -6
- package/types/model-step.d.ts +1 -1
- package/types/monthly.d.ts +1 -0
- package/types/panel/author.d.ts +78 -6
- package/types/panel/authorcard.d.ts +53 -8
- package/types/panel/authorflows.d.ts +68 -6
- package/types/panel/authorresume.d.ts +2 -1
- package/types/panel/authorstart.d.ts +17 -6
- package/types/panel/data.d.ts +10 -6
- package/types/panel/resume.d.ts +2 -1
- package/types/panel/server.d.ts +3 -1
- package/types/panel/settings.d.ts +3 -1
- package/types/panel/spawn.d.ts +13 -4
- package/types/provider.d.ts +94 -284
- package/types/providershapes.d.ts +3 -4
- package/types/runner.d.ts +2 -4
- package/types/signed-diff.d.ts +10 -0
- package/types/thinking.d.ts +25 -0
package/src/panel/index.html
CHANGED
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
|
|
127
127
|
[hidden]{display:none !important;}
|
|
128
128
|
.main{display:flex;flex:1;min-height:0;}
|
|
129
|
-
.left-pane{width:
|
|
129
|
+
.left-pane{width:630px;flex:none;border-right:1px solid var(--border-strong);display:flex;flex-direction:column;background:var(--panel);}
|
|
130
130
|
.right-pane{flex:1;min-width:0;display:flex;flex-direction:column;}
|
|
131
131
|
|
|
132
132
|
.tabrow{display:flex;border-bottom:1px solid var(--border-strong);background:var(--panel2);counter-reset:tabnum;}
|
|
@@ -499,6 +499,9 @@
|
|
|
499
499
|
.chat-steps .step.wait .step-label{color:var(--amber);}
|
|
500
500
|
.chat-steps .step-detail{display:block;flex-basis:100%;min-width:0;padding-left:1.2em;color:var(--text-faint);word-break:break-word;white-space:pre-wrap;}
|
|
501
501
|
.chat-steps .step.bad .step-detail{color:var(--red);}
|
|
502
|
+
.chat-steps .step[data-step="thinking"].bad .step-label{color:var(--red);font-weight:600;}
|
|
503
|
+
.chat-steps .step-raw{margin-top:2px;color:var(--text-faint);}
|
|
504
|
+
.chat-steps .step-raw summary{cursor:pointer;}
|
|
502
505
|
.chat-steps .step.run .step-sign::after{content:"\2026";}
|
|
503
506
|
@keyframes step-dots{0%{content:"";}25%{content:".";}50%{content:"..";}75%{content:"...";}}
|
|
504
507
|
@media (prefers-reduced-motion: no-preference){
|
|
@@ -521,7 +524,10 @@
|
|
|
521
524
|
.msg.bot .who::before{content:"$ ";}
|
|
522
525
|
.msg .who{font-size:11px;color:var(--text-faint);margin-bottom:3px;text-transform:none;font-weight:400;}
|
|
523
526
|
/* the card's free-text boxes wrap (textarea): grow a few rows (fitBox), then scroll inside */
|
|
524
|
-
.job-card textarea.jf-wrap{width:100%;box-sizing:border-box;font:inherit;padding:6px 8px;border:1px solid var(--border-strong);border-radius:0;background:var(--bg);color:var(--text);resize:vertical;overflow-y:auto;
|
|
527
|
+
.job-card textarea.jf-wrap{width:100%;box-sizing:border-box;font:inherit;padding:6px 8px;border:1px solid var(--border-strong);border-radius:0;background:var(--bg);color:var(--text);resize:vertical;overflow-y:auto;}
|
|
528
|
+
/* M6 am2: every job box (the textarea and the read-only lines) grows with its text up to 8 lines, then scrolls inside:
|
|
529
|
+
8 x 1.5em + 6px padding x2 + 1px border x2; ONE rule, fitBox reads this cap */
|
|
530
|
+
.job-card textarea.jf-wrap, .job-card .ro-lines{line-height:1.5;max-height:calc(12em + 14px);}
|
|
525
531
|
/* the focused/selected Chat-card field gets a blue border (the accent), no outline ring */
|
|
526
532
|
#panel-chat :is(input,select,textarea):focus{border-color:var(--accent);outline:none;}
|
|
527
533
|
/* amendment 2: the job and inputs boxes have a gutter OUTSIDE them on the left (`N >` per step, `~` per guardrail; a number per input
|
|
@@ -560,7 +566,7 @@
|
|
|
560
566
|
.rw-picked{display:flex;justify-content:space-between;align-items:center;gap:8px;margin-top:6px;padding:6px 8px;border:1px solid var(--accent);}
|
|
561
567
|
.rw-picked span{overflow-wrap:anywhere;}
|
|
562
568
|
.rw-picked a{font-size:12px;cursor:pointer;flex:none;}
|
|
563
|
-
.ro-lines{padding:6px 8px;border:1px solid var(--border);background:var(--bg);color:var(--text-dim);font-size:12px;overflow-wrap:anywhere;
|
|
569
|
+
.ro-lines{padding:6px 8px;border:1px solid var(--border);background:var(--bg);color:var(--text-dim);font-size:12px;overflow-wrap:anywhere;overflow-y:auto;}
|
|
564
570
|
.ro-lines .ro-line{display:flex;gap:8px;}
|
|
565
571
|
.ro-lines .ro-n{flex:none;min-width:1.4em;color:var(--text-faint);}
|
|
566
572
|
.jf-waitrow{margin-bottom:4px;}
|
|
@@ -663,20 +669,92 @@
|
|
|
663
669
|
.keyfile-strip{position:relative;border:1px solid var(--border-strong);padding:12px 12px 8px;background:var(--panel2);margin:14px 0;font-size:12px;display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap;}
|
|
664
670
|
.keyfile-strip::before{content:"┤ KEYS ├";position:absolute;top:-9px;left:10px;background:var(--panel2);padding:0 4px;font-size:11px;color:var(--text-faint);letter-spacing:0.08em;}
|
|
665
671
|
.keyfile-strip-main{display:flex;flex-direction:column;gap:3px;flex:1;min-width:0;overflow-wrap:anywhere;}
|
|
666
|
-
.keyfile-strip-actions{display:flex;gap:6px;flex:none;}
|
|
672
|
+
.keyfile-strip-actions{display:flex;flex-wrap:wrap;gap:6px;flex:none;max-width:100%;}
|
|
667
673
|
.keyfile-strip code{background:var(--bg);border:1px solid var(--border-strong);padding:1px 5px;font-size:11px;color:var(--amber);overflow-wrap:anywhere;}
|
|
668
674
|
.settings-view input,.settings-view select{font:inherit;padding:6px 8px;border:1px solid var(--border-strong);border-radius:0;background:var(--bg);color:var(--text);}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
.pv-
|
|
674
|
-
.pv-
|
|
675
|
-
.pv-
|
|
675
|
+
/* M4d Providers layout F (hamr approved 2026-10-11, the design lab's Variant F): ONE shared grid, so a key row, the model sub-head and
|
|
676
|
+
every model row sit on the same column edges. Key band: KEY | API SHAPE | BASE URL (two columns) | OLD MAX_TOKENS | TOKENS | refresh.
|
|
677
|
+
Model row: [USE 44px][MODEL] under KEY, IN + OUT side by side under BASE URL, TOKENS on the key band's TOKENS edge. A key row has a
|
|
678
|
+
solid 1px line, a model row a dotted 1px hairline. Below 1280px every row collapses to stacked label : value lines. */
|
|
679
|
+
.pv-grid{--pv-cols:minmax(0,2.8fr) minmax(0,1.5fr) minmax(0,.95fr) minmax(0,.95fr) minmax(0,.9fr) minmax(0,.6fr) 272px;font-size:13px;}
|
|
680
|
+
.pv-head,.pv-krow,.pv-mhead,.pv-mrow{display:grid;grid-template-columns:var(--pv-cols);column-gap:8px;align-items:center;padding:0 8px;min-width:0;}
|
|
681
|
+
.pv-head > *,.pv-krow > *,.pv-mhead > *,.pv-mrow > *{min-width:0;}
|
|
682
|
+
.pv-head,.pv-mhead{font-size:11px;font-weight:700;color:var(--text-dim);letter-spacing:0.04em;min-height:26px;}
|
|
683
|
+
.pv-head{background:var(--panel2);border-bottom:1px solid var(--border-strong);}
|
|
684
|
+
.pv-mhead{background:var(--bg);border-bottom:1px dotted var(--border-strong);}
|
|
685
|
+
.pv-key{border-top:1px solid var(--border-strong);}
|
|
686
|
+
.pv-krow{min-height:40px;padding-top:4px;padding-bottom:4px;}
|
|
687
|
+
.pv-c-url{grid-column:3 / span 2;}
|
|
688
|
+
.pv-lbl{display:none;}
|
|
689
|
+
.pv-name{display:flex;align-items:center;flex-wrap:wrap;gap:4px 6px;min-width:0;overflow-wrap:anywhere;}
|
|
690
|
+
.pv-name code{font-weight:700;}
|
|
691
|
+
.pv-ok{color:var(--green);font-weight:700;}
|
|
692
|
+
.pv-fold{border:0;background:none;color:var(--text);font:inherit;padding:0 4px 0 0;min-width:22px;min-height:24px;cursor:pointer;text-align:left;}
|
|
693
|
+
.pv-krow select,.pv-krow input[type=text]{width:100%;max-width:100%;min-height:28px;box-sizing:border-box;}
|
|
694
|
+
.pv-grid select,.pv-grid input[type=text]{font-size:12px;height:28px;padding:2px 6px;}
|
|
695
|
+
.pv-legacy{display:inline-flex;align-items:center;gap:6px;cursor:pointer;min-height:28px;text-transform:none;letter-spacing:0;font-weight:400;font-size:12px;}
|
|
696
|
+
.pv-legacy input,.pv-m-use input{width:16px;height:16px;margin:0;accent-color:var(--accent);cursor:pointer;}
|
|
697
|
+
.pv-tok{text-align:right;font-variant-numeric:tabular-nums;}
|
|
698
|
+
.pv-refcell{display:flex;justify-content:flex-end;}
|
|
699
|
+
.pv-refbox{display:flex;flex-direction:column;align-items:flex-start;max-width:100%;}
|
|
700
|
+
.pv-refbtns{display:flex;gap:6px;}
|
|
701
|
+
.pv-refbox .pv-msg{width:0;min-width:100%;overflow-wrap:anywhere;margin:2px 0 0;}
|
|
702
|
+
.pv-refbox .pv-msg:empty{display:none;}
|
|
703
|
+
.pv-refbtn{white-space:nowrap;flex:0 0 auto;}
|
|
704
|
+
.pv-refbtn:disabled{opacity:.5;cursor:not-allowed;}
|
|
705
|
+
.pv-sum{color:var(--text-faint);font-size:11px;font-weight:400;}
|
|
706
|
+
.pv-key[data-open="1"] .pv-sum{display:none;}
|
|
707
|
+
.pv-knote{padding:0 8px 4px 34px;margin:0;}
|
|
708
|
+
.pv-knote:empty{display:none;}
|
|
709
|
+
.pv-knote > .hint:empty{display:none;}
|
|
710
|
+
.pv-key[data-open="0"] .pv-models{display:none;}
|
|
711
|
+
.pv-mrow{border-top:1px dotted var(--border-strong);min-height:32px;}
|
|
712
|
+
.pv-mrow:hover,.pv-mrow:focus-within{background:var(--panel2);}
|
|
713
|
+
.pv-um{grid-column:1;display:flex;align-items:center;gap:0;min-width:0;}
|
|
714
|
+
.pv-uh,.pv-m-use{flex:0 0 44px;width:44px;display:flex;align-items:center;justify-content:center;}
|
|
715
|
+
.pv-m-use{min-height:32px;}
|
|
716
|
+
.pv-m-name{min-width:0;overflow-wrap:anywhere;font-size:12px;}
|
|
717
|
+
.pv-pair{grid-column:3 / span 2;display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);column-gap:8px;align-items:center;min-width:0;}
|
|
718
|
+
.pv-pair > *{min-width:0;}
|
|
719
|
+
.pv-pair input[type=text]{width:100%;text-align:right;}
|
|
720
|
+
.pv-mhead .pv-tok{text-align:right;}
|
|
721
|
+
.pv-mhead .pv-tok,.pv-m-tok{grid-column:6;}
|
|
722
|
+
.pv-m-msg{grid-column:1 / -1;padding:2px 8px 2px 52px;margin:0;}
|
|
723
|
+
.pv-m-msg:empty{display:none;}
|
|
724
|
+
.pv-more{padding:3px 8px 3px 34px;border-top:1px dotted var(--border-strong);}
|
|
725
|
+
.pv-more:empty{display:none;}
|
|
726
|
+
.pv-more .pv-add{border:0;background:none;color:var(--accent);font:inherit;font-size:12px;padding:2px 0;min-height:24px;cursor:pointer;text-decoration:underline;}
|
|
727
|
+
.pv-more.pv-failed{color:var(--amber);background:var(--amber-bg);font-size:12px;}
|
|
728
|
+
.pv-typed{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;margin-top:4px;}
|
|
729
|
+
.pv-typed input{flex:1 1 160px;min-width:0;max-width:260px;min-height:28px;box-sizing:border-box;}
|
|
730
|
+
.pv-typed .hint{flex:1 1 100%;margin:0;}
|
|
731
|
+
.field label.jf-thinking{display:flex;flex-direction:row;align-items:center;justify-content:flex-start;gap:6px;margin-top:6px;font-size:12px;text-transform:none;letter-spacing:0;}
|
|
732
|
+
.field label.jf-thinking input{width:auto;min-height:0;margin:0;}
|
|
676
733
|
.hint.bad{color:var(--red);}
|
|
677
734
|
.table-wrap{overflow-x:auto;border:1px solid var(--border-strong);background:var(--panel2);max-width:100%;}
|
|
678
735
|
@media (max-width: 899px){
|
|
679
736
|
.money-strip{grid-template-columns:1fr 1fr;}
|
|
737
|
+
.keyfile-strip-main{flex:1 1 100%;}
|
|
738
|
+
}
|
|
739
|
+
@media (max-width: 1279px){
|
|
740
|
+
.pv-head,.pv-mhead{display:none;}
|
|
741
|
+
.pv-krow,.pv-mrow{display:block;padding:2px 8px;}
|
|
742
|
+
.pv-cell{display:grid;grid-template-columns:104px minmax(0,1fr);gap:8px;align-items:center;min-height:44px;border-top:1px dotted var(--border);}
|
|
743
|
+
.pv-cell:first-child{border-top:none;}
|
|
744
|
+
.pv-lbl{display:block;font-size:11px;text-transform:uppercase;letter-spacing:.04em;color:var(--text-dim);font-weight:700;}
|
|
745
|
+
.pv-cell.nolbl{display:flex;}
|
|
746
|
+
.pv-tok{text-align:left;}
|
|
747
|
+
.pv-grid select,.pv-grid input[type=text]{height:44px;font-size:14px;}
|
|
748
|
+
.pv-krow select,.pv-krow input[type=text]{min-height:44px;}
|
|
749
|
+
.pv-legacy{min-height:44px;gap:10px;}
|
|
750
|
+
.pv-legacy input,.pv-m-use input{width:24px;height:24px;}
|
|
751
|
+
.pv-um{min-height:44px;}
|
|
752
|
+
.pv-uh,.pv-m-use{min-height:44px;}
|
|
753
|
+
.pv-cell.pv-pair{display:grid;grid-template-columns:104px minmax(0,1fr) minmax(0,1fr);}
|
|
754
|
+
.pv-cell.pv-pair::before{content:"In / Out $/1M";font-size:11px;text-transform:uppercase;letter-spacing:.04em;color:var(--text-dim);font-weight:700;}
|
|
755
|
+
.pv-fold,.pv-refbtn,.pv-more .pv-add{min-height:44px;min-width:44px;}
|
|
756
|
+
.pv-knote,.pv-more{padding-left:8px;}
|
|
757
|
+
.pv-m-msg{padding-left:8px;}
|
|
680
758
|
}
|
|
681
759
|
</style>
|
|
682
760
|
</head>
|
|
@@ -712,20 +790,20 @@
|
|
|
712
790
|
<div class="keyfile-strip-main">
|
|
713
791
|
<span>Put <code>NAME=key</code> lines in <code id="keys-path" data-testid="keys-path">~/.config/fwdloop/.env</code>, then Reload keys — each row below says whether its key is set. Only names are listed; keys never reach this page.</span>
|
|
714
792
|
<span class="hint bad" id="keys-refusal" data-testid="keys-refusal"></span>
|
|
793
|
+
<span class="hint" id="keys-open-note" data-testid="keys-open-note"></span>
|
|
715
794
|
</div>
|
|
716
795
|
<div class="keyfile-strip-actions">
|
|
796
|
+
<button class="btn small" id="open-keys-folder" type="button" data-testid="open-keys-folder" aria-label="Open keys folder">Open keys folder</button>
|
|
717
797
|
<button class="btn small" id="reload-keys" type="button" data-testid="reload-keys">Reload keys</button>
|
|
718
798
|
</div>
|
|
719
799
|
</div>
|
|
720
800
|
<div class="table-wrap" data-testid="provider-table-wrap">
|
|
721
|
-
<
|
|
722
|
-
<
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
<tbody id="pv-rows"></tbody>
|
|
726
|
-
</table>
|
|
801
|
+
<div class="pv-grid" data-testid="provider-table">
|
|
802
|
+
<div class="pv-head" aria-hidden="true"><span>KEY</span><span>API SHAPE</span><span class="pv-c-url">BASE URL</span><span>OLD MAX_TOKENS</span><span class="pv-tok">TOKENS</span><span></span></div>
|
|
803
|
+
<div id="pv-rows"></div>
|
|
804
|
+
</div>
|
|
727
805
|
</div>
|
|
728
|
-
<div class="hint" id="pv-note" data-testid="pv-note" style="margin-top:6px;"
|
|
806
|
+
<div class="hint" id="pv-note" data-testid="pv-note" style="margin-top:6px;">⟳ refresh models (free) · old max_tokens: tick if the server wants the old field name</div>
|
|
729
807
|
</section>
|
|
730
808
|
<section id="spanel-money" class="tabpanel" role="tabpanel" aria-labelledby="stab-money" hidden>
|
|
731
809
|
<div class="money-strip" data-testid="money-strip">
|
|
@@ -783,6 +861,14 @@
|
|
|
783
861
|
</div>
|
|
784
862
|
|
|
785
863
|
<div id="jf-new" data-testid="jf-new">
|
|
864
|
+
<div class="hint edit-banner" id="jf-edit-banner" data-testid="jf-edit-banner" hidden></div>
|
|
865
|
+
<div class="field">
|
|
866
|
+
<label for="jf-model">Model</label>
|
|
867
|
+
<select id="jf-model" data-testid="jf-model" disabled><option value="">Reading your models…</option></select>
|
|
868
|
+
<label class="jf-thinking"><input type="checkbox" id="jf-thinking" data-testid="jf-thinking"> Thinking on</label>
|
|
869
|
+
<div class="hint" id="jf-thinking-note" data-testid="jf-thinking-note"></div>
|
|
870
|
+
<div class="jf-err" id="jf-err-model" data-testid="jf-err-model"></div>
|
|
871
|
+
</div>
|
|
786
872
|
<div class="field">
|
|
787
873
|
<label for="jf-name">Flow name</label>
|
|
788
874
|
<input id="jf-name" type="text" placeholder="lowercase letters, digits, - or _" autocomplete="off" spellcheck="false" data-testid="jf-name">
|
|
@@ -794,15 +880,9 @@
|
|
|
794
880
|
<div class="jf-gut" id="jf-job-gut" data-testid="jf-job-gut" aria-hidden="true"><div class="jf-gut-in"></div></div>
|
|
795
881
|
<textarea class="jf-wrap" id="jf-job" rows="6" data-testid="jf-job" autocomplete="off" spellcheck="false" placeholder="Read my resume ~keep it under 600 words Ask: check it with me Write it out"></textarea>
|
|
796
882
|
</div>
|
|
797
|
-
<div class="hint">One step per line. A line starting with <code>~</code> is a guardrail of the step above it. <code>Ask:</code> stops for you; <code>Ask 2h:</code> sets that ask's own wait.</div>
|
|
883
|
+
<div class="hint">One step per line. A line starting with <code>~</code> is a guardrail of the step above it. <code>Ask:</code> stops for you; <code>Ask 2h:</code> sets that ask's own wait. With a Destination, the last line writes the result there.</div>
|
|
798
884
|
<div class="jf-err" id="jf-err-job" data-testid="jf-err-job"></div>
|
|
799
885
|
</div>
|
|
800
|
-
<div class="field">
|
|
801
|
-
<label for="jf-dest-folder">Destination</label>
|
|
802
|
-
<input id="jf-dest-folder" type="text" placeholder="/full/path/to/a/folder" autocomplete="off" spellcheck="false" data-testid="jf-dest-folder">
|
|
803
|
-
<div class="hint">Where the accepted result is placed, at the last step. Leave empty for no send.</div>
|
|
804
|
-
<div class="jf-err" id="jf-err-destination" data-testid="jf-err-destination"></div>
|
|
805
|
-
</div>
|
|
806
886
|
<div class="field">
|
|
807
887
|
<label for="jf-inputs">Inputs</label>
|
|
808
888
|
<div class="jf-gutbox">
|
|
@@ -812,6 +892,12 @@
|
|
|
812
892
|
<div class="hint">One line per file: a name, a colon, its full path starting with /. The page never reads the file.</div>
|
|
813
893
|
<div class="jf-err" id="jf-err-inputs" data-testid="jf-err-inputs"></div>
|
|
814
894
|
</div>
|
|
895
|
+
<div class="field">
|
|
896
|
+
<label for="jf-dest-folder">Destination</label>
|
|
897
|
+
<input id="jf-dest-folder" type="text" placeholder="/full/path/to/a/folder" autocomplete="off" spellcheck="false" data-testid="jf-dest-folder">
|
|
898
|
+
<div class="hint">Where the accepted result is placed, at the last step. Leave empty for no send.</div>
|
|
899
|
+
<div class="jf-err" id="jf-err-destination" data-testid="jf-err-destination"></div>
|
|
900
|
+
</div>
|
|
815
901
|
<div class="cap-row" data-testid="cap-row">
|
|
816
902
|
<div class="cap-field">
|
|
817
903
|
<label for="jf-cap-money">Cap $</label>
|
|
@@ -843,7 +929,12 @@
|
|
|
843
929
|
<div class="field dimmed" data-testid="jf-run-job-field">
|
|
844
930
|
<label>The job</label>
|
|
845
931
|
<div class="ro-lines" id="jf-run-job" data-testid="jf-run-job"></div>
|
|
846
|
-
<div class="hint"
|
|
932
|
+
<div class="hint" id="jf-run-model" data-testid="jf-run-model"></div>
|
|
933
|
+
<select id="jf-run-pick" data-testid="jf-run-pick" aria-label="Model to run this job with" hidden disabled><option value="">Reading your models…</option></select>
|
|
934
|
+
<div class="jf-err" id="jf-err-run-model" data-testid="jf-err-run-model"></div>
|
|
935
|
+
<div class="hint">Fixed by the signature (the steps, the job lines and the asks). To change them, edit the job: the AI drafts a new plan, and signing it replaces this job.</div>
|
|
936
|
+
<button class="btn" type="button" id="jf-run-edit" data-testid="jf-run-edit">Edit this job</button>
|
|
937
|
+
<div class="hint" id="jf-run-edit-why" data-testid="jf-run-edit-why"></div>
|
|
847
938
|
</div>
|
|
848
939
|
<div class="field">
|
|
849
940
|
<label for="jf-run-dest">Destination</label>
|
|
@@ -878,6 +969,7 @@
|
|
|
878
969
|
<div class="field dimmed" data-testid="jf-resume-job-field">
|
|
879
970
|
<label>The job</label>
|
|
880
971
|
<div class="ro-lines" id="jf-resume-job" data-testid="jf-resume-job"></div>
|
|
972
|
+
<div class="hint" id="jf-resume-model" data-testid="jf-resume-model"></div>
|
|
881
973
|
</div>
|
|
882
974
|
<div class="field dimmed">
|
|
883
975
|
<label>Destination</label>
|
|
@@ -921,7 +1013,7 @@
|
|
|
921
1013
|
<button class="btn primary wide" type="button" id="chat-q-send" data-testid="chat-q-send">Send</button>
|
|
922
1014
|
</div>
|
|
923
1015
|
|
|
924
|
-
<!-- M4e amendments 24/25: beside a green plan, Your answers (if it was drafted with any), Checked (built by code from the typed checks) and Not checked (
|
|
1016
|
+
<!-- M4e amendments 24/25: beside a green plan, Your answers (if it was drafted with any), Checked (built by code from the typed checks) and Not checked (labelled, from src/checked.js) -->
|
|
925
1017
|
<div class="chat-extras" id="chat-extras" data-testid="chat-extras"></div>
|
|
926
1018
|
|
|
927
1019
|
<!-- a refused draft / run / sign / abandon POST (or a refused start) shows here and STAYS: set only by this tab's own
|
|
@@ -1049,7 +1141,10 @@
|
|
|
1049
1141
|
<div id="job-empty" class="hint" style="font-size:13px;padding:24px 0;">select a run first</div>
|
|
1050
1142
|
<div class="job-card" id="job-card" hidden data-testid="job-card-readonly">
|
|
1051
1143
|
<h4 id="details-title">Job card — signed</h4>
|
|
1144
|
+
<div class="hint" id="details-jobfrom" data-testid="details-jobfrom"></div>
|
|
1052
1145
|
<div class="field"><label>Model</label><div class="ro-value" id="details-model">—</div></div>
|
|
1146
|
+
<!-- am41 item 6: the same "The job" label the Chat card carries, over the signed lines -->
|
|
1147
|
+
<div class="field" style="margin-bottom:0"><label id="details-job-title">The job</label></div>
|
|
1053
1148
|
<!-- M4e amendment 37: ONE column. #details-prose holds one wrapper per signed line (the line, its ~ rows, its steps folded under it);
|
|
1054
1149
|
#details-plan-tail holds any step from no listed line, then the folded "not checked" line; then Ask, Destination, $ cap, Source, Signed. -->
|
|
1055
1150
|
<div id="job-grid" data-testid="job-grid">
|
|
@@ -1449,24 +1544,6 @@
|
|
|
1449
1544
|
// page's step-map builder; the DATA it draws is fwdloop's own: one box per
|
|
1450
1545
|
// `declaration.steps` entry, no scout/plan/judge/fix-loop/rounds — ruling
|
|
1451
1546
|
// A, "no per-round parts"). ----
|
|
1452
|
-
// hamr review #2: "map cards missing try 2 if multiple attempts/iteration"
|
|
1453
|
-
// — a plain "try N" count whenever a step has been attempted more than
|
|
1454
|
-
// once, plus a mark when the LATEST attempt followed a human redo (the
|
|
1455
|
-
// same `afterReject` boundary src/panel/data.js already worked out —
|
|
1456
|
-
// never re-derived here). One attempt (the common case) shows no "try"
|
|
1457
|
-
// text at all, matching bareloop's own "only say it when it's true" shape.
|
|
1458
|
-
// `tryCount` is server-derived (src/panel/data.js's computeTryCount) —
|
|
1459
|
-
// for an ask (hitl) step it counts asks shown to the human (a pause row
|
|
1460
|
-
// + its answer row are the SAME try), for a model step it counts model
|
|
1461
|
-
// attempts. Never re-derived here from `attempts.length` (browser
|
|
1462
|
-
// re-walk bug #2: that over-counted an ask step's pause/answer pairs).
|
|
1463
|
-
function tryCountText(tryCount, attempts){
|
|
1464
|
-
if(!tryCount || tryCount <= 1) return "";
|
|
1465
|
-
var last = attempts && attempts.length ? attempts[attempts.length - 1] : null;
|
|
1466
|
-
var txt = "try " + tryCount;
|
|
1467
|
-
if(last && last.afterReject) txt += " (re-attempt after redo)";
|
|
1468
|
-
return txt;
|
|
1469
|
-
}
|
|
1470
1547
|
// hamr review (browser re-walk #1): the per-attempt list ("attempt 1
|
|
1471
1548
|
// failed · attempt 2 passed · …") is a map node's single biggest source of
|
|
1472
1549
|
// width — that level of detail belongs in the Audit tab, never on the
|
|
@@ -1781,6 +1858,11 @@
|
|
|
1781
1858
|
// selection on the next render.
|
|
1782
1859
|
var wfExpanded = {};
|
|
1783
1860
|
|
|
1861
|
+
// am41 item 5: a job card shows its latest 7 sub-cards (`runs` is newest first); the rest are reached by search.
|
|
1862
|
+
function capChildRuns(runs){
|
|
1863
|
+
return {shown: runs.slice(0, 7), hidden: Math.max(0, runs.length - 7)};
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1784
1866
|
function renderWorkflows(flows){
|
|
1785
1867
|
var el = document.getElementById("wf-list");
|
|
1786
1868
|
el.innerHTML = "";
|
|
@@ -1837,7 +1919,9 @@
|
|
|
1837
1919
|
if(expanded){
|
|
1838
1920
|
var runsWrap = document.createElement("div");
|
|
1839
1921
|
runsWrap.className = "wf-runs";
|
|
1840
|
-
|
|
1922
|
+
var capped = capChildRuns(childRuns);
|
|
1923
|
+
capped.shown.forEach(function(r){ runsWrap.appendChild(buildRunRowEl(r, { sub: true })); });
|
|
1924
|
+
if(capped.hidden > 0) runsWrap.appendChild(textDiv("hint wf-older", "older runs: use search"));
|
|
1841
1925
|
wrap.appendChild(runsWrap);
|
|
1842
1926
|
}
|
|
1843
1927
|
el.appendChild(wrap);
|
|
@@ -2755,7 +2839,11 @@
|
|
|
2755
2839
|
var sends = (job.sends || []).filter(function(sd){ return sd.line === st.line; });
|
|
2756
2840
|
var writes = (st.mayDo || []).some(function(p){ return p === "write" || p === "send"; });
|
|
2757
2841
|
if(writes && sends.length) out += " → " + (sends[0].target || "unknown");
|
|
2758
|
-
|
|
2842
|
+
if(st.checkClass === "green" || st.checkClass === "softgreen") return head + out + " · machine check";
|
|
2843
|
+
// am41 item 2: after the last ask step the human's part is the accept, not a check.
|
|
2844
|
+
var lastAsk = 0;
|
|
2845
|
+
((job.plan && job.plan.steps) || []).forEach(function(p){ if(p.ask && p.step > lastAsk) lastAsk = p.step; });
|
|
2846
|
+
return head + out + " · " + (lastAsk > 0 && st.step > lastAsk ? "after you accept" : "you check");
|
|
2759
2847
|
}
|
|
2760
2848
|
function jobStepFold(st, job){
|
|
2761
2849
|
var fold = document.createElement("details");
|
|
@@ -2771,7 +2859,7 @@
|
|
|
2771
2859
|
fold.appendChild(textDiv("plan-row", "check: " + (st.ask ? "ASK · waits " + plainWait(st.waitMs) : (st.check || []).join(" "))));
|
|
2772
2860
|
return fold;
|
|
2773
2861
|
}
|
|
2774
|
-
// The tail: any step that came from no listed line, then the folded
|
|
2862
|
+
// The tail: any step that came from no listed line, then the folded Not-checked summary (its label comes from the payload, src/checked.js; always shown).
|
|
2775
2863
|
// `placed` (step numbers already folded under a line) is filled by renderJob's line loop before this runs.
|
|
2776
2864
|
function paintJobPlan(job, placed){
|
|
2777
2865
|
var plan = job.plan || {steps: [], notChecked: {recorded: false, items: []}};
|
|
@@ -2783,7 +2871,7 @@
|
|
|
2783
2871
|
fold.className = "plan-fold plan-notchecked";
|
|
2784
2872
|
var sum = document.createElement("summary");
|
|
2785
2873
|
sum.className = "plan-sum";
|
|
2786
|
-
sum.textContent =
|
|
2874
|
+
sum.textContent = nc.label || "";
|
|
2787
2875
|
fold.appendChild(sum);
|
|
2788
2876
|
if(!nc.recorded) fold.appendChild(textDiv("plan-row", "not recorded (signed before amendment 34)"));
|
|
2789
2877
|
else if(!(nc.items || []).length) fold.appendChild(textDiv("plan-row", "the AI listed nothing"));
|
|
@@ -2798,6 +2886,8 @@
|
|
|
2798
2886
|
empty.hidden = true;
|
|
2799
2887
|
card.hidden = false;
|
|
2800
2888
|
document.getElementById("details-title").textContent = "Job — " + job.flow + " (signed)";
|
|
2889
|
+
// M6: which job this is: the copy the run saved when it started, or (a run from before M6) the flow's job as it is now
|
|
2890
|
+
document.getElementById("details-jobfrom").textContent = job.jobFrom === "run" ? "This is the job as this run started it." : (job.jobFromWhy || "");
|
|
2801
2891
|
// review #5: "Job (prose)" — the signed lines, numbered, WITHOUT their
|
|
2802
2892
|
// guardrail mixed in (guardrails get their own field below).
|
|
2803
2893
|
// M4e amendment 6 item 6: the Job block reads like the card: each numbered line, then its own `~` rows: its guardrail, an ask line's
|
|
@@ -2876,8 +2966,22 @@
|
|
|
2876
2966
|
// One last-payload signature per render. Equal payload = the DOM is not touched. `selectRun` resets
|
|
2877
2967
|
// the ones a different selection invalidates.
|
|
2878
2968
|
var lastSig = { inbox: null, runs: null, detail: null, asks: null, audit: null };
|
|
2969
|
+
// `timeLeftMs` differs on every poll and is not part of what a page draw is built from (the words move in place: `liveLeft`/`tickLeft`),
|
|
2970
|
+
// so it is left out: a poll that changed nothing else is "unchanged" and rebuilds nothing (a rebuild resets every scrolled box).
|
|
2879
2971
|
function sig(obj){
|
|
2880
|
-
try { return JSON.stringify(obj); } catch(e){ return null; }
|
|
2972
|
+
try { return JSON.stringify(obj, function(k, v){ return k === "timeLeftMs" ? undefined : v; }); } catch(e){ return null; }
|
|
2973
|
+
}
|
|
2974
|
+
// "time left" counts down IN PLACE. ONE writer: `liveLeft` stamps the element with when its time ends and how to say it; `tickLeft` (the page's
|
|
2975
|
+
// 2 s tick) says it again. Nothing else re-draws these words, so the countdown never costs a rebuild over what the human is reading.
|
|
2976
|
+
function liveLeft(el, timeLeftMs, say){
|
|
2977
|
+
if(typeof timeLeftMs !== "number") { say(timeLeftMs); return; }
|
|
2978
|
+
el.classList.add("live-left");
|
|
2979
|
+
el._endsAt = Date.now() + timeLeftMs;
|
|
2980
|
+
el._say = say;
|
|
2981
|
+
say(timeLeftMs);
|
|
2982
|
+
}
|
|
2983
|
+
function tickLeft(){
|
|
2984
|
+
document.querySelectorAll(".live-left").forEach(function(el){ el._say(Math.max(0, el._endsAt - Date.now())); });
|
|
2881
2985
|
}
|
|
2882
2986
|
// Saves/restores scrollTop of the given element ids around a re-render.
|
|
2883
2987
|
function withScrollPreserved(ids, fn){
|
|
@@ -2933,9 +3037,9 @@
|
|
|
2933
3037
|
document.getElementById("run-content").hidden = true;
|
|
2934
3038
|
});
|
|
2935
3039
|
// the same late-reply guard on audit, job and asks: a reply for a run the user already left paints nothing
|
|
2936
|
-
getJSON(base + "/audit").then(function(a){ if(still()) renderAudit(a); }).catch(function(){ if(still()) renderAudit(null); });
|
|
3040
|
+
getJSON(base + "/audit").then(function(a){ if(still()){ lastSig.audit = sig(a); renderAudit(a); } }).catch(function(){ if(still()) renderAudit(null); });
|
|
2937
3041
|
getJSON(base + "/job").then(function(j){ if(still()) renderJob(j); }).catch(function(){ if(still()) renderJob(null); });
|
|
2938
|
-
getJSON(base + "/asks").then(function(result){ if(still())
|
|
3042
|
+
getJSON(base + "/asks").then(function(result){ if(still()) paintAsks(result, focusAskId || null); }).catch(function(e){
|
|
2939
3043
|
if(still()) renderAsk(null, null, loadFailureText(e));
|
|
2940
3044
|
});
|
|
2941
3045
|
}
|
|
@@ -2980,17 +3084,21 @@
|
|
|
2980
3084
|
withScrollPreserved(["left-pane-body"], function(){ runsFilterBar.setItems(rows); runsFilterBar.refresh(); });
|
|
2981
3085
|
}).catch(function(){});
|
|
2982
3086
|
}
|
|
3087
|
+
// The ONE way the Ask tab is drawn from the books: the Ask tab is drawn from the books AND the page's own pending answer ("working…" block).
|
|
3088
|
+
// The signature is stamped only when renderAsk REALLY drew (it returns false when held over a typed reason): a held redraw leaves the stamp
|
|
3089
|
+
// unset, so the next tick retries it against the same payload. Both the selection's first draw and every poll come through here, so the
|
|
3090
|
+
// first poll after a click finds the stamp and rebuilds nothing (an unstamped first draw was a second, needless rebuild 2 s later).
|
|
3091
|
+
function paintAsks(a, focusAskId){
|
|
3092
|
+
var next = sig({ asks: a, pending: pendingAnswer });
|
|
3093
|
+
if(focusAskId || next === null || next !== lastSig.asks){ lastSig.asks = renderAsk(a, focusAskId) ? next : null; }
|
|
3094
|
+
}
|
|
2983
3095
|
function reloadRun(flow, runId, skipLists){
|
|
2984
3096
|
var base = "/api/runs/" + encodeURIComponent(flow) + "/" + encodeURIComponent(runId);
|
|
2985
3097
|
var still = function(){ return currentFlow === flow && currentRunId === runId; };
|
|
2986
3098
|
var detailP = getJSON(base).then(function(d){ if(still()) paintRun(d); return d; }).catch(function(){ if(still()) openRunLive = false; return null; }); // unreadable books: the list rate, not 2 s forever
|
|
2987
3099
|
var asksP = getJSON(base + "/asks").then(function(a){
|
|
2988
3100
|
if(still()){
|
|
2989
|
-
|
|
2990
|
-
var next = sig({ asks: a, pending: pendingAnswer });
|
|
2991
|
-
// the signature is stamped only when renderAsk REALLY drew (it returns false when held over a typed
|
|
2992
|
-
// reason): a held redraw leaves the stamp unset, so the next tick retries it against the same payload
|
|
2993
|
-
if(next === null || next !== lastSig.asks){ lastSig.asks = renderAsk(a, null) ? next : null; }
|
|
3101
|
+
paintAsks(a, null);
|
|
2994
3102
|
}
|
|
2995
3103
|
return a;
|
|
2996
3104
|
}).catch(function(e){ if(still()){ lastSig.asks = null; renderAsk(null, null, loadFailureText(e)); } return null; });
|
|
@@ -3010,6 +3118,7 @@
|
|
|
3010
3118
|
if(document.hidden){ wasHidden = true; schedulePoll(LIVE_POLL_MS); return; }
|
|
3011
3119
|
var catchUp = wasHidden; // first tick after the tab came back: force both
|
|
3012
3120
|
wasHidden = false;
|
|
3121
|
+
tickLeft();
|
|
3013
3122
|
var watch = live;
|
|
3014
3123
|
var sel = currentFlow !== null && currentRunId !== null;
|
|
3015
3124
|
var watchIsSelected = watch && sel && watch.flow === currentFlow && watch.runId === currentRunId;
|
|
@@ -3161,7 +3270,11 @@
|
|
|
3161
3270
|
wrap.appendChild(head);
|
|
3162
3271
|
var meta = textDiv("wf-sign-line", "");
|
|
3163
3272
|
meta.setAttribute("data-testid", "inbox-sign-word");
|
|
3164
|
-
|
|
3273
|
+
if(row.waiting){
|
|
3274
|
+
liveLeft(meta, row.timeLeftMs, function(ms){ var h = signHtml(row.word, "time left: " + duration(ms), "time left: " + duration(ms)); if(meta._h !== h){ meta._h = h; meta.innerHTML = h; } });
|
|
3275
|
+
} else {
|
|
3276
|
+
meta.innerHTML = signHtml(row.word, stopStatusLine(row), stopStatusLine(row));
|
|
3277
|
+
}
|
|
3165
3278
|
wrap.appendChild(meta);
|
|
3166
3279
|
if(typeof row.question === "string"){
|
|
3167
3280
|
wrap.appendChild(textDiv("step-meta", "question: " + row.question));
|
|
@@ -3218,7 +3331,11 @@
|
|
|
3218
3331
|
// role="button" (never a real <button>), same posture as the step-map's
|
|
3219
3332
|
// own SVG nodes elsewhere on this page. ----
|
|
3220
3333
|
function askStatusBlock(ask){
|
|
3221
|
-
if(ask.waiting)
|
|
3334
|
+
if(ask.waiting){
|
|
3335
|
+
var left = textDiv("wf-meta", "");
|
|
3336
|
+
liveLeft(left, ask.timeLeftMs, function(ms){ var t = "time left: " + duration(ms); if(left.textContent !== t) left.textContent = t; });
|
|
3337
|
+
return left;
|
|
3338
|
+
}
|
|
3222
3339
|
// an open ask with a saved answer: the header meta line already says the resume label (stuck or starting) — once.
|
|
3223
3340
|
if(ask.open && ask.resume) return null;
|
|
3224
3341
|
var bits = [ask.statusText || ask.status];
|
|
@@ -3716,7 +3833,17 @@
|
|
|
3716
3833
|
kept[w.getAttribute("data-testid")] = { open: w.getAttribute("data-open"), expanded: w.firstChild.getAttribute("aria-expanded") === "true" };
|
|
3717
3834
|
});
|
|
3718
3835
|
}
|
|
3836
|
+
// A redraw (the books really changed) must not move what the human is reading either: every evidence box keeps its scrollTop (same run only),
|
|
3837
|
+
// and so does the pane. The rebuilt boxes are filled below, per block, once they are in the page.
|
|
3838
|
+
var sameRun = askDrawnFor === result.flow + "/" + result.runId;
|
|
3839
|
+
var tops = {};
|
|
3840
|
+
if(sameRun){
|
|
3841
|
+
list.querySelectorAll("[data-testid^='ask-block-']").forEach(function(w){
|
|
3842
|
+
tops[w.getAttribute("data-testid")] = Array.prototype.map.call(w.querySelectorAll(".scroll"), function(b){ return b.scrollTop; });
|
|
3843
|
+
});
|
|
3844
|
+
}
|
|
3719
3845
|
askDrawnFor = result.flow + "/" + result.runId;
|
|
3846
|
+
var paneTop = (document.getElementById("right-pane-body") || {}).scrollTop;
|
|
3720
3847
|
list.innerHTML = "";
|
|
3721
3848
|
// Default expansion: the block holding the ask a click from the Inbox
|
|
3722
3849
|
// (`focusAskId`) named wins; otherwise a block with an open ask expands;
|
|
@@ -3739,6 +3866,8 @@
|
|
|
3739
3866
|
row.classList.add("audit-group-highlight");
|
|
3740
3867
|
}
|
|
3741
3868
|
list.appendChild(row);
|
|
3869
|
+
var savedTops = tops[row.getAttribute("data-testid")];
|
|
3870
|
+
if(savedTops) Array.prototype.forEach.call(row.querySelectorAll(".scroll"), function(b, i){ if(savedTops[i]) b.scrollTop = savedTops[i]; });
|
|
3742
3871
|
if(expanded){
|
|
3743
3872
|
// Scroll the focused ask into view (M4a-1 design: clicking a stop
|
|
3744
3873
|
// on the left "focuses" it on the right) — never on a run's own
|
|
@@ -3748,6 +3877,7 @@
|
|
|
3748
3877
|
}
|
|
3749
3878
|
}
|
|
3750
3879
|
});
|
|
3880
|
+
if(sameRun && paneTop){ var pane = document.getElementById("right-pane-body"); if(pane) pane.scrollTop = paneTop; }
|
|
3751
3881
|
return true;
|
|
3752
3882
|
}
|
|
3753
3883
|
|
|
@@ -3796,6 +3926,7 @@
|
|
|
3796
3926
|
var modeRow = document.getElementById("jf-mode-row");
|
|
3797
3927
|
var titleEl = document.getElementById("job-card-title");
|
|
3798
3928
|
|
|
3929
|
+
var editOf = null; // M6: the signed job this card EDITS: { flow, flowHash } (ONE writer each: startEdit sets it, leaveEdit clears it); null = a new job
|
|
3799
3930
|
var mode = "new"; // "new" | "run" | "resume"
|
|
3800
3931
|
var runSignInfo = null; // Run form, first Sign & run click: { hash } (cleared by any edit)
|
|
3801
3932
|
var resumeCtx = null; // the run being resumed: { flow, runId, form }
|
|
@@ -3925,11 +4056,59 @@
|
|
|
3925
4056
|
return String(n);
|
|
3926
4057
|
});
|
|
3927
4058
|
}
|
|
4059
|
+
// am41 item 7: ONE function turns a checker's red (the text src/declaration.js writes) into one plain sentence for the card. The raw text rides
|
|
4060
|
+
// along unchanged and is folded under "details"; a red no rule below knows gets the generic sentence and still shows its raw text. This reads
|
|
4061
|
+
// the checker's own fixed wording, never the model's prose.
|
|
4062
|
+
function plainPlanCheck(raw){
|
|
4063
|
+
var PLAN_CHECK_RULES = [
|
|
4064
|
+
[/which is not in the job line's words/, "A section name in the plan's check is not in your job line. Change the job line to use the section words you want."],
|
|
4065
|
+
[/the job line says .*; the check says/, "The sections in the plan's check come in a different order than your job line. Change the job line to change the order."],
|
|
4066
|
+
[/the guardrail says \d+ sections; the check has/, "The number of sections in your guardrail is not the number in the plan's check."],
|
|
4067
|
+
[/section name is a short phrase|which is the job line or most of it/, "A section name in the plan's check is too long; it must be a short phrase from your job line."],
|
|
4068
|
+
[/one section name may not contain another/, "One section name in the plan's check contains another, which cannot be checked."],
|
|
4069
|
+
[/wordsPerSection/, "The words for each section in your guardrail and in the plan's check do not match."],
|
|
4070
|
+
[/work as a pair/, "The plan's check has one part of a pair without the other, so it cannot be checked."],
|
|
4071
|
+
[/is blank|characters; the most one entry|ends in ":"/, "A name in the plan's check is empty, too long or ends in a colon, so it cannot be matched."],
|
|
4072
|
+
[/cannot be built into a check/, "The plan's check cannot be built from what the AI wrote."],
|
|
4073
|
+
[/is not its signed line/, "A step does not use your job line word for word as its goal."],
|
|
4074
|
+
[/not in the catalogue|not wired|which is not signed|checkpoint/, "A step uses a tool that is not available for this job."],
|
|
4075
|
+
[/reads artifact|is a duplicate|\.reads must|\.emits must/, "The steps do not pass their results to each other in a workable order."],
|
|
4076
|
+
[/ask at line \d+|signed ask at line|ask slot/, "The ask on one of your lines is not set up as a plain stop where you decide."],
|
|
4077
|
+
[/send at line \d+|signed send at line|send slot/, "The send step is not set up to follow your accept and write only to your destination."],
|
|
4078
|
+
[/hitl after the last signed ask/, "A step after your last ask would leave without your seeing it, so it is refused."],
|
|
4079
|
+
[/is a pause .* unsigned line/, "A step pauses at a line you did not sign as an ask."],
|
|
4080
|
+
[/neither served by any step/, "A line of your job is not covered by any step."],
|
|
4081
|
+
[/picks|inputFacts|invented name/, "The plan names a field that is not in your input."],
|
|
4082
|
+
[/guardrailClasses|unjudgeable|refused/, "The AI's notes on which lines it can check are not in a form the checker accepts."],
|
|
4083
|
+
[/^line \d+'s (guardrail|check)|can't write files/, null],
|
|
4084
|
+
[/must be an? |is required|must name|does not name/, "The plan the AI wrote is not in the shape the checker needs."]
|
|
4085
|
+
];
|
|
4086
|
+
var text = typeof raw === "string" ? raw : "";
|
|
4087
|
+
for(var i = 0; i < PLAN_CHECK_RULES.length; i++){
|
|
4088
|
+
if(PLAN_CHECK_RULES[i][0].test(text)) return {say: PLAN_CHECK_RULES[i][1] === null ? text.replace(/^declaration: /, "") : PLAN_CHECK_RULES[i][1], raw: text};
|
|
4089
|
+
}
|
|
4090
|
+
return {say: "One of the checks on the plan failed.", raw: text};
|
|
4091
|
+
}
|
|
4092
|
+
// a failed step's details: the plain sentences, with the raw checker texts beside them in `raw`
|
|
4093
|
+
function failedDetails(reds){
|
|
4094
|
+
var rows = (reds || []).map(plainPlanCheck);
|
|
4095
|
+
return {details: rows.map(function(r){ return r.say; }), raw: rows.map(function(r){ return r.raw; })};
|
|
4096
|
+
}
|
|
3928
4097
|
// pure: the progress list for a draft. Chronological; a waiting step has no check; a step's detail lines sit under it; no two
|
|
3929
4098
|
// identical lines in a row. `ctx` = { model, starting }.
|
|
3930
4099
|
function stepsFor(state, ctx){
|
|
3931
4100
|
var out = [];
|
|
3932
4101
|
var who = ctx.model ? ctx.model : "the drafter";
|
|
4102
|
+
// M4d am10: when the server sent the draft's own list (state.stepList, built by one function in src/draft-steps.js) it is rendered as it is,
|
|
4103
|
+
// each ✗ plan-check refusal turned into its plain sentence; a draft with no log lists what it always did (`fallback`).
|
|
4104
|
+
function draftLines(fallback){
|
|
4105
|
+
if(!state || !Array.isArray(state.stepList) || state.stepList.length === 0) return fallback();
|
|
4106
|
+
state.stepList.forEach(function(st){
|
|
4107
|
+
var row = {id: st.id, label: st.label, status: st.status === "failed" ? "failed" : "done", details: st.details || []};
|
|
4108
|
+
if(Array.isArray(st.reds)){ var fd = failedDetails(st.reds); row.details = fd.details; row.raw = fd.raw; }
|
|
4109
|
+
out.push(row);
|
|
4110
|
+
});
|
|
4111
|
+
}
|
|
3933
4112
|
var cap = state && state.card && state.card.capUsd !== undefined && state.card.capUsd !== "" ? state.card.capUsd : "";
|
|
3934
4113
|
var capPart = cap !== "" ? ", run cap $" + cap : "";
|
|
3935
4114
|
if(state){
|
|
@@ -3937,14 +4116,14 @@
|
|
|
3937
4116
|
out.push({id: "drafting", label: "drafting with " + who + capPart, status: "running", details: []});
|
|
3938
4117
|
} else if(Array.isArray(state.revises)){
|
|
3939
4118
|
// amendment 14: a draft whose first plan was green. One line per revise with its result; a red one shows its reds (its sentence is on the card error line).
|
|
3940
|
-
out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []});
|
|
4119
|
+
draftLines(function(){ out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []}); });
|
|
3941
4120
|
var reviseNo = 0;
|
|
3942
4121
|
state.revises.forEach(function(rv){
|
|
3943
4122
|
// an answer redraft (amendment 24 item 4) is not a revise and is not counted as one
|
|
3944
4123
|
var label = rv.kind === "answers" ? "drafted again with your answers" : "revise " + (reviseNo += 1);
|
|
3945
4124
|
if(rv.phase === "running") out.push({id: "revise-" + rv.n, label: label, status: "running", details: []});
|
|
3946
4125
|
else if(rv.phase === "green") out.push({id: "revise-" + rv.n, label: label, status: "done", details: []});
|
|
3947
|
-
else out.push({id: "revise-" + rv.n, label: label, status: "failed", details:
|
|
4126
|
+
else { var rf = failedDetails(rv.reds); out.push({id: "revise-" + rv.n, label: label, status: "failed", details: rf.details, raw: rf.raw}); }
|
|
3948
4127
|
});
|
|
3949
4128
|
if(state.phase === "green"){
|
|
3950
4129
|
if(ctx.starting) out.push({id: "signed", label: "signed", status: "done", details: []});
|
|
@@ -3952,12 +4131,15 @@
|
|
|
3952
4131
|
}
|
|
3953
4132
|
if(state.phase === "questions-open") out.push({id: "question", label: "waiting for your answer (" + state.openK + " of " + state.total + ")", status: "waiting", details: []});
|
|
3954
4133
|
} else if(state.phase === "red"){
|
|
3955
|
-
|
|
3956
|
-
|
|
4134
|
+
draftLines(function(){
|
|
4135
|
+
out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []});
|
|
4136
|
+
var cf = failedDetails(state.reds);
|
|
4137
|
+
out.push({id: "checks", label: "plan checks", status: "failed", details: cf.details, raw: cf.raw});
|
|
4138
|
+
});
|
|
3957
4139
|
} else if(state.phase === "stopped"){
|
|
3958
4140
|
out.push({id: "drafting", label: "drafting with " + who + capPart, status: "failed", details: []});
|
|
3959
4141
|
} else if(state.phase === "green" || state.phase === "revising"){
|
|
3960
|
-
out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []});
|
|
4142
|
+
draftLines(function(){ out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []}); });
|
|
3961
4143
|
if(ctx.starting){
|
|
3962
4144
|
out.push({id: "signed", label: "signed", status: "done", details: []});
|
|
3963
4145
|
} else if(state.phase !== "revising"){
|
|
@@ -3994,7 +4176,7 @@
|
|
|
3994
4176
|
return (c.line !== null && c.line !== undefined ? "line " + c.line : "step " + c.step) + ": " + c.sentences.join(" ");
|
|
3995
4177
|
})});
|
|
3996
4178
|
var nc = state.notChecked || {};
|
|
3997
|
-
blocks.push({id: "chat-notchecked", head:
|
|
4179
|
+
blocks.push({id: "chat-notchecked", head: nc.label || "", sub: "", lines: (nc.items && nc.items.length) ? nc.items.map(function(x){ return "- " + x; }) : ["The drafter listed nothing."]});
|
|
3998
4180
|
return {blocks: blocks};
|
|
3999
4181
|
}
|
|
4000
4182
|
// pure: did this POST succeed (one decision for every handler)
|
|
@@ -4024,7 +4206,8 @@
|
|
|
4024
4206
|
el.style.height = "auto";
|
|
4025
4207
|
if(!el.scrollHeight){ el.style.height = ""; return; }
|
|
4026
4208
|
var border = el.offsetHeight - el.clientHeight;
|
|
4027
|
-
|
|
4209
|
+
var cap = parseFloat(window.getComputedStyle(el).maxHeight);
|
|
4210
|
+
el.style.height = Math.min(el.scrollHeight + border, cap > 0 ? cap : 200) + "px";
|
|
4028
4211
|
}
|
|
4029
4212
|
// Paint a gutter: a hidden mirror of the textarea (same font, same content width, same wrapping) measures each logical line's height;
|
|
4030
4213
|
// the gutter gets one entry of exactly that height, its mark on the first visual line. Re-run on every input, resize and fit.
|
|
@@ -4099,7 +4282,11 @@
|
|
|
4099
4282
|
destination: destEl.value.trim(),
|
|
4100
4283
|
inputs: inputsBox.value,
|
|
4101
4284
|
capUsd: byId("jf-cap-money").value.trim(),
|
|
4102
|
-
askWait: askWaitEl.value.trim()
|
|
4285
|
+
askWait: askWaitEl.value.trim(),
|
|
4286
|
+
provider: modelPick().provider,
|
|
4287
|
+
model: modelPick().model,
|
|
4288
|
+
thinking: thinkingEl.checked && !thinkingEl.disabled,
|
|
4289
|
+
editOf: editOf
|
|
4103
4290
|
};
|
|
4104
4291
|
}
|
|
4105
4292
|
function runWaits(){
|
|
@@ -4110,7 +4297,9 @@
|
|
|
4110
4297
|
function currentRun(){
|
|
4111
4298
|
return {
|
|
4112
4299
|
flow: pickedFlow || "", inputs: readRows(runInputsEl), runId: (byId("jf-run-id").value.trim() === autoRunId ? "" : byId("jf-run-id").value.trim()),
|
|
4113
|
-
destination: runDestEl.value.trim(), capUsd: runCapEl.value.trim(), askWaits: runWaits()
|
|
4300
|
+
destination: runDestEl.value.trim(), capUsd: runCapEl.value.trim(), askWaits: runWaits(),
|
|
4301
|
+
// a flow with no recorded model runs with the pick (am7b); a flow with one sends none
|
|
4302
|
+
...(runPickEl.hidden ? {} : { provider: runPickChoice().provider, model: runPickChoice().model })
|
|
4114
4303
|
};
|
|
4115
4304
|
}
|
|
4116
4305
|
// pure-ish (reads the boxes): does the Run form differ from the flow's own signed values? Only a convenience that picks the button's wording
|
|
@@ -4174,8 +4363,10 @@
|
|
|
4174
4363
|
var seq = ++capNoteSeq;
|
|
4175
4364
|
if(cap === ""){ setMoneyNote("", false); return; }
|
|
4176
4365
|
// a Resume holds only what the run has still to spend (amendment 4 item 1): the server is told what is already spent
|
|
4177
|
-
var spent = (mode === "resume" && resumeCtx) ? "&spent=" + encodeURIComponent(String(resumeCtx.form.spentUsd)) : "";
|
|
4178
|
-
|
|
4366
|
+
var spent = (mode === "resume" && resumeCtx) ? "&spent=" + encodeURIComponent(String(resumeCtx.form.spentUsd)) + "&flow=" + encodeURIComponent(resumeCtx.flow) : "";
|
|
4367
|
+
var pk = modelPick();
|
|
4368
|
+
var picked = (mode === "new" && pk.provider !== "") ? "&provider=" + encodeURIComponent(pk.provider) + "&model=" + encodeURIComponent(pk.model) : "";
|
|
4369
|
+
authorGet("/api/author/monthly-check?cap=" + encodeURIComponent(cap) + spent + picked).then(function(j){
|
|
4179
4370
|
if(seq !== capNoteSeq) return;
|
|
4180
4371
|
if(!j || j.ok !== true){ setMoneyNote("", false); return; }
|
|
4181
4372
|
var v = Number(cap);
|
|
@@ -4203,6 +4394,7 @@
|
|
|
4203
4394
|
return row ? row.querySelector(".jf-err") : null;
|
|
4204
4395
|
}
|
|
4205
4396
|
if(field === "inputs") return byId(mode === "run" ? "jf-err-run-inputs" : "jf-err-inputs");
|
|
4397
|
+
if(mode === "run" && field === "model") return byId("jf-err-run-model");
|
|
4206
4398
|
if(mode === "run" && (field === "destination" || field === "capUsd")) return byId("jf-err-run-" + field);
|
|
4207
4399
|
if(mode === "run" && /^askWaits/.test(field)) return byId("jf-err-run-askWaits");
|
|
4208
4400
|
if(mode === "resume" && field === "capUsd") return byId("jf-err-resume-capUsd");
|
|
@@ -4229,8 +4421,10 @@
|
|
|
4229
4421
|
function syncCardLock(){
|
|
4230
4422
|
var on = cardLocked();
|
|
4231
4423
|
card.querySelectorAll("input[type=text], textarea").forEach(function(el){ el.readOnly = on; el.classList.toggle("locked", on); });
|
|
4424
|
+
if(editOf !== null){ byId("jf-name").readOnly = true; byId("jf-name").classList.add("locked"); } // M6: an edit keeps its job's name
|
|
4232
4425
|
runFlowSel.disabled = on;
|
|
4233
4426
|
runFlowSel.classList.toggle("locked", on);
|
|
4427
|
+
syncEditBtn();
|
|
4234
4428
|
rwPickedEl.classList.toggle("locked", on);
|
|
4235
4429
|
card.querySelectorAll('input[name="jf-mode"]').forEach(function(r){ r.disabled = on || sessionLive; });
|
|
4236
4430
|
}
|
|
@@ -4268,12 +4462,46 @@
|
|
|
4268
4462
|
el.appendChild(row);
|
|
4269
4463
|
});
|
|
4270
4464
|
}
|
|
4465
|
+
// ---- M6: Edit a signed job. The list entry carries the job as a card (`edit`); Edit fills the New-job boxes from it and keeps the job's name and
|
|
4466
|
+
// the signature hash it was opened at. Nothing is written until the normal Draft -> Sign. Clear / Abandon leave the job exactly as it was.
|
|
4467
|
+
var editBtn = document.getElementById("jf-run-edit");
|
|
4468
|
+
var editWhyEl = document.getElementById("jf-run-edit-why");
|
|
4469
|
+
var editBannerEl = document.getElementById("jf-edit-banner");
|
|
4470
|
+
function syncEditBtn(){
|
|
4471
|
+
if(!editBtn) return; // called by the first lock sync, before this block has run
|
|
4472
|
+
var f = selectedFlow();
|
|
4473
|
+
var can = !!(f && f.edit && f.edit.ok === true);
|
|
4474
|
+
editBtn.disabled = !can || cardLocked() || sessionLive || startId !== null;
|
|
4475
|
+
editWhyEl.textContent = (f && f.edit && f.edit.ok === false) ? f.edit.say : "";
|
|
4476
|
+
}
|
|
4477
|
+
function startEdit(){
|
|
4478
|
+
var f = selectedFlow();
|
|
4479
|
+
if(!f || !f.edit || f.edit.ok !== true || cardLocked() || sessionLive) return;
|
|
4480
|
+
var c = f.edit.card;
|
|
4481
|
+
editOf = {flow: f.flow, flowHash: f.edit.flowHash};
|
|
4482
|
+
setMode("new");
|
|
4483
|
+
setVal("jf-name", f.flow); setVal("jf-job", c.job); setVal("jf-cap-money", c.capUsd);
|
|
4484
|
+
setVal("jf-dest-folder", c.destination); setVal("jf-inputs", c.inputs); setVal("jf-ask-wait", c.askWait || "1h");
|
|
4485
|
+
editBannerEl.textContent = "Editing \u201c" + f.flow + "\u201d. Draft it, read the new plan, then sign: signing replaces this job. Clear leaves it exactly as it was.";
|
|
4486
|
+
editBannerEl.hidden = false;
|
|
4487
|
+
chatActionOk();
|
|
4488
|
+
refreshCapNote(); fitCardBoxes(); refreshStartEnabled();
|
|
4489
|
+
}
|
|
4490
|
+
// the card stops editing a job: the name box is free again
|
|
4491
|
+
function leaveEdit(){
|
|
4492
|
+
editOf = null;
|
|
4493
|
+
editBannerEl.hidden = true; editBannerEl.textContent = "";
|
|
4494
|
+
var nm = byId("jf-name"); nm.readOnly = false; nm.classList.remove("locked");
|
|
4495
|
+
}
|
|
4496
|
+
editBtn.addEventListener("click", startEdit);
|
|
4271
4497
|
function paintRunFlow(){
|
|
4272
4498
|
var f = selectedFlow();
|
|
4273
4499
|
var v = f ? (pickedRun ? pickedRun.values : f.values) : null; // a picked run's own values, else the flow's own
|
|
4274
4500
|
paintedFlow = pickedKey();
|
|
4275
4501
|
runSignInfo = null;
|
|
4276
4502
|
paintJobDim(byId("jf-run-job"), f ? f.jobLines : []);
|
|
4503
|
+
byId("jf-run-model").textContent = f && f.model ? "Model: " + f.model.label : (f ? "No model is recorded for this job. Pick the one to run it with; it is then remembered for this job." : "");
|
|
4504
|
+
runPickEl.hidden = !(f && !f.model);
|
|
4277
4505
|
runDestEl.value = v && v.destination ? v.destination : "";
|
|
4278
4506
|
runDestEl.readOnly = !(f && f.hasSend);
|
|
4279
4507
|
runDestEl.classList.toggle("locked", !(f && f.hasSend));
|
|
@@ -4296,6 +4524,7 @@
|
|
|
4296
4524
|
byId("jf-run-id").value = autoRunId;
|
|
4297
4525
|
clearFieldErrors();
|
|
4298
4526
|
refreshCapNote();
|
|
4527
|
+
syncEditBtn();
|
|
4299
4528
|
}
|
|
4300
4529
|
// borrowed-from: bareloop src/panel/index.html@b5e37b8 — the Reuse workflow picker: ONE function shows the search box + list before a pick and the
|
|
4301
4530
|
// picked box after; a row is the name (the typed part marked) over the flow's track record line.
|
|
@@ -4329,10 +4558,14 @@
|
|
|
4329
4558
|
byId("jf-err-flow").textContent = "";
|
|
4330
4559
|
renderFlowSearch(); paintRunFlow(); refreshStartEnabled();
|
|
4331
4560
|
}
|
|
4332
|
-
|
|
4333
|
-
|
|
4561
|
+
// the one writer of the Run-a-signed-flow pick (the Change link and Clear both go through it)
|
|
4562
|
+
function clearPick(){
|
|
4334
4563
|
pickedFlow = null; pickedRun = null; pickedLabel = ""; againEntry = null; rwHl = 0;
|
|
4335
4564
|
runFlowSel.value = "";
|
|
4565
|
+
}
|
|
4566
|
+
function unpickFlow(){
|
|
4567
|
+
if(cardLocked()) return;
|
|
4568
|
+
clearPick();
|
|
4336
4569
|
renderFlowSearch(); paintRunFlow(); refreshStartEnabled();
|
|
4337
4570
|
}
|
|
4338
4571
|
function loadFlows(force){
|
|
@@ -4347,12 +4580,76 @@
|
|
|
4347
4580
|
refreshStartEnabled();
|
|
4348
4581
|
}).catch(function(){ /* the card keeps what it had */ });
|
|
4349
4582
|
}
|
|
4350
|
-
// the
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4583
|
+
// ---- the Model menu and the per-job "Thinking on" box (M4d amendments 6 and 7) ----
|
|
4584
|
+
// The menu is the ticked lines of Settings > Providers, "provider · model"; the server decides what is listed (GET /api/author/models) and
|
|
4585
|
+
// whether Thinking can change for a line (one function over bareagent's answer, src/thinking.js). The page decides nothing.
|
|
4586
|
+
var modelEl = byId("jf-model");
|
|
4587
|
+
var thinkingEl = byId("jf-thinking");
|
|
4588
|
+
var modelLines = [];
|
|
4589
|
+
function modelPick(){
|
|
4590
|
+
var l = modelLines[Number(modelEl.value)];
|
|
4591
|
+
return l ? {provider: l.slot, model: l.model} : {provider: "", model: ""};
|
|
4592
|
+
}
|
|
4593
|
+
// the box's state for a menu line: unticked by default; greyed with the server's sentence when thinking cannot change for that model
|
|
4594
|
+
function thinkingBoxState(line, wasChecked){
|
|
4595
|
+
if(!line || !line.thinking) return {disabled: true, checked: false, note: ""};
|
|
4596
|
+
if(line.thinking.canChange !== true) return {disabled: true, checked: false, note: line.thinking.say || ""};
|
|
4597
|
+
// an unchecked model's note (am11 item 2) says "thinking off"; ticked, it would be wrong, so it goes
|
|
4598
|
+
return {disabled: false, checked: wasChecked === true, note: wasChecked === true ? "" : (line.thinking.say || "")};
|
|
4599
|
+
}
|
|
4600
|
+
function paintThinking(){
|
|
4601
|
+
var st = thinkingBoxState(modelLines[Number(modelEl.value)], thinkingEl.checked);
|
|
4602
|
+
thinkingEl.disabled = st.disabled; thinkingEl.checked = st.checked;
|
|
4603
|
+
byId("jf-thinking-note").textContent = st.note;
|
|
4604
|
+
drafterModel = modelPick().model;
|
|
4605
|
+
}
|
|
4606
|
+
modelEl.addEventListener("change", function(){ paintThinking(); refreshCapNote(); });
|
|
4607
|
+
thinkingEl.addEventListener("change", paintThinking);
|
|
4608
|
+
function setModelPick(provider, model){
|
|
4609
|
+
for(var i = 0; i < modelLines.length; i += 1){ if(modelLines[i].slot === provider && modelLines[i].model === model){ modelEl.value = String(i); break; } }
|
|
4610
|
+
paintThinking();
|
|
4611
|
+
}
|
|
4612
|
+
// M4d amendment 7b: an old signed flow with no recorded model is run with the model picked here. This menu is the New job menu's twin:
|
|
4613
|
+
// the same ticked lines (values are indexes into `modelLines`), the pick kept across a re-read. Shown only for a flow with no record (paintRunFlow).
|
|
4614
|
+
var runPickEl = byId("jf-run-pick");
|
|
4615
|
+
var runPicked = {provider: "", model: ""}; // what the person chose here, by identity (the indexes change when the list is re-read)
|
|
4616
|
+
function runPickChoice(){
|
|
4617
|
+
var l = runPickEl.hidden ? null : modelLines[Number(runPickEl.value)];
|
|
4618
|
+
return l ? {provider: l.slot, model: l.model} : {provider: "", model: ""};
|
|
4619
|
+
}
|
|
4620
|
+
runPickEl.addEventListener("change", function(){ runPicked = runPickChoice(); });
|
|
4621
|
+
function syncRunPick(){
|
|
4622
|
+
runPickEl.innerHTML = modelEl.innerHTML; runPickEl.disabled = modelEl.disabled;
|
|
4623
|
+
for(var i = 0; i < modelLines.length; i += 1){ if(modelLines[i].slot === runPicked.provider && modelLines[i].model === runPicked.model){ runPickEl.value = String(i); break; } }
|
|
4624
|
+
}
|
|
4625
|
+
// `tries` counts the reads that failed in a row (a click passes an Event, which is not a number: that is a fresh read).
|
|
4626
|
+
// A failed read never leaves the menu blank: it says so and reads again by itself, a few times, so the first load fills it.
|
|
4627
|
+
function loadModel(tries){
|
|
4628
|
+
var failed = typeof tries === "number" ? tries : 0;
|
|
4629
|
+
function unread(){
|
|
4630
|
+
if(modelLines.length > 0) return; // a menu that was filled keeps what it had
|
|
4631
|
+
modelEl.innerHTML = ""; modelEl.disabled = true;
|
|
4632
|
+
var o = document.createElement("option"); o.value = "";
|
|
4633
|
+
o.textContent = failed < 5 ? "Could not read your models. Trying again\u2026" : "Could not read your models. Reload the page.";
|
|
4634
|
+
modelEl.appendChild(o);
|
|
4635
|
+
syncRunPick();
|
|
4636
|
+
if(failed < 5) setTimeout(function(){ loadModel(failed + 1); }, 1500);
|
|
4637
|
+
}
|
|
4638
|
+
authorGet("/api/author/models").then(function(j){
|
|
4639
|
+
if(!j || j.ok !== true){ failed += 1; unread(); return; }
|
|
4640
|
+
var was = modelPick();
|
|
4641
|
+
modelLines = j.lines || [];
|
|
4642
|
+
modelEl.innerHTML = "";
|
|
4643
|
+
if(modelLines.length === 0){
|
|
4644
|
+
var none = document.createElement("option"); none.value = ""; none.textContent = j.say || "Tick a model in Settings > Providers."; modelEl.appendChild(none);
|
|
4645
|
+
modelEl.disabled = true;
|
|
4646
|
+
} else {
|
|
4647
|
+
modelEl.disabled = false;
|
|
4648
|
+
modelLines.forEach(function(l, i){ var o = document.createElement("option"); o.value = String(i); o.textContent = l.label; modelEl.appendChild(o); });
|
|
4649
|
+
}
|
|
4650
|
+
setModelPick(was.provider, was.model);
|
|
4651
|
+
syncRunPick();
|
|
4652
|
+
}).catch(function(){ failed += 1; unread(); });
|
|
4356
4653
|
}
|
|
4357
4654
|
function setMode(m){
|
|
4358
4655
|
mode = m;
|
|
@@ -4373,17 +4670,32 @@
|
|
|
4373
4670
|
// ---- render: the progress list, the readout and the one main button ----
|
|
4374
4671
|
// Returns true when the list's content actually changed (a new line, or the latest line changed) so the caller can scroll only
|
|
4375
4672
|
// then; an identical poll tick returns false and leaves the person's scroll position alone.
|
|
4673
|
+
// A fold the person opened stays open: the list is rewritten only when its markup changed, and a rewrite draws each fold open again
|
|
4674
|
+
// from progressOpen (keyed step id : detail index, set by the toggle listener) until the person closes it.
|
|
4675
|
+
var progressHtml = "";
|
|
4676
|
+
var progressOpen = {};
|
|
4677
|
+
progressRow.addEventListener("toggle", function(e){
|
|
4678
|
+
var key = e.target && e.target.getAttribute ? e.target.getAttribute("data-fold") : null;
|
|
4679
|
+
if(key) progressOpen[key] = e.target.open === true;
|
|
4680
|
+
}, true);
|
|
4376
4681
|
function renderProgress(steps){
|
|
4377
|
-
var before = progressRow.innerHTML;
|
|
4378
4682
|
progressRow.hidden = steps.length === 0;
|
|
4379
|
-
|
|
4683
|
+
var html = steps.map(function(st){
|
|
4380
4684
|
var cls = st.status === "waiting" ? "wait" : (st.status === "running" ? "run" : (st.status === "failed" ? "bad" : "ok"));
|
|
4381
4685
|
var sign = cls === "ok" ? "✓" : (cls === "bad" ? "✗" : "");
|
|
4382
4686
|
return '<li class="step ' + cls + '" data-step="' + escapeXml(st.id) + '"><div class="step-line"><span class="step-label">' + escapeXml(st.label) + '</span>' +
|
|
4383
4687
|
'<span class="step-sign">' + sign + '</span></div>' +
|
|
4384
|
-
(st.details || []).map(function(d){
|
|
4688
|
+
(st.details || []).map(function(d, k){
|
|
4689
|
+
var raw = st.raw || [];
|
|
4690
|
+
var key = st.id + ":" + k;
|
|
4691
|
+
var fold = typeof raw[k] === "string" && raw[k] !== "" ? '<details class="step-raw" data-fold="' + escapeXml(key) + '"' + (progressOpen[key] ? " open" : "") + '><summary>details</summary>' + escapeXml(raw[k]) + '</details>' : "";
|
|
4692
|
+
return '<div class="step-detail">' + escapeXml("> " + d) + fold + '</div>';
|
|
4693
|
+
}).join("") + '</li>';
|
|
4385
4694
|
}).join("");
|
|
4386
|
-
|
|
4695
|
+
if(html === progressHtml) return false;
|
|
4696
|
+
progressHtml = html;
|
|
4697
|
+
progressRow.innerHTML = html;
|
|
4698
|
+
return true;
|
|
4387
4699
|
}
|
|
4388
4700
|
// the plan the human is about to sign: the drafter's readout and the hash; nothing else goes in the thread
|
|
4389
4701
|
var threadKey = "";
|
|
@@ -4426,7 +4738,7 @@
|
|
|
4426
4738
|
var v = extrasFor(state);
|
|
4427
4739
|
var html = v ? v.blocks.map(function(b){
|
|
4428
4740
|
return '<div class="msg" id="' + b.id + '" data-testid="' + b.id + '"><b class="readout-head">' + escapeXml(b.head) + '</b>' +
|
|
4429
|
-
(b.sub ? ' <span class="hint">(' + escapeXml(b.sub) + ')</span>' : '') + '\n' + b.lines.map(escapeXml).join("\n") + '</div>';
|
|
4741
|
+
(b.sub ? ' <span class="hint">(' + escapeXml(b.sub) + ')</span>' : '') + (b.lines.length ? '\n' + b.lines.map(escapeXml).join("\n") : '') + '</div>';
|
|
4430
4742
|
}).join("") : "";
|
|
4431
4743
|
if(html !== extrasKey){ extrasKey = html; extrasEl.innerHTML = html; }
|
|
4432
4744
|
}
|
|
@@ -4495,7 +4807,7 @@
|
|
|
4495
4807
|
threadKey = ""; thread.innerHTML = "";
|
|
4496
4808
|
renderQuestion(null); renderExtras(null);
|
|
4497
4809
|
errEl.textContent = "";
|
|
4498
|
-
progressRow.hidden = true; progressRow.innerHTML = "";
|
|
4810
|
+
progressRow.hidden = true; progressRow.innerHTML = ""; progressHtml = "";
|
|
4499
4811
|
refreshStartEnabled();
|
|
4500
4812
|
}
|
|
4501
4813
|
function openNewCard(){
|
|
@@ -4508,14 +4820,17 @@
|
|
|
4508
4820
|
sessionId = null; sessionLive = false; lastState = null; signInfo = null; signClickedOnce = false; busy = false; reviseOpen = false;
|
|
4509
4821
|
stopPoll();
|
|
4510
4822
|
progressRow.hidden = true;
|
|
4511
|
-
progressRow.innerHTML = "";
|
|
4823
|
+
progressRow.innerHTML = ""; progressHtml = "";
|
|
4512
4824
|
refreshStartEnabled();
|
|
4513
4825
|
}
|
|
4514
4826
|
// back to a fresh empty card: every box, the inputs, the progress list, the ask box
|
|
4515
4827
|
function resetCard(){
|
|
4516
4828
|
if(mode === "resume"){ resumeCtx = null; setMode(modeBeforeResume === "resume" ? "new" : modeBeforeResume); }
|
|
4829
|
+
leaveEdit();
|
|
4517
4830
|
["jf-name", "jf-job", "jf-cap-money", "jf-dest-folder", "jf-inputs"].forEach(function(id){ byId(id).value = ""; });
|
|
4518
4831
|
askWaitEl.value = "1h";
|
|
4832
|
+
thinkingEl.checked = false; // per job: unticked for the next one
|
|
4833
|
+
clearPick(); // a flow picked in Run a signed flow (Run again too) goes with the rest
|
|
4519
4834
|
refreshCapNote();
|
|
4520
4835
|
openNewCard();
|
|
4521
4836
|
loadFlows(mode === "run");
|
|
@@ -4587,7 +4902,7 @@
|
|
|
4587
4902
|
window.fwdloopResuming = null; // a refused start leaves the run stopped: Resume is offered again
|
|
4588
4903
|
refusedStartId = j.startId;
|
|
4589
4904
|
chatActionFailed(signed ? j.say + " The flow is signed; start it from \"Run a signed flow\"." : j.say);
|
|
4590
|
-
if(signed){ endSession(); loadFlows(true); } else { progressRow.hidden = true; progressRow.innerHTML = ""; refreshStartEnabled(); }
|
|
4905
|
+
if(signed){ leaveEdit(); endSession(); loadFlows(true); } else { progressRow.hidden = true; progressRow.innerHTML = ""; progressHtml = ""; refreshStartEnabled(); }
|
|
4591
4906
|
return;
|
|
4592
4907
|
}
|
|
4593
4908
|
if(j.ok === false && j.refused === "no-such-start"){
|
|
@@ -4709,6 +5024,7 @@
|
|
|
4709
5024
|
resumeCtx = {flow: detail.flow, runId: detail.runId, form: j};
|
|
4710
5025
|
chatActionOk();
|
|
4711
5026
|
paintJobDim(byId("jf-resume-job"), j.jobLines);
|
|
5027
|
+
byId("jf-resume-model").textContent = j.model ? "Model: " + j.model.label : "No model is recorded for this job.";
|
|
4712
5028
|
byId("jf-resume-dest").textContent = j.values.destination || "no send step";
|
|
4713
5029
|
byId("jf-resume-inputs").innerHTML = "";
|
|
4714
5030
|
(j.inputs || []).forEach(function(i){ var d = document.createElement("div"); d.className = "ro-line"; d.textContent = i.role + ": " + i.path; byId("jf-resume-inputs").appendChild(d); });
|
|
@@ -4761,7 +5077,7 @@
|
|
|
4761
5077
|
if(!o.ok){
|
|
4762
5078
|
busy = false;
|
|
4763
5079
|
failFrom(r);
|
|
4764
|
-
if(r.body && r.body.signed === true){ endSession(); loadFlows(true); } else { refreshStartEnabled(); }
|
|
5080
|
+
if(r.body && r.body.signed === true){ leaveEdit(); endSession(); loadFlows(true); } else { refreshStartEnabled(); }
|
|
4765
5081
|
return;
|
|
4766
5082
|
}
|
|
4767
5083
|
chatActionOk();
|
|
@@ -4810,8 +5126,14 @@
|
|
|
4810
5126
|
openNewCard();
|
|
4811
5127
|
setMode("new");
|
|
4812
5128
|
setVal("jf-name", c.flowName); setVal("jf-job", c.job); setVal("jf-cap-money", c.capUsd);
|
|
5129
|
+
setModelPick(c.provider || "", c.model || ""); thinkingEl.checked = c.thinking === true && !thinkingEl.disabled;
|
|
4813
5130
|
refreshCapNote();
|
|
4814
5131
|
setVal("jf-dest-folder", typeof c.destination === "string" ? c.destination : ""); setVal("jf-inputs", typeof c.inputs === "string" ? c.inputs : ""); setVal("jf-ask-wait", c.askWait || "1h");
|
|
5132
|
+
if(c.editOf && typeof c.editOf.flow === "string"){
|
|
5133
|
+
editOf = {flow: c.editOf.flow, flowHash: c.editOf.flowHash};
|
|
5134
|
+
editBannerEl.textContent = "Editing \u201c" + c.editOf.flow + "\u201d. Draft it, read the new plan, then sign: signing replaces this job. Clear leaves it exactly as it was.";
|
|
5135
|
+
editBannerEl.hidden = false;
|
|
5136
|
+
}
|
|
4815
5137
|
sessionId = d.draftId;
|
|
4816
5138
|
sessionLive = CLIENT_TERMINAL_PHASES.indexOf(d.phase) === -1;
|
|
4817
5139
|
renderThread(d);
|
|
@@ -4870,7 +5192,10 @@
|
|
|
4870
5192
|
refreshStartEnabled();
|
|
4871
5193
|
});
|
|
4872
5194
|
document.querySelectorAll('input[name="jf-mode"]').forEach(function(r){
|
|
4873
|
-
r.addEventListener("change", function(){
|
|
5195
|
+
r.addEventListener("change", function(){
|
|
5196
|
+
if(r.checked && editOf !== null && r.value !== "new" && !sessionLive){ leaveEdit(); ["jf-name", "jf-job", "jf-cap-money", "jf-dest-folder", "jf-inputs"].forEach(function(id){ byId(id).value = ""; }); }
|
|
5197
|
+
if(r.checked) setMode(r.value);
|
|
5198
|
+
});
|
|
4874
5199
|
});
|
|
4875
5200
|
runFlowSel.addEventListener("input", function(){ rwHl = 0; renderFlowSearch(); });
|
|
4876
5201
|
runFlowSel.addEventListener("keydown", function(e){
|
|
@@ -4890,6 +5215,8 @@
|
|
|
4890
5215
|
document.addEventListener("fwdloop-limit-changed", function(){ refreshCapNote(); });
|
|
4891
5216
|
|
|
4892
5217
|
loadModel();
|
|
5218
|
+
document.getElementById("settings-back").addEventListener("click", loadModel); // the menu re-reads after Settings changed what is ticked
|
|
5219
|
+
document.getElementById("tab-chat").addEventListener("click", loadModel);
|
|
4893
5220
|
loadFlows();
|
|
4894
5221
|
reattachLive();
|
|
4895
5222
|
refreshStartEnabled();
|
|
@@ -4932,7 +5259,7 @@
|
|
|
4932
5259
|
var PV_NOTE_DEFAULT = pvNote.textContent;
|
|
4933
5260
|
document.getElementById("settings-open").addEventListener("click", function(){
|
|
4934
5261
|
mainView.hidden = true; settingsView.hidden = false;
|
|
4935
|
-
loadProviders(); loadMoney();
|
|
5262
|
+
loadProviders(true); loadMoney();
|
|
4936
5263
|
});
|
|
4937
5264
|
document.getElementById("settings-back").addEventListener("click", function(){
|
|
4938
5265
|
settingsView.hidden = true; mainView.hidden = false;
|
|
@@ -4941,114 +5268,247 @@
|
|
|
4941
5268
|
document.getElementById("stab-money").addEventListener("click", function(){ loadMoney(); });
|
|
4942
5269
|
document.getElementById("stab-providers").addEventListener("click", function(){ loadProviders(); });
|
|
4943
5270
|
|
|
4944
|
-
|
|
4945
|
-
|
|
5271
|
+
// `list` true = also ask each provider for its model list (free): on page open, on Reload keys. A save repaints without asking again.
|
|
5272
|
+
function loadProviders(list){
|
|
5273
|
+
return getJSON("/api/settings/providers").then(function(d){ paintProviders(d, list === true); }, function(e){
|
|
4946
5274
|
setNote(document.getElementById("keys-refusal"), true, loadFailureText(e));
|
|
4947
5275
|
});
|
|
4948
5276
|
}
|
|
4949
|
-
|
|
5277
|
+
// borrowed-from: bareloop src/panel/index.html@07c298f (Open keys folder): the server opens the FOLDER in the file manager; if it cannot, the path shows as text.
|
|
5278
|
+
document.getElementById("open-keys-folder").addEventListener("click", function(){
|
|
5279
|
+
var out = document.getElementById("keys-open-note");
|
|
5280
|
+
out.textContent = "";
|
|
5281
|
+
postJSON("/api/settings/open-keys-folder", {}).then(function(r){
|
|
5282
|
+
var b = r.body || {};
|
|
5283
|
+
if(b.ok === true) out.textContent = b.opened ? "" : "Could not open it here. Your keys folder: " + (b.path || "(unknown)");
|
|
5284
|
+
else out.textContent = settingsRefusal(r);
|
|
5285
|
+
}, function(){ out.textContent = networkText(); });
|
|
5286
|
+
});
|
|
5287
|
+
document.getElementById("reload-keys").addEventListener("click", function(){ loadProviders(true); });
|
|
4950
5288
|
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
}
|
|
4956
|
-
var PRICE_FIELDS = ["inPerM", "outPerM"];
|
|
4957
|
-
// Name, API shape and Base URL are editable (M4d amendment 1), saved on change one field at a time.
|
|
4958
|
-
var PROV_FIELDS = ["name", "shape", "baseUrl"];
|
|
5289
|
+
// M4d Providers layout F. One parent block per key (.pv-key): its key band (name, API shape select, Base URL box, the legacy tick, tokens,
|
|
5290
|
+
// the Refresh button), a folded summary, and its model lines as child rows (.pv-mrow). The key row owns shape, Base URL and the legacy
|
|
5291
|
+
// tick, so a model line can never drift from them. Shape and Base URL are always editable; a change of either saves both (judged together).
|
|
5292
|
+
var folds = {}; // slot -> true (unfolded) / false (folded): set once, on first paint (a key with a ticked model starts unfolded), then only the person changes it
|
|
5293
|
+
var typedOpen = {}; // slot -> true while "+ type a model name" is open
|
|
4959
5294
|
function buildProviderRow(row){
|
|
4960
|
-
var
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
'<div class="
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
'
|
|
4973
|
-
'<
|
|
4974
|
-
'<
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
5295
|
+
var key = document.createElement("div");
|
|
5296
|
+
key.className = "pv-key";
|
|
5297
|
+
key.setAttribute("data-slot", row.slot);
|
|
5298
|
+
key.setAttribute("data-testid", "provider-row-" + row.slot);
|
|
5299
|
+
key.innerHTML =
|
|
5300
|
+
'<div class="pv-krow">' +
|
|
5301
|
+
'<div class="pv-cell pv-name nolbl"><button class="pv-fold" type="button" data-act="fold" data-testid="pv-fold"></button><code></code><span class="pv-status" data-f="status" data-testid="pv-status-' + escapeXml(row.slot) + '"></span><span class="pv-sum" data-f="sum" data-testid="pv-sum"></span></div>' +
|
|
5302
|
+
'<div class="pv-cell"><span class="pv-lbl">API shape</span><select data-prov="shape" data-testid="prov-shape" aria-label="' + escapeXml(row.label + " API shape") + '"></select></div>' +
|
|
5303
|
+
'<div class="pv-cell pv-c-url"><span class="pv-lbl">Base URL</span><input type="text" data-prov="baseUrl" data-testid="prov-baseurl" aria-label="' + escapeXml(row.label + " Base URL") + '" autocomplete="off" spellcheck="false" placeholder="type the Base URL"></div>' +
|
|
5304
|
+
'<div class="pv-cell"><span class="pv-lbl">Old max_tokens</span><label class="pv-legacy"><input type="checkbox" data-prov="legacyMaxTokens" data-testid="prov-legacy" aria-label="' + escapeXml(row.label + " legacy max_tokens") + '"><span data-f="legacy-word">off</span></label></div>' +
|
|
5305
|
+
'<div class="pv-cell pv-tok pv-ktok"><span class="pv-lbl">Tokens</span><span data-f="tokens" data-testid="pv-tokens-' + escapeXml(row.slot) + '"></span></div>' +
|
|
5306
|
+
'<div class="pv-cell pv-refcell nolbl"><div class="pv-refbox"><div class="pv-refbtns"><button class="btn small pv-refbtn" type="button" data-act="test-key" data-testid="prov-test" aria-label="' + escapeXml("Test " + row.envVar) + '">Test</button><button class="btn small pv-refbtn" type="button" data-act="refresh-models" data-testid="prov-refresh" aria-label="' + escapeXml("Refresh models for " + row.label) + '">⟳ Refresh</button></div><div class="hint pv-msg" data-f="msg-test" data-testid="prov-msg-test" role="status"></div></div></div>' +
|
|
5307
|
+
'</div>' +
|
|
5308
|
+
'<div class="pv-knote"><div class="hint bad pv-msg" data-f="msg-edit" data-testid="prov-msg-edit"></div><div class="hint pv-msg" data-f="msg-legacyMaxTokens" data-testid="prov-msg-legacyMaxTokens"></div></div>' +
|
|
5309
|
+
'<div class="pv-models" data-models-for="' + escapeXml(row.slot) + '" data-testid="models-row-' + escapeXml(row.slot) + '">' +
|
|
5310
|
+
'<div class="pv-mhead" aria-hidden="true"><span class="pv-um"><span class="pv-uh">USE</span><span>MODEL</span></span><span class="pv-pair"><span>IN $/1M</span><span>OUT $/1M</span></span><span class="pv-tok">TOKENS</span></div>' +
|
|
5311
|
+
'<div data-f="models"></div>' +
|
|
5312
|
+
'<div class="pv-more"><button class="pv-add" type="button" data-act="typed-open" data-testid="model-typed-open">+ type a model name</button>' +
|
|
5313
|
+
'<div class="pv-typed" data-f="typed" hidden><input type="text" data-typed="1" data-testid="model-typed" autocomplete="off" spellcheck="false" aria-label="' + escapeXml(row.label + " model name") + '" placeholder="type a model name"> ' +
|
|
5314
|
+
'<button class="btn small" type="button" data-act="add-model" data-testid="model-add">Add</button><div class="hint pv-msg" data-f="typed-msg" data-testid="model-typed-msg"></div></div></div>' +
|
|
5315
|
+
'</div>';
|
|
5316
|
+
key.querySelector("code").textContent = row.envVar;
|
|
5317
|
+
key.querySelectorAll("input").forEach(function(inp){
|
|
4979
5318
|
inp.addEventListener("input", function(){ inp.setAttribute("data-dirty", "1"); });
|
|
4980
5319
|
});
|
|
4981
|
-
|
|
5320
|
+
key.querySelector("select").addEventListener("change", function(ev){ ev.target.setAttribute("data-dirty", "1"); });
|
|
5321
|
+
return key;
|
|
5322
|
+
}
|
|
5323
|
+
// One child row per model: [Use][name], In + Out side by side, Tokens. The price pair is both-or-neither; the server's one rule says why not.
|
|
5324
|
+
function buildModelLine(slot, m){
|
|
5325
|
+
var d = document.createElement("div");
|
|
5326
|
+
d.className = "pv-mrow";
|
|
5327
|
+
d.setAttribute("data-model", m.model);
|
|
5328
|
+
d.setAttribute("data-testid", "model-line");
|
|
5329
|
+
d.innerHTML =
|
|
5330
|
+
'<div class="pv-cell pv-um nolbl"><span class="pv-m-use"><input type="checkbox" data-mf="use" data-testid="model-use"></span><code class="pv-m-name"></code></div>' +
|
|
5331
|
+
'<div class="pv-cell pv-pair"><label><input type="text" inputmode="decimal" data-mf="inPerM" data-testid="model-in" autocomplete="off"></label>' +
|
|
5332
|
+
'<label><input type="text" inputmode="decimal" data-mf="outPerM" data-testid="model-out" autocomplete="off"></label></div>' +
|
|
5333
|
+
'<div class="pv-cell pv-tok pv-m-tok"><span class="pv-lbl">Tokens</span><span data-f="model-tokens" data-testid="model-tokens"></span></div>' +
|
|
5334
|
+
'<div class="hint pv-msg pv-m-msg" data-f="msg-model" data-testid="model-msg"></div>';
|
|
5335
|
+
d.querySelector(".pv-m-name").textContent = m.model;
|
|
5336
|
+
d.querySelector("[data-mf=use]").setAttribute("aria-label", slot + " " + m.model + " use");
|
|
5337
|
+
d.querySelector("[data-mf=inPerM]").setAttribute("aria-label", m.model + " price in per 1M tokens");
|
|
5338
|
+
d.querySelector("[data-mf=outPerM]").setAttribute("aria-label", m.model + " price out per 1M tokens");
|
|
5339
|
+
d.querySelectorAll("input[type=text]").forEach(function(inp){
|
|
5340
|
+
inp.addEventListener("input", function(){ inp.setAttribute("data-dirty", "1"); });
|
|
5341
|
+
});
|
|
5342
|
+
return d;
|
|
5343
|
+
}
|
|
5344
|
+
// The provider's own model list per key (asked on page open, Reload keys, Refresh models): { models: [ids] } or { why }. Not saved: only ticked or typed lines are.
|
|
5345
|
+
var listed = {};
|
|
5346
|
+
var lastData = null;
|
|
5347
|
+
function linesFor(row){
|
|
5348
|
+
var l = listed[row.slot];
|
|
5349
|
+
var have = {};
|
|
5350
|
+
row.models.forEach(function(m){ have[m.model] = true; });
|
|
5351
|
+
var extra = (l && l.models ? l.models : []).filter(function(id){ return !have[id]; }).map(function(id){ return { model: id, use: false }; });
|
|
5352
|
+
return row.models.concat(extra);
|
|
5353
|
+
}
|
|
5354
|
+
// "3 models · none ticked", "2 models · 1 ticked"; a list that failed with nothing saved says so.
|
|
5355
|
+
function sumText(row){
|
|
5356
|
+
var l = listed[row.slot];
|
|
5357
|
+
var lines = linesFor(row);
|
|
5358
|
+
if(l && l.why && lines.length === 0) return "failed — type a name";
|
|
5359
|
+
var ticked = lines.filter(function(m){ return m.use === true; }).length;
|
|
5360
|
+
return lines.length + (lines.length === 1 ? " model" : " models") + " · " + (ticked === 0 ? "none ticked" : ticked + " ticked");
|
|
5361
|
+
}
|
|
5362
|
+
function paintModels(row, mr){
|
|
5363
|
+
var box = mr.querySelector("[data-f=models]");
|
|
5364
|
+
var lines = linesFor(row);
|
|
5365
|
+
var l = listed[row.slot];
|
|
5366
|
+
var typed = mr.querySelector("[data-f=typed]");
|
|
5367
|
+
typed.hidden = typedOpen[row.slot] !== true;
|
|
5368
|
+
var wanted = lines.map(function(m){ return m.model; });
|
|
5369
|
+
Array.prototype.slice.call(box.querySelectorAll(".pv-mrow")).forEach(function(el){
|
|
5370
|
+
if(wanted.indexOf(el.getAttribute("data-model")) < 0) box.removeChild(el);
|
|
5371
|
+
});
|
|
5372
|
+
var note = box.querySelector("[data-f=models-note]");
|
|
5373
|
+
lines.forEach(function(m){
|
|
5374
|
+
var line = Array.prototype.find.call(box.querySelectorAll(".pv-mrow"), function(el){ return el.getAttribute("data-model") === m.model; });
|
|
5375
|
+
if(!line){ line = buildModelLine(row.slot, m); box.insertBefore(line, note); }
|
|
5376
|
+
var use = line.querySelector("[data-mf=use]");
|
|
5377
|
+
use.checked = m.use === true;
|
|
5378
|
+
["inPerM", "outPerM"].forEach(function(f){
|
|
5379
|
+
var inp = line.querySelector('[data-mf="' + f + '"]');
|
|
5380
|
+
inp.placeholder = "—";
|
|
5381
|
+
if(inp.getAttribute("data-dirty") !== "1") inp.value = typeof m[f] === "number" ? String(m[f]) : "";
|
|
5382
|
+
});
|
|
5383
|
+
line.querySelector("[data-f=model-tokens]").textContent = typeof m.tokens === "number" ? tokensText(m.tokens) : "—";
|
|
5384
|
+
});
|
|
5385
|
+
note = box.querySelector("[data-f=models-note]");
|
|
5386
|
+
if(!note){ note = document.createElement("div"); note.className = "hint pv-more"; note.setAttribute("data-f", "models-note"); note.setAttribute("data-testid", "models-note"); box.appendChild(note); }
|
|
5387
|
+
setNote(note, false, l && l.why ? l.why + " Type the model name below." : (lines.length === 0 ? "No models yet. Press ⟳ to refresh models, or type a name." : ""));
|
|
5388
|
+
note.className += " pv-more" + (l && l.why ? " pv-failed" : "");
|
|
5389
|
+
box.parentNode.querySelector(".pv-mhead").hidden = lines.length === 0;
|
|
4982
5390
|
}
|
|
4983
5391
|
var STATUS_WORD = { "set in file": "set in file", "found in shell": "found in shell", "not set": "not set", "refused": "refused — see above" };
|
|
4984
|
-
|
|
5392
|
+
// The Refresh button: "[ ⟳ Refresh ]", disabled "[ ⟳ refreshing… ]" while the free list call is out.
|
|
5393
|
+
function setRefreshBtn(key, pending){
|
|
5394
|
+
var b = key.querySelector("[data-act=refresh-models]");
|
|
5395
|
+
b.disabled = pending === true;
|
|
5396
|
+
b.innerHTML = pending === true ? "⟳ refreshing…" : "⟳ Refresh";
|
|
5397
|
+
}
|
|
5398
|
+
// The Test button: "[ Test ]", disabled "[ testing… ]" while the free call is out. The route says ok + ms or a plain-words why; written on the key row's own note.
|
|
5399
|
+
function testKey(slot, key){
|
|
5400
|
+
var b = key.querySelector("[data-act=test-key]");
|
|
5401
|
+
var msg = key.querySelector("[data-f=msg-test]");
|
|
5402
|
+
var row = lastData && lastData.rows.filter(function(r){ return r.slot === slot; })[0];
|
|
5403
|
+
if(row && row.baseUrl === ""){
|
|
5404
|
+
setNote(msg, true, "Type a Base URL for " + row.envVar + " in Settings.");
|
|
5405
|
+
return;
|
|
5406
|
+
}
|
|
5407
|
+
b.disabled = true;
|
|
5408
|
+
b.innerHTML = "testing…";
|
|
5409
|
+
setNote(msg, false, "");
|
|
5410
|
+
postJSON("/api/settings/test", { slot: slot }).then(function(r){
|
|
5411
|
+
var d = r.body;
|
|
5412
|
+
if(d && d.ok === true) setNote(msg, false, "OK \u00b7 " + d.ms + " ms");
|
|
5413
|
+
else setNote(msg, true, d && d.why ? d.why : settingsRefusal(r));
|
|
5414
|
+
}, function(){ setNote(msg, true, networkText()); }).then(function(){
|
|
5415
|
+
b.disabled = false;
|
|
5416
|
+
b.innerHTML = "Test";
|
|
5417
|
+
});
|
|
5418
|
+
}
|
|
5419
|
+
function refreshModels(slot, tr){
|
|
5420
|
+
listed[slot] = { pending: true };
|
|
5421
|
+
setRefreshBtn(tr, true);
|
|
5422
|
+
return postJSON("/api/settings/models", { slot: slot }).then(function(r){
|
|
5423
|
+
var b = r.body;
|
|
5424
|
+
listed[slot] = b && b.ok ? { models: b.models } : { why: (b && b.why) ? b.why : settingsRefusal(r) };
|
|
5425
|
+
}, function(){ listed[slot] = { why: networkText() }; }).then(function(){
|
|
5426
|
+
if(lastData) paintProviders(lastData, false);
|
|
5427
|
+
});
|
|
5428
|
+
}
|
|
5429
|
+
function paintProviders(data, list){
|
|
5430
|
+
lastData = data;
|
|
4985
5431
|
var path = data.keysFile && data.keysFile.path ? data.keysFile.path : "~/.config/fwdloop/.env";
|
|
4986
5432
|
document.getElementById("keys-path").textContent = path;
|
|
4987
5433
|
setNote(document.getElementById("keys-refusal"), true, data.keysFile && data.keysFile.refusal);
|
|
4988
5434
|
setNote(pvNote, !!data.configProblem, data.configProblem || PV_NOTE_DEFAULT);
|
|
4989
5435
|
data.rows.forEach(function(row){
|
|
4990
|
-
var
|
|
4991
|
-
if(!
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
var
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5436
|
+
var key = pvRows.querySelector('.pv-key[data-slot="' + row.slot + '"]');
|
|
5437
|
+
if(!key){ key = buildProviderRow(row); pvRows.appendChild(key); }
|
|
5438
|
+
if(folds[row.slot] === undefined) folds[row.slot] = row.models.some(function(m){ return m.use === true; });
|
|
5439
|
+
key.setAttribute("data-open", folds[row.slot] ? "1" : "0");
|
|
5440
|
+
var fold = key.querySelector("[data-act=fold]");
|
|
5441
|
+
fold.textContent = folds[row.slot] ? "▾" : "▸";
|
|
5442
|
+
fold.setAttribute("aria-expanded", folds[row.slot] ? "true" : "false");
|
|
5443
|
+
fold.setAttribute("aria-label", (folds[row.slot] ? "Fold " : "Unfold ") + row.label + " models");
|
|
5444
|
+
paintModels(row, key.querySelector(".pv-models"));
|
|
5445
|
+
setRefreshBtn(key, !!(listed[row.slot] && listed[row.slot].pending));
|
|
5446
|
+
key.querySelector("[data-f=sum]").textContent = sumText(row);
|
|
5447
|
+
var st = key.querySelector("[data-f=status]");
|
|
5448
|
+
var word = STATUS_WORD[row.keyStatus] || row.keyStatus;
|
|
5449
|
+
st.className = row.keyStatus === "set in file" || row.keyStatus === "found in shell" ? "pv-status pv-ok" : "pv-status hint";
|
|
5450
|
+
st.textContent = st.className.indexOf("pv-ok") >= 0 ? "✓" : word;
|
|
5451
|
+
st.setAttribute("title", word);
|
|
5452
|
+
if(st.className.indexOf("pv-ok") >= 0) st.setAttribute("aria-label", word); else st.removeAttribute("aria-label");
|
|
5453
|
+
var legacyIn = key.querySelector('[data-prov=legacyMaxTokens]');
|
|
5454
|
+
if(document.activeElement !== legacyIn) legacyIn.checked = row.legacyMaxTokens === true;
|
|
5455
|
+
key.querySelector("[data-f=legacy-word]").textContent = legacyIn.checked ? "on" : "off";
|
|
5456
|
+
// shape + Base URL: the key row's own boxes, written from the server's row unless the person has typed in them (a refused value stays typed, with its sentence)
|
|
5457
|
+
var sel = key.querySelector("[data-prov=shape]");
|
|
5458
|
+
if(sel.options.length !== data.shapes.length || data.shapes.some(function(sh, i){ return sel.options[i].value !== sh.id; })){
|
|
5459
|
+
sel.textContent = "";
|
|
5460
|
+
data.shapes.forEach(function(sh){ var o = document.createElement("option"); o.value = sh.id; o.textContent = sh.label; sel.appendChild(o); });
|
|
5002
5461
|
}
|
|
5003
|
-
|
|
5004
|
-
urlIn
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
if(urlIn.getAttribute("data-dirty") !== "1") urlIn.value = row.savedBaseUrl;
|
|
5008
|
-
if(document.activeElement !== shapeSel) shapeSel.value = row.shape;
|
|
5009
|
-
tr.querySelector("[data-f=tokens]").textContent = tokensText(row.tokens);
|
|
5010
|
-
PRICE_FIELDS.forEach(function(f){
|
|
5011
|
-
var inp = tr.querySelector('input[data-field="' + f + '"]');
|
|
5012
|
-
var pr = row.price[f];
|
|
5013
|
-
inp.placeholder = String(pr.value) + " (" + sourceWord(pr.source) + ")";
|
|
5014
|
-
inp.title = inp.placeholder;
|
|
5015
|
-
// a box the person has typed in is never overwritten by a repaint
|
|
5016
|
-
if(inp.getAttribute("data-dirty") !== "1") inp.value = pr.source === "settings" ? String(pr.value) : "";
|
|
5017
|
-
});
|
|
5462
|
+
if(sel.getAttribute("data-dirty") !== "1") sel.value = row.shape;
|
|
5463
|
+
var urlIn = key.querySelector("[data-prov=baseUrl]");
|
|
5464
|
+
if(urlIn.getAttribute("data-dirty") !== "1" && document.activeElement !== urlIn) urlIn.value = row.baseUrl;
|
|
5465
|
+
key.querySelector("[data-f=tokens]").textContent = tokensText(row.tokens);
|
|
5018
5466
|
});
|
|
5467
|
+
// rows that left the keys file leave the page
|
|
5468
|
+
Array.prototype.slice.call(pvRows.querySelectorAll(".pv-key")).forEach(function(key){
|
|
5469
|
+
if(!data.rows.some(function(r){ return r.slot === key.getAttribute("data-slot"); })) pvRows.removeChild(key);
|
|
5470
|
+
});
|
|
5471
|
+
if(list) data.rows.forEach(function(row){
|
|
5472
|
+
var key = pvRows.querySelector('.pv-key[data-slot="' + row.slot + '"]');
|
|
5473
|
+
if(row.baseUrl === ""){ listed[row.slot] = { why: "Type a Base URL for " + row.slot + " in Settings." }; paintProviders(lastData, false); }
|
|
5474
|
+
else refreshModels(row.slot, key);
|
|
5475
|
+
});
|
|
5476
|
+
}
|
|
5477
|
+
// Shape and Base URL save together, on change of either (blur / Enter / pick); the server judges them as a pair and says which sentence on
|
|
5478
|
+
// a refusal (nothing saved, the typed value stays so the person can fix it).
|
|
5479
|
+
function saveEndpoint(key){
|
|
5480
|
+
var msg = key.querySelector("[data-f=msg-edit]");
|
|
5481
|
+
var payload = { slot: key.getAttribute("data-slot"), shape: key.querySelector("[data-prov=shape]").value, baseUrl: key.querySelector("[data-prov=baseUrl]").value.trim() };
|
|
5482
|
+
postJSON("/api/settings/provider", payload).then(function(r){
|
|
5483
|
+
if(r.body && r.body.ok){
|
|
5484
|
+
key.querySelector("[data-prov=shape]").removeAttribute("data-dirty");
|
|
5485
|
+
key.querySelector("[data-prov=baseUrl]").removeAttribute("data-dirty");
|
|
5486
|
+
setNote(msg, true, "");
|
|
5487
|
+
loadProviders();
|
|
5488
|
+
} else setNote(msg, true, settingsRefusal(r));
|
|
5489
|
+
}, function(){ setNote(msg, true, networkText()); });
|
|
5019
5490
|
}
|
|
5020
5491
|
pvRows.addEventListener("click", function(ev){
|
|
5021
5492
|
var b = ev.target.closest && ev.target.closest("button[data-act]");
|
|
5022
5493
|
if(!b) return;
|
|
5023
|
-
var
|
|
5024
|
-
|
|
5025
|
-
|
|
5494
|
+
var key = b.closest(".pv-key");
|
|
5495
|
+
var slot = key.getAttribute("data-slot");
|
|
5496
|
+
var act = b.getAttribute("data-act");
|
|
5497
|
+
if(act === "refresh-models") refreshModels(slot, key);
|
|
5498
|
+
else if(act === "test-key") testKey(slot, key);
|
|
5499
|
+
else if(act === "fold"){ folds[slot] = !folds[slot]; paintProviders(lastData, false); }
|
|
5500
|
+
else if(act === "typed-open"){ typedOpen[slot] = !typedOpen[slot]; paintProviders(lastData, false); }
|
|
5501
|
+
else if(act === "add-model") addTypedModel(slot, b.closest("[data-f=typed]"));
|
|
5026
5502
|
});
|
|
5027
|
-
// Saved like bareloop saves a row field: on change (blur or Enter), no Save button.
|
|
5503
|
+
// Saved like bareloop saves a row field: on change (blur or Enter), no Save button. The legacy tick saves alone; shape and Base URL save as a pair.
|
|
5028
5504
|
pvRows.addEventListener("change", function(ev){
|
|
5029
5505
|
var inp = ev.target;
|
|
5030
5506
|
if(!inp.getAttribute) return;
|
|
5031
|
-
if(inp.getAttribute("data-prov")){ saveProvider(inp.closest("
|
|
5032
|
-
if(
|
|
5033
|
-
|
|
5507
|
+
if(inp.getAttribute("data-prov") === "legacyMaxTokens"){ saveProvider(inp.closest(".pv-key"), inp); return; }
|
|
5508
|
+
if(inp.getAttribute("data-prov") === "shape" || inp.getAttribute("data-prov") === "baseUrl"){ saveEndpoint(inp.closest(".pv-key")); return; }
|
|
5509
|
+
if(!inp.getAttribute("data-mf")) return;
|
|
5510
|
+
saveModel(inp.closest(".pv-models") ? inp.closest(".pv-models").getAttribute("data-models-for") : "", inp.closest(".pv-mrow"));
|
|
5034
5511
|
});
|
|
5035
|
-
function runTest(tr, slot){
|
|
5036
|
-
var out = tr.querySelector("[data-f=test]");
|
|
5037
|
-
out.textContent = "testing…";
|
|
5038
|
-
postJSON("/api/settings/test", { slot: slot }).then(function(r){
|
|
5039
|
-
var b = r.body;
|
|
5040
|
-
out.textContent = b && b.ok ? "OK · " + b.ms + " ms" : (b && b.why ? b.why : settingsRefusal(r));
|
|
5041
|
-
}, function(){ out.textContent = networkText(); });
|
|
5042
|
-
}
|
|
5043
|
-
// Balance is read on a click, never on render (signed M4d: "read on a click").
|
|
5044
|
-
function runBalance(tr, slot){
|
|
5045
|
-
var out = tr.querySelector("[data-f=balance-result]");
|
|
5046
|
-
out.textContent = "checking…";
|
|
5047
|
-
getJSON("/api/settings/balance?slot=" + encodeURIComponent(slot)).then(function(b){
|
|
5048
|
-
if(b.ok) out.textContent = b.balances.map(function(x){ return x.total + " " + x.currency; }).join(" + ");
|
|
5049
|
-
else out.textContent = b.why || "Could not check the balance.";
|
|
5050
|
-
}, function(e){ out.textContent = loadFailureText(e); });
|
|
5051
|
-
}
|
|
5052
5512
|
// A box the person typed: empty = back to the default (null); a number is sent as a number; anything else is
|
|
5053
5513
|
// sent as the text typed, so the server refuses it by naming the box.
|
|
5054
5514
|
function priceValue(text){
|
|
@@ -5057,25 +5517,42 @@
|
|
|
5057
5517
|
var n = Number(t);
|
|
5058
5518
|
return isFinite(n) ? n : t;
|
|
5059
5519
|
}
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5520
|
+
// One model line per save: {slot, model, use, inPerM, outPerM}. A refusal is the line's hint (the server's one rule),
|
|
5521
|
+
// and nothing was saved: the repaint puts the tick back.
|
|
5522
|
+
function saveModel(slot, line){
|
|
5523
|
+
var msg = line.querySelector("[data-f=msg-model]");
|
|
5524
|
+
var payload = {
|
|
5525
|
+
slot: slot,
|
|
5526
|
+
model: line.getAttribute("data-model"),
|
|
5527
|
+
use: line.querySelector("[data-mf=use]").checked,
|
|
5528
|
+
inPerM: priceValue(line.querySelector("[data-mf=inPerM]").value),
|
|
5529
|
+
outPerM: priceValue(line.querySelector("[data-mf=outPerM]").value)
|
|
5530
|
+
};
|
|
5531
|
+
postJSON("/api/settings/model", payload).then(function(r){
|
|
5065
5532
|
if(r.body && r.body.ok){
|
|
5066
|
-
|
|
5533
|
+
line.querySelectorAll("input[type=text]").forEach(function(inp){ inp.removeAttribute("data-dirty"); });
|
|
5067
5534
|
loadProviders();
|
|
5068
5535
|
setNote(msg, false, "saved — applies from the next model call");
|
|
5069
|
-
} else setNote(msg, true, settingsRefusal(r));
|
|
5536
|
+
} else { setNote(msg, true, settingsRefusal(r)); loadProviders(); }
|
|
5537
|
+
}, function(){ setNote(msg, true, networkText()); });
|
|
5538
|
+
}
|
|
5539
|
+
|
|
5540
|
+
// A model name typed because the list failed: saved as an unticked, empty line (typed lines are saved); the person then fills the prices and ticks it.
|
|
5541
|
+
function addTypedModel(slot, box){
|
|
5542
|
+
var inp = box.querySelector("input");
|
|
5543
|
+
var msg = box.querySelector("[data-f=typed-msg]");
|
|
5544
|
+
postJSON("/api/settings/model", { slot: slot, model: inp.value.trim(), use: false }).then(function(r){
|
|
5545
|
+
if(r.body && r.body.ok){ inp.value = ""; setNote(msg, false, "added"); loadProviders(); }
|
|
5546
|
+
else setNote(msg, true, settingsRefusal(r));
|
|
5070
5547
|
}, function(){ setNote(msg, true, networkText()); });
|
|
5071
5548
|
}
|
|
5072
5549
|
|
|
5073
|
-
//
|
|
5074
|
-
function saveProvider(
|
|
5075
|
-
var
|
|
5076
|
-
var msg =
|
|
5077
|
-
var payload = { slot:
|
|
5078
|
-
payload[
|
|
5550
|
+
// The legacy tick saves alone: {slot, legacyMaxTokens}. A refusal is the cell's hint line.
|
|
5551
|
+
function saveProvider(key, inp){
|
|
5552
|
+
var field = inp.getAttribute("data-prov");
|
|
5553
|
+
var msg = key.querySelector("[data-f=msg-" + field + "]");
|
|
5554
|
+
var payload = { slot: key.getAttribute("data-slot") };
|
|
5555
|
+
payload[field] = inp.checked;
|
|
5079
5556
|
postJSON("/api/settings/provider", payload).then(function(r){
|
|
5080
5557
|
if(r.body && r.body.ok){
|
|
5081
5558
|
inp.removeAttribute("data-dirty");
|