2e14873f2d
Track application source and tests; exclude local env, user workspaces, and runtime data via .gitignore. Co-authored-by: Cursor <cursoragent@cursor.com>
67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { Agent, fetch } from 'undici';
|
|
|
|
const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
for (const line of fs.readFileSync(path.join(root, '.env'), 'utf8').split('\n')) {
|
|
const t = line.trim();
|
|
if (!t || t.startsWith('#')) continue;
|
|
const i = t.indexOf('=');
|
|
if (i < 0) continue;
|
|
if (!process.env[t.slice(0, i)]) process.env[t.slice(0, i)] = t.slice(i + 1);
|
|
}
|
|
|
|
const secret = process.env.TKMIND_SERVER__SECRET_KEY ?? 'local-dev-secret';
|
|
const base = process.env.TKMIND_API_TARGET ?? 'https://127.0.0.1:18006';
|
|
const dispatcher = new Agent({ connect: { rejectUnauthorized: false } });
|
|
|
|
async function api(pathname, body) {
|
|
const res = await fetch(`${base}${pathname}`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', 'X-Secret-Key': secret },
|
|
body: JSON.stringify(body),
|
|
dispatcher,
|
|
});
|
|
return res.json();
|
|
}
|
|
|
|
const provider = process.argv[2] ?? 'custom_tkmind_relay_deepseek';
|
|
const start = await api('/agent/start', {
|
|
working_dir: process.env.VITE_TKMIND_WORKING_DIR || '/Users/john/Project/tkmind_go',
|
|
});
|
|
const sessionId = start.id;
|
|
await api('/agent/update_provider', {
|
|
session_id: sessionId,
|
|
provider,
|
|
model: 'deepseek-chat',
|
|
});
|
|
const reqId = crypto.randomUUID();
|
|
const reply = await fetch(`${base}/reply`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', 'X-Secret-Key': secret },
|
|
body: JSON.stringify({
|
|
session_id: sessionId,
|
|
chat_request_id: reqId,
|
|
user_message: {
|
|
role: 'user',
|
|
created: Date.now(),
|
|
content: [{ type: 'text', text: 'say hi in one word' }],
|
|
metadata: { userVisible: true, agentVisible: true },
|
|
},
|
|
}),
|
|
dispatcher,
|
|
});
|
|
console.log('provider', provider, 'status', reply.status);
|
|
const reader = reply.body.getReader();
|
|
const dec = new TextDecoder();
|
|
let buf = '';
|
|
const deadline = Date.now() + 90000;
|
|
while (Date.now() < deadline) {
|
|
const { done, value } = await reader.read();
|
|
if (done) break;
|
|
buf += dec.decode(value);
|
|
if (/"type":"Finish"/.test(buf) || /Server error/.test(buf)) break;
|
|
}
|
|
console.log(buf.slice(-2000));
|