Files
next-tjwater-agent/.opencode/tools/session_search.ts
T

45 lines
1.3 KiB
TypeScript

import { tool } from "@opencode-ai/plugin";
import { getInternalBridgeConfig } from "../internalBridge.js";
export default tool({
description:
"搜索当前用户和项目范围内的历史会话 transcript。适合回忆过去讨论过的案例、约束和结论,避免把一次性案例写入 memory。",
args: {
reason: tool.schema
.string()
.describe("Why prior session history is needed for the current request."),
query: tool.schema
.string()
.describe("What to search for in prior session history."),
max_results: tool.schema
.number()
.int()
.positive()
.optional()
.describe("Optional maximum number of hits to return."),
},
async execute(args, context) {
const { baseUrl: internalBaseUrl, internalToken } = getInternalBridgeConfig();
const response = await fetch(
`${internalBaseUrl}/internal/tools/session-search`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
"x-agent-internal-token": internalToken,
},
body: JSON.stringify({
max_results: args.max_results,
query: args.query,
session_id: context.sessionID,
}),
},
);
const text = await response.text();
if (!response.ok) {
throw new Error(text);
}
return text;
},
});