@kweaver-ai/kweaver-sdk 0.5.2 → 0.6.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.
Files changed (57) hide show
  1. package/README.md +19 -1
  2. package/README.zh.md +19 -1
  3. package/dist/api/agent-chat.d.ts +7 -1
  4. package/dist/api/agent-chat.js +146 -40
  5. package/dist/api/agent-list.js +13 -13
  6. package/dist/api/business-domains.js +9 -5
  7. package/dist/api/context-loader.js +4 -1
  8. package/dist/api/conversations.js +4 -9
  9. package/dist/api/dataflow2.d.ts +95 -0
  10. package/dist/api/dataflow2.js +80 -0
  11. package/dist/api/headers.d.ts +2 -0
  12. package/dist/api/headers.js +7 -2
  13. package/dist/api/skills.js +2 -10
  14. package/dist/api/vega.d.ts +0 -16
  15. package/dist/api/vega.js +0 -33
  16. package/dist/auth/oauth.d.ts +7 -6
  17. package/dist/auth/oauth.js +170 -80
  18. package/dist/cli.js +21 -1
  19. package/dist/client.d.ts +9 -0
  20. package/dist/client.js +48 -8
  21. package/dist/commands/auth.js +103 -42
  22. package/dist/commands/bkn-schema.js +22 -0
  23. package/dist/commands/call.js +8 -5
  24. package/dist/commands/dataflow.d.ts +1 -0
  25. package/dist/commands/dataflow.js +251 -0
  26. package/dist/commands/explore-bkn.d.ts +79 -0
  27. package/dist/commands/explore-bkn.js +273 -0
  28. package/dist/commands/explore-chat.d.ts +3 -0
  29. package/dist/commands/explore-chat.js +193 -0
  30. package/dist/commands/explore-vega.d.ts +3 -0
  31. package/dist/commands/explore-vega.js +71 -0
  32. package/dist/commands/explore.d.ts +9 -0
  33. package/dist/commands/explore.js +258 -0
  34. package/dist/commands/vega.js +2 -104
  35. package/dist/config/no-auth.d.ts +3 -0
  36. package/dist/config/no-auth.js +5 -0
  37. package/dist/config/store.d.ts +8 -0
  38. package/dist/config/store.js +22 -0
  39. package/dist/index.d.ts +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/kweaver.d.ts +5 -0
  42. package/dist/kweaver.js +32 -2
  43. package/dist/resources/bkn.js +2 -3
  44. package/dist/resources/knowledge-networks.js +3 -8
  45. package/dist/resources/vega.d.ts +0 -6
  46. package/dist/resources/vega.js +1 -10
  47. package/dist/templates/explorer/app.js +136 -0
  48. package/dist/templates/explorer/bkn.js +747 -0
  49. package/dist/templates/explorer/chat.js +980 -0
  50. package/dist/templates/explorer/dashboard.js +82 -0
  51. package/dist/templates/explorer/index.html +35 -0
  52. package/dist/templates/explorer/style.css +2440 -0
  53. package/dist/templates/explorer/vega.js +291 -0
  54. package/dist/utils/browser.js +33 -10
  55. package/dist/utils/http.d.ts +3 -0
  56. package/dist/utils/http.js +37 -1
  57. package/package.json +9 -5
@@ -0,0 +1,95 @@
1
+ export interface DataflowListItem {
2
+ id: string;
3
+ title?: string;
4
+ status?: string;
5
+ trigger?: string;
6
+ creator?: string;
7
+ updated_at?: number;
8
+ version_id?: string;
9
+ }
10
+ export interface DataflowListResponse {
11
+ dags: DataflowListItem[];
12
+ limit?: number;
13
+ page?: number;
14
+ total?: number;
15
+ }
16
+ export interface DataflowRunSource {
17
+ name?: string;
18
+ content_type?: string;
19
+ size?: number;
20
+ [key: string]: unknown;
21
+ }
22
+ export interface DataflowRunItem {
23
+ id: string;
24
+ status?: string;
25
+ started_at?: number;
26
+ ended_at?: number | null;
27
+ reason?: string | null;
28
+ source?: DataflowRunSource;
29
+ }
30
+ export interface DataflowRunsResponse {
31
+ results: DataflowRunItem[];
32
+ limit?: number;
33
+ page?: number;
34
+ total?: number;
35
+ }
36
+ export interface DataflowLogMetadata {
37
+ duration?: number;
38
+ [key: string]: unknown;
39
+ }
40
+ export interface DataflowLogItem {
41
+ id: string;
42
+ operator?: string;
43
+ status?: string;
44
+ started_at?: number;
45
+ updated_at?: number;
46
+ inputs?: unknown;
47
+ outputs?: unknown;
48
+ taskId?: string;
49
+ metadata?: DataflowLogMetadata;
50
+ }
51
+ export interface DataflowLogsResponse {
52
+ results: DataflowLogItem[];
53
+ limit?: number;
54
+ page?: number;
55
+ total?: number;
56
+ }
57
+ export interface DataflowRunResponse {
58
+ dag_instance_id: string;
59
+ }
60
+ interface BaseOptions {
61
+ baseUrl: string;
62
+ accessToken: string;
63
+ businessDomain?: string;
64
+ }
65
+ export interface RunDataflowWithFileOptions extends BaseOptions {
66
+ dagId: string;
67
+ fileName: string;
68
+ fileBytes: Uint8Array;
69
+ }
70
+ export interface RunDataflowWithRemoteUrlOptions extends BaseOptions {
71
+ dagId: string;
72
+ url: string;
73
+ name: string;
74
+ }
75
+ export interface ListDataflowRunsOptions extends BaseOptions {
76
+ dagId: string;
77
+ page?: number;
78
+ limit?: number;
79
+ sortBy?: string;
80
+ order?: string;
81
+ startTime?: number;
82
+ endTime?: number;
83
+ }
84
+ export interface GetDataflowLogsPageOptions extends BaseOptions {
85
+ dagId: string;
86
+ instanceId: string;
87
+ page: number;
88
+ limit?: number;
89
+ }
90
+ export declare function listDataflows(options: BaseOptions): Promise<DataflowListResponse>;
91
+ export declare function runDataflowWithFile(options: RunDataflowWithFileOptions): Promise<DataflowRunResponse>;
92
+ export declare function runDataflowWithRemoteUrl(options: RunDataflowWithRemoteUrlOptions): Promise<DataflowRunResponse>;
93
+ export declare function listDataflowRuns(options: ListDataflowRunsOptions): Promise<DataflowRunsResponse>;
94
+ export declare function getDataflowLogsPage(options: GetDataflowLogsPageOptions): Promise<DataflowLogsResponse>;
95
+ export {};
@@ -0,0 +1,80 @@
1
+ import { HttpError } from "../utils/http.js";
2
+ import { buildHeaders } from "./headers.js";
3
+ async function parseJsonOrThrow(response) {
4
+ const body = await response.text();
5
+ if (!response.ok) {
6
+ throw new HttpError(response.status, response.statusText, body);
7
+ }
8
+ return JSON.parse(body);
9
+ }
10
+ export async function listDataflows(options) {
11
+ const { baseUrl, accessToken, businessDomain = "bd_public" } = options;
12
+ const base = baseUrl.replace(/\/+$/, "");
13
+ const url = `${base}/api/automation/v2/dags?type=data-flow&page=0&limit=-1`;
14
+ const response = await fetch(url, {
15
+ method: "GET",
16
+ headers: buildHeaders(accessToken, businessDomain),
17
+ });
18
+ return parseJsonOrThrow(response);
19
+ }
20
+ export async function runDataflowWithFile(options) {
21
+ const { baseUrl, accessToken, businessDomain = "bd_public", dagId, fileName, fileBytes } = options;
22
+ const base = baseUrl.replace(/\/+$/, "");
23
+ const url = `${base}/api/automation/v2/dataflow-doc/trigger/${encodeURIComponent(dagId)}`;
24
+ const form = new FormData();
25
+ form.set("file", new Blob([fileBytes]), fileName);
26
+ const response = await fetch(url, {
27
+ method: "POST",
28
+ headers: buildHeaders(accessToken, businessDomain),
29
+ body: form,
30
+ });
31
+ return parseJsonOrThrow(response);
32
+ }
33
+ export async function runDataflowWithRemoteUrl(options) {
34
+ const { baseUrl, accessToken, businessDomain = "bd_public", dagId, url, name } = options;
35
+ const base = baseUrl.replace(/\/+$/, "");
36
+ const endpoint = `${base}/api/automation/v2/dataflow-doc/trigger/${encodeURIComponent(dagId)}`;
37
+ const response = await fetch(endpoint, {
38
+ method: "POST",
39
+ headers: {
40
+ ...buildHeaders(accessToken, businessDomain),
41
+ "content-type": "application/json",
42
+ },
43
+ body: JSON.stringify({
44
+ source_from: "remote",
45
+ url,
46
+ name,
47
+ }),
48
+ });
49
+ return parseJsonOrThrow(response);
50
+ }
51
+ export async function listDataflowRuns(options) {
52
+ const { baseUrl, accessToken, businessDomain = "bd_public", dagId, page = 0, limit = 100, sortBy, order, startTime, endTime, } = options;
53
+ const base = baseUrl.replace(/\/+$/, "");
54
+ const url = new URL(`${base}/api/automation/v2/dag/${encodeURIComponent(dagId)}/results`);
55
+ url.searchParams.set("page", String(page));
56
+ url.searchParams.set("limit", String(limit));
57
+ if (sortBy)
58
+ url.searchParams.set("sortBy", sortBy);
59
+ if (order)
60
+ url.searchParams.set("order", order);
61
+ if (startTime != null)
62
+ url.searchParams.set("start_time", String(startTime));
63
+ if (endTime != null)
64
+ url.searchParams.set("end_time", String(endTime));
65
+ const response = await fetch(url.toString(), {
66
+ method: "GET",
67
+ headers: buildHeaders(accessToken, businessDomain),
68
+ });
69
+ return parseJsonOrThrow(response);
70
+ }
71
+ export async function getDataflowLogsPage(options) {
72
+ const { baseUrl, accessToken, businessDomain = "bd_public", dagId, instanceId, page, limit = 10 } = options;
73
+ const base = baseUrl.replace(/\/+$/, "");
74
+ const url = `${base}/api/automation/v2/dag/${encodeURIComponent(dagId)}/result/${encodeURIComponent(instanceId)}?page=${page}&limit=${limit}`;
75
+ const response = await fetch(url, {
76
+ method: "GET",
77
+ headers: buildHeaders(accessToken, businessDomain),
78
+ });
79
+ return parseJsonOrThrow(response);
80
+ }
@@ -5,5 +5,7 @@
5
5
  * environment variables KWEAVER_ACCOUNT_ID and KWEAVER_ACCOUNT_TYPE.
6
6
  * These are required by older platform versions (e.g. dip-poc.aishu.cn)
7
7
  * that do not infer account info from the token automatically.
8
+ *
9
+ * When accessToken is the no-auth sentinel, `authorization` and `token` are omitted.
8
10
  */
9
11
  export declare function buildHeaders(accessToken: string, businessDomain: string): Record<string, string>;
@@ -1,3 +1,4 @@
1
+ import { isNoAuth } from "../config/no-auth.js";
1
2
  /**
2
3
  * Shared HTTP header builder for all KWeaver API calls.
3
4
  *
@@ -5,16 +6,20 @@
5
6
  * environment variables KWEAVER_ACCOUNT_ID and KWEAVER_ACCOUNT_TYPE.
6
7
  * These are required by older platform versions (e.g. dip-poc.aishu.cn)
7
8
  * that do not infer account info from the token automatically.
9
+ *
10
+ * When accessToken is the no-auth sentinel, `authorization` and `token` are omitted.
8
11
  */
9
12
  export function buildHeaders(accessToken, businessDomain) {
10
13
  const headers = {
11
14
  accept: "application/json, text/plain, */*",
12
15
  "accept-language": "zh-cn",
13
- authorization: `Bearer ${accessToken}`,
14
- token: accessToken,
15
16
  "x-business-domain": businessDomain,
16
17
  "x-language": "zh-cn",
17
18
  };
19
+ if (!isNoAuth(accessToken)) {
20
+ headers.authorization = `Bearer ${accessToken}`;
21
+ headers.token = accessToken;
22
+ }
18
23
  const accountId = process.env.KWEAVER_ACCOUNT_ID;
19
24
  const accountType = process.env.KWEAVER_ACCOUNT_TYPE;
20
25
  if (accountId)
@@ -2,19 +2,11 @@ import { spawnSync } from "node:child_process";
2
2
  import { Buffer } from "node:buffer";
3
3
  import { existsSync, mkdirSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { basename, resolve } from "node:path";
5
+ import { buildHeaders as buildPlatformHeaders } from "./headers.js";
5
6
  import { HttpError, fetchTextOrThrow } from "../utils/http.js";
6
7
  const SKILL_API_PREFIX = "/api/agent-operator-integration/v1";
7
- function buildHeaders(accessToken, businessDomain) {
8
- return {
9
- accept: "application/json, text/plain, */*",
10
- authorization: `Bearer ${accessToken}`,
11
- token: accessToken,
12
- "x-business-domain": businessDomain,
13
- "x-language": "zh-cn",
14
- };
15
- }
16
8
  function baseHeaders(opts) {
17
- return buildHeaders(opts.accessToken, opts.businessDomain ?? "bd_public");
9
+ return buildPlatformHeaders(opts.accessToken, opts.businessDomain ?? "bd_public");
18
10
  }
19
11
  function buildUrl(baseUrl, path) {
20
12
  return `${baseUrl.replace(/\/+$/, "")}${path}`;
@@ -165,15 +165,6 @@ export interface SetVegaConnectorTypeEnabledOptions {
165
165
  businessDomain?: string;
166
166
  }
167
167
  export declare function setVegaConnectorTypeEnabled(options: SetVegaConnectorTypeEnabledOptions): Promise<string>;
168
- export interface ListVegaDiscoverTasksOptions {
169
- baseUrl: string;
170
- accessToken: string;
171
- status?: string;
172
- limit?: number;
173
- offset?: number;
174
- businessDomain?: string;
175
- }
176
- export declare function listVegaDiscoverTasks(options: ListVegaDiscoverTasksOptions): Promise<string>;
177
168
  export interface CreateVegaDatasetDocsOptions {
178
169
  baseUrl: string;
179
170
  accessToken: string;
@@ -237,10 +228,3 @@ export interface ListAllVegaResourcesOptions {
237
228
  businessDomain?: string;
238
229
  }
239
230
  export declare function listAllVegaResources(options: ListAllVegaResourcesOptions): Promise<string>;
240
- export interface GetVegaDiscoverTaskOptions {
241
- baseUrl: string;
242
- accessToken: string;
243
- id: string;
244
- businessDomain?: string;
245
- }
246
- export declare function getVegaDiscoverTask(options: GetVegaDiscoverTaskOptions): Promise<string>;
package/dist/api/vega.js CHANGED
@@ -346,26 +346,6 @@ export async function setVegaConnectorTypeEnabled(options) {
346
346
  throw new HttpError(response.status, response.statusText, body);
347
347
  return body;
348
348
  }
349
- export async function listVegaDiscoverTasks(options) {
350
- const { baseUrl, accessToken, status, limit, offset, businessDomain = "bd_public", } = options;
351
- const base = baseUrl.replace(/\/+$/, "");
352
- const url = new URL(`${base}${VEGA_BASE}/discover-tasks`);
353
- if (status)
354
- url.searchParams.set("status", status);
355
- if (limit !== undefined)
356
- url.searchParams.set("limit", String(limit));
357
- if (offset !== undefined)
358
- url.searchParams.set("offset", String(offset));
359
- const response = await fetch(url.toString(), {
360
- method: "GET",
361
- headers: buildHeaders(accessToken, businessDomain),
362
- });
363
- const body = await response.text();
364
- if (!response.ok) {
365
- throw new HttpError(response.status, response.statusText, body);
366
- }
367
- return body;
368
- }
369
349
  export async function createVegaDatasetDocs(options) {
370
350
  const { baseUrl, accessToken, id, body: requestBody, businessDomain = "bd_public" } = options;
371
351
  const base = baseUrl.replace(/\/+$/, "");
@@ -495,16 +475,3 @@ export async function listAllVegaResources(options) {
495
475
  throw new HttpError(response.status, response.statusText, body);
496
476
  return body;
497
477
  }
498
- export async function getVegaDiscoverTask(options) {
499
- const { baseUrl, accessToken, id, businessDomain = "bd_public" } = options;
500
- const base = baseUrl.replace(/\/+$/, "");
501
- const url = `${base}${VEGA_BASE}/discover-tasks/${encodeURIComponent(id)}`;
502
- const response = await fetch(url, {
503
- method: "GET",
504
- headers: buildHeaders(accessToken, businessDomain),
505
- });
506
- const body = await response.text();
507
- if (!response.ok)
508
- throw new HttpError(response.status, response.statusText, body);
509
- return body;
510
- }
@@ -14,20 +14,23 @@ export declare function normalizeBaseUrl(value: string): string;
14
14
  /**
15
15
  * OAuth2 Authorization Code login flow.
16
16
  * 1. Register client (if not already registered), OR use a provided client ID
17
- * 2. Open browser to /oauth2/auth
18
- * 3. Receive authorization code via local HTTP callback (or manual paste for non-localhost)
17
+ * 2. Open browser to /oauth2/auth (unless `noBrowser` or browser launch fails)
18
+ * 3. Receive authorization code via local HTTP callback, or stdin paste (`noBrowser` / fallback)
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:8080/callback" or a remote URL). */
25
- redirectUri?: string;
26
24
  scope?: string;
27
25
  clientId?: string;
28
26
  clientSecret?: string;
29
27
  /** Skip TLS certificate verification (self-signed / dev servers only). */
30
28
  tlsInsecure?: boolean;
29
+ /**
30
+ * Do not open a browser; print the auth URL and prompt for the callback URL or code (stdin).
31
+ * For headless servers or when automatic browser launch is unavailable.
32
+ */
33
+ noBrowser?: boolean;
31
34
  }): Promise<TokenConfig>;
32
35
  /**
33
36
  * Playwright-automated OAuth2 login.
@@ -44,8 +47,6 @@ export declare function playwrightLogin(baseUrl: string, options?: {
44
47
  username?: string;
45
48
  password?: string;
46
49
  port?: number;
47
- /** Full redirect URI override. */
48
- redirectUri?: string;
49
50
  scope?: string;
50
51
  tlsInsecure?: boolean;
51
52
  }): Promise<TokenConfig>;