qlogicagent 0.2.1 → 0.3.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/dist/agent.js +1 -0
- package/dist/cli.js +9 -0
- package/dist/contracts.js +1 -0
- package/dist/index.js +5 -15
- package/dist/orchestration.js +118 -0
- package/package.json +56 -42
- package/dist/agent/agent.js +0 -113
- package/dist/agent/tool-loop.js +0 -575
- package/dist/agent/types.js +0 -14
- package/dist/cli/main.js +0 -23
- package/dist/cli/stdio-server.js +0 -463
- package/dist/config/config.js +0 -21
- package/dist/contracts/hooks.js +0 -7
- package/dist/contracts/index.js +0 -10
- package/dist/contracts/planner.js +0 -2
- package/dist/contracts/skill-candidate.js +0 -195
- package/dist/contracts/todo.js +0 -9
- package/dist/llm/builtin-providers.js +0 -531
- package/dist/llm/index.js +0 -14
- package/dist/llm/llm-client.js +0 -67
- package/dist/llm/model-catalog.js +0 -191
- package/dist/llm/provider-def.js +0 -12
- package/dist/llm/provider-registry.js +0 -147
- package/dist/llm/transport.js +0 -27
- package/dist/llm/transports/anthropic-messages.js +0 -293
- package/dist/llm/transports/openai-chat.js +0 -165
- package/dist/orchestration/agent-registry.js +0 -116
- package/dist/orchestration/approval-aware-tool-plan.js +0 -87
- package/dist/orchestration/context-compression.js +0 -583
- package/dist/orchestration/conversation-repair.js +0 -429
- package/dist/orchestration/curator-scheduler.js +0 -135
- package/dist/orchestration/embedded-failover-policy.js +0 -168
- package/dist/orchestration/error-classification.js +0 -77
- package/dist/orchestration/failover-classification.js +0 -381
- package/dist/orchestration/failover-error.js +0 -198
- package/dist/orchestration/fork-subagent.js +0 -98
- package/dist/orchestration/index.js +0 -267
- package/dist/orchestration/memory-flush-policy.js +0 -85
- package/dist/orchestration/memory-provider.js +0 -2
- package/dist/orchestration/parallel-tool-calls.js +0 -59
- package/dist/orchestration/prompt-cache-strategy.js +0 -228
- package/dist/orchestration/reactive-compact.js +0 -78
- package/dist/orchestration/retry-loop.js +0 -24
- package/dist/orchestration/skill-candidate.js +0 -141
- package/dist/orchestration/skill-consolidation.js +0 -220
- package/dist/orchestration/skill-improvement.js +0 -66
- package/dist/orchestration/skill-similarity.js +0 -131
- package/dist/orchestration/streaming-tool-executor.js +0 -96
- package/dist/orchestration/team-orchestration.js +0 -369
- package/dist/orchestration/team-tool-loop-wiring.js +0 -147
- package/dist/orchestration/tool-choice-policy.js +0 -164
- package/dist/orchestration/tool-loop-state.js +0 -133
- package/dist/orchestration/tool-schema.js +0 -297
- package/dist/orchestration/transcript-repair.js +0 -426
- package/dist/orchestration/turn-loop-guard.js +0 -92
- package/dist/orchestration/web-browser-policy.js +0 -39
- package/dist/runtime/context-compression.js +0 -274
- package/dist/runtime/hook-registry.js +0 -53
- package/dist/runtime/memory-hooks.js +0 -65
- package/dist/runtime/tool-eligibility.js +0 -111
- package/dist/skills/index.js +0 -82
- package/dist/skills/memory-extractor.js +0 -173
- package/dist/skills/memory-query-tool.js +0 -127
- package/dist/skills/memory-store.js +0 -228
- package/dist/skills/memory-tool.js +0 -192
- package/dist/skills/portable-tool.js +0 -14
- package/dist/skills/qmemory-adapter.js +0 -165
- package/dist/skills/skill-frontmatter.js +0 -344
- package/dist/skills/skill-guard.js +0 -229
- package/dist/skills/skill-loader.js +0 -303
- package/dist/skills/skill-source.js +0 -126
- package/dist/skills/skill-types.js +0 -6
- package/dist/skills/think-tool.js +0 -59
- package/dist/skills/todo-tool.js +0 -114
- package/dist/skills/tools/agent-tool.js +0 -142
- package/dist/skills/tools/apply-patch-tool.js +0 -184
- package/dist/skills/tools/ask-user-tool.js +0 -121
- package/dist/skills/tools/brief-tool.js +0 -95
- package/dist/skills/tools/browser-tool.js +0 -155
- package/dist/skills/tools/checkpoint-tool.js +0 -102
- package/dist/skills/tools/config-tool.js +0 -143
- package/dist/skills/tools/cron-tool.js +0 -175
- package/dist/skills/tools/edit-tool.js +0 -70
- package/dist/skills/tools/exec-tool.js +0 -133
- package/dist/skills/tools/image-generate-tool.js +0 -67
- package/dist/skills/tools/instructions-tool.js +0 -187
- package/dist/skills/tools/lsp-tool.js +0 -227
- package/dist/skills/tools/mcp-client-types.js +0 -53
- package/dist/skills/tools/mcp-tool.js +0 -503
- package/dist/skills/tools/memory-tool.js +0 -88
- package/dist/skills/tools/monitor-tool.js +0 -131
- package/dist/skills/tools/music-generate-tool.js +0 -62
- package/dist/skills/tools/notify-tool.js +0 -62
- package/dist/skills/tools/patch-tool.js +0 -505
- package/dist/skills/tools/pdf-tool.js +0 -88
- package/dist/skills/tools/plan-mode-tool.js +0 -122
- package/dist/skills/tools/read-tool.js +0 -84
- package/dist/skills/tools/repl-tool.js +0 -69
- package/dist/skills/tools/search-tool.js +0 -225
- package/dist/skills/tools/send-message-tool.js +0 -76
- package/dist/skills/tools/skill-list-tool.js +0 -54
- package/dist/skills/tools/skill-manage-tool.js +0 -153
- package/dist/skills/tools/skill-view-tool.js +0 -72
- package/dist/skills/tools/sleep-tool.js +0 -81
- package/dist/skills/tools/structured-output-tool.js +0 -176
- package/dist/skills/tools/task-tool.js +0 -161
- package/dist/skills/tools/team-tool.js +0 -105
- package/dist/skills/tools/tool-search-tool.js +0 -110
- package/dist/skills/tools/tts-tool.js +0 -45
- package/dist/skills/tools/video-edit-tool.js +0 -74
- package/dist/skills/tools/video-generate-tool.js +0 -66
- package/dist/skills/tools/video-merge-tool.js +0 -92
- package/dist/skills/tools/video-upscale-tool.js +0 -52
- package/dist/skills/tools/web-fetch-tool.js +0 -92
- package/dist/skills/tools/web-search-tool.js +0 -86
- package/dist/skills/tools/worktree-tool.js +0 -147
- package/dist/skills/tools/write-tool.js +0 -81
- /package/dist/{agent → types/agent}/agent.d.ts +0 -0
- /package/dist/{agent → types/agent}/tool-loop.d.ts +0 -0
- /package/dist/{agent → types/agent}/types.d.ts +0 -0
- /package/dist/{cli → types/cli}/main.d.ts +0 -0
- /package/dist/{cli → types/cli}/stdio-server.d.ts +0 -0
- /package/dist/{config → types/config}/config.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/hooks.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/index.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/planner.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/skill-candidate.d.ts +0 -0
- /package/dist/{contracts → types/contracts}/todo.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{llm → types/llm}/builtin-providers.d.ts +0 -0
- /package/dist/{llm → types/llm}/index.d.ts +0 -0
- /package/dist/{llm → types/llm}/llm-client.d.ts +0 -0
- /package/dist/{llm → types/llm}/model-catalog.d.ts +0 -0
- /package/dist/{llm → types/llm}/provider-def.d.ts +0 -0
- /package/dist/{llm → types/llm}/provider-registry.d.ts +0 -0
- /package/dist/{llm → types/llm}/transport.d.ts +0 -0
- /package/dist/{llm → types/llm}/transports/anthropic-messages.d.ts +0 -0
- /package/dist/{llm → types/llm}/transports/openai-chat.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/agent-registry.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/approval-aware-tool-plan.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/context-compression.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/conversation-repair.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/curator-scheduler.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/embedded-failover-policy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/error-classification.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/failover-classification.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/failover-error.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/fork-subagent.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/index.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/memory-flush-policy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/memory-provider.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/parallel-tool-calls.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/prompt-cache-strategy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/reactive-compact.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/retry-loop.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-candidate.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-consolidation.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-improvement.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/skill-similarity.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/streaming-tool-executor.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/team-orchestration.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/team-tool-loop-wiring.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/tool-choice-policy.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/tool-loop-state.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/tool-schema.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/transcript-repair.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/turn-loop-guard.d.ts +0 -0
- /package/dist/{orchestration → types/orchestration}/web-browser-policy.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/context-compression.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/hook-registry.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/memory-hooks.d.ts +0 -0
- /package/dist/{runtime → types/runtime}/tool-eligibility.d.ts +0 -0
- /package/dist/{skills → types/skills}/index.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-extractor.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-query-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-store.d.ts +0 -0
- /package/dist/{skills → types/skills}/memory-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/portable-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/qmemory-adapter.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-frontmatter.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-guard.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-loader.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-source.d.ts +0 -0
- /package/dist/{skills → types/skills}/skill-types.d.ts +0 -0
- /package/dist/{skills → types/skills}/think-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/todo-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/agent-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/apply-patch-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/ask-user-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/brief-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/browser-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/checkpoint-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/config-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/cron-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/edit-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/exec-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/image-generate-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/instructions-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/lsp-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/mcp-client-types.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/mcp-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/memory-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/monitor-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/music-generate-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/notify-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/patch-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/pdf-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/plan-mode-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/read-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/repl-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/search-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/send-message-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/skill-list-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/skill-manage-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/skill-view-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/sleep-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/structured-output-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/task-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/team-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/tool-search-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/tts-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-edit-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-generate-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-merge-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/video-upscale-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/web-fetch-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/web-search-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/worktree-tool.d.ts +0 -0
- /package/dist/{skills → types/skills}/tools/write-tool.d.ts +0 -0
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// Memory Tool Contract — dual-layer agent memory system.
|
|
3
|
-
//
|
|
4
|
-
// Two independent layers (Hermes-inspired):
|
|
5
|
-
//
|
|
6
|
-
// 1. **MD Memory** (local notes, always in system prompt):
|
|
7
|
-
// Agent explicitly manages via add / replace / remove.
|
|
8
|
-
// Character-bounded, no LLM needed, zero-cost.
|
|
9
|
-
// Frozen snapshot in system prompt for KV cache stability.
|
|
10
|
-
//
|
|
11
|
-
// 2. **QMemory** (semantic long-term memory):
|
|
12
|
-
// Automatic extraction from every conversation turn.
|
|
13
|
-
// Agent queries via search action. Vector-based recall.
|
|
14
|
-
//
|
|
15
|
-
// The two layers are independent — no cross-dedup, no sync.
|
|
16
|
-
// MD = curated highlights; QMemory = conversation sediment.
|
|
17
|
-
// ============================================================
|
|
18
|
-
// ── Constants ───────────────────────────────────────────────────
|
|
19
|
-
export const MEMORY_TOOL_NAME = "memory";
|
|
20
|
-
export const MEMORY_TOOL_MAX_CONTENT_LENGTH = 2000;
|
|
21
|
-
export const MEMORY_TOOL_ACTIONS = ["add", "replace", "remove", "search"];
|
|
22
|
-
// ── Tool schema (JSON Schema compatible) ────────────────────
|
|
23
|
-
export const MEMORY_TOOL_SCHEMA = {
|
|
24
|
-
type: "object",
|
|
25
|
-
properties: {
|
|
26
|
-
action: {
|
|
27
|
-
type: "string",
|
|
28
|
-
enum: MEMORY_TOOL_ACTIONS,
|
|
29
|
-
description: [
|
|
30
|
-
"The operation to perform:",
|
|
31
|
-
"• 'add' — Save a concise note about this user (→ local notes, always visible)",
|
|
32
|
-
"• 'replace' — Update an existing note by matching a substring (→ local notes)",
|
|
33
|
-
"• 'remove' — Delete a note by matching a substring (→ local notes)",
|
|
34
|
-
"• 'search' — Semantic search across long-term memory (→ qmemory)",
|
|
35
|
-
].join("\n"),
|
|
36
|
-
},
|
|
37
|
-
target: {
|
|
38
|
-
type: "string",
|
|
39
|
-
enum: ["memory", "user"],
|
|
40
|
-
description: [
|
|
41
|
-
"Which note target to operate on (for add/replace/remove):",
|
|
42
|
-
"• 'memory' — Your personal observations/notes about this user (default)",
|
|
43
|
-
"• 'user' — User profile facts (preferences, timezone, etc.)",
|
|
44
|
-
].join("\n"),
|
|
45
|
-
},
|
|
46
|
-
content: {
|
|
47
|
-
type: "string",
|
|
48
|
-
description: [
|
|
49
|
-
"Required for 'add' and 'replace'. The note content to store.",
|
|
50
|
-
"Write a concise, factual statement.",
|
|
51
|
-
"Good: '用户是后端工程师,主要使用 TypeScript 和 Go'",
|
|
52
|
-
"Good: 'User prefers dark UI themes and minimalist design'",
|
|
53
|
-
"Bad: '用户说了很多话' (too vague)",
|
|
54
|
-
"Bad: entire conversation transcripts (too long)",
|
|
55
|
-
].join("\n"),
|
|
56
|
-
},
|
|
57
|
-
old_text: {
|
|
58
|
-
type: "string",
|
|
59
|
-
description: "Required for 'replace' and 'remove'. A substring that uniquely identifies the note entry to modify.",
|
|
60
|
-
},
|
|
61
|
-
query: {
|
|
62
|
-
type: "string",
|
|
63
|
-
description: "Required for 'search'. Natural language query to find relevant memories.",
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
required: ["action"],
|
|
67
|
-
};
|
|
68
|
-
export const MEMORY_TOOL_DESCRIPTION = [
|
|
69
|
-
"Manage your notes about this user and search long-term memory.",
|
|
70
|
-
"",
|
|
71
|
-
"Your notes (add/replace/remove) are always visible in the system prompt.",
|
|
72
|
-
"Long-term memories are automatically extracted from every conversation",
|
|
73
|
-
"and searchable via 'search'.",
|
|
74
|
-
"",
|
|
75
|
-
"Guidelines:",
|
|
76
|
-
"- Use 'add' to record important user preferences, facts, or context",
|
|
77
|
-
"- Use 'replace' to update outdated notes (match by substring)",
|
|
78
|
-
"- Use 'remove' to delete incorrect notes (match by substring)",
|
|
79
|
-
"- Use 'search' to recall conversation history and past interactions",
|
|
80
|
-
"- Keep notes concise — there's a character limit",
|
|
81
|
-
].join("\n");
|
|
82
|
-
export const MEMORY_TOOL_LABEL = "Memory";
|
|
83
|
-
// ── Content safety ──────────────────────────────────────────
|
|
84
|
-
const BLOCKED_PATTERNS = [
|
|
85
|
-
/ignore\s+(previous|all|above|prior)\s+instructions/i,
|
|
86
|
-
/you\s+are\s+now\s+/i,
|
|
87
|
-
/do\s+not\s+tell\s+the\s+user/i,
|
|
88
|
-
/system\s+prompt\s+override/i,
|
|
89
|
-
];
|
|
90
|
-
export function isMemoryContentSafe(text) {
|
|
91
|
-
return !BLOCKED_PATTERNS.some((pattern) => pattern.test(text));
|
|
92
|
-
}
|
|
93
|
-
export async function executeMemoryTool(params, deps) {
|
|
94
|
-
const { action } = params;
|
|
95
|
-
const target = params.target ?? "memory";
|
|
96
|
-
// ── MD store operations: add / replace / remove ───────
|
|
97
|
-
if (action === "add") {
|
|
98
|
-
if (!deps.store) {
|
|
99
|
-
return { ok: false, message: "Local memory store is not available.", action, errorCode: "no_store" };
|
|
100
|
-
}
|
|
101
|
-
const content = params.content?.trim();
|
|
102
|
-
if (!content) {
|
|
103
|
-
return { ok: false, message: "content is required for 'add' action.", action, errorCode: "empty_content" };
|
|
104
|
-
}
|
|
105
|
-
if (content.length > MEMORY_TOOL_MAX_CONTENT_LENGTH) {
|
|
106
|
-
return { ok: false, message: `Content too long (${content.length} chars, max ${MEMORY_TOOL_MAX_CONTENT_LENGTH}).`, action, errorCode: "too_long" };
|
|
107
|
-
}
|
|
108
|
-
const result = deps.store.add(target, content);
|
|
109
|
-
return {
|
|
110
|
-
ok: result.ok,
|
|
111
|
-
message: result.ok
|
|
112
|
-
? `${result.message} [${result.usage}]`
|
|
113
|
-
: result.message,
|
|
114
|
-
action,
|
|
115
|
-
entryCount: result.entryCount,
|
|
116
|
-
usage: result.usage,
|
|
117
|
-
storeModified: result.ok,
|
|
118
|
-
errorCode: result.errorCode,
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
if (action === "replace") {
|
|
122
|
-
if (!deps.store) {
|
|
123
|
-
return { ok: false, message: "Local memory store is not available.", action, errorCode: "no_store" };
|
|
124
|
-
}
|
|
125
|
-
const oldText = params.old_text?.trim();
|
|
126
|
-
const content = params.content?.trim();
|
|
127
|
-
if (!oldText) {
|
|
128
|
-
return { ok: false, message: "old_text is required for 'replace' action.", action, errorCode: "empty_old_text" };
|
|
129
|
-
}
|
|
130
|
-
if (!content) {
|
|
131
|
-
return { ok: false, message: "content is required for 'replace' action.", action, errorCode: "empty_content" };
|
|
132
|
-
}
|
|
133
|
-
if (content.length > MEMORY_TOOL_MAX_CONTENT_LENGTH) {
|
|
134
|
-
return { ok: false, message: `Content too long (${content.length} chars, max ${MEMORY_TOOL_MAX_CONTENT_LENGTH}).`, action, errorCode: "too_long" };
|
|
135
|
-
}
|
|
136
|
-
const result = deps.store.replace(target, oldText, content);
|
|
137
|
-
return {
|
|
138
|
-
ok: result.ok,
|
|
139
|
-
message: result.ok
|
|
140
|
-
? `${result.message} [${result.usage}]`
|
|
141
|
-
: result.message,
|
|
142
|
-
action,
|
|
143
|
-
entryCount: result.entryCount,
|
|
144
|
-
usage: result.usage,
|
|
145
|
-
storeModified: result.ok,
|
|
146
|
-
errorCode: result.errorCode,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
if (action === "remove") {
|
|
150
|
-
if (!deps.store) {
|
|
151
|
-
return { ok: false, message: "Local memory store is not available.", action, errorCode: "no_store" };
|
|
152
|
-
}
|
|
153
|
-
const oldText = params.old_text?.trim();
|
|
154
|
-
if (!oldText) {
|
|
155
|
-
return { ok: false, message: "old_text is required for 'remove' action.", action, errorCode: "empty_old_text" };
|
|
156
|
-
}
|
|
157
|
-
const result = deps.store.remove(target, oldText);
|
|
158
|
-
return {
|
|
159
|
-
ok: result.ok,
|
|
160
|
-
message: result.ok
|
|
161
|
-
? `${result.message} [${result.usage}]`
|
|
162
|
-
: result.message,
|
|
163
|
-
action,
|
|
164
|
-
entryCount: result.entryCount,
|
|
165
|
-
usage: result.usage,
|
|
166
|
-
storeModified: result.ok,
|
|
167
|
-
errorCode: result.errorCode,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
if (action === "search") {
|
|
171
|
-
const query = params.query?.trim();
|
|
172
|
-
if (!query) {
|
|
173
|
-
return { ok: false, message: "query is required for 'search' action.", action, errorCode: "empty_query" };
|
|
174
|
-
}
|
|
175
|
-
try {
|
|
176
|
-
const results = await deps.provider.search(query, deps.userId, { limit: 10 });
|
|
177
|
-
if (results.length === 0) {
|
|
178
|
-
return { ok: true, message: "No matching memories found.", action, results: [] };
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
ok: true,
|
|
182
|
-
message: results.map((r, i) => `${i + 1}. [${r.blockId}] ${r.text}`).join("\n"),
|
|
183
|
-
action,
|
|
184
|
-
results,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
catch (error) {
|
|
188
|
-
return { ok: false, message: `Search failed: ${error instanceof Error ? error.message : String(error)}`, action, errorCode: "search_failed" };
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return { ok: false, message: `Unknown action: ${action}. Use 'add', 'replace', 'remove', or 'search'.`, action, errorCode: "unknown_action" };
|
|
192
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// Portable Tool Contract — runtime-agnostic tool interface.
|
|
3
|
-
//
|
|
4
|
-
// This is the minimal tool definition that any agent runtime
|
|
5
|
-
// (openclaw, Hub, Electron, third-party) can consume. It uses
|
|
6
|
-
// plain JSON Schema objects instead of @sinclair/typebox so
|
|
7
|
-
// there are zero external dependencies.
|
|
8
|
-
//
|
|
9
|
-
// Consumers wrap PortableTool into their own tool system:
|
|
10
|
-
// - openclaw → AgentTool<TSchema> (via typebox adapter)
|
|
11
|
-
// - Hub → hub-managed tool registration
|
|
12
|
-
// - Electron → desktop tool host
|
|
13
|
-
// ============================================================
|
|
14
|
-
export {};
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// QMemory HTTP adapter — implements MemoryProvider against the
|
|
3
|
-
// QMemory REST API (v1).
|
|
4
|
-
//
|
|
5
|
-
// This is a Hub-ready, provider-agnostic adapter that can be
|
|
6
|
-
// plugged into any consumer of the MemoryProvider contract.
|
|
7
|
-
// ============================================================
|
|
8
|
-
const DEFAULT_TIMEOUT_MS = 5_000;
|
|
9
|
-
const PROVIDER_ID = "qmemory";
|
|
10
|
-
/**
|
|
11
|
-
* Create a MemoryProvider backed by a QMemory HTTP server.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* const provider = createQMemoryAdapter({
|
|
16
|
-
* baseUrl: "http://localhost:18800",
|
|
17
|
-
* apiKey: "sk-...",
|
|
18
|
-
* });
|
|
19
|
-
*
|
|
20
|
-
* const results = await provider.search("last meeting notes", "alice");
|
|
21
|
-
* await provider.ingest([{ role: "user", content: "..." }], "alice");
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export function createQMemoryAdapter(config) {
|
|
25
|
-
const baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
26
|
-
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
27
|
-
function resolveUserId(userId) {
|
|
28
|
-
return config.userIdPrefix ? `${config.userIdPrefix}:${userId}` : userId;
|
|
29
|
-
}
|
|
30
|
-
function buildHeaders() {
|
|
31
|
-
const headers = {
|
|
32
|
-
"Accept": "application/json",
|
|
33
|
-
};
|
|
34
|
-
if (config.apiKey) {
|
|
35
|
-
headers["Authorization"] = `Bearer ${config.apiKey}`;
|
|
36
|
-
}
|
|
37
|
-
return headers;
|
|
38
|
-
}
|
|
39
|
-
async function request(pathname, init) {
|
|
40
|
-
const url = `${baseUrl}${pathname}`;
|
|
41
|
-
const controller = new AbortController();
|
|
42
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
43
|
-
try {
|
|
44
|
-
const response = await fetch(url, {
|
|
45
|
-
...init,
|
|
46
|
-
headers: { ...buildHeaders(), ...init?.headers },
|
|
47
|
-
signal: controller.signal,
|
|
48
|
-
});
|
|
49
|
-
if (!response.ok) {
|
|
50
|
-
const text = await response.text().catch(() => "");
|
|
51
|
-
throw new Error(`QMemory ${init?.method ?? "GET"} ${pathname} returned ${response.status}: ${text.slice(0, 200)}`);
|
|
52
|
-
}
|
|
53
|
-
return await response.json();
|
|
54
|
-
}
|
|
55
|
-
finally {
|
|
56
|
-
clearTimeout(timer);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
providerId: PROVIDER_ID,
|
|
61
|
-
async search(query, userId, options) {
|
|
62
|
-
const resolvedUserId = resolveUserId(userId);
|
|
63
|
-
const limit = options?.limit ?? 10;
|
|
64
|
-
const params = new URLSearchParams({
|
|
65
|
-
q: query,
|
|
66
|
-
user_id: resolvedUserId,
|
|
67
|
-
limit: String(limit),
|
|
68
|
-
});
|
|
69
|
-
const result = await request(`/v1/memories/search/?${params.toString()}`);
|
|
70
|
-
return (result.memories ?? [])
|
|
71
|
-
.filter((m) => m.id && m.text)
|
|
72
|
-
.map((m) => ({
|
|
73
|
-
blockId: m.id,
|
|
74
|
-
text: m.text,
|
|
75
|
-
score: typeof m.importance === "number" ? m.importance : 0,
|
|
76
|
-
source: PROVIDER_ID,
|
|
77
|
-
metadata: m.metadata,
|
|
78
|
-
}));
|
|
79
|
-
},
|
|
80
|
-
async ingest(messages, userId, options) {
|
|
81
|
-
const resolvedUserId = resolveUserId(userId);
|
|
82
|
-
await request("/v1/memories/", {
|
|
83
|
-
method: "POST",
|
|
84
|
-
headers: { "Content-Type": "application/json" },
|
|
85
|
-
body: JSON.stringify({
|
|
86
|
-
user_id: resolvedUserId,
|
|
87
|
-
messages: messages.map((m) => ({
|
|
88
|
-
role: m.role,
|
|
89
|
-
content: m.content,
|
|
90
|
-
...(m.timestamp ? { timestamp: m.timestamp } : {}),
|
|
91
|
-
})), extraction_mode: "none", ...(options?.sessionId ? { session_id: options.sessionId } : {}),
|
|
92
|
-
...(options?.source ? { metadata: { source: options.source } } : {}),
|
|
93
|
-
run_async: true,
|
|
94
|
-
}),
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
async health() {
|
|
98
|
-
const raw = await request("/v1/health/");
|
|
99
|
-
return {
|
|
100
|
-
status: raw.status ?? "unknown",
|
|
101
|
-
version: raw.version ?? "",
|
|
102
|
-
memoryCount: raw.memory_count ?? 0,
|
|
103
|
-
dbSizeBytes: raw.db_size_bytes ?? 0,
|
|
104
|
-
embeddingModel: raw.embedding_model ?? "",
|
|
105
|
-
uptimeSeconds: raw.uptime_seconds ?? 0,
|
|
106
|
-
};
|
|
107
|
-
},
|
|
108
|
-
async addText(text, userId, options) {
|
|
109
|
-
const resolvedUserId = resolveUserId(userId);
|
|
110
|
-
const result = await request("/v1/memories/", {
|
|
111
|
-
method: "POST",
|
|
112
|
-
headers: { "Content-Type": "application/json" },
|
|
113
|
-
body: JSON.stringify({
|
|
114
|
-
user_id: resolvedUserId,
|
|
115
|
-
text,
|
|
116
|
-
extraction_mode: "none",
|
|
117
|
-
...(options?.sessionId ? { session_id: options.sessionId } : {}),
|
|
118
|
-
...(options?.source ? { metadata: { source: options.source } } : {}),
|
|
119
|
-
}),
|
|
120
|
-
});
|
|
121
|
-
return { memoriesAdded: result.memories_added ?? 0 };
|
|
122
|
-
},
|
|
123
|
-
async ingestExtracted(items, userId, options) {
|
|
124
|
-
if (items.length === 0)
|
|
125
|
-
return { memoriesAdded: 0 };
|
|
126
|
-
const resolvedUserId = resolveUserId(userId);
|
|
127
|
-
const results = await Promise.allSettled(items.map((item) => request("/v1/memories/", {
|
|
128
|
-
method: "POST",
|
|
129
|
-
headers: { "Content-Type": "application/json" },
|
|
130
|
-
body: JSON.stringify({
|
|
131
|
-
user_id: resolvedUserId,
|
|
132
|
-
text: item.text,
|
|
133
|
-
extraction_mode: "none",
|
|
134
|
-
...(options?.sessionId ? { session_id: options.sessionId } : {}),
|
|
135
|
-
metadata: {
|
|
136
|
-
...(options?.source ? { source: options.source } : {}),
|
|
137
|
-
...(item.category ? { category: item.category } : {}),
|
|
138
|
-
...(typeof item.importance === "number" ? { importance: item.importance } : {}),
|
|
139
|
-
...(item.speaker ? { speaker: item.speaker } : {}),
|
|
140
|
-
...(item.event_date ? { event_date: item.event_date } : {}),
|
|
141
|
-
...(item.tags?.length ? { tags: item.tags } : {}),
|
|
142
|
-
},
|
|
143
|
-
}),
|
|
144
|
-
})));
|
|
145
|
-
let total = 0;
|
|
146
|
-
for (const r of results) {
|
|
147
|
-
if (r.status === "fulfilled") {
|
|
148
|
-
total += r.value.memories_added ?? 1;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
return { memoriesAdded: total };
|
|
152
|
-
},
|
|
153
|
-
async remove(memoryId) {
|
|
154
|
-
try {
|
|
155
|
-
await request(`/v1/memories/${encodeURIComponent(memoryId)}/`, {
|
|
156
|
-
method: "DELETE",
|
|
157
|
-
});
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
catch {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
}
|