@answerlayer/cli 0.1.19 → 0.2.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/README.md +31 -1
- package/package.json +1 -1
- package/src/cli.js +229 -0
package/README.md
CHANGED
|
@@ -235,6 +235,29 @@ Useful scopes:
|
|
|
235
235
|
|
|
236
236
|
## Commands
|
|
237
237
|
|
|
238
|
+
### Semantic optimization
|
|
239
|
+
|
|
240
|
+
Launch a durable, eval-driven optimization run without changing the active
|
|
241
|
+
semantic layer:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
answerlayer optimize start \
|
|
245
|
+
--name "Exoplanet semantic optimization" \
|
|
246
|
+
--connection CONNECTION_ID \
|
|
247
|
+
--suite SUITE_ID \
|
|
248
|
+
--model openai.gpt-5.6-terra \
|
|
249
|
+
--mode recommendation
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Inspect and operate the registry with `answerlayer optimize list`,
|
|
253
|
+
`get RUN_ID`, `pause RUN_ID`, `resume RUN_ID`, `stop RUN_ID`, `clone RUN_ID`,
|
|
254
|
+
`approve RUN_ID`, and `reject RUN_ID`. Promotion is a separate, explicit atomic
|
|
255
|
+
compare-and-swap using the frozen hash shown by `get RUN_ID`:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
answerlayer optimize promote RUN_ID --base-hash FROZEN_BASE_SHA256
|
|
259
|
+
```
|
|
260
|
+
|
|
238
261
|
```bash
|
|
239
262
|
answerlayer health
|
|
240
263
|
answerlayer openapi --output openapi.json
|
|
@@ -284,6 +307,13 @@ answerlayer evals runs compare <run-id> --baseline <baseline-run-id>
|
|
|
284
307
|
answerlayer evals runs analyze <run-id> --json
|
|
285
308
|
answerlayer generation start --connection <connection-id> --component-type metrics --eval-suite <suite-id> --eval-case <authoring-case-id> --prompt "Improve these concepts"
|
|
286
309
|
|
|
310
|
+
answerlayer ontologies create --domain-key exoplanet-archive --name "Exoplanet Archive"
|
|
311
|
+
answerlayer ontologies version create <ontology-id> --file ./ontology.tff
|
|
312
|
+
answerlayer ontologies version validate <version-id>
|
|
313
|
+
answerlayer ontologies version review <version-id> # admin-only
|
|
314
|
+
answerlayer ontologies version freeze <version-id> # admin-only
|
|
315
|
+
answerlayer ontologies version export <version-id> --output ./ontology.tff
|
|
316
|
+
|
|
287
317
|
answerlayer dashboards create --title "Executive overview" --visibility org
|
|
288
318
|
answerlayer tiles create --title "Revenue" --source-type saved_query --source <saved-query-id>
|
|
289
319
|
answerlayer dashboards attach-tile <dashboard-id> --tile <tile-id> --x 0 --y 0 --w 6 --h 4
|
|
@@ -307,7 +337,7 @@ answerlayer branding update --data-file ./branding.json
|
|
|
307
337
|
## Command groups
|
|
308
338
|
|
|
309
339
|
- Core: `api-keys`, `connections`, `metadata`, `query`, `query-results`
|
|
310
|
-
- Data products: `saved-queries`, `semantic`, `inquiry`, `evals`, `generation`, `tiles`, `dashboards`
|
|
340
|
+
- Data products: `saved-queries`, `semantic`, `inquiry`, `evals`, `ontologies`, `generation`, `tiles`, `dashboards`
|
|
311
341
|
- Supporting resources: `documents`, `branding`, `uploads`, `chains`, `users`, `org`, `roles`, `billing`, `stats`
|
|
312
342
|
|
|
313
343
|
## Development
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -56,6 +56,10 @@ export async function main(argv, io) {
|
|
|
56
56
|
if (group === "semantic") return handleSemantic(client, command, positionals, parsed, io);
|
|
57
57
|
if (group === "inquiry") return handleInquiry(client, command, positionals, parsed, io);
|
|
58
58
|
if (group === "evals" || group === "evaluations") return handleEvals(client, command, positionals, parsed, io);
|
|
59
|
+
if (group === "optimize" || group === "optimization" || group === "semantic-optimization") {
|
|
60
|
+
return handleOptimization(client, command, positionals, parsed, io);
|
|
61
|
+
}
|
|
62
|
+
if (group === "ontologies" || group === "ontology") return handleOntologies(client, command, positionals, parsed, io);
|
|
59
63
|
if (group === "generation") return handleGeneration(client, command, positionals, parsed, io);
|
|
60
64
|
if (group === "tiles") return handleTiles(client, command, positionals, parsed, io);
|
|
61
65
|
if (group === "dashboards") return handleDashboards(client, command, positionals, parsed, io);
|
|
@@ -736,6 +740,178 @@ async function handleEvals(client, resource, positionals, parsed, io) {
|
|
|
736
740
|
throw usage(`Expected evals resource: suites, cases, or runs`);
|
|
737
741
|
}
|
|
738
742
|
|
|
743
|
+
async function handleOptimization(client, command, positionals, parsed, io) {
|
|
744
|
+
const base = "/api/v1/semantic-optimization/runs";
|
|
745
|
+
if (command === "list" || !command) {
|
|
746
|
+
return requestAndPrint(client, "GET", base, parsed, io, {
|
|
747
|
+
query: { execution_status: firstValue(parsed.flags.status) },
|
|
748
|
+
table: [
|
|
749
|
+
{ key: "id", label: "ID" },
|
|
750
|
+
{ key: "name", label: "Name" },
|
|
751
|
+
{ key: "execution_status", label: "Status" },
|
|
752
|
+
{ key: "workflow_phase", label: "Phase" },
|
|
753
|
+
{ key: "mode", label: "Mode" },
|
|
754
|
+
{ key: "case_count", label: "Cases" },
|
|
755
|
+
{ key: "current_iteration", label: "Iteration" },
|
|
756
|
+
{ key: "max_iterations", label: "Max" },
|
|
757
|
+
{ key: "best_metric_movement", label: "Best Δ" },
|
|
758
|
+
],
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
if (command === "start" || command === "create") {
|
|
763
|
+
const sharedModel = firstValue(parsed.flags.model);
|
|
764
|
+
const selectedCaseIds = optionalCsvOrRepeated(parsed.flags.case);
|
|
765
|
+
const categories = optionalDistinctRepeated(parsed.flags.category);
|
|
766
|
+
const tags = optionalDistinctRepeated(parsed.flags.tag);
|
|
767
|
+
const selected = Boolean(selectedCaseIds?.length || categories?.length || tags?.length);
|
|
768
|
+
const payload = await readData(parsed.flags, io, {
|
|
769
|
+
name: firstValue(parsed.flags.name),
|
|
770
|
+
connection_id: firstValue(parsed.flags.connection),
|
|
771
|
+
eval_suite_id: firstValue(parsed.flags.suite),
|
|
772
|
+
cases: {
|
|
773
|
+
mode: selected ? "selected" : "all_active_authoring",
|
|
774
|
+
case_ids: selectedCaseIds || [],
|
|
775
|
+
categories: categories || [],
|
|
776
|
+
tags: tags || [],
|
|
777
|
+
},
|
|
778
|
+
eligible_component_types: optionalCsvOrRepeated(parsed.flags.component) || [
|
|
779
|
+
"entities", "relationships", "measures", "metrics", "dimensions", "filters",
|
|
780
|
+
],
|
|
781
|
+
proposal_strategy: firstValue(parsed.flags.proposalStrategy) || "coherent_patch",
|
|
782
|
+
search_strategy: "greedy_constrained_hill_climbing",
|
|
783
|
+
mode: firstValue(parsed.flags.mode) || "recommendation",
|
|
784
|
+
review_policy: firstValue(parsed.flags.reviewPolicy),
|
|
785
|
+
promotion_policy: firstValue(parsed.flags.promotionPolicy) || "manual",
|
|
786
|
+
models: {
|
|
787
|
+
eval_execution: firstValue(parsed.flags.evalModel) || sharedModel,
|
|
788
|
+
proposal: firstValue(parsed.flags.proposalModel) || sharedModel,
|
|
789
|
+
analysis: "deterministic",
|
|
790
|
+
validation: "deterministic",
|
|
791
|
+
repair: "disabled",
|
|
792
|
+
},
|
|
793
|
+
budget: {
|
|
794
|
+
max_iterations: numberFlag(parsed.flags.maxIterations, 3),
|
|
795
|
+
max_proposals: numberFlag(parsed.flags.maxProposals, 10),
|
|
796
|
+
max_input_tokens: numberFlag(parsed.flags.maxInputTokens, 250000),
|
|
797
|
+
max_output_tokens: numberFlag(parsed.flags.maxOutputTokens, 50000),
|
|
798
|
+
max_sql_queries: numberFlag(parsed.flags.maxSqlQueries, 500),
|
|
799
|
+
max_duration_seconds: numberFlag(parsed.flags.maxDuration, 7200),
|
|
800
|
+
},
|
|
801
|
+
objectives: {
|
|
802
|
+
minimum_score_improvement: numberFlag(parsed.flags.minImprovement, 0.5),
|
|
803
|
+
maximum_regressions: numberFlag(parsed.flags.maxRegressions, 0),
|
|
804
|
+
target_pass_rate: numberFlag(parsed.flags.targetPassRate, 100),
|
|
805
|
+
quality_weight: 1,
|
|
806
|
+
efficiency_weight: 0.25,
|
|
807
|
+
simplicity_weight: 0.25,
|
|
808
|
+
},
|
|
809
|
+
});
|
|
810
|
+
requirePayloadValue(payload, "name", "optimize start requires --name");
|
|
811
|
+
requirePayloadValue(payload, "connection_id", "optimize start requires --connection");
|
|
812
|
+
requirePayloadValue(payload, "eval_suite_id", "optimize start requires --suite");
|
|
813
|
+
const requiredModels = ["eval_execution", "proposal"];
|
|
814
|
+
if (requiredModels.some((key) => typeof payload.models?.[key] !== "string" || !payload.models[key].trim())) {
|
|
815
|
+
throw usage("optimize start requires --model or both --eval-model and --proposal-model");
|
|
816
|
+
}
|
|
817
|
+
return requestAndPrint(client, "POST", base, parsed, io, { body: payload });
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const runId = requirePositional(positionals, 0, "semantic optimization run id");
|
|
821
|
+
if (command === "get" || command === "inspect") {
|
|
822
|
+
return requestAndPrint(client, "GET", `${base}/${encodeURIComponent(runId)}`, parsed, io);
|
|
823
|
+
}
|
|
824
|
+
if (["pause", "resume", "stop"].includes(command)) {
|
|
825
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/${command}`, parsed, io, {
|
|
826
|
+
body: { reason: firstValue(parsed.flags.reason) },
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
if (command === "promote") {
|
|
830
|
+
const expectedActiveSha256 = firstValue(parsed.flags.baseHash);
|
|
831
|
+
if (!expectedActiveSha256) {
|
|
832
|
+
throw usage("optimize promote requires --base-hash from the run's frozen manifest");
|
|
833
|
+
}
|
|
834
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/promote`, parsed, io, {
|
|
835
|
+
body: {
|
|
836
|
+
reason: firstValue(parsed.flags.reason),
|
|
837
|
+
expected_active_sha256: expectedActiveSha256,
|
|
838
|
+
},
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
if (command === "clone") {
|
|
842
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/clone`, parsed, io);
|
|
843
|
+
}
|
|
844
|
+
if (command === "approve" || command === "reject") {
|
|
845
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/decision`, parsed, io, {
|
|
846
|
+
body: { decision: command, reason: firstValue(parsed.flags.reason) },
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
throw usage(`Unknown optimize command: ${command}`);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
async function handleOntologies(client, command, positionals, parsed, io) {
|
|
853
|
+
const base = "/api/v1/ontologies";
|
|
854
|
+
if (command === "list" || !command) {
|
|
855
|
+
return requestAndPrint(client, "GET", base, parsed, io, {
|
|
856
|
+
table: [
|
|
857
|
+
{ key: "id", label: "ID" },
|
|
858
|
+
{ key: "domain_key", label: "Domain" },
|
|
859
|
+
{ key: "name", label: "Name" },
|
|
860
|
+
{ key: "version_count", label: "Versions" },
|
|
861
|
+
{ key: "latest_version.status", label: "Latest" },
|
|
862
|
+
{ key: "latest_version.validation_status", label: "Validation" },
|
|
863
|
+
],
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
if (command === "create") {
|
|
868
|
+
const payload = await readData(parsed.flags, io, {
|
|
869
|
+
domain_key: firstValue(parsed.flags.domainKey),
|
|
870
|
+
name: firstValue(parsed.flags.name),
|
|
871
|
+
description: firstValue(parsed.flags.description),
|
|
872
|
+
});
|
|
873
|
+
requirePayloadValue(payload, "domain_key", "ontologies create requires --domain-key");
|
|
874
|
+
requirePayloadValue(payload, "name", "ontologies create requires --name");
|
|
875
|
+
return requestAndPrint(client, "POST", base, parsed, io, { body: payload });
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
if (command === "get") {
|
|
879
|
+
const ontologyId = requirePositional(positionals, 0, "ontology id");
|
|
880
|
+
return requestAndPrint(client, "GET", `${base}/${encodeURIComponent(ontologyId)}`, parsed, io);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
if (command === "validate") {
|
|
884
|
+
const sourceText = await readTff(parsed.flags, io);
|
|
885
|
+
return requestAndPrint(client, "POST", `${base}/validate`, parsed, io, {
|
|
886
|
+
body: { source_text: sourceText },
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
if (command === "version" || command === "versions") {
|
|
891
|
+
const [action, id] = positionals;
|
|
892
|
+
if (action === "create") {
|
|
893
|
+
const ontologyId = requirePositional(positionals, 1, "ontology id");
|
|
894
|
+
const sourceText = await readTff(parsed.flags, io);
|
|
895
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(ontologyId)}/versions`, parsed, io, {
|
|
896
|
+
body: {
|
|
897
|
+
source_text: sourceText,
|
|
898
|
+
predecessor_version_id: firstValue(parsed.flags.predecessor),
|
|
899
|
+
},
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
const versionId = id || requirePositional(positionals, 1, "ontology version id");
|
|
903
|
+
if (["validate", "review", "freeze"].includes(action)) {
|
|
904
|
+
return requestAndPrint(client, "POST", `${base}/versions/${encodeURIComponent(versionId)}/${action}`, parsed, io);
|
|
905
|
+
}
|
|
906
|
+
if (action === "export") {
|
|
907
|
+
return requestAndPrint(client, "GET", `${base}/versions/${encodeURIComponent(versionId)}/source`, parsed, io, { rawDefault: true });
|
|
908
|
+
}
|
|
909
|
+
throw usage("Expected ontologies version create|validate|review|freeze|export");
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
throw usage(`Unknown ontologies command: ${command}`);
|
|
913
|
+
}
|
|
914
|
+
|
|
739
915
|
async function handleGeneration(client, command, positionals, parsed, io) {
|
|
740
916
|
const base = "/api/v1/semantic/jobs";
|
|
741
917
|
if (command === "start" || command === "create") {
|
|
@@ -1240,6 +1416,18 @@ async function readSql(flags, positionals, io) {
|
|
|
1240
1416
|
throw usage("SQL is required. Pass --sql, --file, a positional SQL string, or stdin.");
|
|
1241
1417
|
}
|
|
1242
1418
|
|
|
1419
|
+
async function readTff(flags, io) {
|
|
1420
|
+
const inline = firstValue(flags.tff);
|
|
1421
|
+
const file = firstValue(flags.file);
|
|
1422
|
+
if (inline) return inline;
|
|
1423
|
+
if (file) return fs.readFileSync(file, "utf8");
|
|
1424
|
+
if (!io.stdin.isTTY) {
|
|
1425
|
+
const source = await readAll(io.stdin);
|
|
1426
|
+
if (source.trim()) return source;
|
|
1427
|
+
}
|
|
1428
|
+
throw usage("TFF0 source is required. Pass --file, --tff, or stdin.");
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1243
1431
|
async function optionalSql(flags, positionals, io) {
|
|
1244
1432
|
if (firstValue(flags.sql) || firstValue(flags.file) || positionals.length > 0) {
|
|
1245
1433
|
return readSql(flags, positionals, io);
|
|
@@ -1429,6 +1617,9 @@ function normalizeFlagName(rawName) {
|
|
|
1429
1617
|
"--expression": "expression",
|
|
1430
1618
|
"--source-type": "sourceType",
|
|
1431
1619
|
"--source": "source",
|
|
1620
|
+
"--domain-key": "domainKey",
|
|
1621
|
+
"--predecessor": "predecessor",
|
|
1622
|
+
"--tff": "tff",
|
|
1432
1623
|
"--visualization": "visualization",
|
|
1433
1624
|
"--dashboard": "dashboard",
|
|
1434
1625
|
"--tile": "tile",
|
|
@@ -1446,6 +1637,24 @@ function normalizeFlagName(rawName) {
|
|
|
1446
1637
|
"--h": "h",
|
|
1447
1638
|
"--prompt": "prompt",
|
|
1448
1639
|
"--model": "model",
|
|
1640
|
+
"--mode": "mode",
|
|
1641
|
+
"--reason": "reason",
|
|
1642
|
+
"--component": "component",
|
|
1643
|
+
"--proposal-strategy": "proposalStrategy",
|
|
1644
|
+
"--review-policy": "reviewPolicy",
|
|
1645
|
+
"--promotion-policy": "promotionPolicy",
|
|
1646
|
+
"--eval-model": "evalModel",
|
|
1647
|
+
"--proposal-model": "proposalModel",
|
|
1648
|
+
"--base-hash": "baseHash",
|
|
1649
|
+
"--max-iterations": "maxIterations",
|
|
1650
|
+
"--max-proposals": "maxProposals",
|
|
1651
|
+
"--max-input-tokens": "maxInputTokens",
|
|
1652
|
+
"--max-output-tokens": "maxOutputTokens",
|
|
1653
|
+
"--max-sql-queries": "maxSqlQueries",
|
|
1654
|
+
"--max-duration": "maxDuration",
|
|
1655
|
+
"--min-improvement": "minImprovement",
|
|
1656
|
+
"--max-regressions": "maxRegressions",
|
|
1657
|
+
"--target-pass-rate": "targetPassRate",
|
|
1449
1658
|
"--component-type": "componentType",
|
|
1450
1659
|
"--use-semantic-layer": "useSemanticLayer",
|
|
1451
1660
|
"--no-semantic-layer": "noSemanticLayer",
|
|
@@ -1564,6 +1773,13 @@ function requirePayloadValue(payload, key, message) {
|
|
|
1564
1773
|
if (!payload[key]) throw usage(message);
|
|
1565
1774
|
}
|
|
1566
1775
|
|
|
1776
|
+
function numberFlag(value, fallback) {
|
|
1777
|
+
if (value === undefined) return fallback;
|
|
1778
|
+
const parsed = Number(firstValue(value));
|
|
1779
|
+
if (!Number.isFinite(parsed)) throw usage(`Expected a numeric value, received ${firstValue(value)}`);
|
|
1780
|
+
return parsed;
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1567
1783
|
function requireEvalBatchSuites(suiteIds) {
|
|
1568
1784
|
if (!Array.isArray(suiteIds) || suiteIds.length < 2 || suiteIds.length > 20) {
|
|
1569
1785
|
throw usage("evals runs create-batch requires 2 to 20 suite ids");
|
|
@@ -1672,6 +1888,7 @@ Data products:
|
|
|
1672
1888
|
answerlayer evals suites list|create|get|update|delete
|
|
1673
1889
|
answerlayer evals cases create|update|reveal|delete
|
|
1674
1890
|
answerlayer evals runs list|create|create-batch|get|update|cancel|compare|analyze
|
|
1891
|
+
answerlayer optimize list|start|get|pause|resume|stop|clone|approve|reject|promote
|
|
1675
1892
|
case create/update accept --category <name>,
|
|
1676
1893
|
--partition <authoring|holdout|adversarial>, and
|
|
1677
1894
|
--oracle-sources '<JSON array>'
|
|
@@ -1682,7 +1899,19 @@ Data products:
|
|
|
1682
1899
|
create-batch accepts 2 to 20 suite ids as positionals or repeatable
|
|
1683
1900
|
--suite values, plus shared --label, --model, --concurrency <1-8>,
|
|
1684
1901
|
and --use-semantic-layer or --no-semantic-layer
|
|
1902
|
+
Optimization:
|
|
1903
|
+
answerlayer optimize start --name NAME --connection ID --suite ID --model MODEL
|
|
1904
|
+
[--mode recommendation|supervised|fully_automatic]
|
|
1905
|
+
[--component entities,relationships,measures,metrics,dimensions,filters]
|
|
1906
|
+
[--review-policy every_sweep|exceptions_only|end_of_run]
|
|
1907
|
+
[--promotion-policy manual|automatic] [--max-iterations N]
|
|
1908
|
+
answerlayer optimize promote RUN_ID --base-hash SHA256
|
|
1685
1909
|
update accepts --label <name>
|
|
1910
|
+
answerlayer ontologies list|create|get|validate
|
|
1911
|
+
validate accepts --file <ontology.tff>, --tff <source>, or stdin
|
|
1912
|
+
answerlayer ontologies version create|validate|review|freeze|export
|
|
1913
|
+
version create accepts an ontology id, --file <ontology.tff>, --tff <source>,
|
|
1914
|
+
or stdin, plus optional --predecessor <version-id>
|
|
1686
1915
|
answerlayer generation start|list|get|status|stream|cancel|questions|guidance|delete
|
|
1687
1916
|
start accepts --connection, --component-type, --prompt, --model,
|
|
1688
1917
|
--eval-suite, and repeatable or comma-separated --eval-case values;
|