@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
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, listVegaDiscoverTasks, getVegaDiscoverTask, } from "../api/vega.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, listVegaDiscoverTasks, getVegaDiscoverTask, 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,6 +28,14 @@ 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
|
|
@@ -94,6 +102,10 @@ export async function runVegaCommand(args) {
|
|
|
94
102
|
return runVegaCatalogCommand(rest);
|
|
95
103
|
if (subcommand === "resource")
|
|
96
104
|
return runVegaResourceCommand(rest);
|
|
105
|
+
if (subcommand === "dataset")
|
|
106
|
+
return runVegaDatasetCommand(rest);
|
|
107
|
+
if (subcommand === "query")
|
|
108
|
+
return runVegaQueryCommand(rest);
|
|
97
109
|
if (subcommand === "connector-type")
|
|
98
110
|
return runVegaConnectorTypeCommand(rest);
|
|
99
111
|
if (subcommand === "discovery-task")
|
|
@@ -142,19 +154,25 @@ async function runVegaStatsCommand(args) {
|
|
|
142
154
|
return 0;
|
|
143
155
|
}
|
|
144
156
|
const { businessDomain, pretty } = parseCommonFlags(args);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
157
|
+
try {
|
|
158
|
+
const token = await ensureValidToken();
|
|
159
|
+
const body = await listVegaCatalogs({
|
|
160
|
+
baseUrl: token.baseUrl,
|
|
161
|
+
accessToken: token.accessToken,
|
|
162
|
+
limit: 100,
|
|
163
|
+
businessDomain,
|
|
164
|
+
});
|
|
165
|
+
const parsed = JSON.parse(body);
|
|
166
|
+
const entries = Array.isArray(parsed) ? parsed : (parsed.entries ?? parsed.data ?? parsed.items ?? parsed.catalogs ?? []);
|
|
167
|
+
const count = Array.isArray(entries) ? entries.length : 0;
|
|
168
|
+
const stats = { catalog_count: count };
|
|
169
|
+
console.log(pretty ? JSON.stringify(stats, null, 2) : JSON.stringify(stats));
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.error(formatHttpError(error));
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
158
176
|
}
|
|
159
177
|
// ---------------------------------------------------------------------------
|
|
160
178
|
// Top-level: inspect
|
|
@@ -652,6 +670,7 @@ async function runVegaResourceCommand(args) {
|
|
|
652
670
|
|
|
653
671
|
Subcommands:
|
|
654
672
|
list [--catalog-id X] [--category X] [--status X] [--limit N] [--offset N]
|
|
673
|
+
list-all [--limit N] [--offset N]
|
|
655
674
|
get <id>
|
|
656
675
|
query <id> -d <json-body>
|
|
657
676
|
create --catalog-id <cid> --name <name> --category <cat>
|
|
@@ -661,6 +680,8 @@ Subcommands:
|
|
|
661
680
|
}
|
|
662
681
|
if (sub === "list")
|
|
663
682
|
return await runResourceList(rest);
|
|
683
|
+
if (sub === "list-all")
|
|
684
|
+
return await runResourceListAll(rest);
|
|
664
685
|
if (sub === "get")
|
|
665
686
|
return await runResourceGet(rest);
|
|
666
687
|
if (sub === "query")
|
|
@@ -735,6 +756,45 @@ Options:
|
|
|
735
756
|
return 0;
|
|
736
757
|
}
|
|
737
758
|
// ---------------------------------------------------------------------------
|
|
759
|
+
// resource list-all
|
|
760
|
+
// ---------------------------------------------------------------------------
|
|
761
|
+
async function runResourceListAll(args) {
|
|
762
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
763
|
+
console.log(`kweaver vega resource list-all [options]
|
|
764
|
+
|
|
765
|
+
Options:
|
|
766
|
+
--limit <n> Max results (default: 30)
|
|
767
|
+
--offset <n> Offset
|
|
768
|
+
-bd, --biz-domain Business domain (default: bd_public)
|
|
769
|
+
--pretty Pretty-print JSON (default)`);
|
|
770
|
+
return 0;
|
|
771
|
+
}
|
|
772
|
+
let limit = 30;
|
|
773
|
+
let offset;
|
|
774
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
775
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
776
|
+
const arg = remaining[i];
|
|
777
|
+
if (arg === "--limit" && remaining[i + 1]) {
|
|
778
|
+
limit = parseInt(remaining[++i], 10);
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
if (arg === "--offset" && remaining[i + 1]) {
|
|
782
|
+
offset = parseInt(remaining[++i], 10);
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
const token = await ensureValidToken();
|
|
787
|
+
const body = await listAllVegaResources({
|
|
788
|
+
baseUrl: token.baseUrl,
|
|
789
|
+
accessToken: token.accessToken,
|
|
790
|
+
limit,
|
|
791
|
+
offset,
|
|
792
|
+
businessDomain,
|
|
793
|
+
});
|
|
794
|
+
console.log(formatCallOutput(body, pretty));
|
|
795
|
+
return 0;
|
|
796
|
+
}
|
|
797
|
+
// ---------------------------------------------------------------------------
|
|
738
798
|
// resource get
|
|
739
799
|
// ---------------------------------------------------------------------------
|
|
740
800
|
async function runResourceGet(args) {
|
|
@@ -980,6 +1040,303 @@ Options:
|
|
|
980
1040
|
return 0;
|
|
981
1041
|
}
|
|
982
1042
|
// ---------------------------------------------------------------------------
|
|
1043
|
+
// Dataset router
|
|
1044
|
+
// ---------------------------------------------------------------------------
|
|
1045
|
+
async function runVegaDatasetCommand(args) {
|
|
1046
|
+
const [sub, ...rest] = args;
|
|
1047
|
+
if (!sub || sub === "--help" || sub === "-h") {
|
|
1048
|
+
console.log(`kweaver vega dataset
|
|
1049
|
+
|
|
1050
|
+
Subcommands:
|
|
1051
|
+
create-docs <resource-id> -d <json-array>
|
|
1052
|
+
update-docs <resource-id> -d <json-array>
|
|
1053
|
+
delete-docs <resource-id> <doc-ids...>
|
|
1054
|
+
delete-docs-query <resource-id> -d <filter-json>
|
|
1055
|
+
build <resource-id> [--mode full|incremental|realtime]
|
|
1056
|
+
build-status <resource-id> <task-id>`);
|
|
1057
|
+
return 0;
|
|
1058
|
+
}
|
|
1059
|
+
if (sub === "create-docs")
|
|
1060
|
+
return await runDatasetCreateDocs(rest);
|
|
1061
|
+
if (sub === "update-docs")
|
|
1062
|
+
return await runDatasetUpdateDocs(rest);
|
|
1063
|
+
if (sub === "delete-docs")
|
|
1064
|
+
return await runDatasetDeleteDocs(rest);
|
|
1065
|
+
if (sub === "delete-docs-query")
|
|
1066
|
+
return await runDatasetDeleteDocsQuery(rest);
|
|
1067
|
+
if (sub === "build")
|
|
1068
|
+
return await runDatasetBuild(rest);
|
|
1069
|
+
if (sub === "build-status")
|
|
1070
|
+
return await runDatasetBuildStatus(rest);
|
|
1071
|
+
console.error(`Unknown dataset subcommand: ${sub}`);
|
|
1072
|
+
return 1;
|
|
1073
|
+
}
|
|
1074
|
+
// ---------------------------------------------------------------------------
|
|
1075
|
+
// dataset create-docs
|
|
1076
|
+
// ---------------------------------------------------------------------------
|
|
1077
|
+
async function runDatasetCreateDocs(args) {
|
|
1078
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1079
|
+
console.log(`kweaver vega dataset create-docs <resource-id> -d <json-array>
|
|
1080
|
+
|
|
1081
|
+
Options:
|
|
1082
|
+
-d, --data <json> Array of documents (JSON string)`);
|
|
1083
|
+
return 0;
|
|
1084
|
+
}
|
|
1085
|
+
let data;
|
|
1086
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1087
|
+
const positionals = [];
|
|
1088
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1089
|
+
const arg = remaining[i];
|
|
1090
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
1091
|
+
data = remaining[++i];
|
|
1092
|
+
continue;
|
|
1093
|
+
}
|
|
1094
|
+
if (!arg.startsWith("-"))
|
|
1095
|
+
positionals.push(arg);
|
|
1096
|
+
}
|
|
1097
|
+
const id = positionals[0];
|
|
1098
|
+
if (!id || !data) {
|
|
1099
|
+
console.error("Usage: kweaver vega dataset create-docs <resource-id> -d <json-array>");
|
|
1100
|
+
return 1;
|
|
1101
|
+
}
|
|
1102
|
+
const token = await ensureValidToken();
|
|
1103
|
+
const body = await createVegaDatasetDocs({
|
|
1104
|
+
baseUrl: token.baseUrl,
|
|
1105
|
+
accessToken: token.accessToken,
|
|
1106
|
+
id,
|
|
1107
|
+
body: data,
|
|
1108
|
+
businessDomain,
|
|
1109
|
+
});
|
|
1110
|
+
console.log(formatCallOutput(body, pretty));
|
|
1111
|
+
return 0;
|
|
1112
|
+
}
|
|
1113
|
+
// ---------------------------------------------------------------------------
|
|
1114
|
+
// dataset update-docs
|
|
1115
|
+
// ---------------------------------------------------------------------------
|
|
1116
|
+
async function runDatasetUpdateDocs(args) {
|
|
1117
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1118
|
+
console.log(`kweaver vega dataset update-docs <resource-id> -d <json-array>
|
|
1119
|
+
|
|
1120
|
+
Options:
|
|
1121
|
+
-d, --data <json> Array of documents with ids (JSON string)`);
|
|
1122
|
+
return 0;
|
|
1123
|
+
}
|
|
1124
|
+
let data;
|
|
1125
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1126
|
+
const positionals = [];
|
|
1127
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1128
|
+
const arg = remaining[i];
|
|
1129
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
1130
|
+
data = remaining[++i];
|
|
1131
|
+
continue;
|
|
1132
|
+
}
|
|
1133
|
+
if (!arg.startsWith("-"))
|
|
1134
|
+
positionals.push(arg);
|
|
1135
|
+
}
|
|
1136
|
+
const id = positionals[0];
|
|
1137
|
+
if (!id || !data) {
|
|
1138
|
+
console.error("Usage: kweaver vega dataset update-docs <resource-id> -d <json-array>");
|
|
1139
|
+
return 1;
|
|
1140
|
+
}
|
|
1141
|
+
const token = await ensureValidToken();
|
|
1142
|
+
const body = await updateVegaDatasetDocs({
|
|
1143
|
+
baseUrl: token.baseUrl,
|
|
1144
|
+
accessToken: token.accessToken,
|
|
1145
|
+
id,
|
|
1146
|
+
body: data,
|
|
1147
|
+
businessDomain,
|
|
1148
|
+
});
|
|
1149
|
+
console.log(formatCallOutput(body || "{}", pretty));
|
|
1150
|
+
return 0;
|
|
1151
|
+
}
|
|
1152
|
+
// ---------------------------------------------------------------------------
|
|
1153
|
+
// dataset delete-docs
|
|
1154
|
+
// ---------------------------------------------------------------------------
|
|
1155
|
+
async function runDatasetDeleteDocs(args) {
|
|
1156
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1157
|
+
console.log(`kweaver vega dataset delete-docs <resource-id> <doc-ids...>
|
|
1158
|
+
|
|
1159
|
+
Positional args:
|
|
1160
|
+
resource-id The dataset resource ID
|
|
1161
|
+
doc-ids One or more document IDs (comma-joined)`);
|
|
1162
|
+
return 0;
|
|
1163
|
+
}
|
|
1164
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1165
|
+
const positionals = remaining.filter((a) => !a.startsWith("-"));
|
|
1166
|
+
const id = positionals[0];
|
|
1167
|
+
const docIds = positionals.slice(1);
|
|
1168
|
+
if (!id || docIds.length === 0) {
|
|
1169
|
+
console.error("Usage: kweaver vega dataset delete-docs <resource-id> <doc-ids...>");
|
|
1170
|
+
return 1;
|
|
1171
|
+
}
|
|
1172
|
+
const token = await ensureValidToken();
|
|
1173
|
+
const body = await deleteVegaDatasetDocs({
|
|
1174
|
+
baseUrl: token.baseUrl,
|
|
1175
|
+
accessToken: token.accessToken,
|
|
1176
|
+
id,
|
|
1177
|
+
docIds: docIds.join(","),
|
|
1178
|
+
businessDomain,
|
|
1179
|
+
});
|
|
1180
|
+
console.log(formatCallOutput(body || "{}", pretty));
|
|
1181
|
+
return 0;
|
|
1182
|
+
}
|
|
1183
|
+
// ---------------------------------------------------------------------------
|
|
1184
|
+
// dataset delete-docs-query
|
|
1185
|
+
// ---------------------------------------------------------------------------
|
|
1186
|
+
async function runDatasetDeleteDocsQuery(args) {
|
|
1187
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1188
|
+
console.log(`kweaver vega dataset delete-docs-query <resource-id> -d <filter-json>
|
|
1189
|
+
|
|
1190
|
+
Options:
|
|
1191
|
+
-d, --data <json> Filter condition (JSON string)`);
|
|
1192
|
+
return 0;
|
|
1193
|
+
}
|
|
1194
|
+
let data;
|
|
1195
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1196
|
+
const positionals = [];
|
|
1197
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1198
|
+
const arg = remaining[i];
|
|
1199
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
1200
|
+
data = remaining[++i];
|
|
1201
|
+
continue;
|
|
1202
|
+
}
|
|
1203
|
+
if (!arg.startsWith("-"))
|
|
1204
|
+
positionals.push(arg);
|
|
1205
|
+
}
|
|
1206
|
+
const id = positionals[0];
|
|
1207
|
+
if (!id || !data) {
|
|
1208
|
+
console.error("Usage: kweaver vega dataset delete-docs-query <resource-id> -d <filter-json>");
|
|
1209
|
+
return 1;
|
|
1210
|
+
}
|
|
1211
|
+
const token = await ensureValidToken();
|
|
1212
|
+
const body = await deleteVegaDatasetDocsQuery({
|
|
1213
|
+
baseUrl: token.baseUrl,
|
|
1214
|
+
accessToken: token.accessToken,
|
|
1215
|
+
id,
|
|
1216
|
+
body: data,
|
|
1217
|
+
businessDomain,
|
|
1218
|
+
});
|
|
1219
|
+
console.log(formatCallOutput(body || "{}", pretty));
|
|
1220
|
+
return 0;
|
|
1221
|
+
}
|
|
1222
|
+
// ---------------------------------------------------------------------------
|
|
1223
|
+
// dataset build
|
|
1224
|
+
// ---------------------------------------------------------------------------
|
|
1225
|
+
async function runDatasetBuild(args) {
|
|
1226
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1227
|
+
console.log(`kweaver vega dataset build <resource-id> [options]
|
|
1228
|
+
|
|
1229
|
+
Options:
|
|
1230
|
+
--mode <mode> Build mode: full, incremental, realtime (default: full)`);
|
|
1231
|
+
return 0;
|
|
1232
|
+
}
|
|
1233
|
+
let mode = "full";
|
|
1234
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1235
|
+
const positionals = [];
|
|
1236
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1237
|
+
const arg = remaining[i];
|
|
1238
|
+
if (arg === "--mode" && remaining[i + 1]) {
|
|
1239
|
+
mode = remaining[++i];
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1242
|
+
if (!arg.startsWith("-"))
|
|
1243
|
+
positionals.push(arg);
|
|
1244
|
+
}
|
|
1245
|
+
const id = positionals[0];
|
|
1246
|
+
if (!id) {
|
|
1247
|
+
console.error("Usage: kweaver vega dataset build <resource-id> [--mode full|incremental|realtime]");
|
|
1248
|
+
return 1;
|
|
1249
|
+
}
|
|
1250
|
+
const token = await ensureValidToken();
|
|
1251
|
+
const body = await buildVegaDataset({
|
|
1252
|
+
baseUrl: token.baseUrl,
|
|
1253
|
+
accessToken: token.accessToken,
|
|
1254
|
+
id,
|
|
1255
|
+
mode,
|
|
1256
|
+
businessDomain,
|
|
1257
|
+
});
|
|
1258
|
+
console.log(formatCallOutput(body, pretty));
|
|
1259
|
+
return 0;
|
|
1260
|
+
}
|
|
1261
|
+
// ---------------------------------------------------------------------------
|
|
1262
|
+
// dataset build-status
|
|
1263
|
+
// ---------------------------------------------------------------------------
|
|
1264
|
+
async function runDatasetBuildStatus(args) {
|
|
1265
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1266
|
+
console.log(`kweaver vega dataset build-status <resource-id> <task-id>`);
|
|
1267
|
+
return 0;
|
|
1268
|
+
}
|
|
1269
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1270
|
+
const positionals = remaining.filter((a) => !a.startsWith("-"));
|
|
1271
|
+
const id = positionals[0];
|
|
1272
|
+
const taskId = positionals[1];
|
|
1273
|
+
if (!id || !taskId) {
|
|
1274
|
+
console.error("Usage: kweaver vega dataset build-status <resource-id> <task-id>");
|
|
1275
|
+
return 1;
|
|
1276
|
+
}
|
|
1277
|
+
const token = await ensureValidToken();
|
|
1278
|
+
const body = await getVegaDatasetBuildStatus({
|
|
1279
|
+
baseUrl: token.baseUrl,
|
|
1280
|
+
accessToken: token.accessToken,
|
|
1281
|
+
id,
|
|
1282
|
+
taskId,
|
|
1283
|
+
businessDomain,
|
|
1284
|
+
});
|
|
1285
|
+
console.log(formatCallOutput(body, pretty));
|
|
1286
|
+
return 0;
|
|
1287
|
+
}
|
|
1288
|
+
// ---------------------------------------------------------------------------
|
|
1289
|
+
// Query router
|
|
1290
|
+
// ---------------------------------------------------------------------------
|
|
1291
|
+
async function runVegaQueryCommand(args) {
|
|
1292
|
+
const [sub, ...rest] = args;
|
|
1293
|
+
if (!sub || sub === "--help" || sub === "-h") {
|
|
1294
|
+
console.log(`kweaver vega query
|
|
1295
|
+
|
|
1296
|
+
Subcommands:
|
|
1297
|
+
execute -d <json> Execute a query`);
|
|
1298
|
+
return 0;
|
|
1299
|
+
}
|
|
1300
|
+
if (sub === "execute")
|
|
1301
|
+
return await runQueryExecute(rest);
|
|
1302
|
+
console.error(`Unknown query subcommand: ${sub}`);
|
|
1303
|
+
return 1;
|
|
1304
|
+
}
|
|
1305
|
+
// ---------------------------------------------------------------------------
|
|
1306
|
+
// query execute
|
|
1307
|
+
// ---------------------------------------------------------------------------
|
|
1308
|
+
async function runQueryExecute(args) {
|
|
1309
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
1310
|
+
console.log(`kweaver vega query execute -d <json>
|
|
1311
|
+
|
|
1312
|
+
Options:
|
|
1313
|
+
-d, --data <json> Query body (tables, joins, output_fields, filter_condition, sort, limit, ...)`);
|
|
1314
|
+
return 0;
|
|
1315
|
+
}
|
|
1316
|
+
let data;
|
|
1317
|
+
const { remaining, businessDomain, pretty } = parseCommonFlags(args);
|
|
1318
|
+
for (let i = 0; i < remaining.length; i += 1) {
|
|
1319
|
+
const arg = remaining[i];
|
|
1320
|
+
if ((arg === "-d" || arg === "--data") && remaining[i + 1]) {
|
|
1321
|
+
data = remaining[++i];
|
|
1322
|
+
continue;
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
if (!data) {
|
|
1326
|
+
console.error("Usage: kweaver vega query execute -d <json>");
|
|
1327
|
+
return 1;
|
|
1328
|
+
}
|
|
1329
|
+
const token = await ensureValidToken();
|
|
1330
|
+
const body = await executeVegaQuery({
|
|
1331
|
+
baseUrl: token.baseUrl,
|
|
1332
|
+
accessToken: token.accessToken,
|
|
1333
|
+
body: data,
|
|
1334
|
+
businessDomain,
|
|
1335
|
+
});
|
|
1336
|
+
console.log(formatCallOutput(body, pretty));
|
|
1337
|
+
return 0;
|
|
1338
|
+
}
|
|
1339
|
+
// ---------------------------------------------------------------------------
|
|
983
1340
|
// Connector-type router
|
|
984
1341
|
// ---------------------------------------------------------------------------
|
|
985
1342
|
async function runVegaConnectorTypeCommand(args) {
|
|
@@ -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
|
+
}
|
package/dist/config/store.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface TokenConfig {
|
|
|
10
10
|
obtainedAt: string;
|
|
11
11
|
/** When true, skip TLS certificate verification for this platform (saved by `kweaver auth --insecure`). */
|
|
12
12
|
tlsInsecure?: boolean;
|
|
13
|
+
/** Human-readable display name fetched from userinfo at login time. */
|
|
14
|
+
displayName?: string;
|
|
13
15
|
}
|
|
14
16
|
/** OAuth2 client registration (per platform), used for refresh_token grant. */
|
|
15
17
|
export interface ClientConfig {
|
|
@@ -38,7 +40,37 @@ export interface PlatformSummary {
|
|
|
38
40
|
hasToken: boolean;
|
|
39
41
|
isCurrent: boolean;
|
|
40
42
|
alias?: string;
|
|
43
|
+
/** Active user ID for this platform (from id_token sub claim). */
|
|
44
|
+
userId?: string;
|
|
45
|
+
/** Human-readable name persisted from /oauth2/userinfo at login time. */
|
|
46
|
+
displayName?: string;
|
|
41
47
|
}
|
|
48
|
+
/** Extract userId from a TokenConfig (try idToken, then accessToken, fallback "default"). */
|
|
49
|
+
export declare function extractUserId(token: TokenConfig): string;
|
|
50
|
+
/** Get the active userId for a platform. */
|
|
51
|
+
export declare function getActiveUser(baseUrl: string): string | null;
|
|
52
|
+
/** Set the active userId for a platform. */
|
|
53
|
+
export declare function setActiveUser(baseUrl: string, userId: string): void;
|
|
54
|
+
/** List all user IDs stored under a platform. */
|
|
55
|
+
export declare function listUsers(baseUrl: string): string[];
|
|
56
|
+
/** Load a specific user's token (not necessarily the active user). */
|
|
57
|
+
export declare function loadUserTokenConfig(baseUrl: string, userId: string): TokenConfig | null;
|
|
58
|
+
export interface UserProfile {
|
|
59
|
+
userId: string;
|
|
60
|
+
username?: string;
|
|
61
|
+
email?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* List all user profiles for a platform, enriched with display names.
|
|
65
|
+
*
|
|
66
|
+
* Resolution order for username:
|
|
67
|
+
* 1. ``displayName`` field persisted in token.json (set at login via /oauth2/userinfo)
|
|
68
|
+
* 2. ``preferred_username`` or ``name`` decoded from id_token JWT
|
|
69
|
+
*/
|
|
70
|
+
export declare function listUserProfiles(baseUrl: string): UserProfile[];
|
|
71
|
+
/** Resolve a user identifier (userId, username, or email) to a userId for the given platform.
|
|
72
|
+
* userId and username are matched case-sensitively; email is case-insensitive. */
|
|
73
|
+
export declare function resolveUserId(baseUrl: string, identifier: string): string | null;
|
|
42
74
|
export declare function getConfigDir(): string;
|
|
43
75
|
export declare function getCurrentPlatform(): string | null;
|
|
44
76
|
export declare function setCurrentPlatform(baseUrl: string): void;
|
|
@@ -47,9 +79,10 @@ export declare function deletePlatformAlias(baseUrl: string): void;
|
|
|
47
79
|
export declare function getPlatformAlias(baseUrl: string): string | null;
|
|
48
80
|
export declare function resolvePlatformIdentifier(value: string): string | null;
|
|
49
81
|
export declare function loadTokenConfig(baseUrl?: string): TokenConfig | null;
|
|
50
|
-
export declare function saveTokenConfig(config: TokenConfig): void;
|
|
82
|
+
export declare function saveTokenConfig(config: TokenConfig, userId?: string): void;
|
|
51
83
|
export declare function loadClientConfig(baseUrl?: string): ClientConfig | null;
|
|
52
84
|
export declare function saveClientConfig(baseUrl: string, config: ClientConfig): void;
|
|
85
|
+
export declare function deleteClientConfig(baseUrl: string): void;
|
|
53
86
|
export declare function loadContextLoaderConfig(baseUrl?: string): ContextLoaderConfig | null;
|
|
54
87
|
export declare function saveContextLoaderConfig(baseUrl: string, config: ContextLoaderConfig): void;
|
|
55
88
|
export interface CurrentContextLoaderKn {
|
|
@@ -61,10 +94,9 @@ export declare function addContextLoaderEntry(baseUrl: string, name: string, knI
|
|
|
61
94
|
export declare function setCurrentContextLoader(baseUrl: string, name: string): void;
|
|
62
95
|
export declare function removeContextLoaderEntry(baseUrl: string, name: string): void;
|
|
63
96
|
export declare function hasPlatform(baseUrl: string): boolean;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export declare function clearPlatformSession(baseUrl: string): void;
|
|
97
|
+
export declare function clearPlatformSession(baseUrl: string, userId?: string): void;
|
|
98
|
+
/** Delete a single user's profile directory under a platform. */
|
|
99
|
+
export declare function deleteUser(baseUrl: string, userId: string): void;
|
|
68
100
|
export declare function deletePlatform(baseUrl: string): void;
|
|
69
101
|
export declare function listPlatforms(): PlatformSummary[];
|
|
70
102
|
/** Per-platform config (not auth — general settings). */
|