Adds packages/nowledge-mem-agent (@magpie-community/agent-nowledge-mem
0.1.0), a kind: agent registry entry and a row in the README's Agents table.
Picking a magpie model for the "Nowledge Mem / AI Now" agent points
Nowledge's Default, AI Now and Background purposes at one native
`magpie:nowledge-agent` provider instance; disconnecting restores what the
user had. Distinct from packages/nowledge-mem (gateway recall/capture).
The descriptor (nowledge-mem.agent.js) records the selection; a
dependency-free Bun main syncs it through Nowledge's /remote-llm/* routes
with a journal, manual-edit detection, a restore phase, a pid lock and 0600
atomic writes. Remote backends need HTTPS with a key, redirects are
refused, and unchanged remote polls back off to 30s.
Reviewed head d3b6e3937b371dea24839fe602818c4e6aa4d03d, merged onto
origin/main 049295f5 (clean). Run on mote (macOS) and WSL2 Ubuntu 24.04,
Bun 1.4.2, HOME=$(mktemp -d) each run:
- bun test packages/nowledge-mem-agent: 28 pass, 0 fail (both machines)
- bun scripts/check.mjs nowledge-mem-agent: ok (it skips agent hooks)
- bun scripts/check.mjs: exit 0
- repo-root bun test: 6608 pass, 20 skip, 0 fail (479 files)
Broken by hand, one at a time, each red on the named test:
redirect: 'error'; the quiet-period return; the remote backoff skip;
!referenced before provider removal; defaultRestored before turning
Remote off; the native provider_type check; the per-purpose shape check;
the sandbox's XDG containment; the sandbox's agent-home deletes; the
sandbox's HOME check (its two halves together; each alone is covered by
the other).
Not tried by the reviewer: a real Nowledge Mem app or nmem (the author
reports a contract run on Nowledge 0.10.115), the opt-in smoke and
contract scripts, the runtime inside magpie's plugin host, Windows.
26 lines
1.7 KiB
JavaScript
26 lines
1.7 KiB
JavaScript
import { normalizeURL } from './api.mjs';
|
|
|
|
export function selectionFrom(value) {
|
|
if (value === null) return null;
|
|
// Magpie restores keys individually; a completely empty object is disconnect.
|
|
if (value && typeof value === 'object' && !Array.isArray(value) && !value.model && !value.gateway?.key && !value.gateway?.baseURL) return null;
|
|
if (!value || typeof value !== 'object' || typeof value.model !== 'string' || !value.model.trim() || typeof value.gateway?.key !== 'string' || !value.gateway.key.trim() || typeof value.gateway.baseURL !== 'string') throw new Error('Incomplete Magpie selection; refusing to change Nowledge.');
|
|
const baseURL = normalizeURL(value.gateway.baseURL);
|
|
if (!baseURL.endsWith('/v1')) throw new Error('Magpie gateway baseURL must end in /v1.');
|
|
return {model:value.model, gateway:{baseURL,key:value.gateway.key}, metadata:value.metadata ?? {}};
|
|
}
|
|
|
|
export function providerConfig(selection, provider) {
|
|
const n = selection.metadata;
|
|
const body = {
|
|
enabled:true, provider, provider_type:'magpie', display_name:'Magpie · Nowledge Agent',
|
|
model:selection.model, api_key:selection.gateway.key, api_base:selection.gateway.baseURL,
|
|
api_format:'chat_completions', temperature:0.7, max_tokens:8192, timeout:600,
|
|
extra_params:{no_activate:true, preserve_enabled:true},
|
|
};
|
|
if (Number.isSafeInteger(n.context) && n.context > 0) body.context_window = n.context;
|
|
if (Number.isSafeInteger(n.output) && n.output > 0) body.max_tokens = Math.min(8192,n.output);
|
|
if (typeof n.images === 'boolean') body.extra_params._nmem_provider_capabilities = {vision:n.images,vision_model:{model:selection.model,supports_image_input:n.images}};
|
|
return body;
|
|
}
|