fix(sdk): require session key for effective tools · openclaw/openclaw@e89c255
vincentkoc
·
2026-06-20
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,7 @@ import type {
|
29 | 29 | TasksGetResult, |
30 | 30 | TasksListParams, |
31 | 31 | TasksListResult, |
| 32 | +ToolsEffectiveParams, |
32 | 33 | ToolInvokeParams, |
33 | 34 | ToolInvokeResult, |
34 | 35 | } from "./types.js"; |
@@ -238,6 +239,18 @@ function requireArtifactQueryScope(api: string, params: unknown): ArtifactQuery
|
238 | 239 | return params; |
239 | 240 | } |
240 | 241 | |
| 242 | +function hasToolsEffectiveSessionKey(params: unknown): params is ToolsEffectiveParams { |
| 243 | +const record = asRecord(params); |
| 244 | +return typeof record.sessionKey === "string" && record.sessionKey.trim().length > 0; |
| 245 | +} |
| 246 | + |
| 247 | +function requireToolsEffectiveSessionKey(params: unknown): ToolsEffectiveParams { |
| 248 | +if (!hasToolsEffectiveSessionKey(params)) { |
| 249 | +throw new Error("oc.tools.effective requires sessionKey"); |
| 250 | +} |
| 251 | +return params; |
| 252 | +} |
| 253 | + |
241 | 254 | function readChatProjection(event: OpenClawEvent): ChatProjection | undefined { |
242 | 255 | const raw = event.raw; |
243 | 256 | if (event.type !== "raw" || raw?.event !== "chat") { |
@@ -861,8 +874,8 @@ export class ToolsNamespace extends RpcNamespace {
|
861 | 874 | return await this.call("catalog", params === undefined ? {} : params); |
862 | 875 | } |
863 | 876 | |
864 | | -async effective(params?: unknown): Promise<unknown> { |
865 | | -return await this.call("effective", params); |
| 877 | +async effective(params: ToolsEffectiveParams): Promise<unknown> { |
| 878 | +return await this.call("effective", requireToolsEffectiveSessionKey(params)); |
866 | 879 | } |
867 | 880 | |
868 | 881 | async invoke(name: string, params?: ToolInvokeParams): Promise<ToolInvokeResult> { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -739,6 +739,23 @@ describe("OpenClaw SDK", () => {
|
739 | 739 | ]); |
740 | 740 | }); |
741 | 741 | |
| 742 | +it("rejects tools.effective without a session key before RPC", async () => { |
| 743 | +type EffectiveMethod = (this: unknown, params?: unknown) => Promise<unknown>; |
| 744 | +const transport = new FakeTransport({ |
| 745 | +"tools.effective": { tools: [] }, |
| 746 | +}); |
| 747 | +const oc = new OpenClaw({ transport }); |
| 748 | + |
| 749 | +await expect((oc.tools.effective as unknown as EffectiveMethod).call(oc.tools)).rejects.toThrow( |
| 750 | +"oc.tools.effective requires sessionKey", |
| 751 | +); |
| 752 | +await expect( |
| 753 | +(oc.tools.effective as unknown as EffectiveMethod).call(oc.tools, {}), |
| 754 | +).rejects.toThrow("oc.tools.effective requires sessionKey"); |
| 755 | + |
| 756 | +expect(transport.calls).toEqual([]); |
| 757 | +}); |
| 758 | + |
742 | 759 | it("keeps close terminal when it races a pending connect", async () => { |
743 | 760 | const transport = new DelayedConnectTransport({ |
744 | 761 | "agents.list": { agents: [] }, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -56,6 +56,7 @@ export type {
|
56 | 56 | TasksGetResult, |
57 | 57 | TasksListParams, |
58 | 58 | TasksListResult, |
| 59 | +ToolsEffectiveParams, |
59 | 60 | ToolInvokeParams, |
60 | 61 | ToolInvokeResult, |
61 | 62 | WorkspaceSelection, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -192,6 +192,11 @@ export type SDKError = {
|
192 | 192 | }; |
193 | 193 | |
194 | 194 | /** Parameters for direct tool invocation through the SDK. */ |
| 195 | +export type ToolsEffectiveParams = { |
| 196 | +sessionKey: string; |
| 197 | +agentId?: string; |
| 198 | +}; |
| 199 | + |
195 | 200 | export type ToolInvokeParams = { |
196 | 201 | args?: JsonObject; |
197 | 202 | sessionKey?: string; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。