@openeryc/pi-coding-agent 0.75.56 → 0.75.57

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.
@@ -4003,11 +4003,10 @@ export class InteractiveMode {
4003
4003
  this.showModelHub("manage");
4004
4004
  return;
4005
4005
  }
4006
- // models.json apiKey is opaque (env/command/literal); do not surface the raw value
4007
4006
  existing = {
4008
4007
  providerId: options.providerId,
4009
4008
  baseUrl: listed.baseUrl ?? "",
4010
- apiKey: "",
4009
+ apiKey: listed.apiKey ?? "",
4011
4010
  models: listed.modelIds.map((id) => ({ id, name: id })),
4012
4011
  };
4013
4012
  }
@@ -4032,31 +4031,28 @@ export class InteractiveMode {
4032
4031
  this.ui.requestRender();
4033
4032
  };
4034
4033
  try {
4035
- let providerId = existing?.providerId ?? "";
4036
- if (!isEdit) {
4037
- const rawName = (await dialog.showPrompt("Provider name/id (e.g. ollama, agnes):", existing?.providerId ?? "ollama")).trim();
4038
- providerId = slugifyProviderId(rawName);
4039
- if (!providerId) {
4040
- throw new Error("Provider name cannot be empty.");
4041
- }
4042
- if (BUILT_IN_MODEL_PROVIDERS.has(providerId) && options.target === "openai_compatible") {
4043
- throw new Error(`"${providerId}" is a built-in provider. Use a different name, or add it via Manage → models.json override.`);
4044
- }
4034
+ const rawName = (await dialog.showPrompt(isEdit ? "Provider name/id:" : "Provider name/id (e.g. ollama, agnes):", existing?.providerId ?? "ollama")).trim();
4035
+ const providerId = slugifyProviderId(rawName);
4036
+ if (!providerId) {
4037
+ throw new Error("Provider name cannot be empty.");
4038
+ }
4039
+ if (BUILT_IN_MODEL_PROVIDERS.has(providerId) && options.target === "openai_compatible") {
4040
+ throw new Error(`"${providerId}" is a built-in provider. Use a different name, or add it via Manage → models.json override.`);
4045
4041
  }
4046
4042
  const baseUrl = (await dialog.showPrompt("Enter base URL:", existing?.baseUrl || "http://localhost:11434/v1")).trim();
4047
4043
  if (!baseUrl) {
4048
4044
  throw new Error("Base URL cannot be empty.");
4049
4045
  }
4050
4046
  const apiKeyPrompt = options.target === "models_json"
4051
- ? "API key (literal, env var name, or !command; blank = not-needed):"
4052
- : "Enter API key (or leave blank for local endpoints):";
4047
+ ? isEdit
4048
+ ? "API key (literal/env/!command; blank keeps current):"
4049
+ : "API key (literal, env var name, or !command; blank = not-needed):"
4050
+ : isEdit
4051
+ ? "API key (blank keeps current; type not-needed for local):"
4052
+ : "Enter API key (or leave blank for local endpoints):";
4053
4053
  const apiKey = (await dialog.showPrompt(apiKeyPrompt, existing?.apiKey === "not-needed" ? "" : (existing?.apiKey ?? ""))).trim();
4054
- // On models.json edit, blank keeps the existing apiKey field (not rewritten).
4055
- const effectiveApiKey = apiKey
4056
- ? apiKey
4057
- : isEdit && options.target === "models_json"
4058
- ? undefined
4059
- : "not-needed";
4054
+ // Blank on edit keeps the existing apiKey (models.json and openai_compatible).
4055
+ const effectiveApiKey = apiKey ? apiKey : isEdit ? undefined : "not-needed";
4060
4056
  dialog.showInfo([theme.fg("muted", "Discovering models from /models ...")]);
4061
4057
  this.ui.requestRender();
4062
4058
  const discovered = await fetchOpenAICompatibleModels(baseUrl, effectiveApiKey);
@@ -4134,8 +4130,8 @@ export class InteractiveMode {
4134
4130
  .map((id) => ({ id, name: id }));
4135
4131
  }
4136
4132
  if (options.target === "openai_compatible") {
4137
- const storedKey = effectiveApiKey ?? "not-needed";
4138
- // Replace previous id if renaming isn't supported (edit keeps id)
4133
+ const storedKey = effectiveApiKey ?? (isEdit && existing?.apiKey ? existing.apiKey : "not-needed");
4134
+ // Rename: drop old id if the name changed
4139
4135
  if (isEdit && existing && existing.providerId !== providerId) {
4140
4136
  this.session.modelRegistry.authStorage.remove(existing.providerId);
4141
4137
  }
@@ -4156,7 +4152,7 @@ export class InteractiveMode {
4156
4152
  await this.completeProviderAuthentication(providerId, baseUrl, "api_key", previousModel);
4157
4153
  }
4158
4154
  else {
4159
- this.session.modelRegistry.upsertProviderInModelsJson(providerId, {
4155
+ const writeConfig = {
4160
4156
  baseUrl,
4161
4157
  ...(effectiveApiKey !== undefined ? { apiKey: effectiveApiKey } : {}),
4162
4158
  api: "openai-completions",
@@ -4166,7 +4162,13 @@ export class InteractiveMode {
4166
4162
  reasoning: false,
4167
4163
  input: ["text"],
4168
4164
  })),
4169
- });
4165
+ };
4166
+ if (isEdit && existing && existing.providerId !== providerId) {
4167
+ this.session.modelRegistry.renameProviderInModelsJson(existing.providerId, providerId, writeConfig);
4168
+ }
4169
+ else {
4170
+ this.session.modelRegistry.upsertProviderInModelsJson(providerId, writeConfig);
4171
+ }
4170
4172
  restoreEditor();
4171
4173
  await this.updateAvailableProviderCount();
4172
4174
  // Prefer selecting first model if no real model yet