@kweaver-ai/kweaver-sdk 0.5.1 → 0.6.0

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.
Files changed (95) hide show
  1. package/README.md +25 -2
  2. package/README.zh.md +24 -1
  3. package/dist/api/agent-chat.d.ts +8 -2
  4. package/dist/api/agent-chat.js +150 -44
  5. package/dist/api/agent-list.d.ts +35 -0
  6. package/dist/api/agent-list.js +95 -21
  7. package/dist/api/bkn-backend.d.ts +60 -0
  8. package/dist/api/bkn-backend.js +103 -10
  9. package/dist/api/business-domains.js +9 -5
  10. package/dist/api/context-loader.js +4 -1
  11. package/dist/api/conversations.d.ts +6 -3
  12. package/dist/api/conversations.js +29 -35
  13. package/dist/api/dataflow.js +1 -10
  14. package/dist/api/dataflow2.d.ts +95 -0
  15. package/dist/api/dataflow2.js +80 -0
  16. package/dist/api/datasources.js +1 -10
  17. package/dist/api/dataviews.js +1 -10
  18. package/dist/api/headers.d.ts +11 -0
  19. package/dist/api/headers.js +30 -0
  20. package/dist/api/knowledge-networks.d.ts +41 -0
  21. package/dist/api/knowledge-networks.js +69 -22
  22. package/dist/api/ontology-query.d.ts +14 -1
  23. package/dist/api/ontology-query.js +63 -49
  24. package/dist/api/semantic-search.js +2 -12
  25. package/dist/api/skills.d.ts +141 -0
  26. package/dist/api/skills.js +208 -0
  27. package/dist/api/vega.d.ts +54 -7
  28. package/dist/api/vega.js +112 -25
  29. package/dist/auth/oauth.d.ts +5 -1
  30. package/dist/auth/oauth.js +351 -95
  31. package/dist/cli.js +49 -5
  32. package/dist/client.d.ts +12 -0
  33. package/dist/client.js +52 -8
  34. package/dist/commands/agent.d.ts +33 -1
  35. package/dist/commands/agent.js +721 -49
  36. package/dist/commands/auth.js +226 -55
  37. package/dist/commands/bkn-ops.d.ts +77 -0
  38. package/dist/commands/bkn-ops.js +1056 -0
  39. package/dist/commands/bkn-query.d.ts +14 -0
  40. package/dist/commands/bkn-query.js +370 -0
  41. package/dist/commands/bkn-schema.d.ts +135 -0
  42. package/dist/commands/bkn-schema.js +1483 -0
  43. package/dist/commands/bkn-utils.d.ts +36 -0
  44. package/dist/commands/bkn-utils.js +102 -0
  45. package/dist/commands/bkn.d.ts +7 -113
  46. package/dist/commands/bkn.js +175 -2429
  47. package/dist/commands/call.js +8 -5
  48. package/dist/commands/dataflow.d.ts +1 -0
  49. package/dist/commands/dataflow.js +251 -0
  50. package/dist/commands/dataview.d.ts +7 -0
  51. package/dist/commands/dataview.js +38 -2
  52. package/dist/commands/ds.d.ts +1 -0
  53. package/dist/commands/ds.js +8 -1
  54. package/dist/commands/explore-bkn.d.ts +79 -0
  55. package/dist/commands/explore-bkn.js +273 -0
  56. package/dist/commands/explore-chat.d.ts +3 -0
  57. package/dist/commands/explore-chat.js +193 -0
  58. package/dist/commands/explore-vega.d.ts +3 -0
  59. package/dist/commands/explore-vega.js +71 -0
  60. package/dist/commands/explore.d.ts +9 -0
  61. package/dist/commands/explore.js +258 -0
  62. package/dist/commands/import-csv.d.ts +2 -0
  63. package/dist/commands/import-csv.js +3 -2
  64. package/dist/commands/skill.d.ts +26 -0
  65. package/dist/commands/skill.js +524 -0
  66. package/dist/commands/vega.js +372 -117
  67. package/dist/config/jwt.d.ts +6 -0
  68. package/dist/config/jwt.js +21 -0
  69. package/dist/config/no-auth.d.ts +3 -0
  70. package/dist/config/no-auth.js +5 -0
  71. package/dist/config/store.d.ts +45 -5
  72. package/dist/config/store.js +385 -30
  73. package/dist/index.d.ts +6 -1
  74. package/dist/index.js +5 -1
  75. package/dist/kweaver.d.ts +5 -0
  76. package/dist/kweaver.js +32 -2
  77. package/dist/resources/bkn.d.ts +4 -0
  78. package/dist/resources/bkn.js +6 -3
  79. package/dist/resources/conversations.d.ts +5 -2
  80. package/dist/resources/conversations.js +17 -3
  81. package/dist/resources/knowledge-networks.js +3 -8
  82. package/dist/resources/skills.d.ts +47 -0
  83. package/dist/resources/skills.js +47 -0
  84. package/dist/resources/vega.d.ts +11 -6
  85. package/dist/resources/vega.js +37 -10
  86. package/dist/templates/explorer/app.js +136 -0
  87. package/dist/templates/explorer/bkn.js +747 -0
  88. package/dist/templates/explorer/chat.js +980 -0
  89. package/dist/templates/explorer/dashboard.js +82 -0
  90. package/dist/templates/explorer/index.html +35 -0
  91. package/dist/templates/explorer/style.css +2440 -0
  92. package/dist/templates/explorer/vega.js +291 -0
  93. package/dist/utils/http.d.ts +3 -0
  94. package/dist/utils/http.js +37 -1
  95. package/package.json +9 -5
@@ -0,0 +1,141 @@
1
+ export type SkillStatus = "unpublish" | "published" | "offline";
2
+ export type SkillFileType = "zip" | "content";
3
+ export interface SkillSummary {
4
+ skill_id: string;
5
+ name: string;
6
+ description?: string;
7
+ version?: string;
8
+ status?: SkillStatus;
9
+ source?: string;
10
+ create_user?: string;
11
+ create_time?: number;
12
+ update_user?: string;
13
+ update_time?: number;
14
+ business_domain_id?: string;
15
+ category?: string;
16
+ category_name?: string;
17
+ }
18
+ export interface SkillInfo extends SkillSummary {
19
+ dependencies?: Record<string, unknown>;
20
+ extend_info?: Record<string, unknown>;
21
+ }
22
+ export interface SkillFileSummary {
23
+ rel_path: string;
24
+ file_type?: string;
25
+ size?: number;
26
+ mime_type?: string;
27
+ }
28
+ export interface SkillContentIndex {
29
+ skill_id: string;
30
+ url: string;
31
+ files: SkillFileSummary[];
32
+ status?: SkillStatus;
33
+ }
34
+ export interface SkillFileReadResult {
35
+ skill_id: string;
36
+ rel_path: string;
37
+ url: string;
38
+ mime_type?: string;
39
+ file_type?: string;
40
+ }
41
+ export interface RegisterSkillResult {
42
+ skill_id: string;
43
+ name: string;
44
+ description?: string;
45
+ version?: string;
46
+ status?: SkillStatus;
47
+ files?: string[];
48
+ }
49
+ export interface DeleteSkillResult {
50
+ skill_id: string;
51
+ deleted: boolean;
52
+ }
53
+ export interface UpdateSkillStatusResult {
54
+ skill_id: string;
55
+ status: SkillStatus;
56
+ }
57
+ export interface SkillListResult {
58
+ total_count?: number;
59
+ total?: number;
60
+ page?: number;
61
+ page_size?: number;
62
+ total_page?: number;
63
+ total_pages?: number;
64
+ has_next?: boolean;
65
+ has_prev?: boolean;
66
+ data: SkillSummary[];
67
+ }
68
+ export interface SkillApiBaseOptions {
69
+ baseUrl: string;
70
+ accessToken: string;
71
+ businessDomain?: string;
72
+ }
73
+ export interface ListSkillsOptions extends SkillApiBaseOptions {
74
+ page?: number;
75
+ pageSize?: number;
76
+ sortBy?: "create_time" | "update_time" | "name";
77
+ sortOrder?: "asc" | "desc";
78
+ all?: boolean;
79
+ name?: string;
80
+ status?: SkillStatus;
81
+ source?: string;
82
+ createUser?: string;
83
+ }
84
+ export interface ListSkillMarketOptions extends SkillApiBaseOptions {
85
+ page?: number;
86
+ pageSize?: number;
87
+ sortBy?: "create_time" | "update_time" | "name";
88
+ sortOrder?: "asc" | "desc";
89
+ all?: boolean;
90
+ name?: string;
91
+ source?: string;
92
+ }
93
+ export interface GetSkillOptions extends SkillApiBaseOptions {
94
+ skillId: string;
95
+ }
96
+ export interface RegisterSkillContentOptions extends SkillApiBaseOptions {
97
+ content: string;
98
+ source?: string;
99
+ extendInfo?: Record<string, unknown>;
100
+ }
101
+ export interface RegisterSkillZipOptions extends SkillApiBaseOptions {
102
+ filename: string;
103
+ bytes: Uint8Array;
104
+ source?: string;
105
+ extendInfo?: Record<string, unknown>;
106
+ }
107
+ export interface UpdateSkillStatusOptions extends SkillApiBaseOptions {
108
+ skillId: string;
109
+ status: SkillStatus;
110
+ }
111
+ export interface ReadSkillFileOptions extends SkillApiBaseOptions {
112
+ skillId: string;
113
+ relPath: string;
114
+ }
115
+ export interface DownloadSkillOptions extends SkillApiBaseOptions {
116
+ skillId: string;
117
+ }
118
+ export interface DownloadedSkillArchive {
119
+ fileName: string;
120
+ bytes: Uint8Array;
121
+ }
122
+ export interface InstallSkillArchiveOptions {
123
+ bytes: Uint8Array;
124
+ directory: string;
125
+ force?: boolean;
126
+ }
127
+ export declare function listSkills(options: ListSkillsOptions): Promise<SkillListResult>;
128
+ export declare function listSkillMarket(options: ListSkillMarketOptions): Promise<SkillListResult>;
129
+ export declare function getSkill(options: GetSkillOptions): Promise<SkillInfo>;
130
+ export declare function deleteSkill(options: GetSkillOptions): Promise<DeleteSkillResult>;
131
+ export declare function updateSkillStatus(options: UpdateSkillStatusOptions): Promise<UpdateSkillStatusResult>;
132
+ export declare function registerSkillContent(options: RegisterSkillContentOptions): Promise<RegisterSkillResult>;
133
+ export declare function registerSkillZip(options: RegisterSkillZipOptions): Promise<RegisterSkillResult>;
134
+ export declare function getSkillContentIndex(options: GetSkillOptions): Promise<SkillContentIndex>;
135
+ export declare function fetchSkillContent(options: GetSkillOptions): Promise<string>;
136
+ export declare function readSkillFile(options: ReadSkillFileOptions): Promise<SkillFileReadResult>;
137
+ export declare function fetchSkillFile(options: ReadSkillFileOptions): Promise<Uint8Array>;
138
+ export declare function downloadSkill(options: DownloadSkillOptions): Promise<DownloadedSkillArchive>;
139
+ export declare function installSkillArchive(options: InstallSkillArchiveOptions): {
140
+ directory: string;
141
+ };
@@ -0,0 +1,208 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { Buffer } from "node:buffer";
3
+ import { existsSync, mkdirSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
4
+ import { basename, resolve } from "node:path";
5
+ import { buildHeaders as buildPlatformHeaders } from "./headers.js";
6
+ import { HttpError, fetchTextOrThrow } from "../utils/http.js";
7
+ const SKILL_API_PREFIX = "/api/agent-operator-integration/v1";
8
+ function baseHeaders(opts) {
9
+ return buildPlatformHeaders(opts.accessToken, opts.businessDomain ?? "bd_public");
10
+ }
11
+ function buildUrl(baseUrl, path) {
12
+ return `${baseUrl.replace(/\/+$/, "")}${path}`;
13
+ }
14
+ function unwrapEnvelope(raw) {
15
+ const parsed = JSON.parse(raw);
16
+ if (parsed && typeof parsed === "object" && "data" in parsed) {
17
+ return parsed.data;
18
+ }
19
+ return parsed;
20
+ }
21
+ function appendCommonListParams(url, opts) {
22
+ if (opts.page !== undefined)
23
+ url.searchParams.set("page", String(opts.page));
24
+ if (opts.pageSize !== undefined)
25
+ url.searchParams.set("page_size", String(opts.pageSize));
26
+ if (opts.sortBy)
27
+ url.searchParams.set("sort_by", opts.sortBy);
28
+ if (opts.sortOrder)
29
+ url.searchParams.set("sort_order", opts.sortOrder);
30
+ if (opts.all !== undefined)
31
+ url.searchParams.set("all", String(opts.all));
32
+ if (opts.name)
33
+ url.searchParams.set("name", opts.name);
34
+ if (opts.source)
35
+ url.searchParams.set("source", opts.source);
36
+ }
37
+ function parseContentDisposition(value) {
38
+ if (!value)
39
+ return undefined;
40
+ const utf8Match = /filename\*=UTF-8''([^;]+)/i.exec(value);
41
+ if (utf8Match?.[1]) {
42
+ return decodeURIComponent(utf8Match[1]);
43
+ }
44
+ const plainMatch = /filename="?([^";]+)"?/i.exec(value);
45
+ return plainMatch?.[1];
46
+ }
47
+ async function fetchBytesOrThrow(input, init) {
48
+ const response = await fetch(input, init);
49
+ const body = new Uint8Array(await response.arrayBuffer());
50
+ if (!response.ok) {
51
+ throw new HttpError(response.status, response.statusText, new TextDecoder().decode(body));
52
+ }
53
+ return { response, body };
54
+ }
55
+ export async function listSkills(options) {
56
+ const url = new URL(buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills`));
57
+ appendCommonListParams(url, options);
58
+ if (options.status)
59
+ url.searchParams.set("status", options.status);
60
+ if (options.createUser)
61
+ url.searchParams.set("create_user", options.createUser);
62
+ const { body } = await fetchTextOrThrow(url, { headers: baseHeaders(options) });
63
+ return unwrapEnvelope(body);
64
+ }
65
+ export async function listSkillMarket(options) {
66
+ const url = new URL(buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/market`));
67
+ appendCommonListParams(url, options);
68
+ const { body } = await fetchTextOrThrow(url, { headers: baseHeaders(options) });
69
+ return unwrapEnvelope(body);
70
+ }
71
+ export async function getSkill(options) {
72
+ const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/${encodeURIComponent(options.skillId)}`);
73
+ const { body } = await fetchTextOrThrow(url, { headers: baseHeaders(options) });
74
+ return unwrapEnvelope(body);
75
+ }
76
+ export async function deleteSkill(options) {
77
+ const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/${encodeURIComponent(options.skillId)}`);
78
+ const { body } = await fetchTextOrThrow(url, { method: "DELETE", headers: baseHeaders(options) });
79
+ return unwrapEnvelope(body);
80
+ }
81
+ export async function updateSkillStatus(options) {
82
+ const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/${encodeURIComponent(options.skillId)}/status`);
83
+ const { body } = await fetchTextOrThrow(url, {
84
+ method: "PUT",
85
+ headers: { ...baseHeaders(options), "content-type": "application/json" },
86
+ body: JSON.stringify({ status: options.status }),
87
+ });
88
+ return unwrapEnvelope(body);
89
+ }
90
+ export async function registerSkillContent(options) {
91
+ const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills`);
92
+ const payload = {
93
+ file_type: "content",
94
+ file: options.content,
95
+ };
96
+ if (options.source)
97
+ payload.source = options.source;
98
+ if (options.extendInfo)
99
+ payload.extend_info = options.extendInfo;
100
+ const { body } = await fetchTextOrThrow(url, {
101
+ method: "POST",
102
+ headers: { ...baseHeaders(options), "content-type": "application/json" },
103
+ body: JSON.stringify(payload),
104
+ });
105
+ return unwrapEnvelope(body);
106
+ }
107
+ export async function registerSkillZip(options) {
108
+ const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills`);
109
+ const form = new FormData();
110
+ form.set("file_type", "zip");
111
+ form.set("file", new Blob([Buffer.from(options.bytes)]), options.filename);
112
+ if (options.source)
113
+ form.set("source", options.source);
114
+ if (options.extendInfo)
115
+ form.set("extend_info", JSON.stringify(options.extendInfo));
116
+ const { body } = await fetchTextOrThrow(url, {
117
+ method: "POST",
118
+ headers: baseHeaders(options),
119
+ body: form,
120
+ });
121
+ return unwrapEnvelope(body);
122
+ }
123
+ export async function getSkillContentIndex(options) {
124
+ const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/${encodeURIComponent(options.skillId)}/content`);
125
+ const { body } = await fetchTextOrThrow(url, { headers: baseHeaders(options) });
126
+ return unwrapEnvelope(body);
127
+ }
128
+ export async function fetchSkillContent(options) {
129
+ const index = await getSkillContentIndex(options);
130
+ const { body } = await fetchTextOrThrow(index.url);
131
+ return body;
132
+ }
133
+ export async function readSkillFile(options) {
134
+ const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/${encodeURIComponent(options.skillId)}/files/read`);
135
+ const { body } = await fetchTextOrThrow(url, {
136
+ method: "POST",
137
+ headers: { ...baseHeaders(options), "content-type": "application/json" },
138
+ body: JSON.stringify({ rel_path: options.relPath }),
139
+ });
140
+ return unwrapEnvelope(body);
141
+ }
142
+ export async function fetchSkillFile(options) {
143
+ const file = await readSkillFile(options);
144
+ const { body } = await fetchBytesOrThrow(file.url);
145
+ return body;
146
+ }
147
+ export async function downloadSkill(options) {
148
+ const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/${encodeURIComponent(options.skillId)}/download`);
149
+ const { response, body } = await fetchBytesOrThrow(url, { headers: baseHeaders(options) });
150
+ const serverName = parseContentDisposition(response.headers.get("content-disposition"));
151
+ return {
152
+ fileName: basename(serverName || `${options.skillId}.zip`),
153
+ bytes: body,
154
+ };
155
+ }
156
+ export function installSkillArchive(options) {
157
+ const targetDir = resolve(options.directory);
158
+ const existed = existsSync(targetDir);
159
+ if (existed) {
160
+ const entries = readdirSync(targetDir);
161
+ if (entries.length > 0) {
162
+ if (!options.force) {
163
+ throw new Error(`Install target is not empty: ${targetDir}. Use --force to replace it.`);
164
+ }
165
+ }
166
+ }
167
+ const parentDir = resolve(targetDir, "..");
168
+ mkdirSync(parentDir, { recursive: true });
169
+ const archivePath = resolve(parentDir, `${basename(targetDir)}.zip`);
170
+ const stagingDir = resolve(parentDir, `.${basename(targetDir)}.tmp-${process.pid}-${Date.now()}`);
171
+ const backupDir = existed ? resolve(parentDir, `.${basename(targetDir)}.bak-${process.pid}-${Date.now()}`) : undefined;
172
+ mkdirSync(stagingDir, { recursive: true });
173
+ writeFileSync(archivePath, options.bytes);
174
+ try {
175
+ const result = spawnSync("unzip", ["-oq", archivePath, "-d", stagingDir], {
176
+ encoding: "utf8",
177
+ });
178
+ if (result.error) {
179
+ throw result.error;
180
+ }
181
+ if (result.status !== 0) {
182
+ throw new Error(result.stderr || `unzip exited with status ${result.status}`);
183
+ }
184
+ if (existsSync(targetDir)) {
185
+ renameSync(targetDir, backupDir);
186
+ }
187
+ renameSync(stagingDir, targetDir);
188
+ if (backupDir && existsSync(backupDir)) {
189
+ rmSync(backupDir, { recursive: true, force: true });
190
+ }
191
+ return { directory: targetDir };
192
+ }
193
+ catch (error) {
194
+ rmSync(stagingDir, { recursive: true, force: true });
195
+ if (backupDir && existsSync(backupDir) && !existsSync(targetDir)) {
196
+ renameSync(backupDir, targetDir);
197
+ }
198
+ throw new Error(error instanceof Error
199
+ ? `Skill install failed: ${error.message}`
200
+ : `Skill install failed: ${String(error)}`);
201
+ }
202
+ finally {
203
+ rmSync(archivePath, { force: true });
204
+ if (backupDir && existsSync(backupDir)) {
205
+ rmSync(backupDir, { recursive: true, force: true });
206
+ }
207
+ }
208
+ }
@@ -165,19 +165,66 @@ export interface SetVegaConnectorTypeEnabledOptions {
165
165
  businessDomain?: string;
166
166
  }
167
167
  export declare function setVegaConnectorTypeEnabled(options: SetVegaConnectorTypeEnabledOptions): Promise<string>;
168
- export interface ListVegaDiscoverTasksOptions {
168
+ export interface CreateVegaDatasetDocsOptions {
169
169
  baseUrl: string;
170
170
  accessToken: string;
171
- status?: string;
172
- limit?: number;
173
- offset?: number;
171
+ id: string;
172
+ body: string;
173
+ businessDomain?: string;
174
+ }
175
+ export declare function createVegaDatasetDocs(options: CreateVegaDatasetDocsOptions): Promise<string>;
176
+ export interface UpdateVegaDatasetDocsOptions {
177
+ baseUrl: string;
178
+ accessToken: string;
179
+ id: string;
180
+ body: string;
181
+ businessDomain?: string;
182
+ }
183
+ export declare function updateVegaDatasetDocs(options: UpdateVegaDatasetDocsOptions): Promise<string>;
184
+ export interface DeleteVegaDatasetDocsOptions {
185
+ baseUrl: string;
186
+ accessToken: string;
187
+ id: string;
188
+ docIds: string;
189
+ businessDomain?: string;
190
+ }
191
+ export declare function deleteVegaDatasetDocs(options: DeleteVegaDatasetDocsOptions): Promise<string>;
192
+ export interface DeleteVegaDatasetDocsQueryOptions {
193
+ baseUrl: string;
194
+ accessToken: string;
195
+ id: string;
196
+ body: string;
197
+ businessDomain?: string;
198
+ }
199
+ export declare function deleteVegaDatasetDocsQuery(options: DeleteVegaDatasetDocsQueryOptions): Promise<string>;
200
+ export interface BuildVegaDatasetOptions {
201
+ baseUrl: string;
202
+ accessToken: string;
203
+ id: string;
204
+ mode?: string;
174
205
  businessDomain?: string;
175
206
  }
176
- export declare function listVegaDiscoverTasks(options: ListVegaDiscoverTasksOptions): Promise<string>;
177
- export interface GetVegaDiscoverTaskOptions {
207
+ export declare function buildVegaDataset(options: BuildVegaDatasetOptions): Promise<string>;
208
+ export interface GetVegaDatasetBuildStatusOptions {
178
209
  baseUrl: string;
179
210
  accessToken: string;
180
211
  id: string;
212
+ taskId: string;
213
+ businessDomain?: string;
214
+ }
215
+ export declare function getVegaDatasetBuildStatus(options: GetVegaDatasetBuildStatusOptions): Promise<string>;
216
+ export interface ExecuteVegaQueryOptions {
217
+ baseUrl: string;
218
+ accessToken: string;
219
+ body: string;
220
+ businessDomain?: string;
221
+ }
222
+ export declare function executeVegaQuery(options: ExecuteVegaQueryOptions): Promise<string>;
223
+ export interface ListAllVegaResourcesOptions {
224
+ baseUrl: string;
225
+ accessToken: string;
226
+ limit?: number;
227
+ offset?: number;
181
228
  businessDomain?: string;
182
229
  }
183
- export declare function getVegaDiscoverTask(options: GetVegaDiscoverTaskOptions): Promise<string>;
230
+ export declare function listAllVegaResources(options: ListAllVegaResourcesOptions): Promise<string>;
package/dist/api/vega.js CHANGED
@@ -1,15 +1,6 @@
1
1
  import { HttpError } from "../utils/http.js";
2
+ import { buildHeaders } from "./headers.js";
2
3
  const VEGA_BASE = "/api/vega-backend/v1";
3
- function buildHeaders(accessToken, businessDomain) {
4
- return {
5
- accept: "application/json, text/plain, */*",
6
- "accept-language": "zh-cn",
7
- authorization: `Bearer ${accessToken}`,
8
- token: accessToken,
9
- "x-business-domain": businessDomain,
10
- "x-language": "zh-cn",
11
- };
12
- }
13
4
  export async function vegaHealth(options) {
14
5
  const { baseUrl, accessToken, businessDomain = "bd_public", } = options;
15
6
  const base = baseUrl.replace(/\/+$/, "");
@@ -355,31 +346,127 @@ export async function setVegaConnectorTypeEnabled(options) {
355
346
  throw new HttpError(response.status, response.statusText, body);
356
347
  return body;
357
348
  }
358
- export async function listVegaDiscoverTasks(options) {
359
- const { baseUrl, accessToken, status, limit, offset, businessDomain = "bd_public", } = options;
349
+ export async function createVegaDatasetDocs(options) {
350
+ const { baseUrl, accessToken, id, body: requestBody, businessDomain = "bd_public" } = options;
360
351
  const base = baseUrl.replace(/\/+$/, "");
361
- const url = new URL(`${base}${VEGA_BASE}/discover-tasks`);
362
- if (status)
363
- url.searchParams.set("status", status);
364
- if (limit !== undefined)
365
- url.searchParams.set("limit", String(limit));
366
- if (offset !== undefined)
367
- url.searchParams.set("offset", String(offset));
368
- const response = await fetch(url.toString(), {
352
+ const url = `${base}${VEGA_BASE}/resources/dataset/${encodeURIComponent(id)}/docs`;
353
+ const response = await fetch(url, {
354
+ method: "POST",
355
+ headers: {
356
+ ...buildHeaders(accessToken, businessDomain),
357
+ "content-type": "application/json",
358
+ },
359
+ body: requestBody,
360
+ });
361
+ const body = await response.text();
362
+ if (!response.ok)
363
+ throw new HttpError(response.status, response.statusText, body);
364
+ return body;
365
+ }
366
+ export async function updateVegaDatasetDocs(options) {
367
+ const { baseUrl, accessToken, id, body: requestBody, businessDomain = "bd_public" } = options;
368
+ const base = baseUrl.replace(/\/+$/, "");
369
+ const url = `${base}${VEGA_BASE}/resources/dataset/${encodeURIComponent(id)}/docs`;
370
+ const response = await fetch(url, {
371
+ method: "PUT",
372
+ headers: {
373
+ ...buildHeaders(accessToken, businessDomain),
374
+ "content-type": "application/json",
375
+ },
376
+ body: requestBody,
377
+ });
378
+ const body = await response.text();
379
+ if (!response.ok)
380
+ throw new HttpError(response.status, response.statusText, body);
381
+ return body;
382
+ }
383
+ export async function deleteVegaDatasetDocs(options) {
384
+ const { baseUrl, accessToken, id, docIds, businessDomain = "bd_public" } = options;
385
+ const base = baseUrl.replace(/\/+$/, "");
386
+ const url = `${base}${VEGA_BASE}/resources/dataset/${encodeURIComponent(id)}/docs/${encodeURIComponent(docIds)}`;
387
+ const response = await fetch(url, {
388
+ method: "DELETE",
389
+ headers: buildHeaders(accessToken, businessDomain),
390
+ });
391
+ const body = await response.text();
392
+ if (!response.ok)
393
+ throw new HttpError(response.status, response.statusText, body);
394
+ return body;
395
+ }
396
+ export async function deleteVegaDatasetDocsQuery(options) {
397
+ const { baseUrl, accessToken, id, body: requestBody, businessDomain = "bd_public" } = options;
398
+ const base = baseUrl.replace(/\/+$/, "");
399
+ const url = `${base}${VEGA_BASE}/resources/dataset/${encodeURIComponent(id)}/docs/query`;
400
+ const response = await fetch(url, {
401
+ method: "POST",
402
+ headers: {
403
+ ...buildHeaders(accessToken, businessDomain),
404
+ "content-type": "application/json",
405
+ "x-http-method-override": "DELETE",
406
+ },
407
+ body: requestBody,
408
+ });
409
+ const body = await response.text();
410
+ if (!response.ok)
411
+ throw new HttpError(response.status, response.statusText, body);
412
+ return body;
413
+ }
414
+ export async function buildVegaDataset(options) {
415
+ const { baseUrl, accessToken, id, mode = "full", businessDomain = "bd_public" } = options;
416
+ const base = baseUrl.replace(/\/+$/, "");
417
+ const url = `${base}${VEGA_BASE}/resources/${encodeURIComponent(id)}/build`;
418
+ const response = await fetch(url, {
419
+ method: "POST",
420
+ headers: {
421
+ ...buildHeaders(accessToken, businessDomain),
422
+ "content-type": "application/json",
423
+ },
424
+ body: JSON.stringify({ mode }),
425
+ });
426
+ const body = await response.text();
427
+ if (!response.ok)
428
+ throw new HttpError(response.status, response.statusText, body);
429
+ return body;
430
+ }
431
+ export async function getVegaDatasetBuildStatus(options) {
432
+ const { baseUrl, accessToken, id, taskId, businessDomain = "bd_public" } = options;
433
+ const base = baseUrl.replace(/\/+$/, "");
434
+ const url = `${base}${VEGA_BASE}/resources/dataset/${encodeURIComponent(id)}/build/${encodeURIComponent(taskId)}`;
435
+ const response = await fetch(url, {
369
436
  method: "GET",
370
437
  headers: buildHeaders(accessToken, businessDomain),
371
438
  });
372
439
  const body = await response.text();
373
- if (!response.ok) {
440
+ if (!response.ok)
374
441
  throw new HttpError(response.status, response.statusText, body);
375
- }
376
442
  return body;
377
443
  }
378
- export async function getVegaDiscoverTask(options) {
379
- const { baseUrl, accessToken, id, businessDomain = "bd_public" } = options;
444
+ export async function executeVegaQuery(options) {
445
+ const { baseUrl, accessToken, body: requestBody, businessDomain = "bd_public" } = options;
380
446
  const base = baseUrl.replace(/\/+$/, "");
381
- const url = `${base}${VEGA_BASE}/discover-tasks/${encodeURIComponent(id)}`;
447
+ const url = `${base}${VEGA_BASE}/query/execute`;
382
448
  const response = await fetch(url, {
449
+ method: "POST",
450
+ headers: {
451
+ ...buildHeaders(accessToken, businessDomain),
452
+ "content-type": "application/json",
453
+ },
454
+ body: requestBody,
455
+ });
456
+ const body = await response.text();
457
+ if (!response.ok)
458
+ throw new HttpError(response.status, response.statusText, body);
459
+ return body;
460
+ }
461
+ export async function listAllVegaResources(options) {
462
+ const { baseUrl, accessToken, limit, offset, businessDomain = "bd_public" } = options;
463
+ const base = baseUrl.replace(/\/+$/, "");
464
+ const url = new URL(`${base}${VEGA_BASE}/resources/list`);
465
+ if (limit !== undefined)
466
+ url.searchParams.set("limit", String(limit));
467
+ if (offset !== undefined)
468
+ url.searchParams.set("offset", String(offset));
469
+ const response = await fetch(url.toString(), {
383
470
  method: "GET",
384
471
  headers: buildHeaders(accessToken, businessDomain),
385
472
  });
@@ -15,12 +15,14 @@ export declare function normalizeBaseUrl(value: string): string;
15
15
  * OAuth2 Authorization Code login flow.
16
16
  * 1. Register client (if not already registered), OR use a provided client ID
17
17
  * 2. Open browser to /oauth2/auth
18
- * 3. Receive authorization code via local HTTP callback
18
+ * 3. Receive authorization code via local HTTP callback (or manual paste for non-localhost)
19
19
  * 4. Exchange code for access_token + refresh_token
20
20
  * 5. Save token.json + client.json to ~/.kweaver/
21
21
  */
22
22
  export declare function oauth2Login(baseUrl: string, options?: {
23
23
  port?: number;
24
+ /** Full redirect URI override (e.g. "http://127.0.0.1:9010/callback" or a remote URL). */
25
+ redirectUri?: string;
24
26
  scope?: string;
25
27
  clientId?: string;
26
28
  clientSecret?: string;
@@ -42,6 +44,8 @@ export declare function playwrightLogin(baseUrl: string, options?: {
42
44
  username?: string;
43
45
  password?: string;
44
46
  port?: number;
47
+ /** Full redirect URI override. */
48
+ redirectUri?: string;
45
49
  scope?: string;
46
50
  tlsInsecure?: boolean;
47
51
  }): Promise<TokenConfig>;