@vscode/component-explorer-cli 0.1.1-1 → 0.1.1-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/mcpCommand.d.ts +8 -0
- package/dist/commands/mcpCommand.d.ts.map +1 -0
- package/dist/commands/mcpCommand.js +24 -0
- package/dist/commands/mcpCommand.js.map +1 -0
- package/dist/commands/screenshotCommand.js +1 -1
- package/dist/commands/screenshotCommand.js.map +1 -1
- package/dist/commands/serveCommand.d.ts +16 -0
- package/dist/commands/serveCommand.d.ts.map +1 -0
- package/dist/commands/serveCommand.js +137 -0
- package/dist/commands/serveCommand.js.map +1 -0
- package/dist/commands/watchCommand.d.ts.map +1 -1
- package/dist/commands/watchCommand.js +6 -3
- package/dist/commands/watchCommand.js.map +1 -1
- package/dist/componentExplorer.d.ts +1 -0
- package/dist/componentExplorer.d.ts.map +1 -1
- package/dist/componentExplorer.js +17 -6
- package/dist/componentExplorer.js.map +1 -1
- package/dist/daemon/DaemonService.d.ts +132 -0
- package/dist/daemon/DaemonService.d.ts.map +1 -0
- package/dist/daemon/DaemonService.js +457 -0
- package/dist/daemon/DaemonService.js.map +1 -0
- package/dist/daemon/approvalStore.d.ts +51 -0
- package/dist/daemon/approvalStore.d.ts.map +1 -0
- package/dist/daemon/approvalStore.js +58 -0
- package/dist/daemon/approvalStore.js.map +1 -0
- package/dist/daemon/lifecycle.d.ts +8 -0
- package/dist/daemon/lifecycle.d.ts.map +1 -0
- package/dist/daemon/lifecycle.js +51 -0
- package/dist/daemon/lifecycle.js.map +1 -0
- package/dist/daemon/pipeClient.d.ts +4 -0
- package/dist/daemon/pipeClient.d.ts.map +1 -0
- package/dist/daemon/pipeClient.js +98 -0
- package/dist/daemon/pipeClient.js.map +1 -0
- package/dist/daemon/pipeName.d.ts +2 -0
- package/dist/daemon/pipeName.d.ts.map +1 -0
- package/dist/daemon/pipeName.js +14 -0
- package/dist/daemon/pipeName.js.map +1 -0
- package/dist/daemon/pipeServer.d.ts +4 -0
- package/dist/daemon/pipeServer.d.ts.map +1 -0
- package/dist/daemon/pipeServer.js +23 -0
- package/dist/daemon/pipeServer.js.map +1 -0
- package/dist/daemon/types.d.ts +12 -0
- package/dist/daemon/types.d.ts.map +1 -0
- package/dist/explorerSession.d.ts +5 -3
- package/dist/explorerSession.d.ts.map +1 -1
- package/dist/explorerSession.js +6 -3
- package/dist/explorerSession.js.map +1 -1
- package/dist/external/vscode-observables/observables/dist/observableInternal/debugLocation.js +3 -0
- package/dist/external/vscode-observables/observables/dist/observableInternal/debugLocation.js.map +1 -1
- package/dist/httpServer.d.ts +8 -7
- package/dist/httpServer.d.ts.map +1 -1
- package/dist/httpServer.js +44 -4
- package/dist/httpServer.js.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/McpServer.d.ts +28 -0
- package/dist/mcp/McpServer.d.ts.map +1 -0
- package/dist/mcp/McpServer.js +386 -0
- package/dist/mcp/McpServer.js.map +1 -0
- package/dist/packages/simple-api/dist/chunk-3R7GHWBM.js +137 -0
- package/dist/packages/simple-api/dist/chunk-3R7GHWBM.js.map +1 -0
- package/dist/packages/simple-api/dist/chunk-A5PE72HI.js +21 -0
- package/dist/packages/simple-api/dist/chunk-A5PE72HI.js.map +1 -0
- package/dist/packages/simple-api/dist/chunk-SGBCNXYH.js +24 -0
- package/dist/packages/simple-api/dist/chunk-SGBCNXYH.js.map +1 -0
- package/dist/packages/simple-api/dist/express.js +96 -0
- package/dist/packages/simple-api/dist/express.js.map +1 -0
- package/dist/watchConfig.d.ts +5 -0
- package/dist/watchConfig.d.ts.map +1 -1
- package/dist/watchConfig.js +14 -2
- package/dist/watchConfig.js.map +1 -1
- package/package.json +11 -3
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Client-local state
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
class WatchList {
|
|
9
|
+
_fixtureIds = new Set();
|
|
10
|
+
_hashes = new Map();
|
|
11
|
+
get fixtureIds() { return this._fixtureIds; }
|
|
12
|
+
add(ids) {
|
|
13
|
+
for (const id of ids) {
|
|
14
|
+
this._fixtureIds.add(id);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
remove(ids) {
|
|
18
|
+
for (const id of ids) {
|
|
19
|
+
this._fixtureIds.delete(id);
|
|
20
|
+
this._hashes.delete(id);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
set(ids) {
|
|
24
|
+
this._fixtureIds.clear();
|
|
25
|
+
this._hashes.clear();
|
|
26
|
+
for (const id of ids) {
|
|
27
|
+
this._fixtureIds.add(id);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
getHash(fixtureId) {
|
|
31
|
+
return this._hashes.get(fixtureId);
|
|
32
|
+
}
|
|
33
|
+
setHash(fixtureId, hash) {
|
|
34
|
+
this._hashes.set(fixtureId, hash);
|
|
35
|
+
}
|
|
36
|
+
toJSON() {
|
|
37
|
+
return {
|
|
38
|
+
fixtureIds: [...this._fixtureIds],
|
|
39
|
+
hashes: Object.fromEntries(this._hashes),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// ComponentExplorerMcpServer
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
class ComponentExplorerMcpServer {
|
|
47
|
+
_daemon;
|
|
48
|
+
_mcp;
|
|
49
|
+
_watchList = new WatchList();
|
|
50
|
+
_sessions = [];
|
|
51
|
+
constructor(_daemon) {
|
|
52
|
+
this._daemon = _daemon;
|
|
53
|
+
this._mcp = new McpServer({
|
|
54
|
+
name: 'component-explorer',
|
|
55
|
+
version: '0.1.0',
|
|
56
|
+
});
|
|
57
|
+
this._registerTools();
|
|
58
|
+
}
|
|
59
|
+
async connect() {
|
|
60
|
+
this._sessions = await this._daemon.methods.sessions();
|
|
61
|
+
const transport = new StdioServerTransport();
|
|
62
|
+
await this._mcp.connect(transport);
|
|
63
|
+
}
|
|
64
|
+
// -- Helpers --------------------------------------------------------------
|
|
65
|
+
_defaultSessionName() {
|
|
66
|
+
return this._sessions[0]?.name ?? 'current';
|
|
67
|
+
}
|
|
68
|
+
_defaultBaselineSessionName() {
|
|
69
|
+
const worktree = this._sessions.find(s => s.sourceKind === 'worktree');
|
|
70
|
+
return worktree?.name ?? this._sessions[1]?.name ?? this._defaultSessionName();
|
|
71
|
+
}
|
|
72
|
+
_defaultCurrentSessionName() {
|
|
73
|
+
const current = this._sessions.find(s => s.sourceKind === 'current');
|
|
74
|
+
return current?.name ?? this._defaultSessionName();
|
|
75
|
+
}
|
|
76
|
+
_sourceTreeId(sessionName) {
|
|
77
|
+
const s = this._sessions.find(s => s.name === sessionName);
|
|
78
|
+
return s?.sourceTreeId ?? '';
|
|
79
|
+
}
|
|
80
|
+
_updateSessionSourceTreeId(sessionName, sourceTreeId) {
|
|
81
|
+
const s = this._sessions.find(s => s.name === sessionName);
|
|
82
|
+
if (s) {
|
|
83
|
+
s.sourceTreeId = sourceTreeId;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async _refreshSessions() {
|
|
87
|
+
this._sessions = await this._daemon.methods.sessions();
|
|
88
|
+
}
|
|
89
|
+
// -- Tool registration ---------------------------------------------------
|
|
90
|
+
_registerTools() {
|
|
91
|
+
this._registerListFixtures();
|
|
92
|
+
this._registerScreenshot();
|
|
93
|
+
this._registerCompareScreenshot();
|
|
94
|
+
this._registerApproveDiff();
|
|
95
|
+
this._registerWatchAdd();
|
|
96
|
+
this._registerWatchRemove();
|
|
97
|
+
this._registerWatchSet();
|
|
98
|
+
this._registerWatchCompare();
|
|
99
|
+
this._registerWaitForUpdate();
|
|
100
|
+
this._registerSessions();
|
|
101
|
+
}
|
|
102
|
+
_registerListFixtures() {
|
|
103
|
+
this._mcp.registerTool('list_fixtures', {
|
|
104
|
+
description: 'List all fixtures from a session',
|
|
105
|
+
inputSchema: {
|
|
106
|
+
sessionName: z.string().optional().describe('Session name (defaults to first session)'),
|
|
107
|
+
sourceTreeId: z.string().optional().describe('Source tree ID (defaults to latest known)'),
|
|
108
|
+
},
|
|
109
|
+
}, async (args) => {
|
|
110
|
+
const sessionName = args.sessionName ?? this._defaultSessionName();
|
|
111
|
+
const sourceTreeId = args.sourceTreeId ?? this._sourceTreeId(sessionName);
|
|
112
|
+
const fixtures = await this._daemon.methods.fixtures.list({ sessionName, sourceTreeId });
|
|
113
|
+
return {
|
|
114
|
+
content: [{ type: 'text', text: JSON.stringify(fixtures, null, 2) }],
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
_registerScreenshot() {
|
|
119
|
+
this._mcp.registerTool('screenshot', {
|
|
120
|
+
description: 'Take a screenshot of a single fixture',
|
|
121
|
+
inputSchema: {
|
|
122
|
+
fixtureId: z.string().describe('The fixture ID'),
|
|
123
|
+
sessionName: z.string().optional().describe('Session name (defaults to first session)'),
|
|
124
|
+
sourceTreeId: z.string().optional().describe('Source tree ID (defaults to latest known)'),
|
|
125
|
+
},
|
|
126
|
+
}, async (args) => {
|
|
127
|
+
const sessionName = args.sessionName ?? this._defaultSessionName();
|
|
128
|
+
const sourceTreeId = args.sourceTreeId ?? this._sourceTreeId(sessionName);
|
|
129
|
+
const result = await this._daemon.methods.screenshots.take({
|
|
130
|
+
fixtureId: args.fixtureId,
|
|
131
|
+
sessionName,
|
|
132
|
+
sourceTreeId,
|
|
133
|
+
includeImage: true,
|
|
134
|
+
});
|
|
135
|
+
const r = result;
|
|
136
|
+
this._updateSessionSourceTreeId(sessionName, r.sourceTreeId);
|
|
137
|
+
const content = [
|
|
138
|
+
{ type: 'text', text: `hash: ${r.hash}\nsourceTreeId: ${r.sourceTreeId}` },
|
|
139
|
+
];
|
|
140
|
+
if (r.image) {
|
|
141
|
+
content.push({ type: 'image', data: r.image, mimeType: 'image/png' });
|
|
142
|
+
}
|
|
143
|
+
return { content };
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
_registerCompareScreenshot() {
|
|
147
|
+
this._mcp.registerTool('compare_screenshot', {
|
|
148
|
+
description: 'Compare a fixture\'s screenshot across two sessions (e.g. baseline vs current)',
|
|
149
|
+
inputSchema: {
|
|
150
|
+
fixtureId: z.string().describe('The fixture ID'),
|
|
151
|
+
baselineSessionName: z.string().optional().describe('Baseline session name (defaults to worktree session)'),
|
|
152
|
+
currentSessionName: z.string().optional().describe('Current session name (defaults to current session)'),
|
|
153
|
+
baselineSourceTreeId: z.string().optional().describe('Baseline source tree ID (defaults to latest known)'),
|
|
154
|
+
currentSourceTreeId: z.string().optional().describe('Current source tree ID (defaults to latest known)'),
|
|
155
|
+
},
|
|
156
|
+
}, async (args) => {
|
|
157
|
+
const baselineSessionName = args.baselineSessionName ?? this._defaultBaselineSessionName();
|
|
158
|
+
const currentSessionName = args.currentSessionName ?? this._defaultCurrentSessionName();
|
|
159
|
+
const baselineSourceTreeId = args.baselineSourceTreeId ?? this._sourceTreeId(baselineSessionName);
|
|
160
|
+
const currentSourceTreeId = args.currentSourceTreeId ?? this._sourceTreeId(currentSessionName);
|
|
161
|
+
const result = await this._daemon.methods.screenshots.compare({
|
|
162
|
+
fixtureId: args.fixtureId,
|
|
163
|
+
baselineSessionName,
|
|
164
|
+
baselineSourceTreeId,
|
|
165
|
+
currentSessionName,
|
|
166
|
+
currentSourceTreeId,
|
|
167
|
+
includeImages: true,
|
|
168
|
+
});
|
|
169
|
+
const r = result;
|
|
170
|
+
const info = {
|
|
171
|
+
match: r.match,
|
|
172
|
+
baselineHash: r.baselineHash,
|
|
173
|
+
currentHash: r.currentHash,
|
|
174
|
+
};
|
|
175
|
+
if (r.approval) {
|
|
176
|
+
info.approval = r.approval;
|
|
177
|
+
}
|
|
178
|
+
const content = [
|
|
179
|
+
{ type: 'text', text: JSON.stringify(info, null, 2) },
|
|
180
|
+
];
|
|
181
|
+
if (r.baselineImage) {
|
|
182
|
+
content.push({ type: 'image', data: r.baselineImage, mimeType: 'image/png' });
|
|
183
|
+
}
|
|
184
|
+
if (r.currentImage) {
|
|
185
|
+
content.push({ type: 'image', data: r.currentImage, mimeType: 'image/png' });
|
|
186
|
+
}
|
|
187
|
+
return { content };
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
_registerApproveDiff() {
|
|
191
|
+
this._mcp.registerTool('approve_diff', {
|
|
192
|
+
description: 'Approve a visual diff so it won\'t require re-inspection next time',
|
|
193
|
+
inputSchema: {
|
|
194
|
+
fixtureId: z.string(),
|
|
195
|
+
originalHash: z.string(),
|
|
196
|
+
modifiedHash: z.string(),
|
|
197
|
+
comment: z.string().describe('Reason for approving this diff'),
|
|
198
|
+
},
|
|
199
|
+
}, async (args) => {
|
|
200
|
+
await this._daemon.methods.approvals.approve(args);
|
|
201
|
+
return {
|
|
202
|
+
content: [{
|
|
203
|
+
type: 'text',
|
|
204
|
+
text: `Approved diff for ${args.fixtureId}: ${args.originalHash} → ${args.modifiedHash}`,
|
|
205
|
+
}],
|
|
206
|
+
};
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
_registerWatchAdd() {
|
|
210
|
+
this._mcp.registerTool('watch_add', {
|
|
211
|
+
description: 'Add fixtures to the watch list. Watched fixtures are automatically re-screenshotted when source changes.',
|
|
212
|
+
inputSchema: {
|
|
213
|
+
fixtureIds: z.array(z.string()).describe('Fixture IDs to add'),
|
|
214
|
+
},
|
|
215
|
+
}, async (args) => {
|
|
216
|
+
this._watchList.add(args.fixtureIds);
|
|
217
|
+
return {
|
|
218
|
+
content: [{
|
|
219
|
+
type: 'text',
|
|
220
|
+
text: `Watch list: ${[...this._watchList.fixtureIds].join(', ') || '(empty)'}`,
|
|
221
|
+
}],
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
_registerWatchRemove() {
|
|
226
|
+
this._mcp.registerTool('watch_remove', {
|
|
227
|
+
description: 'Remove fixtures from the watch list',
|
|
228
|
+
inputSchema: {
|
|
229
|
+
fixtureIds: z.array(z.string()).describe('Fixture IDs to remove'),
|
|
230
|
+
},
|
|
231
|
+
}, async (args) => {
|
|
232
|
+
this._watchList.remove(args.fixtureIds);
|
|
233
|
+
return {
|
|
234
|
+
content: [{
|
|
235
|
+
type: 'text',
|
|
236
|
+
text: `Watch list: ${[...this._watchList.fixtureIds].join(', ') || '(empty)'}`,
|
|
237
|
+
}],
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
_registerWatchSet() {
|
|
242
|
+
this._mcp.registerTool('watch_set', {
|
|
243
|
+
description: 'Replace the watch list entirely',
|
|
244
|
+
inputSchema: {
|
|
245
|
+
fixtureIds: z.array(z.string()).describe('Fixture IDs to watch'),
|
|
246
|
+
},
|
|
247
|
+
}, async (args) => {
|
|
248
|
+
this._watchList.set(args.fixtureIds);
|
|
249
|
+
return {
|
|
250
|
+
content: [{
|
|
251
|
+
type: 'text',
|
|
252
|
+
text: `Watch list: ${[...this._watchList.fixtureIds].join(', ') || '(empty)'}`,
|
|
253
|
+
}],
|
|
254
|
+
};
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
_registerWatchCompare() {
|
|
258
|
+
this._mcp.registerTool('watch_compare', {
|
|
259
|
+
description: 'Compare all watched fixtures across two sessions. Takes fresh screenshots from both sessions and reports which fixtures differ.',
|
|
260
|
+
inputSchema: {
|
|
261
|
+
baselineSessionName: z.string().optional().describe('Baseline session name (defaults to worktree session)'),
|
|
262
|
+
currentSessionName: z.string().optional().describe('Current session name (defaults to current session)'),
|
|
263
|
+
baselineSourceTreeId: z.string().optional().describe('Baseline source tree ID (defaults to latest known)'),
|
|
264
|
+
currentSourceTreeId: z.string().optional().describe('Current source tree ID (defaults to latest known)'),
|
|
265
|
+
},
|
|
266
|
+
}, async (args) => {
|
|
267
|
+
const ids = [...this._watchList.fixtureIds];
|
|
268
|
+
if (ids.length === 0) {
|
|
269
|
+
return { content: [{ type: 'text', text: 'Watch list is empty. Use watch_add or watch_set first.' }] };
|
|
270
|
+
}
|
|
271
|
+
const baselineSessionName = args.baselineSessionName ?? this._defaultBaselineSessionName();
|
|
272
|
+
const currentSessionName = args.currentSessionName ?? this._defaultCurrentSessionName();
|
|
273
|
+
const baselineSourceTreeId = args.baselineSourceTreeId ?? this._sourceTreeId(baselineSessionName);
|
|
274
|
+
const currentSourceTreeId = args.currentSourceTreeId ?? this._sourceTreeId(currentSessionName);
|
|
275
|
+
const [baselineResult, currentResult] = await Promise.all([
|
|
276
|
+
this._daemon.methods.screenshots.takeBatch({
|
|
277
|
+
fixtureIds: ids,
|
|
278
|
+
sessionName: baselineSessionName,
|
|
279
|
+
sourceTreeId: baselineSourceTreeId,
|
|
280
|
+
}),
|
|
281
|
+
this._daemon.methods.screenshots.takeBatch({
|
|
282
|
+
fixtureIds: ids,
|
|
283
|
+
sessionName: currentSessionName,
|
|
284
|
+
sourceTreeId: currentSourceTreeId,
|
|
285
|
+
}),
|
|
286
|
+
]);
|
|
287
|
+
const br = baselineResult;
|
|
288
|
+
const cr = currentResult;
|
|
289
|
+
const baselineMap = new Map(br.screenshots.map(s => [s.fixtureId, s.hash]));
|
|
290
|
+
const currentMap = new Map(cr.screenshots.map(s => [s.fixtureId, s.hash]));
|
|
291
|
+
const entries = ids.map(id => {
|
|
292
|
+
const bHash = baselineMap.get(id) ?? '';
|
|
293
|
+
const cHash = currentMap.get(id) ?? '';
|
|
294
|
+
return {
|
|
295
|
+
fixtureId: id,
|
|
296
|
+
match: bHash === cHash,
|
|
297
|
+
baselineHash: bHash,
|
|
298
|
+
currentHash: cHash,
|
|
299
|
+
};
|
|
300
|
+
});
|
|
301
|
+
// Look up approvals for changed fixtures
|
|
302
|
+
const results = [];
|
|
303
|
+
for (const entry of entries) {
|
|
304
|
+
let approval = undefined;
|
|
305
|
+
if (!entry.match && entry.baselineHash && entry.currentHash) {
|
|
306
|
+
approval = await this._daemon.methods.approvals.lookup({
|
|
307
|
+
fixtureId: entry.fixtureId,
|
|
308
|
+
originalHash: entry.baselineHash,
|
|
309
|
+
modifiedHash: entry.currentHash,
|
|
310
|
+
}) ?? undefined;
|
|
311
|
+
}
|
|
312
|
+
results.push({ ...entry, approval });
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
content: [{ type: 'text', text: JSON.stringify(results, null, 2) }],
|
|
316
|
+
};
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
_registerWaitForUpdate() {
|
|
320
|
+
this._mcp.registerTool('wait_for_update', {
|
|
321
|
+
description: 'Block until the next source change or ref change event. If fixtures are on the watch list, automatically re-screenshots them and reports which changed.',
|
|
322
|
+
}, async () => {
|
|
323
|
+
const events = await this._daemon.methods.events();
|
|
324
|
+
const iterator = events[Symbol.asyncIterator]();
|
|
325
|
+
const { value: event, done } = await iterator.next();
|
|
326
|
+
// Close the stream after consuming one event
|
|
327
|
+
await iterator.return?.();
|
|
328
|
+
if (done || !event) {
|
|
329
|
+
return { content: [{ type: 'text', text: 'Event stream ended.' }] };
|
|
330
|
+
}
|
|
331
|
+
const ev = event;
|
|
332
|
+
// Update cached session info
|
|
333
|
+
if (ev.type === 'source-change' && ev.sourceTreeId) {
|
|
334
|
+
this._updateSessionSourceTreeId(ev.sessionName, ev.sourceTreeId);
|
|
335
|
+
}
|
|
336
|
+
if (ev.type === 'ref-change') {
|
|
337
|
+
await this._refreshSessions();
|
|
338
|
+
}
|
|
339
|
+
// If there are watched fixtures and this is a source-change, re-screenshot them
|
|
340
|
+
const watchedIds = [...this._watchList.fixtureIds];
|
|
341
|
+
if (ev.type === 'source-change' && watchedIds.length > 0 && ev.sourceTreeId) {
|
|
342
|
+
const batchResult = await this._daemon.methods.screenshots.takeBatch({
|
|
343
|
+
fixtureIds: watchedIds,
|
|
344
|
+
sessionName: ev.sessionName,
|
|
345
|
+
sourceTreeId: ev.sourceTreeId,
|
|
346
|
+
});
|
|
347
|
+
const br = batchResult;
|
|
348
|
+
const changes = [];
|
|
349
|
+
for (const s of br.screenshots) {
|
|
350
|
+
const prevHash = this._watchList.getHash(s.fixtureId);
|
|
351
|
+
const changed = prevHash !== undefined && prevHash !== s.hash;
|
|
352
|
+
this._watchList.setHash(s.fixtureId, s.hash);
|
|
353
|
+
if (changed) {
|
|
354
|
+
changes.push({ fixtureId: s.fixtureId, previousHash: prevHash, hash: s.hash });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
content: [{
|
|
359
|
+
type: 'text',
|
|
360
|
+
text: JSON.stringify({
|
|
361
|
+
event: ev,
|
|
362
|
+
watchedFixtures: br.screenshots.length,
|
|
363
|
+
changed: changes,
|
|
364
|
+
}, null, 2),
|
|
365
|
+
}],
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
content: [{ type: 'text', text: JSON.stringify(ev, null, 2) }],
|
|
370
|
+
};
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
_registerSessions() {
|
|
374
|
+
this._mcp.registerTool('sessions', {
|
|
375
|
+
description: 'List active sessions with their names, URLs, and current sourceTreeIds',
|
|
376
|
+
}, async () => {
|
|
377
|
+
await this._refreshSessions();
|
|
378
|
+
return {
|
|
379
|
+
content: [{ type: 'text', text: JSON.stringify(this._sessions, null, 2) }],
|
|
380
|
+
};
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export { ComponentExplorerMcpServer };
|
|
386
|
+
//# sourceMappingURL=McpServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"McpServer.js","sources":["../../src/mcp/McpServer.ts"],"sourcesContent":[null],"names":["SdkMcpServer"],"mappings":";;;;AAMA;AACA;AACA;AAEA,MAAM,SAAS,CAAA;AAC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AA,MAAM,IAAI,CAAC,gBAAgB,EAAE;YAC7B,OAAO;gBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;aACnF;AACF,QAAA,CAAC,CAAC;IACH;AACA;;;;"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/server.ts
|
|
4
|
+
function createApiFactory() {
|
|
5
|
+
const factoryToken = /* @__PURE__ */ Symbol("apiFactory");
|
|
6
|
+
return createFactoryImpl(factoryToken, void 0);
|
|
7
|
+
}
|
|
8
|
+
function createFactoryImpl(factoryToken, middleware) {
|
|
9
|
+
const factory = {
|
|
10
|
+
_factoryToken: factoryToken,
|
|
11
|
+
_middleware: middleware,
|
|
12
|
+
withMiddleware(mwOrFn) {
|
|
13
|
+
const mw = typeof mwOrFn === "function" ? { _dependencies: void 0, _provides: void 0, run: mwOrFn } : mwOrFn;
|
|
14
|
+
const composed = middleware ? {
|
|
15
|
+
_dependencies: void 0,
|
|
16
|
+
_provides: void 0,
|
|
17
|
+
run: async (ctx) => {
|
|
18
|
+
const intermediate = await middleware.run(ctx);
|
|
19
|
+
return await mw.run(intermediate);
|
|
20
|
+
}
|
|
21
|
+
} : mw;
|
|
22
|
+
return createFactoryImpl(factoryToken, composed);
|
|
23
|
+
},
|
|
24
|
+
createMiddleware(fn) {
|
|
25
|
+
return {
|
|
26
|
+
_dependencies: void 0,
|
|
27
|
+
_provides: void 0,
|
|
28
|
+
run: fn
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
createMethod(options, run) {
|
|
32
|
+
const obj = z.object(options.args);
|
|
33
|
+
const resultValidator = options.result;
|
|
34
|
+
return {
|
|
35
|
+
_factoryToken: factoryToken,
|
|
36
|
+
_contextRequirement: void 0,
|
|
37
|
+
get TArg() {
|
|
38
|
+
throw new Error("Type-only property");
|
|
39
|
+
},
|
|
40
|
+
get TResult() {
|
|
41
|
+
throw new Error("Type-only property");
|
|
42
|
+
},
|
|
43
|
+
argType: obj,
|
|
44
|
+
resultType: resultValidator ?? z.unknown(),
|
|
45
|
+
run: async (args, rawContext) => {
|
|
46
|
+
const parsedArgs = obj.parse(args ?? {});
|
|
47
|
+
let ctx;
|
|
48
|
+
const baseCtx = middleware ? await middleware.run(rawContext) : rawContext;
|
|
49
|
+
if (options.middleware) {
|
|
50
|
+
ctx = await options.middleware.run(baseCtx);
|
|
51
|
+
} else {
|
|
52
|
+
ctx = baseCtx;
|
|
53
|
+
}
|
|
54
|
+
const result = await run(parsedArgs, ctx);
|
|
55
|
+
if (resultValidator) {
|
|
56
|
+
return resultValidator.parse(result);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
createApi(methods) {
|
|
63
|
+
for (const [name, method] of Object.entries(methods)) {
|
|
64
|
+
if (method instanceof ApiImplementation) {
|
|
65
|
+
if (method._factoryToken !== factoryToken) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Method "${name}" is from a different factory. All methods in an API must come from the same factory or its .withMiddleware() derivatives.`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
const m = method;
|
|
72
|
+
if (m._factoryToken !== factoryToken) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Method "${name}" is from a different factory. All methods in an API must come from the same factory or its .withMiddleware() derivatives.`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return new ApiImplementation(factoryToken, methods);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return factory;
|
|
83
|
+
}
|
|
84
|
+
var ApiImplementation = class _ApiImplementation {
|
|
85
|
+
constructor(factoryToken, _methods) {
|
|
86
|
+
this._methods = _methods;
|
|
87
|
+
this._factoryToken = factoryToken;
|
|
88
|
+
}
|
|
89
|
+
_factoryToken;
|
|
90
|
+
get TMethods() {
|
|
91
|
+
throw new Error("Type-only property");
|
|
92
|
+
}
|
|
93
|
+
getMethods() {
|
|
94
|
+
const methods = [];
|
|
95
|
+
for (const [name, method] of Object.entries(this._methods)) {
|
|
96
|
+
if (method instanceof _ApiImplementation) {
|
|
97
|
+
const subMethods = method.getMethods();
|
|
98
|
+
for (const subMethod of subMethods) {
|
|
99
|
+
methods.push({
|
|
100
|
+
...subMethod,
|
|
101
|
+
path: `${name}/${subMethod.path}`
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
methods.push({
|
|
106
|
+
path: name,
|
|
107
|
+
argType: method.argType,
|
|
108
|
+
resultType: method.resultType
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return methods;
|
|
113
|
+
}
|
|
114
|
+
async run(method, arg, context) {
|
|
115
|
+
const parts = method.split("/", 2);
|
|
116
|
+
const firstPart = parts[0];
|
|
117
|
+
if (!(firstPart in this._methods)) {
|
|
118
|
+
return Promise.reject(new Error(`Method not found: ${method}`));
|
|
119
|
+
}
|
|
120
|
+
const impl = this._methods[firstPart];
|
|
121
|
+
if (parts.length > 1) {
|
|
122
|
+
if (!(impl instanceof _ApiImplementation)) {
|
|
123
|
+
throw new Error(`Method not found: ${method}`);
|
|
124
|
+
}
|
|
125
|
+
return impl.run(parts[1], arg, context);
|
|
126
|
+
} else {
|
|
127
|
+
if (impl instanceof _ApiImplementation) {
|
|
128
|
+
throw new Error(`Method not found: ${method}`);
|
|
129
|
+
}
|
|
130
|
+
const result = await impl.run(arg, context);
|
|
131
|
+
return result ?? null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export { ApiImplementation, createApiFactory };
|
|
137
|
+
//# sourceMappingURL=chunk-3R7GHWBM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-3R7GHWBM.js","sources":["../../../../../simple-api/dist/chunk-3R7GHWBM.mjs"],"sourcesContent":["// src/server.ts\nimport { z } from \"zod\";\nfunction createApiFactory() {\n const factoryToken = /* @__PURE__ */ Symbol(\"apiFactory\");\n return createFactoryImpl(factoryToken, void 0);\n}\nfunction createFactoryImpl(factoryToken, middleware) {\n const factory = {\n _factoryToken: factoryToken,\n _middleware: middleware,\n withMiddleware(mwOrFn) {\n const mw = typeof mwOrFn === \"function\" ? { _dependencies: void 0, _provides: void 0, run: mwOrFn } : mwOrFn;\n const composed = middleware ? {\n _dependencies: void 0,\n _provides: void 0,\n run: async (ctx) => {\n const intermediate = await middleware.run(ctx);\n return await mw.run(intermediate);\n }\n } : mw;\n return createFactoryImpl(factoryToken, composed);\n },\n createMiddleware(fn) {\n return {\n _dependencies: void 0,\n _provides: void 0,\n run: fn\n };\n },\n createMethod(options, run) {\n const obj = z.object(options.args);\n const resultValidator = options.result;\n return {\n _factoryToken: factoryToken,\n _contextRequirement: void 0,\n get TArg() {\n throw new Error(\"Type-only property\");\n },\n get TResult() {\n throw new Error(\"Type-only property\");\n },\n argType: obj,\n resultType: resultValidator ?? z.unknown(),\n run: async (args, rawContext) => {\n const parsedArgs = obj.parse(args ?? {});\n let ctx;\n const baseCtx = middleware ? await middleware.run(rawContext) : rawContext;\n if (options.middleware) {\n ctx = await options.middleware.run(baseCtx);\n } else {\n ctx = baseCtx;\n }\n const result = await run(parsedArgs, ctx);\n if (resultValidator) {\n return resultValidator.parse(result);\n }\n return result;\n }\n };\n },\n createApi(methods) {\n for (const [name, method] of Object.entries(methods)) {\n if (method instanceof ApiImplementation) {\n if (method._factoryToken !== factoryToken) {\n throw new Error(\n `Method \"${name}\" is from a different factory. All methods in an API must come from the same factory or its .withMiddleware() derivatives.`\n );\n }\n } else {\n const m = method;\n if (m._factoryToken !== factoryToken) {\n throw new Error(\n `Method \"${name}\" is from a different factory. All methods in an API must come from the same factory or its .withMiddleware() derivatives.`\n );\n }\n }\n }\n return new ApiImplementation(factoryToken, methods);\n }\n };\n return factory;\n}\nvar ApiImplementation = class _ApiImplementation {\n constructor(factoryToken, _methods) {\n this._methods = _methods;\n this._factoryToken = factoryToken;\n }\n _factoryToken;\n get TMethods() {\n throw new Error(\"Type-only property\");\n }\n getMethods() {\n const methods = [];\n for (const [name, method] of Object.entries(this._methods)) {\n if (method instanceof _ApiImplementation) {\n const subMethods = method.getMethods();\n for (const subMethod of subMethods) {\n methods.push({\n ...subMethod,\n path: `${name}/${subMethod.path}`\n });\n }\n } else {\n methods.push({\n path: name,\n argType: method.argType,\n resultType: method.resultType\n });\n }\n }\n return methods;\n }\n async run(method, arg, context) {\n const parts = method.split(\"/\", 2);\n const firstPart = parts[0];\n if (!(firstPart in this._methods)) {\n return Promise.reject(new Error(`Method not found: ${method}`));\n }\n const impl = this._methods[firstPart];\n if (parts.length > 1) {\n if (!(impl instanceof _ApiImplementation)) {\n throw new Error(`Method not found: ${method}`);\n }\n return impl.run(parts[1], arg, context);\n } else {\n if (impl instanceof _ApiImplementation) {\n throw new Error(`Method not found: ${method}`);\n }\n const result = await impl.run(arg, context);\n return result ?? null;\n }\n }\n};\n\nexport {\n createApiFactory,\n ApiImplementation\n};\n//# sourceMappingURL=chunk-3R7GHWBM.mjs.map"],"names":[],"mappings":";;AAAA;AAEA,SAAS,gBAAgB,GAAG;AAC5B,EAAE,MAAM,YAAY,mBAAmB,MAAM,CAAC,YAAY,CAAC;AAC3D,EAAE,OAAO,iBAAiB,CAAC,YAAY,EAAE,MAAM,CAAC;AAChD;AACA,SAAS,iBAAiB,CAAC,YAAY,EAAE,UAAU,EAAE;AACrD,EAAE,MAAM,OAAO,GAAG;AAClB,IAAI,aAAa,EAAE,YAAY;AAC/B,IAAI,WAAW,EAAE,UAAU;AAC3B,IAAI,cAAc,CAAC,MAAM,EAAE;AAC3B,MAAM,MAAM,EAAE,GAAG,OAAO,MAAM,KAAK,UAAU,GAAG,EAAE,aAAa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,IAAI,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;AACtC,IAAI,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC;AAC9B,IAAI,IAAI,EAAE,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE;AACvC,MAAM,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AACrE,IAAI;AACJ,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;AACzC,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;AAC1B,MAAM,IAAI,EAAE,IAAI,YAAY,kBAAkB,CAAC,EAAE;AACjD,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAC;AACtD,MAAM;AACN,MAAM,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC;AAC7C,IAAI,CAAC,MAAM;AACX,MAAM,IAAI,IAAI,YAAY,kBAAkB,EAAE;AAC9C,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAC;AACtD,MAAM;AACN,MAAM,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC;AACjD,MAAM,OAAO,MAAM,IAAI,IAAI;AAC3B,IAAI;AACJ,EAAE;AACF;;;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var ProxyApiClient = class {
|
|
2
|
+
constructor(_request) {
|
|
3
|
+
this._request = _request;
|
|
4
|
+
}
|
|
5
|
+
_createProxy(prefix) {
|
|
6
|
+
return new Proxy(() => {
|
|
7
|
+
}, {
|
|
8
|
+
apply: async (_target, _self, args) => {
|
|
9
|
+
const result = await this._request(prefix, args[0]);
|
|
10
|
+
return result;
|
|
11
|
+
},
|
|
12
|
+
get: (_target, prop) => {
|
|
13
|
+
return this._createProxy(`${prefix}${prefix ? "/" : ""}${prop}`);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
methods = this._createProxy("");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { ProxyApiClient };
|
|
21
|
+
//# sourceMappingURL=chunk-A5PE72HI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-A5PE72HI.js","sources":["../../../../../simple-api/dist/chunk-A5PE72HI.mjs"],"sourcesContent":["import {\n AsyncStream\n} from \"./chunk-SGBCNXYH.mjs\";\n\n// src/client.ts\nvar ApiError = class extends Error {\n constructor(statusCode, method, message) {\n super(message);\n this.statusCode = statusCode;\n this.method = method;\n this.name = \"ApiError\";\n }\n};\nvar ProxyApiClient = class {\n constructor(_request) {\n this._request = _request;\n }\n _createProxy(prefix) {\n return new Proxy(() => {\n }, {\n apply: async (_target, _self, args) => {\n const result = await this._request(prefix, args[0]);\n return result;\n },\n get: (_target, prop) => {\n return this._createProxy(`${prefix}${prefix ? \"/\" : \"\"}${prop}`);\n }\n });\n }\n methods = this._createProxy(\"\");\n};\nfunction createFetchClient(baseUrl, options) {\n return new ProxyApiClient(async (method, arg) => {\n const result = await fetch(`${baseUrl}/${method}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...options?.getHeaders?.()\n },\n body: JSON.stringify(arg)\n });\n if (result.status !== 200) {\n const data2 = await result.json().catch(() => null);\n let message;\n if (data2 && typeof data2 === \"object\" && \"errorMessage\" in data2) {\n message = `${data2.errorMessage}`;\n } else {\n message = `Error calling API method ${method}: ${JSON.stringify(data2)} (Status: ${result.status}, Status Text: ${result.statusText})`;\n }\n const error = new ApiError(result.status, method, message);\n options?.onError?.(error);\n throw error;\n }\n const contentType = result.headers.get(\"Content-Type\");\n if (contentType?.startsWith(\"application/jsonl\")) {\n return AsyncStream.fromFn(async function* () {\n const reader = result.body?.getReader();\n if (!reader) {\n return;\n }\n let buffer = \"\";\n const decoder = new TextDecoder(\"utf-8\");\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n buffer += decoder.decode(value, { stream: true });\n let eolIndex;\n while ((eolIndex = buffer.indexOf(\"\\n\")) >= 0) {\n const line = buffer.slice(0, eolIndex).trim();\n buffer = buffer.slice(eolIndex + 1);\n if (line.length > 0) {\n yield JSON.parse(line);\n }\n }\n }\n const finalLine = buffer.trim();\n if (finalLine.length > 0) {\n yield JSON.parse(finalLine);\n }\n });\n }\n const data = await result.json();\n return data;\n });\n}\nfunction createLocalClient(api, context) {\n return new ProxyApiClient(async (method, args) => {\n return await api.run(method, args, context);\n });\n}\n\nexport {\n ApiError,\n ProxyApiClient,\n createFetchClient,\n createLocalClient\n};\n//# sourceMappingURL=chunk-A5PE72HI.mjs.map"],"names":[],"mappings":"AAaG,IAAC,cAAc,GAAG,MAAM;AAC3B,EAAE,WAAW,CAAC,QAAQ,EAAE;AACxB,IAAI,IAAI,CAAC,QAAQ,GAAG,QAAQ;AAC5B,EAAE;AACF,EAAE,YAAY,CAAC,MAAM,EAAE;AACvB,IAAI,OAAO,IAAI,KAAK,CAAC,MAAM;AAC3B,IAAI,CAAC,EAAE;AACP,MAAM,KAAK,EAAE,OAAO,OAAO,EAAE,KAAK,EAAE,IAAI,KAAK;AAC7C,QAAQ,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAC3D,QAAQ,OAAO,MAAM;AACrB,MAAM,CAAC;AACP,MAAM,GAAG,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK;AAC9B,QAAQ,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;AACxE,MAAM;AACN,KAAK,CAAC;AACN,EAAE;AACF,EAAE,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;AACjC;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/AsyncStream.ts
|
|
2
|
+
var AsyncStream = class _AsyncStream {
|
|
3
|
+
constructor(iterator) {
|
|
4
|
+
this.iterator = iterator;
|
|
5
|
+
}
|
|
6
|
+
static fromIterable(fn) {
|
|
7
|
+
return new _AsyncStream(fn[Symbol.asyncIterator]());
|
|
8
|
+
}
|
|
9
|
+
static fromFn(fn) {
|
|
10
|
+
return new _AsyncStream(fn());
|
|
11
|
+
}
|
|
12
|
+
[Symbol.asyncIterator]() {
|
|
13
|
+
return this.iterator;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var MediaResponse = class {
|
|
17
|
+
constructor(mimeType, data) {
|
|
18
|
+
this.mimeType = mimeType;
|
|
19
|
+
this.data = data;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { AsyncStream, MediaResponse };
|
|
24
|
+
//# sourceMappingURL=chunk-SGBCNXYH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-SGBCNXYH.js","sources":["../../../../../simple-api/dist/chunk-SGBCNXYH.mjs"],"sourcesContent":["// src/AsyncStream.ts\nvar AsyncStream = class _AsyncStream {\n constructor(iterator) {\n this.iterator = iterator;\n }\n static fromIterable(fn) {\n return new _AsyncStream(fn[Symbol.asyncIterator]());\n }\n static fromFn(fn) {\n return new _AsyncStream(fn());\n }\n [Symbol.asyncIterator]() {\n return this.iterator;\n }\n};\nvar MediaResponse = class {\n constructor(mimeType, data) {\n this.mimeType = mimeType;\n this.data = data;\n }\n};\n\nexport {\n AsyncStream,\n MediaResponse\n};\n//# sourceMappingURL=chunk-SGBCNXYH.mjs.map"],"names":[],"mappings":"AAAA;AACG,IAAC,WAAW,GAAG,MAAM,YAAY,CAAC;AACrC,EAAE,WAAW,CAAC,QAAQ,EAAE;AACxB,IAAI,IAAI,CAAC,QAAQ,GAAG,QAAQ;AAC5B,EAAE;AACF,EAAE,OAAO,YAAY,CAAC,EAAE,EAAE;AAC1B,IAAI,OAAO,IAAI,YAAY,CAAC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;AACvD,EAAE;AACF,EAAE,OAAO,MAAM,CAAC,EAAE,EAAE;AACpB,IAAI,OAAO,IAAI,YAAY,CAAC,EAAE,EAAE,CAAC;AACjC,EAAE;AACF,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG;AAC3B,IAAI,OAAO,IAAI,CAAC,QAAQ;AACxB,EAAE;AACF;AACG,IAAC,aAAa,GAAG,MAAM;AAC1B,EAAE,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE;AAC9B,IAAI,IAAI,CAAC,QAAQ,GAAG,QAAQ;AAC5B,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI;AACpB,EAAE;AACF;;;;"}
|