@vincentwei1021/synapse-openclaw-plugin 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -0
- package/openclaw.plugin.json +28 -0
- package/package.json +37 -0
- package/src/commands.ts +151 -0
- package/src/config.ts +56 -0
- package/src/event-router.test.ts +265 -0
- package/src/event-router.ts +360 -0
- package/src/index.ts +152 -0
- package/src/mcp-client.test.ts +130 -0
- package/src/mcp-client.ts +144 -0
- package/src/sse-listener.test.ts +150 -0
- package/src/sse-listener.ts +184 -0
- package/src/tools/common-tool-definitions.ts +681 -0
- package/src/tools/common-tools.ts +8 -0
- package/src/tools/tool-registry.ts +68 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { SynapseMcpClient } from "../mcp-client.js";
|
|
2
|
+
|
|
3
|
+
export interface OpenClawObjectSchema {
|
|
4
|
+
type: "object";
|
|
5
|
+
properties: Record<string, unknown>;
|
|
6
|
+
required?: string[];
|
|
7
|
+
additionalProperties?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface OpenClawToolDefinition {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
parameters: OpenClawObjectSchema;
|
|
14
|
+
execute: (mcpClient: SynapseMcpClient, args: Record<string, unknown>) => Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface OpenClawToolApi {
|
|
18
|
+
registerTool(definition: {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
parameters: OpenClawObjectSchema;
|
|
22
|
+
execute: (_id: string, args: Record<string, unknown>) => Promise<string>;
|
|
23
|
+
}): void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function registerOpenClawTools(
|
|
27
|
+
api: OpenClawToolApi,
|
|
28
|
+
mcpClient: SynapseMcpClient,
|
|
29
|
+
definitions: readonly OpenClawToolDefinition[]
|
|
30
|
+
) {
|
|
31
|
+
definitions.forEach((definition) => {
|
|
32
|
+
api.registerTool({
|
|
33
|
+
name: definition.name,
|
|
34
|
+
description: definition.description,
|
|
35
|
+
parameters: definition.parameters,
|
|
36
|
+
async execute(_id: string, args: Record<string, unknown>) {
|
|
37
|
+
const result = await definition.execute(mcpClient, args);
|
|
38
|
+
return JSON.stringify(result, null, 2);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function defineOpenClawTools<const TDefinitions extends readonly OpenClawToolDefinition[]>(
|
|
45
|
+
definitions: TDefinitions
|
|
46
|
+
): TDefinitions {
|
|
47
|
+
return definitions;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createPassthroughTool<TArgs extends Record<string, unknown> = Record<string, unknown>>(definition: {
|
|
51
|
+
name: string;
|
|
52
|
+
description: string;
|
|
53
|
+
parameters: OpenClawObjectSchema;
|
|
54
|
+
targetToolName: string;
|
|
55
|
+
mapArgs?: (args: TArgs) => Record<string, unknown>;
|
|
56
|
+
}): OpenClawToolDefinition {
|
|
57
|
+
return {
|
|
58
|
+
name: definition.name,
|
|
59
|
+
description: definition.description,
|
|
60
|
+
parameters: definition.parameters,
|
|
61
|
+
async execute(mcpClient, args) {
|
|
62
|
+
return mcpClient.callTool(
|
|
63
|
+
definition.targetToolName,
|
|
64
|
+
definition.mapArgs ? definition.mapArgs(args as TArgs) : args
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|