@kweaver-ai/kweaver-sdk 0.5.1 → 0.6.0
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 +25 -2
- package/README.zh.md +24 -1
- package/dist/api/agent-chat.d.ts +8 -2
- package/dist/api/agent-chat.js +150 -44
- package/dist/api/agent-list.d.ts +35 -0
- package/dist/api/agent-list.js +95 -21
- package/dist/api/bkn-backend.d.ts +60 -0
- package/dist/api/bkn-backend.js +103 -10
- package/dist/api/business-domains.js +9 -5
- package/dist/api/context-loader.js +4 -1
- package/dist/api/conversations.d.ts +6 -3
- package/dist/api/conversations.js +29 -35
- package/dist/api/dataflow.js +1 -10
- package/dist/api/dataflow2.d.ts +95 -0
- package/dist/api/dataflow2.js +80 -0
- package/dist/api/datasources.js +1 -10
- package/dist/api/dataviews.js +1 -10
- package/dist/api/headers.d.ts +11 -0
- package/dist/api/headers.js +30 -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 +208 -0
- package/dist/api/vega.d.ts +54 -7
- package/dist/api/vega.js +112 -25
- package/dist/auth/oauth.d.ts +5 -1
- package/dist/auth/oauth.js +351 -95
- package/dist/cli.js +49 -5
- package/dist/client.d.ts +12 -0
- package/dist/client.js +52 -8
- package/dist/commands/agent.d.ts +33 -1
- package/dist/commands/agent.js +721 -49
- package/dist/commands/auth.js +226 -55
- 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 +1483 -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/call.js +8 -5
- package/dist/commands/dataflow.d.ts +1 -0
- package/dist/commands/dataflow.js +251 -0
- 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/explore-bkn.d.ts +79 -0
- package/dist/commands/explore-bkn.js +273 -0
- package/dist/commands/explore-chat.d.ts +3 -0
- package/dist/commands/explore-chat.js +193 -0
- package/dist/commands/explore-vega.d.ts +3 -0
- package/dist/commands/explore-vega.js +71 -0
- package/dist/commands/explore.d.ts +9 -0
- package/dist/commands/explore.js +258 -0
- 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 +372 -117
- package/dist/config/jwt.d.ts +6 -0
- package/dist/config/jwt.js +21 -0
- package/dist/config/no-auth.d.ts +3 -0
- package/dist/config/no-auth.js +5 -0
- package/dist/config/store.d.ts +45 -5
- package/dist/config/store.js +385 -30
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -1
- package/dist/kweaver.d.ts +5 -0
- package/dist/kweaver.js +32 -2
- package/dist/resources/bkn.d.ts +4 -0
- package/dist/resources/bkn.js +6 -3
- package/dist/resources/conversations.d.ts +5 -2
- package/dist/resources/conversations.js +17 -3
- package/dist/resources/knowledge-networks.js +3 -8
- package/dist/resources/skills.d.ts +47 -0
- package/dist/resources/skills.js +47 -0
- package/dist/resources/vega.d.ts +11 -6
- package/dist/resources/vega.js +37 -10
- package/dist/templates/explorer/app.js +136 -0
- package/dist/templates/explorer/bkn.js +747 -0
- package/dist/templates/explorer/chat.js +980 -0
- package/dist/templates/explorer/dashboard.js +82 -0
- package/dist/templates/explorer/index.html +35 -0
- package/dist/templates/explorer/style.css +2440 -0
- package/dist/templates/explorer/vega.js +291 -0
- package/dist/utils/http.d.ts +3 -0
- package/dist/utils/http.js +37 -1
- package/package.json +9 -5
package/dist/commands/vega.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createInterface } from "node:readline";
|
|
2
2
|
import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
|
|
3
|
-
import { vegaHealth, listVegaCatalogs, getVegaCatalog, createVegaCatalog, updateVegaCatalog, deleteVegaCatalogs, vegaCatalogHealthStatus, testVegaCatalogConnection, discoverVegaCatalog, listVegaCatalogResources, listVegaResources, getVegaResource, queryVegaResourceData, createVegaResource, updateVegaResource, deleteVegaResources, listVegaConnectorTypes, getVegaConnectorType, registerVegaConnectorType, updateVegaConnectorType, deleteVegaConnectorType, setVegaConnectorTypeEnabled,
|
|
3
|
+
import { vegaHealth, listVegaCatalogs, getVegaCatalog, createVegaCatalog, updateVegaCatalog, deleteVegaCatalogs, vegaCatalogHealthStatus, testVegaCatalogConnection, discoverVegaCatalog, listVegaCatalogResources, listVegaResources, getVegaResource, queryVegaResourceData, createVegaResource, updateVegaResource, deleteVegaResources, listVegaConnectorTypes, getVegaConnectorType, registerVegaConnectorType, updateVegaConnectorType, deleteVegaConnectorType, setVegaConnectorTypeEnabled, createVegaDatasetDocs, updateVegaDatasetDocs, deleteVegaDatasetDocs, deleteVegaDatasetDocsQuery, buildVegaDataset, getVegaDatasetBuildStatus, executeVegaQuery, listAllVegaResources, } from "../api/vega.js";
|
|
4
4
|
import { formatCallOutput } from "./call.js";
|
|
5
5
|
import { resolveBusinessDomain } from "../config/store.js";
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
@@ -28,15 +28,20 @@ Subcommands:
|
|
|
28
28
|
resource create --catalog-id <cid> --name <n> --category <cat>
|
|
29
29
|
resource update <id> [--name X] [--status X] [--tags X] [-d json]
|
|
30
30
|
resource delete <ids...> [-y]
|
|
31
|
+
resource list-all [--limit N] [--offset N]
|
|
32
|
+
dataset create-docs <resource-id> -d <json-array>
|
|
33
|
+
dataset update-docs <resource-id> -d <json-array>
|
|
34
|
+
dataset delete-docs <resource-id> <doc-ids...>
|
|
35
|
+
dataset delete-docs-query <resource-id> -d <filter-json>
|
|
36
|
+
dataset build <resource-id> [--mode full|incremental|realtime]
|
|
37
|
+
dataset build-status <resource-id> <task-id>
|
|
38
|
+
query execute -d <json>
|
|
31
39
|
connector-type list List connector types
|
|
32
40
|
connector-type get <type> Get connector type details
|
|
33
41
|
connector-type register -d <json> Register a new connector type
|
|
34
42
|
connector-type update <type> -d <json> Update connector type
|
|
35
43
|
connector-type delete <type> [-y] Delete connector type
|
|
36
44
|
connector-type enable <type> --enabled <bool> Enable/disable connector type
|
|
37
|
-
discovery-task list [--status X] [--limit N]
|
|
38
|
-
discovery-task get <id>
|
|
39
|
-
|
|
40
45
|
Common flags:
|
|
41
46
|
-bd, --biz-domain <s> Business domain (default: bd_public)
|
|
42
47
|
--pretty Pretty-print JSON (default)`);
|
|
@@ -94,10 +99,12 @@ export async function runVegaCommand(args) {
|
|
|
94
99
|
return runVegaCatalogCommand(rest);
|
|
95
100
|
if (subcommand === "resource")
|
|
96
101
|
return runVegaResourceCommand(rest);
|
|
102
|
+
if (subcommand === "dataset")
|
|
103
|
+
return runVegaDatasetCommand(rest);
|
|
104
|
+
if (subcommand === "query")
|
|
105
|
+
return runVegaQueryCommand(rest);
|
|
97
106
|
if (subcommand === "connector-type")
|
|
98
107
|
return runVegaConnectorTypeCommand(rest);
|
|
99
|
-
if (subcommand === "discovery-task")
|
|
100
|
-
return runVegaDiscoveryTaskCommand(rest);
|
|
101
108
|
return Promise.resolve(-1);
|
|
102
109
|
};
|
|
103
110
|
try {
|
|
@@ -142,26 +149,32 @@ async function runVegaStatsCommand(args) {
|
|
|
142
149
|
return 0;
|
|
143
150
|
}
|
|
144
151
|
const { businessDomain, pretty } = parseCommonFlags(args);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
try {
|
|
153
|
+
const token = await ensureValidToken();
|
|
154
|
+
const body = await listVegaCatalogs({
|
|
155
|
+
baseUrl: token.baseUrl,
|
|
156
|
+
accessToken: token.accessToken,
|
|
157
|
+
limit: 100,
|
|
158
|
+
businessDomain,
|
|
159
|
+
});
|
|
160
|
+
const parsed = JSON.parse(body);
|
|
161
|
+
const entries = Array.isArray(parsed) ? parsed : (parsed.entries ?? parsed.data ?? parsed.items ?? parsed.catalogs ?? []);
|
|
162
|
+
const count = Array.isArray(entries) ? entries.length : 0;
|
|
163
|
+
const stats = { catalog_count: count };
|
|
164
|
+
console.log(pretty ? JSON.stringify(stats, null, 2) : JSON.stringify(stats));
|
|
165
|
+
return 0;
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error(formatHttpError(error));
|
|
169
|
+
return 1;
|
|
170
|
+
}
|
|
158
171
|
}
|
|
159
172
|
// ---------------------------------------------------------------------------
|
|
160
173
|
// Top-level: inspect
|
|
161
174
|
// ---------------------------------------------------------------------------
|
|
162
175
|
async function runVegaInspectCommand(args) {
|
|
163
176
|
if (args.includes("--help") || args.includes("-h")) {
|
|
164
|
-
console.log("kweaver vega inspect\n\nHealth + catalog summary
|
|
177
|
+
console.log("kweaver vega inspect\n\nHealth + catalog summary.");
|
|
165
178
|
return 0;
|
|
166
179
|
}
|
|
167
180
|
const { businessDomain, pretty } = parseCommonFlags(args);
|
|
@@ -188,17 +201,6 @@ async function runVegaInspectCommand(args) {
|
|
|
188
201
|
console.error(`warn: catalog list failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
189
202
|
result.catalog_count = null;
|
|
190
203
|
}
|
|
191
|
-
// Running discover tasks — best-effort
|
|
192
|
-
try {
|
|
193
|
-
const tasksBody = await listVegaDiscoverTasks({ ...base, status: "running" });
|
|
194
|
-
const parsed = JSON.parse(tasksBody);
|
|
195
|
-
const entries = Array.isArray(parsed) ? parsed : (parsed.entries ?? parsed.data ?? parsed.items ?? parsed.tasks ?? []);
|
|
196
|
-
result.running_discover_tasks = Array.isArray(entries) ? entries.length : 0;
|
|
197
|
-
}
|
|
198
|
-
catch (err) {
|
|
199
|
-
console.error(`warn: discover tasks query failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
200
|
-
result.running_discover_tasks = null;
|
|
201
|
-
}
|
|
202
204
|
console.log(pretty ? JSON.stringify(result, null, 2) : JSON.stringify(result));
|
|
203
205
|
return 0;
|
|
204
206
|
}
|
|
@@ -652,6 +654,7 @@ async function runVegaResourceCommand(args) {
|
|
|
652
654
|
|
|
653
655
|
Subcommands:
|
|
654
656
|
list [--catalog-id X] [--category X] [--status X] [--limit N] [--offset N]
|
|
657
|
+
list-all [--limit N] [--offset N]
|
|
655
658
|
get <id>
|
|
656
659
|
query <id> -d <json-body>
|
|
657
660
|
create --catalog-id <cid> --name <name> --category <cat>
|
|
@@ -661,6 +664,8 @@ Subcommands:
|
|
|
661
664
|
}
|
|
662
665
|
if (sub === "list")
|
|
663
666
|
return await runResourceList(rest);
|
|
667
|
+
if (sub === "list-all")
|
|
668
|
+
return await runResourceListAll(rest);
|
|
664
669
|
if (sub === "get")
|
|
665
670
|
return await runResourceGet(rest);
|
|
666
671
|
if (sub === "query")
|
|
@@ -735,6 +740,45 @@ Options:
|
|
|
735
740
|
return 0;
|
|
736
741
|
}
|
|
737
742
|
// ---------------------------------------------------------------------------
|
|
743
|
+
// resource list-all
|
|
744
|
+
// ---------------------------------------------------------------------------
|
|
745
|
+
async function runResourceListAll(args) {
|
|
746
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
747
|
+
console.log(`kweaver vega resource list-all [options]
|
|
748
|
+
|
|
749
|
+
Options:
|
|
750
|
+
--limit <n> Max results (default: 30)
|
|
751
|
+
--offset <n> Offset
|
|
752
|
+
-bd, --biz-domain Business domain (default: bd_public)
|
|
753
|
+
--pretty Pretty-print JSON (default)`);
|
|
754
|
+
return 0;
|
|
755
|
+
}
|
|
756
|
+
let limit = 30;
|
|
757
|
+
let offset;
|
|
758
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
759
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
760
|
+
const arg = remaining[i];
|
|
761
|
+
if (arg === "--limit" && remaining[i + 1]) {
|
|
762
|
+
limit = parseInt(remaining[++i], 10);
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
if (arg === "--offset" && remaining[i + 1]) {
|
|
766
|
+
offset = parseInt(remaining[++i], 10);
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
const token = await ensureValidToken();
|
|
771
|
+
const body = await listAllVegaResources({
|
|
772
|
+
baseUrl: token.baseUrl,
|
|
773
|
+
accessToken: token.accessToken,
|
|
774
|
+
limit,
|
|
775
|
+
offset,
|
|
776
|
+
businessDomain,
|
|
777
|
+
});
|
|
778
|
+
console.log(formatCallOutput(body, pretty));
|
|
779
|
+
return 0;
|
|
780
|
+
}
|
|
781
|
+
// ---------------------------------------------------------------------------
|
|
738
782
|
// resource get
|
|
739
783
|
// ---------------------------------------------------------------------------
|
|
740
784
|
async function runResourceGet(args) {
|
|
@@ -980,6 +1024,303 @@ Options:
|
|
|
980
1024
|
return 0;
|
|
981
1025
|
}
|
|
982
1026
|
// ---------------------------------------------------------------------------
|
|
1027
|
+
// Dataset router
|
|
1028
|
+
// ---------------------------------------------------------------------------
|
|
1029
|
+
async function runVegaDatasetCommand(args) {
|
|
1030
|
+
const [sub, ...rest] = args;
|
|
1031
|
+
if (!sub || sub === "--help" || sub === "-h") {
|
|
1032
|
+
console.log(`kweaver vega dataset
|
|
1033
|
+
|
|
1034
|
+
Subcommands:
|
|
1035
|
+
create-docs <resource-id> -d <json-array>
|
|
1036
|
+
update-docs <resource-id> -d <json-array>
|
|
1037
|
+
delete-docs <resource-id> <doc-ids...>
|
|
1038
|
+
delete-docs-query <resource-id> -d <filter-json>
|
|
1039
|
+
build <resource-id> [--mode full|incremental|realtime]
|
|
1040
|
+
build-status <resource-id> <task-id>`);
|
|
1041
|
+
return 0;
|
|
1042
|
+
}
|
|
1043
|
+
if (sub === "create-docs")
|
|
1044
|
+
return await runDatasetCreateDocs(rest);
|
|
1045
|
+
if (sub === "update-docs")
|
|
1046
|
+
return await runDatasetUpdateDocs(rest);
|
|
1047
|
+
if (sub === "delete-docs")
|
|
1048
|
+
return await runDatasetDeleteDocs(rest);
|
|
1049
|
+
if (sub === "delete-docs-query")
|
|
1050
|
+
return await runDatasetDeleteDocsQuery(rest);
|
|
1051
|
+
if (sub === "build")
|
|
1052
|
+
return await runDatasetBuild(rest);
|
|
1053
|
+
if (sub === "build-status")
|
|
1054
|
+
return await runDatasetBuildStatus(rest);
|
|
1055
|
+
console.error(`Unknown dataset subcommand: ${sub}`);
|
|
1056
|
+
return 1;
|
|
1057
|
+
}
|
|
1058
|
+
// ---------------------------------------------------------------------------
|
|
1059
|
+
// dataset create-docs
|
|
1060
|
+
// ---------------------------------------------------------------------------
|
|
1061
|
+
async function runDatasetCreateDocs(args) {
|
|
1062
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1063
|
+
console.log(`kweaver vega dataset create-docs <resource-id> -d <json-array>
|
|
1064
|
+
|
|
1065
|
+
Options:
|
|
1066
|
+
-d, --data <json> Array of documents (JSON string)`);
|
|
1067
|
+
return 0;
|
|
1068
|
+
}
|
|
1069
|
+
let data;
|
|
1070
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1071
|
+
const positionals = [];
|
|
1072
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1073
|
+
const arg = remaining[i];
|
|
1074
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
1075
|
+
data = remaining[++i];
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
if (!arg.startsWith("-"))
|
|
1079
|
+
positionals.push(arg);
|
|
1080
|
+
}
|
|
1081
|
+
const id = positionals[0];
|
|
1082
|
+
if (!id || !data) {
|
|
1083
|
+
console.error("Usage: kweaver vega dataset create-docs <resource-id> -d <json-array>");
|
|
1084
|
+
return 1;
|
|
1085
|
+
}
|
|
1086
|
+
const token = await ensureValidToken();
|
|
1087
|
+
const body = await createVegaDatasetDocs({
|
|
1088
|
+
baseUrl: token.baseUrl,
|
|
1089
|
+
accessToken: token.accessToken,
|
|
1090
|
+
id,
|
|
1091
|
+
body: data,
|
|
1092
|
+
businessDomain,
|
|
1093
|
+
});
|
|
1094
|
+
console.log(formatCallOutput(body, pretty));
|
|
1095
|
+
return 0;
|
|
1096
|
+
}
|
|
1097
|
+
// ---------------------------------------------------------------------------
|
|
1098
|
+
// dataset update-docs
|
|
1099
|
+
// ---------------------------------------------------------------------------
|
|
1100
|
+
async function runDatasetUpdateDocs(args) {
|
|
1101
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1102
|
+
console.log(`kweaver vega dataset update-docs <resource-id> -d <json-array>
|
|
1103
|
+
|
|
1104
|
+
Options:
|
|
1105
|
+
-d, --data <json> Array of documents with ids (JSON string)`);
|
|
1106
|
+
return 0;
|
|
1107
|
+
}
|
|
1108
|
+
let data;
|
|
1109
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1110
|
+
const positionals = [];
|
|
1111
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1112
|
+
const arg = remaining[i];
|
|
1113
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
1114
|
+
data = remaining[++i];
|
|
1115
|
+
continue;
|
|
1116
|
+
}
|
|
1117
|
+
if (!arg.startsWith("-"))
|
|
1118
|
+
positionals.push(arg);
|
|
1119
|
+
}
|
|
1120
|
+
const id = positionals[0];
|
|
1121
|
+
if (!id || !data) {
|
|
1122
|
+
console.error("Usage: kweaver vega dataset update-docs <resource-id> -d <json-array>");
|
|
1123
|
+
return 1;
|
|
1124
|
+
}
|
|
1125
|
+
const token = await ensureValidToken();
|
|
1126
|
+
const body = await updateVegaDatasetDocs({
|
|
1127
|
+
baseUrl: token.baseUrl,
|
|
1128
|
+
accessToken: token.accessToken,
|
|
1129
|
+
id,
|
|
1130
|
+
body: data,
|
|
1131
|
+
businessDomain,
|
|
1132
|
+
});
|
|
1133
|
+
console.log(formatCallOutput(body || "{}", pretty));
|
|
1134
|
+
return 0;
|
|
1135
|
+
}
|
|
1136
|
+
// ---------------------------------------------------------------------------
|
|
1137
|
+
// dataset delete-docs
|
|
1138
|
+
// ---------------------------------------------------------------------------
|
|
1139
|
+
async function runDatasetDeleteDocs(args) {
|
|
1140
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1141
|
+
console.log(`kweaver vega dataset delete-docs <resource-id> <doc-ids...>
|
|
1142
|
+
|
|
1143
|
+
Positional args:
|
|
1144
|
+
resource-id The dataset resource ID
|
|
1145
|
+
doc-ids One or more document IDs (comma-joined)`);
|
|
1146
|
+
return 0;
|
|
1147
|
+
}
|
|
1148
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1149
|
+
const positionals = remaining.filter((a) => !a.startsWith("-"));
|
|
1150
|
+
const id = positionals[0];
|
|
1151
|
+
const docIds = positionals.slice(1);
|
|
1152
|
+
if (!id || docIds.length === 0) {
|
|
1153
|
+
console.error("Usage: kweaver vega dataset delete-docs <resource-id> <doc-ids...>");
|
|
1154
|
+
return 1;
|
|
1155
|
+
}
|
|
1156
|
+
const token = await ensureValidToken();
|
|
1157
|
+
const body = await deleteVegaDatasetDocs({
|
|
1158
|
+
baseUrl: token.baseUrl,
|
|
1159
|
+
accessToken: token.accessToken,
|
|
1160
|
+
id,
|
|
1161
|
+
docIds: docIds.join(","),
|
|
1162
|
+
businessDomain,
|
|
1163
|
+
});
|
|
1164
|
+
console.log(formatCallOutput(body || "{}", pretty));
|
|
1165
|
+
return 0;
|
|
1166
|
+
}
|
|
1167
|
+
// ---------------------------------------------------------------------------
|
|
1168
|
+
// dataset delete-docs-query
|
|
1169
|
+
// ---------------------------------------------------------------------------
|
|
1170
|
+
async function runDatasetDeleteDocsQuery(args) {
|
|
1171
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1172
|
+
console.log(`kweaver vega dataset delete-docs-query <resource-id> -d <filter-json>
|
|
1173
|
+
|
|
1174
|
+
Options:
|
|
1175
|
+
-d, --data <json> Filter condition (JSON string)`);
|
|
1176
|
+
return 0;
|
|
1177
|
+
}
|
|
1178
|
+
let data;
|
|
1179
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1180
|
+
const positionals = [];
|
|
1181
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1182
|
+
const arg = remaining[i];
|
|
1183
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
1184
|
+
data = remaining[++i];
|
|
1185
|
+
continue;
|
|
1186
|
+
}
|
|
1187
|
+
if (!arg.startsWith("-"))
|
|
1188
|
+
positionals.push(arg);
|
|
1189
|
+
}
|
|
1190
|
+
const id = positionals[0];
|
|
1191
|
+
if (!id || !data) {
|
|
1192
|
+
console.error("Usage: kweaver vega dataset delete-docs-query <resource-id> -d <filter-json>");
|
|
1193
|
+
return 1;
|
|
1194
|
+
}
|
|
1195
|
+
const token = await ensureValidToken();
|
|
1196
|
+
const body = await deleteVegaDatasetDocsQuery({
|
|
1197
|
+
baseUrl: token.baseUrl,
|
|
1198
|
+
accessToken: token.accessToken,
|
|
1199
|
+
id,
|
|
1200
|
+
body: data,
|
|
1201
|
+
businessDomain,
|
|
1202
|
+
});
|
|
1203
|
+
console.log(formatCallOutput(body || "{}", pretty));
|
|
1204
|
+
return 0;
|
|
1205
|
+
}
|
|
1206
|
+
// ---------------------------------------------------------------------------
|
|
1207
|
+
// dataset build
|
|
1208
|
+
// ---------------------------------------------------------------------------
|
|
1209
|
+
async function runDatasetBuild(args) {
|
|
1210
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1211
|
+
console.log(`kweaver vega dataset build <resource-id> [options]
|
|
1212
|
+
|
|
1213
|
+
Options:
|
|
1214
|
+
--mode <mode> Build mode: full, incremental, realtime (default: full)`);
|
|
1215
|
+
return 0;
|
|
1216
|
+
}
|
|
1217
|
+
let mode = "full";
|
|
1218
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1219
|
+
const positionals = [];
|
|
1220
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1221
|
+
const arg = remaining[i];
|
|
1222
|
+
if (arg === "--mode" && remaining[i + 1]) {
|
|
1223
|
+
mode = remaining[++i];
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
if (!arg.startsWith("-"))
|
|
1227
|
+
positionals.push(arg);
|
|
1228
|
+
}
|
|
1229
|
+
const id = positionals[0];
|
|
1230
|
+
if (!id) {
|
|
1231
|
+
console.error("Usage: kweaver vega dataset build <resource-id> [--mode full|incremental|realtime]");
|
|
1232
|
+
return 1;
|
|
1233
|
+
}
|
|
1234
|
+
const token = await ensureValidToken();
|
|
1235
|
+
const body = await buildVegaDataset({
|
|
1236
|
+
baseUrl: token.baseUrl,
|
|
1237
|
+
accessToken: token.accessToken,
|
|
1238
|
+
id,
|
|
1239
|
+
mode,
|
|
1240
|
+
businessDomain,
|
|
1241
|
+
});
|
|
1242
|
+
console.log(formatCallOutput(body, pretty));
|
|
1243
|
+
return 0;
|
|
1244
|
+
}
|
|
1245
|
+
// ---------------------------------------------------------------------------
|
|
1246
|
+
// dataset build-status
|
|
1247
|
+
// ---------------------------------------------------------------------------
|
|
1248
|
+
async function runDatasetBuildStatus(args) {
|
|
1249
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1250
|
+
console.log(`kweaver vega dataset build-status <resource-id> <task-id>`);
|
|
1251
|
+
return 0;
|
|
1252
|
+
}
|
|
1253
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1254
|
+
const positionals = remaining.filter((a) => !a.startsWith("-"));
|
|
1255
|
+
const id = positionals[0];
|
|
1256
|
+
const taskId = positionals[1];
|
|
1257
|
+
if (!id || !taskId) {
|
|
1258
|
+
console.error("Usage: kweaver vega dataset build-status <resource-id> <task-id>");
|
|
1259
|
+
return 1;
|
|
1260
|
+
}
|
|
1261
|
+
const token = await ensureValidToken();
|
|
1262
|
+
const body = await getVegaDatasetBuildStatus({
|
|
1263
|
+
baseUrl: token.baseUrl,
|
|
1264
|
+
accessToken: token.accessToken,
|
|
1265
|
+
id,
|
|
1266
|
+
taskId,
|
|
1267
|
+
businessDomain,
|
|
1268
|
+
});
|
|
1269
|
+
console.log(formatCallOutput(body, pretty));
|
|
1270
|
+
return 0;
|
|
1271
|
+
}
|
|
1272
|
+
// ---------------------------------------------------------------------------
|
|
1273
|
+
// Query router
|
|
1274
|
+
// ---------------------------------------------------------------------------
|
|
1275
|
+
async function runVegaQueryCommand(args) {
|
|
1276
|
+
const [sub, ...rest] = args;
|
|
1277
|
+
if (!sub || sub === "--help" || sub === "-h") {
|
|
1278
|
+
console.log(`kweaver vega query
|
|
1279
|
+
|
|
1280
|
+
Subcommands:
|
|
1281
|
+
execute -d <json> Execute a query`);
|
|
1282
|
+
return 0;
|
|
1283
|
+
}
|
|
1284
|
+
if (sub === "execute")
|
|
1285
|
+
return await runQueryExecute(rest);
|
|
1286
|
+
console.error(`Unknown query subcommand: ${sub}`);
|
|
1287
|
+
return 1;
|
|
1288
|
+
}
|
|
1289
|
+
// ---------------------------------------------------------------------------
|
|
1290
|
+
// query execute
|
|
1291
|
+
// ---------------------------------------------------------------------------
|
|
1292
|
+
async function runQueryExecute(args) {
|
|
1293
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1294
|
+
console.log(`kweaver vega query execute -d <json>
|
|
1295
|
+
|
|
1296
|
+
Options:
|
|
1297
|
+
-d, --data <json> Query body (tables, joins, output_fields, filter_condition, sort, limit, ...)`);
|
|
1298
|
+
return 0;
|
|
1299
|
+
}
|
|
1300
|
+
let data;
|
|
1301
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1302
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1303
|
+
const arg = remaining[i];
|
|
1304
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
1305
|
+
data = remaining[++i];
|
|
1306
|
+
continue;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
if (!data) {
|
|
1310
|
+
console.error("Usage: kweaver vega query execute -d <json>");
|
|
1311
|
+
return 1;
|
|
1312
|
+
}
|
|
1313
|
+
const token = await ensureValidToken();
|
|
1314
|
+
const body = await executeVegaQuery({
|
|
1315
|
+
baseUrl: token.baseUrl,
|
|
1316
|
+
accessToken: token.accessToken,
|
|
1317
|
+
body: data,
|
|
1318
|
+
businessDomain,
|
|
1319
|
+
});
|
|
1320
|
+
console.log(formatCallOutput(body, pretty));
|
|
1321
|
+
return 0;
|
|
1322
|
+
}
|
|
1323
|
+
// ---------------------------------------------------------------------------
|
|
983
1324
|
// Connector-type router
|
|
984
1325
|
// ---------------------------------------------------------------------------
|
|
985
1326
|
async function runVegaConnectorTypeCommand(args) {
|
|
@@ -1206,89 +1547,3 @@ async function runConnectorTypeEnable(args) {
|
|
|
1206
1547
|
console.log(formatCallOutput(body || "{}", pretty));
|
|
1207
1548
|
return 0;
|
|
1208
1549
|
}
|
|
1209
|
-
// ---------------------------------------------------------------------------
|
|
1210
|
-
// Discovery-task router
|
|
1211
|
-
// ---------------------------------------------------------------------------
|
|
1212
|
-
async function runVegaDiscoveryTaskCommand(args) {
|
|
1213
|
-
const [sub, ...rest] = args;
|
|
1214
|
-
if (!sub || sub === "--help" || sub === "-h") {
|
|
1215
|
-
console.log(`kweaver vega discovery-task
|
|
1216
|
-
|
|
1217
|
-
Subcommands:
|
|
1218
|
-
list [--status X] [--limit N]
|
|
1219
|
-
get <id>`);
|
|
1220
|
-
return 0;
|
|
1221
|
-
}
|
|
1222
|
-
if (sub === "list")
|
|
1223
|
-
return await runDiscoveryTaskList(rest);
|
|
1224
|
-
if (sub === "get")
|
|
1225
|
-
return await runDiscoveryTaskGet(rest);
|
|
1226
|
-
console.error(`Unknown discovery-task subcommand: ${sub}`);
|
|
1227
|
-
return 1;
|
|
1228
|
-
}
|
|
1229
|
-
// ---------------------------------------------------------------------------
|
|
1230
|
-
// discovery-task list
|
|
1231
|
-
// ---------------------------------------------------------------------------
|
|
1232
|
-
async function runDiscoveryTaskList(args) {
|
|
1233
|
-
if (args.includes("--help") || args.includes("-h")) {
|
|
1234
|
-
console.log(`kweaver vega discovery-task list [options]
|
|
1235
|
-
|
|
1236
|
-
Options:
|
|
1237
|
-
--catalog-id <cid> Filter by catalog (reserved)
|
|
1238
|
-
--status <s> Filter by status
|
|
1239
|
-
--limit <n> Max results`);
|
|
1240
|
-
return 0;
|
|
1241
|
-
}
|
|
1242
|
-
let status;
|
|
1243
|
-
let limit;
|
|
1244
|
-
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1245
|
-
for (let i = 0; i < remaining.length; i += 1) {
|
|
1246
|
-
const arg = remaining[i];
|
|
1247
|
-
if (arg === "--status" && remaining[i + 1]) {
|
|
1248
|
-
status = remaining[++i];
|
|
1249
|
-
continue;
|
|
1250
|
-
}
|
|
1251
|
-
if (arg === "--limit" && remaining[i + 1]) {
|
|
1252
|
-
limit = parseInt(remaining[++i], 10);
|
|
1253
|
-
continue;
|
|
1254
|
-
}
|
|
1255
|
-
if (arg === "--catalog-id" && remaining[i + 1]) {
|
|
1256
|
-
remaining[++i];
|
|
1257
|
-
continue;
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
const token = await ensureValidToken();
|
|
1261
|
-
const body = await listVegaDiscoverTasks({
|
|
1262
|
-
baseUrl: token.baseUrl,
|
|
1263
|
-
accessToken: token.accessToken,
|
|
1264
|
-
status,
|
|
1265
|
-
limit,
|
|
1266
|
-
businessDomain,
|
|
1267
|
-
});
|
|
1268
|
-
console.log(formatCallOutput(body, pretty));
|
|
1269
|
-
return 0;
|
|
1270
|
-
}
|
|
1271
|
-
// ---------------------------------------------------------------------------
|
|
1272
|
-
// discovery-task get
|
|
1273
|
-
// ---------------------------------------------------------------------------
|
|
1274
|
-
async function runDiscoveryTaskGet(args) {
|
|
1275
|
-
if (args.includes("--help") || args.includes("-h")) {
|
|
1276
|
-
console.log("kweaver vega discovery-task get <id>");
|
|
1277
|
-
return 0;
|
|
1278
|
-
}
|
|
1279
|
-
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1280
|
-
const id = remaining.find((a) => !a.startsWith("-"));
|
|
1281
|
-
if (!id) {
|
|
1282
|
-
console.error("Usage: kweaver vega discovery-task get <id>");
|
|
1283
|
-
return 1;
|
|
1284
|
-
}
|
|
1285
|
-
const token = await ensureValidToken();
|
|
1286
|
-
const body = await getVegaDiscoverTask({
|
|
1287
|
-
baseUrl: token.baseUrl,
|
|
1288
|
-
accessToken: token.accessToken,
|
|
1289
|
-
id,
|
|
1290
|
-
businessDomain,
|
|
1291
|
-
});
|
|
1292
|
-
console.log(formatCallOutput(body, pretty));
|
|
1293
|
-
return 0;
|
|
1294
|
-
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight JWT payload decoding (no signature verification).
|
|
3
|
+
* Used by the credential store and CLI to extract user identity from id_token / access_token.
|
|
4
|
+
*/
|
|
5
|
+
export declare function decodeJwtPayload(jwt: string): Record<string, unknown> | null;
|
|
6
|
+
export declare function extractUserIdFromJwt(jwt: string): string | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight JWT payload decoding (no signature verification).
|
|
3
|
+
* Used by the credential store and CLI to extract user identity from id_token / access_token.
|
|
4
|
+
*/
|
|
5
|
+
export function decodeJwtPayload(jwt) {
|
|
6
|
+
const parts = jwt.split(".");
|
|
7
|
+
if (parts.length !== 3)
|
|
8
|
+
return null;
|
|
9
|
+
try {
|
|
10
|
+
const base64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
11
|
+
const json = Buffer.from(base64, "base64").toString("utf8");
|
|
12
|
+
return JSON.parse(json);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function extractUserIdFromJwt(jwt) {
|
|
19
|
+
const payload = decodeJwtPayload(jwt);
|
|
20
|
+
return typeof payload?.sub === "string" ? payload.sub : null;
|
|
21
|
+
}
|