@answerlayer/cli 0.2.3 → 0.2.5

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 CHANGED
@@ -83,6 +83,46 @@ export ANSWERLAYER_BASE_URL=https://answerlayer.your-company.com # optional ove
83
83
 
84
84
  The CLI sends API keys using the `X-API-Key` header.
85
85
 
86
+ ## Operate API pipelines
87
+
88
+ API pipeline authoring and lifecycle operations are CLI-first. The AnswerLayer
89
+ web application is a read-only observability surface for pipeline health, run
90
+ history, provenance, and failures.
91
+
92
+ Create a pipeline and upload an immutable package revision:
93
+
94
+ ```bash
95
+ answerlayer pipelines create --name "REMPLAN Census" --json
96
+ answerlayer pipelines revisions push <pipeline-id> \
97
+ --package ./dist/remplan-census.zip \
98
+ --config-file ./pipeline-config.json \
99
+ --json
100
+ ```
101
+
102
+ Validate and promote the returned revision ID. `--wait` polls the exact run to
103
+ a terminal state and exits unsuccessfully when validation fails or is
104
+ cancelled:
105
+
106
+ ```bash
107
+ answerlayer pipelines revisions validate <pipeline-id> <revision-id> --wait --json
108
+ answerlayer pipelines revisions promote <pipeline-id> <revision-id> --json
109
+ ```
110
+
111
+ Run and operate the promoted revision:
112
+
113
+ ```bash
114
+ answerlayer pipelines runs start <pipeline-id> --wait --json
115
+ answerlayer pipelines runs get <pipeline-id> <run-id> --json
116
+ answerlayer pipelines runs retry <pipeline-id> <run-id> --wait --json
117
+ answerlayer pipelines runs cancel <pipeline-id> <run-id> --json
118
+ answerlayer pipelines archive <pipeline-id> --json
119
+ ```
120
+
121
+ Use `--include-archived` with `pipelines list`. Package ZIPs are built from the
122
+ customer-owned package repository; credentials and CA material must not be
123
+ included in the ZIP or revision configuration. They remain in the install's
124
+ managed secret interfaces.
125
+
86
126
  ## Run locally with an agent
87
127
 
88
128
  The package includes an `answerlayer` agent skill for evaluating AnswerLayer
@@ -249,8 +289,10 @@ answerlayer optimize start \
249
289
  --mode recommendation
250
290
  ```
251
291
 
252
- By default the proposal model also reviews bounded failed-case traces during
253
- failure analysis. Use `--analysis-model MODEL` to select a dedicated reviewer.
292
+ The proposal model runs one bounded optimization session that reviews failed-case
293
+ traces, edits a detached candidate, validates it, and repairs diagnostics before
294
+ submission. Tune its bounds with `--max-agent-turns`,
295
+ `--max-validation-attempts`, and `--max-targeted-evals`.
254
296
 
255
297
  Inspect and operate the registry with `answerlayer optimize list`,
256
298
  `get RUN_ID`, `pause RUN_ID`, `resume RUN_ID`, `stop RUN_ID`, `clone RUN_ID`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@answerlayer/cli",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Open-source command line client for the AnswerLayer API.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: answerlayer
3
- description: Query databases in natural language with AnswerLayer. Use when the user wants to set up or configure AnswerLayer, connect to their data, ask analytical or business questions about a database (revenue, users, counts, "top N", trends, metrics), run SQL through AnswerLayer, or manage AnswerLayer connections, saved queries, the semantic layer, or dashboards.
3
+ description: Query databases and operate customer-owned API pipelines with AnswerLayer. Use when the user wants to set up or configure AnswerLayer, connect to their data, ask analytical or business questions about a database, run SQL, or manage AnswerLayer API pipelines, connections, saved queries, the semantic layer, or dashboards.
4
4
  ---
5
5
 
6
6
  # AnswerLayer
@@ -180,6 +180,9 @@ to see exact flags before using one:
180
180
  - `dashboards`, `tiles` — build and read dashboards
181
181
  - `documents` — upload business-context docs and link them to connections
182
182
  - `connections` — create / test / inspect schema
183
+ - `pipelines` — upload immutable package revisions, validate and promote them,
184
+ run/retry/cancel exact revisions, inspect runs, and archive pipelines; use
185
+ `--wait --json` for automation and never put credentials in package config
183
186
  - `metadata`, `api-keys`, `users`, `org`, `billing`, `stats`
184
187
 
185
188
  ## Conventions
package/src/cli.js CHANGED
@@ -48,6 +48,7 @@ export async function main(argv, io) {
48
48
  if (group === "openapi") return handleOpenApi(client, parsed, io);
49
49
  if (group === "auth") return handleAuth(client, command, parsed, io);
50
50
  if (group === "api-keys" || group === "keys") return handleApiKeys(client, command, positionals, parsed, io);
51
+ if (group === "pipelines" || group === "pipeline") return handlePipelines(client, command, positionals, parsed, io);
51
52
  if (group === "connections") return handleConnections(client, command, positionals, parsed, io);
52
53
  if (group === "metadata") return handleMetadata(client, command, positionals, parsed, io);
53
54
  if (group === "query") return handleQuery(client, command, positionals, parsed, io);
@@ -185,6 +186,127 @@ async function handleApiKeys(client, command, positionals, parsed, io) {
185
186
  throw usage(`Unknown api-keys command: ${command}`);
186
187
  }
187
188
 
189
+ async function handlePipelines(client, command, positionals, parsed, io) {
190
+ const base = "/api/v1/api-pipelines";
191
+
192
+ if (command === "list" || !command) {
193
+ return requestAndPrint(client, "GET", base, parsed, io, {
194
+ query: { include_archived: Boolean(parsed.flags.includeArchived) },
195
+ table: [
196
+ { key: "id", label: "ID" },
197
+ { key: "name", label: "Name" },
198
+ { key: "status", label: "Status" },
199
+ { key: "active_revision_id", label: "Active revision" },
200
+ { key: "updated_at", label: "Updated" },
201
+ ],
202
+ });
203
+ }
204
+
205
+ if (command === "create") {
206
+ const payload = await readData(parsed.flags, io, {
207
+ name: firstValue(parsed.flags.name),
208
+ description: firstValue(parsed.flags.description),
209
+ });
210
+ requirePayloadValue(payload, "name", "pipelines create requires --name");
211
+ return requestAndPrint(client, "POST", base, parsed, io, { body: payload });
212
+ }
213
+
214
+ if (command === "archive") {
215
+ const pipelineId = requirePositional(positionals, 0, "pipeline id");
216
+ return requestAndPrint(
217
+ client,
218
+ "DELETE",
219
+ `${base}/${encodeURIComponent(pipelineId)}`,
220
+ parsed,
221
+ io,
222
+ );
223
+ }
224
+
225
+ if (command === "revisions") {
226
+ return handlePipelineRevisions(client, base, positionals, parsed, io);
227
+ }
228
+
229
+ if (command === "runs") {
230
+ return handlePipelineRuns(client, base, positionals, parsed, io);
231
+ }
232
+
233
+ throw usage(`Unknown pipelines command: ${command}`);
234
+ }
235
+
236
+ async function handlePipelineRevisions(client, base, positionals, parsed, io) {
237
+ const action = requirePositional(positionals, 0, "pipeline revisions action");
238
+ const pipelineId = requirePositional(positionals, 1, "pipeline id");
239
+ const pipelinePath = `${base}/${encodeURIComponent(pipelineId)}`;
240
+
241
+ if (action === "push" || action === "upload") {
242
+ const packagePath = firstValue(parsed.flags.package)
243
+ || requirePositional(positionals, 2, "pipeline package ZIP");
244
+ const config = readPipelineRevisionConfig(parsed.flags);
245
+ return requestAndPrint(client, "POST", `${pipelinePath}/revisions`, parsed, io, {
246
+ body: multipartFields({
247
+ files: { package: packagePath },
248
+ fields: { config_json: JSON.stringify(config) },
249
+ }),
250
+ });
251
+ }
252
+
253
+ const revisionId = requirePositional(positionals, 2, "pipeline revision id");
254
+ const revisionPath = `${pipelinePath}/revisions/${encodeURIComponent(revisionId)}`;
255
+ if (action === "validate") {
256
+ return requestWaitAndPrint(
257
+ client,
258
+ "POST",
259
+ `${revisionPath}/validate`,
260
+ parsed,
261
+ io,
262
+ pipelinePath,
263
+ );
264
+ }
265
+ if (action === "promote") {
266
+ return requestAndPrint(client, "POST", `${revisionPath}/promote`, parsed, io);
267
+ }
268
+
269
+ throw usage(`Unknown pipelines revisions command: ${action}`);
270
+ }
271
+
272
+ async function handlePipelineRuns(client, base, positionals, parsed, io) {
273
+ const action = requirePositional(positionals, 0, "pipeline runs action");
274
+ const pipelineId = requirePositional(positionals, 1, "pipeline id");
275
+ const pipelinePath = `${base}/${encodeURIComponent(pipelineId)}`;
276
+
277
+ if (action === "start" || action === "run") {
278
+ return requestWaitAndPrint(
279
+ client,
280
+ "POST",
281
+ `${pipelinePath}/runs`,
282
+ parsed,
283
+ io,
284
+ pipelinePath,
285
+ );
286
+ }
287
+
288
+ const runId = requirePositional(positionals, 2, "pipeline run id");
289
+ const runPath = `${pipelinePath}/runs/${encodeURIComponent(runId)}`;
290
+ if (action === "get") {
291
+ return requestAndPrint(client, "GET", runPath, parsed, io);
292
+ }
293
+ if (action === "retry") {
294
+ return requestWaitAndPrint(
295
+ client,
296
+ "POST",
297
+ `${runPath}/retry`,
298
+ parsed,
299
+ io,
300
+ pipelinePath,
301
+ );
302
+ }
303
+ if (action === "cancel") {
304
+ return requestAndPrint(client, "POST", `${runPath}/cancel`, parsed, io);
305
+ }
306
+
307
+ throw usage(`Unknown pipelines runs command: ${action}`);
308
+ }
309
+
188
310
  async function handleConnections(client, command, positionals, parsed, io) {
189
311
  if (command === "supported" || command === "supported-types") {
190
312
  return requestAndPrint(client, "GET", "/api/v1/connections/supported_types", parsed, io, {
@@ -759,6 +881,9 @@ async function handleOptimization(client, command, positionals, parsed, io) {
759
881
  }
760
882
 
761
883
  if (command === "start" || command === "create") {
884
+ if (parsed.flags.analysisModel !== undefined) {
885
+ throw usage("--analysis-model was removed; use --proposal-model for the coherent optimization agent");
886
+ }
762
887
  const sharedModel = firstValue(parsed.flags.model);
763
888
  const selectedCaseIds = optionalCsvOrRepeated(parsed.flags.case);
764
889
  const categories = optionalDistinctRepeated(parsed.flags.category);
@@ -785,11 +910,7 @@ async function handleOptimization(client, command, positionals, parsed, io) {
785
910
  models: {
786
911
  eval_execution: firstValue(parsed.flags.evalModel) || sharedModel,
787
912
  proposal: firstValue(parsed.flags.proposalModel) || sharedModel,
788
- analysis: firstValue(parsed.flags.analysisModel)
789
- || firstValue(parsed.flags.proposalModel)
790
- || sharedModel,
791
913
  validation: "deterministic",
792
- repair: "disabled",
793
914
  },
794
915
  budget: {
795
916
  max_iterations: numberFlag(parsed.flags.maxIterations, 3),
@@ -798,6 +919,15 @@ async function handleOptimization(client, command, positionals, parsed, io) {
798
919
  max_output_tokens: numberFlag(parsed.flags.maxOutputTokens, 50000),
799
920
  max_sql_queries: numberFlag(parsed.flags.maxSqlQueries, 500),
800
921
  max_duration_seconds: numberFlag(parsed.flags.maxDuration, 7200),
922
+ max_agent_turns: parseBoundedInteger(
923
+ firstValue(parsed.flags.maxAgentTurns), "max-agent-turns", 1, 200,
924
+ ) ?? 50,
925
+ max_validation_attempts: parseBoundedInteger(
926
+ firstValue(parsed.flags.maxValidationAttempts), "max-validation-attempts", 1, 100,
927
+ ) ?? 10,
928
+ max_targeted_evals: parseBoundedInteger(
929
+ firstValue(parsed.flags.maxTargetedEvals), "max-targeted-evals", 0, 25,
930
+ ) ?? 3,
801
931
  },
802
932
  objectives: {
803
933
  minimum_score_improvement: numberFlag(parsed.flags.minImprovement, 0.5),
@@ -1453,13 +1583,36 @@ async function readData(flags, io, defaults = {}) {
1453
1583
  return dropUndefined({ ...defaults, ...data });
1454
1584
  }
1455
1585
 
1586
+ function readPipelineRevisionConfig(flags) {
1587
+ const file = firstValue(flags.configFile);
1588
+ const inline = firstValue(flags.config);
1589
+ if (file && inline) {
1590
+ throw usage("pipelines revisions push accepts either --config-file or --config, not both");
1591
+ }
1592
+ const value = file
1593
+ ? parseJsonFlag(fs.readFileSync(file, "utf8"), "config-file")
1594
+ : inline
1595
+ ? parseJsonFlag(inline, "config")
1596
+ : {};
1597
+ if (!value || Array.isArray(value) || typeof value !== "object") {
1598
+ throw usage("pipeline revision config must be a JSON object");
1599
+ }
1600
+ return value;
1601
+ }
1602
+
1456
1603
  function multipart({ file, fields = {} }) {
1604
+ return multipartFields({ files: { file }, fields });
1605
+ }
1606
+
1607
+ function multipartFields({ files = {}, fields = {} }) {
1457
1608
  const form = new FormData();
1458
1609
  for (const [key, value] of Object.entries(dropUndefined(fields))) {
1459
1610
  form.append(key, String(value));
1460
1611
  }
1461
- const buffer = fs.readFileSync(file);
1462
- form.append("file", new Blob([buffer]), path.basename(file));
1612
+ for (const [key, file] of Object.entries(files)) {
1613
+ const buffer = fs.readFileSync(file);
1614
+ form.append(key, new Blob([buffer]), path.basename(file));
1615
+ }
1463
1616
  return form;
1464
1617
  }
1465
1618
 
@@ -1490,6 +1643,70 @@ async function requestAndPrint(client, method, pathName, parsed, io, options = {
1490
1643
  headers: options.headers,
1491
1644
  });
1492
1645
 
1646
+ return printResult(result, parsed, io, options);
1647
+ }
1648
+
1649
+ async function requestWaitAndPrint(
1650
+ client,
1651
+ method,
1652
+ pathName,
1653
+ parsed,
1654
+ io,
1655
+ pipelinePath,
1656
+ ) {
1657
+ let result = await client.rawRequest(method, pathName);
1658
+ if (parsed.flags.wait) {
1659
+ result = await waitForPipelineRun(client, result, parsed.flags, io, pipelinePath);
1660
+ }
1661
+ printResult(result, parsed, io);
1662
+ if (parsed.flags.wait && ["failed", "cancelled"].includes(result.data?.status)) {
1663
+ const error = new Error(
1664
+ result.data.error
1665
+ ? `Pipeline run ${result.data.id} ${result.data.status}: ${result.data.error}`
1666
+ : `Pipeline run ${result.data.id} ${result.data.status}`,
1667
+ );
1668
+ error.exitCode = 1;
1669
+ throw error;
1670
+ }
1671
+ }
1672
+
1673
+ async function waitForPipelineRun(client, initial, flags, io, pipelinePath) {
1674
+ const runId = initial.data?.id;
1675
+ if (!runId) throw new Error("Pipeline run response did not include an id");
1676
+ const terminal = new Set(["succeeded", "failed", "cancelled"]);
1677
+ const timeoutSeconds = parsePositiveNumber(
1678
+ firstValue(flags.waitTimeout),
1679
+ "wait-timeout",
1680
+ 600,
1681
+ );
1682
+ const pollSeconds = parsePositiveNumber(
1683
+ firstValue(flags.pollInterval),
1684
+ "poll-interval",
1685
+ 2,
1686
+ { allowZero: true },
1687
+ );
1688
+ const now = io.now || (() => Date.now());
1689
+ const sleep = io.sleep || (milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds)));
1690
+ const deadline = now() + timeoutSeconds * 1000;
1691
+ let result = initial;
1692
+
1693
+ write(io.stderr, `Waiting for pipeline run ${runId}...\n`);
1694
+ while (!terminal.has(result.data?.status)) {
1695
+ if (now() >= deadline) {
1696
+ const error = new Error(`Timed out waiting for pipeline run ${runId}`);
1697
+ error.exitCode = 1;
1698
+ throw error;
1699
+ }
1700
+ await sleep(pollSeconds * 1000);
1701
+ result = await client.rawRequest(
1702
+ "GET",
1703
+ `${pipelinePath}/runs/${encodeURIComponent(runId)}`,
1704
+ );
1705
+ }
1706
+ return result;
1707
+ }
1708
+
1709
+ function printResult(result, parsed, io, options = {}) {
1493
1710
  const output = firstValue(parsed.flags.output);
1494
1711
  if (output) {
1495
1712
  fs.writeFileSync(output, result.buffer);
@@ -1599,6 +1816,12 @@ function normalizeFlagName(rawName) {
1599
1816
  "--type": "type",
1600
1817
  "--db-type": "dbType",
1601
1818
  "--config": "config",
1819
+ "--config-file": "configFile",
1820
+ "--package": "package",
1821
+ "--include-archived": "includeArchived",
1822
+ "--wait": "wait",
1823
+ "--wait-timeout": "waitTimeout",
1824
+ "--poll-interval": "pollInterval",
1602
1825
  "--file": "file",
1603
1826
  "-f": "file",
1604
1827
  "--sql": "sql",
@@ -1645,7 +1868,6 @@ function normalizeFlagName(rawName) {
1645
1868
  "--review-policy": "reviewPolicy",
1646
1869
  "--promotion-policy": "promotionPolicy",
1647
1870
  "--eval-model": "evalModel",
1648
- "--analysis-model": "analysisModel",
1649
1871
  "--proposal-model": "proposalModel",
1650
1872
  "--base-hash": "baseHash",
1651
1873
  "--max-iterations": "maxIterations",
@@ -1654,6 +1876,9 @@ function normalizeFlagName(rawName) {
1654
1876
  "--max-output-tokens": "maxOutputTokens",
1655
1877
  "--max-sql-queries": "maxSqlQueries",
1656
1878
  "--max-duration": "maxDuration",
1879
+ "--max-agent-turns": "maxAgentTurns",
1880
+ "--max-validation-attempts": "maxValidationAttempts",
1881
+ "--max-targeted-evals": "maxTargetedEvals",
1657
1882
  "--min-improvement": "minImprovement",
1658
1883
  "--max-regressions": "maxRegressions",
1659
1884
  "--target-pass-rate": "targetPassRate",
@@ -1708,7 +1933,7 @@ function normalizeFlagName(rawName) {
1708
1933
  }
1709
1934
 
1710
1935
  function isBooleanFlag(rawName) {
1711
- return ["--json", "--help", "-h", "--include", "-i", "--raw", "--admin", "--force", "--follow", "--active", "--inactive", "--include-inactive", "--include-semantic-snapshot", "--use-semantic-layer", "--no-semantic-layer", "--no-demo", "--yes", "-y"].includes(rawName);
1936
+ return ["--json", "--help", "-h", "--include", "-i", "--raw", "--admin", "--force", "--follow", "--active", "--inactive", "--include-inactive", "--include-semantic-snapshot", "--include-archived", "--use-semantic-layer", "--no-semantic-layer", "--no-demo", "--yes", "-y", "--wait"].includes(rawName);
1712
1937
  }
1713
1938
 
1714
1939
  function setFlag(flags, name, value) {
@@ -1749,6 +1974,16 @@ function parseNumber(value, name) {
1749
1974
  return parsed;
1750
1975
  }
1751
1976
 
1977
+ function parsePositiveNumber(value, name, fallback, { allowZero = false } = {}) {
1978
+ if (value === undefined || value === null || value === "") return fallback;
1979
+ const parsed = Number(value);
1980
+ const minimum = allowZero ? 0 : Number.EPSILON;
1981
+ if (!Number.isFinite(parsed) || parsed < minimum) {
1982
+ throw usage(`Expected --${name} to be ${allowZero ? "zero or " : ""}greater than zero`);
1983
+ }
1984
+ return parsed;
1985
+ }
1986
+
1752
1987
  function parseBoundedInteger(value, name, minimum, maximum) {
1753
1988
  if (value === undefined || value === "") return undefined;
1754
1989
  if (typeof value !== "string" && typeof value !== "number") {
@@ -1878,6 +2113,9 @@ Usage:
1878
2113
 
1879
2114
  Core:
1880
2115
  answerlayer api-keys list|create|revoke
2116
+ answerlayer pipelines list|create|archive
2117
+ answerlayer pipelines revisions push|validate|promote <pipeline-id> [revision-id]
2118
+ answerlayer pipelines runs start|get|retry|cancel <pipeline-id> [run-id]
1881
2119
  answerlayer connections supported|list|get|create|update|delete|schema|test
1882
2120
  answerlayer metadata structure|tables|columns|pii-summary|pii-settings|detect-pii
1883
2121
  answerlayer query run|validate|export <connection-id> --sql <sql>
@@ -1903,11 +2141,12 @@ Data products:
1903
2141
  and --use-semantic-layer or --no-semantic-layer
1904
2142
  Optimization:
1905
2143
  answerlayer optimize start --name NAME --connection ID --suite ID --model MODEL
1906
- [--eval-model MODEL] [--proposal-model MODEL] [--analysis-model MODEL]
2144
+ [--eval-model MODEL] [--proposal-model MODEL]
1907
2145
  [--mode recommendation|supervised|fully_automatic]
1908
2146
  [--component entities,relationships,measures,metrics,dimensions,filters]
1909
2147
  [--review-policy every_sweep|exceptions_only|end_of_run]
1910
2148
  [--promotion-policy manual|automatic] [--max-iterations N]
2149
+ [--max-agent-turns N] [--max-validation-attempts N] [--max-targeted-evals N]
1911
2150
  answerlayer optimize promote RUN_ID --base-hash SHA256
1912
2151
  update accepts --label <name>
1913
2152
  answerlayer ontologies list|create|get|validate
@@ -1941,6 +2180,15 @@ Common options:
1941
2180
  --data-file <path> Structured request payload file.
1942
2181
  --output, -o <path> Write response bytes to a file.
1943
2182
 
2183
+ Pipeline options:
2184
+ --package <path> Package ZIP for pipelines revisions push.
2185
+ --config-file <path> Non-secret revision configuration JSON file.
2186
+ --config <json> Inline non-secret revision configuration.
2187
+ --include-archived Include archived pipelines when listing.
2188
+ --wait Poll validation or execution to a terminal state.
2189
+ --wait-timeout <sec> Maximum wait time. Default: 600.
2190
+ --poll-interval <sec> Poll interval. Default: 2.
2191
+
1944
2192
  SQL options:
1945
2193
  --sql, -q <sql> SQL text.
1946
2194
  --file, -f <path> Read SQL from a file, or upload a file for upload commands.