pi-advisor-flow 0.12.1-dev.1 → 0.12.1-dev.3
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 +7 -0
- package/README.md +2 -2
- package/dist/index.js +945 -251
- package/package.json +8 -5
- package/scripts/check-bun-version.mjs +67 -0
- package/src/commands/settings-commands.ts +35 -33
- package/src/commands/settings-persistence.ts +4 -0
- package/src/config/defaults.ts +10 -0
- package/src/config/schema.ts +27 -1
- package/src/config/state.ts +10 -0
- package/src/config/types.ts +5 -1
- package/src/config/validation.ts +24 -71
- package/src/herdr-shared.ts +137 -7
- package/src/jev/base-url.ts +68 -0
- package/src/jev/client.ts +23 -5
- package/src/jev/endpoint-key-store.ts +177 -0
- package/src/jev/transport.ts +88 -3
- package/src/ui/jev-filter-submenu.ts +165 -0
- package/src/ui/jev-provider-submenu-view.ts +137 -0
- package/src/ui/{jev-setup-submenu.ts → jev-provider-submenu.ts} +214 -144
- package/src/ui/jev-setup-support.ts +92 -29
- package/src/ui/settings-items.ts +57 -10
- package/src/ui/settings-selector.ts +65 -7
- package/src/ui/types.ts +31 -2
- package/src/ui/jev-setup-submenu-view.ts +0 -96
|
@@ -4,6 +4,10 @@ import { noul } from "@typesafe-ai/sdk";
|
|
|
4
4
|
import type { JevTransport } from "../config/types.ts";
|
|
5
5
|
import { jevClientFromCredentials } from "../jev/client.ts";
|
|
6
6
|
import { OPENAI_DECISIONS_MODEL } from "../jev/decisions-client.ts";
|
|
7
|
+
import {
|
|
8
|
+
clearJevEndpointKey,
|
|
9
|
+
writeJevEndpointKey,
|
|
10
|
+
} from "../jev/endpoint-key-store.ts";
|
|
7
11
|
import {
|
|
8
12
|
clearKeyTypeSafeKey,
|
|
9
13
|
removeTypeSafeKeyFromAdvisorJson,
|
|
@@ -16,46 +20,54 @@ import {
|
|
|
16
20
|
import {
|
|
17
21
|
resolveJevTransport,
|
|
18
22
|
resolveJevTransportFor,
|
|
23
|
+
resolveTypesafeCompatibleCredentials,
|
|
19
24
|
} from "../jev/transport.ts";
|
|
20
25
|
import type { JevCredentials, JevTransportKind } from "../jev/transport.ts";
|
|
21
26
|
import { redactSecrets } from "../redaction.ts";
|
|
22
27
|
import type {
|
|
28
|
+
JevProviderSelection,
|
|
23
29
|
JevSetupDeps,
|
|
24
|
-
JevSetupSelection,
|
|
25
30
|
RenderRequester,
|
|
26
31
|
} from "./types.ts";
|
|
27
32
|
|
|
28
|
-
export
|
|
33
|
+
export type JevProviderMode =
|
|
34
|
+
| "menu"
|
|
35
|
+
| "base-url"
|
|
36
|
+
| "provider-id"
|
|
37
|
+
| "resolving"
|
|
38
|
+
| "verifying"
|
|
39
|
+
| "clearing"
|
|
40
|
+
| "key-entry";
|
|
41
|
+
|
|
42
|
+
export type JevProviderAction =
|
|
43
|
+
| JevTransportKind
|
|
44
|
+
| "clear-stored-key"
|
|
45
|
+
| "done"
|
|
46
|
+
| "enter-key"
|
|
47
|
+
| "reuse-provider-login";
|
|
48
|
+
|
|
49
|
+
export interface JevProviderSubmenuOptions {
|
|
29
50
|
afterSelection?: () => void;
|
|
51
|
+
currentBaseUrl?: string;
|
|
52
|
+
currentKeyProvider?: string;
|
|
30
53
|
currentTransport: JevTransport;
|
|
31
54
|
currentValue: string;
|
|
32
55
|
done: (selectedValue?: string) => void;
|
|
33
|
-
onSelection?: (selection:
|
|
56
|
+
onSelection?: (selection: JevProviderSelection) => boolean;
|
|
34
57
|
setupDeps?: JevSetupDeps;
|
|
35
58
|
theme: Theme;
|
|
36
59
|
tui: RenderRequester;
|
|
37
60
|
}
|
|
38
61
|
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
| "menu"
|
|
42
|
-
| "key-entry"
|
|
43
|
-
| "resolving"
|
|
44
|
-
| "verifying"
|
|
45
|
-
| "clearing";
|
|
46
|
-
export type SetupAction =
|
|
47
|
-
| JevTransportKind
|
|
48
|
-
| "clear-stored-key"
|
|
49
|
-
| "disable"
|
|
50
|
-
| "done"
|
|
51
|
-
| "enter-key";
|
|
52
|
-
|
|
53
|
-
export interface JevSetupViewState {
|
|
62
|
+
export interface JevProviderViewState {
|
|
63
|
+
baseUrl?: string;
|
|
54
64
|
canEnterKey: boolean;
|
|
65
|
+
canReuseProviderLogin: boolean;
|
|
55
66
|
credentials: JevCredentials | undefined;
|
|
56
|
-
|
|
57
|
-
mode:
|
|
67
|
+
inputError: string | undefined;
|
|
68
|
+
mode: JevProviderMode;
|
|
58
69
|
notice: string | undefined;
|
|
70
|
+
providerId?: string;
|
|
59
71
|
selectedIndex: number;
|
|
60
72
|
selectedTransport: JevTransportKind | undefined;
|
|
61
73
|
}
|
|
@@ -79,13 +91,36 @@ export const providerName = (transport: JevTransportKind): string => {
|
|
|
79
91
|
if (transport === "openrouter") {
|
|
80
92
|
return "OpenRouter (Pi login)";
|
|
81
93
|
}
|
|
94
|
+
if (transport === "typesafe-compatible") {
|
|
95
|
+
return "System One–compatible endpoint";
|
|
96
|
+
}
|
|
82
97
|
return `OpenAI Decisions (${OPENAI_DECISIONS_MODEL})`;
|
|
83
98
|
};
|
|
84
99
|
|
|
100
|
+
const endpointSourceLabel = (source: JevCredentials["source"]): string => {
|
|
101
|
+
switch (source) {
|
|
102
|
+
case "provider-credential": {
|
|
103
|
+
return "Pi provider login";
|
|
104
|
+
}
|
|
105
|
+
case "jev-bun-secrets": {
|
|
106
|
+
return "Bun.secrets";
|
|
107
|
+
}
|
|
108
|
+
case "jev-file": {
|
|
109
|
+
return "stored file, mode 0600";
|
|
110
|
+
}
|
|
111
|
+
default: {
|
|
112
|
+
return "JEV_API_KEY";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
85
117
|
export const transportLabel = (credentials: JevCredentials): string => {
|
|
86
118
|
if (credentials.transport === "openrouter") {
|
|
87
119
|
return "OpenRouter (reusing Pi login)";
|
|
88
120
|
}
|
|
121
|
+
if (credentials.transport === "typesafe-compatible") {
|
|
122
|
+
return `System One–compatible (${credentials.baseUrl ?? "no Base URL"}; key: ${endpointSourceLabel(credentials.source)})`;
|
|
123
|
+
}
|
|
89
124
|
if (credentials.transport === "openai-decisions") {
|
|
90
125
|
let source = "verified API key";
|
|
91
126
|
switch (credentials.source) {
|
|
@@ -131,14 +166,27 @@ export const canClearCredential = (credentials: JevCredentials) =>
|
|
|
131
166
|
credentials.source === "bun-secrets" ||
|
|
132
167
|
credentials.source === "file" ||
|
|
133
168
|
credentials.source === "openai-bun-secrets" ||
|
|
134
|
-
credentials.source === "openai-file"
|
|
169
|
+
credentials.source === "openai-file" ||
|
|
170
|
+
credentials.source === "jev-bun-secrets" ||
|
|
171
|
+
credentials.source === "jev-file";
|
|
135
172
|
|
|
136
173
|
export const canReplaceWithEnteredKey = (credentials: JevCredentials) =>
|
|
137
174
|
credentials.transport === "typesafe" ||
|
|
175
|
+
credentials.transport === "typesafe-compatible" ||
|
|
138
176
|
(credentials.transport === "openai-decisions" &&
|
|
139
177
|
(credentials.source === "openai-bun-secrets" ||
|
|
140
178
|
credentials.source === "openai-file"));
|
|
141
179
|
|
|
180
|
+
export const keyEntryPrompt = (transport: JevTransportKind): string => {
|
|
181
|
+
if (transport === "openai-decisions") {
|
|
182
|
+
return "Paste an OpenAI Platform API key";
|
|
183
|
+
}
|
|
184
|
+
if (transport === "typesafe-compatible") {
|
|
185
|
+
return "Paste the endpoint API key";
|
|
186
|
+
}
|
|
187
|
+
return "Paste a TypeSafe API key";
|
|
188
|
+
};
|
|
189
|
+
|
|
142
190
|
export const defaultVerify = async (credentials: JevCredentials) => {
|
|
143
191
|
const client = jevClientFromCredentials(credentials);
|
|
144
192
|
try {
|
|
@@ -155,19 +203,34 @@ export const defaultVerify = async (credentials: JevCredentials) => {
|
|
|
155
203
|
}
|
|
156
204
|
};
|
|
157
205
|
|
|
206
|
+
const writeKeyFor = (key: string, transport: JevTransportKind) => {
|
|
207
|
+
if (transport === "openai-decisions") {
|
|
208
|
+
return writeOpenAIDecisionsKey(key);
|
|
209
|
+
}
|
|
210
|
+
if (transport === "typesafe-compatible") {
|
|
211
|
+
return writeJevEndpointKey(key);
|
|
212
|
+
}
|
|
213
|
+
return writeKeyTypeSafeKey(key);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const clearKeyFor = (transport: JevTransportKind) => {
|
|
217
|
+
if (transport === "openai-decisions") {
|
|
218
|
+
return clearOpenAIDecisionsKey();
|
|
219
|
+
}
|
|
220
|
+
if (transport === "typesafe-compatible") {
|
|
221
|
+
return clearJevEndpointKey();
|
|
222
|
+
}
|
|
223
|
+
return clearKeyTypeSafeKey();
|
|
224
|
+
};
|
|
225
|
+
|
|
158
226
|
export const defaultSetupDeps: Required<JevSetupDeps> = {
|
|
159
|
-
clearStoredKey: (transport) =>
|
|
160
|
-
transport === "openai-decisions"
|
|
161
|
-
? clearOpenAIDecisionsKey()
|
|
162
|
-
: clearKeyTypeSafeKey(),
|
|
227
|
+
clearStoredKey: (transport) => clearKeyFor(transport),
|
|
163
228
|
removePlaintextKey: removeTypeSafeKeyFromAdvisorJson,
|
|
229
|
+
resolveEndpoint: (options) => resolveTypesafeCompatibleCredentials(options),
|
|
164
230
|
resolveTransport: (transport) =>
|
|
165
231
|
transport ? resolveJevTransportFor(transport) : resolveJevTransport(),
|
|
166
232
|
verify: defaultVerify,
|
|
167
|
-
writeKey: (key, transport) =>
|
|
168
|
-
transport === "openai-decisions"
|
|
169
|
-
? writeOpenAIDecisionsKey(key)
|
|
170
|
-
: writeKeyTypeSafeKey(key),
|
|
233
|
+
writeKey: (key, transport) => writeKeyFor(key, transport),
|
|
171
234
|
};
|
|
172
235
|
|
|
173
236
|
export { consumePlaintextKeyWarning as consumeSetupPlaintextWarning } from "../jev/key-store.ts";
|
package/src/ui/settings-items.ts
CHANGED
|
@@ -15,7 +15,9 @@ import {
|
|
|
15
15
|
DEFAULT_SCOUT_TIMEOUT_MS,
|
|
16
16
|
} from "../config/types.ts";
|
|
17
17
|
import { isValidAdvisorToolPolicies } from "../config/validation.ts";
|
|
18
|
-
import {
|
|
18
|
+
import { JevFilterSubmenu } from "./jev-filter-submenu.ts";
|
|
19
|
+
import { JevProviderSubmenu } from "./jev-provider-submenu.ts";
|
|
20
|
+
import { providerName } from "./jev-setup-support.ts";
|
|
19
21
|
import { SearchableModelMultiSelector } from "./model-multi-selector.ts";
|
|
20
22
|
import { SearchableModelSelector } from "./model-selector.ts";
|
|
21
23
|
import {
|
|
@@ -33,8 +35,9 @@ import { FALLBACK_ADVISOR_MODEL_DISABLED } from "./types.ts";
|
|
|
33
35
|
import type {
|
|
34
36
|
AdvisorSettings,
|
|
35
37
|
ContextPreset,
|
|
38
|
+
JevFilterSelection,
|
|
39
|
+
JevProviderSelection,
|
|
36
40
|
JevSetupDeps,
|
|
37
|
-
JevSetupSelection,
|
|
38
41
|
RenderRequester,
|
|
39
42
|
} from "./types.ts";
|
|
40
43
|
|
|
@@ -46,7 +49,8 @@ export interface SettingsItemsOptions {
|
|
|
46
49
|
settings: AdvisorSettings;
|
|
47
50
|
afterJevSetup?: () => void;
|
|
48
51
|
jevSetupDeps?: JevSetupDeps;
|
|
49
|
-
|
|
52
|
+
onJevFilter?: (selection: JevFilterSelection) => boolean;
|
|
53
|
+
onJevProvider?: (selection: JevProviderSelection) => boolean;
|
|
50
54
|
theme: Theme;
|
|
51
55
|
tui: RenderRequester;
|
|
52
56
|
}
|
|
@@ -80,27 +84,61 @@ const scoutTimeoutItem = (settings: AdvisorSettings): SettingItem => {
|
|
|
80
84
|
};
|
|
81
85
|
};
|
|
82
86
|
|
|
87
|
+
const jevProviderLabel = (settings: AdvisorSettings): string => {
|
|
88
|
+
const transport = settings.jevTransport ?? DEFAULT_JEV_TRANSPORT;
|
|
89
|
+
if (transport === "auto") {
|
|
90
|
+
return "Auto (TypeSafe → OpenRouter)";
|
|
91
|
+
}
|
|
92
|
+
if (transport === "typesafe-compatible") {
|
|
93
|
+
const baseUrl = settings.jevBaseUrl ?? "no Base URL";
|
|
94
|
+
return settings.jevKeyProvider
|
|
95
|
+
? `System One–compatible (${baseUrl}; Pi login "${settings.jevKeyProvider}")`
|
|
96
|
+
: `System One–compatible (${baseUrl})`;
|
|
97
|
+
}
|
|
98
|
+
return providerName(transport);
|
|
99
|
+
};
|
|
100
|
+
|
|
83
101
|
const jevItems = (
|
|
84
102
|
settings: AdvisorSettings,
|
|
85
103
|
theme: Theme,
|
|
86
104
|
tui: RenderRequester,
|
|
87
105
|
jevSetupDeps?: JevSetupDeps,
|
|
88
|
-
|
|
106
|
+
onJevFilter?: (selection: JevFilterSelection) => boolean,
|
|
107
|
+
onJevProvider?: (selection: JevProviderSelection) => boolean,
|
|
89
108
|
afterJevSetup?: () => void
|
|
90
109
|
): SettingItem[] => [
|
|
110
|
+
{
|
|
111
|
+
currentValue: jevProviderLabel(settings),
|
|
112
|
+
description:
|
|
113
|
+
"Provider used for screening and the turn gate. Credentials are live-verified before a provider is saved.",
|
|
114
|
+
id: "jevProvider",
|
|
115
|
+
label: "Jev provider",
|
|
116
|
+
submenu: (currentValue, done) =>
|
|
117
|
+
new JevProviderSubmenu({
|
|
118
|
+
afterSelection: afterJevSetup,
|
|
119
|
+
currentBaseUrl: settings.jevBaseUrl,
|
|
120
|
+
currentKeyProvider: settings.jevKeyProvider,
|
|
121
|
+
currentTransport: settings.jevTransport ?? DEFAULT_JEV_TRANSPORT,
|
|
122
|
+
currentValue,
|
|
123
|
+
done,
|
|
124
|
+
onSelection: onJevProvider,
|
|
125
|
+
setupDeps: jevSetupDeps,
|
|
126
|
+
theme,
|
|
127
|
+
tui,
|
|
128
|
+
}),
|
|
129
|
+
},
|
|
91
130
|
{
|
|
92
131
|
currentValue: settingValue(settings.jevFilterEnabled, false),
|
|
93
132
|
description:
|
|
94
|
-
"Screen low-stakes ask_advisor consultations with
|
|
133
|
+
"Screen low-stakes ask_advisor consultations with the selected Jev provider.",
|
|
95
134
|
id: "jevFilter",
|
|
96
135
|
label: "Jev/Decisions consultation filter",
|
|
97
136
|
submenu: (currentValue, done) =>
|
|
98
|
-
new
|
|
99
|
-
afterSelection: afterJevSetup,
|
|
137
|
+
new JevFilterSubmenu({
|
|
100
138
|
currentTransport: settings.jevTransport ?? DEFAULT_JEV_TRANSPORT,
|
|
101
139
|
currentValue,
|
|
102
140
|
done,
|
|
103
|
-
onSelection:
|
|
141
|
+
onSelection: onJevFilter,
|
|
104
142
|
setupDeps: jevSetupDeps,
|
|
105
143
|
theme,
|
|
106
144
|
tui,
|
|
@@ -297,7 +335,8 @@ export const createSettingsItems = ({
|
|
|
297
335
|
settings,
|
|
298
336
|
afterJevSetup,
|
|
299
337
|
jevSetupDeps,
|
|
300
|
-
|
|
338
|
+
onJevFilter,
|
|
339
|
+
onJevProvider,
|
|
301
340
|
theme,
|
|
302
341
|
tui,
|
|
303
342
|
}: SettingsItemsOptions): SettingItem[] => {
|
|
@@ -599,7 +638,15 @@ export const createSettingsItems = ({
|
|
|
599
638
|
settings.outcomeLogging,
|
|
600
639
|
false
|
|
601
640
|
),
|
|
602
|
-
...jevItems(
|
|
641
|
+
...jevItems(
|
|
642
|
+
settings,
|
|
643
|
+
theme,
|
|
644
|
+
tui,
|
|
645
|
+
jevSetupDeps,
|
|
646
|
+
onJevFilter,
|
|
647
|
+
onJevProvider,
|
|
648
|
+
afterJevSetup
|
|
649
|
+
)
|
|
603
650
|
);
|
|
604
651
|
return items;
|
|
605
652
|
};
|
|
@@ -2,6 +2,7 @@ import { getSettingsListTheme } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
import { SettingsList, truncateToWidth } from "@earendil-works/pi-tui";
|
|
3
3
|
import type { Component, Focusable } from "@earendil-works/pi-tui";
|
|
4
4
|
|
|
5
|
+
import { DEFAULT_JEV_TRANSPORT } from "../config/types.ts";
|
|
5
6
|
import {
|
|
6
7
|
rainbowGradient,
|
|
7
8
|
SIMPLE_MODE_GRADIENT_INTERVAL_MS,
|
|
@@ -17,7 +18,8 @@ import type {
|
|
|
17
18
|
AdvisorSettings,
|
|
18
19
|
AdvisorSettingsSelectorOptions,
|
|
19
20
|
ContextPreset,
|
|
20
|
-
|
|
21
|
+
JevFilterSelection,
|
|
22
|
+
JevProviderSelection,
|
|
21
23
|
} from "./types.ts";
|
|
22
24
|
|
|
23
25
|
export class AdvisorSettingsSelector implements Component, Focusable {
|
|
@@ -121,7 +123,8 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
121
123
|
fallbackModel,
|
|
122
124
|
jevSetupDeps: this.options.jevSetupDeps,
|
|
123
125
|
modelWhitelist,
|
|
124
|
-
|
|
126
|
+
onJevFilter: (selection) => this.applyJevFilter(selection),
|
|
127
|
+
onJevProvider: (selection) => this.applyJevProvider(selection),
|
|
125
128
|
presets: this.presets,
|
|
126
129
|
settings: this.settings,
|
|
127
130
|
theme: this.options.theme,
|
|
@@ -142,17 +145,19 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
142
145
|
return adapter;
|
|
143
146
|
}
|
|
144
147
|
|
|
145
|
-
private
|
|
148
|
+
private applyJevSelection(
|
|
149
|
+
patch: Partial<AdvisorSettings>,
|
|
150
|
+
handler?: (settings: AdvisorSettings) => boolean
|
|
151
|
+
): boolean {
|
|
146
152
|
const updated: AdvisorSettings = {
|
|
147
153
|
...this.settings,
|
|
148
|
-
|
|
149
|
-
jevTransport: selection.transport,
|
|
154
|
+
...patch,
|
|
150
155
|
showUsageDetails: this.settings.showUsageDetails ?? true,
|
|
151
156
|
toolPolicies: { ...this.settings.toolPolicies },
|
|
152
157
|
};
|
|
153
158
|
try {
|
|
154
|
-
const result =
|
|
155
|
-
?
|
|
159
|
+
const result = handler
|
|
160
|
+
? handler(updated)
|
|
156
161
|
: (this.options.onChange ?? this.options.onSave)?.(updated);
|
|
157
162
|
if (result === false) {
|
|
158
163
|
return false;
|
|
@@ -164,6 +169,59 @@ export class AdvisorSettingsSelector implements Component, Focusable {
|
|
|
164
169
|
return true;
|
|
165
170
|
}
|
|
166
171
|
|
|
172
|
+
private applyJevFilter(selection: JevFilterSelection): boolean {
|
|
173
|
+
const patch = { jevFilterEnabled: selection.enabled };
|
|
174
|
+
const handler = this.options.onJevFilter;
|
|
175
|
+
if (handler) {
|
|
176
|
+
return this.applyJevSelection(patch, (settings) =>
|
|
177
|
+
handler(selection, settings)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
const legacy = this.options.onJevSetup;
|
|
181
|
+
if (legacy) {
|
|
182
|
+
return this.applyJevSelection(patch, (settings) =>
|
|
183
|
+
legacy(
|
|
184
|
+
{
|
|
185
|
+
enabled: selection.enabled,
|
|
186
|
+
transport: settings.jevTransport ?? DEFAULT_JEV_TRANSPORT,
|
|
187
|
+
},
|
|
188
|
+
settings
|
|
189
|
+
)
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return this.applyJevSelection(patch);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private applyJevProvider(selection: JevProviderSelection): boolean {
|
|
196
|
+
const custom = selection.transport === "typesafe-compatible";
|
|
197
|
+
const patch = {
|
|
198
|
+
jevBaseUrl: custom ? selection.baseUrl : this.settings.jevBaseUrl,
|
|
199
|
+
jevKeyProvider: custom
|
|
200
|
+
? selection.keyProvider
|
|
201
|
+
: this.settings.jevKeyProvider,
|
|
202
|
+
jevTransport: selection.transport,
|
|
203
|
+
};
|
|
204
|
+
const handler = this.options.onJevProvider;
|
|
205
|
+
if (handler) {
|
|
206
|
+
return this.applyJevSelection(patch, (settings) =>
|
|
207
|
+
handler(selection, settings)
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const legacy = this.options.onJevSetup;
|
|
211
|
+
if (legacy) {
|
|
212
|
+
return this.applyJevSelection(patch, (settings) =>
|
|
213
|
+
legacy(
|
|
214
|
+
{
|
|
215
|
+
enabled: settings.jevFilterEnabled ?? false,
|
|
216
|
+
transport: selection.transport,
|
|
217
|
+
},
|
|
218
|
+
settings
|
|
219
|
+
)
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return this.applyJevSelection(patch);
|
|
223
|
+
}
|
|
224
|
+
|
|
167
225
|
private startSimpleModeGradient(): void {
|
|
168
226
|
this.stopSimpleModeGradient();
|
|
169
227
|
this.simpleModeGradientStartedAt = Date.now();
|
package/src/ui/types.ts
CHANGED
|
@@ -4,7 +4,11 @@ import type { KeybindingsManager, TUI } from "@earendil-works/pi-tui";
|
|
|
4
4
|
import type { GateFailureMode, JevTransport } from "../config/types.ts";
|
|
5
5
|
import type { GitContextLevel } from "../git.ts";
|
|
6
6
|
import type { JevKeyStoreResult } from "../jev/key-store.ts";
|
|
7
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
JevCredentials,
|
|
9
|
+
JevEndpointTarget,
|
|
10
|
+
JevTransportKind,
|
|
11
|
+
} from "../jev/transport.ts";
|
|
8
12
|
|
|
9
13
|
export interface RenderRequester {
|
|
10
14
|
requestRender: () => void;
|
|
@@ -87,15 +91,17 @@ export interface AdvisorSettings {
|
|
|
87
91
|
gitContext?: GitContextLevel;
|
|
88
92
|
gitContextMaxChars?: number;
|
|
89
93
|
herdrIntegration?: boolean;
|
|
94
|
+
jevBaseUrl?: string;
|
|
90
95
|
jevDigestMaxChars?: number;
|
|
91
96
|
jevFilterEnabled?: boolean;
|
|
92
97
|
jevFilterNoulMargin?: number;
|
|
93
98
|
jevFilterOverrideWindow?: number;
|
|
94
99
|
jevFilterSkipConfidence?: number;
|
|
100
|
+
jevKeyProvider?: string;
|
|
95
101
|
jevModel?: string;
|
|
96
102
|
jevPricePerMtok?: number;
|
|
97
103
|
jevTimeoutMs?: number;
|
|
98
|
-
jevTransport?:
|
|
104
|
+
jevTransport?: JevTransport;
|
|
99
105
|
jevTurnGateEveryTurns?: number;
|
|
100
106
|
jevTurnGateNoulThreshold?: number;
|
|
101
107
|
loopThreshold?: number;
|
|
@@ -117,11 +123,22 @@ export interface AdvisorSettings {
|
|
|
117
123
|
untrackedContent?: boolean;
|
|
118
124
|
}
|
|
119
125
|
|
|
126
|
+
/** @deprecated Split into JevFilterSelection and JevProviderSelection, which save separately. */
|
|
120
127
|
export interface JevSetupSelection {
|
|
121
128
|
enabled: boolean;
|
|
122
129
|
transport: JevTransport;
|
|
123
130
|
}
|
|
124
131
|
|
|
132
|
+
export interface JevFilterSelection {
|
|
133
|
+
enabled: boolean;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface JevProviderSelection {
|
|
137
|
+
baseUrl?: string;
|
|
138
|
+
keyProvider?: string;
|
|
139
|
+
transport: JevTransport;
|
|
140
|
+
}
|
|
141
|
+
|
|
125
142
|
export interface JevSetupResult {
|
|
126
143
|
message?: string;
|
|
127
144
|
ok: boolean;
|
|
@@ -130,6 +147,9 @@ export interface JevSetupResult {
|
|
|
130
147
|
export interface JevSetupDeps {
|
|
131
148
|
clearStoredKey?: (transport: JevTransportKind) => Promise<JevKeyStoreResult>;
|
|
132
149
|
removePlaintextKey?: () => JevKeyStoreResult;
|
|
150
|
+
resolveEndpoint?: (
|
|
151
|
+
target: JevEndpointTarget
|
|
152
|
+
) => Promise<JevCredentials | undefined>;
|
|
133
153
|
resolveTransport?: (
|
|
134
154
|
transport?: JevTransportKind
|
|
135
155
|
) => Promise<JevCredentials | undefined>;
|
|
@@ -151,6 +171,15 @@ export interface AdvisorSettingsSelectorOptions {
|
|
|
151
171
|
onSave?: (settings: AdvisorSettings) => void;
|
|
152
172
|
presets: ContextPreset[];
|
|
153
173
|
jevSetupDeps?: JevSetupDeps;
|
|
174
|
+
onJevFilter?: (
|
|
175
|
+
selection: JevFilterSelection,
|
|
176
|
+
settings: AdvisorSettings
|
|
177
|
+
) => boolean;
|
|
178
|
+
onJevProvider?: (
|
|
179
|
+
selection: JevProviderSelection,
|
|
180
|
+
settings: AdvisorSettings
|
|
181
|
+
) => boolean;
|
|
182
|
+
/** @deprecated Use onJevFilter and onJevProvider; each is saved independently. */
|
|
154
183
|
onJevSetup?: (
|
|
155
184
|
selection: JevSetupSelection,
|
|
156
185
|
settings: AdvisorSettings
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
canClearCredential,
|
|
5
|
-
providerName,
|
|
6
|
-
transportLabel,
|
|
7
|
-
} from "./jev-setup-support.ts";
|
|
8
|
-
import type {
|
|
9
|
-
JevSetupSubmenuOptions,
|
|
10
|
-
JevSetupViewState,
|
|
11
|
-
SetupAction,
|
|
12
|
-
} from "./jev-setup-support.ts";
|
|
13
|
-
import type { MaskedInput } from "./masked-input.ts";
|
|
14
|
-
|
|
15
|
-
export const setupActions = (state: JevSetupViewState): SetupAction[] => {
|
|
16
|
-
const actions: SetupAction[] = ["typesafe", "openrouter", "openai-decisions"];
|
|
17
|
-
if (state.canEnterKey) {
|
|
18
|
-
actions.push("enter-key");
|
|
19
|
-
}
|
|
20
|
-
if (state.filterEnabled) {
|
|
21
|
-
actions.push("disable");
|
|
22
|
-
}
|
|
23
|
-
if (state.credentials && canClearCredential(state.credentials)) {
|
|
24
|
-
actions.push("clear-stored-key");
|
|
25
|
-
}
|
|
26
|
-
actions.push("done");
|
|
27
|
-
return actions;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const setupLabels = (state: JevSetupViewState): string[] =>
|
|
31
|
-
setupActions(state).map((action) => {
|
|
32
|
-
if (action === "clear-stored-key") {
|
|
33
|
-
return state.filterEnabled
|
|
34
|
-
? "Disable and clear stored key"
|
|
35
|
-
: "Clear stored key";
|
|
36
|
-
}
|
|
37
|
-
if (action === "disable") {
|
|
38
|
-
return "Disable";
|
|
39
|
-
}
|
|
40
|
-
if (action === "done") {
|
|
41
|
-
return "Done";
|
|
42
|
-
}
|
|
43
|
-
if (action === "enter-key") {
|
|
44
|
-
return state.selectedTransport === "openai-decisions"
|
|
45
|
-
? "Enter an OpenAI Platform API key"
|
|
46
|
-
: "Enter a TypeSafe API key";
|
|
47
|
-
}
|
|
48
|
-
return providerName(action);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export const renderJevSetup = (
|
|
52
|
-
options: JevSetupSubmenuOptions,
|
|
53
|
-
state: JevSetupViewState,
|
|
54
|
-
maskedInput: MaskedInput,
|
|
55
|
-
width: number
|
|
56
|
-
): string[] => {
|
|
57
|
-
const { theme } = options;
|
|
58
|
-
const lines = [
|
|
59
|
-
theme.fg("accent", theme.bold(" Jev/Decisions consultation filter")),
|
|
60
|
-
"",
|
|
61
|
-
` Filter: ${state.filterEnabled ? "On" : "Off"}`,
|
|
62
|
-
];
|
|
63
|
-
if (state.credentials) {
|
|
64
|
-
lines.push(` Credential: ${transportLabel(state.credentials)}`);
|
|
65
|
-
} else if (state.selectedTransport) {
|
|
66
|
-
lines.push(` Selected provider: ${providerName(state.selectedTransport)}`);
|
|
67
|
-
} else {
|
|
68
|
-
lines.push(` Saved transport: ${options.currentTransport}`);
|
|
69
|
-
}
|
|
70
|
-
if (state.notice) {
|
|
71
|
-
lines.push("", theme.fg("warning", ` ${state.notice}`));
|
|
72
|
-
}
|
|
73
|
-
lines.push("");
|
|
74
|
-
if (state.mode === "resolving") {
|
|
75
|
-
lines.push(" Checking the selected provider credentials…");
|
|
76
|
-
} else if (state.mode === "verifying") {
|
|
77
|
-
lines.push(" Verifying with a live Jev call…");
|
|
78
|
-
} else if (state.mode === "clearing") {
|
|
79
|
-
lines.push(" Clearing the selected provider's stored key…");
|
|
80
|
-
} else if (state.mode === "key-entry") {
|
|
81
|
-
lines.push(
|
|
82
|
-
` ${providerName(state.selectedTransport ?? "typesafe")}`,
|
|
83
|
-
state.selectedTransport === "openai-decisions"
|
|
84
|
-
? " No OpenAI Platform API key found. ChatGPT subscription OAuth is not accepted."
|
|
85
|
-
: " No TypeSafe API key found.",
|
|
86
|
-
` ${maskedInput.render(Math.max(10, width - 4))[0] ?? ""}`,
|
|
87
|
-
theme.fg("dim", " Enter: verify and securely store · Esc: return")
|
|
88
|
-
);
|
|
89
|
-
} else {
|
|
90
|
-
for (const [index, label] of setupLabels(state).entries()) {
|
|
91
|
-
const prefix = index === state.selectedIndex ? "→ " : " ";
|
|
92
|
-
lines.push(`${prefix}${label}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return lines.map((line) => truncateToWidth(line, width));
|
|
96
|
-
};
|