Skip to content

Commit 7cb6553

Browse files
committed
fix: pass injected config to session tools
1 parent 198c248 commit 7cb6553

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

src/agents/openclaw-tools.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,18 @@ export function createOpenClawTools(
174174
createSessionsListTool({
175175
agentSessionKey: options?.agentSessionKey,
176176
sandboxed: options?.sandboxed,
177+
config: options?.config,
177178
}),
178179
createSessionsHistoryTool({
179180
agentSessionKey: options?.agentSessionKey,
180181
sandboxed: options?.sandboxed,
182+
config: options?.config,
181183
}),
182184
createSessionsSendTool({
183185
agentSessionKey: options?.agentSessionKey,
184186
agentChannel: options?.agentChannel,
185187
sandboxed: options?.sandboxed,
188+
config: options?.config,
186189
}),
187190
createSessionsYieldTool({
188191
sessionId: options?.sessionId,

src/agents/tools/sessions-history-tool.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Type } from "@sinclair/typebox";
2-
import { loadConfig } from "../../config/config.js";
2+
import { type OpenClawConfig, loadConfig } from "../../config/config.js";
33
import { callGateway } from "../../gateway/call.js";
44
import { capArrayByJsonBytes } from "../../gateway/session-utils.fs.js";
55
import { jsonUtf8Bytes } from "../../infra/json-utf8-bytes.js";
@@ -169,6 +169,7 @@ function enforceSessionsHistoryHardCap(params: {
169169
export function createSessionsHistoryTool(opts?: {
170170
agentSessionKey?: string;
171171
sandboxed?: boolean;
172+
config?: OpenClawConfig;
172173
}): AnyAgentTool {
173174
return {
174175
label: "Session History",
@@ -180,7 +181,7 @@ export function createSessionsHistoryTool(opts?: {
180181
const sessionKeyParam = readStringParam(params, "sessionKey", {
181182
required: true,
182183
});
183-
const cfg = loadConfig();
184+
const cfg = opts?.config ?? loadConfig();
184185
const { mainKey, alias, effectiveRequesterKey, restrictToSpawned } =
185186
resolveSandboxedSessionToolContext({
186187
cfg,

src/agents/tools/sessions-list-tool.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from "node:path";
22
import { Type } from "@sinclair/typebox";
3-
import { loadConfig } from "../../config/config.js";
3+
import { type OpenClawConfig, loadConfig } from "../../config/config.js";
44
import {
55
resolveSessionFilePath,
66
resolveSessionFilePathOptions,
@@ -33,6 +33,7 @@ const SessionsListToolSchema = Type.Object({
3333
export function createSessionsListTool(opts?: {
3434
agentSessionKey?: string;
3535
sandboxed?: boolean;
36+
config?: OpenClawConfig;
3637
}): AnyAgentTool {
3738
return {
3839
label: "Sessions",
@@ -41,7 +42,7 @@ export function createSessionsListTool(opts?: {
4142
parameters: SessionsListToolSchema,
4243
execute: async (_toolCallId, args) => {
4344
const params = args as Record<string, unknown>;
44-
const cfg = loadConfig();
45+
const cfg = opts?.config ?? loadConfig();
4546
const { mainKey, alias, requesterInternalKey, restrictToSpawned } =
4647
resolveSandboxedSessionToolContext({
4748
cfg,

src/agents/tools/sessions-send-tool.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import crypto from "node:crypto";
22
import { Type } from "@sinclair/typebox";
3-
import { loadConfig } from "../../config/config.js";
3+
import { type OpenClawConfig, loadConfig } from "../../config/config.js";
44
import { callGateway } from "../../gateway/call.js";
55
import { normalizeAgentId, resolveAgentIdFromSessionKey } from "../../routing/session-key.js";
66
import { SESSION_LABEL_MAX_LENGTH } from "../../sessions/session-label.js";
@@ -36,6 +36,7 @@ export function createSessionsSendTool(opts?: {
3636
agentSessionKey?: string;
3737
agentChannel?: GatewayMessageChannel;
3838
sandboxed?: boolean;
39+
config?: OpenClawConfig;
3940
}): AnyAgentTool {
4041
return {
4142
label: "Session Send",
@@ -46,7 +47,7 @@ export function createSessionsSendTool(opts?: {
4647
execute: async (_toolCallId, args) => {
4748
const params = args as Record<string, unknown>;
4849
const message = readStringParam(params, "message", { required: true });
49-
const cfg = loadConfig();
50+
const cfg = opts?.config ?? loadConfig();
5051
const { mainKey, alias, effectiveRequesterKey, restrictToSpawned } =
5152
resolveSandboxedSessionToolContext({
5253
cfg,

src/gateway/server.sessions-send.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,18 @@ describe("sessions_send label lookup", () => {
184184
timeoutMs: 5000,
185185
});
186186

187-
const tool = getSessionsSendTool();
187+
const tool = createOpenClawTools({
188+
config: {
189+
tools: {
190+
sessions: {
191+
visibility: "all",
192+
},
193+
},
194+
},
195+
}).find((candidate) => candidate.name === "sessions_send");
196+
if (!tool) {
197+
throw new Error("missing sessions_send tool");
198+
}
188199

189200
// Send using label instead of sessionKey
190201
const result = await tool.execute("call-by-label", {

0 commit comments

Comments
 (0)