@openbkn/bkn-sdk 0.1.0 → 0.1.1-alpha.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 +18 -3
- package/dist/{chunk-4NXAIG4G.js → chunk-ADZ23DPF.js} +288 -58
- package/dist/chunk-ADZ23DPF.js.map +1 -0
- package/dist/cli.js +123 -25
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +74 -26
- package/dist/index.js +1 -1
- package/package.json +1 -2
- package/dist/chunk-4NXAIG4G.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
formatError,
|
|
14
14
|
listPlatforms,
|
|
15
15
|
logout,
|
|
16
|
+
parseEmbeddingFields,
|
|
16
17
|
parsePkMap,
|
|
17
18
|
rawCall,
|
|
18
19
|
readPlatformConfig,
|
|
@@ -27,7 +28,7 @@ import {
|
|
|
27
28
|
usersOf,
|
|
28
29
|
whoami,
|
|
29
30
|
writePlatformConfig
|
|
30
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-ADZ23DPF.js";
|
|
31
32
|
|
|
32
33
|
// src/cli.ts
|
|
33
34
|
import { Command as Command16 } from "commander";
|
|
@@ -35,7 +36,7 @@ import { Command as Command16 } from "commander";
|
|
|
35
36
|
// package.json
|
|
36
37
|
var package_default = {
|
|
37
38
|
name: "@openbkn/bkn-sdk",
|
|
38
|
-
version: "0.1.
|
|
39
|
+
version: "0.1.1-alpha.1",
|
|
39
40
|
description: "Unified TypeScript SDK + CLI for the BKN (Business Knowledge Network) platform.",
|
|
40
41
|
type: "module",
|
|
41
42
|
license: "Apache-2.0",
|
|
@@ -76,7 +77,6 @@ var package_default = {
|
|
|
76
77
|
dependencies: {
|
|
77
78
|
"@clack/prompts": "^0.9.1",
|
|
78
79
|
chalk: "^5.4.1",
|
|
79
|
-
"cli-table3": "^0.6.5",
|
|
80
80
|
commander: "^13.1.0",
|
|
81
81
|
"csv-parse": "^6.2.1",
|
|
82
82
|
"js-yaml": "^4.2.0",
|
|
@@ -149,7 +149,6 @@ function installGroupedHelp(root) {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
// src/utils/output.ts
|
|
152
|
-
import Table from "cli-table3";
|
|
153
152
|
function printJson(value, opts = {}) {
|
|
154
153
|
if (opts.json || opts.compact) {
|
|
155
154
|
process.stdout.write(`${JSON.stringify(value, null, opts.compact ? 0 : 2)}
|
|
@@ -158,9 +157,14 @@ function printJson(value, opts = {}) {
|
|
|
158
157
|
}
|
|
159
158
|
const rows = toRows(value);
|
|
160
159
|
if (rows) {
|
|
161
|
-
const columns = columnsOf(rows);
|
|
160
|
+
const columns = opts.full ? columnsOf(rows).filter((c) => rows.some((r) => stringifyCell(r[c]) !== "")) : selectColumns(rows);
|
|
162
161
|
if (columns.length > 0) {
|
|
163
162
|
printTable(rows, columns);
|
|
163
|
+
const hidden = columnsOf(rows).length - columns.length;
|
|
164
|
+
if (hidden > 0 && !opts.full) {
|
|
165
|
+
process.stdout.write(`\u2026 ${hidden} more column(s); use --full or --json for everything
|
|
166
|
+
`);
|
|
167
|
+
}
|
|
164
168
|
return;
|
|
165
169
|
}
|
|
166
170
|
}
|
|
@@ -186,22 +190,68 @@ function columnsOf(rows) {
|
|
|
186
190
|
}
|
|
187
191
|
return seen;
|
|
188
192
|
}
|
|
193
|
+
var MAX_COLS = 8;
|
|
194
|
+
var NOISE_COLS = /* @__PURE__ */ new Set([
|
|
195
|
+
"creator",
|
|
196
|
+
"updater",
|
|
197
|
+
"create_by",
|
|
198
|
+
"update_by",
|
|
199
|
+
"create_user",
|
|
200
|
+
"update_user",
|
|
201
|
+
"operations",
|
|
202
|
+
"status_message",
|
|
203
|
+
"last_check_time",
|
|
204
|
+
"last_discover_status",
|
|
205
|
+
"health_check_result",
|
|
206
|
+
"health_check_enabled"
|
|
207
|
+
]);
|
|
208
|
+
var isNoiseCol = (c) => NOISE_COLS.has(c) || /_time$/.test(c);
|
|
209
|
+
var isKeyCol = (c) => /^(id|name|key|title|label)$/i.test(c) || /_(id|name|key)$/i.test(c) || /^(status|state|type|category|mode|enabled|version|branch)$/i.test(c);
|
|
210
|
+
function selectColumns(rows) {
|
|
211
|
+
const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
212
|
+
const kept = columnsOf(rows).filter((c) => {
|
|
213
|
+
if (isNoiseCol(c)) return false;
|
|
214
|
+
const vals = rows.map((r) => r[c]);
|
|
215
|
+
if (!vals.some((v) => stringifyCell(v) !== "")) return false;
|
|
216
|
+
if (vals.every((v) => v === null || v === void 0 || isObj(v))) return false;
|
|
217
|
+
return true;
|
|
218
|
+
});
|
|
219
|
+
const isLongText = (c) => rows.every((r) => {
|
|
220
|
+
const s = stringifyCell(r[c]);
|
|
221
|
+
return s === "" || s.length >= CELL_MAX - 1;
|
|
222
|
+
});
|
|
223
|
+
const rank = (c) => isKeyCol(c) ? 0 : isLongText(c) ? 2 : 1;
|
|
224
|
+
const ordered = kept.map((c, i) => ({ c, i, r: rank(c) })).sort((a, b) => a.r - b.r || a.i - b.i).map((x) => x.c);
|
|
225
|
+
return ordered.slice(0, MAX_COLS);
|
|
226
|
+
}
|
|
189
227
|
function printTable(rows, columns, opts = {}) {
|
|
190
228
|
if (opts.json || opts.compact) {
|
|
191
229
|
printJson(rows, opts);
|
|
192
230
|
return;
|
|
193
231
|
}
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
232
|
+
const cells = rows.map((row) => columns.map((c) => stringifyCell(row[c])));
|
|
233
|
+
const widths = columns.map(
|
|
234
|
+
(col, i) => Math.max(displayWidth(col), ...cells.map((r) => displayWidth(r[i] ?? "")))
|
|
235
|
+
);
|
|
236
|
+
const fmt = (parts) => parts.map((p, i) => i === parts.length - 1 ? p : pad(p, widths[i] ?? 0)).join(" ").trimEnd();
|
|
237
|
+
const lines = [fmt(columns), ...cells.map(fmt)];
|
|
238
|
+
process.stdout.write(`${lines.join("\n")}
|
|
199
239
|
`);
|
|
200
240
|
}
|
|
201
241
|
var CELL_MAX = 48;
|
|
242
|
+
function displayWidth(s) {
|
|
243
|
+
let w = 0;
|
|
244
|
+
for (const ch of s) w += /[ᄀ-ᅟ⺀-가-힣豈-︰-﹏-⦆¢-₩]/.test(ch) ? 2 : 1;
|
|
245
|
+
return w;
|
|
246
|
+
}
|
|
247
|
+
function pad(s, width) {
|
|
248
|
+
const gap = width - displayWidth(s);
|
|
249
|
+
return gap > 0 ? s + " ".repeat(gap) : s;
|
|
250
|
+
}
|
|
202
251
|
function stringifyCell(v) {
|
|
203
252
|
if (v === null || v === void 0) return "";
|
|
204
|
-
const
|
|
253
|
+
const raw = Array.isArray(v) && v.every((x) => x === null || typeof x !== "object") ? v.join(",") : typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
254
|
+
const s = raw.replace(/\s+/g, " ").trim();
|
|
205
255
|
return s.length > CELL_MAX ? `${s.slice(0, CELL_MAX - 1)}\u2026` : s;
|
|
206
256
|
}
|
|
207
257
|
|
|
@@ -219,7 +269,7 @@ function clientFrom(cmd) {
|
|
|
219
269
|
}
|
|
220
270
|
function outputOptions(cmd) {
|
|
221
271
|
const o = cmd.optsWithGlobals();
|
|
222
|
-
return { json: Boolean(o.json), compact: Boolean(o.compact) };
|
|
272
|
+
return { json: Boolean(o.json), compact: Boolean(o.compact), full: Boolean(o.full) };
|
|
223
273
|
}
|
|
224
274
|
function csv(value) {
|
|
225
275
|
if (!value) return void 0;
|
|
@@ -1379,8 +1429,18 @@ function bknCommand() {
|
|
|
1379
1429
|
job.command("delete <kn-id> <job-ids>").description("Delete job(s) (comma-joined ids)").action(async (knId, ids, _o, cmd) => {
|
|
1380
1430
|
printJson(await clientFrom(cmd).kn.jobDelete(knId, ids), outputOptions(cmd));
|
|
1381
1431
|
});
|
|
1382
|
-
bkn.command("push <directory>").description("Pack a BKN directory into a tar and import it as a knowledge network").option("--branch <name>", "target branch", "main").
|
|
1383
|
-
|
|
1432
|
+
bkn.command("push <directory>").description("Pack a BKN directory into a tar and import it as a knowledge network").option("--branch <name>", "target branch", "main").option("--build", "submit a Vega build task for each object type declaring a vector index").option(
|
|
1433
|
+
"--embedding-model <id>",
|
|
1434
|
+
"embedding model id for declared vector indexes (with --build)"
|
|
1435
|
+
).action(async (dir, opts, cmd) => {
|
|
1436
|
+
printJson(
|
|
1437
|
+
await clientFrom(cmd).kn.push(dir, {
|
|
1438
|
+
branch: opts.branch,
|
|
1439
|
+
build: Boolean(opts.build),
|
|
1440
|
+
embeddingModel: opts.embeddingModel
|
|
1441
|
+
}),
|
|
1442
|
+
outputOptions(cmd)
|
|
1443
|
+
);
|
|
1384
1444
|
});
|
|
1385
1445
|
bkn.command("pull <kn-id> [directory]").description("Download a knowledge network as a BKN tar and extract it locally").option("--branch <name>", "source branch", "main").action(async (knId, dir, opts, cmd) => {
|
|
1386
1446
|
printJson(
|
|
@@ -1397,7 +1457,10 @@ function bknCommand() {
|
|
|
1397
1457
|
bkn.command("resources").description("List BKN-backend resources").action(async (_opts, cmd) => {
|
|
1398
1458
|
printJson(await clientFrom(cmd).kn.bknResources(), outputOptions(cmd));
|
|
1399
1459
|
});
|
|
1400
|
-
bkn.command("create-from-catalog <catalog-id>").description("Build a knowledge network from a Vega catalog's tables").requiredOption("--name <name>", "knowledge network name").option("--tables <list>", "comma-separated table names (default: all)").option("--pk-map <map>", "explicit primary keys: '<table>:<col>[,<table>:<col>...]'").option("--build", "submit a Vega build task per resource after creation").option(
|
|
1460
|
+
bkn.command("create-from-catalog <catalog-id>").description("Build a knowledge network from a Vega catalog's tables").requiredOption("--name <name>", "knowledge network name").option("--tables <list>", "comma-separated table names (default: all)").option("--pk-map <map>", "explicit primary keys: '<table>:<col>[,<table>:<col>...]'").option("--build", "submit a Vega build task per resource after creation").option(
|
|
1461
|
+
"--embedding-fields <map>",
|
|
1462
|
+
"columns to vectorize per table (with --build): '<table>:<col>[+<col>...][,...]'"
|
|
1463
|
+
).option("--embedding-model <id>", "embedding model id for the vector index (with --build)").option("--no-rollback", "keep a partially-created KN on failure").action(async (catalogId, opts, cmd) => {
|
|
1401
1464
|
printJson(
|
|
1402
1465
|
await clientFrom(cmd).kn.createFromCatalog({
|
|
1403
1466
|
catalogId,
|
|
@@ -1405,6 +1468,8 @@ function bknCommand() {
|
|
|
1405
1468
|
tables: csv(opts.tables),
|
|
1406
1469
|
pkMap: opts.pkMap ? parsePkMap(opts.pkMap) : void 0,
|
|
1407
1470
|
build: Boolean(opts.build),
|
|
1471
|
+
embeddingFields: opts.embeddingFields ? parseEmbeddingFields(opts.embeddingFields) : void 0,
|
|
1472
|
+
embeddingModel: opts.embeddingModel,
|
|
1408
1473
|
noRollback: opts.rollback === false,
|
|
1409
1474
|
onProgress: (m) => console.error(m)
|
|
1410
1475
|
}),
|
|
@@ -1416,7 +1481,10 @@ function bknCommand() {
|
|
|
1416
1481
|
printJson(result, outputOptions(cmd));
|
|
1417
1482
|
if (!result.valid) process.exitCode = 1;
|
|
1418
1483
|
});
|
|
1419
|
-
bkn.command("create-from-csv <catalog-id>").description("Import CSV files into a Vega catalog, then build a KN from them").requiredOption("--files <glob>", "CSV paths (comma-separated or glob)").requiredOption("--name <name>", "knowledge network name").option("--table-prefix <s>", "prefix for derived table names", "").option("--batch-size <n>", "rows per insert batch", int3, 500).option("--tables <list>", "subset of imported tables to include in the KN").option("--pk-map <map>", "explicit primary keys: '<table>:<col>[,...]'").option("--build", "submit a Vega build task per resource after creation").option(
|
|
1484
|
+
bkn.command("create-from-csv <catalog-id>").description("Import CSV files into a Vega catalog, then build a KN from them").requiredOption("--files <glob>", "CSV paths (comma-separated or glob)").requiredOption("--name <name>", "knowledge network name").option("--table-prefix <s>", "prefix for derived table names", "").option("--batch-size <n>", "rows per insert batch", int3, 500).option("--tables <list>", "subset of imported tables to include in the KN").option("--pk-map <map>", "explicit primary keys: '<table>:<col>[,...]'").option("--build", "submit a Vega build task per resource after creation").option(
|
|
1485
|
+
"--embedding-fields <map>",
|
|
1486
|
+
"columns to vectorize per table (with --build): '<table>:<col>[+<col>...][,...]'"
|
|
1487
|
+
).option("--embedding-model <id>", "embedding model id for the vector index (with --build)").option("--no-rollback", "keep a partially-created KN on failure").action(async (catalogId, opts, cmd) => {
|
|
1420
1488
|
printJson(
|
|
1421
1489
|
await clientFrom(cmd).kn.createFromCsv({
|
|
1422
1490
|
catalogId,
|
|
@@ -1427,6 +1495,8 @@ function bknCommand() {
|
|
|
1427
1495
|
tables: csv(opts.tables),
|
|
1428
1496
|
pkMap: opts.pkMap ? parsePkMap(opts.pkMap) : void 0,
|
|
1429
1497
|
build: Boolean(opts.build),
|
|
1498
|
+
embeddingFields: opts.embeddingFields ? parseEmbeddingFields(opts.embeddingFields) : void 0,
|
|
1499
|
+
embeddingModel: opts.embeddingModel,
|
|
1430
1500
|
noRollback: opts.rollback === false,
|
|
1431
1501
|
onProgress: (m) => console.error(m)
|
|
1432
1502
|
}),
|
|
@@ -1851,18 +1921,18 @@ import { Command as Command11 } from "commander";
|
|
|
1851
1921
|
var int8 = (v) => Number.parseInt(v, 10);
|
|
1852
1922
|
function resourceCommand() {
|
|
1853
1923
|
const cmd = new Command11("resource").alias("res").description("Resources \u2014 list, find, get, query, delete");
|
|
1854
|
-
cmd.command("list").description("List resources under a
|
|
1924
|
+
cmd.command("list").description("List resources under a catalog").option("--catalog-id <id>", "filter by catalog id").option("--datasource-id <id>", "alias of --catalog-id").option("--category <c>", "resource category (table | logicview | dataset)").option("--type <c>", "alias of --category").option("--limit <n>", "page size", int8, DEFAULT_LIST_LIMIT).action(async (opts, cmd2) => {
|
|
1855
1925
|
const data = await clientFrom(cmd2).resource.list({
|
|
1856
|
-
datasourceId: opts.datasourceId,
|
|
1857
|
-
category: opts.type,
|
|
1926
|
+
datasourceId: opts.catalogId ?? opts.datasourceId,
|
|
1927
|
+
category: opts.category ?? opts.type,
|
|
1858
1928
|
limit: opts.limit
|
|
1859
1929
|
});
|
|
1860
1930
|
printJson(data, outputOptions(cmd2));
|
|
1861
1931
|
});
|
|
1862
|
-
cmd.command("find").description("Search resources by name (fuzzy; --exact for strict)").requiredOption("--name <name>", "resource name to search").option("--exact", "exact name match").option("--
|
|
1932
|
+
cmd.command("find").description("Search resources by name (fuzzy; --exact for strict)").requiredOption("--name <name>", "resource name to search").option("--exact", "exact name match").option("--catalog-id <id>", "limit to a catalog").option("--datasource-id <id>", "alias of --catalog-id").action(async (opts, cmd2) => {
|
|
1863
1933
|
const data = await clientFrom(cmd2).resource.find(opts.name, {
|
|
1864
1934
|
exact: opts.exact,
|
|
1865
|
-
datasourceId: opts.datasourceId
|
|
1935
|
+
datasourceId: opts.catalogId ?? opts.datasourceId
|
|
1866
1936
|
});
|
|
1867
1937
|
printJson(data, outputOptions(cmd2));
|
|
1868
1938
|
});
|
|
@@ -2234,6 +2304,34 @@ function vegaCommand() {
|
|
|
2234
2304
|
catalog.command("health <ids...>").description("Health-status for one or more catalogs").action(async (ids, _opts, cmd) => {
|
|
2235
2305
|
printJson(await clientFrom(cmd).vega.catalogHealth(ids), outputOptions(cmd));
|
|
2236
2306
|
});
|
|
2307
|
+
catalog.command("create").description("Create a catalog (data source)").requiredOption("--name <s>", "catalog name").requiredOption("--connector-type <s>", "connector type (e.g. mysql)").requiredOption("--connector-config <json>", "connector config JSON").option("--tags <t1,t2>", "comma-separated tags").option("--description <s>", "description").option("--enabled", "create enabled (default: disabled)").action(async (opts, cmd) => {
|
|
2308
|
+
let connectorConfig;
|
|
2309
|
+
try {
|
|
2310
|
+
connectorConfig = JSON.parse(opts.connectorConfig);
|
|
2311
|
+
} catch {
|
|
2312
|
+
throw new Error("--connector-config must be valid JSON");
|
|
2313
|
+
}
|
|
2314
|
+
printJson(
|
|
2315
|
+
await clientFrom(cmd).vega.createCatalog({
|
|
2316
|
+
name: opts.name,
|
|
2317
|
+
connectorType: opts.connectorType,
|
|
2318
|
+
connectorConfig,
|
|
2319
|
+
tags: opts.tags ? String(opts.tags).split(",").map((t) => t.trim()).filter(Boolean) : void 0,
|
|
2320
|
+
description: opts.description,
|
|
2321
|
+
enabled: opts.enabled ? true : void 0
|
|
2322
|
+
}),
|
|
2323
|
+
outputOptions(cmd)
|
|
2324
|
+
);
|
|
2325
|
+
});
|
|
2326
|
+
catalog.command("enable <id>").description("Enable a catalog (required before discovery)").action(async (id, _opts, cmd) => {
|
|
2327
|
+
printJson(await clientFrom(cmd).vega.enableCatalog(id), outputOptions(cmd));
|
|
2328
|
+
});
|
|
2329
|
+
catalog.command("discover <id>").description("Trigger catalog resource discovery").option("--wait", "wait for discovery to complete").action(async (id, opts, cmd) => {
|
|
2330
|
+
printJson(
|
|
2331
|
+
await clientFrom(cmd).vega.discoverCatalog(id, Boolean(opts.wait)),
|
|
2332
|
+
outputOptions(cmd)
|
|
2333
|
+
);
|
|
2334
|
+
});
|
|
2237
2335
|
const connector = vega.command("connector-type").description("Connector types");
|
|
2238
2336
|
connector.command("list").description("List connector types").action(async (_opts, cmd) => {
|
|
2239
2337
|
printJson(await clientFrom(cmd).vega.connectorTypes(), outputOptions(cmd));
|
|
@@ -2242,11 +2340,11 @@ function vegaCommand() {
|
|
|
2242
2340
|
printJson(await clientFrom(cmd).vega.connectorType(type), outputOptions(cmd));
|
|
2243
2341
|
});
|
|
2244
2342
|
const resource = vega.command("resource").description("Vega-backend resources");
|
|
2245
|
-
resource.command("list").description("List resources").option("--datasource-id <id>", "filter by catalog/datasource id").option("--type <category>", "resource category").option("--limit <n>", "page size", (v) => Number.parseInt(v, 10), DEFAULT_LIST_LIMIT).action(async (opts, cmd) => {
|
|
2343
|
+
resource.command("list").description("List resources").option("--datasource-id <id>", "filter by catalog/datasource id").option("--catalog-id <id>", "alias of --datasource-id").option("--type <category>", "resource category").option("--category <category>", "alias of --type").option("--limit <n>", "page size", (v) => Number.parseInt(v, 10), DEFAULT_LIST_LIMIT).action(async (opts, cmd) => {
|
|
2246
2344
|
printJson(
|
|
2247
2345
|
await clientFrom(cmd).resource.list({
|
|
2248
|
-
datasourceId: opts.datasourceId,
|
|
2249
|
-
category: opts.type,
|
|
2346
|
+
datasourceId: opts.datasourceId ?? opts.catalogId,
|
|
2347
|
+
category: opts.type ?? opts.category,
|
|
2250
2348
|
limit: opts.limit
|
|
2251
2349
|
}),
|
|
2252
2350
|
outputOptions(cmd)
|
|
@@ -2289,7 +2387,7 @@ function vegaCommand() {
|
|
|
2289
2387
|
|
|
2290
2388
|
// src/cli.ts
|
|
2291
2389
|
var program = new Command16();
|
|
2292
|
-
program.name("openbkn").description("Operate the BKN platform from the CLI").version(package_default.version, "-V, --version", "output the version number").option("--base-url <url>", "platform base URL (env: BKN_BASE_URL)").option("--token <value>", "access token (env: BKN_TOKEN)").option("--user <id|name>", "use specific user credentials (env: BKN_USER)").option("--json", "machine-readable JSON output").option("--compact", "single-line JSON output").option("--biz-domain <s>", "business domain (alias: -bd)").option("-k, --insecure", "skip TLS verification (dev / self-signed only)").showHelpAfterError();
|
|
2390
|
+
program.name("openbkn").description("Operate the BKN platform from the CLI").version(package_default.version, "-V, --version", "output the version number").option("--base-url <url>", "platform base URL (env: BKN_BASE_URL)").option("--token <value>", "access token (env: BKN_TOKEN)").option("--user <id|name>", "use specific user credentials (env: BKN_USER)").option("--json", "machine-readable JSON output").option("--compact", "single-line JSON output").option("--full", "human view: show all columns (default trims to the key ones)").option("--biz-domain <s>", "business domain (alias: -bd)").option("-k, --insecure", "skip TLS verification (dev / self-signed only)").showHelpAfterError();
|
|
2293
2391
|
program.addCommand(authCommand());
|
|
2294
2392
|
program.addCommand(callCommand());
|
|
2295
2393
|
program.addCommand(configCommand());
|