codesysultra 1.0.4 → 1.0.6
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/dist/handlers/tools.js +22 -0
- package/dist/templates/get_all_tools.py +143 -0
- package/dist/templates.js +2 -1
- package/package.json +1 -1
package/dist/handlers/tools.js
CHANGED
|
@@ -328,5 +328,27 @@ function registerTools(server, config) {
|
|
|
328
328
|
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
329
329
|
}
|
|
330
330
|
}));
|
|
331
|
+
server.tool("get_all_tools", // Tool Name
|
|
332
|
+
"Retrieves all available CODESYS script engine APIs, modules, POU types, and implementation languages.", // Tool Description
|
|
333
|
+
{
|
|
334
|
+
projectFilePath: zod_1.z.string().describe("Path to a CODESYS project file (e.g., 'C:/Projects/MyPLC.project'). Used for context, but the tool retrieves system APIs regardless of specific project.")
|
|
335
|
+
}, (args) => __awaiter(this, void 0, void 0, function* () {
|
|
336
|
+
const { projectFilePath } = args;
|
|
337
|
+
let absPath = path.normalize(path.isAbsolute(projectFilePath) ? projectFilePath : path.join(WORKSPACE_DIR, projectFilePath));
|
|
338
|
+
console.error(`Tool call: get_all_tools: ${absPath}`);
|
|
339
|
+
try {
|
|
340
|
+
const escapedPath = absPath.replace(/\\/g, '\\\\');
|
|
341
|
+
const script = templates_1.GET_ALL_TOOLS_SCRIPT_TEMPLATE.replace("{PROJECT_FILE_PATH}", escapedPath);
|
|
342
|
+
console.error(">>> get_all_tools: PREPARED SCRIPT:", script.substring(0, 500) + "...");
|
|
343
|
+
const result = yield (0, codesys_interop_1.executeCodesysScript)(script, codesysExePath, codesysProfileName);
|
|
344
|
+
console.error(">>> get_all_tools: EXECUTION RESULT:", JSON.stringify(result));
|
|
345
|
+
const success = result.success && result.output.includes("SCRIPT_SUCCESS");
|
|
346
|
+
return { content: [{ type: "text", text: success ? result.output : `Failed to get tools. Output:\n${result.output}` }], isError: !success };
|
|
347
|
+
}
|
|
348
|
+
catch (e) {
|
|
349
|
+
console.error(`Error get_all_tools ${absPath}: ${e}`);
|
|
350
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
351
|
+
}
|
|
352
|
+
}));
|
|
331
353
|
// --- End Tools ---
|
|
332
354
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import sys, scriptengine as script_engine, os, traceback, inspect, pkgutil
|
|
2
|
+
|
|
3
|
+
def get_codesys_system_api():
|
|
4
|
+
try:
|
|
5
|
+
print("\\n=== CODESYS Script Engine System API ===\\n")
|
|
6
|
+
|
|
7
|
+
print("=== Script Engine Modules ===")
|
|
8
|
+
print("scriptengine module:")
|
|
9
|
+
for name in dir(script_engine):
|
|
10
|
+
if not name.startswith('_'):
|
|
11
|
+
try:
|
|
12
|
+
obj = getattr(script_engine, name)
|
|
13
|
+
obj_type = type(obj).__name__
|
|
14
|
+
print(" %s (%s)" % (name, obj_type))
|
|
15
|
+
|
|
16
|
+
if inspect.isclass(obj):
|
|
17
|
+
try:
|
|
18
|
+
methods = [m for m in dir(obj) if not m.startswith('_') and callable(getattr(obj, m))]
|
|
19
|
+
if methods:
|
|
20
|
+
print(" Available methods:")
|
|
21
|
+
for method in sorted(methods)[:20]:
|
|
22
|
+
print(" - %s" % method)
|
|
23
|
+
if len(methods) > 20:
|
|
24
|
+
print(" ... and %d more" % (len(methods) - 20))
|
|
25
|
+
except Exception as e:
|
|
26
|
+
print(" Error listing methods: %s" % e)
|
|
27
|
+
except Exception as e:
|
|
28
|
+
print(" Error: %s" % e)
|
|
29
|
+
except Exception as e:
|
|
30
|
+
print(" Error: %s" % e)
|
|
31
|
+
|
|
32
|
+
print("\\n=== Script Engine Functions ===")
|
|
33
|
+
script_functions = []
|
|
34
|
+
for name in dir(script_engine):
|
|
35
|
+
if not name.startswith('_') and callable(getattr(script_engine, name)):
|
|
36
|
+
script_functions.append(name)
|
|
37
|
+
|
|
38
|
+
for func in sorted(script_functions):
|
|
39
|
+
print(" - %s()" % func)
|
|
40
|
+
|
|
41
|
+
print("\\n=== Available Enums ===")
|
|
42
|
+
try:
|
|
43
|
+
enums = []
|
|
44
|
+
for name in dir(script_engine):
|
|
45
|
+
obj = getattr(script_engine, name)
|
|
46
|
+
if inspect.isclass(obj) and issubclass(obj, int):
|
|
47
|
+
enums.append((name, obj))
|
|
48
|
+
|
|
49
|
+
for enum_name, enum_obj in sorted(enums):
|
|
50
|
+
print("\\n%s:" % enum_name)
|
|
51
|
+
try:
|
|
52
|
+
members = [(name, value) for name, value in enum_obj.__dict__.items() if not name.startswith('_')]
|
|
53
|
+
for member_name, member_value in sorted(members, key=lambda x: x[0]):
|
|
54
|
+
print(" %s = %s" % (member_name, member_value))
|
|
55
|
+
except Exception as e:
|
|
56
|
+
print(" Error: %s" % e)
|
|
57
|
+
except Exception as e:
|
|
58
|
+
print(" Error listing enums: %s" % e)
|
|
59
|
+
|
|
60
|
+
print("\\n=== Project Management ===")
|
|
61
|
+
print("script_engine.projects module functions:")
|
|
62
|
+
project_functions = []
|
|
63
|
+
for name in dir(script_engine.projects):
|
|
64
|
+
if not name.startswith('_') and callable(getattr(script_engine.projects, name)):
|
|
65
|
+
project_functions.append(name)
|
|
66
|
+
|
|
67
|
+
for func in sorted(project_functions):
|
|
68
|
+
print(" - %s()" % func)
|
|
69
|
+
|
|
70
|
+
print("\\n=== POU Types ===")
|
|
71
|
+
try:
|
|
72
|
+
pou_types = []
|
|
73
|
+
for name in dir(script_engine):
|
|
74
|
+
obj = getattr(script_engine, name)
|
|
75
|
+
if inspect.isclass(obj) and 'PouType' in name:
|
|
76
|
+
pou_types.append((name, obj))
|
|
77
|
+
|
|
78
|
+
for type_name, type_obj in pou_types:
|
|
79
|
+
print(" %s:" % type_name)
|
|
80
|
+
try:
|
|
81
|
+
values = [(name, getattr(type_obj, name)) for name in dir(type_obj) if not name.startswith('_') and name.isupper()]
|
|
82
|
+
for value_name, value_value in values:
|
|
83
|
+
print(" %s = %s" % (value_name, value_value))
|
|
84
|
+
except Exception as e:
|
|
85
|
+
print(" Error: %s" % e)
|
|
86
|
+
except Exception as e:
|
|
87
|
+
print(" Error: %s" % e)
|
|
88
|
+
|
|
89
|
+
print("\\n=== Implementation Languages ===")
|
|
90
|
+
try:
|
|
91
|
+
impl_langs = []
|
|
92
|
+
for name in dir(script_engine):
|
|
93
|
+
obj = getattr(script_engine, name)
|
|
94
|
+
if inspect.isclass(obj) and 'ImplementationLanguage' in name:
|
|
95
|
+
impl_langs.append((name, obj))
|
|
96
|
+
|
|
97
|
+
for lang_name, lang_obj in impl_langs:
|
|
98
|
+
print(" %s:" % lang_name)
|
|
99
|
+
try:
|
|
100
|
+
values = [(name, getattr(lang_obj, name)) for name in dir(lang_obj) if not name.startswith('_') and name.isupper()]
|
|
101
|
+
for value_name, value_value in values:
|
|
102
|
+
print(" %s = %s" % (value_name, value_value))
|
|
103
|
+
except Exception as e:
|
|
104
|
+
print(" Error: %s" % e)
|
|
105
|
+
except Exception as e:
|
|
106
|
+
print(" Error: %s" % e)
|
|
107
|
+
|
|
108
|
+
print("\\n=== Version Info ===")
|
|
109
|
+
try:
|
|
110
|
+
version = getattr(script_engine, '__version__', 'Unknown')
|
|
111
|
+
print(" Script Engine Version: %s" % version)
|
|
112
|
+
except Exception as e:
|
|
113
|
+
print(" Error getting version: %s" % e)
|
|
114
|
+
|
|
115
|
+
print("\\n=== API Usage Examples ===")
|
|
116
|
+
print("Example 1: Open a project")
|
|
117
|
+
print(" project = script_engine.projects.open('C:/Projects/MyProject.project')")
|
|
118
|
+
print("")
|
|
119
|
+
print("Example 2: Create a POU")
|
|
120
|
+
print(" parent = project.get_children()[0]")
|
|
121
|
+
print(" pou = parent.create_pou(name='MyPOU', type=script_engine.PouType.Program)")
|
|
122
|
+
print("")
|
|
123
|
+
print("Example 3: Get project structure")
|
|
124
|
+
print(" def analyze(obj, indent=0):")
|
|
125
|
+
print(" print(' ' * indent + obj.get_name())")
|
|
126
|
+
print(" if hasattr(obj, 'get_children'):")
|
|
127
|
+
print(" for child in obj.get_children():")
|
|
128
|
+
print(" analyze(child, indent+1)")
|
|
129
|
+
print(" analyze(project)")
|
|
130
|
+
|
|
131
|
+
print("\\n=== Analysis Complete ===")
|
|
132
|
+
print("SCRIPT_SUCCESS: CODESYS system API retrieved successfully.")
|
|
133
|
+
sys.exit(0)
|
|
134
|
+
|
|
135
|
+
except Exception as e:
|
|
136
|
+
detailed_error = traceback.format_exc()
|
|
137
|
+
error_message = "Error retrieving CODESYS system API: %s\\n%s" % (e, detailed_error)
|
|
138
|
+
print(error_message)
|
|
139
|
+
print("SCRIPT_ERROR: %s" % error_message)
|
|
140
|
+
sys.exit(1)
|
|
141
|
+
|
|
142
|
+
if __name__ == "__main__":
|
|
143
|
+
get_codesys_system_api()
|
package/dist/templates.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GET_POU_CODE_SCRIPT_TEMPLATE = exports.CREATE_METHOD_SCRIPT_TEMPLATE = exports.CREATE_PROPERTY_SCRIPT_TEMPLATE = exports.SET_POU_CODE_SCRIPT_TEMPLATE = exports.CREATE_POU_SCRIPT_TEMPLATE = exports.GET_PROJECT_STRUCTURE_SCRIPT_TEMPLATE = exports.COMPILE_PROJECT_SCRIPT_TEMPLATE = exports.SAVE_PROJECT_SCRIPT_TEMPLATE = exports.OPEN_PROJECT_SCRIPT_TEMPLATE = exports.CREATE_PROJECT_SCRIPT_TEMPLATE = exports.CHECK_STATUS_SCRIPT = exports.FIND_OBJECT_BY_PATH_PYTHON_SNIPPET = exports.ENSURE_PROJECT_OPEN_PYTHON_SNIPPET = void 0;
|
|
6
|
+
exports.GET_POU_CODE_SCRIPT_TEMPLATE = exports.CREATE_METHOD_SCRIPT_TEMPLATE = exports.CREATE_PROPERTY_SCRIPT_TEMPLATE = exports.SET_POU_CODE_SCRIPT_TEMPLATE = exports.CREATE_POU_SCRIPT_TEMPLATE = exports.GET_ALL_TOOLS_SCRIPT_TEMPLATE = exports.GET_PROJECT_STRUCTURE_SCRIPT_TEMPLATE = exports.COMPILE_PROJECT_SCRIPT_TEMPLATE = exports.SAVE_PROJECT_SCRIPT_TEMPLATE = exports.OPEN_PROJECT_SCRIPT_TEMPLATE = exports.CREATE_PROJECT_SCRIPT_TEMPLATE = exports.CHECK_STATUS_SCRIPT = exports.FIND_OBJECT_BY_PATH_PYTHON_SNIPPET = exports.ENSURE_PROJECT_OPEN_PYTHON_SNIPPET = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const templatesDir = path_1.default.join(__dirname, 'templates');
|
|
@@ -35,6 +35,7 @@ exports.OPEN_PROJECT_SCRIPT_TEMPLATE = injectDependencies(readTemplate('open_pro
|
|
|
35
35
|
exports.SAVE_PROJECT_SCRIPT_TEMPLATE = injectDependencies(readTemplate('save_project.py'));
|
|
36
36
|
exports.COMPILE_PROJECT_SCRIPT_TEMPLATE = injectDependencies(readTemplate('compile_project.py'));
|
|
37
37
|
exports.GET_PROJECT_STRUCTURE_SCRIPT_TEMPLATE = injectDependencies(readTemplate('get_project_structure.py'));
|
|
38
|
+
exports.GET_ALL_TOOLS_SCRIPT_TEMPLATE = readTemplate('get_all_tools.py');
|
|
38
39
|
exports.CREATE_POU_SCRIPT_TEMPLATE = injectDependencies(readTemplate('create_pou.py'));
|
|
39
40
|
exports.SET_POU_CODE_SCRIPT_TEMPLATE = injectDependencies(readTemplate('set_pou_code.py'));
|
|
40
41
|
exports.CREATE_PROPERTY_SCRIPT_TEMPLATE = injectDependencies(readTemplate('create_property.py'));
|