更新 lib/index.js
This commit is contained in:
parent
484e2d892d
commit
00ddf1b966
34
lib/index.js
34
lib/index.js
|
|
@ -13,13 +13,16 @@ import { CloudClient } from "./api.js";
|
|||
import { Reporter } from "./reporter.js";
|
||||
import { createRoutes } from "./routes.js";
|
||||
import { SettingsStore } from "./store.js";
|
||||
import { createMemoryTools } from "./tools.js";
|
||||
import { SkillSync } from "./skill-sync.js";
|
||||
import { createMemoryTools, createSkillTools } from "./tools.js";
|
||||
/** Package name; also the client bundle id. */
|
||||
export const name = 'dsh-cloud-memory';
|
||||
/** Services required before `apply` runs. */
|
||||
export const inject = ['webServer'];
|
||||
/** Version reported by the status card. */
|
||||
const VERSION = '0.2.0';
|
||||
const VERSION = '0.3.0';
|
||||
/** How often the skill directory is reconciled with the cloud center. */
|
||||
const SKILL_SYNC_INTERVAL_MS = 15 * 60_000;
|
||||
/** How often queued reports are retried. */
|
||||
const RETRY_INTERVAL_MS = 30_000;
|
||||
/** Register the plugin with the host. */
|
||||
|
|
@ -41,6 +44,15 @@ export function apply(ctx, config) {
|
|||
summaryToken: () => store.summaryToken(),
|
||||
log: (message) => logger.warn(message),
|
||||
});
|
||||
const skillSync = new SkillSync({
|
||||
client: () => client,
|
||||
settings: () => ({
|
||||
enabled: settings().enabled,
|
||||
skillsSyncEnabled: settings().skillsSyncEnabled,
|
||||
skillsDir: settings().skillsDir,
|
||||
}),
|
||||
log: (message) => logger.info(message),
|
||||
});
|
||||
// Announce at most once per activation so a missing token is obvious in logs.
|
||||
const effective = settings();
|
||||
if (!effective.enabled) {
|
||||
|
|
@ -70,11 +82,12 @@ export function apply(ctx, config) {
|
|||
const tools = toolsCtx.tools;
|
||||
if (tools === undefined)
|
||||
return;
|
||||
for (const tool of createMemoryTools({
|
||||
const toolDeps = {
|
||||
client: () => client,
|
||||
memoryToken: () => store.memoryToken(),
|
||||
settings: () => ({ enabled: settings().enabled, defaultK: settings().defaultK }),
|
||||
})) {
|
||||
};
|
||||
for (const tool of [...createMemoryTools(toolDeps), ...createSkillTools(toolDeps)]) {
|
||||
toolsCtx.effect(() => tools.register(tool), `dsh-cloud-memory: tool ${tool.name}`);
|
||||
}
|
||||
});
|
||||
|
|
@ -83,7 +96,7 @@ export function apply(ctx, config) {
|
|||
logger.warn('webServer service unavailable; the configuration page stays disabled');
|
||||
}
|
||||
else {
|
||||
const routes = createRoutes({ version: VERSION, store, reporter, client: () => client });
|
||||
const routes = createRoutes({ version: VERSION, store, reporter, client: () => client, skills: () => skillSync.stats() });
|
||||
for (const route of routes) {
|
||||
ctx.effect(() => webServer.register(route), `dsh-cloud-memory: route ${route.path}`);
|
||||
}
|
||||
|
|
@ -99,4 +112,15 @@ export function apply(ctx, config) {
|
|||
timer.unref?.();
|
||||
return () => clearInterval(timer);
|
||||
}, 'dsh-cloud-memory: retry timer');
|
||||
ctx.effect(() => {
|
||||
const run = () => {
|
||||
if (store.memoryToken() !== '')
|
||||
void skillSync.syncOnce().catch(() => { });
|
||||
};
|
||||
const first = setTimeout(run, 5_000);
|
||||
first.unref?.();
|
||||
const timer = setInterval(run, SKILL_SYNC_INTERVAL_MS);
|
||||
timer.unref?.();
|
||||
return () => { clearTimeout(first); clearInterval(timer); };
|
||||
}, 'dsh-cloud-memory: skill sync timer');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue