@answerlayer/cli 0.2.4 → 0.2.6

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,82 @@ 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
+ Inspect and update pipeline metadata, or explicitly pause and resume new
103
+ production executions without losing the active revision:
104
+
105
+ ```bash
106
+ answerlayer pipelines get <pipeline-id> --json
107
+ answerlayer pipelines update <pipeline-id> --description "National census" --json
108
+ answerlayer pipelines disable <pipeline-id> --json
109
+ answerlayer pipelines enable <pipeline-id> --json
110
+ ```
111
+
112
+ Use `--clear-description` to remove the description. Disabling a pipeline does
113
+ not prevent administrators from uploading and validating a replacement
114
+ revision; it prevents production execution until the pipeline is enabled.
115
+
116
+ Validate and promote the returned revision ID. `--wait` polls the exact run to
117
+ a terminal state and exits unsuccessfully when validation fails or is
118
+ cancelled:
119
+
120
+ ```bash
121
+ answerlayer pipelines revisions validate <pipeline-id> <revision-id> --wait --json
122
+ answerlayer pipelines revisions promote <pipeline-id> <revision-id> --json
123
+ ```
124
+
125
+ Revision history is immutable and inspectable. Compare the candidate revision
126
+ against the current or previous revision before promotion:
127
+
128
+ ```bash
129
+ answerlayer pipelines revisions list <pipeline-id> --json
130
+ answerlayer pipelines revisions get <pipeline-id> <revision-id> --json
131
+ answerlayer pipelines revisions diff <pipeline-id> <candidate-revision-id> \
132
+ --against <base-revision-id> --json
133
+ ```
134
+
135
+ The diff contains artifact hashes and a secret-safe, JSON-pointer-addressed
136
+ configuration diff. Configuration descriptors are digest-verified before they
137
+ are returned.
138
+
139
+ Run and operate the promoted revision:
140
+
141
+ ```bash
142
+ answerlayer pipelines runs start <pipeline-id> --wait --json
143
+ answerlayer pipelines runs get <pipeline-id> <run-id> --json
144
+ answerlayer pipelines runs retry <pipeline-id> <run-id> --wait --json
145
+ answerlayer pipelines runs cancel <pipeline-id> <run-id> --json
146
+ answerlayer pipelines archive <pipeline-id> --json
147
+ ```
148
+
149
+ Roll back by selecting a revision that was previously promoted. This moves the
150
+ active pointer back to the existing immutable revision; it does not copy or
151
+ re-upload the package:
152
+
153
+ ```bash
154
+ answerlayer pipelines revisions rollback <pipeline-id> <revision-id> --json
155
+ ```
156
+
157
+ Use `--include-archived` with `pipelines list`. Package ZIPs are built from the
158
+ customer-owned package repository; credentials and CA material must not be
159
+ included in the ZIP or revision configuration. They remain in the install's
160
+ managed secret interfaces.
161
+
86
162
  ## Run locally with an agent
87
163
 
88
164
  The package includes an `answerlayer` agent skill for evaluating AnswerLayer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@answerlayer/cli",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
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,11 @@ 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` — create, inspect, update, enable, disable, and archive pipelines;
184
+ upload immutable packages; list, inspect, diff, validate, promote, and roll
185
+ back revisions; and run/retry/cancel exact revisions. Use `--wait --json` for
186
+ automation. Never put credentials or CA material in package configuration;
187
+ rollback selects a previously promoted revision instead of uploading a copy
183
188
  - `metadata`, `api-keys`, `users`, `org`, `billing`, `stats`
184
189
 
185
190
  ## 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,201 @@ 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 === "get") {
215
+ const pipelineId = requirePositional(positionals, 0, "pipeline id");
216
+ return requestAndPrint(
217
+ client,
218
+ "GET",
219
+ `${base}/${encodeURIComponent(pipelineId)}`,
220
+ parsed,
221
+ io,
222
+ );
223
+ }
224
+
225
+ if (command === "update") {
226
+ const pipelineId = requirePositional(positionals, 0, "pipeline id");
227
+ if (parsed.flags.clearDescription && parsed.flags.description !== undefined) {
228
+ throw usage("pipelines update accepts either --description or --clear-description, not both");
229
+ }
230
+ const payload = await readData(parsed.flags, io, {
231
+ name: firstValue(parsed.flags.name),
232
+ description: parsed.flags.clearDescription
233
+ ? null
234
+ : firstValue(parsed.flags.description),
235
+ });
236
+ if (parsed.flags.clearDescription && payload.description !== null) {
237
+ throw usage("pipelines update cannot combine --clear-description with input data containing description");
238
+ }
239
+ if (Object.keys(payload).length === 0) {
240
+ throw usage("pipelines update requires --name, --description, --clear-description, or --data");
241
+ }
242
+ return requestAndPrint(
243
+ client,
244
+ "PATCH",
245
+ `${base}/${encodeURIComponent(pipelineId)}`,
246
+ parsed,
247
+ io,
248
+ { body: payload },
249
+ );
250
+ }
251
+
252
+ if (command === "enable" || command === "disable") {
253
+ const pipelineId = requirePositional(positionals, 0, "pipeline id");
254
+ return requestAndPrint(
255
+ client,
256
+ "POST",
257
+ `${base}/${encodeURIComponent(pipelineId)}/${command}`,
258
+ parsed,
259
+ io,
260
+ );
261
+ }
262
+
263
+ if (command === "archive") {
264
+ const pipelineId = requirePositional(positionals, 0, "pipeline id");
265
+ return requestAndPrint(
266
+ client,
267
+ "DELETE",
268
+ `${base}/${encodeURIComponent(pipelineId)}`,
269
+ parsed,
270
+ io,
271
+ );
272
+ }
273
+
274
+ if (command === "revisions") {
275
+ return handlePipelineRevisions(client, base, positionals, parsed, io);
276
+ }
277
+
278
+ if (command === "runs") {
279
+ return handlePipelineRuns(client, base, positionals, parsed, io);
280
+ }
281
+
282
+ throw usage(`Unknown pipelines command: ${command}`);
283
+ }
284
+
285
+ async function handlePipelineRevisions(client, base, positionals, parsed, io) {
286
+ const action = requirePositional(positionals, 0, "pipeline revisions action");
287
+ const pipelineId = requirePositional(positionals, 1, "pipeline id");
288
+ const pipelinePath = `${base}/${encodeURIComponent(pipelineId)}`;
289
+
290
+ if (action === "list") {
291
+ return requestAndPrint(client, "GET", `${pipelinePath}/revisions`, parsed, io, {
292
+ table: [
293
+ { key: "id", label: "ID" },
294
+ { key: "revision_number", label: "Revision" },
295
+ { key: "status", label: "Status" },
296
+ { key: "artifact_sha256", label: "Artifact SHA-256" },
297
+ { key: "created_at", label: "Created" },
298
+ ],
299
+ });
300
+ }
301
+
302
+ if (action === "push" || action === "upload") {
303
+ const packagePath = firstValue(parsed.flags.package)
304
+ || requirePositional(positionals, 2, "pipeline package ZIP");
305
+ const config = readPipelineRevisionConfig(parsed.flags);
306
+ return requestAndPrint(client, "POST", `${pipelinePath}/revisions`, parsed, io, {
307
+ body: multipartFields({
308
+ files: { package: packagePath },
309
+ fields: { config_json: JSON.stringify(config) },
310
+ }),
311
+ });
312
+ }
313
+
314
+ const revisionId = requirePositional(positionals, 2, "pipeline revision id");
315
+ const revisionPath = `${pipelinePath}/revisions/${encodeURIComponent(revisionId)}`;
316
+ if (action === "get") {
317
+ return requestAndPrint(client, "GET", revisionPath, parsed, io);
318
+ }
319
+ if (action === "diff") {
320
+ const against = firstValue(parsed.flags.against);
321
+ if (!against) throw usage("pipelines revisions diff requires --against <revision-id>");
322
+ return requestAndPrint(client, "GET", `${revisionPath}/diff`, parsed, io, {
323
+ query: { against },
324
+ });
325
+ }
326
+ if (action === "validate") {
327
+ return requestWaitAndPrint(
328
+ client,
329
+ "POST",
330
+ `${revisionPath}/validate`,
331
+ parsed,
332
+ io,
333
+ pipelinePath,
334
+ );
335
+ }
336
+ if (action === "promote") {
337
+ return requestAndPrint(client, "POST", `${revisionPath}/promote`, parsed, io);
338
+ }
339
+ if (action === "rollback") {
340
+ return requestAndPrint(client, "POST", `${revisionPath}/rollback`, parsed, io);
341
+ }
342
+
343
+ throw usage(`Unknown pipelines revisions command: ${action}`);
344
+ }
345
+
346
+ async function handlePipelineRuns(client, base, positionals, parsed, io) {
347
+ const action = requirePositional(positionals, 0, "pipeline runs action");
348
+ const pipelineId = requirePositional(positionals, 1, "pipeline id");
349
+ const pipelinePath = `${base}/${encodeURIComponent(pipelineId)}`;
350
+
351
+ if (action === "start" || action === "run") {
352
+ return requestWaitAndPrint(
353
+ client,
354
+ "POST",
355
+ `${pipelinePath}/runs`,
356
+ parsed,
357
+ io,
358
+ pipelinePath,
359
+ );
360
+ }
361
+
362
+ const runId = requirePositional(positionals, 2, "pipeline run id");
363
+ const runPath = `${pipelinePath}/runs/${encodeURIComponent(runId)}`;
364
+ if (action === "get") {
365
+ return requestAndPrint(client, "GET", runPath, parsed, io);
366
+ }
367
+ if (action === "retry") {
368
+ return requestWaitAndPrint(
369
+ client,
370
+ "POST",
371
+ `${runPath}/retry`,
372
+ parsed,
373
+ io,
374
+ pipelinePath,
375
+ );
376
+ }
377
+ if (action === "cancel") {
378
+ return requestAndPrint(client, "POST", `${runPath}/cancel`, parsed, io);
379
+ }
380
+
381
+ throw usage(`Unknown pipelines runs command: ${action}`);
382
+ }
383
+
188
384
  async function handleConnections(client, command, positionals, parsed, io) {
189
385
  if (command === "supported" || command === "supported-types") {
190
386
  return requestAndPrint(client, "GET", "/api/v1/connections/supported_types", parsed, io, {
@@ -1461,13 +1657,36 @@ async function readData(flags, io, defaults = {}) {
1461
1657
  return dropUndefined({ ...defaults, ...data });
1462
1658
  }
1463
1659
 
1660
+ function readPipelineRevisionConfig(flags) {
1661
+ const file = firstValue(flags.configFile);
1662
+ const inline = firstValue(flags.config);
1663
+ if (file && inline) {
1664
+ throw usage("pipelines revisions push accepts either --config-file or --config, not both");
1665
+ }
1666
+ const value = file
1667
+ ? parseJsonFlag(fs.readFileSync(file, "utf8"), "config-file")
1668
+ : inline
1669
+ ? parseJsonFlag(inline, "config")
1670
+ : {};
1671
+ if (!value || Array.isArray(value) || typeof value !== "object") {
1672
+ throw usage("pipeline revision config must be a JSON object");
1673
+ }
1674
+ return value;
1675
+ }
1676
+
1464
1677
  function multipart({ file, fields = {} }) {
1678
+ return multipartFields({ files: { file }, fields });
1679
+ }
1680
+
1681
+ function multipartFields({ files = {}, fields = {} }) {
1465
1682
  const form = new FormData();
1466
1683
  for (const [key, value] of Object.entries(dropUndefined(fields))) {
1467
1684
  form.append(key, String(value));
1468
1685
  }
1469
- const buffer = fs.readFileSync(file);
1470
- form.append("file", new Blob([buffer]), path.basename(file));
1686
+ for (const [key, file] of Object.entries(files)) {
1687
+ const buffer = fs.readFileSync(file);
1688
+ form.append(key, new Blob([buffer]), path.basename(file));
1689
+ }
1471
1690
  return form;
1472
1691
  }
1473
1692
 
@@ -1498,6 +1717,70 @@ async function requestAndPrint(client, method, pathName, parsed, io, options = {
1498
1717
  headers: options.headers,
1499
1718
  });
1500
1719
 
1720
+ return printResult(result, parsed, io, options);
1721
+ }
1722
+
1723
+ async function requestWaitAndPrint(
1724
+ client,
1725
+ method,
1726
+ pathName,
1727
+ parsed,
1728
+ io,
1729
+ pipelinePath,
1730
+ ) {
1731
+ let result = await client.rawRequest(method, pathName);
1732
+ if (parsed.flags.wait) {
1733
+ result = await waitForPipelineRun(client, result, parsed.flags, io, pipelinePath);
1734
+ }
1735
+ printResult(result, parsed, io);
1736
+ if (parsed.flags.wait && ["failed", "cancelled"].includes(result.data?.status)) {
1737
+ const error = new Error(
1738
+ result.data.error
1739
+ ? `Pipeline run ${result.data.id} ${result.data.status}: ${result.data.error}`
1740
+ : `Pipeline run ${result.data.id} ${result.data.status}`,
1741
+ );
1742
+ error.exitCode = 1;
1743
+ throw error;
1744
+ }
1745
+ }
1746
+
1747
+ async function waitForPipelineRun(client, initial, flags, io, pipelinePath) {
1748
+ const runId = initial.data?.id;
1749
+ if (!runId) throw new Error("Pipeline run response did not include an id");
1750
+ const terminal = new Set(["succeeded", "failed", "cancelled"]);
1751
+ const timeoutSeconds = parsePositiveNumber(
1752
+ firstValue(flags.waitTimeout),
1753
+ "wait-timeout",
1754
+ 600,
1755
+ );
1756
+ const pollSeconds = parsePositiveNumber(
1757
+ firstValue(flags.pollInterval),
1758
+ "poll-interval",
1759
+ 2,
1760
+ { allowZero: true },
1761
+ );
1762
+ const now = io.now || (() => Date.now());
1763
+ const sleep = io.sleep || (milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds)));
1764
+ const deadline = now() + timeoutSeconds * 1000;
1765
+ let result = initial;
1766
+
1767
+ write(io.stderr, `Waiting for pipeline run ${runId}...\n`);
1768
+ while (!terminal.has(result.data?.status)) {
1769
+ if (now() >= deadline) {
1770
+ const error = new Error(`Timed out waiting for pipeline run ${runId}`);
1771
+ error.exitCode = 1;
1772
+ throw error;
1773
+ }
1774
+ await sleep(pollSeconds * 1000);
1775
+ result = await client.rawRequest(
1776
+ "GET",
1777
+ `${pipelinePath}/runs/${encodeURIComponent(runId)}`,
1778
+ );
1779
+ }
1780
+ return result;
1781
+ }
1782
+
1783
+ function printResult(result, parsed, io, options = {}) {
1501
1784
  const output = firstValue(parsed.flags.output);
1502
1785
  if (output) {
1503
1786
  fs.writeFileSync(output, result.buffer);
@@ -1602,11 +1885,19 @@ function normalizeFlagName(rawName) {
1602
1885
  "--name": "name",
1603
1886
  "--title": "title",
1604
1887
  "--description": "description",
1888
+ "--clear-description": "clearDescription",
1605
1889
  "--visibility": "visibility",
1606
1890
  "--connection": "connection",
1607
1891
  "--type": "type",
1608
1892
  "--db-type": "dbType",
1609
1893
  "--config": "config",
1894
+ "--config-file": "configFile",
1895
+ "--against": "against",
1896
+ "--package": "package",
1897
+ "--include-archived": "includeArchived",
1898
+ "--wait": "wait",
1899
+ "--wait-timeout": "waitTimeout",
1900
+ "--poll-interval": "pollInterval",
1610
1901
  "--file": "file",
1611
1902
  "-f": "file",
1612
1903
  "--sql": "sql",
@@ -1718,7 +2009,7 @@ function normalizeFlagName(rawName) {
1718
2009
  }
1719
2010
 
1720
2011
  function isBooleanFlag(rawName) {
1721
- 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);
2012
+ return ["--json", "--help", "-h", "--include", "-i", "--raw", "--admin", "--force", "--follow", "--active", "--inactive", "--include-inactive", "--include-semantic-snapshot", "--include-archived", "--clear-description", "--use-semantic-layer", "--no-semantic-layer", "--no-demo", "--yes", "-y", "--wait"].includes(rawName);
1722
2013
  }
1723
2014
 
1724
2015
  function setFlag(flags, name, value) {
@@ -1759,6 +2050,16 @@ function parseNumber(value, name) {
1759
2050
  return parsed;
1760
2051
  }
1761
2052
 
2053
+ function parsePositiveNumber(value, name, fallback, { allowZero = false } = {}) {
2054
+ if (value === undefined || value === null || value === "") return fallback;
2055
+ const parsed = Number(value);
2056
+ const minimum = allowZero ? 0 : Number.EPSILON;
2057
+ if (!Number.isFinite(parsed) || parsed < minimum) {
2058
+ throw usage(`Expected --${name} to be ${allowZero ? "zero or " : ""}greater than zero`);
2059
+ }
2060
+ return parsed;
2061
+ }
2062
+
1762
2063
  function parseBoundedInteger(value, name, minimum, maximum) {
1763
2064
  if (value === undefined || value === "") return undefined;
1764
2065
  if (typeof value !== "string" && typeof value !== "number") {
@@ -1888,6 +2189,9 @@ Usage:
1888
2189
 
1889
2190
  Core:
1890
2191
  answerlayer api-keys list|create|revoke
2192
+ answerlayer pipelines list|create|get|update|enable|disable|archive
2193
+ answerlayer pipelines revisions list|get|push|validate|promote|diff|rollback <pipeline-id> [revision-id]
2194
+ answerlayer pipelines runs start|get|retry|cancel <pipeline-id> [run-id]
1891
2195
  answerlayer connections supported|list|get|create|update|delete|schema|test
1892
2196
  answerlayer metadata structure|tables|columns|pii-summary|pii-settings|detect-pii
1893
2197
  answerlayer query run|validate|export <connection-id> --sql <sql>
@@ -1952,6 +2256,17 @@ Common options:
1952
2256
  --data-file <path> Structured request payload file.
1953
2257
  --output, -o <path> Write response bytes to a file.
1954
2258
 
2259
+ Pipeline options:
2260
+ --package <path> Package ZIP for pipelines revisions push.
2261
+ --config-file <path> Non-secret revision configuration JSON file.
2262
+ --config <json> Inline non-secret revision configuration.
2263
+ --against <id> Base revision for pipelines revisions diff.
2264
+ --clear-description Clear a pipeline description during update.
2265
+ --include-archived Include archived pipelines when listing.
2266
+ --wait Poll validation or execution to a terminal state.
2267
+ --wait-timeout <sec> Maximum wait time. Default: 600.
2268
+ --poll-interval <sec> Poll interval. Default: 2.
2269
+
1955
2270
  SQL options:
1956
2271
  --sql, -q <sql> SQL text.
1957
2272
  --file, -f <path> Read SQL from a file, or upload a file for upload commands.