@openchamber/web 1.19.0 → 1.20.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.
- package/dist/assets/{CodeMirrorCommentWidgets-DAvopJvy.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
- package/dist/assets/{CommitSection-D9cV-qR9.js → CommitSection-C-F3AX6D.js} +1 -1
- package/dist/assets/{DiagramEditor-B9NCadU7.js → DiagramEditor-BPECg1jS.js} +1 -1
- package/dist/assets/DiagramView-D0YNMix8.js +1 -0
- package/dist/assets/DiffView-BHWaMYCC.js +4 -0
- package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
- package/dist/assets/{GitView-DsWXqWx3.js → GitView-Rp8P1KEI.js} +4 -4
- package/dist/assets/{JsonTreeView-h4dHASlq.js → JsonTreeView-KnXFN2A-.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-n0ikH-xm.js → MarkdownImageGallery-BMn3mtor.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
- package/dist/assets/{OnboardingScreen-CDjgzxEe.js → OnboardingScreen-CenIeD4v.js} +1 -1
- package/dist/assets/{PatchDiff-jPKTJje5.js → PatchDiff-BzVOVog8.js} +1 -1
- package/dist/assets/{PierreDiffViewer-D_Gt4A_6.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
- package/dist/assets/PlanView-Czu1KMJa.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
- package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
- package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
- package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
- package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-B37yB9jZ.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
- package/dist/assets/{WalkthroughView-Bxun3k66.js → WalkthroughView-CaSYE0lw.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DYFv_yZS.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
- package/dist/assets/{contextPanelEmbeddedChat-BO1wRpaN.js → contextPanelEmbeddedChat-BEARQjgn.js} +1 -1
- package/dist/assets/de-DFdX3ABv.js +9 -0
- package/dist/assets/es-iC-FKvV9.js +15 -0
- package/dist/assets/fr-BBbi_1AL.js +13 -0
- package/dist/assets/{index-BSvmTvZl.js → index-BiEgzzkg.js} +1 -1
- package/dist/assets/index-Cwmuwk3V.js +7 -0
- package/dist/assets/index-GNm1wgUH.css +1 -0
- package/dist/assets/{isDiffPlainText-DwHKxDYc.js → isDiffPlainText-BG53Ixxy.js} +1 -1
- package/dist/assets/{isFilePlainText-Dwq6ILxo.js → isFilePlainText-BbV-39jl.js} +1 -1
- package/dist/assets/ja-DQLQJL2J.js +15 -0
- package/dist/assets/ko-BeElEB4Y.js +15 -0
- package/dist/assets/main-Dpzo18z7.js +2 -0
- package/dist/assets/main-WMjtYzJs.js +921 -0
- package/dist/assets/markdownCore--tDmyI_v.js +2 -0
- package/dist/assets/miniChat-ldEghBLB.js +2 -0
- package/dist/assets/mobile-Dk-VGreF.js +2 -0
- package/dist/assets/{patchFileDiff-BEDPDypx.js → patchFileDiff-BcFaMtMu.js} +2 -2
- package/dist/assets/pl-CLHt2_vV.js +15 -0
- package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
- package/dist/assets/{renderMobileApp-BiMbzPq9.js → renderMobileApp-CDfHS5rr.js} +7 -7
- package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
- package/dist/assets/{scheduledTasksApi-01zzfzqH.js → scheduledTasksApi-BFSlqgnG.js} +1 -1
- package/dist/assets/{shikiHighlight-DXYW46vW.js → shikiHighlight-DCT2Sq_z.js} +1 -1
- package/dist/assets/uk-PhsC-c4-.js +15 -0
- package/dist/assets/{useAppFontEffects-CbzHzFop.js → useAppFontEffects-B53Rb6m7.js} +166 -159
- package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
- package/dist/assets/{vendor-base-ui-BYlZTzrw.js → vendor-base-ui-DsHmyMwp.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-CiAYDJXN.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
- package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
- package/dist/assets/{web-components-DCLjCO9n.js → web-components-pcwCTWjC.js} +4 -4
- package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
- package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
- package/dist/index.html +5 -4
- package/dist/mini-chat.html +4 -3
- package/dist/mobile.html +4 -3
- package/package.json +3 -5
- package/server/index.js +36 -0
- package/server/lib/agent-memory/project-resolution.js +10 -1
- package/server/lib/agent-memory/project-resolution.test.js +9 -0
- package/server/lib/agent-memory/runtime.js +7 -2
- package/server/lib/dictation/DOCUMENTATION.md +32 -8
- package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
- package/server/lib/dictation/local/worker-process.js +2 -2
- package/server/lib/dictation/openai-compatible-session.js +3 -2
- package/server/lib/dictation/stream-manager.js +77 -34
- package/server/lib/dictation/stream-manager.test.js +60 -2
- package/server/lib/fs/routes.test.js +76 -0
- package/server/lib/git/routes.js +43 -0
- package/server/lib/git/service.js +85 -5
- package/server/lib/git/service.test.js +93 -0
- package/server/lib/opencode/DOCUMENTATION.md +6 -2
- package/server/lib/opencode/feature-routes-runtime.js +5 -9
- package/server/lib/opencode/lifecycle.js +202 -26
- package/server/lib/opencode/lifecycle.test.js +179 -1
- package/server/lib/opencode/providers.js +9 -4
- package/server/lib/opencode/providers.test.js +27 -0
- package/server/lib/opencode/restart-session-recovery.test.js +59 -0
- package/server/lib/opencode/session-runtime.js +39 -2
- package/server/lib/opencode/session-runtime.test.js +74 -0
- package/server/lib/opencode/settings-helpers.js +15 -0
- package/server/lib/opencode/settings-helpers.test.js +22 -0
- package/server/lib/opencode/settings-normalization-runtime.js +3 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
- package/server/lib/opencode/settings-runtime.js +32 -10
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/skill-routes.js +29 -73
- package/server/lib/opencode/skill-routes.test.js +2 -5
- package/server/lib/project-context/DOCUMENTATION.md +2 -0
- package/server/lib/project-context/runtime.js +7 -2
- package/server/lib/projects/project-config.js +7 -2
- package/server/lib/quota/DOCUMENTATION.md +1 -1
- package/server/lib/quota/providers/claude/index.js +2 -2
- package/server/lib/quota/providers/command-code.js +1 -1
- package/server/lib/quota/providers/command-code.test.js +13 -0
- package/server/lib/quota/providers/index.js +12 -4
- package/server/lib/quota/providers/zai.js +26 -6
- package/server/lib/quota/providers/zai.test.js +33 -0
- package/server/lib/session-knowledge/DOCUMENTATION.md +2 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
- package/server/lib/skills-catalog/cache.js +120 -1
- package/server/lib/skills-catalog/cache.test.js +77 -0
- package/server/lib/skills-catalog/curated-sources.js +21 -5
- package/server/lib/skills-catalog/curated-sources.test.js +4 -4
- package/server/lib/skills-catalog/disk-cache.js +52 -0
- package/server/lib/skills-catalog/github-meta.js +139 -0
- package/server/lib/skills-catalog/github-meta.test.js +71 -0
- package/server/lib/skills-catalog/source.js +0 -5
- package/server/lib/small-model/DOCUMENTATION.md +74 -6
- package/server/lib/small-model/call.js +46 -12
- package/server/lib/small-model/call.test.js +79 -0
- package/server/lib/small-model/index.js +51 -8
- package/server/lib/small-model/index.test.js +73 -3
- package/server/lib/small-model/routes.js +1 -1
- package/server/lib/small-model/runtime-providers.js +156 -0
- package/server/lib/small-model/runtime-providers.test.js +112 -0
- package/dist/assets/DiagramView-LKGBwf4G.js +0 -1
- package/dist/assets/DiffView-BWNq-0ov.js +0 -4
- package/dist/assets/FilesView-DB-Q0Gkz.js +0 -14
- package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +0 -12
- package/dist/assets/PlanView-UvuxIl9-.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +0 -1
- package/dist/assets/SettingsView-3B9VN6Ys.js +0 -28
- package/dist/assets/SettingsWindow-CqQNDKNd.js +0 -1
- package/dist/assets/ToolOutputDialog-PmjlAxVE.js +0 -15
- package/dist/assets/ToolPartDiffPreview-B34Xw9wq.js +0 -8
- package/dist/assets/de-DbV6CLxv.js +0 -9
- package/dist/assets/es-CVDlyzZ4.js +0 -15
- package/dist/assets/fr-Czc-p0g-.js +0 -13
- package/dist/assets/index-1OhiMDBz.css +0 -1
- package/dist/assets/index-DzriVon2.js +0 -7
- package/dist/assets/ja-dwc9NM_S.js +0 -15
- package/dist/assets/ko-Ds1DZ8FX.js +0 -15
- package/dist/assets/main-BF51IOVF.js +0 -921
- package/dist/assets/main-D7UPARut.js +0 -2
- package/dist/assets/markdownCore-BgeBDwD3.js +0 -2
- package/dist/assets/miniChat-BISXSGOo.js +0 -2
- package/dist/assets/mobile-BnYxVuvw.js +0 -2
- package/dist/assets/pl-CLiTO7i-.js +0 -15
- package/dist/assets/pt-BR-GIimJgpK.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +0 -2
- package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +0 -15
- package/dist/assets/uk-DLfgD1ki.js +0 -15
- package/dist/assets/useInlineCommentController-CegKdDXi.js +0 -2
- package/dist/assets/vendor-zod-adaMkgkm.js +0 -39
- package/dist/assets/zh-CN-DkeP5awK.js +0 -15
- package/dist/assets/zh-TW-BocaFm3d.js +0 -15
- package/server/lib/skills-catalog/clawdhub/api.js +0 -126
- package/server/lib/skills-catalog/clawdhub/install.js +0 -238
- package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
- package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
const resolveDataDir = () => (process.env.OPENCHAMBER_DATA_DIR
|
|
6
|
+
? path.resolve(process.env.OPENCHAMBER_DATA_DIR)
|
|
7
|
+
: path.join(os.homedir(), '.config', 'openchamber'));
|
|
8
|
+
|
|
9
|
+
const readJsonFile = (filePath) => {
|
|
10
|
+
try {
|
|
11
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
12
|
+
const parsed = JSON.parse(raw);
|
|
13
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Read a persisted cache object from the OpenChamber data directory.
|
|
21
|
+
* Returns null when the file is missing, unreadable, or malformed.
|
|
22
|
+
*/
|
|
23
|
+
export const readDiskCache = (fileName) => {
|
|
24
|
+
try {
|
|
25
|
+
return readJsonFile(path.join(resolveDataDir(), fileName));
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Persist a cache object to the OpenChamber data directory with an atomic
|
|
33
|
+
* temp-file rename. Failures are ignored: the in-memory cache stays
|
|
34
|
+
* authoritative and the next successful write retries persistence.
|
|
35
|
+
*/
|
|
36
|
+
export const writeDiskCache = (fileName, data) => {
|
|
37
|
+
const filePath = path.join(resolveDataDir(), fileName);
|
|
38
|
+
const tempPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
39
|
+
try {
|
|
40
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
41
|
+
fs.writeFileSync(tempPath, JSON.stringify(data), { encoding: 'utf8', mode: 0o600 });
|
|
42
|
+
fs.renameSync(tempPath, filePath);
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
try {
|
|
46
|
+
fs.unlinkSync(tempPath);
|
|
47
|
+
} catch {
|
|
48
|
+
// ignore
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { readDiskCache, writeDiskCache } from './disk-cache.js';
|
|
2
|
+
|
|
3
|
+
const GITHUB_API_BASE = 'https://api.github.com';
|
|
4
|
+
const CACHE_TTL_MS = 3 * 60 * 60 * 1000;
|
|
5
|
+
const FAILURE_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
6
|
+
// Keep well under the catalog route's client request deadline so optional
|
|
7
|
+
// metadata enrichment can never abort catalog loading.
|
|
8
|
+
const FETCH_TIMEOUT_MS = 1500;
|
|
9
|
+
const DISK_CACHE_FILE = 'skills-github-meta.json';
|
|
10
|
+
|
|
11
|
+
const metaCache = new Map();
|
|
12
|
+
const inFlight = new Map();
|
|
13
|
+
|
|
14
|
+
let diskLoaded = false;
|
|
15
|
+
let diskWriteTimer = null;
|
|
16
|
+
|
|
17
|
+
const loadDiskEntries = () => {
|
|
18
|
+
if (diskLoaded) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
diskLoaded = true;
|
|
22
|
+
const persisted = readDiskCache(DISK_CACHE_FILE);
|
|
23
|
+
if (!persisted) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
for (const [repo, entry] of Object.entries(persisted)) {
|
|
28
|
+
if (
|
|
29
|
+
entry
|
|
30
|
+
&& typeof entry === 'object'
|
|
31
|
+
&& typeof entry.expiresAt === 'number'
|
|
32
|
+
&& entry.expiresAt > now
|
|
33
|
+
&& entry.value
|
|
34
|
+
&& typeof entry.value === 'object'
|
|
35
|
+
) {
|
|
36
|
+
metaCache.set(repo, entry);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const scheduleDiskWrite = () => {
|
|
42
|
+
if (diskWriteTimer) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
diskWriteTimer = setTimeout(() => {
|
|
46
|
+
diskWriteTimer = null;
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
const persisted = {};
|
|
49
|
+
for (const [repo, entry] of metaCache.entries()) {
|
|
50
|
+
if (entry.expiresAt > now) {
|
|
51
|
+
persisted[repo] = entry;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
writeDiskCache(DISK_CACHE_FILE, persisted);
|
|
55
|
+
}, 1000);
|
|
56
|
+
if (typeof diskWriteTimer.unref === 'function') {
|
|
57
|
+
diskWriteTimer.unref();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const parseMeta = (payload) => {
|
|
62
|
+
if (!payload || typeof payload !== 'object') {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const pushedAt = payload.pushed_at;
|
|
66
|
+
return {
|
|
67
|
+
stars: Number.isFinite(payload.stargazers_count) ? payload.stargazers_count : null,
|
|
68
|
+
repoUpdatedAt: typeof pushedAt === 'string' && pushedAt ? pushedAt : null,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const fetchRepoMeta = async (normalizedRepo) => {
|
|
73
|
+
loadDiskEntries();
|
|
74
|
+
const cached = metaCache.get(normalizedRepo);
|
|
75
|
+
if (cached && Date.now() < cached.expiresAt) {
|
|
76
|
+
return cached.value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const existing = inFlight.get(normalizedRepo);
|
|
80
|
+
if (existing) {
|
|
81
|
+
return existing;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const run = (async () => {
|
|
85
|
+
try {
|
|
86
|
+
const response = await fetch(`${GITHUB_API_BASE}/repos/${normalizedRepo}`, {
|
|
87
|
+
headers: { Accept: 'application/vnd.github+json' },
|
|
88
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
89
|
+
});
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
// Cache failures briefly so repeated catalog loads do not re-hit a
|
|
92
|
+
// rate-limited or failing API for the same repository.
|
|
93
|
+
metaCache.set(normalizedRepo, {
|
|
94
|
+
expiresAt: Date.now() + FAILURE_CACHE_TTL_MS,
|
|
95
|
+
value: { stars: null, repoUpdatedAt: null },
|
|
96
|
+
});
|
|
97
|
+
scheduleDiskWrite();
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const value = parseMeta(await response.json());
|
|
102
|
+
if (value) {
|
|
103
|
+
metaCache.set(normalizedRepo, { expiresAt: Date.now() + CACHE_TTL_MS, value });
|
|
104
|
+
scheduleDiskWrite();
|
|
105
|
+
}
|
|
106
|
+
return value;
|
|
107
|
+
} catch {
|
|
108
|
+
metaCache.set(normalizedRepo, {
|
|
109
|
+
expiresAt: Date.now() + FAILURE_CACHE_TTL_MS,
|
|
110
|
+
value: { stars: null, repoUpdatedAt: null },
|
|
111
|
+
});
|
|
112
|
+
scheduleDiskWrite();
|
|
113
|
+
return null;
|
|
114
|
+
} finally {
|
|
115
|
+
inFlight.delete(normalizedRepo);
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
|
|
119
|
+
inFlight.set(normalizedRepo, run);
|
|
120
|
+
return run;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Fetch GitHub repository metadata (stars, last push) for a list of
|
|
125
|
+
* `owner/repo` strings. Best-effort: failed lookups resolve to null and
|
|
126
|
+
* never block the catalog response.
|
|
127
|
+
*/
|
|
128
|
+
export async function fetchGitHubRepoMetas(normalizedRepos) {
|
|
129
|
+
const unique = [...new Set(normalizedRepos.filter(Boolean))];
|
|
130
|
+
const entries = await Promise.all(unique.map(async (repo) => [repo, await fetchRepoMeta(repo)]));
|
|
131
|
+
return Object.fromEntries(entries);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** For tests only: clear the in-memory repository metadata cache. */
|
|
135
|
+
export function clearGitHubMetaCache() {
|
|
136
|
+
metaCache.clear();
|
|
137
|
+
inFlight.clear();
|
|
138
|
+
diskLoaded = true;
|
|
139
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { clearGitHubMetaCache, fetchGitHubRepoMetas } from './github-meta.js';
|
|
6
|
+
|
|
7
|
+
const originalFetch = globalThis.fetch;
|
|
8
|
+
|
|
9
|
+
let tempDataDir;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
tempDataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'github-meta-test-'));
|
|
13
|
+
process.env.OPENCHAMBER_DATA_DIR = tempDataDir;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
delete process.env.OPENCHAMBER_DATA_DIR;
|
|
18
|
+
globalThis.fetch = originalFetch;
|
|
19
|
+
clearGitHubMetaCache();
|
|
20
|
+
vi.restoreAllMocks();
|
|
21
|
+
fs.rmSync(tempDataDir, { recursive: true, force: true });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('fetchGitHubRepoMetas', () => {
|
|
25
|
+
it('returns stars and pushed_at from the GitHub API', async () => {
|
|
26
|
+
const fetchMock = vi.fn(async () => new Response(
|
|
27
|
+
JSON.stringify({ stargazers_count: 42, pushed_at: '2026-08-01T00:00:00Z' }),
|
|
28
|
+
{ status: 200 },
|
|
29
|
+
));
|
|
30
|
+
globalThis.fetch = fetchMock;
|
|
31
|
+
|
|
32
|
+
const metas = await fetchGitHubRepoMetas(['anthropics/skills']);
|
|
33
|
+
|
|
34
|
+
expect(metas).toEqual({
|
|
35
|
+
'anthropics/skills': { stars: 42, repoUpdatedAt: '2026-08-01T00:00:00Z' },
|
|
36
|
+
});
|
|
37
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('resolves failed lookups to null without throwing', async () => {
|
|
41
|
+
globalThis.fetch = vi.fn(async () => new Response('rate limited', { status: 403 }));
|
|
42
|
+
|
|
43
|
+
const metas = await fetchGitHubRepoMetas(['anthropics/skills']);
|
|
44
|
+
|
|
45
|
+
expect(metas).toEqual({ 'anthropics/skills': null });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('caches failed lookups briefly to avoid repeat hits', async () => {
|
|
49
|
+
const fetchMock = vi.fn(async () => new Response('rate limited', { status: 403 }));
|
|
50
|
+
globalThis.fetch = fetchMock;
|
|
51
|
+
|
|
52
|
+
await fetchGitHubRepoMetas(['anthropics/skills']);
|
|
53
|
+
const second = await fetchGitHubRepoMetas(['anthropics/skills']);
|
|
54
|
+
|
|
55
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
56
|
+
expect(second).toEqual({ 'anthropics/skills': { stars: null, repoUpdatedAt: null } });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('deduplicates repositories', async () => {
|
|
60
|
+
const fetchMock = vi.fn(async () => new Response(
|
|
61
|
+
JSON.stringify({ stargazers_count: 1, pushed_at: null }),
|
|
62
|
+
{ status: 200 },
|
|
63
|
+
));
|
|
64
|
+
globalThis.fetch = fetchMock;
|
|
65
|
+
|
|
66
|
+
const metas = await fetchGitHubRepoMetas(['a/b', 'a/b', null]);
|
|
67
|
+
|
|
68
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
69
|
+
expect(metas['a/b']).toEqual({ stars: 1, repoUpdatedAt: null });
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const GITHUB_HOST = 'github.com';
|
|
2
|
-
const CLAWDHUB_SOURCE_PREFIX = 'clawdhub:';
|
|
3
2
|
|
|
4
3
|
|
|
5
4
|
function normalizeGitOwnerRepo(owner, repo) {
|
|
@@ -86,7 +85,3 @@ export function parseSkillRepoSource(input, options = {}) {
|
|
|
86
85
|
|
|
87
86
|
return { ok: false, error: { kind: 'invalidSource', message: 'Unsupported repository source format' } };
|
|
88
87
|
}
|
|
89
|
-
|
|
90
|
-
export function isClawdHubSource(input) {
|
|
91
|
-
return typeof input === 'string' && input.trim().toLowerCase().startsWith(CLAWDHUB_SOURCE_PREFIX);
|
|
92
|
-
}
|
|
@@ -15,6 +15,15 @@ other runtime API.
|
|
|
15
15
|
## Files
|
|
16
16
|
|
|
17
17
|
- `index.js` — orchestration: `generateSmallModelText()` / `describeSmallModel()`.
|
|
18
|
+
- `runtime-providers.js` — provider state that exists only inside the running
|
|
19
|
+
OpenCode process. A plugin registers its provider from the `config` hook and
|
|
20
|
+
supplies the credential from its `auth` loader, so neither reaches
|
|
21
|
+
`opencode.json` nor `auth.json`; `GET /provider` is the only place they
|
|
22
|
+
become visible. The module caches one snapshot (30s TTL, shared in-flight
|
|
23
|
+
request) and answers `null` — never an empty provider list — when OpenCode is
|
|
24
|
+
unreachable, so a momentary outage cannot retract providers. It is wired once
|
|
25
|
+
from `server/index.js` and reset on OpenCode restart, which reloads plugins
|
|
26
|
+
and can move their ports and keys.
|
|
18
27
|
- `resolve.js` — model selection, mirroring OpenCode's `getSmallModel` chain:
|
|
19
28
|
0. OpenChamber's own settings override (Settings → Sessions → Small Model):
|
|
20
29
|
when `smallModelUseDefault` is `false`, `smallModelOverride`
|
|
@@ -100,9 +109,17 @@ other runtime API.
|
|
|
100
109
|
- Everything else: OpenAI-compatible `/chat/completions` against the
|
|
101
110
|
provider's base URL, resolved from (1) `provider.<id>.options.baseURL`
|
|
102
111
|
in the OpenCode config, (2) the hardcoded `https://api.openai.com/v1`
|
|
103
|
-
endpoint,
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
endpoint, (3) the endpoint OpenCode resolved at runtime, or (4) the
|
|
113
|
+
provider's `api` field from the models.dev catalog. The credential follows
|
|
114
|
+
the same shape: config `options.apiKey`, then the runtime credential, then
|
|
115
|
+
the auth.json entry. Configured API keys honor OpenCode's `{env:NAME}` and
|
|
116
|
+
`{file:path}` substitutions; file contents and resolved credentials remain
|
|
117
|
+
server-side.
|
|
118
|
+
- The runtime credential is refused for providers listed in
|
|
119
|
+
`OWN_CREDENTIAL_HANDLING`. Their branches need the stored entry rather than
|
|
120
|
+
a bearer token: the clearest case is the ChatGPT-plan `openai` login, whose
|
|
121
|
+
runtime `options.apiKey` is an OAuth access token that `api.openai.com`
|
|
122
|
+
answers with 401.
|
|
106
123
|
- `[small-model:diagnostic]` logs record provider/model, input character
|
|
107
124
|
counts, output budget, thinking toggle, HTTP/finish status, and
|
|
108
125
|
content/reasoning lengths without logging prompts, response text, or
|
|
@@ -110,11 +127,59 @@ other runtime API.
|
|
|
110
127
|
`[session-goal:diagnostic]` structural verdict metadata.
|
|
111
128
|
- `catalog.js` — models.dev catalog via the shared in-process cache
|
|
112
129
|
(`../opencode/models-metadata.js`, also serving
|
|
113
|
-
|
|
130
|
+
`/api/openchamber/models-metadata`).
|
|
114
131
|
- `routes.js` — `GET /api/small-model` (resolution preview) and
|
|
115
132
|
`POST /api/small-model/generate` (`{ prompt, system?, maxOutputTokens?,
|
|
116
133
|
model?, directory? }` → `{ text, providerID, modelID, source }`).
|
|
117
134
|
|
|
135
|
+
## Which providers the pickers may offer
|
|
136
|
+
|
|
137
|
+
`listAuthenticatedProviders()` answers one question for the Small Model and
|
|
138
|
+
Changes Walkthrough pickers alike: which providers can this module actually
|
|
139
|
+
call. One rule decides it, applied the same way to every provider — **a
|
|
140
|
+
credential we are allowed to use, and an endpoint to send it to.** The
|
|
141
|
+
auth.json scan as before, plus the credential and endpoint OpenCode resolved
|
|
142
|
+
for a plugin provider.
|
|
143
|
+
|
|
144
|
+
**opencode zen is excluded without a real login.** When the user has no zen
|
|
145
|
+
credential, OpenCode substitutes the sentinel `options.apiKey = "public"` and
|
|
146
|
+
trims its catalog to the free models. Those run on OpenCode's own subsidised
|
|
147
|
+
infrastructure and are meant to be reached through OpenCode, so the sentinel is
|
|
148
|
+
never accepted as a credential — see `ZEN_ANONYMOUS_API_KEY`.
|
|
149
|
+
|
|
150
|
+
### Why there is no capability probe
|
|
151
|
+
|
|
152
|
+
A plugin may implement its whole integration inside `options.fetch` —
|
|
153
|
+
rewriting the path, signing the request, translating the payload — and OpenCode
|
|
154
|
+
cannot serialise a function. Such a provider advertises an ordinary base URL
|
|
155
|
+
that answers nothing we know how to ask, and no reported field distinguishes it
|
|
156
|
+
from a plain one.
|
|
157
|
+
|
|
158
|
+
Asking the endpoint (`GET /models`) does identify that case correctly. It was
|
|
159
|
+
measured against all 166 providers carrying an `api` URL in the models.dev
|
|
160
|
+
catalog, and it also denies six of them — `cloudflare-workers-ai`,
|
|
161
|
+
`infomaniak`, `iflowcn`, `inference`, `kuae-cloud-coding-plan`,
|
|
162
|
+
`thinkingmachines` — which work fine and simply have no `/models` route. At a
|
|
163
|
+
3.6% false-negative rate on providers known to work, the probe removes more
|
|
164
|
+
working models from the picker than broken ones, and a provider that silently
|
|
165
|
+
vanishes explains nothing while one that fails on use says why.
|
|
166
|
+
|
|
167
|
+
So availability stops at credential and endpoint, and the protocol verdict is
|
|
168
|
+
left to the call. A provider whose protocol lives in a plugin's `fetch` stays
|
|
169
|
+
selectable and fails when used — which is what it did before this resolution
|
|
170
|
+
existed.
|
|
171
|
+
|
|
172
|
+
Claude Code is refused unconditionally. A plugin can publish an
|
|
173
|
+
OpenAI-compatible endpoint for it, but that endpoint is a façade over the
|
|
174
|
+
Claude Agent SDK, which spawns the Claude Code CLI per request and spends the
|
|
175
|
+
user's Claude subscription rate limit. Paying that for a session title or a
|
|
176
|
+
summary is the wrong trade, so an available endpoint does not lift the
|
|
177
|
+
refusal — the cost is the reason, not the transport.
|
|
178
|
+
|
|
179
|
+
The result is served as `authenticatedProviders` on `GET /api/small-model`.
|
|
180
|
+
The field name predates the runtime resolution; it now means "callable", which
|
|
181
|
+
is a superset of "has an auth.json entry".
|
|
182
|
+
|
|
118
183
|
## Registration
|
|
119
184
|
|
|
120
185
|
Mounted lazily from `feature-routes-runtime.js` (same pattern as quota): the
|
|
@@ -125,9 +190,12 @@ module is imported on first request, not at server startup.
|
|
|
125
190
|
- OpenCode's free models (`opencode/big-pickle`, `*-free`) work without a
|
|
126
191
|
token only through OpenCode's own server — direct calls are rejected, and
|
|
127
192
|
piggybacking on their subsidized infra is out of bounds by design. Every
|
|
128
|
-
resolution step therefore requires a
|
|
193
|
+
resolution step therefore requires a credential we are allowed to use:
|
|
129
194
|
a session on an unauthenticated `opencode` provider falls through to the
|
|
130
|
-
global scan (or a clean 404 on a vanilla setup with no logins).
|
|
195
|
+
global scan (or a clean 404 on a vanilla setup with no logins). The runtime
|
|
196
|
+
snapshot does not weaken this — OpenCode reports the sentinel
|
|
197
|
+
`apiKey: "public"` for that state, and this module refuses to read it as a
|
|
198
|
+
credential.
|
|
131
199
|
|
|
132
200
|
- Anthropic OAuth (Claude Pro/Max) entries are not supported — OpenCode itself
|
|
133
201
|
keeps those outside `auth.json` in this generation; only `type: api` keys
|
|
@@ -5,6 +5,7 @@ import { readAuthFile, writeAuthFile } from '../opencode/auth.js';
|
|
|
5
5
|
import { readConfig, readConfigLayers } from '../opencode/shared.js';
|
|
6
6
|
import { getCatalogProvider } from './catalog.js';
|
|
7
7
|
import { getAuthEntryForProvider } from './resolve.js';
|
|
8
|
+
import { getRuntimeProvider } from './runtime-providers.js';
|
|
8
9
|
|
|
9
10
|
// Direct, non-streaming text generation against the provider APIs, replicating
|
|
10
11
|
// how OpenCode authenticates each of them (see the plugin auth loaders in the
|
|
@@ -566,23 +567,52 @@ const readProviderConfig = (workingDirectory, providerID) => {
|
|
|
566
567
|
// Dispatch
|
|
567
568
|
// ---------------------------------------------------------------------------
|
|
568
569
|
|
|
570
|
+
/**
|
|
571
|
+
* Providers reached through a dedicated wire format below: a token exchange,
|
|
572
|
+
* an OAuth refresh, or a non-bearer header. OpenCode's runtime
|
|
573
|
+
* `options.apiKey` is not the value those branches need — the ChatGPT-plan
|
|
574
|
+
* `openai` login is the clearest case, where the runtime key is an OAuth
|
|
575
|
+
* access token that api.openai.com answers with 401 — so the runtime
|
|
576
|
+
* credential never stands in for them, and the runtime listing skips them
|
|
577
|
+
* because the auth.json scan already covers them.
|
|
578
|
+
*/
|
|
579
|
+
export const DEDICATED_WIRE_FORMAT_PROVIDERS = new Set(['github-copilot', 'copilot', 'openai', 'anthropic', 'google']);
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* The runtime credential shaped as an auth entry, or `null` when the provider
|
|
583
|
+
* owns its credential handling or OpenCode reports nothing usable.
|
|
584
|
+
*/
|
|
585
|
+
const runtimeCredential = (providerID, runtime) => (
|
|
586
|
+
!DEDICATED_WIRE_FORMAT_PROVIDERS.has(providerID) && runtime?.apiKey
|
|
587
|
+
? { type: 'api', key: runtime.apiKey }
|
|
588
|
+
: null
|
|
589
|
+
);
|
|
590
|
+
|
|
569
591
|
/**
|
|
570
592
|
* Same credential resolution the request path uses: config
|
|
571
|
-
* `provider.<id>.options.apiKey` wins, then the
|
|
593
|
+
* `provider.<id>.options.apiKey` wins, then the runtime credential OpenCode
|
|
594
|
+
* resolved for a plugin provider, then the auth.json entry.
|
|
572
595
|
* Callers that need to refuse before spending a request (walkthrough readiness)
|
|
573
596
|
* must use this rather than inventing a second rule.
|
|
574
597
|
*/
|
|
575
|
-
export function resolveProviderLogin({ auth, workingDirectory, providerID }) {
|
|
598
|
+
export async function resolveProviderLogin({ auth, workingDirectory, providerID }) {
|
|
576
599
|
const providerConfig = readProviderConfig(workingDirectory, providerID);
|
|
577
|
-
return providerConfig?.auth
|
|
600
|
+
return providerConfig?.auth
|
|
601
|
+
|| runtimeCredential(providerID, await getRuntimeProvider(providerID))
|
|
602
|
+
|| getAuthEntryForProvider(auth, providerID)
|
|
603
|
+
|| null;
|
|
578
604
|
}
|
|
579
605
|
|
|
580
606
|
export async function callSmallModel({ auth, catalog, workingDirectory, providerID, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) {
|
|
581
607
|
const tokens = Number(maxOutputTokens) > 0 ? Number(maxOutputTokens) : DEFAULT_MAX_OUTPUT_TOKENS;
|
|
582
608
|
const providerConfig = readProviderConfig(workingDirectory, providerID);
|
|
583
|
-
|
|
584
|
-
// config provider.<id>.options
|
|
585
|
-
|
|
609
|
+
const runtimeProvider = await getRuntimeProvider(providerID);
|
|
610
|
+
// Match OpenCode's resolveSDK precedence: config `provider.<id>.options`
|
|
611
|
+
// wins, then what OpenCode itself resolved at runtime (the only place a
|
|
612
|
+
// plugin's credential exists), and the auth.json entry last.
|
|
613
|
+
const entry = providerConfig?.auth
|
|
614
|
+
|| runtimeCredential(providerID, runtimeProvider)
|
|
615
|
+
|| getAuthEntryForProvider(auth, providerID);
|
|
586
616
|
if (!entry) {
|
|
587
617
|
// Structured so the walkthrough (and any other caller) can show a blocker
|
|
588
618
|
// instead of a raw 500 banner with this developer-oriented sentence.
|
|
@@ -685,9 +715,12 @@ export async function callSmallModel({ auth, catalog, workingDirectory, provider
|
|
|
685
715
|
// Everything else: OpenAI-compatible chat completions against the catalog's
|
|
686
716
|
// base URL for that provider (openai itself included). When a custom provider
|
|
687
717
|
// is not in the catalog (e.g. a user-configured OpenAI-compatible proxy),
|
|
688
|
-
// fall back to its baseURL from the OpenCode provider config
|
|
689
|
-
//
|
|
690
|
-
//
|
|
718
|
+
// fall back to its baseURL from the OpenCode provider config, then to the
|
|
719
|
+
// endpoint OpenCode resolved at runtime — which for a plugin provider is the
|
|
720
|
+
// only place it exists, and for several of them is a local proxy the plugin
|
|
721
|
+
// itself runs. The openai provider also respects
|
|
722
|
+
// provider.openai.options.baseURL — OpenCode itself uses the same config for
|
|
723
|
+
// all providers including openai.
|
|
691
724
|
const provider = getCatalogProvider(catalog, providerID);
|
|
692
725
|
const providerConfigUrl = providerConfig?.baseURL;
|
|
693
726
|
const defaultOpenaiUrl = 'https://api.openai.com/v1';
|
|
@@ -695,9 +728,10 @@ export async function callSmallModel({ auth, catalog, workingDirectory, provider
|
|
|
695
728
|
? providerConfigUrl
|
|
696
729
|
: providerID === 'openai'
|
|
697
730
|
? defaultOpenaiUrl
|
|
698
|
-
:
|
|
699
|
-
|
|
700
|
-
|
|
731
|
+
: runtimeProvider?.baseURL
|
|
732
|
+
?? (typeof provider?.api === 'string' && provider.api
|
|
733
|
+
? provider.api
|
|
734
|
+
: null);
|
|
701
735
|
if (!baseURL) {
|
|
702
736
|
throw new Error(`Provider "${providerID}" has no known API base URL`);
|
|
703
737
|
}
|
|
@@ -12,8 +12,11 @@ vi.mock('../opencode/shared.js', () => ({
|
|
|
12
12
|
readConfigLayers: vi.fn(),
|
|
13
13
|
}));
|
|
14
14
|
|
|
15
|
+
vi.mock('./runtime-providers.js', () => ({ getRuntimeProvider: vi.fn(async () => null) }));
|
|
16
|
+
|
|
15
17
|
const { callSmallModel } = await import('./call.js');
|
|
16
18
|
const { readConfig, readConfigLayers } = await import('../opencode/shared.js');
|
|
19
|
+
const { getRuntimeProvider } = await import('./runtime-providers.js');
|
|
17
20
|
|
|
18
21
|
// Minimal catalog fragment used by the catalog-based base URL resolution case.
|
|
19
22
|
const CATALOG = {
|
|
@@ -55,6 +58,9 @@ describe('callSmallModel — custom provider config', () => {
|
|
|
55
58
|
globalThis.fetch = fetchMock;
|
|
56
59
|
readConfig.mockReset();
|
|
57
60
|
readConfigLayers.mockReset();
|
|
61
|
+
// Default: OpenCode knows nothing, so resolution stays file-based.
|
|
62
|
+
getRuntimeProvider.mockReset();
|
|
63
|
+
getRuntimeProvider.mockResolvedValue(null);
|
|
58
64
|
});
|
|
59
65
|
|
|
60
66
|
afterEach(() => {
|
|
@@ -341,6 +347,79 @@ describe('callSmallModel — custom provider config', () => {
|
|
|
341
347
|
prompt: 'hi',
|
|
342
348
|
})).rejects.toThrow('Provider "custom" has no known API base URL');
|
|
343
349
|
});
|
|
350
|
+
|
|
351
|
+
// A plugin registers its provider inside the running OpenCode process, so
|
|
352
|
+
// neither the config nor auth.json knows anything about it. This is the
|
|
353
|
+
// case that used to fail with "has no known API base URL" (#2666).
|
|
354
|
+
it('uses the endpoint and credential OpenCode resolved for a plugin provider', async () => {
|
|
355
|
+
readConfig.mockReturnValue({});
|
|
356
|
+
getRuntimeProvider.mockResolvedValue({
|
|
357
|
+
id: 'llmapi',
|
|
358
|
+
apiKey: 'plugin-key',
|
|
359
|
+
baseURL: 'https://api.llmapi.ai/v1',
|
|
360
|
+
anonymousZen: false,
|
|
361
|
+
});
|
|
362
|
+
const fetchMock = vi.fn(async () => ok('done'));
|
|
363
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
364
|
+
|
|
365
|
+
await callSmallModel({
|
|
366
|
+
auth: {},
|
|
367
|
+
catalog: {},
|
|
368
|
+
workingDirectory: '/proj',
|
|
369
|
+
providerID: 'llmapi',
|
|
370
|
+
modelID: 'claude-opus-4-8',
|
|
371
|
+
prompt: 'hi',
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
const { url, init } = lastCall(fetchMock);
|
|
375
|
+
expect(url).toBe('https://api.llmapi.ai/v1/chat/completions');
|
|
376
|
+
expect(init.headers.Authorization).toBe('Bearer plugin-key');
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it('keeps the ChatGPT-plan login on its own transport instead of the runtime key', async () => {
|
|
380
|
+
readConfig.mockReturnValue({});
|
|
381
|
+
// OpenCode reports an OAuth access token as `options.apiKey` for openai;
|
|
382
|
+
// api.openai.com answers it with 401, so it must not stand in for the
|
|
383
|
+
// codex path.
|
|
384
|
+
getRuntimeProvider.mockResolvedValue({
|
|
385
|
+
id: 'openai',
|
|
386
|
+
apiKey: 'oauth-access-token',
|
|
387
|
+
baseURL: null,
|
|
388
|
+
anonymousZen: false,
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
await expect(callSmallModel({
|
|
392
|
+
auth: {},
|
|
393
|
+
catalog: {},
|
|
394
|
+
workingDirectory: '/proj',
|
|
395
|
+
providerID: 'openai',
|
|
396
|
+
modelID: 'gpt-5.4-mini',
|
|
397
|
+
prompt: 'hi',
|
|
398
|
+
})).rejects.toMatchObject({ code: 'no-provider-login' });
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('prefers an explicit config baseURL over the runtime endpoint', async () => {
|
|
402
|
+
readConfig.mockReturnValue({ provider: { custom: { options: { baseURL: 'https://configured.example/v1' } } } });
|
|
403
|
+
getRuntimeProvider.mockResolvedValue({
|
|
404
|
+
id: 'custom',
|
|
405
|
+
apiKey: 'runtime-key',
|
|
406
|
+
baseURL: 'https://runtime.example/v1',
|
|
407
|
+
anonymousZen: false,
|
|
408
|
+
});
|
|
409
|
+
const fetchMock = vi.fn(async () => ok('done'));
|
|
410
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
411
|
+
|
|
412
|
+
await callSmallModel({
|
|
413
|
+
auth: { custom: { type: 'api', key: 'auth-key' } },
|
|
414
|
+
catalog: {},
|
|
415
|
+
workingDirectory: '/proj',
|
|
416
|
+
providerID: 'custom',
|
|
417
|
+
modelID: 'm',
|
|
418
|
+
prompt: 'hi',
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
expect(lastCall(fetchMock).url).toBe('https://configured.example/v1/chat/completions');
|
|
422
|
+
});
|
|
344
423
|
});
|
|
345
424
|
|
|
346
425
|
describe('config-supplied key does not leak', () => {
|