Skip to content

The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.

Desktop: the skills gallery refreshes after a skill is added (#113)

taavie-z1da84e34e6fa
diff --git a/.changeset/refresh-added-skills.md b/.changeset/refresh-added-skills.md
new file mode 100644
index 0000000..fececb5
--- /dev/null
+++ b/.changeset/refresh-added-skills.md
@@ -0,0 +1,6 @@
+---
+"openfilm": patch
+"@openfilm/desktop": patch
+---
+
+Refresh the open skills gallery after adding a skill, without reloading the page.
diff --git a/apps/desktop/chat/src/App.tsx b/apps/desktop/chat/src/App.tsx
index 36d1f8d..8dcc1f1 100644
--- a/apps/desktop/chat/src/App.tsx
+++ b/apps/desktop/chat/src/App.tsx
@@ -17,6 +17,7 @@ import { ATTACHMENT_CARD, ATTACHMENT_THUMB, AttachmentCardBody, PlayMark } from
import { attachmentPlace } from '@/lib/attachment-place';
import { ModelPopover } from '@/components/ModelPopover';
import { AddSkillDialog, type PickedSkill } from '@/components/AddSkill';
+import { SKILLS_CHANGED } from 'openfilm/studio-ui/lib/project-sources.ts';
import { CardActions, CardButton, ComposerCard } from '@/components/ComposerCard';
import { LocalAgentQuestionCard } from '@/components/TurnQuestionCard';
import { Tooltip } from '@/components/Tooltip';
@@ -85,7 +86,6 @@ const CONTEXT_NOTICE_SHARE = 0.85;
/** On a video's thumbnail: it plays, it is not a picture. */
/* between the chat's root (the add-skill dialog) and the project's chat: a skill added, a skill to make */
-const SKILLS_CHANGED = 'openfilm:skills-changed';
const MAKE_SKILL = 'openfilm:make-skill';
export function App({ initialProject, initialSelection, initialFfmpeg }: {
diff --git a/packages/openfilm/studio/ui/src/components/ExamplesGallery.tsx b/packages/openfilm/studio/ui/src/components/ExamplesGallery.tsx
index e486e94..93a78ca 100644
--- a/packages/openfilm/studio/ui/src/components/ExamplesGallery.tsx
+++ b/packages/openfilm/studio/ui/src/components/ExamplesGallery.tsx
@@ -22,7 +22,7 @@ import {
} from 'lucide-react';
import { useLanguage, useT } from '@/i18n';
import { studioHost, type CommunityItem } from '@/lib/host';
-import { seenExamples, seenSkills, sourcesApi, type Example, type SkillEntry } from '@/lib/project-sources';
+import { seenExamples, seenSkills, sourcesApi, watchSkills, type Example, type SkillEntry } from '@/lib/project-sources';
import { GitHubDialog } from './ProjectSources';
export type ExamplesMode = 'start' | 'reference';
@@ -106,8 +106,8 @@ export function ExamplesGallery({ mode, projectId = null, heading, initial, onCl
React.useEffect(() => {
let alive = true;
void sourcesApi.examples().then((list) => { if (alive) setExamples(list); });
- if (community) void sourcesApi.skills(projectId).then((list) => { if (alive) setSkills(list); });
- return () => { alive = false; };
+ const stop = community ? watchSkills(projectId, setSkills) : undefined;
+ return () => { alive = false; stop?.(); };
}, [projectId, community]);
React.useEffect(() => {
diff --git a/packages/openfilm/studio/ui/src/lib/project-sources.test.ts b/packages/openfilm/studio/ui/src/lib/project-sources.test.ts
index ae79517..7603a98 100644
--- a/packages/openfilm/studio/ui/src/lib/project-sources.test.ts
+++ b/packages/openfilm/studio/ui/src/lib/project-sources.test.ts
@@ -3,8 +3,52 @@ import assert from 'node:assert/strict';
import {
SourceError, createSpeedMeter, examplesCollapsed, fetchErrorKey, followFetch, formatBytes, formatSeconds, looksLikeRepoUrl,
pathCrumbs, secondsLeft, setExamplesCollapsed, type FetchJob,
+ SKILLS_CHANGED, watchSkills, type SkillEntry,
} from './project-sources.ts';
+test('an open skills gallery reloads the current project after an addition and stops when closed', async (t) => {
+ const events = new EventTarget();
+ const lists: SkillEntry[][] = [];
+ const paths: string[] = [];
+ let skills: SkillEntry[] = [];
+ t.mock.method(globalThis, 'fetch', async (path: string) => {
+ paths.push(path);
+ return new Response(JSON.stringify({ skills }));
+ });
+ const stop = watchSkills('film 1', (list) => lists.push(list), events);
+ await new Promise(setImmediate);
+ assert.deepEqual(lists, [[]]);
+ skills = [{ name: 'new-skill', description: 'Added', source: 'mine', scripts: 0 }];
+ events.dispatchEvent(new Event(SKILLS_CHANGED));
+ await new Promise(setImmediate);
+ assert.deepEqual(lists.at(-1), skills);
+ assert.deepEqual(paths, ['/api/skills?project=film%201', '/api/skills?project=film%201']);
+ stop();
+ events.dispatchEvent(new Event(SKILLS_CHANGED));
+ await new Promise(setImmediate);
+ assert.equal(paths.length, 2);
+});
+
+test('a pre-addition request or closed gallery cannot publish a stale list', async (t) => {
+ const events = new EventTarget();
+ const pending: Array<(response: Response) => void> = [];
+ t.mock.method(globalThis, 'fetch', () => new Promise<Response>((resolve) => pending.push(resolve)));
+ const lists: SkillEntry[][] = [];
+ const stop = watchSkills(null, (list) => lists.push(list), events);
+ events.dispatchEvent(new Event(SKILLS_CHANGED));
+ const added: SkillEntry[] = [{ name: 'added', description: '', source: 'mine', scripts: 0 }];
+ pending[1]!(new Response(JSON.stringify({ skills: added })));
+ await new Promise(setImmediate);
+ pending[0]!(new Response(JSON.stringify({ skills: [] })));
+ await new Promise(setImmediate);
+ assert.deepEqual(lists, [added]);
+ events.dispatchEvent(new Event(SKILLS_CHANGED));
+ stop();
+ pending[2]!(new Response(JSON.stringify({ skills: [] })));
+ await new Promise(setImmediate);
+ assert.deepEqual(lists, [added]);
+});
+
test('what looks like a repository address enables "Get"', () => {
assert.ok(looksLikeRepoUrl('https://github.com/openfilm/examples/tree/main/one-prompt'));
assert.ok(looksLikeRepoUrl(' github.com/openfilm/examples '));
diff --git a/packages/openfilm/studio/ui/src/lib/project-sources.ts b/packages/openfilm/studio/ui/src/lib/project-sources.ts
index df61143..d7c8687 100644
--- a/packages/openfilm/studio/ui/src/lib/project-sources.ts
+++ b/packages/openfilm/studio/ui/src/lib/project-sources.ts
@@ -88,6 +88,21 @@ export const seenExamples = (): Example[] | null => seen.examples;
/** The skills read last for a project (else for no project: the official ones and the person's own), or null. */
export const seenSkills = (projectId?: string | null): SkillEntry[] | null => seen.skills.get(projectId ?? '') ?? seen.skills.get('') ?? null;
+/** The desktop's add dialog and Studio's gallery share the window. */
+export const SKILLS_CHANGED = 'openfilm:skills-changed';
+
+/** Read an open gallery's skills again after an addition; a stale request must not replace the newer list. */
+export function watchSkills(projectId: string | null | undefined, changed: (skills: SkillEntry[]) => void, events: EventTarget = window): () => void {
+ let revision = 0;
+ const refresh = () => {
+ const request = ++revision;
+ void sourcesApi.skills(projectId).then((skills) => { if (request === revision) changed(skills); });
+ };
+ events.addEventListener(SKILLS_CHANGED, refresh);
+ refresh();
+ return () => { ++revision; events.removeEventListener(SKILLS_CHANGED, refresh); };
+}
+
export const sourcesApi = {
browse: (path?: string | null) => call<BrowseListing>(`browse${path ? `?path=${encodeURIComponent(path)}` : ''}`),
/** opens the folder only when it holds a film: else a SourceError with code 'no-film' (or 'not-found') */