pi-advisor-flow 0.13.1 → 0.13.2
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/CHANGELOG.md +6 -0
- package/dist/index.js +14 -7
- package/extensions/index.ts +6 -0
- package/package.json +9 -9
- package/scripts/check-bun-version.mjs +9 -0
- package/src/attachments.ts +36 -0
- package/src/child-session.ts +1 -0
- package/src/commands/activation-preparation.ts +12 -0
- package/src/commands/activation.ts +43 -0
- package/src/commands/advisor-tools.ts +3 -0
- package/src/commands/lifecycle.ts +15 -0
- package/src/commands/manual-command.ts +19 -0
- package/src/commands/manual-consultation.ts +20 -0
- package/src/commands/manual-progress.ts +13 -0
- package/src/commands/model-commands.ts +4 -0
- package/src/commands/model-options.ts +18 -0
- package/src/commands/model-picker.ts +16 -0
- package/src/commands/outcome-stats.ts +9 -0
- package/src/commands/registration.ts +1 -0
- package/src/commands/renderers.ts +14 -0
- package/src/commands/runtime.ts +5 -0
- package/src/commands/settings-commands.ts +18 -0
- package/src/commands/settings-persistence.ts +2 -0
- package/src/commands.ts +1 -0
- package/src/config/args.ts +7 -0
- package/src/config/defaults.ts +1 -0
- package/src/config/schema.ts +1 -0
- package/src/config/state.ts +64 -1
- package/src/config/storage.ts +37 -0
- package/src/config/types.ts +9 -0
- package/src/config/validation.ts +7 -0
- package/src/config.ts +6 -0
- package/src/content-utils.ts +5 -0
- package/src/conversation.ts +39 -0
- package/src/follow-up.ts +8 -0
- package/src/git.ts +8 -0
- package/src/herdr-block.ts +7 -0
- package/src/herdr-shared.ts +23 -0
- package/src/herdr.ts +18 -0
- package/src/image-attachments.ts +24 -0
- package/src/image-validation.ts +58 -0
- package/src/images.ts +24 -0
- package/src/jev/base-url.ts +14 -0
- package/src/jev/client.ts +49 -0
- package/src/jev/decisions-client.ts +14 -0
- package/src/jev/decisions-response.ts +38 -0
- package/src/jev/endpoint-key-store.ts +18 -0
- package/src/jev/key-store.ts +28 -0
- package/src/jev/ledger.ts +30 -12
- package/src/jev/openai-key-store.ts +17 -0
- package/src/jev/questions.ts +15 -0
- package/src/jev/state.ts +5 -0
- package/src/jev/transport.ts +35 -0
- package/src/model-stream.ts +32 -0
- package/src/outcome-stats.ts +16 -0
- package/src/outcomes.ts +31 -0
- package/src/pi-settings.ts +9 -0
- package/src/preferences.ts +26 -0
- package/src/redaction.ts +8 -0
- package/src/scout-context.ts +17 -0
- package/src/scout-curation.ts +12 -0
- package/src/scout-groups.ts +47 -0
- package/src/scout-protocol.ts +17 -0
- package/src/scout-reconstruct.ts +12 -0
- package/src/scout.ts +47 -0
- package/src/session-context.ts +11 -0
- package/src/session-state.ts +73 -13
- package/src/tool-result-cap.ts +11 -0
- package/src/tools/consult-context.ts +24 -0
- package/src/tools/consultation.ts +43 -0
- package/src/tools/gate-policy.ts +18 -0
- package/src/tools/gate-protocol.ts +22 -0
- package/src/tools/jev-filter.ts +26 -0
- package/src/tools/jev-turn-gate.ts +17 -0
- package/src/tools/loop-gate.ts +25 -0
- package/src/tools/model-access.ts +12 -0
- package/src/tools/outage-notifier.ts +4 -0
- package/src/tools/prompts.ts +17 -0
- package/src/tools/register-ask-advisor.ts +44 -0
- package/src/tools/register-lifecycle.ts +32 -0
- package/src/tools/register-outcome.ts +7 -0
- package/src/tools/register-renderers.ts +14 -0
- package/src/tools/registration.ts +3 -0
- package/src/tools/render-advisor-result.ts +44 -0
- package/src/tools/render-common.ts +10 -0
- package/src/tools/scout-status.ts +34 -0
- package/src/tools/session.ts +3 -0
- package/src/tools.ts +8 -0
- package/src/ui/jev-filter-submenu.ts +21 -0
- package/src/ui/jev-provider-submenu-view.ts +22 -0
- package/src/ui/jev-provider-submenu.ts +81 -0
- package/src/ui/jev-setup-support.ts +26 -0
- package/src/ui/manual-dialog-render.ts +20 -0
- package/src/ui/manual-dialog.ts +38 -0
- package/src/ui/masked-input.ts +2 -0
- package/src/ui/searchable-model-list.ts +28 -0
- package/src/ui/settings-formatting.ts +26 -0
- package/src/ui/settings-items.ts +11 -0
- package/src/ui/settings-list-adapter.ts +13 -0
- package/src/ui/settings-mutations.ts +60 -0
- package/src/ui/settings-selector.ts +30 -0
- package/src/ui/text-setting-submenu.ts +9 -0
- package/src/ui-guard.ts +1 -0
- package/src/ui.ts +3 -0
- package/src/usage.ts +31 -0
|
@@ -43,22 +43,30 @@ const applyModeMutation = (
|
|
|
43
43
|
switch (id) {
|
|
44
44
|
case "advisorToolsEnabled": {
|
|
45
45
|
settings.advisorToolsEnabled = value === "On";
|
|
46
|
+
|
|
46
47
|
if (!settings.advisorToolsEnabled) {
|
|
47
48
|
settings.alwaysOn = false;
|
|
48
49
|
}
|
|
50
|
+
|
|
49
51
|
return true;
|
|
50
52
|
}
|
|
53
|
+
|
|
51
54
|
case "simpleMode": {
|
|
52
55
|
settings.simpleMode = value === "On";
|
|
56
|
+
|
|
53
57
|
return true;
|
|
54
58
|
}
|
|
59
|
+
|
|
55
60
|
case "alwaysOn": {
|
|
56
61
|
settings.alwaysOn = value === "On";
|
|
62
|
+
|
|
57
63
|
if (settings.alwaysOn) {
|
|
58
64
|
settings.advisorToolsEnabled = true;
|
|
59
65
|
}
|
|
66
|
+
|
|
60
67
|
return true;
|
|
61
68
|
}
|
|
69
|
+
|
|
62
70
|
default: {
|
|
63
71
|
return false;
|
|
64
72
|
}
|
|
@@ -76,54 +84,74 @@ const applyCoreMutation = (
|
|
|
76
84
|
settings.contextMaxChars =
|
|
77
85
|
presets.find((preset) => preset.label === value)?.value ??
|
|
78
86
|
settings.contextMaxChars;
|
|
87
|
+
|
|
79
88
|
return true;
|
|
80
89
|
}
|
|
90
|
+
|
|
81
91
|
case "fallbackModel": {
|
|
82
92
|
settings.fallbackModel =
|
|
83
93
|
value === FALLBACK_ADVISOR_MODEL_DISABLED
|
|
84
94
|
? undefined
|
|
85
95
|
: value.trim() || undefined;
|
|
96
|
+
|
|
86
97
|
return true;
|
|
87
98
|
}
|
|
99
|
+
|
|
88
100
|
case "effort": {
|
|
89
101
|
settings.effort = value;
|
|
102
|
+
|
|
90
103
|
return true;
|
|
91
104
|
}
|
|
105
|
+
|
|
92
106
|
case "customRule": {
|
|
93
107
|
settings.customRule = value.trim() || undefined;
|
|
108
|
+
|
|
94
109
|
return true;
|
|
95
110
|
}
|
|
111
|
+
|
|
96
112
|
case "toolPolicies": {
|
|
97
113
|
// SAFETY: the value originates from the settings submenu's previously validated JSON editor.
|
|
98
114
|
settings.toolPolicies = JSON.parse(
|
|
99
115
|
value
|
|
100
116
|
) as AdvisorSettings["toolPolicies"];
|
|
117
|
+
|
|
101
118
|
return true;
|
|
102
119
|
}
|
|
120
|
+
|
|
103
121
|
case "loopThreshold": {
|
|
104
122
|
settings.loopThreshold = Number(
|
|
105
123
|
value.replace("After ", "").replace(" repeats", "")
|
|
106
124
|
);
|
|
125
|
+
|
|
107
126
|
return true;
|
|
108
127
|
}
|
|
128
|
+
|
|
109
129
|
case "maxCallsPerSession": {
|
|
110
130
|
settings.maxCallsPerSession = value === "∞" ? undefined : Number(value);
|
|
131
|
+
|
|
111
132
|
return true;
|
|
112
133
|
}
|
|
134
|
+
|
|
113
135
|
case "modelWhitelist": {
|
|
114
136
|
settings.modelWhitelist = parseModelWhitelist(value);
|
|
137
|
+
|
|
115
138
|
return true;
|
|
116
139
|
}
|
|
140
|
+
|
|
117
141
|
case "failureMode": {
|
|
118
142
|
// SAFETY: value comes from the fixed failureMode options of the settings list.
|
|
119
143
|
settings.failureMode = value as AdvisorSettings["failureMode"];
|
|
144
|
+
|
|
120
145
|
return true;
|
|
121
146
|
}
|
|
147
|
+
|
|
122
148
|
case "gitContext": {
|
|
123
149
|
// SAFETY: value comes from the fixed GitContextLevel options of the settings list.
|
|
124
150
|
settings.gitContext = value as AdvisorSettings["gitContext"];
|
|
151
|
+
|
|
125
152
|
return true;
|
|
126
153
|
}
|
|
154
|
+
|
|
127
155
|
default: {
|
|
128
156
|
return false;
|
|
129
157
|
}
|
|
@@ -138,16 +166,22 @@ const applyNumericMutation = (
|
|
|
138
166
|
switch (id) {
|
|
139
167
|
case "toolResultMaxLines": {
|
|
140
168
|
settings.toolResultMaxLines = Number(value);
|
|
169
|
+
|
|
141
170
|
return true;
|
|
142
171
|
}
|
|
172
|
+
|
|
143
173
|
case "toolResultMaxBytes": {
|
|
144
174
|
settings.toolResultMaxBytes = Number(value);
|
|
175
|
+
|
|
145
176
|
return true;
|
|
146
177
|
}
|
|
178
|
+
|
|
147
179
|
case "gitContextMaxChars": {
|
|
148
180
|
settings.gitContextMaxChars = Number(value);
|
|
181
|
+
|
|
149
182
|
return true;
|
|
150
183
|
}
|
|
184
|
+
|
|
151
185
|
default: {
|
|
152
186
|
return false;
|
|
153
187
|
}
|
|
@@ -162,49 +196,71 @@ const applyJevMutation = (
|
|
|
162
196
|
switch (id) {
|
|
163
197
|
case "jevFilter": {
|
|
164
198
|
settings.jevFilterEnabled = value === "On";
|
|
199
|
+
|
|
165
200
|
return true;
|
|
166
201
|
}
|
|
202
|
+
|
|
167
203
|
case "jevFilterSkipConfidence": {
|
|
168
204
|
settings.jevFilterSkipConfidence = Number(value);
|
|
205
|
+
|
|
169
206
|
return true;
|
|
170
207
|
}
|
|
208
|
+
|
|
171
209
|
case "jevFilterNoulMargin": {
|
|
172
210
|
settings.jevFilterNoulMargin = Number(value);
|
|
211
|
+
|
|
173
212
|
return true;
|
|
174
213
|
}
|
|
214
|
+
|
|
175
215
|
case "jevFilterOverrideWindow": {
|
|
176
216
|
settings.jevFilterOverrideWindow = Number(value.replace(" turns", ""));
|
|
217
|
+
|
|
177
218
|
return true;
|
|
178
219
|
}
|
|
220
|
+
|
|
179
221
|
case "jevTurnGateEveryTurns": {
|
|
180
222
|
settings.jevTurnGateEveryTurns =
|
|
181
223
|
value === "Off" ? 0 : Number(value.replaceAll(/[^0-9]/gu, ""));
|
|
224
|
+
|
|
182
225
|
return true;
|
|
183
226
|
}
|
|
227
|
+
|
|
184
228
|
case "jevTurnGateNoulThreshold": {
|
|
185
229
|
settings.jevTurnGateNoulThreshold = Number(value);
|
|
230
|
+
|
|
186
231
|
return true;
|
|
187
232
|
}
|
|
233
|
+
|
|
188
234
|
case "jevModel": {
|
|
189
235
|
settings.jevModel = value.trim() || DEFAULT_JEV_MODEL;
|
|
236
|
+
|
|
190
237
|
return true;
|
|
191
238
|
}
|
|
239
|
+
|
|
192
240
|
case "jevTimeoutMs": {
|
|
193
241
|
settings.jevTimeoutMs = Number(value);
|
|
242
|
+
|
|
194
243
|
return true;
|
|
195
244
|
}
|
|
245
|
+
|
|
196
246
|
case "scoutTimeoutMs": {
|
|
197
247
|
settings.scoutTimeoutMs = Number(value);
|
|
248
|
+
|
|
198
249
|
return true;
|
|
199
250
|
}
|
|
251
|
+
|
|
200
252
|
case "jevDigestMaxChars": {
|
|
201
253
|
settings.jevDigestMaxChars = Number(value);
|
|
254
|
+
|
|
202
255
|
return true;
|
|
203
256
|
}
|
|
257
|
+
|
|
204
258
|
case "jevPricePerMtok": {
|
|
205
259
|
settings.jevPricePerMtok = Number(value);
|
|
260
|
+
|
|
206
261
|
return true;
|
|
207
262
|
}
|
|
263
|
+
|
|
208
264
|
default: {
|
|
209
265
|
return false;
|
|
210
266
|
}
|
|
@@ -220,15 +276,19 @@ export const mutateAdvisorSettings = (
|
|
|
220
276
|
if (applyModeMutation(settings, id, value)) {
|
|
221
277
|
return;
|
|
222
278
|
}
|
|
279
|
+
|
|
223
280
|
if (applyCoreMutation(settings, id, value, presets)) {
|
|
224
281
|
return;
|
|
225
282
|
}
|
|
283
|
+
|
|
226
284
|
if (applyNumericMutation(settings, id, value)) {
|
|
227
285
|
return;
|
|
228
286
|
}
|
|
287
|
+
|
|
229
288
|
if (applyJevMutation(settings, id, value)) {
|
|
230
289
|
return;
|
|
231
290
|
}
|
|
291
|
+
|
|
232
292
|
if (BOOLEAN_SETTING_IDS.has(id)) {
|
|
233
293
|
// SAFETY: BOOLEAN_SETTING_IDS only contains AdvisorSettings boolean fields.
|
|
234
294
|
settings[id as BooleanSettingField] = value === "On";
|
|
@@ -56,9 +56,11 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
56
56
|
value: configuredContext,
|
|
57
57
|
},
|
|
58
58
|
].toSorted((a, b) => a.value - b.value);
|
|
59
|
+
|
|
59
60
|
if (this.settings.simpleMode) {
|
|
60
61
|
this.startSimpleModeGradient();
|
|
61
62
|
}
|
|
63
|
+
|
|
62
64
|
this.settingsList = this.createSettingsList();
|
|
63
65
|
}
|
|
64
66
|
|
|
@@ -75,6 +77,7 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
75
77
|
"border",
|
|
76
78
|
"─".repeat(Math.max(1, width))
|
|
77
79
|
);
|
|
80
|
+
|
|
78
81
|
return [border, ...this.settingsList.render(width), border].map((line) =>
|
|
79
82
|
truncateToWidth(line, width)
|
|
80
83
|
);
|
|
@@ -88,6 +91,7 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
88
91
|
) {
|
|
89
92
|
this.settingsList.handleInput(keyData);
|
|
90
93
|
}
|
|
94
|
+
|
|
91
95
|
this.options.tui.requestRender();
|
|
92
96
|
}
|
|
93
97
|
|
|
@@ -98,8 +102,10 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
98
102
|
if (this.settings.simpleMode && text.startsWith("Simple mode")) {
|
|
99
103
|
return `${rainbowGradient("Simple mode", this.simpleModeGradientStartedAt ?? 0)}${text.slice("Simple mode".length)}`;
|
|
100
104
|
}
|
|
105
|
+
|
|
101
106
|
return defaultLabel(text, selected);
|
|
102
107
|
};
|
|
108
|
+
|
|
103
109
|
const fallbackModel = advisorFallbackModelItem(
|
|
104
110
|
this.settings,
|
|
105
111
|
this.options.modelRefs,
|
|
@@ -107,6 +113,7 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
107
113
|
this.options.theme,
|
|
108
114
|
this.options.tui
|
|
109
115
|
);
|
|
116
|
+
|
|
110
117
|
const modelWhitelist = advisorModelWhitelistItem(
|
|
111
118
|
this.settings,
|
|
112
119
|
this.options.modelRefs,
|
|
@@ -114,6 +121,7 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
114
121
|
this.options.theme,
|
|
115
122
|
this.options.tui
|
|
116
123
|
);
|
|
124
|
+
|
|
117
125
|
const items = createSettingsItems({
|
|
118
126
|
afterJevSetup: () => {
|
|
119
127
|
this.settingsList = this.createSettingsList("jevFilter");
|
|
@@ -130,6 +138,7 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
130
138
|
theme: this.options.theme,
|
|
131
139
|
tui: this.options.tui,
|
|
132
140
|
});
|
|
141
|
+
|
|
133
142
|
const list = new SettingsList(
|
|
134
143
|
items,
|
|
135
144
|
10,
|
|
@@ -138,10 +147,13 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
138
147
|
this.options.onCancel,
|
|
139
148
|
{ enableSearch: true }
|
|
140
149
|
);
|
|
150
|
+
|
|
141
151
|
const adapter = new SettingsListAdapter(list);
|
|
152
|
+
|
|
142
153
|
if (selectedId) {
|
|
143
154
|
adapter.setSelectedId(items, selectedId);
|
|
144
155
|
}
|
|
156
|
+
|
|
145
157
|
return adapter;
|
|
146
158
|
}
|
|
147
159
|
|
|
@@ -155,29 +167,36 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
155
167
|
showUsageDetails: this.settings.showUsageDetails ?? true,
|
|
156
168
|
toolPolicies: { ...this.settings.toolPolicies },
|
|
157
169
|
};
|
|
170
|
+
|
|
158
171
|
try {
|
|
159
172
|
const result = handler
|
|
160
173
|
? handler(updated)
|
|
161
174
|
: (this.options.onChange ?? this.options.onSave)?.(updated);
|
|
175
|
+
|
|
162
176
|
if (result === false) {
|
|
163
177
|
return false;
|
|
164
178
|
}
|
|
165
179
|
} catch {
|
|
166
180
|
return false;
|
|
167
181
|
}
|
|
182
|
+
|
|
168
183
|
Object.assign(this.settings, updated);
|
|
184
|
+
|
|
169
185
|
return true;
|
|
170
186
|
}
|
|
171
187
|
|
|
172
188
|
private applyJevFilter(selection: JevFilterSelection): boolean {
|
|
173
189
|
const patch = { jevFilterEnabled: selection.enabled };
|
|
174
190
|
const handler = this.options.onJevFilter;
|
|
191
|
+
|
|
175
192
|
if (handler) {
|
|
176
193
|
return this.applyJevSelection(patch, (settings) =>
|
|
177
194
|
handler(selection, settings)
|
|
178
195
|
);
|
|
179
196
|
}
|
|
197
|
+
|
|
180
198
|
const legacy = this.options.onJevSetup;
|
|
199
|
+
|
|
181
200
|
if (legacy) {
|
|
182
201
|
return this.applyJevSelection(patch, (settings) =>
|
|
183
202
|
legacy(
|
|
@@ -189,11 +208,13 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
189
208
|
)
|
|
190
209
|
);
|
|
191
210
|
}
|
|
211
|
+
|
|
192
212
|
return this.applyJevSelection(patch);
|
|
193
213
|
}
|
|
194
214
|
|
|
195
215
|
private applyJevProvider(selection: JevProviderSelection): boolean {
|
|
196
216
|
const custom = selection.transport === "typesafe-compatible";
|
|
217
|
+
|
|
197
218
|
const patch = {
|
|
198
219
|
jevBaseUrl: custom ? selection.baseUrl : this.settings.jevBaseUrl,
|
|
199
220
|
jevKeyProvider: custom
|
|
@@ -201,13 +222,17 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
201
222
|
: this.settings.jevKeyProvider,
|
|
202
223
|
jevTransport: selection.transport,
|
|
203
224
|
};
|
|
225
|
+
|
|
204
226
|
const handler = this.options.onJevProvider;
|
|
227
|
+
|
|
205
228
|
if (handler) {
|
|
206
229
|
return this.applyJevSelection(patch, (settings) =>
|
|
207
230
|
handler(selection, settings)
|
|
208
231
|
);
|
|
209
232
|
}
|
|
233
|
+
|
|
210
234
|
const legacy = this.options.onJevSetup;
|
|
235
|
+
|
|
211
236
|
if (legacy) {
|
|
212
237
|
return this.applyJevSelection(patch, (settings) =>
|
|
213
238
|
legacy(
|
|
@@ -219,6 +244,7 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
219
244
|
)
|
|
220
245
|
);
|
|
221
246
|
}
|
|
247
|
+
|
|
222
248
|
return this.applyJevSelection(patch);
|
|
223
249
|
}
|
|
224
250
|
|
|
@@ -236,11 +262,13 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
236
262
|
clearInterval(this.simpleModeGradientTimer);
|
|
237
263
|
this.simpleModeGradientTimer = undefined;
|
|
238
264
|
}
|
|
265
|
+
|
|
239
266
|
this.simpleModeGradientStartedAt = undefined;
|
|
240
267
|
}
|
|
241
268
|
|
|
242
269
|
private change(id: string, value: string): void {
|
|
243
270
|
mutateAdvisorSettings(this.settings, id, value, this.presets);
|
|
271
|
+
|
|
244
272
|
if (id === "simpleMode") {
|
|
245
273
|
if (this.settings.simpleMode) {
|
|
246
274
|
this.startSimpleModeGradient();
|
|
@@ -248,11 +276,13 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
248
276
|
this.stopSimpleModeGradient();
|
|
249
277
|
}
|
|
250
278
|
}
|
|
279
|
+
|
|
251
280
|
(this.options.onChange ?? this.options.onSave)?.({
|
|
252
281
|
...this.settings,
|
|
253
282
|
showUsageDetails: this.settings.showUsageDetails ?? true,
|
|
254
283
|
toolPolicies: { ...this.settings.toolPolicies },
|
|
255
284
|
});
|
|
285
|
+
|
|
256
286
|
if (
|
|
257
287
|
id === "context" ||
|
|
258
288
|
id === "simpleMode" ||
|
|
@@ -25,14 +25,18 @@ export class TextSettingSubmenu implements Component, Focusable {
|
|
|
25
25
|
this.input.focused = true;
|
|
26
26
|
this.input.onSubmit = (value) => {
|
|
27
27
|
const result = options.onSubmit(value);
|
|
28
|
+
|
|
28
29
|
if (result.error) {
|
|
29
30
|
this.error = result.error;
|
|
30
31
|
options.tui.requestRender();
|
|
32
|
+
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
35
|
+
|
|
33
36
|
this.error = undefined;
|
|
34
37
|
options.onCancel(result.value);
|
|
35
38
|
};
|
|
39
|
+
|
|
36
40
|
this.input.onEscape = () => options.onCancel();
|
|
37
41
|
}
|
|
38
42
|
|
|
@@ -43,6 +47,7 @@ export class TextSettingSubmenu implements Component, Focusable {
|
|
|
43
47
|
render(width: number): string[] {
|
|
44
48
|
const { theme } = this.options;
|
|
45
49
|
const input = this.input.render(Math.max(10, width - 4))[0] || "";
|
|
50
|
+
|
|
46
51
|
const lines = [
|
|
47
52
|
theme.fg("accent", theme.bold(` ${this.options.title}`)),
|
|
48
53
|
"",
|
|
@@ -50,16 +55,20 @@ export class TextSettingSubmenu implements Component, Focusable {
|
|
|
50
55
|
"",
|
|
51
56
|
` ${input}`,
|
|
52
57
|
];
|
|
58
|
+
|
|
53
59
|
if (this.error) {
|
|
54
60
|
lines.push(theme.fg("error", ` ${this.error}`));
|
|
55
61
|
}
|
|
62
|
+
|
|
56
63
|
lines.push("", theme.fg("dim", " Enter: apply · Esc: cancel"));
|
|
64
|
+
|
|
57
65
|
return lines.map((line) => truncateToWidth(line, width));
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
handleInput(keyData: string): void {
|
|
61
69
|
const before = this.input.getValue();
|
|
62
70
|
this.input.handleInput(keyData);
|
|
71
|
+
|
|
63
72
|
// A failed submit leaves the error visible; the first value change clears it.
|
|
64
73
|
if (this.error && this.input.getValue() !== before) {
|
|
65
74
|
this.error = undefined;
|
package/src/ui-guard.ts
CHANGED
package/src/ui.ts
CHANGED
package/src/usage.ts
CHANGED
|
@@ -38,6 +38,7 @@ const hasPartialProviderCost = (
|
|
|
38
38
|
usage: RecordValue
|
|
39
39
|
) => {
|
|
40
40
|
const cost = isRecordOf(usage.cost) ? usage.cost : undefined;
|
|
41
|
+
|
|
41
42
|
return (
|
|
42
43
|
cost !== undefined &&
|
|
43
44
|
snapshot.cost === undefined &&
|
|
@@ -52,7 +53,9 @@ export const snapshotAdvisorUsage = <Input>(
|
|
|
52
53
|
if (!isRecordOf(usage)) {
|
|
53
54
|
return undefined;
|
|
54
55
|
}
|
|
56
|
+
|
|
55
57
|
const cost = isRecordOf(usage.cost) ? usage.cost : undefined;
|
|
58
|
+
|
|
56
59
|
const snapshot = {
|
|
57
60
|
cacheRead: finite(usage.cacheRead),
|
|
58
61
|
cacheWrite: finite(usage.cacheWrite),
|
|
@@ -61,9 +64,11 @@ export const snapshotAdvisorUsage = <Input>(
|
|
|
61
64
|
output: finite(usage.output),
|
|
62
65
|
totalTokens: finite(usage.totalTokens),
|
|
63
66
|
} satisfies AdvisorUsageSnapshot;
|
|
67
|
+
|
|
64
68
|
const hasCostField = costFields.some(
|
|
65
69
|
(field) => finite(cost?.[field]) !== undefined
|
|
66
70
|
);
|
|
71
|
+
|
|
67
72
|
return Object.values(snapshot).some((value) => value !== undefined) ||
|
|
68
73
|
hasCostField
|
|
69
74
|
? snapshot
|
|
@@ -78,12 +83,15 @@ const completeUsageSnapshot = <Input>(
|
|
|
78
83
|
usage: Input
|
|
79
84
|
): { snapshot: AdvisorUsageSnapshot; usage: RecordValue } | undefined => {
|
|
80
85
|
const snapshot = snapshotAdvisorUsage(usage);
|
|
86
|
+
|
|
81
87
|
if (!(snapshot && isRecordOf(usage))) {
|
|
82
88
|
return;
|
|
83
89
|
}
|
|
90
|
+
|
|
84
91
|
if (hasPartialProviderCost(snapshot, usage)) {
|
|
85
92
|
return;
|
|
86
93
|
}
|
|
94
|
+
|
|
87
95
|
return { snapshot, usage };
|
|
88
96
|
};
|
|
89
97
|
|
|
@@ -94,19 +102,24 @@ const completeUsageSnapshot = <Input>(
|
|
|
94
102
|
*/
|
|
95
103
|
export const advisorUsageForPi = <Input>(usage: Input): Usage | undefined => {
|
|
96
104
|
const complete = completeUsageSnapshot(usage);
|
|
105
|
+
|
|
97
106
|
if (!complete) {
|
|
98
107
|
return undefined;
|
|
99
108
|
}
|
|
109
|
+
|
|
100
110
|
const { snapshot } = complete;
|
|
111
|
+
|
|
101
112
|
const cost = isRecordOf(complete.usage.cost)
|
|
102
113
|
? complete.usage.cost
|
|
103
114
|
: undefined;
|
|
115
|
+
|
|
104
116
|
const input = snapshot.input ?? 0;
|
|
105
117
|
const output = snapshot.output ?? 0;
|
|
106
118
|
const cacheRead = snapshot.cacheRead ?? 0;
|
|
107
119
|
const cacheWrite = snapshot.cacheWrite ?? 0;
|
|
108
120
|
const cacheWrite1h = finite(complete.usage.cacheWrite1h);
|
|
109
121
|
const reasoning = finite(complete.usage.reasoning);
|
|
122
|
+
|
|
110
123
|
const piUsage: Usage = {
|
|
111
124
|
cacheRead,
|
|
112
125
|
cacheWrite,
|
|
@@ -122,12 +135,15 @@ export const advisorUsageForPi = <Input>(usage: Input): Usage | undefined => {
|
|
|
122
135
|
totalTokens:
|
|
123
136
|
snapshot.totalTokens ?? input + output + cacheRead + cacheWrite,
|
|
124
137
|
};
|
|
138
|
+
|
|
125
139
|
if (cacheWrite1h !== undefined) {
|
|
126
140
|
piUsage.cacheWrite1h = cacheWrite1h;
|
|
127
141
|
}
|
|
142
|
+
|
|
128
143
|
if (reasoning !== undefined) {
|
|
129
144
|
piUsage.reasoning = reasoning;
|
|
130
145
|
}
|
|
146
|
+
|
|
131
147
|
return piUsage;
|
|
132
148
|
};
|
|
133
149
|
|
|
@@ -145,15 +161,18 @@ export const addAdvisorUsage = <Input>(
|
|
|
145
161
|
) => {
|
|
146
162
|
totals.calls += 1;
|
|
147
163
|
const snapshot = snapshotAdvisorUsage(usage);
|
|
164
|
+
|
|
148
165
|
if (!snapshot) {
|
|
149
166
|
return;
|
|
150
167
|
}
|
|
168
|
+
|
|
151
169
|
totals.knownCalls += 1;
|
|
152
170
|
totals.cacheRead = add(totals.cacheRead, snapshot.cacheRead);
|
|
153
171
|
totals.cacheWrite = add(totals.cacheWrite, snapshot.cacheWrite);
|
|
154
172
|
totals.input = add(totals.input, snapshot.input);
|
|
155
173
|
totals.output = add(totals.output, snapshot.output);
|
|
156
174
|
totals.totalTokens = add(totals.totalTokens, snapshot.totalTokens);
|
|
175
|
+
|
|
157
176
|
if (snapshot.cost !== undefined) {
|
|
158
177
|
totals.cost = add(totals.cost, snapshot.cost);
|
|
159
178
|
totals.costCalls += 1;
|
|
@@ -164,15 +183,19 @@ export const formatTokenCount = (value: number) => {
|
|
|
164
183
|
if (value < 1000) {
|
|
165
184
|
return String(value);
|
|
166
185
|
}
|
|
186
|
+
|
|
167
187
|
if (value < 10_000) {
|
|
168
188
|
return `${(value / 1000).toFixed(1)}k`;
|
|
169
189
|
}
|
|
190
|
+
|
|
170
191
|
if (value < 1_000_000) {
|
|
171
192
|
return `${Math.round(value / 1000)}k`;
|
|
172
193
|
}
|
|
194
|
+
|
|
173
195
|
if (value < 10_000_000) {
|
|
174
196
|
return `${(value / 1_000_000).toFixed(1)}M`;
|
|
175
197
|
}
|
|
198
|
+
|
|
176
199
|
return `${Math.round(value / 1_000_000)}M`;
|
|
177
200
|
};
|
|
178
201
|
|
|
@@ -191,17 +214,21 @@ const formatUsageFields = (usage: AdvisorUsageSnapshot): string | undefined => {
|
|
|
191
214
|
? undefined
|
|
192
215
|
: `cw:${formatTokens(usage.cacheWrite)}`,
|
|
193
216
|
].filter((value): value is string => value !== undefined);
|
|
217
|
+
|
|
194
218
|
if (tokens.length === 0 && usage.totalTokens !== undefined) {
|
|
195
219
|
tokens.push(`tokens:${formatTokens(usage.totalTokens)}`);
|
|
196
220
|
}
|
|
221
|
+
|
|
197
222
|
if (usage.cost !== undefined) {
|
|
198
223
|
tokens.push(formatCost(usage.cost));
|
|
199
224
|
}
|
|
225
|
+
|
|
200
226
|
return tokens.join(" · ") || undefined;
|
|
201
227
|
};
|
|
202
228
|
|
|
203
229
|
export const formatAdvisorUsage = <Input>(usage: Input): string | undefined => {
|
|
204
230
|
const snapshot = snapshotAdvisorUsage(usage);
|
|
231
|
+
|
|
205
232
|
return snapshot ? formatUsageFields(snapshot) : undefined;
|
|
206
233
|
};
|
|
207
234
|
|
|
@@ -210,10 +237,12 @@ export const formatAdvisorUsageTotals = (
|
|
|
210
237
|
): string => {
|
|
211
238
|
const usage = formatUsageFields(totals);
|
|
212
239
|
const missing = totals.calls - totals.knownCalls;
|
|
240
|
+
|
|
213
241
|
const parts = [
|
|
214
242
|
usage,
|
|
215
243
|
missing > 0 ? `${missing} without usage data` : undefined,
|
|
216
244
|
];
|
|
245
|
+
|
|
217
246
|
return (
|
|
218
247
|
parts.filter((value): value is string => value !== undefined).join(" · ") ||
|
|
219
248
|
"unavailable"
|
|
@@ -226,6 +255,8 @@ export const formatAdvisorUsageStatus = (
|
|
|
226
255
|
if (totals.calls === 0) {
|
|
227
256
|
return undefined;
|
|
228
257
|
}
|
|
258
|
+
|
|
229
259
|
const label = `Advisor: ${totals.calls} call${totals.calls === 1 ? "" : "s"}`;
|
|
260
|
+
|
|
230
261
|
return `${label} · ${formatAdvisorUsageTotals(totals)}`;
|
|
231
262
|
};
|