devframe 0.2.2 → 0.3.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 (62) hide show
  1. package/dist/adapters/build.d.mts +1 -1
  2. package/dist/adapters/build.mjs +5 -5
  3. package/dist/adapters/cli.d.mts +1 -1
  4. package/dist/adapters/cli.mjs +2 -2
  5. package/dist/adapters/dev.d.mts +2 -2
  6. package/dist/adapters/dev.mjs +1 -1
  7. package/dist/adapters/embedded.d.mts +1 -1
  8. package/dist/adapters/mcp.d.mts +1 -1
  9. package/dist/adapters/mcp.mjs +8 -7
  10. package/dist/client/index.d.mts +18 -4
  11. package/dist/client/index.mjs +321 -8
  12. package/dist/{context-BDpuScNZ.d.mts → context-CwjX6sCG.d.mts} +1 -1
  13. package/dist/{dev-CZ9ZQkuO.mjs → dev-BbmanqL7.mjs} +1 -1
  14. package/dist/{devframe-DAfZWnpI.d.mts → devframe-sc4cb5xr.d.mts} +48 -90
  15. package/dist/diagnostics-GitRGKbr.mjs +33 -0
  16. package/dist/diagnostics-reporter-CBBZwoMv.mjs +38 -0
  17. package/dist/{rpc-BlVCyk9W.mjs → dump-zMleojnD.mjs} +147 -134
  18. package/dist/helpers/vite.d.mts +1 -1
  19. package/dist/helpers/vite.mjs +6 -5
  20. package/dist/{host-h3-DEfOpa0j.mjs → host-h3-TTunNr_n.mjs} +284 -44
  21. package/dist/human-id-Dq-qgtES.mjs +803 -0
  22. package/dist/index-C5PmWqBf.d.mts +79 -0
  23. package/dist/{index-BNAsgVNz.d.mts → index-CTK6fuXs.d.mts} +31 -78
  24. package/dist/index-DTeZXHSi.d.mts +639 -0
  25. package/dist/index.d.mts +4 -4
  26. package/dist/node/auth.d.mts +2 -2
  27. package/dist/node/auth.mjs +1 -2
  28. package/dist/node/index.d.mts +10 -14
  29. package/dist/node/index.mjs +2 -2
  30. package/dist/node/internal.d.mts +2 -2
  31. package/dist/node/internal.mjs +2 -3
  32. package/dist/recipes/open-helpers.d.mts +1 -1
  33. package/dist/rpc/dump.d.mts +2 -0
  34. package/dist/rpc/dump.mjs +2 -0
  35. package/dist/rpc/index.d.mts +2 -2
  36. package/dist/rpc/index.mjs +128 -2
  37. package/dist/rpc/transports/ws-client.d.mts +25 -1
  38. package/dist/rpc/transports/ws-client.mjs +2 -2
  39. package/dist/rpc/transports/ws-server.d.mts +1 -1
  40. package/dist/rpc/transports/ws-server.mjs +2 -2
  41. package/dist/{serialization-CwO31axa.mjs → serialization-BlqLh4_J.mjs} +4 -38
  42. package/dist/{server-BGSrxsQb.d.mts → server-ouL4gZbu.d.mts} +1 -1
  43. package/dist/shared-state-CasqoUba.mjs +1019 -0
  44. package/dist/{shared-state-BJXkPxtf.mjs → shared-state-u0y123fi.mjs} +6 -6
  45. package/dist/{storage-D-jLaxDA.mjs → storage-K-OxR1xf.mjs} +5 -3
  46. package/dist/structured-clone-jegjz0hM.mjs +208 -0
  47. package/dist/types/index.d.mts +4 -4
  48. package/dist/utils/events.d.mts +1 -1
  49. package/dist/utils/hash.mjs +1 -1
  50. package/dist/utils/shared-state.d.mts +1 -1
  51. package/dist/utils/shared-state.mjs +1 -1
  52. package/dist/utils/streaming-channel.d.mts +1 -1
  53. package/dist/utils/structured-clone.mjs +1 -1
  54. package/dist/{ws-server-DKlqI8XP.d.mts → ws-server-DOwLJL23.d.mts} +1 -1
  55. package/package.json +3 -2
  56. package/skills/devframe/SKILL.md +1 -1
  57. package/dist/diagnostics-DNxVjo6X.mjs +0 -56
  58. package/dist/revoke-DDa7VSJa.mjs +0 -35
  59. package/dist/ws-client-CrLsflnY.d.mts +0 -26
  60. /package/dist/{hash-CIBte1yS.mjs → hash-bwOD8RgU.mjs} +0 -0
  61. /package/dist/{structured-clone-CD2l4fI3.mjs → structured-clone-PdCZwt7F.mjs} +0 -0
  62. /package/dist/{types-DmcujDa5.d.mts → types-BXL7EIDM.d.mts} +0 -0
@@ -1,13 +1,9 @@
1
- import { l as RpcFunctionsCollectorBase } from "./rpc-BlVCyk9W.mjs";
2
- import { r as diagnostics } from "./serialization-CwO31axa.mjs";
1
+ import { t as devframeReporter } from "./diagnostics-reporter-CBBZwoMv.mjs";
2
+ import { t as diagnostics } from "./diagnostics-GitRGKbr.mjs";
3
+ import { RpcFunctionsCollectorBase } from "./rpc/index.mjs";
3
4
  import { defineRpcFunction } from "./index.mjs";
4
- import { colors as colors$1 } from "./utils/colors.mjs";
5
- import { n as logger, t as diagnostics$1 } from "./diagnostics-DNxVjo6X.mjs";
6
- import { createEventEmitter } from "./utils/events.mjs";
7
- import { t as createSharedState } from "./shared-state-BJXkPxtf.mjs";
8
- import { createStreamReader, createStreamSink } from "./utils/streaming-channel.mjs";
9
- import { consoleReporter, createLogger, defineDiagnostics } from "logs-sdk";
10
- import { ansiFormatter } from "logs-sdk/formatters/ansi";
5
+ import { i as diagnostics$1, n as nanoid, r as createEventEmitter, t as createSharedState } from "./shared-state-CasqoUba.mjs";
6
+ import { defineDiagnostics } from "nostics";
11
7
  import { isatty } from "node:tty";
12
8
  import { formatWithOptions, inspect } from "node:util";
13
9
  import { existsSync } from "node:fs";
@@ -55,7 +51,7 @@ var DevToolsAgentHost = class {
55
51
  return existed;
56
52
  }
57
53
  registerResource(input) {
58
- if (this.resources.has(input.id)) throw logger.DF0016({ id: input.id }).throw();
54
+ if (this.resources.has(input.id)) throw diagnostics$1.DF0016.throw({ id: input.id });
59
55
  const resource = {
60
56
  id: input.id,
61
57
  name: input.name,
@@ -117,11 +113,11 @@ var DevToolsAgentHost = class {
117
113
  this._rpcUnsubscribe = void 0;
118
114
  }
119
115
  _validateToolId(id) {
120
- if (this.tools.has(id)) throw logger.DF0015({ id }).throw();
121
- if (this.context.rpc.definitions.get(id)?.agent) throw logger.DF0015({ id }).throw();
116
+ if (this.tools.has(id)) throw diagnostics$1.DF0015.throw({ id });
117
+ if (this.context.rpc.definitions.get(id)?.agent) throw diagnostics$1.DF0015.throw({ id });
122
118
  }
123
119
  _projectTool(input) {
124
- if (!input.description || typeof input.description !== "string") throw logger.DF0014({ name: input.id }).throw();
120
+ if (!input.description || typeof input.description !== "string") throw diagnostics$1.DF0014.throw({ name: input.id });
125
121
  return {
126
122
  id: input.id,
127
123
  kind: "tool",
@@ -139,7 +135,7 @@ var DevToolsAgentHost = class {
139
135
  for (const [name, def] of this.context.rpc.definitions) {
140
136
  const agent = def.agent;
141
137
  if (!agent) continue;
142
- if (!agent.description || typeof agent.description !== "string") throw logger.DF0014({ name }).throw();
138
+ if (!agent.description || typeof agent.description !== "string") throw diagnostics$1.DF0014.throw({ name });
143
139
  const type = def.type ?? "query";
144
140
  const safety = agent.safety ?? inferSafety(type);
145
141
  out.push({
@@ -190,28 +186,20 @@ function hasPositionalKeys(obj) {
190
186
  //#region src/node/host-diagnostics.ts
191
187
  var DevToolsDiagnosticsHost = class {
192
188
  context;
193
- _definitions = [];
194
- _logger;
195
- defineDiagnostics = defineDiagnostics;
196
- createLogger = createLogger;
189
+ _registry = {};
190
+ logger = new Proxy({}, { get: (_, code) => this._registry[code] });
191
+ defineDiagnostics = (opts) => {
192
+ return defineDiagnostics({
193
+ ...opts,
194
+ reporters: [devframeReporter, ...opts.reporters ?? []]
195
+ });
196
+ };
197
197
  constructor(context, initialDefinitions = []) {
198
198
  this.context = context;
199
- this._definitions = [...initialDefinitions];
200
- this._rebuild();
201
- }
202
- get logger() {
203
- return this._logger;
199
+ for (const d of initialDefinitions) this.register(d);
204
200
  }
205
- register(definitions) {
206
- this._definitions.push(definitions);
207
- this._rebuild();
208
- }
209
- _rebuild() {
210
- this._logger = createLogger({
211
- diagnostics: this._definitions,
212
- formatter: ansiFormatter(colors$1),
213
- reporters: consoleReporter
214
- });
201
+ register(diagnostics) {
202
+ Object.assign(this._registry, diagnostics);
215
203
  }
216
204
  };
217
205
  //#endregion
@@ -515,7 +503,7 @@ function createRpcSharedStateServerHost(rpc) {
515
503
  const host = {
516
504
  get: async (key, options) => {
517
505
  if (sharedState.has(key)) return sharedState.get(key);
518
- if (options?.initialValue === void 0 && options?.sharedState === void 0) throw logger.DF0013({ key }).throw();
506
+ if (options?.initialValue === void 0 && options?.sharedState === void 0) throw diagnostics$1.DF0013.throw({ key });
519
507
  debug$1("new-state", key);
520
508
  const state = options.sharedState ?? createSharedState({
521
509
  initialValue: options.initialValue,
@@ -576,6 +564,258 @@ function createRpcSharedStateServerHost(rpc) {
576
564
  return host;
577
565
  }
578
566
  //#endregion
567
+ //#region src/utils/streaming-channel.ts
568
+ const DEFAULT_HIGH_WATER_MARK = 256;
569
+ var StreamClosedError = class extends Error {
570
+ name = "StreamClosedError";
571
+ };
572
+ /**
573
+ * Build a server-side stream sink. RPC-agnostic — the RPC host wires
574
+ * `events.on('chunk' | 'end')` to broadcast, and reads `buffer` to replay
575
+ * for late or reconnecting subscribers.
576
+ */
577
+ function createStreamSink(options = {}) {
578
+ const id = options.id ?? nanoid();
579
+ const replayWindow = Math.max(0, options.replayWindow ?? 0);
580
+ const events = createEventEmitter();
581
+ const controller = new AbortController();
582
+ const buffer = [];
583
+ let closed = false;
584
+ let lastSeq = 0;
585
+ function write(chunk) {
586
+ if (closed) throw new StreamClosedError(`Cannot write to a closed stream "${id}"`);
587
+ lastSeq += 1;
588
+ if (replayWindow > 0) {
589
+ buffer.push({
590
+ seq: lastSeq,
591
+ chunk
592
+ });
593
+ if (buffer.length > replayWindow) buffer.splice(0, buffer.length - replayWindow);
594
+ }
595
+ events.emit("chunk", lastSeq, chunk);
596
+ }
597
+ function error(reason) {
598
+ if (closed) return;
599
+ closed = true;
600
+ const payload = toErrorPayload(reason);
601
+ controller.abort(reason);
602
+ events.emit("end", payload);
603
+ }
604
+ function close() {
605
+ if (closed) return;
606
+ closed = true;
607
+ if (!controller.signal.aborted) controller.abort("stream closed");
608
+ events.emit("end", void 0);
609
+ }
610
+ function abort(reason) {
611
+ if (closed) return;
612
+ if (!controller.signal.aborted) controller.abort(reason ?? "aborted");
613
+ }
614
+ const writable = new WritableStream({
615
+ write(chunk) {
616
+ write(chunk);
617
+ },
618
+ close() {
619
+ close();
620
+ },
621
+ abort(reason) {
622
+ error(reason);
623
+ }
624
+ });
625
+ return {
626
+ id,
627
+ signal: controller.signal,
628
+ get closed() {
629
+ return closed;
630
+ },
631
+ get lastSeq() {
632
+ return lastSeq;
633
+ },
634
+ write,
635
+ error,
636
+ close,
637
+ abort,
638
+ writable,
639
+ events,
640
+ buffer
641
+ };
642
+ }
643
+ /**
644
+ * Build a client-side stream reader. RPC-agnostic — the RPC host calls
645
+ * `_push(seq, chunk)` on each incoming chunk and `_end(error?)` on the
646
+ * terminal frame. Consumers iterate with `for await` or pipe `readable`.
647
+ */
648
+ function createStreamReader(options = {}) {
649
+ const id = options.id ?? nanoid();
650
+ const highWaterMark = Math.max(1, options.highWaterMark ?? DEFAULT_HIGH_WATER_MARK);
651
+ const queue = [];
652
+ let lastSeenSeq = 0;
653
+ let done = false;
654
+ let cancelled = false;
655
+ let endError;
656
+ let pending;
657
+ let pullController;
658
+ let readableInstance;
659
+ function drainNext() {
660
+ if (!pending) return;
661
+ if (queue.length > 0) {
662
+ const value = queue.shift();
663
+ const r = pending;
664
+ pending = void 0;
665
+ r.resolve({
666
+ value,
667
+ done: false
668
+ });
669
+ return;
670
+ }
671
+ if (done) {
672
+ const r = pending;
673
+ pending = void 0;
674
+ if (endError) {
675
+ const err = new Error(endError.message);
676
+ err.name = endError.name;
677
+ r.reject(err);
678
+ } else r.resolve({
679
+ value: void 0,
680
+ done: true
681
+ });
682
+ }
683
+ }
684
+ function feedReadable() {
685
+ if (!pullController) return;
686
+ while (queue.length > 0) {
687
+ const v = queue.shift();
688
+ try {
689
+ pullController.enqueue(v);
690
+ } catch {
691
+ break;
692
+ }
693
+ }
694
+ if (done && pullController) {
695
+ try {
696
+ if (endError) {
697
+ const err = new Error(endError.message);
698
+ err.name = endError.name;
699
+ pullController.error(err);
700
+ } else pullController.close();
701
+ } catch {}
702
+ pullController = void 0;
703
+ }
704
+ }
705
+ function push(seq, chunk) {
706
+ if (done || cancelled) return;
707
+ if (seq <= lastSeenSeq) return;
708
+ lastSeenSeq = seq;
709
+ queue.push(chunk);
710
+ if (queue.length > highWaterMark) {
711
+ const overflow = queue.length - highWaterMark;
712
+ queue.splice(0, overflow);
713
+ options.onOverflow?.(overflow);
714
+ }
715
+ drainNext();
716
+ if (readableInstance) feedReadable();
717
+ }
718
+ function end(error) {
719
+ if (done) return;
720
+ done = true;
721
+ endError = error;
722
+ drainNext();
723
+ if (readableInstance) feedReadable();
724
+ }
725
+ function cancel() {
726
+ if (cancelled || done) return;
727
+ cancelled = true;
728
+ options.onCancel?.();
729
+ end(void 0);
730
+ }
731
+ function getReadable() {
732
+ if (readableInstance) return readableInstance;
733
+ readableInstance = new ReadableStream({
734
+ start(controller) {
735
+ pullController = controller;
736
+ feedReadable();
737
+ },
738
+ cancel() {
739
+ cancel();
740
+ }
741
+ });
742
+ return readableInstance;
743
+ }
744
+ return {
745
+ id,
746
+ get cancelled() {
747
+ return cancelled;
748
+ },
749
+ get done() {
750
+ return done;
751
+ },
752
+ get lastSeenSeq() {
753
+ return lastSeenSeq;
754
+ },
755
+ get readable() {
756
+ return getReadable();
757
+ },
758
+ cancel,
759
+ _push: push,
760
+ _end: end,
761
+ [Symbol.asyncIterator]() {
762
+ return {
763
+ next() {
764
+ if (queue.length > 0) return Promise.resolve({
765
+ value: queue.shift(),
766
+ done: false
767
+ });
768
+ if (done) {
769
+ if (endError) {
770
+ const err = new Error(endError.message);
771
+ err.name = endError.name;
772
+ return Promise.reject(err);
773
+ }
774
+ return Promise.resolve({
775
+ value: void 0,
776
+ done: true
777
+ });
778
+ }
779
+ return new Promise((resolve, reject) => {
780
+ pending = {
781
+ resolve,
782
+ reject
783
+ };
784
+ });
785
+ },
786
+ return() {
787
+ cancel();
788
+ return Promise.resolve({
789
+ value: void 0,
790
+ done: true
791
+ });
792
+ }
793
+ };
794
+ }
795
+ };
796
+ }
797
+ function toErrorPayload(reason) {
798
+ if (reason instanceof Error) return {
799
+ name: reason.name || "Error",
800
+ message: reason.message
801
+ };
802
+ if (typeof reason === "string") return {
803
+ name: "Error",
804
+ message: reason
805
+ };
806
+ try {
807
+ return {
808
+ name: "Error",
809
+ message: JSON.stringify(reason)
810
+ };
811
+ } catch {
812
+ return {
813
+ name: "Error",
814
+ message: String(reason)
815
+ };
816
+ }
817
+ }
818
+ //#endregion
579
819
  //#region src/node/rpc-streaming.ts
580
820
  const debug = createDebug("vite:devtools:rpc:streaming");
581
821
  const STREAM_KEY_SEPARATOR = "";
@@ -628,18 +868,18 @@ function createRpcStreamingServerHost(rpc) {
628
868
  handler(channelName, id, opts) {
629
869
  const state = channels.get(channelName);
630
870
  if (!state) {
631
- logger.DF0030({
871
+ diagnostics$1.DF0030.report({
632
872
  channel: channelName,
633
873
  id
634
- }).log();
874
+ }, { method: "error" });
635
875
  return;
636
876
  }
637
877
  const record = state.streams.get(id);
638
878
  if (!record) {
639
- logger.DF0030({
879
+ diagnostics$1.DF0030.report({
640
880
  channel: channelName,
641
881
  id
642
- }).log();
882
+ }, { method: "error" });
643
883
  return;
644
884
  }
645
885
  const session = rpc.getCurrentRpcSession();
@@ -709,10 +949,10 @@ function createRpcStreamingServerHost(rpc) {
709
949
  handler(channelName, id, seq, chunk) {
710
950
  const record = channels.get(channelName)?.inbound.get(id);
711
951
  if (!record) {
712
- logger.DF0030({
952
+ diagnostics$1.DF0030.report({
713
953
  channel: channelName,
714
954
  id
715
- }).log();
955
+ }, { method: "error" });
716
956
  return;
717
957
  }
718
958
  if (!record.uploaderMeta) {
@@ -739,7 +979,7 @@ function createRpcStreamingServerHost(rpc) {
739
979
  }
740
980
  });
741
981
  function createChannel(name, opts = {}) {
742
- if (channels.has(name)) throw logger.DF0032({ channel: name }).throw();
982
+ if (channels.has(name)) throw diagnostics$1.DF0032.throw({ channel: name });
743
983
  const replayWindow = opts.replayWindow ?? 0;
744
984
  const state = {
745
985
  name,
@@ -902,7 +1142,7 @@ var RpcFunctionsHost = class extends RpcFunctionsCollectorBase {
902
1142
  this.streaming._onSessionDisconnected(meta);
903
1143
  }
904
1144
  async invokeLocal(method, ...args) {
905
- if (!this.definitions.has(method)) throw logger.DF0006({ name: String(method) }).throw();
1145
+ if (!this.definitions.has(method)) throw diagnostics$1.DF0006.throw({ name: String(method) });
906
1146
  const handler = await this.getHandler(method);
907
1147
  return await Promise.resolve(handler(...args));
908
1148
  }
@@ -919,7 +1159,7 @@ var RpcFunctionsHost = class extends RpcFunctionsCollectorBase {
919
1159
  }));
920
1160
  }
921
1161
  getCurrentRpcSession() {
922
- if (!this._asyncStorage) throw logger.DF0007().throw();
1162
+ if (!this._asyncStorage) throw diagnostics$1.DF0007.throw();
923
1163
  return this._asyncStorage.getStore();
924
1164
  }
925
1165
  };
@@ -935,7 +1175,7 @@ var DevToolsViewHost = class {
935
1175
  this.context = context;
936
1176
  }
937
1177
  hostStatic(baseUrl, distDir) {
938
- if (!existsSync(distDir)) throw logger.DF0008({ distDir }).throw();
1178
+ if (!existsSync(distDir)) throw diagnostics$1.DF0008.throw({ distDir });
939
1179
  this.buildStaticDirs.push({
940
1180
  baseUrl,
941
1181
  distDir