修复:将插件从 Tool 改为 Command,支持用户输入 /sessions-all 命令

This commit is contained in:
ypshidifu
2026-09-21 17:29:21 +08:00
parent 45e68bfecf
commit 289ff13132
+23 -10
View File
@@ -12,6 +12,16 @@ import { join } from "path";
import { existsSync } from "fs";
import { DatabaseSync } from "node:sqlite";
// Type for command invocation
interface CommandInvocation {
sessionID: string;
prompt: {
text: string;
// other prompt properties
};
delivery: "steer" | "queue";
}
interface Session {
id: string;
project_id: string;
@@ -123,25 +133,28 @@ export default define({
id: "oc-session-all",
async setup(ctx) {
console.log("[oc-session-all] V2 plugin loaded, registering tool...");
console.log("[oc-session-all] V2 plugin loaded, registering command...");
// Register the sessions-all tool
await ctx.tool.transform((editor) => {
// Register the sessions-all command
await ctx.command.transform((editor) => {
editor.add({
name: "sessions-all",
description: "显示所有项目的会话记录,绕过目录过滤限制。Show all sessions from all projects.",
input: {}, // No input parameters required
async execute(input) {
console.log("[oc-session-all] Tool executed");
async execute(invocation: CommandInvocation) {
console.log("[oc-session-all] Command executed");
const sessions = getAllSessionsFromDb();
const output = formatSessions(sessions);
return {
content: output,
};
// Send the output as a prompt to the session
await ctx.session.prompt({
sessionID: invocation.sessionID,
text: output,
delivery: invocation.delivery,
});
},
});
});
console.log("[oc-session-all] Tool registered successfully");
console.log("[oc-session-all] Command registered successfully");
},
});