@wireweave/sdk 0.1.1-beta.9 → 0.2.0-beta.14

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/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { promises } from 'fs';
2
2
  import os from 'os';
3
3
  import path from 'path';
4
- import { parse, validate, renderToHtml, render, diff, exportToJson, exportToFigma, analyze, walkDocument } from '@wireweave/core';
4
+ import { parse, validate, renderToHtml, render, diff, exportToJson, renderToSvg, exportToFigma, analyze, walkDocument, getV4SourceSpan, createAppBundle, linkApp } from '@wireweave/core';
5
5
  import { validateUX } from '@wireweave/ux-rules';
6
6
  import { ALL_COMPONENTS } from '@wireweave/language-data';
7
+ import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv-provider.js';
7
8
 
8
9
  // src/client.ts
9
10
  var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PATCH", "PUT"]);
@@ -17,18 +18,20 @@ function stringifyParam(value) {
17
18
  function buildRequest(config, endpoint, args) {
18
19
  let path2 = endpoint.path;
19
20
  const body = { ...args };
20
- if (endpoint.pathParams && args) {
21
+ if (endpoint.pathParams) {
21
22
  for (const param of endpoint.pathParams) {
22
- const value = args[param];
23
- if (value !== void 0) {
24
- path2 = path2.replace(`:${param}`, stringifyParam(value));
25
- delete body[param];
23
+ const value = args?.[param];
24
+ if (typeof value !== "string" && typeof value !== "number" || value === "" || value === "." || value === ".." || typeof value === "number" && !Number.isFinite(value)) {
25
+ throw new Error(`Invalid or missing path parameter: ${param}`);
26
26
  }
27
+ path2 = path2.replace(`:${param}`, encodeURIComponent(String(value)));
28
+ delete body[param];
27
29
  }
28
30
  }
29
31
  let url = `${config.apiUrl}${path2}`;
30
32
  const options = {
31
33
  method: endpoint.method,
34
+ redirect: "error",
32
35
  headers: {
33
36
  "Content-Type": "application/json",
34
37
  "x-api-key": config.apiKey
@@ -74,18 +77,23 @@ function extractCreditInfo(headers) {
74
77
  totalAvailable: totalAvailable !== null ? parseInt(totalAvailable, 10) : void 0
75
78
  };
76
79
  }
77
- async function callApi(config, endpoint, args, fetchFn = fetch) {
80
+ async function callApi(config, endpoint, args, fetchFn = fetch, signal) {
81
+ signal?.throwIfAborted();
78
82
  if (!config.apiKey) {
79
83
  throw new Error("WIREWEAVE_API_KEY environment variable is required");
80
84
  }
81
85
  const { url, options } = buildRequest(config, endpoint, args);
86
+ const timeout = AbortSignal.timeout(3e4);
87
+ options.signal = signal ? AbortSignal.any([signal, timeout]) : timeout;
82
88
  const response = await fetchFn(url, options);
89
+ options.signal.throwIfAborted();
83
90
  const creditInfo = extractCreditInfo(response.headers);
84
91
  if (!response.ok) {
85
92
  const error = await response.json().catch(() => ({ error: "Request failed" }));
86
93
  throw new Error(parseErrorMessage(response.status, error));
87
94
  }
88
95
  const result = await response.json();
96
+ options.signal.throwIfAborted();
89
97
  if (typeof result === "object" && result !== null && !Array.isArray(result) && (creditInfo.balance !== void 0 || creditInfo.totalAvailable !== void 0)) {
90
98
  return { ...result, _credits: creditInfo };
91
99
  }
@@ -160,6 +168,12 @@ var tools = [
160
168
  }
161
169
  },
162
170
  required: ["source"]
171
+ },
172
+ annotations: {
173
+ readOnlyHint: true,
174
+ destructiveHint: false,
175
+ idempotentHint: true,
176
+ openWorldHint: false
163
177
  }
164
178
  },
165
179
  {
@@ -179,6 +193,12 @@ var tools = [
179
193
  }
180
194
  },
181
195
  required: ["source"]
196
+ },
197
+ annotations: {
198
+ readOnlyHint: true,
199
+ destructiveHint: false,
200
+ idempotentHint: true,
201
+ openWorldHint: false
182
202
  }
183
203
  },
184
204
  {
@@ -188,6 +208,12 @@ var tools = [
188
208
  type: "object",
189
209
  properties: {},
190
210
  required: []
211
+ },
212
+ annotations: {
213
+ readOnlyHint: true,
214
+ destructiveHint: false,
215
+ idempotentHint: true,
216
+ openWorldHint: false
191
217
  }
192
218
  },
193
219
  {
@@ -197,6 +223,12 @@ var tools = [
197
223
  type: "object",
198
224
  properties: {},
199
225
  required: []
226
+ },
227
+ annotations: {
228
+ readOnlyHint: true,
229
+ destructiveHint: false,
230
+ idempotentHint: true,
231
+ openWorldHint: false
200
232
  }
201
233
  },
202
234
  {
@@ -206,6 +238,12 @@ var tools = [
206
238
  type: "object",
207
239
  properties: {},
208
240
  required: []
241
+ },
242
+ annotations: {
243
+ readOnlyHint: true,
244
+ destructiveHint: false,
245
+ idempotentHint: true,
246
+ openWorldHint: false
209
247
  }
210
248
  },
211
249
  {
@@ -227,6 +265,12 @@ var tools = [
227
265
  }
228
266
  },
229
267
  required: []
268
+ },
269
+ annotations: {
270
+ readOnlyHint: true,
271
+ destructiveHint: false,
272
+ idempotentHint: true,
273
+ openWorldHint: false
230
274
  }
231
275
  },
232
276
  {
@@ -241,6 +285,12 @@ var tools = [
241
285
  }
242
286
  },
243
287
  required: []
288
+ },
289
+ annotations: {
290
+ readOnlyHint: true,
291
+ destructiveHint: false,
292
+ idempotentHint: true,
293
+ openWorldHint: false
244
294
  }
245
295
  },
246
296
  {
@@ -266,6 +316,12 @@ var tools = [
266
316
  }
267
317
  },
268
318
  required: ["source"]
319
+ },
320
+ annotations: {
321
+ readOnlyHint: true,
322
+ destructiveHint: false,
323
+ idempotentHint: true,
324
+ openWorldHint: false
269
325
  }
270
326
  },
271
327
  {
@@ -316,6 +372,12 @@ var tools = [
316
372
  }
317
373
  },
318
374
  required: ["source"]
375
+ },
376
+ annotations: {
377
+ readOnlyHint: true,
378
+ destructiveHint: false,
379
+ idempotentHint: true,
380
+ openWorldHint: false
319
381
  }
320
382
  },
321
383
  {
@@ -325,6 +387,12 @@ var tools = [
325
387
  type: "object",
326
388
  properties: {},
327
389
  required: []
390
+ },
391
+ annotations: {
392
+ readOnlyHint: true,
393
+ destructiveHint: false,
394
+ idempotentHint: true,
395
+ openWorldHint: false
328
396
  }
329
397
  },
330
398
  {
@@ -353,6 +421,12 @@ var tools = [
353
421
  }
354
422
  },
355
423
  required: ["oldSource", "newSource"]
424
+ },
425
+ annotations: {
426
+ readOnlyHint: true,
427
+ destructiveHint: false,
428
+ idempotentHint: true,
429
+ openWorldHint: false
356
430
  }
357
431
  },
358
432
  {
@@ -377,20 +451,170 @@ var tools = [
377
451
  }
378
452
  },
379
453
  required: ["source"]
454
+ },
455
+ annotations: {
456
+ readOnlyHint: true,
457
+ destructiveHint: false,
458
+ idempotentHint: true,
459
+ openWorldHint: false
460
+ }
461
+ },
462
+ {
463
+ name: "wireweave_export_svg",
464
+ description: "Export a linked Wireweave 4 application to deterministic static SVG with source manifest and loss report",
465
+ inputSchema: {
466
+ type: "object",
467
+ properties: {
468
+ source: {
469
+ type: "string",
470
+ description: "Complete Wireweave 4 application source"
471
+ },
472
+ sourceId: {
473
+ type: "string",
474
+ description: "Stable source identifier used by diagnostics",
475
+ default: "input.wf"
476
+ },
477
+ languageVersion: {
478
+ type: "string",
479
+ enum: ["4.0.0"]
480
+ },
481
+ moduleSources: {
482
+ type: "object",
483
+ description: "Optional exact module bytes keyed by module id",
484
+ additionalProperties: {
485
+ type: "string"
486
+ }
487
+ },
488
+ profile: {
489
+ type: "object",
490
+ properties: {
491
+ id: {
492
+ type: "string",
493
+ enum: ["wireweave-static-svg-v1"]
494
+ },
495
+ screens: {
496
+ type: "string",
497
+ enum: ["selected", "all"]
498
+ },
499
+ board: {
500
+ type: "object",
501
+ properties: {
502
+ namespace: {
503
+ type: "string"
504
+ },
505
+ id: {
506
+ type: "string"
507
+ },
508
+ variant: {
509
+ type: "string"
510
+ }
511
+ },
512
+ required: ["namespace", "id"],
513
+ additionalProperties: false
514
+ },
515
+ width: {
516
+ type: "number",
517
+ exclusiveMinimum: 0,
518
+ maximum: 16384
519
+ },
520
+ height: {
521
+ type: "number",
522
+ exclusiveMinimum: 0,
523
+ maximum: 16384
524
+ },
525
+ gap: {
526
+ type: "number",
527
+ minimum: 0,
528
+ maximum: 16384
529
+ },
530
+ background: {
531
+ type: "string",
532
+ minLength: 1,
533
+ maxLength: 128
534
+ }
535
+ },
536
+ required: ["id"],
537
+ additionalProperties: false
538
+ }
539
+ },
540
+ required: ["source", "languageVersion", "profile"]
541
+ },
542
+ annotations: {
543
+ readOnlyHint: true,
544
+ destructiveHint: false,
545
+ idempotentHint: true,
546
+ openWorldHint: false
380
547
  }
381
548
  },
382
549
  {
383
550
  name: "wireweave_export_figma",
384
- description: "Export Wireweave DSL to Figma-compatible format",
551
+ description: "Export Wireweave DSL to a local Figma mapping document; Wireweave 4 mode preserves linked identities and reports semantic loss",
385
552
  inputSchema: {
386
553
  type: "object",
387
554
  properties: {
388
555
  source: {
389
556
  type: "string",
390
557
  description: "The Wireweave DSL source code to export"
558
+ },
559
+ sourceId: {
560
+ type: "string",
561
+ description: "Stable source identifier used by Wireweave 4 diagnostics",
562
+ default: "input.wf"
563
+ },
564
+ languageVersion: {
565
+ type: "string",
566
+ enum: ["4.0.0"]
567
+ },
568
+ moduleSources: {
569
+ type: "object",
570
+ description: "Optional exact module bytes keyed by module id",
571
+ additionalProperties: {
572
+ type: "string"
573
+ }
574
+ },
575
+ profile: {
576
+ type: "object",
577
+ properties: {
578
+ id: {
579
+ type: "string",
580
+ enum: ["wireweave-figma-mapping-v1"]
581
+ },
582
+ target: {
583
+ type: "string",
584
+ enum: ["figma-plugin-json-v1"]
585
+ },
586
+ screens: {
587
+ type: "string",
588
+ enum: ["selected", "all"]
589
+ },
590
+ board: {
591
+ type: "object",
592
+ properties: {
593
+ namespace: {
594
+ type: "string"
595
+ },
596
+ id: {
597
+ type: "string"
598
+ },
599
+ variant: {
600
+ type: "string"
601
+ }
602
+ },
603
+ required: ["namespace", "id"],
604
+ additionalProperties: false
605
+ }
606
+ },
607
+ required: ["id", "target"],
608
+ additionalProperties: false
391
609
  }
392
610
  },
393
611
  required: ["source"]
612
+ },
613
+ annotations: {
614
+ readOnlyHint: true,
615
+ destructiveHint: false,
616
+ idempotentHint: true,
617
+ openWorldHint: false
394
618
  }
395
619
  },
396
620
  {
@@ -430,6 +654,12 @@ var tools = [
430
654
  }
431
655
  },
432
656
  required: ["source"]
657
+ },
658
+ annotations: {
659
+ readOnlyHint: true,
660
+ destructiveHint: false,
661
+ idempotentHint: true,
662
+ openWorldHint: false
433
663
  }
434
664
  },
435
665
  {
@@ -445,6 +675,12 @@ var tools = [
445
675
  }
446
676
  },
447
677
  required: []
678
+ },
679
+ annotations: {
680
+ readOnlyHint: true,
681
+ destructiveHint: false,
682
+ idempotentHint: true,
683
+ openWorldHint: false
448
684
  }
449
685
  },
450
686
  {
@@ -467,6 +703,12 @@ var tools = [
467
703
  }
468
704
  },
469
705
  required: ["name"]
706
+ },
707
+ annotations: {
708
+ readOnlyHint: false,
709
+ destructiveHint: false,
710
+ idempotentHint: false,
711
+ openWorldHint: false
470
712
  }
471
713
  },
472
714
  {
@@ -497,6 +739,12 @@ var tools = [
497
739
  }
498
740
  },
499
741
  required: ["id"]
742
+ },
743
+ annotations: {
744
+ readOnlyHint: false,
745
+ destructiveHint: true,
746
+ idempotentHint: true,
747
+ openWorldHint: false
500
748
  }
501
749
  },
502
750
  {
@@ -528,6 +776,12 @@ var tools = [
528
776
  }
529
777
  },
530
778
  required: []
779
+ },
780
+ annotations: {
781
+ readOnlyHint: true,
782
+ destructiveHint: false,
783
+ idempotentHint: true,
784
+ openWorldHint: false
531
785
  }
532
786
  },
533
787
  {
@@ -542,6 +796,12 @@ var tools = [
542
796
  }
543
797
  },
544
798
  required: ["id"]
799
+ },
800
+ annotations: {
801
+ readOnlyHint: true,
802
+ destructiveHint: false,
803
+ idempotentHint: true,
804
+ openWorldHint: false
545
805
  }
546
806
  },
547
807
  {
@@ -580,6 +840,12 @@ var tools = [
580
840
  }
581
841
  },
582
842
  required: ["name", "code"]
843
+ },
844
+ annotations: {
845
+ readOnlyHint: false,
846
+ destructiveHint: false,
847
+ idempotentHint: false,
848
+ openWorldHint: true
583
849
  }
584
850
  },
585
851
  {
@@ -617,6 +883,12 @@ var tools = [
617
883
  }
618
884
  },
619
885
  required: ["id"]
886
+ },
887
+ annotations: {
888
+ readOnlyHint: false,
889
+ destructiveHint: true,
890
+ idempotentHint: false,
891
+ openWorldHint: true
620
892
  }
621
893
  },
622
894
  {
@@ -631,6 +903,12 @@ var tools = [
631
903
  }
632
904
  },
633
905
  required: ["id"]
906
+ },
907
+ annotations: {
908
+ readOnlyHint: false,
909
+ destructiveHint: true,
910
+ idempotentHint: true,
911
+ openWorldHint: true
634
912
  }
635
913
  },
636
914
  {
@@ -645,6 +923,12 @@ var tools = [
645
923
  }
646
924
  },
647
925
  required: ["wireframeId"]
926
+ },
927
+ annotations: {
928
+ readOnlyHint: true,
929
+ destructiveHint: false,
930
+ idempotentHint: true,
931
+ openWorldHint: false
648
932
  }
649
933
  },
650
934
  {
@@ -663,6 +947,12 @@ var tools = [
663
947
  }
664
948
  },
665
949
  required: ["wireframeId", "version"]
950
+ },
951
+ annotations: {
952
+ readOnlyHint: false,
953
+ destructiveHint: true,
954
+ idempotentHint: false,
955
+ openWorldHint: true
666
956
  }
667
957
  },
668
958
  {
@@ -694,6 +984,12 @@ var tools = [
694
984
  }
695
985
  },
696
986
  required: ["wireframeId"]
987
+ },
988
+ annotations: {
989
+ readOnlyHint: false,
990
+ destructiveHint: false,
991
+ idempotentHint: false,
992
+ openWorldHint: true
697
993
  }
698
994
  },
699
995
  {
@@ -708,6 +1004,12 @@ var tools = [
708
1004
  }
709
1005
  },
710
1006
  required: ["wireframeId"]
1007
+ },
1008
+ annotations: {
1009
+ readOnlyHint: true,
1010
+ destructiveHint: false,
1011
+ idempotentHint: true,
1012
+ openWorldHint: false
711
1013
  }
712
1014
  },
713
1015
  {
@@ -730,6 +1032,12 @@ var tools = [
730
1032
  }
731
1033
  },
732
1034
  required: ["wireframeId", "versionA", "versionB"]
1035
+ },
1036
+ annotations: {
1037
+ readOnlyHint: true,
1038
+ destructiveHint: false,
1039
+ idempotentHint: true,
1040
+ openWorldHint: false
733
1041
  }
734
1042
  },
735
1043
  {
@@ -739,6 +1047,12 @@ var tools = [
739
1047
  type: "object",
740
1048
  properties: {},
741
1049
  required: []
1050
+ },
1051
+ annotations: {
1052
+ readOnlyHint: true,
1053
+ destructiveHint: false,
1054
+ idempotentHint: true,
1055
+ openWorldHint: false
742
1056
  }
743
1057
  },
744
1058
  {
@@ -748,6 +1062,12 @@ var tools = [
748
1062
  type: "object",
749
1063
  properties: {},
750
1064
  required: []
1065
+ },
1066
+ annotations: {
1067
+ readOnlyHint: true,
1068
+ destructiveHint: false,
1069
+ idempotentHint: true,
1070
+ openWorldHint: false
751
1071
  }
752
1072
  },
753
1073
  {
@@ -768,6 +1088,12 @@ var tools = [
768
1088
  }
769
1089
  },
770
1090
  required: []
1091
+ },
1092
+ annotations: {
1093
+ readOnlyHint: true,
1094
+ destructiveHint: false,
1095
+ idempotentHint: true,
1096
+ openWorldHint: false
771
1097
  }
772
1098
  },
773
1099
  {
@@ -777,6 +1103,12 @@ var tools = [
777
1103
  type: "object",
778
1104
  properties: {},
779
1105
  required: []
1106
+ },
1107
+ annotations: {
1108
+ readOnlyHint: true,
1109
+ destructiveHint: false,
1110
+ idempotentHint: true,
1111
+ openWorldHint: false
780
1112
  }
781
1113
  },
782
1114
  {
@@ -799,38 +1131,102 @@ var tools = [
799
1131
  }
800
1132
  },
801
1133
  required: []
1134
+ },
1135
+ annotations: {
1136
+ readOnlyHint: true,
1137
+ destructiveHint: false,
1138
+ idempotentHint: true,
1139
+ openWorldHint: true
802
1140
  }
803
1141
  }
804
1142
  ];
805
1143
  var toolEndpoints = {
806
- wireweave_parse: { method: "POST", path: "/tools/parse" },
807
- wireweave_validate: { method: "POST", path: "/tools/validate" },
808
- wireweave_grammar: { method: "GET", path: "/tools/grammar" },
809
- wireweave_guide: { method: "GET", path: "/tools/guide" },
810
- wireweave_patterns: { method: "GET", path: "/tools/patterns" },
811
- wireweave_examples: { method: "GET", path: "/tools/examples" },
812
- wireweave_list_components: { method: "GET", path: "/tools/list-components" },
813
- wireweave_render_html_code: { method: "POST", path: "/tools/render/html" },
814
- wireweave_validate_ux: { method: "POST", path: "/tools/validate/ux" },
815
- wireweave_ux_rules: { method: "GET", path: "/tools/ux-rules" },
816
- wireweave_diff: { method: "POST", path: "/tools/diff" },
817
- wireweave_export_json: { method: "POST", path: "/tools/export/json" },
818
- wireweave_export_figma: { method: "POST", path: "/tools/export/figma" },
819
- wireweave_analyze: { method: "POST", path: "/tools/analyze" },
820
- wireweave_cloud_list_projects: { method: "GET", path: "/cloud/projects" },
821
- wireweave_cloud_create_project: { method: "POST", path: "/cloud/projects" },
1144
+ wireweave_parse: {
1145
+ method: "POST",
1146
+ path: "/tools/parse"
1147
+ },
1148
+ wireweave_validate: {
1149
+ method: "POST",
1150
+ path: "/tools/validate"
1151
+ },
1152
+ wireweave_grammar: {
1153
+ method: "GET",
1154
+ path: "/tools/grammar"
1155
+ },
1156
+ wireweave_guide: {
1157
+ method: "GET",
1158
+ path: "/tools/guide"
1159
+ },
1160
+ wireweave_patterns: {
1161
+ method: "GET",
1162
+ path: "/tools/patterns"
1163
+ },
1164
+ wireweave_examples: {
1165
+ method: "GET",
1166
+ path: "/tools/examples"
1167
+ },
1168
+ wireweave_list_components: {
1169
+ method: "GET",
1170
+ path: "/tools/list-components"
1171
+ },
1172
+ wireweave_render_html_code: {
1173
+ method: "POST",
1174
+ path: "/tools/render/html"
1175
+ },
1176
+ wireweave_validate_ux: {
1177
+ method: "POST",
1178
+ path: "/tools/validate/ux"
1179
+ },
1180
+ wireweave_ux_rules: {
1181
+ method: "GET",
1182
+ path: "/tools/ux-rules"
1183
+ },
1184
+ wireweave_diff: {
1185
+ method: "POST",
1186
+ path: "/tools/diff"
1187
+ },
1188
+ wireweave_export_json: {
1189
+ method: "POST",
1190
+ path: "/tools/export/json"
1191
+ },
1192
+ wireweave_export_svg: {
1193
+ method: "POST",
1194
+ path: "/tools/export/svg"
1195
+ },
1196
+ wireweave_export_figma: {
1197
+ method: "POST",
1198
+ path: "/tools/export/figma"
1199
+ },
1200
+ wireweave_analyze: {
1201
+ method: "POST",
1202
+ path: "/tools/analyze"
1203
+ },
1204
+ wireweave_cloud_list_projects: {
1205
+ method: "GET",
1206
+ path: "/cloud/projects"
1207
+ },
1208
+ wireweave_cloud_create_project: {
1209
+ method: "POST",
1210
+ path: "/cloud/projects"
1211
+ },
822
1212
  wireweave_cloud_update_project: {
823
1213
  method: "PATCH",
824
1214
  path: "/cloud/projects/:id",
825
1215
  pathParams: ["id"]
826
1216
  },
827
- wireweave_cloud_list_wireframes: { method: "GET", path: "/cloud/wireframes" },
1217
+ wireweave_cloud_list_wireframes: {
1218
+ method: "GET",
1219
+ path: "/cloud/wireframes"
1220
+ },
828
1221
  wireweave_cloud_get_wireframe: {
829
1222
  method: "GET",
830
1223
  path: "/cloud/wireframes/:id",
831
1224
  pathParams: ["id"]
832
1225
  },
833
- wireweave_cloud_save_wireframe: { method: "POST", path: "/cloud/wireframes" },
1226
+ wireweave_cloud_save_wireframe: {
1227
+ method: "POST",
1228
+ path: "/cloud/wireframes"
1229
+ },
834
1230
  wireweave_cloud_update_wireframe: {
835
1231
  method: "PATCH",
836
1232
  path: "/cloud/wireframes/:id",
@@ -866,11 +1262,26 @@ var toolEndpoints = {
866
1262
  path: "/cloud/wireframes/:wireframeId/diff",
867
1263
  pathParams: ["wireframeId"]
868
1264
  },
869
- wireweave_account_balance: { method: "GET", path: "/billing/balance" },
870
- wireweave_account_subscription: { method: "GET", path: "/billing/subscription" },
871
- wireweave_account_transactions: { method: "GET", path: "/billing/transactions" },
872
- wireweave_pricing: { method: "GET", path: "/billing/pricing" },
873
- wireweave_gallery: { method: "GET", path: "/cloud/gallery" }
1265
+ wireweave_account_balance: {
1266
+ method: "GET",
1267
+ path: "/billing/balance"
1268
+ },
1269
+ wireweave_account_subscription: {
1270
+ method: "GET",
1271
+ path: "/billing/subscription"
1272
+ },
1273
+ wireweave_account_transactions: {
1274
+ method: "GET",
1275
+ path: "/billing/transactions"
1276
+ },
1277
+ wireweave_pricing: {
1278
+ method: "GET",
1279
+ path: "/billing/pricing"
1280
+ },
1281
+ wireweave_gallery: {
1282
+ method: "GET",
1283
+ path: "/cloud/gallery"
1284
+ }
874
1285
  };
875
1286
  var localToolNames = /* @__PURE__ */ new Set([
876
1287
  "wireweave_parse",
@@ -880,6 +1291,7 @@ var localToolNames = /* @__PURE__ */ new Set([
880
1291
  "wireweave_validate_ux",
881
1292
  "wireweave_diff",
882
1293
  "wireweave_export_json",
1294
+ "wireweave_export_svg",
883
1295
  "wireweave_export_figma",
884
1296
  "wireweave_analyze"
885
1297
  ]);
@@ -907,6 +1319,8 @@ function localDispatch(toolName, args) {
907
1319
  return listComponentsTool(args);
908
1320
  case "wireweave_export_json":
909
1321
  return exportJsonTool(args);
1322
+ case "wireweave_export_svg":
1323
+ return exportSvgTool(args);
910
1324
  case "wireweave_export_figma":
911
1325
  return exportFigmaTool(args);
912
1326
  default:
@@ -1091,10 +1505,83 @@ function exportJsonTool(args) {
1091
1505
  });
1092
1506
  }
1093
1507
  }
1508
+ function linkedAppFromSource(source, args) {
1509
+ const sourceId = typeof args.sourceId === "string" ? args.sourceId : "input.wf";
1510
+ const document = parse(source, { languageVersion: "4.0.0", sourceId });
1511
+ if (document.app.entry === void 0)
1512
+ return {
1513
+ ok: false,
1514
+ diagnostics: [
1515
+ {
1516
+ severity: "error",
1517
+ code: "WW_SCHEMA",
1518
+ phase: "schema",
1519
+ sourceId,
1520
+ start: 0,
1521
+ end: 0,
1522
+ path: "/app/entry",
1523
+ messageKey: "app.entry-required",
1524
+ details: {},
1525
+ related: []
1526
+ }
1527
+ ]
1528
+ };
1529
+ const provided = args.moduleSources !== null && typeof args.moduleSources === "object" ? args.moduleSources : {};
1530
+ const moduleSources = Object.fromEntries(
1531
+ document.modules.map((module) => {
1532
+ const explicit = provided[module.id];
1533
+ const span = getV4SourceSpan(module);
1534
+ return [
1535
+ module.id,
1536
+ typeof explicit === "string" ? explicit : span === void 0 ? source : source.slice(span.start, span.end)
1537
+ ];
1538
+ })
1539
+ );
1540
+ const bundled = createAppBundle([document], {
1541
+ id: document.app.id,
1542
+ entry: document.app.entry,
1543
+ profile: document.app.profile,
1544
+ states: document.states,
1545
+ registry: document.registry,
1546
+ fixtures: document.fixtures,
1547
+ moduleSources
1548
+ });
1549
+ if (!bundled.ok) return { ok: false, diagnostics: bundled.diagnostics };
1550
+ const linked = linkApp(bundled.value);
1551
+ return linked.ok ? { ok: true, value: linked.value } : { ok: false, diagnostics: linked.diagnostics };
1552
+ }
1553
+ function exportSvgTool(args) {
1554
+ const source = requireString(args, "source");
1555
+ if (source === null) return errorResult("source is required");
1556
+ if (args.languageVersion !== "4.0.0")
1557
+ return errorResult("languageVersion must be 4.0.0 for semantic SVG export");
1558
+ if (args.profile === null || typeof args.profile !== "object")
1559
+ return errorResult("profile is required");
1560
+ try {
1561
+ const linked = linkedAppFromSource(source, args);
1562
+ if (!linked.ok) return successResult({ success: false, diagnostics: linked.diagnostics });
1563
+ const result = renderToSvg(linked.value, args.profile);
1564
+ return result.ok ? successResult({ success: true, ...result.value }) : successResult({ success: false, diagnostics: result.diagnostics });
1565
+ } catch (err) {
1566
+ return successResult({
1567
+ success: false,
1568
+ error: errorMessage(err, "SVG export error"),
1569
+ location: getParseErrorLocation(err)
1570
+ });
1571
+ }
1572
+ }
1094
1573
  function exportFigmaTool(args) {
1095
1574
  const source = requireString(args, "source");
1096
1575
  if (source === null) return errorResult("source is required");
1097
1576
  try {
1577
+ if (args.languageVersion === "4.0.0") {
1578
+ if (args.profile === null || typeof args.profile !== "object")
1579
+ return errorResult("profile is required for semantic Figma export");
1580
+ const linked = linkedAppFromSource(source, args);
1581
+ if (!linked.ok) return successResult({ success: false, diagnostics: linked.diagnostics });
1582
+ const result2 = exportToFigma(linked.value, args.profile);
1583
+ return result2.ok ? successResult({ success: true, ...result2.value }) : successResult({ success: false, diagnostics: result2.diagnostics });
1584
+ }
1098
1585
  const ast = parse(source);
1099
1586
  const result = exportToFigma(ast);
1100
1587
  return successResult({ success: true, ...result });
@@ -1128,18 +1615,32 @@ function analyzeTool(args) {
1128
1615
  });
1129
1616
  }
1130
1617
  }
1131
-
1132
- // src/dispatcher.ts
1618
+ var catalog = new Map(tools.map((tool) => [tool.name, tool]));
1619
+ var validators = /* @__PURE__ */ new Map();
1620
+ var schemaValidator;
1133
1621
  async function dispatch(toolName, args, options) {
1134
- if (isLocalDispatchTool(toolName)) {
1135
- return localDispatch(toolName, args);
1136
- }
1137
- const endpoint = options.endpoints[toolName];
1138
- if (!endpoint) {
1622
+ const tool = catalog.get(toolName);
1623
+ if (!tool) {
1139
1624
  return errorResult2(`Unknown tool: ${toolName}`);
1140
1625
  }
1141
1626
  try {
1142
- const result = await callApi(options.apiConfig, endpoint, args, options.fetchFn);
1627
+ options.signal?.throwIfAborted();
1628
+ let validate2 = validators.get(toolName);
1629
+ if (!validate2) {
1630
+ schemaValidator ??= new AjvJsonSchemaValidator();
1631
+ validate2 = schemaValidator.getValidator(tool.inputSchema);
1632
+ validators.set(toolName, validate2);
1633
+ }
1634
+ const validation = validate2(args);
1635
+ if (!validation.valid) {
1636
+ return errorResult2(`Invalid arguments for ${toolName}: ${validation.errorMessage}`);
1637
+ }
1638
+ if (isLocalDispatchTool(toolName)) {
1639
+ return localDispatch(toolName, args);
1640
+ }
1641
+ const endpoint = Object.hasOwn(options.endpoints, toolName) ? options.endpoints[toolName] : void 0;
1642
+ if (!endpoint) return errorResult2(`Unknown tool: ${toolName}`);
1643
+ const result = await callApi(options.apiConfig, endpoint, args, options.fetchFn, options.signal);
1143
1644
  return successResult2(result);
1144
1645
  } catch (err) {
1145
1646
  return errorResult2(err instanceof Error ? err.message : "Unknown error");
@@ -1160,6 +1661,6 @@ function errorResult2(message) {
1160
1661
  return { content: [block], isError: true };
1161
1662
  }
1162
1663
 
1163
- export { LOCAL_DISPATCH_TOOL_NAMES, buildRequest, callApi, clearToken, dispatch, extractCreditInfo, getConfigPath, isLocalDispatchTool, loadToken, localDispatch, parseErrorMessage, saveToken, toolEndpoints, tools, verifyToken };
1664
+ export { LOCAL_DISPATCH_TOOL_NAMES, buildRequest, callApi, clearToken, dispatch, extractCreditInfo, getConfigPath, isLocalDispatchTool, loadToken, localDispatch, localToolNames, parseErrorMessage, saveToken, toolEndpoints, tools, verifyToken };
1164
1665
  //# sourceMappingURL=index.js.map
1165
1666
  //# sourceMappingURL=index.js.map