pupt-lib 1.3.5 → 1.3.7
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/README.md +24 -345
- package/dist/components/structural/Prompt.d.ts.map +1 -1
- package/dist/components/structural/Role.d.ts.map +1 -1
- package/dist/index.js +889 -194
- package/dist/src/api.d.ts +13 -1
- package/dist/src/api.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/render.d.ts.map +1 -1
- package/dist/src/services/module-loader.d.ts +73 -25
- package/dist/src/services/module-loader.d.ts.map +1 -1
- package/dist/src/services/prompt-sources/github-prompt-source.d.ts +38 -0
- package/dist/src/services/prompt-sources/github-prompt-source.d.ts.map +1 -0
- package/dist/src/services/prompt-sources/index.d.ts +8 -0
- package/dist/src/services/prompt-sources/index.d.ts.map +1 -0
- package/dist/src/services/prompt-sources/local-prompt-source.d.ts +30 -0
- package/dist/src/services/prompt-sources/local-prompt-source.d.ts.map +1 -0
- package/dist/src/services/prompt-sources/npm-local-prompt-source.d.ts +27 -0
- package/dist/src/services/prompt-sources/npm-local-prompt-source.d.ts.map +1 -0
- package/dist/src/services/prompt-sources/npm-registry-prompt-source.d.ts +36 -0
- package/dist/src/services/prompt-sources/npm-registry-prompt-source.d.ts.map +1 -0
- package/dist/src/services/prompt-sources/tar-utils.d.ts +30 -0
- package/dist/src/services/prompt-sources/tar-utils.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +5 -1
- package/dist/src/types/index.d.ts.map +1 -1
- package/dist/src/types/module.d.ts +34 -1
- package/dist/src/types/module.d.ts.map +1 -1
- package/dist/src/types/prompt-source.d.ts +12 -0
- package/dist/src/types/prompt-source.d.ts.map +1 -0
- package/dist/src/types/render.d.ts +11 -1
- package/dist/src/types/render.d.ts.map +1 -1
- package/package.json +8 -2
package/dist/index.js
CHANGED
|
@@ -3854,6 +3854,15 @@ function createRuntimeConfig() {
|
|
|
3854
3854
|
uuid: crypto.randomUUID()
|
|
3855
3855
|
};
|
|
3856
3856
|
}
|
|
3857
|
+
function isWarningCode(code) {
|
|
3858
|
+
return code.startsWith("warn_") || code === "validation_warning";
|
|
3859
|
+
}
|
|
3860
|
+
function isResolvedModuleEntry(value) {
|
|
3861
|
+
return value !== null && typeof value === "object" && "type" in value && "source" in value && "name" in value && typeof value.type === "string" && typeof value.source === "string" && typeof value.name === "string" && ["git", "npm", "local", "url"].includes(value.type);
|
|
3862
|
+
}
|
|
3863
|
+
function isPromptSource(value) {
|
|
3864
|
+
return value !== null && typeof value === "object" && "getPrompts" in value && typeof value.getPrompts === "function";
|
|
3865
|
+
}
|
|
3857
3866
|
const COMPONENT_MARKER = Symbol.for("pupt-lib:component:v1");
|
|
3858
3867
|
_a = COMPONENT_MARKER;
|
|
3859
3868
|
class Component {
|
|
@@ -4002,7 +4011,9 @@ async function render(element, options = {}) {
|
|
|
4002
4011
|
const {
|
|
4003
4012
|
inputs = /* @__PURE__ */ new Map(),
|
|
4004
4013
|
env = DEFAULT_ENVIRONMENT,
|
|
4005
|
-
trim = true
|
|
4014
|
+
trim = true,
|
|
4015
|
+
throwOnWarnings = false,
|
|
4016
|
+
ignoreWarnings = []
|
|
4006
4017
|
} = options;
|
|
4007
4018
|
const postExecution = [];
|
|
4008
4019
|
const errors = [];
|
|
@@ -4021,13 +4032,26 @@ async function render(element, options = {}) {
|
|
|
4021
4032
|
seedAskDefaults(element, context);
|
|
4022
4033
|
const text = await renderNode(element, state);
|
|
4023
4034
|
const trimmedText = trim ? text.trim() : text;
|
|
4024
|
-
const
|
|
4025
|
-
const
|
|
4035
|
+
const ignoreSet = new Set(ignoreWarnings);
|
|
4036
|
+
const warnings = [];
|
|
4037
|
+
const hardErrors = [];
|
|
4038
|
+
for (const err of errors) {
|
|
4039
|
+
if (isWarningCode(err.code)) {
|
|
4040
|
+
if (ignoreSet.has(err.code)) continue;
|
|
4041
|
+
if (throwOnWarnings) {
|
|
4042
|
+
hardErrors.push(err);
|
|
4043
|
+
} else {
|
|
4044
|
+
warnings.push(err);
|
|
4045
|
+
}
|
|
4046
|
+
} else {
|
|
4047
|
+
hardErrors.push(err);
|
|
4048
|
+
}
|
|
4049
|
+
}
|
|
4026
4050
|
if (hardErrors.length > 0) {
|
|
4027
4051
|
return {
|
|
4028
4052
|
ok: false,
|
|
4029
4053
|
text: trimmedText,
|
|
4030
|
-
errors,
|
|
4054
|
+
errors: [...hardErrors, ...warnings],
|
|
4031
4055
|
postExecution
|
|
4032
4056
|
};
|
|
4033
4057
|
}
|
|
@@ -43178,6 +43202,49 @@ ${imports}
|
|
|
43178
43202
|
|
|
43179
43203
|
${usesSection}${result}`;
|
|
43180
43204
|
}
|
|
43205
|
+
const CUSTOM_COMPONENTS_GLOBAL = "__PUPT_CUSTOM_COMPONENTS__";
|
|
43206
|
+
async function createPromptFromSource(source, filename, options = {}) {
|
|
43207
|
+
const { components } = options;
|
|
43208
|
+
let processedSource = preprocessSource(source, { filename });
|
|
43209
|
+
if (components && Object.keys(components).length > 0) {
|
|
43210
|
+
globalThis[CUSTOM_COMPONENTS_GLOBAL] = components;
|
|
43211
|
+
const componentNames = Object.keys(components);
|
|
43212
|
+
const extractCode = `const { ${componentNames.join(", ")} } = globalThis.${CUSTOM_COMPONENTS_GLOBAL};
|
|
43213
|
+
`;
|
|
43214
|
+
let lastImportEnd = 0;
|
|
43215
|
+
const fullImportRegex = /import\s+(?:(?:\{[^}]*\}|[^;{]*)\s+from\s+)?['"][^'"]+['"];?/g;
|
|
43216
|
+
let match;
|
|
43217
|
+
while ((match = fullImportRegex.exec(processedSource)) !== null) {
|
|
43218
|
+
const matchEnd = match.index + match[0].length;
|
|
43219
|
+
if (matchEnd > lastImportEnd) {
|
|
43220
|
+
lastImportEnd = matchEnd;
|
|
43221
|
+
}
|
|
43222
|
+
}
|
|
43223
|
+
if (lastImportEnd > 0) {
|
|
43224
|
+
processedSource = processedSource.slice(0, lastImportEnd) + "\n" + extractCode + processedSource.slice(lastImportEnd);
|
|
43225
|
+
} else {
|
|
43226
|
+
processedSource = extractCode + processedSource;
|
|
43227
|
+
}
|
|
43228
|
+
}
|
|
43229
|
+
try {
|
|
43230
|
+
const transformer = new Transformer2();
|
|
43231
|
+
const code = await transformer.transformSourceAsync(processedSource, filename);
|
|
43232
|
+
const module = await evaluateModule(code, { filename });
|
|
43233
|
+
if (module.default === void 0) {
|
|
43234
|
+
throw new Error(`${filename} must have a default export`);
|
|
43235
|
+
}
|
|
43236
|
+
return module.default;
|
|
43237
|
+
} finally {
|
|
43238
|
+
if (components) {
|
|
43239
|
+
delete globalThis[CUSTOM_COMPONENTS_GLOBAL];
|
|
43240
|
+
}
|
|
43241
|
+
}
|
|
43242
|
+
}
|
|
43243
|
+
async function createPrompt(filePath, options = {}) {
|
|
43244
|
+
const { readFile } = await import("fs/promises");
|
|
43245
|
+
const source = await readFile(filePath, "utf-8");
|
|
43246
|
+
return createPromptFromSource(source, filePath, options);
|
|
43247
|
+
}
|
|
43181
43248
|
const isNode = typeof process !== "undefined" && ((_b = process.versions) == null ? void 0 : _b.node);
|
|
43182
43249
|
async function resolveLocalPath(source) {
|
|
43183
43250
|
if (!isNode) {
|
|
@@ -43195,22 +43262,8 @@ class ModuleLoader {
|
|
|
43195
43262
|
__publicField(this, "versions", /* @__PURE__ */ new Map());
|
|
43196
43263
|
}
|
|
43197
43264
|
/**
|
|
43198
|
-
*
|
|
43199
|
-
|
|
43200
|
-
resolveSourceType(source) {
|
|
43201
|
-
if (source.startsWith("https://") || source.startsWith("http://") || source.startsWith("data:")) {
|
|
43202
|
-
return "url";
|
|
43203
|
-
}
|
|
43204
|
-
if (source.startsWith("github:")) {
|
|
43205
|
-
return "github";
|
|
43206
|
-
}
|
|
43207
|
-
if (source.startsWith("./") || source.startsWith("/") || source.startsWith("../")) {
|
|
43208
|
-
return "local";
|
|
43209
|
-
}
|
|
43210
|
-
return "npm";
|
|
43211
|
-
}
|
|
43212
|
-
/**
|
|
43213
|
-
* Parse a package source string into name and version
|
|
43265
|
+
* Parse a package source string into name and version.
|
|
43266
|
+
* Handles scoped packages (@scope/name@version) and regular packages (name@version).
|
|
43214
43267
|
*/
|
|
43215
43268
|
parsePackageSource(source) {
|
|
43216
43269
|
if (source.startsWith("@")) {
|
|
@@ -43233,39 +43286,102 @@ class ModuleLoader {
|
|
|
43233
43286
|
return { name: source };
|
|
43234
43287
|
}
|
|
43235
43288
|
/**
|
|
43236
|
-
* Load a module
|
|
43237
|
-
*
|
|
43289
|
+
* Load a module entry (ResolvedModuleEntry, PromptSource, or package reference).
|
|
43290
|
+
* Dispatches to the appropriate loading strategy based on entry type.
|
|
43238
43291
|
*/
|
|
43239
|
-
async
|
|
43240
|
-
|
|
43241
|
-
|
|
43242
|
-
|
|
43243
|
-
|
|
43244
|
-
|
|
43245
|
-
throw new Error(
|
|
43246
|
-
`Version conflict for ${parsed.name}: trying to load ${parsed.version} but ${existingVersion} is already loaded`
|
|
43247
|
-
);
|
|
43248
|
-
}
|
|
43292
|
+
async loadEntry(entry) {
|
|
43293
|
+
if (isPromptSource(entry)) {
|
|
43294
|
+
return this.loadPromptSource(entry);
|
|
43295
|
+
}
|
|
43296
|
+
if (isResolvedModuleEntry(entry)) {
|
|
43297
|
+
return this.loadResolvedEntry(entry);
|
|
43249
43298
|
}
|
|
43299
|
+
if (typeof entry === "object" && entry !== null && "source" in entry && "config" in entry) {
|
|
43300
|
+
return this.loadPackageReference(entry);
|
|
43301
|
+
}
|
|
43302
|
+
throw new Error("Invalid module entry: must be a ResolvedModuleEntry, PromptSource, or { source, config } object");
|
|
43303
|
+
}
|
|
43304
|
+
/**
|
|
43305
|
+
* Load a module from a ResolvedModuleEntry.
|
|
43306
|
+
* Uses the explicit `type` field for routing and passes `promptDirs` through
|
|
43307
|
+
* to the appropriate prompt source.
|
|
43308
|
+
*/
|
|
43309
|
+
async loadResolvedEntry(entry) {
|
|
43310
|
+
const { name, type, source, promptDirs, version } = entry;
|
|
43311
|
+
const normalizedSource = this.normalizeSource(source, type);
|
|
43250
43312
|
if (this.loaded.has(normalizedSource)) {
|
|
43251
43313
|
return this.loaded.get(normalizedSource);
|
|
43252
43314
|
}
|
|
43253
43315
|
if (this.loading.has(normalizedSource)) {
|
|
43254
43316
|
return this.loading.get(normalizedSource);
|
|
43255
43317
|
}
|
|
43256
|
-
|
|
43318
|
+
if (version) {
|
|
43319
|
+
const existingVersion = this.versions.get(name);
|
|
43320
|
+
if (existingVersion && existingVersion !== version) {
|
|
43321
|
+
throw new Error(
|
|
43322
|
+
`Version conflict for ${name}: trying to load ${version} but ${existingVersion} is already loaded`
|
|
43323
|
+
);
|
|
43324
|
+
}
|
|
43325
|
+
}
|
|
43326
|
+
const promise = this.doLoad(type, source, promptDirs);
|
|
43257
43327
|
this.loading.set(normalizedSource, promise);
|
|
43258
43328
|
try {
|
|
43259
43329
|
const library = await promise;
|
|
43330
|
+
library.name = name;
|
|
43260
43331
|
this.loaded.set(normalizedSource, library);
|
|
43261
|
-
if (
|
|
43262
|
-
this.versions.set(
|
|
43332
|
+
if (version) {
|
|
43333
|
+
this.versions.set(name, version);
|
|
43263
43334
|
}
|
|
43264
43335
|
return library;
|
|
43265
43336
|
} finally {
|
|
43266
43337
|
this.loading.delete(normalizedSource);
|
|
43267
43338
|
}
|
|
43268
43339
|
}
|
|
43340
|
+
/**
|
|
43341
|
+
* Load prompts from a PromptSource instance.
|
|
43342
|
+
*/
|
|
43343
|
+
async loadPromptSource(source, name) {
|
|
43344
|
+
var _a2;
|
|
43345
|
+
const prompts = await this.discoverAndCompilePrompts(source);
|
|
43346
|
+
return {
|
|
43347
|
+
name: name ?? ((_a2 = source.constructor) == null ? void 0 : _a2.name) ?? "PromptSource",
|
|
43348
|
+
components: {},
|
|
43349
|
+
prompts,
|
|
43350
|
+
dependencies: []
|
|
43351
|
+
};
|
|
43352
|
+
}
|
|
43353
|
+
/**
|
|
43354
|
+
* Load prompts from a dynamic package reference.
|
|
43355
|
+
* Imports the source module, instantiates its default export with the config,
|
|
43356
|
+
* and calls getPrompts() on it.
|
|
43357
|
+
*/
|
|
43358
|
+
async loadPackageReference(ref) {
|
|
43359
|
+
let resolvedSource = ref.source;
|
|
43360
|
+
if (isNode && (ref.source.startsWith("./") || ref.source.startsWith("/") || ref.source.startsWith("../"))) {
|
|
43361
|
+
const path = await import("path");
|
|
43362
|
+
const url = await import("url");
|
|
43363
|
+
const absolutePath = path.resolve(process.cwd(), ref.source);
|
|
43364
|
+
resolvedSource = url.pathToFileURL(absolutePath).href;
|
|
43365
|
+
}
|
|
43366
|
+
const module = await import(
|
|
43367
|
+
/* @vite-ignore */
|
|
43368
|
+
resolvedSource
|
|
43369
|
+
);
|
|
43370
|
+
const SourceClass = module.default;
|
|
43371
|
+
if (typeof SourceClass !== "function") {
|
|
43372
|
+
throw new Error(
|
|
43373
|
+
`Package reference source "${ref.source}" must have a default export that is a class or constructor function`
|
|
43374
|
+
);
|
|
43375
|
+
}
|
|
43376
|
+
const sourceInstance = new SourceClass(ref.config);
|
|
43377
|
+
const prompts = await this.discoverAndCompilePrompts(sourceInstance);
|
|
43378
|
+
return {
|
|
43379
|
+
name: ref.source,
|
|
43380
|
+
components: {},
|
|
43381
|
+
prompts,
|
|
43382
|
+
dependencies: []
|
|
43383
|
+
};
|
|
43384
|
+
}
|
|
43269
43385
|
/**
|
|
43270
43386
|
* Detect Component classes in module exports
|
|
43271
43387
|
*/
|
|
@@ -43290,6 +43406,62 @@ class ModuleLoader {
|
|
|
43290
43406
|
}
|
|
43291
43407
|
return prompts;
|
|
43292
43408
|
}
|
|
43409
|
+
/**
|
|
43410
|
+
* Normalize a source string for consistent deduplication.
|
|
43411
|
+
* Resolves relative paths to absolute, normalizes package names to lowercase.
|
|
43412
|
+
*/
|
|
43413
|
+
normalizeSource(source, type) {
|
|
43414
|
+
if (type === "local" && isNode) {
|
|
43415
|
+
try {
|
|
43416
|
+
if (source.startsWith("./") || source.startsWith("../")) {
|
|
43417
|
+
const cwd = process.cwd();
|
|
43418
|
+
return `${cwd}/${source}`.replace(/\/\.\//g, "/");
|
|
43419
|
+
}
|
|
43420
|
+
} catch {
|
|
43421
|
+
}
|
|
43422
|
+
}
|
|
43423
|
+
if (type === "npm") {
|
|
43424
|
+
const parsed = this.parsePackageSource(source);
|
|
43425
|
+
const normalizedName = parsed.name.toLowerCase();
|
|
43426
|
+
return parsed.version ? `${normalizedName}@${parsed.version}` : normalizedName;
|
|
43427
|
+
}
|
|
43428
|
+
return source;
|
|
43429
|
+
}
|
|
43430
|
+
/**
|
|
43431
|
+
* Discover and compile .prompt files from a PromptSource.
|
|
43432
|
+
* Each file is compiled through createPromptFromSource() and metadata extracted.
|
|
43433
|
+
*/
|
|
43434
|
+
async discoverAndCompilePrompts(source) {
|
|
43435
|
+
const files = await source.getPrompts();
|
|
43436
|
+
return this.compilePromptFiles(files);
|
|
43437
|
+
}
|
|
43438
|
+
/**
|
|
43439
|
+
* Clear all loaded modules (useful for testing)
|
|
43440
|
+
*/
|
|
43441
|
+
clear() {
|
|
43442
|
+
this.loaded.clear();
|
|
43443
|
+
this.loading.clear();
|
|
43444
|
+
this.versions.clear();
|
|
43445
|
+
}
|
|
43446
|
+
/**
|
|
43447
|
+
* Convert detected PuptElement prompts from JS exports into CompiledPrompt records.
|
|
43448
|
+
*/
|
|
43449
|
+
convertDetectedPrompts(detectedPrompts) {
|
|
43450
|
+
const prompts = {};
|
|
43451
|
+
for (const [exportName, element] of Object.entries(detectedPrompts)) {
|
|
43452
|
+
const props = element[PROPS];
|
|
43453
|
+
const name = (props == null ? void 0 : props.name) ?? exportName;
|
|
43454
|
+
prompts[name] = {
|
|
43455
|
+
element,
|
|
43456
|
+
id: crypto.randomUUID(),
|
|
43457
|
+
name,
|
|
43458
|
+
description: (props == null ? void 0 : props.description) ?? "",
|
|
43459
|
+
tags: (props == null ? void 0 : props.tags) ?? [],
|
|
43460
|
+
version: props == null ? void 0 : props.version
|
|
43461
|
+
};
|
|
43462
|
+
}
|
|
43463
|
+
return prompts;
|
|
43464
|
+
}
|
|
43293
43465
|
/**
|
|
43294
43466
|
* Check if a value is a PuptElement with a name prop (indicates a Prompt)
|
|
43295
43467
|
*/
|
|
@@ -43301,73 +43473,144 @@ class ModuleLoader {
|
|
|
43301
43473
|
return props !== null && typeof props === "object" && "name" in props;
|
|
43302
43474
|
}
|
|
43303
43475
|
/**
|
|
43304
|
-
*
|
|
43476
|
+
* Compile an array of discovered prompt files into CompiledPrompt records.
|
|
43305
43477
|
*/
|
|
43306
|
-
|
|
43307
|
-
|
|
43478
|
+
async compilePromptFiles(files) {
|
|
43479
|
+
const prompts = {};
|
|
43480
|
+
for (const file of files) {
|
|
43481
|
+
const element = await createPromptFromSource(file.content, file.filename);
|
|
43482
|
+
const props = element[PROPS];
|
|
43483
|
+
const name = (props == null ? void 0 : props.name) ?? file.filename.replace(/\.prompt$/, "");
|
|
43484
|
+
prompts[name] = {
|
|
43485
|
+
element,
|
|
43486
|
+
id: crypto.randomUUID(),
|
|
43487
|
+
name,
|
|
43488
|
+
description: (props == null ? void 0 : props.description) ?? "",
|
|
43489
|
+
tags: (props == null ? void 0 : props.tags) ?? [],
|
|
43490
|
+
version: props == null ? void 0 : props.version
|
|
43491
|
+
};
|
|
43492
|
+
}
|
|
43493
|
+
return prompts;
|
|
43308
43494
|
}
|
|
43309
43495
|
/**
|
|
43310
|
-
*
|
|
43311
|
-
* This is the internal implementation that can be mocked in tests.
|
|
43496
|
+
* Internal load dispatch using explicit type and passing promptDirs to prompt sources.
|
|
43312
43497
|
*/
|
|
43313
|
-
async doLoad(source) {
|
|
43314
|
-
|
|
43315
|
-
switch (sourceType) {
|
|
43498
|
+
async doLoad(type, source, promptDirs) {
|
|
43499
|
+
switch (type) {
|
|
43316
43500
|
case "local":
|
|
43317
|
-
return this.loadLocal(source);
|
|
43501
|
+
return this.loadLocal(source, promptDirs);
|
|
43318
43502
|
case "npm":
|
|
43319
|
-
return this.loadNpm(source);
|
|
43503
|
+
return this.loadNpm(source, promptDirs);
|
|
43320
43504
|
case "url":
|
|
43321
43505
|
return this.loadUrl(source);
|
|
43322
|
-
case "
|
|
43323
|
-
return this.
|
|
43506
|
+
case "git":
|
|
43507
|
+
return this.loadGit(source, promptDirs);
|
|
43324
43508
|
default:
|
|
43325
|
-
throw new Error(`Unsupported
|
|
43509
|
+
throw new Error(`Unsupported module type: ${type}`);
|
|
43326
43510
|
}
|
|
43327
43511
|
}
|
|
43328
43512
|
/**
|
|
43329
43513
|
* Load a local module
|
|
43330
43514
|
*/
|
|
43331
|
-
async loadLocal(source) {
|
|
43515
|
+
async loadLocal(source, promptDirs) {
|
|
43516
|
+
let components = {};
|
|
43517
|
+
let dependencies = [];
|
|
43518
|
+
let prompts = {};
|
|
43332
43519
|
try {
|
|
43333
43520
|
const resolvedPath = await resolveLocalPath(source);
|
|
43334
43521
|
const module = await import(
|
|
43335
43522
|
/* @vite-ignore */
|
|
43336
43523
|
resolvedPath
|
|
43337
43524
|
);
|
|
43338
|
-
|
|
43339
|
-
|
|
43340
|
-
|
|
43341
|
-
|
|
43342
|
-
|
|
43343
|
-
}
|
|
43525
|
+
components = this.detectComponents(module);
|
|
43526
|
+
dependencies = module.dependencies ?? [];
|
|
43527
|
+
const jsPrompts = this.detectPrompts(module);
|
|
43528
|
+
prompts = this.convertDetectedPrompts(jsPrompts);
|
|
43529
|
+
} catch {
|
|
43530
|
+
}
|
|
43531
|
+
if (isNode) {
|
|
43532
|
+
try {
|
|
43533
|
+
const { LocalPromptSource: LocalPromptSource2 } = await Promise.resolve().then(() => localPromptSource);
|
|
43534
|
+
const promptSource = new LocalPromptSource2(source, { promptDirs });
|
|
43535
|
+
const filePrompts = await this.discoverAndCompilePrompts(promptSource);
|
|
43536
|
+
prompts = { ...prompts, ...filePrompts };
|
|
43537
|
+
} catch {
|
|
43538
|
+
}
|
|
43539
|
+
}
|
|
43540
|
+
if (Object.keys(components).length === 0 && Object.keys(prompts).length === 0) {
|
|
43344
43541
|
throw new Error(
|
|
43345
|
-
`Failed to load local module "${source}":
|
|
43542
|
+
`Failed to load local module "${source}": no JS module or .prompt files found`
|
|
43346
43543
|
);
|
|
43347
43544
|
}
|
|
43545
|
+
return {
|
|
43546
|
+
name: this.extractNameFromPath(source),
|
|
43547
|
+
components,
|
|
43548
|
+
prompts,
|
|
43549
|
+
dependencies
|
|
43550
|
+
};
|
|
43348
43551
|
}
|
|
43349
43552
|
/**
|
|
43350
|
-
* Load an npm package
|
|
43553
|
+
* Load an npm package.
|
|
43554
|
+
* Tries to import as a JS module and additionally discovers .prompt files.
|
|
43351
43555
|
*/
|
|
43352
|
-
async loadNpm(source) {
|
|
43556
|
+
async loadNpm(source, promptDirs) {
|
|
43353
43557
|
const parsed = this.parsePackageSource(source);
|
|
43558
|
+
let components = {};
|
|
43559
|
+
let dependencies = [];
|
|
43560
|
+
let prompts = {};
|
|
43561
|
+
let jsLoaded = false;
|
|
43354
43562
|
try {
|
|
43355
43563
|
const module = await import(parsed.name);
|
|
43356
|
-
|
|
43357
|
-
|
|
43358
|
-
|
|
43359
|
-
|
|
43360
|
-
|
|
43361
|
-
} catch
|
|
43564
|
+
components = this.detectComponents(module);
|
|
43565
|
+
dependencies = module.dependencies ?? [];
|
|
43566
|
+
jsLoaded = true;
|
|
43567
|
+
const jsPrompts = this.detectPrompts(module);
|
|
43568
|
+
prompts = this.convertDetectedPrompts(jsPrompts);
|
|
43569
|
+
} catch {
|
|
43570
|
+
}
|
|
43571
|
+
if (isNode) {
|
|
43572
|
+
try {
|
|
43573
|
+
const { NpmLocalPromptSource: NpmLocalPromptSource2 } = await Promise.resolve().then(() => npmLocalPromptSource);
|
|
43574
|
+
const promptSource = new NpmLocalPromptSource2(parsed.name, { promptDirs });
|
|
43575
|
+
const filePrompts = await this.discoverAndCompilePrompts(promptSource);
|
|
43576
|
+
prompts = { ...prompts, ...filePrompts };
|
|
43577
|
+
} catch {
|
|
43578
|
+
}
|
|
43579
|
+
}
|
|
43580
|
+
if (!jsLoaded && Object.keys(prompts).length === 0) {
|
|
43362
43581
|
throw new Error(
|
|
43363
|
-
`Failed to load npm package "${source}":
|
|
43582
|
+
`Failed to load npm package "${source}": no JS module or .prompt files found`
|
|
43364
43583
|
);
|
|
43365
43584
|
}
|
|
43585
|
+
return {
|
|
43586
|
+
name: parsed.name,
|
|
43587
|
+
components,
|
|
43588
|
+
prompts,
|
|
43589
|
+
dependencies
|
|
43590
|
+
};
|
|
43591
|
+
}
|
|
43592
|
+
/**
|
|
43593
|
+
* Check if a URL looks like an npm tarball or CDN package URL.
|
|
43594
|
+
*/
|
|
43595
|
+
isTarballOrCdnUrl(url) {
|
|
43596
|
+
if (url.endsWith(".tgz")) return true;
|
|
43597
|
+
try {
|
|
43598
|
+
const parsed = new URL(url);
|
|
43599
|
+
const host = parsed.hostname;
|
|
43600
|
+
return host === "cdn.jsdelivr.net" || host === "unpkg.com" || host === "esm.sh" || host === "registry.npmjs.org";
|
|
43601
|
+
} catch {
|
|
43602
|
+
return false;
|
|
43603
|
+
}
|
|
43366
43604
|
}
|
|
43367
43605
|
/**
|
|
43368
|
-
* Load a module from a URL
|
|
43606
|
+
* Load a module from a URL.
|
|
43607
|
+
* Routes tarball/CDN URLs to NpmRegistryPromptSource for prompt discovery.
|
|
43608
|
+
* Other URLs are loaded as JS modules via dynamic import.
|
|
43369
43609
|
*/
|
|
43370
43610
|
async loadUrl(source) {
|
|
43611
|
+
if (this.isTarballOrCdnUrl(source)) {
|
|
43612
|
+
return this.loadUrlAsPromptSource(source);
|
|
43613
|
+
}
|
|
43371
43614
|
try {
|
|
43372
43615
|
const module = await import(
|
|
43373
43616
|
/* webpackIgnore: true */
|
|
@@ -43376,6 +43619,7 @@ class ModuleLoader {
|
|
|
43376
43619
|
return {
|
|
43377
43620
|
name: this.extractNameFromUrl(source),
|
|
43378
43621
|
components: this.detectComponents(module),
|
|
43622
|
+
prompts: {},
|
|
43379
43623
|
dependencies: module.dependencies ?? []
|
|
43380
43624
|
};
|
|
43381
43625
|
} catch (error) {
|
|
@@ -43385,16 +43629,60 @@ class ModuleLoader {
|
|
|
43385
43629
|
}
|
|
43386
43630
|
}
|
|
43387
43631
|
/**
|
|
43388
|
-
* Load a
|
|
43632
|
+
* Load prompts from a tarball or CDN URL via NpmRegistryPromptSource.
|
|
43633
|
+
*/
|
|
43634
|
+
async loadUrlAsPromptSource(source) {
|
|
43635
|
+
const { NpmRegistryPromptSource: NpmRegistryPromptSource2 } = await Promise.resolve().then(() => npmRegistryPromptSource);
|
|
43636
|
+
const promptSource = NpmRegistryPromptSource2.fromUrl(source);
|
|
43637
|
+
const prompts = await this.discoverAndCompilePrompts(promptSource);
|
|
43638
|
+
return {
|
|
43639
|
+
name: this.extractNameFromUrl(source),
|
|
43640
|
+
components: {},
|
|
43641
|
+
prompts,
|
|
43642
|
+
dependencies: []
|
|
43643
|
+
};
|
|
43644
|
+
}
|
|
43645
|
+
/**
|
|
43646
|
+
* Load a module from a Git source (GitHub URL).
|
|
43647
|
+
* Extracts owner/repo from the URL, tries JS import and .prompt file discovery.
|
|
43389
43648
|
*/
|
|
43390
|
-
async
|
|
43391
|
-
const match = source.match(
|
|
43649
|
+
async loadGit(source, promptDirs) {
|
|
43650
|
+
const match = source.match(/github\.com[/:]([^/]+)\/([^/.#]+)/);
|
|
43392
43651
|
if (!match) {
|
|
43393
|
-
throw new Error(`
|
|
43652
|
+
throw new Error(`Cannot extract GitHub owner/repo from source: ${source}`);
|
|
43653
|
+
}
|
|
43654
|
+
const [, owner, repo] = match;
|
|
43655
|
+
const hashIndex = source.indexOf("#");
|
|
43656
|
+
const ref = hashIndex !== -1 ? source.slice(hashIndex + 1) : void 0;
|
|
43657
|
+
let components = {};
|
|
43658
|
+
let dependencies = [];
|
|
43659
|
+
let prompts = {};
|
|
43660
|
+
try {
|
|
43661
|
+
const url = `https://raw.githubusercontent.com/${owner}/${repo}/${ref ?? "main"}/index.js`;
|
|
43662
|
+
const library = await this.loadUrl(url);
|
|
43663
|
+
components = library.components;
|
|
43664
|
+
dependencies = library.dependencies;
|
|
43665
|
+
} catch {
|
|
43666
|
+
}
|
|
43667
|
+
try {
|
|
43668
|
+
const { GitHubPromptSource: GitHubPromptSource2 } = await Promise.resolve().then(() => githubPromptSource);
|
|
43669
|
+
const ownerRepo = `${owner}/${repo}`;
|
|
43670
|
+
const options = { ref, promptDirs };
|
|
43671
|
+
const promptSource = new GitHubPromptSource2(ownerRepo, options);
|
|
43672
|
+
prompts = await this.discoverAndCompilePrompts(promptSource);
|
|
43673
|
+
} catch {
|
|
43674
|
+
}
|
|
43675
|
+
if (Object.keys(components).length === 0 && Object.keys(prompts).length === 0) {
|
|
43676
|
+
throw new Error(
|
|
43677
|
+
`Failed to load GitHub module "${source}": no JS module or .prompt files found`
|
|
43678
|
+
);
|
|
43394
43679
|
}
|
|
43395
|
-
|
|
43396
|
-
|
|
43397
|
-
|
|
43680
|
+
return {
|
|
43681
|
+
name: `${owner}/${repo}`,
|
|
43682
|
+
components,
|
|
43683
|
+
prompts,
|
|
43684
|
+
dependencies
|
|
43685
|
+
};
|
|
43398
43686
|
}
|
|
43399
43687
|
/**
|
|
43400
43688
|
* Extract a module name from a file path
|
|
@@ -43417,15 +43705,419 @@ class ModuleLoader {
|
|
|
43417
43705
|
return "unknown";
|
|
43418
43706
|
}
|
|
43419
43707
|
}
|
|
43708
|
+
}
|
|
43709
|
+
class LocalPromptSource {
|
|
43710
|
+
constructor(dirPath, options) {
|
|
43711
|
+
__publicField(this, "dirPath");
|
|
43712
|
+
__publicField(this, "promptDirs");
|
|
43713
|
+
this.dirPath = dirPath;
|
|
43714
|
+
this.promptDirs = options == null ? void 0 : options.promptDirs;
|
|
43715
|
+
}
|
|
43716
|
+
async getPrompts() {
|
|
43717
|
+
const fs = await import("fs/promises");
|
|
43718
|
+
const path = await import("path");
|
|
43719
|
+
const resolvedPath = path.resolve(this.dirPath);
|
|
43720
|
+
try {
|
|
43721
|
+
await fs.access(resolvedPath);
|
|
43722
|
+
} catch {
|
|
43723
|
+
throw new Error(`Directory not found: ${resolvedPath}`);
|
|
43724
|
+
}
|
|
43725
|
+
if (this.promptDirs && this.promptDirs.length > 0) {
|
|
43726
|
+
return this.scanPromptDirs(resolvedPath, this.promptDirs);
|
|
43727
|
+
}
|
|
43728
|
+
let scanDir = resolvedPath;
|
|
43729
|
+
const entries = await fs.readdir(resolvedPath);
|
|
43730
|
+
const hasPromptFiles = entries.some((e) => e.endsWith(".prompt"));
|
|
43731
|
+
if (!hasPromptFiles) {
|
|
43732
|
+
const promptsSubdir = path.join(resolvedPath, "prompts");
|
|
43733
|
+
try {
|
|
43734
|
+
await fs.access(promptsSubdir);
|
|
43735
|
+
scanDir = promptsSubdir;
|
|
43736
|
+
} catch {
|
|
43737
|
+
return [];
|
|
43738
|
+
}
|
|
43739
|
+
}
|
|
43740
|
+
return this.scanDirectory(scanDir);
|
|
43741
|
+
}
|
|
43420
43742
|
/**
|
|
43421
|
-
*
|
|
43743
|
+
* Scan explicit prompt directories relative to the base path.
|
|
43422
43744
|
*/
|
|
43423
|
-
|
|
43424
|
-
|
|
43425
|
-
|
|
43426
|
-
|
|
43745
|
+
async scanPromptDirs(basePath, promptDirs) {
|
|
43746
|
+
const path = await import("path");
|
|
43747
|
+
const fs = await import("fs/promises");
|
|
43748
|
+
const results = [];
|
|
43749
|
+
for (const dir of promptDirs) {
|
|
43750
|
+
const fullDir = path.join(basePath, dir);
|
|
43751
|
+
try {
|
|
43752
|
+
await fs.access(fullDir);
|
|
43753
|
+
const dirResults = await this.scanDirectory(fullDir);
|
|
43754
|
+
results.push(...dirResults);
|
|
43755
|
+
} catch {
|
|
43756
|
+
}
|
|
43757
|
+
}
|
|
43758
|
+
return results;
|
|
43759
|
+
}
|
|
43760
|
+
/**
|
|
43761
|
+
* Scan a single directory for .prompt files.
|
|
43762
|
+
*/
|
|
43763
|
+
async scanDirectory(scanDir) {
|
|
43764
|
+
const fs = await import("fs/promises");
|
|
43765
|
+
const path = await import("path");
|
|
43766
|
+
const dirEntries = await fs.readdir(scanDir);
|
|
43767
|
+
const promptFiles = dirEntries.filter((e) => e.endsWith(".prompt"));
|
|
43768
|
+
const results = [];
|
|
43769
|
+
for (const filename of promptFiles) {
|
|
43770
|
+
const filePath = path.join(scanDir, filename);
|
|
43771
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
43772
|
+
results.push({ filename, content });
|
|
43773
|
+
}
|
|
43774
|
+
return results;
|
|
43775
|
+
}
|
|
43776
|
+
}
|
|
43777
|
+
const localPromptSource = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
43778
|
+
__proto__: null,
|
|
43779
|
+
LocalPromptSource
|
|
43780
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
43781
|
+
class NpmLocalPromptSource {
|
|
43782
|
+
constructor(packageName, options) {
|
|
43783
|
+
__publicField(this, "packageName");
|
|
43784
|
+
__publicField(this, "promptDirs");
|
|
43785
|
+
this.packageName = packageName;
|
|
43786
|
+
this.promptDirs = options == null ? void 0 : options.promptDirs;
|
|
43787
|
+
}
|
|
43788
|
+
async getPrompts() {
|
|
43789
|
+
const packageDir = await this.resolvePackagePath(this.packageName);
|
|
43790
|
+
const fs = await import("fs/promises");
|
|
43791
|
+
const path = await import("path");
|
|
43792
|
+
const dirs = this.promptDirs ?? ["prompts"];
|
|
43793
|
+
const results = [];
|
|
43794
|
+
for (const dir of dirs) {
|
|
43795
|
+
const promptsDir = path.join(packageDir, dir);
|
|
43796
|
+
try {
|
|
43797
|
+
await fs.access(promptsDir);
|
|
43798
|
+
} catch {
|
|
43799
|
+
continue;
|
|
43800
|
+
}
|
|
43801
|
+
const entries = await fs.readdir(promptsDir);
|
|
43802
|
+
const promptFiles = entries.filter((e) => e.endsWith(".prompt"));
|
|
43803
|
+
for (const filename of promptFiles) {
|
|
43804
|
+
const filePath = path.join(promptsDir, filename);
|
|
43805
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
43806
|
+
results.push({ filename, content });
|
|
43807
|
+
}
|
|
43808
|
+
}
|
|
43809
|
+
return results;
|
|
43810
|
+
}
|
|
43811
|
+
/**
|
|
43812
|
+
* Resolve a bare package name to its directory path in node_modules.
|
|
43813
|
+
* Uses import.meta.resolve() when available, with createRequire fallback.
|
|
43814
|
+
*/
|
|
43815
|
+
async resolvePackagePath(packageName) {
|
|
43816
|
+
const path = await import("path");
|
|
43817
|
+
const pkgJsonSpecifier = `${packageName}/package.json`;
|
|
43818
|
+
if (typeof import.meta.resolve === "function") {
|
|
43819
|
+
try {
|
|
43820
|
+
const resolved = import.meta.resolve(pkgJsonSpecifier);
|
|
43821
|
+
const { fileURLToPath } = await import("url");
|
|
43822
|
+
const pkgJsonPath = fileURLToPath(resolved);
|
|
43823
|
+
return path.dirname(pkgJsonPath);
|
|
43824
|
+
} catch {
|
|
43825
|
+
}
|
|
43826
|
+
}
|
|
43827
|
+
try {
|
|
43828
|
+
const { createRequire } = await import("module");
|
|
43829
|
+
const esmRequire = createRequire(import.meta.url);
|
|
43830
|
+
const pkgJsonPath = esmRequire.resolve(pkgJsonSpecifier);
|
|
43831
|
+
return path.dirname(pkgJsonPath);
|
|
43832
|
+
} catch (error) {
|
|
43833
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
43834
|
+
throw new Error(
|
|
43835
|
+
`Cannot resolve npm package "${packageName}": ${message}`
|
|
43836
|
+
);
|
|
43837
|
+
}
|
|
43838
|
+
}
|
|
43839
|
+
}
|
|
43840
|
+
const npmLocalPromptSource = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
43841
|
+
__proto__: null,
|
|
43842
|
+
NpmLocalPromptSource
|
|
43843
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
43844
|
+
function parseGitHubSource(source) {
|
|
43845
|
+
const hashIndex = source.indexOf("#");
|
|
43846
|
+
let ownerRepo = source;
|
|
43847
|
+
let ref;
|
|
43848
|
+
if (hashIndex !== -1) {
|
|
43849
|
+
ownerRepo = source.slice(0, hashIndex);
|
|
43850
|
+
ref = source.slice(hashIndex + 1);
|
|
43851
|
+
}
|
|
43852
|
+
const slashIndex = ownerRepo.indexOf("/");
|
|
43853
|
+
if (slashIndex === -1) {
|
|
43854
|
+
throw new Error(`Invalid GitHub source format: expected "owner/repo", got "${source}"`);
|
|
43855
|
+
}
|
|
43856
|
+
return {
|
|
43857
|
+
owner: ownerRepo.slice(0, slashIndex),
|
|
43858
|
+
repo: ownerRepo.slice(slashIndex + 1),
|
|
43859
|
+
ref
|
|
43860
|
+
};
|
|
43861
|
+
}
|
|
43862
|
+
class GitHubPromptSource {
|
|
43863
|
+
constructor(ownerRepo, options) {
|
|
43864
|
+
__publicField(this, "owner");
|
|
43865
|
+
__publicField(this, "repo");
|
|
43866
|
+
__publicField(this, "ref");
|
|
43867
|
+
__publicField(this, "token");
|
|
43868
|
+
__publicField(this, "promptDirs");
|
|
43869
|
+
const parsed = parseGitHubSource(ownerRepo);
|
|
43870
|
+
this.owner = parsed.owner;
|
|
43871
|
+
this.repo = parsed.repo;
|
|
43872
|
+
this.ref = (options == null ? void 0 : options.ref) ?? parsed.ref ?? "main";
|
|
43873
|
+
this.token = options == null ? void 0 : options.token;
|
|
43874
|
+
this.promptDirs = options == null ? void 0 : options.promptDirs;
|
|
43875
|
+
}
|
|
43876
|
+
async getPrompts() {
|
|
43877
|
+
const tree = await this.fetchTree();
|
|
43878
|
+
const promptEntries = this.filterPromptFiles(tree);
|
|
43879
|
+
if (promptEntries.length === 0) {
|
|
43880
|
+
return [];
|
|
43881
|
+
}
|
|
43882
|
+
const results = [];
|
|
43883
|
+
for (const entry of promptEntries) {
|
|
43884
|
+
const content = await this.fetchFileContent(entry.path);
|
|
43885
|
+
const filename = entry.path.split("/").pop();
|
|
43886
|
+
results.push({ filename, content });
|
|
43887
|
+
}
|
|
43888
|
+
return results;
|
|
43889
|
+
}
|
|
43890
|
+
async fetchTree() {
|
|
43891
|
+
var _a2;
|
|
43892
|
+
const url = `https://api.github.com/repos/${this.owner}/${this.repo}/git/trees/${this.ref}?recursive=1`;
|
|
43893
|
+
let response;
|
|
43894
|
+
try {
|
|
43895
|
+
response = await fetch(url, { headers: this.getHeaders() });
|
|
43896
|
+
} catch (error) {
|
|
43897
|
+
throw new Error(
|
|
43898
|
+
`Failed to fetch GitHub tree for ${this.owner}/${this.repo}: ${error instanceof Error ? error.message : String(error)}`
|
|
43899
|
+
);
|
|
43900
|
+
}
|
|
43901
|
+
if (response.status === 403) {
|
|
43902
|
+
const body = await response.json();
|
|
43903
|
+
if ((_a2 = body.message) == null ? void 0 : _a2.toLowerCase().includes("rate limit")) {
|
|
43904
|
+
throw new Error(`GitHub API rate limit exceeded for ${this.owner}/${this.repo}`);
|
|
43905
|
+
}
|
|
43906
|
+
throw new Error(`GitHub API access forbidden for ${this.owner}/${this.repo}: ${body.message ?? "Unknown error"}`);
|
|
43907
|
+
}
|
|
43908
|
+
if (!response.ok) {
|
|
43909
|
+
throw new Error(
|
|
43910
|
+
`Failed to fetch GitHub tree for ${this.owner}/${this.repo}: HTTP ${response.status}`
|
|
43911
|
+
);
|
|
43912
|
+
}
|
|
43913
|
+
const data = await response.json();
|
|
43914
|
+
return data.tree;
|
|
43915
|
+
}
|
|
43916
|
+
filterPromptFiles(tree) {
|
|
43917
|
+
const dirs = this.promptDirs ?? ["prompts"];
|
|
43918
|
+
return tree.filter(
|
|
43919
|
+
(entry) => entry.type === "blob" && entry.path.endsWith(".prompt") && dirs.some((dir) => {
|
|
43920
|
+
const prefix = dir.endsWith("/") ? dir : `${dir}/`;
|
|
43921
|
+
return entry.path.startsWith(prefix);
|
|
43922
|
+
})
|
|
43923
|
+
);
|
|
43924
|
+
}
|
|
43925
|
+
async fetchFileContent(path) {
|
|
43926
|
+
const url = `https://raw.githubusercontent.com/${this.owner}/${this.repo}/${this.ref}/${path}`;
|
|
43927
|
+
let response;
|
|
43928
|
+
try {
|
|
43929
|
+
response = await fetch(url, { headers: this.getHeaders() });
|
|
43930
|
+
} catch (error) {
|
|
43931
|
+
throw new Error(
|
|
43932
|
+
`Failed to fetch file ${path} from ${this.owner}/${this.repo}: ${error instanceof Error ? error.message : String(error)}`
|
|
43933
|
+
);
|
|
43934
|
+
}
|
|
43935
|
+
if (!response.ok) {
|
|
43936
|
+
throw new Error(
|
|
43937
|
+
`Failed to fetch file ${path} from ${this.owner}/${this.repo}: HTTP ${response.status}`
|
|
43938
|
+
);
|
|
43939
|
+
}
|
|
43940
|
+
return response.text();
|
|
43941
|
+
}
|
|
43942
|
+
getHeaders() {
|
|
43943
|
+
const headers = {
|
|
43944
|
+
"Accept": "application/vnd.github.v3+json"
|
|
43945
|
+
};
|
|
43946
|
+
if (this.token) {
|
|
43947
|
+
headers["Authorization"] = `token ${this.token}`;
|
|
43948
|
+
}
|
|
43949
|
+
return headers;
|
|
43950
|
+
}
|
|
43951
|
+
}
|
|
43952
|
+
const githubPromptSource = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
43953
|
+
__proto__: null,
|
|
43954
|
+
GitHubPromptSource,
|
|
43955
|
+
parseGitHubSource
|
|
43956
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
43957
|
+
async function decompressGzip(compressed) {
|
|
43958
|
+
const stream = new DecompressionStream("gzip");
|
|
43959
|
+
const writer = stream.writable.getWriter();
|
|
43960
|
+
writer.write(new Uint8Array(compressed));
|
|
43961
|
+
writer.close();
|
|
43962
|
+
const reader = stream.readable.getReader();
|
|
43963
|
+
const chunks = [];
|
|
43964
|
+
let totalLength = 0;
|
|
43965
|
+
while (true) {
|
|
43966
|
+
const { done, value } = await reader.read();
|
|
43967
|
+
if (done) break;
|
|
43968
|
+
chunks.push(value);
|
|
43969
|
+
totalLength += value.length;
|
|
43970
|
+
}
|
|
43971
|
+
const result = new Uint8Array(totalLength);
|
|
43972
|
+
let offset = 0;
|
|
43973
|
+
for (const chunk of chunks) {
|
|
43974
|
+
result.set(chunk, offset);
|
|
43975
|
+
offset += chunk.length;
|
|
43976
|
+
}
|
|
43977
|
+
return result.buffer;
|
|
43978
|
+
}
|
|
43979
|
+
function parseTar(buffer) {
|
|
43980
|
+
const data = new Uint8Array(buffer);
|
|
43981
|
+
const entries = [];
|
|
43982
|
+
let offset = 0;
|
|
43983
|
+
while (offset + 512 <= data.length) {
|
|
43984
|
+
const header = data.slice(offset, offset + 512);
|
|
43985
|
+
if (header.every((b) => b === 0)) {
|
|
43986
|
+
break;
|
|
43987
|
+
}
|
|
43988
|
+
const name = readString(header, 0, 100);
|
|
43989
|
+
const sizeStr = readString(header, 124, 12);
|
|
43990
|
+
const size = parseInt(sizeStr, 8) || 0;
|
|
43991
|
+
const typeFlag = header[156];
|
|
43992
|
+
offset += 512;
|
|
43993
|
+
if ((typeFlag === 48 || typeFlag === 0) && size > 0) {
|
|
43994
|
+
const content = data.slice(offset, offset + size);
|
|
43995
|
+
entries.push({ name, size, content });
|
|
43996
|
+
}
|
|
43997
|
+
offset += Math.ceil(size / 512) * 512;
|
|
43998
|
+
}
|
|
43999
|
+
return entries;
|
|
44000
|
+
}
|
|
44001
|
+
function readString(data, offset, maxLength) {
|
|
44002
|
+
let end = offset;
|
|
44003
|
+
while (end < offset + maxLength && data[end] !== 0) {
|
|
44004
|
+
end++;
|
|
44005
|
+
}
|
|
44006
|
+
return new TextDecoder("ascii").decode(data.slice(offset, end)).trim();
|
|
44007
|
+
}
|
|
44008
|
+
async function extractPromptFiles(tarballBuffer) {
|
|
44009
|
+
const decompressed = await decompressGzip(tarballBuffer);
|
|
44010
|
+
const entries = parseTar(decompressed);
|
|
44011
|
+
const promptFiles = [];
|
|
44012
|
+
for (const entry of entries) {
|
|
44013
|
+
const normalizedName = entry.name.replace(/^package\//, "");
|
|
44014
|
+
if (normalizedName.startsWith("prompts/") && normalizedName.endsWith(".prompt")) {
|
|
44015
|
+
const filename = normalizedName.split("/").pop();
|
|
44016
|
+
const content = new TextDecoder("utf-8").decode(entry.content);
|
|
44017
|
+
promptFiles.push({ filename, content });
|
|
44018
|
+
}
|
|
44019
|
+
}
|
|
44020
|
+
return promptFiles;
|
|
44021
|
+
}
|
|
44022
|
+
class NpmRegistryPromptSource {
|
|
44023
|
+
constructor(specifier, options) {
|
|
44024
|
+
__publicField(this, "packageName");
|
|
44025
|
+
__publicField(this, "version");
|
|
44026
|
+
__publicField(this, "tarballUrl");
|
|
44027
|
+
__publicField(this, "registryUrl");
|
|
44028
|
+
this.registryUrl = (options == null ? void 0 : options.registryUrl) ?? "https://registry.npmjs.org";
|
|
44029
|
+
if (specifier.startsWith("https://") || specifier.startsWith("http://")) {
|
|
44030
|
+
this.tarballUrl = specifier;
|
|
44031
|
+
} else {
|
|
44032
|
+
const { name, version } = this.parseSpecifier(specifier);
|
|
44033
|
+
this.packageName = name;
|
|
44034
|
+
this.version = version;
|
|
44035
|
+
}
|
|
44036
|
+
}
|
|
44037
|
+
/**
|
|
44038
|
+
* Create an NpmRegistryPromptSource from a direct tarball URL.
|
|
44039
|
+
*/
|
|
44040
|
+
static fromUrl(url) {
|
|
44041
|
+
return new NpmRegistryPromptSource(url);
|
|
44042
|
+
}
|
|
44043
|
+
async getPrompts() {
|
|
44044
|
+
const tarballUrl = this.tarballUrl ?? await this.resolveTarballUrl();
|
|
44045
|
+
const tarballBuffer = await this.downloadTarball(tarballUrl);
|
|
44046
|
+
return extractPromptFiles(tarballBuffer);
|
|
44047
|
+
}
|
|
44048
|
+
/**
|
|
44049
|
+
* Parse a package specifier into name and optional version.
|
|
44050
|
+
*/
|
|
44051
|
+
parseSpecifier(specifier) {
|
|
44052
|
+
if (specifier.startsWith("@")) {
|
|
44053
|
+
const atIndex2 = specifier.indexOf("@", 1);
|
|
44054
|
+
if (atIndex2 !== -1) {
|
|
44055
|
+
return {
|
|
44056
|
+
name: specifier.slice(0, atIndex2),
|
|
44057
|
+
version: specifier.slice(atIndex2 + 1)
|
|
44058
|
+
};
|
|
44059
|
+
}
|
|
44060
|
+
return { name: specifier };
|
|
44061
|
+
}
|
|
44062
|
+
const atIndex = specifier.indexOf("@");
|
|
44063
|
+
if (atIndex !== -1) {
|
|
44064
|
+
return {
|
|
44065
|
+
name: specifier.slice(0, atIndex),
|
|
44066
|
+
version: specifier.slice(atIndex + 1)
|
|
44067
|
+
};
|
|
44068
|
+
}
|
|
44069
|
+
return { name: specifier };
|
|
44070
|
+
}
|
|
44071
|
+
/**
|
|
44072
|
+
* Resolve the tarball URL by fetching package metadata from the registry.
|
|
44073
|
+
*/
|
|
44074
|
+
async resolveTarballUrl() {
|
|
44075
|
+
var _a2;
|
|
44076
|
+
const version = this.version ?? "latest";
|
|
44077
|
+
const url = `${this.registryUrl}/${this.packageName}/${version}`;
|
|
44078
|
+
let response;
|
|
44079
|
+
try {
|
|
44080
|
+
response = await fetch(url);
|
|
44081
|
+
} catch (error) {
|
|
44082
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
44083
|
+
throw new Error(`Fetch failed for "${this.packageName}@${version}": ${message}`);
|
|
44084
|
+
}
|
|
44085
|
+
if (!response.ok) {
|
|
44086
|
+
throw new Error(
|
|
44087
|
+
`Fetch failed for "${this.packageName}@${version}": HTTP ${response.status} ${response.statusText}`
|
|
44088
|
+
);
|
|
44089
|
+
}
|
|
44090
|
+
const metadata = await response.json();
|
|
44091
|
+
if (!((_a2 = metadata.dist) == null ? void 0 : _a2.tarball)) {
|
|
44092
|
+
throw new Error(
|
|
44093
|
+
`No tarball URL found in registry metadata for "${this.packageName}@${version}"`
|
|
44094
|
+
);
|
|
44095
|
+
}
|
|
44096
|
+
return metadata.dist.tarball;
|
|
44097
|
+
}
|
|
44098
|
+
/**
|
|
44099
|
+
* Download a tarball from the given URL.
|
|
44100
|
+
*/
|
|
44101
|
+
async downloadTarball(url) {
|
|
44102
|
+
let response;
|
|
44103
|
+
try {
|
|
44104
|
+
response = await fetch(url);
|
|
44105
|
+
} catch (error) {
|
|
44106
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
44107
|
+
throw new Error(`Fetch failed for tarball at "${url}": ${message}`);
|
|
44108
|
+
}
|
|
44109
|
+
if (!response.ok) {
|
|
44110
|
+
throw new Error(
|
|
44111
|
+
`Fetch failed for tarball at "${url}": HTTP ${response.status} ${response.statusText}`
|
|
44112
|
+
);
|
|
44113
|
+
}
|
|
44114
|
+
return response.arrayBuffer();
|
|
43427
44115
|
}
|
|
43428
44116
|
}
|
|
44117
|
+
const npmRegistryPromptSource = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
44118
|
+
__proto__: null,
|
|
44119
|
+
NpmRegistryPromptSource
|
|
44120
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
43429
44121
|
const CDN_TEMPLATES = {
|
|
43430
44122
|
"esm.sh": "https://esm.sh/{name}@{version}",
|
|
43431
44123
|
"unpkg": "https://unpkg.com/{name}@{version}",
|
|
@@ -43515,18 +44207,7 @@ class Role extends Component {
|
|
|
43515
44207
|
children
|
|
43516
44208
|
} = props;
|
|
43517
44209
|
if (this.hasContent(children)) {
|
|
43518
|
-
|
|
43519
|
-
if (expertise) {
|
|
43520
|
-
const expertiseStr = Array.isArray(expertise) ? expertise.join(", ") : expertise;
|
|
43521
|
-
parts2.push(`
|
|
43522
|
-
with expertise in ${expertiseStr}`);
|
|
43523
|
-
}
|
|
43524
|
-
if (domain) {
|
|
43525
|
-
parts2.push(`
|
|
43526
|
-
specializing in the ${domain} domain`);
|
|
43527
|
-
}
|
|
43528
|
-
const content = parts2.length === 1 ? parts2[0] : parts2;
|
|
43529
|
-
return wrapWithDelimiter(content, "role", delimiter);
|
|
44210
|
+
return wrapWithDelimiter(children, "role", delimiter);
|
|
43530
44211
|
}
|
|
43531
44212
|
const config = preset ? ROLE_PRESETS[preset] : void 0;
|
|
43532
44213
|
const provider = this.getProvider(context);
|
|
@@ -43962,6 +44643,37 @@ class References extends Component {
|
|
|
43962
44643
|
}
|
|
43963
44644
|
}
|
|
43964
44645
|
__publicField(References, "schema", referencesSchema);
|
|
44646
|
+
const chainOfThoughtSchema = objectType({
|
|
44647
|
+
style: enumType(["step-by-step", "think-aloud", "structured", "minimal"]).optional(),
|
|
44648
|
+
showReasoning: booleanType().optional(),
|
|
44649
|
+
delimiter: enumType(["xml", "markdown", "none"]).optional()
|
|
44650
|
+
}).passthrough();
|
|
44651
|
+
const STYLE_INSTRUCTIONS = {
|
|
44652
|
+
"step-by-step": "Think through this step by step before providing your answer.",
|
|
44653
|
+
"think-aloud": "Reason through your thought process as you work on this.",
|
|
44654
|
+
"structured": "Break down your reasoning into: 1) Understanding, 2) Analysis, 3) Conclusion.",
|
|
44655
|
+
"minimal": "Consider the problem carefully before answering."
|
|
44656
|
+
};
|
|
44657
|
+
class ChainOfThought extends Component {
|
|
44658
|
+
render(props, _resolvedValue, _context) {
|
|
44659
|
+
const { style = "step-by-step", showReasoning = true, delimiter = "xml", children } = props;
|
|
44660
|
+
const sections = [];
|
|
44661
|
+
if (this.hasContent(children)) {
|
|
44662
|
+
const parts = [children];
|
|
44663
|
+
if (showReasoning) {
|
|
44664
|
+
parts.push("\nShow your reasoning process.");
|
|
44665
|
+
}
|
|
44666
|
+
return wrapWithDelimiter(parts, "reasoning", delimiter);
|
|
44667
|
+
}
|
|
44668
|
+
sections.push(STYLE_INSTRUCTIONS[style]);
|
|
44669
|
+
if (showReasoning) {
|
|
44670
|
+
sections.push("Show your reasoning process.");
|
|
44671
|
+
}
|
|
44672
|
+
const content = sections.join("\n");
|
|
44673
|
+
return wrapWithDelimiter(content, "reasoning", delimiter);
|
|
44674
|
+
}
|
|
44675
|
+
}
|
|
44676
|
+
__publicField(ChainOfThought, "schema", chainOfThoughtSchema);
|
|
43965
44677
|
const promptDefaultsObjectSchema = objectType({
|
|
43966
44678
|
role: booleanType().optional(),
|
|
43967
44679
|
format: booleanType().optional(),
|
|
@@ -44028,7 +44740,7 @@ class Prompt extends Component {
|
|
|
44028
44740
|
component: "Prompt",
|
|
44029
44741
|
prop: null,
|
|
44030
44742
|
message: "Prompt has no Task child. Consider adding a <Task> element to define the objective.",
|
|
44031
|
-
code: "
|
|
44743
|
+
code: "warn_missing_task",
|
|
44032
44744
|
path: []
|
|
44033
44745
|
});
|
|
44034
44746
|
}
|
|
@@ -44039,6 +44751,23 @@ class Prompt extends Component {
|
|
|
44039
44751
|
findChildrenOfType(childArray, EdgeCases).length > 0;
|
|
44040
44752
|
findChildrenOfType(childArray, Fallbacks).length > 0;
|
|
44041
44753
|
findChildrenOfType(childArray, References).length > 0;
|
|
44754
|
+
if (hasFormat) {
|
|
44755
|
+
const formatElements = findChildrenOfType(childArray, Format);
|
|
44756
|
+
const cotElements = findChildrenOfType(childArray, ChainOfThought);
|
|
44757
|
+
if (cotElements.length > 0) {
|
|
44758
|
+
const formatIsStrict = formatElements.some((el) => el[PROPS].strict === true);
|
|
44759
|
+
const cotShowsReasoning = cotElements.some((el) => el[PROPS].showReasoning !== false);
|
|
44760
|
+
if (formatIsStrict && cotShowsReasoning) {
|
|
44761
|
+
context.errors.push({
|
|
44762
|
+
component: "Prompt",
|
|
44763
|
+
prop: null,
|
|
44764
|
+
message: "<Format strict> and <ChainOfThought showReasoning> produce contradictory instructions. Format strict tells the LLM to return ONLY formatted output, while ChainOfThought asks it to show reasoning. Consider setting showReasoning={false} or removing strict.",
|
|
44765
|
+
code: "warn_conflicting_instructions",
|
|
44766
|
+
path: []
|
|
44767
|
+
});
|
|
44768
|
+
}
|
|
44769
|
+
}
|
|
44770
|
+
}
|
|
44042
44771
|
const sections = [];
|
|
44043
44772
|
const includeRole = this.shouldIncludeSection(resolvedDefaults.role, promptConfig.includeRole);
|
|
44044
44773
|
if (includeRole && !hasRole) {
|
|
@@ -45674,37 +46403,6 @@ class Steps extends Component {
|
|
|
45674
46403
|
}
|
|
45675
46404
|
}
|
|
45676
46405
|
__publicField(Steps, "schema", stepsSchema);
|
|
45677
|
-
const chainOfThoughtSchema = objectType({
|
|
45678
|
-
style: enumType(["step-by-step", "think-aloud", "structured", "minimal"]).optional(),
|
|
45679
|
-
showReasoning: booleanType().optional(),
|
|
45680
|
-
delimiter: enumType(["xml", "markdown", "none"]).optional()
|
|
45681
|
-
}).passthrough();
|
|
45682
|
-
const STYLE_INSTRUCTIONS = {
|
|
45683
|
-
"step-by-step": "Think through this step by step before providing your answer.",
|
|
45684
|
-
"think-aloud": "Reason through your thought process as you work on this.",
|
|
45685
|
-
"structured": "Break down your reasoning into: 1) Understanding, 2) Analysis, 3) Conclusion.",
|
|
45686
|
-
"minimal": "Consider the problem carefully before answering."
|
|
45687
|
-
};
|
|
45688
|
-
class ChainOfThought extends Component {
|
|
45689
|
-
render(props, _resolvedValue, _context) {
|
|
45690
|
-
const { style = "step-by-step", showReasoning = true, delimiter = "xml", children } = props;
|
|
45691
|
-
const sections = [];
|
|
45692
|
-
if (this.hasContent(children)) {
|
|
45693
|
-
const parts = [children];
|
|
45694
|
-
if (showReasoning) {
|
|
45695
|
-
parts.push("\nShow your reasoning process.");
|
|
45696
|
-
}
|
|
45697
|
-
return wrapWithDelimiter(parts, "reasoning", delimiter);
|
|
45698
|
-
}
|
|
45699
|
-
sections.push(STYLE_INSTRUCTIONS[style]);
|
|
45700
|
-
if (showReasoning) {
|
|
45701
|
-
sections.push("Show your reasoning process.");
|
|
45702
|
-
}
|
|
45703
|
-
const content = sections.join("\n");
|
|
45704
|
-
return wrapWithDelimiter(content, "reasoning", delimiter);
|
|
45705
|
-
}
|
|
45706
|
-
}
|
|
45707
|
-
__publicField(ChainOfThought, "schema", chainOfThoughtSchema);
|
|
45708
46406
|
const codeSchema = objectType({
|
|
45709
46407
|
language: stringType().optional(),
|
|
45710
46408
|
filename: stringType().optional()
|
|
@@ -45981,49 +46679,6 @@ const _allComponentExports = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Objec
|
|
|
45981
46679
|
WhenUncertain,
|
|
45982
46680
|
Xml
|
|
45983
46681
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
45984
|
-
const CUSTOM_COMPONENTS_GLOBAL = "__PUPT_CUSTOM_COMPONENTS__";
|
|
45985
|
-
async function createPromptFromSource(source, filename, options = {}) {
|
|
45986
|
-
const { components } = options;
|
|
45987
|
-
let processedSource = preprocessSource(source, { filename });
|
|
45988
|
-
if (components && Object.keys(components).length > 0) {
|
|
45989
|
-
globalThis[CUSTOM_COMPONENTS_GLOBAL] = components;
|
|
45990
|
-
const componentNames = Object.keys(components);
|
|
45991
|
-
const extractCode = `const { ${componentNames.join(", ")} } = globalThis.${CUSTOM_COMPONENTS_GLOBAL};
|
|
45992
|
-
`;
|
|
45993
|
-
let lastImportEnd = 0;
|
|
45994
|
-
const fullImportRegex = /import\s+(?:(?:\{[^}]*\}|[^;{]*)\s+from\s+)?['"][^'"]+['"];?/g;
|
|
45995
|
-
let match;
|
|
45996
|
-
while ((match = fullImportRegex.exec(processedSource)) !== null) {
|
|
45997
|
-
const matchEnd = match.index + match[0].length;
|
|
45998
|
-
if (matchEnd > lastImportEnd) {
|
|
45999
|
-
lastImportEnd = matchEnd;
|
|
46000
|
-
}
|
|
46001
|
-
}
|
|
46002
|
-
if (lastImportEnd > 0) {
|
|
46003
|
-
processedSource = processedSource.slice(0, lastImportEnd) + "\n" + extractCode + processedSource.slice(lastImportEnd);
|
|
46004
|
-
} else {
|
|
46005
|
-
processedSource = extractCode + processedSource;
|
|
46006
|
-
}
|
|
46007
|
-
}
|
|
46008
|
-
try {
|
|
46009
|
-
const transformer = new Transformer2();
|
|
46010
|
-
const code = await transformer.transformSourceAsync(processedSource, filename);
|
|
46011
|
-
const module = await evaluateModule(code, { filename });
|
|
46012
|
-
if (module.default === void 0) {
|
|
46013
|
-
throw new Error(`${filename} must have a default export`);
|
|
46014
|
-
}
|
|
46015
|
-
return module.default;
|
|
46016
|
-
} finally {
|
|
46017
|
-
if (components) {
|
|
46018
|
-
delete globalThis[CUSTOM_COMPONENTS_GLOBAL];
|
|
46019
|
-
}
|
|
46020
|
-
}
|
|
46021
|
-
}
|
|
46022
|
-
async function createPrompt(filePath, options = {}) {
|
|
46023
|
-
const { readFile } = await import("fs/promises");
|
|
46024
|
-
const source = await readFile(filePath, "utf-8");
|
|
46025
|
-
return createPromptFromSource(source, filePath, options);
|
|
46026
|
-
}
|
|
46027
46682
|
const ENTRIES = "ENTRIES";
|
|
46028
46683
|
const KEYS = "KEYS";
|
|
46029
46684
|
const VALUES = "VALUES";
|
|
@@ -47903,6 +48558,7 @@ class Pupt {
|
|
|
47903
48558
|
__publicField(this, "moduleLoader", new ModuleLoader());
|
|
47904
48559
|
__publicField(this, "searchEngine");
|
|
47905
48560
|
__publicField(this, "prompts", []);
|
|
48561
|
+
__publicField(this, "warnings", []);
|
|
47906
48562
|
__publicField(this, "initialized", false);
|
|
47907
48563
|
this.config = config;
|
|
47908
48564
|
this.searchEngine = createSearchEngine(config.searchConfig);
|
|
@@ -47929,6 +48585,9 @@ class Pupt {
|
|
|
47929
48585
|
getPrompt(name) {
|
|
47930
48586
|
return this.prompts.find((p) => p.name === name);
|
|
47931
48587
|
}
|
|
48588
|
+
getPromptById(id) {
|
|
48589
|
+
return this.prompts.find((p) => p.id === id);
|
|
48590
|
+
}
|
|
47932
48591
|
searchPrompts(query, options) {
|
|
47933
48592
|
return this.searchEngine.search(query, options);
|
|
47934
48593
|
}
|
|
@@ -47938,45 +48597,73 @@ class Pupt {
|
|
|
47938
48597
|
getPromptsByTag(tag) {
|
|
47939
48598
|
return this.prompts.filter((p) => p.tags.includes(tag));
|
|
47940
48599
|
}
|
|
48600
|
+
getWarnings() {
|
|
48601
|
+
return [...this.warnings];
|
|
48602
|
+
}
|
|
47941
48603
|
async discoverPrompts() {
|
|
47942
48604
|
const discovered = [];
|
|
47943
|
-
|
|
47944
|
-
|
|
48605
|
+
const processedLibraries = /* @__PURE__ */ new Set();
|
|
48606
|
+
for (const entry of this.config.modules ?? []) {
|
|
47945
48607
|
try {
|
|
47946
|
-
const
|
|
47947
|
-
|
|
47948
|
-
if (
|
|
47949
|
-
|
|
47950
|
-
const props = element[PROPS];
|
|
47951
|
-
const prompt = this.createDiscoveredPrompt(
|
|
47952
|
-
props.name,
|
|
47953
|
-
props.description ?? "",
|
|
47954
|
-
props.tags ?? [],
|
|
47955
|
-
library.name,
|
|
47956
|
-
element
|
|
47957
|
-
);
|
|
47958
|
-
discovered.push(prompt);
|
|
48608
|
+
const dedupKey = this.getEntryDedupKey(entry);
|
|
48609
|
+
if (dedupKey !== null) {
|
|
48610
|
+
if (processedLibraries.has(dedupKey)) {
|
|
48611
|
+
continue;
|
|
47959
48612
|
}
|
|
48613
|
+
processedLibraries.add(dedupKey);
|
|
48614
|
+
}
|
|
48615
|
+
const library = await this.moduleLoader.loadEntry(entry);
|
|
48616
|
+
for (const compiled of Object.values(library.prompts)) {
|
|
48617
|
+
const prompt = this.createDiscoveredPrompt(
|
|
48618
|
+
compiled.id,
|
|
48619
|
+
compiled.name,
|
|
48620
|
+
compiled.description,
|
|
48621
|
+
compiled.tags,
|
|
48622
|
+
library.name,
|
|
48623
|
+
compiled.element
|
|
48624
|
+
);
|
|
48625
|
+
discovered.push(prompt);
|
|
47960
48626
|
}
|
|
47961
|
-
} catch {
|
|
48627
|
+
} catch (error) {
|
|
48628
|
+
const sourceId = this.getEntryDisplayName(entry);
|
|
48629
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
48630
|
+
this.warnings.push(`Failed to load module "${sourceId}": ${message}`);
|
|
47962
48631
|
}
|
|
47963
48632
|
}
|
|
47964
48633
|
return discovered;
|
|
47965
48634
|
}
|
|
47966
|
-
|
|
48635
|
+
/**
|
|
48636
|
+
* Get a deduplication key for a module entry.
|
|
48637
|
+
* Returns null for PromptSource instances (cannot be deduplicated).
|
|
48638
|
+
*/
|
|
48639
|
+
getEntryDedupKey(entry) {
|
|
48640
|
+
if (isPromptSource(entry)) {
|
|
48641
|
+
return null;
|
|
48642
|
+
}
|
|
48643
|
+
if (isResolvedModuleEntry(entry)) {
|
|
48644
|
+
return this.moduleLoader.normalizeSource(entry.source, entry.type);
|
|
48645
|
+
}
|
|
48646
|
+
if (typeof entry === "object" && entry !== null && "source" in entry && "config" in entry) {
|
|
48647
|
+
const ref = entry;
|
|
48648
|
+
return `pkg:${ref.source}:${JSON.stringify(ref.config)}`;
|
|
48649
|
+
}
|
|
48650
|
+
return null;
|
|
48651
|
+
}
|
|
48652
|
+
/**
|
|
48653
|
+
* Get a human-readable display name for a module entry (used in error messages).
|
|
48654
|
+
*/
|
|
48655
|
+
getEntryDisplayName(entry) {
|
|
47967
48656
|
var _a2;
|
|
47968
|
-
|
|
47969
|
-
|
|
47970
|
-
|
|
47971
|
-
|
|
47972
|
-
|
|
47973
|
-
|
|
47974
|
-
|
|
47975
|
-
|
|
47976
|
-
fileUrl
|
|
47977
|
-
);
|
|
48657
|
+
if (isPromptSource(entry)) {
|
|
48658
|
+
return ((_a2 = entry.constructor) == null ? void 0 : _a2.name) ?? "PromptSource";
|
|
48659
|
+
}
|
|
48660
|
+
if (isResolvedModuleEntry(entry)) {
|
|
48661
|
+
return entry.name;
|
|
48662
|
+
}
|
|
48663
|
+
if (typeof entry === "object" && entry !== null && "source" in entry) {
|
|
48664
|
+
return `{ source: ${entry.source} }`;
|
|
47978
48665
|
}
|
|
47979
|
-
return
|
|
48666
|
+
return "unknown";
|
|
47980
48667
|
}
|
|
47981
48668
|
isPromptElement(value) {
|
|
47982
48669
|
if (!isPuptElement(value)) {
|
|
@@ -47985,8 +48672,9 @@ class Pupt {
|
|
|
47985
48672
|
const props = value[PROPS];
|
|
47986
48673
|
return props !== null && typeof props === "object" && "name" in props;
|
|
47987
48674
|
}
|
|
47988
|
-
createDiscoveredPrompt(name, description, tags, library, element) {
|
|
48675
|
+
createDiscoveredPrompt(id, name, description, tags, library, element) {
|
|
47989
48676
|
return {
|
|
48677
|
+
id,
|
|
47990
48678
|
name,
|
|
47991
48679
|
description,
|
|
47992
48680
|
tags,
|
|
@@ -48348,14 +49036,18 @@ export {
|
|
|
48348
49036
|
FileSearchEngine,
|
|
48349
49037
|
ForEach,
|
|
48350
49038
|
Format,
|
|
49039
|
+
GitHubPromptSource,
|
|
48351
49040
|
Guardrails,
|
|
48352
49041
|
Hostname,
|
|
48353
49042
|
If,
|
|
48354
49043
|
Json,
|
|
48355
49044
|
LANGUAGE_CONVENTIONS,
|
|
48356
49045
|
LLM_PROVIDERS,
|
|
49046
|
+
LocalPromptSource,
|
|
48357
49047
|
ModuleLoader,
|
|
48358
49048
|
NegativeExample,
|
|
49049
|
+
NpmLocalPromptSource,
|
|
49050
|
+
NpmRegistryPromptSource,
|
|
48359
49051
|
Objective,
|
|
48360
49052
|
OpenUrl,
|
|
48361
49053
|
PROPS,
|
|
@@ -48416,8 +49108,11 @@ export {
|
|
|
48416
49108
|
isDeferredRef,
|
|
48417
49109
|
isElementOfType,
|
|
48418
49110
|
isPromptFile,
|
|
49111
|
+
isPromptSource,
|
|
48419
49112
|
isPuptElement,
|
|
49113
|
+
isWarningCode,
|
|
48420
49114
|
loadNodeModules,
|
|
49115
|
+
parseGitHubSource,
|
|
48421
49116
|
partitionChildren,
|
|
48422
49117
|
preprocessSource,
|
|
48423
49118
|
render,
|