@milaboratories/pl-mcp-server 52.1.0 → 53.1.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 +31 -0
- package/dist/instructions.cjs +2 -1
- package/dist/instructions.cjs.map +1 -1
- package/dist/instructions.js +2 -1
- package/dist/instructions.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/server-log.cjs +365 -0
- package/dist/server-log.cjs.map +1 -0
- package/dist/server-log.js +363 -0
- package/dist/server-log.js.map +1 -0
- package/dist/server.cjs +49 -15
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +12 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +49 -15
- package/dist/server.js.map +1 -1
- package/dist/tools/await.cjs +4 -6
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +5 -7
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js.map +1 -1
- package/dist/tools/block-api.cjs +23 -0
- package/dist/tools/block-api.cjs.map +1 -0
- package/dist/tools/block-api.js +22 -0
- package/dist/tools/block-api.js.map +1 -0
- package/dist/tools/block-params.cjs +21 -0
- package/dist/tools/block-params.cjs.map +1 -0
- package/dist/tools/block-params.js +21 -0
- package/dist/tools/block-params.js.map +1 -0
- package/dist/tools/block-state.cjs +2 -2
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +3 -3
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/blocks.cjs +78 -20
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +78 -21
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/connection.cjs.map +1 -1
- package/dist/tools/connection.js.map +1 -1
- package/dist/tools/data-query.cjs +1 -1
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +2 -2
- package/dist/tools/data-query.js.map +1 -1
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/ping.cjs.map +1 -1
- package/dist/tools/ping.js.map +1 -1
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/sandbox.cjs +110 -8
- package/dist/tools/sandbox.cjs.map +1 -1
- package/dist/tools/sandbox.js +107 -9
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/screenshot.cjs +9 -1
- package/dist/tools/screenshot.cjs.map +1 -1
- package/dist/tools/screenshot.js +9 -1
- package/dist/tools/screenshot.js.map +1 -1
- package/dist/tools/types.cjs +29 -0
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.js +27 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/ui-interaction.cjs.map +1 -1
- package/dist/tools/ui-interaction.js.map +1 -1
- package/package.json +5 -4
- package/src/instructions.ts +2 -1
- package/src/server-log.test.ts +859 -0
- package/src/server-log.ts +495 -0
- package/src/server.logging.test.ts +380 -0
- package/src/server.request-failure.test.ts +49 -0
- package/src/server.test.ts +4 -2
- package/src/server.ts +70 -15
- package/src/test/recording-logger.ts +33 -0
- package/src/tools/await.ts +7 -10
- package/src/tools/block-action-context.ts +2 -3
- package/src/tools/block-api.ts +24 -0
- package/src/tools/block-params.ts +29 -0
- package/src/tools/block-state.ts +5 -6
- package/src/tools/blocks.test.ts +148 -0
- package/src/tools/blocks.ts +162 -34
- package/src/tools/connection.ts +2 -3
- package/src/tools/data-query.ts +5 -6
- package/src/tools/logs.ts +2 -3
- package/src/tools/ping.ts +2 -3
- package/src/tools/projects.ts +2 -3
- package/src/tools/sandbox.test.ts +183 -0
- package/src/tools/sandbox.ts +126 -10
- package/src/tools/screenshot.ts +15 -4
- package/src/tools/types.test.ts +4 -3
- package/src/tools/types.ts +65 -2
- package/src/tools/ui-interaction.ts +2 -3
package/dist/tools/sandbox.js
CHANGED
|
@@ -10,32 +10,130 @@ async function getRuntime() {
|
|
|
10
10
|
}
|
|
11
11
|
return sharedRuntime;
|
|
12
12
|
}
|
|
13
|
+
/** File name the expression is evaluated under. QuickJS puts it into the syntax errors of the expression's own text. */
|
|
14
|
+
const EXPRESSION_FILE = "transform.js";
|
|
15
|
+
const SINGLE_EXPRESSION_HINT = "A transform is a single expression; to run several statements, wrap them in an immediately invoked function: (() => { ...; return value; })()";
|
|
16
|
+
/**
|
|
17
|
+
* The classes of the errors built into the JavaScript of the sandbox. Only these names are used as
|
|
18
|
+
* the class of a failure: code can give an error any name, data included.
|
|
19
|
+
*/
|
|
20
|
+
const BUILT_IN_ERRORS = /* @__PURE__ */ new Set([
|
|
21
|
+
"Error",
|
|
22
|
+
"AggregateError",
|
|
23
|
+
"EvalError",
|
|
24
|
+
"InternalError",
|
|
25
|
+
"RangeError",
|
|
26
|
+
"ReferenceError",
|
|
27
|
+
"SyntaxError",
|
|
28
|
+
"TypeError",
|
|
29
|
+
"URIError"
|
|
30
|
+
]);
|
|
31
|
+
/**
|
|
32
|
+
* What kind of failure an error is, in words that hold nothing of the code or its data: the name of
|
|
33
|
+
* a built-in error class, or `Error` for any other name.
|
|
34
|
+
*/
|
|
35
|
+
function errorClassOf(name) {
|
|
36
|
+
return BUILT_IN_ERRORS.has(name) ? name : "Error";
|
|
37
|
+
}
|
|
38
|
+
/** The class of the failure of an evaluation that threw a value that is not an error. */
|
|
39
|
+
const THROWN_VALUE = "Thrown value";
|
|
40
|
+
/** The class of the failure of an evaluation that ran out of time. */
|
|
41
|
+
const TIMEOUT = "timeout";
|
|
42
|
+
/**
|
|
43
|
+
* Thrown by {@link safeEval} when the evaluation fails. The message is the whole error, for the
|
|
44
|
+
* agent; `errorClass` says only what kind of failure it was, for code that treats one kind apart.
|
|
45
|
+
*/
|
|
46
|
+
var SandboxError = class extends Error {
|
|
47
|
+
/** See {@link errorClassOf}, {@link THROWN_VALUE} and {@link TIMEOUT}. */
|
|
48
|
+
errorClass;
|
|
49
|
+
constructor(message, errorClass) {
|
|
50
|
+
super(message);
|
|
51
|
+
this.name = "SandboxError";
|
|
52
|
+
this.errorClass = errorClass;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Reads a thrown value from what `QuickJSContext.dump` returns for it. An error comes as a plain object
|
|
57
|
+
* `{ name, message, stack }`, a syntax error also carries `fileName` and `lineNumber`: the name of the evaluated file
|
|
58
|
+
* when the code did not parse, `<input>` when `JSON.parse` or `eval` failed at run time. Any other thrown value comes
|
|
59
|
+
* as itself: a primitive, or an object that went through JSON.
|
|
60
|
+
*/
|
|
61
|
+
function parseThrown(dumped) {
|
|
62
|
+
if (typeof dumped === "object" && dumped !== null && "name" in dumped && "message" in dumped) {
|
|
63
|
+
const { name, message } = dumped;
|
|
64
|
+
if (typeof name === "string" && typeof message === "string") {
|
|
65
|
+
const label = name === "" ? "Error" : name;
|
|
66
|
+
const text = message === "" ? label : `${label}: ${message}`;
|
|
67
|
+
const errorClass = errorClassOf(name);
|
|
68
|
+
if (name === "SyntaxError" && "fileName" in dumped && typeof dumped.fileName === "string") return {
|
|
69
|
+
text,
|
|
70
|
+
errorClass,
|
|
71
|
+
syntaxErrorFile: dumped.fileName
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
text,
|
|
75
|
+
errorClass
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const errorClass = THROWN_VALUE;
|
|
80
|
+
if (typeof dumped === "string") return {
|
|
81
|
+
text: `${THROWN_VALUE}: ${dumped}`,
|
|
82
|
+
errorClass
|
|
83
|
+
};
|
|
84
|
+
if (typeof dumped === "object" && dumped !== null) {
|
|
85
|
+
const json = JSON.stringify(dumped, (_key, value) => typeof value === "bigint" ? `${value}n` : value);
|
|
86
|
+
return {
|
|
87
|
+
text: `${THROWN_VALUE}: ${json}`,
|
|
88
|
+
errorClass
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
text: `${THROWN_VALUE}: ${String(dumped)}`,
|
|
93
|
+
errorClass
|
|
94
|
+
};
|
|
95
|
+
}
|
|
13
96
|
/**
|
|
14
97
|
* Evaluate a JS expression in a QuickJS sandbox.
|
|
15
98
|
* Variables from `context` are injected as globals.
|
|
16
99
|
* Data is marshaled via JSON — no access to Node APIs, filesystem, or process.
|
|
100
|
+
*
|
|
101
|
+
* A failed evaluation throws a {@link SandboxError} whose message is the error as QuickJS reports it (`Name: message`),
|
|
102
|
+
* with a hint on writing several statements when the expression does not parse. An evaluation that runs longer than
|
|
103
|
+
* `timeout` milliseconds throws a {@link SandboxError} saying that it timed out.
|
|
17
104
|
*/
|
|
18
105
|
async function safeEval(expression, context, timeout) {
|
|
19
106
|
const runtime = await getRuntime();
|
|
20
107
|
const deadline = Date.now() + timeout;
|
|
21
|
-
|
|
108
|
+
let timedOut = false;
|
|
109
|
+
runtime.setInterruptHandler(() => {
|
|
110
|
+
if (Date.now() > deadline) timedOut = true;
|
|
111
|
+
return timedOut;
|
|
112
|
+
});
|
|
113
|
+
const timeoutMessage = `Evaluation timed out after ${timeout} ms`;
|
|
22
114
|
const vm = runtime.newContext();
|
|
115
|
+
/** Reads the error of a failed evaluation and releases its handle. `undefined` when the timeout stopped the code. */
|
|
116
|
+
const takeThrown = (error) => {
|
|
117
|
+
const dumped = vm.dump(error);
|
|
118
|
+
if (error.alive) error.dispose();
|
|
119
|
+
return timedOut ? void 0 : parseThrown(dumped);
|
|
120
|
+
};
|
|
23
121
|
try {
|
|
24
122
|
const contextJson = JSON.stringify(context);
|
|
25
123
|
const setup = `const __ctx = JSON.parse(${JSON.stringify(contextJson)});
|
|
26
124
|
${Object.keys(context).map((k) => `const ${k} = __ctx[${JSON.stringify(k)}];`).join("\n")}`;
|
|
27
125
|
const setupResult = vm.evalCode(setup, "setup.js", { type: "global" });
|
|
28
126
|
if (setupResult.error) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
throw new
|
|
127
|
+
const thrown = takeThrown(setupResult.error);
|
|
128
|
+
if (!thrown) throw new SandboxError(timeoutMessage, TIMEOUT);
|
|
129
|
+
throw new SandboxError(`Context setup failed: ${thrown.text}`, thrown.errorClass);
|
|
32
130
|
}
|
|
33
131
|
setupResult.value.dispose();
|
|
34
|
-
const result = vm.evalCode(`JSON.stringify((${expression}))`,
|
|
132
|
+
const result = vm.evalCode(`JSON.stringify((${expression}))`, EXPRESSION_FILE);
|
|
35
133
|
if (result.error) {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
throw new
|
|
134
|
+
const thrown = takeThrown(result.error);
|
|
135
|
+
if (!thrown) throw new SandboxError(timeoutMessage, TIMEOUT);
|
|
136
|
+
throw new SandboxError(thrown.syntaxErrorFile === EXPRESSION_FILE ? `${thrown.text}. ${SINGLE_EXPRESSION_HINT}` : thrown.text, thrown.errorClass);
|
|
39
137
|
}
|
|
40
138
|
const json = vm.getString(result.value);
|
|
41
139
|
result.value.dispose();
|
|
@@ -45,6 +143,6 @@ ${Object.keys(context).map((k) => `const ${k} = __ctx[${JSON.stringify(k)}];`).j
|
|
|
45
143
|
vm.dispose();
|
|
46
144
|
}
|
|
47
145
|
}
|
|
48
|
-
export { safeEval };
|
|
146
|
+
export { SandboxError, THROWN_VALUE, TIMEOUT, errorClassOf, safeEval };
|
|
49
147
|
|
|
50
148
|
//# sourceMappingURL=sandbox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox.js","names":[],"sources":["../../src/tools/sandbox.ts"],"sourcesContent":["import { getQuickJS, type QuickJSRuntime } from \"quickjs-emscripten\";\n\n/** Lazily initialized QuickJS runtime shared across evaluations. */\nlet sharedRuntime: QuickJSRuntime | undefined;\n\nasync function getRuntime(): Promise<QuickJSRuntime> {\n if (!sharedRuntime) {\n const quickjs = await getQuickJS();\n sharedRuntime = quickjs.newRuntime();\n sharedRuntime.setMemoryLimit(1024 * 1024 * 16); // 16 MB\n sharedRuntime.setMaxStackSize(1024 * 320);\n }\n return sharedRuntime;\n}\n\n/**\n * Evaluate a JS expression in a QuickJS sandbox.\n * Variables from `context` are injected as globals.\n * Data is marshaled via JSON — no access to Node APIs, filesystem, or process.\n */\nexport async function safeEval(\n expression: string,\n context: Record<string, unknown>,\n timeout: number,\n): Promise<unknown> {\n const runtime = await getRuntime();\n\n // Set interrupt handler for timeout
|
|
1
|
+
{"version":3,"file":"sandbox.js","names":[],"sources":["../../src/tools/sandbox.ts"],"sourcesContent":["import { getQuickJS, type QuickJSHandle, type QuickJSRuntime } from \"quickjs-emscripten\";\n\n/** Lazily initialized QuickJS runtime shared across evaluations. */\nlet sharedRuntime: QuickJSRuntime | undefined;\n\nasync function getRuntime(): Promise<QuickJSRuntime> {\n if (!sharedRuntime) {\n const quickjs = await getQuickJS();\n sharedRuntime = quickjs.newRuntime();\n sharedRuntime.setMemoryLimit(1024 * 1024 * 16); // 16 MB\n sharedRuntime.setMaxStackSize(1024 * 320);\n }\n return sharedRuntime;\n}\n\n/** File name the expression is evaluated under. QuickJS puts it into the syntax errors of the expression's own text. */\nconst EXPRESSION_FILE = \"transform.js\";\n\nconst SINGLE_EXPRESSION_HINT =\n \"A transform is a single expression; to run several statements, wrap them in an immediately invoked function: (() => { ...; return value; })()\";\n\n/**\n * The classes of the errors built into the JavaScript of the sandbox. Only these names are used as\n * the class of a failure: code can give an error any name, data included.\n */\nconst BUILT_IN_ERRORS: ReadonlySet<string> = new Set([\n \"Error\",\n \"AggregateError\",\n \"EvalError\",\n \"InternalError\",\n \"RangeError\",\n \"ReferenceError\",\n \"SyntaxError\",\n \"TypeError\",\n \"URIError\",\n]);\n\n/**\n * What kind of failure an error is, in words that hold nothing of the code or its data: the name of\n * a built-in error class, or `Error` for any other name.\n */\nexport function errorClassOf(name: string): string {\n return BUILT_IN_ERRORS.has(name) ? name : \"Error\";\n}\n\n/** The class of the failure of an evaluation that threw a value that is not an error. */\nexport const THROWN_VALUE = \"Thrown value\";\n\n/** The class of the failure of an evaluation that ran out of time. */\nexport const TIMEOUT = \"timeout\";\n\n/**\n * Thrown by {@link safeEval} when the evaluation fails. The message is the whole error, for the\n * agent; `errorClass` says only what kind of failure it was, for code that treats one kind apart.\n */\nexport class SandboxError extends Error {\n /** See {@link errorClassOf}, {@link THROWN_VALUE} and {@link TIMEOUT}. */\n readonly errorClass: string;\n\n constructor(message: string, errorClass: string) {\n super(message);\n this.name = \"SandboxError\";\n this.errorClass = errorClass;\n }\n}\n\n/** A value thrown inside the sandbox. */\ntype Thrown = {\n /** `Name: message` of an error, or the thrown value itself when it is not an error. */\n text: string;\n /** See {@link SandboxError.errorClass}. */\n errorClass: string;\n /** For a syntax error: the file whose text failed to parse, as QuickJS names it. */\n syntaxErrorFile?: string;\n};\n\n/**\n * Reads a thrown value from what `QuickJSContext.dump` returns for it. An error comes as a plain object\n * `{ name, message, stack }`, a syntax error also carries `fileName` and `lineNumber`: the name of the evaluated file\n * when the code did not parse, `<input>` when `JSON.parse` or `eval` failed at run time. Any other thrown value comes\n * as itself: a primitive, or an object that went through JSON.\n */\nfunction parseThrown(dumped: unknown): Thrown {\n if (typeof dumped === \"object\" && dumped !== null && \"name\" in dumped && \"message\" in dumped) {\n const { name, message } = dumped;\n if (typeof name === \"string\" && typeof message === \"string\") {\n // An error with neither a name nor a message still reads as an error.\n const label = name === \"\" ? \"Error\" : name;\n const text = message === \"\" ? label : `${label}: ${message}`;\n const errorClass = errorClassOf(name);\n if (name === \"SyntaxError\" && \"fileName\" in dumped && typeof dumped.fileName === \"string\")\n return { text, errorClass, syntaxErrorFile: dumped.fileName };\n return { text, errorClass };\n }\n }\n const errorClass = THROWN_VALUE;\n if (typeof dumped === \"string\") return { text: `${THROWN_VALUE}: ${dumped}`, errorClass };\n if (typeof dumped === \"object\" && dumped !== null) {\n // A thrown promise is dumped as its state, and the settled value can be a bigint.\n const json = JSON.stringify(dumped, (_key, value: unknown) =>\n typeof value === \"bigint\" ? `${value}n` : value,\n );\n return { text: `${THROWN_VALUE}: ${json}`, errorClass };\n }\n return { text: `${THROWN_VALUE}: ${String(dumped)}`, errorClass };\n}\n\n/**\n * Evaluate a JS expression in a QuickJS sandbox.\n * Variables from `context` are injected as globals.\n * Data is marshaled via JSON — no access to Node APIs, filesystem, or process.\n *\n * A failed evaluation throws a {@link SandboxError} whose message is the error as QuickJS reports it (`Name: message`),\n * with a hint on writing several statements when the expression does not parse. An evaluation that runs longer than\n * `timeout` milliseconds throws a {@link SandboxError} saying that it timed out.\n */\nexport async function safeEval(\n expression: string,\n context: Record<string, unknown>,\n timeout: number,\n): Promise<unknown> {\n const runtime = await getRuntime();\n\n // Set interrupt handler for timeout. QuickJS reports an interrupted evaluation as `InternalError: interrupted`,\n // so the flag is what tells a timeout from an error of the code itself.\n const deadline = Date.now() + timeout;\n let timedOut = false;\n runtime.setInterruptHandler(() => {\n if (Date.now() > deadline) timedOut = true;\n return timedOut;\n });\n const timeoutMessage = `Evaluation timed out after ${timeout} ms`;\n\n const vm = runtime.newContext();\n\n /** Reads the error of a failed evaluation and releases its handle. `undefined` when the timeout stopped the code. */\n const takeThrown = (error: QuickJSHandle): Thrown | undefined => {\n const dumped: unknown = vm.dump(error);\n // `dump` releases the handle itself when the thrown value is a promise.\n if (error.alive) error.dispose();\n return timedOut ? undefined : parseThrown(dumped);\n };\n\n try {\n // Inject context variables via JSON\n const contextJson = JSON.stringify(context);\n const setup = `const __ctx = JSON.parse(${JSON.stringify(contextJson)});\n${Object.keys(context)\n .map((k) => `const ${k} = __ctx[${JSON.stringify(k)}];`)\n .join(\"\\n\")}`;\n const setupResult = vm.evalCode(setup, \"setup.js\", { type: \"global\" });\n if (setupResult.error) {\n const thrown = takeThrown(setupResult.error);\n if (!thrown) throw new SandboxError(timeoutMessage, TIMEOUT);\n throw new SandboxError(`Context setup failed: ${thrown.text}`, thrown.errorClass);\n }\n setupResult.value.dispose();\n\n // Evaluate the expression\n const result = vm.evalCode(`JSON.stringify((${expression}))`, EXPRESSION_FILE);\n if (result.error) {\n const thrown = takeThrown(result.error);\n if (!thrown) throw new SandboxError(timeoutMessage, TIMEOUT);\n throw new SandboxError(\n thrown.syntaxErrorFile === EXPRESSION_FILE\n ? `${thrown.text}. ${SINGLE_EXPRESSION_HINT}`\n : thrown.text,\n thrown.errorClass,\n );\n }\n const json = vm.getString(result.value);\n result.value.dispose();\n return JSON.parse(json);\n } finally {\n runtime.setInterruptHandler(() => false);\n vm.dispose();\n }\n}\n"],"mappings":";;;AAGA,IAAI;AAEJ,eAAe,aAAsC;CACnD,IAAI,CAAC,eAAe;EAElB,iBAAgB,MADM,WAAW,EAAA,CACT,WAAW;EACnC,cAAc,eAAe,QAAgB;EAC7C,cAAc,gBAAgB,MAAU;CAC1C;CACA,OAAO;AACT;;AAGA,MAAM,kBAAkB;AAExB,MAAM,yBACJ;;;;;AAMF,MAAM,kCAAuC,IAAI,IAAI;CACnD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;AAMD,SAAgB,aAAa,MAAsB;CACjD,OAAO,gBAAgB,IAAI,IAAI,IAAI,OAAO;AAC5C;;AAGA,MAAa,eAAe;;AAG5B,MAAa,UAAU;;;;;AAMvB,IAAa,eAAb,cAAkC,MAAM;;CAEtC;CAEA,YAAY,SAAiB,YAAoB;EAC/C,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF;;;;;;;AAkBA,SAAS,YAAY,QAAyB;CAC5C,IAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,UAAU,UAAU,aAAa,QAAQ;EAC5F,MAAM,EAAE,MAAM,YAAY;EAC1B,IAAI,OAAO,SAAS,YAAY,OAAO,YAAY,UAAU;GAE3D,MAAM,QAAQ,SAAS,KAAK,UAAU;GACtC,MAAM,OAAO,YAAY,KAAK,QAAQ,GAAG,MAAM,IAAI;GACnD,MAAM,aAAa,aAAa,IAAI;GACpC,IAAI,SAAS,iBAAiB,cAAc,UAAU,OAAO,OAAO,aAAa,UAC/E,OAAO;IAAE;IAAM;IAAY,iBAAiB,OAAO;GAAS;GAC9D,OAA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AAO;GAC3D,MAAM,IAAI,aAAa,yBAAyB,OAAO,QAAQ,OAAO,UAAU;EAClF;EACA,YAAY,MAAM,QAAQ;EAG1B,MAAM,SAAS,GAAG,SAAS,mBAAmB,WAAW,KAAK,eAAe;EAC7E,IAAI,OAAO,OAAO;GAChB,MAAM,SAAS,WAAW,OAAO,KAAK;GACtC,IAAI,CAAC,QAAQ,MAAM,IAAI,aAAa,gBAAgB,OAAO;GAC3D,MAAM,IAAI,aACR,OAAO,oBAAoB,kBACvB,GAAG,OAAO,KAAK,IAAI,2BACnB,OAAO,MACX,OAAO,UACT;EACF;EACA,MAAM,OAAO,GAAG,UAAU,OAAO,KAAK;EACtC,OAAO,MAAM,QAAQ;EACrB,OAAO,KAAK,MAAM,IAAI;CACxB,UAAU;EACR,QAAQ,0BAA0B,KAAK;EACvC,GAAG,QAAQ;CACb;AACF"}
|
|
@@ -14,7 +14,11 @@ function registerScreenshotTool(server, ctx) {
|
|
|
14
14
|
const base64Png = await ctx.callbacks.captureScreenshot();
|
|
15
15
|
if (savePath) {
|
|
16
16
|
const absPath = (0, node_path.resolve)(savePath);
|
|
17
|
-
|
|
17
|
+
try {
|
|
18
|
+
await (0, node_fs_promises.writeFile)(absPath, Buffer.from(base64Png, "base64"), { flag: "wx" });
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return saveFailedResult(e);
|
|
21
|
+
}
|
|
18
22
|
return { content: [{
|
|
19
23
|
type: "image",
|
|
20
24
|
data: base64Png,
|
|
@@ -31,6 +35,10 @@ function registerScreenshotTool(server, ctx) {
|
|
|
31
35
|
}] };
|
|
32
36
|
});
|
|
33
37
|
}
|
|
38
|
+
/** The result of a screenshot that could not be saved: the error of the file system, as it is. */
|
|
39
|
+
function saveFailedResult(error) {
|
|
40
|
+
return require_types.errorResult(`Could not save the screenshot: ${error instanceof Error ? error.message : String(error)}`, "Check that the folder exists and is writable and that no file exists at the path; the screenshot is not overwritten.");
|
|
41
|
+
}
|
|
34
42
|
exports.registerScreenshotTool = registerScreenshotTool;
|
|
35
43
|
|
|
36
44
|
//# sourceMappingURL=screenshot.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshot.cjs","names":["hints","z","errorResult","resolve","writeFile"],"sources":["../../src/tools/screenshot.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport
|
|
1
|
+
{"version":3,"file":"screenshot.cjs","names":["hints","z","errorResult","resolve","writeFile"],"sources":["../../src/tools/screenshot.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { z } from \"zod\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints } from \"./types\";\n\nexport function registerScreenshotTool(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"capture_screenshot\",\n {\n title: \"Capture Screenshot\",\n annotations: hints.additive,\n description:\n \"Capture a screenshot of the current application window. Optionally save to a file.\",\n inputSchema: z.object({\n savePath: z\n .string()\n .optional()\n .describe(\n \"Absolute file path to save the screenshot as PNG. If omitted, returns the image inline only.\",\n ),\n }),\n },\n async ({ savePath }) => {\n if (!ctx.callbacks.captureScreenshot) {\n return errorResult(\n \"Screenshot capture is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const base64Png = await ctx.callbacks.captureScreenshot();\n\n if (savePath) {\n const absPath = resolve(savePath);\n try {\n await writeFile(absPath, Buffer.from(base64Png, \"base64\"), { flag: \"wx\" });\n } catch (e: unknown) {\n return saveFailedResult(e);\n }\n return {\n content: [\n { type: \"image\" as const, data: base64Png, mimeType: \"image/png\" },\n { type: \"text\" as const, text: `Screenshot saved to ${absPath}` },\n ],\n };\n }\n\n return {\n content: [{ type: \"image\" as const, data: base64Png, mimeType: \"image/png\" }],\n };\n },\n );\n}\n\n/** The result of a screenshot that could not be saved: the error of the file system, as it is. */\nfunction saveFailedResult(error: unknown) {\n return errorResult(\n `Could not save the screenshot: ${error instanceof Error ? error.message : String(error)}`,\n \"Check that the folder exists and is writable and that no file exists at the path; the screenshot is not overwritten.\",\n );\n}\n"],"mappings":";;;;;AAMA,SAAgB,uBAAuB,QAAuB,KAAwB;CACpF,OAAO,aACL,sBACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO,EACpB,UAAUA,IAAAA,EACP,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,8FACF,EACJ,CAAC;CACH,GACA,OAAO,EAAE,eAAe;EACtB,IAAI,CAAC,IAAI,UAAU,mBACjB,OAAOC,cAAAA,YACL,wCACA,qJACF;EAEF,MAAM,YAAY,MAAM,IAAI,UAAU,kBAAkB;EAExD,IAAI,UAAU;GACZ,MAAM,WAAA,GAAUC,UAAAA,QAAAA,CAAQ,QAAQ;GAChC,IAAI;IACF,OAAA,GAAMC,iBAAAA,UAAAA,CAAU,SAAS,OAAO,KAAK,WAAW,QAAQ,GAAG,EAAE,MAAM,KAAK,CAAC;GAC3E,SAAS,GAAY;IACnB,OAAO,iBAAiB,CAAC;GAC3B;GACA,OAAO,EACL,SAAS,CACP;IAAE,MAAM;IAAkB,MAAM;IAAW,UAAU;GAAY,GACjE;IAAE,MAAM;IAAiB,MAAM,uBAAuB;GAAU,CAClE,EACF;EACF;EAEA,OAAO,EACL,SAAS,CAAC;GAAE,MAAM;GAAkB,MAAM;GAAW,UAAU;EAAY,CAAC,EAC9E;CACF,CACF;AACF;;AAGA,SAAS,iBAAiB,OAAgB;CACxC,OAAOF,cAAAA,YACL,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KACvF,sHACF;AACF"}
|
package/dist/tools/screenshot.js
CHANGED
|
@@ -14,7 +14,11 @@ function registerScreenshotTool(server, ctx) {
|
|
|
14
14
|
const base64Png = await ctx.callbacks.captureScreenshot();
|
|
15
15
|
if (savePath) {
|
|
16
16
|
const absPath = resolve(savePath);
|
|
17
|
-
|
|
17
|
+
try {
|
|
18
|
+
await writeFile(absPath, Buffer.from(base64Png, "base64"), { flag: "wx" });
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return saveFailedResult(e);
|
|
21
|
+
}
|
|
18
22
|
return { content: [{
|
|
19
23
|
type: "image",
|
|
20
24
|
data: base64Png,
|
|
@@ -31,6 +35,10 @@ function registerScreenshotTool(server, ctx) {
|
|
|
31
35
|
}] };
|
|
32
36
|
});
|
|
33
37
|
}
|
|
38
|
+
/** The result of a screenshot that could not be saved: the error of the file system, as it is. */
|
|
39
|
+
function saveFailedResult(error) {
|
|
40
|
+
return errorResult(`Could not save the screenshot: ${error instanceof Error ? error.message : String(error)}`, "Check that the folder exists and is writable and that no file exists at the path; the screenshot is not overwritten.");
|
|
41
|
+
}
|
|
34
42
|
export { registerScreenshotTool };
|
|
35
43
|
|
|
36
44
|
//# sourceMappingURL=screenshot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshot.js","names":[],"sources":["../../src/tools/screenshot.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport
|
|
1
|
+
{"version":3,"file":"screenshot.js","names":[],"sources":["../../src/tools/screenshot.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { z } from \"zod\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints } from \"./types\";\n\nexport function registerScreenshotTool(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"capture_screenshot\",\n {\n title: \"Capture Screenshot\",\n annotations: hints.additive,\n description:\n \"Capture a screenshot of the current application window. Optionally save to a file.\",\n inputSchema: z.object({\n savePath: z\n .string()\n .optional()\n .describe(\n \"Absolute file path to save the screenshot as PNG. If omitted, returns the image inline only.\",\n ),\n }),\n },\n async ({ savePath }) => {\n if (!ctx.callbacks.captureScreenshot) {\n return errorResult(\n \"Screenshot capture is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const base64Png = await ctx.callbacks.captureScreenshot();\n\n if (savePath) {\n const absPath = resolve(savePath);\n try {\n await writeFile(absPath, Buffer.from(base64Png, \"base64\"), { flag: \"wx\" });\n } catch (e: unknown) {\n return saveFailedResult(e);\n }\n return {\n content: [\n { type: \"image\" as const, data: base64Png, mimeType: \"image/png\" },\n { type: \"text\" as const, text: `Screenshot saved to ${absPath}` },\n ],\n };\n }\n\n return {\n content: [{ type: \"image\" as const, data: base64Png, mimeType: \"image/png\" }],\n };\n },\n );\n}\n\n/** The result of a screenshot that could not be saved: the error of the file system, as it is. */\nfunction saveFailedResult(error: unknown) {\n return errorResult(\n `Could not save the screenshot: ${error instanceof Error ? error.message : String(error)}`,\n \"Check that the folder exists and is writable and that no file exists at the path; the screenshot is not overwritten.\",\n );\n}\n"],"mappings":";;;;;AAMA,SAAgB,uBAAuB,QAAuB,KAAwB;CACpF,OAAO,aACL,sBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO,EACpB,UAAU,EACP,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,8FACF,EACJ,CAAC;CACH,GACA,OAAO,EAAE,eAAe;EACtB,IAAI,CAAC,IAAI,UAAU,mBACjB,OAAO,YACL,wCACA,qJACF;EAEF,MAAM,YAAY,MAAM,IAAI,UAAU,kBAAkB;EAExD,IAAI,UAAU;GACZ,MAAM,UAAU,QAAQ,QAAQ;GAChC,IAAI;IACF,MAAM,UAAU,SAAS,OAAO,KAAK,WAAW,QAAQ,GAAG,EAAE,MAAM,KAAK,CAAC;GAC3E,SAAS,GAAY;IACnB,OAAO,iBAAiB,CAAC;GAC3B;GACA,OAAO,EACL,SAAS,CACP;IAAE,MAAM;IAAkB,MAAM;IAAW,UAAU;GAAY,GACjE;IAAE,MAAM;IAAiB,MAAM,uBAAuB;GAAU,CAClE,EACF;EACF;EAEA,OAAO,EACL,SAAS,CAAC;GAAE,MAAM;GAAkB,MAAM;GAAW,UAAU;EAAY,CAAC,EAC9E;CACF,CACF;AACF;;AAGA,SAAS,iBAAiB,OAAgB;CACxC,OAAO,YACL,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KACvF,sHACF;AACF"}
|
package/dist/tools/types.cjs
CHANGED
|
@@ -64,9 +64,38 @@ function errorResult(message, hint) {
|
|
|
64
64
|
isError: true
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
+
/** The results made by {@link timedOutResult}. */
|
|
68
|
+
const timedOutResults = /* @__PURE__ */ new WeakSet();
|
|
69
|
+
/**
|
|
70
|
+
* Returns the result of a tool that waited for something and ran out of time: the JSON of `data`
|
|
71
|
+
* with `timedOut: true` in front. It is not an error result, the caller is expected to wait again.
|
|
72
|
+
* The server's log recognises such a result with {@link isTimedOutResult}.
|
|
73
|
+
*/
|
|
74
|
+
function timedOutResult(data) {
|
|
75
|
+
const result = textResult({
|
|
76
|
+
timedOut: true,
|
|
77
|
+
...data
|
|
78
|
+
});
|
|
79
|
+
timedOutResults.add(result);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
/** Whether `result` was made by {@link timedOutResult}. */
|
|
83
|
+
function isTimedOutResult(result) {
|
|
84
|
+
return typeof result === "object" && result !== null && timedOutResults.has(result);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the error result of a tool whose `transform` failed: `Transform failed: ` and the whole
|
|
88
|
+
* error, then `hint`. The agent needs the whole error to fix its expression.
|
|
89
|
+
*/
|
|
90
|
+
function transformFailedResult(error, hint) {
|
|
91
|
+
return errorResult(`Transform failed: ${error instanceof Error ? error.message : String(error)}`, hint);
|
|
92
|
+
}
|
|
67
93
|
exports.authorMarkerSource = authorMarkerSource;
|
|
68
94
|
exports.errorResult = errorResult;
|
|
69
95
|
exports.hints = hints;
|
|
96
|
+
exports.isTimedOutResult = isTimedOutResult;
|
|
70
97
|
exports.textResult = textResult;
|
|
98
|
+
exports.timedOutResult = timedOutResult;
|
|
99
|
+
exports.transformFailedResult = transformFailedResult;
|
|
71
100
|
|
|
72
101
|
//# sourceMappingURL=types.cjs.map
|
package/dist/tools/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","names":[],"sources":["../../src/tools/types.ts"],"sourcesContent":["import type {\n AuthorMarker,\n MiddleLayer,\n Project,\n ProjectId,\n ProjectListEntry,\n} from \"@milaboratories/pl-middle-layer\";\nimport type { PlMcpServerCallbacks } from \"../server\";\n\nexport type { AuthorMarker };\n\nexport interface ToolContext {\n getMl: () => MiddleLayer | null;\n requireMl: () => MiddleLayer;\n resolveProject: (projectId: ProjectId) => Promise<ProjectListEntry>;\n getOpenedProject: (projectId: ProjectId) => Promise<Project>;\n callbacks: PlMcpServerCallbacks;\n /**\n * Returns the marker for the next write made through MCP. All writes of one server instance carry\n * the same `authorId`, whichever client asked for them, and a `localVersion` that grows with\n * every call.\n */\n getAuthorMarker: () => AuthorMarker;\n}\n\n/**\n * Makes the author markers of one writer: every call returns a marker with `authorId` and the next\n * `localVersion`, counted from 1.\n */\nexport function authorMarkerSource(authorId:
|
|
1
|
+
{"version":3,"file":"types.cjs","names":[],"sources":["../../src/tools/types.ts"],"sourcesContent":["import type {\n AuthorMarker,\n MiddleLayer,\n Project,\n ProjectId,\n ProjectListEntry,\n} from \"@milaboratories/pl-middle-layer\";\nimport type {\n Icon,\n RegisteredTool,\n ScopeChallengeHandler,\n StandardSchemaWithJSON,\n ToolAnnotations,\n ToolCallback,\n} from \"@modelcontextprotocol/server\";\nimport type { McpInstanceId, PlMcpServerCallbacks } from \"../server\";\n\nexport type { AuthorMarker };\n\nexport interface ToolContext {\n getMl: () => MiddleLayer | null;\n requireMl: () => MiddleLayer;\n resolveProject: (projectId: ProjectId) => Promise<ProjectListEntry>;\n getOpenedProject: (projectId: ProjectId) => Promise<Project>;\n callbacks: PlMcpServerCallbacks;\n /**\n * Returns the marker for the next write made through MCP. All writes of one server instance carry\n * the same `authorId`, whichever client asked for them, and a `localVersion` that grows with\n * every call.\n */\n getAuthorMarker: () => AuthorMarker;\n}\n\n/**\n * What a tool is registered with: the `registerTool` of an `McpServer`, in its form that takes\n * schemas. The `register*Tools` functions get this and not the server, so that every tool they\n * register goes through whatever the server put around the registration (the call log).\n */\nexport interface ToolRegistrar {\n registerTool<\n OutputArgs extends StandardSchemaWithJSON,\n InputArgs extends StandardSchemaWithJSON | undefined = undefined,\n >(\n name: string,\n config: {\n title?: string;\n description?: string;\n inputSchema?: InputArgs;\n outputSchema?: OutputArgs;\n annotations?: ToolAnnotations;\n icons?: Icon[];\n scopeChallenge?: ScopeChallengeHandler;\n _meta?: Record<string, unknown>;\n },\n cb: ToolCallback<InputArgs>,\n ): RegisteredTool;\n}\n\n/**\n * Makes the author markers of one writer: every call returns a marker with `authorId` and the next\n * `localVersion`, counted from 1.\n */\nexport function authorMarkerSource(authorId: McpInstanceId): () => AuthorMarker {\n let localVersion = 0;\n return () => ({ authorId, localVersion: ++localVersion });\n}\n\n/**\n * The four behaviour hints of a tool, all stated. A client reads a missing hint as the worst case\n * (not read-only, destructive, not idempotent, open world), so no tool leaves one out.\n */\nexport type ToolHints = {\n /** The tool changes nothing. */\n readOnlyHint: boolean;\n /** The tool may replace or discard existing data or work, not only add to it. */\n destructiveHint: boolean;\n /** Calling the tool again with the same arguments changes nothing further. */\n idempotentHint: boolean;\n /** The tool reaches beyond the application and the backend it is connected to. */\n openWorldHint: boolean;\n};\n\n/** The hint sets tools choose from. A tool that fits none spreads the nearest one and overrides. */\nexport const hints = {\n /** Reads state; safe to call in parallel and to repeat. */\n read: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Adds something or starts something; a second call does it again. Loses nothing. */\n additive: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n },\n /** Puts the application into a state; a second call changes nothing. Loses nothing. */\n idempotent: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Replaces or discards data, configuration or running work; a second call changes nothing more. */\n destructive: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Acts on the application window or runs given code: the effect depends on what it hits. */\n unpredictable: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n },\n} as const satisfies Record<string, ToolHints>;\n\nexport function textResult(data: unknown) {\n return {\n content: [{ type: \"text\" as const, text: JSON.stringify(data) }],\n };\n}\n\n/** Return an MCP error result with an actionable hint for the AI agent. */\nexport function errorResult(message: string, hint?: string) {\n const text = hint ? `${message}\\n\\nHint: ${hint}` : message;\n return {\n content: [{ type: \"text\" as const, text }],\n isError: true,\n };\n}\n\n/** The results made by {@link timedOutResult}. */\nconst timedOutResults = new WeakSet<object>();\n\n/**\n * Returns the result of a tool that waited for something and ran out of time: the JSON of `data`\n * with `timedOut: true` in front. It is not an error result, the caller is expected to wait again.\n * The server's log recognises such a result with {@link isTimedOutResult}.\n */\nexport function timedOutResult(data: Record<string, unknown>) {\n const result = textResult({ timedOut: true, ...data });\n timedOutResults.add(result);\n return result;\n}\n\n/** Whether `result` was made by {@link timedOutResult}. */\nexport function isTimedOutResult(result: unknown): boolean {\n return typeof result === \"object\" && result !== null && timedOutResults.has(result);\n}\n\n/**\n * Returns the error result of a tool whose `transform` failed: `Transform failed: ` and the whole\n * error, then `hint`. The agent needs the whole error to fix its expression.\n */\nexport function transformFailedResult(error: unknown, hint: string) {\n return errorResult(\n `Transform failed: ${error instanceof Error ? error.message : String(error)}`,\n hint,\n );\n}\n"],"mappings":";;;;;AA8DA,SAAgB,mBAAmB,UAA6C;CAC9E,IAAI,eAAe;CACnB,cAAc;EAAE;EAAU,cAAc,EAAE;CAAa;AACzD;;AAkBA,MAAa,QAAQ;;CAEnB,MAAM;EACJ,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,UAAU;EACR,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,YAAY;EACV,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,aAAa;EACX,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,eAAe;EACb,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;AACF;AAEA,SAAgB,WAAW,MAAe;CACxC,OAAO,EACL,SAAS,CAAC;EAAE,MAAM;EAAiB,MAAM,KAAK,UAAU,IAAI;CAAE,CAAC,EACjE;AACF;;AAGA,SAAgB,YAAY,SAAiB,MAAe;CAE1D,OAAO;EACL,SAAS,CAAC;GAAE,MAAM;GAAiB,MAFxB,OAAO,GAAG,QAAQ,YAAY,SAAS;EAEV,CAAC;EACzC,SAAS;CACX;AACF;;AAGA,MAAM,kCAAkB,IAAI,QAAgB;;;;;;AAO5C,SAAgB,eAAe,MAA+B;CAC5D,MAAM,SAAS,WAAW;EAAE,UAAU;EAAM,GAAG;CAAK,CAAC;CACrD,gBAAgB,IAAI,MAAM;CAC1B,OAAO;AACT;;AAGA,SAAgB,iBAAiB,QAA0B;CACzD,OAAO,OAAO,WAAW,YAAY,WAAW,QAAQ,gBAAgB,IAAI,MAAM;AACpF;;;;;AAMA,SAAgB,sBAAsB,OAAgB,MAAc;CAClE,OAAO,YACL,qBAAqB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KAC1E,IACF;AACF"}
|
package/dist/tools/types.js
CHANGED
|
@@ -64,6 +64,32 @@ function errorResult(message, hint) {
|
|
|
64
64
|
isError: true
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
/** The results made by {@link timedOutResult}. */
|
|
68
|
+
const timedOutResults = /* @__PURE__ */ new WeakSet();
|
|
69
|
+
/**
|
|
70
|
+
* Returns the result of a tool that waited for something and ran out of time: the JSON of `data`
|
|
71
|
+
* with `timedOut: true` in front. It is not an error result, the caller is expected to wait again.
|
|
72
|
+
* The server's log recognises such a result with {@link isTimedOutResult}.
|
|
73
|
+
*/
|
|
74
|
+
function timedOutResult(data) {
|
|
75
|
+
const result = textResult({
|
|
76
|
+
timedOut: true,
|
|
77
|
+
...data
|
|
78
|
+
});
|
|
79
|
+
timedOutResults.add(result);
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
/** Whether `result` was made by {@link timedOutResult}. */
|
|
83
|
+
function isTimedOutResult(result) {
|
|
84
|
+
return typeof result === "object" && result !== null && timedOutResults.has(result);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the error result of a tool whose `transform` failed: `Transform failed: ` and the whole
|
|
88
|
+
* error, then `hint`. The agent needs the whole error to fix its expression.
|
|
89
|
+
*/
|
|
90
|
+
function transformFailedResult(error, hint) {
|
|
91
|
+
return errorResult(`Transform failed: ${error instanceof Error ? error.message : String(error)}`, hint);
|
|
92
|
+
}
|
|
93
|
+
export { authorMarkerSource, errorResult, hints, isTimedOutResult, textResult, timedOutResult, transformFailedResult };
|
|
68
94
|
|
|
69
95
|
//# sourceMappingURL=types.js.map
|
package/dist/tools/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/tools/types.ts"],"sourcesContent":["import type {\n AuthorMarker,\n MiddleLayer,\n Project,\n ProjectId,\n ProjectListEntry,\n} from \"@milaboratories/pl-middle-layer\";\nimport type { PlMcpServerCallbacks } from \"../server\";\n\nexport type { AuthorMarker };\n\nexport interface ToolContext {\n getMl: () => MiddleLayer | null;\n requireMl: () => MiddleLayer;\n resolveProject: (projectId: ProjectId) => Promise<ProjectListEntry>;\n getOpenedProject: (projectId: ProjectId) => Promise<Project>;\n callbacks: PlMcpServerCallbacks;\n /**\n * Returns the marker for the next write made through MCP. All writes of one server instance carry\n * the same `authorId`, whichever client asked for them, and a `localVersion` that grows with\n * every call.\n */\n getAuthorMarker: () => AuthorMarker;\n}\n\n/**\n * Makes the author markers of one writer: every call returns a marker with `authorId` and the next\n * `localVersion`, counted from 1.\n */\nexport function authorMarkerSource(authorId:
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/tools/types.ts"],"sourcesContent":["import type {\n AuthorMarker,\n MiddleLayer,\n Project,\n ProjectId,\n ProjectListEntry,\n} from \"@milaboratories/pl-middle-layer\";\nimport type {\n Icon,\n RegisteredTool,\n ScopeChallengeHandler,\n StandardSchemaWithJSON,\n ToolAnnotations,\n ToolCallback,\n} from \"@modelcontextprotocol/server\";\nimport type { McpInstanceId, PlMcpServerCallbacks } from \"../server\";\n\nexport type { AuthorMarker };\n\nexport interface ToolContext {\n getMl: () => MiddleLayer | null;\n requireMl: () => MiddleLayer;\n resolveProject: (projectId: ProjectId) => Promise<ProjectListEntry>;\n getOpenedProject: (projectId: ProjectId) => Promise<Project>;\n callbacks: PlMcpServerCallbacks;\n /**\n * Returns the marker for the next write made through MCP. All writes of one server instance carry\n * the same `authorId`, whichever client asked for them, and a `localVersion` that grows with\n * every call.\n */\n getAuthorMarker: () => AuthorMarker;\n}\n\n/**\n * What a tool is registered with: the `registerTool` of an `McpServer`, in its form that takes\n * schemas. The `register*Tools` functions get this and not the server, so that every tool they\n * register goes through whatever the server put around the registration (the call log).\n */\nexport interface ToolRegistrar {\n registerTool<\n OutputArgs extends StandardSchemaWithJSON,\n InputArgs extends StandardSchemaWithJSON | undefined = undefined,\n >(\n name: string,\n config: {\n title?: string;\n description?: string;\n inputSchema?: InputArgs;\n outputSchema?: OutputArgs;\n annotations?: ToolAnnotations;\n icons?: Icon[];\n scopeChallenge?: ScopeChallengeHandler;\n _meta?: Record<string, unknown>;\n },\n cb: ToolCallback<InputArgs>,\n ): RegisteredTool;\n}\n\n/**\n * Makes the author markers of one writer: every call returns a marker with `authorId` and the next\n * `localVersion`, counted from 1.\n */\nexport function authorMarkerSource(authorId: McpInstanceId): () => AuthorMarker {\n let localVersion = 0;\n return () => ({ authorId, localVersion: ++localVersion });\n}\n\n/**\n * The four behaviour hints of a tool, all stated. A client reads a missing hint as the worst case\n * (not read-only, destructive, not idempotent, open world), so no tool leaves one out.\n */\nexport type ToolHints = {\n /** The tool changes nothing. */\n readOnlyHint: boolean;\n /** The tool may replace or discard existing data or work, not only add to it. */\n destructiveHint: boolean;\n /** Calling the tool again with the same arguments changes nothing further. */\n idempotentHint: boolean;\n /** The tool reaches beyond the application and the backend it is connected to. */\n openWorldHint: boolean;\n};\n\n/** The hint sets tools choose from. A tool that fits none spreads the nearest one and overrides. */\nexport const hints = {\n /** Reads state; safe to call in parallel and to repeat. */\n read: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Adds something or starts something; a second call does it again. Loses nothing. */\n additive: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n },\n /** Puts the application into a state; a second call changes nothing. Loses nothing. */\n idempotent: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Replaces or discards data, configuration or running work; a second call changes nothing more. */\n destructive: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Acts on the application window or runs given code: the effect depends on what it hits. */\n unpredictable: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n },\n} as const satisfies Record<string, ToolHints>;\n\nexport function textResult(data: unknown) {\n return {\n content: [{ type: \"text\" as const, text: JSON.stringify(data) }],\n };\n}\n\n/** Return an MCP error result with an actionable hint for the AI agent. */\nexport function errorResult(message: string, hint?: string) {\n const text = hint ? `${message}\\n\\nHint: ${hint}` : message;\n return {\n content: [{ type: \"text\" as const, text }],\n isError: true,\n };\n}\n\n/** The results made by {@link timedOutResult}. */\nconst timedOutResults = new WeakSet<object>();\n\n/**\n * Returns the result of a tool that waited for something and ran out of time: the JSON of `data`\n * with `timedOut: true` in front. It is not an error result, the caller is expected to wait again.\n * The server's log recognises such a result with {@link isTimedOutResult}.\n */\nexport function timedOutResult(data: Record<string, unknown>) {\n const result = textResult({ timedOut: true, ...data });\n timedOutResults.add(result);\n return result;\n}\n\n/** Whether `result` was made by {@link timedOutResult}. */\nexport function isTimedOutResult(result: unknown): boolean {\n return typeof result === \"object\" && result !== null && timedOutResults.has(result);\n}\n\n/**\n * Returns the error result of a tool whose `transform` failed: `Transform failed: ` and the whole\n * error, then `hint`. The agent needs the whole error to fix its expression.\n */\nexport function transformFailedResult(error: unknown, hint: string) {\n return errorResult(\n `Transform failed: ${error instanceof Error ? error.message : String(error)}`,\n hint,\n );\n}\n"],"mappings":";;;;;AA8DA,SAAgB,mBAAmB,UAA6C;CAC9E,IAAI,eAAe;CACnB,cAAc;EAAE;EAAU,cAAc,EAAE;CAAa;AACzD;;AAkBA,MAAa,QAAQ;;CAEnB,MAAM;EACJ,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,UAAU;EACR,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,YAAY;EACV,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,aAAa;EACX,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,eAAe;EACb,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;AACF;AAEA,SAAgB,WAAW,MAAe;CACxC,OAAO,EACL,SAAS,CAAC;EAAE,MAAM;EAAiB,MAAM,KAAK,UAAU,IAAI;CAAE,CAAC,EACjE;AACF;;AAGA,SAAgB,YAAY,SAAiB,MAAe;CAE1D,OAAO;EACL,SAAS,CAAC;GAAE,MAAM;GAAiB,MAFxB,OAAO,GAAG,QAAQ,YAAY,SAAS;EAEV,CAAC;EACzC,SAAS;CACX;AACF;;AAGA,MAAM,kCAAkB,IAAI,QAAgB;;;;;;AAO5C,SAAgB,eAAe,MAA+B;CAC5D,MAAM,SAAS,WAAW;EAAE,UAAU;EAAM,GAAG;CAAK,CAAC;CACrD,gBAAgB,IAAI,MAAM;CAC1B,OAAO;AACT;;AAGA,SAAgB,iBAAiB,QAA0B;CACzD,OAAO,OAAO,WAAW,YAAY,WAAW,QAAQ,gBAAgB,IAAI,MAAM;AACpF;;;;;AAMA,SAAgB,sBAAsB,OAAgB,MAAc;CAClE,OAAO,YACL,qBAAqB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KAC1E,IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-interaction.cjs","names":["hints","z","errorResult","textResult","projectIdInput","blockIdInput"],"sources":["../../src/tools/ui-interaction.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerUIInteractionTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"click\",\n {\n title: \"Click in the Application Window\",\n annotations: hints.unpredictable,\n description:\n \"Click at coordinates (x, y) in the application window. Use capture_screenshot to find element positions.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate\"),\n y: z.number().describe(\"Y coordinate\"),\n doubleClick: z.boolean().optional().describe(\"Double click\"),\n }),\n },\n async ({ x, y, doubleClick }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const clickCount = doubleClick ? 2 : 1;\n await ctx.callbacks.sendInputEvent({\n type: \"mouseDown\",\n x,\n y,\n button: \"left\",\n clickCount,\n });\n await ctx.callbacks.sendInputEvent({ type: \"mouseUp\", x, y, button: \"left\", clickCount });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"type_text\",\n {\n title: \"Type Text\",\n annotations: hints.unpredictable,\n description:\n \"Type text into the element that has focus in the application window. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n text: z.string().describe(\"Text to type\"),\n }),\n },\n async ({ text }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n for (const char of text) {\n await ctx.callbacks.sendInputEvent({ type: \"keyDown\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"char\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"keyUp\", keyCode: char });\n }\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"press_key\",\n {\n title: \"Press Key\",\n annotations: hints.unpredictable,\n description: \"Press a keyboard key (Enter, Tab, Escape, Backspace, ArrowDown, ArrowUp, etc.)\",\n inputSchema: z.object({\n key: z\n .string()\n .describe(\"Key name (e.g. 'Enter', 'Tab', 'Escape', 'Backspace', 'ArrowDown')\"),\n modifiers: z\n .array(z.enum([\"shift\", \"control\", \"alt\", \"meta\"]))\n .optional()\n .describe(\"Modifier keys to hold\"),\n }),\n },\n async ({ key, modifiers }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"keyDown\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n await ctx.callbacks.sendInputEvent({\n type: \"keyUp\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"scroll\",\n {\n title: \"Scroll\",\n annotations: hints.additive,\n description:\n \"Scroll the application window at a given position. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate to scroll at\"),\n y: z.number().describe(\"Y coordinate to scroll at\"),\n deltaX: z.number().optional().default(0).describe(\"Horizontal scroll amount\"),\n deltaY: z.number().describe(\"Vertical scroll amount (negative = up, positive = down)\"),\n }),\n },\n async ({ x, y, deltaX, deltaY }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"mouseWheel\",\n x,\n y,\n deltaX: deltaX ?? 0,\n deltaY,\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"execute_js\",\n {\n title: \"Execute JavaScript\",\n annotations: { ...hints.unpredictable, openWorldHint: true },\n description:\n \"Execute JavaScript in a renderer and return the result. By default runs in the topmost webContents (main app / topmost modal). Pass projectId + blockId to run inside that block's webview, where `window.platforma` is exposed and the driverKit (e.g. `window.platforma.lsDriver.getLocalFileHandle`) is callable. The block must already be open — call `select_block` first if needed.\",\n inputSchema: z.object({\n code: z.string().describe(\"JavaScript code to execute\"),\n projectId: projectIdInput\n .optional()\n .describe(\"Target project ID. Must be paired with blockId.\"),\n blockId: blockIdInput\n .optional()\n .describe(\n \"Target block ID. When provided with projectId, JS runs in that block's webview (where `window.platforma` is available).\",\n ),\n }),\n },\n async ({ code, projectId, blockId }) => {\n if (!ctx.callbacks.executeJavaScript) {\n return errorResult(\n \"JS execution is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n if ((projectId === undefined) !== (blockId === undefined)) {\n return errorResult(\n \"projectId and blockId must be provided together.\",\n \"Either pass both to target a specific block's webview, or pass neither to run in the topmost webContents.\",\n );\n }\n const target =\n projectId !== undefined && blockId !== undefined ? { projectId, blockId } : undefined;\n const result = await ctx.callbacks.executeJavaScript(code, target);\n return textResult(result);\n },\n );\n}\n"],"mappings":";;;;AAMA,SAAgB,2BAA2B,QAAmB,KAAwB;CACpF,OAAO,aACL,SACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO;GACpB,GAAGA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,GAAGA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,aAAaA,IAAAA,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,cAAc;EAC7D,CAAC;CACH,GACA,OAAO,EAAE,GAAG,GAAG,kBAAkB;EAC/B,IAAI,CAAC,IAAI,UAAU,gBACjB,OAAOC,cAAAA,YACL,oCACA,qJACF;EAEF,MAAM,aAAa,cAAc,IAAI;EACrC,MAAM,IAAI,UAAU,eAAe;GACjC,MAAM;GACN;GACA;GACA,QAAQ;GACR;EACF,CAAC;EACD,MAAM,IAAI,UAAU,eAAe;GAAE,MAAM;GAAW;GAAG;GAAG,QAAQ;GAAQ;EAAW,CAAC;EACxF,OAAOC,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;CAEA,OAAO,aACL,aACA;EACE,OAAO;EACP,aAAaH,cAAAA,MAAM;EACnB,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO,EACpB,MAAMA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc,EAC1C,CAAC;CACH,GACA,OAAO,EAAE,WAAW;EAClB,IAAI,CAAC,IAAI,UAAU,gBACjB,OAAOC,cAAAA,YACL,oCACA,qJACF;EAEF,KAAK,MAAM,QAAQ,MAAM;GACvB,MAAM,IAAI,UAAU,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B,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"ui-interaction.cjs","names":["hints","z","errorResult","textResult","projectIdInput","blockIdInput"],"sources":["../../src/tools/ui-interaction.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerUIInteractionTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"click\",\n {\n title: \"Click in the Application Window\",\n annotations: hints.unpredictable,\n description:\n \"Click at coordinates (x, y) in the application window. Use capture_screenshot to find element positions.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate\"),\n y: z.number().describe(\"Y coordinate\"),\n doubleClick: z.boolean().optional().describe(\"Double click\"),\n }),\n },\n async ({ x, y, doubleClick }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const clickCount = doubleClick ? 2 : 1;\n await ctx.callbacks.sendInputEvent({\n type: \"mouseDown\",\n x,\n y,\n button: \"left\",\n clickCount,\n });\n await ctx.callbacks.sendInputEvent({ type: \"mouseUp\", x, y, button: \"left\", clickCount });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"type_text\",\n {\n title: \"Type Text\",\n annotations: hints.unpredictable,\n description:\n \"Type text into the element that has focus in the application window. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n text: z.string().describe(\"Text to type\"),\n }),\n },\n async ({ text }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n for (const char of text) {\n await ctx.callbacks.sendInputEvent({ type: \"keyDown\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"char\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"keyUp\", keyCode: char });\n }\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"press_key\",\n {\n title: \"Press Key\",\n annotations: hints.unpredictable,\n description: \"Press a keyboard key (Enter, Tab, Escape, Backspace, ArrowDown, ArrowUp, etc.)\",\n inputSchema: z.object({\n key: z\n .string()\n .describe(\"Key name (e.g. 'Enter', 'Tab', 'Escape', 'Backspace', 'ArrowDown')\"),\n modifiers: z\n .array(z.enum([\"shift\", \"control\", \"alt\", \"meta\"]))\n .optional()\n .describe(\"Modifier keys to hold\"),\n }),\n },\n async ({ key, modifiers }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"keyDown\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n await ctx.callbacks.sendInputEvent({\n type: \"keyUp\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"scroll\",\n {\n title: \"Scroll\",\n annotations: hints.additive,\n description:\n \"Scroll the application window at a given position. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate to scroll at\"),\n y: z.number().describe(\"Y coordinate to scroll at\"),\n deltaX: z.number().optional().default(0).describe(\"Horizontal scroll amount\"),\n deltaY: z.number().describe(\"Vertical scroll amount (negative = up, positive = down)\"),\n }),\n },\n async ({ x, y, deltaX, deltaY }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"mouseWheel\",\n x,\n y,\n deltaX: deltaX ?? 0,\n deltaY,\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"execute_js\",\n {\n title: \"Execute JavaScript\",\n annotations: { ...hints.unpredictable, openWorldHint: true },\n description:\n \"Execute JavaScript in a renderer and return the result. By default runs in the topmost webContents (main app / topmost modal). Pass projectId + blockId to run inside that block's webview, where `window.platforma` is exposed and the driverKit (e.g. `window.platforma.lsDriver.getLocalFileHandle`) is callable. The block must already be open — call `select_block` first if needed.\",\n inputSchema: z.object({\n code: z.string().describe(\"JavaScript code to execute\"),\n projectId: projectIdInput\n .optional()\n .describe(\"Target project ID. Must be paired with blockId.\"),\n blockId: blockIdInput\n .optional()\n .describe(\n \"Target block ID. When provided with projectId, JS runs in that block's webview (where `window.platforma` is available).\",\n ),\n }),\n },\n async ({ code, projectId, blockId }) => {\n if (!ctx.callbacks.executeJavaScript) {\n return errorResult(\n \"JS execution is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n if ((projectId === undefined) !== (blockId === undefined)) {\n return errorResult(\n \"projectId and blockId must be provided together.\",\n \"Either pass both to target a specific block's webview, or pass neither to run in the topmost webContents.\",\n );\n }\n const target =\n projectId !== undefined && blockId !== undefined ? { projectId, blockId } : undefined;\n const result = await ctx.callbacks.executeJavaScript(code, target);\n return textResult(result);\n },\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,2BAA2B,QAAuB,KAAwB;CACxF,OAAO,aACL,SACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO;GACpB,GAAGA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,GAAGA,IAAAA,EAAE,OAAO,CAA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GACjC,MAAM;GACN;GACA;GACA,QAAQ,UAAU;GAClB;EACF,CAAC;EACD,OAAOC,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;CAEA,OAAO,aACL,cACA;EACE,OAAO;EACP,aAAa;GAAE,GAAGH,cAAAA,MAAM;GAAe,eAAe;EAAK;EAC3D,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO;GACpB,MAAMA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,4BAA4B;GACtD,WAAWG,YAAAA,eACR,SAAS,CAAC,CACV,SAAS,iDAAiD;GAC7D,SAASC,YAAAA,aACN,SAAS,CAAC,CACV,SACC,yHACF;EACJ,CAAC;CACH,GACA,OAAO,EAAE,MAAM,WAAW,cAAc;EACtC,IAAI,CAAC,IAAI,UAAU,mBACjB,OAAOH,cAAAA,YACL,kCACA,qJACF;EAEF,IAAK,cAAc,KAAA,OAAgB,YAAY,KAAA,IAC7C,OAAOA,cAAAA,YACL,oDACA,2GACF;EAEF,MAAM,SACJ,cAAc,KAAA,KAAa,YAAY,KAAA,IAAY;GAAE;GAAW;EAAQ,IAAI,KAAA;EAC9E,MAAM,SAAS,MAAM,IAAI,UAAU,kBAAkB,MAAM,MAAM;EACjE,OAAOC,cAAAA,WAAW,MAAM;CAC1B,CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-interaction.js","names":[],"sources":["../../src/tools/ui-interaction.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerUIInteractionTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"click\",\n {\n title: \"Click in the Application Window\",\n annotations: hints.unpredictable,\n description:\n \"Click at coordinates (x, y) in the application window. Use capture_screenshot to find element positions.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate\"),\n y: z.number().describe(\"Y coordinate\"),\n doubleClick: z.boolean().optional().describe(\"Double click\"),\n }),\n },\n async ({ x, y, doubleClick }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const clickCount = doubleClick ? 2 : 1;\n await ctx.callbacks.sendInputEvent({\n type: \"mouseDown\",\n x,\n y,\n button: \"left\",\n clickCount,\n });\n await ctx.callbacks.sendInputEvent({ type: \"mouseUp\", x, y, button: \"left\", clickCount });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"type_text\",\n {\n title: \"Type Text\",\n annotations: hints.unpredictable,\n description:\n \"Type text into the element that has focus in the application window. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n text: z.string().describe(\"Text to type\"),\n }),\n },\n async ({ text }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n for (const char of text) {\n await ctx.callbacks.sendInputEvent({ type: \"keyDown\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"char\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"keyUp\", keyCode: char });\n }\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"press_key\",\n {\n title: \"Press Key\",\n annotations: hints.unpredictable,\n description: \"Press a keyboard key (Enter, Tab, Escape, Backspace, ArrowDown, ArrowUp, etc.)\",\n inputSchema: z.object({\n key: z\n .string()\n .describe(\"Key name (e.g. 'Enter', 'Tab', 'Escape', 'Backspace', 'ArrowDown')\"),\n modifiers: z\n .array(z.enum([\"shift\", \"control\", \"alt\", \"meta\"]))\n .optional()\n .describe(\"Modifier keys to hold\"),\n }),\n },\n async ({ key, modifiers }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"keyDown\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n await ctx.callbacks.sendInputEvent({\n type: \"keyUp\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"scroll\",\n {\n title: \"Scroll\",\n annotations: hints.additive,\n description:\n \"Scroll the application window at a given position. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate to scroll at\"),\n y: z.number().describe(\"Y coordinate to scroll at\"),\n deltaX: z.number().optional().default(0).describe(\"Horizontal scroll amount\"),\n deltaY: z.number().describe(\"Vertical scroll amount (negative = up, positive = down)\"),\n }),\n },\n async ({ x, y, deltaX, deltaY }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"mouseWheel\",\n x,\n y,\n deltaX: deltaX ?? 0,\n deltaY,\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"execute_js\",\n {\n title: \"Execute JavaScript\",\n annotations: { ...hints.unpredictable, openWorldHint: true },\n description:\n \"Execute JavaScript in a renderer and return the result. By default runs in the topmost webContents (main app / topmost modal). Pass projectId + blockId to run inside that block's webview, where `window.platforma` is exposed and the driverKit (e.g. `window.platforma.lsDriver.getLocalFileHandle`) is callable. The block must already be open — call `select_block` first if needed.\",\n inputSchema: z.object({\n code: z.string().describe(\"JavaScript code to execute\"),\n projectId: projectIdInput\n .optional()\n .describe(\"Target project ID. Must be paired with blockId.\"),\n blockId: blockIdInput\n .optional()\n .describe(\n \"Target block ID. When provided with projectId, JS runs in that block's webview (where `window.platforma` is available).\",\n ),\n }),\n },\n async ({ code, projectId, blockId }) => {\n if (!ctx.callbacks.executeJavaScript) {\n return errorResult(\n \"JS execution is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n if ((projectId === undefined) !== (blockId === undefined)) {\n return errorResult(\n \"projectId and blockId must be provided together.\",\n \"Either pass both to target a specific block's webview, or pass neither to run in the topmost webContents.\",\n );\n }\n const target =\n projectId !== undefined && blockId !== undefined ? { projectId, blockId } : undefined;\n const result = await ctx.callbacks.executeJavaScript(code, target);\n return textResult(result);\n },\n );\n}\n"],"mappings":";;;;AAMA,SAAgB,2BAA2B,QAAmB,KAAwB;CACpF,OAAO,aACL,SACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO;GACpB,GAAG,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,GAAG,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,aAAa,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,cAAc;EAC7D,CAAC;CACH,GACA,OAAO,EAAE,GAAG,GAAG,kBAAkB;EAC/B,IAAI,CAAC,IAAI,UAAU,gBACjB,OAAO,YACL,oCACA,qJACF;EAEF,MAAM,aAAa,cAAc,IAAI;EACrC,MAAM,IAAI,UAAU,eAAe;GACjC,MAAM;GACN;GACA;GACA,QAAQ;GACR;EACF,CAAC;EACD,MAAM,IAAI,UAAU,eAAe;GAAE,MAAM;GAAW;GAAG;GAAG,QAAQ;GAAQ;EAAW,CAAC;EACxF,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;CAEA,OAAO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AAM,SAAS,MAAM,IAAI,UAAU,kBAAkB,MAAM,MAAM;EACjE,OAAO,WAAW,MAAM;CAC1B,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"ui-interaction.js","names":[],"sources":["../../src/tools/ui-interaction.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerUIInteractionTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"click\",\n {\n title: \"Click in the Application Window\",\n annotations: hints.unpredictable,\n description:\n \"Click at coordinates (x, y) in the application window. Use capture_screenshot to find element positions.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate\"),\n y: z.number().describe(\"Y coordinate\"),\n doubleClick: z.boolean().optional().describe(\"Double click\"),\n }),\n },\n async ({ x, y, doubleClick }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const clickCount = doubleClick ? 2 : 1;\n await ctx.callbacks.sendInputEvent({\n type: \"mouseDown\",\n x,\n y,\n button: \"left\",\n clickCount,\n });\n await ctx.callbacks.sendInputEvent({ type: \"mouseUp\", x, y, button: \"left\", clickCount });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"type_text\",\n {\n title: \"Type Text\",\n annotations: hints.unpredictable,\n description:\n \"Type text into the element that has focus in the application window. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n text: z.string().describe(\"Text to type\"),\n }),\n },\n async ({ text }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n for (const char of text) {\n await ctx.callbacks.sendInputEvent({ type: \"keyDown\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"char\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"keyUp\", keyCode: char });\n }\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"press_key\",\n {\n title: \"Press Key\",\n annotations: hints.unpredictable,\n description: \"Press a keyboard key (Enter, Tab, Escape, Backspace, ArrowDown, ArrowUp, etc.)\",\n inputSchema: z.object({\n key: z\n .string()\n .describe(\"Key name (e.g. 'Enter', 'Tab', 'Escape', 'Backspace', 'ArrowDown')\"),\n modifiers: z\n .array(z.enum([\"shift\", \"control\", \"alt\", \"meta\"]))\n .optional()\n .describe(\"Modifier keys to hold\"),\n }),\n },\n async ({ key, modifiers }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"keyDown\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n await ctx.callbacks.sendInputEvent({\n type: \"keyUp\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"scroll\",\n {\n title: \"Scroll\",\n annotations: hints.additive,\n description:\n \"Scroll the application window at a given position. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate to scroll at\"),\n y: z.number().describe(\"Y coordinate to scroll at\"),\n deltaX: z.number().optional().default(0).describe(\"Horizontal scroll amount\"),\n deltaY: z.number().describe(\"Vertical scroll amount (negative = up, positive = down)\"),\n }),\n },\n async ({ x, y, deltaX, deltaY }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"mouseWheel\",\n x,\n y,\n deltaX: deltaX ?? 0,\n deltaY,\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"execute_js\",\n {\n title: \"Execute JavaScript\",\n annotations: { ...hints.unpredictable, openWorldHint: true },\n description:\n \"Execute JavaScript in a renderer and return the result. By default runs in the topmost webContents (main app / topmost modal). Pass projectId + blockId to run inside that block's webview, where `window.platforma` is exposed and the driverKit (e.g. `window.platforma.lsDriver.getLocalFileHandle`) is callable. The block must already be open — call `select_block` first if needed.\",\n inputSchema: z.object({\n code: z.string().describe(\"JavaScript code to execute\"),\n projectId: projectIdInput\n .optional()\n .describe(\"Target project ID. Must be paired with blockId.\"),\n blockId: blockIdInput\n .optional()\n .describe(\n \"Target block ID. When provided with projectId, JS runs in that block's webview (where `window.platforma` is available).\",\n ),\n }),\n },\n async ({ code, projectId, blockId }) => {\n if (!ctx.callbacks.executeJavaScript) {\n return errorResult(\n \"JS execution is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n if ((projectId === undefined) !== (blockId === undefined)) {\n return errorResult(\n \"projectId and blockId must be provided together.\",\n \"Either pass both to target a specific block's webview, or pass neither to run in the topmost webContents.\",\n );\n }\n const target =\n projectId !== undefined && blockId !== undefined ? { projectId, blockId } : undefined;\n const result = await ctx.callbacks.executeJavaScript(code, target);\n return textResult(result);\n },\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,2BAA2B,QAAuB,KAAwB;CACxF,OAAO,aACL,SACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO;GACpB,GAAG,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,GAAG,EAAE,O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,eAAe;EAAK;EAC3D,aACE;EACF,aAAa,EAAE,OAAO;GACpB,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,4BAA4B;GACtD,WAAW,eACR,SAAS,CAAC,CACV,SAAS,iDAAiD;GAC7D,SAAS,aACN,SAAS,CAAC,CACV,SACC,yHACF;EACJ,CAAC;CACH,GACA,OAAO,EAAE,MAAM,WAAW,cAAc;EACtC,IAAI,CAAC,IAAI,UAAU,mBACjB,OAAO,YACL,kCACA,qJACF;EAEF,IAAK,cAAc,KAAA,OAAgB,YAAY,KAAA,IAC7C,OAAO,YACL,oDACA,2GACF;EAEF,MAAM,SACJ,cAAc,KAAA,KAAa,YAAY,KAAA,IAAY;GAAE;GAAW;EAAQ,IAAI,KAAA;EAC9E,MAAM,SAAS,MAAM,IAAI,UAAU,kBAAkB,MAAM,MAAM;EACjE,OAAO,WAAW,MAAM;CAC1B,CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-mcp-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "53.1.0",
|
|
4
4
|
"description": "MCP server for Platforma Desktop",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@milaboratories/helpers": "1.14.7",
|
|
22
23
|
"@modelcontextprotocol/node": "^2.1.2",
|
|
23
24
|
"@modelcontextprotocol/server": "^2.4.0",
|
|
24
25
|
"quickjs-emscripten": "npm:@milaboratories-poc/quickjs-emscripten@0.32.1-bytecode.1",
|
|
@@ -26,8 +27,8 @@
|
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@milaboratories/build-configs": "2.0.3",
|
|
29
|
-
"@milaboratories/pl-errors": "1.
|
|
30
|
-
"@milaboratories/pl-middle-layer": "2.
|
|
30
|
+
"@milaboratories/pl-errors": "1.5.0",
|
|
31
|
+
"@milaboratories/pl-middle-layer": "2.9.0",
|
|
31
32
|
"@milaboratories/pl-model-common": "1.60.0",
|
|
32
33
|
"@milaboratories/ts-builder": "1.8.0",
|
|
33
34
|
"@milaboratories/ts-configs": "1.4.1",
|
|
@@ -40,7 +41,7 @@
|
|
|
40
41
|
"vitest": "^4.1.12"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
|
-
"@milaboratories/pl-middle-layer": ">=2.
|
|
44
|
+
"@milaboratories/pl-middle-layer": ">=2.9.0",
|
|
44
45
|
"@platforma-sdk/model": ">=1.96.1"
|
|
45
46
|
},
|
|
46
47
|
"engines": {
|
package/src/instructions.ts
CHANGED
|
@@ -11,7 +11,7 @@ export const SERVER_INSTRUCTIONS = `Platforma Desktop: build and run data analys
|
|
|
11
11
|
Order of work:
|
|
12
12
|
1. Connection: get_connection_status. If not connected: list_connections, then connect_to_server.
|
|
13
13
|
2. Project: list_projects or create_project, then open_project. Every block tool needs an opened project.
|
|
14
|
-
3. Add blocks: list_available_blocks finds a block; add_block adds it. Add blocks in the order the data flows.
|
|
14
|
+
3. Add blocks: list_available_blocks finds a block; add_block adds it, with params to configure it at creation. Add blocks in the order the data flows.
|
|
15
15
|
4. Configure a block: get_block_state returns the block's data and outputs. Change the data and write the whole object back with set_block_data. The choices a block offers for its inputs (datasets, columns of blocks above) are in its outputs: get_block_outputs.
|
|
16
16
|
5. Check and run: get_project_overview shows for each block whether its inputs are valid and whether it can run. run_block starts a block together with the stale blocks above it; await_block_done waits for it.
|
|
17
17
|
6. Results: get_block_outputs, then list_columns and query_table for tables, get_block_logs for logs.
|
|
@@ -20,4 +20,5 @@ Rules:
|
|
|
20
20
|
- Project ids, block ids, references to blocks and columns, and table handles come from tool results. Copy them; do not compose them.
|
|
21
21
|
- set_block_data replaces the block's data: send the whole object, not the changed part.
|
|
22
22
|
- Changing a block's data can make its results, and the results of blocks that read them, stale until they run again.
|
|
23
|
+
- Only blocks on the current block API can be added.
|
|
23
24
|
- capture_screenshot, click, type_text, press_key, scroll, execute_js and select_block drive the application window. They are for testing the application; configuring and running blocks does not need them.`;
|