@kweaver-ai/kweaver-sdk 0.6.10 → 0.7.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 +35 -5
- package/README.zh.md +34 -4
- package/dist/api/context-loader.d.ts +45 -10
- package/dist/api/context-loader.js +43 -8
- package/dist/api/semantic-search.d.ts +9 -0
- package/dist/api/semantic-search.js +19 -0
- package/dist/api/skills.js +10 -8
- package/dist/api/toolboxes.d.ts +12 -0
- package/dist/api/toolboxes.js +43 -1
- package/dist/cli.js +67 -28
- package/dist/commands/auth.js +43 -3
- package/dist/commands/bkn-ops.d.ts +4 -0
- package/dist/commands/bkn-ops.js +136 -62
- package/dist/commands/bkn-query.js +7 -2
- package/dist/commands/config.js +8 -0
- package/dist/commands/context-loader.js +340 -36
- package/dist/commands/ds.d.ts +23 -0
- package/dist/commands/ds.js +116 -18
- package/dist/commands/skill.js +26 -6
- package/dist/commands/toolbox.d.ts +15 -0
- package/dist/commands/toolbox.js +131 -1
- package/dist/config/stateless.d.ts +13 -0
- package/dist/config/stateless.js +20 -0
- package/dist/config/store.js +7 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- 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 +15 -0
- package/dist/resources/toolboxes.js +15 -1
- package/dist/utils/skill-bundle.d.ts +5 -0
- package/dist/utils/skill-bundle.js +74 -0
- package/package.json +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { debugTool, executeTool, listTools, listToolboxes, setToolStatuses, uploadTool, } from "../api/toolboxes.js";
|
|
1
|
+
import { debugTool, executeTool, exportConfig, importConfig, listTools, listToolboxes, setToolStatuses, uploadTool, } from "../api/toolboxes.js";
|
|
2
2
|
/** Toolbox / tool management on the agent-operator-integration service. */
|
|
3
3
|
export class ToolboxesResource {
|
|
4
4
|
ctx;
|
|
@@ -40,6 +40,20 @@ export class ToolboxesResource {
|
|
|
40
40
|
...this.injectAuth(args),
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Export a toolbox/mcp/operator config (.adp JSON) as raw bytes.
|
|
45
|
+
*
|
|
46
|
+
* Returned bytes are usually UTF-8 JSON; mirrors the Python SDK's
|
|
47
|
+
* `export_config -> bytes`. Use `new TextDecoder().decode(buf)` if you
|
|
48
|
+
* need a string.
|
|
49
|
+
*/
|
|
50
|
+
async exportConfig(id, opts = {}) {
|
|
51
|
+
return exportConfig({ ...this.ctx.base(), id, type: opts.type });
|
|
52
|
+
}
|
|
53
|
+
/** Import a previously exported config from disk. */
|
|
54
|
+
async importConfig(filePath, opts = {}) {
|
|
55
|
+
return importConfig({ ...this.ctx.base(), filePath, type: opts.type });
|
|
56
|
+
}
|
|
43
57
|
// The forwarder requires every header the downstream tool expects to be set
|
|
44
58
|
// explicitly under `header`; most published tools declare an Authorization
|
|
45
59
|
// parameter and would otherwise see no token. Auto-inject the active
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
2
|
+
import { basename, join, posix, relative, sep } from "node:path";
|
|
3
|
+
import JSZip from "jszip";
|
|
4
|
+
const SKILL_MD = "SKILL.md";
|
|
5
|
+
export class SkillBundleError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "SkillBundleError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function walk(rootDir) {
|
|
12
|
+
const out = [];
|
|
13
|
+
const stack = [rootDir];
|
|
14
|
+
while (stack.length > 0) {
|
|
15
|
+
const dir = stack.pop();
|
|
16
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
17
|
+
const abs = join(dir, entry.name);
|
|
18
|
+
if (entry.isDirectory()) {
|
|
19
|
+
stack.push(abs);
|
|
20
|
+
}
|
|
21
|
+
else if (entry.isFile()) {
|
|
22
|
+
out.push(abs);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
function toPosixRelPath(rootDir, abs) {
|
|
29
|
+
const rel = relative(rootDir, abs);
|
|
30
|
+
return sep === posix.sep ? rel : rel.split(sep).join(posix.sep);
|
|
31
|
+
}
|
|
32
|
+
export async function bundleSkillDirectoryToZip(rootDir) {
|
|
33
|
+
const stat = statSync(rootDir);
|
|
34
|
+
if (!stat.isDirectory()) {
|
|
35
|
+
throw new SkillBundleError(`not a directory: ${rootDir}`);
|
|
36
|
+
}
|
|
37
|
+
const files = walk(rootDir);
|
|
38
|
+
if (files.length === 0) {
|
|
39
|
+
throw new SkillBundleError(`empty skill directory: ${rootDir}`);
|
|
40
|
+
}
|
|
41
|
+
const hasSkillMd = files.some((f) => toPosixRelPath(rootDir, f).toLowerCase() === SKILL_MD.toLowerCase());
|
|
42
|
+
if (!hasSkillMd) {
|
|
43
|
+
throw new SkillBundleError(`${SKILL_MD} not found at the root of ${rootDir} (server requires it)`);
|
|
44
|
+
}
|
|
45
|
+
const zip = new JSZip();
|
|
46
|
+
for (const abs of files) {
|
|
47
|
+
const relPath = toPosixRelPath(rootDir, abs);
|
|
48
|
+
zip.file(relPath, readFileSync(abs));
|
|
49
|
+
}
|
|
50
|
+
const buf = await zip.generateAsync({
|
|
51
|
+
type: "uint8array",
|
|
52
|
+
compression: "DEFLATE",
|
|
53
|
+
compressionOptions: { level: 6 },
|
|
54
|
+
});
|
|
55
|
+
return buf;
|
|
56
|
+
}
|
|
57
|
+
export async function bundleSkillFileToZip(filePath) {
|
|
58
|
+
const stat = statSync(filePath);
|
|
59
|
+
if (!stat.isFile()) {
|
|
60
|
+
throw new SkillBundleError(`not a file: ${filePath}`);
|
|
61
|
+
}
|
|
62
|
+
const fileName = basename(filePath);
|
|
63
|
+
if (fileName.toLowerCase() !== SKILL_MD.toLowerCase()) {
|
|
64
|
+
throw new SkillBundleError(`--content-file expects a file named ${SKILL_MD} (got ${fileName}). ` +
|
|
65
|
+
`Pass a directory containing ${SKILL_MD} for skills with assets.`);
|
|
66
|
+
}
|
|
67
|
+
const zip = new JSZip();
|
|
68
|
+
zip.file(SKILL_MD, readFileSync(filePath));
|
|
69
|
+
return zip.generateAsync({
|
|
70
|
+
type: "uint8array",
|
|
71
|
+
compression: "DEFLATE",
|
|
72
|
+
compressionOptions: { level: 6 },
|
|
73
|
+
});
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kweaver-ai/kweaver-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "KWeaver TypeScript SDK — CLI tool and programmatic API for knowledge networks and Decision Agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"ink": "^6.8.0",
|
|
64
64
|
"ink-spinner": "^5.0.0",
|
|
65
65
|
"ink-text-input": "^6.0.0",
|
|
66
|
+
"jszip": "^3.10.1",
|
|
66
67
|
"marked": "^11.2.0",
|
|
67
68
|
"react": "^19.2.4",
|
|
68
69
|
"string-width": "^8.2.0",
|