@kweaver-ai/kweaver-sdk 0.5.0 → 0.5.2
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 +6 -1
- package/README.zh.md +5 -0
- package/dist/api/agent-chat.d.ts +1 -1
- package/dist/api/agent-chat.js +4 -4
- package/dist/api/agent-list.d.ts +35 -0
- package/dist/api/agent-list.js +86 -12
- package/dist/api/bkn-backend.d.ts +60 -0
- package/dist/api/bkn-backend.js +103 -10
- package/dist/api/conversations.d.ts +6 -3
- package/dist/api/conversations.js +26 -27
- package/dist/api/dataflow.js +1 -10
- package/dist/api/datasources.js +1 -10
- package/dist/api/dataviews.js +1 -10
- package/dist/api/headers.d.ts +9 -0
- package/dist/api/headers.js +25 -0
- package/dist/api/knowledge-networks.d.ts +41 -0
- package/dist/api/knowledge-networks.js +69 -22
- package/dist/api/ontology-query.d.ts +14 -1
- package/dist/api/ontology-query.js +63 -49
- package/dist/api/semantic-search.js +2 -12
- package/dist/api/skills.d.ts +141 -0
- package/dist/api/skills.js +216 -0
- package/dist/api/vega.d.ts +63 -0
- package/dist/api/vega.js +131 -10
- package/dist/auth/oauth.d.ts +5 -1
- package/dist/auth/oauth.js +293 -94
- package/dist/cli.js +29 -4
- package/dist/client.d.ts +3 -0
- package/dist/client.js +4 -0
- package/dist/commands/agent.d.ts +33 -1
- package/dist/commands/agent.js +721 -49
- package/dist/commands/auth.js +211 -21
- package/dist/commands/bkn-ops.d.ts +77 -0
- package/dist/commands/bkn-ops.js +1056 -0
- package/dist/commands/bkn-query.d.ts +14 -0
- package/dist/commands/bkn-query.js +370 -0
- package/dist/commands/bkn-schema.d.ts +135 -0
- package/dist/commands/bkn-schema.js +1461 -0
- package/dist/commands/bkn-utils.d.ts +36 -0
- package/dist/commands/bkn-utils.js +102 -0
- package/dist/commands/bkn.d.ts +7 -113
- package/dist/commands/bkn.js +175 -2429
- package/dist/commands/dataview.d.ts +7 -0
- package/dist/commands/dataview.js +38 -2
- package/dist/commands/ds.d.ts +1 -0
- package/dist/commands/ds.js +8 -1
- package/dist/commands/import-csv.d.ts +2 -0
- package/dist/commands/import-csv.js +3 -2
- package/dist/commands/skill.d.ts +26 -0
- package/dist/commands/skill.js +524 -0
- package/dist/commands/vega.js +371 -14
- package/dist/config/jwt.d.ts +6 -0
- package/dist/config/jwt.js +21 -0
- package/dist/config/store.d.ts +37 -5
- package/dist/config/store.js +363 -30
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -1
- package/dist/resources/bkn.d.ts +4 -0
- package/dist/resources/bkn.js +4 -0
- package/dist/resources/conversations.d.ts +5 -2
- package/dist/resources/conversations.js +17 -3
- package/dist/resources/skills.d.ts +47 -0
- package/dist/resources/skills.js +47 -0
- package/dist/resources/vega.d.ts +11 -0
- package/dist/resources/vega.js +37 -1
- package/package.json +1 -1
|
@@ -1 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strip SQL line/block comments and leading whitespace, then return the first identifier token (lowercase).
|
|
3
|
+
* Used to reject DDL/DML passed to dataview query (server applies LIMIT semantics).
|
|
4
|
+
*/
|
|
5
|
+
export declare function getFirstSqlTokenAfterComments(sql: string): string;
|
|
6
|
+
/** True if ad-hoc SQL is safe for dataview query (SELECT / WITH only). */
|
|
7
|
+
export declare function isDataviewSelectLikeSql(sql: string): boolean;
|
|
1
8
|
export declare function runDataviewCommand(args: string[]): Promise<number>;
|
|
@@ -3,6 +3,33 @@ import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/
|
|
|
3
3
|
import { deleteDataView, findDataView, getDataView, listDataViews, queryDataView, } from "../api/dataviews.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
33
|
function confirmYes(prompt) {
|
|
7
34
|
return new Promise((resolve) => {
|
|
8
35
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
@@ -27,7 +54,7 @@ Subcommands:
|
|
|
27
54
|
|
|
28
55
|
list — list all data views (no keyword search)
|
|
29
56
|
find — search by name; default fuzzy, --exact for strict match, --wait to poll
|
|
30
|
-
query — run SQL query against a data view (mdl-uniquery); omit --sql to use view default SQL`);
|
|
57
|
+
query — run SQL query against a data view (mdl-uniquery); omit --sql to use view default SQL; only SELECT/WITH unless --raw-sql`);
|
|
31
58
|
return 0;
|
|
32
59
|
}
|
|
33
60
|
const dispatch = () => {
|
|
@@ -214,8 +241,9 @@ async function runDataviewQueryCommand(args) {
|
|
|
214
241
|
let limit = 50;
|
|
215
242
|
let offset = 0;
|
|
216
243
|
let needTotal = false;
|
|
244
|
+
let rawSql = false;
|
|
217
245
|
if (args.length === 0 || args[0].startsWith("-")) {
|
|
218
|
-
console.error("Usage: kweaver dataview query <id> [--sql <sql>] [--limit <n>] [--offset <n>] [--need-total] [-bd value] [--pretty]");
|
|
246
|
+
console.error("Usage: kweaver dataview query <id> [--sql <sql>] [--limit <n>] [--offset <n>] [--need-total] [--raw-sql] [-bd value] [--pretty]");
|
|
219
247
|
return 1;
|
|
220
248
|
}
|
|
221
249
|
const id = args[0];
|
|
@@ -228,6 +256,10 @@ async function runDataviewQueryCommand(args) {
|
|
|
228
256
|
}
|
|
229
257
|
if (arg === "--pretty")
|
|
230
258
|
continue;
|
|
259
|
+
if (arg === "--raw-sql") {
|
|
260
|
+
rawSql = true;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
231
263
|
if ((arg === "--sql" || arg === "-s") && tail[i + 1]) {
|
|
232
264
|
sql = tail[++i];
|
|
233
265
|
continue;
|
|
@@ -249,6 +281,10 @@ async function runDataviewQueryCommand(args) {
|
|
|
249
281
|
continue;
|
|
250
282
|
}
|
|
251
283
|
}
|
|
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
|
+
}
|
|
252
288
|
const token = await ensureValidToken();
|
|
253
289
|
const result = await queryDataView({
|
|
254
290
|
baseUrl: token.baseUrl,
|
package/dist/commands/ds.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare function parseImportCsvArgs(args: string[]): {
|
|
|
11
11
|
tablePrefix: string;
|
|
12
12
|
batchSize: number;
|
|
13
13
|
businessDomain: string;
|
|
14
|
+
recreate: boolean;
|
|
14
15
|
};
|
|
15
16
|
export declare function resolveFiles(pattern: string): Promise<string[]>;
|
|
16
17
|
export interface ImportCsvResult {
|
package/dist/commands/ds.js
CHANGED
|
@@ -306,6 +306,7 @@ Options:
|
|
|
306
306
|
--files <s> CSV file paths (comma-separated or glob pattern, required)
|
|
307
307
|
--table-prefix <s> Table name prefix (default: none)
|
|
308
308
|
--batch-size <n> Rows per batch (default: 500, range: 1-10000)
|
|
309
|
+
--recreate First batch uses overwrite (drop/recreate table) then append; use when schema changed
|
|
309
310
|
-bd, --biz-domain Business domain (default: bd_public)`;
|
|
310
311
|
export function parseImportCsvArgs(args) {
|
|
311
312
|
let datasourceId = "";
|
|
@@ -313,6 +314,7 @@ export function parseImportCsvArgs(args) {
|
|
|
313
314
|
let tablePrefix = "";
|
|
314
315
|
let batchSize = 500;
|
|
315
316
|
let businessDomain = "";
|
|
317
|
+
let recreate = false;
|
|
316
318
|
for (let i = 0; i < args.length; i += 1) {
|
|
317
319
|
const arg = args[i];
|
|
318
320
|
if (arg === "--help" || arg === "-h")
|
|
@@ -321,6 +323,10 @@ export function parseImportCsvArgs(args) {
|
|
|
321
323
|
files = args[++i];
|
|
322
324
|
continue;
|
|
323
325
|
}
|
|
326
|
+
if (arg === "--recreate") {
|
|
327
|
+
recreate = true;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
324
330
|
if (arg === "--table-prefix" && args[i + 1]) {
|
|
325
331
|
tablePrefix = args[++i];
|
|
326
332
|
continue;
|
|
@@ -343,7 +349,7 @@ export function parseImportCsvArgs(args) {
|
|
|
343
349
|
}
|
|
344
350
|
if (!businessDomain)
|
|
345
351
|
businessDomain = resolveBusinessDomain();
|
|
346
|
-
return { datasourceId, files, tablePrefix, batchSize, businessDomain };
|
|
352
|
+
return { datasourceId, files, tablePrefix, batchSize, businessDomain, recreate };
|
|
347
353
|
}
|
|
348
354
|
export async function resolveFiles(pattern) {
|
|
349
355
|
const parts = pattern.split(",").map((p) => p.trim()).filter(Boolean);
|
|
@@ -446,6 +452,7 @@ export async function runDsImportCsv(args) {
|
|
|
446
452
|
tableExist,
|
|
447
453
|
data: batch,
|
|
448
454
|
fieldMappings,
|
|
455
|
+
recreate: options.recreate,
|
|
449
456
|
});
|
|
450
457
|
const t0 = Date.now();
|
|
451
458
|
process.stderr.write(`[${tableName}] batch ${batchLabel} (${rowCount} rows)... `);
|
|
@@ -19,6 +19,8 @@ export interface DagBodyOptions {
|
|
|
19
19
|
tableExist: boolean;
|
|
20
20
|
data: Array<Record<string, string | null>>;
|
|
21
21
|
fieldMappings: FieldMapping[];
|
|
22
|
+
/** When true on the first batch (`tableExist` false), use overwrite to drop/recreate table before import. */
|
|
23
|
+
recreate?: boolean;
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* Read a CSV file and return its headers and rows.
|
|
@@ -80,8 +80,9 @@ export function buildFieldMappings(headers) {
|
|
|
80
80
|
* The DAG has two steps: a manual trigger and the database write.
|
|
81
81
|
*/
|
|
82
82
|
export function buildDagBody(options) {
|
|
83
|
-
const { datasourceId, datasourceType, tableName, tableExist, data, fieldMappings } = options;
|
|
83
|
+
const { datasourceId, datasourceType, tableName, tableExist, data, fieldMappings, recreate } = options;
|
|
84
84
|
const ts = Date.now();
|
|
85
|
+
const operateType = tableExist ? "append" : recreate ? "overwrite" : "append";
|
|
85
86
|
const triggerStep = {
|
|
86
87
|
id: "step-trigger",
|
|
87
88
|
title: "Trigger",
|
|
@@ -97,7 +98,7 @@ export function buildDagBody(options) {
|
|
|
97
98
|
datasource_id: datasourceId,
|
|
98
99
|
table_name: tableName,
|
|
99
100
|
table_exist: tableExist,
|
|
100
|
-
operate_type:
|
|
101
|
+
operate_type: operateType,
|
|
101
102
|
data,
|
|
102
103
|
sync_model_fields: fieldMappings,
|
|
103
104
|
},
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type SkillStatus } from "../api/skills.js";
|
|
2
|
+
interface BaseOptions {
|
|
3
|
+
businessDomain: string;
|
|
4
|
+
pretty: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface ListOptions extends BaseOptions {
|
|
7
|
+
page: number;
|
|
8
|
+
pageSize: number;
|
|
9
|
+
all: boolean;
|
|
10
|
+
name?: string;
|
|
11
|
+
source?: string;
|
|
12
|
+
status?: SkillStatus;
|
|
13
|
+
createUser?: string;
|
|
14
|
+
sortBy?: "create_time" | "update_time" | "name";
|
|
15
|
+
sortOrder?: "asc" | "desc";
|
|
16
|
+
}
|
|
17
|
+
interface RegisterOptions extends BaseOptions {
|
|
18
|
+
contentFile?: string;
|
|
19
|
+
zipFile?: string;
|
|
20
|
+
source?: string;
|
|
21
|
+
extendInfo?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
export declare function parseSkillListArgs(args: string[]): ListOptions;
|
|
24
|
+
export declare function parseSkillRegisterArgs(args: string[]): RegisterOptions;
|
|
25
|
+
export declare function runSkillCommand(args: string[]): Promise<number>;
|
|
26
|
+
export {};
|