chore(release): 0.10.5
Bumps the manifest, version fallback and README, and rebuilds lib/ and client/ so the committed artifacts match the sources.
This commit is contained in:
parent
48d135aff9
commit
645e47bd59
|
|
@ -1,5 +1,9 @@
|
||||||
# dsh-brain
|
# dsh-brain
|
||||||
|
|
||||||
|
> **0.10.5**:记忆界面改为读取 Mnemon——Brain 面板的概览与记忆页签通过宿主里
|
||||||
|
> Mnemon 的只读通道取数,dsh-brain 不再自存记忆(旧本地库保留作兜底,后续移除)。
|
||||||
|
> 其余见下。
|
||||||
|
>
|
||||||
> **0.10.3**:插件按功能拆成六个可单独开关的子插件,新增可选的原始记录层
|
> **0.10.3**:插件按功能拆成六个可单独开关的子插件,新增可选的原始记录层
|
||||||
> `dsh-brain-raw`(见「六个子插件」);同步清理了不可达的防御性分支与重复
|
> `dsh-brain-raw`(见「六个子插件」);同步清理了不可达的防御性分支与重复
|
||||||
> 响应校验。0.10.1 起技能同步按内容与更新时间自动解决冲突(0.9.9/0.9.10
|
> 响应校验。0.10.1 起技能同步按内容与更新时间自动解决冲突(0.9.9/0.9.10
|
||||||
|
|
@ -9,7 +13,7 @@
|
||||||
活动记录(只上传元数据),并把云端记忆库变成 agent 可用的工具;同时双向
|
活动记录(只上传元数据),并把云端记忆库变成 agent 可用的工具;同时双向
|
||||||
同步云端技能中心与本机技能目录。
|
同步云端技能中心与本机技能目录。
|
||||||
|
|
||||||
当前版本 **0.10.3**,含宿主端与浏览器端两部分:宿主端负责活动上报、
|
当前版本 **0.10.5**,含宿主端与浏览器端两部分:宿主端负责活动上报、
|
||||||
记忆工具注册与技能同步。浏览器 UI 有三个入口:
|
记忆工具注册与技能同步。浏览器 UI 有三个入口:
|
||||||
|
|
||||||
- 左侧栏 **Brain** 展示全局运行状态,管理全局记忆与部门。
|
- 左侧栏 **Brain** 展示全局运行状态,管理全局记忆与部门。
|
||||||
|
|
|
||||||
554
client/index.js
554
client/index.js
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,5 @@
|
||||||
import { brainKernel, VERSION } from "../kernel.js";
|
import { brainKernel, VERSION } from "../kernel.js";
|
||||||
|
import { mnemonReadFromContext } from "../mnemon/read-service.js";
|
||||||
import { createCoreRoutes, legacyAliases } from "../routes.js";
|
import { createCoreRoutes, legacyAliases } from "../routes.js";
|
||||||
import { createSettingsUiRoutes } from "../settings-ui/routes.js";
|
import { createSettingsUiRoutes } from "../settings-ui/routes.js";
|
||||||
export const name = 'dsh-brain-ui';
|
export const name = 'dsh-brain-ui';
|
||||||
|
|
@ -34,7 +35,10 @@ export function apply(ctx, config) {
|
||||||
}
|
}
|
||||||
const routes = [
|
const routes = [
|
||||||
...createSettingsUiRoutes({ version: VERSION, store: kernel.store }),
|
...createSettingsUiRoutes({ version: VERSION, store: kernel.store }),
|
||||||
...createCoreRoutes(kernel.routeDeps()),
|
...createCoreRoutes({
|
||||||
|
...kernel.routeDeps(),
|
||||||
|
mnemon: () => mnemonReadFromContext(ctx),
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
routes.push(...legacyAliases(routes));
|
routes.push(...legacyAliases(routes));
|
||||||
for (const route of routes) {
|
for (const route of routes) {
|
||||||
|
|
|
||||||
|
|
@ -282,9 +282,13 @@ export class LocalMemoryManager {
|
||||||
return record.scope === 'project' && record.projectId === projectId;
|
return record.scope === 'project' && record.projectId === projectId;
|
||||||
});
|
});
|
||||||
const seen = new Set();
|
const seen = new Set();
|
||||||
|
// The whole merged set is ordered before pagination (never just the page).
|
||||||
|
// `updated` keeps the historical order; `created` is the API's new default.
|
||||||
|
const compare = options.order === 'created'
|
||||||
|
? (a, b) => b.createdAt.localeCompare(a.createdAt) || a.id.localeCompare(b.id)
|
||||||
|
: (a, b) => b.updatedAt.localeCompare(a.updatedAt) || a.id.localeCompare(b.id);
|
||||||
const ordered = scoped.filter((record) => { if (seen.has(record.id))
|
const ordered = scoped.filter((record) => { if (seen.has(record.id))
|
||||||
return false; seen.add(record.id); return true; })
|
return false; seen.add(record.id); return true; }).sort(compare);
|
||||||
.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt) || a.id.localeCompare(b.id));
|
|
||||||
const offset = Math.max(0, Math.trunc(options.offset ?? 0));
|
const offset = Math.max(0, Math.trunc(options.offset ?? 0));
|
||||||
const limit = Math.max(1, Math.min(1000, Math.trunc(options.limit ?? 50)));
|
const limit = Math.max(1, Math.min(1000, Math.trunc(options.limit ?? 50)));
|
||||||
return { items: ordered.slice(offset, offset + limit), total: ordered.length };
|
return { items: ordered.slice(offset, offset + limit), total: ordered.length };
|
||||||
|
|
|
||||||
|
|
@ -187,10 +187,15 @@ export class JsonMemoryStore {
|
||||||
}
|
}
|
||||||
async list(options = {}) {
|
async list(options = {}) {
|
||||||
const file = await this.readFile();
|
const file = await this.readFile();
|
||||||
const records = this.activeRecords(file).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
const records = this.activeRecords(file);
|
||||||
|
// Order the whole set before slicing: paging must stay stable across pages.
|
||||||
|
// `updated` keeps the historical order; `created` is the API's new default.
|
||||||
|
const ordered = options.order === 'created'
|
||||||
|
? records.sort((a, b) => b.createdAt.localeCompare(a.createdAt) || a.id.localeCompare(b.id))
|
||||||
|
: records.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
||||||
const offset = Math.max(0, Math.trunc(options.offset ?? 0));
|
const offset = Math.max(0, Math.trunc(options.offset ?? 0));
|
||||||
const limit = Math.max(1, Math.min(1000, Math.trunc(options.limit ?? 50)));
|
const limit = Math.max(1, Math.min(1000, Math.trunc(options.limit ?? 50)));
|
||||||
return { items: records.slice(offset, offset + limit), total: records.length };
|
return { items: ordered.slice(offset, offset + limit), total: ordered.length };
|
||||||
}
|
}
|
||||||
async update(id, patch, expectedRevision) {
|
async update(id, patch, expectedRevision) {
|
||||||
return withFileLock(this.lockPath, async () => { const file = await this.readFile(); const record = file.records.find((item) => item.id === id && item.deleted !== true); if (record === undefined)
|
return withFileLock(this.lockPath, async () => { const file = await this.readFile(); const record = file.records.find((item) => item.id === id && item.deleted !== true); if (record === undefined)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
* Read-only bridge to the live Mnemon Host RPC service.
|
||||||
|
*
|
||||||
|
* Mnemon registers `mnemonRemote` as a Typert service; its `read` method is the
|
||||||
|
* same read handler its own `/dsh-mnemon-read` channel serves. dsh-brain reads
|
||||||
|
* through that service instead of copying Mnemon data: no storage layout is
|
||||||
|
* touched, and no write/forget endpoint is exposed here.
|
||||||
|
*
|
||||||
|
* The service name is resolved lazily from the live Cordis context, so the
|
||||||
|
* plugin loads and runs when Mnemon is absent; the read routes then answer
|
||||||
|
* 503 instead of failing plugin activation.
|
||||||
|
*/
|
||||||
|
import { resolve } from 'node:path';
|
||||||
|
/**
|
||||||
|
* Resolve the live Mnemon read service from a host Context.
|
||||||
|
*
|
||||||
|
* `mnemonRemote` is provided by the installed `dsh-mnemon` Host entry. A
|
||||||
|
* missing service (Mnemon not installed, entry disabled, or a host without the
|
||||||
|
* web transport) returns undefined; the caller exposes that as a capability
|
||||||
|
* gap, never as a read of stale data.
|
||||||
|
*/
|
||||||
|
export function mnemonReadFromContext(ctx) {
|
||||||
|
const get = ctx.get;
|
||||||
|
if (typeof get !== 'function')
|
||||||
|
return undefined;
|
||||||
|
const lookup = (name) => {
|
||||||
|
try {
|
||||||
|
return get.call(ctx, name, false);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const candidate = lookup('mnemonRemote');
|
||||||
|
if (candidate === null || typeof candidate !== 'object')
|
||||||
|
return undefined;
|
||||||
|
const read = candidate.read;
|
||||||
|
if (typeof read !== 'function')
|
||||||
|
return undefined;
|
||||||
|
const service = candidate;
|
||||||
|
return {
|
||||||
|
read: (endpoint, payload, signal) => signal === undefined
|
||||||
|
? service.read(endpoint, payload)
|
||||||
|
: service.read(endpoint, payload, signal),
|
||||||
|
workspaceIdForPath: (path) => {
|
||||||
|
const registry = lookup('workspaceRegistry');
|
||||||
|
if (registry === undefined || typeof registry.list !== 'function')
|
||||||
|
return undefined;
|
||||||
|
let spaces;
|
||||||
|
try {
|
||||||
|
spaces = registry.list();
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const target = resolve(path);
|
||||||
|
const found = spaces.find((space) => typeof space.id === 'string'
|
||||||
|
&& typeof space.path === 'string' && resolve(space.path) === target);
|
||||||
|
return typeof found?.id === 'string' ? found.id : undefined;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
114
lib/routes.js
114
lib/routes.js
|
|
@ -21,6 +21,7 @@ export const ROUTES = {
|
||||||
migrate: '/dsh-brain/migrate',
|
migrate: '/dsh-brain/migrate',
|
||||||
localMemory: '/dsh-brain/local-memory',
|
localMemory: '/dsh-brain/local-memory',
|
||||||
departments: '/dsh-brain/departments',
|
departments: '/dsh-brain/departments',
|
||||||
|
mnemon: '/dsh-brain/mnemon',
|
||||||
};
|
};
|
||||||
/** Reported when the MCP sub-plugin entry is not applied; the client keeps the tab hidden. */
|
/** Reported when the MCP sub-plugin entry is not applied; the client keeps the tab hidden. */
|
||||||
const MCP_UNAVAILABLE = {
|
const MCP_UNAVAILABLE = {
|
||||||
|
|
@ -164,10 +165,16 @@ async function serveLocalMemory(deps, req, res) {
|
||||||
json(res, 200, { ok: true, ...(await manager.storageStatus(workspace, scope)) });
|
json(res, 200, { ok: true, ...(await manager.storageStatus(workspace, scope)) });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const orderParam = url.searchParams.get('order');
|
||||||
|
if (orderParam !== null && orderParam !== 'created' && orderParam !== 'updated') {
|
||||||
|
fail(res, 400, 'invalid-order');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const order = orderParam === 'updated' ? 'updated' : 'created';
|
||||||
const limit = Math.max(1, Math.min(1000, Number.parseInt(url.searchParams.get('limit') ?? '50', 10) || 50));
|
const limit = Math.max(1, Math.min(1000, Number.parseInt(url.searchParams.get('limit') ?? '50', 10) || 50));
|
||||||
const offset = Math.max(0, Number.parseInt(url.searchParams.get('offset') ?? '0', 10) || 0);
|
const offset = Math.max(0, Number.parseInt(url.searchParams.get('offset') ?? '0', 10) || 0);
|
||||||
const page = await manager.list({ limit, offset, scope }, workspace);
|
const page = await manager.list({ limit, offset, scope, order }, workspace);
|
||||||
json(res, 200, { ok: true, total: page.total, items: page.items.map((record) => ({ id: record.id, scope: record.scope, content: record.content, category: record.category, tags: record.tags, source: record.source, revision: record.revision, updatedAt: record.updatedAt })) });
|
json(res, 200, { ok: true, total: page.total, items: page.items.map((record) => ({ id: record.id, scope: record.scope, content: record.content, category: record.category, tags: record.tags, source: record.source, revision: record.revision, createdAt: record.createdAt, updatedAt: record.updatedAt })) });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (suffix === '/spaces') {
|
if (suffix === '/spaces') {
|
||||||
|
|
@ -350,6 +357,104 @@ async function serveMigrate(_deps, req, res) {
|
||||||
}
|
}
|
||||||
fail(res, 404, 'unknown-migrate-route');
|
fail(res, 404, 'unknown-migrate-route');
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Read-only Mnemon bridge: `GET /dsh-brain/mnemon/<endpoint>`.
|
||||||
|
*
|
||||||
|
* The body is Mnemon's own RPC result envelope (`{ok,value}` / `{ok,error}`);
|
||||||
|
* query parameters map 1:1 onto the endpoint's payload. Only reads are
|
||||||
|
* exposed: there is no remember/forget route here, by design.
|
||||||
|
*/
|
||||||
|
async function serveMnemonRead(deps, req, res) {
|
||||||
|
if (req.method !== 'GET') {
|
||||||
|
fail(res, 405, 'method-not-allowed');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const bridge = deps.mnemon?.();
|
||||||
|
if (bridge === undefined) {
|
||||||
|
json(res, 503, { ok: false, error: { code: 'mnemon-unavailable', message: 'Mnemon 读服务未接入:当前宿主没有 mnemonRemote 服务。' } });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const url = new URL(req.url ?? '/', 'http://localhost');
|
||||||
|
const suffix = url.pathname.slice(ROUTES.mnemon.length).replace(/\/+$/, '');
|
||||||
|
const endpoints = {
|
||||||
|
'/list': 'list',
|
||||||
|
'/status': 'status',
|
||||||
|
'/search': 'search',
|
||||||
|
'/runtime': 'runtime-memory',
|
||||||
|
'/documents': 'documents',
|
||||||
|
};
|
||||||
|
const endpoint = endpoints[suffix];
|
||||||
|
if (endpoint === undefined) {
|
||||||
|
fail(res, 404, 'unknown-mnemon-route');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const workspaceIdParam = url.searchParams.get('workspaceId')?.trim();
|
||||||
|
const workspacePath = url.searchParams.get('workspace')?.trim();
|
||||||
|
const sessionId = url.searchParams.get('sessionId')?.trim() || undefined;
|
||||||
|
const workspaceId = workspaceIdParam !== undefined && workspaceIdParam !== ''
|
||||||
|
? workspaceIdParam
|
||||||
|
: workspacePath !== undefined && workspacePath !== ''
|
||||||
|
? bridge.workspaceIdForPath(workspacePath)
|
||||||
|
: undefined;
|
||||||
|
const scope = {
|
||||||
|
...(workspaceId === undefined ? {} : { workspaceId }),
|
||||||
|
...(sessionId === undefined ? {} : { sessionId }),
|
||||||
|
};
|
||||||
|
const ids = url.searchParams.getAll('memoryBodyIds').flatMap((value) => value.split(',')).map((value) => value.trim()).filter((value) => value !== '');
|
||||||
|
const memoryBodyIds = ids.length === 0 ? undefined : [...new Set(ids)];
|
||||||
|
const limit = (fallback) => {
|
||||||
|
const parsed = Number.parseInt(url.searchParams.get('limit') ?? '', 10);
|
||||||
|
return Number.isFinite(parsed) ? Math.max(1, Math.min(1000, parsed)) : fallback;
|
||||||
|
};
|
||||||
|
let payload;
|
||||||
|
if (endpoint === 'list') {
|
||||||
|
const query = url.searchParams.get('query')?.trim();
|
||||||
|
const category = url.searchParams.get('category')?.trim();
|
||||||
|
payload = {
|
||||||
|
...scope,
|
||||||
|
limit: limit(50),
|
||||||
|
...(query === undefined || query === '' ? {} : { query }),
|
||||||
|
...(category === undefined || category === '' ? {} : { category }),
|
||||||
|
...(memoryBodyIds === undefined ? {} : { memoryBodyIds }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (endpoint === 'search') {
|
||||||
|
const query = (url.searchParams.get('q') ?? url.searchParams.get('query') ?? '').trim();
|
||||||
|
if (query === '') {
|
||||||
|
fail(res, 400, 'query-required');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const mode = url.searchParams.get('mode')?.trim();
|
||||||
|
const category = url.searchParams.get('category')?.trim();
|
||||||
|
const source = url.searchParams.get('source')?.trim();
|
||||||
|
const intent = url.searchParams.get('intent')?.trim();
|
||||||
|
payload = {
|
||||||
|
query,
|
||||||
|
...scope,
|
||||||
|
limit: limit(10),
|
||||||
|
...(mode === undefined || mode === '' ? {} : { mode }),
|
||||||
|
...(category === undefined || category === '' ? {} : { category }),
|
||||||
|
...(source === undefined || source === '' ? {} : { source }),
|
||||||
|
...(intent === undefined || intent === '' ? {} : { intent }),
|
||||||
|
...(memoryBodyIds === undefined ? {} : { memoryBodyIds }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
payload = scope;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const result = await bridge.read(endpoint, payload);
|
||||||
|
if (result.ok) {
|
||||||
|
json(res, 200, { ok: true, value: result.value });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const status = result.error.code === 'bad-request' ? 400 : 502;
|
||||||
|
json(res, status, { ok: false, error: result.error });
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
json(res, 502, { ok: false, error: { code: 'mnemon-error', message: error instanceof Error ? error.message : String(error) } });
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Pre-rename aliases (0.8.0): the same route objects under the old
|
* Pre-rename aliases (0.8.0): the same route objects under the old
|
||||||
* `/cloud-memory` prefix. Each sub-plugin entry aliases its own slice this
|
* `/cloud-memory` prefix. Each sub-plugin entry aliases its own slice this
|
||||||
|
|
@ -408,6 +513,11 @@ export function createCoreRoutes(deps) {
|
||||||
path: ROUTES.departments,
|
path: ROUTES.departments,
|
||||||
handler: (req, res) => serveDepartments(deps, req, res),
|
handler: (req, res) => serveDepartments(deps, req, res),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: 'prefix',
|
||||||
|
path: ROUTES.mnemon,
|
||||||
|
handler: (req, res) => serveMnemonRead(deps, req, res),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
kind: 'exact',
|
kind: 'exact',
|
||||||
path: ROUTES.status,
|
path: ROUTES.status,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
const FALLBACK_VERSION = '0.10.4';
|
const FALLBACK_VERSION = '0.10.5';
|
||||||
function readVersion() {
|
function readVersion() {
|
||||||
try {
|
try {
|
||||||
const manifest = JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'));
|
const manifest = JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'));
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "dsh-brain",
|
"name": "dsh-brain",
|
||||||
"version": "0.10.4",
|
"version": "0.10.5",
|
||||||
"description": "Cloud memory for DSH: report one activity turn per conversation round and expose memory_search / memory_read / memory_add tools against a LongMemory cloud endpoint.",
|
"description": "Cloud memory for DSH: report one activity turn per conversation round and expose memory_search / memory_read / memory_add tools against a LongMemory cloud endpoint.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
import { readFileSync } from 'node:fs'
|
import { readFileSync } from 'node:fs'
|
||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
const FALLBACK_VERSION = '0.10.4'
|
const FALLBACK_VERSION = '0.10.5'
|
||||||
|
|
||||||
function readVersion(): string {
|
function readVersion(): string {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue