@kweaver-ai/kweaver-sdk 0.6.3 → 0.6.5
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 +29 -4
- package/README.zh.md +7 -3
- package/dist/api/dataflow.d.ts +1 -1
- package/dist/api/dataflow.js +4 -1
- package/dist/api/toolboxes.d.ts +47 -0
- package/dist/api/toolboxes.js +90 -0
- package/dist/auth/oauth.d.ts +69 -0
- package/dist/auth/oauth.js +647 -1
- package/dist/cli.js +20 -1
- package/dist/commands/auth.js +145 -18
- package/dist/commands/bkn-ops.d.ts +1 -0
- package/dist/commands/bkn-ops.js +8 -1
- package/dist/commands/call.d.ts +10 -0
- package/dist/commands/call.js +61 -5
- package/dist/commands/config.js +19 -9
- package/dist/commands/context-loader.js +8 -2
- package/dist/commands/ds.d.ts +1 -0
- package/dist/commands/ds.js +11 -11
- package/dist/commands/import-csv.d.ts +1 -1
- package/dist/commands/import-csv.js +3 -1
- package/dist/commands/tool.d.ts +16 -0
- package/dist/commands/tool.js +208 -0
- package/dist/commands/toolbox.d.ts +14 -0
- package/dist/commands/toolbox.js +256 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/package.json +1 -1
|
@@ -19,7 +19,7 @@ export interface DagBodyOptions {
|
|
|
19
19
|
tableExist: boolean;
|
|
20
20
|
data: Array<Record<string, string | null>>;
|
|
21
21
|
fieldMappings: FieldMapping[];
|
|
22
|
-
/** When true on the first batch (`tableExist` false), use
|
|
22
|
+
/** When true on the first batch (`tableExist` false), use "insert" to force table recreation. */
|
|
23
23
|
recreate?: boolean;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
@@ -82,7 +82,9 @@ export function buildFieldMappings(headers) {
|
|
|
82
82
|
export function buildDagBody(options) {
|
|
83
83
|
const { datasourceId, datasourceType, tableName, tableExist, data, fieldMappings, recreate } = options;
|
|
84
84
|
const ts = Date.now();
|
|
85
|
-
|
|
85
|
+
// "insert" creates/replaces the table; "append" adds rows to an existing table.
|
|
86
|
+
// With --recreate, use "insert" on first batch to force table recreation when schema changed.
|
|
87
|
+
const operateType = tableExist ? "append" : recreate ? "insert" : "append";
|
|
86
88
|
const triggerStep = {
|
|
87
89
|
id: "step-trigger",
|
|
88
90
|
title: "Trigger",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function runToolCommand(args: string[]): Promise<number>;
|
|
2
|
+
export interface ToolUploadOptions {
|
|
3
|
+
boxId: string;
|
|
4
|
+
filePath: string;
|
|
5
|
+
metadataType: "openapi";
|
|
6
|
+
businessDomain: string;
|
|
7
|
+
pretty: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function parseToolUploadArgs(args: string[]): ToolUploadOptions;
|
|
10
|
+
export interface ToolStatusOptions {
|
|
11
|
+
boxId: string;
|
|
12
|
+
toolIds: string[];
|
|
13
|
+
status: "enabled" | "disabled";
|
|
14
|
+
businessDomain: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function parseToolStatusArgs(args: string[], status: "enabled" | "disabled"): ToolStatusOptions;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { access } from "node:fs/promises";
|
|
2
|
+
import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
|
|
3
|
+
import { listTools, setToolStatuses, uploadTool } from "../api/toolboxes.js";
|
|
4
|
+
import { formatCallOutput } from "./call.js";
|
|
5
|
+
import { resolveBusinessDomain } from "../config/store.js";
|
|
6
|
+
const HELP = `kweaver tool
|
|
7
|
+
|
|
8
|
+
Subcommands:
|
|
9
|
+
upload --toolbox <box-id> <openapi-spec-path> [--metadata-type openapi]
|
|
10
|
+
Upload an OpenAPI spec file as a tool
|
|
11
|
+
list --toolbox <box-id> List tools in a toolbox
|
|
12
|
+
enable --toolbox <box-id> <tool-id>... Enable one or more tools
|
|
13
|
+
disable --toolbox <box-id> <tool-id>... Disable one or more tools
|
|
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 runToolCommand(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 === "upload")
|
|
27
|
+
return runToolUpload(rest);
|
|
28
|
+
if (subcommand === "list")
|
|
29
|
+
return runToolList(rest);
|
|
30
|
+
if (subcommand === "enable")
|
|
31
|
+
return runToolStatus(rest, "enabled");
|
|
32
|
+
if (subcommand === "disable")
|
|
33
|
+
return runToolStatus(rest, "disabled");
|
|
34
|
+
return Promise.resolve(-1);
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
return await with401RefreshRetry(async () => {
|
|
38
|
+
const code = await dispatch();
|
|
39
|
+
if (code === -1) {
|
|
40
|
+
console.error(`Unknown tool subcommand: ${subcommand}`);
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
return code;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error(formatHttpError(error));
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export function parseToolUploadArgs(args) {
|
|
52
|
+
let boxId = "";
|
|
53
|
+
let filePath = "";
|
|
54
|
+
let metadataType = "openapi";
|
|
55
|
+
let businessDomain = "";
|
|
56
|
+
let pretty = true;
|
|
57
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
58
|
+
const a = args[i];
|
|
59
|
+
if (a === "--toolbox" && args[i + 1]) {
|
|
60
|
+
boxId = args[++i];
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (a === "--metadata-type" && args[i + 1]) {
|
|
64
|
+
const val = args[++i];
|
|
65
|
+
if (val !== "openapi") {
|
|
66
|
+
throw new Error(`Unsupported --metadata-type: ${val} (only "openapi" is supported)`);
|
|
67
|
+
}
|
|
68
|
+
metadataType = val;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if ((a === "-bd" || a === "--biz-domain") && args[i + 1]) {
|
|
72
|
+
businessDomain = args[++i];
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (a === "--pretty") {
|
|
76
|
+
pretty = true;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (a === "--compact") {
|
|
80
|
+
pretty = false;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (!a.startsWith("-") && !filePath) {
|
|
84
|
+
filePath = a;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (!boxId)
|
|
89
|
+
throw new Error("Missing required flag: --toolbox");
|
|
90
|
+
if (!filePath)
|
|
91
|
+
throw new Error("Missing required positional argument: <file-path>");
|
|
92
|
+
if (!businessDomain)
|
|
93
|
+
businessDomain = resolveBusinessDomain();
|
|
94
|
+
return { boxId, filePath, metadataType, businessDomain, pretty };
|
|
95
|
+
}
|
|
96
|
+
async function runToolUpload(args) {
|
|
97
|
+
let opts;
|
|
98
|
+
try {
|
|
99
|
+
opts = parseToolUploadArgs(args);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
103
|
+
return 1;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
await access(opts.filePath);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
console.error(`File not found: ${opts.filePath}`);
|
|
110
|
+
return 1;
|
|
111
|
+
}
|
|
112
|
+
const token = await ensureValidToken();
|
|
113
|
+
const body = await uploadTool({
|
|
114
|
+
baseUrl: token.baseUrl,
|
|
115
|
+
accessToken: token.accessToken,
|
|
116
|
+
businessDomain: opts.businessDomain,
|
|
117
|
+
boxId: opts.boxId,
|
|
118
|
+
filePath: opts.filePath,
|
|
119
|
+
metadataType: opts.metadataType,
|
|
120
|
+
});
|
|
121
|
+
console.log(formatCallOutput(body, opts.pretty));
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
// ── list ──────────────────────────────────────────────────────────────────────
|
|
125
|
+
async function runToolList(args) {
|
|
126
|
+
let boxId = "";
|
|
127
|
+
let businessDomain = "";
|
|
128
|
+
let pretty = true;
|
|
129
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
130
|
+
const a = args[i];
|
|
131
|
+
if (a === "--toolbox" && args[i + 1]) {
|
|
132
|
+
boxId = args[++i];
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if ((a === "-bd" || a === "--biz-domain") && args[i + 1]) {
|
|
136
|
+
businessDomain = args[++i];
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (a === "--pretty") {
|
|
140
|
+
pretty = true;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (a === "--compact") {
|
|
144
|
+
pretty = false;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!boxId) {
|
|
149
|
+
console.error("Missing required flag: --toolbox");
|
|
150
|
+
return 1;
|
|
151
|
+
}
|
|
152
|
+
if (!businessDomain)
|
|
153
|
+
businessDomain = resolveBusinessDomain();
|
|
154
|
+
const token = await ensureValidToken();
|
|
155
|
+
const body = await listTools({
|
|
156
|
+
baseUrl: token.baseUrl,
|
|
157
|
+
accessToken: token.accessToken,
|
|
158
|
+
businessDomain,
|
|
159
|
+
boxId,
|
|
160
|
+
});
|
|
161
|
+
console.log(formatCallOutput(body, pretty));
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
164
|
+
export function parseToolStatusArgs(args, status) {
|
|
165
|
+
let boxId = "";
|
|
166
|
+
let businessDomain = "";
|
|
167
|
+
const toolIds = [];
|
|
168
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
169
|
+
const a = args[i];
|
|
170
|
+
if (a === "--toolbox" && args[i + 1]) {
|
|
171
|
+
boxId = args[++i];
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if ((a === "-bd" || a === "--biz-domain") && args[i + 1]) {
|
|
175
|
+
businessDomain = args[++i];
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (!a.startsWith("-"))
|
|
179
|
+
toolIds.push(a);
|
|
180
|
+
}
|
|
181
|
+
if (!boxId)
|
|
182
|
+
throw new Error("Missing required flag: --toolbox");
|
|
183
|
+
if (toolIds.length === 0)
|
|
184
|
+
throw new Error("Missing tool id(s)");
|
|
185
|
+
if (!businessDomain)
|
|
186
|
+
businessDomain = resolveBusinessDomain();
|
|
187
|
+
return { boxId, toolIds, status, businessDomain };
|
|
188
|
+
}
|
|
189
|
+
async function runToolStatus(args, status) {
|
|
190
|
+
let opts;
|
|
191
|
+
try {
|
|
192
|
+
opts = parseToolStatusArgs(args, status);
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
196
|
+
return 1;
|
|
197
|
+
}
|
|
198
|
+
const token = await ensureValidToken();
|
|
199
|
+
await setToolStatuses({
|
|
200
|
+
baseUrl: token.baseUrl,
|
|
201
|
+
accessToken: token.accessToken,
|
|
202
|
+
businessDomain: opts.businessDomain,
|
|
203
|
+
boxId: opts.boxId,
|
|
204
|
+
updates: opts.toolIds.map((toolId) => ({ toolId, status: opts.status })),
|
|
205
|
+
});
|
|
206
|
+
console.error(`${status === "enabled" ? "Enabled" : "Disabled"} ${opts.toolIds.length} tool(s) in toolbox ${opts.boxId}`);
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function runToolboxCommand(args: string[]): Promise<number>;
|
|
2
|
+
export interface ToolboxCreateOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
serviceUrl: string;
|
|
5
|
+
description: string;
|
|
6
|
+
businessDomain: string;
|
|
7
|
+
pretty: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function parseToolboxCreateArgs(args: string[]): ToolboxCreateOptions;
|
|
10
|
+
export interface ToolboxSetStatusOptions {
|
|
11
|
+
boxId: string;
|
|
12
|
+
businessDomain: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function parseToolboxSetStatusArgs(args: string[]): ToolboxSetStatusOptions;
|
|
@@ -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/dist/index.d.ts
CHANGED
|
@@ -62,3 +62,4 @@ export type { TokenConfig, ContextLoaderEntry, ContextLoaderConfig, } from "./co
|
|
|
62
62
|
export type { UserProfile } from "./config/store.js";
|
|
63
63
|
export { NO_AUTH_TOKEN, isNoAuth, saveNoAuthPlatform, autoSelectBusinessDomain, getConfigDir, getCurrentPlatform, getActiveUser, setActiveUser, listUsers, listUserProfiles, resolveUserId, extractUserId, } from "./config/store.js";
|
|
64
64
|
export { decodeJwtPayload, extractUserIdFromJwt } from "./config/jwt.js";
|
|
65
|
+
export { DEFAULT_SIGNIN_RSA_MODULUS_HEX, oauth2PasswordSigninLogin, parseSigninPageHtmlProps, rsaModulusHexToSpkiPem, STUDIOWEB_LOGIN_PUBLIC_KEY_PEM, } from "./auth/oauth.js";
|
package/dist/index.js
CHANGED
|
@@ -49,3 +49,5 @@ export { HttpError, NetworkRequestError, fetchTextOrThrow } from "./utils/http.j
|
|
|
49
49
|
export { NO_AUTH_TOKEN, isNoAuth, saveNoAuthPlatform, autoSelectBusinessDomain, getConfigDir, getCurrentPlatform, getActiveUser, setActiveUser, listUsers, listUserProfiles, resolveUserId, extractUserId, } from "./config/store.js";
|
|
50
50
|
// ── JWT utilities ─────────────────────────────────────────────────────────────
|
|
51
51
|
export { decodeJwtPayload, extractUserIdFromJwt } from "./config/jwt.js";
|
|
52
|
+
// ── OAuth (advanced — CLI uses these internally; optional for custom login tools) ─
|
|
53
|
+
export { DEFAULT_SIGNIN_RSA_MODULUS_HEX, oauth2PasswordSigninLogin, parseSigninPageHtmlProps, rsaModulusHexToSpkiPem, STUDIOWEB_LOGIN_PUBLIC_KEY_PEM, } from "./auth/oauth.js";
|
package/package.json
CHANGED