@jclaw/core 0.1.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/auto-skill/generator.d.ts +30 -0
- package/dist/auto-skill/generator.d.ts.map +1 -0
- package/dist/auto-skill/generator.js +262 -0
- package/dist/auto-skill/generator.js.map +1 -0
- package/dist/auto-skill/index.d.ts +11 -0
- package/dist/auto-skill/index.d.ts.map +1 -0
- package/dist/auto-skill/index.js +10 -0
- package/dist/auto-skill/index.js.map +1 -0
- package/dist/auto-skill/installer.d.ts +44 -0
- package/dist/auto-skill/installer.d.ts.map +1 -0
- package/dist/auto-skill/installer.js +201 -0
- package/dist/auto-skill/installer.js.map +1 -0
- package/dist/auto-skill/types.d.ts +179 -0
- package/dist/auto-skill/types.d.ts.map +1 -0
- package/dist/auto-skill/types.js +9 -0
- package/dist/auto-skill/types.js.map +1 -0
- package/dist/cli/commands/config.d.ts +16 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +119 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/exec.d.ts +12 -0
- package/dist/cli/commands/exec.d.ts.map +1 -0
- package/dist/cli/commands/exec.js +41 -0
- package/dist/cli/commands/exec.js.map +1 -0
- package/dist/cli/index.d.ts +10 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +91 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +13 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/context/index.d.ts +6 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +12 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/memsearch-client.d.ts +34 -0
- package/dist/context/memsearch-client.d.ts.map +1 -0
- package/dist/context/memsearch-client.js +182 -0
- package/dist/context/memsearch-client.js.map +1 -0
- package/dist/context/mock-client.d.ts +116 -0
- package/dist/context/mock-client.d.ts.map +1 -0
- package/dist/context/mock-client.js +150 -0
- package/dist/context/mock-client.js.map +1 -0
- package/dist/context/openviking-client.d.ts +87 -0
- package/dist/context/openviking-client.d.ts.map +1 -0
- package/dist/context/openviking-client.js +166 -0
- package/dist/context/openviking-client.js.map +1 -0
- package/dist/context/openviking-mcp-client.d.ts +29 -0
- package/dist/context/openviking-mcp-client.d.ts.map +1 -0
- package/dist/context/openviking-mcp-client.js +81 -0
- package/dist/context/openviking-mcp-client.js.map +1 -0
- package/dist/context/simple-memory-client.d.ts +43 -0
- package/dist/context/simple-memory-client.d.ts.map +1 -0
- package/dist/context/simple-memory-client.enhanced.d.ts +39 -0
- package/dist/context/simple-memory-client.enhanced.d.ts.map +1 -0
- package/dist/context/simple-memory-client.enhanced.js +207 -0
- package/dist/context/simple-memory-client.enhanced.js.map +1 -0
- package/dist/context/simple-memory-client.js +270 -0
- package/dist/context/simple-memory-client.js.map +1 -0
- package/dist/evolution/continuous.d.ts +127 -0
- package/dist/evolution/continuous.d.ts.map +1 -0
- package/dist/evolution/continuous.js +238 -0
- package/dist/evolution/continuous.js.map +1 -0
- package/dist/evolution/engine.d.ts +97 -0
- package/dist/evolution/engine.d.ts.map +1 -0
- package/dist/evolution/engine.js +187 -0
- package/dist/evolution/engine.js.map +1 -0
- package/dist/evolution/evolver-adapter.d.ts +104 -0
- package/dist/evolution/evolver-adapter.d.ts.map +1 -0
- package/dist/evolution/evolver-adapter.js +227 -0
- package/dist/evolution/evolver-adapter.js.map +1 -0
- package/dist/evolution/index.d.ts +9 -0
- package/dist/evolution/index.d.ts.map +1 -0
- package/dist/evolution/index.js +8 -0
- package/dist/evolution/index.js.map +1 -0
- package/dist/evolution/memory.d.ts +106 -0
- package/dist/evolution/memory.d.ts.map +1 -0
- package/dist/evolution/memory.js +232 -0
- package/dist/evolution/memory.js.map +1 -0
- package/dist/evolution/mutation.d.ts +66 -0
- package/dist/evolution/mutation.d.ts.map +1 -0
- package/dist/evolution/mutation.js +139 -0
- package/dist/evolution/mutation.js.map +1 -0
- package/dist/evolution/sandbox.d.ts +96 -0
- package/dist/evolution/sandbox.d.ts.map +1 -0
- package/dist/evolution/sandbox.js +194 -0
- package/dist/evolution/sandbox.js.map +1 -0
- package/dist/evolution/types.d.ts +93 -0
- package/dist/evolution/types.d.ts.map +1 -0
- package/dist/evolution/types.js +9 -0
- package/dist/evolution/types.js.map +1 -0
- package/dist/executor/index.d.ts +10 -0
- package/dist/executor/index.d.ts.map +1 -0
- package/dist/executor/index.js +10 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/executor/interface.d.ts +9 -0
- package/dist/executor/interface.d.ts.map +1 -0
- package/dist/executor/interface.js +9 -0
- package/dist/executor/interface.js.map +1 -0
- package/dist/executor/local.d.ts +36 -0
- package/dist/executor/local.d.ts.map +1 -0
- package/dist/executor/local.js +95 -0
- package/dist/executor/local.js.map +1 -0
- package/dist/extension-system/capability-router.d.ts +106 -0
- package/dist/extension-system/capability-router.d.ts.map +1 -0
- package/dist/extension-system/capability-router.js +167 -0
- package/dist/extension-system/capability-router.js.map +1 -0
- package/dist/extension-system/index.d.ts +11 -0
- package/dist/extension-system/index.d.ts.map +1 -0
- package/dist/extension-system/index.js +11 -0
- package/dist/extension-system/index.js.map +1 -0
- package/dist/extension-system/loader.d.ts +93 -0
- package/dist/extension-system/loader.d.ts.map +1 -0
- package/dist/extension-system/loader.js +245 -0
- package/dist/extension-system/loader.js.map +1 -0
- package/dist/extension-system/registry.d.ts +112 -0
- package/dist/extension-system/registry.d.ts.map +1 -0
- package/dist/extension-system/registry.js +161 -0
- package/dist/extension-system/registry.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/network/client.d.ts +130 -0
- package/dist/network/client.d.ts.map +1 -0
- package/dist/network/client.js +230 -0
- package/dist/network/client.js.map +1 -0
- package/dist/network/index.d.ts +10 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/index.js +10 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/protocol.d.ts +159 -0
- package/dist/network/protocol.d.ts.map +1 -0
- package/dist/network/protocol.js +118 -0
- package/dist/network/protocol.js.map +1 -0
- package/dist/runtime/agent.d.ts +124 -0
- package/dist/runtime/agent.d.ts.map +1 -0
- package/dist/runtime/agent.js +286 -0
- package/dist/runtime/agent.js.map +1 -0
- package/dist/runtime/agent_fixed.d.ts +39 -0
- package/dist/runtime/agent_fixed.d.ts.map +1 -0
- package/dist/runtime/agent_fixed.js +193 -0
- package/dist/runtime/agent_fixed.js.map +1 -0
- package/dist/runtime/index.d.ts +11 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +11 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/llm-client.d.ts +108 -0
- package/dist/runtime/llm-client.d.ts.map +1 -0
- package/dist/runtime/llm-client.js +125 -0
- package/dist/runtime/llm-client.js.map +1 -0
- package/dist/runtime/task-executor.d.ts +92 -0
- package/dist/runtime/task-executor.d.ts.map +1 -0
- package/dist/runtime/task-executor.js +203 -0
- package/dist/runtime/task-executor.js.map +1 -0
- package/dist/skill-sh/adapter.d.ts +40 -0
- package/dist/skill-sh/adapter.d.ts.map +1 -0
- package/dist/skill-sh/adapter.js +258 -0
- package/dist/skill-sh/adapter.js.map +1 -0
- package/dist/skill-sh/converter.d.ts +37 -0
- package/dist/skill-sh/converter.d.ts.map +1 -0
- package/dist/skill-sh/converter.js +175 -0
- package/dist/skill-sh/converter.js.map +1 -0
- package/dist/skill-sh/discovery.d.ts +29 -0
- package/dist/skill-sh/discovery.d.ts.map +1 -0
- package/dist/skill-sh/discovery.js +189 -0
- package/dist/skill-sh/discovery.js.map +1 -0
- package/dist/skill-sh/index.d.ts +19 -0
- package/dist/skill-sh/index.d.ts.map +1 -0
- package/dist/skill-sh/index.js +20 -0
- package/dist/skill-sh/index.js.map +1 -0
- package/dist/skill-sh/quality.d.ts +51 -0
- package/dist/skill-sh/quality.d.ts.map +1 -0
- package/dist/skill-sh/quality.js +146 -0
- package/dist/skill-sh/quality.js.map +1 -0
- package/dist/skill-sh/registry.d.ts +58 -0
- package/dist/skill-sh/registry.d.ts.map +1 -0
- package/dist/skill-sh/registry.js +118 -0
- package/dist/skill-sh/registry.js.map +1 -0
- package/dist/skill-sh/types.d.ts +228 -0
- package/dist/skill-sh/types.d.ts.map +1 -0
- package/dist/skill-sh/types.js +9 -0
- package/dist/skill-sh/types.js.map +1 -0
- package/dist/types.d.ts +199 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MemSearch Client
|
|
3
|
+
*
|
|
4
|
+
* 通过 Python 子进程调用 MemSearch
|
|
5
|
+
* 替代 OpenViking,更简单轻量
|
|
6
|
+
*
|
|
7
|
+
* MemSearch GitHub: https://github.com/zilliztech/memsearch
|
|
8
|
+
*
|
|
9
|
+
* @module @jclaw/core/context/memsearch-client
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from 'child_process';
|
|
12
|
+
import { writeFile, mkdir } from 'fs/promises';
|
|
13
|
+
import { join } from 'path';
|
|
14
|
+
import { existsSync } from 'fs';
|
|
15
|
+
export class MemSearchClient {
|
|
16
|
+
initialized = false;
|
|
17
|
+
config;
|
|
18
|
+
constructor(config = {}) {
|
|
19
|
+
this.config = {
|
|
20
|
+
memoryPath: config.memoryPath || './memory',
|
|
21
|
+
embeddingProvider: config.embeddingProvider || 'local',
|
|
22
|
+
embeddingModel: config.embeddingModel || 'all-MiniLM-L6-v2',
|
|
23
|
+
verbose: config.verbose || false,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async connect() {
|
|
27
|
+
try {
|
|
28
|
+
// 确保内存目录存在
|
|
29
|
+
if (!existsSync(this.config.memoryPath)) {
|
|
30
|
+
await mkdir(this.config.memoryPath, { recursive: true });
|
|
31
|
+
}
|
|
32
|
+
// 测试 MemSearch 是否可用
|
|
33
|
+
await this.runPythonScript('test', {});
|
|
34
|
+
this.initialized = true;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
38
|
+
throw new Error(`Failed to initialize MemSearch: ${message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async disconnect() {
|
|
42
|
+
this.initialized = false;
|
|
43
|
+
}
|
|
44
|
+
async query(question, options) {
|
|
45
|
+
if (!this.initialized) {
|
|
46
|
+
throw new Error('Client not initialized');
|
|
47
|
+
}
|
|
48
|
+
const results = await this.runPythonScript('search', {
|
|
49
|
+
query: question,
|
|
50
|
+
top_k: options?.topK ?? 5,
|
|
51
|
+
memory_path: this.config.memoryPath,
|
|
52
|
+
});
|
|
53
|
+
return results.map((r) => r.content).join('\n\n');
|
|
54
|
+
}
|
|
55
|
+
async addResource(resourcePath) {
|
|
56
|
+
if (!this.initialized) {
|
|
57
|
+
throw new Error('Client not initialized');
|
|
58
|
+
}
|
|
59
|
+
// 将资源复制到内存目录
|
|
60
|
+
const content = await this.runPythonScript('add_resource', {
|
|
61
|
+
resource_path: resourcePath,
|
|
62
|
+
memory_path: this.config.memoryPath,
|
|
63
|
+
});
|
|
64
|
+
return content.uri || '';
|
|
65
|
+
}
|
|
66
|
+
async saveMemory(content, title) {
|
|
67
|
+
const date = new Date().toISOString().split('T')[0];
|
|
68
|
+
const fileName = `${date}.md`;
|
|
69
|
+
const filePath = join(this.config.memoryPath, fileName);
|
|
70
|
+
const entry = title
|
|
71
|
+
? `\n## ${title}\n${content}\n`
|
|
72
|
+
: `\n${content}\n`;
|
|
73
|
+
await writeFile(filePath, entry, { flag: 'a' });
|
|
74
|
+
// 重新索引
|
|
75
|
+
await this.runPythonScript('index', {
|
|
76
|
+
memory_path: this.config.memoryPath,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
isConnected() {
|
|
80
|
+
return this.initialized;
|
|
81
|
+
}
|
|
82
|
+
runPythonScript(action, params) {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const script = this.generatePythonScript(action, params);
|
|
85
|
+
const proc = spawn('python', ['-c', script], {
|
|
86
|
+
env: {
|
|
87
|
+
...process.env,
|
|
88
|
+
MEMSEARCH_PROVIDER: this.config.embeddingProvider,
|
|
89
|
+
MEMSEARCH_MODEL: this.config.embeddingModel,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
let stdout = '';
|
|
93
|
+
let stderr = '';
|
|
94
|
+
proc.stdout.on('data', (data) => {
|
|
95
|
+
stdout += data.toString();
|
|
96
|
+
});
|
|
97
|
+
proc.stderr.on('data', (data) => {
|
|
98
|
+
stderr += data.toString();
|
|
99
|
+
});
|
|
100
|
+
proc.on('close', (code) => {
|
|
101
|
+
if (code !== 0) {
|
|
102
|
+
reject(new Error(`Python script failed: ${stderr}`));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const result = JSON.parse(stdout);
|
|
107
|
+
resolve(result);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
resolve(stdout.trim());
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
proc.on('error', (error) => {
|
|
114
|
+
reject(error);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
generatePythonScript(action, params) {
|
|
119
|
+
const baseScript = `
|
|
120
|
+
import asyncio
|
|
121
|
+
import json
|
|
122
|
+
import sys
|
|
123
|
+
sys.path.insert(0, '.')
|
|
124
|
+
|
|
125
|
+
from memsearch import MemSearch
|
|
126
|
+
|
|
127
|
+
async def main():
|
|
128
|
+
mem = MemSearch(
|
|
129
|
+
paths=['${params.memory_path || this.config.memoryPath}'],
|
|
130
|
+
embedding_provider='${this.config.embeddingProvider}',
|
|
131
|
+
embedding_model='${this.config.embeddingModel}',
|
|
132
|
+
)
|
|
133
|
+
`;
|
|
134
|
+
switch (action) {
|
|
135
|
+
case 'test':
|
|
136
|
+
return baseScript + `
|
|
137
|
+
await mem.index()
|
|
138
|
+
print(json.dumps({"status": "ok"}))
|
|
139
|
+
|
|
140
|
+
asyncio.run(main())
|
|
141
|
+
`;
|
|
142
|
+
case 'search':
|
|
143
|
+
return baseScript + `
|
|
144
|
+
await mem.index()
|
|
145
|
+
results = await mem.search('${params.query}', top_k=${params.top_k})
|
|
146
|
+
print(json.dumps(results))
|
|
147
|
+
|
|
148
|
+
asyncio.run(main())
|
|
149
|
+
`;
|
|
150
|
+
case 'index':
|
|
151
|
+
return baseScript + `
|
|
152
|
+
await mem.index()
|
|
153
|
+
print(json.dumps({"status": "indexed"}))
|
|
154
|
+
|
|
155
|
+
asyncio.run(main())
|
|
156
|
+
`;
|
|
157
|
+
case 'add_resource':
|
|
158
|
+
return baseScript + `
|
|
159
|
+
import shutil
|
|
160
|
+
from pathlib import Path
|
|
161
|
+
|
|
162
|
+
src = Path('${params.resource_path}')
|
|
163
|
+
dst = Path('${params.memory_path}') / src.name
|
|
164
|
+
shutil.copy2(src, dst)
|
|
165
|
+
await mem.index()
|
|
166
|
+
print(json.dumps({"uri": str(dst)}))
|
|
167
|
+
|
|
168
|
+
asyncio.run(main())
|
|
169
|
+
`;
|
|
170
|
+
default:
|
|
171
|
+
return baseScript + `
|
|
172
|
+
print(json.dumps({"error": "Unknown action"}))
|
|
173
|
+
|
|
174
|
+
asyncio.run(main())
|
|
175
|
+
`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
export function createMemSearchClient(config) {
|
|
180
|
+
return new MemSearchClient(config);
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=memsearch-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memsearch-client.js","sourceRoot":"","sources":["../../src/context/memsearch-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH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QACE,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,qBAAqB,CAAC,MAAwB;IAC5D,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock OpenViking Client
|
|
3
|
+
*
|
|
4
|
+
* In-memory mock implementation of ContextManager interface for offline testing.
|
|
5
|
+
*
|
|
6
|
+
* @module @jclaw/core/context/mock-client
|
|
7
|
+
*/
|
|
8
|
+
import type { ContextManager } from '../types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Internal resource representation for mock client
|
|
11
|
+
*/
|
|
12
|
+
interface MockResource {
|
|
13
|
+
id: string;
|
|
14
|
+
path: string;
|
|
15
|
+
content: string;
|
|
16
|
+
addedAt: Date;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Mock implementation of ContextManager for testing purposes.
|
|
20
|
+
*
|
|
21
|
+
* Provides in-memory storage and retrieval without requiring a real
|
|
22
|
+
* OpenViking server connection. Useful for unit tests and offline development.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const client = new MockClient();
|
|
27
|
+
* await client.connect();
|
|
28
|
+
*
|
|
29
|
+
* // Set custom query responses for testing
|
|
30
|
+
* client.setQueryResponse('What is JClaw?', 'JClaw is a self-evolving agent framework');
|
|
31
|
+
*
|
|
32
|
+
* const result = await client.query('What is JClaw?');
|
|
33
|
+
* console.log(result); // 'JClaw is a self-evolving agent framework'
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class MockClient implements ContextManager {
|
|
37
|
+
private connected;
|
|
38
|
+
private resources;
|
|
39
|
+
private queryResponses;
|
|
40
|
+
/**
|
|
41
|
+
* Establish connection to the mock context backend.
|
|
42
|
+
* Simply sets internal connected flag to true.
|
|
43
|
+
*/
|
|
44
|
+
connect(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Disconnect from the mock context backend.
|
|
47
|
+
* Simply sets internal connected flag to false.
|
|
48
|
+
* Does not clear stored resources or query responses.
|
|
49
|
+
*/
|
|
50
|
+
disconnect(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Query the mock context for relevant information.
|
|
53
|
+
*
|
|
54
|
+
* @param question - The question to query
|
|
55
|
+
* @param options - Query options (topK is ignored in mock)
|
|
56
|
+
* @returns Mock response or custom response if set via setQueryResponse
|
|
57
|
+
* @throws Error if client is not connected
|
|
58
|
+
*/
|
|
59
|
+
query(question: string, options?: {
|
|
60
|
+
topK?: number;
|
|
61
|
+
}): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Add a resource to the mock context.
|
|
64
|
+
*
|
|
65
|
+
* @param resourcePath - Path to the resource to add
|
|
66
|
+
* @returns Generated resource identifier
|
|
67
|
+
* @throws Error if client is not connected
|
|
68
|
+
*/
|
|
69
|
+
addResource(resourcePath: string): Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Set a custom response for a specific query.
|
|
72
|
+
* Useful for testing specific scenarios.
|
|
73
|
+
*
|
|
74
|
+
* @param question - The question to set a response for
|
|
75
|
+
* @param response - The response to return
|
|
76
|
+
*/
|
|
77
|
+
setQueryResponse(question: string, response: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* Clear a previously set query response.
|
|
80
|
+
*
|
|
81
|
+
* @param question - The question to clear the response for
|
|
82
|
+
*/
|
|
83
|
+
clearQueryResponse(question: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* Get all stored resources.
|
|
86
|
+
* Useful for verifying addResource calls in tests.
|
|
87
|
+
*
|
|
88
|
+
* @returns Array of all stored resources
|
|
89
|
+
*/
|
|
90
|
+
getResources(): MockResource[];
|
|
91
|
+
/**
|
|
92
|
+
* Get a specific resource by ID.
|
|
93
|
+
*
|
|
94
|
+
* @param id - The resource ID
|
|
95
|
+
* @returns The resource or undefined if not found
|
|
96
|
+
*/
|
|
97
|
+
getResourceById(id: string): MockResource | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Clear all stored resources.
|
|
100
|
+
* Useful for test cleanup.
|
|
101
|
+
*/
|
|
102
|
+
clearResources(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Check if the client is currently connected.
|
|
105
|
+
*
|
|
106
|
+
* @returns True if connected, false otherwise
|
|
107
|
+
*/
|
|
108
|
+
isConnected(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Reset the client to initial state.
|
|
111
|
+
* Disconnects, clears all resources and query responses.
|
|
112
|
+
*/
|
|
113
|
+
reset(): void;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
|
116
|
+
//# sourceMappingURL=mock-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-client.d.ts","sourceRoot":"","sources":["../../src/context/mock-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;GAEG;AACH,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,UAAW,YAAW,cAAc;IAC/C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,cAAc,CAAkC;IAExD;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;;;;;OAOG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAmB3E;;;;;;OAMG;IACG,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAkBxD;;;;;;OAMG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAI1D;;;;OAIG;IACH,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAI1C;;;;;OAKG;IACH,YAAY,IAAI,YAAY,EAAE;IAI9B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIrD;;;OAGG;IACH,cAAc,IAAI,IAAI;IAItB;;;;OAIG;IACH,WAAW,IAAI,OAAO;IAItB;;;OAGG;IACH,KAAK,IAAI,IAAI;CAKd"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock OpenViking Client
|
|
3
|
+
*
|
|
4
|
+
* In-memory mock implementation of ContextManager interface for offline testing.
|
|
5
|
+
*
|
|
6
|
+
* @module @jclaw/core/context/mock-client
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Mock implementation of ContextManager for testing purposes.
|
|
10
|
+
*
|
|
11
|
+
* Provides in-memory storage and retrieval without requiring a real
|
|
12
|
+
* OpenViking server connection. Useful for unit tests and offline development.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const client = new MockClient();
|
|
17
|
+
* await client.connect();
|
|
18
|
+
*
|
|
19
|
+
* // Set custom query responses for testing
|
|
20
|
+
* client.setQueryResponse('What is JClaw?', 'JClaw is a self-evolving agent framework');
|
|
21
|
+
*
|
|
22
|
+
* const result = await client.query('What is JClaw?');
|
|
23
|
+
* console.log(result); // 'JClaw is a self-evolving agent framework'
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export class MockClient {
|
|
27
|
+
connected = false;
|
|
28
|
+
resources = new Map();
|
|
29
|
+
queryResponses = new Map();
|
|
30
|
+
/**
|
|
31
|
+
* Establish connection to the mock context backend.
|
|
32
|
+
* Simply sets internal connected flag to true.
|
|
33
|
+
*/
|
|
34
|
+
async connect() {
|
|
35
|
+
this.connected = true;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Disconnect from the mock context backend.
|
|
39
|
+
* Simply sets internal connected flag to false.
|
|
40
|
+
* Does not clear stored resources or query responses.
|
|
41
|
+
*/
|
|
42
|
+
async disconnect() {
|
|
43
|
+
this.connected = false;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Query the mock context for relevant information.
|
|
47
|
+
*
|
|
48
|
+
* @param question - The question to query
|
|
49
|
+
* @param options - Query options (topK is ignored in mock)
|
|
50
|
+
* @returns Mock response or custom response if set via setQueryResponse
|
|
51
|
+
* @throws Error if client is not connected
|
|
52
|
+
*/
|
|
53
|
+
async query(question, options) {
|
|
54
|
+
if (!this.connected) {
|
|
55
|
+
throw new Error('Client not connected');
|
|
56
|
+
}
|
|
57
|
+
// Options are available for future use (topK for limiting results)
|
|
58
|
+
const _topK = options?.topK; // Available for future implementation
|
|
59
|
+
void _topK; // mark as used
|
|
60
|
+
// Check for custom response first
|
|
61
|
+
const customResponse = this.queryResponses.get(question);
|
|
62
|
+
if (customResponse !== undefined) {
|
|
63
|
+
return customResponse;
|
|
64
|
+
}
|
|
65
|
+
// Return default mock response
|
|
66
|
+
return `Mock response for: ${question}`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Add a resource to the mock context.
|
|
70
|
+
*
|
|
71
|
+
* @param resourcePath - Path to the resource to add
|
|
72
|
+
* @returns Generated resource identifier
|
|
73
|
+
* @throws Error if client is not connected
|
|
74
|
+
*/
|
|
75
|
+
async addResource(resourcePath) {
|
|
76
|
+
if (!this.connected) {
|
|
77
|
+
throw new Error('Client not connected');
|
|
78
|
+
}
|
|
79
|
+
const id = `mock-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
80
|
+
this.resources.set(id, {
|
|
81
|
+
id,
|
|
82
|
+
path: resourcePath,
|
|
83
|
+
content: '',
|
|
84
|
+
addedAt: new Date(),
|
|
85
|
+
});
|
|
86
|
+
return id;
|
|
87
|
+
}
|
|
88
|
+
// ===== Test Helper Methods =====
|
|
89
|
+
/**
|
|
90
|
+
* Set a custom response for a specific query.
|
|
91
|
+
* Useful for testing specific scenarios.
|
|
92
|
+
*
|
|
93
|
+
* @param question - The question to set a response for
|
|
94
|
+
* @param response - The response to return
|
|
95
|
+
*/
|
|
96
|
+
setQueryResponse(question, response) {
|
|
97
|
+
this.queryResponses.set(question, response);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Clear a previously set query response.
|
|
101
|
+
*
|
|
102
|
+
* @param question - The question to clear the response for
|
|
103
|
+
*/
|
|
104
|
+
clearQueryResponse(question) {
|
|
105
|
+
this.queryResponses.delete(question);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get all stored resources.
|
|
109
|
+
* Useful for verifying addResource calls in tests.
|
|
110
|
+
*
|
|
111
|
+
* @returns Array of all stored resources
|
|
112
|
+
*/
|
|
113
|
+
getResources() {
|
|
114
|
+
return Array.from(this.resources.values());
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get a specific resource by ID.
|
|
118
|
+
*
|
|
119
|
+
* @param id - The resource ID
|
|
120
|
+
* @returns The resource or undefined if not found
|
|
121
|
+
*/
|
|
122
|
+
getResourceById(id) {
|
|
123
|
+
return this.resources.get(id);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Clear all stored resources.
|
|
127
|
+
* Useful for test cleanup.
|
|
128
|
+
*/
|
|
129
|
+
clearResources() {
|
|
130
|
+
this.resources.clear();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check if the client is currently connected.
|
|
134
|
+
*
|
|
135
|
+
* @returns True if connected, false otherwise
|
|
136
|
+
*/
|
|
137
|
+
isConnected() {
|
|
138
|
+
return this.connected;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Reset the client to initial state.
|
|
142
|
+
* Disconnects, clears all resources and query responses.
|
|
143
|
+
*/
|
|
144
|
+
reset() {
|
|
145
|
+
this.connected = false;
|
|
146
|
+
this.resources.clear();
|
|
147
|
+
this.queryResponses.clear();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=mock-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock-client.js","sourceRoot":"","sources":["../../src/context/mock-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,UAAU;IACb,SAAS,GAAG,KAAK,CAAC;IAClB,SAAS,GAA8B,IAAI,GAAG,EAAE,CAAC;IACjD,cAAc,GAAwB,IAAI,GAAG,EAAE,CAAC;IAExD;;;OAGG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,UAAU;QACd,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;IACzB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,KAAK,CAAC,QAAgB,EAAE,OAA2B;QACvD,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC1C,CAAC;QAED,mEAAmE;QACnE,MAAM,KAAK,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,sCAAsC;QACnE,KAAK,KAAK,CAAC,CAAC,eAAe;QAE3B,kCAAkC;QAClC,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzD,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,+BAA+B;QAC/B,OAAO,sBAAsB,QAAQ,EAAE,CAAC;IAC1C,CAAC;IAED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AAS,GAAG,KAAK,CAAC;QACvB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenViking Client
|
|
3
|
+
*
|
|
4
|
+
* HTTP client implementation of ContextManager interface for connecting
|
|
5
|
+
* to OpenViking MCP Server.
|
|
6
|
+
*
|
|
7
|
+
* @module @jclaw/core/context/openviking-client
|
|
8
|
+
*/
|
|
9
|
+
import type { ContextManager } from '../types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for OpenViking client.
|
|
12
|
+
*/
|
|
13
|
+
export interface OpenVikingConfig {
|
|
14
|
+
/** URL of the OpenViking MCP server */
|
|
15
|
+
serverUrl: string;
|
|
16
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
17
|
+
timeout?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* HTTP client implementation of ContextManager for OpenViking MCP Server.
|
|
21
|
+
*
|
|
22
|
+
* Provides connection management and context operations via HTTP requests.
|
|
23
|
+
* For Phase 1, this uses a basic HTTP client approach. Full MCP SDK
|
|
24
|
+
* integration can be added in later phases.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const client = new OpenVikingClient({
|
|
29
|
+
* serverUrl: 'http://localhost:2033/mcp'
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* await client.connect();
|
|
33
|
+
* const result = await client.query('What is the project structure?');
|
|
34
|
+
* await client.disconnect();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class OpenVikingClient implements ContextManager {
|
|
38
|
+
private connected;
|
|
39
|
+
private readonly config;
|
|
40
|
+
/**
|
|
41
|
+
* Create a new OpenViking client instance.
|
|
42
|
+
*
|
|
43
|
+
* @param config - Configuration options including server URL and timeout
|
|
44
|
+
*/
|
|
45
|
+
constructor(config: OpenVikingConfig);
|
|
46
|
+
/**
|
|
47
|
+
* Establish connection to the OpenViking server.
|
|
48
|
+
*
|
|
49
|
+
* Performs a health check GET request to verify the server is available.
|
|
50
|
+
*
|
|
51
|
+
* @throws Error if connection fails or server is not available
|
|
52
|
+
*/
|
|
53
|
+
connect(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Disconnect from the OpenViking server.
|
|
56
|
+
*
|
|
57
|
+
* Simply sets the internal connected flag to false.
|
|
58
|
+
* No explicit disconnect request is sent to the server.
|
|
59
|
+
*/
|
|
60
|
+
disconnect(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Query the OpenViking context for relevant information.
|
|
63
|
+
*
|
|
64
|
+
* @param question - The question to query
|
|
65
|
+
* @param options - Query options including topK for result count
|
|
66
|
+
* @returns Relevant context as string
|
|
67
|
+
* @throws Error if client is not connected or query fails
|
|
68
|
+
*/
|
|
69
|
+
query(question: string, options?: {
|
|
70
|
+
topK?: number;
|
|
71
|
+
}): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Add a resource to the OpenViking context.
|
|
74
|
+
*
|
|
75
|
+
* @param resourcePath - Path to the resource to add
|
|
76
|
+
* @returns Resource identifier returned by the server
|
|
77
|
+
* @throws Error if client is not connected or add operation fails
|
|
78
|
+
*/
|
|
79
|
+
addResource(resourcePath: string): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Check if the client is currently connected.
|
|
82
|
+
*
|
|
83
|
+
* @returns True if connected, false otherwise
|
|
84
|
+
*/
|
|
85
|
+
isConnected(): boolean;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=openviking-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openviking-client.d.ts","sourceRoot":"","sources":["../../src/context/openviking-client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAWD;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAiB,YAAW,cAAc;IACrD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IAEpD;;;;OAIG;gBACS,MAAM,EAAE,gBAAgB;IAOpC;;;;;;OAMG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB9B;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;;;;;OAOG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAwC3E;;;;;;OAMG;IACG,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAyCxD;;;;OAIG;IACH,WAAW,IAAI,OAAO;CAGvB"}
|