mastracode 0.50.4-alpha.0 → 0.51.0-alpha.1
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 +29 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{run-tui-iN-yMNdP.cjs → run-tui-BU5p-oWh.cjs} +2 -2
- package/dist/{run-tui-Cro2miV4.js → run-tui-Bb5I2Op2.js} +2 -2
- package/dist/run-tui.cjs +1 -1
- package/dist/run-tui.js +1 -1
- package/dist/tui/commands/custom-providers.d.ts +39 -1
- package/dist/tui/components/ask-question-dialog.d.ts +4 -0
- package/dist/tui/modal-question.d.ts +3 -0
- package/dist/{tui-Dj2PcyWU.js → tui-DhXpcMRs.js} +396 -11
- package/dist/{tui-C7NUOVDN.cjs → tui-vycpsgSv.cjs} +396 -11
- package/dist/tui.cjs +1 -1
- package/dist/tui.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# mastracode
|
|
2
2
|
|
|
3
|
+
## 0.51.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added a connection test, models from the endpoint, custom headers and an auth scheme choice to `/custom-providers`. Select a provider to find them: ([#31565](https://github.com/mastra-ai/mastra/pull/31565))
|
|
8
|
+
|
|
9
|
+
- **Add model** now offers the models the endpoint lists that are not added yet, one at a time or all at once, and still takes a typed ID. If the endpoint does not answer within a few seconds, it asks for the ID as before.
|
|
10
|
+
- **Test connection** calls the endpoint's model list and shows how many models it lists and how long it took. A failure shows the status, the URL called and the error text the endpoint returned.
|
|
11
|
+
- **Headers** adds or removes extra headers sent on every call. A secret value is masked while it is typed and shows as `••••`.
|
|
12
|
+
- **Auth scheme** sends the API key as `Authorization: Bearer <key>` or as `x-api-key: <key>`.
|
|
13
|
+
|
|
14
|
+
When an edit moves a provider's base URL to another origin, its secret headers are removed so their values are never sent to the new address. Add them again under **Headers**.
|
|
15
|
+
|
|
16
|
+
The choices are saved on the provider in `settings.json`:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"name": "Acme Gateway",
|
|
21
|
+
"authScheme": "x-api-key",
|
|
22
|
+
"headers": [{ "name": "X-Org-Id", "value": "org-123", "secret": false }]
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Updated dependencies [[`ad3d59f`](https://github.com/mastra-ai/mastra/commit/ad3d59f4a7c3557e3871b047ee48075a84731698), [`ad3d59f`](https://github.com/mastra-ai/mastra/commit/ad3d59f4a7c3557e3871b047ee48075a84731698), [`ad3d59f`](https://github.com/mastra-ai/mastra/commit/ad3d59f4a7c3557e3871b047ee48075a84731698), [`ad3d59f`](https://github.com/mastra-ai/mastra/commit/ad3d59f4a7c3557e3871b047ee48075a84731698), [`f19b0cf`](https://github.com/mastra-ai/mastra/commit/f19b0cf20c347921358943bb70c14051493088de), [`18439ea`](https://github.com/mastra-ai/mastra/commit/18439ea68fd5b009119e80af05cabc5ce5004c2b), [`21aee63`](https://github.com/mastra-ai/mastra/commit/21aee631dbb59e843b265706438865928185d500), [`6ae02c2`](https://github.com/mastra-ai/mastra/commit/6ae02c23a7aff35f229f46cc413c661309016e95)]:
|
|
29
|
+
- @mastra/core@1.87.0-alpha.1
|
|
30
|
+
- @mastra/code-sdk@1.22.0-alpha.1
|
|
31
|
+
|
|
3
32
|
## 0.50.4-alpha.0
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/dist/cli.cjs
CHANGED
package/dist/cli.js
CHANGED
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_tui = require("./tui-
|
|
1
|
+
const require_tui = require("./tui-vycpsgSv.cjs");
|
|
2
2
|
let _mastra_code_sdk = require("@mastra/code-sdk");
|
|
3
3
|
let child_process = require("child_process");
|
|
4
4
|
let fs = require("fs");
|
|
@@ -264,7 +264,7 @@ async function runUpdateCommand({ args = [], output = process.stdout, errorOutpu
|
|
|
264
264
|
}
|
|
265
265
|
// src/version.ts
|
|
266
266
|
function getCurrentVersion() {
|
|
267
|
-
return "0.
|
|
267
|
+
return "0.51.0-alpha.1";
|
|
268
268
|
}
|
|
269
269
|
/** Whether the invocation is `mastracode --version` or `mastracode -v`. */
|
|
270
270
|
function isVersionCommand(argv) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { D as closeActiveBrowser, E as activeBrowserGeneration, O as discardBrowser, T as TUI_CO_AUTHOR, _ as normalizeThemePreference, a as formatUpdateHeader, g as applyThemePreference, i as formatUpToDate, k as replaceActiveBrowser, n as formatInstallingLabel, o as formatUpdateOutcome, r as formatRegistryError, t as MastraTUI } from "./tui-
|
|
1
|
+
import { D as closeActiveBrowser, E as activeBrowserGeneration, O as discardBrowser, T as TUI_CO_AUTHOR, _ as normalizeThemePreference, a as formatUpdateHeader, g as applyThemePreference, i as formatUpToDate, k as replaceActiveBrowser, n as formatInstallingLabel, o as formatUpdateOutcome, r as formatRegistryError, t as MastraTUI } from "./tui-DhXpcMRs.js";
|
|
2
2
|
import { createMastraCode, resolveSubagentsSetting } from "@mastra/code-sdk";
|
|
3
3
|
import { spawn } from "child_process";
|
|
4
4
|
import fs from "fs";
|
|
@@ -263,7 +263,7 @@ async function runUpdateCommand({ args = [], output = process.stdout, errorOutpu
|
|
|
263
263
|
}
|
|
264
264
|
// src/version.ts
|
|
265
265
|
function getCurrentVersion() {
|
|
266
|
-
return "0.
|
|
266
|
+
return "0.51.0-alpha.1";
|
|
267
267
|
}
|
|
268
268
|
/** Whether the invocation is `mastracode --version` or `mastracode -v`. */
|
|
269
269
|
function isVersionCommand(argv) {
|
package/dist/run-tui.cjs
CHANGED
package/dist/run-tui.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as runTui } from "./run-tui-
|
|
1
|
+
export { t as runTui } from "./run-tui-Bb5I2Op2.js";
|
|
@@ -1,8 +1,46 @@
|
|
|
1
1
|
import { removeCustomProviderFromSettings, upsertCustomProviderInSettings } from '@mastra/code-sdk/onboarding/custom-providers';
|
|
2
|
-
import type { GlobalSettings } from '@mastra/code-sdk/onboarding/settings';
|
|
2
|
+
import type { CustomProviderAuthScheme, CustomProviderHeader, CustomProviderSetting, GlobalSettings } from '@mastra/code-sdk/onboarding/settings';
|
|
3
3
|
import type { SlashCommandContext } from './types.js';
|
|
4
4
|
export { removeCustomProviderFromSettings, upsertCustomProviderInSettings };
|
|
5
5
|
export declare function addModelToCustomProviderInSettings(settings: GlobalSettings, providerId: string, modelName: string): boolean;
|
|
6
6
|
export declare function removeModelFromCustomProviderInSettings(settings: GlobalSettings, providerId: string, modelName: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Add several model ids to a provider at once and return how many were new.
|
|
9
|
+
* Ids already configured and blank ids are skipped.
|
|
10
|
+
*/
|
|
11
|
+
export declare function addModelsToCustomProviderInSettings(settings: GlobalSettings, providerId: string, modelNames: readonly string[]): number;
|
|
12
|
+
/**
|
|
13
|
+
* The model IDs from an endpoint's list that are worth offering to add.
|
|
14
|
+
*
|
|
15
|
+
* IDs are read the way `parseCustomProviders` reads saved models: trimmed, and
|
|
16
|
+
* with a leading `<providerId>/` removed. Otherwise `acme/foo` would be saved,
|
|
17
|
+
* read back as `foo`, and offered again forever. IDs already configured are
|
|
18
|
+
* left out, and so are IDs equal to a label in `reservedLabels`, because the
|
|
19
|
+
* menu matches picks by label and such an ID would trigger that action.
|
|
20
|
+
*/
|
|
21
|
+
export declare function endpointModelsToOffer(listed: readonly string[], provider: Pick<CustomProviderSetting, 'name' | 'models'>, reservedLabels: readonly string[]): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Change how a provider sends its API key. Returns why the change is refused,
|
|
24
|
+
* or undefined once it is applied. A saved custom header may already use the
|
|
25
|
+
* header the new scheme writes, so the headers are checked against it first.
|
|
26
|
+
*/
|
|
27
|
+
export declare function setCustomProviderAuthSchemeInSettings(settings: GlobalSettings, providerId: string, authScheme: CustomProviderAuthScheme): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Add a custom header to a provider. Returns why the header is refused, or
|
|
30
|
+
* undefined once it is added.
|
|
31
|
+
*/
|
|
32
|
+
export declare function addHeaderToCustomProviderInSettings(settings: GlobalSettings, providerId: string, header: CustomProviderHeader): string | undefined;
|
|
33
|
+
/** Remove a custom header from a provider by name, ignoring case. Returns whether one was removed. */
|
|
34
|
+
export declare function removeHeaderFromCustomProviderInSettings(settings: GlobalSettings, providerId: string, headerName: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Split a provider's headers for an edit that moves it from `previousUrl` to
|
|
37
|
+
* `nextUrl`. A saved secret is never sent to a new origin unless the user
|
|
38
|
+
* types it again, so secret headers are dropped when the origin changes.
|
|
39
|
+
* A header saved without a `secret` flag counts as secret.
|
|
40
|
+
*/
|
|
41
|
+
export declare function headersForCustomProviderUrlChange(headers: readonly CustomProviderHeader[], previousUrl: string, nextUrl: string): {
|
|
42
|
+
kept: CustomProviderHeader[];
|
|
43
|
+
removed: CustomProviderHeader[];
|
|
44
|
+
};
|
|
7
45
|
export declare function handleCustomProvidersCommand(ctx: SlashCommandContext): Promise<void>;
|
|
8
46
|
//# sourceMappingURL=custom-providers.d.ts.map
|
|
@@ -22,6 +22,8 @@ export interface AskQuestionDialogOptions {
|
|
|
22
22
|
* Defaults to false. Enable for prompts that legitimately want paragraph-length replies.
|
|
23
23
|
*/
|
|
24
24
|
multiline?: boolean;
|
|
25
|
+
/** Show typed text as asterisks, for secrets. Applies to single-line input only. */
|
|
26
|
+
masked?: boolean;
|
|
25
27
|
allowEmptyInput?: boolean;
|
|
26
28
|
defaultValue?: string;
|
|
27
29
|
allowCustomResponse?: boolean;
|
|
@@ -41,6 +43,7 @@ export declare class AskQuestionDialogComponent extends Box implements Focusable
|
|
|
41
43
|
private input?;
|
|
42
44
|
private tui?;
|
|
43
45
|
private multiline;
|
|
46
|
+
private masked;
|
|
44
47
|
private multiSelect;
|
|
45
48
|
private allowEmptyInput;
|
|
46
49
|
private defaultValue?;
|
|
@@ -58,6 +61,7 @@ export declare class AskQuestionDialogComponent extends Box implements Focusable
|
|
|
58
61
|
private buildSelectMode;
|
|
59
62
|
/** Whether this prompt should render a multiline editor (vs a single-line input). */
|
|
60
63
|
private useMultiline;
|
|
64
|
+
/** Add the text input, its hint and the default value. A masked prompt uses `MaskedInput`. */
|
|
61
65
|
private buildInputMode;
|
|
62
66
|
private switchToCustomInput;
|
|
63
67
|
handleInput(data: string): void;
|
|
@@ -13,10 +13,13 @@ export type ModalQuestionOptions = {
|
|
|
13
13
|
allowCustomResponse?: boolean;
|
|
14
14
|
selectedOptionLabel?: string;
|
|
15
15
|
multiline?: boolean;
|
|
16
|
+
/** Show typed text as asterisks, for secrets. */
|
|
17
|
+
masked?: boolean;
|
|
16
18
|
overlay?: {
|
|
17
19
|
widthPercent?: number;
|
|
18
20
|
maxHeight?: OverlayOptions['maxHeight'];
|
|
19
21
|
};
|
|
20
22
|
};
|
|
23
|
+
/** Show a question dialog over the TUI and resolve with the answer, or null when the user cancels. */
|
|
21
24
|
export declare function askModalQuestion(tui: TUI, options: ModalQuestionOptions): Promise<string | null>;
|
|
22
25
|
//# sourceMappingURL=modal-question.d.ts.map
|
|
@@ -54,6 +54,8 @@ import { stripVTControlCharacters } from "util";
|
|
|
54
54
|
import { getAvailableModePacks as getAvailableModePacks$1, getBuiltinModePack, resolveAutoOMModelId, resolveModePackFallbackChain } from "@mastra/code-sdk/onboarding/packs";
|
|
55
55
|
import { removeCustomPackFromSettings } from "@mastra/code-sdk/onboarding/custom-packs";
|
|
56
56
|
import { canUseProvider, getActiveRouteMemoryModelId } from "@mastra/code-sdk/agents/model";
|
|
57
|
+
import { listCustomProviderModels } from "@mastra/code-sdk/agents/custom-provider-check";
|
|
58
|
+
import { CONTROL_CHARACTER_PATTERN, customProviderHeaderProblem } from "@mastra/code-sdk/onboarding/custom-provider-headers";
|
|
57
59
|
import { removeCustomProviderFromSettings, upsertCustomProviderInSettings } from "@mastra/code-sdk/onboarding/custom-providers";
|
|
58
60
|
import { applyOmRoleAuto, applyOmRoleOverride, persistOmObserveAttachments } from "@mastra/code-sdk/onboarding/om-settings";
|
|
59
61
|
import { getOAuthProviders as getOAuthProviders$1 } from "@mastra/code-sdk/auth/index";
|
|
@@ -4469,6 +4471,7 @@ var AskQuestionDialogComponent = class AskQuestionDialogComponent extends Box {
|
|
|
4469
4471
|
input;
|
|
4470
4472
|
tui;
|
|
4471
4473
|
multiline = false;
|
|
4474
|
+
masked = false;
|
|
4472
4475
|
multiSelect = false;
|
|
4473
4476
|
allowEmptyInput = false;
|
|
4474
4477
|
defaultValue;
|
|
@@ -4494,6 +4497,7 @@ var AskQuestionDialogComponent = class AskQuestionDialogComponent extends Box {
|
|
|
4494
4497
|
this.onCancel = options.onCancel;
|
|
4495
4498
|
this.tui = options.tui;
|
|
4496
4499
|
this.multiline = Boolean(options.multiline);
|
|
4500
|
+
this.masked = Boolean(options.masked);
|
|
4497
4501
|
this.multiSelect = options.selectionMode === "multi_select";
|
|
4498
4502
|
this.allowEmptyInput = Boolean(options.allowEmptyInput);
|
|
4499
4503
|
this.defaultValue = options.defaultValue;
|
|
@@ -4561,6 +4565,7 @@ var AskQuestionDialogComponent = class AskQuestionDialogComponent extends Box {
|
|
|
4561
4565
|
useMultiline() {
|
|
4562
4566
|
return this.multiline && Boolean(this.tui);
|
|
4563
4567
|
}
|
|
4568
|
+
/** Add the text input, its hint and the default value. A masked prompt uses `MaskedInput`. */
|
|
4564
4569
|
buildInputMode() {
|
|
4565
4570
|
if (this.useMultiline()) {
|
|
4566
4571
|
const multilineInput = new MultilineInput(this.tui, getEditorTheme());
|
|
@@ -4573,7 +4578,7 @@ var AskQuestionDialogComponent = class AskQuestionDialogComponent extends Box {
|
|
|
4573
4578
|
};
|
|
4574
4579
|
this.input = multilineInput;
|
|
4575
4580
|
} else {
|
|
4576
|
-
this.input = new Input();
|
|
4581
|
+
this.input = this.masked ? new MaskedInput() : new Input();
|
|
4577
4582
|
this.input.onSubmit = (value) => {
|
|
4578
4583
|
const trimmed = value.trim();
|
|
4579
4584
|
if (trimmed || this.allowEmptyInput) this.onSubmit(trimmed);
|
|
@@ -4610,6 +4615,7 @@ var AskQuestionDialogComponent = class AskQuestionDialogComponent extends Box {
|
|
|
4610
4615
|
}
|
|
4611
4616
|
};
|
|
4612
4617
|
// src/tui/modal-question.ts
|
|
4618
|
+
/** Show a question dialog over the TUI and resolve with the answer, or null when the user cancels. */
|
|
4613
4619
|
function askModalQuestion(tui, options) {
|
|
4614
4620
|
return new Promise((resolve) => {
|
|
4615
4621
|
const question = new AskQuestionDialogComponent({
|
|
@@ -4617,6 +4623,7 @@ function askModalQuestion(tui, options) {
|
|
|
4617
4623
|
title: options.title,
|
|
4618
4624
|
options: options.options,
|
|
4619
4625
|
multiline: options.multiline,
|
|
4626
|
+
masked: options.masked,
|
|
4620
4627
|
tui,
|
|
4621
4628
|
allowEmptyInput: options.allowEmptyInput,
|
|
4622
4629
|
allowCustomResponse: options.allowCustomResponse,
|
|
@@ -15697,13 +15704,13 @@ async function handleSkillCommand(ctx, skillName, args) {
|
|
|
15697
15704
|
}
|
|
15698
15705
|
}
|
|
15699
15706
|
// src/tui/thread-title.ts
|
|
15700
|
-
const CONTROL_CHARACTER_PATTERN = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
15707
|
+
const CONTROL_CHARACTER_PATTERN$1 = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
15701
15708
|
function setCurrentThreadTitle(state, title) {
|
|
15702
|
-
const safeTitle = title ? stripVTControlCharacters(title).replace(CONTROL_CHARACTER_PATTERN, " ").trim() : void 0;
|
|
15709
|
+
const safeTitle = title ? stripVTControlCharacters(title).replace(CONTROL_CHARACTER_PATTERN$1, " ").trim() : void 0;
|
|
15703
15710
|
state.currentThreadTitle = safeTitle;
|
|
15704
15711
|
const appName = state.options.appName || "Mastra Code";
|
|
15705
15712
|
const cwd = basename(process.cwd());
|
|
15706
|
-
state.ui.terminal.setTitle(`${appName} - ${safeTitle || cwd}`.replace(CONTROL_CHARACTER_PATTERN, " "));
|
|
15713
|
+
state.ui.terminal.setTitle(`${appName} - ${safeTitle || cwd}`.replace(CONTROL_CHARACTER_PATTERN$1, " "));
|
|
15707
15714
|
}
|
|
15708
15715
|
// src/tui/commands/new.ts
|
|
15709
15716
|
async function handleNewCommand(ctx) {
|
|
@@ -18613,24 +18620,120 @@ function removeModelFromCustomProviderInSettings(settings, providerId, modelName
|
|
|
18613
18620
|
provider.models = provider.models.filter((model) => model !== modelName);
|
|
18614
18621
|
return provider.models.length < before;
|
|
18615
18622
|
}
|
|
18616
|
-
|
|
18623
|
+
/**
|
|
18624
|
+
* Add several model ids to a provider at once and return how many were new.
|
|
18625
|
+
* Ids already configured and blank ids are skipped.
|
|
18626
|
+
*/
|
|
18627
|
+
function addModelsToCustomProviderInSettings(settings, providerId, modelNames) {
|
|
18628
|
+
const provider = settings.customProviders.find((entry) => getCustomProviderId(entry.name) === providerId);
|
|
18629
|
+
if (!provider) return 0;
|
|
18630
|
+
const before = provider.models.length;
|
|
18631
|
+
provider.models = [.../* @__PURE__ */ new Set([...provider.models, ...modelNames.map((model) => model.trim()).filter(Boolean)])];
|
|
18632
|
+
return provider.models.length - before;
|
|
18633
|
+
}
|
|
18634
|
+
/**
|
|
18635
|
+
* The model IDs from an endpoint's list that are worth offering to add.
|
|
18636
|
+
*
|
|
18637
|
+
* IDs are read the way `parseCustomProviders` reads saved models: trimmed, and
|
|
18638
|
+
* with a leading `<providerId>/` removed. Otherwise `acme/foo` would be saved,
|
|
18639
|
+
* read back as `foo`, and offered again forever. IDs already configured are
|
|
18640
|
+
* left out, and so are IDs equal to a label in `reservedLabels`, because the
|
|
18641
|
+
* menu matches picks by label and such an ID would trigger that action.
|
|
18642
|
+
*/
|
|
18643
|
+
function endpointModelsToOffer(listed, provider, reservedLabels) {
|
|
18644
|
+
const providerPrefix = `${getCustomProviderId(provider.name)}/`;
|
|
18645
|
+
const offered = listed.map((model) => model.trim()).map((model) => model.startsWith(providerPrefix) ? model.slice(providerPrefix.length) : model).filter((model) => model.length > 0 && !provider.models.includes(model) && !reservedLabels.includes(model));
|
|
18646
|
+
return [...new Set(offered)];
|
|
18647
|
+
}
|
|
18648
|
+
/**
|
|
18649
|
+
* Change how a provider sends its API key. Returns why the change is refused,
|
|
18650
|
+
* or undefined once it is applied. A saved custom header may already use the
|
|
18651
|
+
* header the new scheme writes, so the headers are checked against it first.
|
|
18652
|
+
*/
|
|
18653
|
+
function setCustomProviderAuthSchemeInSettings(settings, providerId, authScheme) {
|
|
18654
|
+
const provider = settings.customProviders.find((entry) => getCustomProviderId(entry.name) === providerId);
|
|
18655
|
+
if (!provider) return "Provider not found.";
|
|
18656
|
+
const problem = customProviderHeaderProblem(provider.headers ?? [], authScheme);
|
|
18657
|
+
if (problem) return problem;
|
|
18658
|
+
provider.authScheme = authScheme;
|
|
18659
|
+
}
|
|
18660
|
+
/**
|
|
18661
|
+
* Add a custom header to a provider. Returns why the header is refused, or
|
|
18662
|
+
* undefined once it is added.
|
|
18663
|
+
*/
|
|
18664
|
+
function addHeaderToCustomProviderInSettings(settings, providerId, header) {
|
|
18665
|
+
const provider = settings.customProviders.find((entry) => getCustomProviderId(entry.name) === providerId);
|
|
18666
|
+
if (!provider) return "Provider not found.";
|
|
18667
|
+
const next = {
|
|
18668
|
+
name: header.name.trim(),
|
|
18669
|
+
value: header.value.trim(),
|
|
18670
|
+
secret: header.secret ?? true
|
|
18671
|
+
};
|
|
18672
|
+
const headers = [...provider.headers ?? [], next];
|
|
18673
|
+
const problem = customProviderHeaderProblem(headers, provider.authScheme);
|
|
18674
|
+
if (problem) return problem;
|
|
18675
|
+
provider.headers = headers;
|
|
18676
|
+
}
|
|
18677
|
+
/** Remove a custom header from a provider by name, ignoring case. Returns whether one was removed. */
|
|
18678
|
+
function removeHeaderFromCustomProviderInSettings(settings, providerId, headerName) {
|
|
18679
|
+
const provider = settings.customProviders.find((entry) => getCustomProviderId(entry.name) === providerId);
|
|
18680
|
+
if (!provider?.headers) return false;
|
|
18681
|
+
const before = provider.headers.length;
|
|
18682
|
+
provider.headers = provider.headers.filter((header) => header.name.toLowerCase() !== headerName.toLowerCase());
|
|
18683
|
+
return provider.headers.length < before;
|
|
18684
|
+
}
|
|
18685
|
+
/** The origin of a URL, or the URL itself when it does not parse. */
|
|
18686
|
+
function urlOrigin(url) {
|
|
18687
|
+
try {
|
|
18688
|
+
return new URL(url).origin;
|
|
18689
|
+
} catch {
|
|
18690
|
+
return url;
|
|
18691
|
+
}
|
|
18692
|
+
}
|
|
18693
|
+
/**
|
|
18694
|
+
* Split a provider's headers for an edit that moves it from `previousUrl` to
|
|
18695
|
+
* `nextUrl`. A saved secret is never sent to a new origin unless the user
|
|
18696
|
+
* types it again, so secret headers are dropped when the origin changes.
|
|
18697
|
+
* A header saved without a `secret` flag counts as secret.
|
|
18698
|
+
*/
|
|
18699
|
+
function headersForCustomProviderUrlChange(headers, previousUrl, nextUrl) {
|
|
18700
|
+
if (urlOrigin(previousUrl) === urlOrigin(nextUrl)) return {
|
|
18701
|
+
kept: [...headers],
|
|
18702
|
+
removed: []
|
|
18703
|
+
};
|
|
18704
|
+
return {
|
|
18705
|
+
kept: headers.filter((header) => header.secret === false),
|
|
18706
|
+
removed: headers.filter((header) => header.secret !== false)
|
|
18707
|
+
};
|
|
18708
|
+
}
|
|
18709
|
+
/**
|
|
18710
|
+
* Ask for one line of text and return it trimmed, or null when it is empty or
|
|
18711
|
+
* the user cancels. `masked` hides the typed text, for secrets.
|
|
18712
|
+
*/
|
|
18713
|
+
async function askText$2(ctx, question, defaultValue, allowEmptyInput = false, masked = false) {
|
|
18617
18714
|
const trimmed = (await askModalQuestion(ctx.state.ui, {
|
|
18618
18715
|
question,
|
|
18619
18716
|
defaultValue,
|
|
18620
|
-
allowEmptyInput
|
|
18717
|
+
allowEmptyInput,
|
|
18718
|
+
masked
|
|
18621
18719
|
}))?.trim() ?? "";
|
|
18622
18720
|
return trimmed.length > 0 ? trimmed : null;
|
|
18623
18721
|
}
|
|
18624
18722
|
async function askOptionalText(ctx, question, defaultValue) {
|
|
18625
18723
|
return (await askText$2(ctx, `${question} (leave blank to skip)`, defaultValue, true))?.trim() || void 0;
|
|
18626
18724
|
}
|
|
18627
|
-
|
|
18725
|
+
/**
|
|
18726
|
+
* Ask the user to pick one option and return its value, or null on Esc.
|
|
18727
|
+
* `selectedLabel` starts the cursor on that option instead of the first one.
|
|
18728
|
+
*/
|
|
18729
|
+
async function askSelect$1(ctx, question, options, selectedLabel) {
|
|
18628
18730
|
const answer = await askModalQuestion(ctx.state.ui, {
|
|
18629
18731
|
question,
|
|
18630
18732
|
options: options.map((option) => ({
|
|
18631
18733
|
label: option.label,
|
|
18632
18734
|
description: option.description
|
|
18633
|
-
}))
|
|
18735
|
+
})),
|
|
18736
|
+
selectedOptionLabel: selectedLabel
|
|
18634
18737
|
});
|
|
18635
18738
|
return options.find((option) => option.label === answer)?.value ?? null;
|
|
18636
18739
|
}
|
|
@@ -18660,6 +18763,12 @@ async function createProviderFlow(ctx) {
|
|
|
18660
18763
|
ctx.showInfo(`Added custom provider: ${name}`);
|
|
18661
18764
|
await manageProviderFlow(ctx, providerId);
|
|
18662
18765
|
}
|
|
18766
|
+
/**
|
|
18767
|
+
* Rename a provider or change its URL or API key. Secret headers are dropped
|
|
18768
|
+
* when the new URL has another origin, see {@link headersForCustomProviderUrlChange}.
|
|
18769
|
+
* The rule lives here and not in `upsertCustomProviderInSettings`, which other
|
|
18770
|
+
* callers use as a plain upsert.
|
|
18771
|
+
*/
|
|
18663
18772
|
async function editProviderFlow(ctx, providerId) {
|
|
18664
18773
|
const settings = loadSettings();
|
|
18665
18774
|
const provider = settings.customProviders.find((entry) => getCustomProviderId(entry.name) === providerId);
|
|
@@ -18681,16 +18790,23 @@ async function editProviderFlow(ctx, providerId) {
|
|
|
18681
18790
|
return;
|
|
18682
18791
|
}
|
|
18683
18792
|
const apiKey = await askOptionalText(ctx, "API key", provider.apiKey);
|
|
18793
|
+
const { kept, removed } = headersForCustomProviderUrlChange(provider.headers ?? [], provider.url, url);
|
|
18684
18794
|
upsertCustomProviderInSettings(settings, {
|
|
18685
18795
|
...provider,
|
|
18686
18796
|
name,
|
|
18687
18797
|
url,
|
|
18688
|
-
apiKey
|
|
18798
|
+
apiKey,
|
|
18799
|
+
headers: kept
|
|
18689
18800
|
}, providerId);
|
|
18690
18801
|
saveSettings(settings);
|
|
18691
18802
|
ctx.showInfo(`Updated custom provider: ${name}`);
|
|
18803
|
+
if (removed.length > 0) {
|
|
18804
|
+
const names = removed.map((header) => header.name).join(", ");
|
|
18805
|
+
ctx.showInfo(removed.length === 1 ? `Removed secret header ${names} because the base URL moved to another origin. Add it again under Headers.` : `Removed secret headers ${names} because the base URL moved to another origin. Add them again under Headers.`);
|
|
18806
|
+
}
|
|
18692
18807
|
}
|
|
18693
|
-
|
|
18808
|
+
/** Ask for one model ID and add it to the provider. */
|
|
18809
|
+
async function typeModelIdFlow(ctx, providerId) {
|
|
18694
18810
|
const settings = loadSettings();
|
|
18695
18811
|
const provider = settings.customProviders.find((entry) => getCustomProviderId(entry.name) === providerId);
|
|
18696
18812
|
if (!provider) {
|
|
@@ -18730,6 +18846,251 @@ async function removeProviderModelFlow(ctx, providerId) {
|
|
|
18730
18846
|
saveSettings(settings);
|
|
18731
18847
|
ctx.showInfo(`Removed model: ${toCustomProviderModelId(provider.name, modelName)}`);
|
|
18732
18848
|
}
|
|
18849
|
+
/** The connection a check uses: the provider exactly as saved. */
|
|
18850
|
+
function savedConnection(provider) {
|
|
18851
|
+
return {
|
|
18852
|
+
url: provider.url,
|
|
18853
|
+
apiKey: provider.apiKey,
|
|
18854
|
+
authScheme: provider.authScheme,
|
|
18855
|
+
headers: provider.headers
|
|
18856
|
+
};
|
|
18857
|
+
}
|
|
18858
|
+
const CONTROL_CHARACTERS = new RegExp(`${CONTROL_CHARACTER_PATTERN.source}+`, "g");
|
|
18859
|
+
/**
|
|
18860
|
+
* Text that came from an endpoint, made safe to print on one line. Escape
|
|
18861
|
+
* sequences in it would act on the terminal instead of being shown, and line
|
|
18862
|
+
* breaks would split one message across several rows.
|
|
18863
|
+
*/
|
|
18864
|
+
function printableText(text) {
|
|
18865
|
+
return text.replace(CONTROL_CHARACTERS, " ").replace(/\s+/g, " ").trim();
|
|
18866
|
+
}
|
|
18867
|
+
/**
|
|
18868
|
+
* Show a failed check as the SDK reports it, with the upstream detail on its
|
|
18869
|
+
* own line. The SDK already cleans both, and cleaning again here keeps the
|
|
18870
|
+
* terminal safe if that ever changes.
|
|
18871
|
+
*/
|
|
18872
|
+
function showCheckFailure(ctx, failure) {
|
|
18873
|
+
const message = printableText(failure.message);
|
|
18874
|
+
const detail = failure.detail ? printableText(failure.detail) : "";
|
|
18875
|
+
ctx.showError(detail ? `${message}\n${detail}` : message);
|
|
18876
|
+
}
|
|
18877
|
+
/** The "Add header" action value, prefixed with NUL so no header name can equal it. */
|
|
18878
|
+
const ADD_HEADER = "\0add-header";
|
|
18879
|
+
/**
|
|
18880
|
+
* Labels of the actions in the "Add model" picker. The picker matches answers
|
|
18881
|
+
* by label, so a listed model ID equal to one of them is not offered.
|
|
18882
|
+
*/
|
|
18883
|
+
const ADD_ALL_LABEL = "Add all";
|
|
18884
|
+
const DONE_LABEL = "Done";
|
|
18885
|
+
const RESERVED_MODEL_LABELS = [ADD_ALL_LABEL, DONE_LABEL];
|
|
18886
|
+
/** `1 model` or `N models`. */
|
|
18887
|
+
function modelCount(count) {
|
|
18888
|
+
return `${count} model${count === 1 ? "" : "s"}`;
|
|
18889
|
+
}
|
|
18890
|
+
/** Load the saved provider, or tell the user it is gone and return undefined. */
|
|
18891
|
+
function loadProvider(ctx, providerId) {
|
|
18892
|
+
const settings = loadSettings();
|
|
18893
|
+
const provider = settings.customProviders.find((entry) => getCustomProviderId(entry.name) === providerId);
|
|
18894
|
+
if (!provider) {
|
|
18895
|
+
ctx.showError("Provider not found.");
|
|
18896
|
+
return;
|
|
18897
|
+
}
|
|
18898
|
+
return {
|
|
18899
|
+
settings,
|
|
18900
|
+
provider
|
|
18901
|
+
};
|
|
18902
|
+
}
|
|
18903
|
+
/** Ask the endpoint for its model list, with a spinner labelled `progressLabel` while the call runs. */
|
|
18904
|
+
async function listModelsWithProgress(ctx, provider, progressLabel, options = {}) {
|
|
18905
|
+
const stopProgress = showProgress(ctx.state, progressLabel);
|
|
18906
|
+
try {
|
|
18907
|
+
return await listCustomProviderModels(savedConnection(provider), options);
|
|
18908
|
+
} finally {
|
|
18909
|
+
stopProgress();
|
|
18910
|
+
}
|
|
18911
|
+
}
|
|
18912
|
+
/** Call the endpoint's model list and show the model count and latency, or the failure. */
|
|
18913
|
+
async function testConnectionFlow(ctx, providerId) {
|
|
18914
|
+
const loaded = loadProvider(ctx, providerId);
|
|
18915
|
+
if (!loaded) return;
|
|
18916
|
+
const result = await listModelsWithProgress(ctx, loaded.provider, `Testing connection to ${loaded.provider.url}`);
|
|
18917
|
+
if (!result.ok) {
|
|
18918
|
+
showCheckFailure(ctx, result.failure);
|
|
18919
|
+
return;
|
|
18920
|
+
}
|
|
18921
|
+
ctx.showInfo(`${loaded.provider.name} answered in ${result.latencyMs} ms and lists ${modelCount(result.models.length)}.`);
|
|
18922
|
+
}
|
|
18923
|
+
/** How long "Add model" waits for the endpoint's model list before asking for a typed ID. */
|
|
18924
|
+
const ADD_MODEL_LIST_TIMEOUT_MS = 3e3;
|
|
18925
|
+
/**
|
|
18926
|
+
* Add model IDs to a provider. When the endpoint lists models that are not
|
|
18927
|
+
* configured yet, they are offered in a picker, and its "Custom response" row
|
|
18928
|
+
* takes a typed ID. Picking one adds it and shows the rest again. When the
|
|
18929
|
+
* list call fails, times out or offers nothing new, the user types the ID with
|
|
18930
|
+
* no error shown: "Test connection" is where the reason is shown.
|
|
18931
|
+
*/
|
|
18932
|
+
async function addProviderModelFlow(ctx, providerId) {
|
|
18933
|
+
const loaded = loadProvider(ctx, providerId);
|
|
18934
|
+
if (!loaded) return;
|
|
18935
|
+
const listed = await listModelsWithProgress(ctx, loaded.provider, `Listing models from ${loaded.provider.url}`, { timeoutMs: ADD_MODEL_LIST_TIMEOUT_MS });
|
|
18936
|
+
const listedModels = listed.ok ? listed.models : [];
|
|
18937
|
+
if (endpointModelsToOffer(listedModels, loaded.provider, RESERVED_MODEL_LABELS).length === 0) {
|
|
18938
|
+
await typeModelIdFlow(ctx, providerId);
|
|
18939
|
+
return;
|
|
18940
|
+
}
|
|
18941
|
+
let cursorLabel;
|
|
18942
|
+
for (;;) {
|
|
18943
|
+
const current = loadProvider(ctx, providerId);
|
|
18944
|
+
if (!current) return;
|
|
18945
|
+
const { provider } = current;
|
|
18946
|
+
const available = endpointModelsToOffer(listedModels, provider, RESERVED_MODEL_LABELS);
|
|
18947
|
+
if (available.length === 0) return;
|
|
18948
|
+
const choice = (await askModalQuestion(ctx.state.ui, {
|
|
18949
|
+
question: `Add a model to ${provider.name}`,
|
|
18950
|
+
options: [
|
|
18951
|
+
{
|
|
18952
|
+
label: ADD_ALL_LABEL,
|
|
18953
|
+
description: `Add the ${modelCount(available.length)} below`
|
|
18954
|
+
},
|
|
18955
|
+
{
|
|
18956
|
+
label: DONE_LABEL,
|
|
18957
|
+
description: "Stop adding models"
|
|
18958
|
+
},
|
|
18959
|
+
...available.map((model) => ({ label: model }))
|
|
18960
|
+
],
|
|
18961
|
+
allowCustomResponse: true,
|
|
18962
|
+
selectedOptionLabel: cursorLabel
|
|
18963
|
+
}))?.trim();
|
|
18964
|
+
if (!choice || choice === DONE_LABEL) return;
|
|
18965
|
+
const picked = choice === ADD_ALL_LABEL ? available : [choice];
|
|
18966
|
+
const latest = loadProvider(ctx, providerId);
|
|
18967
|
+
if (!latest) return;
|
|
18968
|
+
const added = addModelsToCustomProviderInSettings(latest.settings, providerId, picked);
|
|
18969
|
+
if (added > 0) saveSettings(latest.settings);
|
|
18970
|
+
if (choice === ADD_ALL_LABEL) {
|
|
18971
|
+
ctx.showInfo(added > 0 ? `Added ${modelCount(added)} to ${provider.name}.` : `No models added: ${provider.name} already has every listed model.`);
|
|
18972
|
+
return;
|
|
18973
|
+
}
|
|
18974
|
+
ctx.showInfo(added > 0 ? `Added model: ${toCustomProviderModelId(provider.name, choice)}` : `No model added: ${provider.name} already has ${choice}.`);
|
|
18975
|
+
const index = available.indexOf(choice);
|
|
18976
|
+
if (index >= 0) cursorLabel = available[index + 1] ?? available[index - 1];
|
|
18977
|
+
}
|
|
18978
|
+
}
|
|
18979
|
+
/** How a header value appears in lists. Secret values are never shown. */
|
|
18980
|
+
function shownHeaderValue(header) {
|
|
18981
|
+
return header.secret === false ? header.value : "••••";
|
|
18982
|
+
}
|
|
18983
|
+
/**
|
|
18984
|
+
* List a provider's headers, add one, or remove one. The list is shown again
|
|
18985
|
+
* after each change until the user leaves with Esc.
|
|
18986
|
+
*/
|
|
18987
|
+
async function headersFlow(ctx, providerId) {
|
|
18988
|
+
for (;;) {
|
|
18989
|
+
const loaded = loadProvider(ctx, providerId);
|
|
18990
|
+
if (!loaded) return;
|
|
18991
|
+
const { provider } = loaded;
|
|
18992
|
+
const headers = provider.headers ?? [];
|
|
18993
|
+
const choice = await askSelect$1(ctx, `Headers for ${provider.name}`, [{
|
|
18994
|
+
label: "Add header",
|
|
18995
|
+
value: ADD_HEADER,
|
|
18996
|
+
description: "Send an extra header on every call"
|
|
18997
|
+
}, ...headers.map((header) => ({
|
|
18998
|
+
label: header.name,
|
|
18999
|
+
value: header.name,
|
|
19000
|
+
description: shownHeaderValue(header)
|
|
19001
|
+
}))]);
|
|
19002
|
+
if (!choice) return;
|
|
19003
|
+
if (choice === ADD_HEADER) {
|
|
19004
|
+
if (await addHeaderFlow(ctx, providerId) === "refused") return;
|
|
19005
|
+
continue;
|
|
19006
|
+
}
|
|
19007
|
+
if (await askSelect$1(ctx, `Remove the ${choice} header?`, [{
|
|
19008
|
+
label: "Remove",
|
|
19009
|
+
value: "remove",
|
|
19010
|
+
description: `Stop sending ${choice} to ${provider.name}`
|
|
19011
|
+
}]) !== "remove") continue;
|
|
19012
|
+
const latest = loadSettings();
|
|
19013
|
+
if (removeHeaderFromCustomProviderInSettings(latest, providerId, choice)) {
|
|
19014
|
+
saveSettings(latest);
|
|
19015
|
+
ctx.showInfo(`Removed header: ${choice}`);
|
|
19016
|
+
}
|
|
19017
|
+
}
|
|
19018
|
+
}
|
|
19019
|
+
/**
|
|
19020
|
+
* Ask for a header name, secret flag and value, then save the header.
|
|
19021
|
+
* The flag comes before the value so a secret value is typed into a masked input.
|
|
19022
|
+
* Returns whether the header was added, refused, or the user cancelled.
|
|
19023
|
+
*/
|
|
19024
|
+
async function addHeaderFlow(ctx, providerId) {
|
|
19025
|
+
const loaded = loadProvider(ctx, providerId);
|
|
19026
|
+
if (!loaded) return "refused";
|
|
19027
|
+
const { provider } = loaded;
|
|
19028
|
+
const name = await askText$2(ctx, "Header name");
|
|
19029
|
+
if (!name) return "cancelled";
|
|
19030
|
+
const nameProblem = customProviderHeaderProblem([...provider.headers ?? [], { name }], provider.authScheme);
|
|
19031
|
+
if (nameProblem) {
|
|
19032
|
+
ctx.showError(nameProblem);
|
|
19033
|
+
return "refused";
|
|
19034
|
+
}
|
|
19035
|
+
const visibility = await askSelect$1(ctx, `Is ${name} a secret?`, [{
|
|
19036
|
+
label: "Secret",
|
|
19037
|
+
value: "secret",
|
|
19038
|
+
description: "Hide the value while typing and in lists"
|
|
19039
|
+
}, {
|
|
19040
|
+
label: "Plain",
|
|
19041
|
+
value: "plain",
|
|
19042
|
+
description: "Show the value in lists"
|
|
19043
|
+
}]);
|
|
19044
|
+
if (!visibility) return "cancelled";
|
|
19045
|
+
const value = await askText$2(ctx, `Value for ${name}`, void 0, false, visibility === "secret");
|
|
19046
|
+
if (!value) return "cancelled";
|
|
19047
|
+
const settings = loadSettings();
|
|
19048
|
+
const problem = addHeaderToCustomProviderInSettings(settings, providerId, {
|
|
19049
|
+
name,
|
|
19050
|
+
value,
|
|
19051
|
+
secret: visibility === "secret"
|
|
19052
|
+
});
|
|
19053
|
+
if (problem) {
|
|
19054
|
+
ctx.showError(problem);
|
|
19055
|
+
return "refused";
|
|
19056
|
+
}
|
|
19057
|
+
saveSettings(settings);
|
|
19058
|
+
ctx.showInfo(`Added header: ${name}`);
|
|
19059
|
+
return "added";
|
|
19060
|
+
}
|
|
19061
|
+
const AUTH_SCHEME_OPTIONS = [{
|
|
19062
|
+
label: "Bearer token",
|
|
19063
|
+
value: "bearer",
|
|
19064
|
+
description: "Send the API key as Authorization: Bearer <key>",
|
|
19065
|
+
header: "Authorization: Bearer <key>"
|
|
19066
|
+
}, {
|
|
19067
|
+
label: "x-api-key header",
|
|
19068
|
+
value: "x-api-key",
|
|
19069
|
+
description: "Send the API key as x-api-key: <key>",
|
|
19070
|
+
header: "x-api-key: <key>"
|
|
19071
|
+
}];
|
|
19072
|
+
/** Choose how the provider sends its API key. */
|
|
19073
|
+
async function authSchemeFlow(ctx, providerId) {
|
|
19074
|
+
const loaded = loadProvider(ctx, providerId);
|
|
19075
|
+
if (!loaded) return;
|
|
19076
|
+
const { provider } = loaded;
|
|
19077
|
+
const current = AUTH_SCHEME_OPTIONS.find((option) => option.value === (provider.authScheme ?? "bearer"));
|
|
19078
|
+
const choice = await askSelect$1(ctx, `Auth scheme for ${provider.name}`, AUTH_SCHEME_OPTIONS, current?.label);
|
|
19079
|
+
const option = AUTH_SCHEME_OPTIONS.find((entry) => entry.value === choice);
|
|
19080
|
+
if (!option) return;
|
|
19081
|
+
const settings = loadSettings();
|
|
19082
|
+
const problem = setCustomProviderAuthSchemeInSettings(settings, providerId, option.value);
|
|
19083
|
+
if (problem) {
|
|
19084
|
+
ctx.showError(problem);
|
|
19085
|
+
return;
|
|
19086
|
+
}
|
|
19087
|
+
saveSettings(settings);
|
|
19088
|
+
ctx.showInfo(`${provider.name} now sends its API key as ${option.header}.`);
|
|
19089
|
+
}
|
|
19090
|
+
/**
|
|
19091
|
+
* The menu for one saved provider. New items are appended at the end so an
|
|
19092
|
+
* existing item keeps its position for anyone who reaches it by arrow count.
|
|
19093
|
+
*/
|
|
18733
19094
|
async function manageProviderFlow(ctx, providerId) {
|
|
18734
19095
|
const provider = loadSettings().customProviders.find((entry) => getCustomProviderId(entry.name) === providerId);
|
|
18735
19096
|
if (!provider) {
|
|
@@ -18740,7 +19101,7 @@ async function manageProviderFlow(ctx, providerId) {
|
|
|
18740
19101
|
{
|
|
18741
19102
|
label: "Add model",
|
|
18742
19103
|
value: "add-model",
|
|
18743
|
-
description: "
|
|
19104
|
+
description: "Pick a model the endpoint lists or type a model ID"
|
|
18744
19105
|
},
|
|
18745
19106
|
{
|
|
18746
19107
|
label: "Remove model",
|
|
@@ -18756,8 +19117,32 @@ async function manageProviderFlow(ctx, providerId) {
|
|
|
18756
19117
|
label: "Delete provider",
|
|
18757
19118
|
value: "delete-provider",
|
|
18758
19119
|
description: "Remove provider and all its model IDs"
|
|
19120
|
+
},
|
|
19121
|
+
{
|
|
19122
|
+
label: "Test connection",
|
|
19123
|
+
value: "test-connection",
|
|
19124
|
+
description: "Ask the endpoint for its model list"
|
|
19125
|
+
},
|
|
19126
|
+
{
|
|
19127
|
+
label: "Headers",
|
|
19128
|
+
value: "headers",
|
|
19129
|
+
description: "Add or remove headers sent on every call"
|
|
19130
|
+
},
|
|
19131
|
+
{
|
|
19132
|
+
label: "Auth scheme",
|
|
19133
|
+
value: "auth-scheme",
|
|
19134
|
+
description: "Choose how the API key is sent"
|
|
18759
19135
|
}
|
|
18760
19136
|
])) {
|
|
19137
|
+
case "test-connection":
|
|
19138
|
+
await testConnectionFlow(ctx, providerId);
|
|
19139
|
+
break;
|
|
19140
|
+
case "headers":
|
|
19141
|
+
await headersFlow(ctx, providerId);
|
|
19142
|
+
break;
|
|
19143
|
+
case "auth-scheme":
|
|
19144
|
+
await authSchemeFlow(ctx, providerId);
|
|
19145
|
+
break;
|
|
18761
19146
|
case "add-model":
|
|
18762
19147
|
await addProviderModelFlow(ctx, providerId);
|
|
18763
19148
|
break;
|
|
@@ -78,6 +78,8 @@ let util = require("util");
|
|
|
78
78
|
let _mastra_code_sdk_onboarding_packs = require("@mastra/code-sdk/onboarding/packs");
|
|
79
79
|
let _mastra_code_sdk_onboarding_custom_packs = require("@mastra/code-sdk/onboarding/custom-packs");
|
|
80
80
|
let _mastra_code_sdk_agents_model = require("@mastra/code-sdk/agents/model");
|
|
81
|
+
let _mastra_code_sdk_agents_custom_provider_check = require("@mastra/code-sdk/agents/custom-provider-check");
|
|
82
|
+
let _mastra_code_sdk_onboarding_custom_provider_headers = require("@mastra/code-sdk/onboarding/custom-provider-headers");
|
|
81
83
|
let _mastra_code_sdk_onboarding_custom_providers = require("@mastra/code-sdk/onboarding/custom-providers");
|
|
82
84
|
let _mastra_code_sdk_onboarding_om_settings = require("@mastra/code-sdk/onboarding/om-settings");
|
|
83
85
|
let _mastra_code_sdk_auth_index = require("@mastra/code-sdk/auth/index");
|
|
@@ -4493,6 +4495,7 @@ var AskQuestionDialogComponent = class AskQuestionDialogComponent extends _earen
|
|
|
4493
4495
|
input;
|
|
4494
4496
|
tui;
|
|
4495
4497
|
multiline = false;
|
|
4498
|
+
masked = false;
|
|
4496
4499
|
multiSelect = false;
|
|
4497
4500
|
allowEmptyInput = false;
|
|
4498
4501
|
defaultValue;
|
|
@@ -4518,6 +4521,7 @@ var AskQuestionDialogComponent = class AskQuestionDialogComponent extends _earen
|
|
|
4518
4521
|
this.onCancel = options.onCancel;
|
|
4519
4522
|
this.tui = options.tui;
|
|
4520
4523
|
this.multiline = Boolean(options.multiline);
|
|
4524
|
+
this.masked = Boolean(options.masked);
|
|
4521
4525
|
this.multiSelect = options.selectionMode === "multi_select";
|
|
4522
4526
|
this.allowEmptyInput = Boolean(options.allowEmptyInput);
|
|
4523
4527
|
this.defaultValue = options.defaultValue;
|
|
@@ -4585,6 +4589,7 @@ var AskQuestionDialogComponent = class AskQuestionDialogComponent extends _earen
|
|
|
4585
4589
|
useMultiline() {
|
|
4586
4590
|
return this.multiline && Boolean(this.tui);
|
|
4587
4591
|
}
|
|
4592
|
+
/** Add the text input, its hint and the default value. A masked prompt uses `MaskedInput`. */
|
|
4588
4593
|
buildInputMode() {
|
|
4589
4594
|
if (this.useMultiline()) {
|
|
4590
4595
|
const multilineInput = new MultilineInput(this.tui, getEditorTheme());
|
|
@@ -4597,7 +4602,7 @@ var AskQuestionDialogComponent = class AskQuestionDialogComponent extends _earen
|
|
|
4597
4602
|
};
|
|
4598
4603
|
this.input = multilineInput;
|
|
4599
4604
|
} else {
|
|
4600
|
-
this.input = new _earendil_works_pi_tui.Input();
|
|
4605
|
+
this.input = this.masked ? new MaskedInput() : new _earendil_works_pi_tui.Input();
|
|
4601
4606
|
this.input.onSubmit = (value) => {
|
|
4602
4607
|
const trimmed = value.trim();
|
|
4603
4608
|
if (trimmed || this.allowEmptyInput) this.onSubmit(trimmed);
|
|
@@ -4634,6 +4639,7 @@ var AskQuestionDialogComponent = class AskQuestionDialogComponent extends _earen
|
|
|
4634
4639
|
}
|
|
4635
4640
|
};
|
|
4636
4641
|
// src/tui/modal-question.ts
|
|
4642
|
+
/** Show a question dialog over the TUI and resolve with the answer, or null when the user cancels. */
|
|
4637
4643
|
function askModalQuestion(tui, options) {
|
|
4638
4644
|
return new Promise((resolve) => {
|
|
4639
4645
|
const question = new AskQuestionDialogComponent({
|
|
@@ -4641,6 +4647,7 @@ function askModalQuestion(tui, options) {
|
|
|
4641
4647
|
title: options.title,
|
|
4642
4648
|
options: options.options,
|
|
4643
4649
|
multiline: options.multiline,
|
|
4650
|
+
masked: options.masked,
|
|
4644
4651
|
tui,
|
|
4645
4652
|
allowEmptyInput: options.allowEmptyInput,
|
|
4646
4653
|
allowCustomResponse: options.allowCustomResponse,
|
|
@@ -15727,13 +15734,13 @@ async function handleSkillCommand(ctx, skillName, args) {
|
|
|
15727
15734
|
}
|
|
15728
15735
|
}
|
|
15729
15736
|
// src/tui/thread-title.ts
|
|
15730
|
-
const CONTROL_CHARACTER_PATTERN = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
15737
|
+
const CONTROL_CHARACTER_PATTERN$1 = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
15731
15738
|
function setCurrentThreadTitle(state, title) {
|
|
15732
|
-
const safeTitle = title ? (0, util.stripVTControlCharacters)(title).replace(CONTROL_CHARACTER_PATTERN, " ").trim() : void 0;
|
|
15739
|
+
const safeTitle = title ? (0, util.stripVTControlCharacters)(title).replace(CONTROL_CHARACTER_PATTERN$1, " ").trim() : void 0;
|
|
15733
15740
|
state.currentThreadTitle = safeTitle;
|
|
15734
15741
|
const appName = state.options.appName || "Mastra Code";
|
|
15735
15742
|
const cwd = (0, path.basename)(process.cwd());
|
|
15736
|
-
state.ui.terminal.setTitle(`${appName} - ${safeTitle || cwd}`.replace(CONTROL_CHARACTER_PATTERN, " "));
|
|
15743
|
+
state.ui.terminal.setTitle(`${appName} - ${safeTitle || cwd}`.replace(CONTROL_CHARACTER_PATTERN$1, " "));
|
|
15737
15744
|
}
|
|
15738
15745
|
// src/tui/commands/new.ts
|
|
15739
15746
|
async function handleNewCommand(ctx) {
|
|
@@ -18643,24 +18650,120 @@ function removeModelFromCustomProviderInSettings(settings, providerId, modelName
|
|
|
18643
18650
|
provider.models = provider.models.filter((model) => model !== modelName);
|
|
18644
18651
|
return provider.models.length < before;
|
|
18645
18652
|
}
|
|
18646
|
-
|
|
18653
|
+
/**
|
|
18654
|
+
* Add several model ids to a provider at once and return how many were new.
|
|
18655
|
+
* Ids already configured and blank ids are skipped.
|
|
18656
|
+
*/
|
|
18657
|
+
function addModelsToCustomProviderInSettings(settings, providerId, modelNames) {
|
|
18658
|
+
const provider = settings.customProviders.find((entry) => (0, _mastra_code_sdk_onboarding_settings.getCustomProviderId)(entry.name) === providerId);
|
|
18659
|
+
if (!provider) return 0;
|
|
18660
|
+
const before = provider.models.length;
|
|
18661
|
+
provider.models = [.../* @__PURE__ */ new Set([...provider.models, ...modelNames.map((model) => model.trim()).filter(Boolean)])];
|
|
18662
|
+
return provider.models.length - before;
|
|
18663
|
+
}
|
|
18664
|
+
/**
|
|
18665
|
+
* The model IDs from an endpoint's list that are worth offering to add.
|
|
18666
|
+
*
|
|
18667
|
+
* IDs are read the way `parseCustomProviders` reads saved models: trimmed, and
|
|
18668
|
+
* with a leading `<providerId>/` removed. Otherwise `acme/foo` would be saved,
|
|
18669
|
+
* read back as `foo`, and offered again forever. IDs already configured are
|
|
18670
|
+
* left out, and so are IDs equal to a label in `reservedLabels`, because the
|
|
18671
|
+
* menu matches picks by label and such an ID would trigger that action.
|
|
18672
|
+
*/
|
|
18673
|
+
function endpointModelsToOffer(listed, provider, reservedLabels) {
|
|
18674
|
+
const providerPrefix = `${(0, _mastra_code_sdk_onboarding_settings.getCustomProviderId)(provider.name)}/`;
|
|
18675
|
+
const offered = listed.map((model) => model.trim()).map((model) => model.startsWith(providerPrefix) ? model.slice(providerPrefix.length) : model).filter((model) => model.length > 0 && !provider.models.includes(model) && !reservedLabels.includes(model));
|
|
18676
|
+
return [...new Set(offered)];
|
|
18677
|
+
}
|
|
18678
|
+
/**
|
|
18679
|
+
* Change how a provider sends its API key. Returns why the change is refused,
|
|
18680
|
+
* or undefined once it is applied. A saved custom header may already use the
|
|
18681
|
+
* header the new scheme writes, so the headers are checked against it first.
|
|
18682
|
+
*/
|
|
18683
|
+
function setCustomProviderAuthSchemeInSettings(settings, providerId, authScheme) {
|
|
18684
|
+
const provider = settings.customProviders.find((entry) => (0, _mastra_code_sdk_onboarding_settings.getCustomProviderId)(entry.name) === providerId);
|
|
18685
|
+
if (!provider) return "Provider not found.";
|
|
18686
|
+
const problem = (0, _mastra_code_sdk_onboarding_custom_provider_headers.customProviderHeaderProblem)(provider.headers ?? [], authScheme);
|
|
18687
|
+
if (problem) return problem;
|
|
18688
|
+
provider.authScheme = authScheme;
|
|
18689
|
+
}
|
|
18690
|
+
/**
|
|
18691
|
+
* Add a custom header to a provider. Returns why the header is refused, or
|
|
18692
|
+
* undefined once it is added.
|
|
18693
|
+
*/
|
|
18694
|
+
function addHeaderToCustomProviderInSettings(settings, providerId, header) {
|
|
18695
|
+
const provider = settings.customProviders.find((entry) => (0, _mastra_code_sdk_onboarding_settings.getCustomProviderId)(entry.name) === providerId);
|
|
18696
|
+
if (!provider) return "Provider not found.";
|
|
18697
|
+
const next = {
|
|
18698
|
+
name: header.name.trim(),
|
|
18699
|
+
value: header.value.trim(),
|
|
18700
|
+
secret: header.secret ?? true
|
|
18701
|
+
};
|
|
18702
|
+
const headers = [...provider.headers ?? [], next];
|
|
18703
|
+
const problem = (0, _mastra_code_sdk_onboarding_custom_provider_headers.customProviderHeaderProblem)(headers, provider.authScheme);
|
|
18704
|
+
if (problem) return problem;
|
|
18705
|
+
provider.headers = headers;
|
|
18706
|
+
}
|
|
18707
|
+
/** Remove a custom header from a provider by name, ignoring case. Returns whether one was removed. */
|
|
18708
|
+
function removeHeaderFromCustomProviderInSettings(settings, providerId, headerName) {
|
|
18709
|
+
const provider = settings.customProviders.find((entry) => (0, _mastra_code_sdk_onboarding_settings.getCustomProviderId)(entry.name) === providerId);
|
|
18710
|
+
if (!provider?.headers) return false;
|
|
18711
|
+
const before = provider.headers.length;
|
|
18712
|
+
provider.headers = provider.headers.filter((header) => header.name.toLowerCase() !== headerName.toLowerCase());
|
|
18713
|
+
return provider.headers.length < before;
|
|
18714
|
+
}
|
|
18715
|
+
/** The origin of a URL, or the URL itself when it does not parse. */
|
|
18716
|
+
function urlOrigin(url) {
|
|
18717
|
+
try {
|
|
18718
|
+
return new URL(url).origin;
|
|
18719
|
+
} catch {
|
|
18720
|
+
return url;
|
|
18721
|
+
}
|
|
18722
|
+
}
|
|
18723
|
+
/**
|
|
18724
|
+
* Split a provider's headers for an edit that moves it from `previousUrl` to
|
|
18725
|
+
* `nextUrl`. A saved secret is never sent to a new origin unless the user
|
|
18726
|
+
* types it again, so secret headers are dropped when the origin changes.
|
|
18727
|
+
* A header saved without a `secret` flag counts as secret.
|
|
18728
|
+
*/
|
|
18729
|
+
function headersForCustomProviderUrlChange(headers, previousUrl, nextUrl) {
|
|
18730
|
+
if (urlOrigin(previousUrl) === urlOrigin(nextUrl)) return {
|
|
18731
|
+
kept: [...headers],
|
|
18732
|
+
removed: []
|
|
18733
|
+
};
|
|
18734
|
+
return {
|
|
18735
|
+
kept: headers.filter((header) => header.secret === false),
|
|
18736
|
+
removed: headers.filter((header) => header.secret !== false)
|
|
18737
|
+
};
|
|
18738
|
+
}
|
|
18739
|
+
/**
|
|
18740
|
+
* Ask for one line of text and return it trimmed, or null when it is empty or
|
|
18741
|
+
* the user cancels. `masked` hides the typed text, for secrets.
|
|
18742
|
+
*/
|
|
18743
|
+
async function askText$2(ctx, question, defaultValue, allowEmptyInput = false, masked = false) {
|
|
18647
18744
|
const trimmed = (await askModalQuestion(ctx.state.ui, {
|
|
18648
18745
|
question,
|
|
18649
18746
|
defaultValue,
|
|
18650
|
-
allowEmptyInput
|
|
18747
|
+
allowEmptyInput,
|
|
18748
|
+
masked
|
|
18651
18749
|
}))?.trim() ?? "";
|
|
18652
18750
|
return trimmed.length > 0 ? trimmed : null;
|
|
18653
18751
|
}
|
|
18654
18752
|
async function askOptionalText(ctx, question, defaultValue) {
|
|
18655
18753
|
return (await askText$2(ctx, `${question} (leave blank to skip)`, defaultValue, true))?.trim() || void 0;
|
|
18656
18754
|
}
|
|
18657
|
-
|
|
18755
|
+
/**
|
|
18756
|
+
* Ask the user to pick one option and return its value, or null on Esc.
|
|
18757
|
+
* `selectedLabel` starts the cursor on that option instead of the first one.
|
|
18758
|
+
*/
|
|
18759
|
+
async function askSelect$1(ctx, question, options, selectedLabel) {
|
|
18658
18760
|
const answer = await askModalQuestion(ctx.state.ui, {
|
|
18659
18761
|
question,
|
|
18660
18762
|
options: options.map((option) => ({
|
|
18661
18763
|
label: option.label,
|
|
18662
18764
|
description: option.description
|
|
18663
|
-
}))
|
|
18765
|
+
})),
|
|
18766
|
+
selectedOptionLabel: selectedLabel
|
|
18664
18767
|
});
|
|
18665
18768
|
return options.find((option) => option.label === answer)?.value ?? null;
|
|
18666
18769
|
}
|
|
@@ -18690,6 +18793,12 @@ async function createProviderFlow(ctx) {
|
|
|
18690
18793
|
ctx.showInfo(`Added custom provider: ${name}`);
|
|
18691
18794
|
await manageProviderFlow(ctx, providerId);
|
|
18692
18795
|
}
|
|
18796
|
+
/**
|
|
18797
|
+
* Rename a provider or change its URL or API key. Secret headers are dropped
|
|
18798
|
+
* when the new URL has another origin, see {@link headersForCustomProviderUrlChange}.
|
|
18799
|
+
* The rule lives here and not in `upsertCustomProviderInSettings`, which other
|
|
18800
|
+
* callers use as a plain upsert.
|
|
18801
|
+
*/
|
|
18693
18802
|
async function editProviderFlow(ctx, providerId) {
|
|
18694
18803
|
const settings = (0, _mastra_code_sdk_onboarding_settings.loadSettings)();
|
|
18695
18804
|
const provider = settings.customProviders.find((entry) => (0, _mastra_code_sdk_onboarding_settings.getCustomProviderId)(entry.name) === providerId);
|
|
@@ -18711,16 +18820,23 @@ async function editProviderFlow(ctx, providerId) {
|
|
|
18711
18820
|
return;
|
|
18712
18821
|
}
|
|
18713
18822
|
const apiKey = await askOptionalText(ctx, "API key", provider.apiKey);
|
|
18823
|
+
const { kept, removed } = headersForCustomProviderUrlChange(provider.headers ?? [], provider.url, url);
|
|
18714
18824
|
(0, _mastra_code_sdk_onboarding_custom_providers.upsertCustomProviderInSettings)(settings, {
|
|
18715
18825
|
...provider,
|
|
18716
18826
|
name,
|
|
18717
18827
|
url,
|
|
18718
|
-
apiKey
|
|
18828
|
+
apiKey,
|
|
18829
|
+
headers: kept
|
|
18719
18830
|
}, providerId);
|
|
18720
18831
|
(0, _mastra_code_sdk_onboarding_settings.saveSettings)(settings);
|
|
18721
18832
|
ctx.showInfo(`Updated custom provider: ${name}`);
|
|
18833
|
+
if (removed.length > 0) {
|
|
18834
|
+
const names = removed.map((header) => header.name).join(", ");
|
|
18835
|
+
ctx.showInfo(removed.length === 1 ? `Removed secret header ${names} because the base URL moved to another origin. Add it again under Headers.` : `Removed secret headers ${names} because the base URL moved to another origin. Add them again under Headers.`);
|
|
18836
|
+
}
|
|
18722
18837
|
}
|
|
18723
|
-
|
|
18838
|
+
/** Ask for one model ID and add it to the provider. */
|
|
18839
|
+
async function typeModelIdFlow(ctx, providerId) {
|
|
18724
18840
|
const settings = (0, _mastra_code_sdk_onboarding_settings.loadSettings)();
|
|
18725
18841
|
const provider = settings.customProviders.find((entry) => (0, _mastra_code_sdk_onboarding_settings.getCustomProviderId)(entry.name) === providerId);
|
|
18726
18842
|
if (!provider) {
|
|
@@ -18760,6 +18876,251 @@ async function removeProviderModelFlow(ctx, providerId) {
|
|
|
18760
18876
|
(0, _mastra_code_sdk_onboarding_settings.saveSettings)(settings);
|
|
18761
18877
|
ctx.showInfo(`Removed model: ${(0, _mastra_code_sdk_onboarding_settings.toCustomProviderModelId)(provider.name, modelName)}`);
|
|
18762
18878
|
}
|
|
18879
|
+
/** The connection a check uses: the provider exactly as saved. */
|
|
18880
|
+
function savedConnection(provider) {
|
|
18881
|
+
return {
|
|
18882
|
+
url: provider.url,
|
|
18883
|
+
apiKey: provider.apiKey,
|
|
18884
|
+
authScheme: provider.authScheme,
|
|
18885
|
+
headers: provider.headers
|
|
18886
|
+
};
|
|
18887
|
+
}
|
|
18888
|
+
const CONTROL_CHARACTERS = new RegExp(`${_mastra_code_sdk_onboarding_custom_provider_headers.CONTROL_CHARACTER_PATTERN.source}+`, "g");
|
|
18889
|
+
/**
|
|
18890
|
+
* Text that came from an endpoint, made safe to print on one line. Escape
|
|
18891
|
+
* sequences in it would act on the terminal instead of being shown, and line
|
|
18892
|
+
* breaks would split one message across several rows.
|
|
18893
|
+
*/
|
|
18894
|
+
function printableText(text) {
|
|
18895
|
+
return text.replace(CONTROL_CHARACTERS, " ").replace(/\s+/g, " ").trim();
|
|
18896
|
+
}
|
|
18897
|
+
/**
|
|
18898
|
+
* Show a failed check as the SDK reports it, with the upstream detail on its
|
|
18899
|
+
* own line. The SDK already cleans both, and cleaning again here keeps the
|
|
18900
|
+
* terminal safe if that ever changes.
|
|
18901
|
+
*/
|
|
18902
|
+
function showCheckFailure(ctx, failure) {
|
|
18903
|
+
const message = printableText(failure.message);
|
|
18904
|
+
const detail = failure.detail ? printableText(failure.detail) : "";
|
|
18905
|
+
ctx.showError(detail ? `${message}\n${detail}` : message);
|
|
18906
|
+
}
|
|
18907
|
+
/** The "Add header" action value, prefixed with NUL so no header name can equal it. */
|
|
18908
|
+
const ADD_HEADER = "\0add-header";
|
|
18909
|
+
/**
|
|
18910
|
+
* Labels of the actions in the "Add model" picker. The picker matches answers
|
|
18911
|
+
* by label, so a listed model ID equal to one of them is not offered.
|
|
18912
|
+
*/
|
|
18913
|
+
const ADD_ALL_LABEL = "Add all";
|
|
18914
|
+
const DONE_LABEL = "Done";
|
|
18915
|
+
const RESERVED_MODEL_LABELS = [ADD_ALL_LABEL, DONE_LABEL];
|
|
18916
|
+
/** `1 model` or `N models`. */
|
|
18917
|
+
function modelCount(count) {
|
|
18918
|
+
return `${count} model${count === 1 ? "" : "s"}`;
|
|
18919
|
+
}
|
|
18920
|
+
/** Load the saved provider, or tell the user it is gone and return undefined. */
|
|
18921
|
+
function loadProvider(ctx, providerId) {
|
|
18922
|
+
const settings = (0, _mastra_code_sdk_onboarding_settings.loadSettings)();
|
|
18923
|
+
const provider = settings.customProviders.find((entry) => (0, _mastra_code_sdk_onboarding_settings.getCustomProviderId)(entry.name) === providerId);
|
|
18924
|
+
if (!provider) {
|
|
18925
|
+
ctx.showError("Provider not found.");
|
|
18926
|
+
return;
|
|
18927
|
+
}
|
|
18928
|
+
return {
|
|
18929
|
+
settings,
|
|
18930
|
+
provider
|
|
18931
|
+
};
|
|
18932
|
+
}
|
|
18933
|
+
/** Ask the endpoint for its model list, with a spinner labelled `progressLabel` while the call runs. */
|
|
18934
|
+
async function listModelsWithProgress(ctx, provider, progressLabel, options = {}) {
|
|
18935
|
+
const stopProgress = showProgress(ctx.state, progressLabel);
|
|
18936
|
+
try {
|
|
18937
|
+
return await (0, _mastra_code_sdk_agents_custom_provider_check.listCustomProviderModels)(savedConnection(provider), options);
|
|
18938
|
+
} finally {
|
|
18939
|
+
stopProgress();
|
|
18940
|
+
}
|
|
18941
|
+
}
|
|
18942
|
+
/** Call the endpoint's model list and show the model count and latency, or the failure. */
|
|
18943
|
+
async function testConnectionFlow(ctx, providerId) {
|
|
18944
|
+
const loaded = loadProvider(ctx, providerId);
|
|
18945
|
+
if (!loaded) return;
|
|
18946
|
+
const result = await listModelsWithProgress(ctx, loaded.provider, `Testing connection to ${loaded.provider.url}`);
|
|
18947
|
+
if (!result.ok) {
|
|
18948
|
+
showCheckFailure(ctx, result.failure);
|
|
18949
|
+
return;
|
|
18950
|
+
}
|
|
18951
|
+
ctx.showInfo(`${loaded.provider.name} answered in ${result.latencyMs} ms and lists ${modelCount(result.models.length)}.`);
|
|
18952
|
+
}
|
|
18953
|
+
/** How long "Add model" waits for the endpoint's model list before asking for a typed ID. */
|
|
18954
|
+
const ADD_MODEL_LIST_TIMEOUT_MS = 3e3;
|
|
18955
|
+
/**
|
|
18956
|
+
* Add model IDs to a provider. When the endpoint lists models that are not
|
|
18957
|
+
* configured yet, they are offered in a picker, and its "Custom response" row
|
|
18958
|
+
* takes a typed ID. Picking one adds it and shows the rest again. When the
|
|
18959
|
+
* list call fails, times out or offers nothing new, the user types the ID with
|
|
18960
|
+
* no error shown: "Test connection" is where the reason is shown.
|
|
18961
|
+
*/
|
|
18962
|
+
async function addProviderModelFlow(ctx, providerId) {
|
|
18963
|
+
const loaded = loadProvider(ctx, providerId);
|
|
18964
|
+
if (!loaded) return;
|
|
18965
|
+
const listed = await listModelsWithProgress(ctx, loaded.provider, `Listing models from ${loaded.provider.url}`, { timeoutMs: ADD_MODEL_LIST_TIMEOUT_MS });
|
|
18966
|
+
const listedModels = listed.ok ? listed.models : [];
|
|
18967
|
+
if (endpointModelsToOffer(listedModels, loaded.provider, RESERVED_MODEL_LABELS).length === 0) {
|
|
18968
|
+
await typeModelIdFlow(ctx, providerId);
|
|
18969
|
+
return;
|
|
18970
|
+
}
|
|
18971
|
+
let cursorLabel;
|
|
18972
|
+
for (;;) {
|
|
18973
|
+
const current = loadProvider(ctx, providerId);
|
|
18974
|
+
if (!current) return;
|
|
18975
|
+
const { provider } = current;
|
|
18976
|
+
const available = endpointModelsToOffer(listedModels, provider, RESERVED_MODEL_LABELS);
|
|
18977
|
+
if (available.length === 0) return;
|
|
18978
|
+
const choice = (await askModalQuestion(ctx.state.ui, {
|
|
18979
|
+
question: `Add a model to ${provider.name}`,
|
|
18980
|
+
options: [
|
|
18981
|
+
{
|
|
18982
|
+
label: ADD_ALL_LABEL,
|
|
18983
|
+
description: `Add the ${modelCount(available.length)} below`
|
|
18984
|
+
},
|
|
18985
|
+
{
|
|
18986
|
+
label: DONE_LABEL,
|
|
18987
|
+
description: "Stop adding models"
|
|
18988
|
+
},
|
|
18989
|
+
...available.map((model) => ({ label: model }))
|
|
18990
|
+
],
|
|
18991
|
+
allowCustomResponse: true,
|
|
18992
|
+
selectedOptionLabel: cursorLabel
|
|
18993
|
+
}))?.trim();
|
|
18994
|
+
if (!choice || choice === DONE_LABEL) return;
|
|
18995
|
+
const picked = choice === ADD_ALL_LABEL ? available : [choice];
|
|
18996
|
+
const latest = loadProvider(ctx, providerId);
|
|
18997
|
+
if (!latest) return;
|
|
18998
|
+
const added = addModelsToCustomProviderInSettings(latest.settings, providerId, picked);
|
|
18999
|
+
if (added > 0) (0, _mastra_code_sdk_onboarding_settings.saveSettings)(latest.settings);
|
|
19000
|
+
if (choice === ADD_ALL_LABEL) {
|
|
19001
|
+
ctx.showInfo(added > 0 ? `Added ${modelCount(added)} to ${provider.name}.` : `No models added: ${provider.name} already has every listed model.`);
|
|
19002
|
+
return;
|
|
19003
|
+
}
|
|
19004
|
+
ctx.showInfo(added > 0 ? `Added model: ${(0, _mastra_code_sdk_onboarding_settings.toCustomProviderModelId)(provider.name, choice)}` : `No model added: ${provider.name} already has ${choice}.`);
|
|
19005
|
+
const index = available.indexOf(choice);
|
|
19006
|
+
if (index >= 0) cursorLabel = available[index + 1] ?? available[index - 1];
|
|
19007
|
+
}
|
|
19008
|
+
}
|
|
19009
|
+
/** How a header value appears in lists. Secret values are never shown. */
|
|
19010
|
+
function shownHeaderValue(header) {
|
|
19011
|
+
return header.secret === false ? header.value : "••••";
|
|
19012
|
+
}
|
|
19013
|
+
/**
|
|
19014
|
+
* List a provider's headers, add one, or remove one. The list is shown again
|
|
19015
|
+
* after each change until the user leaves with Esc.
|
|
19016
|
+
*/
|
|
19017
|
+
async function headersFlow(ctx, providerId) {
|
|
19018
|
+
for (;;) {
|
|
19019
|
+
const loaded = loadProvider(ctx, providerId);
|
|
19020
|
+
if (!loaded) return;
|
|
19021
|
+
const { provider } = loaded;
|
|
19022
|
+
const headers = provider.headers ?? [];
|
|
19023
|
+
const choice = await askSelect$1(ctx, `Headers for ${provider.name}`, [{
|
|
19024
|
+
label: "Add header",
|
|
19025
|
+
value: ADD_HEADER,
|
|
19026
|
+
description: "Send an extra header on every call"
|
|
19027
|
+
}, ...headers.map((header) => ({
|
|
19028
|
+
label: header.name,
|
|
19029
|
+
value: header.name,
|
|
19030
|
+
description: shownHeaderValue(header)
|
|
19031
|
+
}))]);
|
|
19032
|
+
if (!choice) return;
|
|
19033
|
+
if (choice === ADD_HEADER) {
|
|
19034
|
+
if (await addHeaderFlow(ctx, providerId) === "refused") return;
|
|
19035
|
+
continue;
|
|
19036
|
+
}
|
|
19037
|
+
if (await askSelect$1(ctx, `Remove the ${choice} header?`, [{
|
|
19038
|
+
label: "Remove",
|
|
19039
|
+
value: "remove",
|
|
19040
|
+
description: `Stop sending ${choice} to ${provider.name}`
|
|
19041
|
+
}]) !== "remove") continue;
|
|
19042
|
+
const latest = (0, _mastra_code_sdk_onboarding_settings.loadSettings)();
|
|
19043
|
+
if (removeHeaderFromCustomProviderInSettings(latest, providerId, choice)) {
|
|
19044
|
+
(0, _mastra_code_sdk_onboarding_settings.saveSettings)(latest);
|
|
19045
|
+
ctx.showInfo(`Removed header: ${choice}`);
|
|
19046
|
+
}
|
|
19047
|
+
}
|
|
19048
|
+
}
|
|
19049
|
+
/**
|
|
19050
|
+
* Ask for a header name, secret flag and value, then save the header.
|
|
19051
|
+
* The flag comes before the value so a secret value is typed into a masked input.
|
|
19052
|
+
* Returns whether the header was added, refused, or the user cancelled.
|
|
19053
|
+
*/
|
|
19054
|
+
async function addHeaderFlow(ctx, providerId) {
|
|
19055
|
+
const loaded = loadProvider(ctx, providerId);
|
|
19056
|
+
if (!loaded) return "refused";
|
|
19057
|
+
const { provider } = loaded;
|
|
19058
|
+
const name = await askText$2(ctx, "Header name");
|
|
19059
|
+
if (!name) return "cancelled";
|
|
19060
|
+
const nameProblem = (0, _mastra_code_sdk_onboarding_custom_provider_headers.customProviderHeaderProblem)([...provider.headers ?? [], { name }], provider.authScheme);
|
|
19061
|
+
if (nameProblem) {
|
|
19062
|
+
ctx.showError(nameProblem);
|
|
19063
|
+
return "refused";
|
|
19064
|
+
}
|
|
19065
|
+
const visibility = await askSelect$1(ctx, `Is ${name} a secret?`, [{
|
|
19066
|
+
label: "Secret",
|
|
19067
|
+
value: "secret",
|
|
19068
|
+
description: "Hide the value while typing and in lists"
|
|
19069
|
+
}, {
|
|
19070
|
+
label: "Plain",
|
|
19071
|
+
value: "plain",
|
|
19072
|
+
description: "Show the value in lists"
|
|
19073
|
+
}]);
|
|
19074
|
+
if (!visibility) return "cancelled";
|
|
19075
|
+
const value = await askText$2(ctx, `Value for ${name}`, void 0, false, visibility === "secret");
|
|
19076
|
+
if (!value) return "cancelled";
|
|
19077
|
+
const settings = (0, _mastra_code_sdk_onboarding_settings.loadSettings)();
|
|
19078
|
+
const problem = addHeaderToCustomProviderInSettings(settings, providerId, {
|
|
19079
|
+
name,
|
|
19080
|
+
value,
|
|
19081
|
+
secret: visibility === "secret"
|
|
19082
|
+
});
|
|
19083
|
+
if (problem) {
|
|
19084
|
+
ctx.showError(problem);
|
|
19085
|
+
return "refused";
|
|
19086
|
+
}
|
|
19087
|
+
(0, _mastra_code_sdk_onboarding_settings.saveSettings)(settings);
|
|
19088
|
+
ctx.showInfo(`Added header: ${name}`);
|
|
19089
|
+
return "added";
|
|
19090
|
+
}
|
|
19091
|
+
const AUTH_SCHEME_OPTIONS = [{
|
|
19092
|
+
label: "Bearer token",
|
|
19093
|
+
value: "bearer",
|
|
19094
|
+
description: "Send the API key as Authorization: Bearer <key>",
|
|
19095
|
+
header: "Authorization: Bearer <key>"
|
|
19096
|
+
}, {
|
|
19097
|
+
label: "x-api-key header",
|
|
19098
|
+
value: "x-api-key",
|
|
19099
|
+
description: "Send the API key as x-api-key: <key>",
|
|
19100
|
+
header: "x-api-key: <key>"
|
|
19101
|
+
}];
|
|
19102
|
+
/** Choose how the provider sends its API key. */
|
|
19103
|
+
async function authSchemeFlow(ctx, providerId) {
|
|
19104
|
+
const loaded = loadProvider(ctx, providerId);
|
|
19105
|
+
if (!loaded) return;
|
|
19106
|
+
const { provider } = loaded;
|
|
19107
|
+
const current = AUTH_SCHEME_OPTIONS.find((option) => option.value === (provider.authScheme ?? "bearer"));
|
|
19108
|
+
const choice = await askSelect$1(ctx, `Auth scheme for ${provider.name}`, AUTH_SCHEME_OPTIONS, current?.label);
|
|
19109
|
+
const option = AUTH_SCHEME_OPTIONS.find((entry) => entry.value === choice);
|
|
19110
|
+
if (!option) return;
|
|
19111
|
+
const settings = (0, _mastra_code_sdk_onboarding_settings.loadSettings)();
|
|
19112
|
+
const problem = setCustomProviderAuthSchemeInSettings(settings, providerId, option.value);
|
|
19113
|
+
if (problem) {
|
|
19114
|
+
ctx.showError(problem);
|
|
19115
|
+
return;
|
|
19116
|
+
}
|
|
19117
|
+
(0, _mastra_code_sdk_onboarding_settings.saveSettings)(settings);
|
|
19118
|
+
ctx.showInfo(`${provider.name} now sends its API key as ${option.header}.`);
|
|
19119
|
+
}
|
|
19120
|
+
/**
|
|
19121
|
+
* The menu for one saved provider. New items are appended at the end so an
|
|
19122
|
+
* existing item keeps its position for anyone who reaches it by arrow count.
|
|
19123
|
+
*/
|
|
18763
19124
|
async function manageProviderFlow(ctx, providerId) {
|
|
18764
19125
|
const provider = (0, _mastra_code_sdk_onboarding_settings.loadSettings)().customProviders.find((entry) => (0, _mastra_code_sdk_onboarding_settings.getCustomProviderId)(entry.name) === providerId);
|
|
18765
19126
|
if (!provider) {
|
|
@@ -18770,7 +19131,7 @@ async function manageProviderFlow(ctx, providerId) {
|
|
|
18770
19131
|
{
|
|
18771
19132
|
label: "Add model",
|
|
18772
19133
|
value: "add-model",
|
|
18773
|
-
description: "
|
|
19134
|
+
description: "Pick a model the endpoint lists or type a model ID"
|
|
18774
19135
|
},
|
|
18775
19136
|
{
|
|
18776
19137
|
label: "Remove model",
|
|
@@ -18786,8 +19147,32 @@ async function manageProviderFlow(ctx, providerId) {
|
|
|
18786
19147
|
label: "Delete provider",
|
|
18787
19148
|
value: "delete-provider",
|
|
18788
19149
|
description: "Remove provider and all its model IDs"
|
|
19150
|
+
},
|
|
19151
|
+
{
|
|
19152
|
+
label: "Test connection",
|
|
19153
|
+
value: "test-connection",
|
|
19154
|
+
description: "Ask the endpoint for its model list"
|
|
19155
|
+
},
|
|
19156
|
+
{
|
|
19157
|
+
label: "Headers",
|
|
19158
|
+
value: "headers",
|
|
19159
|
+
description: "Add or remove headers sent on every call"
|
|
19160
|
+
},
|
|
19161
|
+
{
|
|
19162
|
+
label: "Auth scheme",
|
|
19163
|
+
value: "auth-scheme",
|
|
19164
|
+
description: "Choose how the API key is sent"
|
|
18789
19165
|
}
|
|
18790
19166
|
])) {
|
|
19167
|
+
case "test-connection":
|
|
19168
|
+
await testConnectionFlow(ctx, providerId);
|
|
19169
|
+
break;
|
|
19170
|
+
case "headers":
|
|
19171
|
+
await headersFlow(ctx, providerId);
|
|
19172
|
+
break;
|
|
19173
|
+
case "auth-scheme":
|
|
19174
|
+
await authSchemeFlow(ctx, providerId);
|
|
19175
|
+
break;
|
|
18791
19176
|
case "add-model":
|
|
18792
19177
|
await addProviderModelFlow(ctx, providerId);
|
|
18793
19178
|
break;
|
package/dist/tui.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_tui = require("./tui-
|
|
2
|
+
const require_tui = require("./tui-vycpsgSv.cjs");
|
|
3
3
|
let _mastra_code_sdk_theme_palette = require("@mastra/code-sdk/theme-palette");
|
|
4
4
|
exports.AssistantMessageComponent = require_tui.AssistantMessageComponent;
|
|
5
5
|
exports.LoginDialogComponent = require_tui.LoginDialogComponent;
|
package/dist/tui.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { h as AssistantMessageComponent, c as LoginDialogComponent, s as LoginSelectorComponent, t as MastraTUI, m as ModelSelectorComponent, l as OMProgressComponent, p as ToolExecutionComponentEnhanced, f as UserMessageComponent, v as applyThemeMode, d as createTUIState, u as formatOMStatus, y as getEditorTheme, b as getMarkdownTheme, x as getThemeMode, S as mastra, C as mastraBrand, w as theme } from "./tui-
|
|
1
|
+
export { h as AssistantMessageComponent, c as LoginDialogComponent, s as LoginSelectorComponent, t as MastraTUI, m as ModelSelectorComponent, l as OMProgressComponent, p as ToolExecutionComponentEnhanced, f as UserMessageComponent, v as applyThemeMode, d as createTUIState, u as formatOMStatus, y as getEditorTheme, b as getMarkdownTheme, x as getThemeMode, S as mastra, C as mastraBrand, w as theme } from "./tui-DhXpcMRs.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mastracode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -107,17 +107,17 @@
|
|
|
107
107
|
"yaml": "^2.9.1",
|
|
108
108
|
"zod": "^4.6.7",
|
|
109
109
|
"@mastra/agent-browser": "0.7.0",
|
|
110
|
-
"@mastra/code-sdk": "^1.22.0-alpha.
|
|
110
|
+
"@mastra/code-sdk": "^1.22.0-alpha.1",
|
|
111
|
+
"@mastra/core": "1.87.0-alpha.1",
|
|
111
112
|
"@mastra/duckdb": "1.19.2",
|
|
112
113
|
"@mastra/fastembed": "1.4.0",
|
|
113
|
-
"@mastra/core": "1.87.0-alpha.0",
|
|
114
114
|
"@mastra/github-signals": "0.5.4",
|
|
115
115
|
"@mastra/libsql": "1.33.0-alpha.0",
|
|
116
116
|
"@mastra/mcp": "2.11.0",
|
|
117
117
|
"@mastra/memory": "1.41.3",
|
|
118
118
|
"@mastra/observability": "1.24.4-alpha.0",
|
|
119
|
-
"@mastra/schema-compat": "1.4.1",
|
|
120
119
|
"@mastra/pg": "1.39.0-alpha.0",
|
|
120
|
+
"@mastra/schema-compat": "1.4.1",
|
|
121
121
|
"@mastra/stagehand": "0.4.1",
|
|
122
122
|
"@mastra/tavily": "1.1.4"
|
|
123
123
|
},
|