Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

Cache open source project catalog

wyt83b541fd903d
diff --git a/src/main/data/oss-projects.json b/src/main/data/oss-projects.json
new file mode 100644
index 00000000..89c859ce
--- /dev/null
+++ b/src/main/data/oss-projects.json
@@ -0,0 +1,69 @@
+{
+ "categories": [
+ { "code": "anim", "name_zh": "动画 / 视频", "name_en": "Animation / Video", "name_ja": "アニメ / 動画", "sort_order": 10 },
+ { "code": "browser", "name_zh": "浏览器", "name_en": "Browser", "name_ja": "ブラウザ", "sort_order": 30 },
+ { "code": "slides", "name_zh": "演示 / PPT", "name_en": "Slides / PPT", "name_ja": "スライド / PPT", "sort_order": 70 }
+ ],
+ "projects": [
+ {
+ "id": "hyperframes",
+ "name": "HyperFrames",
+ "repo": "heygen-com/hyperframes",
+ "category": "anim",
+ "driver": "cli",
+ "glyph": "◓",
+ "color": "#8b5cf6",
+ "by": "HyperFrames",
+ "home": true,
+ "description_zh": "生成开场动画和短视频, 装好后 Orkas 会自动调用。",
+ "description_en": "Generate intro animations and short videos; Orkas uses it automatically once installed.",
+ "task_zh": "帮我做一段产品开场动画",
+ "task_en": "Make a product intro animation for me"
+ },
+ {
+ "id": "browser-use",
+ "name": "Browser-Use",
+ "repo": "browser-use/browser-use",
+ "category": "browser",
+ "driver": "mcp",
+ "glyph": "◍",
+ "color": "#10b981",
+ "by": "Browser-Use",
+ "home": false,
+ "description_zh": "让 AI 直接帮你操作浏览器、点击和填写网页。",
+ "description_en": "Let AI operate the browser for you - click and fill in pages.",
+ "task_zh": "让 AI 帮我操作浏览器",
+ "task_en": "Let AI operate the browser for me"
+ },
+ {
+ "id": "ppt-master",
+ "name": "PPT-Master",
+ "repo": "hugohe3/ppt-master",
+ "category": "slides",
+ "driver": "install",
+ "glyph": "▥",
+ "color": "#f97316",
+ "by": "PPT-Master",
+ "home": true,
+ "description_zh": "用一段大纲或要点自动生成可编辑的 PPT 演示文稿。",
+ "description_en": "Generate an editable slide deck from an outline or a few bullet points.",
+ "task_zh": "把要点做成一份 PPT",
+ "task_en": "Turn my outline into a slide deck"
+ },
+ {
+ "id": "crawl4ai",
+ "name": "Crawl4AI",
+ "repo": "unclecode/crawl4ai",
+ "category": "browser",
+ "driver": "cli",
+ "glyph": "◑",
+ "color": "#14b8a6",
+ "by": "Crawl4AI",
+ "home": true,
+ "description_zh": "抓取网页正文并整理成干净的文档或结构化数据, 装好后 Orkas 会自动调用。",
+ "description_en": "Extract a web page's main content into a clean document or structured data; Orkas uses it automatically once installed.",
+ "task_zh": "抓取这个网页的内容整理成文档",
+ "task_en": "Pull this web page into a clean document"
+ }
+ ]
+}
diff --git a/src/main/features/marketplace.ts b/src/main/features/marketplace.ts
index dd18ad85..1e8a6ef8 100644
--- a/src/main/features/marketplace.ts
+++ b/src/main/features/marketplace.ts
@@ -108,6 +108,7 @@ export interface MarketplaceCategory {
code: string;
name_zh: string;
name_en: string;
+ name_ja?: string;
sort_order: number;
}
@@ -235,16 +236,107 @@ export interface MarketplaceProject {
task_en: string;
home?: boolean;
}
+export interface MarketplaceProjectsListResult {
+ list: MarketplaceProject[];
+ total: number;
+ categories: MarketplaceCategory[];
+ source?: 'server' | 'bundled';
+ stale?: boolean;
+}
+
+interface MarketplaceProjectsCatalog {
+ categories: MarketplaceCategory[];
+ projects: MarketplaceProject[];
+}
+
+let _localProjectsCatalog: MarketplaceProjectsCatalog | null = null;
+
+function _loadLocalProjectsCatalog(): MarketplaceProjectsCatalog {
+ if (_localProjectsCatalog) return _localProjectsCatalog;
+ // Bundled mirror of Server/biz/marketplace/marketplace_mgr.py::_OSS_* for offline dev.
+ const file = path.join(__dirname, '..', 'data', 'oss-projects.json');
+ const parsed = JSON.parse(fs.readFileSync(file, 'utf-8')) as Partial<MarketplaceProjectsCatalog>;
+ _localProjectsCatalog = {
+ categories: Array.isArray(parsed.categories) ? parsed.categories : [],
+ projects: Array.isArray(parsed.projects) ? parsed.projects : [],
+ };
+ return _localProjectsCatalog;
+}
+
+function _normProjectListOpts(
+ opts: { category?: string; q?: string; page?: number; size?: number; home_only?: boolean; local_only?: boolean } = {},
+): { category: string; q: string; page: number; size?: number; homeOnly: boolean } {
+ const page = Number(opts.page);
+ const size = Number(opts.size);
+ return {
+ category: String(opts.category || '').trim().toLowerCase(),
+ q: String(opts.q || '').trim().toLowerCase(),
+ page: Number.isFinite(page) ? Math.max(1, Math.floor(page)) : 1,
+ ...(Number.isFinite(size) ? { size: Math.max(1, Math.min(100, Math.floor(size))) } : {}),
+ homeOnly: opts.home_only === true,
+ };
+}
+
+function _listLocalMarketplaceProjects(
+ opts: { category?: string; q?: string; page?: number; size?: number; home_only?: boolean; local_only?: boolean } = {},
+): MarketplaceProjectsListResult {
+ const catalog = _loadLocalProjectsCatalog();
+ const normalized = _normProjectListOpts(opts);
+ const categoryCodes = new Set(catalog.categories.map((c) => c.code));
+ let rows = catalog.projects;
+ if (normalized.homeOnly) rows = rows.filter((p) => p.home);
+ if (normalized.category && categoryCodes.has(normalized.category)) {
+ rows = rows.filter((p) => p.category === normalized.category);
+ } else if (normalized.category) {
+ rows = [];
+ }
+ if (normalized.q) {
+ rows = rows.filter((p) => [
+ p.name,
+ p.repo,
+ p.by,
+ p.description_zh,
+ p.description_en,
+ p.task_zh,
+ p.task_en,
+ ].join(' ').toLowerCase().includes(normalized.q));
+ }
+
+ const total = rows.length;
+ const size = normalized.size || (normalized.homeOnly ? total || 1 : 20);
+ const start = (normalized.page - 1) * size;
+ const categories = catalog.categories
+ .slice()
+ .sort((a, b) => (a.sort_order - b.sort_order) || a.code.localeCompare(b.code));
+
+ return {
+ list: rows.slice(start, start + size).map((p) => ({ ...p })),
+ total,
+ categories: categories.map((c) => ({ ...c })),
+ source: 'bundled',
+ stale: true,
+ };
+}
+
export async function listMarketplaceProjects(
- opts: { category?: string; q?: string; page?: number; size?: number; home_only?: boolean } = {},
-): Promise<{ list: MarketplaceProject[]; total: number; categories: MarketplaceCategory[] }> {
- return await postJson('/marketplace/projects/list', {
- category: opts.category || null,
- q: opts.q || null,
- page: opts.page || 1,
- ...(typeof opts.size === 'number' ? { size: opts.size } : {}),
- home_only: opts.home_only === true,
- });
+ opts: { category?: string; q?: string; page?: number; size?: number; home_only?: boolean; local_only?: boolean } = {},
+): Promise<MarketplaceProjectsListResult> {
+ if (opts.local_only === true) return _listLocalMarketplaceProjects(opts);
+ try {
+ const fresh = await postJson<MarketplaceProjectsListResult>('/marketplace/projects/list', {
+ category: opts.category || null,
+ q: opts.q || null,
+ page: opts.page || 1,
+ ...(typeof opts.size === 'number' ? { size: opts.size } : {}),
+ home_only: opts.home_only === true,
+ });
+ return { ...fresh, source: fresh.source || 'server', stale: false };
+ } catch (err) {
+ log.warn('marketplace projects server list failed; using bundled catalog', {
+ error: (err as Error)?.message || String(err),
+ });
+ return _listLocalMarketplaceProjects(opts);
+ }
}
// ── detail (cache-aware) ──────────────────────────────────────────────────
diff --git a/src/renderer/modules/marketplace.js b/src/renderer/modules/marketplace.js
index c175792b..a60c9109 100644
--- a/src/renderer/modules/marketplace.js
+++ b/src/renderer/modules/marketplace.js
@@ -688,6 +688,10 @@ window.addEventListener('i18n-change', () => { _mpUpdateReconcileBanner(); });
// next openMarketplace will SWR-refresh anyway).
function refreshMarketplaceIfActive() {
if (!isMarketplaceOpen() || !_mpState) return;
+ if (_mpState.tab === 'oss') {
+ _mpLoadOss({ forceState: true }).catch(() => {});
+ return;
+ }
Promise.all([
_mpRefreshInstalledState(),
_mpRefreshListingsAndRender(),
@@ -1101,7 +1105,7 @@ async function _mpLoadOss(opts = {}) {
q: _mpState.ossQ || '',
size: typeof OSS_MARKETPLACE_PAGE_SIZE === 'number' ? OSS_MARKETPLACE_PAGE_SIZE : 100,
force: opts.force === true,
- revalidate: opts.revalidate !== false,
+ revalidate: opts.revalidate === false ? false : 'always',
}),
loadOssInstalled(),
]);
diff --git a/src/renderer/modules/oss.js b/src/renderer/modules/oss.js
index 0578a679..f0b3c8ba 100644
--- a/src/renderer/modules/oss.js
+++ b/src/renderer/modules/oss.js
@@ -26,25 +26,33 @@ function ossIconFor(cat) { return _OSS_CAT_ICON[cat] || 'sparkles'; }
// Cache contract mirrors marketplace agent/skill listings:
// renderer Map for hot reads + main-process `marketplace/listings.json` for
-// cold-start hydration + stale-while-revalidate when the cached row ages out.
+// cold-start hydration + stale-while-revalidate. Cached rows render first;
+// network refreshes are throttled per key so re-renders/i18n changes do not
+// hammer the Server.
const OSS_CATALOG_REVALIDATE_MS = 5 * 60 * 1000;
+const OSS_HOME_COLD_REVALIDATE_MS = 4 * 60 * 60 * 1000;
const OSS_MARKETPLACE_PAGE_SIZE = 100;
let _ossCatalogHydrated = false;
let _ossCatalogHydratePromise = null;
const _ossCatalogCache = new Map();
const _ossCatalogInflight = new Map();
+const _ossCatalogNextRefreshAt = new Map();
+const _ossCatalogColdRefreshChecked = new Set();
function _ossNormalizeCatalogOpts(forceOrOpts) {
if (typeof forceOrOpts === 'boolean') return { force: forceOrOpts };
const raw = forceOrOpts && typeof forceOrOpts === 'object' ? forceOrOpts : {};
const size = Number(raw.size);
+ const revalidate = raw.revalidate === 'always' || raw.revalidate === 'cold-start'
+ ? raw.revalidate
+ : raw.revalidate !== false;
return {
homeOnly: raw.homeOnly === true || raw.home_only === true,
category: String(raw.category || '').trim(),
q: String(raw.q || '').trim(),
...(Number.isFinite(size) && size > 0 ? { size: Math.min(100, Math.max(1, Math.floor(size))) } : {}),
force: raw.force === true,
- revalidate: raw.revalidate !== false,
+ revalidate,
};
}
@@ -95,7 +103,7 @@ function _ossPersistCatalogCache(key, entry) {
items: entry.projects || [],
categories: entry.categories || [],
total: typeof entry.total === 'number' ? entry.total : (entry.projects || []).length,
- ts: entry.ts || Date.now(),
+ ts: typeof entry.ts === 'number' ? entry.ts : Date.now(),
},
},
}).catch(() => {});
@@ -111,6 +119,16 @@ function _ossCatalogPayload(opts) {
};
}
+function _ossEntryFromCatalogResponse(res) {
+ const bundledFallback = !!(res && (res.source === 'bundled' || res.stale === true));
+ return {
+ projects: Array.isArray(res && res.list) ? res.list : [],
+ categories: Array.isArray(res && res.categories) ? res.categories : [],
+ total: typeof (res && res.total) === 'number' ? res.total : (Array.isArray(res && res.list) ? res.list.length : 0),
+ ts: bundledFallback ? 0 : Date.now(),
+ };
+}
+
function _ossDispatchCatalogUpdated(key, opts, entry) {
if (typeof window === 'undefined' || typeof window.dispatchEvent !== 'function' || typeof CustomEvent !== 'function') return;
try {
@@ -129,14 +147,13 @@ function _ossDispatchCatalogUpdated(key, opts, entry) {
async function _ossFetchCatalog(key, opts, notify) {
if (_ossCatalogInflight.has(key)) return _ossCatalogInflight.get(key);
+ _ossCatalogNextRefreshAt.set(key, Date.now() + OSS_CATALOG_REVALIDATE_MS);
const p = window.orkas.invoke('marketplace.listProjects', _ossCatalogPayload(opts))
.then((res) => {
- const entry = {
- projects: Array.isArray(res && res.list) ? res.list : [],
- categories: Array.isArray(res && res.categories) ? res.categories : [],
- total: typeof (res && res.total) === 'number' ? res.total : (Array.isArray(res && res.list) ? res.list.length : 0),
- ts: Date.now(),
- };
+ const bundledFallback = !!(res && (res.source === 'bundled' || res.stale === true));
+ const existing = _ossCatalogCache.get(key);
+ if (bundledFallback && existing && existing.ts > 0) return existing;
+ const entry = _ossEntryFromCatalogResponse(res);
_ossCatalogCache.set(key, entry);
_ossPersistCatalogCache(key, entry);
if (notify) _ossDispatchCatalogUpdated(key, opts, entry);
@@ -147,6 +164,37 @@ async function _ossFetchCatalog(key, opts, notify) {
return p;
}
+async function _ossLoadLocalCatalog(key, opts) {
+ const res = await window.orkas.invoke('marketplace.listProjects', {
+ ..._ossCatalogPayload(opts),
+ local_only: true,
+ });
+ const entry = _ossEntryFromCatalogResponse(res);
+ _ossCatalogCache.set(key, entry);
+ _ossPersistCatalogCache(key, entry);
+ return entry;
+}
+
+function _ossShouldRefreshCached(key, cached, opts) {
+ if (!opts.revalidate || _ossCatalogInflight.has(key)) return false;
+ if (opts.revalidate === 'always') return true;
+ if (opts.revalidate === 'cold-start') {
+ if (_ossCatalogColdRefreshChecked.has(key)) return false;
+ _ossCatalogColdRefreshChecked.add(key);
+ return !cached || !cached.ts || (Date.now() - cached.ts > OSS_HOME_COLD_REVALIDATE_MS);
+ }
+ const now = Date.now();
+ const stale = !cached || !cached.ts || (now - cached.ts > OSS_CATALOG_REVALIDATE_MS);
+ const nextRefreshAt = _ossCatalogNextRefreshAt.get(key) || 0;
+ return stale || now >= nextRefreshAt;
+}
+
+function _ossRefreshCatalogInBackground(key, opts) {
+ _ossFetchCatalog(key, opts, true).catch((err) => {
+ _ossLog.warn('oss catalog refresh failed', { error: err && err.message });
+ });
+}
+
async function loadOssCatalog(forceOrOpts) {
const opts = _ossNormalizeCatalogOpts(forceOrOpts);
const key = ossCatalogCacheKey(opts);
@@ -155,13 +203,20 @@ async function loadOssCatalog(forceOrOpts) {
const cached = _ossCatalogCache.get(key);
if (cached && !opts.force) {
const missingCategories = !opts.homeOnly && !(cached.categories || []).length;
- if (opts.revalidate && (missingCategories || Date.now() - cached.ts > OSS_CATALOG_REVALIDATE_MS)) {
- _ossFetchCatalog(key, opts, true).catch((err) => {
- _ossLog.warn('oss catalog refresh failed', { error: err && err.message });
- });
+ if (opts.revalidate && (missingCategories || _ossShouldRefreshCached(key, cached, opts))) {
+ _ossRefreshCatalogInBackground(key, opts);
}
return cached;
}
+ if (!opts.force) {
+ try {
+ const localEntry = await _ossLoadLocalCatalog(key, opts);
+ if (_ossShouldRefreshCached(key, localEntry, opts)) _ossRefreshCatalogInBackground(key, opts);
+ return localEntry;
+ } catch (err) {
+ _ossLog.warn('oss bundled catalog load failed', { error: err && err.message });
+ }
+ }
return _ossFetchCatalog(key, opts, false);
}
@@ -260,7 +315,12 @@ async function initOssEntry(opts = {}) {
}
let data;
- try { data = await loadOssCatalog({ homeOnly: true, revalidate: opts.revalidate !== false }); }
+ try {
+ data = await loadOssCatalog({
+ homeOnly: true,
+ revalidate: opts.revalidate === false ? false : 'cold-start',
+ });
+ }
catch (err) { _ossLog.warn('oss entry load failed', { error: err && err.message }); entry.style.display = 'none'; return; }
// ① receives the curated home subset from the Server. The Server config
diff --git a/test/main/features/marketplace_projects.test.ts b/test/main/features/marketplace_projects.test.ts
new file mode 100644
index 00000000..e405fe51
--- /dev/null
+++ b/test/main/features/marketplace_projects.test.ts
@@ -0,0 +1,59 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+async function loadMarketplace() {
+ const users = await import('../../../src/main/features/users');
+ users.activateUser('u_marketplace_projects');
+ return import('../../../src/main/features/marketplace');
+}
+
+describe('marketplace projects catalog', () => {
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ vi.resetModules();
+ delete process.env.ORKAS_API_BASE_URL;
+ });
+
+ it('falls back to bundled projects when the Server catalog is unavailable', async () => {
+ process.env.ORKAS_API_BASE_URL = 'https://marketplace.test/api';
+ vi.stubGlobal('fetch', vi.fn(async () => new Response('not found', { status: 404 })));
+
+ const marketplace = await loadMarketplace();
+ const home = await marketplace.listMarketplaceProjects({ home_only: true });
+
+ expect(home.list.map((p) => p.id)).toEqual(['hyperframes', 'ppt-master', 'crawl4ai']);
+ expect(home.categories.map((c) => c.code)).toEqual(['anim', 'browser', 'slides']);
+ expect(home.source).toBe('bundled');
+ expect(home.stale).toBe(true);
+ });
+
+ it('applies category, search, and pagination to the bundled fallback', async () => {
+ process.env.ORKAS_API_BASE_URL = 'https://marketplace.test/api';
+ vi.stubGlobal('fetch', vi.fn(async () => new Response('not found', { status: 404 })));
+
+ const marketplace = await loadMarketplace();
+ const browser = await marketplace.listMarketplaceProjects({ category: 'browser', q: '结构化', size: 1 });
+
+ expect(browser.total).toBe(1);
+ expect(browser.list).toHaveLength(1);
+ expect(browser.list[0].id).toBe('crawl4ai');
+ });
+
+ it('uses Server results when the catalog request succeeds', async () => {
+ process.env.ORKAS_API_BASE_URL = 'https://marketplace.test/api';
+ const fetchMock = vi.fn(async () => new Response(JSON.stringify({
+ code: 0,
+ list: [{ id: 'server-project', name: 'Server Project' }],
+ total: 1,
+ categories: [{ code: 'server', name_zh: '服务端', name_en: 'Server', sort_order: 1 }],
+ })));
+ vi.stubGlobal('fetch', fetchMock);
+
+ const marketplace = await loadMarketplace();
+ const data = await marketplace.listMarketplaceProjects({ home_only: true });
+
+ expect(data.list.map((p) => p.id)).toEqual(['server-project']);
+ expect(data.source).toBe('server');
+ expect(data.stale).toBe(false);
+ expect(fetchMock).toHaveBeenCalledOnce();
+ });
+});
diff --git a/test/renderer/oss.test.ts b/test/renderer/oss.test.ts
index 7ba4a2ac..eea53ae7 100644
--- a/test/renderer/oss.test.ts
+++ b/test/renderer/oss.test.ts
@@ -111,7 +111,7 @@ describe('oss.js', () => {
expect(calls.setView).toEqual([]);
});
- it('loadOssCatalog maps the IPC envelope and memoizes (one round-trip)', async () => {
+ it('loadOssCatalog uses bundled cache first, then refreshes without duplicate calls', async () => {
const payload = {
list: [{ id: 'x', name: 'X', task_zh: 't', task_en: 't', category: 'anim', driver: 'cli', stars: 10 }],
categories: [{ code: 'anim', name_zh: '动画', name_en: 'Animation' }],
@@ -127,8 +127,165 @@ describe('oss.js', () => {
const b = await context.loadOssCatalog();
expect(a.projects).toHaveLength(1);
expect(a.categories).toHaveLength(1);
- expect(b).toBe(a); // same memoized result
+ expect(b.projects).toHaveLength(1);
+ const listCalls = invokeCalls.filter((c) => c.channel === 'marketplace.listProjects');
+ expect(listCalls).toHaveLength(2);
+ expect(listCalls[0].payload).toEqual({ local_only: true });
+ expect(listCalls[1].payload).toEqual({});
+ });
+
+ it('loadOssCatalog returns disk cache first and refreshes once in the background', async () => {
+ const cachedProject = { id: 'cached', name: 'Cached', task_zh: '旧', task_en: 'old', category: 'anim', driver: 'cli' };
+ const freshPayload = {
+ source: 'server',
+ list: [{ id: 'fresh', name: 'Fresh', task_zh: '新', task_en: 'new', category: 'anim', driver: 'cli' }],
+ categories: [{ code: 'anim', name_zh: '动画', name_en: 'Animation' }],
+ total: 1,
+ };
+ let resolveList: (value: unknown) => void = () => {};
+ const listPromise = new Promise((resolve) => { resolveList = resolve; });
+ const { context, invokeCalls } = loadOss({
+ invoke: async (channel) => {
+ if (channel === 'marketplace.getListingsCache') {
+ return {
+ entries: {
+ 'project|home|||': { items: [cachedProject], categories: [], total: 1, ts: Date.now() },
+ },
+ };
+ }
+ if (channel === 'marketplace.mergeListingsCache') return { ok: true };
+ return listPromise;
+ },
+ });
+
+ const a = await context.loadOssCatalog({ homeOnly: true });
+ const b = await context.loadOssCatalog({ homeOnly: true });
+
+ expect(a.projects.map((p: any) => p.id)).toEqual(['cached']);
+ expect(b.projects.map((p: any) => p.id)).toEqual(['cached']);
expect(invokeCalls.filter((c) => c.channel === 'marketplace.listProjects')).toHaveLength(1);
+
+ resolveList(freshPayload);
+ await listPromise;
+ await Promise.resolve();
+ const c = await context.loadOssCatalog({ homeOnly: true, revalidate: false });
+ expect(c.projects.map((p: any) => p.id)).toEqual(['fresh']);
+ });
+
+ it('loadOssCatalog stores bundled fallback as stale cache', async () => {
+ const { context, invokeCalls } = loadOss({
+ invoke: async (channel) => {
+ if (channel === 'marketplace.getListingsCache') return { entries: {} };
+ if (channel === 'marketplace.mergeListingsCache') return { ok: true };
+ return {
+ source: 'bundled',
+ stale: true,
+ list: [{ id: 'bundled', name: 'Bundled', task_zh: '本地', task_en: 'local', category: 'anim', driver: 'cli' }],
+ categories: [],
+ total: 1,
+ };
+ },
+ });
+
+ await context.loadOssCatalog({ homeOnly: true });
+
+ const merge = invokeCalls.find((c) => c.channel === 'marketplace.mergeListingsCache');
+ expect(merge?.payload.entries['project|home|||'].ts).toBe(0);
+ });
+
+ it('loadOssCatalog does not replace real cache with bundled fallback', async () => {
+ const cachedProject = { id: 'server-cached', name: 'Server Cached', task_zh: '缓存', task_en: 'cached', category: 'anim', driver: 'cli' };
+ const { context } = loadOss({
+ invoke: async (channel) => {
+ if (channel === 'marketplace.getListingsCache') {
+ return {
+ entries: {
+ 'project|home|||': { items: [cachedProject], categories: [], total: 1, ts: Date.now() },
+ },
+ };
+ }
+ if (channel === 'marketplace.mergeListingsCache') return { ok: true };
+ return {
+ source: 'bundled',
+ stale: true,
+ list: [{ id: 'bundled', name: 'Bundled', task_zh: '本地', task_en: 'local', category: 'anim', driver: 'cli' }],
+ categories: [],
+ total: 1,
+ };
+ },
+ });
+
+ await context.loadOssCatalog({ homeOnly: true });
+ await Promise.resolve();
+ const current = await context.loadOssCatalog({ homeOnly: true, revalidate: false });
+
+ expect(current.projects.map((p: any) => p.id)).toEqual(['server-cached']);
+ });
+
+ it('homepage cold-start policy skips refresh when server cache is under 4h old', async () => {
+ const cachedProject = { id: 'warm', name: 'Warm', task_zh: '缓存', task_en: 'cached', category: 'anim', driver: 'cli' };
+ const { context, invokeCalls } = loadOss({
+ invoke: async (channel) => {
+ if (channel === 'marketplace.getListingsCache') {
+ return {
+ entries: {
+ 'project|home|||': { items: [cachedProject], categories: [], total: 1, ts: Date.now() },
+ },
+ };
+ }
+ if (channel === 'marketplace.mergeListingsCache') return { ok: true };
+ return {
+ source: 'server',
+ list: [{ id: 'fresh', name: 'Fresh', task_zh: '新', task_en: 'new', category: 'anim', driver: 'cli' }],
+ categories: [],
+ total: 1,
+ };
+ },
+ });
+
+ const data = await context.loadOssCatalog({ homeOnly: true, revalidate: 'cold-start' });
+
+ expect(data.projects.map((p: any) => p.id)).toEqual(['warm']);
+ expect(invokeCalls.filter((c) => c.channel === 'marketplace.listProjects')).toHaveLength(0);
+ });
+
+ it('homepage cold-start policy refreshes stale cache once per renderer boot', async () => {
+ const cachedProject = { id: 'old', name: 'Old', task_zh: '旧', task_en: 'old', category: 'anim', driver: 'cli' };
+ let resolveList: (value: unknown) => void = () => {};
+ const listPromise = new Promise((resolve) => { resolveList = resolve; });
+ const { context, invokeCalls } = loadOss({
+ invoke: async (channel) => {
+ if (channel === 'marketplace.getListingsCache') {
+ return {
+ entries: {
+ 'project|home|||': {
+ items: [cachedProject],
+ categories: [],
+ total: 1,
+ ts: Date.now() - (4 * 60 * 60 * 1000) - 1,
+ },
+ },
+ };
+ }
+ if (channel === 'marketplace.mergeListingsCache') return { ok: true };
+ return listPromise;
+ },
+ });
+
+ await context.loadOssCatalog({ homeOnly: true, revalidate: 'cold-start' });
+ await context.loadOssCatalog({ homeOnly: true, revalidate: 'cold-start' });
+
+ expect(invokeCalls.filter((c) => c.channel === 'marketplace.listProjects')).toHaveLength(1);
+ resolveList({
+ source: 'server',
+ list: [{ id: 'fresh', name: 'Fresh', task_zh: '新', task_en: 'new', category: 'anim', driver: 'cli' }],
+ categories: [],
+ total: 1,
+ });
+ await listPromise;
+ await Promise.resolve();
+ const current = await context.loadOssCatalog({ homeOnly: true, revalidate: false });
+ expect(current.projects.map((p: any) => p.id)).toEqual(['fresh']);
});
it('loadOssCatalog passes home/search/category options through to Server', async () => {
@@ -142,8 +299,12 @@ describe('oss.js', () => {
await context.loadOssCatalog({ homeOnly: true });
await context.loadOssCatalog({ category: 'rag', q: 'llama', size: 100 });
const listCalls = invokeCalls.filter((c) => c.channel === 'marketplace.listProjects');
- expect(listCalls[0].payload).toEqual({ home_only: true });
- expect(listCalls[1].payload).toEqual({ category: 'rag', q: 'llama', size: 100 });
+ expect(listCalls.map((c) => c.payload)).toEqual([
+ { home_only: true, local_only: true },
+ { home_only: true },
+ { category: 'rag', q: 'llama', size: 100, local_only: true },
+ { category: 'rag', q: 'llama', size: 100 },
+ ]);
});
it('ossGithubUrl derives the repo page', () => {