faux-studio 0.4.3 → 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 +44 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10777,8 +10777,8 @@ function sanitizeSchema(obj) {
10777
10777
  }
10778
10778
  return result;
10779
10779
  }
10780
- function sanitizeTools(tools) {
10781
- return tools.map((t) => ({
10780
+ function sanitizeTools(tools2) {
10781
+ return tools2.map((t) => ({
10782
10782
  ...t,
10783
10783
  inputSchema: sanitizeSchema(t.inputSchema)
10784
10784
  }));
@@ -10801,10 +10801,10 @@ async function fetchRemoteTools(jwt2) {
10801
10801
  }
10802
10802
  async function getTools(jwt2) {
10803
10803
  try {
10804
- const tools = await fetchRemoteTools(jwt2);
10805
- await saveCachedTools({ tools, fetchedAt: Date.now() });
10806
- log(`${tools.length} tools loaded`);
10807
- 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;
10808
10808
  } catch (fetchErr) {
10809
10809
  const cached2 = await loadCachedTools();
10810
10810
  if (cached2 && cached2.tools.length > 0) {
@@ -25937,7 +25937,7 @@ Resources provide quick read-only access to Figma state without tool calls:
25937
25937
  - Create components for reusable UI patterns.`;
25938
25938
  function createMcpServer(deps) {
25939
25939
  const server2 = new Server(
25940
- { name: "faux-studio", version: "0.4.3" },
25940
+ { name: "faux-studio", version: "0.4.4" },
25941
25941
  {
25942
25942
  capabilities: { tools: { listChanged: true }, resources: {}, logging: {} },
25943
25943
  instructions: INSTRUCTIONS
@@ -25960,7 +25960,7 @@ function createMcpServer(deps) {
25960
25960
  }
25961
25961
  }
25962
25962
  ];
25963
- const allTools = [...localTools, ...deps.getTools()].map(annotate);
25963
+ const allTools = [...localTools, ...await deps.getTools()].map(annotate);
25964
25964
  return { tools: allTools };
25965
25965
  });
25966
25966
  server2.setRequestHandler(CallToolRequestSchema, async (request) => {
@@ -26153,10 +26153,27 @@ async function startServer(server2) {
26153
26153
 
26154
26154
  // src/index.ts
26155
26155
  var auth;
26156
+ var tools = [];
26156
26157
  var cdpClient = null;
26157
26158
  var fileTracker = null;
26158
26159
  var pluginServer = new PluginWsServer();
26159
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
+ }
26160
26177
  async function tryConnectCdp() {
26161
26178
  try {
26162
26179
  if (cdpClient?.connected && cdpClient.hasContext) return cdpClient;
@@ -26242,6 +26259,7 @@ async function recoverCdp(client, script) {
26242
26259
  }
26243
26260
  }
26244
26261
  async function generateWithAuth(toolName, params) {
26262
+ await lazyInit();
26245
26263
  auth = await refreshIfNeeded(auth);
26246
26264
  let result;
26247
26265
  try {
@@ -26390,13 +26408,7 @@ Call setup_figma again once the plugin shows "Ready".`,
26390
26408
  };
26391
26409
  }
26392
26410
  async function main() {
26393
- log(`faux-studio v${"0.4.3"}`);
26394
- try {
26395
- auth = await ensureAuth();
26396
- } catch (err) {
26397
- error(err instanceof Error ? err.message : String(err));
26398
- process.exit(1);
26399
- }
26411
+ log(`faux-studio v${"0.4.4"}`);
26400
26412
  try {
26401
26413
  const port = await pluginServer.start();
26402
26414
  if (forceTransport === "plugin") {
@@ -26409,25 +26421,16 @@ async function main() {
26409
26421
  } catch (err) {
26410
26422
  warn(`Plugin WS server failed to start: ${err instanceof Error ? err.message : err}`);
26411
26423
  }
26412
- let tools;
26413
- try {
26414
- tools = await getTools(auth.jwt);
26415
- } catch (err) {
26416
- error(err instanceof Error ? err.message : String(err));
26417
- process.exit(1);
26418
- }
26419
- if (forceTransport !== "plugin") {
26420
- try {
26421
- await tryConnectCdp();
26422
- } catch {
26423
- }
26424
- }
26425
26424
  const server2 = createMcpServer({
26426
- getTools: () => tools,
26425
+ getTools: async () => {
26426
+ await lazyInit();
26427
+ return tools;
26428
+ },
26427
26429
  generateScript: generateWithAuth,
26428
26430
  executeScript,
26429
26431
  getJwt: () => auth.jwt,
26430
26432
  refreshJwt: async (force) => {
26433
+ await lazyInit();
26431
26434
  auth = await refreshIfNeeded(auth, force);
26432
26435
  return auth.jwt;
26433
26436
  },
@@ -26442,11 +26445,11 @@ async function main() {
26442
26445
  return { userId: auth.user.id, handle: auth.user.handle, email: auth.user.email };
26443
26446
  },
26444
26447
  getAuthStatus: () => ({
26445
- userId: auth.user.id,
26446
- handle: auth.user.handle,
26447
- email: auth.user.email,
26448
- source: auth.source,
26449
- 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"
26450
26453
  }),
26451
26454
  getTransport: () => {
26452
26455
  if (pluginServer.hasConnections) return "plugin";
@@ -26457,8 +26460,15 @@ async function main() {
26457
26460
  });
26458
26461
  await startServer(server2);
26459
26462
  setServer(server2);
26463
+ if (forceTransport !== "plugin") {
26464
+ try {
26465
+ await tryConnectCdp();
26466
+ } catch {
26467
+ }
26468
+ }
26460
26469
  const REFRESH_INTERVAL = 30 * 6e4;
26461
26470
  setInterval(async () => {
26471
+ if (!initPromise2) return;
26462
26472
  try {
26463
26473
  auth = await refreshIfNeeded(auth);
26464
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.3",
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": {