vibedgames 0.6.2 → 0.7.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.
Files changed (140) hide show
  1. package/README.md +14 -9
  2. package/dist/THIRD_PARTY_NOTICES.txt +383 -0
  3. package/dist/chunk-2GL2WJZX.js +172 -0
  4. package/dist/chunk-2QBYTIMH.js +511 -0
  5. package/dist/chunk-34AHIMX7.js +466 -0
  6. package/dist/chunk-6FZPPUQH.js +107 -0
  7. package/dist/chunk-BVVYDSFJ.js +99 -0
  8. package/dist/chunk-CAKBGDCY.js +47 -0
  9. package/dist/chunk-CBKOPVU6.js +1780 -0
  10. package/dist/chunk-CU7UY5YJ.js +1108 -0
  11. package/dist/chunk-CZPKN32Z.js +257 -0
  12. package/dist/chunk-DHEXGWJY.js +111 -0
  13. package/dist/chunk-FL6IFBUF.js +22 -0
  14. package/dist/chunk-FLUXEHMU.js +1360 -0
  15. package/dist/chunk-FNYBZNW2.js +165 -0
  16. package/dist/chunk-G5FRIFA3.js +22 -0
  17. package/dist/chunk-HCMTSR7E.js +69 -0
  18. package/dist/chunk-HKA5LBYW.js +159 -0
  19. package/dist/chunk-I6O4HIDY.js +1063 -0
  20. package/dist/chunk-J6PKNPI2.js +26 -0
  21. package/dist/chunk-JT2AU24K.js +759 -0
  22. package/dist/chunk-MBXCVCC4.js +478 -0
  23. package/dist/chunk-MJQSHP3Y.js +415 -0
  24. package/dist/chunk-MYFLYNPO.js +68 -0
  25. package/dist/chunk-PEUP4MZR.js +59 -0
  26. package/dist/chunk-PHEDW6C7.js +32 -0
  27. package/dist/chunk-PQDBCZRT.js +2017 -0
  28. package/dist/chunk-QGEITHUP.js +395 -0
  29. package/dist/chunk-QIVCBUYD.js +273 -0
  30. package/dist/chunk-RYFO3ZPO.js +71 -0
  31. package/dist/chunk-RZ4DIJQW.js +68 -0
  32. package/dist/chunk-SAANBZ25.js +118 -0
  33. package/dist/chunk-VFFOT7KD.js +2980 -0
  34. package/dist/chunk-Y552BNFZ.js +41 -0
  35. package/dist/chunk-Z4Z24FWO.js +39 -0
  36. package/dist/chunk-ZI6PKVXG.js +64 -0
  37. package/dist/chunk-ZYCSYJWX.js +87 -0
  38. package/dist/index.js +67 -60
  39. package/package.json +13 -16
  40. package/templates/none/_gitignore +3 -0
  41. package/templates/none/index.html +29 -0
  42. package/templates/none/package.json +16 -0
  43. package/templates/none/src/main.ts +16 -0
  44. package/templates/none/tsconfig.json +18 -0
  45. package/templates/none/vite.config.ts +8 -0
  46. package/templates/phaser/_gitignore +3 -0
  47. package/templates/phaser/index.html +24 -0
  48. package/templates/phaser/package.json +19 -0
  49. package/templates/phaser/src/main.ts +16 -0
  50. package/templates/phaser/src/scenes/game-scene.ts +65 -0
  51. package/templates/phaser/tsconfig.json +18 -0
  52. package/templates/phaser/vite.config.ts +8 -0
  53. package/templates/react-r3f/_gitignore +3 -0
  54. package/templates/react-r3f/index.html +24 -0
  55. package/templates/react-r3f/package.json +27 -0
  56. package/templates/react-r3f/src/app.tsx +33 -0
  57. package/templates/react-r3f/src/main.tsx +15 -0
  58. package/templates/react-r3f/tsconfig.json +19 -0
  59. package/templates/react-r3f/vite.config.ts +10 -0
  60. package/templates/threejs/_gitignore +3 -0
  61. package/templates/threejs/index.html +36 -0
  62. package/templates/threejs/package.json +20 -0
  63. package/templates/threejs/src/main.ts +44 -0
  64. package/templates/threejs/tsconfig.json +18 -0
  65. package/templates/threejs/vite.config.ts +8 -0
  66. package/dist/commands/completions.d.ts +0 -7
  67. package/dist/commands/completions.js +0 -145
  68. package/dist/commands/credits.d.ts +0 -10
  69. package/dist/commands/credits.js +0 -136
  70. package/dist/commands/deploy.d.ts +0 -26
  71. package/dist/commands/deploy.js +0 -257
  72. package/dist/commands/factory.d.ts +0 -3
  73. package/dist/commands/factory.js +0 -73
  74. package/dist/commands/fork.d.ts +0 -29
  75. package/dist/commands/fork.js +0 -124
  76. package/dist/commands/generate.d.ts +0 -1
  77. package/dist/commands/generate.js +0 -565
  78. package/dist/commands/init.d.ts +0 -20
  79. package/dist/commands/init.js +0 -105
  80. package/dist/commands/login.d.ts +0 -1
  81. package/dist/commands/login.js +0 -45
  82. package/dist/commands/logout.d.ts +0 -1
  83. package/dist/commands/logout.js +0 -13
  84. package/dist/commands/new.d.ts +0 -26
  85. package/dist/commands/new.js +0 -318
  86. package/dist/commands/playtest-run.d.ts +0 -66
  87. package/dist/commands/playtest-run.js +0 -268
  88. package/dist/commands/playtest.d.ts +0 -76
  89. package/dist/commands/playtest.js +0 -372
  90. package/dist/commands/update.d.ts +0 -13
  91. package/dist/commands/update.js +0 -82
  92. package/dist/commands/whoami.d.ts +0 -10
  93. package/dist/commands/whoami.js +0 -44
  94. package/dist/index.d.ts +0 -2
  95. package/dist/lib/api.d.ts +0 -18
  96. package/dist/lib/api.js +0 -27
  97. package/dist/lib/archive.d.ts +0 -17
  98. package/dist/lib/archive.js +0 -228
  99. package/dist/lib/codex.d.ts +0 -117
  100. package/dist/lib/codex.js +0 -426
  101. package/dist/lib/config-file.d.ts +0 -16
  102. package/dist/lib/config-file.js +0 -54
  103. package/dist/lib/config.d.ts +0 -11
  104. package/dist/lib/config.js +0 -54
  105. package/dist/lib/manifest.d.ts +0 -10
  106. package/dist/lib/manifest.js +0 -91
  107. package/dist/lib/media-args.d.ts +0 -30
  108. package/dist/lib/media-args.js +0 -219
  109. package/dist/lib/media-download.d.ts +0 -37
  110. package/dist/lib/media-download.js +0 -268
  111. package/dist/lib/media-poll.d.ts +0 -18
  112. package/dist/lib/media-poll.js +0 -86
  113. package/dist/lib/media-upload.d.ts +0 -12
  114. package/dist/lib/media-upload.js +0 -52
  115. package/dist/lib/output.d.ts +0 -68
  116. package/dist/lib/output.js +0 -102
  117. package/dist/lib/package-manager.d.ts +0 -25
  118. package/dist/lib/package-manager.js +0 -77
  119. package/dist/lib/playtest/agent.d.ts +0 -192
  120. package/dist/lib/playtest/agent.js +0 -652
  121. package/dist/lib/playtest/browser.d.ts +0 -109
  122. package/dist/lib/playtest/browser.js +0 -219
  123. package/dist/lib/playtest/controls.d.ts +0 -47
  124. package/dist/lib/playtest/controls.js +0 -218
  125. package/dist/lib/playtest/errors.d.ts +0 -9
  126. package/dist/lib/playtest/errors.js +0 -12
  127. package/dist/lib/playtest/keys.d.ts +0 -41
  128. package/dist/lib/playtest/keys.js +0 -157
  129. package/dist/lib/playtest/run.d.ts +0 -195
  130. package/dist/lib/playtest/run.js +0 -409
  131. package/dist/lib/run.d.ts +0 -19
  132. package/dist/lib/run.js +0 -23
  133. package/dist/lib/strict-args.d.ts +0 -27
  134. package/dist/lib/strict-args.js +0 -78
  135. package/dist/lib/types.d.ts +0 -16
  136. package/dist/lib/types.js +0 -10
  137. package/dist/lib/update.d.ts +0 -10
  138. package/dist/lib/update.js +0 -110
  139. package/dist/lib/upload.d.ts +0 -16
  140. package/dist/lib/upload.js +0 -41
@@ -0,0 +1,2017 @@
1
+ import { createRequire as __createRequire } from "node:module";
2
+ import { dirname as __pathDirname } from "node:path";
3
+ import { fileURLToPath as __fileURLToPath } from "node:url";
4
+ const require = __createRequire(import.meta.url);
5
+ var __filename = __fileURLToPath(import.meta.url);
6
+ var __dirname = __pathDirname(__filename);
7
+ import {
8
+ PACKAGE_VERSION
9
+ } from "./chunk-Z4Z24FWO.js";
10
+ import {
11
+ getBaseUrl,
12
+ getToken
13
+ } from "./chunk-RYFO3ZPO.js";
14
+
15
+ // ../../packages/contract/src/cli.ts
16
+ var CLI_VERSION_HEADER = "x-vg-cli";
17
+
18
+ // ../../node_modules/.pnpm/@standard-server+shared@0.10.1/node_modules/@standard-server/shared/dist/index.mjs
19
+ function toArray(value2) {
20
+ return Array.isArray(value2) ? value2 : value2 === void 0 || value2 === null ? [] : [value2];
21
+ }
22
+ function sequential(fn) {
23
+ let lastOperationPromise = Promise.resolve();
24
+ return (...args) => {
25
+ return lastOperationPromise = lastOperationPromise.catch(() => {
26
+ }).then(() => {
27
+ return fn(...args);
28
+ });
29
+ };
30
+ }
31
+ function isAsyncIteratorObject(maybe) {
32
+ if (!maybe || typeof maybe !== "object") {
33
+ return false;
34
+ }
35
+ return "next" in maybe && typeof maybe.next === "function" && Symbol.asyncIterator in maybe && typeof maybe[Symbol.asyncIterator] === "function";
36
+ }
37
+ var fallbackAsyncDisposeSymbol = /* @__PURE__ */ Symbol.for("asyncDispose");
38
+ var asyncDisposeSymbol = Symbol.asyncDispose ?? fallbackAsyncDisposeSymbol;
39
+ var AsyncIteratorClass = class {
40
+ isDone = false;
41
+ isExecuteComplete = false;
42
+ cleanup;
43
+ next;
44
+ constructor(next, cleanup) {
45
+ this.cleanup = cleanup;
46
+ this.next = sequential(async () => {
47
+ if (this.isDone) {
48
+ return { done: true, value: void 0 };
49
+ }
50
+ let errorRef;
51
+ try {
52
+ const result = await next();
53
+ if (this.isDone) {
54
+ return { done: true, value: void 0 };
55
+ }
56
+ if (result.done) {
57
+ this.isDone = true;
58
+ }
59
+ return result;
60
+ } catch (error) {
61
+ if (this.isDone) {
62
+ return { done: true, value: void 0 };
63
+ }
64
+ errorRef = { value: error };
65
+ this.isDone = true;
66
+ throw error;
67
+ } finally {
68
+ if (this.isDone && !this.isExecuteComplete) {
69
+ this.isExecuteComplete = true;
70
+ await this.cleanup(
71
+ errorRef ? { kind: "error", error: errorRef.value } : { kind: "success" }
72
+ );
73
+ }
74
+ }
75
+ });
76
+ }
77
+ async return(value2) {
78
+ this.isDone = true;
79
+ if (!this.isExecuteComplete) {
80
+ this.isExecuteComplete = true;
81
+ await this.cleanup({ kind: "cancelled" });
82
+ }
83
+ return { done: true, value: value2 };
84
+ }
85
+ async throw(error) {
86
+ this.isDone = true;
87
+ if (!this.isExecuteComplete) {
88
+ this.isExecuteComplete = true;
89
+ await this.cleanup({ kind: "cancelled", error });
90
+ }
91
+ throw error;
92
+ }
93
+ /**
94
+ * asyncDispose symbol only available in esnext, we should fallback to Symbol.for('asyncDispose')
95
+ */
96
+ async [asyncDisposeSymbol]() {
97
+ this.isDone = true;
98
+ if (!this.isExecuteComplete) {
99
+ this.isExecuteComplete = true;
100
+ await this.cleanup({ kind: "cancelled" });
101
+ }
102
+ }
103
+ [Symbol.asyncIterator]() {
104
+ return this;
105
+ }
106
+ };
107
+ function parseEmptyableJSON(text) {
108
+ if (!text) {
109
+ return void 0;
110
+ }
111
+ return JSON.parse(text);
112
+ }
113
+ function stringifyJSON(value2) {
114
+ return JSON.stringify(value2);
115
+ }
116
+ function isTypescriptObject(maybeObject) {
117
+ if (!maybeObject) {
118
+ return false;
119
+ }
120
+ const type = typeof maybeObject;
121
+ return type === "object" || type === "function";
122
+ }
123
+ var GET_OR_BIND_CACHE = /* @__PURE__ */ new WeakMap();
124
+ function getOrBind(target, property, { bind = true } = {}) {
125
+ const value2 = Reflect.get(target, property);
126
+ if (!bind || typeof value2 !== "function") {
127
+ return value2;
128
+ }
129
+ let targetCache = GET_OR_BIND_CACHE.get(value2);
130
+ if (!targetCache) {
131
+ GET_OR_BIND_CACHE.set(value2, targetCache = /* @__PURE__ */ new WeakMap());
132
+ }
133
+ let bound = targetCache.get(target);
134
+ if (!bound) {
135
+ targetCache.set(target, bound = value2.bind(target));
136
+ }
137
+ return bound;
138
+ }
139
+ var LONE_SURROGATE_REGEX = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
140
+ var PERCENT_ESCAPES_REGEX = /(?:%[0-9A-F]{2})+/gi;
141
+ function safeEncodeURIComponent(value2) {
142
+ try {
143
+ return encodeURIComponent(value2);
144
+ } catch {
145
+ return encodeURIComponent(value2.replace(LONE_SURROGATE_REGEX, "\uFFFD"));
146
+ }
147
+ }
148
+ function safeDecodeURIComponent(value2) {
149
+ if (!value2.includes("%")) {
150
+ return value2;
151
+ }
152
+ try {
153
+ return decodeURIComponent(value2);
154
+ } catch {
155
+ return value2.replace(PERCENT_ESCAPES_REGEX, (escapes) => {
156
+ try {
157
+ return decodeURIComponent(escapes);
158
+ } catch {
159
+ return escapes;
160
+ }
161
+ });
162
+ }
163
+ }
164
+
165
+ // ../../node_modules/.pnpm/@orpc+shared@2.0.0-beta.42/node_modules/@orpc/shared/dist/index.mjs
166
+ function resolveMaybeOptionalOptions(rest) {
167
+ return rest[0] ?? {};
168
+ }
169
+ var ORPC_NAME = "orpc";
170
+ function isAbortError(error) {
171
+ return error instanceof Error && error.name.includes("Abort");
172
+ }
173
+ var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {
174
+ }).constructor;
175
+ function once(fn) {
176
+ let cached;
177
+ return () => {
178
+ if (cached) {
179
+ return cached.result;
180
+ }
181
+ const result = fn();
182
+ cached = { result };
183
+ return result;
184
+ };
185
+ }
186
+ function pathToHttpPath(path) {
187
+ return `/${path.map(safeEncodeURIComponent).join("/")}`;
188
+ }
189
+ var TRACER_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_TRACER");
190
+ function getTracer() {
191
+ return globalThis[TRACER_SYMBOL];
192
+ }
193
+ function startSpan(options) {
194
+ const tracer = getTracer();
195
+ if (!tracer) {
196
+ return void 0;
197
+ }
198
+ if (typeof options === "string") {
199
+ return tracer.startSpan(options);
200
+ }
201
+ return tracer.startSpan(options.name, options.parent);
202
+ }
203
+ function recordSpanError(span, error) {
204
+ if (!span) {
205
+ return;
206
+ }
207
+ span.recordException(isAbortError(error) ? "info" : "error", toTracingException(error));
208
+ }
209
+ function toTracingException(error) {
210
+ if (error instanceof Error) {
211
+ const exception = {
212
+ message: error.message,
213
+ name: error.name,
214
+ stack: error.stack
215
+ };
216
+ if ("code" in error && (typeof error.code === "string" || typeof error.code === "number")) {
217
+ exception.code = error.code;
218
+ }
219
+ return exception;
220
+ }
221
+ return { message: String(error) };
222
+ }
223
+ async function runWithSpan(options, fn) {
224
+ const tracer = getTracer();
225
+ if (!tracer) {
226
+ return fn();
227
+ }
228
+ const name = typeof options === "string" ? options : options.name;
229
+ const parent = typeof options === "string" ? void 0 : options.parent;
230
+ return tracer.startActiveSpan(name, parent, async (span) => {
231
+ try {
232
+ return await fn(span);
233
+ } catch (e) {
234
+ recordSpanError(span, e);
235
+ throw e;
236
+ } finally {
237
+ span.end();
238
+ }
239
+ });
240
+ }
241
+ function runInSpanContext(span, fn) {
242
+ const tracer = getTracer();
243
+ if (!span || !tracer) {
244
+ return fn();
245
+ }
246
+ return tracer.withActiveSpan(span, fn);
247
+ }
248
+ function wrapAsyncIterator(iterator, { runWith, mapResult, mapError, onError, onFinish }) {
249
+ runWith ??= (run) => run();
250
+ let isDone;
251
+ return new AsyncIteratorClass(async () => {
252
+ try {
253
+ let result;
254
+ try {
255
+ result = await runWith(() => iterator.next());
256
+ isDone = result.done;
257
+ } catch (error) {
258
+ isDone = true;
259
+ throw error;
260
+ }
261
+ return mapResult ? await mapResult(result) : result;
262
+ } catch (error) {
263
+ await onError?.(error);
264
+ throw mapError ? await mapError(error) : error;
265
+ }
266
+ }, async (_state) => {
267
+ try {
268
+ if (!isDone) {
269
+ try {
270
+ await runWith(async () => iterator.return?.());
271
+ } catch (error) {
272
+ await onError?.(error);
273
+ throw error;
274
+ }
275
+ }
276
+ } finally {
277
+ await onFinish?.();
278
+ }
279
+ });
280
+ }
281
+ function traceAsyncIterator(options, iterator) {
282
+ const getSpan = once(() => startSpan(options));
283
+ return wrapAsyncIterator(iterator, {
284
+ runWith: (run) => runInSpanContext(getSpan(), run),
285
+ mapResult(result) {
286
+ getSpan()?.addEvent(result.done ? "completed" : "yielded");
287
+ return result;
288
+ },
289
+ onError(error) {
290
+ recordSpanError(getSpan(), error);
291
+ },
292
+ onFinish() {
293
+ getSpan()?.end();
294
+ }
295
+ });
296
+ }
297
+ function value(value2, ...args) {
298
+ if (typeof value2 === "function") {
299
+ return value2(...args);
300
+ }
301
+ return value2;
302
+ }
303
+ function override(target, partial) {
304
+ const proxy = new Proxy(typeof target === "function" ? partial : target, {
305
+ get(_, prop) {
306
+ const targetValue = prop in partial ? partial : value(target);
307
+ return getOrBind(targetValue, prop);
308
+ },
309
+ has(_, prop) {
310
+ return Reflect.has(partial, prop) || Reflect.has(value(target), prop);
311
+ }
312
+ });
313
+ return proxy;
314
+ }
315
+ function* getConstructors(value2) {
316
+ if (!isTypescriptObject(value2)) {
317
+ return;
318
+ }
319
+ let proto = Object.getPrototypeOf(value2);
320
+ while (proto != null) {
321
+ if (proto.constructor) {
322
+ yield proto.constructor;
323
+ }
324
+ proto = Object.getPrototypeOf(proto);
325
+ }
326
+ }
327
+ function isPlainObject(value2) {
328
+ if (!value2 || typeof value2 !== "object") {
329
+ return false;
330
+ }
331
+ const proto = Object.getPrototypeOf(value2);
332
+ return proto === Object.prototype || !proto || !proto.constructor;
333
+ }
334
+ function setOwn(object, key, value2) {
335
+ if (key === "__proto__") {
336
+ Object.defineProperty(object, key, {
337
+ value: value2,
338
+ writable: true,
339
+ enumerable: true,
340
+ configurable: true
341
+ });
342
+ } else {
343
+ object[key] = value2;
344
+ }
345
+ }
346
+ function copyOnWrite(parent, key, original) {
347
+ const value2 = parent[key];
348
+ if (value2 !== original) {
349
+ return value2;
350
+ }
351
+ let copy;
352
+ if (Array.isArray(value2)) {
353
+ copy = value2.slice();
354
+ } else if (isPlainObject(value2)) {
355
+ copy = { ...value2 };
356
+ } else {
357
+ return value2;
358
+ }
359
+ setOwn(parent, key, copy);
360
+ return copy;
361
+ }
362
+ var NullProtoObj = /* @__PURE__ */ (() => {
363
+ const e = function() {
364
+ };
365
+ e.prototype = /* @__PURE__ */ Object.create(null);
366
+ Object.freeze(e.prototype);
367
+ return e;
368
+ })();
369
+ function wrapReadableStream(stream, { runWith, mapResult, mapError, onError, onFinish }) {
370
+ runWith ??= (run) => run();
371
+ const reader = once(() => stream.getReader());
372
+ const finish = once(async () => onFinish?.());
373
+ return new ReadableStream({
374
+ async pull(controller) {
375
+ let result;
376
+ try {
377
+ const readResult = await runWith(() => reader().read());
378
+ result = mapResult ? await mapResult(readResult) : readResult;
379
+ } catch (error) {
380
+ try {
381
+ await onError?.(error);
382
+ controller.error(mapError ? await mapError(error) : error);
383
+ } finally {
384
+ await finish();
385
+ }
386
+ return;
387
+ }
388
+ if (result.done) {
389
+ controller.close();
390
+ await finish();
391
+ } else {
392
+ controller.enqueue(result.value);
393
+ }
394
+ },
395
+ async cancel(reason) {
396
+ try {
397
+ try {
398
+ await runWith(() => reader().cancel(reason));
399
+ } catch (error) {
400
+ await onError?.(error);
401
+ throw error;
402
+ }
403
+ } finally {
404
+ await finish();
405
+ }
406
+ }
407
+ });
408
+ }
409
+ function traceReadableStream(options, stream) {
410
+ const getSpan = once(() => startSpan(options));
411
+ return wrapReadableStream(stream, {
412
+ runWith: (run) => runInSpanContext(getSpan(), run),
413
+ mapResult(result) {
414
+ getSpan()?.addEvent(result.done ? "closed" : "enqueued");
415
+ return result;
416
+ },
417
+ onError(error) {
418
+ recordSpanError(getSpan(), error);
419
+ },
420
+ onFinish() {
421
+ getSpan()?.end();
422
+ }
423
+ });
424
+ }
425
+ function intercept(interceptors, options, main) {
426
+ if (!interceptors?.length) {
427
+ return main(options);
428
+ }
429
+ const next = (options2, index) => {
430
+ const interceptor = interceptors[index];
431
+ if (!interceptor) {
432
+ return main(options2);
433
+ }
434
+ return interceptor({
435
+ ...options2,
436
+ next: (newOptions = options2) => next(newOptions, index + 1)
437
+ });
438
+ };
439
+ return next(options, 0);
440
+ }
441
+ function sortPlugins(plugins) {
442
+ const pluginCount = plugins.length;
443
+ const pluginIdToIndices = /* @__PURE__ */ new Map();
444
+ for (let i = 0; i < pluginCount; i++) {
445
+ const plugin = plugins[i];
446
+ const indices = pluginIdToIndices.get(plugin.name);
447
+ if (indices === void 0) {
448
+ pluginIdToIndices.set(plugin.name, [i]);
449
+ } else {
450
+ indices.push(i);
451
+ }
452
+ }
453
+ const dependencies = Array.from({ length: pluginCount }, () => []);
454
+ for (let i = 0; i < pluginCount; i++) {
455
+ const plugin = plugins[i];
456
+ if (plugin.before !== void 0) {
457
+ for (const beforeId of plugin.before) {
458
+ const beforeIndices = pluginIdToIndices.get(beforeId);
459
+ if (beforeIndices !== void 0) {
460
+ for (const beforeIndex of beforeIndices) {
461
+ dependencies[beforeIndex].push(i);
462
+ }
463
+ }
464
+ }
465
+ }
466
+ if (plugin.after !== void 0) {
467
+ for (const afterId of plugin.after) {
468
+ const afterIndices = pluginIdToIndices.get(afterId);
469
+ if (afterIndices !== void 0) {
470
+ for (const afterIndex of afterIndices) {
471
+ dependencies[i].push(afterIndex);
472
+ }
473
+ }
474
+ }
475
+ }
476
+ }
477
+ const sorted = [];
478
+ const placed = /* @__PURE__ */ new Set();
479
+ while (sorted.length < pluginCount) {
480
+ const next = plugins.findIndex((_, i) => !placed.has(i) && dependencies[i].every((dependency) => placed.has(dependency)));
481
+ if (next === -1) {
482
+ throw new Error(`Circular dependency detected involving plugin "${findCyclicPlugin(plugins, dependencies, placed).name}"`);
483
+ }
484
+ placed.add(next);
485
+ sorted.push(plugins[next]);
486
+ }
487
+ return sorted;
488
+ }
489
+ function findCyclicPlugin(plugins, dependencies, placed) {
490
+ const seen = /* @__PURE__ */ new Set();
491
+ let current = plugins.findIndex((_, i) => !placed.has(i));
492
+ while (!seen.has(current)) {
493
+ seen.add(current);
494
+ current = dependencies[current].find((dependency) => !placed.has(dependency));
495
+ }
496
+ return plugins[current];
497
+ }
498
+
499
+ // ../../node_modules/.pnpm/@standard-server+core@0.10.1/node_modules/@standard-server/core/dist/index.mjs
500
+ var EventStreamEncoderError = class extends TypeError {
501
+ };
502
+ var EventStreamDecoderError = class extends TypeError {
503
+ };
504
+ var ErrorEvent = class extends Error {
505
+ constructor(data, options = {}) {
506
+ super(options?.message ?? "Error Event", options);
507
+ this.data = data;
508
+ }
509
+ };
510
+ var EVENT_STREAM_LINE_ENDING_REGEX = /\r\n|[\n\r]/;
511
+ var EVENT_STREAM_LINE_ENDING_GLOBAL_REGEX = /\r\n|[\n\r]/g;
512
+ var EVENT_STREAM_INVALID_ID_CHAR_REGEX = /[\r\n\0]/;
513
+ function containsEventStreamLineBreak(value2) {
514
+ return EVENT_STREAM_LINE_ENDING_REGEX.test(value2);
515
+ }
516
+ function isEventStreamMessageId(maybe) {
517
+ return typeof maybe === "string" && !EVENT_STREAM_INVALID_ID_CHAR_REGEX.test(maybe);
518
+ }
519
+ function isEventStreamMessageRetry(maybe) {
520
+ return Number.isInteger(maybe) && maybe >= 0;
521
+ }
522
+ function isEventStreamMessageComment(maybe) {
523
+ return typeof maybe === "string" && !containsEventStreamLineBreak(maybe);
524
+ }
525
+ function assertEventStreamMessageId(id) {
526
+ if (!isEventStreamMessageId(id)) {
527
+ throw new EventStreamEncoderError(
528
+ "Event's id must not contain a carriage return, newline or NULL character"
529
+ );
530
+ }
531
+ }
532
+ function assertEventStreamMessageName(event) {
533
+ if (containsEventStreamLineBreak(event)) {
534
+ throw new EventStreamEncoderError(
535
+ "Event's event must not contain a carriage return or newline character"
536
+ );
537
+ }
538
+ }
539
+ function assertEventStreamMessageRetry(retry) {
540
+ if (!isEventStreamMessageRetry(retry)) {
541
+ throw new EventStreamEncoderError("Event's retry must be a integer and >= 0");
542
+ }
543
+ }
544
+ function assertEventStreamMessageComment(comment) {
545
+ if (!isEventStreamMessageComment(comment)) {
546
+ throw new EventStreamEncoderError(
547
+ "Event's comment must not contain a carriage return or newline character"
548
+ );
549
+ }
550
+ }
551
+ function encodeEventStreamMessageData(data) {
552
+ if (data === void 0) {
553
+ return "";
554
+ }
555
+ return `data: ${data.replace(EVENT_STREAM_LINE_ENDING_GLOBAL_REGEX, "\ndata: ")}
556
+ `;
557
+ }
558
+ function encodeEventStreamMessageComments(comments) {
559
+ let output = "";
560
+ for (const comment of comments ?? []) {
561
+ assertEventStreamMessageComment(comment);
562
+ output += `: ${comment}
563
+ `;
564
+ }
565
+ return output;
566
+ }
567
+ function encodeEventStreamMessage(message) {
568
+ let output = "";
569
+ output += encodeEventStreamMessageComments(message.comments);
570
+ if (message.event !== void 0 && (message.event !== "message" || message.data === void 0)) {
571
+ assertEventStreamMessageName(message.event);
572
+ output += `event: ${message.event}
573
+ `;
574
+ }
575
+ if (message.retry !== void 0) {
576
+ assertEventStreamMessageRetry(message.retry);
577
+ output += `retry: ${message.retry}
578
+ `;
579
+ }
580
+ if (message.id !== void 0) {
581
+ assertEventStreamMessageId(message.id);
582
+ output += `id: ${message.id}
583
+ `;
584
+ }
585
+ output += encodeEventStreamMessageData(message.data);
586
+ output += "\n";
587
+ return output;
588
+ }
589
+ var LINE_ENDING_REGEX = /\r\n?|\n/;
590
+ var MESSAGE_DELIMITER_REGEX = /[\r\n]{3,}|\r\r|\n[\r\n]/g;
591
+ var LEADING_LINE_ENDINGS_REGEX = /^[\r\n]+/;
592
+ var ASCII_DIGITS_REGEX = /^\d+$/;
593
+ var SPACE = 32;
594
+ var LF = 10;
595
+ var CR = 13;
596
+ function decodeEventStreamMessage(encoded) {
597
+ const message = {};
598
+ for (const line of encoded.split(LINE_ENDING_REGEX)) {
599
+ if (line === "") {
600
+ continue;
601
+ }
602
+ const index = line.indexOf(":");
603
+ const value2 = index === -1 ? "" : line.slice(line.charCodeAt(index + 1) === SPACE ? index + 2 : index + 1);
604
+ if (index === 0) {
605
+ (message.comments ??= []).push(value2);
606
+ continue;
607
+ }
608
+ switch (index === -1 ? line : line.slice(0, index)) {
609
+ case "data":
610
+ message.data = message.data === void 0 ? value2 : `${message.data}
611
+ ${value2}`;
612
+ break;
613
+ case "event":
614
+ message.event = value2;
615
+ break;
616
+ case "id":
617
+ if (isEventStreamMessageId(value2)) {
618
+ message.id = value2;
619
+ }
620
+ break;
621
+ case "retry": {
622
+ const retry = Number.parseInt(value2, 10);
623
+ if (ASCII_DIGITS_REGEX.test(value2) && isEventStreamMessageRetry(retry)) {
624
+ message.retry = retry;
625
+ }
626
+ break;
627
+ }
628
+ }
629
+ }
630
+ if (!message.event) {
631
+ if (message.data === void 0) {
632
+ delete message.event;
633
+ } else {
634
+ message.event = "message";
635
+ }
636
+ }
637
+ return message;
638
+ }
639
+ var EventStreamDecoder = class {
640
+ constructor(onEvent) {
641
+ this.onEvent = onEvent;
642
+ }
643
+ // The incomplete message: empty, or text that neither starts with a line
644
+ // ending nor contains a blank line.
645
+ pending = [];
646
+ // Last MAX_DELIMITER_OVERLAP characters of the pending text, prefixed to the
647
+ // next chunk so a delimiter straddling the boundary is still found.
648
+ tail = "";
649
+ feed(chunk) {
650
+ if (this.pending.length === 0) {
651
+ const first = chunk.charCodeAt(0);
652
+ if (first === LF || first === CR) {
653
+ chunk = chunk.replace(LEADING_LINE_ENDINGS_REGEX, "");
654
+ }
655
+ }
656
+ if (chunk === "") {
657
+ return;
658
+ }
659
+ const scan = this.tail + chunk;
660
+ this.pending.push(chunk);
661
+ MESSAGE_DELIMITER_REGEX.lastIndex = 0;
662
+ let match = MESSAGE_DELIMITER_REGEX.exec(scan);
663
+ if (match === null) {
664
+ this.tail = scan.slice(-2);
665
+ return;
666
+ }
667
+ const buffered = this.pending.length === 1 ? chunk : this.pending.join("");
668
+ const offset = buffered.length - scan.length;
669
+ const parts = [];
670
+ let start = 0;
671
+ while (match !== null) {
672
+ parts.push(buffered.slice(start, offset + match.index));
673
+ start = offset + match.index + match[0].length;
674
+ match = MESSAGE_DELIMITER_REGEX.exec(scan);
675
+ }
676
+ const incomplete = buffered.slice(start);
677
+ this.pending = incomplete === "" ? [] : [incomplete];
678
+ this.tail = incomplete.slice(-2);
679
+ for (const encoded of parts) {
680
+ this.onEvent(decodeEventStreamMessage(encoded));
681
+ }
682
+ }
683
+ end() {
684
+ if (this.pending.length !== 0) {
685
+ throw new EventStreamDecoderError("Event Stream ended before complete");
686
+ }
687
+ }
688
+ };
689
+ var EventStreamDecoderStream = class {
690
+ readable;
691
+ writable;
692
+ constructor() {
693
+ let decoder;
694
+ const transform = new TransformStream({
695
+ start(controller) {
696
+ decoder = new EventStreamDecoder((event) => {
697
+ controller.enqueue(event);
698
+ });
699
+ },
700
+ transform(chunk) {
701
+ decoder.feed(chunk);
702
+ },
703
+ flush() {
704
+ decoder.end();
705
+ }
706
+ });
707
+ this.readable = transform.readable;
708
+ this.writable = transform.writable;
709
+ }
710
+ };
711
+ var EVENT_META_SYMBOL = /* @__PURE__ */ Symbol.for("STANDARD_SERVER_EVENT_META");
712
+ var EVENT_SOURCE_SYMBOL = /* @__PURE__ */ Symbol.for("STANDARD_SERVER_EVENT_SOURCE");
713
+ function withEventMeta(container, meta) {
714
+ let assertedMeta;
715
+ if (meta.id !== void 0) {
716
+ assertEventStreamMessageId(meta.id);
717
+ assertedMeta ??= {};
718
+ assertedMeta.id = meta.id;
719
+ }
720
+ if (meta.retry !== void 0) {
721
+ assertEventStreamMessageRetry(meta.retry);
722
+ assertedMeta ??= {};
723
+ assertedMeta.retry = meta.retry;
724
+ }
725
+ if (meta.comments !== void 0) {
726
+ for (const comment of meta.comments) {
727
+ assertEventStreamMessageComment(comment);
728
+ }
729
+ assertedMeta ??= {};
730
+ assertedMeta.comments = meta.comments;
731
+ }
732
+ if (!assertedMeta) {
733
+ return container;
734
+ }
735
+ return new Proxy(container, {
736
+ get(target, prop, _receiver) {
737
+ if (prop === EVENT_SOURCE_SYMBOL) {
738
+ return target;
739
+ }
740
+ if (prop === EVENT_META_SYMBOL) {
741
+ return assertedMeta;
742
+ }
743
+ return getOrBind(target, prop, { bind: prop !== "constructor" });
744
+ }
745
+ });
746
+ }
747
+ function unwrapEvent(container) {
748
+ if (!isTypescriptObject(container)) {
749
+ return [container, void 0];
750
+ }
751
+ const meta = container[EVENT_META_SYMBOL];
752
+ const target = container[EVENT_SOURCE_SYMBOL] ?? container;
753
+ return [target, meta];
754
+ }
755
+ function getEventMeta(container) {
756
+ if (!isTypescriptObject(container)) {
757
+ return void 0;
758
+ }
759
+ return container[EVENT_META_SYMBOL];
760
+ }
761
+ var FALLBACK_FILENAME_UNSAFE_CHAR_REGEX = /[^\x20-\x7E]|[;=]/g;
762
+ var QUOTED_STRING_SPECIAL_CHAR_REGEX = /[\\"]/g;
763
+ var QUOTED_PAIR_REGEX = /\\(.)/g;
764
+ var EXT_VALUE_RESERVED_CHAR_REGEX = /['()*]/g;
765
+ var EXT_VALUE_ALLOWED_ESCAPE_REGEX = /%(7C|60|5E)/g;
766
+ var EXT_VALUE_REGEX = /^([^']*)'[^']*'(.*)$/;
767
+ var EXT_VALUE_SUPPORTED_CHARSET_REGEX = /^(?:utf-8|us-ascii)$/i;
768
+ var CONTENT_DISPOSITION_PARAM_REGEX = /[\s;]*([^;=]*)(?:=\s*(?:"((?:\\.|[^"\\])*)"[^;]*|"[\s\S]*|([^;]*)))?/y;
769
+ function generateContentDisposition(filename, type = "inline") {
770
+ const encodedFilename = filename.replace(FALLBACK_FILENAME_UNSAFE_CHAR_REGEX, "_").replace(QUOTED_STRING_SPECIAL_CHAR_REGEX, "\\$&");
771
+ const encodedFilenameStar = safeEncodeURIComponent(filename).replace(EXT_VALUE_RESERVED_CHAR_REGEX, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`).replace(
772
+ EXT_VALUE_ALLOWED_ESCAPE_REGEX,
773
+ (str, hex) => String.fromCharCode(Number.parseInt(hex, 16))
774
+ );
775
+ return `${type}; filename="${encodedFilename}"; filename*=utf-8''${encodedFilenameStar}`;
776
+ }
777
+ function getContentDispositionParam(contentDisposition, name) {
778
+ CONTENT_DISPOSITION_PARAM_REGEX.lastIndex = 0;
779
+ while (CONTENT_DISPOSITION_PARAM_REGEX.lastIndex < contentDisposition.length) {
780
+ const [, paramName = "", quoted, token] = CONTENT_DISPOSITION_PARAM_REGEX.exec(contentDisposition);
781
+ if (paramName.trimEnd().toLowerCase() === name) {
782
+ return quoted !== void 0 ? quoted.replace(QUOTED_PAIR_REGEX, "$1") : token?.trim() || void 0;
783
+ }
784
+ }
785
+ return void 0;
786
+ }
787
+ function getFilenameFromContentDisposition(contentDisposition) {
788
+ const extValue = getContentDispositionParam(contentDisposition, "filename*");
789
+ const extValueMatch = extValue?.match(EXT_VALUE_REGEX);
790
+ if (extValueMatch) {
791
+ const [, charset = "", encodedFilename = ""] = extValueMatch;
792
+ if (EXT_VALUE_SUPPORTED_CHARSET_REGEX.test(charset)) {
793
+ return safeDecodeURIComponent(encodedFilename);
794
+ }
795
+ } else if (extValue) {
796
+ return safeDecodeURIComponent(extValue);
797
+ }
798
+ return getContentDispositionParam(contentDisposition, "filename");
799
+ }
800
+ function flattenStandardHeader(header) {
801
+ if (typeof header === "string" || header === void 0) {
802
+ return header;
803
+ }
804
+ if (header.length === 0) {
805
+ return void 0;
806
+ }
807
+ return header.join(", ");
808
+ }
809
+ var STANDARD_BODY_HINT_SET = /* @__PURE__ */ new Set([
810
+ "json",
811
+ "form-data",
812
+ "url-search-params",
813
+ "event-stream",
814
+ "octet-stream",
815
+ "file",
816
+ "none"
817
+ ]);
818
+ function resolveStandardBodyHint(headers) {
819
+ const hint = flattenStandardHeader(headers["standard-server"]);
820
+ if (hint !== void 0 && STANDARD_BODY_HINT_SET.has(hint)) {
821
+ return hint;
822
+ }
823
+ const mimeType = flattenStandardHeader(headers["content-type"])?.split(";")[0]?.trim().toLowerCase();
824
+ const contentLength = flattenStandardHeader(headers["content-length"]);
825
+ const contentDisposition = flattenStandardHeader(headers["content-disposition"]);
826
+ const fileName = contentDisposition !== void 0 ? getFilenameFromContentDisposition(contentDisposition) : void 0;
827
+ if (mimeType === void 0 && (contentLength === void 0 || contentLength === "0")) {
828
+ return "none";
829
+ }
830
+ if (mimeType === "application/json") {
831
+ return "json";
832
+ }
833
+ if (mimeType === "multipart/form-data") {
834
+ return "form-data";
835
+ }
836
+ if (mimeType === "application/x-www-form-urlencoded") {
837
+ return "url-search-params";
838
+ }
839
+ if (mimeType === "text/event-stream") {
840
+ return "event-stream";
841
+ }
842
+ if (fileName !== void 0 || contentLength !== void 0) {
843
+ return "file";
844
+ }
845
+ return "octet-stream";
846
+ }
847
+ function mergeStandardHeaders(a, b) {
848
+ const merged = { ...a, ...b };
849
+ for (const key of Object.keys(b)) {
850
+ if (!Object.hasOwn(a, key)) {
851
+ continue;
852
+ }
853
+ const aValue = a[key];
854
+ const bValue = b[key];
855
+ merged[key] = aValue === void 0 || bValue === void 0 ? aValue ?? bValue : [...toArray(aValue), ...toArray(bValue)];
856
+ }
857
+ return merged;
858
+ }
859
+ function parseStandardUrl(url) {
860
+ const hashStart = url.indexOf("#");
861
+ const searchStart = url.indexOf("?");
862
+ const hasSearchBeforeHash = searchStart !== -1 && (hashStart === -1 || searchStart < hashStart);
863
+ const pathnameEnd = hasSearchBeforeHash ? searchStart : hashStart !== -1 ? hashStart : url.length;
864
+ const searchEnd = hashStart !== -1 ? hashStart : url.length;
865
+ const pathname = url.slice(0, pathnameEnd);
866
+ const search = hasSearchBeforeHash ? url.slice(searchStart, searchEnd) : void 0;
867
+ const hash = hashStart !== -1 ? url.slice(hashStart) : void 0;
868
+ return [pathname, search, hash];
869
+ }
870
+
871
+ // ../../node_modules/.pnpm/@orpc+client@2.0.0-beta.42/node_modules/@orpc/client/dist/shared/client.DD2eNne_.mjs
872
+ var COMMON_ERROR_STATUS_MAP = {
873
+ BAD_REQUEST: 400,
874
+ UNAUTHORIZED: 401,
875
+ PAYMENT_REQUIRED: 402,
876
+ FORBIDDEN: 403,
877
+ NOT_FOUND: 404,
878
+ METHOD_NOT_SUPPORTED: 405,
879
+ NOT_ACCEPTABLE: 406,
880
+ TIMEOUT: 408,
881
+ CONFLICT: 409,
882
+ GONE: 410,
883
+ LENGTH_REQUIRED: 411,
884
+ PRECONDITION_FAILED: 412,
885
+ PAYLOAD_TOO_LARGE: 413,
886
+ UNSUPPORTED_MEDIA_TYPE: 415,
887
+ UNPROCESSABLE_CONTENT: 422,
888
+ PRECONDITION_REQUIRED: 428,
889
+ TOO_MANY_REQUESTS: 429,
890
+ CLIENT_CLOSED_REQUEST: 499,
891
+ INTERNAL_SERVER_ERROR: 500,
892
+ NOT_IMPLEMENTED: 501,
893
+ BAD_GATEWAY: 502,
894
+ SERVICE_UNAVAILABLE: 503,
895
+ GATEWAY_TIMEOUT: 504
896
+ };
897
+ var ORPCErrorConstructors;
898
+ var ORPCError = class _ORPCError extends Error {
899
+ static {
900
+ const ORPC_ERROR_CONSTRUCTORS_SYMBOL = /* @__PURE__ */ Symbol.for("ORPC_ERROR_CONSTRUCTORS");
901
+ void (globalThis[ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
902
+ ORPCErrorConstructors = globalThis[ORPC_ERROR_CONSTRUCTORS_SYMBOL];
903
+ ORPCErrorConstructors.add(_ORPCError);
904
+ }
905
+ /**
906
+ * @remarks
907
+ * **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish
908
+ * an `ORPCError` instance from plain objects with a similar structure.
909
+ */
910
+ name = "ORPCError";
911
+ /**
912
+ * Indicates whether the error matches a definition in the procedure's `.errors` map,
913
+ * which makes its type inferable on the client.
914
+ */
915
+ defined = false;
916
+ code;
917
+ data;
918
+ constructor(code, ...rest) {
919
+ const options = resolveMaybeOptionalOptions(rest);
920
+ const message = options.message ?? code.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
921
+ super(message, options);
922
+ this.code = code;
923
+ this.data = options.data;
924
+ }
925
+ toJSON() {
926
+ return {
927
+ defined: this.defined,
928
+ code: this.code,
929
+ message: this.message,
930
+ data: this.data
931
+ };
932
+ }
933
+ /**
934
+ * Workaround for Next.js where different contexts use separate
935
+ * dependency graphs, causing multiple ORPCError constructors existing and breaking
936
+ * `instanceof` checks across contexts.
937
+ *
938
+ * This is particularly problematic with "Optimized SSR", where orpc-client
939
+ * executes in one context but is invoked from another. When an error is thrown
940
+ * in the execution context, `instanceof ORPCError` checks fail in the
941
+ * invocation context due to separate class constructors.
942
+ *
943
+ * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
944
+ */
945
+ static [Symbol.hasInstance](instance) {
946
+ if (!ORPCErrorConstructors.has(this)) {
947
+ return super[Symbol.hasInstance](instance);
948
+ }
949
+ for (const constructor of getConstructors(instance)) {
950
+ if (ORPCErrorConstructors.has(constructor)) {
951
+ return true;
952
+ }
953
+ }
954
+ return false;
955
+ }
956
+ };
957
+ var MalformedResponseError = class extends Error {
958
+ name = "MalformedResponseError";
959
+ response;
960
+ constructor(options) {
961
+ super(options.message, options);
962
+ this.response = options.response;
963
+ }
964
+ };
965
+
966
+ // ../../node_modules/.pnpm/@orpc+client@2.0.0-beta.42/node_modules/@orpc/client/dist/shared/client.DpkGsZt-.mjs
967
+ function toORPCError(error) {
968
+ return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", { cause: error });
969
+ }
970
+ function isORPCErrorJson(json) {
971
+ if (!isPlainObject(json)) {
972
+ return false;
973
+ }
974
+ const validKeys = ["defined", "code", "message", "data"];
975
+ if (Object.keys(json).some((k) => !validKeys.includes(k))) {
976
+ return false;
977
+ }
978
+ return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "message" in json && typeof json.message === "string";
979
+ }
980
+ function createORPCErrorFromJson(json, options = {}) {
981
+ const error = new ORPCError(json.code, {
982
+ ...json,
983
+ ...options
984
+ });
985
+ error.defined = json.defined;
986
+ return error;
987
+ }
988
+ function createORPCErrorFromMalformedResponse(options) {
989
+ const error = new ORPCError("MALFORMED_ORPC_RESPONSE", {
990
+ message: options.message ?? inferMalformedResponseMessage(options.response),
991
+ data: options.response
992
+ });
993
+ error.cause = new MalformedResponseError({ ...options, message: error.message });
994
+ return error;
995
+ }
996
+ var INFERRED_MESSAGE_MIN_LENGTH = 1;
997
+ var INFERRED_MESSAGE_MAX_LENGTH = 256;
998
+ function isInferableMessage(text) {
999
+ return text.length >= INFERRED_MESSAGE_MIN_LENGTH && text.length <= INFERRED_MESSAGE_MAX_LENGTH;
1000
+ }
1001
+ function inferMalformedResponseMessage(response) {
1002
+ if (typeof response.body === "string" && isInferableMessage(response.body)) {
1003
+ return response.body;
1004
+ }
1005
+ if (isPlainObject(response.body) && typeof response.body.message === "string" && isInferableMessage(response.body.message)) {
1006
+ return response.body.message;
1007
+ }
1008
+ const commonCode = Object.entries(COMMON_ERROR_STATUS_MAP).find(([, status]) => status === response.status)?.[0];
1009
+ return commonCode?.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
1010
+ }
1011
+ function wrapAsyncIteratorPreservingEventMeta(iterator, { mapResult, mapError, ...rest }) {
1012
+ return wrapAsyncIterator(iterator, {
1013
+ ...rest,
1014
+ mapResult: mapResult && (async (result) => {
1015
+ const mapped = await mapResult(result);
1016
+ if (mapped.value !== result.value) {
1017
+ const meta = getEventMeta(result.value);
1018
+ if (meta && isTypescriptObject(mapped.value)) {
1019
+ return { done: mapped.done, value: withEventMeta(mapped.value, meta) };
1020
+ }
1021
+ }
1022
+ return mapped;
1023
+ }),
1024
+ mapError: mapError && (async (error) => {
1025
+ const mapped = await mapError(error);
1026
+ if (mapped !== error) {
1027
+ const meta = getEventMeta(error);
1028
+ if (meta && isTypescriptObject(mapped)) {
1029
+ return withEventMeta(mapped, meta);
1030
+ }
1031
+ }
1032
+ return mapped;
1033
+ })
1034
+ });
1035
+ }
1036
+ function invalidSerializedData(detail) {
1037
+ return new TypeError(`Invalid RPC serialized data: ${detail}`);
1038
+ }
1039
+ function assertSerializedType(ok, type, expected) {
1040
+ if (!ok) {
1041
+ throw invalidSerializedData(`type "${type}" expects ${expected}.`);
1042
+ }
1043
+ }
1044
+ var DEFAULT_RPC_JSON_SERIALIZER_HANDLERS = {
1045
+ undefined: {
1046
+ condition(data) {
1047
+ return data === void 0;
1048
+ },
1049
+ serialize() {
1050
+ return null;
1051
+ },
1052
+ deserialize(serialized) {
1053
+ assertSerializedType(serialized === null, "undefined", "null");
1054
+ return void 0;
1055
+ },
1056
+ isTerminal: true
1057
+ },
1058
+ bigint: {
1059
+ condition(data) {
1060
+ return typeof data === "bigint";
1061
+ },
1062
+ serialize(data) {
1063
+ return data.toString();
1064
+ },
1065
+ deserialize(serialized) {
1066
+ assertSerializedType(typeof serialized === "string", "bigint", "a string");
1067
+ return BigInt(serialized);
1068
+ },
1069
+ isTerminal: true
1070
+ },
1071
+ date: {
1072
+ condition(data) {
1073
+ return data instanceof Date;
1074
+ },
1075
+ serialize(data) {
1076
+ if (Number.isNaN(data.getTime())) {
1077
+ return null;
1078
+ }
1079
+ return data.toISOString();
1080
+ },
1081
+ deserialize(serialized) {
1082
+ assertSerializedType(typeof serialized === "string" || serialized === null, "date", "a string or null");
1083
+ return new Date(serialized ?? Number.NaN);
1084
+ },
1085
+ isTerminal: true
1086
+ },
1087
+ nan: {
1088
+ condition(data) {
1089
+ return typeof data === "number" && Number.isNaN(data);
1090
+ },
1091
+ serialize() {
1092
+ return null;
1093
+ },
1094
+ deserialize(serialized) {
1095
+ assertSerializedType(serialized === null, "nan", "null");
1096
+ return Number.NaN;
1097
+ },
1098
+ isTerminal: true
1099
+ },
1100
+ infinity: {
1101
+ condition(data) {
1102
+ return data === Number.POSITIVE_INFINITY || data === Number.NEGATIVE_INFINITY;
1103
+ },
1104
+ serialize(data) {
1105
+ return data > 0 ? "Infinity" : "-Infinity";
1106
+ },
1107
+ deserialize(serialized) {
1108
+ assertSerializedType(serialized === "Infinity" || serialized === "-Infinity", "infinity", '"Infinity" or "-Infinity"');
1109
+ return serialized === "Infinity" ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
1110
+ },
1111
+ isTerminal: true
1112
+ },
1113
+ url: {
1114
+ condition(data) {
1115
+ return data instanceof URL;
1116
+ },
1117
+ serialize(data) {
1118
+ return data.toString();
1119
+ },
1120
+ deserialize(serialized) {
1121
+ assertSerializedType(typeof serialized === "string", "url", "a string");
1122
+ return new URL(serialized);
1123
+ },
1124
+ isTerminal: true
1125
+ },
1126
+ set: {
1127
+ condition(data) {
1128
+ return data instanceof Set;
1129
+ },
1130
+ serialize(data) {
1131
+ return Array.from(data);
1132
+ },
1133
+ deserialize(serialized) {
1134
+ assertSerializedType(Array.isArray(serialized), "set", "an array");
1135
+ return new Set(serialized);
1136
+ }
1137
+ },
1138
+ map: {
1139
+ condition(data) {
1140
+ return data instanceof Map;
1141
+ },
1142
+ serialize(data) {
1143
+ return Array.from(data.entries());
1144
+ },
1145
+ deserialize(serialized) {
1146
+ assertSerializedType(Array.isArray(serialized), "map", "an array");
1147
+ return new Map(serialized);
1148
+ }
1149
+ }
1150
+ };
1151
+ var RPCJsonSerializer = class {
1152
+ handlers;
1153
+ inlineBuiltInHandlers;
1154
+ handlerEntries;
1155
+ omitUndefinedProperties;
1156
+ constructor(options = {}) {
1157
+ this.omitUndefinedProperties = options.omitUndefinedProperties !== false;
1158
+ this.handlers = Object.assign(new NullProtoObj(), DEFAULT_RPC_JSON_SERIALIZER_HANDLERS);
1159
+ const customHandlers = options.handlers;
1160
+ if (customHandlers === void 0) {
1161
+ this.inlineBuiltInHandlers = true;
1162
+ return;
1163
+ }
1164
+ let inlineBuiltInHandlers = true;
1165
+ let handlerEntries = [];
1166
+ for (const key of Object.keys(customHandlers)) {
1167
+ const handler = customHandlers[key];
1168
+ this.handlers[key] = handler;
1169
+ if (inlineBuiltInHandlers && key in DEFAULT_RPC_JSON_SERIALIZER_HANDLERS) {
1170
+ inlineBuiltInHandlers = false;
1171
+ }
1172
+ if (inlineBuiltInHandlers && handler !== void 0) {
1173
+ handlerEntries.push([key, handler]);
1174
+ }
1175
+ }
1176
+ if (!inlineBuiltInHandlers) {
1177
+ handlerEntries = [];
1178
+ for (const key of Object.keys(this.handlers)) {
1179
+ const handler = this.handlers[key];
1180
+ if (handler !== void 0) {
1181
+ handlerEntries.push([key, handler]);
1182
+ }
1183
+ }
1184
+ }
1185
+ this.inlineBuiltInHandlers = inlineBuiltInHandlers;
1186
+ this.handlerEntries = handlerEntries;
1187
+ }
1188
+ serialize(data) {
1189
+ let meta = [];
1190
+ const maps = [];
1191
+ const blobs = [];
1192
+ const json = this.serializeValue(data, [], meta, maps, blobs);
1193
+ meta = meta.length === 0 ? void 0 : meta;
1194
+ if (maps.length === 0) {
1195
+ return { json, meta };
1196
+ }
1197
+ return { json, meta, maps, blobs };
1198
+ }
1199
+ /**
1200
+ * `segments` is a shared mutable stack (push/pop while walking),
1201
+ * so it must be copied before being stored in `meta` or `maps`.
1202
+ */
1203
+ serializeValue(data, segments, meta, maps, blobs) {
1204
+ if (this.inlineBuiltInHandlers) {
1205
+ switch (typeof data) {
1206
+ case "string":
1207
+ case "boolean":
1208
+ return data;
1209
+ case "number":
1210
+ if (Number.isFinite(data)) {
1211
+ return data;
1212
+ }
1213
+ if (Number.isNaN(data)) {
1214
+ meta.push(["nan", ...segments]);
1215
+ return null;
1216
+ }
1217
+ meta.push(["infinity", ...segments]);
1218
+ return data > 0 ? "Infinity" : "-Infinity";
1219
+ case "undefined":
1220
+ meta.push(["undefined", ...segments]);
1221
+ return null;
1222
+ case "bigint":
1223
+ meta.push(["bigint", ...segments]);
1224
+ return data.toString();
1225
+ case "object": {
1226
+ if (data === null) {
1227
+ return data;
1228
+ }
1229
+ if (data instanceof Date) {
1230
+ meta.push(["date", ...segments]);
1231
+ return Number.isNaN(data.getTime()) ? null : data.toISOString();
1232
+ }
1233
+ if (data instanceof URL) {
1234
+ meta.push(["url", ...segments]);
1235
+ return data.toString();
1236
+ }
1237
+ if (data instanceof Set) {
1238
+ const result = this.serializeValue(Array.from(data), segments, meta, maps, blobs);
1239
+ meta.push(["set", ...segments]);
1240
+ return result;
1241
+ }
1242
+ if (data instanceof Map) {
1243
+ const result = this.serializeValue(Array.from(data.entries()), segments, meta, maps, blobs);
1244
+ meta.push(["map", ...segments]);
1245
+ return result;
1246
+ }
1247
+ }
1248
+ }
1249
+ }
1250
+ const handlerEntries = this.handlerEntries;
1251
+ if (handlerEntries) {
1252
+ for (let i = 0; i < handlerEntries.length; i++) {
1253
+ const entry = handlerEntries[i];
1254
+ const handler = entry[1];
1255
+ if (handler.condition(data)) {
1256
+ const serialized = handler.serialize(data);
1257
+ if (handler.isTerminal) {
1258
+ meta.push([entry[0], ...segments]);
1259
+ if (serialized instanceof Blob) {
1260
+ maps.push(segments.slice());
1261
+ blobs.push(serialized);
1262
+ }
1263
+ return serialized;
1264
+ }
1265
+ const result = this.serializeValue(serialized, segments, meta, maps, blobs);
1266
+ meta.push([entry[0], ...segments]);
1267
+ return result;
1268
+ }
1269
+ }
1270
+ }
1271
+ if (data instanceof Blob) {
1272
+ maps.push(segments.slice());
1273
+ blobs.push(data);
1274
+ return data;
1275
+ }
1276
+ if (Array.isArray(data)) {
1277
+ const json = [];
1278
+ for (let i = 0; i < data.length; i++) {
1279
+ segments.push(i);
1280
+ json.push(this.serializeValue(data[i], segments, meta, maps, blobs));
1281
+ segments.pop();
1282
+ }
1283
+ return json;
1284
+ }
1285
+ if (isPlainObject(data)) {
1286
+ const json = new NullProtoObj();
1287
+ for (const k of Object.keys(data)) {
1288
+ const v = data[k];
1289
+ if (k === "toJSON" && typeof v === "function") {
1290
+ continue;
1291
+ }
1292
+ if (v === void 0 && this.omitUndefinedProperties) {
1293
+ continue;
1294
+ }
1295
+ segments.push(k);
1296
+ json[k] = this.serializeValue(v, segments, meta, maps, blobs);
1297
+ segments.pop();
1298
+ }
1299
+ return json;
1300
+ }
1301
+ return data;
1302
+ }
1303
+ deserialize(serialized) {
1304
+ const ref = { json: serialized.json };
1305
+ if (serialized.blobs?.length) {
1306
+ for (let i = 0; i < serialized.maps.length; i++) {
1307
+ const blob = serialized.blobs[i];
1308
+ if (!(blob instanceof Blob)) {
1309
+ throw invalidSerializedData(`blob ${i} is not a Blob.`);
1310
+ }
1311
+ const segments = serialized.maps[i];
1312
+ let original = serialized;
1313
+ let currentRef = ref;
1314
+ let preSegment = "json";
1315
+ for (let j = 0; j < segments.length; j++) {
1316
+ original = original[preSegment];
1317
+ currentRef = copyOnWrite(currentRef, preSegment, original);
1318
+ preSegment = segments[j];
1319
+ if (!Object.hasOwn(currentRef, preSegment)) {
1320
+ throw invalidSerializedData(`segment "${preSegment}" does not exist.`);
1321
+ }
1322
+ }
1323
+ currentRef[preSegment] = blob;
1324
+ }
1325
+ }
1326
+ if (serialized.meta) {
1327
+ for (const item of serialized.meta) {
1328
+ const type = item[0];
1329
+ const handler = this.handlers[type];
1330
+ if (handler === void 0) {
1331
+ throw invalidSerializedData(`type "${type}" is not supported.`);
1332
+ }
1333
+ let original = serialized;
1334
+ let currentRef = ref;
1335
+ let preSegment = "json";
1336
+ for (let i = 1; i < item.length; i++) {
1337
+ original = original[preSegment];
1338
+ currentRef = copyOnWrite(currentRef, preSegment, original);
1339
+ preSegment = item[i];
1340
+ if (!Object.hasOwn(currentRef, preSegment)) {
1341
+ throw invalidSerializedData(`segment "${preSegment}" does not exist.`);
1342
+ }
1343
+ }
1344
+ currentRef[preSegment] = handler.deserialize(currentRef[preSegment]);
1345
+ }
1346
+ }
1347
+ return ref.json;
1348
+ }
1349
+ };
1350
+ var RPCSerializer = class {
1351
+ jsonSerializer;
1352
+ defaultSerializeOptions;
1353
+ constructor(options = {}) {
1354
+ this.jsonSerializer = new RPCJsonSerializer(options);
1355
+ this.defaultSerializeOptions = options.serialize;
1356
+ }
1357
+ serialize(data, options = {}) {
1358
+ if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) {
1359
+ return data;
1360
+ }
1361
+ if (isAsyncIteratorObject(data)) {
1362
+ return wrapAsyncIteratorPreservingEventMeta(data, {
1363
+ mapResult: (result) => {
1364
+ if (result.value === void 0) {
1365
+ return result;
1366
+ }
1367
+ return { done: result.done, value: this.serializeValue(result.value, false) };
1368
+ },
1369
+ mapError: (e) => new ErrorEvent(
1370
+ this.serializeValue(toORPCError(e).toJSON(), false),
1371
+ { cause: e }
1372
+ )
1373
+ });
1374
+ }
1375
+ const useFormDataForBlobs = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true;
1376
+ return this.serializeValue(data, useFormDataForBlobs);
1377
+ }
1378
+ serializeValue(data, useFormDataForBlobs) {
1379
+ const { json, meta, maps, blobs } = this.jsonSerializer.serialize(data);
1380
+ if (!useFormDataForBlobs || !blobs?.length) {
1381
+ return { json, meta };
1382
+ }
1383
+ const form = new FormData();
1384
+ form.set("data", stringifyJSON({ json, meta, maps }));
1385
+ blobs.forEach((blob, i) => {
1386
+ form.set(i.toString(), blob);
1387
+ });
1388
+ return form;
1389
+ }
1390
+ deserialize(data) {
1391
+ if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) {
1392
+ return data;
1393
+ }
1394
+ if (isAsyncIteratorObject(data)) {
1395
+ return wrapAsyncIteratorPreservingEventMeta(data, {
1396
+ mapResult: (result) => {
1397
+ if (result.value === void 0) {
1398
+ return result;
1399
+ }
1400
+ return { done: result.done, value: this.deserializeValue(result.value) };
1401
+ },
1402
+ mapError: (e) => {
1403
+ if (!(e instanceof ErrorEvent)) {
1404
+ return e;
1405
+ }
1406
+ const deserialized = this.deserializeValue(e.data);
1407
+ if (isORPCErrorJson(deserialized)) {
1408
+ return createORPCErrorFromJson(deserialized, { cause: e });
1409
+ }
1410
+ return new ErrorEvent(deserialized, { cause: e });
1411
+ }
1412
+ });
1413
+ }
1414
+ return this.deserializeValue(data);
1415
+ }
1416
+ deserializeValue(data) {
1417
+ if (!(data instanceof FormData)) {
1418
+ return this.jsonSerializer.deserialize(data);
1419
+ }
1420
+ const serialized = JSON.parse(data.get("data"));
1421
+ const blobs = [];
1422
+ for (const [key, value2] of data) {
1423
+ if (value2 instanceof Blob) {
1424
+ blobs[Number(key)] = value2;
1425
+ }
1426
+ }
1427
+ return this.jsonSerializer.deserialize({ ...serialized, blobs });
1428
+ }
1429
+ };
1430
+
1431
+ // ../../node_modules/.pnpm/@orpc+client@2.0.0-beta.42/node_modules/@orpc/client/dist/index.mjs
1432
+ var RECURSIVE_CLIENT_UNWRAP_KEYS = /* @__PURE__ */ new Set([
1433
+ /**
1434
+ * Prevents the client from being treated as a thenable when users
1435
+ * accidentally write `await client`.
1436
+ */
1437
+ "then",
1438
+ /**
1439
+ * Commonly used by libraries to bind functions to a specific `this`
1440
+ * context.
1441
+ */
1442
+ "bind",
1443
+ /**
1444
+ * Commonly used by libraries to invoke functions with a specific `this`
1445
+ * context.
1446
+ */
1447
+ "call",
1448
+ /**
1449
+ * Commonly used by libraries to invoke functions with a specific `this`
1450
+ * context and an arguments array.
1451
+ */
1452
+ "apply",
1453
+ /**
1454
+ * Commonly accessed during primitive conversion, inspection, and logging.
1455
+ */
1456
+ "valueOf",
1457
+ /**
1458
+ * Commonly accessed during string conversion, inspection, and logging.
1459
+ */
1460
+ "toString",
1461
+ /**
1462
+ * Commonly accessed by serializers such as `JSON.stringify`.
1463
+ */
1464
+ "toJSON"
1465
+ ]);
1466
+ function resolveFriendlyClientOptions(options) {
1467
+ return {
1468
+ ...options,
1469
+ context: options.context ?? {}
1470
+ // Context only optional if all fields are optional
1471
+ };
1472
+ }
1473
+ function resolveClientRest(rest) {
1474
+ return [
1475
+ rest[0],
1476
+ // rest[0] can be undefined if TInput is optional,
1477
+ resolveFriendlyClientOptions(rest[1] ?? {})
1478
+ // rest[1] can be undefined if all fields of FriendlyClientOptions are optional
1479
+ ];
1480
+ }
1481
+ function createORPCClient(link, { path = [], ...options } = {}) {
1482
+ const procedureClient = (...rest) => {
1483
+ const [input, callOptions] = resolveClientRest(rest);
1484
+ const interceptors = [
1485
+ ...toArray(options.interceptors),
1486
+ ...toArray(options.scoped?.interceptors)
1487
+ ];
1488
+ return intercept(
1489
+ interceptors,
1490
+ { ...callOptions, input, path },
1491
+ ({ path: path2, input: input2, ...callOptions2 }) => link.call(path2, input2, callOptions2)
1492
+ );
1493
+ };
1494
+ const cache = /* @__PURE__ */ new Map();
1495
+ const recursive = new Proxy(procedureClient, {
1496
+ get(target, key) {
1497
+ if (typeof key !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) {
1498
+ return Reflect.get(target, key);
1499
+ }
1500
+ let client = cache.get(key);
1501
+ if (client === void 0) {
1502
+ client = createORPCClient(link, {
1503
+ ...options,
1504
+ path: [...path, key],
1505
+ scoped: options.scoped?.[key]
1506
+ });
1507
+ cache.set(key, client);
1508
+ }
1509
+ return client;
1510
+ }
1511
+ });
1512
+ return recursive;
1513
+ }
1514
+
1515
+ // ../../node_modules/.pnpm/@standard-server+fetch@0.10.1/node_modules/@standard-server/fetch/dist/index.mjs
1516
+ function toAsyncIteratorObject(stream) {
1517
+ const eventStream = stream?.pipeThrough(new TextDecoderStream()).pipeThrough(new EventStreamDecoderStream());
1518
+ const reader = eventStream?.getReader();
1519
+ return new AsyncIteratorClass(
1520
+ async () => {
1521
+ while (true) {
1522
+ if (reader === void 0) {
1523
+ return { done: true, value: void 0 };
1524
+ }
1525
+ const { done, value: value2 } = await reader.read();
1526
+ if (done) {
1527
+ return { done: true, value: void 0 };
1528
+ }
1529
+ switch (value2.event) {
1530
+ case "message": {
1531
+ let message = parseEmptyableJSON(value2.data);
1532
+ if (isTypescriptObject(message)) {
1533
+ message = withEventMeta(message, value2);
1534
+ }
1535
+ return { done: false, value: message };
1536
+ }
1537
+ case "error": {
1538
+ let error = new ErrorEvent(parseEmptyableJSON(value2.data));
1539
+ error = withEventMeta(error, value2);
1540
+ throw error;
1541
+ }
1542
+ case "close": {
1543
+ let close = parseEmptyableJSON(value2.data);
1544
+ if (isTypescriptObject(close)) {
1545
+ close = withEventMeta(close, value2);
1546
+ }
1547
+ return { done: true, value: close };
1548
+ }
1549
+ }
1550
+ }
1551
+ },
1552
+ async () => {
1553
+ await reader?.cancel();
1554
+ }
1555
+ );
1556
+ }
1557
+ function toEventStream(iterator, options = {}) {
1558
+ const keepAliveEnabled = options.keepAlive?.enabled ?? true;
1559
+ const keepAliveInterval = options.keepAlive?.interval ?? 15e3;
1560
+ const keepAliveComment = options.keepAlive?.comment ?? "";
1561
+ const initialCommentEnabled = options.initialComment?.enabled ?? true;
1562
+ const initialComment = options.initialComment?.comment ?? "";
1563
+ let cancelled = false;
1564
+ let timeout;
1565
+ const stream = new ReadableStream({
1566
+ start(controller) {
1567
+ if (initialCommentEnabled) {
1568
+ controller.enqueue(
1569
+ encodeEventStreamMessage({
1570
+ comments: [initialComment]
1571
+ })
1572
+ );
1573
+ }
1574
+ },
1575
+ async pull(controller) {
1576
+ let result;
1577
+ try {
1578
+ if (keepAliveEnabled) {
1579
+ timeout = setInterval(() => {
1580
+ controller.enqueue(
1581
+ encodeEventStreamMessage({
1582
+ comments: [keepAliveComment]
1583
+ })
1584
+ );
1585
+ }, keepAliveInterval);
1586
+ }
1587
+ result = await iterator.next();
1588
+ } catch (err) {
1589
+ clearInterval(timeout);
1590
+ if (cancelled) {
1591
+ return;
1592
+ }
1593
+ if (err instanceof ErrorEvent) {
1594
+ controller.enqueue(
1595
+ encodeEventStreamMessage({
1596
+ ...getEventMeta(err),
1597
+ event: "error",
1598
+ data: stringifyJSON(err.data)
1599
+ })
1600
+ );
1601
+ controller.close();
1602
+ } else {
1603
+ controller.error(err);
1604
+ }
1605
+ return;
1606
+ }
1607
+ clearInterval(timeout);
1608
+ if (cancelled) {
1609
+ return;
1610
+ }
1611
+ try {
1612
+ const [data, meta] = unwrapEvent(result.value);
1613
+ controller.enqueue(
1614
+ encodeEventStreamMessage({
1615
+ ...meta,
1616
+ event: result.done ? "close" : "message",
1617
+ data: stringifyJSON(data)
1618
+ })
1619
+ );
1620
+ } catch (err) {
1621
+ try {
1622
+ if (!result.done) {
1623
+ await iterator.return?.();
1624
+ }
1625
+ } finally {
1626
+ controller.error(err);
1627
+ }
1628
+ return;
1629
+ }
1630
+ if (result.done) {
1631
+ controller.close();
1632
+ }
1633
+ },
1634
+ async cancel() {
1635
+ cancelled = true;
1636
+ clearInterval(timeout);
1637
+ await iterator.return?.();
1638
+ }
1639
+ }).pipeThrough(new TextEncoderStream());
1640
+ return stream;
1641
+ }
1642
+ async function toStandardBody(re, options) {
1643
+ const hint = options?.hint ?? resolveStandardBodyHint({
1644
+ "standard-server": re.headers.get("standard-server") ?? void 0,
1645
+ "content-type": re.headers.get("content-type") ?? void 0,
1646
+ "content-length": re.headers.get("content-length") ?? void 0,
1647
+ "content-disposition": re.headers.get("content-disposition") ?? void 0
1648
+ });
1649
+ if (hint === "none") {
1650
+ return void 0;
1651
+ }
1652
+ if (re.bodyUsed) {
1653
+ throw new TypeError("Failed to read body: body stream already read");
1654
+ }
1655
+ if (hint === "json") {
1656
+ const text = await re.text();
1657
+ return parseEmptyableJSON(text);
1658
+ }
1659
+ if (hint === "form-data") {
1660
+ return await re.formData();
1661
+ }
1662
+ if (hint === "url-search-params") {
1663
+ const text = await re.text();
1664
+ return new URLSearchParams(text);
1665
+ }
1666
+ if (hint === "event-stream") {
1667
+ return toAsyncIteratorObject(re.body);
1668
+ }
1669
+ if (hint === "file") {
1670
+ const contentDisposition = re.headers.get("content-disposition");
1671
+ const fileName = contentDisposition !== null ? getFilenameFromContentDisposition(contentDisposition) : void 0;
1672
+ const blob = await re.blob();
1673
+ return new File([blob], fileName ?? "blob", {
1674
+ type: blob.type
1675
+ });
1676
+ }
1677
+ return re.body ?? new ReadableStream({
1678
+ start(controller) {
1679
+ controller.close();
1680
+ }
1681
+ });
1682
+ }
1683
+ function toFetchBody(body, headers, options = {}) {
1684
+ headers = { ...headers };
1685
+ if (body instanceof ReadableStream) {
1686
+ headers["standard-server"] ??= "octet-stream";
1687
+ headers["content-type"] ??= "application/octet-stream";
1688
+ return [body, headers];
1689
+ }
1690
+ if (body instanceof Blob) {
1691
+ headers["standard-server"] ??= "file";
1692
+ headers["content-type"] ??= body.type;
1693
+ headers["content-disposition"] ??= generateContentDisposition(
1694
+ body instanceof File ? body.name ?? "" : "blob"
1695
+ );
1696
+ if (Number.isFinite(body.size)) {
1697
+ headers["content-length"] = body.size.toString();
1698
+ return [body, headers];
1699
+ }
1700
+ return [body.stream(), headers];
1701
+ }
1702
+ headers["standard-server"] = void 0;
1703
+ headers["content-length"] = void 0;
1704
+ if (body === void 0) {
1705
+ headers["content-type"] = void 0;
1706
+ return [void 0, headers];
1707
+ }
1708
+ if (body instanceof FormData) {
1709
+ headers["content-type"] = void 0;
1710
+ return [body, headers];
1711
+ }
1712
+ if (body instanceof URLSearchParams) {
1713
+ headers["content-type"] = void 0;
1714
+ return [body, headers];
1715
+ }
1716
+ if (isAsyncIteratorObject(body)) {
1717
+ headers["content-type"] = "text/event-stream";
1718
+ return [toEventStream(body, options.eventStream), headers];
1719
+ }
1720
+ headers["content-type"] = "application/json";
1721
+ return [stringifyJSON(body), headers];
1722
+ }
1723
+ function toStandardHeaders(headers) {
1724
+ const standardHeaders = /* @__PURE__ */ Object.create(null);
1725
+ headers.forEach((value2, key) => {
1726
+ if (Array.isArray(standardHeaders[key])) {
1727
+ standardHeaders[key].push(value2);
1728
+ } else if (standardHeaders[key] !== void 0) {
1729
+ standardHeaders[key] = [standardHeaders[key], value2];
1730
+ } else {
1731
+ standardHeaders[key] = value2;
1732
+ }
1733
+ });
1734
+ return standardHeaders;
1735
+ }
1736
+ function toFetchHeaders(standardHeaders) {
1737
+ const headers = new Headers();
1738
+ for (const key of Object.keys(standardHeaders)) {
1739
+ if (key.startsWith(":")) {
1740
+ continue;
1741
+ }
1742
+ const value2 = standardHeaders[key];
1743
+ if (Array.isArray(value2)) {
1744
+ for (const v of value2) {
1745
+ headers.append(key, v);
1746
+ }
1747
+ } else if (value2 !== void 0) {
1748
+ headers.append(key, value2);
1749
+ }
1750
+ }
1751
+ return headers;
1752
+ }
1753
+ function toStandardLazyResponse(response) {
1754
+ return {
1755
+ resolveBody: (hint) => toStandardBody(response, { hint }),
1756
+ status: response.status,
1757
+ get headers() {
1758
+ const headers = toStandardHeaders(response.headers);
1759
+ Object.defineProperty(this, "headers", { value: headers, writable: true });
1760
+ return headers;
1761
+ },
1762
+ set headers(value2) {
1763
+ Object.defineProperty(this, "headers", { value: value2, writable: true });
1764
+ }
1765
+ };
1766
+ }
1767
+
1768
+ // ../../node_modules/.pnpm/@orpc+client@2.0.0-beta.42/node_modules/@orpc/client/dist/shared/client.Bstqyaro.mjs
1769
+ var CompositeStandardLinkPlugin = class {
1770
+ name = "~composite";
1771
+ plugins;
1772
+ constructor(plugins = []) {
1773
+ this.plugins = sortPlugins(plugins);
1774
+ }
1775
+ init(options) {
1776
+ for (const plugin of this.plugins) {
1777
+ if (plugin.init) {
1778
+ options = plugin.init(options);
1779
+ }
1780
+ }
1781
+ return options;
1782
+ }
1783
+ };
1784
+ var StandardLink = class {
1785
+ constructor(codec, transport, options = {}) {
1786
+ this.codec = codec;
1787
+ this.transport = transport;
1788
+ options = new CompositeStandardLinkPlugin(options.plugins).init(options);
1789
+ this.interceptors = options.interceptors;
1790
+ this.transportInterceptors = options.transportInterceptors;
1791
+ }
1792
+ interceptors;
1793
+ transportInterceptors;
1794
+ /**
1795
+ * @throws ORPCError, transport-level errors (network failures, timeouts, etc.)
1796
+ */
1797
+ call(path, input, options) {
1798
+ return runWithSpan(`${ORPC_NAME}.${path.join("/")}`, (span) => {
1799
+ span?.setAttribute("rpc.system", ORPC_NAME);
1800
+ span?.setAttribute("rpc.method", path.join("."));
1801
+ if (getTracer() && isAsyncIteratorObject(input)) {
1802
+ input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
1803
+ } else if (getTracer() && input instanceof ReadableStream) {
1804
+ input = override(input, traceReadableStream("consume_octet_stream_input", input));
1805
+ }
1806
+ return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
1807
+ const tracer = getTracer();
1808
+ const activeSpan = tracer?.getActiveSpan() ?? span;
1809
+ let request = await runWithSpan(
1810
+ { name: "encode_input", parent: activeSpan },
1811
+ () => this.codec.encodeInput(input2, path2, options2)
1812
+ );
1813
+ if (activeSpan && tracer?.inject) {
1814
+ const headers = { ...request.headers };
1815
+ tracer.inject(activeSpan, headers);
1816
+ request = { ...request, headers };
1817
+ }
1818
+ const response = await intercept(
1819
+ this.transportInterceptors,
1820
+ { ...options2, path: path2, request },
1821
+ ({ path: path3, request: request2, ...options3 }) => {
1822
+ const activeTransportSpan = tracer?.getActiveSpan() ?? activeSpan;
1823
+ return runWithSpan(
1824
+ { name: "send_request", parent: activeTransportSpan },
1825
+ () => this.transport.send(request2, path3, options3)
1826
+ );
1827
+ }
1828
+ );
1829
+ const decodedResult = await runWithSpan(
1830
+ { name: "decode_response", parent: activeSpan },
1831
+ () => this.codec.decodeResponse(response, path2, options2)
1832
+ );
1833
+ if (decodedResult.kind === "error") {
1834
+ throw decodedResult.error;
1835
+ }
1836
+ const output = decodedResult.output;
1837
+ if (getTracer() && isAsyncIteratorObject(output)) {
1838
+ return override(output, traceAsyncIterator("consume_async_iterator_object_output", output));
1839
+ } else if (getTracer() && output instanceof ReadableStream) {
1840
+ return override(output, traceReadableStream("consume_octet_stream_output", output));
1841
+ }
1842
+ return output;
1843
+ });
1844
+ });
1845
+ }
1846
+ };
1847
+ var END_SLASH_REGEX = /\/$/;
1848
+ var RPCLinkCodec = class {
1849
+ baseUrl;
1850
+ maxUrlLength;
1851
+ fallbackMethod;
1852
+ expectedMethod;
1853
+ headers;
1854
+ serializer;
1855
+ constructor(options) {
1856
+ this.baseUrl = options.url ?? "/";
1857
+ this.maxUrlLength = options.maxUrlLength ?? 2083;
1858
+ this.fallbackMethod = options.fallbackMethod ?? "POST";
1859
+ this.expectedMethod = options.method ?? this.fallbackMethod;
1860
+ this.headers = options.headers ?? {};
1861
+ this.serializer = options.serializer ?? new RPCSerializer();
1862
+ }
1863
+ async encodeInput(input, path, options) {
1864
+ let headers = toResolvedStandardHeaders(await value(this.headers, options, path, input));
1865
+ if (options.lastEventId !== void 0) {
1866
+ headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
1867
+ }
1868
+ const expectedMethod = await value(this.expectedMethod, options, path, input);
1869
+ const baseUrl = await value(this.baseUrl, options, path, input);
1870
+ const [pathname, search, hash] = parseStandardUrl(baseUrl);
1871
+ const newPathname = `${pathname.replace(END_SLASH_REGEX, "")}${pathToHttpPath(path)}`;
1872
+ const serialized = this.serializer.serialize(input);
1873
+ if (expectedMethod === "GET" && !(serialized instanceof Blob) && !(serialized instanceof ReadableStream) && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
1874
+ const maxUrlLength = await value(this.maxUrlLength, options, path, input);
1875
+ const mergedSearch = new URLSearchParams(search);
1876
+ mergedSearch.append("data", stringifyJSON(serialized) ?? "");
1877
+ const url2 = `${newPathname}?${mergedSearch}${hash ?? ""}`;
1878
+ if (url2.length <= maxUrlLength) {
1879
+ return {
1880
+ body: void 0,
1881
+ method: expectedMethod,
1882
+ headers,
1883
+ url: url2,
1884
+ signal: options.signal
1885
+ };
1886
+ }
1887
+ }
1888
+ const url = `${newPathname}${search ?? ""}${hash ?? ""}`;
1889
+ return {
1890
+ url,
1891
+ method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
1892
+ headers,
1893
+ body: serialized,
1894
+ signal: options.signal
1895
+ };
1896
+ }
1897
+ async decodeResponse(response) {
1898
+ const isOk = response.status < 400;
1899
+ const body = await response.resolveBody();
1900
+ const deserialized = await (async () => {
1901
+ try {
1902
+ return this.serializer.deserialize(body);
1903
+ } catch (cause) {
1904
+ throw createORPCErrorFromMalformedResponse({
1905
+ message: "Invalid RPC response format.",
1906
+ response: { status: response.status, headers: response.headers, body },
1907
+ cause
1908
+ });
1909
+ }
1910
+ })();
1911
+ if (!isOk) {
1912
+ if (isORPCErrorJson(deserialized)) {
1913
+ return { kind: "error", error: createORPCErrorFromJson(deserialized) };
1914
+ }
1915
+ return {
1916
+ kind: "error",
1917
+ error: createORPCErrorFromMalformedResponse({ response: { headers: response.headers, status: response.status, body } })
1918
+ };
1919
+ }
1920
+ return { kind: "output", output: deserialized };
1921
+ }
1922
+ };
1923
+ function toResolvedStandardHeaders(headers) {
1924
+ if (typeof headers.forEach === "function") {
1925
+ return toStandardHeaders(headers);
1926
+ }
1927
+ return headers;
1928
+ }
1929
+
1930
+ // ../../node_modules/.pnpm/@orpc+client@2.0.0-beta.42/node_modules/@orpc/client/dist/adapters/fetch/index.mjs
1931
+ var GET_SUPPORTED_DUPLEX_MODE = once(() => {
1932
+ try {
1933
+ let duplex;
1934
+ void new Request(
1935
+ "https://example.com",
1936
+ {
1937
+ method: "POST",
1938
+ body: new ReadableStream(),
1939
+ get duplex() {
1940
+ duplex = "half";
1941
+ return "half";
1942
+ }
1943
+ }
1944
+ );
1945
+ return duplex;
1946
+ } catch {
1947
+ return void 0;
1948
+ }
1949
+ });
1950
+ var FetchLinkTransport = class {
1951
+ origin;
1952
+ fetch;
1953
+ toFetchRequestOptions;
1954
+ constructor(options) {
1955
+ this.origin = options.origin;
1956
+ this.fetch = options.fetch ?? ((url, init) => globalThis.fetch(url, init));
1957
+ this.toFetchRequestOptions = options.toFetchRequest;
1958
+ }
1959
+ async send(standardRequest, path, options) {
1960
+ let origin = await value(this.origin, options, path);
1961
+ if (origin?.endsWith("/")) {
1962
+ origin = origin.slice(0, -1);
1963
+ }
1964
+ const url = `${origin ?? ""}${standardRequest.url}`;
1965
+ const [body, standardHeaders] = toFetchBody(standardRequest.body, standardRequest.headers, this.toFetchRequestOptions);
1966
+ const init = {
1967
+ body,
1968
+ headers: toFetchHeaders(standardHeaders),
1969
+ method: standardRequest.method,
1970
+ signal: options.signal,
1971
+ redirect: "manual"
1972
+ };
1973
+ if (body instanceof ReadableStream) {
1974
+ const duplex = GET_SUPPORTED_DUPLEX_MODE();
1975
+ if (duplex !== void 0) {
1976
+ init.duplex = duplex;
1977
+ }
1978
+ }
1979
+ const fetch = this.fetch;
1980
+ const response = await fetch(url, init, options, path);
1981
+ const standardResponse = toStandardLazyResponse(response);
1982
+ return standardResponse;
1983
+ }
1984
+ };
1985
+ var RPCLink = class extends StandardLink {
1986
+ constructor(options) {
1987
+ const codec = new RPCLinkCodec(options);
1988
+ const transport = new FetchLinkTransport(options);
1989
+ super(codec, transport, options);
1990
+ }
1991
+ };
1992
+
1993
+ // src/lib/api.ts
1994
+ var makeClient = (baseUrl, token) => createORPCClient(
1995
+ new RPCLink({
1996
+ headers: () => token ? { Authorization: `Bearer ${token}`, [CLI_VERSION_HEADER]: PACKAGE_VERSION } : { [CLI_VERSION_HEADER]: PACKAGE_VERSION },
1997
+ origin: baseUrl,
1998
+ url: "/api/orpc"
1999
+ })
2000
+ );
2001
+ var createClient = () => {
2002
+ const token = getToken();
2003
+ if (!token) {
2004
+ throw new Error("Not logged in. Run `vg login` to authenticate.");
2005
+ }
2006
+ return makeClient(getBaseUrl(), token);
2007
+ };
2008
+ var authErrorCode = (cause) => cause instanceof ORPCError ? cause.code : null;
2009
+ var forwardJson = async (client, input) => await client.generate.forward(input);
2010
+ var createPublicClient = (baseUrl) => makeClient(baseUrl);
2011
+
2012
+ export {
2013
+ createClient,
2014
+ authErrorCode,
2015
+ forwardJson,
2016
+ createPublicClient
2017
+ };