重构会话管理,简化上下文存储逻辑
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
import { tool } from "@opencode-ai/plugin";
|
||||
import { ToolSessionContextStore } from "../../src/session/toolContextStore.js";
|
||||
|
||||
const internalBaseUrl =
|
||||
process.env.TJWATER_AGENT_INTERNAL_BASE_URL ?? "http://127.0.0.1:8787";
|
||||
const internalToken = process.env.TJWATER_AGENT_INTERNAL_TOKEN ?? "";
|
||||
const toolContextStore = new ToolSessionContextStore();
|
||||
const initializePromise = toolContextStore.initialize();
|
||||
|
||||
export default tool({
|
||||
description:
|
||||
@@ -25,11 +22,6 @@ export default tool({
|
||||
.describe("Optional maximum number of hits to return."),
|
||||
},
|
||||
async execute(args, context) {
|
||||
await initializePromise;
|
||||
const sessionContext = await toolContextStore.read(context.sessionID);
|
||||
if (!sessionContext) {
|
||||
throw new Error(`session context not found for ${context.sessionID}`);
|
||||
}
|
||||
const response = await fetch(`${internalBaseUrl}/internal/tools/session-search`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -39,7 +31,7 @@ export default tool({
|
||||
body: JSON.stringify({
|
||||
max_results: args.max_results,
|
||||
query: args.query,
|
||||
sessionScopeKey: sessionContext.sessionScopeKey,
|
||||
session_id: context.sessionID,
|
||||
}),
|
||||
});
|
||||
const text = await response.text();
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { tool } from "@opencode-ai/plugin";
|
||||
import { ToolSessionContextStore } from "../../src/session/toolContextStore.js";
|
||||
|
||||
const internalBaseUrl = process.env.TJWATER_AGENT_INTERNAL_BASE_URL ?? "http://127.0.0.1:8787";
|
||||
const internalToken = process.env.TJWATER_AGENT_INTERNAL_TOKEN ?? "";
|
||||
const toolContextStore = new ToolSessionContextStore();
|
||||
const initializePromise = toolContextStore.initialize();
|
||||
|
||||
export default tool({
|
||||
description:
|
||||
@@ -20,11 +17,6 @@ export default tool({
|
||||
),
|
||||
},
|
||||
async execute(args, context) {
|
||||
await initializePromise;
|
||||
const sessionContext = await toolContextStore.read(context.sessionID);
|
||||
if (!sessionContext) {
|
||||
throw new Error(`session context not found for ${context.sessionID}`);
|
||||
}
|
||||
const response = await fetch(`${internalBaseUrl}/internal/tools/store-render-ref`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -32,7 +24,7 @@ export default tool({
|
||||
"x-agent-internal-token": internalToken,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sessionScopeKey: sessionContext.sessionScopeKey,
|
||||
session_id: context.sessionID,
|
||||
file_path: args.file_path,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { tool } from "@opencode-ai/plugin";
|
||||
import { ToolSessionContextStore } from "../../src/session/toolContextStore.js";
|
||||
|
||||
const internalBaseUrl = process.env.TJWATER_AGENT_INTERNAL_BASE_URL ?? "http://127.0.0.1:8787";
|
||||
const internalToken = process.env.TJWATER_AGENT_INTERNAL_TOKEN ?? "";
|
||||
const toolContextStore = new ToolSessionContextStore();
|
||||
const initializePromise = toolContextStore.initialize();
|
||||
|
||||
export default tool({
|
||||
description:
|
||||
@@ -21,14 +18,9 @@ export default tool({
|
||||
timeout: tool.schema
|
||||
.number()
|
||||
.optional()
|
||||
.describe("超时秒数,默认 60。大结果集建议设 120。"),
|
||||
.describe("超时秒数,默认 120。大结果集建议设 300+。"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
await initializePromise;
|
||||
const sessionContext = await toolContextStore.read(context.sessionID);
|
||||
if (!sessionContext) {
|
||||
throw new Error(`session context not found for ${context.sessionID}`);
|
||||
}
|
||||
const response = await fetch(`${internalBaseUrl}/internal/tools/tjwater-cli-call`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -36,7 +28,7 @@ export default tool({
|
||||
"x-agent-internal-token": internalToken,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sessionScopeKey: sessionContext.sessionScopeKey,
|
||||
session_id: context.sessionID,
|
||||
reason: args.reason,
|
||||
command: args.command,
|
||||
timeout: args.timeout,
|
||||
|
||||
Reference in New Issue
Block a user