@biolab/talk-to-figma 0.6.0 → 0.8.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 +0 -125
- package/dist/cli.cjs +31 -2582
- package/dist/cli.js +31 -2562
- package/dist/relay.cjs +4 -158
- package/dist/relay.js +4 -135
- package/dist/talk_to_figma_mcp/server.cjs +28 -2422
- package/dist/talk_to_figma_mcp/server.js +28 -2400
- package/figma-plugin/code.js +489 -3
- package/figma-plugin/figma-plugin.zip +0 -0
- package/package.json +1 -1
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/relay.cjs.map +0 -1
- package/dist/relay.js.map +0 -1
- package/dist/talk_to_figma_mcp/server.cjs.map +0 -1
- package/dist/talk_to_figma_mcp/server.js.map +0 -1
package/dist/relay.cjs
CHANGED
|
@@ -1,159 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/relay.ts
|
|
21
|
-
var relay_exports = {};
|
|
22
|
-
__export(relay_exports, {
|
|
23
|
-
startRelay: () => startRelay
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(relay_exports);
|
|
26
|
-
var import_ws = require("ws");
|
|
27
|
-
var import_http = require("http");
|
|
28
|
-
var channels = /* @__PURE__ */ new Map();
|
|
29
|
-
function startRelay() {
|
|
30
|
-
const port = parseInt(process.env.PORT || "3055", 10);
|
|
31
|
-
const httpServer = (0, import_http.createServer)((req, res) => {
|
|
32
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
33
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
34
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
35
|
-
if (req.method === "OPTIONS") {
|
|
36
|
-
res.writeHead(204);
|
|
37
|
-
res.end();
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
res.writeHead(200);
|
|
41
|
-
res.end("WebSocket server running");
|
|
42
|
-
});
|
|
43
|
-
const wss = new import_ws.WebSocketServer({ server: httpServer });
|
|
44
|
-
wss.on("connection", (ws) => {
|
|
45
|
-
console.log("New client connected");
|
|
46
|
-
ws.send(
|
|
47
|
-
JSON.stringify({
|
|
48
|
-
type: "system",
|
|
49
|
-
message: "Please join a channel to start chatting"
|
|
50
|
-
})
|
|
51
|
-
);
|
|
52
|
-
ws.on("message", (raw) => {
|
|
53
|
-
try {
|
|
54
|
-
const data = JSON.parse(raw.toString());
|
|
55
|
-
console.log(`
|
|
56
|
-
=== Received message from client ===`);
|
|
57
|
-
console.log(`Type: ${data.type}, Channel: ${data.channel || "N/A"}`);
|
|
58
|
-
if (data.message?.command) {
|
|
59
|
-
console.log(`Command: ${data.message.command}, ID: ${data.id}`);
|
|
60
|
-
} else if (data.message?.result) {
|
|
61
|
-
console.log(`Response: ID: ${data.id}, Has Result: ${!!data.message.result}`);
|
|
62
|
-
}
|
|
63
|
-
console.log(`Full message:`, JSON.stringify(data, null, 2));
|
|
64
|
-
if (data.type === "join") {
|
|
65
|
-
const channelName = data.channel;
|
|
66
|
-
if (!channelName || typeof channelName !== "string") {
|
|
67
|
-
ws.send(JSON.stringify({ type: "error", message: "Channel name is required" }));
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (!channels.has(channelName)) {
|
|
71
|
-
channels.set(channelName, /* @__PURE__ */ new Set());
|
|
72
|
-
}
|
|
73
|
-
const channelClients = channels.get(channelName);
|
|
74
|
-
channelClients.add(ws);
|
|
75
|
-
console.log(`
|
|
76
|
-
\u2713 Client joined channel "${channelName}" (${channelClients.size} total clients)`);
|
|
77
|
-
ws.send(
|
|
78
|
-
JSON.stringify({
|
|
79
|
-
type: "system",
|
|
80
|
-
message: `Joined channel: ${channelName}`,
|
|
81
|
-
channel: channelName
|
|
82
|
-
})
|
|
83
|
-
);
|
|
84
|
-
ws.send(
|
|
85
|
-
JSON.stringify({
|
|
86
|
-
type: "system",
|
|
87
|
-
message: {
|
|
88
|
-
id: data.id,
|
|
89
|
-
result: "Connected to channel: " + channelName
|
|
90
|
-
},
|
|
91
|
-
channel: channelName
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
channelClients.forEach((client) => {
|
|
95
|
-
if (client !== ws && client.readyState === import_ws.WebSocket.OPEN) {
|
|
96
|
-
client.send(
|
|
97
|
-
JSON.stringify({
|
|
98
|
-
type: "system",
|
|
99
|
-
message: "A new user has joined the channel",
|
|
100
|
-
channel: channelName
|
|
101
|
-
})
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (data.type === "message") {
|
|
108
|
-
const channelName = data.channel;
|
|
109
|
-
if (!channelName || typeof channelName !== "string") {
|
|
110
|
-
ws.send(JSON.stringify({ type: "error", message: "Channel name is required" }));
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const channelClients = channels.get(channelName);
|
|
114
|
-
if (!channelClients || !channelClients.has(ws)) {
|
|
115
|
-
ws.send(JSON.stringify({ type: "error", message: "You must join the channel first" }));
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
let broadcastCount = 0;
|
|
119
|
-
channelClients.forEach((client) => {
|
|
120
|
-
if (client !== ws && client.readyState === import_ws.WebSocket.OPEN) {
|
|
121
|
-
broadcastCount++;
|
|
122
|
-
const broadcastMessage = {
|
|
123
|
-
type: "broadcast",
|
|
124
|
-
message: data.message,
|
|
125
|
-
sender: "peer",
|
|
126
|
-
channel: channelName
|
|
127
|
-
};
|
|
128
|
-
console.log(`
|
|
129
|
-
=== Broadcasting to peer #${broadcastCount} ===`);
|
|
130
|
-
console.log(JSON.stringify(broadcastMessage, null, 2));
|
|
131
|
-
client.send(JSON.stringify(broadcastMessage));
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
if (broadcastCount === 0) {
|
|
135
|
-
console.log(`\u26A0\uFE0F No other clients in channel "${channelName}" to receive message!`);
|
|
136
|
-
} else {
|
|
137
|
-
console.log(`\u2713 Broadcast to ${broadcastCount} peer(s) in channel "${channelName}"`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
} catch (err) {
|
|
141
|
-
console.error("Error handling message:", err);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
ws.on("close", () => {
|
|
145
|
-
console.log("Client disconnected");
|
|
146
|
-
channels.forEach((clients) => {
|
|
147
|
-
clients.delete(ws);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
httpServer.listen(port, () => {
|
|
152
|
-
console.log(`WebSocket relay running on port ${port}`);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
-
0 && (module.exports = {
|
|
157
|
-
startRelay
|
|
158
|
-
});
|
|
159
|
-
//# sourceMappingURL=relay.cjs.map
|
|
2
|
+
var m=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var u=(r,t)=>{for(var c in t)m(r,c,{get:t[c],enumerable:!0})},N=(r,t,c,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of p(t))!S.call(r,s)&&s!==c&&m(r,s,{get:()=>t[s],enumerable:!(e=f(t,s))||e.enumerable});return r};var O=r=>N(m({},"__esModule",{value:!0}),r);var $={};u($,{startRelay:()=>C});module.exports=O($);var g=require("ws"),y=require("http"),i=new Map;function C(){let r=parseInt(process.env.PORT||"3055",10),t=(0,y.createServer)((e,s)=>{if(s.setHeader("Access-Control-Allow-Origin","*"),s.setHeader("Access-Control-Allow-Methods","GET, POST, OPTIONS"),s.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization"),e.method==="OPTIONS"){s.writeHead(204),s.end();return}s.writeHead(200),s.end("WebSocket server running")});new g.WebSocketServer({server:t}).on("connection",e=>{console.log("New client connected"),e.send(JSON.stringify({type:"system",message:"Please join a channel to start chatting"})),e.on("message",s=>{try{let o=JSON.parse(s.toString());if(console.log(`
|
|
3
|
+
=== Received message from client ===`),console.log(`Type: ${o.type}, Channel: ${o.channel||"N/A"}`),o.message?.command?console.log(`Command: ${o.message.command}, ID: ${o.id}`):o.message?.result&&console.log(`Response: ID: ${o.id}, Has Result: ${!!o.message.result}`),console.log("Full message:",JSON.stringify(o,null,2)),o.type==="join"){let n=o.channel;if(!n||typeof n!="string"){e.send(JSON.stringify({type:"error",message:"Channel name is required"}));return}i.has(n)||i.set(n,new Set);let l=i.get(n);l.add(e),console.log(`
|
|
4
|
+
\u2713 Client joined channel "${n}" (${l.size} total clients)`),e.send(JSON.stringify({type:"system",message:`Joined channel: ${n}`,channel:n})),e.send(JSON.stringify({type:"system",message:{id:o.id,result:"Connected to channel: "+n},channel:n})),l.forEach(a=>{a!==e&&a.readyState===g.WebSocket.OPEN&&a.send(JSON.stringify({type:"system",message:"A new user has joined the channel",channel:n}))});return}if(o.type==="message"){let n=o.channel;if(!n||typeof n!="string"){e.send(JSON.stringify({type:"error",message:"Channel name is required"}));return}let l=i.get(n);if(!l||!l.has(e)){e.send(JSON.stringify({type:"error",message:"You must join the channel first"}));return}let a=0;l.forEach(d=>{if(d!==e&&d.readyState===g.WebSocket.OPEN){a++;let h={type:"broadcast",message:o.message,sender:"peer",channel:n};console.log(`
|
|
5
|
+
=== Broadcasting to peer #${a} ===`),console.log(JSON.stringify(h,null,2)),d.send(JSON.stringify(h))}}),console.log(a===0?`\u26A0\uFE0F No other clients in channel "${n}" to receive message!`:`\u2713 Broadcast to ${a} peer(s) in channel "${n}"`)}}catch(o){console.error("Error handling message:",o)}}),e.on("close",()=>{console.log("Client disconnected"),i.forEach(s=>{s.delete(e)})})}),t.listen(r,()=>{console.log(`WebSocket relay running on port ${r}`)})}0&&(module.exports={startRelay});
|
package/dist/relay.js
CHANGED
|
@@ -1,136 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var channels = /* @__PURE__ */ new Map();
|
|
7
|
-
function startRelay() {
|
|
8
|
-
const port = parseInt(process.env.PORT || "3055", 10);
|
|
9
|
-
const httpServer = createServer((req, res) => {
|
|
10
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
11
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
12
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
13
|
-
if (req.method === "OPTIONS") {
|
|
14
|
-
res.writeHead(204);
|
|
15
|
-
res.end();
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
res.writeHead(200);
|
|
19
|
-
res.end("WebSocket server running");
|
|
20
|
-
});
|
|
21
|
-
const wss = new WebSocketServer({ server: httpServer });
|
|
22
|
-
wss.on("connection", (ws) => {
|
|
23
|
-
console.log("New client connected");
|
|
24
|
-
ws.send(
|
|
25
|
-
JSON.stringify({
|
|
26
|
-
type: "system",
|
|
27
|
-
message: "Please join a channel to start chatting"
|
|
28
|
-
})
|
|
29
|
-
);
|
|
30
|
-
ws.on("message", (raw) => {
|
|
31
|
-
try {
|
|
32
|
-
const data = JSON.parse(raw.toString());
|
|
33
|
-
console.log(`
|
|
34
|
-
=== Received message from client ===`);
|
|
35
|
-
console.log(`Type: ${data.type}, Channel: ${data.channel || "N/A"}`);
|
|
36
|
-
if (data.message?.command) {
|
|
37
|
-
console.log(`Command: ${data.message.command}, ID: ${data.id}`);
|
|
38
|
-
} else if (data.message?.result) {
|
|
39
|
-
console.log(`Response: ID: ${data.id}, Has Result: ${!!data.message.result}`);
|
|
40
|
-
}
|
|
41
|
-
console.log(`Full message:`, JSON.stringify(data, null, 2));
|
|
42
|
-
if (data.type === "join") {
|
|
43
|
-
const channelName = data.channel;
|
|
44
|
-
if (!channelName || typeof channelName !== "string") {
|
|
45
|
-
ws.send(JSON.stringify({ type: "error", message: "Channel name is required" }));
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
if (!channels.has(channelName)) {
|
|
49
|
-
channels.set(channelName, /* @__PURE__ */ new Set());
|
|
50
|
-
}
|
|
51
|
-
const channelClients = channels.get(channelName);
|
|
52
|
-
channelClients.add(ws);
|
|
53
|
-
console.log(`
|
|
54
|
-
\u2713 Client joined channel "${channelName}" (${channelClients.size} total clients)`);
|
|
55
|
-
ws.send(
|
|
56
|
-
JSON.stringify({
|
|
57
|
-
type: "system",
|
|
58
|
-
message: `Joined channel: ${channelName}`,
|
|
59
|
-
channel: channelName
|
|
60
|
-
})
|
|
61
|
-
);
|
|
62
|
-
ws.send(
|
|
63
|
-
JSON.stringify({
|
|
64
|
-
type: "system",
|
|
65
|
-
message: {
|
|
66
|
-
id: data.id,
|
|
67
|
-
result: "Connected to channel: " + channelName
|
|
68
|
-
},
|
|
69
|
-
channel: channelName
|
|
70
|
-
})
|
|
71
|
-
);
|
|
72
|
-
channelClients.forEach((client) => {
|
|
73
|
-
if (client !== ws && client.readyState === WebSocket.OPEN) {
|
|
74
|
-
client.send(
|
|
75
|
-
JSON.stringify({
|
|
76
|
-
type: "system",
|
|
77
|
-
message: "A new user has joined the channel",
|
|
78
|
-
channel: channelName
|
|
79
|
-
})
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (data.type === "message") {
|
|
86
|
-
const channelName = data.channel;
|
|
87
|
-
if (!channelName || typeof channelName !== "string") {
|
|
88
|
-
ws.send(JSON.stringify({ type: "error", message: "Channel name is required" }));
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const channelClients = channels.get(channelName);
|
|
92
|
-
if (!channelClients || !channelClients.has(ws)) {
|
|
93
|
-
ws.send(JSON.stringify({ type: "error", message: "You must join the channel first" }));
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
let broadcastCount = 0;
|
|
97
|
-
channelClients.forEach((client) => {
|
|
98
|
-
if (client !== ws && client.readyState === WebSocket.OPEN) {
|
|
99
|
-
broadcastCount++;
|
|
100
|
-
const broadcastMessage = {
|
|
101
|
-
type: "broadcast",
|
|
102
|
-
message: data.message,
|
|
103
|
-
sender: "peer",
|
|
104
|
-
channel: channelName
|
|
105
|
-
};
|
|
106
|
-
console.log(`
|
|
107
|
-
=== Broadcasting to peer #${broadcastCount} ===`);
|
|
108
|
-
console.log(JSON.stringify(broadcastMessage, null, 2));
|
|
109
|
-
client.send(JSON.stringify(broadcastMessage));
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
if (broadcastCount === 0) {
|
|
113
|
-
console.log(`\u26A0\uFE0F No other clients in channel "${channelName}" to receive message!`);
|
|
114
|
-
} else {
|
|
115
|
-
console.log(`\u2713 Broadcast to ${broadcastCount} peer(s) in channel "${channelName}"`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
} catch (err) {
|
|
119
|
-
console.error("Error handling message:", err);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
ws.on("close", () => {
|
|
123
|
-
console.log("Client disconnected");
|
|
124
|
-
channels.forEach((clients) => {
|
|
125
|
-
clients.delete(ws);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
httpServer.listen(port, () => {
|
|
130
|
-
console.log(`WebSocket relay running on port ${port}`);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
export {
|
|
134
|
-
startRelay
|
|
135
|
-
};
|
|
136
|
-
//# sourceMappingURL=relay.js.map
|
|
2
|
+
import{WebSocketServer as m,WebSocket as d}from"ws";import{createServer as h}from"http";var a=new Map;function S(){let c=parseInt(process.env.PORT||"3055",10),i=h((s,o)=>{if(o.setHeader("Access-Control-Allow-Origin","*"),o.setHeader("Access-Control-Allow-Methods","GET, POST, OPTIONS"),o.setHeader("Access-Control-Allow-Headers","Content-Type, Authorization"),s.method==="OPTIONS"){o.writeHead(204),o.end();return}o.writeHead(200),o.end("WebSocket server running")});new m({server:i}).on("connection",s=>{console.log("New client connected"),s.send(JSON.stringify({type:"system",message:"Please join a channel to start chatting"})),s.on("message",o=>{try{let n=JSON.parse(o.toString());if(console.log(`
|
|
3
|
+
=== Received message from client ===`),console.log(`Type: ${n.type}, Channel: ${n.channel||"N/A"}`),n.message?.command?console.log(`Command: ${n.message.command}, ID: ${n.id}`):n.message?.result&&console.log(`Response: ID: ${n.id}, Has Result: ${!!n.message.result}`),console.log("Full message:",JSON.stringify(n,null,2)),n.type==="join"){let e=n.channel;if(!e||typeof e!="string"){s.send(JSON.stringify({type:"error",message:"Channel name is required"}));return}a.has(e)||a.set(e,new Set);let r=a.get(e);r.add(s),console.log(`
|
|
4
|
+
\u2713 Client joined channel "${e}" (${r.size} total clients)`),s.send(JSON.stringify({type:"system",message:`Joined channel: ${e}`,channel:e})),s.send(JSON.stringify({type:"system",message:{id:n.id,result:"Connected to channel: "+e},channel:e})),r.forEach(t=>{t!==s&&t.readyState===d.OPEN&&t.send(JSON.stringify({type:"system",message:"A new user has joined the channel",channel:e}))});return}if(n.type==="message"){let e=n.channel;if(!e||typeof e!="string"){s.send(JSON.stringify({type:"error",message:"Channel name is required"}));return}let r=a.get(e);if(!r||!r.has(s)){s.send(JSON.stringify({type:"error",message:"You must join the channel first"}));return}let t=0;r.forEach(l=>{if(l!==s&&l.readyState===d.OPEN){t++;let g={type:"broadcast",message:n.message,sender:"peer",channel:e};console.log(`
|
|
5
|
+
=== Broadcasting to peer #${t} ===`),console.log(JSON.stringify(g,null,2)),l.send(JSON.stringify(g))}}),console.log(t===0?`\u26A0\uFE0F No other clients in channel "${e}" to receive message!`:`\u2713 Broadcast to ${t} peer(s) in channel "${e}"`)}}catch(n){console.error("Error handling message:",n)}}),s.on("close",()=>{console.log("Client disconnected"),a.forEach(o=>{o.delete(s)})})}),i.listen(c,()=>{console.log(`WebSocket relay running on port ${c}`)})}export{S as startRelay};
|