deepline 0.1.63 → 0.1.65
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/cli/index.js +933 -533
- package/dist/cli/index.mjs +837 -421
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +102 -49
- package/dist/index.mjs +98 -45
- package/dist/repo/apps/play-runner-workers/src/coordinator-entry.ts +9 -10
- package/dist/repo/apps/play-runner-workers/src/runtime/dataset-handles.ts +36 -27
- package/dist/repo/apps/play-runner-workers/src/runtime/tool-http-errors.ts +5 -2
- package/dist/repo/sdk/src/client.ts +71 -63
- package/dist/repo/sdk/src/errors.ts +5 -1
- package/dist/repo/sdk/src/http.ts +69 -17
- package/dist/repo/sdk/src/plays/local-file-discovery.ts +93 -24
- package/dist/repo/sdk/src/release.ts +2 -2
- package/dist/repo/sdk/src/tool-output.ts +40 -20
- package/dist/repo/shared_libs/play-runtime/batch-runtime.ts +10 -3
- package/dist/repo/shared_libs/play-runtime/batching-types.ts +15 -4
- package/dist/repo/shared_libs/play-runtime/coordinator-headers.ts +2 -1
- package/dist/repo/shared_libs/play-runtime/dedup-backend.ts +0 -0
- package/dist/repo/shared_libs/play-runtime/default-batch-strategies.ts +3 -4
- package/dist/repo/shared_libs/play-runtime/run-failure.ts +1 -3
- package/dist/repo/shared_libs/play-runtime/step-lifecycle-tracker.ts +4 -1
- package/dist/repo/shared_libs/play-runtime/tool-batch-executor.ts +4 -1
- package/dist/repo/shared_libs/plays/dataset.ts +10 -11
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -25,8 +25,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
|
|
26
26
|
// src/cli/index.ts
|
|
27
27
|
var import_promises5 = require("fs/promises");
|
|
28
|
-
var
|
|
29
|
-
var
|
|
28
|
+
var import_node_path17 = require("path");
|
|
29
|
+
var import_node_os10 = require("os");
|
|
30
30
|
var import_commander3 = require("commander");
|
|
31
31
|
|
|
32
32
|
// src/config.ts
|
|
@@ -57,7 +57,11 @@ var RateLimitError = class extends DeeplineError {
|
|
|
57
57
|
/** Milliseconds to wait before retrying, from the `Retry-After` response header. Defaults to 5000. */
|
|
58
58
|
retryAfterMs;
|
|
59
59
|
constructor(retryAfterMs = 5e3, message) {
|
|
60
|
-
super(
|
|
60
|
+
super(
|
|
61
|
+
message ?? `Rate limited. Retry after ${retryAfterMs}ms.`,
|
|
62
|
+
429,
|
|
63
|
+
"RATE_LIMIT"
|
|
64
|
+
);
|
|
61
65
|
this.name = "RateLimitError";
|
|
62
66
|
this.retryAfterMs = retryAfterMs;
|
|
63
67
|
}
|
|
@@ -218,12 +222,17 @@ function resolveConfig(options) {
|
|
|
218
222
|
};
|
|
219
223
|
}
|
|
220
224
|
|
|
225
|
+
// src/http.ts
|
|
226
|
+
var import_node_fs2 = require("fs");
|
|
227
|
+
var import_node_os2 = require("os");
|
|
228
|
+
var import_node_path2 = require("path");
|
|
229
|
+
|
|
221
230
|
// src/release.ts
|
|
222
231
|
var SDK_RELEASE = {
|
|
223
|
-
version: "0.1.
|
|
232
|
+
version: "0.1.65",
|
|
224
233
|
apiContract: "2026-05-play-bootstrap-dataset-summary",
|
|
225
234
|
supportPolicy: {
|
|
226
|
-
latest: "0.1.
|
|
235
|
+
latest: "0.1.65",
|
|
227
236
|
minimumSupported: "0.1.53",
|
|
228
237
|
deprecatedBelow: "0.1.53"
|
|
229
238
|
}
|
|
@@ -239,19 +248,51 @@ var COORDINATOR_URL_OVERRIDE_HEADER = "x-deepline-coordinator-url";
|
|
|
239
248
|
var WORKER_CALLBACK_URL_OVERRIDE_HEADER = "x-deepline-worker-callback-url";
|
|
240
249
|
|
|
241
250
|
// src/http.ts
|
|
251
|
+
var MAX_DIAGNOSTIC_HEADER_LENGTH = 120;
|
|
242
252
|
var HttpClient = class {
|
|
243
253
|
constructor(config) {
|
|
244
254
|
this.config = config;
|
|
245
255
|
}
|
|
246
256
|
config;
|
|
257
|
+
cleanDiagnosticHeader(value) {
|
|
258
|
+
const normalized = String(value ?? "").replace(/[\u0000-\u001f\u007f]/g, " ").trim().slice(0, MAX_DIAGNOSTIC_HEADER_LENGTH);
|
|
259
|
+
return normalized || null;
|
|
260
|
+
}
|
|
261
|
+
readSkillsVersionHeader() {
|
|
262
|
+
const explicit = this.cleanDiagnosticHeader(
|
|
263
|
+
process.env.DEEPLINE_SKILLS_VERSION
|
|
264
|
+
);
|
|
265
|
+
if (explicit) return explicit;
|
|
266
|
+
try {
|
|
267
|
+
const versionPath = (0, import_node_path2.join)(
|
|
268
|
+
process.env.HOME?.trim() || (0, import_node_os2.homedir)(),
|
|
269
|
+
".local",
|
|
270
|
+
"deepline",
|
|
271
|
+
baseUrlSlug(this.config.baseUrl),
|
|
272
|
+
"sdk-skills",
|
|
273
|
+
".version"
|
|
274
|
+
);
|
|
275
|
+
if (!(0, import_node_fs2.existsSync)(versionPath)) return null;
|
|
276
|
+
return this.cleanDiagnosticHeader((0, import_node_fs2.readFileSync)(versionPath, "utf-8"));
|
|
277
|
+
} catch {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
247
281
|
authHeaders(extra) {
|
|
248
282
|
const headers = {
|
|
249
|
-
|
|
283
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
250
284
|
"User-Agent": `deepline-ts-sdk/${SDK_VERSION}`,
|
|
285
|
+
"X-Deepline-Client-Family": "sdk",
|
|
286
|
+
"X-Deepline-CLI-Family": "sdk",
|
|
287
|
+
"X-Deepline-CLI-Version": SDK_VERSION,
|
|
251
288
|
"X-Deepline-SDK-Version": SDK_VERSION,
|
|
252
289
|
"X-Deepline-API-Contract": SDK_API_CONTRACT,
|
|
253
290
|
...extra
|
|
254
291
|
};
|
|
292
|
+
const skillsVersion = this.readSkillsVersionHeader();
|
|
293
|
+
if (skillsVersion) {
|
|
294
|
+
headers["X-Deepline-Skills-Version"] = skillsVersion;
|
|
295
|
+
}
|
|
255
296
|
const bypassToken = typeof process !== "undefined" ? process.env?.VERCEL_PROTECTION_BYPASS_TOKEN : void 0;
|
|
256
297
|
if (bypassToken) {
|
|
257
298
|
headers["x-vercel-protection-bypass"] = bypassToken;
|
|
@@ -929,31 +970,34 @@ var DeeplineClient = class {
|
|
|
929
970
|
* artifactStorageKey: 'plays/v1/orgs/acme/plays/my-play/artifacts/playgraph_abc123.json',
|
|
930
971
|
* });
|
|
931
972
|
* ```
|
|
932
|
-
|
|
973
|
+
*/
|
|
933
974
|
async startPlayRun(request) {
|
|
934
|
-
const response = await this.http.post(
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
975
|
+
const response = await this.http.post(
|
|
976
|
+
"/api/v2/plays/run",
|
|
977
|
+
{
|
|
978
|
+
...request.name ? { name: request.name } : {},
|
|
979
|
+
...request.revisionId ? { revisionId: request.revisionId } : {},
|
|
980
|
+
...request.artifactStorageKey ? { artifactStorageKey: request.artifactStorageKey } : {},
|
|
981
|
+
...request.sourceCode ? { sourceCode: request.sourceCode } : {},
|
|
982
|
+
...request.sourceFiles ? { sourceFiles: request.sourceFiles } : {},
|
|
983
|
+
..."staticPipeline" in request ? { staticPipeline: request.staticPipeline } : {},
|
|
984
|
+
...request.artifactHash ? { artifactHash: request.artifactHash } : {},
|
|
985
|
+
...request.graphHash ? { graphHash: request.graphHash } : {},
|
|
986
|
+
...request.runtimeArtifact ? { runtimeArtifact: request.runtimeArtifact } : {},
|
|
987
|
+
...request.compilerManifest ? { compilerManifest: request.compilerManifest } : {},
|
|
988
|
+
...request.inputFileUpload ? { inputFileUpload: request.inputFileUpload } : {},
|
|
989
|
+
...request.packagedFileUploads?.length ? { packagedFileUploads: request.packagedFileUploads } : {},
|
|
990
|
+
...request.input ? { input: request.input } : {},
|
|
991
|
+
...request.inputFile ? { inputFile: request.inputFile } : {},
|
|
992
|
+
...request.packagedFiles?.length ? { packagedFiles: request.packagedFiles } : {},
|
|
993
|
+
...request.force ? { force: true } : {},
|
|
994
|
+
...typeof request.waitForCompletionMs === "number" ? { waitForCompletionMs: request.waitForCompletionMs } : {},
|
|
995
|
+
// Profile selection is the API's job, not the CLI's. The server
|
|
996
|
+
// hardcodes workers_edge as the default; tests that want a
|
|
997
|
+
// different profile pass `request.profile` explicitly.
|
|
998
|
+
...request.profile ? { profile: request.profile } : {}
|
|
999
|
+
}
|
|
1000
|
+
);
|
|
957
1001
|
return normalizePlayRunStart(response);
|
|
958
1002
|
}
|
|
959
1003
|
async *startPlayRunStream(request, options) {
|
|
@@ -1205,10 +1249,7 @@ var DeeplineClient = class {
|
|
|
1205
1249
|
}
|
|
1206
1250
|
return formData;
|
|
1207
1251
|
};
|
|
1208
|
-
const response = await this.http.postFormData(
|
|
1209
|
-
"/api/v2/plays/files/stage",
|
|
1210
|
-
buildFormData
|
|
1211
|
-
);
|
|
1252
|
+
const response = await this.http.postFormData("/api/v2/plays/files/stage", buildFormData);
|
|
1212
1253
|
return response.files;
|
|
1213
1254
|
}
|
|
1214
1255
|
async resolveStagedPlayFiles(files) {
|
|
@@ -1655,7 +1696,9 @@ var DeeplineClient = class {
|
|
|
1655
1696
|
}
|
|
1656
1697
|
options?.onProgress?.(status);
|
|
1657
1698
|
if (TERMINAL_PLAY_STATUSES.has(status.status)) {
|
|
1658
|
-
const finalStatus = await this.getPlayStatus(
|
|
1699
|
+
const finalStatus = await this.getPlayStatus(
|
|
1700
|
+
status.runId || workflowId
|
|
1701
|
+
).catch(() => status);
|
|
1659
1702
|
return playRunResultFromStatus(finalStatus, start, workflowId);
|
|
1660
1703
|
}
|
|
1661
1704
|
}
|
|
@@ -1738,15 +1781,15 @@ async function enforceSdkCompatibility(baseUrl) {
|
|
|
1738
1781
|
}
|
|
1739
1782
|
|
|
1740
1783
|
// src/cli/commands/auth.ts
|
|
1741
|
-
var
|
|
1742
|
-
var
|
|
1743
|
-
var
|
|
1784
|
+
var import_node_fs4 = require("fs");
|
|
1785
|
+
var import_node_os4 = require("os");
|
|
1786
|
+
var import_node_path4 = require("path");
|
|
1744
1787
|
|
|
1745
1788
|
// src/cli/utils.ts
|
|
1746
|
-
var
|
|
1789
|
+
var import_node_fs3 = require("fs");
|
|
1747
1790
|
var import_promises = require("fs/promises");
|
|
1748
|
-
var
|
|
1749
|
-
var
|
|
1791
|
+
var import_node_os3 = require("os");
|
|
1792
|
+
var import_node_path3 = require("path");
|
|
1750
1793
|
var childProcess = __toESM(require("child_process"));
|
|
1751
1794
|
var import_sync = require("csv-parse/sync");
|
|
1752
1795
|
var import_sync2 = require("csv-stringify/sync");
|
|
@@ -1757,15 +1800,15 @@ function getAuthedHttpClient() {
|
|
|
1757
1800
|
return { config, http: new HttpClient(config) };
|
|
1758
1801
|
}
|
|
1759
1802
|
async function writeOutputFile(filename, content) {
|
|
1760
|
-
const outputDir = (0,
|
|
1803
|
+
const outputDir = (0, import_node_path3.resolve)(process.cwd(), "deepline", "data");
|
|
1761
1804
|
await (0, import_promises.mkdir)(outputDir, { recursive: true });
|
|
1762
|
-
const fullPath = (0,
|
|
1805
|
+
const fullPath = (0, import_node_path3.join)(outputDir, filename);
|
|
1763
1806
|
await (0, import_promises.writeFile)(fullPath, content, "utf-8");
|
|
1764
1807
|
return fullPath;
|
|
1765
1808
|
}
|
|
1766
1809
|
function browserFocusStateFile() {
|
|
1767
|
-
const homeDir = process.env.HOME || (0,
|
|
1768
|
-
return (0,
|
|
1810
|
+
const homeDir = process.env.HOME || (0, import_node_os3.homedir)();
|
|
1811
|
+
return (0, import_node_path3.join)(
|
|
1769
1812
|
homeDir,
|
|
1770
1813
|
".local",
|
|
1771
1814
|
"deepline",
|
|
@@ -1777,10 +1820,10 @@ function browserFocusStateFile() {
|
|
|
1777
1820
|
function claimBrowserFocus(now = Date.now()) {
|
|
1778
1821
|
const statePath = browserFocusStateFile();
|
|
1779
1822
|
try {
|
|
1780
|
-
(0,
|
|
1823
|
+
(0, import_node_fs3.mkdirSync)((0, import_node_path3.dirname)(statePath), { recursive: true });
|
|
1781
1824
|
let lastFocusedAt = 0;
|
|
1782
|
-
if ((0,
|
|
1783
|
-
const payload = JSON.parse((0,
|
|
1825
|
+
if ((0, import_node_fs3.existsSync)(statePath)) {
|
|
1826
|
+
const payload = JSON.parse((0, import_node_fs3.readFileSync)(statePath, "utf-8"));
|
|
1784
1827
|
const value = payload.lastFocusedAt ?? payload.last_focused_at;
|
|
1785
1828
|
if (typeof value === "number" && Number.isFinite(value)) {
|
|
1786
1829
|
lastFocusedAt = value;
|
|
@@ -1792,7 +1835,7 @@ function claimBrowserFocus(now = Date.now()) {
|
|
|
1792
1835
|
if (now - lastFocusedAt < BROWSER_FOCUS_COOLDOWN_MS) {
|
|
1793
1836
|
return false;
|
|
1794
1837
|
}
|
|
1795
|
-
(0,
|
|
1838
|
+
(0, import_node_fs3.writeFileSync)(statePath, JSON.stringify({ lastFocusedAt: now }), "utf-8");
|
|
1796
1839
|
return true;
|
|
1797
1840
|
} catch {
|
|
1798
1841
|
return true;
|
|
@@ -1826,7 +1869,7 @@ function readDefaultMacBrowserBundleId(runner = defaultBrowserCommandRunner) {
|
|
|
1826
1869
|
"/usr/bin/defaults",
|
|
1827
1870
|
[
|
|
1828
1871
|
"read",
|
|
1829
|
-
`${(0,
|
|
1872
|
+
`${(0, import_node_os3.homedir)()}/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist`,
|
|
1830
1873
|
"LSHandlers"
|
|
1831
1874
|
],
|
|
1832
1875
|
{ encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }
|
|
@@ -1946,11 +1989,9 @@ function openUrlMacos(targetUrl, allowFocus, runner = defaultBrowserCommandRunne
|
|
|
1946
1989
|
return true;
|
|
1947
1990
|
}
|
|
1948
1991
|
try {
|
|
1949
|
-
runner.execFileSync(
|
|
1950
|
-
"
|
|
1951
|
-
|
|
1952
|
-
{ stdio: "ignore" }
|
|
1953
|
-
);
|
|
1992
|
+
runner.execFileSync("open", [...allowFocus ? [] : ["-g"], targetUrl], {
|
|
1993
|
+
stdio: "ignore"
|
|
1994
|
+
});
|
|
1954
1995
|
return true;
|
|
1955
1996
|
} catch {
|
|
1956
1997
|
return false;
|
|
@@ -1987,11 +2028,11 @@ function collectLocalEnvInfo() {
|
|
|
1987
2028
|
return {
|
|
1988
2029
|
os: `${process.platform} ${process.arch}`,
|
|
1989
2030
|
node_version: process.version,
|
|
1990
|
-
home_dir: (0,
|
|
2031
|
+
home_dir: (0, import_node_os3.homedir)()
|
|
1991
2032
|
};
|
|
1992
2033
|
}
|
|
1993
2034
|
function readCsvRows(csvPath) {
|
|
1994
|
-
const raw = (0,
|
|
2035
|
+
const raw = (0, import_node_fs3.readFileSync)((0, import_node_path3.resolve)(csvPath), "utf-8");
|
|
1995
2036
|
return (0, import_sync.parse)(raw, {
|
|
1996
2037
|
columns: true,
|
|
1997
2038
|
skip_empty_lines: true
|
|
@@ -2144,7 +2185,10 @@ function createTimestampedName(prefix, extension) {
|
|
|
2144
2185
|
return `${prefix}-${timestamp}.${extension}`;
|
|
2145
2186
|
}
|
|
2146
2187
|
async function writeCsvRowsFile(prefix, rows) {
|
|
2147
|
-
const path = await writeOutputFile(
|
|
2188
|
+
const path = await writeOutputFile(
|
|
2189
|
+
createTimestampedName(prefix, "csv"),
|
|
2190
|
+
csvStringFromRows(rows)
|
|
2191
|
+
);
|
|
2148
2192
|
return path;
|
|
2149
2193
|
}
|
|
2150
2194
|
function clip(value, maxLength) {
|
|
@@ -2195,25 +2239,25 @@ function pendingClaimTokenPath(baseUrl) {
|
|
|
2195
2239
|
}
|
|
2196
2240
|
function savePendingClaimToken(baseUrl, claimToken) {
|
|
2197
2241
|
const filePath = pendingClaimTokenPath(baseUrl);
|
|
2198
|
-
const dir = (0,
|
|
2199
|
-
if (!(0,
|
|
2200
|
-
(0,
|
|
2242
|
+
const dir = (0, import_node_path4.dirname)(filePath);
|
|
2243
|
+
if (!(0, import_node_fs4.existsSync)(dir)) {
|
|
2244
|
+
(0, import_node_fs4.mkdirSync)(dir, { recursive: true });
|
|
2201
2245
|
}
|
|
2202
|
-
(0,
|
|
2246
|
+
(0, import_node_fs4.writeFileSync)(filePath, `${claimToken}
|
|
2203
2247
|
`, "utf-8");
|
|
2204
2248
|
}
|
|
2205
2249
|
function readPendingClaimToken(baseUrl) {
|
|
2206
2250
|
const filePath = pendingClaimTokenPath(baseUrl);
|
|
2207
|
-
if (!(0,
|
|
2251
|
+
if (!(0, import_node_fs4.existsSync)(filePath)) return "";
|
|
2208
2252
|
try {
|
|
2209
|
-
return (0,
|
|
2253
|
+
return (0, import_node_fs4.readFileSync)(filePath, "utf-8").trim();
|
|
2210
2254
|
} catch {
|
|
2211
2255
|
return "";
|
|
2212
2256
|
}
|
|
2213
2257
|
}
|
|
2214
2258
|
function clearPendingClaimToken(baseUrl) {
|
|
2215
2259
|
try {
|
|
2216
|
-
(0,
|
|
2260
|
+
(0, import_node_fs4.rmSync)(pendingClaimTokenPath(baseUrl), { force: true });
|
|
2217
2261
|
} catch {
|
|
2218
2262
|
}
|
|
2219
2263
|
}
|
|
@@ -2225,7 +2269,9 @@ function saveEnvValues(values, baseUrl) {
|
|
|
2225
2269
|
saveHostEnvValues(baseUrl, filtered);
|
|
2226
2270
|
}
|
|
2227
2271
|
async function httpJson(method, url, apiKey, body) {
|
|
2228
|
-
const headers = {
|
|
2272
|
+
const headers = {
|
|
2273
|
+
"Content-Type": "application/json"
|
|
2274
|
+
};
|
|
2229
2275
|
if (apiKey) headers["Authorization"] = `Bearer ${apiKey}`;
|
|
2230
2276
|
let response = null;
|
|
2231
2277
|
let lastError = null;
|
|
@@ -2280,12 +2326,24 @@ function sleep3(ms) {
|
|
|
2280
2326
|
}
|
|
2281
2327
|
function printDeeplineLogo() {
|
|
2282
2328
|
if (process.stdout.isTTY && (process.stdout.columns ?? 80) >= 70) {
|
|
2283
|
-
console.log(
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
console.log(
|
|
2287
|
-
|
|
2288
|
-
|
|
2329
|
+
console.log(
|
|
2330
|
+
" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557"
|
|
2331
|
+
);
|
|
2332
|
+
console.log(
|
|
2333
|
+
" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D"
|
|
2334
|
+
);
|
|
2335
|
+
console.log(
|
|
2336
|
+
" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557"
|
|
2337
|
+
);
|
|
2338
|
+
console.log(
|
|
2339
|
+
" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D"
|
|
2340
|
+
);
|
|
2341
|
+
console.log(
|
|
2342
|
+
" \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557"
|
|
2343
|
+
);
|
|
2344
|
+
console.log(
|
|
2345
|
+
" \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D"
|
|
2346
|
+
);
|
|
2289
2347
|
console.log("");
|
|
2290
2348
|
return;
|
|
2291
2349
|
}
|
|
@@ -2311,7 +2369,7 @@ async function handleRegister(args) {
|
|
|
2311
2369
|
}
|
|
2312
2370
|
if (!agentName) {
|
|
2313
2371
|
try {
|
|
2314
|
-
agentName = (0,
|
|
2372
|
+
agentName = (0, import_node_os4.hostname)() || "Deepline CLI (TS)";
|
|
2315
2373
|
} catch {
|
|
2316
2374
|
agentName = "Deepline CLI (TS)";
|
|
2317
2375
|
}
|
|
@@ -2319,7 +2377,12 @@ async function handleRegister(args) {
|
|
|
2319
2377
|
const payload = {};
|
|
2320
2378
|
if (orgName) payload.org_name = orgName;
|
|
2321
2379
|
if (agentName) payload.agent_name = agentName;
|
|
2322
|
-
const { status, data } = await httpJson(
|
|
2380
|
+
const { status, data } = await httpJson(
|
|
2381
|
+
"POST",
|
|
2382
|
+
`${baseUrl}/api/v2/auth/cli/register`,
|
|
2383
|
+
null,
|
|
2384
|
+
payload
|
|
2385
|
+
);
|
|
2323
2386
|
if (status >= 400) {
|
|
2324
2387
|
console.error(`Auth register failed (status ${status}).`);
|
|
2325
2388
|
if (data.error) console.error(String(data.error));
|
|
@@ -2329,9 +2392,12 @@ async function handleRegister(args) {
|
|
|
2329
2392
|
const claimToken = String(data.claim_token || "");
|
|
2330
2393
|
if (claimToken) {
|
|
2331
2394
|
savePendingClaimToken(baseUrl, claimToken);
|
|
2332
|
-
saveEnvValues(
|
|
2333
|
-
|
|
2334
|
-
|
|
2395
|
+
saveEnvValues(
|
|
2396
|
+
{
|
|
2397
|
+
[HOST_URL_ENV]: baseUrl
|
|
2398
|
+
},
|
|
2399
|
+
baseUrl
|
|
2400
|
+
);
|
|
2335
2401
|
}
|
|
2336
2402
|
if (claimUrl) {
|
|
2337
2403
|
console.log(" Opening approval page in your browser.");
|
|
@@ -2370,10 +2436,13 @@ async function handleRegister(args) {
|
|
|
2370
2436
|
if (state === "claimed") {
|
|
2371
2437
|
const apiKey = String(statusData.api_key || "");
|
|
2372
2438
|
if (apiKey) {
|
|
2373
|
-
saveEnvValues(
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2439
|
+
saveEnvValues(
|
|
2440
|
+
{
|
|
2441
|
+
[HOST_URL_ENV]: baseUrl,
|
|
2442
|
+
[API_KEY_ENV]: apiKey
|
|
2443
|
+
},
|
|
2444
|
+
baseUrl
|
|
2445
|
+
);
|
|
2377
2446
|
clearPendingClaimToken(baseUrl);
|
|
2378
2447
|
printClaimSuccessBanner(statusData);
|
|
2379
2448
|
return EXIT_OK;
|
|
@@ -2381,7 +2450,9 @@ async function handleRegister(args) {
|
|
|
2381
2450
|
}
|
|
2382
2451
|
if (state === "expired") {
|
|
2383
2452
|
clearPendingClaimToken(baseUrl);
|
|
2384
|
-
console.log(
|
|
2453
|
+
console.log(
|
|
2454
|
+
"That approval link expired. Please run: deepline auth register"
|
|
2455
|
+
);
|
|
2385
2456
|
return EXIT_AUTH;
|
|
2386
2457
|
}
|
|
2387
2458
|
await sleep3(2e3);
|
|
@@ -2432,10 +2503,13 @@ async function handleWait(args) {
|
|
|
2432
2503
|
if (state === "claimed") {
|
|
2433
2504
|
const apiKey = String(data.api_key || "");
|
|
2434
2505
|
if (apiKey) {
|
|
2435
|
-
saveEnvValues(
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2506
|
+
saveEnvValues(
|
|
2507
|
+
{
|
|
2508
|
+
[HOST_URL_ENV]: baseUrl,
|
|
2509
|
+
[API_KEY_ENV]: apiKey
|
|
2510
|
+
},
|
|
2511
|
+
baseUrl
|
|
2512
|
+
);
|
|
2439
2513
|
clearPendingClaimToken(baseUrl);
|
|
2440
2514
|
printClaimSuccessBanner(data);
|
|
2441
2515
|
return EXIT_OK;
|
|
@@ -2448,7 +2522,9 @@ async function handleWait(args) {
|
|
|
2448
2522
|
}
|
|
2449
2523
|
await sleep3(2e3);
|
|
2450
2524
|
}
|
|
2451
|
-
console.error(
|
|
2525
|
+
console.error(
|
|
2526
|
+
"Still pending. Approve the browser link, then run: deepline auth wait"
|
|
2527
|
+
);
|
|
2452
2528
|
return EXIT_AUTH;
|
|
2453
2529
|
}
|
|
2454
2530
|
async function handleStatus(args) {
|
|
@@ -2458,7 +2534,11 @@ async function handleStatus(args) {
|
|
|
2458
2534
|
let hostStatusPayload = null;
|
|
2459
2535
|
const hostLines = [];
|
|
2460
2536
|
try {
|
|
2461
|
-
const { status: hStatus, data: hData } = await httpJson(
|
|
2537
|
+
const { status: hStatus, data: hData } = await httpJson(
|
|
2538
|
+
"GET",
|
|
2539
|
+
`${baseUrl}/api/v2/health`,
|
|
2540
|
+
null
|
|
2541
|
+
);
|
|
2462
2542
|
if (hStatus === 200) {
|
|
2463
2543
|
hostStatusPayload = {
|
|
2464
2544
|
host: baseUrl,
|
|
@@ -2480,45 +2560,74 @@ async function handleStatus(args) {
|
|
|
2480
2560
|
const apiKey = resolveApiKeyForBaseUrl(baseUrl);
|
|
2481
2561
|
if (!apiKey) {
|
|
2482
2562
|
if (readPendingClaimToken(baseUrl)) {
|
|
2483
|
-
printCommandEnvelope(
|
|
2563
|
+
printCommandEnvelope(
|
|
2564
|
+
{
|
|
2565
|
+
...hostStatusPayload ?? { host: baseUrl },
|
|
2566
|
+
status: "pending",
|
|
2567
|
+
connected: false,
|
|
2568
|
+
next: "deepline auth wait",
|
|
2569
|
+
render: {
|
|
2570
|
+
sections: [
|
|
2571
|
+
{
|
|
2572
|
+
title: "auth status",
|
|
2573
|
+
lines: [...hostLines, "Status: pending"]
|
|
2574
|
+
}
|
|
2575
|
+
],
|
|
2576
|
+
actions: [{ label: "Run", command: "deepline auth wait" }]
|
|
2577
|
+
}
|
|
2578
|
+
},
|
|
2579
|
+
{ json: jsonOutput }
|
|
2580
|
+
);
|
|
2581
|
+
return EXIT_OK;
|
|
2582
|
+
}
|
|
2583
|
+
printCommandEnvelope(
|
|
2584
|
+
{
|
|
2484
2585
|
...hostStatusPayload ?? { host: baseUrl },
|
|
2485
|
-
status: "
|
|
2586
|
+
status: "not connected",
|
|
2486
2587
|
connected: false,
|
|
2487
|
-
next: "deepline auth
|
|
2588
|
+
next: "deepline auth register",
|
|
2488
2589
|
render: {
|
|
2489
|
-
sections: [
|
|
2490
|
-
|
|
2590
|
+
sections: [
|
|
2591
|
+
{
|
|
2592
|
+
title: "auth status",
|
|
2593
|
+
lines: [...hostLines, "Status: not connected"]
|
|
2594
|
+
}
|
|
2595
|
+
],
|
|
2596
|
+
actions: [{ label: "Run", command: "deepline auth register" }]
|
|
2491
2597
|
}
|
|
2492
|
-
},
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
printCommandEnvelope({
|
|
2496
|
-
...hostStatusPayload ?? { host: baseUrl },
|
|
2497
|
-
status: "not connected",
|
|
2498
|
-
connected: false,
|
|
2499
|
-
next: "deepline auth register",
|
|
2500
|
-
render: {
|
|
2501
|
-
sections: [{ title: "auth status", lines: [...hostLines, "Status: not connected"] }],
|
|
2502
|
-
actions: [{ label: "Run", command: "deepline auth register" }]
|
|
2503
|
-
}
|
|
2504
|
-
}, { json: jsonOutput });
|
|
2598
|
+
},
|
|
2599
|
+
{ json: jsonOutput }
|
|
2600
|
+
);
|
|
2505
2601
|
return EXIT_OK;
|
|
2506
2602
|
}
|
|
2507
|
-
const { status, data } = await httpJson(
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2603
|
+
const { status, data } = await httpJson(
|
|
2604
|
+
"POST",
|
|
2605
|
+
`${baseUrl}/api/v2/auth/cli/status`,
|
|
2606
|
+
apiKey,
|
|
2607
|
+
{
|
|
2608
|
+
api_key: apiKey,
|
|
2609
|
+
reveal
|
|
2610
|
+
}
|
|
2611
|
+
);
|
|
2511
2612
|
if (status === 401 || status === 403) {
|
|
2512
|
-
printCommandEnvelope(
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2613
|
+
printCommandEnvelope(
|
|
2614
|
+
{
|
|
2615
|
+
...hostStatusPayload ?? { host: baseUrl },
|
|
2616
|
+
status: "unauthorized",
|
|
2617
|
+
connected: false,
|
|
2618
|
+
next: "deepline auth register",
|
|
2619
|
+
render: {
|
|
2620
|
+
sections: [
|
|
2621
|
+
{
|
|
2622
|
+
title: "auth status",
|
|
2623
|
+
lines: [...hostLines, "Status: unauthorized"]
|
|
2624
|
+
}
|
|
2625
|
+
],
|
|
2626
|
+
actions: [{ label: "Run", command: "deepline auth register" }]
|
|
2627
|
+
}
|
|
2628
|
+
},
|
|
2629
|
+
{ json: jsonOutput }
|
|
2630
|
+
);
|
|
2522
2631
|
return EXIT_AUTH;
|
|
2523
2632
|
}
|
|
2524
2633
|
if (status >= 400) {
|
|
@@ -2545,35 +2654,44 @@ async function handleStatus(args) {
|
|
|
2545
2654
|
if (reveal) {
|
|
2546
2655
|
const apiKeyResp = String(data.api_key || apiKey);
|
|
2547
2656
|
if (apiKeyResp) {
|
|
2548
|
-
saveEnvValues(
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2657
|
+
saveEnvValues(
|
|
2658
|
+
{
|
|
2659
|
+
[HOST_URL_ENV]: baseUrl,
|
|
2660
|
+
[API_KEY_ENV]: apiKeyResp
|
|
2661
|
+
},
|
|
2662
|
+
baseUrl
|
|
2663
|
+
);
|
|
2552
2664
|
savedApiKeyPath = envFilePath(baseUrl);
|
|
2553
2665
|
}
|
|
2554
2666
|
}
|
|
2555
|
-
printCommandEnvelope(
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2667
|
+
printCommandEnvelope(
|
|
2668
|
+
{
|
|
2669
|
+
...payload,
|
|
2670
|
+
...savedApiKeyPath ? { saved_api_key_path: savedApiKeyPath } : {},
|
|
2671
|
+
render: {
|
|
2672
|
+
sections: [
|
|
2673
|
+
{
|
|
2674
|
+
title: "auth status",
|
|
2675
|
+
lines: [
|
|
2676
|
+
...hostLines,
|
|
2677
|
+
`Status: ${payload.status}`,
|
|
2678
|
+
`Rate limit tier: ${payload.rateLimitTier}`,
|
|
2679
|
+
...payload.workspace.name ? [`Workspace: ${payload.workspace.name}`] : [],
|
|
2680
|
+
...payload.workspace.slug ? [`Workspace slug: ${payload.workspace.slug}`] : [],
|
|
2681
|
+
...payload.workspace.id != null ? [`Org ID: ${payload.workspace.id}`] : [],
|
|
2682
|
+
...payload.user.id != null ? [`User ID: ${payload.user.id}`] : [],
|
|
2683
|
+
...payload.examples.length > 0 ? [
|
|
2684
|
+
"Examples:",
|
|
2685
|
+
...payload.examples.slice(0, 3).map((example) => ` ${String(example)}`)
|
|
2686
|
+
] : [],
|
|
2687
|
+
...savedApiKeyPath ? [`Saved API key to ${savedApiKeyPath}`] : []
|
|
2688
|
+
]
|
|
2689
|
+
}
|
|
2690
|
+
]
|
|
2691
|
+
}
|
|
2692
|
+
},
|
|
2693
|
+
{ json: jsonOutput }
|
|
2694
|
+
);
|
|
2577
2695
|
return EXIT_OK;
|
|
2578
2696
|
}
|
|
2579
2697
|
function registerAuthCommands(program) {
|
|
@@ -2593,7 +2711,9 @@ Notes:
|
|
|
2593
2711
|
Auth status shows the target host and active workspace without printing secrets.
|
|
2594
2712
|
`
|
|
2595
2713
|
);
|
|
2596
|
-
auth.command("register").description(
|
|
2714
|
+
auth.command("register").description(
|
|
2715
|
+
"Register this device and open the approval page in your browser."
|
|
2716
|
+
).addHelpText(
|
|
2597
2717
|
"after",
|
|
2598
2718
|
`
|
|
2599
2719
|
Notes:
|
|
@@ -2640,7 +2760,10 @@ Examples:
|
|
|
2640
2760
|
deepline auth status
|
|
2641
2761
|
deepline auth status --json
|
|
2642
2762
|
`
|
|
2643
|
-
).option(
|
|
2763
|
+
).option(
|
|
2764
|
+
"--reveal",
|
|
2765
|
+
"Persist the revealed API key back to the host auth file"
|
|
2766
|
+
).option("--json", "Emit JSON output. Also automatic when stdout is piped").action(async (options) => {
|
|
2644
2767
|
process.exitCode = await handleStatus([
|
|
2645
2768
|
...options.reveal ? ["--reveal"] : [],
|
|
2646
2769
|
...options.json ? ["--json"] : []
|
|
@@ -2651,7 +2774,7 @@ Examples:
|
|
|
2651
2774
|
// src/cli/commands/billing.ts
|
|
2652
2775
|
var import_commander = require("commander");
|
|
2653
2776
|
var import_promises2 = require("fs/promises");
|
|
2654
|
-
var
|
|
2777
|
+
var import_node_path5 = require("path");
|
|
2655
2778
|
var import_sync3 = require("csv-stringify/sync");
|
|
2656
2779
|
function humanize(value) {
|
|
2657
2780
|
return String(value || "").split("_").filter(Boolean).map((token) => token[0]?.toUpperCase() + token.slice(1)).join(" ") || "Unknown";
|
|
@@ -2665,7 +2788,9 @@ function recentUsageLines(entries) {
|
|
|
2665
2788
|
const op = `${humanize(entry.provider)} ${humanize(entry.operation)}`.trim();
|
|
2666
2789
|
const charge = entry.billing_mode === "no_bill" ? "free" : `${entry.credits ?? 0} cr`;
|
|
2667
2790
|
const status = entry.status || "completed";
|
|
2668
|
-
lines.push(
|
|
2791
|
+
lines.push(
|
|
2792
|
+
`${op} | ${charge} | ${status} | ${entry.created_at || "unknown"}`
|
|
2793
|
+
);
|
|
2669
2794
|
}
|
|
2670
2795
|
return lines;
|
|
2671
2796
|
}
|
|
@@ -2710,7 +2835,7 @@ function ledgerRowsToCsv(rows, header) {
|
|
|
2710
2835
|
});
|
|
2711
2836
|
}
|
|
2712
2837
|
function defaultLedgerExportPath() {
|
|
2713
|
-
return (0,
|
|
2838
|
+
return (0, import_node_path5.resolve)(
|
|
2714
2839
|
process.cwd(),
|
|
2715
2840
|
"deepline",
|
|
2716
2841
|
"data",
|
|
@@ -2719,16 +2844,21 @@ function defaultLedgerExportPath() {
|
|
|
2719
2844
|
}
|
|
2720
2845
|
async function handleBalance(options) {
|
|
2721
2846
|
const { http } = getAuthedHttpClient();
|
|
2722
|
-
const payload = await http.get(
|
|
2847
|
+
const payload = await http.get(
|
|
2848
|
+
"/api/v2/billing/balance"
|
|
2849
|
+
);
|
|
2723
2850
|
const status = String(payload.balance_status || "");
|
|
2724
2851
|
const lines = status === "no_billing" ? [
|
|
2725
2852
|
"Balance: 0 credits",
|
|
2726
2853
|
"Billing: No billing account or payment method set up for this workspace."
|
|
2727
2854
|
] : [`Balance: ${payload.balance ?? "(unknown)"} credits`];
|
|
2728
|
-
printCommandEnvelope(
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2855
|
+
printCommandEnvelope(
|
|
2856
|
+
{
|
|
2857
|
+
...payload,
|
|
2858
|
+
render: { sections: [{ title: "billing balance", lines }] }
|
|
2859
|
+
},
|
|
2860
|
+
{ json: options.json }
|
|
2861
|
+
);
|
|
2732
2862
|
return;
|
|
2733
2863
|
}
|
|
2734
2864
|
async function handleUsage(options) {
|
|
@@ -2737,7 +2867,9 @@ async function handleUsage(options) {
|
|
|
2737
2867
|
if (options.limit) params.set("recent_limit", options.limit);
|
|
2738
2868
|
if (options.offset) params.set("recent_offset", options.offset);
|
|
2739
2869
|
const suffix = Array.from(params).length > 0 ? `?${params.toString()}` : "";
|
|
2740
|
-
const payload = await http.get(
|
|
2870
|
+
const payload = await http.get(
|
|
2871
|
+
`/api/v2/billing/usage${suffix}`
|
|
2872
|
+
);
|
|
2741
2873
|
const usage = payload.usage ?? {};
|
|
2742
2874
|
const quota = payload.quota ?? {};
|
|
2743
2875
|
const recent = payload.recent ?? {};
|
|
@@ -2745,24 +2877,34 @@ async function handleUsage(options) {
|
|
|
2745
2877
|
`Balance: ${payload.balance ?? "(unknown)"}`,
|
|
2746
2878
|
`Last 30 days spent: ${usage.month_spent_credits ?? "(unknown)"}`,
|
|
2747
2879
|
`Monthly limit: ${quota.enabled ? quota.monthly_credits_limit ?? "(unknown)" : "off"}`,
|
|
2748
|
-
...recentUsageLines(
|
|
2880
|
+
...recentUsageLines(
|
|
2881
|
+
Array.isArray(recent.entries) ? recent.entries : []
|
|
2882
|
+
)
|
|
2749
2883
|
];
|
|
2750
|
-
printCommandEnvelope(
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2884
|
+
printCommandEnvelope(
|
|
2885
|
+
{
|
|
2886
|
+
...payload,
|
|
2887
|
+
render: { sections: [{ title: "billing usage", lines }] }
|
|
2888
|
+
},
|
|
2889
|
+
{ json: options.json }
|
|
2890
|
+
);
|
|
2754
2891
|
}
|
|
2755
2892
|
async function handleLimit(options) {
|
|
2756
2893
|
const { http } = getAuthedHttpClient();
|
|
2757
|
-
const payload = await http.get(
|
|
2894
|
+
const payload = await http.get(
|
|
2895
|
+
"/api/v2/billing/limit"
|
|
2896
|
+
);
|
|
2758
2897
|
const lines = payload.enabled ? [
|
|
2759
2898
|
`Monthly limit: ${payload.monthly_credits_limit ?? "(unknown)"}`,
|
|
2760
2899
|
`Remaining before cap: ${payload.remaining_credits ?? "(unknown)"}`
|
|
2761
2900
|
] : ["Monthly limit: off"];
|
|
2762
|
-
printCommandEnvelope(
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2901
|
+
printCommandEnvelope(
|
|
2902
|
+
{
|
|
2903
|
+
...payload,
|
|
2904
|
+
render: { sections: [{ title: "billing limit", lines }] }
|
|
2905
|
+
},
|
|
2906
|
+
{ json: options.json }
|
|
2907
|
+
);
|
|
2766
2908
|
}
|
|
2767
2909
|
async function handleSetLimit(credits, options) {
|
|
2768
2910
|
const { http } = getAuthedHttpClient();
|
|
@@ -2770,26 +2912,53 @@ async function handleSetLimit(credits, options) {
|
|
|
2770
2912
|
method: "PUT",
|
|
2771
2913
|
body: { monthly_credits_limit: Number.parseInt(credits, 10) }
|
|
2772
2914
|
});
|
|
2773
|
-
printCommandEnvelope(
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2915
|
+
printCommandEnvelope(
|
|
2916
|
+
{
|
|
2917
|
+
...payload,
|
|
2918
|
+
render: {
|
|
2919
|
+
sections: [
|
|
2920
|
+
{
|
|
2921
|
+
title: "billing limit",
|
|
2922
|
+
lines: [`Monthly billing limit set to ${credits} credits.`]
|
|
2923
|
+
}
|
|
2924
|
+
]
|
|
2925
|
+
}
|
|
2926
|
+
},
|
|
2927
|
+
{ json: options.json }
|
|
2928
|
+
);
|
|
2779
2929
|
}
|
|
2780
2930
|
async function handleLimitOff(options) {
|
|
2781
2931
|
const { http } = getAuthedHttpClient();
|
|
2782
|
-
const payload = await http.request("/api/v2/billing/limit", {
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2932
|
+
const payload = await http.request("/api/v2/billing/limit", {
|
|
2933
|
+
method: "DELETE"
|
|
2934
|
+
});
|
|
2935
|
+
printCommandEnvelope(
|
|
2936
|
+
{
|
|
2937
|
+
...payload,
|
|
2938
|
+
render: {
|
|
2939
|
+
sections: [
|
|
2940
|
+
{
|
|
2941
|
+
title: "billing limit",
|
|
2942
|
+
lines: ["Monthly billing limit is now off."]
|
|
2943
|
+
}
|
|
2944
|
+
]
|
|
2945
|
+
}
|
|
2946
|
+
},
|
|
2947
|
+
{ json: options.json }
|
|
2948
|
+
);
|
|
2787
2949
|
}
|
|
2788
2950
|
async function handleHistory(options) {
|
|
2789
2951
|
const { http } = getAuthedHttpClient();
|
|
2790
|
-
const windows = {
|
|
2952
|
+
const windows = {
|
|
2953
|
+
"1d": 86400,
|
|
2954
|
+
"1w": 604800,
|
|
2955
|
+
"1m": 2592e3,
|
|
2956
|
+
"1y": 31536e3
|
|
2957
|
+
};
|
|
2791
2958
|
const sinceAt = Math.max(0, Math.floor(Date.now() / 1e3) - windows[options.time]) * 1e3;
|
|
2792
|
-
const payload = await http.get(
|
|
2959
|
+
const payload = await http.get(
|
|
2960
|
+
`/api/v2/billing/ledger?since_at=${sinceAt}&limit=5000`
|
|
2961
|
+
);
|
|
2793
2962
|
const entries = Array.isArray(payload.entries) ? payload.entries : [];
|
|
2794
2963
|
const rows = entries.map((entry) => {
|
|
2795
2964
|
const metadata = entry.metadata ?? {};
|
|
@@ -2801,25 +2970,34 @@ async function handleHistory(options) {
|
|
|
2801
2970
|
operation: metadata.operation ?? ""
|
|
2802
2971
|
};
|
|
2803
2972
|
});
|
|
2804
|
-
const outputPath = await writeCsvRowsFile(
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2973
|
+
const outputPath = await writeCsvRowsFile(
|
|
2974
|
+
`billing-history-${options.time}`,
|
|
2975
|
+
rows
|
|
2976
|
+
);
|
|
2977
|
+
printCommandEnvelope(
|
|
2978
|
+
{
|
|
2979
|
+
output_path: outputPath,
|
|
2980
|
+
row_count: rows.length,
|
|
2981
|
+
time_window: options.time,
|
|
2982
|
+
render: {
|
|
2983
|
+
sections: [
|
|
2984
|
+
{
|
|
2985
|
+
title: "billing history",
|
|
2986
|
+
lines: [
|
|
2987
|
+
`Billing history written to ${outputPath}`,
|
|
2988
|
+
`${rows.length} row(s) exported.`
|
|
2989
|
+
]
|
|
2990
|
+
}
|
|
2991
|
+
]
|
|
2992
|
+
},
|
|
2993
|
+
local: { output_path: outputPath }
|
|
2816
2994
|
},
|
|
2817
|
-
|
|
2818
|
-
|
|
2995
|
+
{ json: options.json }
|
|
2996
|
+
);
|
|
2819
2997
|
}
|
|
2820
2998
|
async function handleLedgerExportAll(options) {
|
|
2821
2999
|
const { http } = getAuthedHttpClient();
|
|
2822
|
-
const outputPath = options.output ? (0,
|
|
3000
|
+
const outputPath = options.output ? (0, import_node_path5.resolve)(String(options.output)) : defaultLedgerExportPath();
|
|
2823
3001
|
let summary = { row_count: 0, net_delta_credits: 0 };
|
|
2824
3002
|
let cursor = null;
|
|
2825
3003
|
let initializedOutput = false;
|
|
@@ -2832,7 +3010,7 @@ async function handleLedgerExportAll(options) {
|
|
|
2832
3010
|
const entries = Array.isArray(payload.entries) ? payload.entries : [];
|
|
2833
3011
|
const rows = entries.map(ledgerApiEntryToRow);
|
|
2834
3012
|
if (!initializedOutput) {
|
|
2835
|
-
await (0, import_promises2.mkdir)((0,
|
|
3013
|
+
await (0, import_promises2.mkdir)((0, import_node_path5.dirname)(outputPath), { recursive: true });
|
|
2836
3014
|
await (0, import_promises2.writeFile)(outputPath, ledgerRowsToCsv([], true), "utf-8");
|
|
2837
3015
|
initializedOutput = true;
|
|
2838
3016
|
}
|
|
@@ -2847,51 +3025,75 @@ async function handleLedgerExportAll(options) {
|
|
|
2847
3025
|
if (nextCursor === cursor) break;
|
|
2848
3026
|
cursor = nextCursor;
|
|
2849
3027
|
}
|
|
2850
|
-
printCommandEnvelope(
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
3028
|
+
printCommandEnvelope(
|
|
3029
|
+
{
|
|
3030
|
+
output_path: outputPath,
|
|
3031
|
+
row_count: summary.row_count,
|
|
3032
|
+
net_delta_credits: summary.net_delta_credits,
|
|
3033
|
+
scope: "current_auth_context",
|
|
3034
|
+
render: {
|
|
3035
|
+
sections: [
|
|
3036
|
+
{
|
|
3037
|
+
title: "billing ledger",
|
|
3038
|
+
lines: [
|
|
3039
|
+
`Billing ledger written to ${outputPath}`,
|
|
3040
|
+
`${summary.row_count} row(s) exported for the current auth context.`,
|
|
3041
|
+
`Net ledger delta: ${summary.net_delta_credits} Deepline Credits`
|
|
3042
|
+
]
|
|
3043
|
+
}
|
|
3044
|
+
]
|
|
3045
|
+
},
|
|
3046
|
+
local: { output_path: outputPath }
|
|
2866
3047
|
},
|
|
2867
|
-
|
|
2868
|
-
|
|
3048
|
+
{ json: options.json }
|
|
3049
|
+
);
|
|
2869
3050
|
}
|
|
2870
3051
|
async function handleCheckout(options) {
|
|
2871
3052
|
const { http } = getAuthedHttpClient();
|
|
2872
|
-
const payload = await http.post(
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
3053
|
+
const payload = await http.post(
|
|
3054
|
+
"/api/v2/billing/checkout",
|
|
3055
|
+
{
|
|
3056
|
+
...options.tier ? { tierId: options.tier } : {},
|
|
3057
|
+
...options.credits ? { credits: Number.parseInt(options.credits, 10) } : {},
|
|
3058
|
+
...options.discountCode ? { discountCode: options.discountCode } : {}
|
|
3059
|
+
}
|
|
3060
|
+
);
|
|
2877
3061
|
const url = String(payload.url || payload.checkout_url || "");
|
|
2878
3062
|
if (!options.json && !options.noOpen && url) openInBrowser(url);
|
|
2879
|
-
printCommandEnvelope(
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
3063
|
+
printCommandEnvelope(
|
|
3064
|
+
{
|
|
3065
|
+
...payload,
|
|
3066
|
+
render: {
|
|
3067
|
+
sections: [
|
|
3068
|
+
{
|
|
3069
|
+
title: "billing checkout",
|
|
3070
|
+
lines: [url || "Checkout session created."]
|
|
3071
|
+
}
|
|
3072
|
+
]
|
|
3073
|
+
}
|
|
3074
|
+
},
|
|
3075
|
+
{ json: options.json }
|
|
3076
|
+
);
|
|
2883
3077
|
}
|
|
2884
3078
|
async function handleRedeemCode(code, options) {
|
|
2885
3079
|
const { http } = getAuthedHttpClient();
|
|
2886
|
-
const payload = await http.post(
|
|
2887
|
-
|
|
2888
|
-
|
|
3080
|
+
const payload = await http.post(
|
|
3081
|
+
"/api/v2/billing/checkout",
|
|
3082
|
+
{
|
|
3083
|
+
discountCode: code
|
|
3084
|
+
}
|
|
3085
|
+
);
|
|
2889
3086
|
const url = String(payload.url || payload.checkout_url || "");
|
|
2890
3087
|
if (!options.json && !options.noOpen && url) openInBrowser(url);
|
|
2891
|
-
printCommandEnvelope(
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
3088
|
+
printCommandEnvelope(
|
|
3089
|
+
{
|
|
3090
|
+
...payload,
|
|
3091
|
+
render: {
|
|
3092
|
+
sections: [{ title: "billing code", lines: [url || "Code redeemed."] }]
|
|
3093
|
+
}
|
|
3094
|
+
},
|
|
3095
|
+
{ json: options.json }
|
|
3096
|
+
);
|
|
2895
3097
|
}
|
|
2896
3098
|
function registerBillingCommands(program) {
|
|
2897
3099
|
const billing = program.command("billing").description("Inspect balance, usage, limits, and checkout flows.").addHelpText(
|
|
@@ -2999,7 +3201,10 @@ Examples:
|
|
|
2999
3201
|
deepline billing ledger export all
|
|
3000
3202
|
deepline billing ledger export all --json
|
|
3001
3203
|
`
|
|
3002
|
-
).option("--output <path>", "Write CSV to an explicit path").option(
|
|
3204
|
+
).option("--output <path>", "Write CSV to an explicit path").option(
|
|
3205
|
+
"--json",
|
|
3206
|
+
"Emit JSON output. Also automatic when stdout is piped"
|
|
3207
|
+
).action(handleLedgerExportAll)
|
|
3003
3208
|
)
|
|
3004
3209
|
);
|
|
3005
3210
|
billing.command("history").description("Export billing ledger history to CSV.").addHelpText(
|
|
@@ -3014,7 +3219,9 @@ Examples:
|
|
|
3014
3219
|
deepline billing history --time 1y --json
|
|
3015
3220
|
`
|
|
3016
3221
|
).requiredOption("--time <window>", "Rolling time window: 1d, 1w, 1m, or 1y").option("--json", "Emit JSON output. Also automatic when stdout is piped").action(handleHistory);
|
|
3017
|
-
billing.command("checkout").description(
|
|
3222
|
+
billing.command("checkout").description(
|
|
3223
|
+
"Create a checkout session and optionally open it in your browser."
|
|
3224
|
+
).addHelpText(
|
|
3018
3225
|
"after",
|
|
3019
3226
|
`
|
|
3020
3227
|
Notes:
|
|
@@ -3042,8 +3249,8 @@ Examples:
|
|
|
3042
3249
|
}
|
|
3043
3250
|
|
|
3044
3251
|
// src/cli/dataset-stats.ts
|
|
3045
|
-
var
|
|
3046
|
-
var
|
|
3252
|
+
var import_node_fs5 = require("fs");
|
|
3253
|
+
var import_node_path6 = require("path");
|
|
3047
3254
|
|
|
3048
3255
|
// ../shared_libs/plays/dataset-summary.ts
|
|
3049
3256
|
function datasetSummaryPercentText(numerator, denominator) {
|
|
@@ -3060,12 +3267,18 @@ function formatDatasetExecutionStats(raw, denominator) {
|
|
|
3060
3267
|
readCount(raw.completed),
|
|
3061
3268
|
denominator
|
|
3062
3269
|
),
|
|
3063
|
-
"completed:reused": datasetSummaryPercentText(
|
|
3270
|
+
"completed:reused": datasetSummaryPercentText(
|
|
3271
|
+
readCount(raw.cached),
|
|
3272
|
+
denominator
|
|
3273
|
+
),
|
|
3064
3274
|
"skipped:condition": datasetSummaryPercentText(
|
|
3065
3275
|
readCount(raw.skipped),
|
|
3066
3276
|
denominator
|
|
3067
3277
|
),
|
|
3068
|
-
"skipped:missed": datasetSummaryPercentText(
|
|
3278
|
+
"skipped:missed": datasetSummaryPercentText(
|
|
3279
|
+
readCount(raw.missed),
|
|
3280
|
+
denominator
|
|
3281
|
+
),
|
|
3069
3282
|
failed: datasetSummaryPercentText(readCount(raw.failed), denominator)
|
|
3070
3283
|
};
|
|
3071
3284
|
}
|
|
@@ -3246,19 +3459,51 @@ function collectCanonicalRowsInfos(statusOrResult) {
|
|
|
3246
3459
|
const metadata = isRecord2(result._metadata) ? result._metadata : null;
|
|
3247
3460
|
const totalFromMetadata = metadata?.totalRows ?? metadata?.rowCount ?? metadata?.count;
|
|
3248
3461
|
const candidates = [
|
|
3249
|
-
{
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3462
|
+
{
|
|
3463
|
+
source: "result.contacts",
|
|
3464
|
+
value: result.contacts,
|
|
3465
|
+
total: totalFromMetadata ?? result.totalRows ?? result.rowCount ?? result.count
|
|
3466
|
+
},
|
|
3467
|
+
{
|
|
3468
|
+
source: "result.previewRows",
|
|
3469
|
+
value: result.previewRows,
|
|
3470
|
+
total: totalFromMetadata ?? result.totalRows ?? result.rowCount ?? result.count
|
|
3471
|
+
},
|
|
3472
|
+
{
|
|
3473
|
+
source: "result.rows",
|
|
3474
|
+
value: result.rows,
|
|
3475
|
+
total: totalFromMetadata ?? result.totalRows ?? result.rowCount ?? result.count
|
|
3476
|
+
},
|
|
3477
|
+
{
|
|
3478
|
+
source: "result.results",
|
|
3479
|
+
value: result.results,
|
|
3480
|
+
total: totalFromMetadata ?? result.totalRows ?? result.rowCount ?? result.count
|
|
3481
|
+
}
|
|
3253
3482
|
];
|
|
3254
3483
|
if (isRecord2(result.output)) {
|
|
3255
3484
|
const outputMetadata = isRecord2(result.output._metadata) ? result.output._metadata : null;
|
|
3256
3485
|
const outputTotalFromMetadata = outputMetadata?.totalRows ?? outputMetadata?.rowCount ?? outputMetadata?.count;
|
|
3257
3486
|
candidates.push(
|
|
3258
|
-
{
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3487
|
+
{
|
|
3488
|
+
source: "result.output.contacts",
|
|
3489
|
+
value: result.output.contacts,
|
|
3490
|
+
total: outputTotalFromMetadata ?? result.output.totalRows ?? result.output.rowCount ?? result.output.count
|
|
3491
|
+
},
|
|
3492
|
+
{
|
|
3493
|
+
source: "result.output.previewRows",
|
|
3494
|
+
value: result.output.previewRows,
|
|
3495
|
+
total: outputTotalFromMetadata ?? result.output.totalRows ?? result.output.rowCount ?? result.output.count
|
|
3496
|
+
},
|
|
3497
|
+
{
|
|
3498
|
+
source: "result.output.rows",
|
|
3499
|
+
value: result.output.rows,
|
|
3500
|
+
total: outputTotalFromMetadata ?? result.output.totalRows ?? result.output.rowCount ?? result.output.count
|
|
3501
|
+
},
|
|
3502
|
+
{
|
|
3503
|
+
source: "result.output.results",
|
|
3504
|
+
value: result.output.results,
|
|
3505
|
+
total: outputTotalFromMetadata ?? result.output.totalRows ?? result.output.rowCount ?? result.output.count
|
|
3506
|
+
}
|
|
3262
3507
|
);
|
|
3263
3508
|
}
|
|
3264
3509
|
collectDatasetCandidates({
|
|
@@ -3396,7 +3641,8 @@ function compactCell(value) {
|
|
|
3396
3641
|
const parsed = parseJsonLike(value);
|
|
3397
3642
|
if (parsed === null || parsed === void 0) return "";
|
|
3398
3643
|
if (typeof parsed === "string") return compactScalar(parsed, 120);
|
|
3399
|
-
if (typeof parsed === "number" || typeof parsed === "boolean")
|
|
3644
|
+
if (typeof parsed === "number" || typeof parsed === "boolean")
|
|
3645
|
+
return String(parsed);
|
|
3400
3646
|
if (Array.isArray(parsed)) {
|
|
3401
3647
|
if (parsed.length === 0) return "";
|
|
3402
3648
|
if (parsed.slice(0, 3).every((item) => ["string", "number", "boolean"].includes(typeof item))) {
|
|
@@ -3410,7 +3656,15 @@ function compactCell(value) {
|
|
|
3410
3656
|
return compactCell(parsed[key]);
|
|
3411
3657
|
}
|
|
3412
3658
|
}
|
|
3413
|
-
const preferred = [
|
|
3659
|
+
const preferred = [
|
|
3660
|
+
"email",
|
|
3661
|
+
"status",
|
|
3662
|
+
"name",
|
|
3663
|
+
"full_name",
|
|
3664
|
+
"title",
|
|
3665
|
+
"domain",
|
|
3666
|
+
"linkedin_url"
|
|
3667
|
+
];
|
|
3414
3668
|
const parts = [];
|
|
3415
3669
|
for (const key of preferred) {
|
|
3416
3670
|
if (parsed[key] !== null && parsed[key] !== void 0 && parsed[key] !== "") {
|
|
@@ -3452,7 +3706,10 @@ function buildDatasetStats(rows, totalRows = rows.length, columns = inferColumns
|
|
|
3452
3706
|
};
|
|
3453
3707
|
const rawExecutionStats = executionStats?.columnStats[column];
|
|
3454
3708
|
if (rawExecutionStats) {
|
|
3455
|
-
stat3.execution = formatDatasetExecutionStats(
|
|
3709
|
+
stat3.execution = formatDatasetExecutionStats(
|
|
3710
|
+
rawExecutionStats,
|
|
3711
|
+
totalRows
|
|
3712
|
+
);
|
|
3456
3713
|
}
|
|
3457
3714
|
if (sampleValue !== void 0 && sampleValueType) {
|
|
3458
3715
|
stat3.sample_value = sampleValue;
|
|
@@ -3493,12 +3750,8 @@ function writeCanonicalRowsCsv(rowsInfo, outPath) {
|
|
|
3493
3750
|
});
|
|
3494
3751
|
const rows = dataExportRows(sanitized.rows);
|
|
3495
3752
|
const columns = dataExportColumns(rows, sanitized.columns);
|
|
3496
|
-
const resolved = (0,
|
|
3497
|
-
(0,
|
|
3498
|
-
resolved,
|
|
3499
|
-
csvStringFromRows(rows, columns),
|
|
3500
|
-
"utf-8"
|
|
3501
|
-
);
|
|
3753
|
+
const resolved = (0, import_node_path6.resolve)(outPath);
|
|
3754
|
+
(0, import_node_fs5.writeFileSync)(resolved, csvStringFromRows(rows, columns), "utf-8");
|
|
3502
3755
|
return resolved;
|
|
3503
3756
|
}
|
|
3504
3757
|
|
|
@@ -3509,7 +3762,9 @@ function parseRowRange(raw) {
|
|
|
3509
3762
|
const start = Number.parseInt(startRaw ?? "", 10);
|
|
3510
3763
|
const end = Number.parseInt(endRaw ?? "", 10);
|
|
3511
3764
|
if (!Number.isFinite(start) || !Number.isFinite(end) || start < 0 || end < start) {
|
|
3512
|
-
throw new Error(
|
|
3765
|
+
throw new Error(
|
|
3766
|
+
`Invalid --rows value: ${source} (expected start:end, e.g. 0:19).`
|
|
3767
|
+
);
|
|
3513
3768
|
}
|
|
3514
3769
|
return [start, end];
|
|
3515
3770
|
}
|
|
@@ -3520,7 +3775,9 @@ function selectColumns(rows, rawColumns) {
|
|
|
3520
3775
|
if (!rawColumns?.trim()) return rows;
|
|
3521
3776
|
const requested = rawColumns.split(",").map((part) => part.trim()).filter(Boolean);
|
|
3522
3777
|
if (requested.length === 0) {
|
|
3523
|
-
throw new Error(
|
|
3778
|
+
throw new Error(
|
|
3779
|
+
"Invalid --columns value: provide at least one column name."
|
|
3780
|
+
);
|
|
3524
3781
|
}
|
|
3525
3782
|
const available = new Set(Object.keys(rows[0] ?? {}));
|
|
3526
3783
|
const missing = requested.filter((column) => !available.has(column));
|
|
@@ -3557,13 +3814,22 @@ function renderTable(rows, totalRows, verbose) {
|
|
|
3557
3814
|
return display.padEnd(widths[column]);
|
|
3558
3815
|
}).join(" | ")
|
|
3559
3816
|
);
|
|
3560
|
-
return [
|
|
3817
|
+
return [
|
|
3818
|
+
header,
|
|
3819
|
+
divider,
|
|
3820
|
+
...body,
|
|
3821
|
+
"",
|
|
3822
|
+
`showing ${rows.length} row(s) of ${totalRows}`
|
|
3823
|
+
].join("\n");
|
|
3561
3824
|
}
|
|
3562
3825
|
async function handleCsvShow(options) {
|
|
3563
3826
|
const csvPath = options.csv;
|
|
3564
3827
|
const [rowStart, rowEnd] = parseRowRange(options.rows);
|
|
3565
3828
|
const allRows = readCsvRows(csvPath);
|
|
3566
|
-
const selected = selectColumns(
|
|
3829
|
+
const selected = selectColumns(
|
|
3830
|
+
selectRows(allRows, rowStart, rowEnd),
|
|
3831
|
+
options.columns
|
|
3832
|
+
);
|
|
3567
3833
|
const format = options.format ?? "json";
|
|
3568
3834
|
if (options.summary) {
|
|
3569
3835
|
printJson(buildDatasetStats(selected, allRows.length));
|
|
@@ -3580,13 +3846,17 @@ async function handleCsvShow(options) {
|
|
|
3580
3846
|
process.stdout.write(`${columns.join(",")}
|
|
3581
3847
|
`);
|
|
3582
3848
|
for (const row of selected) {
|
|
3583
|
-
process.stdout.write(
|
|
3584
|
-
|
|
3849
|
+
process.stdout.write(
|
|
3850
|
+
`${columns.map((column) => JSON.stringify(row[column] ?? "")).join(",")}
|
|
3851
|
+
`
|
|
3852
|
+
);
|
|
3585
3853
|
}
|
|
3586
3854
|
return;
|
|
3587
3855
|
}
|
|
3588
|
-
process.stdout.write(
|
|
3589
|
-
|
|
3856
|
+
process.stdout.write(
|
|
3857
|
+
`${renderTable(selected, allRows.length, Boolean(options.verbose))}
|
|
3858
|
+
`
|
|
3859
|
+
);
|
|
3590
3860
|
}
|
|
3591
3861
|
function registerCsvCommands(program) {
|
|
3592
3862
|
const csv = program.command("csv").description("Inspect local CSV files.").addHelpText(
|
|
@@ -3617,14 +3887,9 @@ Examples:
|
|
|
3617
3887
|
}
|
|
3618
3888
|
|
|
3619
3889
|
// src/cli/commands/db.ts
|
|
3620
|
-
var
|
|
3621
|
-
var
|
|
3622
|
-
var CUSTOMER_DB_QUERY_FORMATS = /* @__PURE__ */ new Set([
|
|
3623
|
-
"table",
|
|
3624
|
-
"json",
|
|
3625
|
-
"csv",
|
|
3626
|
-
"markdown"
|
|
3627
|
-
]);
|
|
3890
|
+
var import_node_fs6 = require("fs");
|
|
3891
|
+
var import_node_path7 = require("path");
|
|
3892
|
+
var CUSTOMER_DB_QUERY_FORMATS = /* @__PURE__ */ new Set(["table", "json", "csv", "markdown"]);
|
|
3628
3893
|
function parsePositiveInteger(value, flagName) {
|
|
3629
3894
|
const parsed = Number.parseInt(value, 10);
|
|
3630
3895
|
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
@@ -3639,10 +3904,17 @@ function formatCell(value) {
|
|
|
3639
3904
|
}
|
|
3640
3905
|
function tableLines(result) {
|
|
3641
3906
|
const rows = dataExportRows(customerDbRows(result));
|
|
3642
|
-
const responseColumns = dataExportColumns(
|
|
3643
|
-
|
|
3907
|
+
const responseColumns = dataExportColumns(
|
|
3908
|
+
rows,
|
|
3909
|
+
customerDbColumnNames(result)
|
|
3910
|
+
);
|
|
3911
|
+
const businessColumns = responseColumns.filter(
|
|
3912
|
+
(column) => !column.startsWith("_")
|
|
3913
|
+
);
|
|
3644
3914
|
const columns = businessColumns.length > 0 ? businessColumns : responseColumns;
|
|
3645
|
-
const hiddenColumns = responseColumns.filter(
|
|
3915
|
+
const hiddenColumns = responseColumns.filter(
|
|
3916
|
+
(column) => !columns.includes(column)
|
|
3917
|
+
);
|
|
3646
3918
|
const lines = [
|
|
3647
3919
|
`${result.command} returned ${result.row_count_returned} row(s)` + (result.truncated ? " (truncated)" : "")
|
|
3648
3920
|
];
|
|
@@ -3650,7 +3922,9 @@ function tableLines(result) {
|
|
|
3650
3922
|
lines.push(
|
|
3651
3923
|
`Showing ${columns.length}/${responseColumns.length} columns; hidden metadata: ${hiddenColumns.join(", ")}`
|
|
3652
3924
|
);
|
|
3653
|
-
lines.push(
|
|
3925
|
+
lines.push(
|
|
3926
|
+
"Use --json or select metadata columns explicitly when you need run ids/errors/stages."
|
|
3927
|
+
);
|
|
3654
3928
|
}
|
|
3655
3929
|
if (rows.length === 0) {
|
|
3656
3930
|
return lines;
|
|
@@ -3664,7 +3938,9 @@ function tableLines(result) {
|
|
|
3664
3938
|
)
|
|
3665
3939
|
)
|
|
3666
3940
|
);
|
|
3667
|
-
lines.push(
|
|
3941
|
+
lines.push(
|
|
3942
|
+
columns.map((column, index) => column.padEnd(widths[index])).join(" ")
|
|
3943
|
+
);
|
|
3668
3944
|
lines.push(widths.map((width) => "-".repeat(width)).join(" "));
|
|
3669
3945
|
for (const row of rows) {
|
|
3670
3946
|
lines.push(
|
|
@@ -3680,8 +3956,8 @@ function customerDbColumnNames(result) {
|
|
|
3680
3956
|
return result.columns.map((column) => column.name).filter(Boolean);
|
|
3681
3957
|
}
|
|
3682
3958
|
function writeCustomerDbCsv(result, outPath) {
|
|
3683
|
-
const resolved = (0,
|
|
3684
|
-
(0,
|
|
3959
|
+
const resolved = (0, import_node_path7.resolve)(outPath);
|
|
3960
|
+
(0, import_node_fs6.writeFileSync)(
|
|
3685
3961
|
resolved,
|
|
3686
3962
|
dataExportCsvString(customerDbRows(result), customerDbColumnNames(result)),
|
|
3687
3963
|
"utf-8"
|
|
@@ -3740,10 +4016,12 @@ async function handleDbQuery(args) {
|
|
|
3740
4016
|
const explicitJsonOutput = args.includes("--json");
|
|
3741
4017
|
const client = new DeeplineClient();
|
|
3742
4018
|
const result = await client.queryCustomerDb({ sql, maxRows });
|
|
3743
|
-
const toolCommand = `deepline tools execute query_customer_db --payload ${JSON.stringify(
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
4019
|
+
const toolCommand = `deepline tools execute query_customer_db --payload ${JSON.stringify(
|
|
4020
|
+
{
|
|
4021
|
+
sql,
|
|
4022
|
+
...maxRows ? { max_rows: maxRows } : {}
|
|
4023
|
+
}
|
|
4024
|
+
)} --json`;
|
|
3747
4025
|
if (format === "csv") {
|
|
3748
4026
|
if (outPath) {
|
|
3749
4027
|
const exportedPath = writeCustomerDbCsv(result, outPath);
|
|
@@ -3771,7 +4049,10 @@ async function handleDbQuery(args) {
|
|
|
3771
4049
|
}),
|
|
3772
4050
|
{
|
|
3773
4051
|
json: explicitJsonOutput,
|
|
3774
|
-
text: dataExportCsvString(
|
|
4052
|
+
text: dataExportCsvString(
|
|
4053
|
+
customerDbRows(result),
|
|
4054
|
+
customerDbColumnNames(result)
|
|
4055
|
+
)
|
|
3775
4056
|
}
|
|
3776
4057
|
);
|
|
3777
4058
|
return 0;
|
|
@@ -3782,8 +4063,8 @@ async function handleDbQuery(args) {
|
|
|
3782
4063
|
customerDbColumnNames(result)
|
|
3783
4064
|
);
|
|
3784
4065
|
if (outPath) {
|
|
3785
|
-
const exportedPath = (0,
|
|
3786
|
-
(0,
|
|
4066
|
+
const exportedPath = (0, import_node_path7.resolve)(outPath);
|
|
4067
|
+
(0, import_node_fs6.writeFileSync)(exportedPath, content, "utf-8");
|
|
3787
4068
|
printCommandEnvelope(
|
|
3788
4069
|
dbQueryExportEnvelope({
|
|
3789
4070
|
result,
|
|
@@ -3813,14 +4094,17 @@ async function handleDbQuery(args) {
|
|
|
3813
4094
|
);
|
|
3814
4095
|
return 0;
|
|
3815
4096
|
}
|
|
3816
|
-
printCommandEnvelope(
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
4097
|
+
printCommandEnvelope(
|
|
4098
|
+
{
|
|
4099
|
+
...result,
|
|
4100
|
+
next: { toolEquivalent: toolCommand },
|
|
4101
|
+
render: {
|
|
4102
|
+
sections: [{ title: "customer db query", lines: tableLines(result) }],
|
|
4103
|
+
actions: [{ label: "Tool equivalent", command: toolCommand }]
|
|
4104
|
+
}
|
|
4105
|
+
},
|
|
4106
|
+
{ json: jsonOutput || format === "json" }
|
|
4107
|
+
);
|
|
3824
4108
|
return 0;
|
|
3825
4109
|
}
|
|
3826
4110
|
function registerDbCommands(program) {
|
|
@@ -3856,7 +4140,10 @@ Examples:
|
|
|
3856
4140
|
deepline db query --sql "select * from contacts limit 20" --format csv --out contacts.csv
|
|
3857
4141
|
deepline db query --sql "select domain, name from companies limit 20" --format markdown
|
|
3858
4142
|
`
|
|
3859
|
-
).requiredOption("--sql <sql>", "SQL statement").option("--max-rows <n>", "Maximum returned rows").option("--format <format>", "Output format: table, json, csv, or markdown").option("--out <path>", "Write csv or markdown output to a file").option(
|
|
4143
|
+
).requiredOption("--sql <sql>", "SQL statement").option("--max-rows <n>", "Maximum returned rows").option("--format <format>", "Output format: table, json, csv, or markdown").option("--out <path>", "Write csv or markdown output to a file").option(
|
|
4144
|
+
"--json",
|
|
4145
|
+
"Emit raw JSON response. Also automatic when stdout is piped"
|
|
4146
|
+
).action(async (options) => {
|
|
3860
4147
|
process.exitCode = await handleDbQuery([
|
|
3861
4148
|
"--sql",
|
|
3862
4149
|
options.sql,
|
|
@@ -3877,12 +4164,17 @@ async function handleFeedback(text, options) {
|
|
|
3877
4164
|
...options.command ? { command: options.command } : {},
|
|
3878
4165
|
...options.payload ? { payload: options.payload } : {}
|
|
3879
4166
|
});
|
|
3880
|
-
printCommandEnvelope(
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
4167
|
+
printCommandEnvelope(
|
|
4168
|
+
{
|
|
4169
|
+
...response,
|
|
4170
|
+
render: {
|
|
4171
|
+
sections: [
|
|
4172
|
+
{ title: "feedback", lines: ["Feedback submitted. Thank you."] }
|
|
4173
|
+
]
|
|
4174
|
+
}
|
|
4175
|
+
},
|
|
4176
|
+
{ json: options.json }
|
|
4177
|
+
);
|
|
3886
4178
|
}
|
|
3887
4179
|
function registerFeedbackCommands(program) {
|
|
3888
4180
|
const feedback = program.command("feedback").description("Submit CLI feedback to Deepline.").addHelpText(
|
|
@@ -3925,76 +4217,106 @@ async function handleOrgList(options) {
|
|
|
3925
4217
|
const config = resolveConfig();
|
|
3926
4218
|
const http = new HttpClient(config);
|
|
3927
4219
|
const payload = await fetchOrganizations(http, config.apiKey);
|
|
3928
|
-
printCommandEnvelope(
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
4220
|
+
printCommandEnvelope(
|
|
4221
|
+
{
|
|
4222
|
+
...payload,
|
|
4223
|
+
render: {
|
|
4224
|
+
sections: [
|
|
4225
|
+
{
|
|
4226
|
+
title: "Your organizations:",
|
|
4227
|
+
lines: orgListLines(payload.organizations)
|
|
4228
|
+
}
|
|
4229
|
+
]
|
|
4230
|
+
}
|
|
4231
|
+
},
|
|
4232
|
+
{ json: options.json }
|
|
4233
|
+
);
|
|
3934
4234
|
}
|
|
3935
4235
|
async function handleOrgSwitch(selection, options) {
|
|
3936
4236
|
const config = resolveConfig();
|
|
3937
4237
|
const http = new HttpClient(config);
|
|
3938
4238
|
const payload = await fetchOrganizations(http, config.apiKey);
|
|
3939
4239
|
if (!selection && !options.orgId) {
|
|
3940
|
-
printCommandEnvelope(
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
4240
|
+
printCommandEnvelope(
|
|
4241
|
+
{
|
|
4242
|
+
...payload,
|
|
4243
|
+
next: { switch: "deepline org switch <number>" },
|
|
4244
|
+
render: {
|
|
4245
|
+
sections: [
|
|
4246
|
+
{
|
|
4247
|
+
title: "Your organizations:",
|
|
4248
|
+
lines: orgListLines(payload.organizations)
|
|
4249
|
+
}
|
|
4250
|
+
],
|
|
4251
|
+
actions: [{ label: "Run", command: "deepline org switch <number>" }]
|
|
4252
|
+
}
|
|
4253
|
+
},
|
|
4254
|
+
{ json: options.json }
|
|
4255
|
+
);
|
|
3948
4256
|
return;
|
|
3949
4257
|
}
|
|
3950
|
-
let target = payload.organizations.find(
|
|
4258
|
+
let target = payload.organizations.find(
|
|
4259
|
+
(org) => org.org_id === options.orgId
|
|
4260
|
+
);
|
|
3951
4261
|
if (!target && selection) {
|
|
3952
4262
|
const index = Number.parseInt(selection, 10);
|
|
3953
4263
|
if (Number.isFinite(index) && index >= 1 && index <= payload.organizations.length) {
|
|
3954
4264
|
target = payload.organizations[index - 1];
|
|
3955
4265
|
} else {
|
|
3956
|
-
target = payload.organizations.find(
|
|
4266
|
+
target = payload.organizations.find(
|
|
4267
|
+
(org) => org.name === selection || org.org_id === selection
|
|
4268
|
+
);
|
|
3957
4269
|
}
|
|
3958
4270
|
}
|
|
3959
4271
|
if (!target) {
|
|
3960
4272
|
throw new Error("Could not resolve the selected organization.");
|
|
3961
4273
|
}
|
|
3962
4274
|
if (target.is_current) {
|
|
3963
|
-
printCommandEnvelope(
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
4275
|
+
printCommandEnvelope(
|
|
4276
|
+
{
|
|
4277
|
+
ok: true,
|
|
4278
|
+
unchanged: true,
|
|
4279
|
+
organization: target,
|
|
4280
|
+
render: {
|
|
4281
|
+
sections: [
|
|
4282
|
+
{ title: "org switch", lines: [`Already on ${target.name}.`] }
|
|
4283
|
+
]
|
|
4284
|
+
}
|
|
4285
|
+
},
|
|
4286
|
+
{ json: options.json }
|
|
4287
|
+
);
|
|
3969
4288
|
return;
|
|
3970
4289
|
}
|
|
3971
|
-
const switched = await http.post(
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
);
|
|
4290
|
+
const switched = await http.post("/api/v2/auth/cli/switch", {
|
|
4291
|
+
api_key: config.apiKey,
|
|
4292
|
+
org_id: target.org_id
|
|
4293
|
+
});
|
|
3975
4294
|
saveHostEnvValues(config.baseUrl, {
|
|
3976
4295
|
DEEPLINE_API_KEY: switched.api_key,
|
|
3977
4296
|
DEEPLINE_ACTIVE_ORG_ID: switched.org_id,
|
|
3978
4297
|
DEEPLINE_ACTIVE_ORG_NAME: switched.org_name
|
|
3979
4298
|
});
|
|
3980
4299
|
const { api_key: _apiKey, ...publicSwitched } = switched;
|
|
3981
|
-
printCommandEnvelope(
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
4300
|
+
printCommandEnvelope(
|
|
4301
|
+
{
|
|
4302
|
+
ok: true,
|
|
4303
|
+
host_env_path: hostEnvFilePath(config.baseUrl),
|
|
4304
|
+
...publicSwitched,
|
|
4305
|
+
api_key_saved: true,
|
|
4306
|
+
render: {
|
|
4307
|
+
sections: [
|
|
4308
|
+
{
|
|
4309
|
+
title: "org switch",
|
|
4310
|
+
lines: [
|
|
4311
|
+
`Switched to ${switched.org_name}.`,
|
|
4312
|
+
`Saved host auth in ${hostEnvFilePath(config.baseUrl)}`
|
|
4313
|
+
]
|
|
4314
|
+
}
|
|
4315
|
+
]
|
|
4316
|
+
}
|
|
4317
|
+
},
|
|
4318
|
+
{ json: options.json }
|
|
4319
|
+
);
|
|
3998
4320
|
}
|
|
3999
4321
|
function registerOrgCommands(program) {
|
|
4000
4322
|
const org = program.command("org").description("List and switch organizations.").addHelpText(
|
|
@@ -4021,7 +4343,9 @@ Examples:
|
|
|
4021
4343
|
deepline org list --json
|
|
4022
4344
|
`
|
|
4023
4345
|
).option("--json", "Emit JSON output. Also automatic when stdout is piped").action(handleOrgList);
|
|
4024
|
-
org.command("switch [selection]").description(
|
|
4346
|
+
org.command("switch [selection]").description(
|
|
4347
|
+
"Switch to another organization and save the new API key in the host auth file."
|
|
4348
|
+
).addHelpText(
|
|
4025
4349
|
"after",
|
|
4026
4350
|
`
|
|
4027
4351
|
Notes:
|
|
@@ -4038,21 +4362,21 @@ Examples:
|
|
|
4038
4362
|
|
|
4039
4363
|
// src/cli/commands/play.ts
|
|
4040
4364
|
var import_node_crypto3 = require("crypto");
|
|
4041
|
-
var
|
|
4042
|
-
var
|
|
4365
|
+
var import_node_fs10 = require("fs");
|
|
4366
|
+
var import_node_path12 = require("path");
|
|
4043
4367
|
|
|
4044
4368
|
// src/plays/bundle-play-file.ts
|
|
4045
|
-
var
|
|
4046
|
-
var
|
|
4369
|
+
var import_node_os6 = require("os");
|
|
4370
|
+
var import_node_path10 = require("path");
|
|
4047
4371
|
var import_node_url = require("url");
|
|
4048
|
-
var
|
|
4372
|
+
var import_node_fs8 = require("fs");
|
|
4049
4373
|
|
|
4050
4374
|
// ../shared_libs/plays/bundling/index.ts
|
|
4051
4375
|
var import_node_crypto = require("crypto");
|
|
4052
|
-
var
|
|
4376
|
+
var import_node_fs7 = require("fs");
|
|
4053
4377
|
var import_promises3 = require("fs/promises");
|
|
4054
|
-
var
|
|
4055
|
-
var
|
|
4378
|
+
var import_node_os5 = require("os");
|
|
4379
|
+
var import_node_path8 = require("path");
|
|
4056
4380
|
var import_node_module = require("module");
|
|
4057
4381
|
var import_esbuild = require("esbuild");
|
|
4058
4382
|
|
|
@@ -4111,8 +4435,8 @@ function buildPlayContractCompatibility(input) {
|
|
|
4111
4435
|
var PLAY_BUNDLE_CACHE_VERSION = 24;
|
|
4112
4436
|
var MAX_PLAY_BUNDLE_BYTES = 30 * 1024 * 1024;
|
|
4113
4437
|
var MAX_ESM_WORKERS_BUNDLE_BYTES = 115e4;
|
|
4114
|
-
var PLAY_ARTIFACT_CACHE_DIR = (0,
|
|
4115
|
-
(0,
|
|
4438
|
+
var PLAY_ARTIFACT_CACHE_DIR = (0, import_node_path8.join)(
|
|
4439
|
+
(0, import_node_os5.tmpdir)(),
|
|
4116
4440
|
`deepline-play-artifacts-v${PLAY_BUNDLE_CACHE_VERSION}`
|
|
4117
4441
|
);
|
|
4118
4442
|
var PLAY_PROXY_NAMESPACE = "deepline-play-runtime-ref";
|
|
@@ -4156,13 +4480,13 @@ async function normalizeLocalPath(filePath) {
|
|
|
4156
4480
|
try {
|
|
4157
4481
|
return await (0, import_promises3.realpath)(filePath);
|
|
4158
4482
|
} catch {
|
|
4159
|
-
return (0,
|
|
4483
|
+
return (0, import_node_path8.resolve)(filePath);
|
|
4160
4484
|
}
|
|
4161
4485
|
}
|
|
4162
4486
|
function createPlayWorkspace(entryFile) {
|
|
4163
4487
|
return {
|
|
4164
4488
|
entryFile,
|
|
4165
|
-
rootDir: (0,
|
|
4489
|
+
rootDir: (0, import_node_path8.dirname)(entryFile)
|
|
4166
4490
|
};
|
|
4167
4491
|
}
|
|
4168
4492
|
function isPathInsideDirectory(filePath, directory) {
|
|
@@ -4331,7 +4655,7 @@ function extractDefinedPlayName(sourceCode) {
|
|
|
4331
4655
|
}
|
|
4332
4656
|
function readPackageVersionFromPackageJson(packageJsonPath, packageName) {
|
|
4333
4657
|
try {
|
|
4334
|
-
const packageJson = JSON.parse((0,
|
|
4658
|
+
const packageJson = JSON.parse((0, import_node_fs7.readFileSync)(packageJsonPath, "utf-8"));
|
|
4335
4659
|
if (packageJson.name === packageName && typeof packageJson.version === "string") {
|
|
4336
4660
|
return packageJson.version;
|
|
4337
4661
|
}
|
|
@@ -4341,18 +4665,18 @@ function readPackageVersionFromPackageJson(packageJsonPath, packageName) {
|
|
|
4341
4665
|
return null;
|
|
4342
4666
|
}
|
|
4343
4667
|
function findPackageJsonPathFrom(startDir, packageName) {
|
|
4344
|
-
let current = (0,
|
|
4668
|
+
let current = (0, import_node_path8.resolve)(startDir);
|
|
4345
4669
|
while (true) {
|
|
4346
|
-
const packageJsonPath = (0,
|
|
4670
|
+
const packageJsonPath = (0, import_node_path8.join)(
|
|
4347
4671
|
current,
|
|
4348
4672
|
"node_modules",
|
|
4349
4673
|
packageName,
|
|
4350
4674
|
"package.json"
|
|
4351
4675
|
);
|
|
4352
|
-
if ((0,
|
|
4676
|
+
if ((0, import_node_fs7.existsSync)(packageJsonPath)) {
|
|
4353
4677
|
return packageJsonPath;
|
|
4354
4678
|
}
|
|
4355
|
-
const parent = (0,
|
|
4679
|
+
const parent = (0, import_node_path8.dirname)(current);
|
|
4356
4680
|
if (parent === current) {
|
|
4357
4681
|
return null;
|
|
4358
4682
|
}
|
|
@@ -4361,29 +4685,29 @@ function findPackageJsonPathFrom(startDir, packageName) {
|
|
|
4361
4685
|
}
|
|
4362
4686
|
function findPackageJsonPath(packageName, fromFile, adapter) {
|
|
4363
4687
|
const startDirs = [
|
|
4364
|
-
(0,
|
|
4688
|
+
(0, import_node_path8.dirname)(fromFile),
|
|
4365
4689
|
adapter.projectRoot,
|
|
4366
|
-
(0,
|
|
4690
|
+
(0, import_node_path8.dirname)(adapter.sdkPackageJson),
|
|
4367
4691
|
process.cwd()
|
|
4368
4692
|
];
|
|
4369
4693
|
const seen = /* @__PURE__ */ new Set();
|
|
4370
4694
|
for (const startDir of startDirs) {
|
|
4371
|
-
const normalized = (0,
|
|
4695
|
+
const normalized = (0, import_node_path8.resolve)(startDir);
|
|
4372
4696
|
if (seen.has(normalized)) continue;
|
|
4373
4697
|
seen.add(normalized);
|
|
4374
4698
|
const packageJsonPath = findPackageJsonPathFrom(normalized, packageName);
|
|
4375
4699
|
if (packageJsonPath) return packageJsonPath;
|
|
4376
4700
|
}
|
|
4377
|
-
const adapterNodeModulesPackageJson = (0,
|
|
4701
|
+
const adapterNodeModulesPackageJson = (0, import_node_path8.join)(
|
|
4378
4702
|
adapter.nodeModulesDir,
|
|
4379
4703
|
packageName,
|
|
4380
4704
|
"package.json"
|
|
4381
4705
|
);
|
|
4382
|
-
return (0,
|
|
4706
|
+
return (0, import_node_fs7.existsSync)(adapterNodeModulesPackageJson) ? adapterNodeModulesPackageJson : null;
|
|
4383
4707
|
}
|
|
4384
4708
|
function localSdkAliasPlugin(adapter, options) {
|
|
4385
4709
|
const entryFile = options?.workersRuntime ? adapter.sdkWorkersEntryFile : adapter.sdkEntryFile;
|
|
4386
|
-
if (!(0,
|
|
4710
|
+
if (!(0, import_node_fs7.existsSync)(entryFile)) {
|
|
4387
4711
|
return null;
|
|
4388
4712
|
}
|
|
4389
4713
|
return {
|
|
@@ -4393,7 +4717,7 @@ function localSdkAliasPlugin(adapter, options) {
|
|
|
4393
4717
|
path: entryFile
|
|
4394
4718
|
}));
|
|
4395
4719
|
buildContext.onResolve({ filter: /^deepline\/helpers$/ }, () => ({
|
|
4396
|
-
path: (0,
|
|
4720
|
+
path: (0, import_node_path8.join)(adapter.sdkSourceRoot, "helpers.ts")
|
|
4397
4721
|
}));
|
|
4398
4722
|
}
|
|
4399
4723
|
};
|
|
@@ -4426,7 +4750,7 @@ function workersNamedPlayEntryAliasPlugin(playFilePath, exportName) {
|
|
|
4426
4750
|
contents: `export { ${exportName} as default } from ${JSON.stringify(playFilePath)};
|
|
4427
4751
|
`,
|
|
4428
4752
|
loader: "ts",
|
|
4429
|
-
resolveDir: (0,
|
|
4753
|
+
resolveDir: (0, import_node_path8.dirname)(playFilePath)
|
|
4430
4754
|
})
|
|
4431
4755
|
);
|
|
4432
4756
|
}
|
|
@@ -4597,7 +4921,7 @@ function importedPlayProxyPlugin(importedPlayDependencies) {
|
|
|
4597
4921
|
return {
|
|
4598
4922
|
contents: buildImportedPlayProxyModule(dependency.playName),
|
|
4599
4923
|
loader: "ts",
|
|
4600
|
-
resolveDir: (0,
|
|
4924
|
+
resolveDir: (0, import_node_path8.dirname)(args.path)
|
|
4601
4925
|
};
|
|
4602
4926
|
}
|
|
4603
4927
|
);
|
|
@@ -4616,15 +4940,15 @@ async function resolveLocalImport(fromFile, specifier) {
|
|
|
4616
4940
|
if (specifier.startsWith("file:")) {
|
|
4617
4941
|
return normalizeLocalPath(new URL(specifier).pathname);
|
|
4618
4942
|
}
|
|
4619
|
-
const base = (0,
|
|
4943
|
+
const base = (0, import_node_path8.isAbsolute)(specifier) ? (0, import_node_path8.resolve)(specifier) : (0, import_node_path8.resolve)((0, import_node_path8.dirname)(fromFile), specifier);
|
|
4620
4944
|
const candidates = [base];
|
|
4621
|
-
const explicitExtension = (0,
|
|
4945
|
+
const explicitExtension = (0, import_node_path8.extname)(base).toLowerCase();
|
|
4622
4946
|
if (!explicitExtension) {
|
|
4623
4947
|
candidates.push(
|
|
4624
4948
|
...SOURCE_EXTENSIONS.map((extension) => `${base}${extension}`)
|
|
4625
4949
|
);
|
|
4626
4950
|
candidates.push(
|
|
4627
|
-
...SOURCE_EXTENSIONS.map((extension) => (0,
|
|
4951
|
+
...SOURCE_EXTENSIONS.map((extension) => (0, import_node_path8.join)(base, `index${extension}`))
|
|
4628
4952
|
);
|
|
4629
4953
|
} else if ([".js", ".jsx", ".mjs", ".cjs"].includes(explicitExtension)) {
|
|
4630
4954
|
const stem = base.slice(0, -explicitExtension.length);
|
|
@@ -4643,9 +4967,9 @@ async function resolveLocalImport(fromFile, specifier) {
|
|
|
4643
4967
|
}
|
|
4644
4968
|
function resolvePackageImport(specifier, fromFile, adapter) {
|
|
4645
4969
|
const packageName = getPackageName(specifier);
|
|
4646
|
-
if (packageName === "deepline" && (0,
|
|
4970
|
+
if (packageName === "deepline" && (0, import_node_fs7.existsSync)(adapter.sdkPackageJson)) {
|
|
4647
4971
|
const packageJson = JSON.parse(
|
|
4648
|
-
(0,
|
|
4972
|
+
(0, import_node_fs7.readFileSync)(adapter.sdkPackageJson, "utf-8")
|
|
4649
4973
|
);
|
|
4650
4974
|
return {
|
|
4651
4975
|
name: "deepline",
|
|
@@ -4677,7 +5001,7 @@ async function analyzeSourceGraph(entryFile, adapter) {
|
|
|
4677
5001
|
visited.add(absolutePath);
|
|
4678
5002
|
const sourceCode2 = await (0, import_promises3.readFile)(absolutePath, "utf-8");
|
|
4679
5003
|
localFiles.set(absolutePath, sourceCode2);
|
|
4680
|
-
if ((0,
|
|
5004
|
+
if ((0, import_node_path8.extname)(absolutePath).toLowerCase() === ".json") {
|
|
4681
5005
|
return;
|
|
4682
5006
|
}
|
|
4683
5007
|
const handleSpecifier = async (specifier, line, column, kind) => {
|
|
@@ -4792,7 +5116,7 @@ async function computeWorkersHarnessFingerprintWithAdapter(adapter) {
|
|
|
4792
5116
|
const parts = [];
|
|
4793
5117
|
for (const name of tsFiles) {
|
|
4794
5118
|
const contents = await (0, import_promises3.readFile)(
|
|
4795
|
-
(0,
|
|
5119
|
+
(0, import_node_path8.join)(adapter.workersHarnessFilesDir, name),
|
|
4796
5120
|
"utf-8"
|
|
4797
5121
|
);
|
|
4798
5122
|
parts.push({ name, hash: sha256(contents) });
|
|
@@ -4800,7 +5124,7 @@ async function computeWorkersHarnessFingerprintWithAdapter(adapter) {
|
|
|
4800
5124
|
return sha256(JSON.stringify(parts));
|
|
4801
5125
|
}
|
|
4802
5126
|
function artifactCachePath(graphHash, artifactKind, adapter) {
|
|
4803
|
-
return (0,
|
|
5127
|
+
return (0, import_node_path8.join)(
|
|
4804
5128
|
adapter.cacheDir ?? PLAY_ARTIFACT_CACHE_DIR,
|
|
4805
5129
|
`${graphHash}.${artifactKind}.json`
|
|
4806
5130
|
);
|
|
@@ -4835,7 +5159,7 @@ function normalizeSourceMapForRuntime(sourceMapText) {
|
|
|
4835
5159
|
if (sourcePath.startsWith("data:") || sourcePath.startsWith("node:") || sourcePath.startsWith("/") || /^[a-zA-Z]+:\/\//.test(sourcePath)) {
|
|
4836
5160
|
return sourcePath;
|
|
4837
5161
|
}
|
|
4838
|
-
return (0,
|
|
5162
|
+
return (0, import_node_path8.resolve)(process.cwd(), sourcePath);
|
|
4839
5163
|
});
|
|
4840
5164
|
parsed.sourceRoot = void 0;
|
|
4841
5165
|
return JSON.stringify(parsed);
|
|
@@ -4867,8 +5191,8 @@ async function runEsbuildForCjsNode(entryFile, importedPlayDependencies, adapter
|
|
|
4867
5191
|
...namedExportShim ? {
|
|
4868
5192
|
stdin: {
|
|
4869
5193
|
contents: namedExportShim,
|
|
4870
|
-
resolveDir: (0,
|
|
4871
|
-
sourcefile: `${(0,
|
|
5194
|
+
resolveDir: (0, import_node_path8.dirname)(entryFile),
|
|
5195
|
+
sourcefile: `${(0, import_node_path8.basename)(entryFile)}.${exportName}.entry.ts`,
|
|
4872
5196
|
loader: "ts"
|
|
4873
5197
|
}
|
|
4874
5198
|
} : { entryPoints: [entryFile] },
|
|
@@ -5093,10 +5417,10 @@ workers-harness:${harnessFingerprint}`
|
|
|
5093
5417
|
}
|
|
5094
5418
|
const { bundledCode, sourceMapText, outputExtension } = buildOutcome;
|
|
5095
5419
|
const normalizedSourceMap = normalizeSourceMapForRuntime(sourceMapText);
|
|
5096
|
-
const virtualBaseName = exportName === "default" ? (0,
|
|
5420
|
+
const virtualBaseName = exportName === "default" ? (0, import_node_path8.basename)(absolutePath).replace(/\.[^.]+$/, "") : `${(0, import_node_path8.basename)(absolutePath).replace(/\.[^.]+$/, "")}.${exportName}`;
|
|
5097
5421
|
const virtualFilename = `/virtual/deepline-plays/${analysis.graphHash}/${virtualBaseName}.${outputExtension}`;
|
|
5098
5422
|
const executableCode = `${bundledCode}
|
|
5099
|
-
//# sourceMappingURL=${(0,
|
|
5423
|
+
//# sourceMappingURL=${(0, import_node_path8.basename)(virtualFilename)}.map
|
|
5100
5424
|
`;
|
|
5101
5425
|
const bundleSizeError = getBundleSizeError(
|
|
5102
5426
|
absolutePath,
|
|
@@ -5233,13 +5557,23 @@ function resolveExecutionProfile(override) {
|
|
|
5233
5557
|
// src/plays/local-file-discovery.ts
|
|
5234
5558
|
var import_node_crypto2 = require("crypto");
|
|
5235
5559
|
var import_promises4 = require("fs/promises");
|
|
5236
|
-
var
|
|
5237
|
-
var SOURCE_EXTENSIONS2 = [
|
|
5560
|
+
var import_node_path9 = require("path");
|
|
5561
|
+
var SOURCE_EXTENSIONS2 = [
|
|
5562
|
+
".ts",
|
|
5563
|
+
".tsx",
|
|
5564
|
+
".mts",
|
|
5565
|
+
".cts",
|
|
5566
|
+
".js",
|
|
5567
|
+
".jsx",
|
|
5568
|
+
".mjs",
|
|
5569
|
+
".cjs",
|
|
5570
|
+
".json"
|
|
5571
|
+
];
|
|
5238
5572
|
function sha2562(buffer) {
|
|
5239
5573
|
return (0, import_node_crypto2.createHash)("sha256").update(buffer).digest("hex");
|
|
5240
5574
|
}
|
|
5241
5575
|
function contentTypeForFile(filePath) {
|
|
5242
|
-
const extension = (0,
|
|
5576
|
+
const extension = (0, import_node_path9.extname)(filePath).toLowerCase();
|
|
5243
5577
|
if (extension === ".csv") return "text/csv";
|
|
5244
5578
|
if (extension === ".json") return "application/json";
|
|
5245
5579
|
if (extension === ".txt") return "text/plain";
|
|
@@ -5258,7 +5592,9 @@ function unquoteStringLiteral2(literal) {
|
|
|
5258
5592
|
return null;
|
|
5259
5593
|
}
|
|
5260
5594
|
try {
|
|
5261
|
-
return JSON.parse(
|
|
5595
|
+
return JSON.parse(
|
|
5596
|
+
quote === '"' ? trimmed : `"${trimmed.slice(1, -1).replace(/"/g, '\\"')}"`
|
|
5597
|
+
);
|
|
5262
5598
|
} catch {
|
|
5263
5599
|
return trimmed.slice(1, -1);
|
|
5264
5600
|
}
|
|
@@ -5319,7 +5655,9 @@ function resolveStringExpression(expression, constants) {
|
|
|
5319
5655
|
}
|
|
5320
5656
|
const parts = splitTopLevelPlus(value);
|
|
5321
5657
|
if (parts) {
|
|
5322
|
-
const resolved = parts.map(
|
|
5658
|
+
const resolved = parts.map(
|
|
5659
|
+
(part) => resolveStringExpression(part, constants)
|
|
5660
|
+
);
|
|
5323
5661
|
return resolved.every((part) => part != null) ? resolved.join("") : null;
|
|
5324
5662
|
}
|
|
5325
5663
|
return null;
|
|
@@ -5327,7 +5665,9 @@ function resolveStringExpression(expression, constants) {
|
|
|
5327
5665
|
function collectTopLevelStringConstants(sourceCode) {
|
|
5328
5666
|
const constants = /* @__PURE__ */ new Map();
|
|
5329
5667
|
const source = stripCommentsToSpaces2(sourceCode);
|
|
5330
|
-
for (const match of source.matchAll(
|
|
5668
|
+
for (const match of source.matchAll(
|
|
5669
|
+
/(?:^|\n)\s*const\s+([A-Za-z_$][\w$]*)\s*=\s*([^;\n]+)/g
|
|
5670
|
+
)) {
|
|
5331
5671
|
const resolved = resolveStringExpression(match[2], constants);
|
|
5332
5672
|
if (resolved != null) {
|
|
5333
5673
|
constants.set(match[1], resolved);
|
|
@@ -5416,7 +5756,9 @@ function localImportSpecifiers(sourceCode) {
|
|
|
5416
5756
|
)) {
|
|
5417
5757
|
if (match[1]?.startsWith(".")) specifiers.push(match[1]);
|
|
5418
5758
|
}
|
|
5419
|
-
for (const match of source.matchAll(
|
|
5759
|
+
for (const match of source.matchAll(
|
|
5760
|
+
/\brequire\s*\(\s*(['"])(\.[^'"]*)\1\s*\)/g
|
|
5761
|
+
)) {
|
|
5420
5762
|
specifiers.push(match[2]);
|
|
5421
5763
|
}
|
|
5422
5764
|
return specifiers;
|
|
@@ -5430,35 +5772,43 @@ async function fileExists2(filePath) {
|
|
|
5430
5772
|
}
|
|
5431
5773
|
}
|
|
5432
5774
|
function isPathInsideDirectory2(filePath, directory) {
|
|
5433
|
-
const relativePath = (0,
|
|
5434
|
-
return relativePath === "" || !relativePath.startsWith("..") && !(0,
|
|
5775
|
+
const relativePath = (0, import_node_path9.relative)(directory, filePath);
|
|
5776
|
+
return relativePath === "" || !relativePath.startsWith("..") && !(0, import_node_path9.isAbsolute)(relativePath);
|
|
5435
5777
|
}
|
|
5436
5778
|
async function resolveLocalImport2(fromFile, specifier) {
|
|
5437
|
-
const base = (0,
|
|
5779
|
+
const base = (0, import_node_path9.isAbsolute)(specifier) ? (0, import_node_path9.resolve)(specifier) : (0, import_node_path9.resolve)((0, import_node_path9.dirname)(fromFile), specifier);
|
|
5438
5780
|
const candidates = [base];
|
|
5439
|
-
const explicitExtension = (0,
|
|
5781
|
+
const explicitExtension = (0, import_node_path9.extname)(base).toLowerCase();
|
|
5440
5782
|
if (!explicitExtension) {
|
|
5441
|
-
candidates.push(
|
|
5442
|
-
|
|
5783
|
+
candidates.push(
|
|
5784
|
+
...SOURCE_EXTENSIONS2.map((extension) => `${base}${extension}`)
|
|
5785
|
+
);
|
|
5786
|
+
candidates.push(
|
|
5787
|
+
...SOURCE_EXTENSIONS2.map((extension) => (0, import_node_path9.join)(base, `index${extension}`))
|
|
5788
|
+
);
|
|
5443
5789
|
} else if ([".js", ".jsx", ".mjs", ".cjs"].includes(explicitExtension)) {
|
|
5444
5790
|
const stem = base.slice(0, -explicitExtension.length);
|
|
5445
|
-
candidates.push(
|
|
5791
|
+
candidates.push(
|
|
5792
|
+
...SOURCE_EXTENSIONS2.map((extension) => `${stem}${extension}`)
|
|
5793
|
+
);
|
|
5446
5794
|
}
|
|
5447
5795
|
for (const candidate of candidates) {
|
|
5448
5796
|
if (await fileExists2(candidate)) {
|
|
5449
5797
|
return candidate;
|
|
5450
5798
|
}
|
|
5451
5799
|
}
|
|
5452
|
-
throw new Error(
|
|
5800
|
+
throw new Error(
|
|
5801
|
+
`Could not resolve local import "${specifier}" from ${fromFile}`
|
|
5802
|
+
);
|
|
5453
5803
|
}
|
|
5454
5804
|
async function discoverPackagedLocalFiles(entryFile) {
|
|
5455
|
-
const absoluteEntryFile = (0,
|
|
5456
|
-
const packagingRoot = (0,
|
|
5805
|
+
const absoluteEntryFile = (0, import_node_path9.resolve)(entryFile);
|
|
5806
|
+
const packagingRoot = (0, import_node_path9.dirname)(absoluteEntryFile);
|
|
5457
5807
|
const files = /* @__PURE__ */ new Map();
|
|
5458
5808
|
const unresolved = [];
|
|
5459
5809
|
const visitedFiles = /* @__PURE__ */ new Set();
|
|
5460
5810
|
const visitSourceFile = async (filePath) => {
|
|
5461
|
-
const absolutePath = (0,
|
|
5811
|
+
const absolutePath = (0, import_node_path9.resolve)(filePath);
|
|
5462
5812
|
if (visitedFiles.has(absolutePath)) {
|
|
5463
5813
|
return;
|
|
5464
5814
|
}
|
|
@@ -5467,12 +5817,17 @@ async function discoverPackagedLocalFiles(entryFile) {
|
|
|
5467
5817
|
const scanSource = stripCommentsToSpaces2(sourceCode);
|
|
5468
5818
|
const constants = collectTopLevelStringConstants(sourceCode);
|
|
5469
5819
|
const childVisits = [];
|
|
5470
|
-
for (const match of scanSource.matchAll(
|
|
5820
|
+
for (const match of scanSource.matchAll(
|
|
5821
|
+
/\b([A-Za-z_$][\w$]*)\s*\.\s*csv\b/g
|
|
5822
|
+
)) {
|
|
5471
5823
|
const target = match[1];
|
|
5472
5824
|
if (target !== "ctx" && !target.endsWith("Ctx")) {
|
|
5473
5825
|
continue;
|
|
5474
5826
|
}
|
|
5475
|
-
const openParen = findCallOpenParen(
|
|
5827
|
+
const openParen = findCallOpenParen(
|
|
5828
|
+
scanSource,
|
|
5829
|
+
match.index + match[0].length
|
|
5830
|
+
);
|
|
5476
5831
|
if (openParen < 0) {
|
|
5477
5832
|
continue;
|
|
5478
5833
|
}
|
|
@@ -5490,8 +5845,8 @@ async function discoverPackagedLocalFiles(entryFile) {
|
|
|
5490
5845
|
message: "Could not resolve this ctx.csv(...) path at submit time. Use a string literal, a top-level const string, or pass a runtime input like input.file."
|
|
5491
5846
|
});
|
|
5492
5847
|
} else {
|
|
5493
|
-
const absoluteCsvPath = (0,
|
|
5494
|
-
if ((0,
|
|
5848
|
+
const absoluteCsvPath = (0, import_node_path9.resolve)((0, import_node_path9.dirname)(absolutePath), resolvedPath);
|
|
5849
|
+
if ((0, import_node_path9.isAbsolute)(resolvedPath) || !isPathInsideDirectory2(absoluteCsvPath, packagingRoot)) {
|
|
5495
5850
|
unresolved.push({
|
|
5496
5851
|
sourceFragment: sourceCode.slice(argument.start, argument.end).trim(),
|
|
5497
5852
|
message: "ctx.csv(...) packaged file paths must be relative paths inside the play directory. Pass external files at runtime with input.file instead."
|
|
@@ -5530,30 +5885,30 @@ async function discoverPackagedLocalFiles(entryFile) {
|
|
|
5530
5885
|
// src/plays/bundle-play-file.ts
|
|
5531
5886
|
var import_meta = {};
|
|
5532
5887
|
var PLAY_BUNDLE_CACHE_VERSION2 = 30;
|
|
5533
|
-
var MODULE_DIR = (0,
|
|
5534
|
-
var SDK_PACKAGE_ROOT = (0,
|
|
5535
|
-
var SOURCE_REPO_ROOT = (0,
|
|
5536
|
-
var HAS_SOURCE_BUNDLING_SOURCES = (0,
|
|
5537
|
-
(0,
|
|
5888
|
+
var MODULE_DIR = (0, import_node_path10.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
5889
|
+
var SDK_PACKAGE_ROOT = (0, import_node_path10.resolve)(MODULE_DIR, "..", "..");
|
|
5890
|
+
var SOURCE_REPO_ROOT = (0, import_node_path10.resolve)(SDK_PACKAGE_ROOT, "..");
|
|
5891
|
+
var HAS_SOURCE_BUNDLING_SOURCES = (0, import_node_fs8.existsSync)(
|
|
5892
|
+
(0, import_node_path10.resolve)(SOURCE_REPO_ROOT, "apps", "play-runner-workers", "src", "entry.ts")
|
|
5538
5893
|
);
|
|
5539
|
-
var PACKAGED_REPO_ROOT = (0,
|
|
5540
|
-
var HAS_PACKAGED_BUNDLING_SOURCES = (0,
|
|
5541
|
-
(0,
|
|
5894
|
+
var PACKAGED_REPO_ROOT = (0, import_node_path10.resolve)(SDK_PACKAGE_ROOT, "dist", "repo");
|
|
5895
|
+
var HAS_PACKAGED_BUNDLING_SOURCES = (0, import_node_fs8.existsSync)(
|
|
5896
|
+
(0, import_node_path10.resolve)(PACKAGED_REPO_ROOT, "apps", "play-runner-workers", "src", "entry.ts")
|
|
5542
5897
|
);
|
|
5543
|
-
var PROJECT_ROOT = HAS_SOURCE_BUNDLING_SOURCES ? SOURCE_REPO_ROOT : HAS_PACKAGED_BUNDLING_SOURCES ? PACKAGED_REPO_ROOT : (0,
|
|
5544
|
-
var SDK_SOURCE_ROOT = HAS_SOURCE_BUNDLING_SOURCES ? (0,
|
|
5545
|
-
var SDK_PACKAGE_JSON = (0,
|
|
5546
|
-
var SDK_ENTRY_FILE = (0,
|
|
5547
|
-
var SDK_TYPES_ENTRY_FILE = HAS_SOURCE_BUNDLING_SOURCES ? SDK_ENTRY_FILE : (0,
|
|
5548
|
-
var SDK_WORKERS_ENTRY_FILE = (0,
|
|
5549
|
-
var WORKERS_HARNESS_ENTRY_FILE = (0,
|
|
5898
|
+
var PROJECT_ROOT = HAS_SOURCE_BUNDLING_SOURCES ? SOURCE_REPO_ROOT : HAS_PACKAGED_BUNDLING_SOURCES ? PACKAGED_REPO_ROOT : (0, import_node_path10.resolve)(SDK_PACKAGE_ROOT, "..");
|
|
5899
|
+
var SDK_SOURCE_ROOT = HAS_SOURCE_BUNDLING_SOURCES ? (0, import_node_path10.resolve)(SOURCE_REPO_ROOT, "sdk", "src") : HAS_PACKAGED_BUNDLING_SOURCES ? (0, import_node_path10.resolve)(PACKAGED_REPO_ROOT, "sdk", "src") : (0, import_node_path10.resolve)(SDK_PACKAGE_ROOT, "src");
|
|
5900
|
+
var SDK_PACKAGE_JSON = (0, import_node_path10.resolve)(SDK_PACKAGE_ROOT, "package.json");
|
|
5901
|
+
var SDK_ENTRY_FILE = (0, import_node_path10.resolve)(SDK_SOURCE_ROOT, "index.ts");
|
|
5902
|
+
var SDK_TYPES_ENTRY_FILE = HAS_SOURCE_BUNDLING_SOURCES ? SDK_ENTRY_FILE : (0, import_node_path10.resolve)(SDK_PACKAGE_ROOT, "dist", "index.d.ts");
|
|
5903
|
+
var SDK_WORKERS_ENTRY_FILE = (0, import_node_path10.resolve)(SDK_SOURCE_ROOT, "worker-play-entry.ts");
|
|
5904
|
+
var WORKERS_HARNESS_ENTRY_FILE = (0, import_node_path10.resolve)(
|
|
5550
5905
|
PROJECT_ROOT,
|
|
5551
5906
|
"apps",
|
|
5552
5907
|
"play-runner-workers",
|
|
5553
5908
|
"src",
|
|
5554
5909
|
"entry.ts"
|
|
5555
5910
|
);
|
|
5556
|
-
var WORKERS_HARNESS_FILES_DIR = (0,
|
|
5911
|
+
var WORKERS_HARNESS_FILES_DIR = (0, import_node_path10.resolve)(
|
|
5557
5912
|
PROJECT_ROOT,
|
|
5558
5913
|
"apps",
|
|
5559
5914
|
"play-runner-workers",
|
|
@@ -5582,15 +5937,15 @@ function defaultPlayBundleTarget() {
|
|
|
5582
5937
|
function createSdkPlayBundlingAdapter() {
|
|
5583
5938
|
return {
|
|
5584
5939
|
projectRoot: PROJECT_ROOT,
|
|
5585
|
-
nodeModulesDir: (0,
|
|
5586
|
-
cacheDir: (0,
|
|
5587
|
-
(0,
|
|
5940
|
+
nodeModulesDir: (0, import_node_path10.resolve)(PROJECT_ROOT, "node_modules"),
|
|
5941
|
+
cacheDir: (0, import_node_path10.join)(
|
|
5942
|
+
(0, import_node_os6.tmpdir)(),
|
|
5588
5943
|
`deepline-play-artifacts-v${PLAY_BUNDLE_CACHE_VERSION2}`
|
|
5589
5944
|
),
|
|
5590
5945
|
sdkSourceRoot: SDK_SOURCE_ROOT,
|
|
5591
5946
|
sdkPackageJson: SDK_PACKAGE_JSON,
|
|
5592
5947
|
sdkEntryFile: SDK_ENTRY_FILE,
|
|
5593
|
-
sdkTypesEntryFile: HAS_SOURCE_BUNDLING_SOURCES || !(0,
|
|
5948
|
+
sdkTypesEntryFile: HAS_SOURCE_BUNDLING_SOURCES || !(0, import_node_fs8.existsSync)(SDK_TYPES_ENTRY_FILE) ? SDK_ENTRY_FILE : SDK_TYPES_ENTRY_FILE,
|
|
5594
5949
|
sdkWorkersEntryFile: SDK_WORKERS_ENTRY_FILE,
|
|
5595
5950
|
workersHarnessEntryFile: WORKERS_HARNESS_ENTRY_FILE,
|
|
5596
5951
|
workersHarnessFilesDir: WORKERS_HARNESS_FILES_DIR,
|
|
@@ -5607,8 +5962,8 @@ async function bundlePlayFile2(filePath, options = {}) {
|
|
|
5607
5962
|
}
|
|
5608
5963
|
|
|
5609
5964
|
// src/cli/commands/plays/bootstrap.ts
|
|
5610
|
-
var
|
|
5611
|
-
var
|
|
5965
|
+
var import_node_fs9 = require("fs");
|
|
5966
|
+
var import_node_path11 = require("path");
|
|
5612
5967
|
var import_sync4 = require("csv-parse/sync");
|
|
5613
5968
|
|
|
5614
5969
|
// ../shared_libs/plays/bootstrap-routes.ts
|
|
@@ -6029,13 +6384,13 @@ function inferCsvColumnSpecs(headers, rows) {
|
|
|
6029
6384
|
}));
|
|
6030
6385
|
}
|
|
6031
6386
|
function readCsvSample(csvPath) {
|
|
6032
|
-
const resolvedPath = (0,
|
|
6033
|
-
const size = (0,
|
|
6034
|
-
const fd = (0,
|
|
6387
|
+
const resolvedPath = (0, import_node_path11.resolve)(csvPath);
|
|
6388
|
+
const size = (0, import_node_fs9.statSync)(resolvedPath).size;
|
|
6389
|
+
const fd = (0, import_node_fs9.openSync)(resolvedPath, "r");
|
|
6035
6390
|
const byteLength = Math.min(size, CSV_HEADER_SAMPLE_BYTES);
|
|
6036
6391
|
const buffer = Buffer.alloc(byteLength);
|
|
6037
|
-
const bytesRead = (0,
|
|
6038
|
-
(0,
|
|
6392
|
+
const bytesRead = (0, import_node_fs9.readSync)(fd, buffer, 0, byteLength, 0);
|
|
6393
|
+
(0, import_node_fs9.closeSync)(fd);
|
|
6039
6394
|
if (bytesRead === 0) {
|
|
6040
6395
|
throw new PlayBootstrapUsageError(`--from csv:${csvPath} is empty.`);
|
|
6041
6396
|
}
|
|
@@ -6104,9 +6459,9 @@ ${properties}
|
|
|
6104
6459
|
}
|
|
6105
6460
|
function packagedCsvPathForPlay(csvPath) {
|
|
6106
6461
|
const playDir = process.cwd();
|
|
6107
|
-
const absoluteCsvPath = (0,
|
|
6108
|
-
const relativePath = (0,
|
|
6109
|
-
if (relativePath === "" || relativePath.startsWith("..") || (0,
|
|
6462
|
+
const absoluteCsvPath = (0, import_node_path11.resolve)(csvPath);
|
|
6463
|
+
const relativePath = (0, import_node_path11.relative)(playDir, absoluteCsvPath);
|
|
6464
|
+
if (relativePath === "" || relativePath.startsWith("..") || (0, import_node_path11.isAbsolute)(relativePath)) {
|
|
6110
6465
|
throw new PlayBootstrapUsageError(
|
|
6111
6466
|
`--from csv:${csvPath} must point to a file inside the directory where you run plays bootstrap. Run bootstrap from the intended play directory, then redirect stdout to a .play.ts file there.`
|
|
6112
6467
|
);
|
|
@@ -7538,7 +7893,7 @@ function formatPlayListReference(play) {
|
|
|
7538
7893
|
return play.reference || play.name;
|
|
7539
7894
|
}
|
|
7540
7895
|
function defaultMaterializedPlayPath(reference) {
|
|
7541
|
-
return (0,
|
|
7896
|
+
return (0, import_node_path12.resolve)(defaultStarterPlayPath(reference));
|
|
7542
7897
|
}
|
|
7543
7898
|
function defaultStarterPlayPath(reference) {
|
|
7544
7899
|
const playName = parseReferencedPlayTarget2(reference).unqualifiedPlayName;
|
|
@@ -7564,15 +7919,15 @@ function materializeRemotePlaySource(input) {
|
|
|
7564
7919
|
return null;
|
|
7565
7920
|
}
|
|
7566
7921
|
const outputPath = input.outPath ?? defaultMaterializedPlayPath(input.playName);
|
|
7567
|
-
if ((0,
|
|
7568
|
-
const existingSource = (0,
|
|
7922
|
+
if ((0, import_node_fs10.existsSync)(outputPath)) {
|
|
7923
|
+
const existingSource = (0, import_node_fs10.readFileSync)(outputPath, "utf-8");
|
|
7569
7924
|
if (existingSource === input.sourceCode) {
|
|
7570
7925
|
return { path: outputPath, status: "unchanged", created: false };
|
|
7571
7926
|
}
|
|
7572
|
-
(0,
|
|
7927
|
+
(0, import_node_fs10.writeFileSync)(outputPath, input.sourceCode, "utf-8");
|
|
7573
7928
|
return { path: outputPath, status: "updated", created: false };
|
|
7574
7929
|
}
|
|
7575
|
-
(0,
|
|
7930
|
+
(0, import_node_fs10.writeFileSync)(outputPath, input.sourceCode, "utf-8");
|
|
7576
7931
|
return { path: outputPath, status: "created", created: true };
|
|
7577
7932
|
}
|
|
7578
7933
|
function formatLoadedPlayMessage(materializedFile) {
|
|
@@ -7617,7 +7972,7 @@ function extractPlayName(code, filePath) {
|
|
|
7617
7972
|
throw buildMissingDefinePlayError(filePath);
|
|
7618
7973
|
}
|
|
7619
7974
|
function isFileTarget(target) {
|
|
7620
|
-
return (0,
|
|
7975
|
+
return (0, import_node_fs10.existsSync)((0, import_node_path12.resolve)(target));
|
|
7621
7976
|
}
|
|
7622
7977
|
function looksLikeRunId(target) {
|
|
7623
7978
|
return /^play\/[^/]+\/run\/[^/]+/.test(target.trim());
|
|
@@ -7646,7 +8001,7 @@ function parsePositiveInteger3(value, flagName) {
|
|
|
7646
8001
|
return parsed;
|
|
7647
8002
|
}
|
|
7648
8003
|
function parseJsonInput(raw) {
|
|
7649
|
-
const source = raw.startsWith("@") ? (0,
|
|
8004
|
+
const source = raw.startsWith("@") ? (0, import_node_fs10.readFileSync)((0, import_node_path12.resolve)(raw.slice(1)), "utf-8") : raw;
|
|
7650
8005
|
const parsed = JSON.parse(source);
|
|
7651
8006
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
7652
8007
|
throw new Error("--input must be a JSON object.");
|
|
@@ -7748,7 +8103,7 @@ function fileInputBindingsFromStaticPipeline(staticPipeline) {
|
|
|
7748
8103
|
function isLocalFilePathValue(value) {
|
|
7749
8104
|
if (typeof value !== "string" || !value.trim()) return false;
|
|
7750
8105
|
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(value.trim())) return false;
|
|
7751
|
-
return (0,
|
|
8106
|
+
return (0, import_node_fs10.existsSync)((0, import_node_path12.resolve)(value));
|
|
7752
8107
|
}
|
|
7753
8108
|
function inputContainsLocalFilePath(value) {
|
|
7754
8109
|
if (isLocalFilePathValue(value)) {
|
|
@@ -7776,8 +8131,8 @@ async function stageFileInputArgs(input) {
|
|
|
7776
8131
|
const localFiles = uniqueBindings.flatMap((binding) => {
|
|
7777
8132
|
const value = getDottedInputValue(input.runtimeInput, binding.inputPath);
|
|
7778
8133
|
if (!isLocalFilePathValue(value)) return [];
|
|
7779
|
-
const absolutePath = (0,
|
|
7780
|
-
return [{ binding, absolutePath, logicalPath: (0,
|
|
8134
|
+
const absolutePath = (0, import_node_path12.resolve)(value);
|
|
8135
|
+
return [{ binding, absolutePath, logicalPath: (0, import_node_path12.basename)(absolutePath) }];
|
|
7781
8136
|
});
|
|
7782
8137
|
if (localFiles.length === 0) {
|
|
7783
8138
|
return { inputFile: null, packagedFiles: [] };
|
|
@@ -7809,7 +8164,7 @@ async function stageFileInputArgs(input) {
|
|
|
7809
8164
|
};
|
|
7810
8165
|
}
|
|
7811
8166
|
function stageFile(logicalPath, absolutePath) {
|
|
7812
|
-
const buffer = (0,
|
|
8167
|
+
const buffer = (0, import_node_fs10.readFileSync)(absolutePath);
|
|
7813
8168
|
return {
|
|
7814
8169
|
logicalPath,
|
|
7815
8170
|
contentBase64: buffer.toString("base64"),
|
|
@@ -7820,9 +8175,9 @@ function stageFile(logicalPath, absolutePath) {
|
|
|
7820
8175
|
}
|
|
7821
8176
|
function normalizePlayPath(filePath) {
|
|
7822
8177
|
try {
|
|
7823
|
-
return
|
|
8178
|
+
return import_node_fs10.realpathSync.native((0, import_node_path12.resolve)(filePath));
|
|
7824
8179
|
} catch {
|
|
7825
|
-
return (0,
|
|
8180
|
+
return (0, import_node_path12.resolve)(filePath);
|
|
7826
8181
|
}
|
|
7827
8182
|
}
|
|
7828
8183
|
function formatBundlingErrors(filePath, errors) {
|
|
@@ -9264,7 +9619,9 @@ function buildRunPackageTextLines(packaged) {
|
|
|
9264
9619
|
lines.push(` ${kind} ${id}: ${stepStatus}${rowCount}`);
|
|
9265
9620
|
lines.push(...formatPackageDatasetSummaryLines(output?.summary));
|
|
9266
9621
|
if (previewRows !== null) {
|
|
9267
|
-
lines.push(
|
|
9622
|
+
lines.push(
|
|
9623
|
+
` preview=${previewRows}${preview?.truncated ? " truncated" : ""}`
|
|
9624
|
+
);
|
|
9268
9625
|
}
|
|
9269
9626
|
}
|
|
9270
9627
|
const next = packaged.next && typeof packaged.next === "object" && !Array.isArray(packaged.next) ? packaged.next : {};
|
|
@@ -9366,7 +9723,7 @@ function sqlStringLiteral(value) {
|
|
|
9366
9723
|
return `'${value.replace(/'/g, "''")}'`;
|
|
9367
9724
|
}
|
|
9368
9725
|
function runExportRetryCommand(runId, outPath, datasetPath) {
|
|
9369
|
-
return `deepline runs export ${runId}${datasetPath ? ` --dataset ${shellSingleQuote(datasetPath)}` : ""} --out ${shellSingleQuote((0,
|
|
9726
|
+
return `deepline runs export ${runId}${datasetPath ? ` --dataset ${shellSingleQuote(datasetPath)}` : ""} --out ${shellSingleQuote((0, import_node_path12.resolve)(outPath))}`;
|
|
9370
9727
|
}
|
|
9371
9728
|
function extractRunPlayName(status) {
|
|
9372
9729
|
const run = status.run;
|
|
@@ -9400,7 +9757,7 @@ function buildCustomerDbQueryPlan(input) {
|
|
|
9400
9757
|
return {
|
|
9401
9758
|
sql,
|
|
9402
9759
|
json: `${base} --json`,
|
|
9403
|
-
csv: `${base} --format csv --out ${shellSingleQuote((0,
|
|
9760
|
+
csv: `${base} --format csv --out ${shellSingleQuote((0, import_node_path12.resolve)(input.outPath))}`
|
|
9404
9761
|
};
|
|
9405
9762
|
}
|
|
9406
9763
|
function exportableSheetRow(row) {
|
|
@@ -10038,12 +10395,12 @@ function printToolGetterHints(hints) {
|
|
|
10038
10395
|
async function handlePlayCheck(args) {
|
|
10039
10396
|
const options = parsePlayCheckOptions(args);
|
|
10040
10397
|
if (!isFileTarget(options.target)) {
|
|
10041
|
-
const resolved = (0,
|
|
10398
|
+
const resolved = (0, import_node_path12.resolve)(options.target);
|
|
10042
10399
|
console.error(`File not found: ${resolved}`);
|
|
10043
10400
|
return 1;
|
|
10044
10401
|
}
|
|
10045
|
-
const absolutePlayPath = (0,
|
|
10046
|
-
const sourceCode = (0,
|
|
10402
|
+
const absolutePlayPath = (0, import_node_path12.resolve)(options.target);
|
|
10403
|
+
const sourceCode = (0, import_node_fs10.readFileSync)(absolutePlayPath, "utf-8");
|
|
10047
10404
|
let graph;
|
|
10048
10405
|
try {
|
|
10049
10406
|
graph = await collectBundledPlayGraph(absolutePlayPath);
|
|
@@ -10122,12 +10479,12 @@ async function handleFileBackedRun(options) {
|
|
|
10122
10479
|
}
|
|
10123
10480
|
const client = new DeeplineClient();
|
|
10124
10481
|
const progress = getActiveCliProgress() ?? createCliProgress(!options.jsonOutput);
|
|
10125
|
-
const absolutePlayPath = (0,
|
|
10482
|
+
const absolutePlayPath = (0, import_node_path12.resolve)(options.target.path);
|
|
10126
10483
|
progress.phase("compiling play");
|
|
10127
10484
|
const sourceCode = traceCliSync(
|
|
10128
10485
|
"cli.play_file_read_source",
|
|
10129
10486
|
{ targetKind: "file" },
|
|
10130
|
-
() => (0,
|
|
10487
|
+
() => (0, import_node_fs10.readFileSync)(absolutePlayPath, "utf-8")
|
|
10131
10488
|
);
|
|
10132
10489
|
const runtimeInput = options.input ? { ...options.input } : {};
|
|
10133
10490
|
let graph;
|
|
@@ -10411,19 +10768,19 @@ async function handlePlayRun(args) {
|
|
|
10411
10768
|
if (isFileTarget(options.target.path)) {
|
|
10412
10769
|
return handleFileBackedRun(options);
|
|
10413
10770
|
}
|
|
10414
|
-
const resolved = (0,
|
|
10771
|
+
const resolved = (0, import_node_path12.resolve)(options.target.path);
|
|
10415
10772
|
console.error(`File not found: ${resolved}`);
|
|
10416
|
-
const dir = (0,
|
|
10417
|
-
if ((0,
|
|
10418
|
-
const base = (0,
|
|
10773
|
+
const dir = (0, import_node_path12.dirname)(resolved);
|
|
10774
|
+
if ((0, import_node_fs10.existsSync)(dir)) {
|
|
10775
|
+
const base = (0, import_node_path12.basename)(resolved);
|
|
10419
10776
|
try {
|
|
10420
|
-
const siblings = (0,
|
|
10777
|
+
const siblings = (0, import_node_fs10.readdirSync)(dir).filter(
|
|
10421
10778
|
(f) => f.includes(base.replace(/\.(play\.)?ts$/, "")) || f.endsWith(".play.ts")
|
|
10422
10779
|
);
|
|
10423
10780
|
if (siblings.length > 0) {
|
|
10424
10781
|
console.error(`Did you mean one of these?`);
|
|
10425
10782
|
for (const s of siblings.slice(0, 5)) {
|
|
10426
|
-
console.error(` ${(0,
|
|
10783
|
+
console.error(` ${(0, import_node_path12.join)(dir, s)}`);
|
|
10427
10784
|
}
|
|
10428
10785
|
}
|
|
10429
10786
|
} catch {
|
|
@@ -10567,14 +10924,14 @@ async function handleRunLogs(args) {
|
|
|
10567
10924
|
continue;
|
|
10568
10925
|
}
|
|
10569
10926
|
if (arg === "--out" && args[index + 1]) {
|
|
10570
|
-
outPath = (0,
|
|
10927
|
+
outPath = (0, import_node_path12.resolve)(args[++index]);
|
|
10571
10928
|
}
|
|
10572
10929
|
}
|
|
10573
10930
|
const client = new DeeplineClient();
|
|
10574
10931
|
const status = await client.runs.get(runId);
|
|
10575
10932
|
const logs = status.progress?.logs ?? [];
|
|
10576
10933
|
if (outPath) {
|
|
10577
|
-
(0,
|
|
10934
|
+
(0, import_node_fs10.writeFileSync)(outPath, `${logs.join("\n")}${logs.length > 0 ? "\n" : ""}`);
|
|
10578
10935
|
printCommandEnvelope(
|
|
10579
10936
|
{
|
|
10580
10937
|
runId: status.runId,
|
|
@@ -10663,7 +11020,7 @@ async function handleRunExport(args) {
|
|
|
10663
11020
|
for (let index = 0; index < args.length; index += 1) {
|
|
10664
11021
|
const arg = args[index];
|
|
10665
11022
|
if (arg === "--out" && args[index + 1]) {
|
|
10666
|
-
outPath = (0,
|
|
11023
|
+
outPath = (0, import_node_path12.resolve)(args[++index]);
|
|
10667
11024
|
continue;
|
|
10668
11025
|
}
|
|
10669
11026
|
if (arg === "--dataset" && args[index + 1]) {
|
|
@@ -10671,7 +11028,7 @@ async function handleRunExport(args) {
|
|
|
10671
11028
|
continue;
|
|
10672
11029
|
}
|
|
10673
11030
|
if (arg === "--metadata-out" && args[index + 1]) {
|
|
10674
|
-
metadataOutPath = (0,
|
|
11031
|
+
metadataOutPath = (0, import_node_path12.resolve)(args[++index]);
|
|
10675
11032
|
}
|
|
10676
11033
|
}
|
|
10677
11034
|
if (!outPath) {
|
|
@@ -10728,7 +11085,7 @@ async function handleRunExport(args) {
|
|
|
10728
11085
|
}
|
|
10729
11086
|
};
|
|
10730
11087
|
if (metadataOutPath) {
|
|
10731
|
-
(0,
|
|
11088
|
+
(0, import_node_fs10.writeFileSync)(
|
|
10732
11089
|
metadataOutPath,
|
|
10733
11090
|
`${JSON.stringify(payload, null, 2)}
|
|
10734
11091
|
`,
|
|
@@ -10758,10 +11115,10 @@ async function handlePlayGet(args) {
|
|
|
10758
11115
|
for (let index = 1; index < args.length; index += 1) {
|
|
10759
11116
|
const arg = args[index];
|
|
10760
11117
|
if (arg === "--out" && args[index + 1]) {
|
|
10761
|
-
outPath = (0,
|
|
11118
|
+
outPath = (0, import_node_path12.resolve)(args[++index]);
|
|
10762
11119
|
}
|
|
10763
11120
|
}
|
|
10764
|
-
const playName = isFileTarget(target) ? extractPlayName((0,
|
|
11121
|
+
const playName = isFileTarget(target) ? extractPlayName((0, import_node_fs10.readFileSync)((0, import_node_path12.resolve)(target), "utf-8"), (0, import_node_path12.resolve)(target)) : parseReferencedPlayTarget2(target).playName;
|
|
10765
11122
|
const detail = isFileTarget(target) ? await client.getPlay(playName) : await assertCanonicalNamedPlayReference(client, target);
|
|
10766
11123
|
const resolvedSource = detail.play.workingRevision?.sourceCode ?? detail.play.liveRevision?.sourceCode ?? detail.play.currentRevision?.sourceCode ?? detail.play.sourceCode ?? "";
|
|
10767
11124
|
const materializedFile = outPath ? materializeRemotePlaySource({
|
|
@@ -11066,7 +11423,9 @@ function matchesPlayGrepQuery(value, query, mode) {
|
|
|
11066
11423
|
async function handlePlayGrep(args) {
|
|
11067
11424
|
const query = args[0]?.trim();
|
|
11068
11425
|
if (!query) {
|
|
11069
|
-
console.error(
|
|
11426
|
+
console.error(
|
|
11427
|
+
"Usage: deepline plays grep <query> [--mode all|any|phrase] [--compact] [--json]"
|
|
11428
|
+
);
|
|
11070
11429
|
return 1;
|
|
11071
11430
|
}
|
|
11072
11431
|
let mode = "all";
|
|
@@ -11099,13 +11458,15 @@ async function handlePlayGrep(args) {
|
|
|
11099
11458
|
)
|
|
11100
11459
|
).map((play) => summarizePlayListItemForCli(play, { compact }));
|
|
11101
11460
|
if (argsWantJson(args)) {
|
|
11102
|
-
process.stdout.write(
|
|
11103
|
-
|
|
11104
|
-
|
|
11105
|
-
|
|
11106
|
-
|
|
11107
|
-
|
|
11108
|
-
|
|
11461
|
+
process.stdout.write(
|
|
11462
|
+
`${JSON.stringify({
|
|
11463
|
+
plays,
|
|
11464
|
+
count: plays.length,
|
|
11465
|
+
query,
|
|
11466
|
+
grep: { mode, terms: parsePlayGrepTerms(query, mode) }
|
|
11467
|
+
})}
|
|
11468
|
+
`
|
|
11469
|
+
);
|
|
11109
11470
|
return 0;
|
|
11110
11471
|
}
|
|
11111
11472
|
process.stdout.write(`${plays.length} plays found:
|
|
@@ -11183,7 +11544,7 @@ async function handlePlayPublish(args) {
|
|
|
11183
11544
|
}
|
|
11184
11545
|
let graph;
|
|
11185
11546
|
try {
|
|
11186
|
-
graph = await collectBundledPlayGraph((0,
|
|
11547
|
+
graph = await collectBundledPlayGraph((0, import_node_path12.resolve)(playName));
|
|
11187
11548
|
await compileBundledPlayGraphManifests(client, graph);
|
|
11188
11549
|
await publishImportedPlayDependencies(client, graph);
|
|
11189
11550
|
} catch (error) {
|
|
@@ -11739,14 +12100,14 @@ Examples:
|
|
|
11739
12100
|
|
|
11740
12101
|
// src/cli/commands/tools.ts
|
|
11741
12102
|
var import_commander2 = require("commander");
|
|
12103
|
+
var import_node_fs12 = require("fs");
|
|
12104
|
+
var import_node_os8 = require("os");
|
|
12105
|
+
var import_node_path14 = require("path");
|
|
12106
|
+
|
|
12107
|
+
// src/tool-output.ts
|
|
11742
12108
|
var import_node_fs11 = require("fs");
|
|
11743
12109
|
var import_node_os7 = require("os");
|
|
11744
12110
|
var import_node_path13 = require("path");
|
|
11745
|
-
|
|
11746
|
-
// src/tool-output.ts
|
|
11747
|
-
var import_node_fs10 = require("fs");
|
|
11748
|
-
var import_node_os6 = require("os");
|
|
11749
|
-
var import_node_path12 = require("path");
|
|
11750
12111
|
function isPlainObject(value) {
|
|
11751
12112
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
11752
12113
|
}
|
|
@@ -11768,7 +12129,9 @@ function normalizeRows(value) {
|
|
|
11768
12129
|
});
|
|
11769
12130
|
}
|
|
11770
12131
|
function candidateRoots(payload) {
|
|
11771
|
-
const roots = [
|
|
12132
|
+
const roots = [
|
|
12133
|
+
{ path: null, value: payload }
|
|
12134
|
+
];
|
|
11772
12135
|
if (isPlainObject(payload) && isPlainObject(payload.toolResponse)) {
|
|
11773
12136
|
roots.push({ path: "toolResponse", value: payload.toolResponse });
|
|
11774
12137
|
if (Object.prototype.hasOwnProperty.call(payload.toolResponse, "raw")) {
|
|
@@ -11795,7 +12158,9 @@ function candidateRoots(payload) {
|
|
|
11795
12158
|
function findBestArrayCandidate(value, pathPrefix = "", depth = 0) {
|
|
11796
12159
|
if (depth > 5) return null;
|
|
11797
12160
|
const directRows = normalizeRows(value);
|
|
11798
|
-
const hasObjectRow = directRows?.some(
|
|
12161
|
+
const hasObjectRow = directRows?.some(
|
|
12162
|
+
(row) => Object.keys(row).some((key) => key !== "value")
|
|
12163
|
+
) ?? false;
|
|
11799
12164
|
let best = directRows && directRows.length > 0 && hasObjectRow ? { path: pathPrefix, rows: directRows } : null;
|
|
11800
12165
|
if (!isPlainObject(value)) {
|
|
11801
12166
|
return best;
|
|
@@ -11811,7 +12176,9 @@ function findBestArrayCandidate(value, pathPrefix = "", depth = 0) {
|
|
|
11811
12176
|
return best;
|
|
11812
12177
|
}
|
|
11813
12178
|
function tryConvertToList(payload, options) {
|
|
11814
|
-
const listExtractorPaths = Array.isArray(options?.listExtractorPaths) ? options?.listExtractorPaths.filter(
|
|
12179
|
+
const listExtractorPaths = Array.isArray(options?.listExtractorPaths) ? options?.listExtractorPaths.filter(
|
|
12180
|
+
(entry) => typeof entry === "string" && entry.trim().length > 0
|
|
12181
|
+
) : [];
|
|
11815
12182
|
if (listExtractorPaths.length > 0) {
|
|
11816
12183
|
for (const root of candidateRoots(payload)) {
|
|
11817
12184
|
for (const extractorPath of listExtractorPaths) {
|
|
@@ -11836,19 +12203,19 @@ function tryConvertToList(payload, options) {
|
|
|
11836
12203
|
return null;
|
|
11837
12204
|
}
|
|
11838
12205
|
function ensureOutputDir() {
|
|
11839
|
-
const outputDir = (0,
|
|
11840
|
-
(0,
|
|
12206
|
+
const outputDir = (0, import_node_path13.join)((0, import_node_os7.homedir)(), ".local", "share", "deepline", "data");
|
|
12207
|
+
(0, import_node_fs11.mkdirSync)(outputDir, { recursive: true });
|
|
11841
12208
|
return outputDir;
|
|
11842
12209
|
}
|
|
11843
12210
|
function writeJsonOutputFile(payload, stem) {
|
|
11844
12211
|
const outputDir = ensureOutputDir();
|
|
11845
|
-
const outputPath = (0,
|
|
11846
|
-
(0,
|
|
12212
|
+
const outputPath = (0, import_node_path13.join)(outputDir, `${stem}_${Date.now()}.json`);
|
|
12213
|
+
(0, import_node_fs11.writeFileSync)(outputPath, JSON.stringify(payload, null, 2), "utf-8");
|
|
11847
12214
|
return outputPath;
|
|
11848
12215
|
}
|
|
11849
12216
|
function writeCsvOutputFile(rows, stem) {
|
|
11850
12217
|
const outputDir = ensureOutputDir();
|
|
11851
|
-
const outputPath = (0,
|
|
12218
|
+
const outputPath = (0, import_node_path13.join)(outputDir, `${stem}_${Date.now()}.csv`);
|
|
11852
12219
|
const seen = /* @__PURE__ */ new Set();
|
|
11853
12220
|
const columns = [];
|
|
11854
12221
|
for (const row of rows) {
|
|
@@ -11871,13 +12238,15 @@ function writeCsvOutputFile(rows, stem) {
|
|
|
11871
12238
|
for (const row of rows) {
|
|
11872
12239
|
lines.push(columns.map((column) => escapeCell(row[column])).join(","));
|
|
11873
12240
|
}
|
|
11874
|
-
(0,
|
|
12241
|
+
(0, import_node_fs11.writeFileSync)(outputPath, `${lines.join("\n")}
|
|
11875
12242
|
`, "utf-8");
|
|
11876
12243
|
const previewRows = rows.slice(0, 5);
|
|
11877
12244
|
const previewColumns = columns.slice(0, 5);
|
|
11878
12245
|
const preview = [
|
|
11879
12246
|
previewColumns.join(","),
|
|
11880
|
-
...previewRows.map(
|
|
12247
|
+
...previewRows.map(
|
|
12248
|
+
(row) => previewColumns.map((column) => escapeCell(row[column])).join(",")
|
|
12249
|
+
)
|
|
11881
12250
|
].join("\n");
|
|
11882
12251
|
return {
|
|
11883
12252
|
path: outputPath,
|
|
@@ -11890,9 +12259,11 @@ function extractSummaryFields(payload) {
|
|
|
11890
12259
|
const candidates = candidateRoots(payload);
|
|
11891
12260
|
for (const candidate of candidates) {
|
|
11892
12261
|
if (!isPlainObject(candidate.value)) continue;
|
|
11893
|
-
const summaryEntries = Object.entries(candidate.value).filter(
|
|
11894
|
-
|
|
11895
|
-
|
|
12262
|
+
const summaryEntries = Object.entries(candidate.value).filter(
|
|
12263
|
+
([, value]) => {
|
|
12264
|
+
return value == null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
12265
|
+
}
|
|
12266
|
+
);
|
|
11896
12267
|
if (summaryEntries.length === 0) continue;
|
|
11897
12268
|
return Object.fromEntries(summaryEntries);
|
|
11898
12269
|
}
|
|
@@ -12422,8 +12793,16 @@ function toolContractJsonForDescribe(tool, requestedToolId) {
|
|
|
12422
12793
|
arrayField(toolExecutionResult, "extractedValues", "extracted_values")
|
|
12423
12794
|
);
|
|
12424
12795
|
const cost = recordField(tool, "cost");
|
|
12425
|
-
const deeplineCredits = numberField(
|
|
12426
|
-
|
|
12796
|
+
const deeplineCredits = numberField(
|
|
12797
|
+
tool,
|
|
12798
|
+
"deeplineCreditsPerPricingUnit",
|
|
12799
|
+
"deepline_credits_per_pricing_unit"
|
|
12800
|
+
);
|
|
12801
|
+
const deeplineUsdPerPricingUnit = numberField(
|
|
12802
|
+
tool,
|
|
12803
|
+
"deeplineUsdPerPricingUnit",
|
|
12804
|
+
"deepline_usd_per_pricing_unit"
|
|
12805
|
+
);
|
|
12427
12806
|
const starterScript = seedToolListScript({
|
|
12428
12807
|
toolId,
|
|
12429
12808
|
payload: samplePayloadForInputFields(inputFields),
|
|
@@ -12511,7 +12890,9 @@ function printCompactToolContract(tool, requestedToolId) {
|
|
|
12511
12890
|
if (starterPath) {
|
|
12512
12891
|
console.log("");
|
|
12513
12892
|
console.log(`Starter script: ${starterPath}`);
|
|
12514
|
-
console.log(
|
|
12893
|
+
console.log(
|
|
12894
|
+
"Copy it into your project and replace the sample input with the proven probe payload."
|
|
12895
|
+
);
|
|
12515
12896
|
}
|
|
12516
12897
|
if (listGetters.length || valueGetters.length) {
|
|
12517
12898
|
console.log("");
|
|
@@ -12674,7 +13055,9 @@ function playResultExpression(entry) {
|
|
|
12674
13055
|
}
|
|
12675
13056
|
function toolMetadataJsonForDescribe(tool, requestedToolId) {
|
|
12676
13057
|
const toolId = String(tool.toolId || requestedToolId);
|
|
12677
|
-
const inputFields = toolInputFieldsForDisplay(
|
|
13058
|
+
const inputFields = toolInputFieldsForDisplay(
|
|
13059
|
+
recordField(tool, "inputSchema", "input_schema")
|
|
13060
|
+
);
|
|
12678
13061
|
const starterScript = seedToolListScript({
|
|
12679
13062
|
toolId,
|
|
12680
13063
|
payload: samplePayloadForInputFields(inputFields),
|
|
@@ -12699,7 +13082,9 @@ function toolMetadataJsonForDescribe(tool, requestedToolId) {
|
|
|
12699
13082
|
toolId,
|
|
12700
13083
|
provider: tool.provider,
|
|
12701
13084
|
displayName: tool.displayName,
|
|
12702
|
-
usageGuidance: usageGuidanceWithAccessDefaults(
|
|
13085
|
+
usageGuidance: usageGuidanceWithAccessDefaults(
|
|
13086
|
+
recordField(tool, "usageGuidance", "usage_guidance")
|
|
13087
|
+
),
|
|
12703
13088
|
runtimeOutputHelp: {
|
|
12704
13089
|
contract: "tools describe shows declared schema and Deepline getters; it is not an observed provider response.",
|
|
12705
13090
|
getterScope: "extractedValues/extractedLists .get() only works for declared Deepline getters listed in usageGuidance.toolExecutionResult.",
|
|
@@ -12921,9 +13306,9 @@ function powerShellQuote(value) {
|
|
|
12921
13306
|
function seedToolListScript(input) {
|
|
12922
13307
|
const stem = safeFileStem(input.toolId);
|
|
12923
13308
|
const fileName = `${stem}-workflow-seed-${Date.now()}.play.ts`;
|
|
12924
|
-
const scriptDir = (0,
|
|
12925
|
-
(0,
|
|
12926
|
-
const scriptPath = (0,
|
|
13309
|
+
const scriptDir = (0, import_node_fs12.mkdtempSync)((0, import_node_path14.join)((0, import_node_os8.tmpdir)(), "deepline-workflow-seed-"));
|
|
13310
|
+
(0, import_node_fs12.chmodSync)(scriptDir, 448);
|
|
13311
|
+
const scriptPath = (0, import_node_path14.join)(scriptDir, fileName);
|
|
12927
13312
|
const projectDir = `deepline/projects/${stem}-workflow`;
|
|
12928
13313
|
const playName = `${stem}-workflow`;
|
|
12929
13314
|
const sampleRows = input.rows.length > 0 ? `${JSON.stringify(input.rows.slice(0, 2)).replace(/\]$/, "")}, ...]` : "[]";
|
|
@@ -12959,7 +13344,7 @@ export default definePlay(${JSON.stringify(playName)}, async (ctx) => {
|
|
|
12959
13344
|
};
|
|
12960
13345
|
});
|
|
12961
13346
|
`;
|
|
12962
|
-
(0,
|
|
13347
|
+
(0, import_node_fs12.writeFileSync)(scriptPath, script, { encoding: "utf-8", mode: 384 });
|
|
12963
13348
|
return {
|
|
12964
13349
|
path: scriptPath,
|
|
12965
13350
|
sourceCode: script,
|
|
@@ -13214,8 +13599,8 @@ async function executeTool(args) {
|
|
|
13214
13599
|
|
|
13215
13600
|
// src/cli/commands/update.ts
|
|
13216
13601
|
var import_node_child_process = require("child_process");
|
|
13217
|
-
var
|
|
13218
|
-
var
|
|
13602
|
+
var import_node_fs13 = require("fs");
|
|
13603
|
+
var import_node_path15 = require("path");
|
|
13219
13604
|
function posixShellQuote(value) {
|
|
13220
13605
|
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
13221
13606
|
}
|
|
@@ -13234,19 +13619,19 @@ function buildSourceUpdateCommand(sourceRoot) {
|
|
|
13234
13619
|
return `${cdCommand} && git fetch origin main --tags && git merge --ff-only origin/main`;
|
|
13235
13620
|
}
|
|
13236
13621
|
function findRepoBackedSdkRoot(startPath) {
|
|
13237
|
-
let current = (0,
|
|
13622
|
+
let current = (0, import_node_path15.resolve)(startPath);
|
|
13238
13623
|
while (true) {
|
|
13239
|
-
if ((0,
|
|
13624
|
+
if ((0, import_node_fs13.existsSync)((0, import_node_path15.join)(current, "sdk", "package.json")) && (0, import_node_fs13.existsSync)((0, import_node_path15.join)(current, "sdk", "bin", "deepline-dev.ts"))) {
|
|
13240
13625
|
return current;
|
|
13241
13626
|
}
|
|
13242
|
-
const parent = (0,
|
|
13627
|
+
const parent = (0, import_node_path15.dirname)(current);
|
|
13243
13628
|
if (parent === current) return null;
|
|
13244
13629
|
current = parent;
|
|
13245
13630
|
}
|
|
13246
13631
|
}
|
|
13247
13632
|
function resolveUpdatePlan() {
|
|
13248
|
-
const entrypoint = process.argv[1] ? (0,
|
|
13249
|
-
const sourceRoot = entrypoint ? findRepoBackedSdkRoot((0,
|
|
13633
|
+
const entrypoint = process.argv[1] ? (0, import_node_path15.resolve)(process.argv[1]) : "";
|
|
13634
|
+
const sourceRoot = entrypoint ? findRepoBackedSdkRoot((0, import_node_path15.dirname)(entrypoint)) : null;
|
|
13250
13635
|
if (sourceRoot) {
|
|
13251
13636
|
return {
|
|
13252
13637
|
kind: "source",
|
|
@@ -13314,8 +13699,10 @@ async function handleUpdate(options) {
|
|
|
13314
13699
|
printCommandEnvelope({ ...plan, render }, { json: false });
|
|
13315
13700
|
return 0;
|
|
13316
13701
|
}
|
|
13317
|
-
process.stderr.write(
|
|
13318
|
-
`
|
|
13702
|
+
process.stderr.write(
|
|
13703
|
+
`Updating Deepline SDK/CLI with: ${plan.manualCommand}
|
|
13704
|
+
`
|
|
13705
|
+
);
|
|
13319
13706
|
return runCommand(plan.command, plan.args);
|
|
13320
13707
|
}
|
|
13321
13708
|
function registerUpdateCommand(program) {
|
|
@@ -13339,9 +13726,9 @@ Examples:
|
|
|
13339
13726
|
|
|
13340
13727
|
// src/cli/skills-sync.ts
|
|
13341
13728
|
var import_node_child_process2 = require("child_process");
|
|
13342
|
-
var
|
|
13343
|
-
var
|
|
13344
|
-
var
|
|
13729
|
+
var import_node_fs14 = require("fs");
|
|
13730
|
+
var import_node_os9 = require("os");
|
|
13731
|
+
var import_node_path16 = require("path");
|
|
13345
13732
|
var CHECK_TIMEOUT_MS2 = 3e3;
|
|
13346
13733
|
var SDK_SKILL_NAME = "deepline-sdk";
|
|
13347
13734
|
var SKILL_AGENTS = ["codex", "claude-code", "cursor"];
|
|
@@ -13351,29 +13738,36 @@ function shouldSkipSkillsSync() {
|
|
|
13351
13738
|
return value === "1" || value === "true" || value === "yes" || value === "on";
|
|
13352
13739
|
}
|
|
13353
13740
|
function sdkSkillsVersionPath(baseUrl) {
|
|
13354
|
-
const home = process.env.HOME?.trim() || (0,
|
|
13355
|
-
return (0,
|
|
13741
|
+
const home = process.env.HOME?.trim() || (0, import_node_os9.homedir)();
|
|
13742
|
+
return (0, import_node_path16.join)(
|
|
13743
|
+
home,
|
|
13744
|
+
".local",
|
|
13745
|
+
"deepline",
|
|
13746
|
+
baseUrlSlug(baseUrl),
|
|
13747
|
+
"sdk-skills",
|
|
13748
|
+
".version"
|
|
13749
|
+
);
|
|
13356
13750
|
}
|
|
13357
13751
|
function readLocalSkillsVersion(baseUrl) {
|
|
13358
13752
|
const path = sdkSkillsVersionPath(baseUrl);
|
|
13359
|
-
if (!(0,
|
|
13753
|
+
if (!(0, import_node_fs14.existsSync)(path)) return "";
|
|
13360
13754
|
try {
|
|
13361
|
-
return (0,
|
|
13755
|
+
return (0, import_node_fs14.readFileSync)(path, "utf-8").trim();
|
|
13362
13756
|
} catch {
|
|
13363
13757
|
return "";
|
|
13364
13758
|
}
|
|
13365
13759
|
}
|
|
13366
13760
|
function writeLocalSkillsVersion(baseUrl, version) {
|
|
13367
13761
|
const path = sdkSkillsVersionPath(baseUrl);
|
|
13368
|
-
(0,
|
|
13369
|
-
(0,
|
|
13762
|
+
(0, import_node_fs14.mkdirSync)((0, import_node_path16.dirname)(path), { recursive: true });
|
|
13763
|
+
(0, import_node_fs14.writeFileSync)(path, `${version}
|
|
13370
13764
|
`, "utf-8");
|
|
13371
13765
|
}
|
|
13372
13766
|
function installedSdkSkillHasStalePositionalExecuteExamples() {
|
|
13373
|
-
const home = process.env.HOME?.trim() || (0,
|
|
13767
|
+
const home = process.env.HOME?.trim() || (0, import_node_os9.homedir)();
|
|
13374
13768
|
const roots = [
|
|
13375
|
-
(0,
|
|
13376
|
-
(0,
|
|
13769
|
+
(0, import_node_path16.join)(home, ".claude", "skills", SDK_SKILL_NAME),
|
|
13770
|
+
(0, import_node_path16.join)(home, ".agents", "skills", SDK_SKILL_NAME)
|
|
13377
13771
|
];
|
|
13378
13772
|
const staleMarkers = [
|
|
13379
13773
|
"ctx.tools.execute(key",
|
|
@@ -13383,22 +13777,22 @@ function installedSdkSkillHasStalePositionalExecuteExamples() {
|
|
|
13383
13777
|
'rowCtx.tools.execute("'
|
|
13384
13778
|
];
|
|
13385
13779
|
const scan = (dir) => {
|
|
13386
|
-
for (const entry of (0,
|
|
13387
|
-
const path = (0,
|
|
13388
|
-
const stat3 = (0,
|
|
13780
|
+
for (const entry of (0, import_node_fs14.readdirSync)(dir)) {
|
|
13781
|
+
const path = (0, import_node_path16.join)(dir, entry);
|
|
13782
|
+
const stat3 = (0, import_node_fs14.statSync)(path);
|
|
13389
13783
|
if (stat3.isDirectory()) {
|
|
13390
13784
|
if (scan(path)) return true;
|
|
13391
13785
|
continue;
|
|
13392
13786
|
}
|
|
13393
13787
|
if (!entry.endsWith(".md")) continue;
|
|
13394
|
-
const text = (0,
|
|
13788
|
+
const text = (0, import_node_fs14.readFileSync)(path, "utf-8");
|
|
13395
13789
|
if (staleMarkers.some((marker) => text.includes(marker))) return true;
|
|
13396
13790
|
}
|
|
13397
13791
|
return false;
|
|
13398
13792
|
};
|
|
13399
13793
|
for (const root of roots) {
|
|
13400
13794
|
try {
|
|
13401
|
-
if ((0,
|
|
13795
|
+
if ((0, import_node_fs14.existsSync)(root) && scan(root)) return true;
|
|
13402
13796
|
} catch {
|
|
13403
13797
|
continue;
|
|
13404
13798
|
}
|
|
@@ -13434,7 +13828,10 @@ async function fetchSkillsUpdate(baseUrl, localVersion) {
|
|
|
13434
13828
|
}
|
|
13435
13829
|
}
|
|
13436
13830
|
function buildSkillsInstallArgs(baseUrl) {
|
|
13437
|
-
const packageUrl = new URL(
|
|
13831
|
+
const packageUrl = new URL(
|
|
13832
|
+
"/.well-known/skills/index.json",
|
|
13833
|
+
baseUrl
|
|
13834
|
+
).toString();
|
|
13438
13835
|
return [
|
|
13439
13836
|
"--yes",
|
|
13440
13837
|
"skills",
|
|
@@ -13450,7 +13847,10 @@ function buildSkillsInstallArgs(baseUrl) {
|
|
|
13450
13847
|
];
|
|
13451
13848
|
}
|
|
13452
13849
|
function buildBunxSkillsInstallArgs(baseUrl) {
|
|
13453
|
-
const packageUrl = new URL(
|
|
13850
|
+
const packageUrl = new URL(
|
|
13851
|
+
"/.well-known/skills/index.json",
|
|
13852
|
+
baseUrl
|
|
13853
|
+
).toString();
|
|
13454
13854
|
return [
|
|
13455
13855
|
"--bun",
|
|
13456
13856
|
"skills",
|
|
@@ -13594,8 +13994,8 @@ function shouldDeferSkillsSyncForCommand() {
|
|
|
13594
13994
|
return (command === "play" || command === "plays") && subcommand === "run" && args.includes("--json");
|
|
13595
13995
|
}
|
|
13596
13996
|
async function runPlayRunnerHealthCheck() {
|
|
13597
|
-
const dir = await (0, import_promises5.mkdtemp)((0,
|
|
13598
|
-
const file = (0,
|
|
13997
|
+
const dir = await (0, import_promises5.mkdtemp)((0, import_node_path17.join)((0, import_node_os10.tmpdir)(), "deepline-health-play-"));
|
|
13998
|
+
const file = (0, import_node_path17.join)(dir, "health-check.play.ts");
|
|
13599
13999
|
try {
|
|
13600
14000
|
await (0, import_promises5.writeFile)(
|
|
13601
14001
|
file,
|