@edgehero/pi-dispatch 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,7 +33,7 @@ import { egressEnv } from "./egress.mjs";
33
33
  import { forgeSpec } from "./forges.mjs";
34
34
  import { apiKeyVariable } from "./provider-key.mjs";
35
35
  import { isDeterminateFsCode } from "./transient.mjs";
36
- import { KEYLESS_HOW, keylessVerdict } from "./model-endpoints.mjs";
36
+ import { KEYLESS_HOW, keylessVerdict, providerRenameHint, readOverlayModels, RENAMED_PROVIDERS } from "./model-endpoints.mjs";
37
37
  import { KEYLESS_ENV_NAME } from "./reserved-env.mjs";
38
38
 
39
39
  function configError(message) {
@@ -161,7 +161,7 @@ export function resolveProviderCredential({ provider, hostEnv, authFromPi = fals
161
161
  error.code = unreadable.code;
162
162
  throw error;
163
163
  }
164
- throw configError(unknownProviderMessage(provider));
164
+ throw configError(unknownProviderMessage(provider, hintOverlay(provider, modelEndpoints, hostEnv)));
165
165
  }
166
166
  const held = candidates
167
167
  .map((name) => [name, hostEnv[name]])
@@ -209,8 +209,24 @@ export function keylessEndpointsFor(provider, modelEndpoints) {
209
209
  return verdict.keyless ? verdict.endpoints : null;
210
210
  }
211
211
 
212
- function unknownProviderMessage(provider) {
213
- return `pi has no provider "${provider}", so there is no key variable to give it a key. Use one of pi's provider ids with its key in the worker environment or in pi's auth.json, or, ${KEYLESS_HOW}.`;
212
+ function unknownProviderMessage(provider, overlay = {}) {
213
+ return `pi has no provider "${provider}", so there is no key variable to give it a key.${providerRenameHint(provider, { ...overlay, piProviders: piProviders() })} Use one of pi's provider ids with its key in the worker environment or in pi's auth.json, or, ${KEYLESS_HOW}.`;
214
+ }
215
+
216
+ /**
217
+ * The overlay models.json the rename hint is judged on (issue #587's review): the pickup's snapshot when it read one, else
218
+ * the overlay itself, read here, only for an id pi renamed. The snapshot reads the overlay only when an endpoint is
219
+ * declared, so a full custom provider under the old id, with no endpoint, was told "did you mean". A read that fails
220
+ * is `overlayUnread`: no guess.
221
+ */
222
+ function hintOverlay(provider, modelEndpoints, hostEnv) {
223
+ if (modelEndpoints?.models) return { models: modelEndpoints.models };
224
+ if (!Object.hasOwn(RENAMED_PROVIDERS, provider)) return {};
225
+ try {
226
+ return { models: readOverlayModels(hostEnv?.PI_GLOBAL_PI_DIR) };
227
+ } catch {
228
+ return { overlayUnread: true };
229
+ }
214
230
  }
215
231
 
216
232
  function defaultAgentDir(hostEnv) {
@@ -524,13 +540,15 @@ export function buildContainerEnv({ provider, model, maxTurns, maxTokens, maxCos
524
540
  if (exitAuth === true) env.PI_EXIT_AUTH = "stdin";
525
541
  else delete env.PI_EXIT_AUTH;
526
542
 
527
- // Issue #500: the runner sets these two in its own environment, for its child processes, and no value from outside
543
+ // Issue #500: the runner sets these in its own environment, for its child processes, and no value from outside
528
544
  // may arrive first. Both lists refuse them upstream (config.mjs for PI_FORWARD_ENV, the triggers loader for
529
545
  // run.secrets, through RUNNER_ENV_NAMES); this is the line that holds if either refusal is ever bypassed.
530
546
  // env-internal PI_DISPATCH_CHILD_LEDGER: set by the runner inside the container, never by the worker, so removed here.
531
547
  delete env.PI_DISPATCH_CHILD_LEDGER;
532
548
  // env-internal PI_DISPATCH_RUNNER_PID: set by the runner inside the container, never by the worker, so removed here.
533
549
  delete env.PI_DISPATCH_RUNNER_PID;
550
+ // env-internal PI_DISPATCH_PRICE_TABLE: set by the runner inside the container, never by the worker, so removed here.
551
+ delete env.PI_DISPATCH_PRICE_TABLE;
534
552
 
535
553
  // Forge-backed jobs, and local cron jobs that opted in via run.github. Other local-folder jobs have
536
554
  // no token (CONST-TOKEN-SCOPED-PER-JOB). The mint goes into BOTH of its forge's variables because