langwatch 0.3.0 → 0.3.1
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/add-LBBS4I3H.js +114 -0
- package/dist/add-LBBS4I3H.js.map +1 -0
- package/dist/add-RD3ZKFAT.mjs +114 -0
- package/dist/add-RD3ZKFAT.mjs.map +1 -0
- package/dist/chunk-2JU376G7.js +242 -0
- package/dist/chunk-2JU376G7.js.map +1 -0
- package/dist/chunk-2ODBGSBI.js +4 -0
- package/dist/{chunk-G3AUABT7.js.map → chunk-2ODBGSBI.js.map} +1 -1
- package/dist/chunk-3GKPQB4R.mjs +242 -0
- package/dist/chunk-3GKPQB4R.mjs.map +1 -0
- package/dist/chunk-4NRLVT2U.mjs +35 -0
- package/dist/chunk-4NRLVT2U.mjs.map +1 -0
- package/dist/{chunk-SVJ7SCGB.js → chunk-52GXX3MA.js} +33 -31
- package/dist/chunk-52GXX3MA.js.map +1 -0
- package/dist/chunk-5NC5ILKA.js +94 -0
- package/dist/chunk-5NC5ILKA.js.map +1 -0
- package/dist/{chunk-76KNOWLS.js → chunk-6I4EA43Y.js} +2 -2
- package/dist/chunk-6I4EA43Y.js.map +1 -0
- package/dist/chunk-DHJKJVY7.mjs +20 -0
- package/dist/chunk-DHJKJVY7.mjs.map +1 -0
- package/dist/{chunk-VJSOCNPA.js → chunk-DTEKFQ4U.js} +6 -28
- package/dist/chunk-DTEKFQ4U.js.map +1 -0
- package/dist/chunk-E7UE2MPD.mjs +93 -0
- package/dist/chunk-E7UE2MPD.mjs.map +1 -0
- package/dist/chunk-F6E4XQQU.js +20 -0
- package/dist/chunk-F6E4XQQU.js.map +1 -0
- package/dist/chunk-FJLK5CFL.js +37 -0
- package/dist/chunk-FJLK5CFL.js.map +1 -0
- package/dist/{chunk-Z5J5UI5E.mjs → chunk-GJSEBQXF.mjs} +139 -107
- package/dist/chunk-GJSEBQXF.mjs.map +1 -0
- package/dist/chunk-HA3LI5IK.js +35 -0
- package/dist/chunk-HA3LI5IK.js.map +1 -0
- package/dist/chunk-HJU67C7H.js +93 -0
- package/dist/chunk-HJU67C7H.js.map +1 -0
- package/dist/{chunk-PMBEK6YE.mjs → chunk-J7ICRUU4.mjs} +5 -3
- package/dist/{chunk-PMBEK6YE.mjs.map → chunk-J7ICRUU4.mjs.map} +1 -1
- package/dist/{chunk-HPC6Z7J4.js → chunk-PWZBLTHR.js} +3 -3
- package/dist/{chunk-HPC6Z7J4.js.map → chunk-PWZBLTHR.js.map} +1 -1
- package/dist/chunk-SMXXAVMB.js +100 -0
- package/dist/chunk-SMXXAVMB.js.map +1 -0
- package/dist/{chunk-CSC3CMIT.mjs → chunk-STV4ZVNA.mjs} +2 -2
- package/dist/chunk-T5AZMMVS.mjs +94 -0
- package/dist/chunk-T5AZMMVS.mjs.map +1 -0
- package/dist/{chunk-4BZATFKJ.mjs → chunk-UU33HCCZ.mjs} +4 -26
- package/dist/{chunk-4BZATFKJ.mjs.map → chunk-UU33HCCZ.mjs.map} +1 -1
- package/dist/{chunk-PTJ6AAI7.js → chunk-VGHLQXKB.js} +138 -106
- package/dist/chunk-VGHLQXKB.js.map +1 -0
- package/dist/chunk-W5ZEP3CI.mjs +100 -0
- package/dist/chunk-W5ZEP3CI.mjs.map +1 -0
- package/dist/chunk-Y666BJA5.mjs +4 -0
- package/dist/{chunk-X62YT4WB.mjs → chunk-YFUZF7JM.mjs} +2 -2
- package/dist/chunk-YFUZF7JM.mjs.map +1 -0
- package/dist/chunk-YN4436PK.mjs +37 -0
- package/dist/chunk-YN4436PK.mjs.map +1 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +106 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/index.mjs +106 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/client-browser.js +12 -10
- package/dist/client-browser.js.map +1 -1
- package/dist/client-browser.mjs +5 -3
- package/dist/client-browser.mjs.map +1 -1
- package/dist/client-node.js +11 -9
- package/dist/client-node.js.map +1 -1
- package/dist/client-node.mjs +7 -5
- package/dist/client-node.mjs.map +1 -1
- package/dist/create-G5MTGOOH.js +70 -0
- package/dist/create-G5MTGOOH.js.map +1 -0
- package/dist/create-QUZYBMQB.mjs +70 -0
- package/dist/create-QUZYBMQB.mjs.map +1 -0
- package/dist/evaluation/index.js +5 -4
- package/dist/evaluation/index.js.map +1 -1
- package/dist/evaluation/index.mjs +4 -3
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -6
- package/dist/init-H67RW22E.mjs +16 -0
- package/dist/init-H67RW22E.mjs.map +1 -0
- package/dist/init-XU2JFY6N.js +16 -0
- package/dist/init-XU2JFY6N.js.map +1 -0
- package/dist/list-7NPSX2E4.mjs +136 -0
- package/dist/list-7NPSX2E4.mjs.map +1 -0
- package/dist/list-ZXFLAF52.js +136 -0
- package/dist/list-ZXFLAF52.js.map +1 -0
- package/dist/login-76NQIHKR.js +110 -0
- package/dist/login-76NQIHKR.js.map +1 -0
- package/dist/login-EK4WVOI2.mjs +110 -0
- package/dist/login-EK4WVOI2.mjs.map +1 -0
- package/dist/observability/index.d.mts +3 -3
- package/dist/observability/index.d.ts +3 -3
- package/dist/observability/index.js +5 -4
- package/dist/observability/index.js.map +1 -1
- package/dist/observability/index.mjs +4 -3
- package/dist/observability/instrumentation/langchain/index.d.mts +2 -2
- package/dist/observability/instrumentation/langchain/index.d.ts +2 -2
- package/dist/observability/instrumentation/langchain/index.js +29 -27
- package/dist/observability/instrumentation/langchain/index.js.map +1 -1
- package/dist/observability/instrumentation/langchain/index.mjs +5 -3
- package/dist/observability/instrumentation/langchain/index.mjs.map +1 -1
- package/dist/prompt/index.d.mts +2 -2
- package/dist/prompt/index.d.ts +2 -2
- package/dist/prompt/index.js +8 -4
- package/dist/prompt/index.js.map +1 -1
- package/dist/prompt/index.mjs +10 -6
- package/dist/{prompt-BXJWdbQp.d.mts → prompt-D-jpMrLS.d.mts} +245 -0
- package/dist/{prompt-BXJWdbQp.d.ts → prompt-D-jpMrLS.d.ts} +245 -0
- package/dist/remove-SDJYEPAY.mjs +106 -0
- package/dist/remove-SDJYEPAY.mjs.map +1 -0
- package/dist/remove-XBNGIVMR.js +106 -0
- package/dist/remove-XBNGIVMR.js.map +1 -0
- package/dist/sync-EISKGPTL.js +403 -0
- package/dist/sync-EISKGPTL.js.map +1 -0
- package/dist/sync-ST2IWXSB.mjs +403 -0
- package/dist/sync-ST2IWXSB.mjs.map +1 -0
- package/dist/{trace-G2312klE.d.ts → trace-CqaKo0kZ.d.ts} +1 -1
- package/dist/{trace-D-bZOuqb.d.mts → trace-DtVc5GhF.d.mts} +1 -1
- package/package.json +13 -2
- package/dist/chunk-76KNOWLS.js.map +0 -1
- package/dist/chunk-G3AUABT7.js +0 -4
- package/dist/chunk-OM7VY3XT.mjs +0 -4
- package/dist/chunk-PTJ6AAI7.js.map +0 -1
- package/dist/chunk-SVJ7SCGB.js.map +0 -1
- package/dist/chunk-VJSOCNPA.js.map +0 -1
- package/dist/chunk-X62YT4WB.mjs.map +0 -1
- package/dist/chunk-Z5J5UI5E.mjs.map +0 -1
- /package/dist/{chunk-CSC3CMIT.mjs.map → chunk-STV4ZVNA.mjs.map} +0 -0
- /package/dist/{chunk-OM7VY3XT.mjs.map → chunk-Y666BJA5.mjs.map} +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
var _chunkHJU67C7Hjs = require('./chunk-HJU67C7H.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk2JU376G7js = require('./chunk-2JU376G7.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkF6E4XQQUjs = require('./chunk-F6E4XQQU.js');
|
|
10
|
+
require('./chunk-HA3LI5IK.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkVGHLQXKBjs = require('./chunk-VGHLQXKB.js');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunkSMXXAVMBjs = require('./chunk-SMXXAVMB.js');
|
|
18
|
+
require('./chunk-PCQVQ7SB.js');
|
|
19
|
+
require('./chunk-FJLK5CFL.js');
|
|
20
|
+
|
|
21
|
+
// src/cli/commands/add.ts
|
|
22
|
+
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
23
|
+
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
24
|
+
var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
|
|
25
|
+
var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
|
|
26
|
+
var addLocalFile = async (name, localFilePath) => {
|
|
27
|
+
if (!fs.existsSync(localFilePath)) {
|
|
28
|
+
console.error(_chalk2.default.red(`Error: Local file not found: ${localFilePath}`));
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
if (!localFilePath.endsWith(".prompt.yaml")) {
|
|
32
|
+
console.error(_chalk2.default.red(`Error: Local file must have .prompt.yaml extension`));
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const config = _chunk2JU376G7js.FileManager.loadLocalPrompt(localFilePath);
|
|
37
|
+
await _chunkHJU67C7Hjs.ensureProjectInitialized.call(void 0, );
|
|
38
|
+
const promptsConfig = _chunk2JU376G7js.FileManager.loadPromptsConfig();
|
|
39
|
+
promptsConfig.prompts[name] = `file:${localFilePath}`;
|
|
40
|
+
_chunk2JU376G7js.FileManager.savePromptsConfig(promptsConfig);
|
|
41
|
+
const lock = _chunk2JU376G7js.FileManager.loadPromptsLock();
|
|
42
|
+
lock.prompts[name] = {
|
|
43
|
+
version: 0,
|
|
44
|
+
// Local files start at version 0
|
|
45
|
+
versionId: "local",
|
|
46
|
+
materialized: localFilePath
|
|
47
|
+
// Store the original file path
|
|
48
|
+
};
|
|
49
|
+
_chunk2JU376G7js.FileManager.savePromptsLock(lock);
|
|
50
|
+
console.log(_chalk2.default.green(`\u2713 Added local prompt: ${_chalk2.default.cyan(name)} \u2192 ${_chalk2.default.gray(localFilePath)}`));
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(_chalk2.default.red("Error loading local prompt file:"));
|
|
53
|
+
console.error(_chalk2.default.red(error instanceof Error ? error.message : String(error)));
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var addCommand = async (name, options) => {
|
|
58
|
+
try {
|
|
59
|
+
if (!name || name.trim() === "") {
|
|
60
|
+
console.error(_chalk2.default.red("Error: Prompt name cannot be empty"));
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
if (options.localFile) {
|
|
64
|
+
await addLocalFile(name, options.localFile);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
_chunkF6E4XQQUjs.checkApiKey.call(void 0, );
|
|
68
|
+
const promptService = _chunkVGHLQXKBjs.PromptService.getInstance();
|
|
69
|
+
const version = options.version || "latest";
|
|
70
|
+
const spinner = _ora2.default.call(void 0, `Adding ${_chalk2.default.cyan(`${name}@${version}`)}...`).start();
|
|
71
|
+
try {
|
|
72
|
+
const prompt = await promptService.get(name);
|
|
73
|
+
if (!prompt) {
|
|
74
|
+
spinner.fail();
|
|
75
|
+
console.error(_chalk2.default.red(`Error: Prompt "${name}" not found`));
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
spinner.stop();
|
|
79
|
+
await _chunkHJU67C7Hjs.ensureProjectInitialized.call(void 0, );
|
|
80
|
+
spinner.start(`Adding ${_chalk2.default.cyan(`${name}@${version}`)}...`);
|
|
81
|
+
const materializedPrompt = _chunkSMXXAVMBjs.PromptConverter.fromApiToMaterialized(prompt);
|
|
82
|
+
const savedPath = _chunk2JU376G7js.FileManager.saveMaterializedPrompt(name, materializedPrompt);
|
|
83
|
+
const relativePath = path.relative(process.cwd(), savedPath);
|
|
84
|
+
const config = _chunk2JU376G7js.FileManager.loadPromptsConfig();
|
|
85
|
+
const lock = _chunk2JU376G7js.FileManager.loadPromptsLock();
|
|
86
|
+
config.prompts[name] = version;
|
|
87
|
+
_chunk2JU376G7js.FileManager.updateLockEntry(lock, name, materializedPrompt, savedPath);
|
|
88
|
+
_chunk2JU376G7js.FileManager.savePromptsConfig(config);
|
|
89
|
+
_chunk2JU376G7js.FileManager.savePromptsLock(lock);
|
|
90
|
+
spinner.succeed();
|
|
91
|
+
const displayPath = relativePath.startsWith("./") ? relativePath : `./${relativePath}`;
|
|
92
|
+
console.log(_chalk2.default.green(`\u2713 Pulled ${_chalk2.default.cyan(`${name}@${version}`)} ${_chalk2.default.gray(`(version ${prompt.version})`)} \u2192 ${_chalk2.default.gray(displayPath)}`));
|
|
93
|
+
} catch (error) {
|
|
94
|
+
spinner.fail();
|
|
95
|
+
if (error instanceof _chunkVGHLQXKBjs.PromptsError) {
|
|
96
|
+
console.error(_chalk2.default.red(`Error: ${error.message}`));
|
|
97
|
+
} else {
|
|
98
|
+
console.error(_chalk2.default.red(`Error adding prompt: ${error instanceof Error ? error.message : "Unknown error"}`));
|
|
99
|
+
}
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error instanceof _chunkVGHLQXKBjs.PromptsError) {
|
|
104
|
+
console.error(_chalk2.default.red(`Error: ${error.message}`));
|
|
105
|
+
} else {
|
|
106
|
+
console.error(_chalk2.default.red(`Unexpected error: ${error instanceof Error ? error.message : "Unknown error"}`));
|
|
107
|
+
}
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
exports.addCommand = addCommand;
|
|
114
|
+
//# sourceMappingURL=add-LBBS4I3H.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/add-LBBS4I3H.js","../src/cli/commands/add.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B,+BAA4B;AAC5B;AACA;ACpBA,+DAAoB;AACpB,uEAAsB;AACtB,4EAAkB;AAClB,oEAAgB;AAYhB,IAAM,aAAA,EAAe,MAAA,CAAO,IAAA,EAAc,aAAA,EAAA,GAAyC;AAEjF,EAAA,GAAA,CAAI,CAAI,EAAA,CAAA,UAAA,CAAW,aAAa,CAAA,EAAG;AACjC,IAAA,OAAA,CAAQ,KAAA,CAAM,eAAA,CAAM,GAAA,CAAI,CAAA,6BAAA,EAAgC,aAAa,CAAA,CAAA;AACvD,IAAA;AAChB,EAAA;AAE6C,EAAA;AACnB,IAAA;AACV,IAAA;AAChB,EAAA;AAGI,EAAA;AACsD,IAAA;AAGzB,IAAA;AAGqB,IAAA;AACD,IAAA;AACR,IAAA;AAGF,IAAA;AACpB,IAAA;AACV,MAAA;AAAA;AACE,MAAA;AACG,MAAA;AAAA;AAChB,IAAA;AACgC,IAAA;AAEiC,IAAA;AAEnD,EAAA;AAC6C,IAAA;AACM,IAAA;AACnD,IAAA;AAChB,EAAA;AACF;AAEsF;AAChF,EAAA;AAE+B,IAAA;AAC8B,MAAA;AAC/C,MAAA;AAChB,IAAA;AAGuB,IAAA;AACqB,MAAA;AAC1C,MAAA;AACF,IAAA;AAGY,IAAA;AAEoC,IAAA;AACb,IAAA;AAGkC,IAAA;AAEjE,IAAA;AAEyC,MAAA;AAE9B,MAAA;AACE,QAAA;AAC+C,QAAA;AAC9C,QAAA;AAChB,MAAA;AAGa,MAAA;AAGkB,MAAA;AAG8B,MAAA;AAGI,MAAA;AACN,MAAA;AACA,MAAA;AAGd,MAAA;AACJ,MAAA;AAElB,MAAA;AACqC,MAAA;AAGxB,MAAA;AACJ,MAAA;AAEhB,MAAA;AAGmD,MAAA;AACT,MAAA;AAE5C,IAAA;AACD,MAAA;AACsB,MAAA;AACiB,QAAA;AAC7C,MAAA;AAC4D,QAAA;AACnE,MAAA;AACc,MAAA;AAChB,IAAA;AAEc,EAAA;AACqB,IAAA;AACiB,MAAA;AAC7C,IAAA;AACyD,MAAA;AAChE,IAAA;AACc,IAAA;AAChB,EAAA;AACF;AD7B0E;AACA;AACA","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/add-LBBS4I3H.js","sourcesContent":[null,"import * as fs from \"fs\";\nimport * as path from \"path\";\nimport chalk from \"chalk\";\nimport ora from \"ora\";\nimport { FileManager } from \"../utils/fileManager\";\nimport { PromptService, PromptsError } from \"../../prompt/service\";\nimport { PromptConverter } from \"../../prompt/converter\";\nimport { ensureProjectInitialized } from \"../utils/init\";\nimport { checkApiKey } from \"../utils/apiKey\";\n\ninterface AddOptions {\n version?: string;\n localFile?: string;\n}\n\nconst addLocalFile = async (name: string, localFilePath: string): Promise<void> => {\n // Validate that the file exists and has the right extension\n if (!fs.existsSync(localFilePath)) {\n console.error(chalk.red(`Error: Local file not found: ${localFilePath}`));\n process.exit(1);\n }\n\n if (!localFilePath.endsWith('.prompt.yaml')) {\n console.error(chalk.red(`Error: Local file must have .prompt.yaml extension`));\n process.exit(1);\n }\n\n // Load and validate the YAML file\n try {\n const config = FileManager.loadLocalPrompt(localFilePath);\n\n // Ensure project is initialized\n await ensureProjectInitialized();\n\n // Add to prompts.json as a file: dependency\n const promptsConfig = FileManager.loadPromptsConfig();\n promptsConfig.prompts[name] = `file:${localFilePath}`;\n FileManager.savePromptsConfig(promptsConfig);\n\n // Update lock file\n const lock = FileManager.loadPromptsLock();\n lock.prompts[name] = {\n version: 0, // Local files start at version 0\n versionId: \"local\",\n materialized: localFilePath, // Store the original file path\n };\n FileManager.savePromptsLock(lock);\n\n console.log(chalk.green(`✓ Added local prompt: ${chalk.cyan(name)} → ${chalk.gray(localFilePath)}`));\n\n } catch (error) {\n console.error(chalk.red(\"Error loading local prompt file:\"));\n console.error(chalk.red(error instanceof Error ? error.message : String(error)));\n process.exit(1);\n }\n};\n\nexport const addCommand = async (name: string, options: AddOptions): Promise<void> => {\n try {\n // Validate prompt name\n if (!name || name.trim() === \"\") {\n console.error(chalk.red(\"Error: Prompt name cannot be empty\"));\n process.exit(1);\n }\n\n // Handle local file addition\n if (options.localFile) {\n await addLocalFile(name, options.localFile);\n return;\n }\n\n // Check API key before doing anything else\n checkApiKey();\n\n const promptService = PromptService.getInstance();\n const version = options.version || \"latest\";\n\n // Fetch and materialize the prompt (like sync does for individual prompts)\n const spinner = ora(`Adding ${chalk.cyan(`${name}@${version}`)}...`).start();\n\n try {\n // Fetch the prompt from the API\n const prompt = await promptService.get(name);\n\n if (!prompt) {\n spinner.fail();\n console.error(chalk.red(`Error: Prompt \"${name}\" not found`));\n process.exit(1);\n }\n\n // Stop spinner before any user input prompts\n spinner.stop();\n\n // Ensure project is initialized (prompts.json, lock file, directories)\n await ensureProjectInitialized();\n\n // Restart spinner for the actual work\n spinner.start(`Adding ${chalk.cyan(`${name}@${version}`)}...`);\n\n // Convert to MaterializedPrompt format and save\n const materializedPrompt = PromptConverter.fromApiToMaterialized(prompt);\n const savedPath = FileManager.saveMaterializedPrompt(name, materializedPrompt);\n const relativePath = path.relative(process.cwd(), savedPath);\n\n // Load existing config and lock, add the new dependency\n const config = FileManager.loadPromptsConfig();\n const lock = FileManager.loadPromptsLock();\n\n config.prompts[name] = version;\n FileManager.updateLockEntry(lock, name, materializedPrompt, savedPath);\n\n // Save the updated config and lock\n FileManager.savePromptsConfig(config);\n FileManager.savePromptsLock(lock);\n\n spinner.succeed();\n\n // Show what was done (add ./ prefix for consistency)\n const displayPath = relativePath.startsWith('./') ? relativePath : `./${relativePath}`;\n console.log(chalk.green(`✓ Pulled ${chalk.cyan(`${name}@${version}`)} ${chalk.gray(`(version ${prompt.version})`)} → ${chalk.gray(displayPath)}`));\n\n } catch (error) {\n spinner.fail();\n if (error instanceof PromptsError) {\n console.error(chalk.red(`Error: ${error.message}`));\n } else {\n console.error(chalk.red(`Error adding prompt: ${error instanceof Error ? error.message : \"Unknown error\"}`));\n }\n process.exit(1);\n }\n\n } catch (error) {\n if (error instanceof PromptsError) {\n console.error(chalk.red(`Error: ${error.message}`));\n } else {\n console.error(chalk.red(`Unexpected error: ${error instanceof Error ? error.message : \"Unknown error\"}`));\n }\n process.exit(1);\n }\n};"]}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensureProjectInitialized
|
|
3
|
+
} from "./chunk-E7UE2MPD.mjs";
|
|
4
|
+
import {
|
|
5
|
+
FileManager
|
|
6
|
+
} from "./chunk-3GKPQB4R.mjs";
|
|
7
|
+
import {
|
|
8
|
+
checkApiKey
|
|
9
|
+
} from "./chunk-DHJKJVY7.mjs";
|
|
10
|
+
import "./chunk-4NRLVT2U.mjs";
|
|
11
|
+
import {
|
|
12
|
+
PromptService,
|
|
13
|
+
PromptsError
|
|
14
|
+
} from "./chunk-GJSEBQXF.mjs";
|
|
15
|
+
import {
|
|
16
|
+
PromptConverter
|
|
17
|
+
} from "./chunk-W5ZEP3CI.mjs";
|
|
18
|
+
import "./chunk-QEWDG5QE.mjs";
|
|
19
|
+
import "./chunk-YN4436PK.mjs";
|
|
20
|
+
|
|
21
|
+
// src/cli/commands/add.ts
|
|
22
|
+
import * as fs from "fs";
|
|
23
|
+
import * as path from "path";
|
|
24
|
+
import chalk from "chalk";
|
|
25
|
+
import ora from "ora";
|
|
26
|
+
var addLocalFile = async (name, localFilePath) => {
|
|
27
|
+
if (!fs.existsSync(localFilePath)) {
|
|
28
|
+
console.error(chalk.red(`Error: Local file not found: ${localFilePath}`));
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
if (!localFilePath.endsWith(".prompt.yaml")) {
|
|
32
|
+
console.error(chalk.red(`Error: Local file must have .prompt.yaml extension`));
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const config = FileManager.loadLocalPrompt(localFilePath);
|
|
37
|
+
await ensureProjectInitialized();
|
|
38
|
+
const promptsConfig = FileManager.loadPromptsConfig();
|
|
39
|
+
promptsConfig.prompts[name] = `file:${localFilePath}`;
|
|
40
|
+
FileManager.savePromptsConfig(promptsConfig);
|
|
41
|
+
const lock = FileManager.loadPromptsLock();
|
|
42
|
+
lock.prompts[name] = {
|
|
43
|
+
version: 0,
|
|
44
|
+
// Local files start at version 0
|
|
45
|
+
versionId: "local",
|
|
46
|
+
materialized: localFilePath
|
|
47
|
+
// Store the original file path
|
|
48
|
+
};
|
|
49
|
+
FileManager.savePromptsLock(lock);
|
|
50
|
+
console.log(chalk.green(`\u2713 Added local prompt: ${chalk.cyan(name)} \u2192 ${chalk.gray(localFilePath)}`));
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(chalk.red("Error loading local prompt file:"));
|
|
53
|
+
console.error(chalk.red(error instanceof Error ? error.message : String(error)));
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var addCommand = async (name, options) => {
|
|
58
|
+
try {
|
|
59
|
+
if (!name || name.trim() === "") {
|
|
60
|
+
console.error(chalk.red("Error: Prompt name cannot be empty"));
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
if (options.localFile) {
|
|
64
|
+
await addLocalFile(name, options.localFile);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
checkApiKey();
|
|
68
|
+
const promptService = PromptService.getInstance();
|
|
69
|
+
const version = options.version || "latest";
|
|
70
|
+
const spinner = ora(`Adding ${chalk.cyan(`${name}@${version}`)}...`).start();
|
|
71
|
+
try {
|
|
72
|
+
const prompt = await promptService.get(name);
|
|
73
|
+
if (!prompt) {
|
|
74
|
+
spinner.fail();
|
|
75
|
+
console.error(chalk.red(`Error: Prompt "${name}" not found`));
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
spinner.stop();
|
|
79
|
+
await ensureProjectInitialized();
|
|
80
|
+
spinner.start(`Adding ${chalk.cyan(`${name}@${version}`)}...`);
|
|
81
|
+
const materializedPrompt = PromptConverter.fromApiToMaterialized(prompt);
|
|
82
|
+
const savedPath = FileManager.saveMaterializedPrompt(name, materializedPrompt);
|
|
83
|
+
const relativePath = path.relative(process.cwd(), savedPath);
|
|
84
|
+
const config = FileManager.loadPromptsConfig();
|
|
85
|
+
const lock = FileManager.loadPromptsLock();
|
|
86
|
+
config.prompts[name] = version;
|
|
87
|
+
FileManager.updateLockEntry(lock, name, materializedPrompt, savedPath);
|
|
88
|
+
FileManager.savePromptsConfig(config);
|
|
89
|
+
FileManager.savePromptsLock(lock);
|
|
90
|
+
spinner.succeed();
|
|
91
|
+
const displayPath = relativePath.startsWith("./") ? relativePath : `./${relativePath}`;
|
|
92
|
+
console.log(chalk.green(`\u2713 Pulled ${chalk.cyan(`${name}@${version}`)} ${chalk.gray(`(version ${prompt.version})`)} \u2192 ${chalk.gray(displayPath)}`));
|
|
93
|
+
} catch (error) {
|
|
94
|
+
spinner.fail();
|
|
95
|
+
if (error instanceof PromptsError) {
|
|
96
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
97
|
+
} else {
|
|
98
|
+
console.error(chalk.red(`Error adding prompt: ${error instanceof Error ? error.message : "Unknown error"}`));
|
|
99
|
+
}
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error instanceof PromptsError) {
|
|
104
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
105
|
+
} else {
|
|
106
|
+
console.error(chalk.red(`Unexpected error: ${error instanceof Error ? error.message : "Unknown error"}`));
|
|
107
|
+
}
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
export {
|
|
112
|
+
addCommand
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=add-RD3ZKFAT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli/commands/add.ts"],"sourcesContent":["import * as fs from \"fs\";\nimport * as path from \"path\";\nimport chalk from \"chalk\";\nimport ora from \"ora\";\nimport { FileManager } from \"../utils/fileManager\";\nimport { PromptService, PromptsError } from \"../../prompt/service\";\nimport { PromptConverter } from \"../../prompt/converter\";\nimport { ensureProjectInitialized } from \"../utils/init\";\nimport { checkApiKey } from \"../utils/apiKey\";\n\ninterface AddOptions {\n version?: string;\n localFile?: string;\n}\n\nconst addLocalFile = async (name: string, localFilePath: string): Promise<void> => {\n // Validate that the file exists and has the right extension\n if (!fs.existsSync(localFilePath)) {\n console.error(chalk.red(`Error: Local file not found: ${localFilePath}`));\n process.exit(1);\n }\n\n if (!localFilePath.endsWith('.prompt.yaml')) {\n console.error(chalk.red(`Error: Local file must have .prompt.yaml extension`));\n process.exit(1);\n }\n\n // Load and validate the YAML file\n try {\n const config = FileManager.loadLocalPrompt(localFilePath);\n\n // Ensure project is initialized\n await ensureProjectInitialized();\n\n // Add to prompts.json as a file: dependency\n const promptsConfig = FileManager.loadPromptsConfig();\n promptsConfig.prompts[name] = `file:${localFilePath}`;\n FileManager.savePromptsConfig(promptsConfig);\n\n // Update lock file\n const lock = FileManager.loadPromptsLock();\n lock.prompts[name] = {\n version: 0, // Local files start at version 0\n versionId: \"local\",\n materialized: localFilePath, // Store the original file path\n };\n FileManager.savePromptsLock(lock);\n\n console.log(chalk.green(`✓ Added local prompt: ${chalk.cyan(name)} → ${chalk.gray(localFilePath)}`));\n\n } catch (error) {\n console.error(chalk.red(\"Error loading local prompt file:\"));\n console.error(chalk.red(error instanceof Error ? error.message : String(error)));\n process.exit(1);\n }\n};\n\nexport const addCommand = async (name: string, options: AddOptions): Promise<void> => {\n try {\n // Validate prompt name\n if (!name || name.trim() === \"\") {\n console.error(chalk.red(\"Error: Prompt name cannot be empty\"));\n process.exit(1);\n }\n\n // Handle local file addition\n if (options.localFile) {\n await addLocalFile(name, options.localFile);\n return;\n }\n\n // Check API key before doing anything else\n checkApiKey();\n\n const promptService = PromptService.getInstance();\n const version = options.version || \"latest\";\n\n // Fetch and materialize the prompt (like sync does for individual prompts)\n const spinner = ora(`Adding ${chalk.cyan(`${name}@${version}`)}...`).start();\n\n try {\n // Fetch the prompt from the API\n const prompt = await promptService.get(name);\n\n if (!prompt) {\n spinner.fail();\n console.error(chalk.red(`Error: Prompt \"${name}\" not found`));\n process.exit(1);\n }\n\n // Stop spinner before any user input prompts\n spinner.stop();\n\n // Ensure project is initialized (prompts.json, lock file, directories)\n await ensureProjectInitialized();\n\n // Restart spinner for the actual work\n spinner.start(`Adding ${chalk.cyan(`${name}@${version}`)}...`);\n\n // Convert to MaterializedPrompt format and save\n const materializedPrompt = PromptConverter.fromApiToMaterialized(prompt);\n const savedPath = FileManager.saveMaterializedPrompt(name, materializedPrompt);\n const relativePath = path.relative(process.cwd(), savedPath);\n\n // Load existing config and lock, add the new dependency\n const config = FileManager.loadPromptsConfig();\n const lock = FileManager.loadPromptsLock();\n\n config.prompts[name] = version;\n FileManager.updateLockEntry(lock, name, materializedPrompt, savedPath);\n\n // Save the updated config and lock\n FileManager.savePromptsConfig(config);\n FileManager.savePromptsLock(lock);\n\n spinner.succeed();\n\n // Show what was done (add ./ prefix for consistency)\n const displayPath = relativePath.startsWith('./') ? relativePath : `./${relativePath}`;\n console.log(chalk.green(`✓ Pulled ${chalk.cyan(`${name}@${version}`)} ${chalk.gray(`(version ${prompt.version})`)} → ${chalk.gray(displayPath)}`));\n\n } catch (error) {\n spinner.fail();\n if (error instanceof PromptsError) {\n console.error(chalk.red(`Error: ${error.message}`));\n } else {\n console.error(chalk.red(`Error adding prompt: ${error instanceof Error ? error.message : \"Unknown error\"}`));\n }\n process.exit(1);\n }\n\n } catch (error) {\n if (error instanceof PromptsError) {\n console.error(chalk.red(`Error: ${error.message}`));\n } else {\n console.error(chalk.red(`Unexpected error: ${error instanceof Error ? error.message : \"Unknown error\"}`));\n }\n process.exit(1);\n }\n};"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,OAAO,WAAW;AAClB,OAAO,SAAS;AAYhB,IAAM,eAAe,OAAO,MAAc,kBAAyC;AAEjF,MAAI,CAAI,cAAW,aAAa,GAAG;AACjC,YAAQ,MAAM,MAAM,IAAI,gCAAgC,aAAa,EAAE,CAAC;AACxE,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,MAAI,CAAC,cAAc,SAAS,cAAc,GAAG;AAC3C,YAAQ,MAAM,MAAM,IAAI,oDAAoD,CAAC;AAC7E,YAAQ,KAAK,CAAC;AAAA,EAChB;AAGA,MAAI;AACF,UAAM,SAAS,YAAY,gBAAgB,aAAa;AAGxD,UAAM,yBAAyB;AAG/B,UAAM,gBAAgB,YAAY,kBAAkB;AACpD,kBAAc,QAAQ,IAAI,IAAI,QAAQ,aAAa;AACnD,gBAAY,kBAAkB,aAAa;AAG3C,UAAM,OAAO,YAAY,gBAAgB;AACzC,SAAK,QAAQ,IAAI,IAAI;AAAA,MACnB,SAAS;AAAA;AAAA,MACT,WAAW;AAAA,MACX,cAAc;AAAA;AAAA,IAChB;AACA,gBAAY,gBAAgB,IAAI;AAEhC,YAAQ,IAAI,MAAM,MAAM,8BAAyB,MAAM,KAAK,IAAI,CAAC,WAAM,MAAM,KAAK,aAAa,CAAC,EAAE,CAAC;AAAA,EAErG,SAAS,OAAO;AACd,YAAQ,MAAM,MAAM,IAAI,kCAAkC,CAAC;AAC3D,YAAQ,MAAM,MAAM,IAAI,iBAAiB,QAA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AAa,WAAW,IAAI,IAAI,eAAe,KAAK,YAAY;AACpF,cAAQ,IAAI,MAAM,MAAM,iBAAY,MAAM,KAAK,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,IAAI,MAAM,KAAK,YAAY,OAAO,OAAO,GAAG,CAAC,WAAM,MAAM,KAAK,WAAW,CAAC,EAAE,CAAC;AAAA,IAEnJ,SAAS,OAAO;AACd,cAAQ,KAAK;AACb,UAAI,iBAAiB,cAAc;AACjC,gBAAQ,MAAM,MAAM,IAAI,UAAU,MAAM,OAAO,EAAE,CAAC;AAAA,MACpD,OAAO;AACL,gBAAQ,MAAM,MAAM,IAAI,wBAAwB,iBAAiB,QAAQ,MAAM,UAAU,eAAe,EAAE,CAAC;AAAA,MAC7G;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EAEF,SAAS,OAAO;AACd,QAAI,iBAAiB,cAAc;AACjC,cAAQ,MAAM,MAAM,IAAI,UAAU,MAAM,OAAO,EAAE,CAAC;AAAA,IACpD,OAAO;AACL,cAAQ,MAAM,MAAM,IAAI,qBAAqB,iBAAiB,QAAQ,MAAM,UAAU,eAAe,EAAE,CAAC;AAAA,IAC1G;AACA,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
var _chunkHA3LI5IKjs = require('./chunk-HA3LI5IK.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkSMXXAVMBjs = require('./chunk-SMXXAVMB.js');
|
|
7
|
+
|
|
8
|
+
// src/cli/utils/fileManager.ts
|
|
9
|
+
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
10
|
+
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
11
|
+
var _jsyaml = require('js-yaml'); var yaml = _interopRequireWildcard(_jsyaml);
|
|
12
|
+
var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
|
|
13
|
+
var FileManager = class {
|
|
14
|
+
static getPromptsConfigPath() {
|
|
15
|
+
return path.join(process.cwd(), this.PROMPTS_CONFIG_FILE);
|
|
16
|
+
}
|
|
17
|
+
static getPromptsLockPath() {
|
|
18
|
+
return path.join(process.cwd(), this.PROMPTS_LOCK_FILE);
|
|
19
|
+
}
|
|
20
|
+
static getPromptsDir() {
|
|
21
|
+
return path.join(process.cwd(), this.PROMPTS_DIR);
|
|
22
|
+
}
|
|
23
|
+
static getMaterializedDir() {
|
|
24
|
+
return path.join(this.getPromptsDir(), this.MATERIALIZED_DIR);
|
|
25
|
+
}
|
|
26
|
+
static ensureDirectories() {
|
|
27
|
+
const promptsDir = this.getPromptsDir();
|
|
28
|
+
const materializedDir = this.getMaterializedDir();
|
|
29
|
+
if (!fs.existsSync(promptsDir)) {
|
|
30
|
+
fs.mkdirSync(promptsDir, { recursive: true });
|
|
31
|
+
}
|
|
32
|
+
if (!fs.existsSync(materializedDir)) {
|
|
33
|
+
fs.mkdirSync(materializedDir, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
static loadPromptsConfig() {
|
|
37
|
+
const configPath = this.getPromptsConfigPath();
|
|
38
|
+
if (!fs.existsSync(configPath)) {
|
|
39
|
+
return { prompts: {} };
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const content = fs.readFileSync(configPath, "utf-8");
|
|
43
|
+
return JSON.parse(content);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
throw new Error(`Failed to parse prompts.json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
static savePromptsConfig(config) {
|
|
49
|
+
const configPath = this.getPromptsConfigPath();
|
|
50
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
51
|
+
}
|
|
52
|
+
static initializePromptsConfig() {
|
|
53
|
+
const configPath = this.getPromptsConfigPath();
|
|
54
|
+
const existed = fs.existsSync(configPath);
|
|
55
|
+
if (!existed) {
|
|
56
|
+
const emptyConfig = { prompts: {} };
|
|
57
|
+
this.savePromptsConfig(emptyConfig);
|
|
58
|
+
return { created: true, path: configPath };
|
|
59
|
+
}
|
|
60
|
+
return { created: false, path: configPath };
|
|
61
|
+
}
|
|
62
|
+
static loadPromptsLock() {
|
|
63
|
+
const lockPath = this.getPromptsLockPath();
|
|
64
|
+
if (!fs.existsSync(lockPath)) {
|
|
65
|
+
return {
|
|
66
|
+
lockfileVersion: 1,
|
|
67
|
+
prompts: {}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const content = fs.readFileSync(lockPath, "utf-8");
|
|
72
|
+
return JSON.parse(content);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throw new Error(`Failed to parse prompts-lock.json: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
static savePromptsLock(lock) {
|
|
78
|
+
const lockPath = this.getPromptsLockPath();
|
|
79
|
+
fs.writeFileSync(lockPath, JSON.stringify(lock, null, 2) + "\n");
|
|
80
|
+
}
|
|
81
|
+
static initializePromptsLock() {
|
|
82
|
+
const lockPath = this.getPromptsLockPath();
|
|
83
|
+
const existed = fs.existsSync(lockPath);
|
|
84
|
+
if (!existed) {
|
|
85
|
+
const emptyLock = {
|
|
86
|
+
lockfileVersion: 1,
|
|
87
|
+
prompts: {}
|
|
88
|
+
};
|
|
89
|
+
this.savePromptsLock(emptyLock);
|
|
90
|
+
return { created: true, path: lockPath };
|
|
91
|
+
}
|
|
92
|
+
return { created: false, path: lockPath };
|
|
93
|
+
}
|
|
94
|
+
static loadLocalPrompt(filePath) {
|
|
95
|
+
const fullPath = path.resolve(filePath);
|
|
96
|
+
if (!fs.existsSync(fullPath)) {
|
|
97
|
+
throw new Error(`Local prompt file not found: ${filePath}`);
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const content = fs.readFileSync(fullPath, "utf-8");
|
|
101
|
+
const rawData = yaml.load(content);
|
|
102
|
+
const result = _chunkHA3LI5IKjs.localPromptConfigSchema.safeParse(rawData);
|
|
103
|
+
if (!result.success) {
|
|
104
|
+
const prettyError = result.error.issues.map((issue) => `\u2716 ${issue.message}${issue.path.length > 0 ? `
|
|
105
|
+
\u2192 at ${issue.path.join(".")}` : ""}`).join("\n");
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Invalid prompt configuration in ${_chalk2.default.yellow(filePath)}:
|
|
108
|
+
${prettyError}`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
return result.data;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (error instanceof Error && error.message.includes("Invalid prompt configuration")) {
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
throw new Error(`Failed to parse local prompt file ${filePath}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
static saveMaterializedPrompt(name, prompt) {
|
|
120
|
+
const materializedDir = this.getMaterializedDir();
|
|
121
|
+
const parts = name.split("/");
|
|
122
|
+
const fileName = `${parts[parts.length - 1]}.prompt.yaml`;
|
|
123
|
+
if (parts.length > 1) {
|
|
124
|
+
const subDir = path.join(materializedDir, ...parts.slice(0, -1));
|
|
125
|
+
if (!fs.existsSync(subDir)) {
|
|
126
|
+
fs.mkdirSync(subDir, { recursive: true });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const filePath = path.join(materializedDir, ...parts.slice(0, -1), fileName);
|
|
130
|
+
const yamlContent = _chunkSMXXAVMBjs.PromptConverter.fromMaterializedToYaml(prompt);
|
|
131
|
+
const yamlString = yaml.dump(yamlContent, {
|
|
132
|
+
lineWidth: -1,
|
|
133
|
+
noRefs: true,
|
|
134
|
+
sortKeys: false
|
|
135
|
+
});
|
|
136
|
+
fs.writeFileSync(filePath, yamlString);
|
|
137
|
+
return filePath;
|
|
138
|
+
}
|
|
139
|
+
static getLocalPromptFiles() {
|
|
140
|
+
const promptsDir = this.getPromptsDir();
|
|
141
|
+
const materializedDir = this.getMaterializedDir();
|
|
142
|
+
if (!fs.existsSync(promptsDir)) {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
const files = [];
|
|
146
|
+
const walkDir = (dir, relativePath = "") => {
|
|
147
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
const fullPath = path.join(dir, entry.name);
|
|
150
|
+
const relativeFilePath = path.join(relativePath, entry.name);
|
|
151
|
+
if (entry.isDirectory()) {
|
|
152
|
+
if (fullPath === materializedDir) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
walkDir(fullPath, relativeFilePath);
|
|
156
|
+
} else if (entry.isFile() && entry.name.endsWith(".prompt.yaml")) {
|
|
157
|
+
files.push(path.join(promptsDir, relativeFilePath));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
walkDir(promptsDir);
|
|
162
|
+
return files;
|
|
163
|
+
}
|
|
164
|
+
static promptNameFromPath(filePath) {
|
|
165
|
+
const promptsDir = this.getPromptsDir();
|
|
166
|
+
const relativePath = path.relative(promptsDir, filePath);
|
|
167
|
+
return relativePath.replace(/\.prompt\.yaml$/, "");
|
|
168
|
+
}
|
|
169
|
+
static cleanupOrphanedMaterializedFiles(currentDependencies) {
|
|
170
|
+
const materializedDir = this.getMaterializedDir();
|
|
171
|
+
if (!fs.existsSync(materializedDir)) {
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
const cleaned = [];
|
|
175
|
+
const cleanupDir = (dir, relativePath = "") => {
|
|
176
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
177
|
+
for (const entry of entries) {
|
|
178
|
+
const fullPath = path.join(dir, entry.name);
|
|
179
|
+
const relativeFilePath = path.join(relativePath, entry.name);
|
|
180
|
+
if (entry.isDirectory()) {
|
|
181
|
+
cleanupDir(fullPath, relativeFilePath);
|
|
182
|
+
try {
|
|
183
|
+
const dirEntries = fs.readdirSync(fullPath);
|
|
184
|
+
if (dirEntries.length === 0) {
|
|
185
|
+
fs.rmdirSync(fullPath);
|
|
186
|
+
}
|
|
187
|
+
} catch (e) {
|
|
188
|
+
}
|
|
189
|
+
} else if (entry.isFile() && entry.name.endsWith(".prompt.yaml")) {
|
|
190
|
+
const promptName = relativeFilePath.replace(/\.prompt\.yaml$/, "");
|
|
191
|
+
if (!currentDependencies.has(promptName)) {
|
|
192
|
+
fs.unlinkSync(fullPath);
|
|
193
|
+
cleaned.push(promptName);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
cleanupDir(materializedDir);
|
|
199
|
+
return cleaned;
|
|
200
|
+
}
|
|
201
|
+
static updateLockEntry(lock, name, prompt, materializedPath) {
|
|
202
|
+
const relativePath = path.relative(process.cwd(), materializedPath);
|
|
203
|
+
lock.prompts[name] = {
|
|
204
|
+
version: prompt.version,
|
|
205
|
+
versionId: prompt.versionId,
|
|
206
|
+
materialized: relativePath
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
static removeFromLock(lock, names) {
|
|
210
|
+
for (const name of names) {
|
|
211
|
+
delete lock.prompts[name];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
static addToGitignore(entry) {
|
|
215
|
+
const gitignorePath = path.join(process.cwd(), ".gitignore");
|
|
216
|
+
if (!fs.existsSync(gitignorePath)) {
|
|
217
|
+
fs.writeFileSync(gitignorePath, `${entry}
|
|
218
|
+
`);
|
|
219
|
+
return { added: true, existed: false };
|
|
220
|
+
}
|
|
221
|
+
const content = fs.readFileSync(gitignorePath, "utf-8");
|
|
222
|
+
const lines = content.split("\n").map((line) => line.trim());
|
|
223
|
+
if (lines.includes(entry)) {
|
|
224
|
+
return { added: false, existed: true };
|
|
225
|
+
}
|
|
226
|
+
const newContent = content.endsWith("\n") ? `${content}${entry}
|
|
227
|
+
` : `${content}
|
|
228
|
+
${entry}
|
|
229
|
+
`;
|
|
230
|
+
fs.writeFileSync(gitignorePath, newContent);
|
|
231
|
+
return { added: true, existed: false };
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
FileManager.PROMPTS_CONFIG_FILE = "prompts.json";
|
|
235
|
+
FileManager.PROMPTS_LOCK_FILE = "prompts-lock.json";
|
|
236
|
+
FileManager.PROMPTS_DIR = "prompts";
|
|
237
|
+
FileManager.MATERIALIZED_DIR = ".materialized";
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
exports.FileManager = FileManager;
|
|
242
|
+
//# sourceMappingURL=chunk-2JU376G7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-2JU376G7.js","../src/cli/utils/fileManager.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;ACPA,+DAAoB;AACpB,uEAAsB;AACtB,8EAAsB;AACtB,4EAAkB;AAMX,IAAM,YAAA,EAAN,MAAkB;AAAA,EAMvB,OAAO,oBAAA,CAAA,EAA+B;AACpC,IAAA,OAAY,IAAA,CAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,CAAA,EAAG,IAAA,CAAK,mBAAmB,CAAA;AAAA,EAC1D;AAAA,EAEA,OAAO,kBAAA,CAAA,EAA6B;AAClC,IAAA,OAAY,IAAA,CAAA,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,CAAA,EAAG,IAAA,CAAK,iBAAiB,CAAA;AAAA,EACxD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unk-2JU376G7.js","sourcesContent":[null,"import * as fs from \"fs\";\nimport * as path from \"path\";\nimport * as yaml from \"js-yaml\";\nimport chalk from \"chalk\";\nimport { z } from \"zod\";\nimport type { PromptsConfig, LocalPromptConfig, MaterializedPrompt, PromptsLock, PromptsLockEntry } from \"../types\";\nimport { localPromptConfigSchema } from \"../types\";\nimport { PromptConverter } from \"../../prompt/converter\";\n\nexport class FileManager {\n private static readonly PROMPTS_CONFIG_FILE = \"prompts.json\";\n private static readonly PROMPTS_LOCK_FILE = \"prompts-lock.json\";\n private static readonly PROMPTS_DIR = \"prompts\";\n private static readonly MATERIALIZED_DIR = \".materialized\";\n\n static getPromptsConfigPath(): string {\n return path.join(process.cwd(), this.PROMPTS_CONFIG_FILE);\n }\n\n static getPromptsLockPath(): string {\n return path.join(process.cwd(), this.PROMPTS_LOCK_FILE);\n }\n\n static getPromptsDir(): string {\n return path.join(process.cwd(), this.PROMPTS_DIR);\n }\n\n static getMaterializedDir(): string {\n return path.join(this.getPromptsDir(), this.MATERIALIZED_DIR);\n }\n\n static ensureDirectories(): void {\n const promptsDir = this.getPromptsDir();\n const materializedDir = this.getMaterializedDir();\n\n if (!fs.existsSync(promptsDir)) {\n fs.mkdirSync(promptsDir, { recursive: true });\n }\n\n if (!fs.existsSync(materializedDir)) {\n fs.mkdirSync(materializedDir, { recursive: true });\n }\n }\n\n static loadPromptsConfig(): PromptsConfig {\n const configPath = this.getPromptsConfigPath();\n\n if (!fs.existsSync(configPath)) {\n return { prompts: {} };\n }\n\n try {\n const content = fs.readFileSync(configPath, \"utf-8\");\n return JSON.parse(content) as PromptsConfig;\n } catch (error) {\n throw new Error(`Failed to parse prompts.json: ${error instanceof Error ? error.message : \"Unknown error\"}`);\n }\n }\n\n static savePromptsConfig(config: PromptsConfig): void {\n const configPath = this.getPromptsConfigPath();\n fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + \"\\n\");\n }\n\n static initializePromptsConfig(): { created: boolean; path: string } {\n const configPath = this.getPromptsConfigPath();\n const existed = fs.existsSync(configPath);\n\n if (!existed) {\n const emptyConfig: PromptsConfig = { prompts: {} };\n this.savePromptsConfig(emptyConfig);\n return { created: true, path: configPath };\n }\n\n return { created: false, path: configPath };\n }\n\n static loadPromptsLock(): PromptsLock {\n const lockPath = this.getPromptsLockPath();\n\n if (!fs.existsSync(lockPath)) {\n return {\n lockfileVersion: 1,\n prompts: {}\n };\n }\n\n try {\n const content = fs.readFileSync(lockPath, \"utf-8\");\n return JSON.parse(content) as PromptsLock;\n } catch (error) {\n throw new Error(`Failed to parse prompts-lock.json: ${error instanceof Error ? error.message : \"Unknown error\"}`);\n }\n }\n\n static savePromptsLock(lock: PromptsLock): void {\n const lockPath = this.getPromptsLockPath();\n fs.writeFileSync(lockPath, JSON.stringify(lock, null, 2) + \"\\n\");\n }\n\n static initializePromptsLock(): { created: boolean; path: string } {\n const lockPath = this.getPromptsLockPath();\n const existed = fs.existsSync(lockPath);\n\n if (!existed) {\n const emptyLock: PromptsLock = {\n lockfileVersion: 1,\n prompts: {}\n };\n this.savePromptsLock(emptyLock);\n return { created: true, path: lockPath };\n }\n\n return { created: false, path: lockPath };\n }\n\n static loadLocalPrompt(filePath: string): LocalPromptConfig {\n const fullPath = path.resolve(filePath);\n\n if (!fs.existsSync(fullPath)) {\n throw new Error(`Local prompt file not found: ${filePath}`);\n }\n\n try {\n const content = fs.readFileSync(fullPath, \"utf-8\");\n const rawData = yaml.load(content);\n\n // Validate with zod and provide nice error messages\n const result = localPromptConfigSchema.safeParse(rawData);\n\n if (!result.success) {\n // Format zod errors nicely (manually since z.prettifyError might not be available)\n const prettyError = result.error.issues\n .map(issue => `✖ ${issue.message}${issue.path.length > 0 ? `\\n → at ${issue.path.join('.')}` : ''}`)\n .join('\\n');\n\n throw new Error(\n `Invalid prompt configuration in ${chalk.yellow(filePath)}:\\n${prettyError}`\n );\n }\n\n return result.data;\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"Invalid prompt configuration\")) {\n throw error; // Re-throw zod validation errors as-is\n }\n throw new Error(`Failed to parse local prompt file ${filePath}: ${error instanceof Error ? error.message : \"Unknown error\"}`);\n }\n }\n\n static saveMaterializedPrompt(name: string, prompt: MaterializedPrompt): string {\n const materializedDir = this.getMaterializedDir();\n const parts = name.split(\"/\");\n const fileName = `${parts[parts.length - 1]}.prompt.yaml`;\n\n // Create nested directories if needed\n if (parts.length > 1) {\n const subDir = path.join(materializedDir, ...parts.slice(0, -1));\n if (!fs.existsSync(subDir)) {\n fs.mkdirSync(subDir, { recursive: true });\n }\n }\n\n const filePath = path.join(materializedDir, ...parts.slice(0, -1), fileName);\n\n // Convert to YAML format using the converter\n const yamlContent = PromptConverter.fromMaterializedToYaml(prompt);\n\n const yamlString = yaml.dump(yamlContent, {\n lineWidth: -1,\n noRefs: true,\n sortKeys: false\n });\n\n fs.writeFileSync(filePath, yamlString);\n return filePath;\n }\n\n static getLocalPromptFiles(): string[] {\n const promptsDir = this.getPromptsDir();\n const materializedDir = this.getMaterializedDir();\n\n if (!fs.existsSync(promptsDir)) {\n return [];\n }\n\n const files: string[] = [];\n\n const walkDir = (dir: string, relativePath = \"\"): void => {\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n const relativeFilePath = path.join(relativePath, entry.name);\n\n if (entry.isDirectory()) {\n // Skip the .materialized directory\n if (fullPath === materializedDir) {\n continue;\n }\n walkDir(fullPath, relativeFilePath);\n } else if (entry.isFile() && entry.name.endsWith(\".prompt.yaml\")) {\n files.push(path.join(promptsDir, relativeFilePath));\n }\n }\n };\n\n walkDir(promptsDir);\n return files;\n }\n\n static promptNameFromPath(filePath: string): string {\n const promptsDir = this.getPromptsDir();\n const relativePath = path.relative(promptsDir, filePath);\n return relativePath.replace(/\\.prompt\\.yaml$/, \"\");\n }\n\n static cleanupOrphanedMaterializedFiles(currentDependencies: Set<string>): string[] {\n const materializedDir = this.getMaterializedDir();\n\n if (!fs.existsSync(materializedDir)) {\n return [];\n }\n\n const cleaned: string[] = [];\n\n const cleanupDir = (dir: string, relativePath = \"\"): void => {\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n const relativeFilePath = path.join(relativePath, entry.name);\n\n if (entry.isDirectory()) {\n cleanupDir(fullPath, relativeFilePath);\n\n // Remove empty directories\n try {\n const dirEntries = fs.readdirSync(fullPath);\n if (dirEntries.length === 0) {\n fs.rmdirSync(fullPath);\n }\n } catch {\n // Directory not empty or other error, ignore\n }\n } else if (entry.isFile() && entry.name.endsWith(\".prompt.yaml\")) {\n // Extract prompt name from materialized file path\n const promptName = relativeFilePath.replace(/\\.prompt\\.yaml$/, \"\");\n\n if (!currentDependencies.has(promptName)) {\n fs.unlinkSync(fullPath);\n cleaned.push(promptName);\n }\n }\n }\n };\n\n cleanupDir(materializedDir);\n return cleaned;\n }\n\n static updateLockEntry(lock: PromptsLock, name: string, prompt: MaterializedPrompt, materializedPath: string): void {\n const relativePath = path.relative(process.cwd(), materializedPath);\n\n lock.prompts[name] = {\n version: prompt.version,\n versionId: prompt.versionId,\n materialized: relativePath,\n };\n }\n\n static removeFromLock(lock: PromptsLock, names: string[]): void {\n for (const name of names) {\n delete lock.prompts[name];\n }\n }\n\n static addToGitignore(entry: string): { added: boolean; existed: boolean } {\n const gitignorePath = path.join(process.cwd(), \".gitignore\");\n\n // Check if .gitignore exists\n if (!fs.existsSync(gitignorePath)) {\n // Create new .gitignore with the entry\n fs.writeFileSync(gitignorePath, `${entry}\\n`);\n return { added: true, existed: false };\n }\n\n // Read existing .gitignore\n const content = fs.readFileSync(gitignorePath, \"utf-8\");\n const lines = content.split(\"\\n\").map(line => line.trim());\n\n // Check if entry already exists\n if (lines.includes(entry)) {\n return { added: false, existed: true };\n }\n\n // Add entry to .gitignore\n const newContent = content.endsWith(\"\\n\") ? `${content}${entry}\\n` : `${content}\\n${entry}\\n`;\n fs.writeFileSync(gitignorePath, newContent);\n\n return { added: true, existed: false };\n }\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-2ODBGSBI.js"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-2ODBGSBI.js"}
|