@yuhere/js-jsonrpc2 2.1.11 → 2.1.13

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 (181) hide show
  1. package/dist/cli/cli.d.ts +0 -1
  2. package/dist/cli/cli.js +0 -1
  3. package/dist/cli/demo-methods.d.ts +0 -1
  4. package/dist/cli/demo-methods.js +0 -1
  5. package/dist/cli/express.d.ts +0 -1
  6. package/dist/cli/express.js +0 -1
  7. package/dist/cli/stdio.d.ts +0 -1
  8. package/dist/cli/stdio.js +0 -1
  9. package/dist/core/Repository.d.ts +0 -1
  10. package/dist/core/Repository.js +0 -1
  11. package/dist/core/convert.d.ts +0 -1
  12. package/dist/core/convert.js +0 -1
  13. package/dist/core/descriptor.d.ts +0 -1
  14. package/dist/core/descriptor.js +0 -1
  15. package/dist/core/index.d.ts +0 -1
  16. package/dist/core/index.js +0 -1
  17. package/dist/core/llm-tools.d.ts +0 -1
  18. package/dist/core/llm-tools.js +89 -3
  19. package/dist/core/permission.d.ts +0 -1
  20. package/dist/core/permission.js +0 -1
  21. package/dist/core/spec-check.d.ts +0 -1
  22. package/dist/core/spec-check.js +0 -1
  23. package/dist/core/system-methods.d.ts +0 -1
  24. package/dist/core/system-methods.js +12 -7
  25. package/dist/errors/RPCError.d.ts +0 -1
  26. package/dist/errors/RPCError.js +0 -1
  27. package/dist/errors/codes.d.ts +0 -1
  28. package/dist/errors/codes.js +0 -1
  29. package/dist/errors/index.d.ts +0 -1
  30. package/dist/errors/index.js +0 -1
  31. package/dist/index.d.ts +0 -1
  32. package/dist/index.js +0 -1
  33. package/dist/metrics/memory.d.ts +0 -1
  34. package/dist/metrics/memory.js +0 -1
  35. package/dist/metrics/prom.d.ts +0 -1
  36. package/dist/metrics/prom.js +0 -1
  37. package/dist/schema/json/index.d.ts +0 -1
  38. package/dist/schema/json/index.js +0 -1
  39. package/dist/schema/json/marker.d.ts +0 -1
  40. package/dist/schema/json/marker.js +0 -1
  41. package/dist/schema/json/primitives.d.ts +0 -1
  42. package/dist/schema/json/primitives.js +0 -1
  43. package/dist/schema/z/protocol.d.ts +0 -1
  44. package/dist/schema/z/protocol.js +0 -1
  45. package/dist/schema/z/register.d.ts +0 -1
  46. package/dist/schema/z/register.js +0 -1
  47. package/dist/stream/stringify-stream.d.ts +0 -1
  48. package/dist/stream/stringify-stream.js +94 -70
  49. package/dist/transport/express/body.d.ts +0 -1
  50. package/dist/transport/express/body.js +0 -1
  51. package/dist/transport/express/index.d.ts +0 -1
  52. package/dist/transport/express/index.js +0 -1
  53. package/dist/transport/express/middleware.d.ts +0 -1
  54. package/dist/transport/express/middleware.js +8 -6
  55. package/dist/transport/express/respond.d.ts +0 -1
  56. package/dist/transport/express/respond.js +0 -1
  57. package/dist/transport/stdio/index.d.ts +0 -1
  58. package/dist/transport/stdio/index.js +0 -1
  59. package/dist/transport/stdio/middleware.d.ts +0 -1
  60. package/dist/transport/stdio/middleware.js +7 -5
  61. package/dist/transport/ws/index.d.ts +0 -1
  62. package/dist/transport/ws/index.js +0 -1
  63. package/dist/transport/ws/middleware.d.ts +0 -1
  64. package/dist/transport/ws/middleware.js +7 -5
  65. package/dist/transport/ws/standalone.d.ts +0 -1
  66. package/dist/transport/ws/standalone.js +0 -1
  67. package/dist/types.d.ts +0 -1
  68. package/dist/types.js +0 -1
  69. package/dist/webclient/webui/src/client/httpTransport.d.ts +8 -0
  70. package/dist/webclient/webui/src/client/httpTransport.js +114 -0
  71. package/dist/webclient/webui/src/client/index.d.ts +4 -0
  72. package/dist/webclient/webui/src/client/index.js +2 -0
  73. package/dist/webclient/webui/src/client/rpc.d.ts +24 -0
  74. package/dist/webclient/webui/src/client/rpc.js +32 -0
  75. package/dist/webclient/webui/src/client/types.d.ts +14 -0
  76. package/dist/webclient/webui/src/client/types.js +1 -0
  77. package/dist/webclient/webui/src/client/wsTransport.d.ts +8 -0
  78. package/{webui/src/api/wsTransport.ts → dist/webclient/webui/src/client/wsTransport.js} +263 -305
  79. package/htdoc/assets/favicon-CXdFuLlv.png +0 -0
  80. package/htdoc/assets/{index-Cr0Jnrgb.js → index-CqI7vRAS.js} +1191 -327
  81. package/htdoc/assets/index-CqI7vRAS.js.map +1 -0
  82. package/htdoc/assets/{index-Ck-39Igh.css → index-Rq1yIwo2.css} +58 -0
  83. package/htdoc/index.html +4 -2
  84. package/package.json +10 -7
  85. package/dist/cli/cli.d.ts.map +0 -1
  86. package/dist/cli/cli.js.map +0 -1
  87. package/dist/cli/demo-methods.d.ts.map +0 -1
  88. package/dist/cli/demo-methods.js.map +0 -1
  89. package/dist/cli/express.d.ts.map +0 -1
  90. package/dist/cli/express.js.map +0 -1
  91. package/dist/cli/stdio.d.ts.map +0 -1
  92. package/dist/cli/stdio.js.map +0 -1
  93. package/dist/core/Repository.d.ts.map +0 -1
  94. package/dist/core/Repository.js.map +0 -1
  95. package/dist/core/convert.d.ts.map +0 -1
  96. package/dist/core/convert.js.map +0 -1
  97. package/dist/core/descriptor.d.ts.map +0 -1
  98. package/dist/core/descriptor.js.map +0 -1
  99. package/dist/core/index.d.ts.map +0 -1
  100. package/dist/core/index.js.map +0 -1
  101. package/dist/core/llm-tools.d.ts.map +0 -1
  102. package/dist/core/llm-tools.js.map +0 -1
  103. package/dist/core/permission.d.ts.map +0 -1
  104. package/dist/core/permission.js.map +0 -1
  105. package/dist/core/spec-check.d.ts.map +0 -1
  106. package/dist/core/spec-check.js.map +0 -1
  107. package/dist/core/system-methods.d.ts.map +0 -1
  108. package/dist/core/system-methods.js.map +0 -1
  109. package/dist/errors/RPCError.d.ts.map +0 -1
  110. package/dist/errors/RPCError.js.map +0 -1
  111. package/dist/errors/codes.d.ts.map +0 -1
  112. package/dist/errors/codes.js.map +0 -1
  113. package/dist/errors/index.d.ts.map +0 -1
  114. package/dist/errors/index.js.map +0 -1
  115. package/dist/index.d.ts.map +0 -1
  116. package/dist/index.js.map +0 -1
  117. package/dist/metrics/memory.d.ts.map +0 -1
  118. package/dist/metrics/memory.js.map +0 -1
  119. package/dist/metrics/prom.d.ts.map +0 -1
  120. package/dist/metrics/prom.js.map +0 -1
  121. package/dist/schema/json/index.d.ts.map +0 -1
  122. package/dist/schema/json/index.js.map +0 -1
  123. package/dist/schema/json/marker.d.ts.map +0 -1
  124. package/dist/schema/json/marker.js.map +0 -1
  125. package/dist/schema/json/primitives.d.ts.map +0 -1
  126. package/dist/schema/json/primitives.js.map +0 -1
  127. package/dist/schema/z/protocol.d.ts.map +0 -1
  128. package/dist/schema/z/protocol.js.map +0 -1
  129. package/dist/schema/z/register.d.ts.map +0 -1
  130. package/dist/schema/z/register.js.map +0 -1
  131. package/dist/stream/stringify-stream.d.ts.map +0 -1
  132. package/dist/stream/stringify-stream.js.map +0 -1
  133. package/dist/transport/express/body.d.ts.map +0 -1
  134. package/dist/transport/express/body.js.map +0 -1
  135. package/dist/transport/express/index.d.ts.map +0 -1
  136. package/dist/transport/express/index.js.map +0 -1
  137. package/dist/transport/express/middleware.d.ts.map +0 -1
  138. package/dist/transport/express/middleware.js.map +0 -1
  139. package/dist/transport/express/respond.d.ts.map +0 -1
  140. package/dist/transport/express/respond.js.map +0 -1
  141. package/dist/transport/stdio/index.d.ts.map +0 -1
  142. package/dist/transport/stdio/index.js.map +0 -1
  143. package/dist/transport/stdio/middleware.d.ts.map +0 -1
  144. package/dist/transport/stdio/middleware.js.map +0 -1
  145. package/dist/transport/ws/index.d.ts.map +0 -1
  146. package/dist/transport/ws/index.js.map +0 -1
  147. package/dist/transport/ws/middleware.d.ts.map +0 -1
  148. package/dist/transport/ws/middleware.js.map +0 -1
  149. package/dist/transport/ws/standalone.d.ts.map +0 -1
  150. package/dist/transport/ws/standalone.js.map +0 -1
  151. package/dist/types.d.ts.map +0 -1
  152. package/dist/types.js.map +0 -1
  153. package/htdoc/assets/index-Cr0Jnrgb.js.map +0 -1
  154. package/webui/index.html +0 -12
  155. package/webui/src/App.tsx +0 -164
  156. package/webui/src/api/docGen.ts +0 -188
  157. package/webui/src/api/glob.ts +0 -90
  158. package/webui/src/api/httpTransport.ts +0 -148
  159. package/webui/src/api/metrics.ts +0 -135
  160. package/webui/src/api/paramForm.ts +0 -80
  161. package/webui/src/api/rpc.ts +0 -57
  162. package/webui/src/api/schema.ts +0 -12
  163. package/webui/src/api/types.ts +0 -16
  164. package/webui/src/components/MethodDetail.tsx +0 -43
  165. package/webui/src/components/MethodTree.tsx +0 -118
  166. package/webui/src/components/MetricsPanel.md +0 -126
  167. package/webui/src/components/MetricsPanel.tsx +0 -290
  168. package/webui/src/components/SchemaForm.tsx +0 -697
  169. package/webui/src/components/SchemaView.tsx +0 -151
  170. package/webui/src/components/TestPanel.tsx +0 -322
  171. package/webui/src/components/Toolbar.tsx +0 -82
  172. package/webui/src/hooks/useMethodDetail.ts +0 -61
  173. package/webui/src/hooks/useMethods.ts +0 -27
  174. package/webui/src/hooks/useMetrics.ts +0 -91
  175. package/webui/src/main.tsx +0 -13
  176. package/webui/src/styles/geek.css +0 -963
  177. package/webui/src/theme/ThemeProvider.tsx +0 -79
  178. package/webui/src/vite-env.d.ts +0 -1
  179. package/webui/tsconfig.json +0 -34
  180. package/webui/tsconfig.node.json +0 -13
  181. package/webui/vite.config.ts +0 -15
@@ -1,290 +0,0 @@
1
- import { useMemo } from 'react';
2
- import {
3
- deriveMethod,
4
- type MethodDerived,
5
- type MetricsSnapshot,
6
- } from '../api/metrics';
7
-
8
- interface MetricsPanelProps {
9
- snapshot: MetricsSnapshot | undefined;
10
- previous: { snapshot: MetricsSnapshot; fetchedAt: number } | undefined;
11
- fetchedAt: number | undefined;
12
- loading: boolean;
13
- error: string | null;
14
- available: boolean;
15
- onRefresh: () => void;
16
- autoRefresh: boolean;
17
- onAutoRefreshChange: (v: boolean) => void;
18
- intervalMs: number;
19
- onIntervalChange: (v: number) => void;
20
- }
21
-
22
- function formatDuration(seconds: number): string {
23
- if (!Number.isFinite(seconds) || seconds <= 0) return '—';
24
- if (seconds < 0.001) return `${(seconds * 1e6).toFixed(0)} µs`;
25
- if (seconds < 1) return `${(seconds * 1000).toFixed(1)} ms`;
26
- if (seconds < 60) return `${seconds.toFixed(2)} s`;
27
- return `${(seconds / 60).toFixed(1)} min`;
28
- }
29
-
30
- function formatRate(v: number | undefined): string {
31
- if (v === undefined) return '—';
32
- if (v >= 100) return v.toFixed(0);
33
- if (v >= 10) return v.toFixed(1);
34
- return v.toFixed(2);
35
- }
36
-
37
- function formatPercent(v: number): string {
38
- if (!Number.isFinite(v)) return '—';
39
- return `${(v * 100).toFixed(1)}%`;
40
- }
41
-
42
- function rateClass(v: number | undefined): string {
43
- if (v === undefined) return '';
44
- if (v > 100) return 'rate-hot';
45
- if (v > 10) return 'rate-warm';
46
- return 'rate-cold';
47
- }
48
-
49
- export function MetricsPanel({
50
- snapshot,
51
- previous,
52
- fetchedAt,
53
- loading,
54
- error,
55
- available,
56
- onRefresh,
57
- autoRefresh,
58
- onAutoRefreshChange,
59
- intervalMs,
60
- onIntervalChange,
61
- }: MetricsPanelProps) {
62
- const derived = useMemo<MethodDerived[]>(() => {
63
- if (!snapshot) return [];
64
- const dtSeconds =
65
- previous && fetchedAt
66
- ? (fetchedAt - previous.fetchedAt) / 1000
67
- : undefined;
68
- const rows: MethodDerived[] = [];
69
- for (const [method, stats] of Object.entries(snapshot.methods)) {
70
- const prev = previous?.snapshot.methods[method];
71
- rows.push(deriveMethod(method, stats, prev, dtSeconds));
72
- }
73
- rows.sort((a, b) => b.stats.calls - a.stats.calls);
74
- return rows;
75
- }, [snapshot, previous, fetchedAt]);
76
-
77
- // 只按「是否产生过流式调用」分组;一旦 opened>0 即视为 stream method。
78
- const streamMethods = derived.filter((r) => r.stats.streams.opened > 0);
79
- const nonStreamMethods = derived.filter((r) => r.stats.streams.opened === 0);
80
-
81
- const totals = useMemo(() => {
82
- if (!snapshot) return { calls: 0, errors: 0, methods: 0, streams: 0 };
83
- let calls = 0;
84
- let errors = 0;
85
- let streams = 0;
86
- for (const s of Object.values(snapshot.methods)) {
87
- calls += s.calls;
88
- errors += Object.values(s.errorsByCode).reduce((a, b) => a + b, 0);
89
- streams += s.streams.opened;
90
- }
91
- return { calls, errors, methods: Object.keys(snapshot.methods).length, streams };
92
- }, [snapshot]);
93
-
94
- if (!available) {
95
- return (
96
- <section className="metrics">
97
- <h2>Metrics</h2>
98
- <p className="hint">
99
- 服务端未启用 <code>system.metrics</code>(<code>withSystemMethods: false</code> 或未注册)。
100
- </p>
101
- </section>
102
- );
103
- }
104
-
105
- return (
106
- <section className="metrics">
107
- <header className="metrics-header">
108
- <h2>Metrics</h2>
109
- <div className="metrics-controls">
110
- <label className="metrics-auto">
111
- <input
112
- type="checkbox"
113
- checked={autoRefresh}
114
- onChange={(e) => onAutoRefreshChange(e.target.checked)}
115
- />
116
- 自动刷新
117
- </label>
118
- <select
119
- className="sf-input"
120
- value={intervalMs}
121
- onChange={(e) => onIntervalChange(Number(e.target.value))}
122
- disabled={!autoRefresh}
123
- title="刷新间隔"
124
- >
125
- <option value={1000}>1s</option>
126
- <option value={3000}>3s</option>
127
- <option value={5000}>5s</option>
128
- <option value={10000}>10s</option>
129
- </select>
130
- <button onClick={onRefresh} disabled={loading}>
131
- {loading ? '刷新中…' : '立即刷新'}
132
- </button>
133
- {snapshot && (
134
- <span className="hint">
135
- uptime {formatDuration(snapshot.uptimeMs / 1000)}
136
- </span>
137
- )}
138
- </div>
139
- </header>
140
-
141
- {error && <p className="error">{error}</p>}
142
- {!snapshot && !error && <p className="hint">加载中…</p>}
143
-
144
- {snapshot && (
145
- <>
146
- <div className="metrics-cards">
147
- <MetricCard label="Methods" value={String(totals.methods)} />
148
- <MetricCard label="Calls" value={String(totals.calls)} />
149
- <MetricCard label="Streams" value={String(totals.streams)} />
150
- <MetricCard
151
- label="Errors"
152
- value={String(totals.errors)}
153
- tone={totals.errors > 0 ? 'danger' : undefined}
154
- />
155
- <MetricCard
156
- label="Error rate"
157
- value={totals.calls > 0 ? formatPercent(totals.errors / totals.calls) : '—'}
158
- tone={totals.calls > 0 && totals.errors / totals.calls > 0.05 ? 'danger' : undefined}
159
- />
160
- <MetricCard
161
- label="Invalid requests"
162
- value={String(snapshot.invalidRequests)}
163
- tone={snapshot.invalidRequests > 0 ? 'warn' : undefined}
164
- />
165
- </div>
166
-
167
- <h3>
168
- Non-stream methods
169
- <span className="hint"> ({nonStreamMethods.length})</span>
170
- </h3>
171
- {nonStreamMethods.length === 0 ? (
172
- <p className="hint">暂无数据。</p>
173
- ) : (
174
- <NonStreamTable rows={nonStreamMethods} />
175
- )}
176
-
177
- <h3>
178
- Stream methods
179
- <span className="hint"> ({streamMethods.length})</span>
180
- </h3>
181
- {streamMethods.length === 0 ? (
182
- <p className="hint">暂无流式调用。</p>
183
- ) : (
184
- <StreamTable rows={streamMethods} />
185
- )}
186
- </>
187
- )}
188
- </section>
189
- );
190
- }
191
-
192
- function MetricCard({ label, value, tone }: { label: string; value: string; tone?: 'danger' | 'warn' }) {
193
- return (
194
- <div className={`metric-card${tone ? ` metric-card-${tone}` : ''}`}>
195
- <div className="metric-card-label">{label}</div>
196
- <div className="metric-card-value">{value}</div>
197
- </div>
198
- );
199
- }
200
-
201
- function NonStreamTable({ rows }: { rows: MethodDerived[] }) {
202
- return (
203
- <table className="metrics-table">
204
- <thead>
205
- <tr>
206
- <th>method</th>
207
- <th className="num">calls</th>
208
- <th className="num">rate/s</th>
209
- <th className="num">errors</th>
210
- <th className="num">err%</th>
211
- <th className="num">p50</th>
212
- <th className="num">p95</th>
213
- <th className="num">p99</th>
214
- <th className="num">avg</th>
215
- </tr>
216
- </thead>
217
- <tbody>
218
- {rows.map((r) => {
219
- const errorCount = Object.values(r.stats.errorsByCode).reduce((a, b) => a + b, 0);
220
- const avg =
221
- r.stats.duration.count > 0
222
- ? r.stats.duration.sum / r.stats.duration.count
223
- : 0;
224
- return (
225
- <tr key={r.method}>
226
- <td className="method-name" title={r.method}>{r.method}</td>
227
- <td className="num">{r.stats.calls}</td>
228
- <td className={`num ${rateClass(r.callsPerSecond)}`}>{formatRate(r.callsPerSecond)}</td>
229
- <td className={`num${errorCount > 0 ? ' error' : ''}`}>{errorCount}</td>
230
- <td className={`num${r.errorRate > 0.05 ? ' error' : ''}`}>{formatPercent(r.errorRate)}</td>
231
- <td className="num">{formatDuration(r.p50)}</td>
232
- <td className="num">{formatDuration(r.p95)}</td>
233
- <td className="num">{formatDuration(r.p99)}</td>
234
- <td className="num">{formatDuration(avg)}</td>
235
- </tr>
236
- );
237
- })}
238
- </tbody>
239
- </table>
240
- );
241
- }
242
-
243
- function StreamTable({ rows }: { rows: MethodDerived[] }) {
244
- return (
245
- <table className="metrics-table">
246
- <thead>
247
- <tr>
248
- <th>method</th>
249
- <th className="num">opened</th>
250
- <th className="num">completed</th>
251
- <th className="num">failed</th>
252
- <th className="num">aborted</th>
253
- <th className="num">complete%</th>
254
- <th className="num">abort%</th>
255
- <th className="num">avg chunks</th>
256
- <th className="num">ttfb p50</th>
257
- <th className="num">ttfb p95</th>
258
- <th className="num">duration avg</th>
259
- </tr>
260
- </thead>
261
- <tbody>
262
- {rows.map((r) => (
263
- <tr key={r.method}>
264
- <td className="method-name" title={r.method}>{r.method}</td>
265
- <td className="num">{r.stats.streams.opened}</td>
266
- <td className="num">{r.stats.streams.completed}</td>
267
- <td className={`num${r.stats.streams.failed > 0 ? ' error' : ''}`}>
268
- {r.stats.streams.failed}
269
- </td>
270
- <td className={`num${r.stats.streams.aborted > 0 ? ' warn' : ''}`}>
271
- {r.stats.streams.aborted}
272
- </td>
273
- <td className="num">{formatPercent(r.streamCompletionRate)}</td>
274
- <td className="num">{formatPercent(r.streamAbortRate)}</td>
275
- <td className="num">{r.avgChunksPerStream.toFixed(1)}</td>
276
- <td className="num">{formatDuration(r.ttfbP50)}</td>
277
- <td className="num">{formatDuration(r.ttfbP95)}</td>
278
- <td className="num">
279
- {formatDuration(
280
- r.stats.streamDuration.count > 0
281
- ? r.stats.streamDuration.sum / r.stats.streamDuration.count
282
- : 0,
283
- )}
284
- </td>
285
- </tr>
286
- ))}
287
- </tbody>
288
- </table>
289
- );
290
- }