mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-14 15:38:33 +00:00
fix: preserve raw media invoke for HTTP tool clients (#34365)
This commit is contained in:
@@ -32,10 +32,18 @@ function unexpectedGatewayMethod(method: unknown): never {
|
||||
throw new Error(`unexpected method: ${String(method)}`);
|
||||
}
|
||||
|
||||
function getNodesTool(options?: { modelHasVision?: boolean }) {
|
||||
const tool = createOpenClawTools(
|
||||
options?.modelHasVision !== undefined ? { modelHasVision: options.modelHasVision } : {},
|
||||
).find((candidate) => candidate.name === "nodes");
|
||||
function getNodesTool(options?: { modelHasVision?: boolean; allowMediaInvokeCommands?: boolean }) {
|
||||
const toolOptions: {
|
||||
modelHasVision?: boolean;
|
||||
allowMediaInvokeCommands?: boolean;
|
||||
} = {};
|
||||
if (options?.modelHasVision !== undefined) {
|
||||
toolOptions.modelHasVision = options.modelHasVision;
|
||||
}
|
||||
if (options?.allowMediaInvokeCommands !== undefined) {
|
||||
toolOptions.allowMediaInvokeCommands = options.allowMediaInvokeCommands;
|
||||
}
|
||||
const tool = createOpenClawTools(toolOptions).find((candidate) => candidate.name === "nodes");
|
||||
if (!tool) {
|
||||
throw new Error("missing nodes tool");
|
||||
}
|
||||
@@ -44,7 +52,7 @@ function getNodesTool(options?: { modelHasVision?: boolean }) {
|
||||
|
||||
async function executeNodes(
|
||||
input: Record<string, unknown>,
|
||||
options?: { modelHasVision?: boolean },
|
||||
options?: { modelHasVision?: boolean; allowMediaInvokeCommands?: boolean },
|
||||
) {
|
||||
return getNodesTool(options).execute("call1", input as never);
|
||||
}
|
||||
@@ -777,4 +785,36 @@ describe("nodes invoke", () => {
|
||||
}),
|
||||
).rejects.toThrow(/use action="photos_latest"/i);
|
||||
});
|
||||
|
||||
it("allows media invoke commands when explicitly enabled", async () => {
|
||||
setupNodeInvokeMock({
|
||||
onInvoke: (invokeParams) => {
|
||||
expect(invokeParams).toMatchObject({
|
||||
command: "photos.latest",
|
||||
params: { limit: 1 },
|
||||
});
|
||||
return {
|
||||
payload: {
|
||||
photos: [{ format: "jpg", base64: "aGVsbG8=", width: 1, height: 1 }],
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const result = await executeNodes(
|
||||
{
|
||||
action: "invoke",
|
||||
node: NODE_ID,
|
||||
invokeCommand: "photos.latest",
|
||||
invokeParamsJson: '{"limit":1}',
|
||||
},
|
||||
{ allowMediaInvokeCommands: true },
|
||||
);
|
||||
|
||||
expect(result.details).toMatchObject({
|
||||
payload: {
|
||||
photos: [{ format: "jpg", base64: "aGVsbG8=", width: 1, height: 1 }],
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user