Пакетный импорт заметок из thatch: API import-notes и лимит 16000
This commit is contained in:
parent
85ecb086fb
commit
7b2cc8ce52
1 changed files with 26 additions and 3 deletions
29
index.js
29
index.js
|
|
@ -26,7 +26,7 @@ const { Pool } = pg
|
||||||
export const name = 'memory'
|
export const name = 'memory'
|
||||||
export const inject = ['tools', 'systemPrompt']
|
export const inject = ['tools', 'systemPrompt']
|
||||||
|
|
||||||
const MAX_BODY = 4000
|
const MAX_BODY = 16000
|
||||||
const MAX_TAGS = 8
|
const MAX_TAGS = 8
|
||||||
const MAX_TAG_LEN = 32
|
const MAX_TAG_LEN = 32
|
||||||
const RECALL_BODY_LIMIT = 280
|
const RECALL_BODY_LIMIT = 280
|
||||||
|
|
@ -1424,7 +1424,7 @@ function registerCommand(ctx, engine, settings, recall, logger) {
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// HTTP API для менеджера паролей в карточке плагина
|
// HTTP API для менеджера паролей в карточке плагина
|
||||||
|
|
||||||
function registerApi(ctx, engine, settings, logger) {
|
function registerApi(ctx, engine, settings, logger, recall) {
|
||||||
const web = ctx.get('webServer')
|
const web = ctx.get('webServer')
|
||||||
if (web === undefined || typeof web.register !== 'function') return
|
if (web === undefined || typeof web.register !== 'function') return
|
||||||
|
|
||||||
|
|
@ -1480,6 +1480,29 @@ function registerApi(ctx, engine, settings, logger) {
|
||||||
send(res, 200, saved)
|
send(res, 200, saved)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (action === 'import-notes') {
|
||||||
|
const notes = Array.isArray(body.notes) ? body.notes : []
|
||||||
|
if (notes.length === 0) { send(res, 400, { error: 'notes[] is required' }); return }
|
||||||
|
if (notes.length > 200) { send(res, 400, { error: 'at most 200 notes per call' }); return }
|
||||||
|
let imported = 0
|
||||||
|
for (const note of notes) {
|
||||||
|
const text = normalizeBody(note?.body)
|
||||||
|
if (text.length === 0) continue
|
||||||
|
const scope = note.scope === 'workspace' ? 'workspace' : 'global'
|
||||||
|
await engine.saveNote({
|
||||||
|
body: text,
|
||||||
|
tags: normalizeTags(note.tags),
|
||||||
|
scope,
|
||||||
|
workspace: scope === 'workspace' ? note.workspace : undefined,
|
||||||
|
pinned: note.pinned === true,
|
||||||
|
collection: normalizeCollection(note.collection) ?? 'general',
|
||||||
|
})
|
||||||
|
imported += 1
|
||||||
|
}
|
||||||
|
recall.invalidate()
|
||||||
|
send(res, 200, { imported })
|
||||||
|
return
|
||||||
|
}
|
||||||
if (action === 'forget') {
|
if (action === 'forget') {
|
||||||
const removed = await engine.forgetSecret(requireMatch(body.match ?? body.id ?? body.name))
|
const removed = await engine.forgetSecret(requireMatch(body.match ?? body.id ?? body.name))
|
||||||
if (removed === undefined) { send(res, 404, { error: 'secret not found' }); return }
|
if (removed === undefined) { send(res, 404, { error: 'secret not found' }); return }
|
||||||
|
|
@ -1535,7 +1558,7 @@ export async function apply(ctx, config) {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
registerCommand(ctx, engine, settings, recall, logger)
|
registerCommand(ctx, engine, settings, recall, logger)
|
||||||
registerApi(ctx, engine, settings, logger)
|
registerApi(ctx, engine, settings, logger, recall)
|
||||||
|
|
||||||
const skills = ctx.get('skills')
|
const skills = ctx.get('skills')
|
||||||
if (skills !== undefined && typeof skills.register === 'function') {
|
if (skills !== undefined && typeof skills.register === 'function') {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue