@kweaver-ai/kweaver-sdk 0.6.9 → 0.7.1
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 +8 -3
- package/README.zh.md +8 -3
- package/dist/api/agent-list.js +15 -2
- package/dist/api/context-loader.d.ts +45 -10
- package/dist/api/context-loader.js +43 -8
- package/dist/api/ontology-query.d.ts +32 -3
- package/dist/api/semantic-search.d.ts +9 -0
- package/dist/api/semantic-search.js +19 -0
- package/dist/api/toolboxes.d.ts +28 -0
- package/dist/api/toolboxes.js +82 -6
- package/dist/cli.js +30 -19
- package/dist/client.d.ts +3 -0
- package/dist/client.js +5 -0
- package/dist/commands/bkn-query.js +7 -2
- package/dist/commands/bkn-schema.d.ts +27 -0
- package/dist/commands/bkn-schema.js +232 -7
- package/dist/commands/bkn.js +2 -1
- package/dist/commands/context-loader.js +236 -8
- package/dist/commands/tool.d.ts +12 -0
- package/dist/commands/tool.js +177 -7
- package/dist/commands/toolbox.d.ts +15 -0
- package/dist/commands/toolbox.js +131 -1
- package/dist/config/store.js +7 -2
- package/dist/index.d.ts +8 -4
- package/dist/index.js +4 -2
- package/dist/resources/agents.js +19 -5
- package/dist/resources/bkn.d.ts +2 -1
- package/dist/resources/bkn.js +19 -7
- package/dist/resources/context-loader.d.ts +4 -3
- package/dist/resources/context-loader.js +8 -5
- package/dist/resources/toolboxes.d.ts +54 -0
- package/dist/resources/toolboxes.js +68 -0
- package/package.json +1 -1
|
@@ -31,13 +31,18 @@ Query subgraph via ontology-query API. JSON body format see references/json-form
|
|
|
31
31
|
return 1;
|
|
32
32
|
}
|
|
33
33
|
try {
|
|
34
|
-
//
|
|
34
|
+
// Map body shape to ontology-query subgraph query_type:
|
|
35
|
+
// - relation_type_paths mode → ?query_type=relation_path
|
|
36
|
+
// - source_object_type_id mode → omit query_type (default path; do not send relation_path)
|
|
35
37
|
let queryType;
|
|
36
38
|
try {
|
|
37
39
|
const parsedBody = JSON.parse(body);
|
|
38
|
-
if (parsedBody.
|
|
40
|
+
if (Array.isArray(parsedBody.relation_type_paths)) {
|
|
39
41
|
queryType = "relation_path";
|
|
40
42
|
}
|
|
43
|
+
else if (parsedBody.source_object_type_id) {
|
|
44
|
+
queryType = "";
|
|
45
|
+
}
|
|
41
46
|
}
|
|
42
47
|
catch {
|
|
43
48
|
// Not valid JSON — let the API return the error
|
|
@@ -95,6 +95,33 @@ export interface KnActionTypeExecuteOptions {
|
|
|
95
95
|
timeout: number;
|
|
96
96
|
}
|
|
97
97
|
export declare function parseKnActionTypeExecuteArgs(args: string[]): KnActionTypeExecuteOptions;
|
|
98
|
+
/**
|
|
99
|
+
* Assemble the action-type execute envelope from CLI flags. Each flag is
|
|
100
|
+
* parsed as JSON; instance entries must be JSON objects; dynamic_params must
|
|
101
|
+
* be a JSON object. The shape produced is the contract documented in
|
|
102
|
+
* skills/kweaver-core/references/bkn.md.
|
|
103
|
+
*/
|
|
104
|
+
export declare function buildExecuteEnvelope(opts: {
|
|
105
|
+
triggerType: string;
|
|
106
|
+
dynamicParamsJson?: string;
|
|
107
|
+
instanceJsons: string[];
|
|
108
|
+
}): string;
|
|
109
|
+
export interface InputParameterSummary {
|
|
110
|
+
name: string;
|
|
111
|
+
type?: string;
|
|
112
|
+
source?: string;
|
|
113
|
+
required?: boolean;
|
|
114
|
+
description?: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Walk a getActionType response and collect parameters where
|
|
118
|
+
* `value_from === "input"`. The exact response shape varies (sometimes the
|
|
119
|
+
* action-type is at the root, sometimes nested under data/result/...), so we
|
|
120
|
+
* search a few likely locations.
|
|
121
|
+
*/
|
|
122
|
+
export declare function extractInputParameters(rawJson: string): InputParameterSummary[];
|
|
123
|
+
export declare function buildDynamicParamsTemplate(inputs: InputParameterSummary[]): Record<string, unknown>;
|
|
124
|
+
export declare function renderInputsTable(atId: string, inputs: InputParameterSummary[]): string;
|
|
98
125
|
/** Parse relation-type create args: --name --source --target [--mapping src:tgt ...] */
|
|
99
126
|
export declare function parseRelationTypeCreateArgs(args: string[]): {
|
|
100
127
|
knId: string;
|
|
@@ -562,6 +562,9 @@ export function parseKnActionTypeExecuteArgs(args) {
|
|
|
562
562
|
let businessDomain = "";
|
|
563
563
|
let wait = true;
|
|
564
564
|
let timeout = 300;
|
|
565
|
+
let dynamicParamsJson;
|
|
566
|
+
let triggerType;
|
|
567
|
+
const instanceJsons = [];
|
|
565
568
|
const positional = [];
|
|
566
569
|
for (let i = 0; i < args.length; i += 1) {
|
|
567
570
|
const arg = args[i];
|
|
@@ -592,11 +595,41 @@ export function parseKnActionTypeExecuteArgs(args) {
|
|
|
592
595
|
i += 1;
|
|
593
596
|
continue;
|
|
594
597
|
}
|
|
598
|
+
if (arg === "--dynamic-params" && args[i + 1]) {
|
|
599
|
+
dynamicParamsJson = args[++i];
|
|
600
|
+
continue;
|
|
601
|
+
}
|
|
602
|
+
if (arg === "--instance" && args[i + 1]) {
|
|
603
|
+
instanceJsons.push(args[++i]);
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
if (arg === "--trigger-type" && args[i + 1]) {
|
|
607
|
+
triggerType = args[++i];
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
595
610
|
positional.push(arg);
|
|
596
611
|
}
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
612
|
+
const usingFlags = dynamicParamsJson !== undefined || instanceJsons.length > 0 || triggerType !== undefined;
|
|
613
|
+
const [knId, atId, positionalBody] = positional;
|
|
614
|
+
if (!knId || !atId) {
|
|
615
|
+
throw new Error("Missing kn-id or at-id. Usage: kweaver bkn action-type execute <kn-id> <at-id> [<json>|--dynamic-params '<json>' --instance '<json>'] [options]");
|
|
616
|
+
}
|
|
617
|
+
if (positionalBody && usingFlags) {
|
|
618
|
+
throw new Error("Positional body and --dynamic-params/--instance/--trigger-type are mutually exclusive. Use one form.");
|
|
619
|
+
}
|
|
620
|
+
if (!positionalBody && !usingFlags) {
|
|
621
|
+
throw new Error("Missing body. Provide a positional JSON envelope, or use --dynamic-params / --instance / --trigger-type.");
|
|
622
|
+
}
|
|
623
|
+
let body;
|
|
624
|
+
if (positionalBody) {
|
|
625
|
+
body = positionalBody;
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
body = buildExecuteEnvelope({
|
|
629
|
+
triggerType: triggerType ?? "manual",
|
|
630
|
+
dynamicParamsJson,
|
|
631
|
+
instanceJsons,
|
|
632
|
+
});
|
|
600
633
|
}
|
|
601
634
|
if (!businessDomain)
|
|
602
635
|
businessDomain = resolveBusinessDomain();
|
|
@@ -610,6 +643,143 @@ export function parseKnActionTypeExecuteArgs(args) {
|
|
|
610
643
|
timeout,
|
|
611
644
|
};
|
|
612
645
|
}
|
|
646
|
+
/**
|
|
647
|
+
* Assemble the action-type execute envelope from CLI flags. Each flag is
|
|
648
|
+
* parsed as JSON; instance entries must be JSON objects; dynamic_params must
|
|
649
|
+
* be a JSON object. The shape produced is the contract documented in
|
|
650
|
+
* skills/kweaver-core/references/bkn.md.
|
|
651
|
+
*/
|
|
652
|
+
export function buildExecuteEnvelope(opts) {
|
|
653
|
+
const envelope = {
|
|
654
|
+
trigger_type: opts.triggerType,
|
|
655
|
+
_instance_identities: opts.instanceJsons.map((s, idx) => {
|
|
656
|
+
let parsed;
|
|
657
|
+
try {
|
|
658
|
+
parsed = JSON.parse(s);
|
|
659
|
+
}
|
|
660
|
+
catch (e) {
|
|
661
|
+
throw new Error(`--instance #${idx + 1} is not valid JSON: ${e.message}`);
|
|
662
|
+
}
|
|
663
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
664
|
+
throw new Error(`--instance #${idx + 1} must be a JSON object, got ${Array.isArray(parsed) ? "array" : typeof parsed}`);
|
|
665
|
+
}
|
|
666
|
+
return parsed;
|
|
667
|
+
}),
|
|
668
|
+
};
|
|
669
|
+
if (opts.dynamicParamsJson !== undefined) {
|
|
670
|
+
let parsed;
|
|
671
|
+
try {
|
|
672
|
+
parsed = JSON.parse(opts.dynamicParamsJson);
|
|
673
|
+
}
|
|
674
|
+
catch (e) {
|
|
675
|
+
throw new Error(`--dynamic-params is not valid JSON: ${e.message}`);
|
|
676
|
+
}
|
|
677
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
678
|
+
throw new Error(`--dynamic-params must be a JSON object, got ${Array.isArray(parsed) ? "array" : typeof parsed}`);
|
|
679
|
+
}
|
|
680
|
+
envelope.dynamic_params = parsed;
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
envelope.dynamic_params = {};
|
|
684
|
+
}
|
|
685
|
+
return JSON.stringify(envelope);
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* Walk a getActionType response and collect parameters where
|
|
689
|
+
* `value_from === "input"`. The exact response shape varies (sometimes the
|
|
690
|
+
* action-type is at the root, sometimes nested under data/result/...), so we
|
|
691
|
+
* search a few likely locations.
|
|
692
|
+
*/
|
|
693
|
+
export function extractInputParameters(rawJson) {
|
|
694
|
+
let root;
|
|
695
|
+
try {
|
|
696
|
+
root = JSON.parse(rawJson);
|
|
697
|
+
}
|
|
698
|
+
catch {
|
|
699
|
+
return [];
|
|
700
|
+
}
|
|
701
|
+
const candidates = collectParameterArrays(root);
|
|
702
|
+
const seen = new Set();
|
|
703
|
+
const out = [];
|
|
704
|
+
for (const params of candidates) {
|
|
705
|
+
for (const p of params) {
|
|
706
|
+
if (!p || typeof p !== "object")
|
|
707
|
+
continue;
|
|
708
|
+
const obj = p;
|
|
709
|
+
if (obj.value_from !== "input")
|
|
710
|
+
continue;
|
|
711
|
+
const name = typeof obj.name === "string" ? obj.name : "";
|
|
712
|
+
if (!name || seen.has(name))
|
|
713
|
+
continue;
|
|
714
|
+
seen.add(name);
|
|
715
|
+
out.push({
|
|
716
|
+
name,
|
|
717
|
+
type: typeof obj.type === "string" ? obj.type : undefined,
|
|
718
|
+
source: typeof obj.source === "string" ? obj.source : undefined,
|
|
719
|
+
required: typeof obj.required === "boolean" ? obj.required : undefined,
|
|
720
|
+
description: typeof obj.description === "string" ? obj.description : undefined,
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return out;
|
|
725
|
+
}
|
|
726
|
+
function collectParameterArrays(node, acc = []) {
|
|
727
|
+
if (!node)
|
|
728
|
+
return acc;
|
|
729
|
+
if (Array.isArray(node)) {
|
|
730
|
+
for (const item of node)
|
|
731
|
+
collectParameterArrays(item, acc);
|
|
732
|
+
return acc;
|
|
733
|
+
}
|
|
734
|
+
if (typeof node !== "object")
|
|
735
|
+
return acc;
|
|
736
|
+
const obj = node;
|
|
737
|
+
if (Array.isArray(obj.parameters))
|
|
738
|
+
acc.push(obj.parameters);
|
|
739
|
+
for (const v of Object.values(obj))
|
|
740
|
+
collectParameterArrays(v, acc);
|
|
741
|
+
return acc;
|
|
742
|
+
}
|
|
743
|
+
export function buildDynamicParamsTemplate(inputs) {
|
|
744
|
+
const tpl = {};
|
|
745
|
+
for (const p of inputs) {
|
|
746
|
+
tpl[p.name] = placeholderForType(p);
|
|
747
|
+
}
|
|
748
|
+
return tpl;
|
|
749
|
+
}
|
|
750
|
+
function placeholderForType(p) {
|
|
751
|
+
const hint = p.description ? ` (${p.description})` : "";
|
|
752
|
+
const t = (p.type ?? "").toLowerCase();
|
|
753
|
+
if (t === "int" || t === "integer" || t === "long" || t === "number" || t === "float" || t === "double")
|
|
754
|
+
return 0;
|
|
755
|
+
if (t === "bool" || t === "boolean")
|
|
756
|
+
return false;
|
|
757
|
+
if (t === "array" || t === "list")
|
|
758
|
+
return [];
|
|
759
|
+
if (t === "object" || t === "dict" || t === "map")
|
|
760
|
+
return {};
|
|
761
|
+
return `<${p.type ?? "string"}${p.required === false ? "?" : ""}>${hint}`;
|
|
762
|
+
}
|
|
763
|
+
export function renderInputsTable(atId, inputs) {
|
|
764
|
+
if (inputs.length === 0) {
|
|
765
|
+
return `Action type ${atId} has no parameters with value_from=input. dynamic_params can be {}.`;
|
|
766
|
+
}
|
|
767
|
+
const rows = inputs.map(p => [
|
|
768
|
+
p.name,
|
|
769
|
+
p.type ?? "-",
|
|
770
|
+
p.source ?? "-",
|
|
771
|
+
p.required === undefined ? "-" : p.required ? "yes" : "no",
|
|
772
|
+
truncate(p.description ?? "", 60),
|
|
773
|
+
]);
|
|
774
|
+
const header = ["NAME", "TYPE", "SOURCE", "REQUIRED", "DESCRIPTION"];
|
|
775
|
+
const widths = header.map((h, i) => Math.max(h.length, ...rows.map(r => r[i].length)));
|
|
776
|
+
const fmt = (cols) => cols.map((c, i) => c.padEnd(widths[i])).join(" ");
|
|
777
|
+
const lines = [fmt(header), fmt(widths.map(w => "-".repeat(w))), ...rows.map(fmt)];
|
|
778
|
+
return `Action type ${atId} input parameters (value_from=input):\n${lines.join("\n")}`;
|
|
779
|
+
}
|
|
780
|
+
function truncate(s, n) {
|
|
781
|
+
return s.length <= n ? s : s.slice(0, n - 1) + "…";
|
|
782
|
+
}
|
|
613
783
|
// ── Action-type execute helpers ────────────────────────────────────────────────
|
|
614
784
|
const TERMINAL_STATUSES = ["SUCCESS", "FAILED", "CANCELLED"];
|
|
615
785
|
function extractExecutionId(body) {
|
|
@@ -1123,17 +1293,30 @@ kweaver bkn action-type create <kn-id> '<json>' [--pretty] [-bd value]
|
|
|
1123
1293
|
kweaver bkn action-type update <kn-id> <at-id> '<json>' [--pretty] [-bd value]
|
|
1124
1294
|
kweaver bkn action-type delete <kn-id> <at-ids> [-y] [--pretty] [-bd value]
|
|
1125
1295
|
kweaver bkn action-type query <kn-id> <at-id> '<json>' [--pretty] [-bd value]
|
|
1126
|
-
kweaver bkn action-type
|
|
1296
|
+
kweaver bkn action-type inputs <kn-id> <at-id> [--json|--template] [-bd value]
|
|
1297
|
+
kweaver bkn action-type execute <kn-id> <at-id> [<json>|--dynamic-params '<json>' --instance '<json>' --trigger-type <v>] [--pretty] [-bd value] [--wait|--no-wait] [--timeout n]
|
|
1127
1298
|
|
|
1128
1299
|
list: List action types (schema) from ontology-manager.
|
|
1129
1300
|
get: Get a single action type by ID.
|
|
1130
1301
|
create: Create action type(s) (POST JSON body).
|
|
1131
1302
|
update: Update an action type (PUT JSON body).
|
|
1132
1303
|
delete: Delete action type(s) by ID(s).
|
|
1133
|
-
query
|
|
1304
|
+
query: Query actions backing this action type.
|
|
1305
|
+
inputs: List parameters with value_from=input that the caller MUST supply.
|
|
1306
|
+
Default prints a table + a starter dynamic_params template.
|
|
1307
|
+
--json dump filtered parameters as raw JSON
|
|
1308
|
+
--template print only the dynamic_params template object
|
|
1309
|
+
execute: Run an action (has side effects - only use when explicitly requested).
|
|
1310
|
+
Body forms (mutually exclusive):
|
|
1311
|
+
1. Positional envelope JSON: '{"trigger_type":"manual","_instance_identities":[],"dynamic_params":{...}}'
|
|
1312
|
+
2. Flag form (CLI assembles the envelope):
|
|
1313
|
+
--dynamic-params '<json object>' parameters with value_from=input
|
|
1314
|
+
--instance '<json object>' repeatable; one per identity
|
|
1315
|
+
--trigger-type <value> defaults to "manual"
|
|
1134
1316
|
--wait (default) Poll until execution completes
|
|
1135
1317
|
--no-wait Return immediately after starting execution
|
|
1136
|
-
--timeout <seconds> Max wait time when --wait (default: 300)
|
|
1318
|
+
--timeout <seconds> Max wait time when --wait (default: 300)
|
|
1319
|
+
See skills/kweaver-core/references/bkn.md for the full payload contract.`);
|
|
1137
1320
|
return 0;
|
|
1138
1321
|
}
|
|
1139
1322
|
if (action === "list") {
|
|
@@ -1283,6 +1466,48 @@ query/execute: Query or execute actions. execute has side effects - only use whe
|
|
|
1283
1466
|
return 1;
|
|
1284
1467
|
}
|
|
1285
1468
|
}
|
|
1469
|
+
if (action === "inputs") {
|
|
1470
|
+
const parsed = parseOntologyQueryFlags(rest);
|
|
1471
|
+
const flags = new Set(parsed.filteredArgs.filter(a => a.startsWith("--")));
|
|
1472
|
+
const positional = parsed.filteredArgs.filter(a => !a.startsWith("--"));
|
|
1473
|
+
const [knId, atId] = positional;
|
|
1474
|
+
if (!knId || !atId) {
|
|
1475
|
+
console.error("Usage: kweaver bkn action-type inputs <kn-id> <at-id> [--json|--template]");
|
|
1476
|
+
return 1;
|
|
1477
|
+
}
|
|
1478
|
+
if (flags.has("--json") && flags.has("--template")) {
|
|
1479
|
+
console.error("--json and --template are mutually exclusive.");
|
|
1480
|
+
return 1;
|
|
1481
|
+
}
|
|
1482
|
+
try {
|
|
1483
|
+
const token = await ensureValidToken();
|
|
1484
|
+
const raw = await getActionType({
|
|
1485
|
+
baseUrl: token.baseUrl,
|
|
1486
|
+
accessToken: token.accessToken,
|
|
1487
|
+
knId,
|
|
1488
|
+
atId,
|
|
1489
|
+
businessDomain: parsed.businessDomain,
|
|
1490
|
+
});
|
|
1491
|
+
const inputs = extractInputParameters(raw);
|
|
1492
|
+
if (flags.has("--json")) {
|
|
1493
|
+
console.log(formatCallOutput(JSON.stringify(inputs), parsed.pretty));
|
|
1494
|
+
return 0;
|
|
1495
|
+
}
|
|
1496
|
+
const template = buildDynamicParamsTemplate(inputs);
|
|
1497
|
+
if (flags.has("--template")) {
|
|
1498
|
+
console.log(JSON.stringify(template, null, 2));
|
|
1499
|
+
return 0;
|
|
1500
|
+
}
|
|
1501
|
+
console.log(renderInputsTable(atId, inputs));
|
|
1502
|
+
console.log("\n# Starter dynamic_params (fill in real values, then pass via --dynamic-params):");
|
|
1503
|
+
console.log(JSON.stringify(template, null, 2));
|
|
1504
|
+
return 0;
|
|
1505
|
+
}
|
|
1506
|
+
catch (error) {
|
|
1507
|
+
console.error(formatHttpError(error));
|
|
1508
|
+
return 1;
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1286
1511
|
if (action === "execute") {
|
|
1287
1512
|
let options;
|
|
1288
1513
|
try {
|
|
@@ -1349,7 +1574,7 @@ query/execute: Query or execute actions. execute has side effects - only use whe
|
|
|
1349
1574
|
return 1;
|
|
1350
1575
|
}
|
|
1351
1576
|
}
|
|
1352
|
-
console.error(`Unknown action-type action: ${action}. Use list, get, create, update, delete, query, or execute.`);
|
|
1577
|
+
console.error(`Unknown action-type action: ${action}. Use list, get, create, update, delete, query, inputs, or execute.`);
|
|
1353
1578
|
return 1;
|
|
1354
1579
|
}
|
|
1355
1580
|
export function parseConceptGroupArgs(args) {
|
package/dist/commands/bkn.js
CHANGED
|
@@ -393,7 +393,8 @@ Subcommands:
|
|
|
393
393
|
action-type update <kn-id> <at-id> '<json>' Update action type
|
|
394
394
|
action-type delete <kn-id> <at-ids> [-y] Delete action type(s)
|
|
395
395
|
action-type query <kn-id> <at-id> '<json>' Query action info
|
|
396
|
-
action-type
|
|
396
|
+
action-type inputs <kn-id> <at-id> List value_from=input params + dynamic_params template
|
|
397
|
+
action-type execute <kn-id> <at-id> '<envelope-json>' | --dynamic-params '<json>' [--instance '<json>']... [--trigger-type <v>] Execute action (has side effects)
|
|
397
398
|
action-execution get <kn-id> <execution-id> Get execution status
|
|
398
399
|
action-log list <kn-id> [options] List action execution logs
|
|
399
400
|
action-log get <kn-id> <log-id> Get single execution log
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ensureValidToken, formatHttpError, resolveActivePlatform, with401RefreshRetry } from "../auth/oauth.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { callTool, searchSchema, queryObjectInstance, queryInstanceSubgraph, getLogicPropertiesValues, getActionInfo, findSkills, listTools, listResources, readResource, listResourceTemplates, listPrompts, getPrompt, } from "../api/context-loader.js";
|
|
3
|
+
import { knSearchHttp, semanticSearch } from "../api/semantic-search.js";
|
|
4
|
+
import { addContextLoaderEntry, getCurrentContextLoaderKn, loadContextLoaderConfig, removeContextLoaderEntry, resolveBusinessDomain, setCurrentContextLoader, } from "../config/store.js";
|
|
4
5
|
const MCP_NOT_CONFIGURED = "Context-loader MCP is not configured. Run: kweaver context-loader config set --kn-id <kn-id>";
|
|
5
6
|
function ensureContextLoaderConfig() {
|
|
6
7
|
const active = resolveActivePlatform();
|
|
@@ -12,9 +13,11 @@ function ensureContextLoaderConfig() {
|
|
|
12
13
|
throw new Error(MCP_NOT_CONFIGURED);
|
|
13
14
|
}
|
|
14
15
|
return {
|
|
16
|
+
baseUrl: active.url,
|
|
15
17
|
mcpUrl: kn.mcpUrl,
|
|
16
18
|
knId: kn.knId,
|
|
17
19
|
accessToken: "", // filled by caller after ensureValidToken
|
|
20
|
+
businessDomain: resolveBusinessDomain(active.url),
|
|
18
21
|
};
|
|
19
22
|
}
|
|
20
23
|
function formatOutput(value, pretty) {
|
|
@@ -38,16 +41,21 @@ Subcommands:
|
|
|
38
41
|
templates resources/templates/list - list resource templates
|
|
39
42
|
prompts prompts/list - list prompts
|
|
40
43
|
prompt <name> [--args json] prompts/get - get prompt by name
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
search-schema <query> [options] MCP search_schema (object/relation/action/metric types)
|
|
45
|
+
tool-call <name> --args '<json>' MCP tools/call for any server tool
|
|
46
|
+
kn-search <query> [--only-schema] Compatibility: HTTP kn_search
|
|
47
|
+
kn-schema-search <query> [--max N] Compatibility: HTTP semantic-search
|
|
43
48
|
query-object-instance <json> Layer 2: Query instances (args as JSON)
|
|
44
49
|
query-instance-subgraph <json> Layer 2: Query subgraph (args as JSON)
|
|
45
50
|
get-logic-properties <json> Layer 3: Get logic property values (args as JSON)
|
|
46
51
|
get-action-info <json> Layer 3: Get action info (args as JSON)
|
|
52
|
+
find-skills <ot_id> [options] Layer 3: Recall skills for an object type
|
|
47
53
|
|
|
48
54
|
Examples:
|
|
49
55
|
kweaver context-loader config set --kn-id d5iv6c9818p72mpje8pg
|
|
50
56
|
kweaver context-loader config set --kn-id xyz123 --name project-a
|
|
57
|
+
kweaver context-loader search-schema "利润率" --scope object,metric --max 5
|
|
58
|
+
kweaver context-loader tool-call search_schema --args '{"query":"利润率"}'
|
|
51
59
|
kweaver context-loader kn-search "高血压 治疗 药品" --only-schema --pretty`);
|
|
52
60
|
return 0;
|
|
53
61
|
}
|
|
@@ -76,6 +84,10 @@ Examples:
|
|
|
76
84
|
return runListPrompts(options, rest, pretty);
|
|
77
85
|
if (subcommand === "prompt")
|
|
78
86
|
return runGetPrompt(options, rest, pretty);
|
|
87
|
+
if (subcommand === "search-schema")
|
|
88
|
+
return runSearchSchema(options, rest, pretty);
|
|
89
|
+
if (subcommand === "tool-call")
|
|
90
|
+
return runToolCall(options, rest, pretty);
|
|
79
91
|
if (subcommand === "kn-search")
|
|
80
92
|
return runKnSearch(options, rest, pretty);
|
|
81
93
|
if (subcommand === "kn-schema-search")
|
|
@@ -88,6 +100,8 @@ Examples:
|
|
|
88
100
|
return runGetLogicProperties(options, rest, pretty);
|
|
89
101
|
if (subcommand === "get-action-info")
|
|
90
102
|
return runGetActionInfo(options, rest, pretty);
|
|
103
|
+
if (subcommand === "find-skills")
|
|
104
|
+
return runFindSkills(options, rest, pretty);
|
|
91
105
|
return -1;
|
|
92
106
|
};
|
|
93
107
|
try {
|
|
@@ -279,6 +293,145 @@ async function runGetPrompt(options, args, pretty) {
|
|
|
279
293
|
console.log(formatOutput(result, pretty));
|
|
280
294
|
return 0;
|
|
281
295
|
}
|
|
296
|
+
function parseResponseText(text) {
|
|
297
|
+
try {
|
|
298
|
+
return JSON.parse(text);
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
return { raw: text };
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function parseSearchSchemaScope(raw) {
|
|
305
|
+
const scope = {
|
|
306
|
+
include_object_types: false,
|
|
307
|
+
include_relation_types: false,
|
|
308
|
+
include_action_types: false,
|
|
309
|
+
include_metric_types: false,
|
|
310
|
+
};
|
|
311
|
+
const aliases = {
|
|
312
|
+
object: "include_object_types",
|
|
313
|
+
objects: "include_object_types",
|
|
314
|
+
object_type: "include_object_types",
|
|
315
|
+
object_types: "include_object_types",
|
|
316
|
+
relation: "include_relation_types",
|
|
317
|
+
relations: "include_relation_types",
|
|
318
|
+
relation_type: "include_relation_types",
|
|
319
|
+
relation_types: "include_relation_types",
|
|
320
|
+
action: "include_action_types",
|
|
321
|
+
actions: "include_action_types",
|
|
322
|
+
action_type: "include_action_types",
|
|
323
|
+
action_types: "include_action_types",
|
|
324
|
+
metric: "include_metric_types",
|
|
325
|
+
metrics: "include_metric_types",
|
|
326
|
+
metric_type: "include_metric_types",
|
|
327
|
+
metric_types: "include_metric_types",
|
|
328
|
+
};
|
|
329
|
+
for (const item of raw.split(",")) {
|
|
330
|
+
const key = item.trim().toLowerCase();
|
|
331
|
+
if (!key)
|
|
332
|
+
continue;
|
|
333
|
+
const field = aliases[key];
|
|
334
|
+
if (!field) {
|
|
335
|
+
throw new Error(`Invalid --scope value: ${item}`);
|
|
336
|
+
}
|
|
337
|
+
scope[field] = true;
|
|
338
|
+
}
|
|
339
|
+
return scope;
|
|
340
|
+
}
|
|
341
|
+
async function runSearchSchema(options, args, pretty) {
|
|
342
|
+
let query;
|
|
343
|
+
let responseFormat;
|
|
344
|
+
let searchScope;
|
|
345
|
+
let maxConcepts;
|
|
346
|
+
let schemaBrief;
|
|
347
|
+
let enableRerank;
|
|
348
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
349
|
+
const arg = args[i];
|
|
350
|
+
if ((arg === "--format" || arg === "-f") && args[i + 1]) {
|
|
351
|
+
const value = args[i + 1];
|
|
352
|
+
if (value !== "json" && value !== "toon") {
|
|
353
|
+
console.error("Usage: kweaver context-loader search-schema <query> [--format json|toon] [--scope object,relation,action,metric] [--max N] [--brief] [--no-rerank]");
|
|
354
|
+
return 1;
|
|
355
|
+
}
|
|
356
|
+
responseFormat = value;
|
|
357
|
+
i += 1;
|
|
358
|
+
}
|
|
359
|
+
else if ((arg === "--scope" || arg === "-s") && args[i + 1]) {
|
|
360
|
+
try {
|
|
361
|
+
searchScope = parseSearchSchemaScope(args[i + 1]);
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
365
|
+
return 1;
|
|
366
|
+
}
|
|
367
|
+
i += 1;
|
|
368
|
+
}
|
|
369
|
+
else if ((arg === "--max" || arg === "-n") && args[i + 1]) {
|
|
370
|
+
maxConcepts = parseInt(args[i + 1], 10);
|
|
371
|
+
if (!Number.isFinite(maxConcepts)) {
|
|
372
|
+
console.error("Usage: kweaver context-loader search-schema <query> [--max N]");
|
|
373
|
+
return 1;
|
|
374
|
+
}
|
|
375
|
+
i += 1;
|
|
376
|
+
}
|
|
377
|
+
else if (arg === "--brief") {
|
|
378
|
+
schemaBrief = true;
|
|
379
|
+
}
|
|
380
|
+
else if (arg === "--no-rerank") {
|
|
381
|
+
enableRerank = false;
|
|
382
|
+
}
|
|
383
|
+
else if (!arg.startsWith("-") && !query) {
|
|
384
|
+
query = arg;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (!query) {
|
|
388
|
+
console.error("Usage: kweaver context-loader search-schema <query> [--format json|toon] [--scope object,relation,action,metric] [--max N] [--brief] [--no-rerank]");
|
|
389
|
+
return 1;
|
|
390
|
+
}
|
|
391
|
+
const result = await searchSchema(options, {
|
|
392
|
+
query,
|
|
393
|
+
response_format: responseFormat,
|
|
394
|
+
search_scope: searchScope,
|
|
395
|
+
max_concepts: maxConcepts,
|
|
396
|
+
schema_brief: schemaBrief,
|
|
397
|
+
enable_rerank: enableRerank,
|
|
398
|
+
});
|
|
399
|
+
console.log(formatOutput(result, pretty));
|
|
400
|
+
return 0;
|
|
401
|
+
}
|
|
402
|
+
async function runToolCall(options, args, pretty) {
|
|
403
|
+
let toolName;
|
|
404
|
+
let rawArgs;
|
|
405
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
406
|
+
const arg = args[i];
|
|
407
|
+
if ((arg === "--args" || arg === "-a") && args[i + 1]) {
|
|
408
|
+
rawArgs = args[i + 1];
|
|
409
|
+
i += 1;
|
|
410
|
+
}
|
|
411
|
+
else if (!arg.startsWith("-") && !toolName) {
|
|
412
|
+
toolName = arg;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (!toolName || rawArgs === undefined) {
|
|
416
|
+
console.error("Usage: kweaver context-loader tool-call <name> --args '<json>'");
|
|
417
|
+
return 1;
|
|
418
|
+
}
|
|
419
|
+
let parsedArgs;
|
|
420
|
+
try {
|
|
421
|
+
parsedArgs = JSON.parse(rawArgs);
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
console.error("Invalid --args JSON");
|
|
425
|
+
return 1;
|
|
426
|
+
}
|
|
427
|
+
if (parsedArgs === null || typeof parsedArgs !== "object" || Array.isArray(parsedArgs)) {
|
|
428
|
+
console.error("--args must be a JSON object");
|
|
429
|
+
return 1;
|
|
430
|
+
}
|
|
431
|
+
const result = await callTool(options, toolName, parsedArgs);
|
|
432
|
+
console.log(formatOutput(result, pretty));
|
|
433
|
+
return 0;
|
|
434
|
+
}
|
|
282
435
|
async function runKnSearch(options, args, pretty) {
|
|
283
436
|
let query;
|
|
284
437
|
let onlySchema = false;
|
|
@@ -300,8 +453,15 @@ async function runKnSearch(options, args, pretty) {
|
|
|
300
453
|
console.error("Usage: kweaver context-loader kn-search <query> [--kn-id <id>] [--only-schema]");
|
|
301
454
|
return 1;
|
|
302
455
|
}
|
|
303
|
-
const
|
|
304
|
-
|
|
456
|
+
const raw = await knSearchHttp({
|
|
457
|
+
baseUrl: options.baseUrl,
|
|
458
|
+
accessToken: options.accessToken,
|
|
459
|
+
businessDomain: options.businessDomain,
|
|
460
|
+
knId: knIdOverride ?? options.knId,
|
|
461
|
+
query,
|
|
462
|
+
onlySchema,
|
|
463
|
+
});
|
|
464
|
+
const result = parseResponseText(raw);
|
|
305
465
|
console.log(formatOutput(result, pretty));
|
|
306
466
|
return 0;
|
|
307
467
|
}
|
|
@@ -322,10 +482,15 @@ async function runKnSchemaSearch(options, args, pretty) {
|
|
|
322
482
|
console.error("Usage: kweaver context-loader kn-schema-search <query> [--max N]");
|
|
323
483
|
return 1;
|
|
324
484
|
}
|
|
325
|
-
const
|
|
485
|
+
const raw = await semanticSearch({
|
|
486
|
+
baseUrl: options.baseUrl,
|
|
487
|
+
accessToken: options.accessToken,
|
|
488
|
+
businessDomain: options.businessDomain,
|
|
489
|
+
knId: options.knId,
|
|
326
490
|
query,
|
|
327
|
-
|
|
491
|
+
maxConcepts,
|
|
328
492
|
});
|
|
493
|
+
const result = parseResponseText(raw);
|
|
329
494
|
console.log(formatOutput(result, pretty));
|
|
330
495
|
return 0;
|
|
331
496
|
}
|
|
@@ -385,3 +550,66 @@ async function runGetActionInfo(options, args, pretty) {
|
|
|
385
550
|
console.log(formatOutput(result, pretty));
|
|
386
551
|
return 0;
|
|
387
552
|
}
|
|
553
|
+
async function runFindSkills(options, args, pretty) {
|
|
554
|
+
const usage = "Usage: kweaver context-loader find-skills <object_type_id> " +
|
|
555
|
+
"[--query <text>] [--top-k N] [--instance-identities <json>] [--format json|toon]";
|
|
556
|
+
let objectTypeId;
|
|
557
|
+
let skillQuery;
|
|
558
|
+
let topK;
|
|
559
|
+
let instanceIdentities;
|
|
560
|
+
let responseFormat;
|
|
561
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
562
|
+
const arg = args[i];
|
|
563
|
+
if ((arg === "--query" || arg === "-q") && args[i + 1]) {
|
|
564
|
+
skillQuery = args[i + 1];
|
|
565
|
+
i += 1;
|
|
566
|
+
}
|
|
567
|
+
else if ((arg === "--top-k" || arg === "-n") && args[i + 1]) {
|
|
568
|
+
topK = parseInt(args[i + 1], 10);
|
|
569
|
+
if (!Number.isFinite(topK)) {
|
|
570
|
+
console.error(usage);
|
|
571
|
+
return 1;
|
|
572
|
+
}
|
|
573
|
+
i += 1;
|
|
574
|
+
}
|
|
575
|
+
else if ((arg === "--instance-identities" || arg === "-i") && args[i + 1]) {
|
|
576
|
+
try {
|
|
577
|
+
const parsed = JSON.parse(args[i + 1]);
|
|
578
|
+
if (!Array.isArray(parsed)) {
|
|
579
|
+
throw new Error("--instance-identities must be a JSON array");
|
|
580
|
+
}
|
|
581
|
+
instanceIdentities = parsed;
|
|
582
|
+
}
|
|
583
|
+
catch (error) {
|
|
584
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
585
|
+
return 1;
|
|
586
|
+
}
|
|
587
|
+
i += 1;
|
|
588
|
+
}
|
|
589
|
+
else if ((arg === "--format" || arg === "-f") && args[i + 1]) {
|
|
590
|
+
const value = args[i + 1];
|
|
591
|
+
if (value !== "json" && value !== "toon") {
|
|
592
|
+
console.error(usage);
|
|
593
|
+
return 1;
|
|
594
|
+
}
|
|
595
|
+
responseFormat = value;
|
|
596
|
+
i += 1;
|
|
597
|
+
}
|
|
598
|
+
else if (!arg.startsWith("-") && !objectTypeId) {
|
|
599
|
+
objectTypeId = arg;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
if (!objectTypeId) {
|
|
603
|
+
console.error(usage);
|
|
604
|
+
return 1;
|
|
605
|
+
}
|
|
606
|
+
const result = await findSkills(options, {
|
|
607
|
+
object_type_id: objectTypeId,
|
|
608
|
+
skill_query: skillQuery,
|
|
609
|
+
top_k: topK,
|
|
610
|
+
instance_identities: instanceIdentities,
|
|
611
|
+
response_format: responseFormat,
|
|
612
|
+
});
|
|
613
|
+
console.log(formatOutput(result, pretty));
|
|
614
|
+
return 0;
|
|
615
|
+
}
|
package/dist/commands/tool.d.ts
CHANGED
|
@@ -14,3 +14,15 @@ export interface ToolStatusOptions {
|
|
|
14
14
|
businessDomain: string;
|
|
15
15
|
}
|
|
16
16
|
export declare function parseToolStatusArgs(args: string[], status: "enabled" | "disabled"): ToolStatusOptions;
|
|
17
|
+
export interface ToolInvokeOptions {
|
|
18
|
+
boxId: string;
|
|
19
|
+
toolId: string;
|
|
20
|
+
header?: Record<string, unknown>;
|
|
21
|
+
query?: Record<string, unknown>;
|
|
22
|
+
body?: unknown;
|
|
23
|
+
bodyFile?: string;
|
|
24
|
+
timeout?: number;
|
|
25
|
+
businessDomain: string;
|
|
26
|
+
pretty: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare function parseToolInvokeArgs(args: string[]): ToolInvokeOptions;
|