@openchamber/web 1.18.3 → 1.19.0
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 +1 -0
- package/dist/assets/{CodeMirrorCommentWidgets-DbUi6I9s.js → CodeMirrorCommentWidgets-DAvopJvy.js} +1 -1
- package/dist/assets/{CommitSection-Jc2_hNPE.js → CommitSection-D9cV-qR9.js} +1 -1
- package/dist/assets/{DiagramEditor-PCrYHBko.js → DiagramEditor-B9NCadU7.js} +1 -1
- package/dist/assets/DiagramView-LKGBwf4G.js +1 -0
- package/dist/assets/{DiffView-DEGlNjMH.js → DiffView-BWNq-0ov.js} +2 -2
- package/dist/assets/FilesView-DB-Q0Gkz.js +14 -0
- package/dist/assets/{GitView-C-n17voy.js → GitView-DsWXqWx3.js} +3 -3
- package/dist/assets/{JsonTreeView-BYcgdTOQ.js → JsonTreeView-h4dHASlq.js} +1 -1
- package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +1 -0
- package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +12 -0
- package/dist/assets/OnboardingScreen-CDjgzxEe.js +1 -0
- package/dist/assets/{PatchDiff-Bn7bfgUv.js → PatchDiff-jPKTJje5.js} +1 -1
- package/dist/assets/{PierreDiffViewer-D1fWvrUn.js → PierreDiffViewer-D_Gt4A_6.js} +1 -1
- package/dist/assets/PlanView-UvuxIl9-.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +1 -0
- package/dist/assets/SettingsView-3B9VN6Ys.js +28 -0
- package/dist/assets/SettingsWindow-CqQNDKNd.js +1 -0
- package/dist/assets/{ToolOutputDialog-BtIJkFno.js → ToolOutputDialog-PmjlAxVE.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-i3PQo6_0.js → ToolPartDiffPreview-B34Xw9wq.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-DkcusvMa.js → VirtualizedFileDiff-B37yB9jZ.js} +3 -3
- package/dist/assets/{WalkthroughView-Cc5Hd6P5.js → WalkthroughView-Bxun3k66.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-xPena3W2.js → computeVirtualFileMetrics-DYFv_yZS.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +1 -0
- package/dist/assets/de-DbV6CLxv.js +9 -0
- package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
- package/dist/assets/es-CVDlyzZ4.js +15 -0
- package/dist/assets/fr-Czc-p0g-.js +13 -0
- package/dist/assets/index-1OhiMDBz.css +1 -0
- package/dist/assets/index-BSvmTvZl.js +1 -0
- package/dist/assets/index-DzriVon2.js +7 -0
- package/dist/assets/{isDiffPlainText-Dudf-dWx.js → isDiffPlainText-DwHKxDYc.js} +1 -1
- package/dist/assets/{isFilePlainText-DS4QV1dd.js → isFilePlainText-Dwq6ILxo.js} +1 -1
- package/dist/assets/ja-dwc9NM_S.js +15 -0
- package/dist/assets/ko-Ds1DZ8FX.js +15 -0
- package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
- package/dist/assets/main-BF51IOVF.js +921 -0
- package/dist/assets/{main-C0DyIwTb.js → main-D7UPARut.js} +2 -2
- package/dist/assets/markdownCore-BgeBDwD3.js +2 -0
- package/dist/assets/{miniChat-CGfrxKpJ.js → miniChat-BISXSGOo.js} +2 -2
- package/dist/assets/mobile-BnYxVuvw.js +2 -0
- package/dist/assets/{patchFileDiff-C5D1OPCa.js → patchFileDiff-BEDPDypx.js} +2 -2
- package/dist/assets/pl-CLiTO7i-.js +15 -0
- package/dist/assets/pt-BR-GIimJgpK.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +2 -0
- package/dist/assets/{renderMobileApp-B5HA4qbi.js → renderMobileApp-BiMbzPq9.js} +7 -7
- package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +15 -0
- package/dist/assets/scheduledTasksApi-01zzfzqH.js +1 -0
- package/dist/assets/{shikiHighlight-CmanopUB.js → shikiHighlight-DXYW46vW.js} +1 -1
- package/dist/assets/uk-DLfgD1ki.js +15 -0
- package/dist/assets/{useAppFontEffects-sHmU5b8u.js → useAppFontEffects-CbzHzFop.js} +139 -142
- package/dist/assets/{useInlineCommentController-gt56WkxJ.js → useInlineCommentController-CegKdDXi.js} +2 -2
- package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-BYlZTzrw.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
- package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
- package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-Dihw9MtL.js → vendor-codemirror-language-data-CiAYDJXN.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
- package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
- package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
- package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
- package/dist/assets/vendor-zod-adaMkgkm.js +39 -0
- package/dist/assets/{web-components-BL-Ur2Tb.js → web-components-DCLjCO9n.js} +1 -1
- package/dist/assets/zh-CN-DkeP5awK.js +15 -0
- package/dist/assets/zh-TW-BocaFm3d.js +15 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/index.js +116 -3
- package/server/lib/agent-memory/actions.js +243 -0
- package/server/lib/agent-memory/actions.test.js +343 -0
- package/server/lib/agent-memory/feature-flag.js +19 -0
- package/server/lib/agent-memory/feature-flag.test.js +38 -0
- package/server/lib/agent-memory/project-resolution.js +56 -0
- package/server/lib/agent-memory/project-resolution.test.js +85 -0
- package/server/lib/agent-memory/routes.http.test.js +270 -0
- package/server/lib/agent-memory/routes.js +169 -0
- package/server/lib/agent-memory/runtime.js +427 -0
- package/server/lib/agent-memory/runtime.test.js +344 -0
- package/server/lib/agent-memory/threat-patterns.js +61 -0
- package/server/lib/agent-memory/threat-patterns.test.js +61 -0
- package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
- package/server/lib/agent-tool/runtime.js +63 -13
- package/server/lib/agent-tool/runtime.test.js +85 -2
- package/server/lib/context-obligatory/runtime.js +34 -3
- package/server/lib/context-obligatory/runtime.test.js +114 -0
- package/server/lib/dev-tunnel/client.js +20 -1
- package/server/lib/dev-tunnel/tunnel.test.js +9 -0
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +149 -32
- package/server/lib/fs/routes.test.js +225 -0
- package/server/lib/git/DOCUMENTATION.md +8 -0
- package/server/lib/git/service.js +121 -67
- package/server/lib/git/service.test.js +129 -0
- package/server/lib/github/DOCUMENTATION.md +14 -3
- package/server/lib/github/pr-status.js +188 -83
- package/server/lib/github/pr-status.test.js +182 -0
- package/server/lib/github/routes.js +36 -30
- package/server/lib/markdown-image-grants/DOCUMENTATION.md +36 -0
- package/server/lib/markdown-image-grants/routes.js +340 -0
- package/server/lib/markdown-image-grants/routes.test.js +221 -0
- package/server/lib/notifications/template-runtime.js +2 -3
- package/server/lib/openchamber-control/action-resolution.test.js +65 -0
- package/server/lib/openchamber-control/actions.js +78 -0
- package/server/lib/openchamber-control/service.js +7 -0
- package/server/lib/openchamber-sessions/routes.js +14 -0
- package/server/lib/opencode/DOCUMENTATION.md +6 -4
- package/server/lib/opencode/claude-cli-auth.js +60 -0
- package/server/lib/opencode/claude-cli-auth.test.js +54 -0
- package/server/lib/opencode/feature-routes-runtime.js +22 -0
- package/server/lib/opencode/plugins.js +12 -3
- package/server/lib/opencode/plugins.test.js +18 -0
- package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
- package/server/lib/opencode/proxy.js +116 -6
- package/server/lib/opencode/proxy.test.js +158 -1
- package/server/lib/opencode/routes.js +4 -1
- package/server/lib/opencode/server-startup-runtime.js +22 -1
- package/server/lib/opencode/server-startup-runtime.test.js +44 -0
- package/server/lib/opencode/settings-helpers.js +11 -0
- package/server/lib/opencode/settings-helpers.test.js +35 -0
- package/server/lib/opencode/settings-runtime.js +51 -0
- package/server/lib/opencode/shared.js +120 -16
- package/server/lib/opencode/shared.test.js +185 -1
- package/server/lib/project-context/DOCUMENTATION.md +158 -0
- package/server/lib/project-context/routes.http.test.js +264 -0
- package/server/lib/project-context/routes.js +237 -0
- package/server/lib/project-context/runtime.js +667 -0
- package/server/lib/project-context/runtime.test.js +498 -0
- package/server/lib/quota/DOCUMENTATION.md +16 -1
- package/server/lib/quota/providers/claude/auth.js +113 -0
- package/server/lib/quota/providers/claude/auth.test.js +117 -0
- package/server/lib/quota/providers/claude/index.js +151 -0
- package/server/lib/quota/providers/claude/index.test.js +147 -0
- package/server/lib/quota/providers/claude/transforms.js +127 -0
- package/server/lib/quota/providers/claude/transforms.test.js +82 -0
- package/server/lib/quota/providers/command-code.js +90 -0
- package/server/lib/quota/providers/command-code.test.js +72 -0
- package/server/lib/quota/providers/index.js +22 -2
- package/server/lib/quota/providers/index.test.js +10 -1
- package/server/lib/quota/utils/formatters.js +2 -1
- package/server/lib/scheduled-tasks/runtime.js +21 -2
- package/server/lib/session-knowledge/DOCUMENTATION.md +87 -0
- package/server/lib/session-knowledge/routes.js +107 -0
- package/server/lib/session-knowledge/runtime.js +331 -0
- package/server/lib/session-knowledge/runtime.test.js +275 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +22 -22
- package/server/lib/skills-catalog/curated-sources.js +1 -1
- package/server/lib/skills-catalog/curated-sources.test.js +10 -0
- package/server/lib/small-model/index.js +8 -0
- package/server/lib/small-model/index.test.js +31 -1
- package/server/lib/small-model/routes.js +3 -1
- package/dist/assets/DiagramView-CndEcZNu.js +0 -1
- package/dist/assets/FilesView-CzUgIvUm.js +0 -14
- package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +0 -12
- package/dist/assets/OnboardingScreen-BmN0lhk4.js +0 -1
- package/dist/assets/PlanView-CWM0iyFk.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-Cez-9xRh.js +0 -1
- package/dist/assets/SettingsView-Bl1drwPw.js +0 -28
- package/dist/assets/SettingsWindow-DL5axjDZ.js +0 -1
- package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +0 -1
- package/dist/assets/de-u7gSnqWs.js +0 -9
- package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
- package/dist/assets/es-T9O7aAOr.js +0 -15
- package/dist/assets/fr-Oor7ewbE.js +0 -13
- package/dist/assets/index-CVNuER6G.css +0 -1
- package/dist/assets/index-Crz1YOFl.js +0 -1
- package/dist/assets/index-iFY_N5aO.js +0 -7
- package/dist/assets/ja-DHpqbVmr.js +0 -15
- package/dist/assets/ko-CwLkS3nx.js +0 -15
- package/dist/assets/main-CAxX6DAN.js +0 -915
- package/dist/assets/markdownCore-DhfzuGXu.js +0 -2
- package/dist/assets/markdownImageAssets-BTNlRyjd.js +0 -1
- package/dist/assets/mobile-DEmhwNcV.js +0 -2
- package/dist/assets/pl-CcZILN8q.js +0 -15
- package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-Dpbswpom.js +0 -2
- package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +0 -13
- package/dist/assets/scheduledTasksApi-BxgGWTL8.js +0 -1
- package/dist/assets/uk-BA2kZR38.js +0 -15
- package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
- package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
- package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
- package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
- package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
- package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
- package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
- package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
- package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
- package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
- package/server/lib/quota/providers/claude.js +0 -107
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import request from 'supertest';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import { registerAgentMemoryRoutes } from './routes.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* End-to-end route tests over real HTTP.
|
|
9
|
+
*
|
|
10
|
+
* Mounted on a bare express app, exactly as production runs: `core-routes`
|
|
11
|
+
* parses only an allowlist of path prefixes so the OpenCode proxy keeps an
|
|
12
|
+
* unread stream. The PATCH route is the one that carries a body, so it is the
|
|
13
|
+
* one that has to attach its own `express.json()` — and these tests are what
|
|
14
|
+
* would fail if it stopped.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const entry = (overrides = {}) => ({
|
|
18
|
+
id: 'mem-1',
|
|
19
|
+
title: 'Uses bun',
|
|
20
|
+
body: 'Tests run with bun test.',
|
|
21
|
+
type: 'fact',
|
|
22
|
+
createdAt: 1,
|
|
23
|
+
updatedAt: 1,
|
|
24
|
+
...overrides,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const createApp = (overrides = {}) => {
|
|
28
|
+
const received = {};
|
|
29
|
+
const runtime = {
|
|
30
|
+
read: async (target) => {
|
|
31
|
+
received.readTarget = target;
|
|
32
|
+
return { version: 1, entries: [entry()] };
|
|
33
|
+
},
|
|
34
|
+
readAll: async (projectId) => {
|
|
35
|
+
received.readAllProjectId = projectId;
|
|
36
|
+
return { global: [entry()], project: [], globalFailed: false, projectFailed: false };
|
|
37
|
+
},
|
|
38
|
+
update: async (target, memoryId, patch) => {
|
|
39
|
+
received.updateTarget = target;
|
|
40
|
+
received.patch = patch;
|
|
41
|
+
received.updatedId = memoryId;
|
|
42
|
+
return { entry: entry(patch), entries: [entry(patch)] };
|
|
43
|
+
},
|
|
44
|
+
remove: async (target, memoryId) => {
|
|
45
|
+
received.removeTarget = target;
|
|
46
|
+
received.removedId = memoryId;
|
|
47
|
+
return { deleted: true, entries: [] };
|
|
48
|
+
},
|
|
49
|
+
...overrides.runtime,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const app = express();
|
|
53
|
+
registerAgentMemoryRoutes(app, {
|
|
54
|
+
agentMemoryRuntime: runtime,
|
|
55
|
+
isAgentMemoryEnabled: overrides.isAgentMemoryEnabled,
|
|
56
|
+
});
|
|
57
|
+
return { app, received };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
describe('scope resolution', () => {
|
|
61
|
+
it('reads global scope', async () => {
|
|
62
|
+
const { app, received } = createApp();
|
|
63
|
+
|
|
64
|
+
const response = await request(app).get('/api/agent-memory?scope=global');
|
|
65
|
+
|
|
66
|
+
expect(response.status).toBe(200);
|
|
67
|
+
expect(received.readTarget).toEqual({ scope: 'global' });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('reads project scope with its id', async () => {
|
|
71
|
+
const { app, received } = createApp();
|
|
72
|
+
|
|
73
|
+
await request(app).get('/api/agent-memory?scope=project&projectId=path_abc');
|
|
74
|
+
|
|
75
|
+
expect(received.readTarget).toEqual({ scope: 'project', projectId: 'path_abc' });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('refuses a project scope with no id rather than falling back to global', async () => {
|
|
79
|
+
const { app, received } = createApp();
|
|
80
|
+
|
|
81
|
+
const response = await request(app).get('/api/agent-memory?scope=project');
|
|
82
|
+
|
|
83
|
+
expect(response.status).toBe(400);
|
|
84
|
+
expect(response.body.error).toContain('projectId is required');
|
|
85
|
+
expect(received.readTarget).toBeUndefined();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('refuses a missing scope', async () => {
|
|
89
|
+
const { app } = createApp();
|
|
90
|
+
|
|
91
|
+
const response = await request(app).get('/api/agent-memory');
|
|
92
|
+
|
|
93
|
+
expect(response.status).toBe(400);
|
|
94
|
+
expect(response.body.error).toContain('scope must be');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('refuses a delete with no scope before touching the store', async () => {
|
|
98
|
+
const { app, received } = createApp();
|
|
99
|
+
|
|
100
|
+
const response = await request(app).delete('/api/agent-memory/mem-1');
|
|
101
|
+
|
|
102
|
+
expect(response.status).toBe(400);
|
|
103
|
+
expect(received.removedId).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('both scopes at once', () => {
|
|
108
|
+
it('returns global and project together', async () => {
|
|
109
|
+
const { app, received } = createApp();
|
|
110
|
+
|
|
111
|
+
const response = await request(app).get('/api/agent-memory/all?projectId=path_abc');
|
|
112
|
+
|
|
113
|
+
expect(response.status).toBe(200);
|
|
114
|
+
expect(received.readAllProjectId).toBe('path_abc');
|
|
115
|
+
expect(response.body.global).toHaveLength(1);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('reads global alone when no project is open', async () => {
|
|
119
|
+
const { app, received } = createApp();
|
|
120
|
+
|
|
121
|
+
await request(app).get('/api/agent-memory/all');
|
|
122
|
+
|
|
123
|
+
expect(received.readAllProjectId).toBeNull();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('failures', () => {
|
|
128
|
+
it('reports malformed storage as a server error', async () => {
|
|
129
|
+
const { app } = createApp({
|
|
130
|
+
runtime: {
|
|
131
|
+
read: async () => { throw new Error('Stored agent memory is malformed'); },
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const response = await request(app).get('/api/agent-memory?scope=global');
|
|
136
|
+
|
|
137
|
+
expect(response.status).toBe(500);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('reports a bad project id as a client error', async () => {
|
|
141
|
+
const { app } = createApp({
|
|
142
|
+
runtime: {
|
|
143
|
+
read: async () => { throw new Error('projectId contains unsupported characters'); },
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const response = await request(app).get('/api/agent-memory?scope=project&projectId=..');
|
|
148
|
+
|
|
149
|
+
expect(response.status).toBe(400);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('corrections', () => {
|
|
154
|
+
it('patches a memory from a JSON body', async () => {
|
|
155
|
+
// This route is the only one here that carries a body, so it is the only
|
|
156
|
+
// one that needs its own parser — and the only place that can prove it.
|
|
157
|
+
const { app, received } = createApp();
|
|
158
|
+
|
|
159
|
+
const response = await request(app)
|
|
160
|
+
.patch('/api/agent-memory/mem-1?scope=global')
|
|
161
|
+
.send({ title: 'Clearer', body: 'Reworded.' });
|
|
162
|
+
|
|
163
|
+
expect(response.status).toBe(200);
|
|
164
|
+
expect(received.patch).toEqual({ title: 'Clearer', body: 'Reworded.' });
|
|
165
|
+
expect(received.updatedId).toBe('mem-1');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('rejects a non-string title', async () => {
|
|
169
|
+
const { app } = createApp();
|
|
170
|
+
|
|
171
|
+
const response = await request(app)
|
|
172
|
+
.patch('/api/agent-memory/mem-1?scope=global')
|
|
173
|
+
.send({ title: 42 });
|
|
174
|
+
|
|
175
|
+
expect(response.status).toBe(400);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('reports a missing memory as 404', async () => {
|
|
179
|
+
const { app } = createApp({ runtime: { update: async () => null } });
|
|
180
|
+
|
|
181
|
+
const response = await request(app)
|
|
182
|
+
.patch('/api/agent-memory/nope?scope=global')
|
|
183
|
+
.send({ body: 'x' });
|
|
184
|
+
|
|
185
|
+
expect(response.status).toBe(404);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe('delete', () => {
|
|
190
|
+
it('deletes the named memory in the named scope', async () => {
|
|
191
|
+
const { app, received } = createApp();
|
|
192
|
+
|
|
193
|
+
const response = await request(app).delete('/api/agent-memory/mem-1?scope=global');
|
|
194
|
+
|
|
195
|
+
expect(response.status).toBe(200);
|
|
196
|
+
expect(received.removedId).toBe('mem-1');
|
|
197
|
+
expect(received.removeTarget).toEqual({ scope: 'global' });
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('reports a missing memory as 404', async () => {
|
|
201
|
+
const { app } = createApp({ runtime: { remove: async () => ({ deleted: false, entries: [] }) } });
|
|
202
|
+
|
|
203
|
+
const response = await request(app).delete('/api/agent-memory/nope?scope=global');
|
|
204
|
+
|
|
205
|
+
expect(response.status).toBe(404);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('the settings toggle disables the surface, not just its UI', () => {
|
|
210
|
+
it('flags the disabled answer so a deleted entry cannot be mistaken for it', async () => {
|
|
211
|
+
// Both answer 404. Without the flag a client would report one memory the
|
|
212
|
+
// user just deleted as the whole feature being switched off.
|
|
213
|
+
const off = createApp({ isAgentMemoryEnabled: () => false });
|
|
214
|
+
const missing = createApp({ runtime: { remove: async () => ({ deleted: false, entries: [] }) } });
|
|
215
|
+
|
|
216
|
+
const disabled = await request(off.app).get('/api/agent-memory?scope=global');
|
|
217
|
+
const notFound = await request(missing.app).delete('/api/agent-memory/nope?scope=global');
|
|
218
|
+
|
|
219
|
+
expect(disabled.status).toBe(404);
|
|
220
|
+
expect(disabled.body.disabled).toBe(true);
|
|
221
|
+
expect(notFound.status).toBe(404);
|
|
222
|
+
expect(notFound.body.disabled).toBeUndefined();
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('refuses reads while memory is off', async () => {
|
|
226
|
+
const { app, received } = createApp({ isAgentMemoryEnabled: () => false });
|
|
227
|
+
|
|
228
|
+
const response = await request(app).get('/api/agent-memory?scope=global');
|
|
229
|
+
|
|
230
|
+
expect(response.status).toBe(404);
|
|
231
|
+
expect(received.readTarget).toBeUndefined();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('refuses deletes from a stale client while memory is off', async () => {
|
|
235
|
+
const { app, received } = createApp({ isAgentMemoryEnabled: () => false });
|
|
236
|
+
|
|
237
|
+
const response = await request(app).delete('/api/agent-memory/mem-1?scope=global');
|
|
238
|
+
|
|
239
|
+
expect(response.status).toBe(404);
|
|
240
|
+
expect(received.removedId).toBeUndefined();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('serves normally while memory is on', async () => {
|
|
244
|
+
const { app } = createApp({ isAgentMemoryEnabled: () => true });
|
|
245
|
+
|
|
246
|
+
expect((await request(app).get('/api/agent-memory?scope=global')).status).toBe(200);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('honours a gate that resolves asynchronously', async () => {
|
|
250
|
+
// The real gate reads the settings file. A synchronous truthiness test on
|
|
251
|
+
// its promise would leave the surface open with memory turned off.
|
|
252
|
+
const { app, received } = createApp({ isAgentMemoryEnabled: async () => false });
|
|
253
|
+
|
|
254
|
+
const response = await request(app).get('/api/agent-memory?scope=global');
|
|
255
|
+
|
|
256
|
+
expect(response.status).toBe(404);
|
|
257
|
+
expect(received.readTarget).toBeUndefined();
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('closes the surface when the setting cannot be read', async () => {
|
|
261
|
+
const { app, received } = createApp({
|
|
262
|
+
isAgentMemoryEnabled: async () => { throw new Error('settings unreadable'); },
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
const response = await request(app).get('/api/agent-memory?scope=global');
|
|
266
|
+
|
|
267
|
+
expect(response.status).toBe(503);
|
|
268
|
+
expect(received.readTarget).toBeUndefined();
|
|
269
|
+
});
|
|
270
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenChamber agent memory routes.
|
|
3
|
+
*
|
|
4
|
+
* The scope is a query parameter rather than part of the path, because global
|
|
5
|
+
* and project memory are the same resource with two homes: one set of handlers
|
|
6
|
+
* that resolve `?scope=global` or `?scope=project&projectId=...`. Getting the
|
|
7
|
+
* scope wrong must fail loudly, never silently write the user's global memory
|
|
8
|
+
* from a project-scoped call.
|
|
9
|
+
*
|
|
10
|
+
* Memory is created by the agent through the `openchamber_memory` tool, so
|
|
11
|
+
* there is no create route here; the panel reads, corrects, and deletes.
|
|
12
|
+
*
|
|
13
|
+
* The body parser is attached per route rather than globally: the generic
|
|
14
|
+
* OpenCode proxy needs an unread request stream, so `core-routes` parses only
|
|
15
|
+
* an explicit allowlist of path prefixes. A route that forgets this sees
|
|
16
|
+
* `req.body` as undefined and rejects every write as a malformed body.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import express from 'express';
|
|
20
|
+
|
|
21
|
+
const parseJsonBody = express.json({ limit: '1mb' });
|
|
22
|
+
|
|
23
|
+
const MEMORY_TYPES = new Set(['fact', 'preference', 'reference']);
|
|
24
|
+
|
|
25
|
+
const isObjectRecord = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
26
|
+
|
|
27
|
+
const isValidationError = (error) => {
|
|
28
|
+
const message = error instanceof Error ? error.message : '';
|
|
29
|
+
return message.includes('is required')
|
|
30
|
+
|| message.includes('unsupported characters')
|
|
31
|
+
|| message.includes('holds at most');
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const respondWithError = (res, error, fallbackMessage) => {
|
|
35
|
+
const message = error instanceof Error ? error.message : fallbackMessage;
|
|
36
|
+
if (isValidationError(error)) {
|
|
37
|
+
return res.status(400).json({ error: message });
|
|
38
|
+
}
|
|
39
|
+
return res.status(500).json({ error: message || fallbackMessage });
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the target scope, or returns the reason it could not be resolved.
|
|
44
|
+
* A project request without an id is rejected here rather than quietly falling
|
|
45
|
+
* back to global, which would write project facts into every other project.
|
|
46
|
+
*/
|
|
47
|
+
const resolveScope = (query) => {
|
|
48
|
+
if (query.scope === 'global') {
|
|
49
|
+
return { target: { scope: 'global' } };
|
|
50
|
+
}
|
|
51
|
+
if (query.scope === 'project') {
|
|
52
|
+
if (typeof query.projectId !== 'string' || query.projectId.trim().length === 0) {
|
|
53
|
+
return { error: 'projectId is required for project scope' };
|
|
54
|
+
}
|
|
55
|
+
return { target: { scope: 'project', projectId: query.projectId } };
|
|
56
|
+
}
|
|
57
|
+
return { error: 'scope must be global or project' };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const registerAgentMemoryRoutes = (app, dependencies) => {
|
|
61
|
+
const { agentMemoryRuntime, isAgentMemoryEnabled } = dependencies;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* One gate for the whole surface. The settings toggle disables the feature,
|
|
65
|
+
* not just its UI: with memory off, these routes must not read or write the
|
|
66
|
+
* store at all, or a stale client would keep editing memory the user believes
|
|
67
|
+
* is turned off.
|
|
68
|
+
*/
|
|
69
|
+
const requireEnabled = async (_req, res, next) => {
|
|
70
|
+
if (!isAgentMemoryEnabled) {
|
|
71
|
+
return next();
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
// Awaited: the setting is read from disk, and testing the returned
|
|
75
|
+
// promise for truthiness would leave the gate permanently open.
|
|
76
|
+
if (!(await isAgentMemoryEnabled())) {
|
|
77
|
+
// Flagged, not merely 404: a missing entry answers 404 too, and a
|
|
78
|
+
// client that could not tell them apart would report a deleted memory
|
|
79
|
+
// as the whole feature being switched off.
|
|
80
|
+
return res.status(404).json({ error: 'Agent memory is disabled', disabled: true });
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
// An unreadable settings file must not silently expose a surface the
|
|
84
|
+
// user may have turned off.
|
|
85
|
+
return res.status(503).json({ error: 'Agent memory availability is unknown' });
|
|
86
|
+
}
|
|
87
|
+
return next();
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
app.get('/api/agent-memory', requireEnabled, async (req, res) => {
|
|
91
|
+
const { target, error } = resolveScope(req.query);
|
|
92
|
+
if (error) {
|
|
93
|
+
return res.status(400).json({ error });
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
return res.json(await agentMemoryRuntime.read(target));
|
|
97
|
+
} catch (caught) {
|
|
98
|
+
return respondWithError(res, caught, 'Failed to read agent memory');
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Both scopes in one response. The panel always shows them together, and two
|
|
104
|
+
* separate requests would let one scope render while the other is still
|
|
105
|
+
* loading, which reads as memory that has gone missing.
|
|
106
|
+
*/
|
|
107
|
+
app.get('/api/agent-memory/all', requireEnabled, async (req, res) => {
|
|
108
|
+
const projectId = typeof req.query.projectId === 'string' && req.query.projectId.trim().length > 0
|
|
109
|
+
? req.query.projectId
|
|
110
|
+
: null;
|
|
111
|
+
try {
|
|
112
|
+
return res.json(await agentMemoryRuntime.readAll(projectId));
|
|
113
|
+
} catch (caught) {
|
|
114
|
+
return respondWithError(res, caught, 'Failed to read agent memory');
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
app.patch('/api/agent-memory/:memoryId', requireEnabled, parseJsonBody, async (req, res) => {
|
|
119
|
+
const { target, error } = resolveScope(req.query);
|
|
120
|
+
if (error) {
|
|
121
|
+
return res.status(400).json({ error });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const body = req.body;
|
|
125
|
+
if (!isObjectRecord(body)) {
|
|
126
|
+
return res.status(400).json({ error: 'Body must be an object' });
|
|
127
|
+
}
|
|
128
|
+
if (body.title !== undefined && typeof body.title !== 'string') {
|
|
129
|
+
return res.status(400).json({ error: 'title must be a string' });
|
|
130
|
+
}
|
|
131
|
+
if (body.body !== undefined && typeof body.body !== 'string') {
|
|
132
|
+
return res.status(400).json({ error: 'body must be a string' });
|
|
133
|
+
}
|
|
134
|
+
if (body.type !== undefined && !MEMORY_TYPES.has(body.type)) {
|
|
135
|
+
return res.status(400).json({ error: 'type must be fact, preference, or reference' });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const result = await agentMemoryRuntime.update(target, req.params.memoryId, {
|
|
140
|
+
...(body.title !== undefined ? { title: body.title } : {}),
|
|
141
|
+
...(body.body !== undefined ? { body: body.body } : {}),
|
|
142
|
+
...(body.type !== undefined ? { type: body.type } : {}),
|
|
143
|
+
});
|
|
144
|
+
if (!result) {
|
|
145
|
+
return res.status(404).json({ error: 'Memory not found' });
|
|
146
|
+
}
|
|
147
|
+
return res.json(result);
|
|
148
|
+
} catch (caught) {
|
|
149
|
+
return respondWithError(res, caught, 'Failed to save memory');
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
app.delete('/api/agent-memory/:memoryId', requireEnabled, async (req, res) => {
|
|
154
|
+
const { target, error } = resolveScope(req.query);
|
|
155
|
+
if (error) {
|
|
156
|
+
return res.status(400).json({ error });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
const result = await agentMemoryRuntime.remove(target, req.params.memoryId);
|
|
161
|
+
if (!result.deleted) {
|
|
162
|
+
return res.status(404).json({ error: 'Memory not found' });
|
|
163
|
+
}
|
|
164
|
+
return res.json(result);
|
|
165
|
+
} catch (caught) {
|
|
166
|
+
return respondWithError(res, caught, 'Failed to delete memory');
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
};
|