fwdloop 0.15.0 → 0.17.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/README.md +2 -0
- package/bin/fwdloop +113 -36
- package/package.json +2 -2
- package/src/authoring.js +27 -15
- package/src/catalogue.json +9 -3
- package/src/closers.js +5 -0
- package/src/config.js +66 -4
- package/src/ctx-tools.js +245 -0
- package/src/declaration.js +25 -1
- package/src/draft-steps.js +138 -0
- package/src/drafter.js +81 -18
- package/src/draftspend.js +109 -3
- package/src/flowmodel.js +30 -0
- package/src/input-facts.js +12 -3
- package/src/keysfile.js +51 -16
- package/src/liveness.js +34 -10
- package/src/model-step.js +13 -11
- package/src/monthly.js +9 -1
- package/src/panel/author.js +170 -43
- package/src/panel/authorcard.js +32 -20
- package/src/panel/authorflows.js +34 -19
- package/src/panel/authorresume.js +11 -9
- package/src/panel/authorstart.js +11 -9
- package/src/panel/authorvalues.js +5 -3
- package/src/panel/data.js +20 -8
- package/src/panel/index.html +584 -182
- package/src/panel/resume.js +3 -3
- package/src/panel/server.js +12 -6
- package/src/panel/settings.js +138 -80
- package/src/panel/spawn.js +15 -9
- package/src/plain-checks.js +51 -0
- package/src/primitives.js +34 -3
- package/src/provider.js +148 -181
- package/src/providershapes.js +7 -7
- package/src/run-store.js +47 -0
- package/src/runner.js +40 -22
- package/src/setup.js +3 -0
- package/src/thinking.js +55 -0
- package/src/version.js +13 -0
- package/types/authoring.d.ts +11 -6
- package/types/closers.d.ts +2 -0
- package/types/config.d.ts +9 -1
- package/types/ctx-tools.d.ts +18 -0
- package/types/draft-steps.d.ts +47 -0
- package/types/drafter.d.ts +15 -12
- package/types/draftspend.d.ts +56 -0
- package/types/flowmodel.d.ts +16 -0
- package/types/input-facts.d.ts +6 -1
- package/types/keysfile.d.ts +23 -6
- package/types/liveness.d.ts +7 -1
- package/types/model-step.d.ts +1 -1
- package/types/monthly.d.ts +1 -0
- package/types/panel/author.d.ts +47 -9
- package/types/panel/authorcard.d.ts +33 -10
- package/types/panel/authorflows.d.ts +32 -9
- package/types/panel/authorresume.d.ts +2 -1
- package/types/panel/authorstart.d.ts +16 -6
- package/types/panel/authorvalues.d.ts +3 -1
- package/types/panel/data.d.ts +2 -2
- package/types/panel/resume.d.ts +2 -1
- package/types/panel/server.d.ts +6 -2
- package/types/panel/settings.d.ts +3 -1
- package/types/panel/spawn.d.ts +13 -4
- package/types/plain-checks.d.ts +22 -0
- package/types/primitives.d.ts +0 -6
- package/types/provider.d.ts +100 -284
- package/types/providershapes.d.ts +3 -4
- package/types/run-store.d.ts +11 -0
- package/types/runner.d.ts +2 -4
- package/types/setup.d.ts +8 -0
- package/types/thinking.d.ts +25 -0
- package/types/version.d.ts +2 -0
package/src/panel/index.html
CHANGED
|
@@ -119,6 +119,11 @@
|
|
|
119
119
|
.topbar > div:first-child{display:flex;align-items:baseline;gap:0;white-space:nowrap;overflow:hidden;}
|
|
120
120
|
.topbar .brand{font-weight:700;font-size:17px;letter-spacing:0.06em;flex:none;}
|
|
121
121
|
.topbar .brand::before{content:"■ ";}
|
|
122
|
+
.update-bar{display:flex;flex-wrap:wrap;align-items:center;gap:6px 12px;padding:6px 16px;background:var(--amber);color:#000;font-size:13px;}
|
|
123
|
+
.update-bar[hidden]{display:none;}
|
|
124
|
+
.update-bar .btn{color:#000;border-color:#000;}
|
|
125
|
+
.topbar .version{font-size:12px;color:var(--text-dim);margin-left:8px;flex:none;white-space:nowrap;}
|
|
126
|
+
.topbar .version::before{content:"· ";color:var(--text-faint);}
|
|
122
127
|
.topbar .tagline{font-size:12px;color:var(--text-dim);margin-left:8px;overflow:hidden;text-overflow:ellipsis;}
|
|
123
128
|
.topbar .tagline::before{content:"· ";color:var(--text-faint);}
|
|
124
129
|
@media (max-width: 600px){ .topbar .tagline{display:none;} }
|
|
@@ -499,6 +504,9 @@
|
|
|
499
504
|
.chat-steps .step.wait .step-label{color:var(--amber);}
|
|
500
505
|
.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
506
|
.chat-steps .step.bad .step-detail{color:var(--red);}
|
|
507
|
+
.chat-steps .step.note .step-label{color:var(--text);padding-left:1.2em;}
|
|
508
|
+
.chat-steps .step[data-step="thinking"].bad .step-label{color:var(--red);font-weight:600;}
|
|
509
|
+
.audit-raw{color:var(--text-faint);font-size:11px;word-break:break-word;white-space:pre-wrap;margin-top:2px;}
|
|
502
510
|
.chat-steps .step-raw{margin-top:2px;color:var(--text-faint);}
|
|
503
511
|
.chat-steps .step-raw summary{cursor:pointer;}
|
|
504
512
|
.chat-steps .step.run .step-sign::after{content:"\2026";}
|
|
@@ -668,20 +676,92 @@
|
|
|
668
676
|
.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;}
|
|
669
677
|
.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;}
|
|
670
678
|
.keyfile-strip-main{display:flex;flex-direction:column;gap:3px;flex:1;min-width:0;overflow-wrap:anywhere;}
|
|
671
|
-
.keyfile-strip-actions{display:flex;gap:6px;flex:none;}
|
|
679
|
+
.keyfile-strip-actions{display:flex;flex-wrap:wrap;gap:6px;flex:none;max-width:100%;}
|
|
672
680
|
.keyfile-strip code{background:var(--bg);border:1px solid var(--border-strong);padding:1px 5px;font-size:11px;color:var(--amber);overflow-wrap:anywhere;}
|
|
673
681
|
.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);}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
.pv-
|
|
679
|
-
.pv-
|
|
680
|
-
.pv-
|
|
682
|
+
/* 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
|
|
683
|
+
every model row sit on the same column edges. Key band: KEY | API SHAPE | BASE URL (two columns) | OLD MAX_TOKENS | TOKENS | refresh.
|
|
684
|
+
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
|
|
685
|
+
solid 1px line, a model row a dotted 1px hairline. Below 1280px every row collapses to stacked label : value lines. */
|
|
686
|
+
.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;}
|
|
687
|
+
.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;}
|
|
688
|
+
.pv-head > *,.pv-krow > *,.pv-mhead > *,.pv-mrow > *{min-width:0;}
|
|
689
|
+
.pv-head,.pv-mhead{font-size:11px;font-weight:700;color:var(--text-dim);letter-spacing:0.04em;min-height:26px;}
|
|
690
|
+
.pv-head{background:var(--panel2);border-bottom:1px solid var(--border-strong);}
|
|
691
|
+
.pv-mhead{background:var(--bg);border-bottom:1px dotted var(--border-strong);}
|
|
692
|
+
.pv-key{border-top:1px solid var(--border-strong);}
|
|
693
|
+
.pv-krow{min-height:40px;padding-top:4px;padding-bottom:4px;}
|
|
694
|
+
.pv-c-url{grid-column:3 / span 2;}
|
|
695
|
+
.pv-lbl{display:none;}
|
|
696
|
+
.pv-name{display:flex;align-items:center;flex-wrap:wrap;gap:4px 6px;min-width:0;overflow-wrap:anywhere;}
|
|
697
|
+
.pv-name code{font-weight:700;}
|
|
698
|
+
.pv-ok{color:var(--green);font-weight:700;}
|
|
699
|
+
.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;}
|
|
700
|
+
.pv-krow select,.pv-krow input[type=text]{width:100%;max-width:100%;min-height:28px;box-sizing:border-box;}
|
|
701
|
+
.pv-grid select,.pv-grid input[type=text]{font-size:12px;height:28px;padding:2px 6px;}
|
|
702
|
+
.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;}
|
|
703
|
+
.pv-legacy input,.pv-m-use input{width:16px;height:16px;margin:0;accent-color:var(--accent);cursor:pointer;}
|
|
704
|
+
.pv-tok{text-align:right;font-variant-numeric:tabular-nums;}
|
|
705
|
+
.pv-refcell{display:flex;justify-content:flex-end;}
|
|
706
|
+
.pv-refbox{display:flex;flex-direction:column;align-items:flex-start;max-width:100%;}
|
|
707
|
+
.pv-refbtns{display:flex;gap:6px;}
|
|
708
|
+
.pv-refbox .pv-msg{width:0;min-width:100%;overflow-wrap:anywhere;margin:2px 0 0;}
|
|
709
|
+
.pv-refbox .pv-msg:empty{display:none;}
|
|
710
|
+
.pv-refbtn{white-space:nowrap;flex:0 0 auto;}
|
|
711
|
+
.pv-refbtn:disabled{opacity:.5;cursor:not-allowed;}
|
|
712
|
+
.pv-sum{color:var(--text-faint);font-size:11px;font-weight:400;}
|
|
713
|
+
.pv-key[data-open="1"] .pv-sum{display:none;}
|
|
714
|
+
.pv-knote{padding:0 8px 4px 34px;margin:0;}
|
|
715
|
+
.pv-knote:empty{display:none;}
|
|
716
|
+
.pv-knote > .hint:empty{display:none;}
|
|
717
|
+
.pv-key[data-open="0"] .pv-models{display:none;}
|
|
718
|
+
.pv-mrow{border-top:1px dotted var(--border-strong);min-height:32px;}
|
|
719
|
+
.pv-mrow:hover,.pv-mrow:focus-within{background:var(--panel2);}
|
|
720
|
+
.pv-um{grid-column:1;display:flex;align-items:center;gap:0;min-width:0;}
|
|
721
|
+
.pv-uh,.pv-m-use{flex:0 0 44px;width:44px;display:flex;align-items:center;justify-content:center;}
|
|
722
|
+
.pv-m-use{min-height:32px;}
|
|
723
|
+
.pv-m-name{min-width:0;overflow-wrap:anywhere;font-size:12px;}
|
|
724
|
+
.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;}
|
|
725
|
+
.pv-pair > *{min-width:0;}
|
|
726
|
+
.pv-pair input[type=text]{width:100%;text-align:right;}
|
|
727
|
+
.pv-mhead .pv-tok{text-align:right;}
|
|
728
|
+
.pv-mhead .pv-tok,.pv-m-tok{grid-column:6;}
|
|
729
|
+
.pv-m-msg{grid-column:1 / -1;padding:2px 8px 2px 52px;margin:0;}
|
|
730
|
+
.pv-m-msg:empty{display:none;}
|
|
731
|
+
.pv-more{padding:3px 8px 3px 34px;border-top:1px dotted var(--border-strong);}
|
|
732
|
+
.pv-more:empty{display:none;}
|
|
733
|
+
.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;}
|
|
734
|
+
.pv-more.pv-failed{color:var(--amber);background:var(--amber-bg);font-size:12px;}
|
|
735
|
+
.pv-typed{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;margin-top:4px;}
|
|
736
|
+
.pv-typed input{flex:1 1 160px;min-width:0;max-width:260px;min-height:28px;box-sizing:border-box;}
|
|
737
|
+
.pv-typed .hint{flex:1 1 100%;margin:0;}
|
|
738
|
+
.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;}
|
|
739
|
+
.field label.jf-thinking input{width:auto;min-height:0;margin:0;}
|
|
681
740
|
.hint.bad{color:var(--red);}
|
|
682
741
|
.table-wrap{overflow-x:auto;border:1px solid var(--border-strong);background:var(--panel2);max-width:100%;}
|
|
683
742
|
@media (max-width: 899px){
|
|
684
743
|
.money-strip{grid-template-columns:1fr 1fr;}
|
|
744
|
+
.keyfile-strip-main{flex:1 1 100%;}
|
|
745
|
+
}
|
|
746
|
+
@media (max-width: 1279px){
|
|
747
|
+
.pv-head,.pv-mhead{display:none;}
|
|
748
|
+
.pv-krow,.pv-mrow{display:block;padding:2px 8px;}
|
|
749
|
+
.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);}
|
|
750
|
+
.pv-cell:first-child{border-top:none;}
|
|
751
|
+
.pv-lbl{display:block;font-size:11px;text-transform:uppercase;letter-spacing:.04em;color:var(--text-dim);font-weight:700;}
|
|
752
|
+
.pv-cell.nolbl{display:flex;}
|
|
753
|
+
.pv-tok{text-align:left;}
|
|
754
|
+
.pv-grid select,.pv-grid input[type=text]{height:44px;font-size:14px;}
|
|
755
|
+
.pv-krow select,.pv-krow input[type=text]{min-height:44px;}
|
|
756
|
+
.pv-legacy{min-height:44px;gap:10px;}
|
|
757
|
+
.pv-legacy input,.pv-m-use input{width:24px;height:24px;}
|
|
758
|
+
.pv-um{min-height:44px;}
|
|
759
|
+
.pv-uh,.pv-m-use{min-height:44px;}
|
|
760
|
+
.pv-cell.pv-pair{display:grid;grid-template-columns:104px minmax(0,1fr) minmax(0,1fr);}
|
|
761
|
+
.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;}
|
|
762
|
+
.pv-fold,.pv-refbtn,.pv-more .pv-add{min-height:44px;min-width:44px;}
|
|
763
|
+
.pv-knote,.pv-more{padding-left:8px;}
|
|
764
|
+
.pv-m-msg{padding-left:8px;}
|
|
685
765
|
}
|
|
686
766
|
</style>
|
|
687
767
|
</head>
|
|
@@ -689,9 +769,15 @@
|
|
|
689
769
|
|
|
690
770
|
<div id="FwdloopPanel">
|
|
691
771
|
|
|
772
|
+
<div id="update-bar" class="update-bar" data-testid="update-bar" role="status" hidden>
|
|
773
|
+
<span id="update-text"></span>
|
|
774
|
+
<button class="btn" type="button" id="update-reload" data-testid="update-reload">Reload</button>
|
|
775
|
+
</div>
|
|
776
|
+
|
|
692
777
|
<header class="topbar">
|
|
693
778
|
<div>
|
|
694
779
|
<span class="brand">fwdloop</span>
|
|
780
|
+
<span class="version" data-version="__FWDLOOP_VERSION__">v__FWDLOOP_VERSION__</span>
|
|
695
781
|
<span class="tagline">automate a job — it has humans in it</span>
|
|
696
782
|
</div>
|
|
697
783
|
<div class="topbar-right">
|
|
@@ -717,20 +803,20 @@
|
|
|
717
803
|
<div class="keyfile-strip-main">
|
|
718
804
|
<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>
|
|
719
805
|
<span class="hint bad" id="keys-refusal" data-testid="keys-refusal"></span>
|
|
806
|
+
<span class="hint" id="keys-open-note" data-testid="keys-open-note"></span>
|
|
720
807
|
</div>
|
|
721
808
|
<div class="keyfile-strip-actions">
|
|
809
|
+
<button class="btn small" id="open-keys-folder" type="button" data-testid="open-keys-folder" aria-label="Open keys folder">Open keys folder</button>
|
|
722
810
|
<button class="btn small" id="reload-keys" type="button" data-testid="reload-keys">Reload keys</button>
|
|
723
811
|
</div>
|
|
724
812
|
</div>
|
|
725
813
|
<div class="table-wrap" data-testid="provider-table-wrap">
|
|
726
|
-
<
|
|
727
|
-
<
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
<tbody id="pv-rows"></tbody>
|
|
731
|
-
</table>
|
|
814
|
+
<div class="pv-grid" data-testid="provider-table">
|
|
815
|
+
<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>
|
|
816
|
+
<div id="pv-rows"></div>
|
|
817
|
+
</div>
|
|
732
818
|
</div>
|
|
733
|
-
<div class="hint" id="pv-note" data-testid="pv-note" style="margin-top:6px;"
|
|
819
|
+
<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>
|
|
734
820
|
</section>
|
|
735
821
|
<section id="spanel-money" class="tabpanel" role="tabpanel" aria-labelledby="stab-money" hidden>
|
|
736
822
|
<div class="money-strip" data-testid="money-strip">
|
|
@@ -789,6 +875,13 @@
|
|
|
789
875
|
|
|
790
876
|
<div id="jf-new" data-testid="jf-new">
|
|
791
877
|
<div class="hint edit-banner" id="jf-edit-banner" data-testid="jf-edit-banner" hidden></div>
|
|
878
|
+
<div class="field">
|
|
879
|
+
<label for="jf-model">Model</label>
|
|
880
|
+
<select id="jf-model" data-testid="jf-model" disabled><option value="">Reading your models…</option></select>
|
|
881
|
+
<label class="jf-thinking"><input type="checkbox" id="jf-thinking" data-testid="jf-thinking"> Thinking on</label>
|
|
882
|
+
<div class="hint" id="jf-thinking-note" data-testid="jf-thinking-note"></div>
|
|
883
|
+
<div class="jf-err" id="jf-err-model" data-testid="jf-err-model"></div>
|
|
884
|
+
</div>
|
|
792
885
|
<div class="field">
|
|
793
886
|
<label for="jf-name">Flow name</label>
|
|
794
887
|
<input id="jf-name" type="text" placeholder="lowercase letters, digits, - or _" autocomplete="off" spellcheck="false" data-testid="jf-name">
|
|
@@ -800,15 +893,9 @@
|
|
|
800
893
|
<div class="jf-gut" id="jf-job-gut" data-testid="jf-job-gut" aria-hidden="true"><div class="jf-gut-in"></div></div>
|
|
801
894
|
<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>
|
|
802
895
|
</div>
|
|
803
|
-
<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>
|
|
896
|
+
<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>
|
|
804
897
|
<div class="jf-err" id="jf-err-job" data-testid="jf-err-job"></div>
|
|
805
898
|
</div>
|
|
806
|
-
<div class="field">
|
|
807
|
-
<label for="jf-dest-folder">Destination</label>
|
|
808
|
-
<input id="jf-dest-folder" type="text" placeholder="/full/path/to/a/folder" autocomplete="off" spellcheck="false" data-testid="jf-dest-folder">
|
|
809
|
-
<div class="hint">Where the accepted result is placed, at the last step. Leave empty for no send.</div>
|
|
810
|
-
<div class="jf-err" id="jf-err-destination" data-testid="jf-err-destination"></div>
|
|
811
|
-
</div>
|
|
812
899
|
<div class="field">
|
|
813
900
|
<label for="jf-inputs">Inputs</label>
|
|
814
901
|
<div class="jf-gutbox">
|
|
@@ -818,11 +905,18 @@
|
|
|
818
905
|
<div class="hint">One line per file: a name, a colon, its full path starting with /. The page never reads the file.</div>
|
|
819
906
|
<div class="jf-err" id="jf-err-inputs" data-testid="jf-err-inputs"></div>
|
|
820
907
|
</div>
|
|
908
|
+
<div class="field">
|
|
909
|
+
<label for="jf-dest-folder">Destination</label>
|
|
910
|
+
<input id="jf-dest-folder" type="text" placeholder="/full/path/to/a/folder" autocomplete="off" spellcheck="false" data-testid="jf-dest-folder">
|
|
911
|
+
<div class="hint">Where the accepted result is placed, at the last step. Leave empty for no send.</div>
|
|
912
|
+
<div class="jf-err" id="jf-err-destination" data-testid="jf-err-destination"></div>
|
|
913
|
+
</div>
|
|
821
914
|
<div class="cap-row" data-testid="cap-row">
|
|
822
915
|
<div class="cap-field">
|
|
823
916
|
<label for="jf-cap-money">Cap $</label>
|
|
824
917
|
<input id="jf-cap-money" type="text" inputmode="decimal" placeholder="per run" data-testid="jf-cap-money">
|
|
825
918
|
<div class="hint" id="jf-cap-note" data-testid="cap-note"></div>
|
|
919
|
+
<div class="hint" id="jf-cap-job-note" data-testid="jf-cap-job-note"></div>
|
|
826
920
|
<div class="jf-err" id="jf-err-capUsd" data-testid="jf-err-capUsd"></div>
|
|
827
921
|
</div>
|
|
828
922
|
<div class="cap-field">
|
|
@@ -849,6 +943,9 @@
|
|
|
849
943
|
<div class="field dimmed" data-testid="jf-run-job-field">
|
|
850
944
|
<label>The job</label>
|
|
851
945
|
<div class="ro-lines" id="jf-run-job" data-testid="jf-run-job"></div>
|
|
946
|
+
<div class="hint" id="jf-run-model" data-testid="jf-run-model"></div>
|
|
947
|
+
<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>
|
|
948
|
+
<div class="jf-err" id="jf-err-run-model" data-testid="jf-err-run-model"></div>
|
|
852
949
|
<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>
|
|
853
950
|
<button class="btn" type="button" id="jf-run-edit" data-testid="jf-run-edit">Edit this job</button>
|
|
854
951
|
<div class="hint" id="jf-run-edit-why" data-testid="jf-run-edit-why"></div>
|
|
@@ -886,6 +983,7 @@
|
|
|
886
983
|
<div class="field dimmed" data-testid="jf-resume-job-field">
|
|
887
984
|
<label>The job</label>
|
|
888
985
|
<div class="ro-lines" id="jf-resume-job" data-testid="jf-resume-job"></div>
|
|
986
|
+
<div class="hint" id="jf-resume-model" data-testid="jf-resume-model"></div>
|
|
889
987
|
</div>
|
|
890
988
|
<div class="field dimmed">
|
|
891
989
|
<label>Destination</label>
|
|
@@ -1108,6 +1206,7 @@
|
|
|
1108
1206
|
"use strict";
|
|
1109
1207
|
|
|
1110
1208
|
var PORT = "__FWDLOOP_PANEL_PORT__";
|
|
1209
|
+
var PLAN_CHECK_RULES = __FWDLOOP_PLAN_CHECK_RULES__;
|
|
1111
1210
|
// No token, no cookie (M4e amendment 4 item 8): the panel is local and trusted; the server checks Host and, on a POST, Origin.
|
|
1112
1211
|
document.getElementById("host-line").textContent = "127.0.0.1:" + PORT;
|
|
1113
1212
|
|
|
@@ -1201,7 +1300,7 @@
|
|
|
1201
1300
|
return (r.gapHead || []).concat(["ask waits " + waits]).join(" · ");
|
|
1202
1301
|
}
|
|
1203
1302
|
function auditCostCellText(r){
|
|
1204
|
-
if(r.setup && typeof r.usd !== "number" && r.verdict === "hitl") return "—"; // a setup row you wrote (card, note, sign) has no cost
|
|
1303
|
+
if(r.setup && typeof r.usd !== "number" && (r.verdict === "hitl" || r.tryRow === true)) return "—"; // a try row (its plan row has the cost) or a setup row you wrote (card, note, sign) has no cost of its own
|
|
1205
1304
|
if(r.setup) return money(r.usd, r.spendComplete) + (typeof r.wallMs === "number" ? " \u00b7 " + duration(r.wallMs) : ""); // a draft/change row: its own booked cost ("unknown" when nobody booked it) and time (left out when not recorded)
|
|
1206
1305
|
var bits = [money(r.usd, r.spendComplete)];
|
|
1207
1306
|
var td = r.tokensDisplay;
|
|
@@ -2383,6 +2482,7 @@
|
|
|
2383
2482
|
function auditDetailHtml(r, word, actionText, isRejectRow){
|
|
2384
2483
|
var lines = (typeof r.step === "string" && r.step.length > 0 ? [["step", r.step]] : []).concat([["result", word], ["action", actionText]]);
|
|
2385
2484
|
if(!isRejectRow && r.gap) lines.push(["gap", auditGapText(r)]);
|
|
2485
|
+
if(Array.isArray(r.raw) && r.raw.length > 0) lines.push(["raw", r.raw.join(" | ")]);
|
|
2386
2486
|
if(Array.isArray(r.refused) && r.refused.length > 0){
|
|
2387
2487
|
lines.push(["refused", r.refused.map(function(x){ return x.verb + " " + x.path + " (" + x.rule + ")"; }).join("; ")]);
|
|
2388
2488
|
}
|
|
@@ -2403,6 +2503,11 @@
|
|
|
2403
2503
|
// number and no close class — it shows nothing / "—", never "null", "unknown" or "#null".
|
|
2404
2504
|
function auditAttemptText(r){ return (typeof r.attempt === "number" || (typeof r.attempt === "string" && r.attempt.length > 0)) ? String(r.attempt) : ""; }
|
|
2405
2505
|
function auditCloseText(r){ return (r.setup || r.class === null || r.class === undefined) ? "—" : closeClassLabel(r.class); }
|
|
2506
|
+
// M4d am15 item 4: a try row's raw checker text, under its plain reason (the Gap cell). Server data, always escaped.
|
|
2507
|
+
function auditRawHtml(r){
|
|
2508
|
+
if(!Array.isArray(r.raw) || r.raw.length === 0) return "";
|
|
2509
|
+
return r.raw.map(function(t){ return "<div class=\"audit-raw\">" + escapeXml(String(t)) + "</div>"; }).join("");
|
|
2510
|
+
}
|
|
2406
2511
|
function buildAuditRowEl(r, includeStep){
|
|
2407
2512
|
var tr = document.createElement("tr");
|
|
2408
2513
|
var glyph = verdictGlyph(r.verdict, r.class);
|
|
@@ -2419,7 +2524,7 @@
|
|
|
2419
2524
|
"<td data-label=\"Attempt\">" + escapeXml(auditAttemptText(r)) + "</td>" +
|
|
2420
2525
|
(includeStep ? "<td data-label=\"Step\">" + escapeXml(r.stepName || r.step) + "</td>" : "") +
|
|
2421
2526
|
"<td data-label=\"Action\">" + escapeXml(actionText) + "</td>" +
|
|
2422
|
-
"<td data-label=\"Gap\">" + escapeXml(isRejectRow ? "" : auditGapText(r)) + "</td>" +
|
|
2527
|
+
"<td data-label=\"Gap\">" + escapeXml(isRejectRow ? "" : auditGapText(r)) + auditRawHtml(r) + "</td>" +
|
|
2423
2528
|
"<td data-label=\"Cost\">" + escapeXml(auditCostCellText(r)) + "</td>" +
|
|
2424
2529
|
"<td data-label=\"Verdict\"><span class=\"badge " + badgeClass + "\">" + escapeXml(word) + "</span></td>" +
|
|
2425
2530
|
"<td data-label=\"Close\">" + escapeXml(auditCloseText(r)) + "</td>" +
|
|
@@ -2882,8 +2987,35 @@
|
|
|
2882
2987
|
// One last-payload signature per render. Equal payload = the DOM is not touched. `selectRun` resets
|
|
2883
2988
|
// the ones a different selection invalidates.
|
|
2884
2989
|
var lastSig = { inbox: null, runs: null, detail: null, asks: null, audit: null };
|
|
2990
|
+
// `timeLeftMs` differs on every poll and is not part of what a page draw is built from (the words move in place: `liveLeft`/`tickLeft`),
|
|
2991
|
+
// so it is left out: a poll that changed nothing else is "unchanged" and rebuilds nothing (a rebuild resets every scrolled box).
|
|
2885
2992
|
function sig(obj){
|
|
2886
|
-
try { return JSON.stringify(obj); } catch(e){ return null; }
|
|
2993
|
+
try { return JSON.stringify(obj, function(k, v){ return k === "timeLeftMs" ? undefined : v; }); } catch(e){ return null; }
|
|
2994
|
+
}
|
|
2995
|
+
// "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
|
|
2996
|
+
// 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.
|
|
2997
|
+
function liveLeft(el, timeLeftMs, say){
|
|
2998
|
+
if(typeof timeLeftMs !== "number") { say(timeLeftMs); return; }
|
|
2999
|
+
el.classList.add("live-left");
|
|
3000
|
+
el._endsAt = Date.now() + timeLeftMs;
|
|
3001
|
+
el._say = say;
|
|
3002
|
+
say(timeLeftMs);
|
|
3003
|
+
}
|
|
3004
|
+
// M4d am18: the page keeps the version it was served with (the header's data-version, am17); the Inbox poll reports the server's. A different one = the panel
|
|
3005
|
+
// restarted on newer code under this open tab: say so. Pure text rule (null = no bar), one painter.
|
|
3006
|
+
function updateBarText(pageVersion, serverVersion){
|
|
3007
|
+
if(typeof pageVersion !== "string" || pageVersion === "" || typeof serverVersion !== "string" || serverVersion === "") return null;
|
|
3008
|
+
return pageVersion === serverVersion ? null : "fwdloop was updated to v" + serverVersion + ". Reload this page.";
|
|
3009
|
+
}
|
|
3010
|
+
function paintUpdateBar(serverVersion){
|
|
3011
|
+
var vEl = document.querySelector(".topbar .version");
|
|
3012
|
+
var text = updateBarText(vEl ? vEl.getAttribute("data-version") : "", serverVersion);
|
|
3013
|
+
document.getElementById("update-bar").hidden = text === null;
|
|
3014
|
+
if(text !== null) document.getElementById("update-text").textContent = text;
|
|
3015
|
+
}
|
|
3016
|
+
document.getElementById("update-reload").addEventListener("click", function(){ location.reload(); });
|
|
3017
|
+
function tickLeft(){
|
|
3018
|
+
document.querySelectorAll(".live-left").forEach(function(el){ el._say(Math.max(0, el._endsAt - Date.now())); });
|
|
2887
3019
|
}
|
|
2888
3020
|
// Saves/restores scrollTop of the given element ids around a re-render.
|
|
2889
3021
|
function withScrollPreserved(ids, fn){
|
|
@@ -2939,9 +3071,9 @@
|
|
|
2939
3071
|
document.getElementById("run-content").hidden = true;
|
|
2940
3072
|
});
|
|
2941
3073
|
// the same late-reply guard on audit, job and asks: a reply for a run the user already left paints nothing
|
|
2942
|
-
getJSON(base + "/audit").then(function(a){ if(still()) renderAudit(a); }).catch(function(){ if(still()) renderAudit(null); });
|
|
3074
|
+
getJSON(base + "/audit").then(function(a){ if(still()){ lastSig.audit = sig(a); renderAudit(a); } }).catch(function(){ if(still()) renderAudit(null); });
|
|
2943
3075
|
getJSON(base + "/job").then(function(j){ if(still()) renderJob(j); }).catch(function(){ if(still()) renderJob(null); });
|
|
2944
|
-
getJSON(base + "/asks").then(function(result){ if(still())
|
|
3076
|
+
getJSON(base + "/asks").then(function(result){ if(still()) paintAsks(result, focusAskId || null); }).catch(function(e){
|
|
2945
3077
|
if(still()) renderAsk(null, null, loadFailureText(e));
|
|
2946
3078
|
});
|
|
2947
3079
|
}
|
|
@@ -2977,7 +3109,7 @@
|
|
|
2977
3109
|
// Immediate (every user action that re-reads calls this); the tick uses `listsDue` to throttle.
|
|
2978
3110
|
function reloadLists(){
|
|
2979
3111
|
lastListsAt = Date.now();
|
|
2980
|
-
getJSON("/api/inbox").then(function(r){ renderInbox(r.rows || [], r.openCount); }).catch(function(){});
|
|
3112
|
+
getJSON("/api/inbox").then(function(r){ renderInbox(r.rows || [], r.openCount); paintUpdateBar(r.version); }).catch(function(){});
|
|
2981
3113
|
getJSON("/api/runs").then(function(r){
|
|
2982
3114
|
var rows = r.rows || [];
|
|
2983
3115
|
var next = sig(rows);
|
|
@@ -2986,17 +3118,21 @@
|
|
|
2986
3118
|
withScrollPreserved(["left-pane-body"], function(){ runsFilterBar.setItems(rows); runsFilterBar.refresh(); });
|
|
2987
3119
|
}).catch(function(){});
|
|
2988
3120
|
}
|
|
3121
|
+
// 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).
|
|
3122
|
+
// The signature is stamped only when renderAsk REALLY drew (it returns false when held over a typed reason): a held redraw leaves the stamp
|
|
3123
|
+
// 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
|
|
3124
|
+
// first poll after a click finds the stamp and rebuilds nothing (an unstamped first draw was a second, needless rebuild 2 s later).
|
|
3125
|
+
function paintAsks(a, focusAskId){
|
|
3126
|
+
var next = sig({ asks: a, pending: pendingAnswer });
|
|
3127
|
+
if(focusAskId || next === null || next !== lastSig.asks){ lastSig.asks = renderAsk(a, focusAskId) ? next : null; }
|
|
3128
|
+
}
|
|
2989
3129
|
function reloadRun(flow, runId, skipLists){
|
|
2990
3130
|
var base = "/api/runs/" + encodeURIComponent(flow) + "/" + encodeURIComponent(runId);
|
|
2991
3131
|
var still = function(){ return currentFlow === flow && currentRunId === runId; };
|
|
2992
3132
|
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
|
|
2993
3133
|
var asksP = getJSON(base + "/asks").then(function(a){
|
|
2994
3134
|
if(still()){
|
|
2995
|
-
|
|
2996
|
-
var next = sig({ asks: a, pending: pendingAnswer });
|
|
2997
|
-
// the signature is stamped only when renderAsk REALLY drew (it returns false when held over a typed
|
|
2998
|
-
// reason): a held redraw leaves the stamp unset, so the next tick retries it against the same payload
|
|
2999
|
-
if(next === null || next !== lastSig.asks){ lastSig.asks = renderAsk(a, null) ? next : null; }
|
|
3135
|
+
paintAsks(a, null);
|
|
3000
3136
|
}
|
|
3001
3137
|
return a;
|
|
3002
3138
|
}).catch(function(e){ if(still()){ lastSig.asks = null; renderAsk(null, null, loadFailureText(e)); } return null; });
|
|
@@ -3016,6 +3152,7 @@
|
|
|
3016
3152
|
if(document.hidden){ wasHidden = true; schedulePoll(LIVE_POLL_MS); return; }
|
|
3017
3153
|
var catchUp = wasHidden; // first tick after the tab came back: force both
|
|
3018
3154
|
wasHidden = false;
|
|
3155
|
+
tickLeft();
|
|
3019
3156
|
var watch = live;
|
|
3020
3157
|
var sel = currentFlow !== null && currentRunId !== null;
|
|
3021
3158
|
var watchIsSelected = watch && sel && watch.flow === currentFlow && watch.runId === currentRunId;
|
|
@@ -3167,7 +3304,11 @@
|
|
|
3167
3304
|
wrap.appendChild(head);
|
|
3168
3305
|
var meta = textDiv("wf-sign-line", "");
|
|
3169
3306
|
meta.setAttribute("data-testid", "inbox-sign-word");
|
|
3170
|
-
|
|
3307
|
+
if(row.waiting){
|
|
3308
|
+
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; } });
|
|
3309
|
+
} else {
|
|
3310
|
+
meta.innerHTML = signHtml(row.word, stopStatusLine(row), stopStatusLine(row));
|
|
3311
|
+
}
|
|
3171
3312
|
wrap.appendChild(meta);
|
|
3172
3313
|
if(typeof row.question === "string"){
|
|
3173
3314
|
wrap.appendChild(textDiv("step-meta", "question: " + row.question));
|
|
@@ -3224,7 +3365,11 @@
|
|
|
3224
3365
|
// role="button" (never a real <button>), same posture as the step-map's
|
|
3225
3366
|
// own SVG nodes elsewhere on this page. ----
|
|
3226
3367
|
function askStatusBlock(ask){
|
|
3227
|
-
if(ask.waiting)
|
|
3368
|
+
if(ask.waiting){
|
|
3369
|
+
var left = textDiv("wf-meta", "");
|
|
3370
|
+
liveLeft(left, ask.timeLeftMs, function(ms){ var t = "time left: " + duration(ms); if(left.textContent !== t) left.textContent = t; });
|
|
3371
|
+
return left;
|
|
3372
|
+
}
|
|
3228
3373
|
// an open ask with a saved answer: the header meta line already says the resume label (stuck or starting) — once.
|
|
3229
3374
|
if(ask.open && ask.resume) return null;
|
|
3230
3375
|
var bits = [ask.statusText || ask.status];
|
|
@@ -3722,7 +3867,17 @@
|
|
|
3722
3867
|
kept[w.getAttribute("data-testid")] = { open: w.getAttribute("data-open"), expanded: w.firstChild.getAttribute("aria-expanded") === "true" };
|
|
3723
3868
|
});
|
|
3724
3869
|
}
|
|
3870
|
+
// A redraw (the books really changed) must not move what the human is reading either: every evidence box keeps its scrollTop (same run only),
|
|
3871
|
+
// and so does the pane. The rebuilt boxes are filled below, per block, once they are in the page.
|
|
3872
|
+
var sameRun = askDrawnFor === result.flow + "/" + result.runId;
|
|
3873
|
+
var tops = {};
|
|
3874
|
+
if(sameRun){
|
|
3875
|
+
list.querySelectorAll("[data-testid^='ask-block-']").forEach(function(w){
|
|
3876
|
+
tops[w.getAttribute("data-testid")] = Array.prototype.map.call(w.querySelectorAll(".scroll"), function(b){ return b.scrollTop; });
|
|
3877
|
+
});
|
|
3878
|
+
}
|
|
3725
3879
|
askDrawnFor = result.flow + "/" + result.runId;
|
|
3880
|
+
var paneTop = (document.getElementById("right-pane-body") || {}).scrollTop;
|
|
3726
3881
|
list.innerHTML = "";
|
|
3727
3882
|
// Default expansion: the block holding the ask a click from the Inbox
|
|
3728
3883
|
// (`focusAskId`) named wins; otherwise a block with an open ask expands;
|
|
@@ -3745,6 +3900,8 @@
|
|
|
3745
3900
|
row.classList.add("audit-group-highlight");
|
|
3746
3901
|
}
|
|
3747
3902
|
list.appendChild(row);
|
|
3903
|
+
var savedTops = tops[row.getAttribute("data-testid")];
|
|
3904
|
+
if(savedTops) Array.prototype.forEach.call(row.querySelectorAll(".scroll"), function(b, i){ if(savedTops[i]) b.scrollTop = savedTops[i]; });
|
|
3748
3905
|
if(expanded){
|
|
3749
3906
|
// Scroll the focused ask into view (M4a-1 design: clicking a stop
|
|
3750
3907
|
// on the left "focuses" it on the right) — never on a run's own
|
|
@@ -3754,6 +3911,7 @@
|
|
|
3754
3911
|
}
|
|
3755
3912
|
}
|
|
3756
3913
|
});
|
|
3914
|
+
if(sameRun && paneTop){ var pane = document.getElementById("right-pane-body"); if(pane) pane.scrollTop = paneTop; }
|
|
3757
3915
|
return true;
|
|
3758
3916
|
}
|
|
3759
3917
|
|
|
@@ -3814,7 +3972,7 @@
|
|
|
3814
3972
|
var sessionId = null; // the draft's id (GET /api/author/<id>)
|
|
3815
3973
|
var sessionLive = false; // a draft exists that is not abandoned or signed
|
|
3816
3974
|
var lastState = null; // the draft as the server last described it
|
|
3817
|
-
var signInfo = null; // the first Sign click's reply: { hash, flowName, capUsd, runId }
|
|
3975
|
+
var signInfo = null; // the first Sign click's reply: { hash, flowName, capUsd, runId, split }
|
|
3818
3976
|
var signClickedOnce = false;
|
|
3819
3977
|
var reviseOpen = false; // amendment 14 item 2: Revise was pressed on a green plan, so every card field is open (ONE writer: setReviseOpen)
|
|
3820
3978
|
var qKey = ""; // which question the box is showing (draft id + k): the answer box is rewritten only when this changes
|
|
@@ -3935,33 +4093,11 @@
|
|
|
3935
4093
|
// 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
|
|
3936
4094
|
// 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
|
|
3937
4095
|
// the checker's own fixed wording, never the model's prose.
|
|
4096
|
+
// M4d am15: the plain words are src/plain-checks.js, handed to the page by the server (PLAN_CHECK_RULES, top of this script): one copy.
|
|
3938
4097
|
function plainPlanCheck(raw){
|
|
3939
|
-
var PLAN_CHECK_RULES = [
|
|
3940
|
-
[/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."],
|
|
3941
|
-
[/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."],
|
|
3942
|
-
[/the guardrail says \d+ sections; the check has/, "The number of sections in your guardrail is not the number in the plan's check."],
|
|
3943
|
-
[/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."],
|
|
3944
|
-
[/one section name may not contain another/, "One section name in the plan's check contains another, which cannot be checked."],
|
|
3945
|
-
[/wordsPerSection/, "The words for each section in your guardrail and in the plan's check do not match."],
|
|
3946
|
-
[/work as a pair/, "The plan's check has one part of a pair without the other, so it cannot be checked."],
|
|
3947
|
-
[/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."],
|
|
3948
|
-
[/cannot be built into a check/, "The plan's check cannot be built from what the AI wrote."],
|
|
3949
|
-
[/is not its signed line/, "A step does not use your job line word for word as its goal."],
|
|
3950
|
-
[/not in the catalogue|not wired|which is not signed|checkpoint/, "A step uses a tool that is not available for this job."],
|
|
3951
|
-
[/reads artifact|is a duplicate|\.reads must|\.emits must/, "The steps do not pass their results to each other in a workable order."],
|
|
3952
|
-
[/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."],
|
|
3953
|
-
[/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."],
|
|
3954
|
-
[/hitl after the last signed ask/, "A step after your last ask would leave without your seeing it, so it is refused."],
|
|
3955
|
-
[/is a pause .* unsigned line/, "A step pauses at a line you did not sign as an ask."],
|
|
3956
|
-
[/neither served by any step/, "A line of your job is not covered by any step."],
|
|
3957
|
-
[/picks|inputFacts|invented name/, "The plan names a field that is not in your input."],
|
|
3958
|
-
[/guardrailClasses|unjudgeable|refused/, "The AI's notes on which lines it can check are not in a form the checker accepts."],
|
|
3959
|
-
[/^line \d+'s (guardrail|check)|can't write files/, null],
|
|
3960
|
-
[/must be an? |is required|must name|does not name/, "The plan the AI wrote is not in the shape the checker needs."]
|
|
3961
|
-
];
|
|
3962
4098
|
var text = typeof raw === "string" ? raw : "";
|
|
3963
4099
|
for(var i = 0; i < PLAN_CHECK_RULES.length; i++){
|
|
3964
|
-
if(PLAN_CHECK_RULES[i]
|
|
4100
|
+
if(new RegExp(PLAN_CHECK_RULES[i].re).test(text)) return {say: PLAN_CHECK_RULES[i].say === null ? text.replace(/^declaration: /, "") : PLAN_CHECK_RULES[i].say, raw: text};
|
|
3965
4101
|
}
|
|
3966
4102
|
return {say: "One of the checks on the plan failed.", raw: text};
|
|
3967
4103
|
}
|
|
@@ -3975,6 +4111,16 @@
|
|
|
3975
4111
|
function stepsFor(state, ctx){
|
|
3976
4112
|
var out = [];
|
|
3977
4113
|
var who = ctx.model ? ctx.model : "the drafter";
|
|
4114
|
+
// 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,
|
|
4115
|
+
// each ✗ plan-check refusal turned into its plain sentence; a draft with no log lists what it always did (`fallback`).
|
|
4116
|
+
function draftLines(fallback){
|
|
4117
|
+
if(!state || !Array.isArray(state.stepList) || state.stepList.length === 0) return fallback();
|
|
4118
|
+
state.stepList.forEach(function(st){
|
|
4119
|
+
var row = {id: st.id, label: st.label, status: st.status === "failed" ? "failed" : (st.status === "waiting" ? "waiting" : "done"), details: st.details || []};
|
|
4120
|
+
if(st.note === true) row.note = true;
|
|
4121
|
+
out.push(row);
|
|
4122
|
+
});
|
|
4123
|
+
}
|
|
3978
4124
|
var cap = state && state.card && state.card.capUsd !== undefined && state.card.capUsd !== "" ? state.card.capUsd : "";
|
|
3979
4125
|
var capPart = cap !== "" ? ", run cap $" + cap : "";
|
|
3980
4126
|
if(state){
|
|
@@ -3982,14 +4128,21 @@
|
|
|
3982
4128
|
out.push({id: "drafting", label: "drafting with " + who + capPart, status: "running", details: []});
|
|
3983
4129
|
} else if(Array.isArray(state.revises)){
|
|
3984
4130
|
// 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).
|
|
3985
|
-
out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []});
|
|
4131
|
+
draftLines(function(){ out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []}); });
|
|
3986
4132
|
var reviseNo = 0;
|
|
3987
4133
|
state.revises.forEach(function(rv){
|
|
3988
|
-
// an answer redraft (amendment 24 item 4) is not a revise and is not counted as one
|
|
3989
|
-
|
|
4134
|
+
// an answer redraft (amendment 24 item 4) is not a revise and is not counted as one; the server names each one (`rv.name`) and, from the plan's own log,
|
|
4135
|
+
// writes its line (`rv.lines`, src/draft-steps.js `reviseStepList`): one line, facts joined by " · ", a red one with one plain reason and a Fix line (am15)
|
|
4136
|
+
var label = rv.name || (rv.kind === "answers" ? "drafted again with your answers" : "revise " + (reviseNo += 1));
|
|
3990
4137
|
if(rv.phase === "running") out.push({id: "revise-" + rv.n, label: label, status: "running", details: []});
|
|
3991
|
-
else if(rv.
|
|
3992
|
-
|
|
4138
|
+
else if(Array.isArray(rv.lines) && rv.lines.length){
|
|
4139
|
+
rv.lines.forEach(function(l){
|
|
4140
|
+
var row = {id: "revise-" + rv.n + "-" + l.id, label: l.label, status: l.status === "failed" ? "failed" : "done", details: []};
|
|
4141
|
+
if(l.note === true) row.note = true;
|
|
4142
|
+
out.push(row);
|
|
4143
|
+
});
|
|
4144
|
+
}
|
|
4145
|
+
else out.push({id: "revise-" + rv.n, label: label, status: rv.phase === "green" ? "done" : "failed", details: []});
|
|
3993
4146
|
});
|
|
3994
4147
|
if(state.phase === "green"){
|
|
3995
4148
|
if(ctx.starting) out.push({id: "signed", label: "signed", status: "done", details: []});
|
|
@@ -3997,13 +4150,14 @@
|
|
|
3997
4150
|
}
|
|
3998
4151
|
if(state.phase === "questions-open") out.push({id: "question", label: "waiting for your answer (" + state.openK + " of " + state.total + ")", status: "waiting", details: []});
|
|
3999
4152
|
} else if(state.phase === "red"){
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4153
|
+
draftLines(function(){
|
|
4154
|
+
out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []});
|
|
4155
|
+
out.push({id: "checks", label: "plan checks", status: "failed", details: []}); // no log to read a reason from: the card's own sentence says it
|
|
4156
|
+
});
|
|
4003
4157
|
} else if(state.phase === "stopped"){
|
|
4004
4158
|
out.push({id: "drafting", label: "drafting with " + who + capPart, status: "failed", details: []});
|
|
4005
4159
|
} else if(state.phase === "green" || state.phase === "revising"){
|
|
4006
|
-
out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []});
|
|
4160
|
+
draftLines(function(){ out.push({id: "drafted", label: "drafted with " + who, status: "done", details: []}); });
|
|
4007
4161
|
if(ctx.starting){
|
|
4008
4162
|
out.push({id: "signed", label: "signed", status: "done", details: []});
|
|
4009
4163
|
} else if(state.phase !== "revising"){
|
|
@@ -4147,6 +4301,9 @@
|
|
|
4147
4301
|
inputs: inputsBox.value,
|
|
4148
4302
|
capUsd: byId("jf-cap-money").value.trim(),
|
|
4149
4303
|
askWait: askWaitEl.value.trim(),
|
|
4304
|
+
provider: modelPick().provider,
|
|
4305
|
+
model: modelPick().model,
|
|
4306
|
+
thinking: thinkingEl.checked && !thinkingEl.disabled,
|
|
4150
4307
|
editOf: editOf
|
|
4151
4308
|
};
|
|
4152
4309
|
}
|
|
@@ -4158,7 +4315,9 @@
|
|
|
4158
4315
|
function currentRun(){
|
|
4159
4316
|
return {
|
|
4160
4317
|
flow: pickedFlow || "", inputs: readRows(runInputsEl), runId: (byId("jf-run-id").value.trim() === autoRunId ? "" : byId("jf-run-id").value.trim()),
|
|
4161
|
-
destination: runDestEl.value.trim(), capUsd: runCapEl.value.trim(), askWaits: runWaits()
|
|
4318
|
+
destination: runDestEl.value.trim(), capUsd: runCapEl.value.trim(), askWaits: runWaits(),
|
|
4319
|
+
// a flow with no recorded model runs with the pick (am7b); a flow with one sends none
|
|
4320
|
+
...(runPickEl.hidden ? {} : { provider: runPickChoice().provider, model: runPickChoice().model })
|
|
4162
4321
|
};
|
|
4163
4322
|
}
|
|
4164
4323
|
// 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
|
|
@@ -4217,21 +4376,33 @@
|
|
|
4217
4376
|
function jobHasModelStep(){
|
|
4218
4377
|
return byId("jf-job").value.split("\n").some(function(l){ var t = l.trim(); return t !== "" && t.charAt(0) !== "~" && !/^ask\b/i.test(t); });
|
|
4219
4378
|
}
|
|
4379
|
+
// M4d am21 item 3: with no step that needs a model the cap cannot be checked against one yet: a grey line says so (the New job card only)
|
|
4380
|
+
function paintCapJobNote(m){
|
|
4381
|
+
byId("jf-cap-job-note").textContent = (m === "new" && !jobHasModelStep()) ? "The cap is checked against the model once the job has a step." : "";
|
|
4382
|
+
}
|
|
4220
4383
|
function refreshCapNote(){
|
|
4384
|
+
paintCapJobNote(mode);
|
|
4221
4385
|
var cap = mode === "run" ? runCapEl.value.trim() : (mode === "resume" ? resumeCapEl.value.trim() : byId("jf-cap-money").value.trim());
|
|
4222
4386
|
var seq = ++capNoteSeq;
|
|
4223
4387
|
if(cap === ""){ setMoneyNote("", false); return; }
|
|
4224
4388
|
// a Resume holds only what the run has still to spend (amendment 4 item 1): the server is told what is already spent
|
|
4225
|
-
var spent = (mode === "resume" && resumeCtx) ? "&spent=" + encodeURIComponent(String(resumeCtx.form.spentUsd)) : "";
|
|
4226
|
-
|
|
4389
|
+
var spent = (mode === "resume" && resumeCtx) ? "&spent=" + encodeURIComponent(String(resumeCtx.form.spentUsd)) + "&flow=" + encodeURIComponent(resumeCtx.flow) + "&kind=run" : "";
|
|
4390
|
+
var pk = modelPick();
|
|
4391
|
+
var picked = (mode === "new" && pk.provider !== "") ? "&provider=" + encodeURIComponent(pk.provider) + "&model=" + encodeURIComponent(pk.model) : "";
|
|
4392
|
+
// M4d am20: Run a signed flow does not draft: the server writes the same cap-too-small sentence with "run" (the flow's recorded model, else the one picked in Chat)
|
|
4393
|
+
var sfNow = selectedFlow();
|
|
4394
|
+
if(mode === "run" && sfNow) picked = "&kind=run&flow=" + encodeURIComponent(sfNow.flow) + (pk.provider !== "" ? "&provider=" + encodeURIComponent(pk.provider) + "&model=" + encodeURIComponent(pk.model) : "");
|
|
4395
|
+
// M4d am21 item 1: a card that belongs to a live draft (a revise, or the Start over about to be made) is checked for the pot left, as the doors do
|
|
4396
|
+
var ofDraft = (mode === "new" && sessionLive && sessionId) ? "&draft=" + encodeURIComponent(sessionId) : "";
|
|
4397
|
+
authorGet("/api/author/monthly-check?cap=" + encodeURIComponent(cap) + spent + picked + ofDraft).then(function(j){
|
|
4227
4398
|
if(seq !== capNoteSeq) return;
|
|
4228
4399
|
if(!j || j.ok !== true){ setMoneyNote("", false); return; }
|
|
4229
4400
|
var v = Number(cap);
|
|
4230
4401
|
if(mode === "new" && j.floorText && isFinite(v) && v > 0 && v < j.floorUsd && jobHasModelStep()){ setMoneyNote(j.floorText, true); return; }
|
|
4231
4402
|
// a Run's own cap is never judged against the floor (an old flow signed lower still runs plain); a changed cap below it is red
|
|
4232
4403
|
var sf = selectedFlow();
|
|
4233
|
-
if(mode === "run" && sf && j.floorText && isFinite(v) && v > 0 && v !== sf.capUsd && v < sf.capFloorUsd){ setMoneyNote(
|
|
4234
|
-
if(mode === "resume" && resumeCtx && j.floorText && isFinite(v) && v > resumeCtx.form.spentUsd && v < resumeCtx.form.floorUsd){ setMoneyNote(
|
|
4404
|
+
if(mode === "run" && sf && j.floorText && isFinite(v) && v > 0 && v !== sf.capUsd && v < sf.capFloorUsd){ setMoneyNote(j.floorText, true); return; }
|
|
4405
|
+
if(mode === "resume" && resumeCtx && j.floorText && isFinite(v) && v > resumeCtx.form.spentUsd && v < resumeCtx.form.floorUsd){ setMoneyNote(j.floorText, true); return; }
|
|
4235
4406
|
setMoneyNote(typeof j.text === "string" ? j.text : "", j.red === true);
|
|
4236
4407
|
}).catch(function(){ if(seq === capNoteSeq) setMoneyNote("", false); });
|
|
4237
4408
|
}
|
|
@@ -4251,6 +4422,7 @@
|
|
|
4251
4422
|
return row ? row.querySelector(".jf-err") : null;
|
|
4252
4423
|
}
|
|
4253
4424
|
if(field === "inputs") return byId(mode === "run" ? "jf-err-run-inputs" : "jf-err-inputs");
|
|
4425
|
+
if(mode === "run" && field === "model") return byId("jf-err-run-model");
|
|
4254
4426
|
if(mode === "run" && (field === "destination" || field === "capUsd")) return byId("jf-err-run-" + field);
|
|
4255
4427
|
if(mode === "run" && /^askWaits/.test(field)) return byId("jf-err-run-askWaits");
|
|
4256
4428
|
if(mode === "resume" && field === "capUsd") return byId("jf-err-resume-capUsd");
|
|
@@ -4356,6 +4528,8 @@
|
|
|
4356
4528
|
paintedFlow = pickedKey();
|
|
4357
4529
|
runSignInfo = null;
|
|
4358
4530
|
paintJobDim(byId("jf-run-job"), f ? f.jobLines : []);
|
|
4531
|
+
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." : "");
|
|
4532
|
+
runPickEl.hidden = !(f && !f.model);
|
|
4359
4533
|
runDestEl.value = v && v.destination ? v.destination : "";
|
|
4360
4534
|
runDestEl.readOnly = !(f && f.hasSend);
|
|
4361
4535
|
runDestEl.classList.toggle("locked", !(f && f.hasSend));
|
|
@@ -4412,10 +4586,14 @@
|
|
|
4412
4586
|
byId("jf-err-flow").textContent = "";
|
|
4413
4587
|
renderFlowSearch(); paintRunFlow(); refreshStartEnabled();
|
|
4414
4588
|
}
|
|
4415
|
-
|
|
4416
|
-
|
|
4589
|
+
// the one writer of the Run-a-signed-flow pick (the Change link and Clear both go through it)
|
|
4590
|
+
function clearPick(){
|
|
4417
4591
|
pickedFlow = null; pickedRun = null; pickedLabel = ""; againEntry = null; rwHl = 0;
|
|
4418
4592
|
runFlowSel.value = "";
|
|
4593
|
+
}
|
|
4594
|
+
function unpickFlow(){
|
|
4595
|
+
if(cardLocked()) return;
|
|
4596
|
+
clearPick();
|
|
4419
4597
|
renderFlowSearch(); paintRunFlow(); refreshStartEnabled();
|
|
4420
4598
|
}
|
|
4421
4599
|
function loadFlows(force){
|
|
@@ -4430,12 +4608,76 @@
|
|
|
4430
4608
|
refreshStartEnabled();
|
|
4431
4609
|
}).catch(function(){ /* the card keeps what it had */ });
|
|
4432
4610
|
}
|
|
4433
|
-
// the
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4611
|
+
// ---- the Model menu and the per-job "Thinking on" box (M4d amendments 6 and 7) ----
|
|
4612
|
+
// The menu is the ticked lines of Settings > Providers, "provider · model"; the server decides what is listed (GET /api/author/models) and
|
|
4613
|
+
// whether Thinking can change for a line (one function over bareagent's answer, src/thinking.js). The page decides nothing.
|
|
4614
|
+
var modelEl = byId("jf-model");
|
|
4615
|
+
var thinkingEl = byId("jf-thinking");
|
|
4616
|
+
var modelLines = [];
|
|
4617
|
+
function modelPick(){
|
|
4618
|
+
var l = modelLines[Number(modelEl.value)];
|
|
4619
|
+
return l ? {provider: l.slot, model: l.model} : {provider: "", model: ""};
|
|
4620
|
+
}
|
|
4621
|
+
// the box's state for a menu line: unticked by default; greyed with the server's sentence when thinking cannot change for that model
|
|
4622
|
+
function thinkingBoxState(line, wasChecked){
|
|
4623
|
+
if(!line || !line.thinking) return {disabled: true, checked: false, note: ""};
|
|
4624
|
+
if(line.thinking.canChange !== true) return {disabled: true, checked: false, note: line.thinking.say || ""};
|
|
4625
|
+
// an unchecked model's note (am11 item 2) says "thinking off"; ticked, it would be wrong, so it goes
|
|
4626
|
+
return {disabled: false, checked: wasChecked === true, note: wasChecked === true ? "" : (line.thinking.say || "")};
|
|
4627
|
+
}
|
|
4628
|
+
function paintThinking(){
|
|
4629
|
+
var st = thinkingBoxState(modelLines[Number(modelEl.value)], thinkingEl.checked);
|
|
4630
|
+
thinkingEl.disabled = st.disabled; thinkingEl.checked = st.checked;
|
|
4631
|
+
byId("jf-thinking-note").textContent = st.note;
|
|
4632
|
+
drafterModel = modelPick().model;
|
|
4633
|
+
}
|
|
4634
|
+
modelEl.addEventListener("change", function(){ paintThinking(); refreshCapNote(); });
|
|
4635
|
+
thinkingEl.addEventListener("change", paintThinking);
|
|
4636
|
+
function setModelPick(provider, model){
|
|
4637
|
+
for(var i = 0; i < modelLines.length; i += 1){ if(modelLines[i].slot === provider && modelLines[i].model === model){ modelEl.value = String(i); break; } }
|
|
4638
|
+
paintThinking();
|
|
4639
|
+
}
|
|
4640
|
+
// 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:
|
|
4641
|
+
// 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).
|
|
4642
|
+
var runPickEl = byId("jf-run-pick");
|
|
4643
|
+
var runPicked = {provider: "", model: ""}; // what the person chose here, by identity (the indexes change when the list is re-read)
|
|
4644
|
+
function runPickChoice(){
|
|
4645
|
+
var l = runPickEl.hidden ? null : modelLines[Number(runPickEl.value)];
|
|
4646
|
+
return l ? {provider: l.slot, model: l.model} : {provider: "", model: ""};
|
|
4647
|
+
}
|
|
4648
|
+
runPickEl.addEventListener("change", function(){ runPicked = runPickChoice(); });
|
|
4649
|
+
function syncRunPick(){
|
|
4650
|
+
runPickEl.innerHTML = modelEl.innerHTML; runPickEl.disabled = modelEl.disabled;
|
|
4651
|
+
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; } }
|
|
4652
|
+
}
|
|
4653
|
+
// `tries` counts the reads that failed in a row (a click passes an Event, which is not a number: that is a fresh read).
|
|
4654
|
+
// 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.
|
|
4655
|
+
function loadModel(tries){
|
|
4656
|
+
var failed = typeof tries === "number" ? tries : 0;
|
|
4657
|
+
function unread(){
|
|
4658
|
+
if(modelLines.length > 0) return; // a menu that was filled keeps what it had
|
|
4659
|
+
modelEl.innerHTML = ""; modelEl.disabled = true;
|
|
4660
|
+
var o = document.createElement("option"); o.value = "";
|
|
4661
|
+
o.textContent = failed < 5 ? "Could not read your models. Trying again\u2026" : "Could not read your models. Reload the page.";
|
|
4662
|
+
modelEl.appendChild(o);
|
|
4663
|
+
syncRunPick();
|
|
4664
|
+
if(failed < 5) setTimeout(function(){ loadModel(failed + 1); }, 1500);
|
|
4665
|
+
}
|
|
4666
|
+
authorGet("/api/author/models").then(function(j){
|
|
4667
|
+
if(!j || j.ok !== true){ failed += 1; unread(); return; }
|
|
4668
|
+
var was = modelPick();
|
|
4669
|
+
modelLines = j.lines || [];
|
|
4670
|
+
modelEl.innerHTML = "";
|
|
4671
|
+
if(modelLines.length === 0){
|
|
4672
|
+
var none = document.createElement("option"); none.value = ""; none.textContent = j.say || "Tick a model in Settings > Providers."; modelEl.appendChild(none);
|
|
4673
|
+
modelEl.disabled = true;
|
|
4674
|
+
} else {
|
|
4675
|
+
modelEl.disabled = false;
|
|
4676
|
+
modelLines.forEach(function(l, i){ var o = document.createElement("option"); o.value = String(i); o.textContent = l.label; modelEl.appendChild(o); });
|
|
4677
|
+
}
|
|
4678
|
+
setModelPick(was.provider, was.model);
|
|
4679
|
+
syncRunPick();
|
|
4680
|
+
}).catch(function(){ failed += 1; unread(); });
|
|
4439
4681
|
}
|
|
4440
4682
|
function setMode(m){
|
|
4441
4683
|
mode = m;
|
|
@@ -4468,7 +4710,9 @@
|
|
|
4468
4710
|
progressRow.hidden = steps.length === 0;
|
|
4469
4711
|
var html = steps.map(function(st){
|
|
4470
4712
|
var cls = st.status === "waiting" ? "wait" : (st.status === "running" ? "run" : (st.status === "failed" ? "bad" : "ok"));
|
|
4471
|
-
var sign = cls === "ok" ? "✓" : (cls === "bad" ? "✗" : "");
|
|
4713
|
+
var sign = st.note ? "" : (cls === "ok" ? "✓" : (cls === "bad" ? "✗" : ""));
|
|
4714
|
+
// M4d am15: a line with no ✓/✗ (the Fix line under a red plan check)
|
|
4715
|
+
if(st.note) cls += " note";
|
|
4472
4716
|
return '<li class="step ' + cls + '" data-step="' + escapeXml(st.id) + '"><div class="step-line"><span class="step-label">' + escapeXml(st.label) + '</span>' +
|
|
4473
4717
|
'<span class="step-sign">' + sign + '</span></div>' +
|
|
4474
4718
|
(st.details || []).map(function(d, k){
|
|
@@ -4524,7 +4768,7 @@
|
|
|
4524
4768
|
var v = extrasFor(state);
|
|
4525
4769
|
var html = v ? v.blocks.map(function(b){
|
|
4526
4770
|
return '<div class="msg" id="' + b.id + '" data-testid="' + b.id + '"><b class="readout-head">' + escapeXml(b.head) + '</b>' +
|
|
4527
|
-
(b.sub ? ' <span class="hint">(' + escapeXml(b.sub) + ')</span>' : '') + '\n' + b.lines.map(escapeXml).join("\n") + '</div>';
|
|
4771
|
+
(b.sub ? ' <span class="hint">(' + escapeXml(b.sub) + ')</span>' : '') + (b.lines.length ? '\n' + b.lines.map(escapeXml).join("\n") : '') + '</div>';
|
|
4528
4772
|
}).join("") : "";
|
|
4529
4773
|
if(html !== extrasKey){ extrasKey = html; extrasEl.innerHTML = html; }
|
|
4530
4774
|
}
|
|
@@ -4556,6 +4800,8 @@
|
|
|
4556
4800
|
mainAction = b.action; mainStartOver = !!b.startOver;
|
|
4557
4801
|
// amendment 14 item 3: the count shows while a draft has revises to count; at 0 the way on is Start over
|
|
4558
4802
|
mainHint.textContent = (mode === "new" && sessionLive && st.revisable && st.phase !== "signed" && st.phase !== "questions-open") ? (st.left > 0 ? revisesLeftText(st.left) : "No revises left: Start over keeps the fields and gives 2 new ones.") : "";
|
|
4803
|
+
// M4d am16 item 3: the first Sign click shows how the card's Cap $ is split between drafting and this run, before the second click starts it
|
|
4804
|
+
if(mode === "new" && sessionLive && signInfo && signInfo.split && signClickedOnce) mainHint.textContent = signInfo.split.line;
|
|
4559
4805
|
reviseBtn.hidden = !reviseShownFor(st);
|
|
4560
4806
|
reviseBtn.disabled = !!st.busy;
|
|
4561
4807
|
startOverBtn.hidden = !startOverShownFor(st);
|
|
@@ -4615,6 +4861,8 @@
|
|
|
4615
4861
|
leaveEdit();
|
|
4616
4862
|
["jf-name", "jf-job", "jf-cap-money", "jf-dest-folder", "jf-inputs"].forEach(function(id){ byId(id).value = ""; });
|
|
4617
4863
|
askWaitEl.value = "1h";
|
|
4864
|
+
thinkingEl.checked = false; // per job: unticked for the next one
|
|
4865
|
+
clearPick(); // a flow picked in Run a signed flow (Run again too) goes with the rest
|
|
4618
4866
|
refreshCapNote();
|
|
4619
4867
|
openNewCard();
|
|
4620
4868
|
loadFlows(mode === "run");
|
|
@@ -4808,6 +5056,7 @@
|
|
|
4808
5056
|
resumeCtx = {flow: detail.flow, runId: detail.runId, form: j};
|
|
4809
5057
|
chatActionOk();
|
|
4810
5058
|
paintJobDim(byId("jf-resume-job"), j.jobLines);
|
|
5059
|
+
byId("jf-resume-model").textContent = j.model ? "Model: " + j.model.label : "No model is recorded for this job.";
|
|
4811
5060
|
byId("jf-resume-dest").textContent = j.values.destination || "no send step";
|
|
4812
5061
|
byId("jf-resume-inputs").innerHTML = "";
|
|
4813
5062
|
(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); });
|
|
@@ -4846,7 +5095,7 @@
|
|
|
4846
5095
|
var o = chatPostOutcome(r);
|
|
4847
5096
|
if(!o.ok){ failFrom(r); refreshStartEnabled(); return; }
|
|
4848
5097
|
chatActionOk();
|
|
4849
|
-
signInfo = {hash: r.body.hash, flowName: r.body.flowName, capUsd: r.body.capUsd, runId: r.body.runId};
|
|
5098
|
+
signInfo = {hash: r.body.hash, flowName: r.body.flowName, capUsd: r.body.capUsd, runId: r.body.runId, split: r.body.split || null};
|
|
4850
5099
|
signClickedOnce = true;
|
|
4851
5100
|
if(lastState) renderActions(lastState); else refreshStartEnabled();
|
|
4852
5101
|
}).catch(function(){ busy = false; chatActionFailed(NETWORK_SAY); refreshStartEnabled(); });
|
|
@@ -4909,6 +5158,7 @@
|
|
|
4909
5158
|
openNewCard();
|
|
4910
5159
|
setMode("new");
|
|
4911
5160
|
setVal("jf-name", c.flowName); setVal("jf-job", c.job); setVal("jf-cap-money", c.capUsd);
|
|
5161
|
+
setModelPick(c.provider || "", c.model || ""); thinkingEl.checked = c.thinking === true && !thinkingEl.disabled;
|
|
4912
5162
|
refreshCapNote();
|
|
4913
5163
|
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");
|
|
4914
5164
|
if(c.editOf && typeof c.editOf.flow === "string"){
|
|
@@ -4997,6 +5247,8 @@
|
|
|
4997
5247
|
document.addEventListener("fwdloop-limit-changed", function(){ refreshCapNote(); });
|
|
4998
5248
|
|
|
4999
5249
|
loadModel();
|
|
5250
|
+
document.getElementById("settings-back").addEventListener("click", loadModel); // the menu re-reads after Settings changed what is ticked
|
|
5251
|
+
document.getElementById("tab-chat").addEventListener("click", loadModel);
|
|
5000
5252
|
loadFlows();
|
|
5001
5253
|
reattachLive();
|
|
5002
5254
|
refreshStartEnabled();
|
|
@@ -5039,7 +5291,7 @@
|
|
|
5039
5291
|
var PV_NOTE_DEFAULT = pvNote.textContent;
|
|
5040
5292
|
document.getElementById("settings-open").addEventListener("click", function(){
|
|
5041
5293
|
mainView.hidden = true; settingsView.hidden = false;
|
|
5042
|
-
loadProviders(); loadMoney();
|
|
5294
|
+
loadProviders(true); loadMoney();
|
|
5043
5295
|
});
|
|
5044
5296
|
document.getElementById("settings-back").addEventListener("click", function(){
|
|
5045
5297
|
settingsView.hidden = true; mainView.hidden = false;
|
|
@@ -5048,114 +5300,247 @@
|
|
|
5048
5300
|
document.getElementById("stab-money").addEventListener("click", function(){ loadMoney(); });
|
|
5049
5301
|
document.getElementById("stab-providers").addEventListener("click", function(){ loadProviders(); });
|
|
5050
5302
|
|
|
5051
|
-
|
|
5052
|
-
|
|
5303
|
+
// `list` true = also ask each provider for its model list (free): on page open, on Reload keys. A save repaints without asking again.
|
|
5304
|
+
function loadProviders(list){
|
|
5305
|
+
return getJSON("/api/settings/providers").then(function(d){ paintProviders(d, list === true); }, function(e){
|
|
5053
5306
|
setNote(document.getElementById("keys-refusal"), true, loadFailureText(e));
|
|
5054
5307
|
});
|
|
5055
5308
|
}
|
|
5056
|
-
|
|
5309
|
+
// 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.
|
|
5310
|
+
document.getElementById("open-keys-folder").addEventListener("click", function(){
|
|
5311
|
+
var out = document.getElementById("keys-open-note");
|
|
5312
|
+
out.textContent = "";
|
|
5313
|
+
postJSON("/api/settings/open-keys-folder", {}).then(function(r){
|
|
5314
|
+
var b = r.body || {};
|
|
5315
|
+
if(b.ok === true) out.textContent = b.opened ? "" : "Could not open it here. Your keys folder: " + (b.path || "(unknown)");
|
|
5316
|
+
else out.textContent = settingsRefusal(r);
|
|
5317
|
+
}, function(){ out.textContent = networkText(); });
|
|
5318
|
+
});
|
|
5319
|
+
document.getElementById("reload-keys").addEventListener("click", function(){ loadProviders(true); });
|
|
5057
5320
|
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
}
|
|
5063
|
-
var PRICE_FIELDS = ["inPerM", "outPerM"];
|
|
5064
|
-
// Name, API shape and Base URL are editable (M4d amendment 1), saved on change one field at a time.
|
|
5065
|
-
var PROV_FIELDS = ["name", "shape", "baseUrl"];
|
|
5321
|
+
// 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,
|
|
5322
|
+
// 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
|
|
5323
|
+
// 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).
|
|
5324
|
+
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
|
|
5325
|
+
var typedOpen = {}; // slot -> true while "+ type a model name" is open
|
|
5066
5326
|
function buildProviderRow(row){
|
|
5067
|
-
var
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
'<div class="
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
'
|
|
5080
|
-
'<
|
|
5081
|
-
'<
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5327
|
+
var key = document.createElement("div");
|
|
5328
|
+
key.className = "pv-key";
|
|
5329
|
+
key.setAttribute("data-slot", row.slot);
|
|
5330
|
+
key.setAttribute("data-testid", "provider-row-" + row.slot);
|
|
5331
|
+
key.innerHTML =
|
|
5332
|
+
'<div class="pv-krow">' +
|
|
5333
|
+
'<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>' +
|
|
5334
|
+
'<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>' +
|
|
5335
|
+
'<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>' +
|
|
5336
|
+
'<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>' +
|
|
5337
|
+
'<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>' +
|
|
5338
|
+
'<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>' +
|
|
5339
|
+
'</div>' +
|
|
5340
|
+
'<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>' +
|
|
5341
|
+
'<div class="pv-models" data-models-for="' + escapeXml(row.slot) + '" data-testid="models-row-' + escapeXml(row.slot) + '">' +
|
|
5342
|
+
'<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>' +
|
|
5343
|
+
'<div data-f="models"></div>' +
|
|
5344
|
+
'<div class="pv-more"><button class="pv-add" type="button" data-act="typed-open" data-testid="model-typed-open">+ type a model name</button>' +
|
|
5345
|
+
'<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"> ' +
|
|
5346
|
+
'<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>' +
|
|
5347
|
+
'</div>';
|
|
5348
|
+
key.querySelector("code").textContent = row.envVar;
|
|
5349
|
+
key.querySelectorAll("input").forEach(function(inp){
|
|
5086
5350
|
inp.addEventListener("input", function(){ inp.setAttribute("data-dirty", "1"); });
|
|
5087
5351
|
});
|
|
5088
|
-
|
|
5352
|
+
key.querySelector("select").addEventListener("change", function(ev){ ev.target.setAttribute("data-dirty", "1"); });
|
|
5353
|
+
return key;
|
|
5354
|
+
}
|
|
5355
|
+
// 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.
|
|
5356
|
+
function buildModelLine(slot, m){
|
|
5357
|
+
var d = document.createElement("div");
|
|
5358
|
+
d.className = "pv-mrow";
|
|
5359
|
+
d.setAttribute("data-model", m.model);
|
|
5360
|
+
d.setAttribute("data-testid", "model-line");
|
|
5361
|
+
d.innerHTML =
|
|
5362
|
+
'<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>' +
|
|
5363
|
+
'<div class="pv-cell pv-pair"><label><input type="text" inputmode="decimal" data-mf="inPerM" data-testid="model-in" autocomplete="off"></label>' +
|
|
5364
|
+
'<label><input type="text" inputmode="decimal" data-mf="outPerM" data-testid="model-out" autocomplete="off"></label></div>' +
|
|
5365
|
+
'<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>' +
|
|
5366
|
+
'<div class="hint pv-msg pv-m-msg" data-f="msg-model" data-testid="model-msg"></div>';
|
|
5367
|
+
d.querySelector(".pv-m-name").textContent = m.model;
|
|
5368
|
+
d.querySelector("[data-mf=use]").setAttribute("aria-label", slot + " " + m.model + " use");
|
|
5369
|
+
d.querySelector("[data-mf=inPerM]").setAttribute("aria-label", m.model + " price in per 1M tokens");
|
|
5370
|
+
d.querySelector("[data-mf=outPerM]").setAttribute("aria-label", m.model + " price out per 1M tokens");
|
|
5371
|
+
d.querySelectorAll("input[type=text]").forEach(function(inp){
|
|
5372
|
+
inp.addEventListener("input", function(){ inp.setAttribute("data-dirty", "1"); });
|
|
5373
|
+
});
|
|
5374
|
+
return d;
|
|
5375
|
+
}
|
|
5376
|
+
// 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.
|
|
5377
|
+
var listed = {};
|
|
5378
|
+
var lastData = null;
|
|
5379
|
+
function linesFor(row){
|
|
5380
|
+
var l = listed[row.slot];
|
|
5381
|
+
var have = {};
|
|
5382
|
+
row.models.forEach(function(m){ have[m.model] = true; });
|
|
5383
|
+
var extra = (l && l.models ? l.models : []).filter(function(id){ return !have[id]; }).map(function(id){ return { model: id, use: false }; });
|
|
5384
|
+
return row.models.concat(extra);
|
|
5385
|
+
}
|
|
5386
|
+
// "3 models · none ticked", "2 models · 1 ticked"; a list that failed with nothing saved says so.
|
|
5387
|
+
function sumText(row){
|
|
5388
|
+
var l = listed[row.slot];
|
|
5389
|
+
var lines = linesFor(row);
|
|
5390
|
+
if(l && l.why && lines.length === 0) return "failed — type a name";
|
|
5391
|
+
var ticked = lines.filter(function(m){ return m.use === true; }).length;
|
|
5392
|
+
return lines.length + (lines.length === 1 ? " model" : " models") + " · " + (ticked === 0 ? "none ticked" : ticked + " ticked");
|
|
5393
|
+
}
|
|
5394
|
+
function paintModels(row, mr){
|
|
5395
|
+
var box = mr.querySelector("[data-f=models]");
|
|
5396
|
+
var lines = linesFor(row);
|
|
5397
|
+
var l = listed[row.slot];
|
|
5398
|
+
var typed = mr.querySelector("[data-f=typed]");
|
|
5399
|
+
typed.hidden = typedOpen[row.slot] !== true;
|
|
5400
|
+
var wanted = lines.map(function(m){ return m.model; });
|
|
5401
|
+
Array.prototype.slice.call(box.querySelectorAll(".pv-mrow")).forEach(function(el){
|
|
5402
|
+
if(wanted.indexOf(el.getAttribute("data-model")) < 0) box.removeChild(el);
|
|
5403
|
+
});
|
|
5404
|
+
var note = box.querySelector("[data-f=models-note]");
|
|
5405
|
+
lines.forEach(function(m){
|
|
5406
|
+
var line = Array.prototype.find.call(box.querySelectorAll(".pv-mrow"), function(el){ return el.getAttribute("data-model") === m.model; });
|
|
5407
|
+
if(!line){ line = buildModelLine(row.slot, m); box.insertBefore(line, note); }
|
|
5408
|
+
var use = line.querySelector("[data-mf=use]");
|
|
5409
|
+
use.checked = m.use === true;
|
|
5410
|
+
["inPerM", "outPerM"].forEach(function(f){
|
|
5411
|
+
var inp = line.querySelector('[data-mf="' + f + '"]');
|
|
5412
|
+
inp.placeholder = "—";
|
|
5413
|
+
if(inp.getAttribute("data-dirty") !== "1") inp.value = typeof m[f] === "number" ? String(m[f]) : "";
|
|
5414
|
+
});
|
|
5415
|
+
line.querySelector("[data-f=model-tokens]").textContent = typeof m.tokens === "number" ? tokensText(m.tokens) : "—";
|
|
5416
|
+
});
|
|
5417
|
+
note = box.querySelector("[data-f=models-note]");
|
|
5418
|
+
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); }
|
|
5419
|
+
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." : ""));
|
|
5420
|
+
note.className += " pv-more" + (l && l.why ? " pv-failed" : "");
|
|
5421
|
+
box.parentNode.querySelector(".pv-mhead").hidden = lines.length === 0;
|
|
5089
5422
|
}
|
|
5090
5423
|
var STATUS_WORD = { "set in file": "set in file", "found in shell": "found in shell", "not set": "not set", "refused": "refused — see above" };
|
|
5091
|
-
|
|
5424
|
+
// The Refresh button: "[ ⟳ Refresh ]", disabled "[ ⟳ refreshing… ]" while the free list call is out.
|
|
5425
|
+
function setRefreshBtn(key, pending){
|
|
5426
|
+
var b = key.querySelector("[data-act=refresh-models]");
|
|
5427
|
+
b.disabled = pending === true;
|
|
5428
|
+
b.innerHTML = pending === true ? "⟳ refreshing…" : "⟳ Refresh";
|
|
5429
|
+
}
|
|
5430
|
+
// 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.
|
|
5431
|
+
function testKey(slot, key){
|
|
5432
|
+
var b = key.querySelector("[data-act=test-key]");
|
|
5433
|
+
var msg = key.querySelector("[data-f=msg-test]");
|
|
5434
|
+
var row = lastData && lastData.rows.filter(function(r){ return r.slot === slot; })[0];
|
|
5435
|
+
if(row && row.baseUrl === ""){
|
|
5436
|
+
setNote(msg, true, "Type a Base URL for " + row.envVar + " in Settings.");
|
|
5437
|
+
return;
|
|
5438
|
+
}
|
|
5439
|
+
b.disabled = true;
|
|
5440
|
+
b.innerHTML = "testing…";
|
|
5441
|
+
setNote(msg, false, "");
|
|
5442
|
+
postJSON("/api/settings/test", { slot: slot }).then(function(r){
|
|
5443
|
+
var d = r.body;
|
|
5444
|
+
if(d && d.ok === true) setNote(msg, false, "OK \u00b7 " + d.ms + " ms");
|
|
5445
|
+
else setNote(msg, true, d && d.why ? d.why : settingsRefusal(r));
|
|
5446
|
+
}, function(){ setNote(msg, true, networkText()); }).then(function(){
|
|
5447
|
+
b.disabled = false;
|
|
5448
|
+
b.innerHTML = "Test";
|
|
5449
|
+
});
|
|
5450
|
+
}
|
|
5451
|
+
function refreshModels(slot, tr){
|
|
5452
|
+
listed[slot] = { pending: true };
|
|
5453
|
+
setRefreshBtn(tr, true);
|
|
5454
|
+
return postJSON("/api/settings/models", { slot: slot }).then(function(r){
|
|
5455
|
+
var b = r.body;
|
|
5456
|
+
listed[slot] = b && b.ok ? { models: b.models } : { why: (b && b.why) ? b.why : settingsRefusal(r) };
|
|
5457
|
+
}, function(){ listed[slot] = { why: networkText() }; }).then(function(){
|
|
5458
|
+
if(lastData) paintProviders(lastData, false);
|
|
5459
|
+
});
|
|
5460
|
+
}
|
|
5461
|
+
function paintProviders(data, list){
|
|
5462
|
+
lastData = data;
|
|
5092
5463
|
var path = data.keysFile && data.keysFile.path ? data.keysFile.path : "~/.config/fwdloop/.env";
|
|
5093
5464
|
document.getElementById("keys-path").textContent = path;
|
|
5094
5465
|
setNote(document.getElementById("keys-refusal"), true, data.keysFile && data.keysFile.refusal);
|
|
5095
5466
|
setNote(pvNote, !!data.configProblem, data.configProblem || PV_NOTE_DEFAULT);
|
|
5096
5467
|
data.rows.forEach(function(row){
|
|
5097
|
-
var
|
|
5098
|
-
if(!
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
var
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5468
|
+
var key = pvRows.querySelector('.pv-key[data-slot="' + row.slot + '"]');
|
|
5469
|
+
if(!key){ key = buildProviderRow(row); pvRows.appendChild(key); }
|
|
5470
|
+
if(folds[row.slot] === undefined) folds[row.slot] = row.models.some(function(m){ return m.use === true; });
|
|
5471
|
+
key.setAttribute("data-open", folds[row.slot] ? "1" : "0");
|
|
5472
|
+
var fold = key.querySelector("[data-act=fold]");
|
|
5473
|
+
fold.textContent = folds[row.slot] ? "▾" : "▸";
|
|
5474
|
+
fold.setAttribute("aria-expanded", folds[row.slot] ? "true" : "false");
|
|
5475
|
+
fold.setAttribute("aria-label", (folds[row.slot] ? "Fold " : "Unfold ") + row.label + " models");
|
|
5476
|
+
paintModels(row, key.querySelector(".pv-models"));
|
|
5477
|
+
setRefreshBtn(key, !!(listed[row.slot] && listed[row.slot].pending));
|
|
5478
|
+
key.querySelector("[data-f=sum]").textContent = sumText(row);
|
|
5479
|
+
var st = key.querySelector("[data-f=status]");
|
|
5480
|
+
var word = STATUS_WORD[row.keyStatus] || row.keyStatus;
|
|
5481
|
+
st.className = row.keyStatus === "set in file" || row.keyStatus === "found in shell" ? "pv-status pv-ok" : "pv-status hint";
|
|
5482
|
+
st.textContent = st.className.indexOf("pv-ok") >= 0 ? "✓" : word;
|
|
5483
|
+
st.setAttribute("title", word);
|
|
5484
|
+
if(st.className.indexOf("pv-ok") >= 0) st.setAttribute("aria-label", word); else st.removeAttribute("aria-label");
|
|
5485
|
+
var legacyIn = key.querySelector('[data-prov=legacyMaxTokens]');
|
|
5486
|
+
if(document.activeElement !== legacyIn) legacyIn.checked = row.legacyMaxTokens === true;
|
|
5487
|
+
key.querySelector("[data-f=legacy-word]").textContent = legacyIn.checked ? "on" : "off";
|
|
5488
|
+
// 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)
|
|
5489
|
+
var sel = key.querySelector("[data-prov=shape]");
|
|
5490
|
+
if(sel.options.length !== data.shapes.length || data.shapes.some(function(sh, i){ return sel.options[i].value !== sh.id; })){
|
|
5491
|
+
sel.textContent = "";
|
|
5492
|
+
data.shapes.forEach(function(sh){ var o = document.createElement("option"); o.value = sh.id; o.textContent = sh.label; sel.appendChild(o); });
|
|
5109
5493
|
}
|
|
5110
|
-
|
|
5111
|
-
urlIn
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
var inp = tr.querySelector('input[data-field="' + f + '"]');
|
|
5119
|
-
var pr = row.price[f];
|
|
5120
|
-
inp.placeholder = String(pr.value) + " (" + sourceWord(pr.source) + ")";
|
|
5121
|
-
inp.title = inp.placeholder;
|
|
5122
|
-
// a box the person has typed in is never overwritten by a repaint
|
|
5123
|
-
if(inp.getAttribute("data-dirty") !== "1") inp.value = pr.source === "settings" ? String(pr.value) : "";
|
|
5124
|
-
});
|
|
5494
|
+
if(sel.getAttribute("data-dirty") !== "1") sel.value = row.shape;
|
|
5495
|
+
var urlIn = key.querySelector("[data-prov=baseUrl]");
|
|
5496
|
+
if(urlIn.getAttribute("data-dirty") !== "1" && document.activeElement !== urlIn) urlIn.value = row.baseUrl;
|
|
5497
|
+
key.querySelector("[data-f=tokens]").textContent = tokensText(row.tokens);
|
|
5498
|
+
});
|
|
5499
|
+
// rows that left the keys file leave the page
|
|
5500
|
+
Array.prototype.slice.call(pvRows.querySelectorAll(".pv-key")).forEach(function(key){
|
|
5501
|
+
if(!data.rows.some(function(r){ return r.slot === key.getAttribute("data-slot"); })) pvRows.removeChild(key);
|
|
5125
5502
|
});
|
|
5503
|
+
if(list) data.rows.forEach(function(row){
|
|
5504
|
+
var key = pvRows.querySelector('.pv-key[data-slot="' + row.slot + '"]');
|
|
5505
|
+
if(row.baseUrl === ""){ listed[row.slot] = { why: "Type a Base URL for " + row.slot + " in Settings." }; paintProviders(lastData, false); }
|
|
5506
|
+
else refreshModels(row.slot, key);
|
|
5507
|
+
});
|
|
5508
|
+
}
|
|
5509
|
+
// 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
|
|
5510
|
+
// a refusal (nothing saved, the typed value stays so the person can fix it).
|
|
5511
|
+
function saveEndpoint(key){
|
|
5512
|
+
var msg = key.querySelector("[data-f=msg-edit]");
|
|
5513
|
+
var payload = { slot: key.getAttribute("data-slot"), shape: key.querySelector("[data-prov=shape]").value, baseUrl: key.querySelector("[data-prov=baseUrl]").value.trim() };
|
|
5514
|
+
postJSON("/api/settings/provider", payload).then(function(r){
|
|
5515
|
+
if(r.body && r.body.ok){
|
|
5516
|
+
key.querySelector("[data-prov=shape]").removeAttribute("data-dirty");
|
|
5517
|
+
key.querySelector("[data-prov=baseUrl]").removeAttribute("data-dirty");
|
|
5518
|
+
setNote(msg, true, "");
|
|
5519
|
+
loadProviders();
|
|
5520
|
+
} else setNote(msg, true, settingsRefusal(r));
|
|
5521
|
+
}, function(){ setNote(msg, true, networkText()); });
|
|
5126
5522
|
}
|
|
5127
5523
|
pvRows.addEventListener("click", function(ev){
|
|
5128
5524
|
var b = ev.target.closest && ev.target.closest("button[data-act]");
|
|
5129
5525
|
if(!b) return;
|
|
5130
|
-
var
|
|
5131
|
-
|
|
5132
|
-
|
|
5526
|
+
var key = b.closest(".pv-key");
|
|
5527
|
+
var slot = key.getAttribute("data-slot");
|
|
5528
|
+
var act = b.getAttribute("data-act");
|
|
5529
|
+
if(act === "refresh-models") refreshModels(slot, key);
|
|
5530
|
+
else if(act === "test-key") testKey(slot, key);
|
|
5531
|
+
else if(act === "fold"){ folds[slot] = !folds[slot]; paintProviders(lastData, false); }
|
|
5532
|
+
else if(act === "typed-open"){ typedOpen[slot] = !typedOpen[slot]; paintProviders(lastData, false); }
|
|
5533
|
+
else if(act === "add-model") addTypedModel(slot, b.closest("[data-f=typed]"));
|
|
5133
5534
|
});
|
|
5134
|
-
// Saved like bareloop saves a row field: on change (blur or Enter), no Save button.
|
|
5535
|
+
// 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.
|
|
5135
5536
|
pvRows.addEventListener("change", function(ev){
|
|
5136
5537
|
var inp = ev.target;
|
|
5137
5538
|
if(!inp.getAttribute) return;
|
|
5138
|
-
if(inp.getAttribute("data-prov")){ saveProvider(inp.closest("
|
|
5139
|
-
if(
|
|
5140
|
-
|
|
5539
|
+
if(inp.getAttribute("data-prov") === "legacyMaxTokens"){ saveProvider(inp.closest(".pv-key"), inp); return; }
|
|
5540
|
+
if(inp.getAttribute("data-prov") === "shape" || inp.getAttribute("data-prov") === "baseUrl"){ saveEndpoint(inp.closest(".pv-key")); return; }
|
|
5541
|
+
if(!inp.getAttribute("data-mf")) return;
|
|
5542
|
+
saveModel(inp.closest(".pv-models") ? inp.closest(".pv-models").getAttribute("data-models-for") : "", inp.closest(".pv-mrow"));
|
|
5141
5543
|
});
|
|
5142
|
-
function runTest(tr, slot){
|
|
5143
|
-
var out = tr.querySelector("[data-f=test]");
|
|
5144
|
-
out.textContent = "testing…";
|
|
5145
|
-
postJSON("/api/settings/test", { slot: slot }).then(function(r){
|
|
5146
|
-
var b = r.body;
|
|
5147
|
-
out.textContent = b && b.ok ? "OK · " + b.ms + " ms" : (b && b.why ? b.why : settingsRefusal(r));
|
|
5148
|
-
}, function(){ out.textContent = networkText(); });
|
|
5149
|
-
}
|
|
5150
|
-
// Balance is read on a click, never on render (signed M4d: "read on a click").
|
|
5151
|
-
function runBalance(tr, slot){
|
|
5152
|
-
var out = tr.querySelector("[data-f=balance-result]");
|
|
5153
|
-
out.textContent = "checking…";
|
|
5154
|
-
getJSON("/api/settings/balance?slot=" + encodeURIComponent(slot)).then(function(b){
|
|
5155
|
-
if(b.ok) out.textContent = b.balances.map(function(x){ return x.total + " " + x.currency; }).join(" + ");
|
|
5156
|
-
else out.textContent = b.why || "Could not check the balance.";
|
|
5157
|
-
}, function(e){ out.textContent = loadFailureText(e); });
|
|
5158
|
-
}
|
|
5159
5544
|
// A box the person typed: empty = back to the default (null); a number is sent as a number; anything else is
|
|
5160
5545
|
// sent as the text typed, so the server refuses it by naming the box.
|
|
5161
5546
|
function priceValue(text){
|
|
@@ -5164,25 +5549,42 @@
|
|
|
5164
5549
|
var n = Number(t);
|
|
5165
5550
|
return isFinite(n) ? n : t;
|
|
5166
5551
|
}
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5552
|
+
// One model line per save: {slot, model, use, inPerM, outPerM}. A refusal is the line's hint (the server's one rule),
|
|
5553
|
+
// and nothing was saved: the repaint puts the tick back.
|
|
5554
|
+
function saveModel(slot, line){
|
|
5555
|
+
var msg = line.querySelector("[data-f=msg-model]");
|
|
5556
|
+
var payload = {
|
|
5557
|
+
slot: slot,
|
|
5558
|
+
model: line.getAttribute("data-model"),
|
|
5559
|
+
use: line.querySelector("[data-mf=use]").checked,
|
|
5560
|
+
inPerM: priceValue(line.querySelector("[data-mf=inPerM]").value),
|
|
5561
|
+
outPerM: priceValue(line.querySelector("[data-mf=outPerM]").value)
|
|
5562
|
+
};
|
|
5563
|
+
postJSON("/api/settings/model", payload).then(function(r){
|
|
5172
5564
|
if(r.body && r.body.ok){
|
|
5173
|
-
|
|
5565
|
+
line.querySelectorAll("input[type=text]").forEach(function(inp){ inp.removeAttribute("data-dirty"); });
|
|
5174
5566
|
loadProviders();
|
|
5175
5567
|
setNote(msg, false, "saved — applies from the next model call");
|
|
5176
|
-
} else setNote(msg, true, settingsRefusal(r));
|
|
5568
|
+
} else { setNote(msg, true, settingsRefusal(r)); loadProviders(); }
|
|
5569
|
+
}, function(){ setNote(msg, true, networkText()); });
|
|
5570
|
+
}
|
|
5571
|
+
|
|
5572
|
+
// 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.
|
|
5573
|
+
function addTypedModel(slot, box){
|
|
5574
|
+
var inp = box.querySelector("input");
|
|
5575
|
+
var msg = box.querySelector("[data-f=typed-msg]");
|
|
5576
|
+
postJSON("/api/settings/model", { slot: slot, model: inp.value.trim(), use: false }).then(function(r){
|
|
5577
|
+
if(r.body && r.body.ok){ inp.value = ""; setNote(msg, false, "added"); loadProviders(); }
|
|
5578
|
+
else setNote(msg, true, settingsRefusal(r));
|
|
5177
5579
|
}, function(){ setNote(msg, true, networkText()); });
|
|
5178
5580
|
}
|
|
5179
5581
|
|
|
5180
|
-
//
|
|
5181
|
-
function saveProvider(
|
|
5182
|
-
var
|
|
5183
|
-
var msg =
|
|
5184
|
-
var payload = { slot:
|
|
5185
|
-
payload[
|
|
5582
|
+
// The legacy tick saves alone: {slot, legacyMaxTokens}. A refusal is the cell's hint line.
|
|
5583
|
+
function saveProvider(key, inp){
|
|
5584
|
+
var field = inp.getAttribute("data-prov");
|
|
5585
|
+
var msg = key.querySelector("[data-f=msg-" + field + "]");
|
|
5586
|
+
var payload = { slot: key.getAttribute("data-slot") };
|
|
5587
|
+
payload[field] = inp.checked;
|
|
5186
5588
|
postJSON("/api/settings/provider", payload).then(function(r){
|
|
5187
5589
|
if(r.body && r.body.ok){
|
|
5188
5590
|
inp.removeAttribute("data-dirty");
|