@memtensor/memos-local-openclaw-plugin 1.0.2-beta.5 â 1.0.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/dist/capture/index.js +52 -8
- package/dist/capture/index.js.map +1 -1
- package/dist/ingest/chunker.d.ts +3 -4
- package/dist/ingest/chunker.d.ts.map +1 -1
- package/dist/ingest/chunker.js +19 -24
- package/dist/ingest/chunker.js.map +1 -1
- package/dist/ingest/providers/anthropic.d.ts +3 -1
- package/dist/ingest/providers/anthropic.d.ts.map +1 -1
- package/dist/ingest/providers/anthropic.js +79 -39
- package/dist/ingest/providers/anthropic.js.map +1 -1
- package/dist/ingest/providers/bedrock.d.ts +3 -1
- package/dist/ingest/providers/bedrock.d.ts.map +1 -1
- package/dist/ingest/providers/bedrock.js +79 -39
- package/dist/ingest/providers/bedrock.js.map +1 -1
- package/dist/ingest/providers/gemini.d.ts +3 -1
- package/dist/ingest/providers/gemini.d.ts.map +1 -1
- package/dist/ingest/providers/gemini.js +77 -39
- package/dist/ingest/providers/gemini.js.map +1 -1
- package/dist/ingest/providers/index.d.ts +3 -1
- package/dist/ingest/providers/index.d.ts.map +1 -1
- package/dist/ingest/providers/index.js +70 -30
- package/dist/ingest/providers/index.js.map +1 -1
- package/dist/ingest/providers/openai.d.ts +3 -1
- package/dist/ingest/providers/openai.d.ts.map +1 -1
- package/dist/ingest/providers/openai.js +80 -39
- package/dist/ingest/providers/openai.js.map +1 -1
- package/dist/ingest/task-processor.d.ts +1 -0
- package/dist/ingest/task-processor.d.ts.map +1 -1
- package/dist/ingest/task-processor.js +33 -9
- package/dist/ingest/task-processor.js.map +1 -1
- package/dist/ingest/worker.d.ts.map +1 -1
- package/dist/ingest/worker.js +29 -13
- package/dist/ingest/worker.js.map +1 -1
- package/dist/recall/engine.d.ts.map +1 -1
- package/dist/recall/engine.js +19 -14
- package/dist/recall/engine.js.map +1 -1
- package/dist/skill/bundled-memory-guide.d.ts +1 -5
- package/dist/skill/bundled-memory-guide.d.ts.map +1 -1
- package/dist/skill/bundled-memory-guide.js +38 -97
- package/dist/skill/bundled-memory-guide.js.map +1 -1
- package/dist/skill/evaluator.js +1 -1
- package/dist/storage/sqlite.d.ts +1 -2
- package/dist/storage/sqlite.d.ts.map +1 -1
- package/dist/storage/sqlite.js +90 -17
- package/dist/storage/sqlite.js.map +1 -1
- package/dist/tools/memory-get.d.ts.map +1 -1
- package/dist/tools/memory-get.js +1 -3
- package/dist/tools/memory-get.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/update-check.d.ts +21 -0
- package/dist/update-check.d.ts.map +1 -0
- package/dist/update-check.js +111 -0
- package/dist/update-check.js.map +1 -0
- package/dist/viewer/html.d.ts.map +1 -1
- package/dist/viewer/html.js +444 -182
- package/dist/viewer/html.js.map +1 -1
- package/dist/viewer/server.d.ts +1 -1
- package/dist/viewer/server.d.ts.map +1 -1
- package/dist/viewer/server.js +142 -78
- package/dist/viewer/server.js.map +1 -1
- package/index.ts +206 -198
- package/openclaw.plugin.json +3 -0
- package/package.json +5 -1
- package/scripts/postinstall.cjs +69 -2
- package/skill/memos-memory-guide/SKILL.md +73 -36
- package/src/capture/index.ts +52 -8
- package/src/ingest/chunker.ts +22 -30
- package/src/ingest/providers/anthropic.ts +89 -41
- package/src/ingest/providers/bedrock.ts +90 -41
- package/src/ingest/providers/gemini.ts +89 -41
- package/src/ingest/providers/index.ts +81 -35
- package/src/ingest/providers/openai.ts +90 -41
- package/src/ingest/task-processor.ts +29 -8
- package/src/ingest/worker.ts +31 -13
- package/src/recall/engine.ts +20 -13
- package/src/skill/bundled-memory-guide.ts +5 -96
- package/src/skill/evaluator.ts +1 -1
- package/src/storage/sqlite.ts +93 -21
- package/src/tools/memory-get.ts +1 -4
- package/src/types.ts +2 -9
- package/src/update-check.ts +96 -0
- package/src/viewer/html.ts +444 -182
- package/src/viewer/server.ts +101 -66
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
import type { SummarizerConfig, Logger } from "../../types";
|
|
2
2
|
|
|
3
|
-
const SYSTEM_PROMPT = `You
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
3
|
+
const SYSTEM_PROMPT = `You generate a retrieval-friendly title.
|
|
4
|
+
|
|
5
|
+
Return exactly one noun phrase that names the topic AND its key details.
|
|
6
|
+
|
|
7
|
+
Requirements:
|
|
8
|
+
- Same language as input
|
|
9
|
+
- Keep proper nouns, API/function names, specific parameters, versions, error codes
|
|
10
|
+
- Include WHO/WHAT/WHERE details when present (e.g. person name + event, tool name + what it does)
|
|
11
|
+
- Prefer concrete topic words over generic words
|
|
12
|
+
- No verbs unless unavoidable
|
|
13
|
+
- No generic endings like:
|
|
14
|
+
åč―čŊīæãä―ŋįĻčŊīæãįŪäŧãäŧįŧãįĻéãsummaryãoverviewãbasics
|
|
15
|
+
- Chinese: 10-50 characters (aim for 15-30)
|
|
16
|
+
- Non-Chinese: 5-15 words (aim for 8-12)
|
|
17
|
+
- Output title only`;
|
|
13
18
|
|
|
14
19
|
const TASK_SUMMARY_PROMPT = `You create a DETAILED task summary from a multi-turn conversation. This summary will be the ONLY record of this conversation, so it must preserve ALL important information.
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
## LANGUAGE RULE (HIGHEST PRIORITY)
|
|
22
|
+
Detect the PRIMARY language of the user's messages. If most user messages are Chinese, ALL output (title, goal, steps, result, details) MUST be in Chinese. If English, output in English. NEVER mix. This rule overrides everything below.
|
|
17
23
|
|
|
18
24
|
Output EXACTLY this structure:
|
|
19
25
|
|
|
20
|
-
ð Title
|
|
21
|
-
A short, descriptive title (10-30 characters).
|
|
26
|
+
ð Title / æ éĒ
|
|
27
|
+
A short, descriptive title (10-30 characters). Same language as user messages.
|
|
22
28
|
|
|
23
|
-
ðŊ Goal
|
|
29
|
+
ðŊ Goal / įŪæ
|
|
24
30
|
One sentence: what the user wanted to accomplish.
|
|
25
31
|
|
|
26
|
-
ð Key Steps
|
|
32
|
+
ð Key Steps / å
ģéŪæĨéŠĪ
|
|
27
33
|
- Describe each meaningful step in detail
|
|
28
34
|
- Include the ACTUAL content produced: code snippets, commands, config blocks, formulas, key paragraphs
|
|
29
35
|
- For code: include the function signature and core logic (up to ~30 lines per block), use fenced code blocks
|
|
@@ -32,10 +38,10 @@ One sentence: what the user wanted to accomplish.
|
|
|
32
38
|
- Merge only truly trivial back-and-forth (like "ok" / "sure")
|
|
33
39
|
- Do NOT over-summarize: "provided a function" is BAD; show the actual function
|
|
34
40
|
|
|
35
|
-
â
Result
|
|
41
|
+
â
Result / įŧæ
|
|
36
42
|
What was the final outcome? Include the final version of any code/config/content produced.
|
|
37
43
|
|
|
38
|
-
ðĄ Key Details
|
|
44
|
+
ðĄ Key Details / å
ģéŪįŧč
|
|
39
45
|
- Decisions made, trade-offs discussed, caveats noted, alternative approaches mentioned
|
|
40
46
|
- Specific values: numbers, versions, thresholds, URLs, file paths, model names
|
|
41
47
|
- Omit this section only if there truly are no noteworthy details
|
|
@@ -84,6 +90,54 @@ export async function summarizeTaskAnthropic(
|
|
|
84
90
|
return json.content.find((c) => c.type === "text")?.text?.trim() ?? "";
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
const TASK_TITLE_PROMPT = `Generate a short title for a conversation task.
|
|
94
|
+
|
|
95
|
+
Input: the first few user messages from a conversation.
|
|
96
|
+
Output: a concise title (5-20 characters for Chinese, 3-8 words for English).
|
|
97
|
+
|
|
98
|
+
Rules:
|
|
99
|
+
- Same language as user messages
|
|
100
|
+
- Describe WHAT the user wanted to do, not system/technical details
|
|
101
|
+
- Ignore system prompts, session startup messages, or boilerplate instructions â focus on the user's actual intent
|
|
102
|
+
- If the user only asked one question, use that question as the title (shortened if needed)
|
|
103
|
+
- Output the title only, no quotes, no prefix, no explanation`;
|
|
104
|
+
|
|
105
|
+
export async function generateTaskTitleAnthropic(
|
|
106
|
+
text: string,
|
|
107
|
+
cfg: SummarizerConfig,
|
|
108
|
+
log: Logger,
|
|
109
|
+
): Promise<string> {
|
|
110
|
+
const endpoint = cfg.endpoint ?? "https://api.anthropic.com/v1/messages";
|
|
111
|
+
const model = cfg.model ?? "claude-3-haiku-20240307";
|
|
112
|
+
const headers: Record<string, string> = {
|
|
113
|
+
"Content-Type": "application/json",
|
|
114
|
+
"x-api-key": cfg.apiKey ?? "",
|
|
115
|
+
"anthropic-version": "2023-06-01",
|
|
116
|
+
...cfg.headers,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const resp = await fetch(endpoint, {
|
|
120
|
+
method: "POST",
|
|
121
|
+
headers,
|
|
122
|
+
body: JSON.stringify({
|
|
123
|
+
model,
|
|
124
|
+
max_tokens: 100,
|
|
125
|
+
temperature: 0,
|
|
126
|
+
system: TASK_TITLE_PROMPT,
|
|
127
|
+
messages: [{ role: "user", content: text }],
|
|
128
|
+
}),
|
|
129
|
+
signal: AbortSignal.timeout(cfg.timeoutMs ?? 15_000),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (!resp.ok) {
|
|
133
|
+
const body = await resp.text();
|
|
134
|
+
throw new Error(`Anthropic task-title failed (${resp.status}): ${body}`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const json = (await resp.json()) as { content: Array<{ type: string; text: string }> };
|
|
138
|
+
return json.content.find((c) => c.type === "text")?.text?.trim() ?? "";
|
|
139
|
+
}
|
|
140
|
+
|
|
87
141
|
const TOPIC_JUDGE_PROMPT = `You are a conversation topic boundary detector. Given the CURRENT task context and a NEW user message, decide if the new message belongs to the SAME task or starts a NEW one.
|
|
88
142
|
|
|
89
143
|
Answer ONLY "NEW" or "SAME".
|
|
@@ -151,39 +205,30 @@ export async function judgeNewTopicAnthropic(
|
|
|
151
205
|
return answer.startsWith("NEW");
|
|
152
206
|
}
|
|
153
207
|
|
|
154
|
-
const FILTER_RELEVANT_PROMPT = `You are a
|
|
155
|
-
|
|
156
|
-
1. Select ONLY candidates that are DIRECTLY relevant to the query's topic.
|
|
157
|
-
- A candidate is relevant ONLY if it shares the same subject/topic as the query.
|
|
158
|
-
- EXCLUDE candidates about unrelated topics, even if they are from the same user.
|
|
159
|
-
- For list/history questions (e.g. "which companies did I work at"), include all MATCHING items.
|
|
160
|
-
- For factual lookups, a single direct answer is enough.
|
|
161
|
-
- When in doubt, EXCLUDE the candidate. Precision is more important than recall.
|
|
162
|
-
2. Judge whether the selected memories are SUFFICIENT to fully answer the query.
|
|
208
|
+
const FILTER_RELEVANT_PROMPT = `You are a memory relevance judge.
|
|
163
209
|
|
|
164
|
-
|
|
165
|
-
- Query: "recipe for braised beef" â ONLY include candidates about cooking/recipes/beef. EXCLUDE candidates about weather, deployment, identity, etc.
|
|
166
|
-
- Query: "ææŊč°" â ONLY include candidates about user identity/name/profile. EXCLUDE candidates about cooking, news, technical issues, etc.
|
|
167
|
-
- Query: "SSH port" â ONLY include candidates mentioning SSH or port configuration.
|
|
210
|
+
Given a QUERY and CANDIDATE memories, decide: does each candidate's content contain information that would HELP ANSWER the query?
|
|
168
211
|
|
|
169
|
-
|
|
170
|
-
-
|
|
171
|
-
-
|
|
212
|
+
CORE QUESTION: "If I include this memory, will it help produce a better answer?"
|
|
213
|
+
- YES â include
|
|
214
|
+
- NO â exclude
|
|
172
215
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
- "sufficient": true ONLY if the memories contain a direct answer; false otherwise.
|
|
216
|
+
RULES:
|
|
217
|
+
1. A candidate is relevant if its content provides facts, context, or data that directly supports answering the query.
|
|
218
|
+
2. A candidate that merely shares the same broad topic/domain but contains NO useful information for answering is NOT relevant.
|
|
219
|
+
3. If NO candidate can help answer the query, return {"relevant":[],"sufficient":false} â do NOT force-pick the "least irrelevant" one.
|
|
178
220
|
|
|
179
|
-
|
|
221
|
+
OUTPUT â JSON only:
|
|
222
|
+
{"relevant":[1,3],"sufficient":true}
|
|
223
|
+
- "relevant": candidate numbers whose content helps answer the query. [] if none can help.
|
|
224
|
+
- "sufficient": true only if the selected memories fully answer the query.`;
|
|
180
225
|
|
|
181
226
|
import type { FilterResult } from "./openai";
|
|
182
227
|
export type { FilterResult } from "./openai";
|
|
183
228
|
|
|
184
229
|
export async function filterRelevantAnthropic(
|
|
185
230
|
query: string,
|
|
186
|
-
candidates: Array<{ index: number;
|
|
231
|
+
candidates: Array<{ index: number; role: string; content: string; time?: string }>,
|
|
187
232
|
cfg: SummarizerConfig,
|
|
188
233
|
log: Logger,
|
|
189
234
|
): Promise<FilterResult> {
|
|
@@ -197,7 +242,10 @@ export async function filterRelevantAnthropic(
|
|
|
197
242
|
};
|
|
198
243
|
|
|
199
244
|
const candidateText = candidates
|
|
200
|
-
.map((c) =>
|
|
245
|
+
.map((c) => {
|
|
246
|
+
const timeTag = c.time ? ` (${c.time})` : "";
|
|
247
|
+
return `${c.index}. [${c.role}]${timeTag}\n ${c.content}`;
|
|
248
|
+
})
|
|
201
249
|
.join("\n");
|
|
202
250
|
|
|
203
251
|
const resp = await fetch(endpoint, {
|
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
import type { SummarizerConfig, Logger } from "../../types";
|
|
2
2
|
|
|
3
|
-
const SYSTEM_PROMPT = `You
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
3
|
+
const SYSTEM_PROMPT = `You generate a retrieval-friendly title.
|
|
4
|
+
|
|
5
|
+
Return exactly one noun phrase that names the topic AND its key details.
|
|
6
|
+
|
|
7
|
+
Requirements:
|
|
8
|
+
- Same language as input
|
|
9
|
+
- Keep proper nouns, API/function names, specific parameters, versions, error codes
|
|
10
|
+
- Include WHO/WHAT/WHERE details when present (e.g. person name + event, tool name + what it does)
|
|
11
|
+
- Prefer concrete topic words over generic words
|
|
12
|
+
- No verbs unless unavoidable
|
|
13
|
+
- No generic endings like:
|
|
14
|
+
åč―čŊīæãä―ŋįĻčŊīæãįŪäŧãäŧįŧãįĻéãsummaryãoverviewãbasics
|
|
15
|
+
- Chinese: 10-50 characters (aim for 15-30)
|
|
16
|
+
- Non-Chinese: 5-15 words (aim for 8-12)
|
|
17
|
+
- Output title only`;
|
|
13
18
|
|
|
14
19
|
const TASK_SUMMARY_PROMPT = `You create a DETAILED task summary from a multi-turn conversation. This summary will be the ONLY record of this conversation, so it must preserve ALL important information.
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
## LANGUAGE RULE (HIGHEST PRIORITY)
|
|
22
|
+
Detect the PRIMARY language of the user's messages. If most user messages are Chinese, ALL output (title, goal, steps, result, details) MUST be in Chinese. If English, output in English. NEVER mix. This rule overrides everything below.
|
|
17
23
|
|
|
18
24
|
Output EXACTLY this structure:
|
|
19
25
|
|
|
20
|
-
ð Title
|
|
21
|
-
A short, descriptive title (10-30 characters).
|
|
26
|
+
ð Title / æ éĒ
|
|
27
|
+
A short, descriptive title (10-30 characters). Same language as user messages.
|
|
22
28
|
|
|
23
|
-
ðŊ Goal
|
|
29
|
+
ðŊ Goal / įŪæ
|
|
24
30
|
One sentence: what the user wanted to accomplish.
|
|
25
31
|
|
|
26
|
-
ð Key Steps
|
|
32
|
+
ð Key Steps / å
ģéŪæĨéŠĪ
|
|
27
33
|
- Describe each meaningful step in detail
|
|
28
34
|
- Include the ACTUAL content produced: code snippets, commands, config blocks, formulas, key paragraphs
|
|
29
35
|
- For code: include the function signature and core logic (up to ~30 lines per block), use fenced code blocks
|
|
@@ -32,10 +38,10 @@ One sentence: what the user wanted to accomplish.
|
|
|
32
38
|
- Merge only truly trivial back-and-forth (like "ok" / "sure")
|
|
33
39
|
- Do NOT over-summarize: "provided a function" is BAD; show the actual function
|
|
34
40
|
|
|
35
|
-
â
Result
|
|
41
|
+
â
Result / įŧæ
|
|
36
42
|
What was the final outcome? Include the final version of any code/config/content produced.
|
|
37
43
|
|
|
38
|
-
ðĄ Key Details
|
|
44
|
+
ðĄ Key Details / å
ģéŪįŧč
|
|
39
45
|
- Decisions made, trade-offs discussed, caveats noted, alternative approaches mentioned
|
|
40
46
|
- Specific values: numbers, versions, thresholds, URLs, file paths, model names
|
|
41
47
|
- Omit this section only if there truly are no noteworthy details
|
|
@@ -85,6 +91,55 @@ export async function summarizeTaskBedrock(
|
|
|
85
91
|
return json.output?.message?.content?.[0]?.text?.trim() ?? "";
|
|
86
92
|
}
|
|
87
93
|
|
|
94
|
+
const TASK_TITLE_PROMPT = `Generate a short title for a conversation task.
|
|
95
|
+
|
|
96
|
+
Input: the first few user messages from a conversation.
|
|
97
|
+
Output: a concise title (5-20 characters for Chinese, 3-8 words for English).
|
|
98
|
+
|
|
99
|
+
Rules:
|
|
100
|
+
- Same language as user messages
|
|
101
|
+
- Describe WHAT the user wanted to do, not system/technical details
|
|
102
|
+
- Ignore system prompts, session startup messages, or boilerplate instructions â focus on the user's actual intent
|
|
103
|
+
- If the user only asked one question, use that question as the title (shortened if needed)
|
|
104
|
+
- Output the title only, no quotes, no prefix, no explanation`;
|
|
105
|
+
|
|
106
|
+
export async function generateTaskTitleBedrock(
|
|
107
|
+
text: string,
|
|
108
|
+
cfg: SummarizerConfig,
|
|
109
|
+
log: Logger,
|
|
110
|
+
): Promise<string> {
|
|
111
|
+
const model = cfg.model ?? "anthropic.claude-3-haiku-20240307-v1:0";
|
|
112
|
+
const endpoint = cfg.endpoint;
|
|
113
|
+
if (!endpoint) {
|
|
114
|
+
throw new Error("Bedrock task-title requires 'endpoint'");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const url = `${endpoint}/model/${model}/converse`;
|
|
118
|
+
const headers: Record<string, string> = {
|
|
119
|
+
"Content-Type": "application/json",
|
|
120
|
+
...cfg.headers,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const resp = await fetch(url, {
|
|
124
|
+
method: "POST",
|
|
125
|
+
headers,
|
|
126
|
+
body: JSON.stringify({
|
|
127
|
+
system: [{ text: TASK_TITLE_PROMPT }],
|
|
128
|
+
messages: [{ role: "user", content: [{ text }] }],
|
|
129
|
+
inferenceConfig: { temperature: 0, maxTokens: 100 },
|
|
130
|
+
}),
|
|
131
|
+
signal: AbortSignal.timeout(cfg.timeoutMs ?? 15_000),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
if (!resp.ok) {
|
|
135
|
+
const body = await resp.text();
|
|
136
|
+
throw new Error(`Bedrock task-title failed (${resp.status}): ${body}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const json = (await resp.json()) as { output: { message: { content: Array<{ text: string }> } } };
|
|
140
|
+
return json.output?.message?.content?.[0]?.text?.trim() ?? "";
|
|
141
|
+
}
|
|
142
|
+
|
|
88
143
|
const TOPIC_JUDGE_PROMPT = `You are a conversation topic boundary detector. Given the CURRENT task context and a NEW user message, decide if the new message belongs to the SAME task or starts a NEW one.
|
|
89
144
|
|
|
90
145
|
Answer ONLY "NEW" or "SAME".
|
|
@@ -153,39 +208,30 @@ export async function judgeNewTopicBedrock(
|
|
|
153
208
|
return answer.startsWith("NEW");
|
|
154
209
|
}
|
|
155
210
|
|
|
156
|
-
const FILTER_RELEVANT_PROMPT = `You are a
|
|
157
|
-
|
|
158
|
-
1. Select ONLY candidates that are DIRECTLY relevant to the query's topic.
|
|
159
|
-
- A candidate is relevant ONLY if it shares the same subject/topic as the query.
|
|
160
|
-
- EXCLUDE candidates about unrelated topics, even if they are from the same user.
|
|
161
|
-
- For list/history questions (e.g. "which companies did I work at"), include all MATCHING items.
|
|
162
|
-
- For factual lookups, a single direct answer is enough.
|
|
163
|
-
- When in doubt, EXCLUDE the candidate. Precision is more important than recall.
|
|
164
|
-
2. Judge whether the selected memories are SUFFICIENT to fully answer the query.
|
|
211
|
+
const FILTER_RELEVANT_PROMPT = `You are a memory relevance judge.
|
|
165
212
|
|
|
166
|
-
|
|
167
|
-
- Query: "recipe for braised beef" â ONLY include candidates about cooking/recipes/beef. EXCLUDE candidates about weather, deployment, identity, etc.
|
|
168
|
-
- Query: "ææŊč°" â ONLY include candidates about user identity/name/profile. EXCLUDE candidates about cooking, news, technical issues, etc.
|
|
169
|
-
- Query: "SSH port" â ONLY include candidates mentioning SSH or port configuration.
|
|
213
|
+
Given a QUERY and CANDIDATE memories, decide: does each candidate's content contain information that would HELP ANSWER the query?
|
|
170
214
|
|
|
171
|
-
|
|
172
|
-
-
|
|
173
|
-
-
|
|
215
|
+
CORE QUESTION: "If I include this memory, will it help produce a better answer?"
|
|
216
|
+
- YES â include
|
|
217
|
+
- NO â exclude
|
|
174
218
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
- "sufficient": true ONLY if the memories contain a direct answer; false otherwise.
|
|
219
|
+
RULES:
|
|
220
|
+
1. A candidate is relevant if its content provides facts, context, or data that directly supports answering the query.
|
|
221
|
+
2. A candidate that merely shares the same broad topic/domain but contains NO useful information for answering is NOT relevant.
|
|
222
|
+
3. If NO candidate can help answer the query, return {"relevant":[],"sufficient":false} â do NOT force-pick the "least irrelevant" one.
|
|
180
223
|
|
|
181
|
-
|
|
224
|
+
OUTPUT â JSON only:
|
|
225
|
+
{"relevant":[1,3],"sufficient":true}
|
|
226
|
+
- "relevant": candidate numbers whose content helps answer the query. [] if none can help.
|
|
227
|
+
- "sufficient": true only if the selected memories fully answer the query.`;
|
|
182
228
|
|
|
183
229
|
import type { FilterResult } from "./openai";
|
|
184
230
|
export type { FilterResult } from "./openai";
|
|
185
231
|
|
|
186
232
|
export async function filterRelevantBedrock(
|
|
187
233
|
query: string,
|
|
188
|
-
candidates: Array<{ index: number;
|
|
234
|
+
candidates: Array<{ index: number; role: string; content: string; time?: string }>,
|
|
189
235
|
cfg: SummarizerConfig,
|
|
190
236
|
log: Logger,
|
|
191
237
|
): Promise<FilterResult> {
|
|
@@ -202,7 +248,10 @@ export async function filterRelevantBedrock(
|
|
|
202
248
|
};
|
|
203
249
|
|
|
204
250
|
const candidateText = candidates
|
|
205
|
-
.map((c) =>
|
|
251
|
+
.map((c) => {
|
|
252
|
+
const timeTag = c.time ? ` (${c.time})` : "";
|
|
253
|
+
return `${c.index}. [${c.role}]${timeTag}\n ${c.content}`;
|
|
254
|
+
})
|
|
206
255
|
.join("\n");
|
|
207
256
|
|
|
208
257
|
const resp = await fetch(url, {
|
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
import type { SummarizerConfig, Logger } from "../../types";
|
|
2
2
|
|
|
3
|
-
const SYSTEM_PROMPT = `You
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
3
|
+
const SYSTEM_PROMPT = `You generate a retrieval-friendly title.
|
|
4
|
+
|
|
5
|
+
Return exactly one noun phrase that names the topic AND its key details.
|
|
6
|
+
|
|
7
|
+
Requirements:
|
|
8
|
+
- Same language as input
|
|
9
|
+
- Keep proper nouns, API/function names, specific parameters, versions, error codes
|
|
10
|
+
- Include WHO/WHAT/WHERE details when present (e.g. person name + event, tool name + what it does)
|
|
11
|
+
- Prefer concrete topic words over generic words
|
|
12
|
+
- No verbs unless unavoidable
|
|
13
|
+
- No generic endings like:
|
|
14
|
+
åč―čŊīæãä―ŋįĻčŊīæãįŪäŧãäŧįŧãįĻéãsummaryãoverviewãbasics
|
|
15
|
+
- Chinese: 10-50 characters (aim for 15-30)
|
|
16
|
+
- Non-Chinese: 5-15 words (aim for 8-12)
|
|
17
|
+
- Output title only`;
|
|
13
18
|
|
|
14
19
|
const TASK_SUMMARY_PROMPT = `You create a DETAILED task summary from a multi-turn conversation. This summary will be the ONLY record of this conversation, so it must preserve ALL important information.
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
## LANGUAGE RULE (HIGHEST PRIORITY)
|
|
22
|
+
Detect the PRIMARY language of the user's messages. If most user messages are Chinese, ALL output (title, goal, steps, result, details) MUST be in Chinese. If English, output in English. NEVER mix. This rule overrides everything below.
|
|
17
23
|
|
|
18
24
|
Output EXACTLY this structure:
|
|
19
25
|
|
|
20
|
-
ð Title
|
|
21
|
-
A short, descriptive title (10-30 characters).
|
|
26
|
+
ð Title / æ éĒ
|
|
27
|
+
A short, descriptive title (10-30 characters). Same language as user messages.
|
|
22
28
|
|
|
23
|
-
ðŊ Goal
|
|
29
|
+
ðŊ Goal / įŪæ
|
|
24
30
|
One sentence: what the user wanted to accomplish.
|
|
25
31
|
|
|
26
|
-
ð Key Steps
|
|
32
|
+
ð Key Steps / å
ģéŪæĨéŠĪ
|
|
27
33
|
- Describe each meaningful step in detail
|
|
28
34
|
- Include the ACTUAL content produced: code snippets, commands, config blocks, formulas, key paragraphs
|
|
29
35
|
- For code: include the function signature and core logic (up to ~30 lines per block), use fenced code blocks
|
|
@@ -32,10 +38,10 @@ One sentence: what the user wanted to accomplish.
|
|
|
32
38
|
- Merge only truly trivial back-and-forth (like "ok" / "sure")
|
|
33
39
|
- Do NOT over-summarize: "provided a function" is BAD; show the actual function
|
|
34
40
|
|
|
35
|
-
â
Result
|
|
41
|
+
â
Result / įŧæ
|
|
36
42
|
What was the final outcome? Include the final version of any code/config/content produced.
|
|
37
43
|
|
|
38
|
-
ðĄ Key Details
|
|
44
|
+
ðĄ Key Details / å
ģéŪįŧč
|
|
39
45
|
- Decisions made, trade-offs discussed, caveats noted, alternative approaches mentioned
|
|
40
46
|
- Specific values: numbers, versions, thresholds, URLs, file paths, model names
|
|
41
47
|
- Omit this section only if there truly are no noteworthy details
|
|
@@ -84,6 +90,54 @@ export async function summarizeTaskGemini(
|
|
|
84
90
|
return json.candidates?.[0]?.content?.parts?.[0]?.text?.trim() ?? "";
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
const TASK_TITLE_PROMPT = `Generate a short title for a conversation task.
|
|
94
|
+
|
|
95
|
+
Input: the first few user messages from a conversation.
|
|
96
|
+
Output: a concise title (5-20 characters for Chinese, 3-8 words for English).
|
|
97
|
+
|
|
98
|
+
Rules:
|
|
99
|
+
- Same language as user messages
|
|
100
|
+
- Describe WHAT the user wanted to do, not system/technical details
|
|
101
|
+
- Ignore system prompts, session startup messages, or boilerplate instructions â focus on the user's actual intent
|
|
102
|
+
- If the user only asked one question, use that question as the title (shortened if needed)
|
|
103
|
+
- Output the title only, no quotes, no prefix, no explanation`;
|
|
104
|
+
|
|
105
|
+
export async function generateTaskTitleGemini(
|
|
106
|
+
text: string,
|
|
107
|
+
cfg: SummarizerConfig,
|
|
108
|
+
log: Logger,
|
|
109
|
+
): Promise<string> {
|
|
110
|
+
const model = cfg.model ?? "gemini-1.5-flash";
|
|
111
|
+
const endpoint =
|
|
112
|
+
cfg.endpoint ??
|
|
113
|
+
`https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`;
|
|
114
|
+
|
|
115
|
+
const url = `${endpoint}?key=${cfg.apiKey}`;
|
|
116
|
+
const headers: Record<string, string> = {
|
|
117
|
+
"Content-Type": "application/json",
|
|
118
|
+
...cfg.headers,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const resp = await fetch(url, {
|
|
122
|
+
method: "POST",
|
|
123
|
+
headers,
|
|
124
|
+
body: JSON.stringify({
|
|
125
|
+
systemInstruction: { parts: [{ text: TASK_TITLE_PROMPT }] },
|
|
126
|
+
contents: [{ parts: [{ text }] }],
|
|
127
|
+
generationConfig: { temperature: 0, maxOutputTokens: 100 },
|
|
128
|
+
}),
|
|
129
|
+
signal: AbortSignal.timeout(cfg.timeoutMs ?? 15_000),
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (!resp.ok) {
|
|
133
|
+
const body = await resp.text();
|
|
134
|
+
throw new Error(`Gemini task-title failed (${resp.status}): ${body}`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const json = (await resp.json()) as { candidates: Array<{ content: { parts: Array<{ text: string }> } }> };
|
|
138
|
+
return json.candidates?.[0]?.content?.parts?.[0]?.text?.trim() ?? "";
|
|
139
|
+
}
|
|
140
|
+
|
|
87
141
|
const TOPIC_JUDGE_PROMPT = `You are a conversation topic boundary detector. Given the CURRENT task context and a NEW user message, decide if the new message belongs to the SAME task or starts a NEW one.
|
|
88
142
|
|
|
89
143
|
Answer ONLY "NEW" or "SAME".
|
|
@@ -151,39 +205,30 @@ export async function judgeNewTopicGemini(
|
|
|
151
205
|
return answer.startsWith("NEW");
|
|
152
206
|
}
|
|
153
207
|
|
|
154
|
-
const FILTER_RELEVANT_PROMPT = `You are a
|
|
155
|
-
|
|
156
|
-
1. Select ONLY candidates that are DIRECTLY relevant to the query's topic.
|
|
157
|
-
- A candidate is relevant ONLY if it shares the same subject/topic as the query.
|
|
158
|
-
- EXCLUDE candidates about unrelated topics, even if they are from the same user.
|
|
159
|
-
- For list/history questions (e.g. "which companies did I work at"), include all MATCHING items.
|
|
160
|
-
- For factual lookups, a single direct answer is enough.
|
|
161
|
-
- When in doubt, EXCLUDE the candidate. Precision is more important than recall.
|
|
162
|
-
2. Judge whether the selected memories are SUFFICIENT to fully answer the query.
|
|
208
|
+
const FILTER_RELEVANT_PROMPT = `You are a memory relevance judge.
|
|
163
209
|
|
|
164
|
-
|
|
165
|
-
- Query: "recipe for braised beef" â ONLY include candidates about cooking/recipes/beef. EXCLUDE candidates about weather, deployment, identity, etc.
|
|
166
|
-
- Query: "ææŊč°" â ONLY include candidates about user identity/name/profile. EXCLUDE candidates about cooking, news, technical issues, etc.
|
|
167
|
-
- Query: "SSH port" â ONLY include candidates mentioning SSH or port configuration.
|
|
210
|
+
Given a QUERY and CANDIDATE memories, decide: does each candidate's content contain information that would HELP ANSWER the query?
|
|
168
211
|
|
|
169
|
-
|
|
170
|
-
-
|
|
171
|
-
-
|
|
212
|
+
CORE QUESTION: "If I include this memory, will it help produce a better answer?"
|
|
213
|
+
- YES â include
|
|
214
|
+
- NO â exclude
|
|
172
215
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
- "sufficient": true ONLY if the memories contain a direct answer; false otherwise.
|
|
216
|
+
RULES:
|
|
217
|
+
1. A candidate is relevant if its content provides facts, context, or data that directly supports answering the query.
|
|
218
|
+
2. A candidate that merely shares the same broad topic/domain but contains NO useful information for answering is NOT relevant.
|
|
219
|
+
3. If NO candidate can help answer the query, return {"relevant":[],"sufficient":false} â do NOT force-pick the "least irrelevant" one.
|
|
178
220
|
|
|
179
|
-
|
|
221
|
+
OUTPUT â JSON only:
|
|
222
|
+
{"relevant":[1,3],"sufficient":true}
|
|
223
|
+
- "relevant": candidate numbers whose content helps answer the query. [] if none can help.
|
|
224
|
+
- "sufficient": true only if the selected memories fully answer the query.`;
|
|
180
225
|
|
|
181
226
|
import type { FilterResult } from "./openai";
|
|
182
227
|
export type { FilterResult } from "./openai";
|
|
183
228
|
|
|
184
229
|
export async function filterRelevantGemini(
|
|
185
230
|
query: string,
|
|
186
|
-
candidates: Array<{ index: number;
|
|
231
|
+
candidates: Array<{ index: number; role: string; content: string; time?: string }>,
|
|
187
232
|
cfg: SummarizerConfig,
|
|
188
233
|
log: Logger,
|
|
189
234
|
): Promise<FilterResult> {
|
|
@@ -199,7 +244,10 @@ export async function filterRelevantGemini(
|
|
|
199
244
|
};
|
|
200
245
|
|
|
201
246
|
const candidateText = candidates
|
|
202
|
-
.map((c) =>
|
|
247
|
+
.map((c) => {
|
|
248
|
+
const timeTag = c.time ? ` (${c.time})` : "";
|
|
249
|
+
return `${c.index}. [${c.role}]${timeTag}\n ${c.content}`;
|
|
250
|
+
})
|
|
203
251
|
.join("\n");
|
|
204
252
|
|
|
205
253
|
const resp = await fetch(url, {
|