@kweaver-ai/kweaver-sdk 0.8.2 → 0.8.3

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.
Files changed (40) hide show
  1. package/README.md +26 -52
  2. package/README.zh.md +27 -46
  3. package/dist/api/resources.d.ts +94 -0
  4. package/dist/api/resources.js +166 -0
  5. package/dist/cli.js +102 -10
  6. package/dist/client.d.ts +3 -3
  7. package/dist/client.js +5 -5
  8. package/dist/commands/agent-members.js +27 -11
  9. package/dist/commands/agent.js +383 -272
  10. package/dist/commands/auth.js +184 -71
  11. package/dist/commands/bkn-metric.js +37 -16
  12. package/dist/commands/bkn-ops.js +164 -86
  13. package/dist/commands/bkn-query.js +99 -31
  14. package/dist/commands/bkn-schema.d.ts +3 -3
  15. package/dist/commands/bkn-schema.js +127 -86
  16. package/dist/commands/bkn.js +153 -114
  17. package/dist/commands/call.js +23 -13
  18. package/dist/commands/config.js +22 -12
  19. package/dist/commands/context-loader.js +98 -92
  20. package/dist/commands/dataflow.js +14 -6
  21. package/dist/commands/ds.js +52 -30
  22. package/dist/commands/explore.js +18 -15
  23. package/dist/commands/model.js +53 -42
  24. package/dist/commands/resource.d.ts +1 -0
  25. package/dist/commands/{dataview.js → resource.js} +62 -84
  26. package/dist/commands/skill.js +201 -65
  27. package/dist/commands/token.js +11 -0
  28. package/dist/commands/tool.js +46 -29
  29. package/dist/commands/toolbox.js +31 -15
  30. package/dist/commands/vega.js +466 -250
  31. package/dist/help/format.d.ts +65 -0
  32. package/dist/help/format.js +141 -0
  33. package/dist/index.d.ts +3 -3
  34. package/dist/index.js +2 -2
  35. package/dist/resources/{dataviews.d.ts → resources.d.ts} +10 -11
  36. package/dist/resources/{dataviews.js → resources.js} +12 -13
  37. package/package.json +1 -1
  38. package/dist/api/dataviews.d.ts +0 -117
  39. package/dist/api/dataviews.js +0 -265
  40. package/dist/commands/dataview.d.ts +0 -8
@@ -98,6 +98,12 @@ export async function runDataflowCommand(args) {
98
98
  let exitCode = 0;
99
99
  const parser = yargs(args)
100
100
  .scriptName("kweaver dataflow")
101
+ .usage("Dataflow document workflows — list, run, runs, logs, templates, create*\n\n" +
102
+ "USAGE\n" +
103
+ " kweaver dataflow <subcommand> [flags]")
104
+ .epilog("LEARN MORE\n" +
105
+ " Use `kweaver dataflow <subcommand> --help` for flag details\n" +
106
+ " See docs/cli_conventions.md §8 for help format spec")
101
107
  .exitProcess(false)
102
108
  .help()
103
109
  .version(false)
@@ -130,12 +136,14 @@ export async function runDataflowCommand(args) {
130
136
  return 0;
131
137
  });
132
138
  })
133
- .command("run <dagId>", "Trigger one dataflow run", (command) => command
134
- .positional("dagId", { type: "string" })
135
- .option("file", { type: "string" })
136
- .option("url", { type: "string" })
137
- .option("name", { type: "string" })
138
- .option("biz-domain", { alias: "bd", type: "string" })
139
+ .command("run <dagId>", "Trigger one dataflow run (provide --file or --url+--name)", (command) => command
140
+ .positional("dagId", { type: "string", describe: "Dataflow DAG id" })
141
+ .option("file", { type: "string", describe: "Path to local file to upload (multipart)" })
142
+ .option("url", { type: "string", describe: "Remote URL to fetch payload from (requires --name)" })
143
+ .option("name", { type: "string", describe: "Filename for --url payload" })
144
+ .option("biz-domain", { alias: "bd", type: "string", describe: "Business domain (default: bd_public)" })
145
+ .example("kweaver dataflow run dag-123 --file ./input.csv", "Upload local file")
146
+ .example("kweaver dataflow run dag-123 --url https://host/x.csv --name x.csv", "Fetch from remote URL")
139
147
  .check((argv) => {
140
148
  const hasFile = typeof argv.file === "string";
141
149
  const hasUrl = typeof argv.url === "string";
@@ -10,6 +10,31 @@ import { resolveBusinessDomain } from "../config/store.js";
10
10
  import { assertVegaCatalogId } from "./bkn-utils.js";
11
11
  import { parseCsvFile, buildTableName, splitBatches, buildFieldMappings, buildDagBody, } from "./import-csv.js";
12
12
  import { executeDataflow } from "../api/dataflow.js";
13
+ import { renderHelp } from "../help/format.js";
14
+ const DS_HELP = renderHelp({
15
+ tagline: "Manage datasources — list, get, delete, tables, connect, import-csv",
16
+ usage: "kweaver ds <subcommand> [flags]",
17
+ sections: [
18
+ {
19
+ title: "AVAILABLE COMMANDS",
20
+ items: [
21
+ { name: "list", desc: "List datasources" },
22
+ { name: "get", desc: "Get datasource details" },
23
+ { name: "delete", desc: "Delete a datasource" },
24
+ { name: "tables", desc: "List tables with columns" },
25
+ { name: "connect", desc: "Test, register and discover; reuses by (type,host,port,db,account) unless --force-new" },
26
+ { name: "import-csv", desc: "Import CSV files into datasource tables via dataflow API" },
27
+ ],
28
+ },
29
+ ],
30
+ inheritedFlags: "--base-url, --token, --user, --help",
31
+ examples: [
32
+ "kweaver ds list --keyword mysql",
33
+ "kweaver ds connect mysql 127.0.0.1 3306 mydb --account root --password ******",
34
+ "kweaver ds tables <id> --keyword users",
35
+ ],
36
+ learnMore: ["Use `kweaver ds <subcommand> --help` for flag details"],
37
+ });
13
38
  function confirmYes(prompt) {
14
39
  return new Promise((resolve) => {
15
40
  const rl = createInterface({ input: process.stdin, output: process.stdout });
@@ -31,20 +56,7 @@ function extractDatasourceId(body) {
31
56
  export async function runDsCommand(args) {
32
57
  const [subcommand, ...rest] = args;
33
58
  if (!subcommand || subcommand === "--help" || subcommand === "-h") {
34
- console.log(`kweaver ds
35
-
36
- Subcommands:
37
- list [--keyword X] [--type Y] List datasources
38
- get <id> Get datasource details
39
- delete <id> [-y] Delete a datasource
40
- tables <id> [--keyword X] List tables with columns
41
- connect <db_type> <host> <port> <database> --account X --password Y [--schema Z] [--name N]
42
- [--reuse-existing|--force-new]
43
- Test connectivity, register datasource, and discover tables.
44
- By default reuses an existing ds with the same (type, host, port, database, account)
45
- instead of creating a duplicate. --force-new always creates a new entry.
46
- import-csv <ds-id> --files <glob_or_list> [--table-prefix X] [--batch-size N]
47
- Import CSV files into datasource tables via dataflow API.`);
59
+ console.log(DS_HELP);
48
60
  return 0;
49
61
  }
50
62
  const dispatch = () => {
@@ -123,13 +135,17 @@ async function runDsListCommand(args) {
123
135
  }
124
136
  catch (error) {
125
137
  if (error instanceof Error && error.message === "help") {
126
- console.log(`kweaver ds list [options]
127
-
128
- Options:
129
- --keyword <s> Filter by keyword
130
- --type <s> Filter by database type
131
- -bd, --biz-domain Business domain (default: bd_public)
132
- --pretty Pretty-print JSON (default)`);
138
+ console.log(renderHelp({
139
+ tagline: "List datasources",
140
+ usage: "kweaver ds list [options]",
141
+ flags: [
142
+ { name: "--keyword <s>", desc: "Filter by keyword" },
143
+ { name: "--type <s>", desc: "Filter by database type" },
144
+ { name: "-bd, --biz-domain", desc: "Business domain (default: bd_public)" },
145
+ { name: "--pretty", desc: "Pretty-print JSON (default)" },
146
+ ],
147
+ inheritedFlags: "--base-url, --token, --user, --help",
148
+ }));
133
149
  return 0;
134
150
  }
135
151
  throw error;
@@ -407,15 +423,21 @@ async function printDsConnectOutput(base, dsId) {
407
423
  return 0;
408
424
  }
409
425
  // ── import-csv ────────────────────────────────────────────────────────────────
410
- const IMPORT_CSV_HELP = `kweaver ds import-csv <ds-id> --files <glob_or_list> [options]
411
-
412
- Import CSV files into datasource tables via dataflow API.
413
-
414
- Options:
415
- --files <s> CSV file paths (comma-separated or glob pattern, required)
416
- --table-prefix <s> Table name prefix (default: none)
417
- --batch-size <n> Rows per batch (default: 500, range: 1-10000)
418
- -bd, --biz-domain Business domain (default: bd_public)`;
426
+ const IMPORT_CSV_HELP = renderHelp({
427
+ tagline: "Import CSV files into datasource tables via dataflow API",
428
+ usage: "kweaver ds import-csv <ds-id> --files <glob_or_list> [flags]",
429
+ flags: [
430
+ { name: "--files <s>", desc: "CSV file paths — comma-separated or glob pattern (required)" },
431
+ { name: "--table-prefix <s>", desc: "Table name prefix (default: none)" },
432
+ { name: "--batch-size <n>", desc: "Rows per batch (default: 500, range: 1-10000)" },
433
+ { name: "-bd, --biz-domain <s>", desc: "Business domain (default: bd_public)" },
434
+ ],
435
+ inheritedFlags: "--base-url, --token, --user, --help",
436
+ examples: [
437
+ "kweaver ds import-csv ds-123 --files './data/*.csv'",
438
+ "kweaver ds import-csv ds-123 --files ./a.csv,./b.csv --table-prefix raw_ --batch-size 1000",
439
+ ],
440
+ });
419
441
  export function parseImportCsvArgs(args) {
420
442
  let datasourceId = "";
421
443
  let files = "";
@@ -11,6 +11,7 @@ import { registerVegaRoutes } from "./explore-vega.js";
11
11
  import { listKnowledgeNetworks } from "../api/knowledge-networks.js";
12
12
  import { listAgents } from "../api/agent-list.js";
13
13
  import { listVegaCatalogs } from "../api/vega.js";
14
+ import { renderHelp } from "../help/format.js";
14
15
  export function parseExploreArgs(args) {
15
16
  const opts = {
16
17
  knId: "",
@@ -47,21 +48,23 @@ export function parseExploreArgs(args) {
47
48
  return opts;
48
49
  }
49
50
  function printExploreHelp() {
50
- console.log(`kweaver explore
51
-
52
- Launch an interactive web UI for exploring KWeaver resources.
53
-
54
- Usage:
55
- kweaver explore [options]
56
-
57
- Options:
58
- --kn <id> Open directly to BKN tab with specified KN
59
- --agent <id> Open directly to Chat tab with specified Agent
60
- --port <n> HTTP server port (default: 3721)
61
- --no-open Don't auto-open browser
62
- -bd <value> Business domain override
63
- -h, --help Show this help
64
- `);
51
+ console.log(renderHelp({
52
+ tagline: "Launch interactive web UI for exploring KWeaver resources",
53
+ usage: "kweaver explore [flags]",
54
+ flags: [
55
+ { name: "--kn <id>", desc: "Open directly to BKN tab with specified KN" },
56
+ { name: "--agent <id>", desc: "Open directly to Chat tab with specified Agent" },
57
+ { name: "--port <n>", desc: "HTTP server port (default: 3721)" },
58
+ { name: "--no-open", desc: "Don't auto-open browser" },
59
+ { name: "-bd, --biz-domain <s>", desc: "Business domain override" },
60
+ ],
61
+ inheritedFlags: "--base-url, --token, --user, --help",
62
+ examples: [
63
+ "kweaver explore",
64
+ "kweaver explore --kn <kn-id> --port 4000",
65
+ "kweaver explore --agent <agent-id> --no-open",
66
+ ],
67
+ }));
65
68
  }
66
69
  // MIME map for static files
67
70
  const MIME = {
@@ -5,6 +5,7 @@ import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/
5
5
  import { resolveBusinessDomain } from "../config/store.js";
6
6
  import { addLlmModel, addSmallModel, deleteLlmModels, deleteSmallModels, editLlmModel, editSmallModel, getLlmModel, getSmallModel, listLlmModels, listSmallModels, testLlmModel, testSmallModel, } from "../api/models.js";
7
7
  import { modelChatCompletions, modelEmbeddings, modelRerank } from "../api/model-invocation.js";
8
+ import { renderHelp } from "../help/format.js";
8
9
  import { formatCallOutput } from "./call.js";
9
10
  const DEFAULT_LIST_LIMIT = 30;
10
11
  /** Strip global flags; fill default business domain. */
@@ -51,48 +52,58 @@ export function parseModelGlobalFlags(args) {
51
52
  return { rest, businessDomain, mfManagerBaseUrl, mfApiBaseUrl, pretty };
52
53
  }
53
54
  function printModelUsage() {
54
- console.log(`kweaver model
55
-
56
- Usage:
57
- kweaver model llm list [--keyword X] [--type llm|rlm|vu] [--series S] [--api-model M] [--page N] [--limit N] [--json] [-bd value]
58
- kweaver model llm get <model_id> [--json] [-bd value]
59
- kweaver model llm add --body-file <path.json> [--upstream-url <url>] [--api-model <id>] [--api-key <secret>|--api-key-file <path>] [--json] [-bd value]
60
- kweaver model llm edit [<model_id>] --body-file <path.json> [--upstream-url <url>] [--api-model <id>] [--api-key <secret>|--api-key-file <path>] [--json] [-bd value]
61
- (optional leading model_id overrides body.model_id after merge)
62
- OR: kweaver model llm edit <model_id> [sparse flags] (GET /llm/get then merge only flags you pass)
63
- Sparse flags: --name, --series, --type|-t, --max-model-len, --quota, --model-config-file, upstream flags (same as --body-file)
64
- kweaver model llm delete <model_id> [<model_id> ...] [-y] [-bd value]
65
- kweaver model llm test --body-file <path.json> [--upstream-url <url>] [--api-model <id>] [--api-key <secret>|--api-key-file <path>] [--json] [-bd value]
66
- kweaver model llm chat <model_id> (-m|--message) "text" [--model-name <registry_model_name>] [--skip-model-name-resolve] [--stream] [--no-stream] [--verbose] [--temperature N] [--max-tokens N] [--mf-api-base-url url] [-bd value]
67
- kweaver model llm --template [--json] (offline: bundled llm registration JSON stub)
68
-
69
- kweaver model small list [--name X] [--type embedding|reranker] [--series S] [--page N] [--limit N] [--json] [-bd value]
70
- kweaver model small get <model_id> [--json] [-bd value]
71
- kweaver model small add --name N --type embedding|reranker --batch-size N
72
- (--model-config-file <path.json> | --adapter --adapter-code-file <path.py>)
73
- [--upstream-url <url>] [--api-model <id>] [--api-key <secret>|--api-key-file <path>]
74
- [--max-tokens N] [--embedding-dim N] [--json] [-bd value]
75
- (embedding requires --max-tokens and --embedding-dim; upstream flags merge into model_config.api_* — not valid with --adapter)
76
- kweaver model small edit <model_id> [--body-file <path.json> | partial flags]
77
- (without --body-file: loads current model via GET, then applies only the flags you pass)
78
- kweaver model small delete <model_id> [<model_id> ...] [-y] [-bd value]
79
- kweaver model small test [--body-file <path.json>|<model_id>] [--json] [-bd value]
80
- kweaver model small embeddings <model_id> (-i|--input <text>) ... [--model-name <registry_model_name>] [--skip-model-name-resolve] [--mf-api-base-url url] [-bd value]
81
- (runtime: POST mf-model-api /small-model/embeddings like llm chat for vectors)
82
- kweaver model small rerank <model_id> (-q|--query) <text> (-d|--document <text>) ... [--model-name <registry_model_name>] [--skip-model-name-resolve] [--mf-api-base-url url] [-bd value]
83
- (runtime: POST mf-model-api /small-model/reranker)
84
- kweaver model small --template [--json] (offline: bundled small model_config JSON stub)
85
-
86
- Global:
87
- --mf-base-url <url> Override origin for mf-model-manager (default: KWEAVER_BASE_URL or KWEAVER_MF_MODEL_MANAGER_URL)
88
- --mf-api-base-url <url> Override origin for mf-model-api / chat (default: KWEAVER_BASE_URL or KWEAVER_MF_MODEL_API_URL)
89
- -bd, --biz-domain Business domain (default from config)
90
-
91
- Upstream secrets:
92
- Prefer --api-key-file over --api-key (shell history). For LLM add/edit/test, flags merge into body.model_config as api_url, api_model, api_key (creating model_config if missing). Small-model upstream flags merge into model_config the same way.
93
-
94
- Bundled templates:
95
- model llm --template | model small --template — print offline JSON stub (no auth).`);
55
+ console.log(renderHelp({
56
+ tagline: "Model factory — LLM / small-model CRUD (mf-model-manager) + runtime invocation (mf-model-api)",
57
+ usage: [
58
+ "kweaver model llm <subcommand> [flags]",
59
+ "kweaver model small <subcommand> [flags]",
60
+ ],
61
+ sections: [
62
+ {
63
+ title: "LLM",
64
+ items: [
65
+ { name: "list", desc: "List LLM models" },
66
+ { name: "get", desc: "Get an LLM model by id" },
67
+ { name: "add", desc: "Register an LLM model (--body-file or sparse flags)" },
68
+ { name: "edit", desc: "Update an LLM model (merge mode by default)" },
69
+ { name: "delete", desc: "Delete one or more LLM models" },
70
+ { name: "test", desc: "Run model registration self-test (mf-model-manager)" },
71
+ { name: "chat", desc: "OpenAI-compatible chat completion (mf-model-api)" },
72
+ { name: "--template", desc: "Print bundled LLM registration JSON stub (offline)" },
73
+ ],
74
+ },
75
+ {
76
+ title: "SMALL MODEL",
77
+ items: [
78
+ { name: "list", desc: "List small models (embedding / reranker)" },
79
+ { name: "get", desc: "Get a small model by id" },
80
+ { name: "add", desc: "Register a small model (--model-config-file | --adapter)" },
81
+ { name: "edit", desc: "Update a small model (sparse-merge or --body-file)" },
82
+ { name: "delete", desc: "Delete one or more small models" },
83
+ { name: "test", desc: "Run small-model registration self-test" },
84
+ { name: "embeddings", desc: "Runtime: POST mf-model-api /small-model/embeddings" },
85
+ { name: "rerank", desc: "Runtime: POST mf-model-api /small-model/reranker" },
86
+ { name: "--template", desc: "Print bundled small-model config JSON stub (offline)" },
87
+ ],
88
+ },
89
+ ],
90
+ flags: [
91
+ { name: "--mf-base-url <url>", desc: "Override mf-model-manager origin (env: KWEAVER_MF_MODEL_MANAGER_URL)" },
92
+ { name: "--mf-api-base-url <url>", desc: "Override mf-model-api origin (env: KWEAVER_MF_MODEL_API_URL)" },
93
+ { name: "-bd, --biz-domain <s>", desc: "Business domain (default from config)" },
94
+ { name: "--json", desc: "Print raw API JSON output" },
95
+ ],
96
+ inheritedFlags: "--base-url, --token, --user, --help",
97
+ examples: [
98
+ "kweaver model llm list --type llm --limit 20",
99
+ "kweaver model llm chat <model_id> -m \"hello\" --stream",
100
+ "kweaver model small embeddings <model_id> -i \"text\"",
101
+ ],
102
+ learnMore: [
103
+ "Upstream secrets: prefer --api-key-file over --api-key (shell history)",
104
+ "Use `kweaver help all` for full per-subcommand signatures",
105
+ ],
106
+ }));
96
107
  }
97
108
  async function printBundledModelBranchTemplate(branch, g) {
98
109
  try {
@@ -0,0 +1 @@
1
+ export declare function runResourceCommand(args: string[]): Promise<number>;
@@ -1,35 +1,39 @@
1
1
  import { createInterface } from "node:readline";
2
2
  import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
3
- import { deleteDataView, findDataView, getDataView, listDataViews, queryDataView, } from "../api/dataviews.js";
3
+ import { RESOURCE_LIST_DEFAULT_LIMIT, deleteResource, findResource, getResource, listResources, queryResource, } from "../api/resources.js";
4
4
  import { formatCallOutput } from "./call.js";
5
5
  import { resolveBusinessDomain } from "../config/store.js";
6
- /**
7
- * Strip SQL line/block comments and leading whitespace, then return the first identifier token (lowercase).
8
- * Used to reject DDL/DML passed to dataview query (server applies LIMIT semantics).
9
- */
10
- export function getFirstSqlTokenAfterComments(sql) {
11
- let s = sql.replace(/\/\*[\s\S]*?\*\//g, " ");
12
- const lines = s.split("\n").map((line) => {
13
- const idx = line.indexOf("--");
14
- return idx >= 0 ? line.slice(0, idx) : line;
15
- });
16
- s = lines.join("\n");
17
- s = s.replace(/\s+/g, " ").trim();
18
- if (!s)
19
- return "";
20
- const match = /^([a-zA-Z_][a-zA-Z0-9_]*|"(?:[^"]|"")*")/.exec(s);
21
- if (!match)
22
- return "";
23
- const tok = match[1];
24
- if (tok.startsWith('"'))
25
- return tok.slice(1, -1).replace(/""/g, '"').toLowerCase();
26
- return tok.toLowerCase();
27
- }
28
- /** True if ad-hoc SQL is safe for dataview query (SELECT / WITH only). */
29
- export function isDataviewSelectLikeSql(sql) {
30
- const kw = getFirstSqlTokenAfterComments(sql);
31
- return kw === "select" || kw === "with";
32
- }
6
+ import { renderHelp } from "../help/format.js";
7
+ const RESOURCE_HELP = renderHelp({
8
+ tagline: "Resources list, find, get, query, delete (vega-backend)",
9
+ usage: "kweaver resource <subcommand> [flags]",
10
+ sections: [
11
+ {
12
+ title: "AVAILABLE COMMANDS",
13
+ items: [
14
+ { name: "list", desc: "List resources under a catalog/datasource (default limit: 30)" },
15
+ { name: "find", desc: "Search by name; default fuzzy, --exact for strict, --wait to poll" },
16
+ { name: "get", desc: "Get resource details" },
17
+ { name: "query", desc: "Fetch data rows from a vega-backend resource" },
18
+ { name: "delete", desc: "Delete a resource" },
19
+ ],
20
+ },
21
+ ],
22
+ flags: [
23
+ { name: "-bd, --biz-domain <s>", desc: "Business domain (default: bd_public)" },
24
+ { name: "--pretty / --compact", desc: "JSON output style (default: pretty)" },
25
+ ],
26
+ inheritedFlags: "--base-url, --token, --user, --help",
27
+ examples: [
28
+ "kweaver resource list --datasource-id <id> --type table",
29
+ "kweaver resource find --name customers --exact",
30
+ "kweaver resource query <id> --limit 100",
31
+ ],
32
+ learnMore: [
33
+ "Alias: `kweaver res ...`",
34
+ "Use `kweaver resource <subcommand> --help` for flag details",
35
+ ],
36
+ });
33
37
  function confirmYes(prompt) {
34
38
  return new Promise((resolve) => {
35
39
  const rl = createInterface({ input: process.stdin, output: process.stdout });
@@ -40,41 +44,30 @@ function confirmYes(prompt) {
40
44
  });
41
45
  });
42
46
  }
43
- export async function runDataviewCommand(args) {
47
+ export async function runResourceCommand(args) {
44
48
  const [subcommand, ...rest] = args;
45
49
  if (!subcommand || subcommand === "--help" || subcommand === "-h") {
46
- console.log(`kweaver dataview
47
-
48
- Subcommands:
49
- list [--datasource-id <id>] [--type <atomic|custom>] [--limit <n>] [-bd value] [--pretty]
50
- find --name <name> [--exact] [--datasource-id <id>] [--wait] [--no-wait] [--timeout <ms>] [-bd value] [--pretty]
51
- get <id> [-bd value] [--pretty]
52
- query <id> [--sql <sql>] [--limit <n>] [--offset <n>] [--need-total] [-bd value] [--pretty]
53
- delete <id> [-y] [-bd value]
54
-
55
- list — list all data views (no keyword search)
56
- find — search by name; default fuzzy, --exact for strict match, --wait to poll
57
- query — run SQL query against a data view (mdl-uniquery); omit --sql to use view default SQL; only SELECT/WITH unless --raw-sql`);
50
+ console.log(RESOURCE_HELP);
58
51
  return 0;
59
52
  }
60
53
  const dispatch = () => {
61
54
  if (subcommand === "list")
62
- return runDataviewListCommand(rest);
55
+ return runResourceListCommand(rest);
63
56
  if (subcommand === "find")
64
- return runDataviewFindCommand(rest);
57
+ return runResourceFindCommand(rest);
65
58
  if (subcommand === "get")
66
- return runDataviewGetCommand(rest);
59
+ return runResourceGetCommand(rest);
67
60
  if (subcommand === "query")
68
- return runDataviewQueryCommand(rest);
61
+ return runResourceQueryCommand(rest);
69
62
  if (subcommand === "delete")
70
- return runDataviewDeleteCommand(rest);
63
+ return runResourceDeleteCommand(rest);
71
64
  return Promise.resolve(-1);
72
65
  };
73
66
  try {
74
67
  return await with401RefreshRetry(async () => {
75
68
  const code = await dispatch();
76
69
  if (code === -1) {
77
- console.error(`Unknown dataview subcommand: ${subcommand}`);
70
+ console.error(`Unknown resource subcommand: ${subcommand}`);
78
71
  return 1;
79
72
  }
80
73
  return code;
@@ -85,7 +78,7 @@ Subcommands:
85
78
  return 1;
86
79
  }
87
80
  }
88
- function parseDataviewCommonArgs(args) {
81
+ function parseResourceCommonArgs(args) {
89
82
  let businessDomain = "";
90
83
  let pretty = true;
91
84
  for (let i = 0; i < args.length; i += 1) {
@@ -103,11 +96,11 @@ function parseDataviewCommonArgs(args) {
103
96
  businessDomain = resolveBusinessDomain();
104
97
  return { businessDomain, pretty };
105
98
  }
106
- async function runDataviewListCommand(args) {
99
+ async function runResourceListCommand(args) {
107
100
  let datasourceId;
108
101
  let type;
109
- let limit;
110
- const { businessDomain, pretty } = parseDataviewCommonArgs(args);
102
+ let limit = RESOURCE_LIST_DEFAULT_LIMIT;
103
+ const { businessDomain, pretty } = parseResourceCommonArgs(args);
111
104
  for (let i = 0; i < args.length; i += 1) {
112
105
  const arg = args[i];
113
106
  if (arg === "-bd" || arg === "--biz-domain") {
@@ -132,24 +125,24 @@ async function runDataviewListCommand(args) {
132
125
  }
133
126
  }
134
127
  const token = await ensureValidToken();
135
- const views = await listDataViews({
128
+ const views = await listResources({
136
129
  baseUrl: token.baseUrl,
137
130
  accessToken: token.accessToken,
138
131
  businessDomain,
139
132
  datasourceId,
140
- type,
133
+ category: type,
141
134
  limit,
142
135
  });
143
136
  console.log(formatCallOutput(JSON.stringify(views), pretty));
144
137
  return 0;
145
138
  }
146
- async function runDataviewFindCommand(args) {
139
+ async function runResourceFindCommand(args) {
147
140
  let datasourceId;
148
141
  let name;
149
142
  let exact = false;
150
143
  let wait = false;
151
144
  let timeoutMs = 30_000;
152
- const { businessDomain, pretty } = parseDataviewCommonArgs(args);
145
+ const { businessDomain, pretty } = parseResourceCommonArgs(args);
153
146
  for (let i = 0; i < args.length; i += 1) {
154
147
  const arg = args[i];
155
148
  if (arg === "-bd" || arg === "--biz-domain") {
@@ -188,11 +181,11 @@ async function runDataviewFindCommand(args) {
188
181
  }
189
182
  }
190
183
  if (!name) {
191
- console.error("Usage: kweaver dataview find --name <name> [--exact] [--datasource-id <id>] [--wait] [--timeout <ms>] [-bd value] [--pretty]");
184
+ console.error("Usage: kweaver resource find --name <name> [--exact] [--datasource-id <id>] [--wait] [--timeout <ms>] [-bd value] [--pretty]");
192
185
  return 1;
193
186
  }
194
187
  const token = await ensureValidToken();
195
- const views = await findDataView({
188
+ const views = await findResource({
196
189
  baseUrl: token.baseUrl,
197
190
  accessToken: token.accessToken,
198
191
  businessDomain,
@@ -205,8 +198,8 @@ async function runDataviewFindCommand(args) {
205
198
  console.log(formatCallOutput(JSON.stringify(views), pretty));
206
199
  return 0;
207
200
  }
208
- async function runDataviewGetCommand(args) {
209
- const { businessDomain, pretty } = parseDataviewCommonArgs(args);
201
+ async function runResourceGetCommand(args) {
202
+ const { businessDomain, pretty } = parseResourceCommonArgs(args);
210
203
  let id = "";
211
204
  for (let i = 0; i < args.length; i += 1) {
212
205
  const arg = args[i];
@@ -222,11 +215,11 @@ async function runDataviewGetCommand(args) {
222
215
  }
223
216
  }
224
217
  if (!id) {
225
- console.error("Usage: kweaver dataview get <id> [-bd value] [--pretty]");
218
+ console.error("Usage: kweaver resource get <id> [-bd value] [--pretty]");
226
219
  return 1;
227
220
  }
228
221
  const token = await ensureValidToken();
229
- const view = await getDataView({
222
+ const view = await getResource({
230
223
  baseUrl: token.baseUrl,
231
224
  accessToken: token.accessToken,
232
225
  businessDomain,
@@ -235,15 +228,13 @@ async function runDataviewGetCommand(args) {
235
228
  console.log(formatCallOutput(JSON.stringify(view), pretty));
236
229
  return 0;
237
230
  }
238
- async function runDataviewQueryCommand(args) {
239
- const { businessDomain, pretty } = parseDataviewCommonArgs(args);
240
- let sql;
231
+ async function runResourceQueryCommand(args) {
232
+ const { businessDomain, pretty } = parseResourceCommonArgs(args);
241
233
  let limit = 50;
242
234
  let offset = 0;
243
235
  let needTotal = false;
244
- let rawSql = false;
245
236
  if (args.length === 0 || args[0].startsWith("-")) {
246
- console.error("Usage: kweaver dataview query <id> [--sql <sql>] [--limit <n>] [--offset <n>] [--need-total] [--raw-sql] [-bd value] [--pretty]");
237
+ console.error("Usage: kweaver resource query <id> [--limit <n>] [--offset <n>] [--need-total] [-bd value] [--pretty]");
247
238
  return 1;
248
239
  }
249
240
  const id = args[0];
@@ -256,14 +247,6 @@ async function runDataviewQueryCommand(args) {
256
247
  }
257
248
  if (arg === "--pretty")
258
249
  continue;
259
- if (arg === "--raw-sql") {
260
- rawSql = true;
261
- continue;
262
- }
263
- if ((arg === "--sql" || arg === "-s") && tail[i + 1]) {
264
- sql = tail[++i];
265
- continue;
266
- }
267
250
  if (arg === "--limit" && tail[i + 1]) {
268
251
  const n = Number.parseInt(tail[++i], 10);
269
252
  if (!Number.isNaN(n))
@@ -281,17 +264,12 @@ async function runDataviewQueryCommand(args) {
281
264
  continue;
282
265
  }
283
266
  }
284
- if (sql !== undefined && sql !== "" && !rawSql && !isDataviewSelectLikeSql(sql)) {
285
- console.error("dataview query only supports SELECT statements (or WITH for CTEs). Use --raw-sql to send other SQL at your own risk.");
286
- return 1;
287
- }
288
267
  const token = await ensureValidToken();
289
- const result = await queryDataView({
268
+ const result = await queryResource({
290
269
  baseUrl: token.baseUrl,
291
270
  accessToken: token.accessToken,
292
271
  businessDomain,
293
272
  id,
294
- sql,
295
273
  offset,
296
274
  limit,
297
275
  needTotal,
@@ -299,7 +277,7 @@ async function runDataviewQueryCommand(args) {
299
277
  console.log(formatCallOutput(JSON.stringify(result), pretty));
300
278
  return 0;
301
279
  }
302
- async function runDataviewDeleteCommand(args) {
280
+ async function runResourceDeleteCommand(args) {
303
281
  let id = "";
304
282
  let yes = false;
305
283
  let businessDomain = "";
@@ -317,18 +295,18 @@ async function runDataviewDeleteCommand(args) {
317
295
  if (!businessDomain)
318
296
  businessDomain = resolveBusinessDomain();
319
297
  if (!id) {
320
- console.error("Usage: kweaver dataview delete <id> [-y] [-bd value]");
298
+ console.error("Usage: kweaver resource delete <id> [-y] [-bd value]");
321
299
  return 1;
322
300
  }
323
301
  if (!yes) {
324
- const confirmed = await confirmYes("Are you sure you want to delete this data view?");
302
+ const confirmed = await confirmYes("Are you sure you want to delete this resource?");
325
303
  if (!confirmed) {
326
304
  console.error("Aborted.");
327
305
  return 1;
328
306
  }
329
307
  }
330
308
  const token = await ensureValidToken();
331
- await deleteDataView({
309
+ await deleteResource({
332
310
  baseUrl: token.baseUrl,
333
311
  accessToken: token.accessToken,
334
312
  businessDomain,