langwatch 0.13.0 → 0.15.0
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-ZAPD2GBO.mjs → add-2IXDXEK6.mjs} +5 -5
- package/dist/{add-Z5UVUPCK.js → add-JT6DMMHI.js} +8 -8
- package/dist/{add-Z5UVUPCK.js.map → add-JT6DMMHI.js.map} +1 -1
- package/dist/chunk-2L4OQ2V4.js +191 -0
- package/dist/chunk-2L4OQ2V4.js.map +1 -0
- package/dist/{chunk-SZRV7E6P.mjs → chunk-3FGEJOXJ.mjs} +2 -2
- package/dist/{chunk-RM2VUAFL.js → chunk-3SRD4FTK.js} +11 -11
- package/dist/{chunk-RM2VUAFL.js.map → chunk-3SRD4FTK.js.map} +1 -1
- package/dist/{chunk-J4HK6XZR.mjs → chunk-62FCDILL.mjs} +5 -5
- package/dist/{chunk-OAKQ7UBU.mjs → chunk-AEBXFLKZ.mjs} +3 -3
- package/dist/chunk-CMWRDIEK.js +331 -0
- package/dist/chunk-CMWRDIEK.js.map +1 -0
- package/dist/chunk-FONDDULA.mjs +331 -0
- package/dist/chunk-FONDDULA.mjs.map +1 -0
- package/dist/{chunk-NPFWFQK6.js → chunk-HKAAWGL2.js} +2 -2
- package/dist/{chunk-NPFWFQK6.js.map → chunk-HKAAWGL2.js.map} +1 -1
- package/dist/{chunk-IIUI2XYW.mjs → chunk-KD5U3MP3.mjs} +11 -2
- package/dist/chunk-KD5U3MP3.mjs.map +1 -0
- package/dist/{chunk-DXBTJGCK.js → chunk-KRVLZYQ2.js} +10 -10
- package/dist/{chunk-DXBTJGCK.js.map → chunk-KRVLZYQ2.js.map} +1 -1
- package/dist/{chunk-4BNGSDYW.js → chunk-OFM5YRU7.js} +14 -14
- package/dist/{chunk-4BNGSDYW.js.map → chunk-OFM5YRU7.js.map} +1 -1
- package/dist/{chunk-ONXIZKC6.js → chunk-SHJZRXU7.js} +11 -2
- package/dist/chunk-SHJZRXU7.js.map +1 -0
- package/dist/chunk-ZSFUEQNQ.mjs +191 -0
- package/dist/chunk-ZSFUEQNQ.mjs.map +1 -0
- package/dist/{chunk-77XIPD42.mjs → chunk-ZWP3XAML.mjs} +2 -2
- package/dist/{chunk-77XIPD42.mjs.map → chunk-ZWP3XAML.mjs.map} +1 -1
- package/dist/cli/index.js +30 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +30 -6
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{implementation-Ck58nRkT.d.mts → implementation-Dl15eRjo.d.mts} +1 -1
- package/dist/{implementation-Bnc8Aymq.d.ts → implementation-gLzM6qpI.d.ts} +1 -1
- package/dist/index.d.mts +31 -3
- package/dist/index.d.ts +31 -3
- package/dist/index.js +72 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -9
- package/dist/index.mjs.map +1 -1
- package/dist/{list-LASBYRI4.js → list-DVHIOSYS.js} +8 -8
- package/dist/{list-LASBYRI4.js.map → list-DVHIOSYS.js.map} +1 -1
- package/dist/{list-XX4VPNJA.mjs → list-YTBLDLDR.mjs} +5 -5
- package/dist/{login-2VCZDSLE.js → login-5AK4ERR6.js} +3 -3
- package/dist/{login-2VCZDSLE.js.map → login-5AK4ERR6.js.map} +1 -1
- package/dist/{login-CZ2257SV.mjs → login-PEGONPR5.mjs} +2 -2
- package/dist/observability-sdk/index.d.mts +3 -3
- package/dist/observability-sdk/index.d.ts +3 -3
- package/dist/observability-sdk/index.js +4 -4
- package/dist/observability-sdk/index.js.map +1 -1
- package/dist/observability-sdk/index.mjs +8 -8
- package/dist/observability-sdk/instrumentation/langchain/index.d.mts +1 -1
- package/dist/observability-sdk/instrumentation/langchain/index.d.ts +1 -1
- package/dist/observability-sdk/instrumentation/langchain/index.js +3 -3
- package/dist/observability-sdk/instrumentation/langchain/index.mjs +1 -1
- package/dist/observability-sdk/setup/node/index.js +4 -4
- package/dist/observability-sdk/setup/node/index.mjs +3 -3
- package/dist/pull-5PYS2W6F.js +20 -0
- package/dist/pull-5PYS2W6F.js.map +1 -0
- package/dist/pull-LRX5WFAL.mjs +20 -0
- package/dist/pull-LRX5WFAL.mjs.map +1 -0
- package/dist/push-23BCXSEH.mjs +20 -0
- package/dist/push-23BCXSEH.mjs.map +1 -0
- package/dist/push-IK2OQDXQ.js +20 -0
- package/dist/push-IK2OQDXQ.js.map +1 -0
- package/dist/{remove-XWN3XTF5.js → remove-BFUQEPHI.js} +7 -7
- package/dist/{remove-XWN3XTF5.js.map → remove-BFUQEPHI.js.map} +1 -1
- package/dist/{remove-KESD7YHL.mjs → remove-M2PKTPUW.mjs} +5 -5
- package/dist/sync-EQFZ2JB3.js +123 -0
- package/dist/sync-EQFZ2JB3.js.map +1 -0
- package/dist/sync-K4SYFVKU.mjs +123 -0
- package/dist/sync-K4SYFVKU.mjs.map +1 -0
- package/dist/{types-5h2Im4pl.d.mts → types-ExKeJEM0.d.mts} +1179 -17
- package/dist/{types-fo-Ij9pl.d.ts → types-WRcnQUom.d.ts} +1179 -17
- package/package.json +1 -1
- package/dist/chunk-IIUI2XYW.mjs.map +0 -1
- package/dist/chunk-ONXIZKC6.js.map +0 -1
- package/dist/sync-IJ26JHEP.js +0 -413
- package/dist/sync-IJ26JHEP.js.map +0 -1
- package/dist/sync-SCVP7CHX.mjs +0 -413
- package/dist/sync-SCVP7CHX.mjs.map +0 -1
- /package/dist/{add-ZAPD2GBO.mjs.map → add-2IXDXEK6.mjs.map} +0 -0
- /package/dist/{chunk-SZRV7E6P.mjs.map → chunk-3FGEJOXJ.mjs.map} +0 -0
- /package/dist/{chunk-J4HK6XZR.mjs.map → chunk-62FCDILL.mjs.map} +0 -0
- /package/dist/{chunk-OAKQ7UBU.mjs.map → chunk-AEBXFLKZ.mjs.map} +0 -0
- /package/dist/{list-XX4VPNJA.mjs.map → list-YTBLDLDR.mjs.map} +0 -0
- /package/dist/{login-CZ2257SV.mjs.map → login-PEGONPR5.mjs.map} +0 -0
- /package/dist/{remove-KESD7YHL.mjs.map → remove-M2PKTPUW.mjs.map} +0 -0
|
@@ -0,0 +1,331 @@
|
|
|
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 _chunkF6E4XQQUjs = require('./chunk-F6E4XQQU.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkKRVLZYQ2js = require('./chunk-KRVLZYQ2.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkBYG3QS2Xjs = require('./chunk-BYG3QS2X.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkWAAQLJ67js = require('./chunk-WAAQLJ67.js');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkOHM7JUMRjs = require('./chunk-OHM7JUMR.js');
|
|
19
|
+
|
|
20
|
+
// src/cli/commands/push.ts
|
|
21
|
+
var _fs = require('fs'); var fs = _interopRequireWildcard(_fs);
|
|
22
|
+
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
23
|
+
var _chalk = require('chalk'); var _chalk2 = _interopRequireDefault(_chalk);
|
|
24
|
+
var _ora = require('ora'); var _ora2 = _interopRequireDefault(_ora);
|
|
25
|
+
var _jsyaml = require('js-yaml'); var yaml = _interopRequireWildcard(_jsyaml);
|
|
26
|
+
var _readline = require('readline'); var _readline2 = _interopRequireDefault(_readline);
|
|
27
|
+
var handleConflict = async (promptName, conflictInfo) => {
|
|
28
|
+
console.log(
|
|
29
|
+
_chalk2.default.yellow(`
|
|
30
|
+
\u26A0 Conflict detected for prompt: ${_chalk2.default.cyan(promptName)}`)
|
|
31
|
+
);
|
|
32
|
+
console.log(
|
|
33
|
+
_chalk2.default.gray(
|
|
34
|
+
`Local version: ${conflictInfo.localVersion}, Remote version: ${conflictInfo.remoteVersion}`
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
if (conflictInfo.differences.length > 0) {
|
|
38
|
+
console.log(_chalk2.default.yellow("\nDifferences:"));
|
|
39
|
+
conflictInfo.differences.forEach((diff) => {
|
|
40
|
+
console.log(_chalk2.default.gray(` \u2022 ${diff}`));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
console.log(_chalk2.default.yellow("\nOptions:"));
|
|
44
|
+
console.log(" [l] Use local version (overwrite remote)");
|
|
45
|
+
console.log(" [r] Use remote version (overwrite local)");
|
|
46
|
+
console.log(" [a] Abort push for this prompt");
|
|
47
|
+
const rl = _readline2.default.createInterface({
|
|
48
|
+
input: process.stdin,
|
|
49
|
+
output: process.stdout
|
|
50
|
+
});
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
rl.question("Choose resolution (l/r/a): ", (answer) => {
|
|
53
|
+
rl.close();
|
|
54
|
+
const choice = answer.toLowerCase();
|
|
55
|
+
if (choice === "l" || choice === "local") {
|
|
56
|
+
resolve("local");
|
|
57
|
+
} else if (choice === "r" || choice === "remote") {
|
|
58
|
+
resolve("remote");
|
|
59
|
+
} else {
|
|
60
|
+
resolve("abort");
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
var pushPrompts = async ({
|
|
66
|
+
config,
|
|
67
|
+
lock,
|
|
68
|
+
promptsApiService,
|
|
69
|
+
result
|
|
70
|
+
}) => {
|
|
71
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
72
|
+
const localFileRefs = Object.entries(config.prompts).filter(
|
|
73
|
+
([, dependency]) => {
|
|
74
|
+
return typeof dependency === "string" && dependency.startsWith("file:");
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
if (localFileRefs.length > 0) {
|
|
78
|
+
const pushSpinner = _ora2.default.call(void 0,
|
|
79
|
+
`Pushing ${localFileRefs.length} local prompts...`
|
|
80
|
+
).start();
|
|
81
|
+
for (const [promptName, dependency] of localFileRefs) {
|
|
82
|
+
try {
|
|
83
|
+
const filePath = dependency.slice(5);
|
|
84
|
+
const localConfig = _chunkWAAQLJ67js.FileManager.loadLocalPrompt(filePath);
|
|
85
|
+
const currentVersion = (_a = lock.prompts[promptName]) == null ? void 0 : _a.version;
|
|
86
|
+
const configData = {
|
|
87
|
+
model: localConfig.model,
|
|
88
|
+
prompt: _chunkWAAQLJ67js.PromptConverter.extractSystemPrompt(localConfig.messages),
|
|
89
|
+
messages: _chunkWAAQLJ67js.PromptConverter.filterNonSystemMessages(
|
|
90
|
+
localConfig.messages
|
|
91
|
+
),
|
|
92
|
+
temperature: (_b = localConfig.modelParameters) == null ? void 0 : _b.temperature,
|
|
93
|
+
max_tokens: (_c = localConfig.modelParameters) == null ? void 0 : _c.max_tokens,
|
|
94
|
+
inputs: [{ identifier: "input", type: "str" }],
|
|
95
|
+
outputs: [{ identifier: "output", type: "str" }]
|
|
96
|
+
};
|
|
97
|
+
const syncResult = await promptsApiService.sync({
|
|
98
|
+
name: promptName,
|
|
99
|
+
configData,
|
|
100
|
+
localVersion: currentVersion,
|
|
101
|
+
commitMessage: `Synced from local file: ${path.basename(filePath)}`
|
|
102
|
+
});
|
|
103
|
+
const relativePath = path.relative(process.cwd(), filePath);
|
|
104
|
+
let conflictResolution = null;
|
|
105
|
+
if (syncResult.action === "conflict") {
|
|
106
|
+
pushSpinner.stop();
|
|
107
|
+
conflictResolution = await handleConflict(
|
|
108
|
+
promptName,
|
|
109
|
+
syncResult.conflictInfo
|
|
110
|
+
);
|
|
111
|
+
if (conflictResolution === "abort") {
|
|
112
|
+
result.errors.push({
|
|
113
|
+
name: promptName,
|
|
114
|
+
error: "Push aborted due to conflict"
|
|
115
|
+
});
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (conflictResolution === "remote" && syncResult.conflictInfo) {
|
|
119
|
+
const remoteConfig = {
|
|
120
|
+
model: syncResult.conflictInfo.remoteConfigData.model,
|
|
121
|
+
modelParameters: {
|
|
122
|
+
temperature: syncResult.conflictInfo.remoteConfigData.temperature,
|
|
123
|
+
max_tokens: syncResult.conflictInfo.remoteConfigData.max_tokens
|
|
124
|
+
},
|
|
125
|
+
messages: [
|
|
126
|
+
{
|
|
127
|
+
role: "system",
|
|
128
|
+
content: syncResult.conflictInfo.remoteConfigData.prompt
|
|
129
|
+
},
|
|
130
|
+
...(_d = syncResult.conflictInfo.remoteConfigData.messages) != null ? _d : []
|
|
131
|
+
]
|
|
132
|
+
};
|
|
133
|
+
const yamlContent = yaml.dump(remoteConfig, {
|
|
134
|
+
lineWidth: -1,
|
|
135
|
+
noRefs: true,
|
|
136
|
+
sortKeys: false
|
|
137
|
+
});
|
|
138
|
+
fs.writeFileSync(filePath, yamlContent);
|
|
139
|
+
}
|
|
140
|
+
pushSpinner.start();
|
|
141
|
+
}
|
|
142
|
+
if (syncResult.prompt) {
|
|
143
|
+
lock.prompts[promptName] = {
|
|
144
|
+
version: syncResult.prompt.version,
|
|
145
|
+
versionId: syncResult.prompt.versionId,
|
|
146
|
+
materialized: filePath
|
|
147
|
+
};
|
|
148
|
+
} else if (syncResult.action === "conflict") {
|
|
149
|
+
const remoteVersion = (_f = (_e = syncResult.conflictInfo) == null ? void 0 : _e.remoteVersion) != null ? _f : 0;
|
|
150
|
+
if (conflictResolution === "remote") {
|
|
151
|
+
lock.prompts[promptName] = {
|
|
152
|
+
version: remoteVersion,
|
|
153
|
+
versionId: "remote_version",
|
|
154
|
+
materialized: filePath
|
|
155
|
+
};
|
|
156
|
+
} else {
|
|
157
|
+
const formattedConfig = _chunkWAAQLJ67js.PromptConverter.fromLocalToApiFormat(localConfig);
|
|
158
|
+
const updatedPrompt = await promptsApiService.update(promptName, _chunkOHM7JUMRjs.__spreadProps.call(void 0, _chunkOHM7JUMRjs.__spreadValues.call(void 0, {}, formattedConfig), {
|
|
159
|
+
commitMessage: `Updated via CLI: synced from local file`
|
|
160
|
+
}));
|
|
161
|
+
lock.prompts[promptName] = {
|
|
162
|
+
version: updatedPrompt.version,
|
|
163
|
+
versionId: updatedPrompt.versionId,
|
|
164
|
+
materialized: filePath
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
let actionText;
|
|
169
|
+
if (syncResult.action === "conflict") {
|
|
170
|
+
if (conflictResolution === "remote") {
|
|
171
|
+
actionText = "Pulled";
|
|
172
|
+
result.fetched.push({
|
|
173
|
+
name: promptName,
|
|
174
|
+
version: (_h = (_g = syncResult.conflictInfo) == null ? void 0 : _g.remoteVersion) != null ? _h : 0,
|
|
175
|
+
versionSpec: "latest"
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
actionText = "Pushed";
|
|
179
|
+
result.pushed.push({
|
|
180
|
+
name: promptName,
|
|
181
|
+
version: ((_j = (_i = syncResult.conflictInfo) == null ? void 0 : _i.remoteVersion) != null ? _j : 0) + 1
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
} else if (syncResult.action === "up_to_date") {
|
|
185
|
+
actionText = "Up-to-date";
|
|
186
|
+
result.unchanged.push(promptName);
|
|
187
|
+
} else {
|
|
188
|
+
const actionMap = {
|
|
189
|
+
created: "Created",
|
|
190
|
+
updated: "Updated",
|
|
191
|
+
conflict: "Conflict resolved",
|
|
192
|
+
up_to_date: "Up to date"
|
|
193
|
+
};
|
|
194
|
+
actionText = actionMap[syncResult.action] || "Pushed";
|
|
195
|
+
result.pushed.push({
|
|
196
|
+
name: promptName,
|
|
197
|
+
version: (_l = (_k = syncResult.prompt) == null ? void 0 : _k.version) != null ? _l : 0
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
pushSpinner.text = `${actionText} ${_chalk2.default.cyan(
|
|
201
|
+
promptName
|
|
202
|
+
)} ${_chalk2.default.gray(
|
|
203
|
+
`(version ${(_p = (_o = (_m = syncResult.prompt) == null ? void 0 : _m.version) != null ? _o : (_n = syncResult.conflictInfo) == null ? void 0 : _n.remoteVersion) != null ? _p : "unknown"})`
|
|
204
|
+
)} ${conflictResolution === "remote" ? "to" : "from"} ${_chalk2.default.gray(
|
|
205
|
+
relativePath
|
|
206
|
+
)}`;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
209
|
+
result.errors.push({ name: promptName, error: errorMessage });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
pushSpinner.stop();
|
|
213
|
+
}
|
|
214
|
+
const discoveredLocalFiles = _chunkWAAQLJ67js.FileManager.getLocalPromptFiles();
|
|
215
|
+
const orphanFiles = discoveredLocalFiles.filter((filePath) => {
|
|
216
|
+
const promptName = _chunkWAAQLJ67js.FileManager.promptNameFromPath(filePath);
|
|
217
|
+
return !config.prompts[promptName];
|
|
218
|
+
});
|
|
219
|
+
if (orphanFiles.length > 0) {
|
|
220
|
+
console.log(
|
|
221
|
+
_chalk2.default.yellow(
|
|
222
|
+
`
|
|
223
|
+
\u26A0 Found ${orphanFiles.length} orphan prompt file${orphanFiles.length > 1 ? "s" : ""}:`
|
|
224
|
+
)
|
|
225
|
+
);
|
|
226
|
+
for (const filePath of orphanFiles) {
|
|
227
|
+
const promptName = _chunkWAAQLJ67js.FileManager.promptNameFromPath(filePath);
|
|
228
|
+
const relativePath = path.relative(process.cwd(), filePath);
|
|
229
|
+
console.log(_chalk2.default.yellow(` ${relativePath}`));
|
|
230
|
+
console.log(
|
|
231
|
+
_chalk2.default.gray(
|
|
232
|
+
` Add to prompts.json: "${promptName}": "file:${relativePath}"`
|
|
233
|
+
)
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
console.log(
|
|
237
|
+
_chalk2.default.gray(
|
|
238
|
+
`
|
|
239
|
+
Tip: Add these to prompts.json to include them in push operations.`
|
|
240
|
+
)
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
var printPushResults = ({
|
|
245
|
+
result,
|
|
246
|
+
duration
|
|
247
|
+
}) => {
|
|
248
|
+
if (result.pushed.length > 0) {
|
|
249
|
+
for (const { name, version } of result.pushed) {
|
|
250
|
+
const localPath = `./prompts/${name}.prompt.yaml`;
|
|
251
|
+
console.log(
|
|
252
|
+
_chalk2.default.green(
|
|
253
|
+
`\u2713 Pushed ${_chalk2.default.cyan(name)} ${_chalk2.default.gray(
|
|
254
|
+
`(version ${version})`
|
|
255
|
+
)} from ${_chalk2.default.gray(localPath)}`
|
|
256
|
+
)
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (result.fetched.length > 0) {
|
|
261
|
+
for (const { name, version } of result.fetched) {
|
|
262
|
+
console.log(
|
|
263
|
+
_chalk2.default.green(
|
|
264
|
+
`\u2713 Pulled ${_chalk2.default.cyan(name)} ${_chalk2.default.gray(
|
|
265
|
+
`(version ${version})`
|
|
266
|
+
)} (resolved conflict with remote)`
|
|
267
|
+
)
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (result.errors.length > 0) {
|
|
272
|
+
for (const { name, error } of result.errors) {
|
|
273
|
+
console.log(_chalk2.default.red(`\u2717 Failed ${_chalk2.default.cyan(name)}: ${error}`));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const totalActions = result.fetched.length + result.pushed.length;
|
|
277
|
+
if (totalActions === 0 && result.errors.length === 0) {
|
|
278
|
+
console.log(_chalk2.default.gray(`Pushed in ${duration}s, no changes`));
|
|
279
|
+
} else {
|
|
280
|
+
const summary = [];
|
|
281
|
+
if (result.pushed.length > 0)
|
|
282
|
+
summary.push(`${result.pushed.length} pushed`);
|
|
283
|
+
if (result.fetched.length > 0)
|
|
284
|
+
summary.push(`${result.fetched.length} pulled (conflict resolution)`);
|
|
285
|
+
if (result.errors.length > 0)
|
|
286
|
+
summary.push(`${result.errors.length} errors`);
|
|
287
|
+
console.log(_chalk2.default.gray(`Pushed ${summary.join(", ")} in ${duration}s`));
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
var pushCommand = async () => {
|
|
291
|
+
console.log("\u2B06\uFE0F Pushing local prompts...");
|
|
292
|
+
const startTime = Date.now();
|
|
293
|
+
try {
|
|
294
|
+
_chunkF6E4XQQUjs.checkApiKey.call(void 0, );
|
|
295
|
+
const promptsApiService = new (0, _chunkKRVLZYQ2js.PromptsApiService)();
|
|
296
|
+
await _chunkBYG3QS2Xjs.ensureProjectInitialized.call(void 0, false);
|
|
297
|
+
const config = _chunkWAAQLJ67js.FileManager.loadPromptsConfig();
|
|
298
|
+
const lock = _chunkWAAQLJ67js.FileManager.loadPromptsLock();
|
|
299
|
+
const result = {
|
|
300
|
+
fetched: [],
|
|
301
|
+
pushed: [],
|
|
302
|
+
unchanged: [],
|
|
303
|
+
cleaned: [],
|
|
304
|
+
errors: []
|
|
305
|
+
};
|
|
306
|
+
await pushPrompts({ config, lock, promptsApiService, result });
|
|
307
|
+
_chunkWAAQLJ67js.FileManager.savePromptsLock(lock);
|
|
308
|
+
const duration = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
309
|
+
printPushResults({ result, duration });
|
|
310
|
+
if (result.errors.length > 0) {
|
|
311
|
+
process.exit(1);
|
|
312
|
+
}
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (error instanceof _chunkKRVLZYQ2js.PromptsError) {
|
|
315
|
+
console.error(_chalk2.default.red(`Error: ${error.message}`));
|
|
316
|
+
} else {
|
|
317
|
+
console.error(
|
|
318
|
+
_chalk2.default.red(
|
|
319
|
+
`Unexpected error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
320
|
+
)
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
process.exit(1);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
exports.pushPrompts = pushPrompts; exports.pushCommand = pushCommand;
|
|
331
|
+
//# sourceMappingURL=chunk-CMWRDIEK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-CMWRDIEK.js","../src/cli/commands/push.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACE;AACA;AACF,sDAA4B;AAC5B;AACA;ACnBA,+DAAoB;AACpB,uEAAsB;AACtB,4EAAkB;AAClB,oEAAgB;AAChB,8EAAsB;AAYtB,wFAAqB;AAGrB,IAAM,eAAA,EAAiB,MAAA,CACrB,UAAA,EACA,YAAA,EAAA,GAM0C;AAC1C,EAAA,OAAA,CAAQ,GAAA;AAAA,IACN,eAAA,CAAM,MAAA,CAAO,CAAA;AAAA,qCAAA,EAAqC,eAAA,CAAM,IAAA,CAAK,UAAU,CAAC,CAAA,CAAA;AAC1E,EAAA;AACQ,EAAA;AACA,IAAA;AACuC,MAAA;AAC7C,IAAA;AACF,EAAA;AAEyC,EAAA;AACG,IAAA;AACC,IAAA;AACJ,MAAA;AACtC,IAAA;AACH,EAAA;AAEsC,EAAA;AACkB,EAAA;AACA,EAAA;AACV,EAAA;AAEV,EAAA;AACnB,IAAA;AACC,IAAA;AACjB,EAAA;AAE+B,EAAA;AACiC,IAAA;AACpD,MAAA;AACyB,MAAA;AACQ,MAAA;AACzB,QAAA;AACiC,MAAA;AAChC,QAAA;AACX,MAAA;AACU,QAAA;AACjB,MAAA;AACD,IAAA;AACF,EAAA;AACH;AAMkC;AAChC,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAMmB;AAnFrB,EAAA;AAoFuD,EAAA;AAC/B,IAAA;AACkC,MAAA;AACtD,IAAA;AACF,EAAA;AAE8B,EAAA;AACR,IAAA;AACa,MAA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AAA;AAEf,EAAA;AAEvB,EAAA;AACU,IAAA;AAEoC,IAAA;AAEZ,IAAA;AAES,IAAA;AACJ,IAAA;AAEd,IAAA;AACf,MAAA;AACD,MAAA;AACG,MAAA;AACF,MAAA;AACD,MAAA;AACX,IAAA;AAEqD,IAAA;AAErB,IAAA;AAE2B,IAAA;AACtB,IAAA;AAEP,IAAA;AACd,MAAA;AAChB,IAAA;AACc,EAAA;AACqB,IAAA;AACiB,MAAA;AAC7C,IAAA;AACG,MAAA;AACA,QAAA;AAE6B,UAAA;AAEnC,QAAA;AACF,MAAA;AACF,IAAA;AACc,IAAA;AAChB,EAAA;AACF;ADnE8D;AACA;AACA;AACA;AACA","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-CMWRDIEK.js","sourcesContent":[null,"import * as fs from \"fs\";\nimport * as path from \"path\";\nimport chalk from \"chalk\";\nimport ora from \"ora\";\nimport * as yaml from \"js-yaml\";\nimport { PromptConverter } from \"@/cli/utils/promptConverter\";\nimport {\n type ConfigData,\n PromptsApiService,\n PromptsError,\n type SyncAction,\n} from \"@/client-sdk/services/prompts\";\nimport type { PromptsConfig, PromptsLock, SyncResult } from \"../types\";\nimport { FileManager } from \"../utils/fileManager\";\nimport { ensureProjectInitialized } from \"../utils/init\";\nimport { checkApiKey } from \"../utils/apiKey\";\nimport readline from \"node:readline\";\n\n// Handle conflict resolution - show diff and ask user to choose\nconst handleConflict = async (\n promptName: string,\n conflictInfo: {\n localVersion: number;\n remoteVersion: number;\n differences: string[];\n remoteConfigData: any;\n }\n): Promise<\"local\" | \"remote\" | \"abort\"> => {\n console.log(\n chalk.yellow(`\\n⚠ Conflict detected for prompt: ${chalk.cyan(promptName)}`)\n );\n console.log(\n chalk.gray(\n `Local version: ${conflictInfo.localVersion}, Remote version: ${conflictInfo.remoteVersion}`\n )\n );\n\n if (conflictInfo.differences.length > 0) {\n console.log(chalk.yellow(\"\\nDifferences:\"));\n conflictInfo.differences.forEach((diff) => {\n console.log(chalk.gray(` • ${diff}`));\n });\n }\n\n console.log(chalk.yellow(\"\\nOptions:\"));\n console.log(\" [l] Use local version (overwrite remote)\");\n console.log(\" [r] Use remote version (overwrite local)\");\n console.log(\" [a] Abort push for this prompt\");\n\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n });\n\n return new Promise((resolve) => {\n rl.question(\"Choose resolution (l/r/a): \", (answer: string) => {\n rl.close();\n const choice = answer.toLowerCase();\n if (choice === \"l\" || choice === \"local\") {\n resolve(\"local\");\n } else if (choice === \"r\" || choice === \"remote\") {\n resolve(\"remote\");\n } else {\n resolve(\"abort\");\n }\n });\n });\n};\n\n/**\n * Core push logic: pushes local prompts to the server.\n * Returns the result and mutates the lock object in place.\n */\nexport const pushPrompts = async ({\n config,\n lock,\n promptsApiService,\n result,\n}: {\n config: PromptsConfig;\n lock: PromptsLock;\n promptsApiService: PromptsApiService;\n result: SyncResult;\n}): Promise<void> => {\n const localFileRefs = Object.entries(config.prompts).filter(\n ([, dependency]) => {\n return typeof dependency === \"string\" && dependency.startsWith(\"file:\");\n }\n );\n\n if (localFileRefs.length > 0) {\n const pushSpinner = ora(\n `Pushing ${localFileRefs.length} local prompts...`\n ).start();\n\n for (const [promptName, dependency] of localFileRefs) {\n try {\n const filePath = (dependency as string).slice(5); // Remove \"file:\" prefix\n\n const localConfig = FileManager.loadLocalPrompt(filePath);\n\n const currentVersion = lock.prompts[promptName]?.version;\n\n const configData: ConfigData = {\n model: localConfig.model,\n prompt: PromptConverter.extractSystemPrompt(localConfig.messages),\n messages: PromptConverter.filterNonSystemMessages(\n localConfig.messages\n ) as Array<{\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n }>,\n temperature: localConfig.modelParameters?.temperature,\n max_tokens: localConfig.modelParameters?.max_tokens,\n inputs: [{ identifier: \"input\", type: \"str\" }],\n outputs: [{ identifier: \"output\", type: \"str\" }],\n };\n\n const syncResult = await promptsApiService.sync({\n name: promptName,\n configData,\n localVersion: currentVersion,\n commitMessage: `Synced from local file: ${path.basename(filePath)}`,\n });\n\n const relativePath = path.relative(process.cwd(), filePath);\n\n let conflictResolution: \"local\" | \"remote\" | \"abort\" | null = null;\n if (syncResult.action === \"conflict\") {\n pushSpinner.stop();\n conflictResolution = await handleConflict(\n promptName,\n syncResult.conflictInfo!\n );\n if (conflictResolution === \"abort\") {\n result.errors.push({\n name: promptName,\n error: \"Push aborted due to conflict\",\n });\n continue;\n }\n\n if (conflictResolution === \"remote\" && syncResult.conflictInfo) {\n const remoteConfig = {\n model: syncResult.conflictInfo.remoteConfigData.model,\n modelParameters: {\n temperature:\n syncResult.conflictInfo.remoteConfigData.temperature,\n max_tokens:\n syncResult.conflictInfo.remoteConfigData.max_tokens,\n },\n messages: [\n {\n role: \"system\" as const,\n content: syncResult.conflictInfo.remoteConfigData.prompt,\n },\n ...(syncResult.conflictInfo.remoteConfigData.messages ?? []),\n ],\n };\n\n const yamlContent = yaml.dump(remoteConfig, {\n lineWidth: -1,\n noRefs: true,\n sortKeys: false,\n });\n\n fs.writeFileSync(filePath, yamlContent);\n }\n\n pushSpinner.start();\n }\n\n if (syncResult.prompt) {\n lock.prompts[promptName] = {\n version: syncResult.prompt.version,\n versionId: syncResult.prompt.versionId,\n materialized: filePath,\n };\n } else if (syncResult.action === \"conflict\") {\n const remoteVersion = syncResult.conflictInfo?.remoteVersion ?? 0;\n if (conflictResolution === \"remote\") {\n lock.prompts[promptName] = {\n version: remoteVersion,\n versionId: \"remote_version\",\n materialized: filePath,\n };\n } else {\n const formattedConfig = PromptConverter.fromLocalToApiFormat(localConfig);\n const updatedPrompt = await promptsApiService.update(promptName, {\n ...formattedConfig,\n commitMessage: `Updated via CLI: synced from local file`\n });\n lock.prompts[promptName] = {\n version: updatedPrompt.version,\n versionId: updatedPrompt.versionId,\n materialized: filePath,\n };\n }\n }\n\n let actionText: string;\n if (syncResult.action === \"conflict\") {\n if (conflictResolution === \"remote\") {\n actionText = \"Pulled\";\n result.fetched.push({\n name: promptName,\n version: syncResult.conflictInfo?.remoteVersion ?? 0,\n versionSpec: \"latest\",\n });\n } else {\n actionText = \"Pushed\";\n result.pushed.push({\n name: promptName,\n version: (syncResult.conflictInfo?.remoteVersion ?? 0) + 1,\n });\n }\n } else if (syncResult.action === \"up_to_date\") {\n actionText = \"Up-to-date\";\n result.unchanged.push(promptName);\n } else {\n const actionMap: Record<SyncAction, string> = {\n created: \"Created\",\n updated: \"Updated\",\n conflict: \"Conflict resolved\",\n up_to_date: \"Up to date\",\n };\n actionText = actionMap[syncResult.action as SyncAction] || \"Pushed\";\n result.pushed.push({\n name: promptName,\n version: syncResult.prompt?.version ?? 0,\n });\n }\n\n pushSpinner.text = `${actionText} ${chalk.cyan(\n promptName\n )} ${chalk.gray(\n `(version ${\n syncResult.prompt?.version ??\n syncResult.conflictInfo?.remoteVersion ??\n \"unknown\"\n })`\n )} ${conflictResolution === \"remote\" ? \"to\" : \"from\"} ${chalk.gray(\n relativePath\n )}`;\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : \"Unknown error\";\n result.errors.push({ name: promptName, error: errorMessage });\n }\n }\n\n pushSpinner.stop();\n }\n\n // Check for orphan local prompt files and show helpful warnings\n const discoveredLocalFiles = FileManager.getLocalPromptFiles();\n const orphanFiles = discoveredLocalFiles.filter((filePath) => {\n const promptName = FileManager.promptNameFromPath(filePath);\n return !config.prompts[promptName];\n });\n\n if (orphanFiles.length > 0) {\n console.log(\n chalk.yellow(\n `\\n⚠ Found ${orphanFiles.length} orphan prompt file${\n orphanFiles.length > 1 ? \"s\" : \"\"\n }:`\n )\n );\n\n for (const filePath of orphanFiles) {\n const promptName = FileManager.promptNameFromPath(filePath);\n const relativePath = path.relative(process.cwd(), filePath);\n\n console.log(chalk.yellow(` ${relativePath}`));\n console.log(\n chalk.gray(\n ` Add to prompts.json: \"${promptName}\": \"file:${relativePath}\"`\n )\n );\n }\n\n console.log(\n chalk.gray(\n `\\nTip: Add these to prompts.json to include them in push operations.`\n )\n );\n }\n};\n\nconst printPushResults = ({\n result,\n duration,\n}: {\n result: SyncResult;\n duration: string;\n}): void => {\n if (result.pushed.length > 0) {\n for (const { name, version } of result.pushed) {\n const localPath = `./prompts/${name}.prompt.yaml`;\n console.log(\n chalk.green(\n `✓ Pushed ${chalk.cyan(name)} ${chalk.gray(\n `(version ${version})`\n )} from ${chalk.gray(localPath)}`\n )\n );\n }\n }\n\n if (result.fetched.length > 0) {\n for (const { name, version } of result.fetched) {\n console.log(\n chalk.green(\n `✓ Pulled ${chalk.cyan(name)} ${chalk.gray(\n `(version ${version})`\n )} (resolved conflict with remote)`\n )\n );\n }\n }\n\n if (result.errors.length > 0) {\n for (const { name, error } of result.errors) {\n console.log(chalk.red(`✗ Failed ${chalk.cyan(name)}: ${error}`));\n }\n }\n\n const totalActions = result.fetched.length + result.pushed.length;\n\n if (totalActions === 0 && result.errors.length === 0) {\n console.log(chalk.gray(`Pushed in ${duration}s, no changes`));\n } else {\n const summary = [];\n if (result.pushed.length > 0)\n summary.push(`${result.pushed.length} pushed`);\n if (result.fetched.length > 0)\n summary.push(`${result.fetched.length} pulled (conflict resolution)`);\n if (result.errors.length > 0)\n summary.push(`${result.errors.length} errors`);\n\n console.log(chalk.gray(`Pushed ${summary.join(\", \")} in ${duration}s`));\n }\n};\n\nexport const pushCommand = async (): Promise<void> => {\n console.log(\"⬆️ Pushing local prompts...\");\n\n const startTime = Date.now();\n\n try {\n checkApiKey();\n\n const promptsApiService = new PromptsApiService();\n\n await ensureProjectInitialized(false);\n\n const config = FileManager.loadPromptsConfig();\n const lock = FileManager.loadPromptsLock();\n\n const result: SyncResult = {\n fetched: [],\n pushed: [],\n unchanged: [],\n cleaned: [],\n errors: [],\n };\n\n await pushPrompts({ config, lock, promptsApiService, result });\n\n FileManager.savePromptsLock(lock);\n\n const duration = ((Date.now() - startTime) / 1000).toFixed(1);\n printPushResults({ result, duration });\n\n if (result.errors.length > 0) {\n process.exit(1);\n }\n } catch (error) {\n if (error instanceof PromptsError) {\n console.error(chalk.red(`Error: ${error.message}`));\n } else {\n console.error(\n chalk.red(\n `Unexpected error: ${\n error instanceof Error ? error.message : \"Unknown error\"\n }`\n )\n );\n }\n process.exit(1);\n }\n};\n"]}
|