@dsh-libing/memory-manager 0.0.0-stage → 0.1.1
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/CHANGELOG.md +12 -0
- package/README.md +68 -2
- package/cordis.patch.yml +3 -0
- package/icon.svg +1 -0
- package/lib/client-types/client/Dialogs.d.ts +29 -0
- package/lib/client-types/client/Editor.d.ts +12 -0
- package/lib/client-types/client/MemoryPage.d.ts +31 -0
- package/lib/client-types/client/api.d.ts +9 -0
- package/lib/client-types/client/index.d.ts +9 -0
- package/lib/client-types/client/locales.d.ts +207 -0
- package/lib/client-types/client/navigation.d.ts +6 -0
- package/lib/client-types/client/turnView.d.ts +7 -0
- package/lib/client-types/client/useMemory.d.ts +123 -0
- package/lib/client-types/shared.d.ts +508 -0
- package/lib/client.js +221 -0
- package/lib/index.d.ts +26 -0
- package/lib/index.js +134 -0
- package/lib/models.d.ts +21 -0
- package/lib/models.js +71 -0
- package/lib/recall.d.ts +55 -0
- package/lib/recall.js +47 -0
- package/lib/runtime.d.ts +351 -0
- package/lib/runtime.js +207 -0
- package/lib/scope.d.ts +48 -0
- package/lib/scope.js +100 -0
- package/lib/shared.d.ts +508 -0
- package/lib/shared.js +40 -0
- package/lib/storage-worker.d.ts +1 -0
- package/lib/storage-worker.js +276 -0
- package/lib/store.d.ts +15 -0
- package/lib/store.js +114 -0
- package/package.json +123 -3
package/lib/scope.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { SessionId } from '@deepseek-ai/dsh-session';
|
|
2
|
+
import { realpath } from 'node:fs/promises';
|
|
3
|
+
import { resolve, basename } from 'node:path';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { MemoryError, abort } from "./shared.js";
|
|
6
|
+
export const canonical = async (path) => await realpath(resolve(path));
|
|
7
|
+
export const workspaceKey = (path) => createHash('sha256').update(path).digest('hex');
|
|
8
|
+
export async function agentScope(agent, ctx) {
|
|
9
|
+
if (!agent.session.header.cwd)
|
|
10
|
+
throw new MemoryError('unknownScope', 403);
|
|
11
|
+
const binding = ctx?.get('libingMemoryScopes')?.resolveSession(agent.id);
|
|
12
|
+
if (!binding && /^solo:(?:chat|standing-run):/u.test(agent.session.header.agentPreset ?? ''))
|
|
13
|
+
throw new MemoryError('memoryDisabled', 403);
|
|
14
|
+
if (binding && !binding.enabled)
|
|
15
|
+
throw new MemoryError('memoryDisabled', 403);
|
|
16
|
+
return { workspace: binding?.namespace || workspaceKey(await canonical(agent.session.header.cwd)), session: agent.session.id, ...binding ? { includePersonal: false } : {} };
|
|
17
|
+
}
|
|
18
|
+
export async function selection(ctx, input, signal) {
|
|
19
|
+
const records = await ctx.sessionQuery.listSessions(signal);
|
|
20
|
+
const workspaces = [];
|
|
21
|
+
const paths = new Map();
|
|
22
|
+
const sessions = [];
|
|
23
|
+
for (const workspace of ctx.workspaceRegistry.list()) {
|
|
24
|
+
try {
|
|
25
|
+
const path = await canonical(workspace.path);
|
|
26
|
+
const id = workspaceKey(path);
|
|
27
|
+
paths.set(id, path);
|
|
28
|
+
if (!workspaces.some(row => row.id === id))
|
|
29
|
+
workspaces.push({ id, title: workspace.title });
|
|
30
|
+
}
|
|
31
|
+
catch { /* deleted workspace is not an authority */ }
|
|
32
|
+
}
|
|
33
|
+
const titles = await ctx.sessionQuery.readTitleSnapshots(records.map(row => row.header.id), signal);
|
|
34
|
+
for (const record of records) {
|
|
35
|
+
if (!record.header.cwd)
|
|
36
|
+
continue;
|
|
37
|
+
try {
|
|
38
|
+
const path = await canonical(record.header.cwd);
|
|
39
|
+
const binding = ctx.get('libingMemoryScopes')?.resolveSession(record.header.id);
|
|
40
|
+
const id = binding?.namespace || workspaceKey(path);
|
|
41
|
+
paths.set(id, path);
|
|
42
|
+
if (!workspaces.some(row => row.id === id))
|
|
43
|
+
workspaces.push({ id, title: binding?.namespace ? binding.label : basename(path) });
|
|
44
|
+
const result = titles.find(row => row.sessionId === record.header.id);
|
|
45
|
+
sessions.push({ id: record.header.id, title: result?.status === 'fulfilled' ? result.value.title?.title ?? record.header.id : record.header.id, workspace: id });
|
|
46
|
+
}
|
|
47
|
+
catch { /* unknown roots cannot fall back to another workspace */ }
|
|
48
|
+
}
|
|
49
|
+
const chosen = input.sessionId ? sessions.find(row => row.id === input.sessionId) : undefined;
|
|
50
|
+
if (input.sessionId && !chosen)
|
|
51
|
+
throw new MemoryError('notFound', 404);
|
|
52
|
+
const workspace = input.workspaceId ?? chosen?.workspace ?? workspaces[0]?.id;
|
|
53
|
+
if (!workspace || !paths.has(workspace))
|
|
54
|
+
throw new MemoryError('unknownScope', 403);
|
|
55
|
+
if (chosen && chosen.workspace !== workspace)
|
|
56
|
+
throw new MemoryError('outsideScope', 403);
|
|
57
|
+
abort(signal);
|
|
58
|
+
const matched = sessions.filter(row => row.workspace === workspace);
|
|
59
|
+
const session = chosen?.id ?? matched[0]?.id ?? null;
|
|
60
|
+
const managed = session ? ctx.get('libingMemoryScopes')?.resolveSession(session) : undefined;
|
|
61
|
+
return { scope: { workspace, session, ...managed ? { includePersonal: false } : {} }, selectedSession: session, workspaces, sessions: matched.map(({ workspace: _workspace, ...row }) => row) };
|
|
62
|
+
}
|
|
63
|
+
export async function observedTurn(ctx, session, requested, signal) {
|
|
64
|
+
const view = await ctx.sessionQuery.observeSession(SessionId(session), signal ? { signal } : {});
|
|
65
|
+
try {
|
|
66
|
+
const ends = view.events.flatMap(event => event.type === 'turn/end' && event.data.reason.kind === 'completed' ? [event.data.turn] : []);
|
|
67
|
+
const last = requested ?? ends.at(-1);
|
|
68
|
+
if (!last || !ends.includes(last))
|
|
69
|
+
throw new MemoryError('completedTurnRequired');
|
|
70
|
+
let inside = false;
|
|
71
|
+
const seqs = [];
|
|
72
|
+
const lines = [];
|
|
73
|
+
for (const event of view.events) {
|
|
74
|
+
if (event.type === 'turn/start')
|
|
75
|
+
inside = event.data.turn === last;
|
|
76
|
+
if (!inside)
|
|
77
|
+
continue;
|
|
78
|
+
if (event.type === 'user/message' && event.data.source.kind === 'user') {
|
|
79
|
+
lines.push(`User: ${event.data.content.filter(block => block.type === 'text').map(block => block.text).join('\n')}`);
|
|
80
|
+
seqs.push(event.seq);
|
|
81
|
+
}
|
|
82
|
+
if (event.type === 'assistant/message') {
|
|
83
|
+
lines.push(`Assistant: ${event.data.message.content.filter(block => block.type === 'text').map(block => block.text).join('\n')}`);
|
|
84
|
+
seqs.push(event.seq);
|
|
85
|
+
}
|
|
86
|
+
if (event.type === 'turn/end')
|
|
87
|
+
inside = false;
|
|
88
|
+
}
|
|
89
|
+
if (!lines.some(line => line.startsWith('User:')))
|
|
90
|
+
throw new MemoryError('noUserInput');
|
|
91
|
+
const text = lines.join('\n').slice(0, 12000);
|
|
92
|
+
// Skip, rather than redact and silently change, credential-bearing extraction input.
|
|
93
|
+
if (/-----BEGIN .*PRIVATE KEY|(?:api[_-]?key|password|token|密钥|密码)\s*[:=]\s*\S+/iu.test(text))
|
|
94
|
+
throw new MemoryError('sensitiveInput');
|
|
95
|
+
return { turn: last, input: text, source: { kind: 'capture', session, turn: last, evidence: text.slice(0, 1200), seqs: seqs.slice(0, 100) } };
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
view[Symbol.dispose]();
|
|
99
|
+
}
|
|
100
|
+
}
|
package/lib/shared.d.ts
ADDED
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
/** Validated wire/domain identities; candidates never belong to the readable collection. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const API = "/api/libing-memory-manager";
|
|
4
|
+
export declare const kinds: readonly ["agreement", "decision", "lesson", "handoff"];
|
|
5
|
+
export declare const kindSchema: z.ZodEnum<{
|
|
6
|
+
agreement: "agreement";
|
|
7
|
+
decision: "decision";
|
|
8
|
+
lesson: "lesson";
|
|
9
|
+
handoff: "handoff";
|
|
10
|
+
}>;
|
|
11
|
+
export declare const scopeSchema: z.ZodObject<{
|
|
12
|
+
workspace: z.ZodString;
|
|
13
|
+
session: z.ZodNullable<z.ZodString>;
|
|
14
|
+
includePersonal: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
+
}, z.core.$strict>;
|
|
16
|
+
export type Scope = z.infer<typeof scopeSchema>;
|
|
17
|
+
export declare const draftSchema: z.ZodObject<{
|
|
18
|
+
title: z.ZodString;
|
|
19
|
+
content: z.ZodString;
|
|
20
|
+
kind: z.ZodEnum<{
|
|
21
|
+
agreement: "agreement";
|
|
22
|
+
decision: "decision";
|
|
23
|
+
lesson: "lesson";
|
|
24
|
+
handoff: "handoff";
|
|
25
|
+
}>;
|
|
26
|
+
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
27
|
+
pinned: z.ZodDefault<z.ZodBoolean>;
|
|
28
|
+
recall: z.ZodDefault<z.ZodBoolean>;
|
|
29
|
+
range: z.ZodDefault<z.ZodEnum<{
|
|
30
|
+
workspace: "workspace";
|
|
31
|
+
session: "session";
|
|
32
|
+
personal: "personal";
|
|
33
|
+
}>>;
|
|
34
|
+
}, z.core.$strict>;
|
|
35
|
+
export type Draft = z.infer<typeof draftSchema>;
|
|
36
|
+
export declare const sourceSchema: z.ZodObject<{
|
|
37
|
+
kind: z.ZodEnum<{
|
|
38
|
+
manual: "manual";
|
|
39
|
+
model: "model";
|
|
40
|
+
capture: "capture";
|
|
41
|
+
}>;
|
|
42
|
+
session: z.ZodNullable<z.ZodString>;
|
|
43
|
+
turn: z.ZodNullable<z.ZodNumber>;
|
|
44
|
+
evidence: z.ZodString;
|
|
45
|
+
seqs: z.ZodArray<z.ZodNumber>;
|
|
46
|
+
}, z.core.$strict>;
|
|
47
|
+
export type Source = z.infer<typeof sourceSchema>;
|
|
48
|
+
export declare const entrySchema: z.ZodObject<{
|
|
49
|
+
title: z.ZodString;
|
|
50
|
+
content: z.ZodString;
|
|
51
|
+
kind: z.ZodEnum<{
|
|
52
|
+
agreement: "agreement";
|
|
53
|
+
decision: "decision";
|
|
54
|
+
lesson: "lesson";
|
|
55
|
+
handoff: "handoff";
|
|
56
|
+
}>;
|
|
57
|
+
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
58
|
+
pinned: z.ZodDefault<z.ZodBoolean>;
|
|
59
|
+
recall: z.ZodDefault<z.ZodBoolean>;
|
|
60
|
+
range: z.ZodDefault<z.ZodEnum<{
|
|
61
|
+
workspace: "workspace";
|
|
62
|
+
session: "session";
|
|
63
|
+
personal: "personal";
|
|
64
|
+
}>>;
|
|
65
|
+
id: z.ZodString;
|
|
66
|
+
version: z.ZodNumber;
|
|
67
|
+
workspace: z.ZodString;
|
|
68
|
+
session: z.ZodNullable<z.ZodString>;
|
|
69
|
+
state: z.ZodEnum<{
|
|
70
|
+
active: "active";
|
|
71
|
+
trash: "trash";
|
|
72
|
+
}>;
|
|
73
|
+
source: z.ZodObject<{
|
|
74
|
+
kind: z.ZodEnum<{
|
|
75
|
+
manual: "manual";
|
|
76
|
+
model: "model";
|
|
77
|
+
capture: "capture";
|
|
78
|
+
}>;
|
|
79
|
+
session: z.ZodNullable<z.ZodString>;
|
|
80
|
+
turn: z.ZodNullable<z.ZodNumber>;
|
|
81
|
+
evidence: z.ZodString;
|
|
82
|
+
seqs: z.ZodArray<z.ZodNumber>;
|
|
83
|
+
}, z.core.$strict>;
|
|
84
|
+
updated: z.ZodString;
|
|
85
|
+
}, z.core.$strict>;
|
|
86
|
+
export type Entry = z.infer<typeof entrySchema>;
|
|
87
|
+
export declare const candidateSchema: z.ZodObject<{
|
|
88
|
+
id: z.ZodString;
|
|
89
|
+
revision: z.ZodString;
|
|
90
|
+
target: z.ZodNullable<z.ZodString>;
|
|
91
|
+
expected: z.ZodNumber;
|
|
92
|
+
workspace: z.ZodString;
|
|
93
|
+
session: z.ZodNullable<z.ZodString>;
|
|
94
|
+
draft: z.ZodObject<{
|
|
95
|
+
title: z.ZodString;
|
|
96
|
+
content: z.ZodString;
|
|
97
|
+
kind: z.ZodEnum<{
|
|
98
|
+
agreement: "agreement";
|
|
99
|
+
decision: "decision";
|
|
100
|
+
lesson: "lesson";
|
|
101
|
+
handoff: "handoff";
|
|
102
|
+
}>;
|
|
103
|
+
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
104
|
+
pinned: z.ZodDefault<z.ZodBoolean>;
|
|
105
|
+
recall: z.ZodDefault<z.ZodBoolean>;
|
|
106
|
+
range: z.ZodDefault<z.ZodEnum<{
|
|
107
|
+
workspace: "workspace";
|
|
108
|
+
session: "session";
|
|
109
|
+
personal: "personal";
|
|
110
|
+
}>>;
|
|
111
|
+
}, z.core.$strict>;
|
|
112
|
+
source: z.ZodObject<{
|
|
113
|
+
kind: z.ZodEnum<{
|
|
114
|
+
manual: "manual";
|
|
115
|
+
model: "model";
|
|
116
|
+
capture: "capture";
|
|
117
|
+
}>;
|
|
118
|
+
session: z.ZodNullable<z.ZodString>;
|
|
119
|
+
turn: z.ZodNullable<z.ZodNumber>;
|
|
120
|
+
evidence: z.ZodString;
|
|
121
|
+
seqs: z.ZodArray<z.ZodNumber>;
|
|
122
|
+
}, z.core.$strict>;
|
|
123
|
+
state: z.ZodEnum<{
|
|
124
|
+
pending: "pending";
|
|
125
|
+
rejected: "rejected";
|
|
126
|
+
accepted: "accepted";
|
|
127
|
+
}>;
|
|
128
|
+
updated: z.ZodString;
|
|
129
|
+
}, z.core.$strip>;
|
|
130
|
+
export type Candidate = z.infer<typeof candidateSchema>;
|
|
131
|
+
export declare const activityItemSchema: z.ZodObject<{
|
|
132
|
+
id: z.ZodString;
|
|
133
|
+
version: z.ZodNumber;
|
|
134
|
+
title: z.ZodString;
|
|
135
|
+
summary: z.ZodString;
|
|
136
|
+
status: z.ZodEnum<{
|
|
137
|
+
prepared: "prepared";
|
|
138
|
+
included: "included";
|
|
139
|
+
search: "search";
|
|
140
|
+
read: "read";
|
|
141
|
+
deleted: "deleted";
|
|
142
|
+
}>;
|
|
143
|
+
}, z.core.$strip>;
|
|
144
|
+
export type ActivityItem = z.infer<typeof activityItemSchema>;
|
|
145
|
+
export declare const activitySchema: z.ZodObject<{
|
|
146
|
+
id: z.ZodString;
|
|
147
|
+
workspace: z.ZodString;
|
|
148
|
+
session: z.ZodNullable<z.ZodString>;
|
|
149
|
+
turn: z.ZodNullable<z.ZodNumber>;
|
|
150
|
+
kind: z.ZodString;
|
|
151
|
+
reason: z.ZodString;
|
|
152
|
+
items: z.ZodArray<z.ZodObject<{
|
|
153
|
+
id: z.ZodString;
|
|
154
|
+
version: z.ZodNumber;
|
|
155
|
+
title: z.ZodString;
|
|
156
|
+
summary: z.ZodString;
|
|
157
|
+
status: z.ZodEnum<{
|
|
158
|
+
prepared: "prepared";
|
|
159
|
+
included: "included";
|
|
160
|
+
search: "search";
|
|
161
|
+
read: "read";
|
|
162
|
+
deleted: "deleted";
|
|
163
|
+
}>;
|
|
164
|
+
}, z.core.$strip>>;
|
|
165
|
+
updated: z.ZodString;
|
|
166
|
+
}, z.core.$strip>;
|
|
167
|
+
export type Activity = z.infer<typeof activitySchema>;
|
|
168
|
+
export declare const jobSchema: z.ZodObject<{
|
|
169
|
+
id: z.ZodString;
|
|
170
|
+
workspace: z.ZodString;
|
|
171
|
+
session: z.ZodString;
|
|
172
|
+
turn: z.ZodNumber;
|
|
173
|
+
state: z.ZodEnum<{
|
|
174
|
+
queued: "queued";
|
|
175
|
+
running: "running";
|
|
176
|
+
done: "done";
|
|
177
|
+
failed: "failed";
|
|
178
|
+
cancelled: "cancelled";
|
|
179
|
+
interrupted: "interrupted";
|
|
180
|
+
skipped: "skipped";
|
|
181
|
+
}>;
|
|
182
|
+
reason: z.ZodString;
|
|
183
|
+
candidateIds: z.ZodArray<z.ZodString>;
|
|
184
|
+
updated: z.ZodString;
|
|
185
|
+
automatic: z.ZodBoolean;
|
|
186
|
+
}, z.core.$strip>;
|
|
187
|
+
export type Job = z.infer<typeof jobSchema>;
|
|
188
|
+
export declare const settingsSchema: z.ZodObject<{
|
|
189
|
+
revision: z.ZodDefault<z.ZodNumber>;
|
|
190
|
+
autoRecall: z.ZodDefault<z.ZodBoolean>;
|
|
191
|
+
autoCapture: z.ZodDefault<z.ZodBoolean>;
|
|
192
|
+
provider: z.ZodDefault<z.ZodString>;
|
|
193
|
+
model: z.ZodDefault<z.ZodString>;
|
|
194
|
+
maxDailyCalls: z.ZodDefault<z.ZodNumber>;
|
|
195
|
+
maxRecallChars: z.ZodDefault<z.ZodNumber>;
|
|
196
|
+
}, z.core.$strict>;
|
|
197
|
+
export type Settings = z.infer<typeof settingsSchema>;
|
|
198
|
+
export declare const selectionSchema: z.ZodObject<{
|
|
199
|
+
workspaceId: z.ZodOptional<z.ZodString>;
|
|
200
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
201
|
+
}, z.core.$strict>;
|
|
202
|
+
export type Selection = z.infer<typeof selectionSchema>;
|
|
203
|
+
export declare const mutationSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
204
|
+
action: z.ZodLiteral<"create">;
|
|
205
|
+
draft: z.ZodObject<{
|
|
206
|
+
title: z.ZodString;
|
|
207
|
+
content: z.ZodString;
|
|
208
|
+
kind: z.ZodEnum<{
|
|
209
|
+
agreement: "agreement";
|
|
210
|
+
decision: "decision";
|
|
211
|
+
lesson: "lesson";
|
|
212
|
+
handoff: "handoff";
|
|
213
|
+
}>;
|
|
214
|
+
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
215
|
+
pinned: z.ZodDefault<z.ZodBoolean>;
|
|
216
|
+
recall: z.ZodDefault<z.ZodBoolean>;
|
|
217
|
+
range: z.ZodDefault<z.ZodEnum<{
|
|
218
|
+
workspace: "workspace";
|
|
219
|
+
session: "session";
|
|
220
|
+
personal: "personal";
|
|
221
|
+
}>>;
|
|
222
|
+
}, z.core.$strict>;
|
|
223
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
224
|
+
action: z.ZodLiteral<"propose">;
|
|
225
|
+
draft: z.ZodObject<{
|
|
226
|
+
title: z.ZodString;
|
|
227
|
+
content: z.ZodString;
|
|
228
|
+
kind: z.ZodEnum<{
|
|
229
|
+
agreement: "agreement";
|
|
230
|
+
decision: "decision";
|
|
231
|
+
lesson: "lesson";
|
|
232
|
+
handoff: "handoff";
|
|
233
|
+
}>;
|
|
234
|
+
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
235
|
+
pinned: z.ZodDefault<z.ZodBoolean>;
|
|
236
|
+
recall: z.ZodDefault<z.ZodBoolean>;
|
|
237
|
+
range: z.ZodDefault<z.ZodEnum<{
|
|
238
|
+
workspace: "workspace";
|
|
239
|
+
session: "session";
|
|
240
|
+
personal: "personal";
|
|
241
|
+
}>>;
|
|
242
|
+
}, z.core.$strict>;
|
|
243
|
+
target: z.ZodOptional<z.ZodString>;
|
|
244
|
+
expected: z.ZodOptional<z.ZodNumber>;
|
|
245
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
246
|
+
action: z.ZodLiteral<"approve">;
|
|
247
|
+
id: z.ZodString;
|
|
248
|
+
revision: z.ZodString;
|
|
249
|
+
draft: z.ZodObject<{
|
|
250
|
+
title: z.ZodString;
|
|
251
|
+
content: z.ZodString;
|
|
252
|
+
kind: z.ZodEnum<{
|
|
253
|
+
agreement: "agreement";
|
|
254
|
+
decision: "decision";
|
|
255
|
+
lesson: "lesson";
|
|
256
|
+
handoff: "handoff";
|
|
257
|
+
}>;
|
|
258
|
+
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
259
|
+
pinned: z.ZodDefault<z.ZodBoolean>;
|
|
260
|
+
recall: z.ZodDefault<z.ZodBoolean>;
|
|
261
|
+
range: z.ZodDefault<z.ZodEnum<{
|
|
262
|
+
workspace: "workspace";
|
|
263
|
+
session: "session";
|
|
264
|
+
personal: "personal";
|
|
265
|
+
}>>;
|
|
266
|
+
}, z.core.$strict>;
|
|
267
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
268
|
+
action: z.ZodLiteral<"reject">;
|
|
269
|
+
id: z.ZodString;
|
|
270
|
+
revision: z.ZodString;
|
|
271
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
272
|
+
action: z.ZodEnum<{
|
|
273
|
+
trash: "trash";
|
|
274
|
+
restore: "restore";
|
|
275
|
+
toggle: "toggle";
|
|
276
|
+
}>;
|
|
277
|
+
id: z.ZodString;
|
|
278
|
+
version: z.ZodNumber;
|
|
279
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
280
|
+
action: z.ZodLiteral<"purge">;
|
|
281
|
+
id: z.ZodString;
|
|
282
|
+
version: z.ZodNumber;
|
|
283
|
+
confirmTitle: z.ZodString;
|
|
284
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
285
|
+
action: z.ZodLiteral<"settings">;
|
|
286
|
+
settings: z.ZodObject<{
|
|
287
|
+
revision: z.ZodDefault<z.ZodNumber>;
|
|
288
|
+
autoRecall: z.ZodDefault<z.ZodBoolean>;
|
|
289
|
+
autoCapture: z.ZodDefault<z.ZodBoolean>;
|
|
290
|
+
provider: z.ZodDefault<z.ZodString>;
|
|
291
|
+
model: z.ZodDefault<z.ZodString>;
|
|
292
|
+
maxDailyCalls: z.ZodDefault<z.ZodNumber>;
|
|
293
|
+
maxRecallChars: z.ZodDefault<z.ZodNumber>;
|
|
294
|
+
}, z.core.$strict>;
|
|
295
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
296
|
+
action: z.ZodLiteral<"capture">;
|
|
297
|
+
turn: z.ZodOptional<z.ZodNumber>;
|
|
298
|
+
expectedModel: z.ZodOptional<z.ZodObject<{
|
|
299
|
+
provider: z.ZodString;
|
|
300
|
+
model: z.ZodString;
|
|
301
|
+
}, z.core.$strict>>;
|
|
302
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
303
|
+
action: z.ZodLiteral<"cancel">;
|
|
304
|
+
id: z.ZodString;
|
|
305
|
+
}, z.core.$strict>], "action">;
|
|
306
|
+
export type Mutation = z.infer<typeof mutationSchema>;
|
|
307
|
+
export declare const captureModelSchema: z.ZodObject<{
|
|
308
|
+
provider: z.ZodString;
|
|
309
|
+
model: z.ZodString;
|
|
310
|
+
source: z.ZodEnum<{
|
|
311
|
+
session: "session";
|
|
312
|
+
default: "default";
|
|
313
|
+
custom: "custom";
|
|
314
|
+
}>;
|
|
315
|
+
available: z.ZodBoolean;
|
|
316
|
+
}, z.core.$strip>;
|
|
317
|
+
export declare const modelDirectorySchema: z.ZodObject<{
|
|
318
|
+
providers: z.ZodArray<z.ZodObject<{
|
|
319
|
+
id: z.ZodString;
|
|
320
|
+
name: z.ZodString;
|
|
321
|
+
models: z.ZodArray<z.ZodObject<{
|
|
322
|
+
id: z.ZodString;
|
|
323
|
+
name: z.ZodString;
|
|
324
|
+
}, z.core.$strip>>;
|
|
325
|
+
unavailable: z.ZodBoolean;
|
|
326
|
+
}, z.core.$strip>>;
|
|
327
|
+
}, z.core.$strip>;
|
|
328
|
+
export type CaptureModel = z.infer<typeof captureModelSchema>;
|
|
329
|
+
export type ModelDirectory = z.infer<typeof modelDirectorySchema>;
|
|
330
|
+
export declare const stateSchema: z.ZodObject<{
|
|
331
|
+
profile: z.ZodString;
|
|
332
|
+
scope: z.ZodObject<{
|
|
333
|
+
workspace: z.ZodString;
|
|
334
|
+
session: z.ZodNullable<z.ZodString>;
|
|
335
|
+
includePersonal: z.ZodOptional<z.ZodBoolean>;
|
|
336
|
+
}, z.core.$strict>;
|
|
337
|
+
selectedSession: z.ZodNullable<z.ZodString>;
|
|
338
|
+
workspaces: z.ZodArray<z.ZodObject<{
|
|
339
|
+
id: z.ZodString;
|
|
340
|
+
title: z.ZodString;
|
|
341
|
+
}, z.core.$strip>>;
|
|
342
|
+
sessions: z.ZodArray<z.ZodObject<{
|
|
343
|
+
id: z.ZodString;
|
|
344
|
+
title: z.ZodString;
|
|
345
|
+
}, z.core.$strip>>;
|
|
346
|
+
entries: z.ZodArray<z.ZodObject<{
|
|
347
|
+
title: z.ZodString;
|
|
348
|
+
content: z.ZodString;
|
|
349
|
+
kind: z.ZodEnum<{
|
|
350
|
+
agreement: "agreement";
|
|
351
|
+
decision: "decision";
|
|
352
|
+
lesson: "lesson";
|
|
353
|
+
handoff: "handoff";
|
|
354
|
+
}>;
|
|
355
|
+
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
356
|
+
pinned: z.ZodDefault<z.ZodBoolean>;
|
|
357
|
+
recall: z.ZodDefault<z.ZodBoolean>;
|
|
358
|
+
range: z.ZodDefault<z.ZodEnum<{
|
|
359
|
+
workspace: "workspace";
|
|
360
|
+
session: "session";
|
|
361
|
+
personal: "personal";
|
|
362
|
+
}>>;
|
|
363
|
+
id: z.ZodString;
|
|
364
|
+
version: z.ZodNumber;
|
|
365
|
+
workspace: z.ZodString;
|
|
366
|
+
session: z.ZodNullable<z.ZodString>;
|
|
367
|
+
state: z.ZodEnum<{
|
|
368
|
+
active: "active";
|
|
369
|
+
trash: "trash";
|
|
370
|
+
}>;
|
|
371
|
+
source: z.ZodObject<{
|
|
372
|
+
kind: z.ZodEnum<{
|
|
373
|
+
manual: "manual";
|
|
374
|
+
model: "model";
|
|
375
|
+
capture: "capture";
|
|
376
|
+
}>;
|
|
377
|
+
session: z.ZodNullable<z.ZodString>;
|
|
378
|
+
turn: z.ZodNullable<z.ZodNumber>;
|
|
379
|
+
evidence: z.ZodString;
|
|
380
|
+
seqs: z.ZodArray<z.ZodNumber>;
|
|
381
|
+
}, z.core.$strict>;
|
|
382
|
+
updated: z.ZodString;
|
|
383
|
+
}, z.core.$strict>>;
|
|
384
|
+
candidates: z.ZodArray<z.ZodObject<{
|
|
385
|
+
id: z.ZodString;
|
|
386
|
+
revision: z.ZodString;
|
|
387
|
+
target: z.ZodNullable<z.ZodString>;
|
|
388
|
+
expected: z.ZodNumber;
|
|
389
|
+
workspace: z.ZodString;
|
|
390
|
+
session: z.ZodNullable<z.ZodString>;
|
|
391
|
+
draft: z.ZodObject<{
|
|
392
|
+
title: z.ZodString;
|
|
393
|
+
content: z.ZodString;
|
|
394
|
+
kind: z.ZodEnum<{
|
|
395
|
+
agreement: "agreement";
|
|
396
|
+
decision: "decision";
|
|
397
|
+
lesson: "lesson";
|
|
398
|
+
handoff: "handoff";
|
|
399
|
+
}>;
|
|
400
|
+
tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
401
|
+
pinned: z.ZodDefault<z.ZodBoolean>;
|
|
402
|
+
recall: z.ZodDefault<z.ZodBoolean>;
|
|
403
|
+
range: z.ZodDefault<z.ZodEnum<{
|
|
404
|
+
workspace: "workspace";
|
|
405
|
+
session: "session";
|
|
406
|
+
personal: "personal";
|
|
407
|
+
}>>;
|
|
408
|
+
}, z.core.$strict>;
|
|
409
|
+
source: z.ZodObject<{
|
|
410
|
+
kind: z.ZodEnum<{
|
|
411
|
+
manual: "manual";
|
|
412
|
+
model: "model";
|
|
413
|
+
capture: "capture";
|
|
414
|
+
}>;
|
|
415
|
+
session: z.ZodNullable<z.ZodString>;
|
|
416
|
+
turn: z.ZodNullable<z.ZodNumber>;
|
|
417
|
+
evidence: z.ZodString;
|
|
418
|
+
seqs: z.ZodArray<z.ZodNumber>;
|
|
419
|
+
}, z.core.$strict>;
|
|
420
|
+
state: z.ZodEnum<{
|
|
421
|
+
pending: "pending";
|
|
422
|
+
rejected: "rejected";
|
|
423
|
+
accepted: "accepted";
|
|
424
|
+
}>;
|
|
425
|
+
updated: z.ZodString;
|
|
426
|
+
}, z.core.$strip>>;
|
|
427
|
+
activities: z.ZodArray<z.ZodObject<{
|
|
428
|
+
id: z.ZodString;
|
|
429
|
+
workspace: z.ZodString;
|
|
430
|
+
session: z.ZodNullable<z.ZodString>;
|
|
431
|
+
turn: z.ZodNullable<z.ZodNumber>;
|
|
432
|
+
kind: z.ZodString;
|
|
433
|
+
reason: z.ZodString;
|
|
434
|
+
items: z.ZodArray<z.ZodObject<{
|
|
435
|
+
id: z.ZodString;
|
|
436
|
+
version: z.ZodNumber;
|
|
437
|
+
title: z.ZodString;
|
|
438
|
+
summary: z.ZodString;
|
|
439
|
+
status: z.ZodEnum<{
|
|
440
|
+
prepared: "prepared";
|
|
441
|
+
included: "included";
|
|
442
|
+
search: "search";
|
|
443
|
+
read: "read";
|
|
444
|
+
deleted: "deleted";
|
|
445
|
+
}>;
|
|
446
|
+
}, z.core.$strip>>;
|
|
447
|
+
updated: z.ZodString;
|
|
448
|
+
}, z.core.$strip>>;
|
|
449
|
+
jobs: z.ZodArray<z.ZodObject<{
|
|
450
|
+
id: z.ZodString;
|
|
451
|
+
workspace: z.ZodString;
|
|
452
|
+
session: z.ZodString;
|
|
453
|
+
turn: z.ZodNumber;
|
|
454
|
+
state: z.ZodEnum<{
|
|
455
|
+
queued: "queued";
|
|
456
|
+
running: "running";
|
|
457
|
+
done: "done";
|
|
458
|
+
failed: "failed";
|
|
459
|
+
cancelled: "cancelled";
|
|
460
|
+
interrupted: "interrupted";
|
|
461
|
+
skipped: "skipped";
|
|
462
|
+
}>;
|
|
463
|
+
reason: z.ZodString;
|
|
464
|
+
candidateIds: z.ZodArray<z.ZodString>;
|
|
465
|
+
updated: z.ZodString;
|
|
466
|
+
automatic: z.ZodBoolean;
|
|
467
|
+
}, z.core.$strip>>;
|
|
468
|
+
settings: z.ZodObject<{
|
|
469
|
+
revision: z.ZodDefault<z.ZodNumber>;
|
|
470
|
+
autoRecall: z.ZodDefault<z.ZodBoolean>;
|
|
471
|
+
autoCapture: z.ZodDefault<z.ZodBoolean>;
|
|
472
|
+
provider: z.ZodDefault<z.ZodString>;
|
|
473
|
+
model: z.ZodDefault<z.ZodString>;
|
|
474
|
+
maxDailyCalls: z.ZodDefault<z.ZodNumber>;
|
|
475
|
+
maxRecallChars: z.ZodDefault<z.ZodNumber>;
|
|
476
|
+
}, z.core.$strict>;
|
|
477
|
+
captureModel: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
478
|
+
provider: z.ZodString;
|
|
479
|
+
model: z.ZodString;
|
|
480
|
+
source: z.ZodEnum<{
|
|
481
|
+
session: "session";
|
|
482
|
+
default: "default";
|
|
483
|
+
custom: "custom";
|
|
484
|
+
}>;
|
|
485
|
+
available: z.ZodBoolean;
|
|
486
|
+
}, z.core.$strip>>>;
|
|
487
|
+
followingModel: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
488
|
+
provider: z.ZodString;
|
|
489
|
+
model: z.ZodString;
|
|
490
|
+
source: z.ZodEnum<{
|
|
491
|
+
session: "session";
|
|
492
|
+
default: "default";
|
|
493
|
+
custom: "custom";
|
|
494
|
+
}>;
|
|
495
|
+
available: z.ZodBoolean;
|
|
496
|
+
}, z.core.$strip>>>;
|
|
497
|
+
}, z.core.$strip>;
|
|
498
|
+
export type State = z.infer<typeof stateSchema>;
|
|
499
|
+
export declare const visible: (value: {
|
|
500
|
+
workspace: string;
|
|
501
|
+
session: string | null;
|
|
502
|
+
}, scope: Scope) => boolean;
|
|
503
|
+
export declare class MemoryError extends Error {
|
|
504
|
+
readonly code: string;
|
|
505
|
+
readonly status: number;
|
|
506
|
+
constructor(code: string, status?: number);
|
|
507
|
+
}
|
|
508
|
+
export declare function abort(signal?: AbortSignal): void;
|
package/lib/shared.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Validated wire/domain identities; candidates never belong to the readable collection. */
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export const API = '/api/libing-memory-manager';
|
|
4
|
+
export const kinds = ['agreement', 'decision', 'lesson', 'handoff'];
|
|
5
|
+
export const kindSchema = z.enum(kinds);
|
|
6
|
+
export const scopeSchema = z.object({ workspace: z.string().min(1), session: z.string().min(1).nullable(), includePersonal: z.boolean().optional() }).strict();
|
|
7
|
+
export const draftSchema = z.object({ title: z.string().trim().min(1).max(120), content: z.string().trim().min(1).max(6000), kind: kindSchema, tags: z.array(z.string().trim().min(1).max(40)).max(12).default([]), pinned: z.boolean().default(false), recall: z.boolean().default(true), range: z.enum(['workspace', 'session', 'personal']).default('workspace') }).strict();
|
|
8
|
+
export const sourceSchema = z.object({ kind: z.enum(['manual', 'model', 'capture']), session: z.string().nullable(), turn: z.number().int().nonnegative().nullable(), evidence: z.string().max(1200), seqs: z.array(z.number().int().nonnegative()).max(100) }).strict();
|
|
9
|
+
export const entrySchema = draftSchema.extend({ id: z.string(), version: z.number().int().positive(), workspace: z.string(), session: z.string().nullable(), state: z.enum(['active', 'trash']), source: sourceSchema, updated: z.string() });
|
|
10
|
+
export const candidateSchema = z.object({ id: z.string(), revision: z.string(), target: z.string().nullable(), expected: z.number().int().nonnegative(), workspace: z.string(), session: z.string().nullable(), draft: draftSchema, source: sourceSchema, state: z.enum(['pending', 'rejected', 'accepted']), updated: z.string() });
|
|
11
|
+
export const activityItemSchema = z.object({ id: z.string(), version: z.number().int(), title: z.string(), summary: z.string(), status: z.enum(['prepared', 'included', 'search', 'read', 'deleted']) });
|
|
12
|
+
export const activitySchema = z.object({ id: z.string(), workspace: z.string(), session: z.string().nullable(), turn: z.number().int().nullable(), kind: z.string(), reason: z.string(), items: z.array(activityItemSchema), updated: z.string() });
|
|
13
|
+
export const jobSchema = z.object({ id: z.string(), workspace: z.string(), session: z.string(), turn: z.number().int(), state: z.enum(['queued', 'running', 'done', 'failed', 'cancelled', 'interrupted', 'skipped']), reason: z.string(), candidateIds: z.array(z.string()), updated: z.string(), automatic: z.boolean() });
|
|
14
|
+
export const settingsSchema = z.object({ revision: z.number().int().nonnegative().default(0), autoRecall: z.boolean().default(true), autoCapture: z.boolean().default(false), provider: z.string().max(120).default(''), model: z.string().max(160).default(''), maxDailyCalls: z.number().int().min(1).max(100).default(20), maxRecallChars: z.number().int().min(500).max(8000).default(4000) }).strict();
|
|
15
|
+
export const selectionSchema = z.object({ workspaceId: z.string().optional(), sessionId: z.string().optional() }).strict();
|
|
16
|
+
export const mutationSchema = z.discriminatedUnion('action', [
|
|
17
|
+
z.strictObject({ action: z.literal('create'), draft: draftSchema }),
|
|
18
|
+
z.strictObject({ action: z.literal('propose'), draft: draftSchema, target: z.string().optional(), expected: z.number().int().optional() }),
|
|
19
|
+
z.strictObject({ action: z.literal('approve'), id: z.string(), revision: z.string(), draft: draftSchema }),
|
|
20
|
+
z.strictObject({ action: z.literal('reject'), id: z.string(), revision: z.string() }),
|
|
21
|
+
z.strictObject({ action: z.enum(['trash', 'restore', 'toggle']), id: z.string(), version: z.number().int().positive() }),
|
|
22
|
+
z.strictObject({ action: z.literal('purge'), id: z.string(), version: z.number().int().positive(), confirmTitle: z.string() }),
|
|
23
|
+
z.strictObject({ action: z.literal('settings'), settings: settingsSchema }),
|
|
24
|
+
z.strictObject({ action: z.literal('capture'), turn: z.number().int().positive().optional(), expectedModel: z.strictObject({ provider: z.string(), model: z.string() }).optional() }),
|
|
25
|
+
z.strictObject({ action: z.literal('cancel'), id: z.string() })
|
|
26
|
+
]);
|
|
27
|
+
export const captureModelSchema = z.object({ provider: z.string(), model: z.string(), source: z.enum(['session', 'default', 'custom']), available: z.boolean() });
|
|
28
|
+
export const modelDirectorySchema = z.object({ providers: z.array(z.object({ id: z.string(), name: z.string(), models: z.array(z.object({ id: z.string(), name: z.string() })), unavailable: z.boolean() })) });
|
|
29
|
+
export const stateSchema = z.object({ profile: z.string(), scope: scopeSchema, selectedSession: z.string().nullable(), workspaces: z.array(z.object({ id: z.string(), title: z.string() })), sessions: z.array(z.object({ id: z.string(), title: z.string() })), entries: z.array(entrySchema), candidates: z.array(candidateSchema), activities: z.array(activitySchema), jobs: z.array(jobSchema), settings: settingsSchema, captureModel: captureModelSchema.nullable().default(null), followingModel: captureModelSchema.nullable().default(null) });
|
|
30
|
+
export const visible = (value, scope) => (value.workspace === 'personal' && scope.includePersonal !== false || value.workspace === scope.workspace) && (value.session === null || value.session === scope.session);
|
|
31
|
+
export class MemoryError extends Error {
|
|
32
|
+
code;
|
|
33
|
+
status;
|
|
34
|
+
constructor(code, status = 409) {
|
|
35
|
+
super(code);
|
|
36
|
+
this.code = code;
|
|
37
|
+
this.status = status;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function abort(signal) { signal?.throwIfAborted(); }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|