更新 vite 后调整 task-loop 的打包策略

This commit is contained in:
kirigaya 2025-05-19 17:08:39 +08:00
parent 13fd6a00e1
commit 3924ee0224
2 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,41 @@
{
"compilerOptions": {
"target": "esnext",
"module": "nodenext",
"strict": true,
"jsx": "preserve",
"moduleResolution": "nodenext",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"useDefineForClassFields": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}

View File

@ -0,0 +1,59 @@
const { TaskLoop } = require('../../openmcp-sdk/task-loop');
const { TaskLoopAdapter } = require('../../openmcp-sdk/service');
async function main() {
// 创建适配器,负责通信和 mcp 连接
const adapter = new TaskLoopAdapter();
// 创建事件循环驱动器
const taskLoop = new TaskLoop({ adapter });
// 配置改次事件循环使用的大模型
taskLoop.setLlmConfig({
id: 'deepseek',
baseUrl: 'https://api.deepseek.com/v1',
userToken: process.env['DEEPSEEK_API_TOKEN'],
userModel: 'deepseek-chat'
});
// 创建当前事件循环对应的上下文,并且配置当前上下文的设置
const storage = {
messages: [],
settings: {
temperature: 0.7,
enableTools: [],
systemPrompt: 'you are a clever bot',
contextLength: 20
}
};
// 本次发出的问题
const message = 'hello world';
// 事件循环结束的句柄
taskLoop.registerOnDone(() => {
console.log('taskLoop done');
});
// 事件循环每一次 epoch 开始的句柄
taskLoop.registerOnError((error) => {
console.log('taskLoop error', error);
});
// 事件循环出现 error 时的句柄(出现 error 不一定会停止事件循环)
taskLoop.registerOnEpoch(() => {
console.log('taskLoop epoch');
});
// 开启事件循环
await taskLoop.start(storage, message);
// 打印上下文,最终的回答在 messages.at(-1) 中
console.log(storage.messages);
const content = storage.messages.at(-1).content;
console.log(content);
}
main();