@enerlence/suntropy-cli 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/suntropy.js +37 -13
- package/dist/bin/suntropy.js.map +1 -1
- package/package.json +1 -1
package/dist/bin/suntropy.js
CHANGED
|
@@ -7,7 +7,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
|
-
import { Command as
|
|
10
|
+
import { Command as Command3 } from "commander";
|
|
11
11
|
|
|
12
12
|
// src/config.ts
|
|
13
13
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
@@ -139,6 +139,15 @@ function createUnauthClient(baseURL) {
|
|
|
139
139
|
headers: { "Content-Type": "application/json" }
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
|
+
function assertFound(data, entity, id) {
|
|
143
|
+
const isEmptyObject = data != null && typeof data === "object" && !Array.isArray(data) && Object.keys(data).length === 0;
|
|
144
|
+
if (data == null || typeof data !== "object" || Array.isArray(data) || isEmptyObject) {
|
|
145
|
+
throw new Error(
|
|
146
|
+
`${entity} not found: ${id}. The backend returned an empty response \u2014 verify the id is correct and belongs to your account and environment (the CLI and the app must point to the same backend).`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return data;
|
|
150
|
+
}
|
|
142
151
|
function handleApiError(err) {
|
|
143
152
|
if (axios.isAxiosError(err)) {
|
|
144
153
|
const ae = err;
|
|
@@ -1797,6 +1806,7 @@ function registerInventoryCommands(program2) {
|
|
|
1797
1806
|
}
|
|
1798
1807
|
|
|
1799
1808
|
// src/commands/studies/builder.ts
|
|
1809
|
+
import { Option } from "commander";
|
|
1800
1810
|
import { readFileSync as readFileSync3, writeFileSync as writeFileSync4, existsSync as existsSync2 } from "fs";
|
|
1801
1811
|
|
|
1802
1812
|
// node_modules/uuid/dist/esm-node/rng.js
|
|
@@ -2183,7 +2193,7 @@ function registerStudyBuilderCommands(studies) {
|
|
|
2183
2193
|
const global = getGlobalOpts7(studies);
|
|
2184
2194
|
const client = createServiceClient("solar", global);
|
|
2185
2195
|
const res = await client.get(`/solar-study/findById/${studyId}`);
|
|
2186
|
-
const study = res.data;
|
|
2196
|
+
const study = assertFound(res.data, "Solar study", studyId);
|
|
2187
2197
|
const { stepsProgress, missing } = evaluateSteps(study);
|
|
2188
2198
|
const progress = study.solarStudyProgress || {};
|
|
2189
2199
|
progress.stepsProgress = stepsProgress;
|
|
@@ -3144,13 +3154,18 @@ Example: suntropy studies set data --file study.json --data '{"referenceId":"REF
|
|
|
3144
3154
|
});
|
|
3145
3155
|
studies.command("comment <studyId>").description(
|
|
3146
3156
|
'Add a comment to an existing study via API.\nExample: suntropy studies comment abc123 --content "Revisado por agente"'
|
|
3147
|
-
).requiredOption("--content <text>", "Comment text").action(async (studyId, opts) => {
|
|
3157
|
+
).requiredOption("--content <text>", "Comment text").addOption(new Option("--as-alexandria").hideHelp()).addOption(new Option("--reply-to-user <userUID>").hideHelp()).addOption(new Option("--reply-to-name <name>").hideHelp()).action(async (studyId, opts) => {
|
|
3148
3158
|
try {
|
|
3149
3159
|
const global = getGlobalOpts7(studies);
|
|
3150
3160
|
const client = createServiceClient("solar", global);
|
|
3151
|
-
const comment = createComment("commented", opts.content
|
|
3161
|
+
const comment = createComment("commented", opts.content, {
|
|
3162
|
+
asAlexandria: Boolean(opts.asAlexandria),
|
|
3163
|
+
replyToUser: opts.replyToUser,
|
|
3164
|
+
replyToName: opts.replyToName
|
|
3165
|
+
});
|
|
3152
3166
|
const res = await client.post(`/solar-study/addSolarStudyComment/${studyId}`, comment);
|
|
3153
|
-
|
|
3167
|
+
const saved = assertFound(res.data, "Solar study", studyId);
|
|
3168
|
+
output(saved, global);
|
|
3154
3169
|
} catch (err) {
|
|
3155
3170
|
outputError(handleApiError(err));
|
|
3156
3171
|
}
|
|
@@ -3271,19 +3286,28 @@ async function fetchPeriodDistribution(study, global) {
|
|
|
3271
3286
|
return null;
|
|
3272
3287
|
}
|
|
3273
3288
|
}
|
|
3274
|
-
function createComment(type, content) {
|
|
3289
|
+
function createComment(type, content, extra) {
|
|
3275
3290
|
const config = loadConfig();
|
|
3276
3291
|
const profile = getActiveProfile(config);
|
|
3277
3292
|
const autoContent = {
|
|
3278
3293
|
created: "Estudio creado via CLI",
|
|
3279
3294
|
modified: "Estudio actualizado via CLI"
|
|
3280
3295
|
};
|
|
3281
|
-
|
|
3282
|
-
|
|
3296
|
+
let body = content || autoContent[type] || "";
|
|
3297
|
+
if (extra?.replyToUser) {
|
|
3298
|
+
const name = extra.replyToName || extra.replyToUser;
|
|
3299
|
+
body = `@[${name}](${extra.replyToUser}) ${body}`.trim();
|
|
3300
|
+
}
|
|
3301
|
+
const comment = {
|
|
3302
|
+
content: body,
|
|
3283
3303
|
type,
|
|
3284
3304
|
creationTimestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3285
|
-
creationUserUID: profile.userUID || "cli-agent"
|
|
3305
|
+
creationUserUID: extra?.asAlexandria ? "alexandria" : profile.userUID || "cli-agent"
|
|
3286
3306
|
};
|
|
3307
|
+
if (extra?.asAlexandria) {
|
|
3308
|
+
comment.aiGenerated = true;
|
|
3309
|
+
}
|
|
3310
|
+
return comment;
|
|
3287
3311
|
}
|
|
3288
3312
|
|
|
3289
3313
|
// src/commands/studies/index.ts
|
|
@@ -3456,7 +3480,7 @@ function registerStudiesCommands(program2) {
|
|
|
3456
3480
|
const global = getGlobalOpts8(studies);
|
|
3457
3481
|
const client = createServiceClient("solar", global);
|
|
3458
3482
|
const res = await client.get(`/solar-study/findById/${studyId}`);
|
|
3459
|
-
const study = res.data;
|
|
3483
|
+
const study = assertFound(res.data, "Solar study", studyId);
|
|
3460
3484
|
const filtered = global.fields ? study : filterStudy(study, opts.expand);
|
|
3461
3485
|
if (global.fields) {
|
|
3462
3486
|
const requested = global.fields.split(",").map((f) => f.trim());
|
|
@@ -3478,7 +3502,7 @@ function registerStudiesCommands(program2) {
|
|
|
3478
3502
|
const global = getGlobalOpts8(studies);
|
|
3479
3503
|
const client = createServiceClient("solar", global);
|
|
3480
3504
|
const res = await client.get(`/solar-study/findById/${studyId}`);
|
|
3481
|
-
const study = res.data;
|
|
3505
|
+
const study = assertFound(res.data, "Solar study", studyId);
|
|
3482
3506
|
let curveData;
|
|
3483
3507
|
switch (curveName) {
|
|
3484
3508
|
case "consumption":
|
|
@@ -4309,9 +4333,9 @@ function registerGeocodeCommands(program2) {
|
|
|
4309
4333
|
}
|
|
4310
4334
|
|
|
4311
4335
|
// src/index.ts
|
|
4312
|
-
var CLI_VERSION = true ? "0.
|
|
4336
|
+
var CLI_VERSION = true ? "0.8.1" : "0.0.0-dev";
|
|
4313
4337
|
function createProgram() {
|
|
4314
|
-
const program2 = new
|
|
4338
|
+
const program2 = new Command3();
|
|
4315
4339
|
program2.name("suntropy").description("Agent-first CLI for Suntropy solar platform. Optimized for programmatic data manipulation and progressive exploration.").version(CLI_VERSION).option("--format <format>", "Output format: json (default), human, csv", "json").option("--fields <fields>", "Comma-separated fields to include in output").option("--server <url>", "Override API server URL").option("--token <jwt>", "Override authentication token").option("--profile <name>", "Use a specific config profile").option("--verbose", "Show HTTP request/response details on stderr").option("--quiet", "Suppress non-data output").option("--save <file>", "Save output to file (also writes to stdout)");
|
|
4316
4340
|
registerAuthCommands(program2);
|
|
4317
4341
|
registerConfigCommands(program2);
|