@kweaver-ai/kweaver-sdk 0.5.1 → 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 +130 -10
- package/dist/auth/oauth.d.ts +5 -1
- package/dist/auth/oauth.js +293 -94
- package/dist/cli.js +28 -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 +156 -33
- 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
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface PollOptions<T> {
|
|
2
|
+
fn: () => Promise<{
|
|
3
|
+
done: boolean;
|
|
4
|
+
value: T;
|
|
5
|
+
}>;
|
|
6
|
+
interval: number;
|
|
7
|
+
timeout: number;
|
|
8
|
+
maxInterval?: number;
|
|
9
|
+
_sleep?: (ms: number) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function pollWithBackoff<T>(opts: PollOptions<T>): Promise<T>;
|
|
12
|
+
export declare function parseJsonObject(text: string, errorMessage: string): Record<string, unknown>;
|
|
13
|
+
export declare function parseSearchAfterArray(text: string): unknown[];
|
|
14
|
+
/** Parse common flags for ontology-query subcommands; returns { filteredArgs, pretty, businessDomain } */
|
|
15
|
+
export declare function parseOntologyQueryFlags(args: string[]): {
|
|
16
|
+
filteredArgs: string[];
|
|
17
|
+
pretty: boolean;
|
|
18
|
+
businessDomain: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const DISPLAY_HINTS: string[];
|
|
21
|
+
/** Detect primary key: first column (left-to-right) with all unique values in the sample. */
|
|
22
|
+
export declare function detectPrimaryKey(table: {
|
|
23
|
+
name: string;
|
|
24
|
+
columns: Array<{
|
|
25
|
+
name: string;
|
|
26
|
+
type: string;
|
|
27
|
+
}>;
|
|
28
|
+
}, rows?: Array<Record<string, string | null>>): string;
|
|
29
|
+
export declare function detectDisplayKey(table: {
|
|
30
|
+
name: string;
|
|
31
|
+
columns: Array<{
|
|
32
|
+
name: string;
|
|
33
|
+
type: string;
|
|
34
|
+
}>;
|
|
35
|
+
}, primaryKey: string): string;
|
|
36
|
+
export declare function confirmYes(prompt: string): Promise<boolean>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { resolveBusinessDomain } from "../config/store.js";
|
|
3
|
+
export async function pollWithBackoff(opts) {
|
|
4
|
+
const { fn, timeout, maxInterval = 15000, _sleep = (ms) => new Promise(r => setTimeout(r, ms)) } = opts;
|
|
5
|
+
let currentInterval = opts.interval;
|
|
6
|
+
const deadline = Date.now() + timeout;
|
|
7
|
+
while (Date.now() < deadline) {
|
|
8
|
+
const result = await fn();
|
|
9
|
+
if (result.done)
|
|
10
|
+
return result.value;
|
|
11
|
+
await _sleep(currentInterval);
|
|
12
|
+
currentInterval = Math.min(currentInterval * 2, maxInterval);
|
|
13
|
+
}
|
|
14
|
+
throw new Error(`Polling timed out after ${timeout}ms`);
|
|
15
|
+
}
|
|
16
|
+
// ── JSON parsing helpers ─────────────────────────────────────────────────────
|
|
17
|
+
export function parseJsonObject(text, errorMessage) {
|
|
18
|
+
let parsed;
|
|
19
|
+
try {
|
|
20
|
+
parsed = JSON.parse(text);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw new Error(errorMessage);
|
|
24
|
+
}
|
|
25
|
+
if (!parsed || Array.isArray(parsed) || typeof parsed !== "object") {
|
|
26
|
+
throw new Error(errorMessage);
|
|
27
|
+
}
|
|
28
|
+
return parsed;
|
|
29
|
+
}
|
|
30
|
+
export function parseSearchAfterArray(text) {
|
|
31
|
+
let parsed;
|
|
32
|
+
try {
|
|
33
|
+
parsed = JSON.parse(text);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new Error("Invalid value for --search-after. Expected a JSON array string.");
|
|
37
|
+
}
|
|
38
|
+
if (!Array.isArray(parsed)) {
|
|
39
|
+
throw new Error("Invalid value for --search-after. Expected a JSON array string.");
|
|
40
|
+
}
|
|
41
|
+
return parsed;
|
|
42
|
+
}
|
|
43
|
+
// ── Ontology query flag parsing ──────────────────────────────────────────────
|
|
44
|
+
/** Parse common flags for ontology-query subcommands; returns { filteredArgs, pretty, businessDomain } */
|
|
45
|
+
export function parseOntologyQueryFlags(args) {
|
|
46
|
+
let pretty = true;
|
|
47
|
+
let businessDomain = "";
|
|
48
|
+
const filteredArgs = [];
|
|
49
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
50
|
+
const arg = args[i];
|
|
51
|
+
if (arg === "--help" || arg === "-h") {
|
|
52
|
+
throw new Error("help");
|
|
53
|
+
}
|
|
54
|
+
if (arg === "--pretty") {
|
|
55
|
+
pretty = true;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if ((arg === "-bd" || arg === "--biz-domain") && args[i + 1]) {
|
|
59
|
+
businessDomain = args[i + 1];
|
|
60
|
+
i += 1;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
filteredArgs.push(arg);
|
|
64
|
+
}
|
|
65
|
+
if (!businessDomain)
|
|
66
|
+
businessDomain = resolveBusinessDomain();
|
|
67
|
+
return { filteredArgs, pretty, businessDomain };
|
|
68
|
+
}
|
|
69
|
+
// ── Schema detection helpers ─────────────────────────────────────────────────
|
|
70
|
+
export const DISPLAY_HINTS = ["name", "title", "label", "display_name", "description"];
|
|
71
|
+
/** Detect primary key: first column (left-to-right) with all unique values in the sample. */
|
|
72
|
+
export function detectPrimaryKey(table, rows) {
|
|
73
|
+
if (rows && rows.length > 0) {
|
|
74
|
+
for (const col of table.columns) {
|
|
75
|
+
const values = rows.map((r) => r[col.name]);
|
|
76
|
+
const unique = new Set(values);
|
|
77
|
+
if (unique.size === rows.length)
|
|
78
|
+
return col.name;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Fallback: first column
|
|
82
|
+
return table.columns[0]?.name ?? "id";
|
|
83
|
+
}
|
|
84
|
+
export function detectDisplayKey(table, primaryKey) {
|
|
85
|
+
for (const col of table.columns) {
|
|
86
|
+
if (DISPLAY_HINTS.some((h) => col.name.toLowerCase().includes(h))) {
|
|
87
|
+
return col.name;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return primaryKey;
|
|
91
|
+
}
|
|
92
|
+
// ── Interactive confirmation ─────────────────────────────────────────────────
|
|
93
|
+
export function confirmYes(prompt) {
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
96
|
+
rl.question(`${prompt} [y/N] `, (answer) => {
|
|
97
|
+
rl.close();
|
|
98
|
+
const trimmed = answer.trim().toLowerCase();
|
|
99
|
+
resolve(trimmed === "y" || trimmed === "yes");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
package/dist/commands/bkn.d.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
timeout: number;
|
|
9
|
-
maxInterval?: number;
|
|
10
|
-
_sleep?: (ms: number) => Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export declare function pollWithBackoff<T>(opts: PollOptions<T>): Promise<T>;
|
|
1
|
+
export { pollWithBackoff, parseOntologyQueryFlags, parseJsonObject, parseSearchAfterArray, confirmYes, DISPLAY_HINTS, detectPrimaryKey, detectDisplayKey, } from "./bkn-utils.js";
|
|
2
|
+
export type { PollOptions } from "./bkn-utils.js";
|
|
3
|
+
export { parseObjectTypeCreateArgs, finalizeObjectTypeCreateFromDataview, ensureMappedFieldOnDataProperty, normalizeAdpFieldType, parseKnObjectTypeQueryArgs, parseKnActionTypeExecuteArgs, parseRelationTypeCreateArgs, applyObjectTypeMerge, stripObjectTypeForPut, parseObjectTypeUpdateArgs, parseObjectTypeDeleteArgs, parseRelationTypeUpdateArgs, parseRelationTypeDeleteArgs, runKnObjectTypeCommand, runKnRelationTypeCommand, runKnActionTypeCommand, parseConceptGroupArgs, } from "./bkn-schema.js";
|
|
4
|
+
export type { KnObjectTypeQueryOptions, KnActionTypeExecuteOptions, ObjectTypeMergeFields, ObjectTypeUpdateParsed, ObjectTypeCreateParsed, } from "./bkn-schema.js";
|
|
5
|
+
export { parseKnSearchArgs } from "./bkn-query.js";
|
|
6
|
+
export { parseKnBuildArgs, parseKnPushArgs, parseKnPullArgs, packDirectoryToTar, extractTarToDirectory, parseActionScheduleArgs, parseJobArgs, } from "./bkn-ops.js";
|
|
7
|
+
export type { KnPushOptions, KnPullOptions } from "./bkn-ops.js";
|
|
13
8
|
export interface KnListOptions {
|
|
14
9
|
offset: number;
|
|
15
10
|
limit: number;
|
|
@@ -53,105 +48,4 @@ export interface KnDeleteOptions {
|
|
|
53
48
|
yes: boolean;
|
|
54
49
|
}
|
|
55
50
|
export declare function parseKnDeleteArgs(args: string[]): KnDeleteOptions;
|
|
56
|
-
export interface KnPushOptions {
|
|
57
|
-
directory: string;
|
|
58
|
-
branch: string;
|
|
59
|
-
businessDomain: string;
|
|
60
|
-
pretty: boolean;
|
|
61
|
-
encodingOptions: BknEncodingImportOptions;
|
|
62
|
-
}
|
|
63
|
-
export declare function parseKnPushArgs(args: string[]): KnPushOptions;
|
|
64
|
-
export interface KnPullOptions {
|
|
65
|
-
knId: string;
|
|
66
|
-
directory: string;
|
|
67
|
-
branch: string;
|
|
68
|
-
businessDomain: string;
|
|
69
|
-
}
|
|
70
|
-
export declare function parseKnPullArgs(args: string[]): KnPullOptions;
|
|
71
|
-
export interface KnObjectTypeQueryOptions {
|
|
72
|
-
knId: string;
|
|
73
|
-
otId: string;
|
|
74
|
-
body: string;
|
|
75
|
-
pretty: boolean;
|
|
76
|
-
businessDomain: string;
|
|
77
|
-
}
|
|
78
|
-
export declare function parseKnObjectTypeQueryArgs(args: string[]): KnObjectTypeQueryOptions;
|
|
79
51
|
export declare function runKnCommand(args: string[]): Promise<number>;
|
|
80
|
-
/** Parse object-type create args: --name --dataview-id --primary-key --display-key [--property '<json>' ...] */
|
|
81
|
-
export declare function parseObjectTypeCreateArgs(args: string[]): {
|
|
82
|
-
knId: string;
|
|
83
|
-
body: string;
|
|
84
|
-
businessDomain: string;
|
|
85
|
-
branch: string;
|
|
86
|
-
pretty: boolean;
|
|
87
|
-
};
|
|
88
|
-
/** Fields merged via GET → modify → PUT (not raw body mode). */
|
|
89
|
-
export interface ObjectTypeMergeFields {
|
|
90
|
-
name?: string;
|
|
91
|
-
displayKey?: string;
|
|
92
|
-
addProperties: Record<string, unknown>[];
|
|
93
|
-
removeProperties: string[];
|
|
94
|
-
tags?: string[];
|
|
95
|
-
comment?: string;
|
|
96
|
-
icon?: string;
|
|
97
|
-
color?: string;
|
|
98
|
-
}
|
|
99
|
-
export type ObjectTypeUpdateParsed = {
|
|
100
|
-
mode: "body";
|
|
101
|
-
knId: string;
|
|
102
|
-
otId: string;
|
|
103
|
-
body: string;
|
|
104
|
-
businessDomain: string;
|
|
105
|
-
pretty: boolean;
|
|
106
|
-
} | {
|
|
107
|
-
mode: "merge";
|
|
108
|
-
knId: string;
|
|
109
|
-
otId: string;
|
|
110
|
-
merge: ObjectTypeMergeFields;
|
|
111
|
-
businessDomain: string;
|
|
112
|
-
pretty: boolean;
|
|
113
|
-
branch: string;
|
|
114
|
-
};
|
|
115
|
-
/** Prepare a GET response entry for PUT (drop read-only fields). */
|
|
116
|
-
export declare function stripObjectTypeForPut(entry: Record<string, unknown>): Record<string, unknown>;
|
|
117
|
-
/**
|
|
118
|
-
* Apply merge flags onto a stripped object-type object (mutates copy).
|
|
119
|
-
* - Add: property `name` not in list → append.
|
|
120
|
-
* - Update: property `name` exists → replace entry (same as add; CLI also accepts `--update-property`).
|
|
121
|
-
* - Delete: `--remove-property` removes by `name` before adds are applied.
|
|
122
|
-
*/
|
|
123
|
-
export declare function applyObjectTypeMerge(target: Record<string, unknown>, merge: ObjectTypeMergeFields): Record<string, unknown>;
|
|
124
|
-
export interface KnActionTypeExecuteOptions {
|
|
125
|
-
knId: string;
|
|
126
|
-
atId: string;
|
|
127
|
-
body: string;
|
|
128
|
-
pretty: boolean;
|
|
129
|
-
businessDomain: string;
|
|
130
|
-
wait: boolean;
|
|
131
|
-
timeout: number;
|
|
132
|
-
}
|
|
133
|
-
export declare function parseKnActionTypeExecuteArgs(args: string[]): KnActionTypeExecuteOptions;
|
|
134
|
-
/** Parse relation-type create args: --name --source --target [--mapping src:tgt ...] */
|
|
135
|
-
export declare function parseRelationTypeCreateArgs(args: string[]): {
|
|
136
|
-
knId: string;
|
|
137
|
-
body: string;
|
|
138
|
-
businessDomain: string;
|
|
139
|
-
branch: string;
|
|
140
|
-
pretty: boolean;
|
|
141
|
-
};
|
|
142
|
-
export declare function parseKnBuildArgs(args: string[]): {
|
|
143
|
-
knId: string;
|
|
144
|
-
wait: boolean;
|
|
145
|
-
timeout: number;
|
|
146
|
-
businessDomain: string;
|
|
147
|
-
};
|
|
148
|
-
export declare function packDirectoryToTar(dirPath: string): Buffer;
|
|
149
|
-
export declare function extractTarToDirectory(tarBuffer: Buffer, dirPath: string): void;
|
|
150
|
-
export declare function parseKnSearchArgs(args: string[]): {
|
|
151
|
-
knId: string;
|
|
152
|
-
query: string;
|
|
153
|
-
maxConcepts: number;
|
|
154
|
-
mode: string;
|
|
155
|
-
pretty: boolean;
|
|
156
|
-
businessDomain: string;
|
|
157
|
-
};
|