diff --git a/examples/openclaw-plugin/config.ts b/examples/openclaw-plugin/config.ts index a25037bdc..808a30ebc 100644 --- a/examples/openclaw-plugin/config.ts +++ b/examples/openclaw-plugin/config.ts @@ -16,6 +16,8 @@ export type MemoryOpenVikingConfig = { timeoutMs?: number; autoCapture?: boolean; captureMode?: "semantic" | "keyword"; + /** Minimum sanitized text length (chars) required to trigger auto-capture. Default 50. */ + captureMinLength?: number; captureMaxLength?: number; autoRecall?: boolean; recallLimit?: number; @@ -41,6 +43,7 @@ const DEFAULT_PORT = 1933; const DEFAULT_TARGET_URI = "viking://user/memories"; const DEFAULT_TIMEOUT_MS = 15000; const DEFAULT_CAPTURE_MODE = "semantic"; +const DEFAULT_CAPTURE_MIN_LENGTH = 50; const DEFAULT_CAPTURE_MAX_LENGTH = 24000; const DEFAULT_RECALL_LIMIT = 6; const DEFAULT_RECALL_SCORE_THRESHOLD = 0.15; @@ -131,6 +134,7 @@ export const memoryOpenVikingConfigSchema = { "timeoutMs", "autoCapture", "captureMode", + "captureMinLength", "captureMaxLength", "autoRecall", "recallLimit", @@ -185,6 +189,10 @@ export const memoryOpenVikingConfigSchema = { timeoutMs: Math.max(1000, Math.floor(toNumber(cfg.timeoutMs, DEFAULT_TIMEOUT_MS))), autoCapture: cfg.autoCapture !== false, captureMode: captureMode ?? DEFAULT_CAPTURE_MODE, + captureMinLength: Math.max( + 1, + Math.min(1000, Math.floor(toNumber(cfg.captureMinLength, DEFAULT_CAPTURE_MIN_LENGTH))), + ), captureMaxLength: Math.max( 200, Math.min(200_000, Math.floor(toNumber(cfg.captureMaxLength, DEFAULT_CAPTURE_MAX_LENGTH))), @@ -290,6 +298,12 @@ export const memoryOpenVikingConfigSchema = { advanced: true, help: '"semantic" captures all eligible user text and relies on OpenViking extraction; "keyword" uses trigger regex first.', }, + captureMinLength: { + label: "Capture Min Length", + placeholder: String(DEFAULT_CAPTURE_MIN_LENGTH), + advanced: true, + help: "Minimum sanitized text length (chars) required to trigger auto-capture. Shorter messages are skipped to save VLM tokens.", + }, captureMaxLength: { label: "Capture Max Length", placeholder: String(DEFAULT_CAPTURE_MAX_LENGTH), diff --git a/examples/openclaw-plugin/text-utils.ts b/examples/openclaw-plugin/text-utils.ts index a9f4decef..4ad5fc8d7 100644 --- a/examples/openclaw-plugin/text-utils.ts +++ b/examples/openclaw-plugin/text-utils.ts @@ -206,7 +206,7 @@ export function pickRecentUniqueTexts(texts: string[], limit: number): string[] return picked.reverse(); } -export function getCaptureDecision(text: string, mode: CaptureMode, captureMaxLength: number): { +export function getCaptureDecision(text: string, mode: CaptureMode, captureMinLength: number, captureMaxLength: number): { shouldCapture: boolean; reason: string; normalizedText: string; @@ -223,7 +223,7 @@ export function getCaptureDecision(text: string, mode: CaptureMode, captureMaxLe } const compactText = normalizedText.replace(/\s+/g, ""); - const minLength = resolveCaptureMinLength(compactText); + const minLength = Math.max(resolveCaptureMinLength(compactText), captureMinLength); if (compactText.length < minLength || normalizedText.length > captureMaxLength) { return { shouldCapture: false, diff --git a/openviking/server/routers/sessions.py b/openviking/server/routers/sessions.py index 3ea057b72..a8ea92f5f 100644 --- a/openviking/server/routers/sessions.py +++ b/openviking/server/routers/sessions.py @@ -151,9 +151,13 @@ async def get_session_context( _ctx: RequestContext = Depends(get_request_context), ): """Get assembled session context.""" + from openviking_cli.exceptions import NotFoundError service = get_service() session = service.sessions.session(_ctx, session_id) - await session.load() + try: + await session.load() + except NotFoundError: + session = await service.sessions.create(_ctx, session_id) result = await session.get_session_context(token_budget=token_budget) return Response(status="ok", result=_to_jsonable(result))