@kweaver-ai/kweaver-sdk 0.6.4 → 0.6.6

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.
@@ -0,0 +1,256 @@
1
+ import { createInterface } from "node:readline";
2
+ import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
3
+ import { createToolbox, deleteToolbox, listToolboxes, setToolboxStatus } from "../api/toolboxes.js";
4
+ import { formatCallOutput } from "./call.js";
5
+ import { resolveBusinessDomain } from "../config/store.js";
6
+ const HELP = `kweaver toolbox
7
+
8
+ Subcommands:
9
+ create --name <n> --service-url <url> [--description <d>] Create a new toolbox
10
+ list [--keyword <s>] [--limit <n>] [--offset <n>] List toolboxes
11
+ publish <box-id> Publish a toolbox (status=published)
12
+ unpublish <box-id> Unpublish (status=draft)
13
+ delete <box-id> [-y|--yes] Delete a toolbox
14
+
15
+ Options:
16
+ -bd, --biz-domain <s> Business domain (default: bd_public)
17
+ --pretty Pretty-print JSON (default)
18
+ --compact Single-line JSON (pipeline-friendly)`;
19
+ export async function runToolboxCommand(args) {
20
+ const [subcommand, ...rest] = args;
21
+ if (!subcommand || subcommand === "--help" || subcommand === "-h") {
22
+ console.log(HELP);
23
+ return 0;
24
+ }
25
+ const dispatch = () => {
26
+ if (subcommand === "create")
27
+ return runToolboxCreate(rest);
28
+ if (subcommand === "list")
29
+ return runToolboxList(rest);
30
+ if (subcommand === "publish")
31
+ return runToolboxSetStatus(rest, "published");
32
+ if (subcommand === "unpublish")
33
+ return runToolboxSetStatus(rest, "draft");
34
+ if (subcommand === "delete")
35
+ return runToolboxDelete(rest);
36
+ return Promise.resolve(-1);
37
+ };
38
+ try {
39
+ return await with401RefreshRetry(async () => {
40
+ const code = await dispatch();
41
+ if (code === -1) {
42
+ console.error(`Unknown toolbox subcommand: ${subcommand}`);
43
+ return 1;
44
+ }
45
+ return code;
46
+ });
47
+ }
48
+ catch (error) {
49
+ console.error(formatHttpError(error));
50
+ return 1;
51
+ }
52
+ }
53
+ export function parseToolboxCreateArgs(args) {
54
+ let name = "";
55
+ let serviceUrl = "";
56
+ let description = "";
57
+ let businessDomain = "";
58
+ let pretty = true;
59
+ for (let i = 0; i < args.length; i += 1) {
60
+ const a = args[i];
61
+ if (a === "--name" && args[i + 1]) {
62
+ name = args[++i];
63
+ continue;
64
+ }
65
+ if (a === "--service-url" && args[i + 1]) {
66
+ serviceUrl = args[++i];
67
+ continue;
68
+ }
69
+ if (a === "--description" && args[i + 1]) {
70
+ description = args[++i];
71
+ continue;
72
+ }
73
+ if ((a === "-bd" || a === "--biz-domain") && args[i + 1]) {
74
+ businessDomain = args[++i];
75
+ continue;
76
+ }
77
+ if (a === "--pretty") {
78
+ pretty = true;
79
+ continue;
80
+ }
81
+ if (a === "--compact") {
82
+ pretty = false;
83
+ continue;
84
+ }
85
+ }
86
+ if (!name)
87
+ throw new Error("Missing required flag: --name");
88
+ if (!serviceUrl)
89
+ throw new Error("Missing required flag: --service-url");
90
+ if (!businessDomain)
91
+ businessDomain = resolveBusinessDomain();
92
+ return { name, serviceUrl, description, businessDomain, pretty };
93
+ }
94
+ async function runToolboxCreate(args) {
95
+ let opts;
96
+ try {
97
+ opts = parseToolboxCreateArgs(args);
98
+ }
99
+ catch (e) {
100
+ console.error(e instanceof Error ? e.message : String(e));
101
+ return 1;
102
+ }
103
+ const token = await ensureValidToken();
104
+ const body = await createToolbox({
105
+ baseUrl: token.baseUrl,
106
+ accessToken: token.accessToken,
107
+ name: opts.name,
108
+ description: opts.description,
109
+ serviceUrl: opts.serviceUrl,
110
+ businessDomain: opts.businessDomain,
111
+ });
112
+ console.log(formatCallOutput(body, opts.pretty));
113
+ return 0;
114
+ }
115
+ // ── list ──────────────────────────────────────────────────────────────────────
116
+ async function runToolboxList(args) {
117
+ let keyword;
118
+ let limit;
119
+ let offset;
120
+ let businessDomain = "";
121
+ let pretty = true;
122
+ for (let i = 0; i < args.length; i += 1) {
123
+ const a = args[i];
124
+ if (a === "--keyword" && args[i + 1]) {
125
+ keyword = args[++i];
126
+ continue;
127
+ }
128
+ if (a === "--limit" && args[i + 1]) {
129
+ const n = parseInt(args[++i], 10);
130
+ if (Number.isNaN(n)) {
131
+ console.error("--limit must be a number");
132
+ return 1;
133
+ }
134
+ limit = n;
135
+ continue;
136
+ }
137
+ if (a === "--offset" && args[i + 1]) {
138
+ const n = parseInt(args[++i], 10);
139
+ if (Number.isNaN(n)) {
140
+ console.error("--offset must be a number");
141
+ return 1;
142
+ }
143
+ offset = n;
144
+ continue;
145
+ }
146
+ if ((a === "-bd" || a === "--biz-domain") && args[i + 1]) {
147
+ businessDomain = args[++i];
148
+ continue;
149
+ }
150
+ if (a === "--pretty") {
151
+ pretty = true;
152
+ continue;
153
+ }
154
+ if (a === "--compact") {
155
+ pretty = false;
156
+ continue;
157
+ }
158
+ }
159
+ if (!businessDomain)
160
+ businessDomain = resolveBusinessDomain();
161
+ const token = await ensureValidToken();
162
+ const body = await listToolboxes({
163
+ baseUrl: token.baseUrl,
164
+ accessToken: token.accessToken,
165
+ businessDomain,
166
+ keyword, limit, offset,
167
+ });
168
+ console.log(formatCallOutput(body, pretty));
169
+ return 0;
170
+ }
171
+ export function parseToolboxSetStatusArgs(args) {
172
+ let boxId = "";
173
+ let businessDomain = "";
174
+ for (let i = 0; i < args.length; i += 1) {
175
+ const a = args[i];
176
+ if ((a === "-bd" || a === "--biz-domain") && args[i + 1]) {
177
+ businessDomain = args[++i];
178
+ continue;
179
+ }
180
+ if (!a.startsWith("-"))
181
+ boxId = a;
182
+ }
183
+ if (!boxId)
184
+ throw new Error("Missing required argument: <box-id>");
185
+ if (!businessDomain)
186
+ businessDomain = resolveBusinessDomain();
187
+ return { boxId, businessDomain };
188
+ }
189
+ async function runToolboxSetStatus(args, status) {
190
+ let opts;
191
+ try {
192
+ opts = parseToolboxSetStatusArgs(args);
193
+ }
194
+ catch (e) {
195
+ console.error(`Usage: kweaver toolbox ${status === "published" ? "publish" : "unpublish"} <box-id>`);
196
+ return 1;
197
+ }
198
+ const token = await ensureValidToken();
199
+ await setToolboxStatus({
200
+ baseUrl: token.baseUrl,
201
+ accessToken: token.accessToken,
202
+ businessDomain: opts.businessDomain,
203
+ boxId: opts.boxId,
204
+ status,
205
+ });
206
+ console.error(`${status === "published" ? "Published" : "Unpublished"} toolbox ${opts.boxId}`);
207
+ return 0;
208
+ }
209
+ // ── delete ────────────────────────────────────────────────────────────────────
210
+ function confirmYes(prompt) {
211
+ return new Promise((resolve) => {
212
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
213
+ rl.question(`${prompt} [y/N] `, (answer) => {
214
+ rl.close();
215
+ const t = answer.trim().toLowerCase();
216
+ resolve(t === "y" || t === "yes");
217
+ });
218
+ });
219
+ }
220
+ async function runToolboxDelete(args) {
221
+ let boxId = "";
222
+ let yes = false;
223
+ let businessDomain = "";
224
+ for (let i = 0; i < args.length; i += 1) {
225
+ const a = args[i];
226
+ if (a === "--yes" || a === "-y")
227
+ yes = true;
228
+ else if ((a === "-bd" || a === "--biz-domain") && args[i + 1]) {
229
+ businessDomain = args[++i];
230
+ }
231
+ else if (!a.startsWith("-"))
232
+ boxId = a;
233
+ }
234
+ if (!boxId) {
235
+ console.error("Usage: kweaver toolbox delete <box-id> [-y|--yes]");
236
+ return 1;
237
+ }
238
+ if (!yes) {
239
+ const ok = await confirmYes(`Delete toolbox ${boxId}?`);
240
+ if (!ok) {
241
+ console.error("Aborted.");
242
+ return 1;
243
+ }
244
+ }
245
+ if (!businessDomain)
246
+ businessDomain = resolveBusinessDomain();
247
+ const token = await ensureValidToken();
248
+ await deleteToolbox({
249
+ baseUrl: token.baseUrl,
250
+ accessToken: token.accessToken,
251
+ businessDomain,
252
+ boxId,
253
+ });
254
+ console.error(`Deleted toolbox ${boxId}`);
255
+ return 0;
256
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kweaver-ai/kweaver-sdk",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
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",
@@ -51,21 +51,11 @@
51
51
  "@types/node": "^24.6.0",
52
52
  "@types/react": "^19.2.14",
53
53
  "@types/yargs": "^17.0.35",
54
- "playwright": "^1.58.2",
55
54
  "tsx": "^4.20.5",
56
55
  "typescript": "^5.9.3"
57
56
  },
58
- "peerDependencies": {
59
- "playwright": ">=1.40.0"
60
- },
61
- "peerDependenciesMeta": {
62
- "playwright": {
63
- "optional": true
64
- }
65
- },
66
57
  "dependencies": {
67
58
  "@kweaver-ai/bkn": "^0.1.0",
68
- "@playwright/test": "^1.58.2",
69
59
  "chardet": "^2.1.1",
70
60
  "columnify": "^1.6.0",
71
61
  "csv-parse": "^6.2.1",