clawport-ui 0.8.1 → 0.8.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/app/api/memory/reindex/route.ts +36 -0
- package/app/api/memory/route.ts +36 -1
- package/app/memory/page.tsx +1419 -49
- package/lib/memory-health-prompt.test.ts +247 -0
- package/lib/memory-health-prompt.ts +320 -0
- package/lib/memory-health.test.ts +440 -0
- package/lib/memory-health.ts +368 -0
- package/lib/memory-hints.test.ts +207 -0
- package/lib/memory-hints.ts +139 -0
- package/lib/memory-write.test.ts +300 -0
- package/lib/memory-write.ts +162 -0
- package/lib/types.ts +36 -0
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server'
|
|
2
|
+
import { execSync } from 'child_process'
|
|
3
|
+
import { requireEnv } from '@/lib/env'
|
|
4
|
+
|
|
5
|
+
export async function POST() {
|
|
6
|
+
let bin: string
|
|
7
|
+
try {
|
|
8
|
+
bin = requireEnv('OPENCLAW_BIN')
|
|
9
|
+
} catch {
|
|
10
|
+
return NextResponse.json(
|
|
11
|
+
{ status: 'unavailable', message: 'OPENCLAW_BIN not configured', timestamp: null },
|
|
12
|
+
{ status: 503 }
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const output = execSync(`${bin} memory reindex`, {
|
|
18
|
+
timeout: 30000,
|
|
19
|
+
encoding: 'utf-8',
|
|
20
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
21
|
+
}).trim()
|
|
22
|
+
|
|
23
|
+
return NextResponse.json({
|
|
24
|
+
status: 'success',
|
|
25
|
+
message: output || 'Reindex completed',
|
|
26
|
+
timestamp: new Date().toISOString(),
|
|
27
|
+
})
|
|
28
|
+
} catch (err) {
|
|
29
|
+
const message = err instanceof Error ? err.message : 'Reindex failed'
|
|
30
|
+
return NextResponse.json({
|
|
31
|
+
status: 'failed',
|
|
32
|
+
message,
|
|
33
|
+
timestamp: new Date().toISOString(),
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
package/app/api/memory/route.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { getMemoryFiles, getMemoryConfig, getMemoryStatus, computeMemoryStats } from '@/lib/memory'
|
|
2
|
+
import { computeMemoryHealth } from '@/lib/memory-health'
|
|
3
|
+
import { writeMemoryFile, PathValidationError } from '@/lib/memory-write'
|
|
2
4
|
import { apiErrorResponse } from '@/lib/api-error'
|
|
3
5
|
import { NextResponse } from 'next/server'
|
|
4
6
|
|
|
@@ -8,8 +10,41 @@ export async function GET() {
|
|
|
8
10
|
const config = getMemoryConfig()
|
|
9
11
|
const status = getMemoryStatus()
|
|
10
12
|
const stats = computeMemoryStats(files)
|
|
11
|
-
|
|
13
|
+
const health = computeMemoryHealth(files, config, status, stats)
|
|
14
|
+
return NextResponse.json({ files, config, status, stats, health })
|
|
12
15
|
} catch (err) {
|
|
13
16
|
return apiErrorResponse(err, 'Failed to load memory files')
|
|
14
17
|
}
|
|
15
18
|
}
|
|
19
|
+
|
|
20
|
+
export async function PUT(req: Request) {
|
|
21
|
+
try {
|
|
22
|
+
const body = await req.json()
|
|
23
|
+
const { relativePath, content, expectedLastModified } = body
|
|
24
|
+
|
|
25
|
+
if (typeof content !== 'string') {
|
|
26
|
+
return NextResponse.json({ error: 'Content must be a string' }, { status: 400 })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const result = writeMemoryFile(relativePath, content, expectedLastModified)
|
|
30
|
+
return NextResponse.json({ ok: true, ...result })
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (err instanceof PathValidationError) {
|
|
33
|
+
return NextResponse.json({ error: err.message }, { status: 400 })
|
|
34
|
+
}
|
|
35
|
+
const code = (err as NodeJS.ErrnoException).code
|
|
36
|
+
if (code === 'ENOENT') {
|
|
37
|
+
return NextResponse.json({ error: 'File not found' }, { status: 404 })
|
|
38
|
+
}
|
|
39
|
+
if (code === 'E2BIG') {
|
|
40
|
+
return NextResponse.json({ error: (err as Error).message }, { status: 413 })
|
|
41
|
+
}
|
|
42
|
+
if (code === 'ECONFLICT') {
|
|
43
|
+
return NextResponse.json(
|
|
44
|
+
{ error: 'File was modified by another process. Refresh or overwrite.' },
|
|
45
|
+
{ status: 409 }
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
return apiErrorResponse(err, 'Failed to save memory file')
|
|
49
|
+
}
|
|
50
|
+
}
|