@aiscene/shared 1.6.0 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/cli/cli-runner.mjs +13 -1
- package/dist/es/constants/example-code.mjs +25 -21
- package/dist/es/env/parse-model-config.mjs +11 -1
- package/dist/es/env/types.mjs +1 -0
- package/dist/es/extractor/dom-util.mjs +9 -5
- package/dist/es/extractor/locator.mjs +6 -6
- package/dist/es/extractor/util.mjs +6 -6
- package/dist/es/img/canvas-fallback.mjs +1 -1
- package/dist/es/index.mjs +1 -3
- package/dist/es/logger.mjs +1 -7
- package/dist/es/mcp/base-server.mjs +1 -1
- package/dist/es/mcp/base-tools.mjs +2 -2
- package/dist/es/mcp/tool-generator.mjs +131 -57
- package/dist/es/node/fs.mjs +1 -1
- package/dist/es/us-keyboard-layout.mjs +1 -1
- package/dist/es/utils.mjs +4 -9
- package/dist/lib/baseDB.js +1 -1
- package/dist/lib/cli/cli-runner.js +14 -2
- package/dist/lib/cli/index.js +1 -1
- package/dist/lib/common.js +1 -1
- package/dist/lib/constants/example-code.js +26 -22
- package/dist/lib/constants/index.js +1 -1
- package/dist/lib/env/basic.js +1 -1
- package/dist/lib/env/constants.js +1 -1
- package/dist/lib/env/global-config-manager.js +1 -1
- package/dist/lib/env/helper.js +1 -1
- package/dist/lib/env/index.js +1 -1
- package/dist/lib/env/init-debug.js +1 -1
- package/dist/lib/env/model-config-manager.js +1 -1
- package/dist/lib/env/parse-model-config.js +12 -2
- package/dist/lib/env/types.js +2 -1
- package/dist/lib/env/utils.js +1 -1
- package/dist/lib/extractor/constants.js +1 -1
- package/dist/lib/extractor/dom-util.js +10 -6
- package/dist/lib/extractor/index.js +1 -1
- package/dist/lib/extractor/locator.js +7 -7
- package/dist/lib/extractor/tree.js +1 -1
- package/dist/lib/extractor/util.js +7 -7
- package/dist/lib/extractor/web-extractor.js +1 -1
- package/dist/lib/img/box-select.js +1 -1
- package/dist/lib/img/canvas-fallback.js +2 -2
- package/dist/lib/img/get-photon.js +1 -1
- package/dist/lib/img/get-sharp.js +1 -1
- package/dist/lib/img/index.js +1 -1
- package/dist/lib/img/info.js +1 -1
- package/dist/lib/img/transform.js +1 -1
- package/dist/lib/index.js +3 -14
- package/dist/lib/logger.js +1 -10
- package/dist/lib/mcp/base-server.js +3 -3
- package/dist/lib/mcp/base-tools.js +5 -5
- package/dist/lib/mcp/chrome-path.js +1 -1
- package/dist/lib/mcp/index.js +1 -1
- package/dist/lib/mcp/inject-report-html-plugin.js +1 -1
- package/dist/lib/mcp/launcher-helper.js +1 -1
- package/dist/lib/mcp/tool-generator.js +134 -60
- package/dist/lib/mcp/types.js +1 -1
- package/dist/lib/node/fs.js +2 -2
- package/dist/lib/node/index.js +1 -1
- package/dist/lib/node/port.js +1 -1
- package/dist/lib/polyfills/async-hooks.js +1 -1
- package/dist/lib/polyfills/index.js +1 -1
- package/dist/lib/types/index.js +1 -1
- package/dist/lib/us-keyboard-layout.js +2 -2
- package/dist/lib/utils.js +4 -12
- package/dist/lib/zod-schema-utils.js +1 -1
- package/dist/types/cli/cli-runner.d.ts +8 -0
- package/dist/types/cli/index.d.ts +1 -1
- package/dist/types/constants/example-code.d.ts +1 -1
- package/dist/types/env/types.d.ts +1 -1
- package/dist/types/extractor/dom-util.d.ts +5 -4
- package/dist/types/index.d.ts +0 -2
- package/dist/types/logger.d.ts +0 -1
- package/dist/types/mcp/types.d.ts +1 -0
- package/dist/types/utils.d.ts +0 -3
- package/package.json +2 -2
- package/src/cli/cli-runner.ts +26 -1
- package/src/cli/index.ts +1 -1
- package/src/constants/example-code.ts +25 -21
- package/src/env/parse-model-config.ts +21 -1
- package/src/env/types.ts +2 -0
- package/src/extractor/dom-util.ts +10 -5
- package/src/img/canvas-fallback.ts +1 -1
- package/src/index.ts +0 -7
- package/src/logger.ts +0 -11
- package/src/mcp/base-server.ts +1 -1
- package/src/mcp/base-tools.ts +2 -2
- package/src/mcp/tool-generator.ts +218 -67
- package/src/mcp/types.ts +4 -0
- package/src/utils.ts +0 -17
- package/dist/es/build/copy-static.mjs +0 -31
- package/dist/es/build/rspack-config.mjs +0 -4
- package/dist/lib/build/copy-static.js +0 -79
- package/dist/lib/build/rspack-config.js +0 -38
- package/dist/types/build/copy-static.d.ts +0 -31
- package/dist/types/build/rspack-config.d.ts +0 -8
- package/src/build/copy-static.ts +0 -68
- package/src/build/rspack-config.ts +0 -12
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { parseBase64 } from '
|
|
1
|
+
import { parseBase64 } from '@aiscene/shared/img';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getZodDescription,
|
|
5
|
+
getZodTypeName,
|
|
6
|
+
isMidsceneLocatorField,
|
|
7
|
+
unwrapZodField,
|
|
8
|
+
} from '../zod-schema-utils';
|
|
4
9
|
import type {
|
|
5
10
|
ActionSpaceItem,
|
|
6
11
|
BaseAgent,
|
|
@@ -26,23 +31,18 @@ function describeActionForMCP(action: ActionSpaceItem): string {
|
|
|
26
31
|
return `${action.name} action, ${actionDesc}`;
|
|
27
32
|
}
|
|
28
33
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
shape?: Record<string, unknown>;
|
|
32
|
-
};
|
|
33
|
-
const isZodObjectType = schema._def?.typeName === 'ZodObject';
|
|
34
|
-
|
|
35
|
-
if (!isZodObjectType || !schema.shape) {
|
|
34
|
+
const shape = getZodObjectShape(action.paramSchema);
|
|
35
|
+
if (!shape) {
|
|
36
36
|
// Simple type schema
|
|
37
|
-
const typeName = getZodTypeName(
|
|
38
|
-
const description = getZodDescription(
|
|
37
|
+
const typeName = getZodTypeName(action.paramSchema);
|
|
38
|
+
const description = getZodDescription(action.paramSchema as z.ZodTypeAny);
|
|
39
39
|
const paramDesc = description ? `${typeName} - ${description}` : typeName;
|
|
40
40
|
return `${action.name} action, ${actionDesc}. Parameter: ${paramDesc}`;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Object schema with multiple fields
|
|
44
44
|
const paramDescriptions: string[] = [];
|
|
45
|
-
for (const [key, field] of Object.entries(
|
|
45
|
+
for (const [key, field] of Object.entries(shape)) {
|
|
46
46
|
if (field && typeof field === 'object') {
|
|
47
47
|
const isFieldOptional =
|
|
48
48
|
typeof (field as { isOptional?: () => boolean }).isOptional ===
|
|
@@ -96,25 +96,42 @@ function unwrapOptional(value: z.ZodTypeAny): {
|
|
|
96
96
|
return { innerValue: value, isOptional: false };
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return false;
|
|
99
|
+
function getZodObjectShape(
|
|
100
|
+
value: z.ZodTypeAny | undefined,
|
|
101
|
+
): Record<string, z.ZodTypeAny> | undefined {
|
|
102
|
+
if (!value) {
|
|
103
|
+
return undefined;
|
|
105
104
|
}
|
|
106
|
-
|
|
105
|
+
|
|
106
|
+
const actualValue = unwrapZodField(value) as {
|
|
107
|
+
_def?: { typeName?: string; shape?: () => Record<string, z.ZodTypeAny> };
|
|
108
|
+
shape?: Record<string, z.ZodTypeAny>;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
if (actualValue._def?.typeName !== 'ZodObject') {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (typeof actualValue._def.shape === 'function') {
|
|
116
|
+
return actualValue._def.shape();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return actualValue.shape;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
123
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
107
124
|
}
|
|
108
125
|
|
|
109
126
|
/**
|
|
110
127
|
* Transform a locate field schema to make its 'prompt' field optional
|
|
111
128
|
*/
|
|
112
129
|
function makePromptOptional(
|
|
113
|
-
|
|
130
|
+
shape: Record<string, z.ZodTypeAny>,
|
|
114
131
|
wrapInOptional: boolean,
|
|
115
132
|
): z.ZodTypeAny {
|
|
116
|
-
const newShape = { ...
|
|
117
|
-
newShape.prompt =
|
|
133
|
+
const newShape = { ...shape };
|
|
134
|
+
newShape.prompt = shape.prompt.optional();
|
|
118
135
|
|
|
119
136
|
let newSchema: z.ZodTypeAny = z.object(newShape).passthrough();
|
|
120
137
|
if (wrapInOptional) {
|
|
@@ -131,9 +148,10 @@ function transformSchemaField(
|
|
|
131
148
|
value: z.ZodTypeAny,
|
|
132
149
|
): [string, z.ZodTypeAny] {
|
|
133
150
|
const { innerValue, isOptional } = unwrapOptional(value);
|
|
151
|
+
const shape = getZodObjectShape(innerValue);
|
|
134
152
|
|
|
135
|
-
if (
|
|
136
|
-
return [key, makePromptOptional(
|
|
153
|
+
if (shape && isMidsceneLocatorField(innerValue)) {
|
|
154
|
+
return [key, makePromptOptional(shape, isOptional)];
|
|
137
155
|
}
|
|
138
156
|
return [key, value];
|
|
139
157
|
}
|
|
@@ -148,18 +166,117 @@ function extractActionSchema(
|
|
|
148
166
|
return {};
|
|
149
167
|
}
|
|
150
168
|
|
|
151
|
-
const
|
|
152
|
-
if (!
|
|
153
|
-
return
|
|
169
|
+
const shape = getZodObjectShape(paramSchema);
|
|
170
|
+
if (!shape) {
|
|
171
|
+
return paramSchema as unknown as Record<string, z.ZodTypeAny>;
|
|
154
172
|
}
|
|
155
173
|
|
|
156
174
|
return Object.fromEntries(
|
|
157
|
-
Object.entries(
|
|
175
|
+
Object.entries(shape).map(([key, value]) =>
|
|
158
176
|
transformSchemaField(key, value as z.ZodTypeAny),
|
|
159
177
|
),
|
|
160
178
|
);
|
|
161
179
|
}
|
|
162
180
|
|
|
181
|
+
function getPromptText(prompt: unknown): string | undefined {
|
|
182
|
+
if (typeof prompt === 'string') {
|
|
183
|
+
return prompt;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (isRecord(prompt) && typeof prompt.prompt === 'string') {
|
|
187
|
+
return prompt.prompt;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function moveLocateExtrasIntoPrompt(
|
|
194
|
+
value: Record<string, unknown>,
|
|
195
|
+
locateFieldKeys: Set<string>,
|
|
196
|
+
): Record<string, unknown> {
|
|
197
|
+
const promptText = getPromptText(value.prompt);
|
|
198
|
+
if (!promptText) {
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const normalizedPrompt: Record<string, unknown> = isRecord(value.prompt)
|
|
203
|
+
? { ...value.prompt }
|
|
204
|
+
: { prompt: promptText };
|
|
205
|
+
const normalizedLocate: Record<string, unknown> = {};
|
|
206
|
+
let movedExtraField = false;
|
|
207
|
+
|
|
208
|
+
for (const [key, fieldValue] of Object.entries(value)) {
|
|
209
|
+
if (key === 'prompt') {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (locateFieldKeys.has(key)) {
|
|
214
|
+
normalizedLocate[key] = fieldValue;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
movedExtraField = true;
|
|
219
|
+
if (!(key in normalizedPrompt)) {
|
|
220
|
+
normalizedPrompt[key] = fieldValue;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (!movedExtraField) {
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return { ...normalizedLocate, prompt: normalizedPrompt };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function normalizeLocateLikeArg(
|
|
232
|
+
value: unknown,
|
|
233
|
+
fieldSchema: z.ZodTypeAny,
|
|
234
|
+
): unknown {
|
|
235
|
+
if (typeof value === 'string') {
|
|
236
|
+
return { prompt: value };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (!isRecord(value)) {
|
|
240
|
+
return value;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const shape = getZodObjectShape(fieldSchema);
|
|
244
|
+
if (!shape) {
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return moveLocateExtrasIntoPrompt(value, new Set(Object.keys(shape)));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function normalizeActionArgs(
|
|
252
|
+
args: Record<string, unknown>,
|
|
253
|
+
paramSchema?: z.ZodTypeAny,
|
|
254
|
+
): Record<string, unknown> {
|
|
255
|
+
if (!paramSchema) {
|
|
256
|
+
return args;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const shape = getZodObjectShape(paramSchema);
|
|
260
|
+
if (!shape) {
|
|
261
|
+
return args;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return Object.fromEntries(
|
|
265
|
+
Object.entries(args).map(([key, value]) => {
|
|
266
|
+
const fieldSchema = shape[key] as z.ZodTypeAny | undefined;
|
|
267
|
+
if (!fieldSchema) {
|
|
268
|
+
return [key, value];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (isMidsceneLocatorField(fieldSchema)) {
|
|
272
|
+
return [key, normalizeLocateLikeArg(value, fieldSchema)];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return [key, value];
|
|
276
|
+
}),
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
163
280
|
/**
|
|
164
281
|
* Serialize args to human-readable description for AI action
|
|
165
282
|
*/
|
|
@@ -194,10 +311,9 @@ function buildActionInstruction(
|
|
|
194
311
|
actionName: string,
|
|
195
312
|
args: Record<string, unknown>,
|
|
196
313
|
): string {
|
|
197
|
-
const locatePrompt =
|
|
198
|
-
args.locate
|
|
199
|
-
|
|
200
|
-
: undefined;
|
|
314
|
+
const locatePrompt = isRecord(args.locate)
|
|
315
|
+
? getPromptText(args.locate.prompt)
|
|
316
|
+
: undefined;
|
|
201
317
|
|
|
202
318
|
switch (actionName) {
|
|
203
319
|
case 'Tap':
|
|
@@ -227,39 +343,71 @@ function buildActionInstruction(
|
|
|
227
343
|
}
|
|
228
344
|
}
|
|
229
345
|
|
|
346
|
+
async function executeAction(
|
|
347
|
+
agent: BaseAgent,
|
|
348
|
+
actionName: string,
|
|
349
|
+
args: Record<string, unknown>,
|
|
350
|
+
): Promise<unknown> {
|
|
351
|
+
if (agent.callActionInActionSpace) {
|
|
352
|
+
return agent.callActionInActionSpace(actionName, args);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (agent.aiAction) {
|
|
356
|
+
const instruction = buildActionInstruction(actionName, args);
|
|
357
|
+
return agent.aiAction(instruction);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
throw new Error(`Action "${actionName}" is not supported by this agent`);
|
|
361
|
+
}
|
|
362
|
+
|
|
230
363
|
/**
|
|
231
364
|
* Capture screenshot and return as tool result
|
|
232
365
|
*/
|
|
233
366
|
async function captureScreenshotResult(
|
|
234
367
|
agent: BaseAgent,
|
|
235
368
|
actionName: string,
|
|
369
|
+
actionResult?: unknown,
|
|
236
370
|
): Promise<ToolResult> {
|
|
371
|
+
const content: ToolResult['content'] = [
|
|
372
|
+
{ type: 'text', text: `Action "${actionName}" completed.` },
|
|
373
|
+
];
|
|
374
|
+
|
|
375
|
+
if (actionResult !== undefined) {
|
|
376
|
+
content.push({
|
|
377
|
+
type: 'text',
|
|
378
|
+
text: `Result: ${serializeActionResult(actionResult)}`,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
237
382
|
try {
|
|
238
383
|
const screenshot = await agent.page?.screenshotBase64();
|
|
239
384
|
if (!screenshot) {
|
|
240
|
-
return {
|
|
241
|
-
content: [{ type: 'text', text: `Action "${actionName}" completed.` }],
|
|
242
|
-
};
|
|
385
|
+
return { content };
|
|
243
386
|
}
|
|
244
387
|
|
|
245
388
|
const { mimeType, body } = parseBase64(screenshot);
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
{ type: 'text', text: `Action "${actionName}" completed.` },
|
|
249
|
-
{ type: 'image', data: body, mimeType },
|
|
250
|
-
],
|
|
251
|
-
};
|
|
389
|
+
content.push({ type: 'image', data: body, mimeType });
|
|
390
|
+
return { content };
|
|
252
391
|
} catch (error: unknown) {
|
|
253
392
|
const errorMessage = getErrorMessage(error);
|
|
254
393
|
console.error('Error capturing screenshot:', errorMessage);
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
type: 'text',
|
|
259
|
-
text: `Action "${actionName}" completed (screenshot unavailable: ${errorMessage})`,
|
|
260
|
-
},
|
|
261
|
-
],
|
|
394
|
+
content[0] = {
|
|
395
|
+
type: 'text',
|
|
396
|
+
text: `Action "${actionName}" completed (screenshot unavailable: ${errorMessage})`,
|
|
262
397
|
};
|
|
398
|
+
return { content };
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function serializeActionResult(actionResult: unknown): string {
|
|
403
|
+
if (typeof actionResult === 'string') {
|
|
404
|
+
return actionResult;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
try {
|
|
408
|
+
return JSON.stringify(actionResult);
|
|
409
|
+
} catch {
|
|
410
|
+
return String(actionResult);
|
|
263
411
|
}
|
|
264
412
|
}
|
|
265
413
|
|
|
@@ -323,28 +471,31 @@ export function generateToolsFromActionSpace(
|
|
|
323
471
|
handler: async (args: Record<string, unknown>) => {
|
|
324
472
|
try {
|
|
325
473
|
const agent = await getAgent();
|
|
474
|
+
const normalizedArgs = normalizeActionArgs(args, action.paramSchema);
|
|
475
|
+
let actionResult: unknown;
|
|
326
476
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
errorMessage,
|
|
343
|
-
);
|
|
344
|
-
}
|
|
477
|
+
try {
|
|
478
|
+
actionResult = await executeAction(
|
|
479
|
+
agent,
|
|
480
|
+
action.name,
|
|
481
|
+
normalizedArgs,
|
|
482
|
+
);
|
|
483
|
+
} catch (error: unknown) {
|
|
484
|
+
const errorMessage = getErrorMessage(error);
|
|
485
|
+
console.error(
|
|
486
|
+
`Error executing action "${action.name}":`,
|
|
487
|
+
errorMessage,
|
|
488
|
+
);
|
|
489
|
+
// Return screenshot + warning instead of hard error,
|
|
490
|
+
// so the AI agent can see current state and decide to retry or adjust strategy
|
|
491
|
+
return await captureFailureResult(agent, action.name, errorMessage);
|
|
345
492
|
}
|
|
346
493
|
|
|
347
|
-
return await captureScreenshotResult(
|
|
494
|
+
return await captureScreenshotResult(
|
|
495
|
+
agent,
|
|
496
|
+
action.name,
|
|
497
|
+
actionResult,
|
|
498
|
+
);
|
|
348
499
|
} catch (error: unknown) {
|
|
349
500
|
// Connection/agent errors are still hard errors
|
|
350
501
|
const errorMessage = getErrorMessage(error);
|
package/src/mcp/types.ts
CHANGED
|
@@ -84,6 +84,10 @@ export interface BaseAgent {
|
|
|
84
84
|
page?: {
|
|
85
85
|
screenshotBase64(): Promise<string>;
|
|
86
86
|
};
|
|
87
|
+
callActionInActionSpace?: (
|
|
88
|
+
actionName: string,
|
|
89
|
+
params?: unknown,
|
|
90
|
+
) => Promise<unknown>;
|
|
87
91
|
aiAction?: (
|
|
88
92
|
description: string,
|
|
89
93
|
params?: Record<string, unknown>,
|
package/src/utils.ts
CHANGED
|
@@ -64,23 +64,6 @@ export function assert(condition: any, message?: string): asserts condition {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
type GlobalScope = typeof window | typeof globalThis | typeof self | undefined;
|
|
68
|
-
|
|
69
|
-
export function getGlobalScope(): GlobalScope {
|
|
70
|
-
if (typeof window !== 'undefined') {
|
|
71
|
-
return window;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (typeof globalThis !== 'undefined') {
|
|
75
|
-
return globalThis;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (typeof self !== 'undefined') {
|
|
79
|
-
return self;
|
|
80
|
-
}
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
67
|
let isMcp = false;
|
|
85
68
|
|
|
86
69
|
export function setIsMcp(value: boolean) {
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import node_fs from "node:fs";
|
|
2
|
-
import node_path from "node:path";
|
|
3
|
-
const createCopyStaticPlugin = (options)=>({
|
|
4
|
-
name: options.pluginName || 'copy-static',
|
|
5
|
-
setup (api) {
|
|
6
|
-
api.onAfterBuild(async ()=>{
|
|
7
|
-
const { srcDir, destDir, faviconPath } = options;
|
|
8
|
-
const stat = await node_fs.promises.lstat(destDir).catch(()=>null);
|
|
9
|
-
if (stat?.isSymbolicLink()) await node_fs.promises.unlink(destDir);
|
|
10
|
-
await node_fs.promises.mkdir(destDir, {
|
|
11
|
-
recursive: true
|
|
12
|
-
});
|
|
13
|
-
await node_fs.promises.cp(srcDir, destDir, {
|
|
14
|
-
recursive: true
|
|
15
|
-
});
|
|
16
|
-
console.log(`Copied build artifacts from ${srcDir} to ${destDir}`);
|
|
17
|
-
if (faviconPath) {
|
|
18
|
-
const faviconDest = node_path.join(destDir, 'favicon.ico');
|
|
19
|
-
await node_fs.promises.copyFile(faviconPath, faviconDest);
|
|
20
|
-
console.log(`Copied favicon from ${faviconPath} to ${faviconDest}`);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
const createPlaygroundCopyPlugin = (srcDir, destDir, pluginName, faviconSrc)=>createCopyStaticPlugin({
|
|
26
|
-
srcDir,
|
|
27
|
-
destDir,
|
|
28
|
-
faviconPath: faviconSrc,
|
|
29
|
-
pluginName
|
|
30
|
-
});
|
|
31
|
-
export { createCopyStaticPlugin, createPlaygroundCopyPlugin };
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: definition[key]
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
})();
|
|
20
|
-
(()=>{
|
|
21
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
-
})();
|
|
23
|
-
(()=>{
|
|
24
|
-
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
-
value: 'Module'
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
-
value: true
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __webpack_exports__ = {};
|
|
34
|
-
__webpack_require__.r(__webpack_exports__);
|
|
35
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
createCopyStaticPlugin: ()=>createCopyStaticPlugin,
|
|
37
|
-
createPlaygroundCopyPlugin: ()=>createPlaygroundCopyPlugin
|
|
38
|
-
});
|
|
39
|
-
const external_node_fs_namespaceObject = require("node:fs");
|
|
40
|
-
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
41
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
42
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
43
|
-
const createCopyStaticPlugin = (options)=>({
|
|
44
|
-
name: options.pluginName || 'copy-static',
|
|
45
|
-
setup (api) {
|
|
46
|
-
api.onAfterBuild(async ()=>{
|
|
47
|
-
const { srcDir, destDir, faviconPath } = options;
|
|
48
|
-
const stat = await external_node_fs_default().promises.lstat(destDir).catch(()=>null);
|
|
49
|
-
if (stat?.isSymbolicLink()) await external_node_fs_default().promises.unlink(destDir);
|
|
50
|
-
await external_node_fs_default().promises.mkdir(destDir, {
|
|
51
|
-
recursive: true
|
|
52
|
-
});
|
|
53
|
-
await external_node_fs_default().promises.cp(srcDir, destDir, {
|
|
54
|
-
recursive: true
|
|
55
|
-
});
|
|
56
|
-
console.log(`Copied build artifacts from ${srcDir} to ${destDir}`);
|
|
57
|
-
if (faviconPath) {
|
|
58
|
-
const faviconDest = external_node_path_default().join(destDir, 'favicon.ico');
|
|
59
|
-
await external_node_fs_default().promises.copyFile(faviconPath, faviconDest);
|
|
60
|
-
console.log(`Copied favicon from ${faviconPath} to ${faviconDest}`);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
const createPlaygroundCopyPlugin = (srcDir, destDir, pluginName, faviconSrc)=>createCopyStaticPlugin({
|
|
66
|
-
srcDir,
|
|
67
|
-
destDir,
|
|
68
|
-
faviconPath: faviconSrc,
|
|
69
|
-
pluginName
|
|
70
|
-
});
|
|
71
|
-
exports.createCopyStaticPlugin = __webpack_exports__.createCopyStaticPlugin;
|
|
72
|
-
exports.createPlaygroundCopyPlugin = __webpack_exports__.createPlaygroundCopyPlugin;
|
|
73
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
74
|
-
"createCopyStaticPlugin",
|
|
75
|
-
"createPlaygroundCopyPlugin"
|
|
76
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
77
|
-
Object.defineProperty(exports, '__esModule', {
|
|
78
|
-
value: true
|
|
79
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()=>{
|
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
-
})();
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
-
value: 'Module'
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
commonIgnoreWarnings: ()=>commonIgnoreWarnings
|
|
28
|
-
});
|
|
29
|
-
const commonIgnoreWarnings = [
|
|
30
|
-
/Critical dependency: the request of a dependency is an expression/
|
|
31
|
-
];
|
|
32
|
-
exports.commonIgnoreWarnings = __webpack_exports__.commonIgnoreWarnings;
|
|
33
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
34
|
-
"commonIgnoreWarnings"
|
|
35
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
36
|
-
Object.defineProperty(exports, '__esModule', {
|
|
37
|
-
value: true
|
|
38
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export interface CopyStaticOptions {
|
|
2
|
-
/** Source directory to copy from */
|
|
3
|
-
srcDir: string;
|
|
4
|
-
/** Destination directory to copy to */
|
|
5
|
-
destDir: string;
|
|
6
|
-
/** Optional favicon source path (relative to directory containing srcDir) */
|
|
7
|
-
faviconPath?: string;
|
|
8
|
-
/** Name for the rsbuild plugin */
|
|
9
|
-
pluginName?: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Creates an rsbuild plugin that copies static files after build
|
|
13
|
-
* @param options Configuration options for copying static files
|
|
14
|
-
* @returns Rsbuild plugin object
|
|
15
|
-
*/
|
|
16
|
-
export declare const createCopyStaticPlugin: (options: CopyStaticOptions) => {
|
|
17
|
-
name: string;
|
|
18
|
-
setup(api: any): void;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Helper function to create a copy static plugin for playground builds
|
|
22
|
-
* @param srcDir Source directory (usually dist directory)
|
|
23
|
-
* @param destDir Destination directory
|
|
24
|
-
* @param pluginName Optional plugin name
|
|
25
|
-
* @param faviconSrc Optional favicon source path
|
|
26
|
-
* @returns Rsbuild plugin
|
|
27
|
-
*/
|
|
28
|
-
export declare const createPlaygroundCopyPlugin: (srcDir: string, destDir: string, pluginName?: string, faviconSrc?: string) => {
|
|
29
|
-
name: string;
|
|
30
|
-
setup(api: any): void;
|
|
31
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Common Rspack configuration helpers for rsbuild projects
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Common warning patterns to ignore in Rspack builds.
|
|
6
|
-
* These warnings are typically from optional dependencies or known non-critical issues.
|
|
7
|
-
*/
|
|
8
|
-
export declare const commonIgnoreWarnings: RegExp[];
|
package/src/build/copy-static.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
export interface CopyStaticOptions {
|
|
5
|
-
/** Source directory to copy from */
|
|
6
|
-
srcDir: string;
|
|
7
|
-
/** Destination directory to copy to */
|
|
8
|
-
destDir: string;
|
|
9
|
-
/** Optional favicon source path (relative to directory containing srcDir) */
|
|
10
|
-
faviconPath?: string;
|
|
11
|
-
/** Name for the rsbuild plugin */
|
|
12
|
-
pluginName?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates an rsbuild plugin that copies static files after build
|
|
17
|
-
* @param options Configuration options for copying static files
|
|
18
|
-
* @returns Rsbuild plugin object
|
|
19
|
-
*/
|
|
20
|
-
export const createCopyStaticPlugin = (options: CopyStaticOptions) => ({
|
|
21
|
-
name: options.pluginName || 'copy-static',
|
|
22
|
-
setup(api: any) {
|
|
23
|
-
api.onAfterBuild(async () => {
|
|
24
|
-
const { srcDir, destDir, faviconPath } = options;
|
|
25
|
-
|
|
26
|
-
// Remove symlink left by dev mode before copying
|
|
27
|
-
const stat = await fs.promises.lstat(destDir).catch(() => null);
|
|
28
|
-
if (stat?.isSymbolicLink()) {
|
|
29
|
-
await fs.promises.unlink(destDir);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
await fs.promises.mkdir(destDir, { recursive: true });
|
|
33
|
-
|
|
34
|
-
// Copy directory contents recursively
|
|
35
|
-
await fs.promises.cp(srcDir, destDir, { recursive: true });
|
|
36
|
-
console.log(`Copied build artifacts from ${srcDir} to ${destDir}`);
|
|
37
|
-
|
|
38
|
-
// Copy favicon if specified
|
|
39
|
-
if (faviconPath) {
|
|
40
|
-
const faviconDest = path.join(destDir, 'favicon.ico');
|
|
41
|
-
await fs.promises.copyFile(faviconPath, faviconDest);
|
|
42
|
-
console.log(`Copied favicon from ${faviconPath} to ${faviconDest}`);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Helper function to create a copy static plugin for playground builds
|
|
50
|
-
* @param srcDir Source directory (usually dist directory)
|
|
51
|
-
* @param destDir Destination directory
|
|
52
|
-
* @param pluginName Optional plugin name
|
|
53
|
-
* @param faviconSrc Optional favicon source path
|
|
54
|
-
* @returns Rsbuild plugin
|
|
55
|
-
*/
|
|
56
|
-
export const createPlaygroundCopyPlugin = (
|
|
57
|
-
srcDir: string,
|
|
58
|
-
destDir: string,
|
|
59
|
-
pluginName?: string,
|
|
60
|
-
faviconSrc?: string,
|
|
61
|
-
) => {
|
|
62
|
-
return createCopyStaticPlugin({
|
|
63
|
-
srcDir,
|
|
64
|
-
destDir,
|
|
65
|
-
faviconPath: faviconSrc,
|
|
66
|
-
pluginName,
|
|
67
|
-
});
|
|
68
|
-
};
|