@cloxco/clox 0.0.0-stage → 0.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 +11 -2
- package/clox +2 -0
- package/clox.cjs +87256 -0
- package/mcp-proxy.js +146 -0
- package/package.json +20 -4
package/mcp-proxy.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// ../desktop_ui/remote-host/mcp-proxy.ts
|
|
26
|
+
var import_readline = __toESM(require("readline"));
|
|
27
|
+
var endpoint = process.env.CLOX_LOCAL_TOOL_ENDPOINT ?? "";
|
|
28
|
+
var token = process.env.CLOX_LOCAL_TOOL_TOKEN || process.env.CLOX_LOCAL_TOOL_AUTH || "";
|
|
29
|
+
var turnId = process.env.CLOX_REMOTE_TURN_ID ?? "";
|
|
30
|
+
var threadId = process.env.CLOX_REMOTE_THREAD_ID ?? "";
|
|
31
|
+
var request = async (path, init) => {
|
|
32
|
+
const response = await fetch(endpoint + path, {
|
|
33
|
+
...init,
|
|
34
|
+
headers: {
|
|
35
|
+
...init?.headers ?? {},
|
|
36
|
+
Authorization: `Bearer ${token}`,
|
|
37
|
+
"Content-Type": "application/json"
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const body = await response.json();
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
throw new Error(body.error || `local tool server returned ${response.status}`);
|
|
43
|
+
}
|
|
44
|
+
return body;
|
|
45
|
+
};
|
|
46
|
+
var send = (value) => {
|
|
47
|
+
process.stdout.write(JSON.stringify(value) + "\n");
|
|
48
|
+
};
|
|
49
|
+
var resultContent = (result) => {
|
|
50
|
+
const content = [{ type: "text", text: result.text }];
|
|
51
|
+
if (result.imageBase64) {
|
|
52
|
+
content.push({
|
|
53
|
+
type: "image",
|
|
54
|
+
data: result.imageBase64,
|
|
55
|
+
mimeType: result.mimeType || "image/jpeg"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return content;
|
|
59
|
+
};
|
|
60
|
+
var handle = async (rpc) => {
|
|
61
|
+
if (rpc.id === void 0 || rpc.id === null) return;
|
|
62
|
+
try {
|
|
63
|
+
switch (rpc.method) {
|
|
64
|
+
case "initialize":
|
|
65
|
+
send({
|
|
66
|
+
jsonrpc: "2.0",
|
|
67
|
+
id: rpc.id,
|
|
68
|
+
result: {
|
|
69
|
+
protocolVersion: "2024-11-05",
|
|
70
|
+
capabilities: { tools: { listChanged: false } },
|
|
71
|
+
serverInfo: { name: "clox-device", version: "1.0.0" }
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
case "ping":
|
|
76
|
+
send({ jsonrpc: "2.0", id: rpc.id, result: {} });
|
|
77
|
+
return;
|
|
78
|
+
case "tools/list": {
|
|
79
|
+
if (!endpoint) {
|
|
80
|
+
send({ jsonrpc: "2.0", id: rpc.id, result: { tools: [] } });
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const body = await request("/tools");
|
|
84
|
+
send({
|
|
85
|
+
jsonrpc: "2.0",
|
|
86
|
+
id: rpc.id,
|
|
87
|
+
result: {
|
|
88
|
+
tools: body.tools.map((tool) => ({
|
|
89
|
+
name: tool.name,
|
|
90
|
+
description: tool.description,
|
|
91
|
+
inputSchema: tool.inputSchema
|
|
92
|
+
}))
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
case "tools/call": {
|
|
98
|
+
const name = String(rpc.params?.name ?? "");
|
|
99
|
+
const args = typeof rpc.params?.arguments === "object" && rpc.params.arguments !== null ? rpc.params.arguments : {};
|
|
100
|
+
const body = await request("/call", {
|
|
101
|
+
method: "POST",
|
|
102
|
+
body: JSON.stringify({ name, args, turnId, threadId })
|
|
103
|
+
});
|
|
104
|
+
send({
|
|
105
|
+
jsonrpc: "2.0",
|
|
106
|
+
id: rpc.id,
|
|
107
|
+
result: {
|
|
108
|
+
content: resultContent(body.result),
|
|
109
|
+
isError: false
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
default:
|
|
115
|
+
send({
|
|
116
|
+
jsonrpc: "2.0",
|
|
117
|
+
id: rpc.id,
|
|
118
|
+
error: { code: -32601, message: "Method not found" }
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
} catch (err) {
|
|
122
|
+
send({
|
|
123
|
+
jsonrpc: "2.0",
|
|
124
|
+
id: rpc.id,
|
|
125
|
+
error: {
|
|
126
|
+
code: -32e3,
|
|
127
|
+
message: err instanceof Error ? err.message : String(err)
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var lines = import_readline.default.createInterface({ input: process.stdin });
|
|
133
|
+
lines.on("line", (line) => {
|
|
134
|
+
const trimmed = line.trim();
|
|
135
|
+
if (!trimmed) return;
|
|
136
|
+
try {
|
|
137
|
+
const rpc = JSON.parse(trimmed);
|
|
138
|
+
void handle(rpc);
|
|
139
|
+
} catch {
|
|
140
|
+
send({
|
|
141
|
+
jsonrpc: "2.0",
|
|
142
|
+
id: null,
|
|
143
|
+
error: { code: -32700, message: "Parse error" }
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloxco/clox",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Clox from the command line: run your computer for Clox, and manage devices, tasks and businesses.",
|
|
5
|
+
"homepage": "https://www.clox.co/docs",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"bin": {
|
|
8
|
+
"clox": "clox"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"clox",
|
|
12
|
+
"clox.cjs",
|
|
13
|
+
"mcp-proxy.js",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
19
|
+
"optionalDependencies": {
|
|
20
|
+
"@nut-tree-fork/nut-js": "4.2.6"
|
|
21
|
+
}
|
|
22
|
+
}
|