update
This commit is contained in:
@@ -77,12 +77,7 @@ app.route({
|
||||
ctx.body = { content: `问题不能为空` };
|
||||
return;
|
||||
}
|
||||
// const sessionList = await client.session.list()
|
||||
let session: Session | null = null;
|
||||
// const hasSession = sessionList.data.find(s => s.directory === directory);
|
||||
// if (hasSession) {
|
||||
// session = hasSession;
|
||||
// } else {
|
||||
if (sessionId) {
|
||||
try {
|
||||
const getSession = await client.session.get({ path: { id: sessionId } });
|
||||
@@ -109,7 +104,7 @@ app.route({
|
||||
body: {
|
||||
messageID: messageId,
|
||||
parts: _parts,
|
||||
model
|
||||
...model ? { model } : {},
|
||||
},
|
||||
path: {
|
||||
id: sessionId || session.id,
|
||||
@@ -118,6 +113,12 @@ app.route({
|
||||
if (awaitAnswer) {
|
||||
const message = await promptPromise;
|
||||
data = message.data;
|
||||
} else {
|
||||
promptPromise.then(res => {
|
||||
console.log(`Prompt completed with response:`, res.data.info.id);
|
||||
}).catch(() => {
|
||||
// 忽略错误
|
||||
})
|
||||
}
|
||||
ctx.body = { content: awaitAnswer ? `已经完成` : `运行中`, data, sessionId: session.id, messageId: messageId };
|
||||
ctx.body = { content: awaitAnswer ? `已经完成` : `运行中`, data, sessionId: session.id };
|
||||
}).addTo(app);
|
||||
@@ -93,20 +93,20 @@ app.route({
|
||||
title: '列出 Session 消息',
|
||||
summary: '列出指定 OpenCode 会话的所有消息记录',
|
||||
args: {
|
||||
id: tool.schema.string().describe('Session ID'),
|
||||
sessionId: tool.schema.string().describe('Session ID'),
|
||||
port: tool.schema.number().optional().describe('OpenCode 服务端口,默认为 4096'),
|
||||
}
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const { id, port } = ctx.query;
|
||||
if (!id) {
|
||||
const { sessionId, port } = ctx.query;
|
||||
if (!sessionId) {
|
||||
ctx.throw(400, 'Session ID 不能为空');
|
||||
return;
|
||||
}
|
||||
const client = await opencodeManager.getClient({ port });
|
||||
const result = await client.session.messages({ path: { id } });
|
||||
ctx.body = { data: result.data, content: `Session ${id} 共 ${(result.data as any[])?.length ?? 0} 条消息` };
|
||||
const result = await client.session.messages({ path: { id: sessionId } });
|
||||
ctx.body = { data: result.data, content: `Session ${sessionId} 共 ${(result.data as any[])?.length ?? 0} 条消息` };
|
||||
}).addTo(app);
|
||||
|
||||
// 新增 - 创建 session
|
||||
@@ -147,21 +147,21 @@ app.route({
|
||||
title: '更新 Session',
|
||||
summary: '更新指定 OpenCode 会话的属性,如标题',
|
||||
args: {
|
||||
id: tool.schema.string().describe('Session ID'),
|
||||
sessionId: tool.schema.string().describe('Session ID'),
|
||||
title: tool.schema.string().optional().describe('新的会话标题'),
|
||||
port: tool.schema.number().optional().describe('OpenCode 服务端口,默认为 4096'),
|
||||
}
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const { id, title, port } = ctx.query;
|
||||
if (!id) {
|
||||
const { sessionId, title, port } = ctx.query;
|
||||
if (!sessionId) {
|
||||
ctx.throw(400, 'Session ID 不能为空');
|
||||
return;
|
||||
}
|
||||
const client = await opencodeManager.getClient({ port });
|
||||
const result = await client.session.update({ path: { id }, body: { title } });
|
||||
ctx.body = { data: result.data, content: `Session ${id} 已更新` };
|
||||
const result = await client.session.update({ path: { id: sessionId }, body: { title } });
|
||||
ctx.body = { data: result.data, content: `Session ${sessionId} 已更新` };
|
||||
}).addTo(app);
|
||||
|
||||
// 删除 - 删除 session
|
||||
@@ -177,20 +177,20 @@ app.route({
|
||||
title: '删除 Session',
|
||||
summary: '根据 ID 删除指定的 OpenCode 会话及其所有数据',
|
||||
args: {
|
||||
id: tool.schema.string().describe('Session ID'),
|
||||
sessionId: tool.schema.string().describe('Session ID'),
|
||||
port: tool.schema.number().optional().describe('OpenCode 服务端口,默认为 4096'),
|
||||
}
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const { id, port } = ctx.query;
|
||||
if (!id) {
|
||||
const { sessionId, port } = ctx.query;
|
||||
if (!sessionId) {
|
||||
ctx.throw(400, 'Session ID 不能为空');
|
||||
return;
|
||||
}
|
||||
const client = await opencodeManager.getClient({ port });
|
||||
await client.session.delete({ path: { id } });
|
||||
ctx.body = { content: `Session ${id} 已删除` };
|
||||
await client.session.delete({ path: { id: sessionId } });
|
||||
ctx.body = { content: `Session ${sessionId} 已删除` };
|
||||
}).addTo(app);
|
||||
|
||||
// 操作 - 中止 session
|
||||
@@ -206,20 +206,20 @@ app.route({
|
||||
title: '中止 Session',
|
||||
summary: '中止正在运行的 OpenCode 会话',
|
||||
args: {
|
||||
id: tool.schema.string().describe('Session ID'),
|
||||
sessionId: tool.schema.string().describe('Session ID'),
|
||||
port: tool.schema.number().optional().describe('OpenCode 服务端口,默认为 4096'),
|
||||
}
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const { id, port } = ctx.query;
|
||||
if (!id) {
|
||||
const { sessionId, port } = ctx.query;
|
||||
if (!sessionId) {
|
||||
ctx.throw(400, 'Session ID 不能为空');
|
||||
return;
|
||||
}
|
||||
const client = await opencodeManager.getClient({ port });
|
||||
await client.session.abort({ path: { id } });
|
||||
ctx.body = { content: `Session ${id} 已中止` };
|
||||
await client.session.abort({ path: { id: sessionId } });
|
||||
ctx.body = { content: `Session ${sessionId} 已中止` };
|
||||
}).addTo(app);
|
||||
|
||||
// 操作 - Fork session
|
||||
@@ -235,21 +235,21 @@ app.route({
|
||||
title: 'Fork Session',
|
||||
summary: '从指定消息处 Fork 一个 OpenCode 会话',
|
||||
args: {
|
||||
id: tool.schema.string().describe('Session ID'),
|
||||
sessionId: tool.schema.string().describe('Session ID'),
|
||||
messageId: tool.schema.string().describe('从该消息处开始 Fork'),
|
||||
port: tool.schema.number().optional().describe('OpenCode 服务端口,默认为 4096'),
|
||||
}
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const { id, messageId, port } = ctx.query;
|
||||
if (!id || !messageId) {
|
||||
const { sessionId, messageId, port } = ctx.query;
|
||||
if (!sessionId || !messageId) {
|
||||
ctx.throw(400, 'Session ID 和 messageId 不能为空');
|
||||
return;
|
||||
}
|
||||
const client = await opencodeManager.getClient({ port });
|
||||
const result = await client.session.fork({ path: { id }, body: { messageID: messageId } });
|
||||
ctx.body = { data: result.data, content: `Session ${id} 已从消息 ${messageId} Fork` };
|
||||
const result = await client.session.fork({ path: { id: sessionId }, body: { messageID: messageId } });
|
||||
ctx.body = { data: result.data, content: `Session ${sessionId} 已从消息 ${messageId} Fork` };
|
||||
}).addTo(app);
|
||||
|
||||
// 操作 - 总结 session
|
||||
@@ -265,18 +265,18 @@ app.route({
|
||||
title: '总结 Session',
|
||||
summary: '对指定的 OpenCode 会话进行内容总结',
|
||||
args: {
|
||||
id: tool.schema.string().describe('Session ID'),
|
||||
sessionId: tool.schema.string().describe('Session ID'),
|
||||
port: tool.schema.number().optional().describe('OpenCode 服务端口,默认为 4096'),
|
||||
}
|
||||
})
|
||||
}
|
||||
}).define(async (ctx) => {
|
||||
const { id, port } = ctx.query;
|
||||
if (!id) {
|
||||
const { sessionId, port } = ctx.query;
|
||||
if (!sessionId) {
|
||||
ctx.throw(400, 'Session ID 不能为空');
|
||||
return;
|
||||
}
|
||||
const client = await opencodeManager.getClient({ port });
|
||||
const result = await client.session.summarize({ path: { id } });
|
||||
ctx.body = { data: result.data, content: `Session ${id} 总结完成` };
|
||||
const result = await client.session.summarize({ path: { id: sessionId } });
|
||||
ctx.body = { data: result.data, content: `Session ${sessionId} 总结完成` };
|
||||
}).addTo(app);
|
||||
|
||||
Reference in New Issue
Block a user