@kweaver-ai/kweaver-sdk 0.4.11 → 0.4.12

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
@@ -90,6 +90,29 @@ const graph = await client.bkn.querySubgraph("bkn-id", { /* path spec */ });
90
90
  await client.bkn.executeAction("bkn-id", "at-id", { /* params */ });
91
91
  const logs = await client.bkn.listActionLogs("bkn-id");
92
92
 
93
+ // Data sources & data views
94
+ const dsList = await client.datasources.list();
95
+ const tables = await client.datasources.listTables("ds-id");
96
+ const viewId = await client.dataviews.create({ name: "v", datasourceId: "ds-id", table: "orders" });
97
+ const views = await client.dataviews.list({ datasourceId: "ds-id" });
98
+ const fuzzy = await client.dataviews.find("BOM", { wait: false });
99
+ const exact = await client.dataviews.find("orders", {
100
+ datasourceId: "ds-id",
101
+ exact: true,
102
+ wait: true,
103
+ });
104
+ const dv = await client.dataviews.get(viewId);
105
+
106
+ // Dataflow automation (CSV import pipeline, etc.)
107
+ const result = await client.dataflows.execute({
108
+ title: "import", trigger_config: { operator: "manual" },
109
+ steps: [{ id: "s1", title: "load", operator: "csv_import", parameters: {} }],
110
+ });
111
+
112
+ // Vega observability
113
+ const catalogs = await client.vega.listCatalogs();
114
+ const health = await client.vega.health();
115
+
93
116
  // Context Loader (semantic search over a BKN via MCP)
94
117
  const cl = client.contextLoader(mcpUrl, "bkn-id");
95
118
  const results = await cl.search({ query: "hypertension treatment" });
@@ -100,14 +123,22 @@ const results = await cl.search({ query: "hypertension treatment" });
100
123
  ```
101
124
  kweaver auth login <url> [--alias name] [-u user] [-p pass] [--playwright] [--insecure|-k] — also: status, list, use, delete, logout
102
125
  kweaver token
126
+ kweaver config show / set-bd <value>
127
+ kweaver ds list/get/delete/tables/connect
128
+ kweaver ds import-csv <ds_id> --files <glob> [--table-prefix <p>] [--batch-size 500]
129
+ kweaver dataview list/find/get/delete
103
130
  kweaver bkn list/get/stats/export/create/update/delete
131
+ kweaver bkn create-from-ds <ds_id> --name <name> [--tables t1,t2] [--build]
132
+ kweaver bkn create-from-csv <ds_id> --files <glob> --name <name> [--build]
133
+ kweaver bkn validate/push/pull
104
134
  kweaver bkn object-type list/get/create/update/delete/query/properties
105
135
  kweaver bkn relation-type list/get/create/update/delete
106
136
  kweaver bkn action-type list/query/execute
107
- kweaver bkn subgraph
137
+ kweaver bkn subgraph / search
108
138
  kweaver bkn action-execution get
109
139
  kweaver bkn action-log list/get/cancel
110
- kweaver agent list/get/chat/sessions/history
140
+ kweaver agent list/get/create/update/delete/chat/sessions/history/publish/unpublish
141
+ kweaver vega health/stats/inspect/catalog/resource/connector-type
111
142
  kweaver context-loader config set/use/list/show
112
143
  kweaver context-loader kn-search/query-object-instance/...
113
144
  kweaver call <path> [-X METHOD] [-d BODY] [-H header]
package/README.zh.md CHANGED
@@ -90,6 +90,18 @@ const graph = await client.bkn.querySubgraph("bkn-id", { /* 路径规格 */
90
90
  await client.bkn.executeAction("bkn-id", "at-id", { /* 参数 */ });
91
91
  const logs = await client.bkn.listActionLogs("bkn-id");
92
92
 
93
+ // 数据源与数据视图
94
+ const dsList = await client.datasources.list();
95
+ const viewId = await client.dataviews.create({ name: "v", datasourceId: "ds-id", table: "orders" });
96
+ const views = await client.dataviews.list({ datasourceId: "ds-id" });
97
+ const fuzzy = await client.dataviews.find("BOM", { wait: false });
98
+ const exact = await client.dataviews.find("orders", {
99
+ datasourceId: "ds-id",
100
+ exact: true,
101
+ wait: true,
102
+ });
103
+ const dv = await client.dataviews.get(viewId);
104
+
93
105
  // Context Loader(通过 MCP 对 BKN 做语义搜索)
94
106
  const cl = client.contextLoader(mcpUrl, "bkn-id");
95
107
  const results = await cl.search({ query: "高血压 治疗" });
@@ -100,6 +112,8 @@ const results = await cl.search({ query: "高血压 治疗" });
100
112
  ```
101
113
  kweaver auth login <url> [--alias name] [-u user] [-p pass] [--playwright] [--insecure|-k] — 另有 status、list、use、delete、logout
102
114
  kweaver token
115
+ kweaver ds list/get/delete/tables/connect
116
+ kweaver dataview list/find/get/delete
103
117
  kweaver bkn list/get/stats/export/create/update/delete
104
118
  kweaver bkn object-type list/get/create/update/delete/query/properties
105
119
  kweaver bkn relation-type list/get/create/update/delete
@@ -1,3 +1,19 @@
1
+ /** Field metadata returned by the data-views API. */
2
+ export interface ViewField {
3
+ name: string;
4
+ type: string;
5
+ display_name?: string;
6
+ comment?: string;
7
+ }
8
+ /** Normalized data view model (mdl-data-model). */
9
+ export interface DataView {
10
+ id: string;
11
+ name: string;
12
+ query_type: string;
13
+ datasource_id: string;
14
+ fields: ViewField[];
15
+ }
16
+ export declare function parseDataView(raw: Record<string, unknown>): DataView;
1
17
  export interface CreateDataViewOptions {
2
18
  baseUrl: string;
3
19
  accessToken: string;
@@ -11,10 +27,51 @@ export interface CreateDataViewOptions {
11
27
  businessDomain?: string;
12
28
  }
13
29
  export declare function createDataView(options: CreateDataViewOptions): Promise<string>;
30
+ export interface ListDataViewsOptions {
31
+ baseUrl: string;
32
+ accessToken: string;
33
+ businessDomain?: string;
34
+ /** Filter by data source id. */
35
+ datasourceId?: string;
36
+ /** Server-side keyword filter (fuzzy). */
37
+ name?: string;
38
+ /** View type filter (e.g. atomic, custom). */
39
+ type?: string;
40
+ /** Max items; default -1 (all). */
41
+ limit?: number;
42
+ }
43
+ export declare function listDataViews(options: ListDataViewsOptions): Promise<DataView[]>;
44
+ export interface DeleteDataViewOptions {
45
+ baseUrl: string;
46
+ accessToken: string;
47
+ id: string;
48
+ businessDomain?: string;
49
+ }
50
+ export declare function deleteDataView(options: DeleteDataViewOptions): Promise<void>;
14
51
  export interface GetDataViewOptions {
15
52
  baseUrl: string;
16
53
  accessToken: string;
17
54
  id: string;
18
55
  businessDomain?: string;
19
56
  }
20
- export declare function getDataView(options: GetDataViewOptions): Promise<string>;
57
+ export declare function getDataView(options: GetDataViewOptions): Promise<DataView>;
58
+ export interface FindDataViewOptions {
59
+ baseUrl: string;
60
+ accessToken: string;
61
+ businessDomain?: string;
62
+ /** View name to search for (sent as keyword to server). */
63
+ name: string;
64
+ /** Filter by data source id. */
65
+ datasourceId?: string;
66
+ /** When true, apply client-side exact name match after keyword search (default false). */
67
+ exact?: boolean;
68
+ /** When true, poll until a result appears or timeout (default false). */
69
+ wait?: boolean;
70
+ /** Total wait budget in ms (default 30000). Only used when wait is true. */
71
+ timeoutMs?: number;
72
+ }
73
+ /**
74
+ * Find data views by name. Uses server-side keyword filtering; when `exact` is true,
75
+ * applies client-side `name ===` filter. Optional polling with exponential backoff.
76
+ */
77
+ export declare function findDataView(options: FindDataViewOptions): Promise<DataView[]>;
@@ -24,6 +24,41 @@ function extractViewId(data) {
24
24
  }
25
25
  return null;
26
26
  }
27
+ export function parseDataView(raw) {
28
+ const fieldsRaw = raw.fields;
29
+ const fields = [];
30
+ if (Array.isArray(fieldsRaw)) {
31
+ for (const f of fieldsRaw) {
32
+ if (f && typeof f === "object") {
33
+ const fr = f;
34
+ fields.push({
35
+ name: String(fr.name ?? ""),
36
+ type: String(fr.type ?? "varchar"),
37
+ display_name: fr.display_name != null ? String(fr.display_name) : undefined,
38
+ comment: fr.comment != null ? String(fr.comment) : undefined,
39
+ });
40
+ }
41
+ }
42
+ }
43
+ return {
44
+ id: String(raw.id ?? ""),
45
+ name: String(raw.name ?? ""),
46
+ query_type: String(raw.query_type ?? "SQL"),
47
+ datasource_id: String(raw.data_source_id ?? raw.group_id ?? ""),
48
+ fields,
49
+ };
50
+ }
51
+ function extractListPayload(data) {
52
+ if (Array.isArray(data))
53
+ return data;
54
+ if (data && typeof data === "object") {
55
+ const obj = data;
56
+ const items = obj.entries ?? obj.data;
57
+ if (Array.isArray(items))
58
+ return items;
59
+ }
60
+ return [];
61
+ }
27
62
  export async function createDataView(options) {
28
63
  const { baseUrl, accessToken, name, datasourceId, table, fields = [], businessDomain = "bd_public", } = options;
29
64
  const viewId = createHash("md5").update(`${datasourceId}:${table}`).digest("hex").slice(0, 35);
@@ -84,26 +119,56 @@ export async function createDataView(options) {
84
119
  return createdId ?? viewId;
85
120
  }
86
121
  async function findDataViewByName(options) {
87
- const base = options.baseUrl.replace(/\/+$/, "");
122
+ const list = await listDataViews({
123
+ baseUrl: options.baseUrl,
124
+ accessToken: options.accessToken,
125
+ businessDomain: options.businessDomain,
126
+ name: options.name,
127
+ });
128
+ const match = list.find((e) => e.name === options.name && e.datasource_id === options.groupId);
129
+ return match?.id ?? null;
130
+ }
131
+ export async function listDataViews(options) {
132
+ const { baseUrl, accessToken, businessDomain = "bd_public", datasourceId, name, type, limit = -1, } = options;
133
+ const base = baseUrl.replace(/\/+$/, "");
88
134
  const url = new URL(`${base}/api/mdl-data-model/v1/data-views`);
89
- url.searchParams.set("keyword", options.name);
135
+ url.searchParams.set("limit", String(limit));
136
+ if (datasourceId)
137
+ url.searchParams.set("data_source_id", datasourceId);
138
+ if (name)
139
+ url.searchParams.set("keyword", name);
140
+ if (type)
141
+ url.searchParams.set("type", type);
90
142
  const response = await fetch(url.toString(), {
91
143
  method: "GET",
92
- headers: buildHeaders(options.accessToken, options.businessDomain),
144
+ headers: buildHeaders(accessToken, businessDomain),
93
145
  });
94
- if (!response.ok)
95
- return null;
96
- const body = JSON.parse(await response.text());
97
- const match = body.entries?.find((e) => e.name === options.name && e.group_id === options.groupId);
98
- return match?.id ?? null;
146
+ const bodyText = await response.text();
147
+ if (!response.ok) {
148
+ throw new HttpError(response.status, response.statusText, bodyText);
149
+ }
150
+ const parsed = JSON.parse(bodyText);
151
+ const items = extractListPayload(parsed);
152
+ const out = [];
153
+ for (const item of items) {
154
+ if (item && typeof item === "object") {
155
+ out.push(parseDataView(item));
156
+ }
157
+ }
158
+ return out;
99
159
  }
100
- async function deleteDataView(options) {
101
- const base = options.baseUrl.replace(/\/+$/, "");
102
- const url = `${base}/api/mdl-data-model/v1/data-views/${encodeURIComponent(options.id)}`;
103
- await fetch(url, {
160
+ export async function deleteDataView(options) {
161
+ const { baseUrl, accessToken, id, businessDomain = "bd_public" } = options;
162
+ const base = baseUrl.replace(/\/+$/, "");
163
+ const url = `${base}/api/mdl-data-model/v1/data-views/${encodeURIComponent(id)}`;
164
+ const response = await fetch(url, {
104
165
  method: "DELETE",
105
- headers: buildHeaders(options.accessToken, options.businessDomain),
166
+ headers: buildHeaders(accessToken, businessDomain),
106
167
  });
168
+ const bodyText = await response.text();
169
+ if (!response.ok) {
170
+ throw new HttpError(response.status, response.statusText, bodyText);
171
+ }
107
172
  }
108
173
  export async function getDataView(options) {
109
174
  const { baseUrl, accessToken, id, businessDomain = "bd_public", } = options;
@@ -117,5 +182,40 @@ export async function getDataView(options) {
117
182
  if (!response.ok) {
118
183
  throw new HttpError(response.status, response.statusText, body);
119
184
  }
120
- return body;
185
+ let parsed = JSON.parse(body);
186
+ if (Array.isArray(parsed) && parsed.length > 0) {
187
+ parsed = parsed[0];
188
+ }
189
+ if (!parsed || typeof parsed !== "object") {
190
+ throw new HttpError(500, "Invalid response", body);
191
+ }
192
+ return parseDataView(parsed);
193
+ }
194
+ function sleepMs(ms) {
195
+ return new Promise((resolve) => setTimeout(resolve, ms));
196
+ }
197
+ /**
198
+ * Find data views by name. Uses server-side keyword filtering; when `exact` is true,
199
+ * applies client-side `name ===` filter. Optional polling with exponential backoff.
200
+ */
201
+ export async function findDataView(options) {
202
+ const { baseUrl, accessToken, businessDomain = "bd_public", name, datasourceId, exact = false, wait = false, timeoutMs = 30_000, } = options;
203
+ const deadline = Date.now() + timeoutMs;
204
+ let attempt = 0;
205
+ while (true) {
206
+ const list = await listDataViews({
207
+ baseUrl,
208
+ accessToken,
209
+ businessDomain,
210
+ datasourceId,
211
+ name,
212
+ limit: -1,
213
+ });
214
+ const results = exact ? list.filter((v) => v.name === name) : list;
215
+ if (results.length > 0 || !wait || Date.now() >= deadline)
216
+ return results;
217
+ const delayMs = Math.min(5000, 1000 * 2 ** attempt);
218
+ attempt += 1;
219
+ await sleepMs(delayMs);
220
+ }
121
221
  }
package/dist/cli.js CHANGED
@@ -6,6 +6,7 @@ import { runCallCommand } from "./commands/call.js";
6
6
  import { runConfigCommand } from "./commands/config.js";
7
7
  import { runContextLoaderCommand } from "./commands/context-loader.js";
8
8
  import { runDsCommand } from "./commands/ds.js";
9
+ import { runDataviewCommand } from "./commands/dataview.js";
9
10
  import { runTokenCommand } from "./commands/token.js";
10
11
  import { runVegaCommand } from "./commands/vega.js";
11
12
  function printHelp() {
@@ -47,6 +48,11 @@ Usage:
47
48
  kweaver ds tables <id> [--keyword X] [--pretty]
48
49
  kweaver ds connect <db_type> <host> <port> <database> --account X --password Y [--schema S] [--name N]
49
50
 
51
+ kweaver dataview list [--datasource-id id] [--type atomic|custom] [--limit n] [-bd value] [--pretty]
52
+ kweaver dataview find --name <name> [--exact] [--datasource-id id] [--wait] [--timeout ms] [-bd value] [--pretty]
53
+ kweaver dataview get <id> [-bd value] [--pretty]
54
+ kweaver dataview delete <id> [-y] [-bd value]
55
+
50
56
  kweaver bkn list [options]
51
57
  kweaver bkn get <kn-id> [options]
52
58
  kweaver bkn search <kn-id> <query> [--max-concepts N] [--mode M] [--pretty] [-bd value]
@@ -90,6 +96,7 @@ Commands:
90
96
  call (curl) Call an API with curl-style flags and auto-injected token headers
91
97
  agent Agent CRUD, chat, sessions, history, publish/unpublish
92
98
  ds Manage datasources (list, get, delete, tables, connect)
99
+ dataview List, find, get, delete data views (atomic / custom)
93
100
  bkn Knowledge network (CRUD, build, validate, export, stats, push/pull,
94
101
  object-type, relation-type, subgraph, action-type, action-execution, action-log)
95
102
  config Per-platform configuration (business domain)
@@ -120,6 +127,9 @@ export async function run(argv) {
120
127
  if (command === "ds") {
121
128
  return runDsCommand(rest);
122
129
  }
130
+ if (command === "dataview") {
131
+ return runDataviewCommand(rest);
132
+ }
123
133
  if (command === "token") {
124
134
  return runTokenCommand(rest);
125
135
  }
package/dist/client.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  import { AgentsResource } from "./resources/agents.js";
2
2
  import { ConversationsResource } from "./resources/conversations.js";
3
3
  import { ContextLoaderResource } from "./resources/context-loader.js";
4
+ import { DataflowsResource } from "./resources/dataflows.js";
5
+ import { DataSourcesResource } from "./resources/datasources.js";
6
+ import { DataViewsResource } from "./resources/dataviews.js";
4
7
  import { KnowledgeNetworksResource } from "./resources/knowledge-networks.js";
5
8
  import { BknResource } from "./resources/bkn.js";
9
+ import { VegaResource } from "./resources/vega.js";
6
10
  /**
7
11
  * Shared credentials passed to every resource method.
8
12
  * Internal — use KWeaverClient.
@@ -78,6 +82,14 @@ export declare class KWeaverClient implements ClientContext {
78
82
  readonly bkn: BknResource;
79
83
  /** Conversation and message history. */
80
84
  readonly conversations: ConversationsResource;
85
+ /** Dataflow DAG automation (create/run/poll/delete). */
86
+ readonly dataflows: DataflowsResource;
87
+ /** Data source management (connect, test, list tables). */
88
+ readonly datasources: DataSourcesResource;
89
+ /** Data view creation and retrieval. */
90
+ readonly dataviews: DataViewsResource;
91
+ /** Vega observability platform (catalogs, resources, connector types). */
92
+ readonly vega: VegaResource;
81
93
  constructor(opts?: KWeaverClientOptions);
82
94
  /**
83
95
  * Async factory that auto-refreshes expired or revoked tokens.
package/dist/client.js CHANGED
@@ -4,8 +4,12 @@ import { ensureValidToken } from "./auth/oauth.js";
4
4
  import { AgentsResource } from "./resources/agents.js";
5
5
  import { ConversationsResource } from "./resources/conversations.js";
6
6
  import { ContextLoaderResource } from "./resources/context-loader.js";
7
+ import { DataflowsResource } from "./resources/dataflows.js";
8
+ import { DataSourcesResource } from "./resources/datasources.js";
9
+ import { DataViewsResource } from "./resources/dataviews.js";
7
10
  import { KnowledgeNetworksResource } from "./resources/knowledge-networks.js";
8
11
  import { BknResource } from "./resources/bkn.js";
12
+ import { VegaResource } from "./resources/vega.js";
9
13
  // ── KWeaverClient ─────────────────────────────────────────────────────────────
10
14
  /**
11
15
  * Main entry point for the KWeaver TypeScript SDK.
@@ -47,6 +51,14 @@ export class KWeaverClient {
47
51
  bkn;
48
52
  /** Conversation and message history. */
49
53
  conversations;
54
+ /** Dataflow DAG automation (create/run/poll/delete). */
55
+ dataflows;
56
+ /** Data source management (connect, test, list tables). */
57
+ datasources;
58
+ /** Data view creation and retrieval. */
59
+ dataviews;
60
+ /** Vega observability platform (catalogs, resources, connector types). */
61
+ vega;
50
62
  constructor(opts = {}) {
51
63
  const envDomain = process.env.KWEAVER_BUSINESS_DOMAIN;
52
64
  let baseUrl;
@@ -98,6 +110,10 @@ export class KWeaverClient {
98
110
  this.agents = new AgentsResource(this);
99
111
  this.bkn = new BknResource(this);
100
112
  this.conversations = new ConversationsResource(this);
113
+ this.dataflows = new DataflowsResource(this);
114
+ this.datasources = new DataSourcesResource(this);
115
+ this.dataviews = new DataViewsResource(this);
116
+ this.vega = new VegaResource(this);
101
117
  }
102
118
  /**
103
119
  * Async factory that auto-refreshes expired or revoked tokens.
@@ -9,7 +9,7 @@ import { listKnowledgeNetworks, getKnowledgeNetwork, createKnowledgeNetwork, upd
9
9
  import { objectTypeQuery, objectTypeProperties, subgraph, actionTypeQuery, actionTypeExecute, actionExecutionGet, actionLogsList, actionLogGet, actionLogCancel, } from "../api/ontology-query.js";
10
10
  import { semanticSearch } from "../api/semantic-search.js";
11
11
  import { listTablesWithColumns, scanMetadata, getDatasource } from "../api/datasources.js";
12
- import { createDataView } from "../api/dataviews.js"; // used by runKnCreateFromDsCommand
12
+ import { createDataView, findDataView } from "../api/dataviews.js"; // used by runKnCreateFromDsCommand
13
13
  import { downloadBkn, uploadBkn } from "../api/bkn-backend.js";
14
14
  import { formatCallOutput } from "./call.js";
15
15
  import { resolveBusinessDomain } from "../config/store.js";
@@ -2195,13 +2195,21 @@ async function runKnCreateFromDsCommand(args, sampleRows) {
2195
2195
  console.error(`Creating data views for ${targetTables.length} table(s) ...`);
2196
2196
  const viewMap = {};
2197
2197
  for (const t of targetTables) {
2198
- const dvId = await createDataView({
2198
+ const found = await findDataView({
2199
2199
  ...base,
2200
2200
  name: t.name,
2201
2201
  datasourceId: options.dsId,
2202
- table: t.name,
2203
- fields: t.columns.map((c) => ({ name: c.name, type: c.type })),
2202
+ exact: true,
2203
+ wait: true,
2204
2204
  });
2205
+ const dvId = found[0]?.id ??
2206
+ (await createDataView({
2207
+ ...base,
2208
+ name: t.name,
2209
+ datasourceId: options.dsId,
2210
+ table: t.name,
2211
+ fields: t.columns.map((c) => ({ name: c.name, type: c.type })),
2212
+ }));
2205
2213
  viewMap[t.name] = dvId;
2206
2214
  }
2207
2215
  // Phase 2: Create the KN record
@@ -0,0 +1 @@
1
+ export declare function runDataviewCommand(args: string[]): Promise<number>;
@@ -0,0 +1,244 @@
1
+ import { createInterface } from "node:readline";
2
+ import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
3
+ import { deleteDataView, findDataView, getDataView, listDataViews, } from "../api/dataviews.js";
4
+ import { formatCallOutput } from "./call.js";
5
+ import { resolveBusinessDomain } from "../config/store.js";
6
+ function confirmYes(prompt) {
7
+ return new Promise((resolve) => {
8
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
9
+ rl.question(`${prompt} [y/N] `, (answer) => {
10
+ rl.close();
11
+ const trimmed = answer.trim().toLowerCase();
12
+ resolve(trimmed === "y" || trimmed === "yes");
13
+ });
14
+ });
15
+ }
16
+ export async function runDataviewCommand(args) {
17
+ const [subcommand, ...rest] = args;
18
+ if (!subcommand || subcommand === "--help" || subcommand === "-h") {
19
+ console.log(`kweaver dataview
20
+
21
+ Subcommands:
22
+ list [--datasource-id <id>] [--type <atomic|custom>] [--limit <n>] [-bd value] [--pretty]
23
+ find --name <name> [--exact] [--datasource-id <id>] [--wait] [--no-wait] [--timeout <ms>] [-bd value] [--pretty]
24
+ get <id> [-bd value] [--pretty]
25
+ delete <id> [-y] [-bd value]
26
+
27
+ list — list all data views (no keyword search)
28
+ find — search by name; default fuzzy, --exact for strict match, --wait to poll`);
29
+ return 0;
30
+ }
31
+ const dispatch = () => {
32
+ if (subcommand === "list")
33
+ return runDataviewListCommand(rest);
34
+ if (subcommand === "find")
35
+ return runDataviewFindCommand(rest);
36
+ if (subcommand === "get")
37
+ return runDataviewGetCommand(rest);
38
+ if (subcommand === "delete")
39
+ return runDataviewDeleteCommand(rest);
40
+ return Promise.resolve(-1);
41
+ };
42
+ try {
43
+ return await with401RefreshRetry(async () => {
44
+ const code = await dispatch();
45
+ if (code === -1) {
46
+ console.error(`Unknown dataview subcommand: ${subcommand}`);
47
+ return 1;
48
+ }
49
+ return code;
50
+ });
51
+ }
52
+ catch (error) {
53
+ console.error(formatHttpError(error));
54
+ return 1;
55
+ }
56
+ }
57
+ function parseDataviewCommonArgs(args) {
58
+ let businessDomain = "";
59
+ let pretty = true;
60
+ for (let i = 0; i < args.length; i += 1) {
61
+ const arg = args[i];
62
+ if ((arg === "-bd" || arg === "--biz-domain") && args[i + 1]) {
63
+ businessDomain = args[++i];
64
+ continue;
65
+ }
66
+ if (arg === "--pretty") {
67
+ pretty = true;
68
+ continue;
69
+ }
70
+ }
71
+ if (!businessDomain)
72
+ businessDomain = resolveBusinessDomain();
73
+ return { businessDomain, pretty };
74
+ }
75
+ async function runDataviewListCommand(args) {
76
+ let datasourceId;
77
+ let type;
78
+ let limit;
79
+ const { businessDomain, pretty } = parseDataviewCommonArgs(args);
80
+ for (let i = 0; i < args.length; i += 1) {
81
+ const arg = args[i];
82
+ if (arg === "-bd" || arg === "--biz-domain") {
83
+ i += 1;
84
+ continue;
85
+ }
86
+ if (arg === "--pretty")
87
+ continue;
88
+ if (arg === "--datasource-id" && args[i + 1]) {
89
+ datasourceId = args[++i];
90
+ continue;
91
+ }
92
+ if (arg === "--type" && args[i + 1]) {
93
+ type = args[++i];
94
+ continue;
95
+ }
96
+ if (arg === "--limit" && args[i + 1]) {
97
+ const n = Number.parseInt(args[++i], 10);
98
+ if (!Number.isNaN(n))
99
+ limit = n;
100
+ continue;
101
+ }
102
+ }
103
+ const token = await ensureValidToken();
104
+ const views = await listDataViews({
105
+ baseUrl: token.baseUrl,
106
+ accessToken: token.accessToken,
107
+ businessDomain,
108
+ datasourceId,
109
+ type,
110
+ limit,
111
+ });
112
+ console.log(formatCallOutput(JSON.stringify(views), pretty));
113
+ return 0;
114
+ }
115
+ async function runDataviewFindCommand(args) {
116
+ let datasourceId;
117
+ let name;
118
+ let exact = false;
119
+ let wait = false;
120
+ let timeoutMs = 30_000;
121
+ const { businessDomain, pretty } = parseDataviewCommonArgs(args);
122
+ for (let i = 0; i < args.length; i += 1) {
123
+ const arg = args[i];
124
+ if (arg === "-bd" || arg === "--biz-domain") {
125
+ i += 1;
126
+ continue;
127
+ }
128
+ if (arg === "--pretty")
129
+ continue;
130
+ if (arg === "--datasource-id" && args[i + 1]) {
131
+ datasourceId = args[++i];
132
+ continue;
133
+ }
134
+ if (arg === "--name" && args[i + 1]) {
135
+ name = args[++i];
136
+ continue;
137
+ }
138
+ if (arg === "--exact") {
139
+ exact = true;
140
+ continue;
141
+ }
142
+ if (arg === "--wait") {
143
+ wait = true;
144
+ continue;
145
+ }
146
+ if (arg === "--no-wait") {
147
+ wait = false;
148
+ continue;
149
+ }
150
+ if (arg === "--timeout" && args[i + 1]) {
151
+ timeoutMs = Number(args[++i]);
152
+ if (Number.isNaN(timeoutMs) || timeoutMs < 0) {
153
+ console.error("Invalid --timeout value");
154
+ return 1;
155
+ }
156
+ continue;
157
+ }
158
+ }
159
+ if (!name) {
160
+ console.error("Usage: kweaver dataview find --name <name> [--exact] [--datasource-id <id>] [--wait] [--timeout <ms>] [-bd value] [--pretty]");
161
+ return 1;
162
+ }
163
+ const token = await ensureValidToken();
164
+ const views = await findDataView({
165
+ baseUrl: token.baseUrl,
166
+ accessToken: token.accessToken,
167
+ businessDomain,
168
+ name,
169
+ datasourceId,
170
+ exact,
171
+ wait,
172
+ timeoutMs,
173
+ });
174
+ console.log(formatCallOutput(JSON.stringify(views), pretty));
175
+ return 0;
176
+ }
177
+ async function runDataviewGetCommand(args) {
178
+ const { businessDomain, pretty } = parseDataviewCommonArgs(args);
179
+ let id = "";
180
+ for (let i = 0; i < args.length; i += 1) {
181
+ const arg = args[i];
182
+ if (arg === "-bd" || arg === "--biz-domain") {
183
+ i += 1;
184
+ continue;
185
+ }
186
+ if (arg === "--pretty")
187
+ continue;
188
+ if (!arg.startsWith("-")) {
189
+ id = arg;
190
+ break;
191
+ }
192
+ }
193
+ if (!id) {
194
+ console.error("Usage: kweaver dataview get <id> [-bd value] [--pretty]");
195
+ return 1;
196
+ }
197
+ const token = await ensureValidToken();
198
+ const view = await getDataView({
199
+ baseUrl: token.baseUrl,
200
+ accessToken: token.accessToken,
201
+ businessDomain,
202
+ id,
203
+ });
204
+ console.log(formatCallOutput(JSON.stringify(view), pretty));
205
+ return 0;
206
+ }
207
+ async function runDataviewDeleteCommand(args) {
208
+ let id = "";
209
+ let yes = false;
210
+ let businessDomain = "";
211
+ for (let i = 0; i < args.length; i += 1) {
212
+ const arg = args[i];
213
+ if (arg === "--yes" || arg === "-y")
214
+ yes = true;
215
+ else if ((arg === "-bd" || arg === "--biz-domain") && args[i + 1]) {
216
+ businessDomain = args[++i];
217
+ continue;
218
+ }
219
+ else if (!arg.startsWith("-"))
220
+ id = arg;
221
+ }
222
+ if (!businessDomain)
223
+ businessDomain = resolveBusinessDomain();
224
+ if (!id) {
225
+ console.error("Usage: kweaver dataview delete <id> [-y] [-bd value]");
226
+ return 1;
227
+ }
228
+ if (!yes) {
229
+ const confirmed = await confirmYes("Are you sure you want to delete this data view?");
230
+ if (!confirmed) {
231
+ console.error("Aborted.");
232
+ return 1;
233
+ }
234
+ }
235
+ const token = await ensureValidToken();
236
+ await deleteDataView({
237
+ baseUrl: token.baseUrl,
238
+ accessToken: token.accessToken,
239
+ businessDomain,
240
+ id,
241
+ });
242
+ console.error(`Deleted ${id}`);
243
+ return 0;
244
+ }
package/dist/index.d.ts CHANGED
@@ -49,6 +49,9 @@ export type { AgentConfig, AgentInput, AgentInputField, AgentOutput, AgentLlmCon
49
49
  export { BknResource } from "./resources/bkn.js";
50
50
  export { ConversationsResource } from "./resources/conversations.js";
51
51
  export { ContextLoaderResource } from "./resources/context-loader.js";
52
+ export type { ViewField, DataView, CreateDataViewOptions, GetDataViewOptions, ListDataViewsOptions, DeleteDataViewOptions, FindDataViewOptions, } from "./api/dataviews.js";
53
+ export { parseDataView, createDataView, getDataView, listDataViews, deleteDataView, findDataView, } from "./api/dataviews.js";
54
+ export { DataViewsResource } from "./resources/dataviews.js";
52
55
  export { HttpError, NetworkRequestError, fetchTextOrThrow } from "./utils/http.js";
53
56
  export type { TokenConfig, ContextLoaderEntry, ContextLoaderConfig, } from "./config/store.js";
54
57
  export { getConfigDir, getCurrentPlatform } from "./config/store.js";
package/dist/index.js CHANGED
@@ -39,6 +39,8 @@ export { AgentsResource } from "./resources/agents.js";
39
39
  export { BknResource } from "./resources/bkn.js";
40
40
  export { ConversationsResource } from "./resources/conversations.js";
41
41
  export { ContextLoaderResource } from "./resources/context-loader.js";
42
+ export { parseDataView, createDataView, getDataView, listDataViews, deleteDataView, findDataView, } from "./api/dataviews.js";
43
+ export { DataViewsResource } from "./resources/dataviews.js";
42
44
  // ── HTTP utilities ────────────────────────────────────────────────────────────
43
45
  export { HttpError, NetworkRequestError, fetchTextOrThrow } from "./utils/http.js";
44
46
  export { getConfigDir, getCurrentPlatform } from "./config/store.js";
@@ -0,0 +1,17 @@
1
+ import { type DataflowCreateBody, type DataflowResult } from "../api/dataflow.js";
2
+ import type { ClientContext } from "../client.js";
3
+ export declare class DataflowsResource {
4
+ private readonly ctx;
5
+ constructor(ctx: ClientContext);
6
+ create(body: DataflowCreateBody): Promise<string>;
7
+ run(dagId: string): Promise<void>;
8
+ poll(dagId: string, opts?: {
9
+ interval?: number;
10
+ timeout?: number;
11
+ }): Promise<DataflowResult>;
12
+ delete(dagId: string): Promise<void>;
13
+ execute(body: DataflowCreateBody, opts?: {
14
+ interval?: number;
15
+ timeout?: number;
16
+ }): Promise<DataflowResult>;
17
+ }
@@ -0,0 +1,22 @@
1
+ import { createDataflow, runDataflow, pollDataflowResults, deleteDataflow, executeDataflow, } from "../api/dataflow.js";
2
+ export class DataflowsResource {
3
+ ctx;
4
+ constructor(ctx) {
5
+ this.ctx = ctx;
6
+ }
7
+ async create(body) {
8
+ return createDataflow({ ...this.ctx.base(), body });
9
+ }
10
+ async run(dagId) {
11
+ return runDataflow({ ...this.ctx.base(), dagId });
12
+ }
13
+ async poll(dagId, opts = {}) {
14
+ return pollDataflowResults({ ...this.ctx.base(), dagId, ...opts });
15
+ }
16
+ async delete(dagId) {
17
+ return deleteDataflow({ ...this.ctx.base(), dagId });
18
+ }
19
+ async execute(body, opts = {}) {
20
+ return executeDataflow({ ...this.ctx.base(), body, ...opts });
21
+ }
22
+ }
@@ -0,0 +1,52 @@
1
+ import type { ClientContext } from "../client.js";
2
+ export declare class DataSourcesResource {
3
+ private readonly ctx;
4
+ constructor(ctx: ClientContext);
5
+ test(opts: {
6
+ type: string;
7
+ host: string;
8
+ port: number;
9
+ database: string;
10
+ account: string;
11
+ password: string;
12
+ schema?: string;
13
+ }): Promise<void>;
14
+ create(opts: {
15
+ name: string;
16
+ type: string;
17
+ host: string;
18
+ port: number;
19
+ database: string;
20
+ account: string;
21
+ password: string;
22
+ schema?: string;
23
+ comment?: string;
24
+ }): Promise<unknown>;
25
+ list(opts?: {
26
+ keyword?: string;
27
+ type?: string;
28
+ }): Promise<unknown[]>;
29
+ get(id: string): Promise<unknown>;
30
+ delete(id: string): Promise<void>;
31
+ listTables(id: string, opts?: {
32
+ keyword?: string;
33
+ limit?: number;
34
+ offset?: number;
35
+ }): Promise<unknown[]>;
36
+ listTablesWithColumns(id: string, opts?: {
37
+ keyword?: string;
38
+ limit?: number;
39
+ offset?: number;
40
+ autoScan?: boolean;
41
+ }): Promise<Array<{
42
+ name: string;
43
+ columns: Array<{
44
+ name: string;
45
+ type: string;
46
+ comment?: string;
47
+ }>;
48
+ }>>;
49
+ scanMetadata(id: string, opts?: {
50
+ dsType?: string;
51
+ }): Promise<string>;
52
+ }
@@ -0,0 +1,54 @@
1
+ import { testDatasource, createDatasource, listDatasources, getDatasource, deleteDatasource, listTables, listTablesWithColumns, scanMetadata, } from "../api/datasources.js";
2
+ export class DataSourcesResource {
3
+ ctx;
4
+ constructor(ctx) {
5
+ this.ctx = ctx;
6
+ }
7
+ async test(opts) {
8
+ await testDatasource({ ...this.ctx.base(), ...opts });
9
+ }
10
+ async create(opts) {
11
+ const raw = await createDatasource({ ...this.ctx.base(), ...opts });
12
+ return JSON.parse(raw);
13
+ }
14
+ async list(opts = {}) {
15
+ const raw = await listDatasources({ ...this.ctx.base(), ...opts });
16
+ const parsed = JSON.parse(raw);
17
+ if (Array.isArray(parsed))
18
+ return parsed;
19
+ if (parsed && typeof parsed === "object") {
20
+ const obj = parsed;
21
+ const items = obj.entries ?? obj.data ?? obj.records;
22
+ if (Array.isArray(items))
23
+ return items;
24
+ }
25
+ return [];
26
+ }
27
+ async get(id) {
28
+ const raw = await getDatasource({ ...this.ctx.base(), id });
29
+ return JSON.parse(raw);
30
+ }
31
+ async delete(id) {
32
+ await deleteDatasource({ ...this.ctx.base(), id });
33
+ }
34
+ async listTables(id, opts = {}) {
35
+ const raw = await listTables({ ...this.ctx.base(), id, ...opts });
36
+ const parsed = JSON.parse(raw);
37
+ if (Array.isArray(parsed))
38
+ return parsed;
39
+ if (parsed && typeof parsed === "object") {
40
+ const obj = parsed;
41
+ const items = obj.entries ?? obj.data;
42
+ if (Array.isArray(items))
43
+ return items;
44
+ }
45
+ return [];
46
+ }
47
+ async listTablesWithColumns(id, opts = {}) {
48
+ const raw = await listTablesWithColumns({ ...this.ctx.base(), id, ...opts });
49
+ return JSON.parse(raw);
50
+ }
51
+ async scanMetadata(id, opts = {}) {
52
+ return scanMetadata({ ...this.ctx.base(), id, ...opts });
53
+ }
54
+ }
@@ -0,0 +1,28 @@
1
+ import type { DataView } from "../api/dataviews.js";
2
+ import type { ClientContext } from "../client.js";
3
+ export declare class DataViewsResource {
4
+ private readonly ctx;
5
+ constructor(ctx: ClientContext);
6
+ create(opts: {
7
+ name: string;
8
+ datasourceId: string;
9
+ table: string;
10
+ fields?: Array<{
11
+ name: string;
12
+ type: string;
13
+ }>;
14
+ }): Promise<string>;
15
+ get(id: string): Promise<DataView>;
16
+ list(opts?: {
17
+ datasourceId?: string;
18
+ type?: string;
19
+ limit?: number;
20
+ }): Promise<DataView[]>;
21
+ find(name: string, opts?: {
22
+ datasourceId?: string;
23
+ exact?: boolean;
24
+ wait?: boolean;
25
+ timeoutMs?: number;
26
+ }): Promise<DataView[]>;
27
+ delete(id: string): Promise<void>;
28
+ }
@@ -0,0 +1,34 @@
1
+ import { createDataView, deleteDataView, findDataView, getDataView, listDataViews, } from "../api/dataviews.js";
2
+ export class DataViewsResource {
3
+ ctx;
4
+ constructor(ctx) {
5
+ this.ctx = ctx;
6
+ }
7
+ async create(opts) {
8
+ return createDataView({ ...this.ctx.base(), ...opts });
9
+ }
10
+ async get(id) {
11
+ return getDataView({ ...this.ctx.base(), id });
12
+ }
13
+ async list(opts = {}) {
14
+ return listDataViews({
15
+ ...this.ctx.base(),
16
+ datasourceId: opts.datasourceId,
17
+ type: opts.type,
18
+ limit: opts.limit,
19
+ });
20
+ }
21
+ async find(name, opts) {
22
+ return findDataView({
23
+ ...this.ctx.base(),
24
+ name,
25
+ datasourceId: opts?.datasourceId,
26
+ exact: opts?.exact,
27
+ wait: opts?.wait,
28
+ timeoutMs: opts?.timeoutMs,
29
+ });
30
+ }
31
+ async delete(id) {
32
+ await deleteDataView({ ...this.ctx.base(), id });
33
+ }
34
+ }
@@ -0,0 +1,41 @@
1
+ import type { ClientContext } from "../client.js";
2
+ export declare class VegaResource {
3
+ private readonly ctx;
4
+ constructor(ctx: ClientContext);
5
+ health(): Promise<unknown>;
6
+ listCatalogs(opts?: {
7
+ status?: string;
8
+ limit?: number;
9
+ offset?: number;
10
+ }): Promise<unknown[]>;
11
+ getCatalog(id: string): Promise<unknown>;
12
+ catalogHealthStatus(ids: string): Promise<unknown>;
13
+ testCatalogConnection(id: string): Promise<unknown>;
14
+ discoverCatalog(id: string, opts?: {
15
+ wait?: boolean;
16
+ }): Promise<unknown>;
17
+ listCatalogResources(id: string, opts?: {
18
+ category?: string;
19
+ limit?: number;
20
+ offset?: number;
21
+ }): Promise<unknown[]>;
22
+ listResources(opts?: {
23
+ catalogId?: string;
24
+ category?: string;
25
+ status?: string;
26
+ limit?: number;
27
+ offset?: number;
28
+ }): Promise<unknown[]>;
29
+ getResource(id: string): Promise<unknown>;
30
+ queryResourceData(id: string, body: string): Promise<unknown>;
31
+ previewResource(id: string, opts?: {
32
+ limit?: number;
33
+ }): Promise<unknown>;
34
+ listConnectorTypes(): Promise<unknown[]>;
35
+ getConnectorType(type: string): Promise<unknown>;
36
+ listDiscoverTasks(opts?: {
37
+ status?: string;
38
+ limit?: number;
39
+ offset?: number;
40
+ }): Promise<unknown[]>;
41
+ }
@@ -0,0 +1,80 @@
1
+ import { vegaHealth, listVegaCatalogs, getVegaCatalog, vegaCatalogHealthStatus, testVegaCatalogConnection, discoverVegaCatalog, listVegaCatalogResources, listVegaResources, getVegaResource, queryVegaResourceData, previewVegaResource, listVegaConnectorTypes, getVegaConnectorType, listVegaDiscoverTasks, } from "../api/vega.js";
2
+ function unwrapArray(raw) {
3
+ const parsed = JSON.parse(raw);
4
+ if (Array.isArray(parsed))
5
+ return parsed;
6
+ if (parsed && typeof parsed === "object") {
7
+ const obj = parsed;
8
+ const items = obj.entries ?? obj.data ?? obj.records;
9
+ if (Array.isArray(items))
10
+ return items;
11
+ }
12
+ return [];
13
+ }
14
+ export class VegaResource {
15
+ ctx;
16
+ constructor(ctx) {
17
+ this.ctx = ctx;
18
+ }
19
+ // ── Health ──────────────────────────────────────────────────────────────────
20
+ async health() {
21
+ const raw = await vegaHealth(this.ctx.base());
22
+ return JSON.parse(raw);
23
+ }
24
+ // ── Catalogs ────────────────────────────────────────────────────────────────
25
+ async listCatalogs(opts = {}) {
26
+ const raw = await listVegaCatalogs({ ...this.ctx.base(), ...opts });
27
+ return unwrapArray(raw);
28
+ }
29
+ async getCatalog(id) {
30
+ const raw = await getVegaCatalog({ ...this.ctx.base(), id });
31
+ return JSON.parse(raw);
32
+ }
33
+ async catalogHealthStatus(ids) {
34
+ const raw = await vegaCatalogHealthStatus({ ...this.ctx.base(), ids });
35
+ return JSON.parse(raw);
36
+ }
37
+ async testCatalogConnection(id) {
38
+ const raw = await testVegaCatalogConnection({ ...this.ctx.base(), id });
39
+ return JSON.parse(raw);
40
+ }
41
+ async discoverCatalog(id, opts = {}) {
42
+ const raw = await discoverVegaCatalog({ ...this.ctx.base(), id, ...opts });
43
+ return JSON.parse(raw);
44
+ }
45
+ async listCatalogResources(id, opts = {}) {
46
+ const raw = await listVegaCatalogResources({ ...this.ctx.base(), id, ...opts });
47
+ return unwrapArray(raw);
48
+ }
49
+ // ── Resources ───────────────────────────────────────────────────────────────
50
+ async listResources(opts = {}) {
51
+ const raw = await listVegaResources({ ...this.ctx.base(), ...opts });
52
+ return unwrapArray(raw);
53
+ }
54
+ async getResource(id) {
55
+ const raw = await getVegaResource({ ...this.ctx.base(), id });
56
+ return JSON.parse(raw);
57
+ }
58
+ async queryResourceData(id, body) {
59
+ const raw = await queryVegaResourceData({ ...this.ctx.base(), id, body });
60
+ return JSON.parse(raw);
61
+ }
62
+ async previewResource(id, opts = {}) {
63
+ const raw = await previewVegaResource({ ...this.ctx.base(), id, ...opts });
64
+ return JSON.parse(raw);
65
+ }
66
+ // ── Connector Types ─────────────────────────────────────────────────────────
67
+ async listConnectorTypes() {
68
+ const raw = await listVegaConnectorTypes(this.ctx.base());
69
+ return unwrapArray(raw);
70
+ }
71
+ async getConnectorType(type) {
72
+ const raw = await getVegaConnectorType({ ...this.ctx.base(), type });
73
+ return JSON.parse(raw);
74
+ }
75
+ // ── Discover Tasks ──────────────────────────────────────────────────────────
76
+ async listDiscoverTasks(opts = {}) {
77
+ const raw = await listVegaDiscoverTasks({ ...this.ctx.base(), ...opts });
78
+ return unwrapArray(raw);
79
+ }
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kweaver-ai/kweaver-sdk",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "description": "KWeaver TypeScript SDK — CLI tool and programmatic API for knowledge networks and Decision Agents.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",