@diafunc/cli 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/diafunc.js +3 -3
- package/dist/{chunk-D7AJH4Y3.js → chunk-IV75CA5V.js} +76 -29
- package/dist/chunk-IV75CA5V.js.map +1 -0
- package/dist/{chunk-V2VLVFWP.js → chunk-M34533JL.js} +2 -2
- package/dist/{chunk-V2VLVFWP.js.map → chunk-M34533JL.js.map} +1 -1
- package/dist/{chunk-4STLEQUJ.js → chunk-ZCJKBLEW.js} +2 -2
- package/dist/src/index.js +2 -2
- package/dist/update-check-EW6JPLJT.js +8 -0
- package/package.json +1 -1
- package/dist/chunk-D7AJH4Y3.js.map +0 -1
- package/dist/update-check-7F4ABBDC.js +0 -8
- /package/dist/{chunk-4STLEQUJ.js.map → chunk-ZCJKBLEW.js.map} +0 -0
- /package/dist/{update-check-7F4ABBDC.js.map → update-check-EW6JPLJT.js.map} +0 -0
package/dist/bin/diafunc.js
CHANGED
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
PromptCancelled,
|
|
5
5
|
createProgram,
|
|
6
6
|
handleError
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-IV75CA5V.js";
|
|
8
8
|
import {
|
|
9
9
|
getUpdateNotice
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-ZCJKBLEW.js";
|
|
11
11
|
import {
|
|
12
12
|
package_default
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-M34533JL.js";
|
|
14
14
|
|
|
15
15
|
// bin/diafunc.ts
|
|
16
16
|
import chalk2 from "chalk";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-M34533JL.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import chalk37 from "chalk";
|
|
@@ -1559,6 +1559,14 @@ function createAnalysisService(client) {
|
|
|
1559
1559
|
path: `/${encodeURIComponent(analysisId)}`
|
|
1560
1560
|
});
|
|
1561
1561
|
},
|
|
1562
|
+
/** The depth the platform would give the caller's next analysis if its creation named none. */
|
|
1563
|
+
async getDepthDefault() {
|
|
1564
|
+
return client.request({
|
|
1565
|
+
method: "GET",
|
|
1566
|
+
service: SERVICE2,
|
|
1567
|
+
path: "/depth-default"
|
|
1568
|
+
});
|
|
1569
|
+
},
|
|
1562
1570
|
// ----- Public analyses: readable without signing in --------------------------------
|
|
1563
1571
|
/** One page of the public analyses. `cursor` is the `nextCursor` of the page before. */
|
|
1564
1572
|
async listPublic(page = {}) {
|
|
@@ -6287,7 +6295,7 @@ var HELP = [
|
|
|
6287
6295
|
];
|
|
6288
6296
|
async function runChatRepl(options) {
|
|
6289
6297
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
6290
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
6298
|
+
const { getUpdateNotice } = await import("./update-check-EW6JPLJT.js");
|
|
6291
6299
|
let sessionId = options.session;
|
|
6292
6300
|
let lastReportedSession;
|
|
6293
6301
|
console.log(chalk19.bold("Diafunc chat") + chalk19.dim(" \xB7 /help for commands, /quit to exit"));
|
|
@@ -7443,8 +7451,12 @@ var DEPTH_PRESETS = [
|
|
|
7443
7451
|
{ name: "Thorough", hours: "8", budget: "40000" },
|
|
7444
7452
|
{ name: "Deep", hours: "24", budget: "150000" }
|
|
7445
7453
|
];
|
|
7446
|
-
var
|
|
7447
|
-
|
|
7454
|
+
var STARTING_DEPTH_RULE = "Defaults to the account's starting depth: Express (1 hour, 500 credits) until the account has a finished analysis, Standard (4 hours, 10,000 credits) afterwards.";
|
|
7455
|
+
function depthOf(hours, budget) {
|
|
7456
|
+
const h = hours?.trim();
|
|
7457
|
+
const b = budget?.trim();
|
|
7458
|
+
return h && b ? { hours: h, budget: b } : null;
|
|
7459
|
+
}
|
|
7448
7460
|
async function promptCreationFields(prompter, supplied, fallbackName) {
|
|
7449
7461
|
const name = supplied.name ?? await prompter.input({
|
|
7450
7462
|
message: "Analysis name",
|
|
@@ -7480,7 +7492,7 @@ function positiveNumber(label) {
|
|
|
7480
7492
|
};
|
|
7481
7493
|
}
|
|
7482
7494
|
async function promptRunFields(prompter, options) {
|
|
7483
|
-
const { columns } = options;
|
|
7495
|
+
const { columns, depthDefault } = options;
|
|
7484
7496
|
const named = columns.filter((c) => c.name && c.name.length > 0);
|
|
7485
7497
|
let supplied = { ...options.supplied };
|
|
7486
7498
|
const nothingSupplied = supplied.targets === void 0 && supplied.segment === void 0 && supplied.questions === void 0 && supplied.hours === void 0 && supplied.budget === void 0;
|
|
@@ -7573,7 +7585,7 @@ async function promptRunFields(prompter, options) {
|
|
|
7573
7585
|
if (hours === void 0 && budget === void 0) {
|
|
7574
7586
|
const chosen = await prompter.select({
|
|
7575
7587
|
message: "Depth: how long may the search run, and what may it spend?",
|
|
7576
|
-
default:
|
|
7588
|
+
default: matchDepthPreset(depthDefault?.hours, depthDefault?.budget) ?? void 0,
|
|
7577
7589
|
choices: [
|
|
7578
7590
|
...DEPTH_PRESETS.map((p) => ({
|
|
7579
7591
|
name: p.name,
|
|
@@ -7591,14 +7603,14 @@ async function promptRunFields(prompter, options) {
|
|
|
7591
7603
|
if (hours === void 0) {
|
|
7592
7604
|
hours = await prompter.input({
|
|
7593
7605
|
message: "Time budget (hours)",
|
|
7594
|
-
default:
|
|
7606
|
+
default: depthDefault?.hours,
|
|
7595
7607
|
validate: positiveNumber("Time budget")
|
|
7596
7608
|
});
|
|
7597
7609
|
}
|
|
7598
7610
|
if (budget === void 0) {
|
|
7599
7611
|
budget = await prompter.input({
|
|
7600
7612
|
message: "Credit budget",
|
|
7601
|
-
default:
|
|
7613
|
+
default: depthDefault?.budget,
|
|
7602
7614
|
validate: positiveNumber("Credit budget")
|
|
7603
7615
|
});
|
|
7604
7616
|
}
|
|
@@ -7611,7 +7623,9 @@ async function promptRunFields(prompter, options) {
|
|
|
7611
7623
|
};
|
|
7612
7624
|
}
|
|
7613
7625
|
function describePreset(preset) {
|
|
7614
|
-
const parts = [
|
|
7626
|
+
const parts = [];
|
|
7627
|
+
if (preset.time) parts.push(`${preset.time}h`);
|
|
7628
|
+
if (preset.budget) parts.push(`${preset.budget} credits`);
|
|
7615
7629
|
if (preset.targetKeys.length > 0) parts.push(`targets: ${preset.targetKeys.join(", ")}`);
|
|
7616
7630
|
if (preset.segmentKey) parts.push(`segmented by ${preset.segmentKey}`);
|
|
7617
7631
|
return parts.join(" \xB7 ");
|
|
@@ -7626,11 +7640,14 @@ function summaryLines(creation, run) {
|
|
|
7626
7640
|
if (run.questions && run.questions.length > 0) {
|
|
7627
7641
|
lines.push(`Questions: ${run.questions.length}`);
|
|
7628
7642
|
}
|
|
7629
|
-
|
|
7630
|
-
const named = depth ? `${depth.name}, ` : "";
|
|
7631
|
-
lines.push(`Depth: ${named}${run.hours}h \xB7 ${run.budget} credits`);
|
|
7643
|
+
lines.push(`Depth: ${depthLabel(run)}`);
|
|
7632
7644
|
return lines;
|
|
7633
7645
|
}
|
|
7646
|
+
function depthLabel(depth) {
|
|
7647
|
+
const preset = matchDepthPreset(depth.hours, depth.budget);
|
|
7648
|
+
const named = preset ? `${preset.name}, ` : "";
|
|
7649
|
+
return `${named}${depth.hours}h \xB7 ${depth.budget} credits`;
|
|
7650
|
+
}
|
|
7634
7651
|
function missingRunFields(recipe) {
|
|
7635
7652
|
const missing = [];
|
|
7636
7653
|
if (!recipe.hours || recipe.hours.trim().length === 0) missing.push("hours");
|
|
@@ -8159,6 +8176,12 @@ function parseVisibility(value) {
|
|
|
8159
8176
|
function isTerminalState(state) {
|
|
8160
8177
|
return state === "COMPLETED" || state === "FAILED" || state === "CANCELLED";
|
|
8161
8178
|
}
|
|
8179
|
+
function namedDepth(options) {
|
|
8180
|
+
const depth = {};
|
|
8181
|
+
if (options.hours?.trim()) depth.hours = options.hours.trim();
|
|
8182
|
+
if (options.budget?.trim()) depth.budget = options.budget.trim();
|
|
8183
|
+
return depth;
|
|
8184
|
+
}
|
|
8162
8185
|
function budgetHoursOf(hours) {
|
|
8163
8186
|
if (hours === null || hours === void 0) return null;
|
|
8164
8187
|
const parsed = Number(hours);
|
|
@@ -8199,8 +8222,8 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8199
8222
|
if (options.targets === void 0 && p.targetKeys.length > 0) presetTargets = p.targetKeys;
|
|
8200
8223
|
if (options.question === void 0 && p.questions.length > 0) options.question = [...p.questions];
|
|
8201
8224
|
if (options.segment === void 0 && p.segmentKey) options.segment = p.segmentKey;
|
|
8202
|
-
if (options.hours === void 0) options.hours = p.time;
|
|
8203
|
-
if (options.budget === void 0) options.budget = p.budget;
|
|
8225
|
+
if (options.hours === void 0 && p.time?.trim()) options.hours = p.time;
|
|
8226
|
+
if (options.budget === void 0 && p.budget?.trim()) options.budget = p.budget;
|
|
8204
8227
|
}
|
|
8205
8228
|
const typedTargets = occurrences(options.targets)?.filter((entry) => entry.trim().length > 0);
|
|
8206
8229
|
const targetsGiven = (typedTargets?.length ?? 0) > 0 || (presetTargets?.length ?? 0) > 0;
|
|
@@ -8226,8 +8249,7 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8226
8249
|
description: creation.description,
|
|
8227
8250
|
visibility: creation.visibility,
|
|
8228
8251
|
introduction: options.introduction ?? null,
|
|
8229
|
-
|
|
8230
|
-
budget: options.budget ?? DEFAULT_BUDGET,
|
|
8252
|
+
...namedDepth(options),
|
|
8231
8253
|
// The targets and the segment are column names, and the columns exist only once the file is
|
|
8232
8254
|
// uploaded. They are set below, read against the real header.
|
|
8233
8255
|
targets: null,
|
|
@@ -8240,6 +8262,20 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8240
8262
|
return;
|
|
8241
8263
|
}
|
|
8242
8264
|
detail(`analysisId: ${created.analysisId}`);
|
|
8265
|
+
const stored = depthOf(created.hours, created.budget);
|
|
8266
|
+
const recipe = { ...request, hours: created.hours, budget: created.budget };
|
|
8267
|
+
if (!interactive) {
|
|
8268
|
+
if (!stored) {
|
|
8269
|
+
throw new CliError(
|
|
8270
|
+
`The platform gave analysis ${created.analysisId} no depth, and ${whyNoPrompt(outputFormat, noInteractive)}.`,
|
|
8271
|
+
{
|
|
8272
|
+
exitCode: EXIT_USAGE,
|
|
8273
|
+
hint: `Pass --hours and --budget. Analysis ${created.analysisId} is created and holds no data yet; remove it with 'diafunc analyze delete ${created.analysisId}'.`
|
|
8274
|
+
}
|
|
8275
|
+
);
|
|
8276
|
+
}
|
|
8277
|
+
detail(`depth: ${depthLabel(stored)}${created.depthPreselection ? " (the account's starting depth)" : ""}`);
|
|
8278
|
+
}
|
|
8243
8279
|
await sendData(importContext(api, created.analysisId, cmd, "stream"), () => files.length > 1 ? uploadSeveral(api, created.analysisId, files, stackChoices(options), outputFormat === "human") : withStatus(
|
|
8244
8280
|
`Uploading ${path8.basename(file)}`,
|
|
8245
8281
|
() => api.analysis.uploadDataMultipart(created.analysisId, multipartFromFile(file))
|
|
@@ -8251,9 +8287,9 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8251
8287
|
interactive,
|
|
8252
8288
|
{ typedTargets, presetTargets, segment: options.segment }
|
|
8253
8289
|
);
|
|
8254
|
-
let runHours =
|
|
8290
|
+
let runHours = created.hours;
|
|
8255
8291
|
if (interactive) {
|
|
8256
|
-
const configuredHours = await configureInteractively(api, prompter, created.analysisId,
|
|
8292
|
+
const configuredHours = await configureInteractively(api, prompter, created.analysisId, recipe, {
|
|
8257
8293
|
targets: named.targets,
|
|
8258
8294
|
segment: named.segment,
|
|
8259
8295
|
questions: options.question === void 0 ? void 0 : questionsOf(options.question),
|
|
@@ -8264,7 +8300,7 @@ async function runAnalysis(files, options, cmd) {
|
|
|
8264
8300
|
runHours = configuredHours;
|
|
8265
8301
|
} else {
|
|
8266
8302
|
await withStatus("Saving the analysis settings", () => api.analysis.update(created.analysisId, {
|
|
8267
|
-
...
|
|
8303
|
+
...recipe,
|
|
8268
8304
|
targets: named.targets ?? null,
|
|
8269
8305
|
segment: named.segment ?? null
|
|
8270
8306
|
}));
|
|
@@ -8301,10 +8337,12 @@ function namedColumns(analysisId, columns, interactive, given) {
|
|
|
8301
8337
|
async function configureInteractively(api, prompter, analysisId, recipe, supplied, knownColumns) {
|
|
8302
8338
|
const columns = knownColumns ?? await readColumns(api, analysisId);
|
|
8303
8339
|
const presets = await readPresets(api);
|
|
8340
|
+
const depthAsked = supplied.hours === void 0 || supplied.budget === void 0;
|
|
8341
|
+
const depthDefault = depthAsked ? await readDepthDefault(api, recipe) : null;
|
|
8304
8342
|
console.log();
|
|
8305
|
-
const answers = await promptRunFields(prompter, { columns, presets, supplied });
|
|
8343
|
+
const answers = await promptRunFields(prompter, { columns, presets, supplied, depthDefault });
|
|
8306
8344
|
console.log();
|
|
8307
|
-
await withStatus("Saving the analysis settings", () => api.analysis.update(analysisId, {
|
|
8345
|
+
const saved = await withStatus("Saving the analysis settings", () => api.analysis.update(analysisId, {
|
|
8308
8346
|
...recipe,
|
|
8309
8347
|
targets: answers.targets,
|
|
8310
8348
|
questions: answers.questions,
|
|
@@ -8319,14 +8357,24 @@ async function configureInteractively(api, prompter, analysisId, recipe, supplie
|
|
|
8319
8357
|
description: recipe.description ?? null,
|
|
8320
8358
|
visibility: recipe.visibility ?? "PRIVATE"
|
|
8321
8359
|
};
|
|
8322
|
-
|
|
8360
|
+
const depth = depthOf(saved?.hours, saved?.budget) ?? { hours: answers.hours, budget: answers.budget };
|
|
8361
|
+
for (const line of summaryLines(identity, { ...answers, ...depth })) detail(line);
|
|
8323
8362
|
console.log();
|
|
8324
8363
|
if (!await prompter.confirm({ message: "Start the analysis?", default: true })) {
|
|
8325
8364
|
warn("Not started. The analysis and these settings are saved.");
|
|
8326
8365
|
hint(`Start it later with 'diafunc analyze rerun ${analysisId}'.`);
|
|
8327
8366
|
return null;
|
|
8328
8367
|
}
|
|
8329
|
-
return
|
|
8368
|
+
return depth.hours;
|
|
8369
|
+
}
|
|
8370
|
+
async function readDepthDefault(api, stored) {
|
|
8371
|
+
try {
|
|
8372
|
+
const answer = await api.analysis.getDepthDefault();
|
|
8373
|
+
const depth = depthOf(answer?.hours, answer?.budget);
|
|
8374
|
+
if (depth) return depth;
|
|
8375
|
+
} catch {
|
|
8376
|
+
}
|
|
8377
|
+
return depthOf(stored.hours, stored.budget);
|
|
8330
8378
|
}
|
|
8331
8379
|
async function readColumns(api, analysisId) {
|
|
8332
8380
|
for (let attempt = 0; attempt < COLUMN_READ_ATTEMPTS; attempt++) {
|
|
@@ -8638,8 +8686,7 @@ async function createAnalysis(options, cmd) {
|
|
|
8638
8686
|
description: options.description ?? null,
|
|
8639
8687
|
visibility,
|
|
8640
8688
|
introduction: options.introduction ?? null,
|
|
8641
|
-
|
|
8642
|
-
budget: options.budget ?? null,
|
|
8689
|
+
...namedDepth(options),
|
|
8643
8690
|
targets: typedColumns(options.targets),
|
|
8644
8691
|
questions: questionsOf(options.question),
|
|
8645
8692
|
segment: options.segment ?? null
|
|
@@ -8940,7 +8987,7 @@ var COLUMN_LIST_HELP = "one argument each or comma-separated; a name that contai
|
|
|
8940
8987
|
var TARGETS_HELP = `Target column names: repeat the flag or separate them with commas; a name that contains a comma is one flag of its own, or goes in double quotes inside a list`;
|
|
8941
8988
|
function registerAnalyzeCommand(program) {
|
|
8942
8989
|
const analyze = program.command("analyze").description("Run and manage automatic analyses");
|
|
8943
|
-
analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[files...]", "Data file to analyze (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files are combined into one table: files with the same columns are stacked, a file that shares a key adds its columns").option("--name <name>", "Analysis name (asked for, or derived from the filename)").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC (default: PRIVATE)").option("--hours <hours>", `Time budget (hours).
|
|
8990
|
+
analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[files...]", "Data file to analyze (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files are combined into one table: files with the same columns are stacked, a file that shares a key adds its columns").option("--name <name>", "Analysis name (asked for, or derived from the filename)").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC (default: PRIVATE)").option("--hours <hours>", `Time budget (hours). ${STARTING_DEPTH_RULE}`).option("--budget <credits>", `Credit budget. ${STARTING_DEPTH_RULE}`).option("--targets <columns>", `${TARGETS_HELP} (required when not interactive)`, collectColumns).option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction shown at the top of the notebook").option("--preset <id>", "Apply a saved preset as defaults (explicit flags override it)").option("--no-file-column", "With several files: do not add the column that records the file each row came from").option("--keep-duplicates", "With several files: keep rows that occur in more than one file").option("--rows-of <file>", "With several files that can be read two ways: the file in which one row is one observation").action(async (files, options, cmd) => {
|
|
8944
8991
|
try {
|
|
8945
8992
|
if (files.length === 0) {
|
|
8946
8993
|
analyze.help();
|
|
@@ -8986,7 +9033,7 @@ function registerAnalyzeCommand(program) {
|
|
|
8986
9033
|
reportCommandError(error);
|
|
8987
9034
|
}
|
|
8988
9035
|
});
|
|
8989
|
-
analyze.command("create").description("Create an analysis without uploading data or running it").option("--name <name>", "Analysis name").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--hours <hours>",
|
|
9036
|
+
analyze.command("create").description("Create an analysis without uploading data or running it").option("--name <name>", "Analysis name").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--hours <hours>", `Time budget (hours). ${STARTING_DEPTH_RULE}`).option("--budget <credits>", `Credit budget. ${STARTING_DEPTH_RULE}`).option("--targets <columns>", TARGETS_HELP, collectColumns).option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction shown at the top of the notebook").action(async (options, cmd) => {
|
|
8990
9037
|
try {
|
|
8991
9038
|
await createAnalysis(options, cmd);
|
|
8992
9039
|
} catch (error) {
|
|
@@ -10659,7 +10706,7 @@ function registerShellCommand(program) {
|
|
|
10659
10706
|
});
|
|
10660
10707
|
const api = createApiClient();
|
|
10661
10708
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
10662
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
10709
|
+
const { getUpdateNotice } = await import("./update-check-EW6JPLJT.js");
|
|
10663
10710
|
const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
|
|
10664
10711
|
console.log(chalk32.bold("Diafunc shell") + chalk32.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
|
|
10665
10712
|
console.log(chalk32.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
@@ -11709,4 +11756,4 @@ export {
|
|
|
11709
11756
|
PromptCancelled,
|
|
11710
11757
|
createProgram
|
|
11711
11758
|
};
|
|
11712
|
-
//# sourceMappingURL=chunk-
|
|
11759
|
+
//# sourceMappingURL=chunk-IV75CA5V.js.map
|