修复:使用 OpenCode 2.x Plugin API,正确导入类型和 tool helper

This commit is contained in:
ypshidifu
2026-09-20 23:45:41 +08:00
parent 02f3ded256
commit 5d43b5ed76
+7 -15
View File
@@ -1,11 +1,11 @@
/**
* OpenCode Plugin: Show All Sessions
* OpenCode 2.x Plugin: Show All Sessions
*
* This plugin provides /sessions-all command to show all sessions
* regardless of the current working directory.
*/
import { tool } from "@opencode-ai/plugin";
import { type Plugin, tool } from "@opencode-ai/plugin";
import { exec } from "child_process";
import { promisify } from "util";
import { join } from "path";
@@ -47,7 +47,6 @@ function getDbPath(): string {
async function getAllSessionsFromDb(): Promise<Session[]> {
try {
const dbPath = getDbPath();
console.log(`[oc-session-all] Database path: ${dbPath}`);
const query = `
SELECT id, project_id, directory, title, time_created, time_updated, cost
@@ -102,7 +101,10 @@ function formatCost(cost: number): string {
return `$${cost.toFixed(4)}`;
}
export const OcSessionAll = async ({ project, client, $ }: any) => {
/**
* OpenCode 2.x Plugin
*/
export const OcSessionAll: Plugin = async ({ project, client, $, directory, worktree }) => {
console.log("[oc-session-all] Plugin loaded");
return {
@@ -110,7 +112,7 @@ export const OcSessionAll = async ({ project, client, $ }: any) => {
"sessions-all": tool({
description: "显示所有项目的会话记录,绕过目录过滤限制。Show all sessions from all projects.",
args: {},
async execute() {
async execute(args, context) {
const sessions = await getAllSessionsFromDb();
if (!sessions || sessions.length === 0) {
@@ -119,16 +121,6 @@ export const OcSessionAll = async ({ project, client, $ }: any) => {
let output = "=== 所有会话记录 (All Sessions) ===\n\n";
// Group sessions by project
const byProject = new Map<string, Session[]>();
for (const session of sessions) {
const key = session.project_id || "unknown";
if (!byProject.has(key)) {
byProject.set(key, []);
}
byProject.get(key)!.push(session);
}
// Display sessions
let index = 1;
for (const session of sessions) {