@swarmclawai/swarmclaw 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/package.json +5 -2
- package/skills/coding-agent/SKILL.md +111 -0
- package/skills/github/SKILL.md +140 -0
- package/skills/nano-banana-pro/SKILL.md +62 -0
- package/skills/nano-banana-pro/scripts/generate_image.py +235 -0
- package/skills/nano-pdf/SKILL.md +53 -0
- package/skills/openai-image-gen/SKILL.md +78 -0
- package/skills/openai-image-gen/scripts/gen.py +328 -0
- package/skills/resourceful-problem-solving/SKILL.md +49 -0
- package/skills/skill-creator/SKILL.md +147 -0
- package/skills/skill-creator/scripts/init_skill.py +378 -0
- package/skills/skill-creator/scripts/quick_validate.py +159 -0
- package/skills/summarize/SKILL.md +77 -0
- package/src/app/api/auth/route.ts +20 -5
- package/src/app/api/chats/[id]/deploy/route.ts +11 -6
- package/src/app/api/chats/[id]/devserver/route.ts +17 -20
- package/src/app/api/chats/[id]/messages/route.ts +15 -11
- package/src/app/api/chats/[id]/route.ts +9 -10
- package/src/app/api/chats/[id]/stop/route.ts +5 -7
- package/src/app/api/chats/messages-route.test.ts +8 -6
- package/src/app/api/chats/route.ts +9 -10
- package/src/app/api/credentials/[id]/route.ts +4 -1
- package/src/app/api/extensions/marketplace/route.ts +5 -2
- package/src/app/api/ip/route.ts +2 -2
- package/src/app/api/memory/maintenance/route.ts +5 -2
- package/src/app/api/preview-server/route.ts +15 -12
- package/src/app/api/projects/[id]/route.ts +7 -46
- package/src/app/api/system/status/route.ts +11 -0
- package/src/app/api/upload/route.ts +4 -1
- package/src/cli/index.js +7 -0
- package/src/cli/spec.js +1 -0
- package/src/components/agents/agent-files-editor.tsx +44 -32
- package/src/components/agents/personality-builder.tsx +13 -7
- package/src/components/agents/trash-list.tsx +1 -1
- package/src/components/chat/chat-area.tsx +45 -23
- package/src/components/chat/message-bubble.test.ts +35 -0
- package/src/components/chat/message-bubble.tsx +20 -9
- package/src/components/chat/message-list.tsx +62 -42
- package/src/components/chat/swarm-status-card.tsx +10 -3
- package/src/components/input/chat-input.tsx +34 -14
- package/src/components/layout/daemon-indicator.tsx +7 -8
- package/src/components/layout/update-banner.tsx +8 -13
- package/src/components/logs/log-list.tsx +1 -1
- package/src/components/memory/memory-card.tsx +3 -1
- package/src/components/org-chart/org-chart-view.tsx +4 -0
- package/src/components/projects/project-list.tsx +4 -2
- package/src/components/projects/tabs/overview-tab.tsx +3 -2
- package/src/components/secrets/secret-sheet.tsx +1 -1
- package/src/components/secrets/secrets-list.tsx +1 -1
- package/src/components/shared/agent-switch-dialog.tsx +12 -6
- package/src/components/shared/dir-browser.tsx +22 -18
- package/src/components/skills/skill-sheet.tsx +2 -3
- package/src/components/tasks/task-list.tsx +1 -1
- package/src/components/tasks/task-sheet.tsx +1 -1
- package/src/hooks/use-openclaw-gateway.ts +46 -27
- package/src/instrumentation.ts +10 -7
- package/src/lib/chat/assistant-render-id.ts +3 -0
- package/src/lib/chat/chat-streaming-state.test.ts +42 -3
- package/src/lib/chat/chat-streaming-state.ts +20 -8
- package/src/lib/chat/chat.ts +18 -2
- package/src/lib/chat/queued-message-queue.test.ts +23 -1
- package/src/lib/chat/queued-message-queue.ts +11 -2
- package/src/lib/providers/anthropic.ts +6 -3
- package/src/lib/providers/claude-cli.ts +9 -3
- package/src/lib/providers/cli-utils.test.ts +124 -0
- package/src/lib/providers/cli-utils.ts +15 -0
- package/src/lib/providers/codex-cli.ts +9 -3
- package/src/lib/providers/gemini-cli.ts +6 -2
- package/src/lib/providers/index.ts +4 -1
- package/src/lib/providers/ollama.ts +5 -2
- package/src/lib/providers/openai.ts +8 -5
- package/src/lib/providers/opencode-cli.ts +6 -2
- package/src/lib/server/activity/activity-log.ts +21 -0
- package/src/lib/server/agents/agent-availability.test.ts +10 -5
- package/src/lib/server/agents/agent-cascade.ts +79 -59
- package/src/lib/server/agents/agent-registry.ts +23 -4
- package/src/lib/server/agents/agent-repository.ts +90 -0
- package/src/lib/server/agents/delegation-job-repository.ts +53 -0
- package/src/lib/server/agents/delegation-jobs.ts +11 -4
- package/src/lib/server/agents/guardian-checkpoint-repository.ts +35 -0
- package/src/lib/server/agents/guardian.ts +2 -2
- package/src/lib/server/agents/main-agent-loop.ts +14 -6
- package/src/lib/server/agents/main-loop-state-repository.ts +38 -0
- package/src/lib/server/agents/subagent-runtime.ts +9 -6
- package/src/lib/server/agents/subagent-swarm.ts +3 -2
- package/src/lib/server/agents/task-session.ts +3 -4
- package/src/lib/server/approvals/approval-repository.ts +30 -0
- package/src/lib/server/autonomy/supervisor-incident-repository.ts +42 -0
- package/src/lib/server/autonomy/supervisor-reflection.ts +14 -1
- package/src/lib/server/chat-execution/chat-execution-types.ts +38 -0
- package/src/lib/server/chat-execution/chat-execution-utils.ts +1 -1
- package/src/lib/server/chat-execution/chat-execution.ts +84 -1914
- package/src/lib/server/chat-execution/chat-turn-finalization.ts +620 -0
- package/src/lib/server/chat-execution/chat-turn-partial-persistence.ts +221 -0
- package/src/lib/server/chat-execution/chat-turn-preflight.ts +133 -0
- package/src/lib/server/chat-execution/chat-turn-preparation.ts +817 -0
- package/src/lib/server/chat-execution/chat-turn-stream-execution.ts +296 -0
- package/src/lib/server/chat-execution/chat-turn-tool-routing.ts +5 -5
- package/src/lib/server/chat-execution/continuation-evaluator.ts +4 -3
- package/src/lib/server/chat-execution/continuation-limits.ts +6 -3
- package/src/lib/server/chat-execution/message-classifier.test.ts +329 -0
- package/src/lib/server/chat-execution/message-classifier.ts +5 -2
- package/src/lib/server/chat-execution/post-stream-finalization.ts +5 -2
- package/src/lib/server/chat-execution/prompt-builder.ts +22 -1
- package/src/lib/server/chat-execution/prompt-sections.ts +55 -13
- package/src/lib/server/chat-execution/response-completeness.ts +5 -2
- package/src/lib/server/chat-execution/situational-awareness.ts +12 -7
- package/src/lib/server/chat-execution/stream-agent-chat.ts +58 -25
- package/src/lib/server/chatrooms/chatroom-memory-bridge.ts +6 -3
- package/src/lib/server/chatrooms/chatroom-repository.ts +32 -0
- package/src/lib/server/connectors/bluebubbles.ts +7 -4
- package/src/lib/server/connectors/connector-inbound.ts +16 -13
- package/src/lib/server/connectors/connector-lifecycle.ts +11 -8
- package/src/lib/server/connectors/connector-outbound.ts +6 -3
- package/src/lib/server/connectors/connector-repository.ts +58 -0
- package/src/lib/server/connectors/discord.ts +10 -7
- package/src/lib/server/connectors/email.ts +17 -14
- package/src/lib/server/connectors/googlechat.ts +7 -4
- package/src/lib/server/connectors/inbound-audio-transcription.ts +5 -2
- package/src/lib/server/connectors/matrix.ts +6 -3
- package/src/lib/server/connectors/openclaw.ts +20 -17
- package/src/lib/server/connectors/outbox.ts +4 -1
- package/src/lib/server/connectors/runtime-state.test.ts +117 -0
- package/src/lib/server/connectors/runtime-state.ts +19 -0
- package/src/lib/server/connectors/session-consolidation.ts +5 -2
- package/src/lib/server/connectors/signal.ts +9 -6
- package/src/lib/server/connectors/slack.ts +13 -10
- package/src/lib/server/connectors/teams.ts +8 -5
- package/src/lib/server/connectors/telegram.ts +15 -12
- package/src/lib/server/connectors/whatsapp.ts +32 -29
- package/src/lib/server/credentials/credential-repository.ts +7 -0
- package/src/lib/server/embeddings.ts +4 -1
- package/src/lib/server/gateways/gateway-profile-repository.ts +4 -0
- package/src/lib/server/link-understanding.ts +4 -1
- package/src/lib/server/memory/memory-abstract.test.ts +59 -0
- package/src/lib/server/memory/memory-abstract.ts +59 -0
- package/src/lib/server/memory/memory-db.ts +40 -14
- package/src/lib/server/missions/mission-repository.ts +74 -0
- package/src/lib/server/missions/mission-service/actions.ts +6 -0
- package/src/lib/server/missions/mission-service/bindings.ts +9 -0
- package/src/lib/server/missions/mission-service/context.ts +4 -0
- package/src/lib/server/missions/mission-service/core.ts +2269 -0
- package/src/lib/server/missions/mission-service/queries.ts +12 -0
- package/src/lib/server/missions/mission-service/recovery.ts +5 -0
- package/src/lib/server/missions/mission-service/ticks.ts +9 -0
- package/src/lib/server/missions/mission-service.test.ts +9 -2
- package/src/lib/server/missions/mission-service.ts +6 -2263
- package/src/lib/server/openclaw/gateway.ts +8 -5
- package/src/lib/server/persistence/repository-utils.ts +154 -0
- package/src/lib/server/persistence/storage-context.ts +51 -0
- package/src/lib/server/persistence/transaction.ts +1 -0
- package/src/lib/server/project-utils.ts +13 -0
- package/src/lib/server/projects/project-repository.ts +36 -0
- package/src/lib/server/projects/project-service.ts +79 -0
- package/src/lib/server/protocols/protocol-agent-turn.ts +5 -2
- package/src/lib/server/protocols/protocol-normalization.test.ts +6 -4
- package/src/lib/server/protocols/protocol-run-lifecycle.ts +5 -2
- package/src/lib/server/protocols/protocol-step-helpers.ts +4 -1
- package/src/lib/server/provider-health.ts +18 -0
- package/src/lib/server/query-expansion.ts +4 -1
- package/src/lib/server/runtime/alert-dispatch.ts +8 -7
- package/src/lib/server/runtime/daemon-policy.ts +1 -1
- package/src/lib/server/runtime/daemon-state/core.ts +1570 -0
- package/src/lib/server/runtime/daemon-state/health.ts +6 -0
- package/src/lib/server/runtime/daemon-state/policy.ts +7 -0
- package/src/lib/server/runtime/daemon-state/supervisor.ts +6 -0
- package/src/lib/server/runtime/daemon-state.test.ts +48 -0
- package/src/lib/server/runtime/daemon-state.ts +3 -1331
- package/src/lib/server/runtime/estop-repository.ts +4 -0
- package/src/lib/server/runtime/estop.ts +3 -1
- package/src/lib/server/runtime/heartbeat-service.test.ts +2 -2
- package/src/lib/server/runtime/heartbeat-service.ts +78 -34
- package/src/lib/server/runtime/heartbeat-wake.ts +6 -4
- package/src/lib/server/runtime/idle-window.ts +6 -3
- package/src/lib/server/runtime/network.ts +11 -0
- package/src/lib/server/runtime/orchestrator-events.ts +2 -2
- package/src/lib/server/runtime/perf.ts +4 -1
- package/src/lib/server/runtime/process-manager.ts +7 -4
- package/src/lib/server/runtime/queue/claims.ts +4 -0
- package/src/lib/server/runtime/queue/core.ts +2079 -0
- package/src/lib/server/runtime/queue/execution.ts +7 -0
- package/src/lib/server/runtime/queue/followups.ts +4 -0
- package/src/lib/server/runtime/queue/queries.ts +12 -0
- package/src/lib/server/runtime/queue/recovery.ts +7 -0
- package/src/lib/server/runtime/queue-recovery.test.ts +48 -13
- package/src/lib/server/runtime/queue-repository.ts +17 -0
- package/src/lib/server/runtime/queue.ts +5 -2058
- package/src/lib/server/runtime/run-ledger.ts +6 -5
- package/src/lib/server/runtime/run-repository.ts +73 -0
- package/src/lib/server/runtime/runtime-lock-repository.ts +8 -0
- package/src/lib/server/runtime/runtime-settings.ts +1 -1
- package/src/lib/server/runtime/runtime-state.ts +99 -0
- package/src/lib/server/runtime/scheduler.ts +13 -8
- package/src/lib/server/runtime/session-run-manager/cancellation.ts +157 -0
- package/src/lib/server/runtime/session-run-manager/drain.ts +246 -0
- package/src/lib/server/runtime/session-run-manager/enqueue.ts +287 -0
- package/src/lib/server/runtime/session-run-manager/queries.ts +117 -0
- package/src/lib/server/runtime/session-run-manager/recovery.ts +238 -0
- package/src/lib/server/runtime/session-run-manager/state.ts +441 -0
- package/src/lib/server/runtime/session-run-manager/types.ts +74 -0
- package/src/lib/server/runtime/session-run-manager.ts +72 -1374
- package/src/lib/server/runtime/watch-job-repository.ts +35 -0
- package/src/lib/server/runtime/watch-jobs.ts +3 -1
- package/src/lib/server/sandbox/bridge-auth-registry.ts +6 -0
- package/src/lib/server/sandbox/novnc-auth.ts +10 -0
- package/src/lib/server/schedules/schedule-repository.ts +42 -0
- package/src/lib/server/session-tools/context.ts +14 -0
- package/src/lib/server/session-tools/discovery.ts +9 -6
- package/src/lib/server/session-tools/index.ts +3 -1
- package/src/lib/server/session-tools/platform.ts +1 -1
- package/src/lib/server/session-tools/subagent.ts +23 -2
- package/src/lib/server/session-tools/wallet.ts +4 -1
- package/src/lib/server/sessions/session-repository.ts +85 -0
- package/src/lib/server/settings/settings-repository.ts +25 -0
- package/src/lib/server/skills/clawhub-client.ts +4 -1
- package/src/lib/server/skills/runtime-skill-resolver.ts +8 -2
- package/src/lib/server/skills/skill-discovery.test.ts +2 -2
- package/src/lib/server/skills/skill-discovery.ts +2 -2
- package/src/lib/server/skills/skill-eligibility.ts +6 -0
- package/src/lib/server/skills/skill-repository.ts +14 -0
- package/src/lib/server/solana.ts +6 -0
- package/src/lib/server/storage-auth.ts +5 -5
- package/src/lib/server/storage-normalization.ts +4 -0
- package/src/lib/server/storage.ts +32 -32
- package/src/lib/server/tasks/task-followups.ts +4 -1
- package/src/lib/server/tasks/task-repository.ts +54 -0
- package/src/lib/server/tool-loop-detection.ts +8 -3
- package/src/lib/server/tool-planning.ts +226 -0
- package/src/lib/server/tool-retry.ts +4 -3
- package/src/lib/server/usage/usage-repository.ts +30 -0
- package/src/lib/server/wallet/wallet-portfolio.ts +29 -0
- package/src/lib/server/webhooks/webhook-repository.ts +10 -0
- package/src/lib/server/ws-hub.ts +5 -2
- package/src/lib/strip-internal-metadata.test.ts +78 -37
- package/src/lib/strip-internal-metadata.ts +20 -6
- package/src/stores/use-approval-store.ts +7 -1
- package/src/stores/use-chat-store.test.ts +54 -0
- package/src/stores/use-chat-store.ts +26 -6
- package/src/types/index.ts +6 -0
- /package/{bundled-skills → skills}/google-workspace/SKILL.md +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates concise abstracts (~100 tokens) for memory entries.
|
|
3
|
+
* Inspired by OpenViking's L0/L1/L2 tiered context representations.
|
|
4
|
+
*
|
|
5
|
+
* Used in proactive recall to inject summaries instead of truncated raw content,
|
|
6
|
+
* reducing token waste and preserving semantic meaning.
|
|
7
|
+
*/
|
|
8
|
+
import { HumanMessage } from '@langchain/core/messages'
|
|
9
|
+
|
|
10
|
+
const ABSTRACT_TIMEOUT_MS = 15_000
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generate a short abstract (~100 tokens) summarizing memory content.
|
|
14
|
+
* Falls back to a truncated prefix if LLM generation fails or is unavailable.
|
|
15
|
+
*/
|
|
16
|
+
export async function generateAbstract(content: string, title?: string): Promise<string | null> {
|
|
17
|
+
if (!content || content.length <= 200) return null
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const { buildLLM } = await import('@/lib/server/build-llm')
|
|
21
|
+
const { llm } = await buildLLM()
|
|
22
|
+
|
|
23
|
+
const prompt = [
|
|
24
|
+
'Summarize the following memory entry in 1-2 concise sentences (max ~100 tokens).',
|
|
25
|
+
'Preserve the key facts, decisions, or conclusions. Do not add commentary.',
|
|
26
|
+
title ? `Title: ${title}` : '',
|
|
27
|
+
`Content: ${content.slice(0, 2000)}`,
|
|
28
|
+
].filter(Boolean).join('\n')
|
|
29
|
+
|
|
30
|
+
const response = await Promise.race([
|
|
31
|
+
llm.invoke([new HumanMessage(prompt)]),
|
|
32
|
+
new Promise<never>((_, reject) =>
|
|
33
|
+
setTimeout(() => reject(new Error('abstract-timeout')), ABSTRACT_TIMEOUT_MS),
|
|
34
|
+
),
|
|
35
|
+
])
|
|
36
|
+
|
|
37
|
+
const text = extractText(response.content)
|
|
38
|
+
return text || fallbackAbstract(content)
|
|
39
|
+
} catch {
|
|
40
|
+
return fallbackAbstract(content)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function fallbackAbstract(content: string): string {
|
|
45
|
+
return content.slice(0, 150) + (content.length > 150 ? '...' : '')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function extractText(content: unknown): string {
|
|
49
|
+
if (typeof content === 'string') return content.trim()
|
|
50
|
+
if (Array.isArray(content)) {
|
|
51
|
+
for (const part of content) {
|
|
52
|
+
if (typeof part === 'string') return part.trim()
|
|
53
|
+
if (part && typeof part === 'object' && 'text' in part && typeof part.text === 'string') {
|
|
54
|
+
return part.text.trim()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return ''
|
|
59
|
+
}
|
|
@@ -5,6 +5,7 @@ import { createHash } from 'crypto'
|
|
|
5
5
|
import { genId } from '@/lib/id'
|
|
6
6
|
import type { MemoryEntry, FileReference, MemoryImage, MemoryReference } from '@/types'
|
|
7
7
|
import { getEmbedding, cosineSimilarity, serializeEmbedding, deserializeEmbedding } from '@/lib/server/embeddings'
|
|
8
|
+
import { hmrSingleton } from '@/lib/shared-utils'
|
|
8
9
|
import { applyMMR } from '@/lib/server/mmr'
|
|
9
10
|
import { calculateTemporalDecayMultiplier, isDecayExempt } from '@/lib/server/memory/temporal-decay'
|
|
10
11
|
import { loadSettings } from '@/lib/server/storage'
|
|
@@ -17,9 +18,13 @@ import {
|
|
|
17
18
|
} from '@/lib/server/memory/memory-graph'
|
|
18
19
|
import { isWorkingMemoryCategory } from '@/lib/server/memory/memory-tiers'
|
|
19
20
|
|
|
21
|
+
import { generateAbstract } from '@/lib/server/memory/memory-abstract'
|
|
20
22
|
import { DATA_DIR, MEMORY_IMAGES_DIR, WORKSPACE_DIR } from '@/lib/server/data-dir'
|
|
21
23
|
import { safeJsonParse } from '@/lib/server/json-utils'
|
|
22
24
|
import { tryResolvePathWithinBaseDir } from '@/lib/server/path-utils'
|
|
25
|
+
import { log } from '@/lib/server/logger'
|
|
26
|
+
|
|
27
|
+
const TAG = 'memory-db'
|
|
23
28
|
|
|
24
29
|
const DB_PATH = path.join(DATA_DIR, 'memory.db')
|
|
25
30
|
const IMAGES_DIR = MEMORY_IMAGES_DIR
|
|
@@ -207,19 +212,28 @@ function shouldSkipSearchQuery(input: string): boolean {
|
|
|
207
212
|
}
|
|
208
213
|
|
|
209
214
|
// Simple cache for query embeddings to avoid blocking
|
|
210
|
-
const
|
|
215
|
+
const EMBEDDING_CACHE_MAX = 100
|
|
216
|
+
const EMBEDDING_CACHE_EVICT_TO = 80
|
|
217
|
+
const embeddingCache = hmrSingleton('__swarmclaw_memory_embedding_cache__', () => new Map<string, number[]>())
|
|
218
|
+
|
|
219
|
+
function evictEmbeddingCache(): void {
|
|
220
|
+
if (embeddingCache.size <= EMBEDDING_CACHE_MAX) return
|
|
221
|
+
const excess = embeddingCache.size - EMBEDDING_CACHE_EVICT_TO
|
|
222
|
+
const iter = embeddingCache.keys()
|
|
223
|
+
for (let i = 0; i < excess; i++) {
|
|
224
|
+
const k = iter.next().value
|
|
225
|
+
if (k !== undefined) embeddingCache.delete(k)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
211
228
|
|
|
212
229
|
function getEmbeddingSync(query: string): number[] | null {
|
|
213
230
|
const cached = embeddingCache.get(query)
|
|
214
231
|
if (cached) return cached
|
|
232
|
+
// Evict before async call to bound growth regardless of resolution
|
|
233
|
+
evictEmbeddingCache()
|
|
215
234
|
// Kick off async computation for next time
|
|
216
235
|
getEmbedding(query).then((emb) => {
|
|
217
236
|
if (emb) embeddingCache.set(query, emb)
|
|
218
|
-
// Evict old entries
|
|
219
|
-
if (embeddingCache.size > 100) {
|
|
220
|
-
const firstKey = embeddingCache.keys().next().value
|
|
221
|
-
if (firstKey) embeddingCache.delete(firstKey)
|
|
222
|
-
}
|
|
223
237
|
}).catch(() => { /* ok */ })
|
|
224
238
|
return null
|
|
225
239
|
}
|
|
@@ -524,6 +538,7 @@ function initDb() {
|
|
|
524
538
|
'lastAccessedAt INTEGER DEFAULT 0',
|
|
525
539
|
'contentHash TEXT',
|
|
526
540
|
'reinforcementCount INTEGER DEFAULT 0',
|
|
541
|
+
'abstract TEXT',
|
|
527
542
|
]) {
|
|
528
543
|
try { db.exec(`ALTER TABLE memories ADD COLUMN ${col}`) } catch { /* already exists */ }
|
|
529
544
|
}
|
|
@@ -612,7 +627,7 @@ function initDb() {
|
|
|
612
627
|
migrated++
|
|
613
628
|
}
|
|
614
629
|
if (migrated > 0) {
|
|
615
|
-
|
|
630
|
+
log.info(TAG, `Migrated ${migrated} legacy memory row(s) to graph schema`)
|
|
616
631
|
}
|
|
617
632
|
})
|
|
618
633
|
migrateLegacyRows()
|
|
@@ -632,7 +647,7 @@ function initDb() {
|
|
|
632
647
|
})
|
|
633
648
|
tx()
|
|
634
649
|
}
|
|
635
|
-
|
|
650
|
+
log.info(TAG, `Backfilled contentHash for ${backfillRows.length} memory row(s)`)
|
|
636
651
|
}
|
|
637
652
|
|
|
638
653
|
// Fresh installs now start with an empty memory graph.
|
|
@@ -642,9 +657,9 @@ function initDb() {
|
|
|
642
657
|
insert: db.prepare(`
|
|
643
658
|
INSERT INTO memories (
|
|
644
659
|
id, agentId, sessionId, category, title, content, metadata, embedding,
|
|
645
|
-
"references", filePaths, image, imagePath, linkedMemoryIds, pinned, sharedWith, contentHash, createdAt, updatedAt
|
|
660
|
+
"references", filePaths, image, imagePath, linkedMemoryIds, pinned, sharedWith, contentHash, abstract, createdAt, updatedAt
|
|
646
661
|
)
|
|
647
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
662
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
648
663
|
`),
|
|
649
664
|
update: db.prepare(`
|
|
650
665
|
UPDATE memories
|
|
@@ -748,6 +763,7 @@ function initDb() {
|
|
|
748
763
|
lastAccessedAt: typeof row.lastAccessedAt === 'number' ? row.lastAccessedAt : 0,
|
|
749
764
|
contentHash: typeof row.contentHash === 'string' ? row.contentHash : undefined,
|
|
750
765
|
reinforcementCount: typeof row.reinforcementCount === 'number' ? row.reinforcementCount : 0,
|
|
766
|
+
abstract: typeof row.abstract === 'string' ? row.abstract : null,
|
|
751
767
|
createdAt: typeof row.createdAt === 'number' ? row.createdAt : Date.now(),
|
|
752
768
|
updatedAt: typeof row.updatedAt === 'number' ? row.updatedAt : Date.now(),
|
|
753
769
|
}
|
|
@@ -819,6 +835,7 @@ function initDb() {
|
|
|
819
835
|
pinned,
|
|
820
836
|
sharedWith,
|
|
821
837
|
contentHash,
|
|
838
|
+
null, // abstract computed async
|
|
822
839
|
now, now,
|
|
823
840
|
)
|
|
824
841
|
// Compute embedding in background (fire-and-forget)
|
|
@@ -829,7 +846,16 @@ function initDb() {
|
|
|
829
846
|
serializeEmbedding(emb), id,
|
|
830
847
|
)
|
|
831
848
|
}
|
|
832
|
-
}).catch((err: unknown) => {
|
|
849
|
+
}).catch((err: unknown) => { log.warn(TAG, `Embedding generation failed for memory ${id}:`, err instanceof Error ? err.message : String(err)) })
|
|
850
|
+
|
|
851
|
+
// Generate abstract for long content in background (fire-and-forget)
|
|
852
|
+
if (content.length > 200) {
|
|
853
|
+
generateAbstract(content, title).then((abstract) => {
|
|
854
|
+
if (abstract) {
|
|
855
|
+
db.prepare(`UPDATE memories SET abstract = ? WHERE id = ?`).run(abstract, id)
|
|
856
|
+
}
|
|
857
|
+
}).catch(() => { /* non-critical */ })
|
|
858
|
+
}
|
|
833
859
|
|
|
834
860
|
// Keep memory links bidirectional by default.
|
|
835
861
|
if (linkedMemoryIds.length) this.link(id, linkedMemoryIds, true)
|
|
@@ -1086,7 +1112,7 @@ function initDb() {
|
|
|
1086
1112
|
})
|
|
1087
1113
|
}
|
|
1088
1114
|
} catch (err: unknown) {
|
|
1089
|
-
|
|
1115
|
+
log.warn(TAG, 'Vector search failed, falling back to FTS:', err instanceof Error ? err.message : String(err))
|
|
1090
1116
|
}
|
|
1091
1117
|
|
|
1092
1118
|
// Merge: deduplicate by id
|
|
@@ -1146,8 +1172,8 @@ function initDb() {
|
|
|
1146
1172
|
|
|
1147
1173
|
const elapsed = Date.now() - startedAt
|
|
1148
1174
|
if (elapsed > 1200) {
|
|
1149
|
-
|
|
1150
|
-
`
|
|
1175
|
+
log.warn(TAG,
|
|
1176
|
+
`Slow search ${elapsed}ms (scope=${scopeMode}, rerank=${rerankMode}, rawLen=${String(query || '').length}, fts="${ftsQuery.slice(0, 180)}")`,
|
|
1151
1177
|
)
|
|
1152
1178
|
}
|
|
1153
1179
|
return out
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Mission, MissionEvent } from '@/types'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
deleteMission as deleteStoredMission,
|
|
5
|
+
loadMission as loadStoredMission,
|
|
6
|
+
loadMissionEvent as loadStoredMissionEvent,
|
|
7
|
+
loadMissionEvents as loadStoredMissionEvents,
|
|
8
|
+
loadMissions as loadStoredMissions,
|
|
9
|
+
patchMission as patchStoredMission,
|
|
10
|
+
saveMissionEvents as saveStoredMissionEvents,
|
|
11
|
+
saveMissions as saveStoredMissions,
|
|
12
|
+
upsertMission as upsertStoredMission,
|
|
13
|
+
upsertMissionEvent as upsertStoredMissionEvent,
|
|
14
|
+
upsertMissionEvents as upsertStoredMissionEvents,
|
|
15
|
+
} from '@/lib/server/storage'
|
|
16
|
+
import { createRecordRepository } from '@/lib/server/persistence/repository-utils'
|
|
17
|
+
|
|
18
|
+
export const missionRepository = createRecordRepository<Mission>(
|
|
19
|
+
'missions',
|
|
20
|
+
{
|
|
21
|
+
get(id) {
|
|
22
|
+
return loadStoredMission(id) as Mission | null
|
|
23
|
+
},
|
|
24
|
+
list() {
|
|
25
|
+
return loadStoredMissions() as Record<string, Mission>
|
|
26
|
+
},
|
|
27
|
+
upsert(id, value) {
|
|
28
|
+
upsertStoredMission(id, value as Mission)
|
|
29
|
+
},
|
|
30
|
+
replace(data) {
|
|
31
|
+
saveStoredMissions(data as Record<string, Mission>)
|
|
32
|
+
},
|
|
33
|
+
patch(id, updater) {
|
|
34
|
+
return patchStoredMission(id, updater as (current: Mission | null) => Mission | null) as Mission | null
|
|
35
|
+
},
|
|
36
|
+
delete(id) {
|
|
37
|
+
deleteStoredMission(id)
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
export const missionEventRepository = createRecordRepository<MissionEvent>(
|
|
43
|
+
'mission-events',
|
|
44
|
+
{
|
|
45
|
+
get(id) {
|
|
46
|
+
return loadStoredMissionEvent(id) as MissionEvent | null
|
|
47
|
+
},
|
|
48
|
+
list() {
|
|
49
|
+
return loadStoredMissionEvents() as Record<string, MissionEvent>
|
|
50
|
+
},
|
|
51
|
+
upsert(id, value) {
|
|
52
|
+
upsertStoredMissionEvent(id, value as MissionEvent)
|
|
53
|
+
},
|
|
54
|
+
upsertMany(entries) {
|
|
55
|
+
upsertStoredMissionEvents(entries as Array<[string, MissionEvent]>)
|
|
56
|
+
},
|
|
57
|
+
replace(data) {
|
|
58
|
+
saveStoredMissionEvents(data as Record<string, MissionEvent>)
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
export const loadMissions = () => missionRepository.list()
|
|
64
|
+
export const loadMission = (id: string) => missionRepository.get(id)
|
|
65
|
+
export const saveMissions = (items: Record<string, Mission | Record<string, unknown>>) => missionRepository.replace(items as Record<string, Mission>)
|
|
66
|
+
export const upsertMission = (id: string, value: Mission | Record<string, unknown>) => missionRepository.upsert(id, value as Mission)
|
|
67
|
+
export const patchMission = (id: string, updater: (current: Mission | null) => Mission | null) => missionRepository.patch(id, updater)
|
|
68
|
+
export const deleteMission = (id: string) => missionRepository.delete(id)
|
|
69
|
+
|
|
70
|
+
export const loadMissionEvents = () => missionEventRepository.list()
|
|
71
|
+
export const loadMissionEvent = (id: string) => missionEventRepository.get(id)
|
|
72
|
+
export const saveMissionEvents = (items: Record<string, MissionEvent | Record<string, unknown>>) => missionEventRepository.replace(items as Record<string, MissionEvent>)
|
|
73
|
+
export const upsertMissionEvent = (id: string, value: MissionEvent | Record<string, unknown>) => missionEventRepository.upsert(id, value as MissionEvent)
|
|
74
|
+
export const upsertMissionEvents = (entries: Array<[string, MissionEvent | Record<string, unknown>]>) => missionEventRepository.upsertMany(entries as Array<[string, MissionEvent]>)
|