@goodandready/dsh-key-rotation 0.8.11 → 0.8.13

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.
@@ -0,0 +1,55 @@
1
+ // lib/sandbox-service.js — sandbox runner and cache service
2
+ import { LastTestCache, SandboxRunner } from './sandbox.js';
3
+
4
+ export function createSandboxService({ getRuntime }) {
5
+ let sandboxRunner = null;
6
+ let defaultCtx = null;
7
+ const lastTestCache = new LastTestCache();
8
+
9
+ function ensureSandboxRunner(ctx) {
10
+ if (ctx) defaultCtx = ctx;
11
+ if (sandboxRunner) return sandboxRunner;
12
+ function resolveBaseUrl(providerOrRef) {
13
+ try {
14
+ let provider = providerOrRef;
15
+ const rt = typeof getRuntime === 'function' ? getRuntime() : null;
16
+ const pool = rt?.poolByRef?.get(providerOrRef);
17
+ if (pool?.base) provider = pool.base;
18
+ else if (pool?.provider) provider = pool.provider;
19
+
20
+ const c = ctx || defaultCtx;
21
+ const pInfo = c?.llm?.getProvider?.(provider);
22
+ if (pInfo && (pInfo.baseUrl || pInfo.endpoint || pInfo.url)) {
23
+ return String(pInfo.baseUrl || pInfo.endpoint || pInfo.url);
24
+ }
25
+ for (const info of (c?.llm?.listProviders?.() || [])) {
26
+ if (info && (info.id === provider || info.name === provider)) {
27
+ const u = info.baseUrl || info.endpoint || info.url;
28
+ if (u) return String(u);
29
+ }
30
+ }
31
+ const ns = c?.get ? c.get('llm-pi-ai') : null;
32
+ const list = ns && (ns.providers || (ns.config && ns.config.providers) || []);
33
+ if (Array.isArray(list)) {
34
+ const hit = list.find((p) => p && (p.id === provider || p.name === provider || (Array.isArray(p.aliases) && p.aliases.includes(provider))));
35
+ const base = hit && (hit.baseUrl || hit.endpoint || hit.url);
36
+ if (base) return String(base);
37
+ }
38
+ return null;
39
+ } catch (_) {
40
+ return null;
41
+ }
42
+ }
43
+ sandboxRunner = new SandboxRunner({ fetchImpl: globalThis.fetch, resolveBaseUrl });
44
+ return sandboxRunner;
45
+ }
46
+
47
+ async function probeRef(ref, key) {
48
+ const runner = ensureSandboxRunner();
49
+ const result = await runner.probeModels(ref, key);
50
+ lastTestCache.set(ref, { ...result, at: Date.now() });
51
+ return result;
52
+ }
53
+
54
+ return { ensureSandboxRunner, probeRef, lastTestCache };
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-key-rotation",
3
- "version": "0.8.11",
3
+ "version": "0.8.13",
4
4
  "packageManager": "pnpm@10.33.2",
5
5
  "description": "Per-provider API key rotation for DeepSeek Harness: a key pool per provider, auto-created clone routes, and switching to the next key on quota/rate-limit errors. Includes a Settings section (Key Rotation) to edit the key pools, cooldown and switch codes.",
6
6
  "keywords": [
@@ -33,6 +33,9 @@
33
33
  "lib",
34
34
  "cordis.patch.yml",
35
35
  "README.md",
36
+ "README.zh.md",
37
+ "README.ru.md",
38
+ "CHANGELOG.md",
36
39
  "LICENSE"
37
40
  ],
38
41
  "dsh": {