@vivix-labs/studio-chat-mcp 0.0.0-stage → 0.1.2

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/setup.js ADDED
@@ -0,0 +1,992 @@
1
+ // scripts/setup.mjs
2
+ import { execFileSync } from "node:child_process";
3
+ import { createHash, randomUUID } from "node:crypto";
4
+ import { homedir } from "node:os";
5
+ import { join, resolve } from "node:path";
6
+ import {
7
+ lstat,
8
+ mkdir,
9
+ readFile,
10
+ readlink,
11
+ realpath,
12
+ rename,
13
+ rm,
14
+ symlink,
15
+ writeFile
16
+ } from "node:fs/promises";
17
+ import { setTimeout as delay } from "node:timers/promises";
18
+
19
+ // ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/error.js
20
+ function getLineColFromPtr(string, ptr) {
21
+ let lines = string.slice(0, ptr).split(/\r?\n/);
22
+ return [lines.length, lines.pop().length + 1];
23
+ }
24
+ function makeCodeBlock(string, line, column) {
25
+ let lines = string.split(/\r?\n/);
26
+ let codeblock = "";
27
+ let numberLen = (Math.log10(line + 1) | 0) + 1;
28
+ for (let i = line - 1; i <= line + 1; i++) {
29
+ let l = lines[i - 1];
30
+ if (!l)
31
+ continue;
32
+ codeblock += i.toString().padEnd(numberLen, " ");
33
+ codeblock += ": ";
34
+ codeblock += l;
35
+ codeblock += "\n";
36
+ if (i === line) {
37
+ codeblock += " ".repeat(numberLen + column + 2);
38
+ codeblock += "^\n";
39
+ }
40
+ }
41
+ return codeblock;
42
+ }
43
+ var TomlError = class _TomlError extends Error {
44
+ line;
45
+ column;
46
+ codeblock;
47
+ constructor(message, options) {
48
+ const [line, column] = getLineColFromPtr(options.toml, options.ptr);
49
+ const codeblock = makeCodeBlock(options.toml, line, column);
50
+ super(`Invalid TOML document: ${message}
51
+
52
+ ${codeblock}`, options);
53
+ this.line = line;
54
+ this.column = column;
55
+ this.codeblock = codeblock;
56
+ }
57
+ /** @internal */
58
+ static x(message, ctx, ptr) {
59
+ throw new _TomlError(message, { toml: ctx.s, ptr: ptr ?? ctx.p });
60
+ }
61
+ };
62
+
63
+ // ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/primitive.js
64
+ function parseString(ctx) {
65
+ let startPtr = ctx.p;
66
+ let c = ctx.s.charCodeAt(ctx.p++);
67
+ let first = c;
68
+ let isLiteral = c === 39;
69
+ let isMultiline = c === ctx.s.charCodeAt(ctx.p) && c === ctx.s.charCodeAt(ctx.p + 1);
70
+ if (isMultiline) {
71
+ if ((c = ctx.s.charCodeAt(ctx.p += 2)) === 10)
72
+ ctx.p++;
73
+ else if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)
74
+ ctx.p += 2;
75
+ }
76
+ let parsed = "";
77
+ let sliceStart = ctx.p;
78
+ let state = 0;
79
+ for (; ctx.p < ctx.s.length; ctx.p++) {
80
+ c = ctx.s.charCodeAt(ctx.p);
81
+ if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) {
82
+ state = state && 3;
83
+ } else if (c < 32 && c !== 9 || c === 127) {
84
+ TomlError.x("control characters are not allowed in strings", ctx);
85
+ } else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
86
+ if (isMultiline) {
87
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
88
+ ctx.p++;
89
+ if (ctx.s.charCodeAt(ctx.p + 3) === first)
90
+ ctx.p++;
91
+ }
92
+ if (!state) {
93
+ let s = ctx.s.slice(sliceStart, ctx.p);
94
+ parsed = parsed ? parsed + s : s;
95
+ }
96
+ ctx.p += isMultiline ? 3 : 1;
97
+ return parsed;
98
+ } else if (!state) {
99
+ if (!isLiteral && c === 92) {
100
+ parsed += ctx.s.slice(sliceStart, sliceStart = ctx.p);
101
+ state = 1;
102
+ }
103
+ } else if (state === 1) {
104
+ if (c === 120 || c === 117 || c === 85) {
105
+ let errPtr = ctx.p++ - 1;
106
+ let value = 0;
107
+ let len = c === 120 ? 2 : c === 117 ? 4 : 8;
108
+ for (let j = 0; j < len; j++, ctx.p++) {
109
+ let hex = ctx.s.charCodeAt(ctx.p);
110
+ let digit = (
111
+ /* 0-9 */
112
+ hex >= 48 && hex <= 57 ? hex - 48 : (
113
+ /* A-F */
114
+ hex >= 65 && hex <= 70 ? hex - 65 + 10 : (
115
+ /* a-f */
116
+ hex >= 97 && hex <= 102 ? hex - 97 + 10 : -1
117
+ )
118
+ )
119
+ );
120
+ if (digit < 0)
121
+ TomlError.x("invalid non-hex character in unicode escape", ctx);
122
+ value = value << 4 | digit;
123
+ }
124
+ if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) {
125
+ TomlError.x("invalid unicode escape", ctx, errPtr);
126
+ }
127
+ parsed += String.fromCodePoint(value);
128
+ sliceStart = ctx.p--;
129
+ state = 0;
130
+ } else if (isMultiline && (c === 32 || c === 9)) {
131
+ state = 2;
132
+ } else {
133
+ if (c === 98)
134
+ parsed += "\b";
135
+ else if (c === 116)
136
+ parsed += " ";
137
+ else if (c === 110)
138
+ parsed += "\n";
139
+ else if (c === 102)
140
+ parsed += "\f";
141
+ else if (c === 114)
142
+ parsed += "\r";
143
+ else if (c === 101)
144
+ parsed += "\x1B";
145
+ else if (c === 34)
146
+ parsed += '"';
147
+ else if (c === 92)
148
+ parsed += "\\";
149
+ else
150
+ TomlError.x("unrecognised escape sequence", ctx);
151
+ sliceStart = ctx.p + 1;
152
+ state = 0;
153
+ }
154
+ } else if (c !== 32 && c !== 9) {
155
+ if (state === 2)
156
+ TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
157
+ state = !isLiteral && c === 92 ? 1 : 0;
158
+ sliceStart = ctx.p;
159
+ }
160
+ }
161
+ TomlError.x("unfinished string", ctx, startPtr);
162
+ }
163
+
164
+ // ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/date.js
165
+ var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
166
+ var TomlDate = class _TomlDate extends Date {
167
+ #hasDate = false;
168
+ #hasTime = false;
169
+ #offset = null;
170
+ constructor(date, fasttype, unsafeDelim) {
171
+ let hasDate = true;
172
+ let hasTime = true;
173
+ let offset = "Z";
174
+ let c;
175
+ if (typeof date === "string") {
176
+ if (fasttype)
177
+ prep: {
178
+ if (fasttype < 3) {
179
+ if (+date.slice(11, 13) > 23) {
180
+ date = "";
181
+ break prep;
182
+ }
183
+ if (fasttype === 2) {
184
+ offset = null;
185
+ date += "Z";
186
+ } else if ((c = date.charCodeAt(date.length - 1)) !== 90 && c !== 122) {
187
+ offset = date.slice(date.length - 6);
188
+ }
189
+ if (unsafeDelim)
190
+ date = date.slice(0, 10) + "T" + date.slice(11);
191
+ } else if (fasttype === 4) {
192
+ date = +date.slice(0, 2) > 23 ? "" : `0000-01-01T${date}Z`;
193
+ }
194
+ hasDate = fasttype !== 4;
195
+ hasTime = fasttype !== 3;
196
+ }
197
+ else {
198
+ let match = date.match(DATE_TIME_RE);
199
+ if (match) {
200
+ if (!match[1]) {
201
+ hasDate = false;
202
+ date = `0000-01-01T${date}`;
203
+ }
204
+ hasTime = !!match[2];
205
+ hasTime && date[10] === " " && (date = date.replace(" ", "T"));
206
+ if (match[2] && +match[2] > 23) {
207
+ date = "";
208
+ } else {
209
+ offset = match[3] || null;
210
+ if (!offset && hasTime)
211
+ date += "Z";
212
+ }
213
+ } else {
214
+ date = "";
215
+ }
216
+ }
217
+ }
218
+ super(date);
219
+ if (!isNaN(this.getTime())) {
220
+ this.#hasDate = hasDate;
221
+ this.#hasTime = hasTime;
222
+ this.#offset = offset;
223
+ }
224
+ }
225
+ isDateTime() {
226
+ return this.#hasDate && this.#hasTime;
227
+ }
228
+ isLocal() {
229
+ return !this.#hasDate || !this.#hasTime || !this.#offset;
230
+ }
231
+ isDate() {
232
+ return this.#hasDate && !this.#hasTime;
233
+ }
234
+ isTime() {
235
+ return this.#hasTime && !this.#hasDate;
236
+ }
237
+ isValid() {
238
+ return this.#hasDate || this.#hasTime;
239
+ }
240
+ toISOString() {
241
+ let iso = super.toISOString();
242
+ if (this.isDate())
243
+ return iso.slice(0, 10);
244
+ if (this.isTime())
245
+ return iso.slice(11, 23);
246
+ if (this.#offset === null)
247
+ return iso.slice(0, -1);
248
+ if (this.#offset === "Z" || this.#offset === "z")
249
+ return iso;
250
+ let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
251
+ offset = this.#offset[0] === "-" ? offset : -offset;
252
+ let offsetDate = new Date(this.getTime() - offset * 6e4);
253
+ return offsetDate.toISOString().slice(0, -1) + this.#offset;
254
+ }
255
+ static wrapAsOffsetDateTime(jsDate, offset = "Z") {
256
+ let date = new _TomlDate(jsDate);
257
+ date.#offset = offset;
258
+ return date;
259
+ }
260
+ static wrapAsLocalDateTime(jsDate) {
261
+ let date = new _TomlDate(jsDate);
262
+ date.#offset = null;
263
+ return date;
264
+ }
265
+ static wrapAsLocalDate(jsDate) {
266
+ let date = new _TomlDate(jsDate);
267
+ date.#hasTime = false;
268
+ date.#offset = null;
269
+ return date;
270
+ }
271
+ static wrapAsLocalTime(jsDate) {
272
+ let date = new _TomlDate(jsDate);
273
+ date.#hasDate = false;
274
+ date.#offset = null;
275
+ return date;
276
+ }
277
+ };
278
+
279
+ // ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/extract.js
280
+ function isDigit(char, base = 10) {
281
+ return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
282
+ }
283
+ function isEndOfValue(char, delim) {
284
+ return char === 32 || char === 9 || char === 10 || char === 13 || // Structure end or next value delimiter
285
+ delim && (char === delim || char === 44) || // Comment
286
+ char === 35;
287
+ }
288
+ function extractValue(ctx, end) {
289
+ let errPtr = ctx.p;
290
+ let c = ctx.s.charCodeAt(ctx.p);
291
+ if (c === 91 || c === 123) {
292
+ ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
293
+ let value = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
294
+ ctx.d++;
295
+ return value;
296
+ }
297
+ if (c === 34 || c === 39) {
298
+ return parseString(ctx);
299
+ }
300
+ if (c === 116) {
301
+ if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101)
302
+ TomlError.x("invalid value", ctx, errPtr);
303
+ return ctx.p++, true;
304
+ }
305
+ if (c === 102) {
306
+ if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101)
307
+ TomlError.x("invalid value", ctx, errPtr);
308
+ return ctx.p++, false;
309
+ }
310
+ if (c === 43 || c === 45) {
311
+ return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
312
+ }
313
+ if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) {
314
+ return parseDate(ctx, c, end);
315
+ }
316
+ if (ctx.s.charCodeAt(ctx.p + 2) === 58) {
317
+ return parseTime(ctx, c, end);
318
+ }
319
+ return parseNumber(ctx, ctx.p, c, 0, end);
320
+ }
321
+ function parseNumber(ctx, startPtr, startChr, sign, endChr) {
322
+ let c = startChr;
323
+ let state = 0;
324
+ let hasUnderscores = false;
325
+ if (c === 105) {
326
+ if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102)
327
+ TomlError.x("invalid value", ctx, startPtr);
328
+ return ctx.p++, (sign || 1) / 0;
329
+ }
330
+ if (c === 110) {
331
+ if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110)
332
+ TomlError.x("invalid value", ctx, startPtr);
333
+ return ctx.p++, NaN;
334
+ }
335
+ if (c === 48) {
336
+ if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr))
337
+ return ctx.bi === true ? 0n : 0;
338
+ if (!sign) {
339
+ if (c === 120)
340
+ return parseIntegerBaseN(ctx, startPtr, 16, endChr);
341
+ else if (c === 98)
342
+ return parseIntegerBaseN(ctx, startPtr, 2, endChr);
343
+ else if (c === 111)
344
+ return parseIntegerBaseN(ctx, startPtr, 8, endChr);
345
+ }
346
+ if (c === 46)
347
+ state = 2;
348
+ else if (c === 101 || c === 69)
349
+ state = 4;
350
+ else
351
+ TomlError.x("illegal leading zero", ctx, startPtr);
352
+ } else if (!isDigit(c))
353
+ TomlError.x("invalid value", ctx, startPtr);
354
+ while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
355
+ if (!state)
356
+ state = 1;
357
+ if (c === 95) {
358
+ if (!(state & 1))
359
+ TomlError.x("illegal underscore", ctx);
360
+ state += 11;
361
+ hasUnderscores = true;
362
+ } else if (state === 1 && c === 46)
363
+ state = 2;
364
+ else if ((state === 1 || state === 3) && (c === 101 || c === 69))
365
+ state = 4;
366
+ else if (state === 4 && (c === 43 || c === 45)) {
367
+ state = 6;
368
+ } else if (!isDigit(c))
369
+ TomlError.x(`illegal character in numeric literal`, ctx);
370
+ else if (state > 9)
371
+ state -= 11;
372
+ else if (!(state & 1))
373
+ state++;
374
+ }
375
+ if (!state) {
376
+ let val = (startChr - 48) * (sign || 1);
377
+ return ctx.bi === true ? BigInt(val) : val;
378
+ }
379
+ if (!(state & 1))
380
+ TomlError.x("unfinished numeric value", ctx, startPtr);
381
+ let str = ctx.s.slice(startPtr, ctx.p);
382
+ if (hasUnderscores)
383
+ str = str.replaceAll("_", "");
384
+ return state > 1 ? parseFloat(str) : parseInteger(ctx, str, 10, startPtr);
385
+ }
386
+ function parseIntegerBaseN(ctx, startPtr, base, endChr) {
387
+ let c, underscore = 1;
388
+ while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
389
+ if (c === 95) {
390
+ if (underscore & 1)
391
+ TomlError.x("illegal underscore", ctx);
392
+ underscore = 3;
393
+ } else if (!isDigit(c, base))
394
+ TomlError.x(`illegal character in numeric literal`, ctx);
395
+ else if (underscore & 1)
396
+ underscore--;
397
+ }
398
+ if (underscore & 1)
399
+ TomlError.x("unfinished numeric value", ctx);
400
+ let str = ctx.s.slice(startPtr + 2, ctx.p);
401
+ if (underscore)
402
+ str = str.replaceAll("_", "");
403
+ return parseInteger(ctx, str, base, startPtr);
404
+ }
405
+ function parseInteger(ctx, str, base, startPtr) {
406
+ if (ctx.bi !== true)
407
+ int: {
408
+ let val = parseInt(str, base);
409
+ if (!Number.isSafeInteger(val)) {
410
+ if (ctx.bi)
411
+ break int;
412
+ TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
413
+ }
414
+ return val;
415
+ }
416
+ return base === 10 ? BigInt(str) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str);
417
+ }
418
+ function parseDate(ctx, c, endChr) {
419
+ let startPtr = ctx.p++, unsafeSeparator;
420
+ if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++)) || !isDigit(ctx.s.charCodeAt(ctx.p++))) {
421
+ return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
422
+ }
423
+ ctx.p += 5;
424
+ if (!isDigit(ctx.s.charCodeAt(ctx.p++)))
425
+ TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
426
+ if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) {
427
+ let t2 = ctx.s.slice(startPtr, ctx.p);
428
+ return readDate(ctx, t2, 3, false, startPtr);
429
+ }
430
+ if (ctx.s.charCodeAt(ctx.p += 3) !== 58)
431
+ TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
432
+ if (ctx.s.charCodeAt(ctx.p += 3) === 58)
433
+ ctx.p += 3;
434
+ if (ctx.s.charCodeAt(ctx.p) === 46)
435
+ while (isDigit(ctx.s.charCodeAt(++ctx.p)))
436
+ ;
437
+ if (c = ctx.s.charCodeAt(ctx.p)) {
438
+ if (c === 90 || c === 122) {
439
+ let t2 = ctx.s.slice(startPtr, ++ctx.p);
440
+ return readDate(ctx, t2, 1, unsafeSeparator, startPtr, "[+00:00]");
441
+ }
442
+ if (c === 43 || c === 45) {
443
+ let t2 = ctx.s.slice(startPtr, ctx.p += 6);
444
+ return readDate(ctx, t2, 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
445
+ }
446
+ }
447
+ let t = ctx.s.slice(startPtr, ctx.p);
448
+ return readDate(ctx, t, 2, unsafeSeparator, startPtr);
449
+ }
450
+ function parseTime(ctx, c, endChr) {
451
+ let start = ctx.p;
452
+ if (!isDigit(c) || !isDigit(ctx.s.charCodeAt(++ctx.p))) {
453
+ return parseNumber(ctx, --ctx.p, c, 0, endChr);
454
+ }
455
+ if (ctx.s.charCodeAt(ctx.p += 4) === 58)
456
+ ctx.p += 3;
457
+ if (ctx.s.charCodeAt(ctx.p) === 46)
458
+ while (isDigit(ctx.s.charCodeAt(++ctx.p)))
459
+ ;
460
+ let t = ctx.s.slice(start, ctx.p);
461
+ return readDate(ctx, t, 4, false, start);
462
+ }
463
+ function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
464
+ if (ctx.ld) {
465
+ let date = new TomlDate(str, type, unsafeDelim);
466
+ if (!date.isValid())
467
+ TomlError.x("invalid date", ctx, errPtr);
468
+ return date;
469
+ }
470
+ try {
471
+ if (temporalSuffix)
472
+ str += temporalSuffix;
473
+ switch (type) {
474
+ case 1:
475
+ return Temporal.ZonedDateTime.from(str);
476
+ case 2:
477
+ return Temporal.PlainDateTime.from(str);
478
+ case 3:
479
+ return Temporal.PlainDate.from(str);
480
+ case 4:
481
+ return Temporal.PlainTime.from(str);
482
+ }
483
+ } catch (e) {
484
+ TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
485
+ }
486
+ }
487
+
488
+ // ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/util.js
489
+ function skipComment(ctx) {
490
+ for (; ctx.p < ctx.s.length; ctx.p++) {
491
+ let c = ctx.s.charCodeAt(ctx.p);
492
+ if (c === 10)
493
+ break;
494
+ if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
495
+ ctx.p++;
496
+ break;
497
+ }
498
+ if (c < 32 && c !== 9 || c === 127) {
499
+ TomlError.x("control characters are not allowed in comments", ctx);
500
+ }
501
+ }
502
+ }
503
+ function skipVoid(ctx, banNewLines, banComments) {
504
+ let c;
505
+ while (ctx.p < ctx.s.length) {
506
+ while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)))
507
+ ctx.p++;
508
+ if (banComments || c !== 35)
509
+ break;
510
+ skipComment(ctx);
511
+ }
512
+ }
513
+
514
+ // ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/struct.js
515
+ function parseKey(ctx, end = 61) {
516
+ let startPtr;
517
+ let state = 0;
518
+ let parsed = [];
519
+ let sliceStart;
520
+ let c = ctx.s.charCodeAt(startPtr = ctx.p);
521
+ do {
522
+ if (c === end) {
523
+ if (!state)
524
+ TomlError.x("unexpected end of key", ctx);
525
+ if (state === 1)
526
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
527
+ return ctx.p++, parsed;
528
+ } else if (c === 46) {
529
+ if (!state)
530
+ TomlError.x("illegal empty bare key", ctx);
531
+ if (state === 1)
532
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
533
+ state = 0;
534
+ } else if (!state && (c === 34 || c === 39)) {
535
+ if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2))
536
+ TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
537
+ parsed.push(parseString(ctx));
538
+ state = 2;
539
+ ctx.p--;
540
+ } else if (c === 32 || c === 9) {
541
+ if (state === 1) {
542
+ parsed.push(ctx.s.slice(sliceStart, ctx.p));
543
+ state = 2;
544
+ }
545
+ } else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) {
546
+ TomlError.x("illegal character in key", ctx);
547
+ } else if (!state) {
548
+ state = 1;
549
+ sliceStart = ctx.p;
550
+ }
551
+ } while (c = ctx.s.charCodeAt(++ctx.p));
552
+ TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
553
+ }
554
+ function parseInlineTable(ctx) {
555
+ let startPtr = ctx.p++;
556
+ let res = /* @__PURE__ */ Object.create(null);
557
+ let seen = /* @__PURE__ */ new Set();
558
+ let c;
559
+ while (ctx.p < ctx.s.length) {
560
+ skipVoid(ctx);
561
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
562
+ ctx.p++;
563
+ return res;
564
+ }
565
+ let k;
566
+ let t = res;
567
+ let hasOwn = false;
568
+ let errPtr = ctx.p;
569
+ let key = parseKey(ctx);
570
+ for (let i = 0; i < key.length; i++) {
571
+ if (i)
572
+ t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
573
+ k = key[i];
574
+ if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
575
+ TomlError.x("trying to redefine an already defined value", ctx, errPtr);
576
+ }
577
+ let unsafe = k === "__proto__";
578
+ if (ctx.uk && (unsafe || k === "constructor")) {
579
+ t = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
580
+ break;
581
+ }
582
+ if (!hasOwn && unsafe) {
583
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
584
+ }
585
+ }
586
+ if (hasOwn) {
587
+ TomlError.x("trying to redefine an already defined value", ctx, errPtr);
588
+ }
589
+ skipVoid(ctx, true, true);
590
+ let value = extractValue(
591
+ ctx,
592
+ 125
593
+ /* } */
594
+ );
595
+ if (t && typeof (t[k] = value) === "object")
596
+ seen.add(value);
597
+ skipVoid(ctx);
598
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) {
599
+ return res;
600
+ }
601
+ if (c !== 44)
602
+ TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
603
+ }
604
+ TomlError.x("unfinished table", ctx, startPtr);
605
+ }
606
+ function parseArray(ctx) {
607
+ let startPtr = ctx.p++;
608
+ let res = [];
609
+ let c;
610
+ while (ctx.p < ctx.s.length) {
611
+ skipVoid(ctx);
612
+ if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
613
+ ctx.p++;
614
+ return res;
615
+ }
616
+ res.push(extractValue(
617
+ ctx,
618
+ 93
619
+ /* ] */
620
+ ));
621
+ skipVoid(ctx);
622
+ if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) {
623
+ return res;
624
+ }
625
+ if (c !== 44)
626
+ TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
627
+ }
628
+ TomlError.x("unfinished array", ctx, startPtr);
629
+ }
630
+
631
+ // ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/parse.js
632
+ function peekTable(ctx, key, table, meta, type) {
633
+ let t = table;
634
+ let m = meta;
635
+ let k;
636
+ let hasOwn = false;
637
+ let state;
638
+ for (let i = 0; i < key.length; i++) {
639
+ if (i) {
640
+ t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
641
+ m = (state = m[k]).c;
642
+ if (type === 0 && (state.t === 1 || state.t === 2)) {
643
+ return null;
644
+ }
645
+ if (state.t === 2) {
646
+ let l = t.length - 1;
647
+ t = t[l];
648
+ m = m[l].c;
649
+ }
650
+ }
651
+ k = key[i];
652
+ if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) {
653
+ return null;
654
+ }
655
+ if (!hasOwn) {
656
+ let unsafe = k === "__proto__";
657
+ if (ctx.uk && (unsafe || k === "constructor"))
658
+ return false;
659
+ if (unsafe) {
660
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
661
+ Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
662
+ }
663
+ m[k] = {
664
+ t: i < key.length - 1 && type === 2 ? 3 : type,
665
+ d: false,
666
+ i: 0,
667
+ c: /* @__PURE__ */ Object.create(null)
668
+ };
669
+ }
670
+ }
671
+ state = m[k];
672
+ if (state.t !== type && !(type === 1 && state.t === 3)) {
673
+ return null;
674
+ }
675
+ if (type === 2) {
676
+ if (!state.d) {
677
+ state.d = true;
678
+ t[k] = [];
679
+ }
680
+ t[k].push(t = /* @__PURE__ */ Object.create(null));
681
+ state.c[state.i++] = state = { t: 1, d: false, i: 0, c: /* @__PURE__ */ Object.create(null) };
682
+ }
683
+ if (state.d) {
684
+ return null;
685
+ }
686
+ state.d = true;
687
+ if (type === 1) {
688
+ t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
689
+ } else if (type === 0 && hasOwn) {
690
+ return null;
691
+ }
692
+ return [k, t, state.c];
693
+ }
694
+ function validateTablePeek(ctx, peek, ptr) {
695
+ if (peek === null || ctx.uk === 2)
696
+ TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
697
+ }
698
+ function parse(toml, options = {}) {
699
+ let ctx = {
700
+ s: toml,
701
+ p: 0,
702
+ d: options.maxDepth ?? 1e3,
703
+ bi: options.integersAsBigInt ?? false,
704
+ ld: options.useLegacyDate ?? true,
705
+ uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
706
+ };
707
+ let res = /* @__PURE__ */ Object.create(null);
708
+ let meta = /* @__PURE__ */ Object.create(null);
709
+ let tmp;
710
+ let skipping = false;
711
+ let tbl = res;
712
+ let m = meta;
713
+ if (toml.charCodeAt(0) === 65279)
714
+ ctx.p++;
715
+ skipVoid(ctx);
716
+ while (ctx.p < toml.length) {
717
+ if (toml.charCodeAt(ctx.p) === 91) {
718
+ let isTableArray = toml.charCodeAt(++ctx.p) === 91;
719
+ tmp = ctx.p += +isTableArray;
720
+ skipping = false;
721
+ let k = parseKey(
722
+ ctx,
723
+ 93
724
+ /* ] */
725
+ );
726
+ if (isTableArray) {
727
+ if (toml.charCodeAt(ctx.p) !== 93) {
728
+ TomlError.x("expected end of table array declaration", ctx);
729
+ }
730
+ ctx.p++;
731
+ }
732
+ let p = peekTable(
733
+ ctx,
734
+ k,
735
+ res,
736
+ meta,
737
+ isTableArray ? 2 : 1
738
+ /* Type.EXPLICIT */
739
+ );
740
+ if (!p) {
741
+ validateTablePeek(ctx, p, tmp);
742
+ skipping = true;
743
+ } else {
744
+ m = p[2];
745
+ tbl = p[1];
746
+ }
747
+ } else {
748
+ tmp = ctx.p;
749
+ let k = parseKey(ctx);
750
+ let p = peekTable(
751
+ ctx,
752
+ k,
753
+ tbl,
754
+ m,
755
+ 0
756
+ /* Type.DOTTED */
757
+ );
758
+ if (!p && !skipping)
759
+ validateTablePeek(ctx, p, tmp);
760
+ skipVoid(ctx, true, true);
761
+ let v = extractValue(ctx, void 0);
762
+ if (p && !skipping)
763
+ p[1][p[0]] = v;
764
+ }
765
+ skipVoid(ctx, true);
766
+ if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) {
767
+ TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
768
+ }
769
+ skipVoid(ctx);
770
+ }
771
+ return res;
772
+ }
773
+
774
+ // ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/stringify.js
775
+ var HAS_WELLFORMED = !!"".isWellFormed;
776
+
777
+ // scripts/setup.mjs
778
+ var [cli, scratch] = process.argv.slice(2);
779
+ var profile = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "vivix-studio");
780
+ var read = async (path2) => JSON.parse(await readFile(path2, "utf8"));
781
+ var present = (path2) => lstat(path2).catch((error) => {
782
+ if (error.code !== "ENOENT") throw error;
783
+ });
784
+ var cliCall = (...args) => {
785
+ let stdout;
786
+ try {
787
+ stdout = execFileSync(cli, [...args, "--json"], {
788
+ encoding: "utf8",
789
+ maxBuffer: 16 * 1024 * 1024,
790
+ stdio: ["ignore", "pipe", "inherit"]
791
+ });
792
+ } catch (error) {
793
+ stdout = error.stdout;
794
+ }
795
+ const reply = JSON.parse(stdout);
796
+ if (!reply.ok)
797
+ throw Object.assign(Error(reply.error.code + ": " + reply.error.message), {
798
+ code: reply.error.code
799
+ });
800
+ return reply.data;
801
+ };
802
+ var catalog = (await read(join(scratch, "packages.json"))).data.packages;
803
+ var user = ["--scope", "user"];
804
+ var pins = await read(join(scratch, "chat-pins.json"));
805
+ var packages = {
806
+ "studio-chat": "@vivix-labs/studio-chat-mcp",
807
+ "chat-components": "@vivix-labs/chat-components",
808
+ "ui-system": "@vivix-labs/ui-system",
809
+ authoring: "@vivix-labs/short-drama-authoring"
810
+ };
811
+ var restarted = false;
812
+ async function enable(id, scope, options = [], additions) {
813
+ const name = packages[id], version = pins[name];
814
+ const before = cliCall("plugin", "list", ...scope).instances;
815
+ const current = before.find((item) => item.id === id);
816
+ if (current && current.package !== name) throw Error("Another plugin owns the instance " + id);
817
+ const config = { ...current?.config || {} };
818
+ if (additions) {
819
+ config.targets = { ...config.targets };
820
+ for (const [key, target] of Object.entries(additions)) {
821
+ if (Object.values(config.targets).some(
822
+ (t) => t.instanceId === target.instanceId && t.operationId === target.operationId
823
+ ))
824
+ continue;
825
+ if (config.targets[key])
826
+ throw Error("The existing card target " + key + " is used by another operation.");
827
+ config.targets[key] = target;
828
+ }
829
+ }
830
+ if (current?.state === "ready" && current.version === version && JSON.stringify(config) === JSON.stringify(current.config))
831
+ return;
832
+ if (additions) {
833
+ const file = join(scratch, "component-config.json");
834
+ await writeFile(file, JSON.stringify(config), { mode: 384 });
835
+ options = [...options, "--config", file];
836
+ }
837
+ const activate = () => cliCall(
838
+ "plugin",
839
+ "enable",
840
+ name,
841
+ "--version",
842
+ version,
843
+ "--instance",
844
+ id,
845
+ ...scope,
846
+ "--trust",
847
+ ...options
848
+ );
849
+ try {
850
+ activate();
851
+ } catch (error) {
852
+ if (error.code !== "USER_SCOPE_IN_USE" || scope !== user || restarted) throw error;
853
+ restarted = true;
854
+ cliCall("host", "stop");
855
+ for (let i = 0; cliCall("host", "status").pid; i++) {
856
+ if (i === 60) throw Error("Studio Host is still stopping. Rerun setup after it exits.");
857
+ await delay(500);
858
+ }
859
+ activate();
860
+ }
861
+ const after = cliCall("plugin", "describe", id, ...scope).instance;
862
+ if (after.state !== "ready" || after.version !== version)
863
+ throw Error(id + " did not become ready: " + after.reason);
864
+ }
865
+ await enable("studio-chat", user, ["--allow-access", "host.operations"]);
866
+ await enable("chat-components", user);
867
+ await enable("ui-system", user);
868
+ var examples = await present(join(profile, "home-initialization.json")) ? await read(join(profile, "home-initialization.json")) : {};
869
+ var drama = examples.projects?.["out-of-steps"]?.projectId;
870
+ if (drama && cliCall("project", "list").projects.some((p) => p.id === drama && p.available)) {
871
+ const scope = ["--project", drama];
872
+ const author = cliCall("plugin", "list", ...scope).instances.find((i) => i.id === "authoring");
873
+ if (author?.package === packages.authoring) {
874
+ await enable("authoring", scope);
875
+ await enable("chat-components", scope, [], {
876
+ character: { instanceId: "authoring", operationId: "characters.receiveCard" }
877
+ });
878
+ }
879
+ }
880
+ for (const [id, skill] of [
881
+ ["studio-chat", "vivix-studio-chat"],
882
+ ["chat-components", "chat-components"],
883
+ ["ui-system", "vivix-studio-ui"]
884
+ ]) {
885
+ const name = packages[id], version = pins[name];
886
+ const record = catalog.find((p) => p.package === name && p.version === version);
887
+ const packageStore = join(profile, "plugins", encodeURIComponent(name));
888
+ const source = join(packageStore, version, record.relativeRoot, "skills", skill);
889
+ await readFile(join(source, "SKILL.md"));
890
+ for (const directory of [".agents/skills", ".claude/skills"]) {
891
+ const parent = join(homedir(), directory), dest = join(parent, skill);
892
+ await mkdir(parent, { recursive: true });
893
+ const link = await present(dest);
894
+ if (link) {
895
+ const old2 = link.isSymbolicLink() && resolve(parent, await readlink(dest));
896
+ if (old2 === source) continue;
897
+ if (!old2 || !old2.startsWith(packageStore + "/") || !old2.endsWith("/skills/" + skill)) {
898
+ console.log("Retained personal Skill: " + dest);
899
+ continue;
900
+ }
901
+ }
902
+ const tmp = dest + "." + randomUUID();
903
+ try {
904
+ await symlink(source, tmp);
905
+ await rename(tmp, dest);
906
+ } finally {
907
+ await rm(tmp, { force: true });
908
+ }
909
+ }
910
+ }
911
+ var empty = join(scratch, "connection-input.json");
912
+ await writeFile(empty, "{}", { mode: 384 });
913
+ var conn = cliCall("plugin", "call", "studio-chat", "connection", ...user, "--input", empty);
914
+ var host = await read(join(profile, "runtime/host.json"));
915
+ if (conn.pid !== host.pid || conn.url !== host.origin + "/v1/user/http/studio-chat/mcp" || !/^Bearer [A-Za-z0-9._~-]+$/.test(conn.headers.Authorization))
916
+ throw Error("Unexpected Host connection.");
917
+ var configDir = process.env.CODEX_HOME || join(homedir(), ".codex");
918
+ await mkdir(configDir, { recursive: true, mode: 448 });
919
+ var path = join(configDir, "config.toml");
920
+ if (await present(path)) path = await realpath(path);
921
+ var old = await readFile(path, "utf8").catch((e) => {
922
+ if (e.code !== "ENOENT") throw e;
923
+ return "";
924
+ });
925
+ var servers = parse(old).mcp_servers || {};
926
+ var expected = Object.entries(servers).find(
927
+ ([, value]) => value.enabled !== false && value.url === conn.url && value.http_headers?.Authorization === conn.headers.Authorization
928
+ );
929
+ if (!expected) {
930
+ let key = "vivix-studio-chat";
931
+ if (Object.hasOwn(servers, key)) {
932
+ const suffix = createHash("sha256").update(conn.url).digest("hex").slice(0, 10);
933
+ key += "-" + suffix;
934
+ if (Object.hasOwn(servers, key))
935
+ throw Error("Existing Codex MCP configuration conflicts with this connection.");
936
+ }
937
+ const section = "\n[mcp_servers." + key + "]\nurl = " + JSON.stringify(conn.url) + "\n[mcp_servers." + key + ".http_headers]\nAuthorization = " + JSON.stringify(conn.headers.Authorization) + "\n";
938
+ const next = old + section;
939
+ parse(next);
940
+ const tmp = path + "." + randomUUID() + ".tmp";
941
+ try {
942
+ await writeFile(tmp, next, { mode: 384, flag: "wx" });
943
+ if (await readFile(path, "utf8").catch((e) => {
944
+ if (e.code !== "ENOENT") throw e;
945
+ return "";
946
+ }) !== old)
947
+ throw Error("Codex configuration changed during setup. Rerun the installer.");
948
+ await rename(tmp, path);
949
+ } finally {
950
+ await rm(tmp, { force: true });
951
+ }
952
+ }
953
+ console.log("Studio Chat is connected to the local Host. Open a new Codex chat to load its cards.");
954
+ /*! Bundled license information:
955
+
956
+ smol-toml/dist/error.js:
957
+ smol-toml/dist/primitive.js:
958
+ smol-toml/dist/date.js:
959
+ smol-toml/dist/extract.js:
960
+ smol-toml/dist/util.js:
961
+ smol-toml/dist/struct.js:
962
+ smol-toml/dist/parse.js:
963
+ smol-toml/dist/stringify.js:
964
+ smol-toml/dist/index.js:
965
+ (*!
966
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
967
+ * SPDX-License-Identifier: BSD-3-Clause
968
+ *
969
+ * Redistribution and use in source and binary forms, with or without
970
+ * modification, are permitted provided that the following conditions are met:
971
+ *
972
+ * 1. Redistributions of source code must retain the above copyright notice, this
973
+ * list of conditions and the following disclaimer.
974
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
975
+ * this list of conditions and the following disclaimer in the
976
+ * documentation and/or other materials provided with the distribution.
977
+ * 3. Neither the name of the copyright holder nor the names of its contributors
978
+ * may be used to endorse or promote products derived from this software without
979
+ * specific prior written permission.
980
+ *
981
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
982
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
983
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
984
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
985
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
986
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
987
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
988
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
989
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
990
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
991
+ *)
992
+ */