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