faux-studio 0.4.2 → 0.4.4

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.
Files changed (2) hide show
  1. package/dist/index.js +45 -33
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10616,6 +10616,7 @@ async function authenticate() {
10616
10616
  log("Opening browser for Figma sign-in...");
10617
10617
  openBrowser(authUrl);
10618
10618
  log('Waiting for you to click "Allow" in the browser...');
10619
+ await new Promise((r) => setTimeout(r, 5e3));
10619
10620
  const deadline = Date.now() + POLL_TIMEOUT_MS;
10620
10621
  while (Date.now() < deadline) {
10621
10622
  await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
@@ -10776,8 +10777,8 @@ function sanitizeSchema(obj) {
10776
10777
  }
10777
10778
  return result;
10778
10779
  }
10779
- function sanitizeTools(tools) {
10780
- return tools.map((t) => ({
10780
+ function sanitizeTools(tools2) {
10781
+ return tools2.map((t) => ({
10781
10782
  ...t,
10782
10783
  inputSchema: sanitizeSchema(t.inputSchema)
10783
10784
  }));
@@ -10800,10 +10801,10 @@ async function fetchRemoteTools(jwt2) {
10800
10801
  }
10801
10802
  async function getTools(jwt2) {
10802
10803
  try {
10803
- const tools = await fetchRemoteTools(jwt2);
10804
- await saveCachedTools({ tools, fetchedAt: Date.now() });
10805
- log(`${tools.length} tools loaded`);
10806
- return tools;
10804
+ const tools2 = await fetchRemoteTools(jwt2);
10805
+ await saveCachedTools({ tools: tools2, fetchedAt: Date.now() });
10806
+ log(`${tools2.length} tools loaded`);
10807
+ return tools2;
10807
10808
  } catch (fetchErr) {
10808
10809
  const cached2 = await loadCachedTools();
10809
10810
  if (cached2 && cached2.tools.length > 0) {
@@ -25936,7 +25937,7 @@ Resources provide quick read-only access to Figma state without tool calls:
25936
25937
  - Create components for reusable UI patterns.`;
25937
25938
  function createMcpServer(deps) {
25938
25939
  const server2 = new Server(
25939
- { name: "faux-studio", version: "0.4.2" },
25940
+ { name: "faux-studio", version: "0.4.4" },
25940
25941
  {
25941
25942
  capabilities: { tools: { listChanged: true }, resources: {}, logging: {} },
25942
25943
  instructions: INSTRUCTIONS
@@ -25959,7 +25960,7 @@ function createMcpServer(deps) {
25959
25960
  }
25960
25961
  }
25961
25962
  ];
25962
- const allTools = [...localTools, ...deps.getTools()].map(annotate);
25963
+ const allTools = [...localTools, ...await deps.getTools()].map(annotate);
25963
25964
  return { tools: allTools };
25964
25965
  });
25965
25966
  server2.setRequestHandler(CallToolRequestSchema, async (request) => {
@@ -26152,10 +26153,27 @@ async function startServer(server2) {
26152
26153
 
26153
26154
  // src/index.ts
26154
26155
  var auth;
26156
+ var tools = [];
26155
26157
  var cdpClient = null;
26156
26158
  var fileTracker = null;
26157
26159
  var pluginServer = new PluginWsServer();
26158
26160
  var forceTransport = process.env.FAUX_TRANSPORT;
26161
+ var initPromise2 = null;
26162
+ function lazyInit() {
26163
+ if (!initPromise2) {
26164
+ initPromise2 = doInit();
26165
+ }
26166
+ return initPromise2;
26167
+ }
26168
+ async function doInit() {
26169
+ auth = await ensureAuth();
26170
+ try {
26171
+ tools = await getTools(auth.jwt);
26172
+ } catch (err) {
26173
+ error(err instanceof Error ? err.message : String(err));
26174
+ process.exit(1);
26175
+ }
26176
+ }
26159
26177
  async function tryConnectCdp() {
26160
26178
  try {
26161
26179
  if (cdpClient?.connected && cdpClient.hasContext) return cdpClient;
@@ -26241,6 +26259,7 @@ async function recoverCdp(client, script) {
26241
26259
  }
26242
26260
  }
26243
26261
  async function generateWithAuth(toolName, params) {
26262
+ await lazyInit();
26244
26263
  auth = await refreshIfNeeded(auth);
26245
26264
  let result;
26246
26265
  try {
@@ -26389,12 +26408,7 @@ Call setup_figma again once the plugin shows "Ready".`,
26389
26408
  };
26390
26409
  }
26391
26410
  async function main() {
26392
- try {
26393
- auth = await ensureAuth();
26394
- } catch (err) {
26395
- error(err instanceof Error ? err.message : String(err));
26396
- process.exit(1);
26397
- }
26411
+ log(`faux-studio v${"0.4.4"}`);
26398
26412
  try {
26399
26413
  const port = await pluginServer.start();
26400
26414
  if (forceTransport === "plugin") {
@@ -26407,25 +26421,16 @@ async function main() {
26407
26421
  } catch (err) {
26408
26422
  warn(`Plugin WS server failed to start: ${err instanceof Error ? err.message : err}`);
26409
26423
  }
26410
- let tools;
26411
- try {
26412
- tools = await getTools(auth.jwt);
26413
- } catch (err) {
26414
- error(err instanceof Error ? err.message : String(err));
26415
- process.exit(1);
26416
- }
26417
- if (forceTransport !== "plugin") {
26418
- try {
26419
- await tryConnectCdp();
26420
- } catch {
26421
- }
26422
- }
26423
26424
  const server2 = createMcpServer({
26424
- getTools: () => tools,
26425
+ getTools: async () => {
26426
+ await lazyInit();
26427
+ return tools;
26428
+ },
26425
26429
  generateScript: generateWithAuth,
26426
26430
  executeScript,
26427
26431
  getJwt: () => auth.jwt,
26428
26432
  refreshJwt: async (force) => {
26433
+ await lazyInit();
26429
26434
  auth = await refreshIfNeeded(auth, force);
26430
26435
  return auth.jwt;
26431
26436
  },
@@ -26440,11 +26445,11 @@ async function main() {
26440
26445
  return { userId: auth.user.id, handle: auth.user.handle, email: auth.user.email };
26441
26446
  },
26442
26447
  getAuthStatus: () => ({
26443
- userId: auth.user.id,
26444
- handle: auth.user.handle,
26445
- email: auth.user.email,
26446
- source: auth.source,
26447
- isApiKey: auth.source === "api-key"
26448
+ userId: auth?.user?.id ?? "",
26449
+ handle: auth?.user?.handle ?? "",
26450
+ email: auth?.user?.email ?? "",
26451
+ source: auth?.source ?? "none",
26452
+ isApiKey: auth?.source === "api-key"
26448
26453
  }),
26449
26454
  getTransport: () => {
26450
26455
  if (pluginServer.hasConnections) return "plugin";
@@ -26455,8 +26460,15 @@ async function main() {
26455
26460
  });
26456
26461
  await startServer(server2);
26457
26462
  setServer(server2);
26463
+ if (forceTransport !== "plugin") {
26464
+ try {
26465
+ await tryConnectCdp();
26466
+ } catch {
26467
+ }
26468
+ }
26458
26469
  const REFRESH_INTERVAL = 30 * 6e4;
26459
26470
  setInterval(async () => {
26471
+ if (!initPromise2) return;
26460
26472
  try {
26461
26473
  auth = await refreshIfNeeded(auth);
26462
26474
  const fresh = await getTools(auth.jwt);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "faux-studio",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "AI-powered Figma design via MCP — connect any AI client to Figma Desktop",
5
5
  "type": "module",
6
6
  "bin": {