@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
package/dist/cli.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { NO_AUTH_TOKEN } from "./config/no-auth.js";
1
2
  import { applyTlsEnvFromSavedTokens } from "./config/tls-env.js";
2
3
  import { runAgentCommand } from "./commands/agent.js";
3
4
  import { runAuthCommand } from "./commands/auth.js";
@@ -5,18 +6,22 @@ import { runKnCommand } from "./commands/bkn.js";
5
6
  import { runCallCommand } from "./commands/call.js";
6
7
  import { runConfigCommand } from "./commands/config.js";
7
8
  import { runContextLoaderCommand } from "./commands/context-loader.js";
9
+ import { runDataflowCommand } from "./commands/dataflow.js";
8
10
  import { runDsCommand } from "./commands/ds.js";
11
+ import { runExploreCommand } from "./commands/explore.js";
9
12
  import { runDataviewCommand } from "./commands/dataview.js";
13
+ import { runSkillCommand } from "./commands/skill.js";
10
14
  import { runTokenCommand } from "./commands/token.js";
11
15
  import { runVegaCommand } from "./commands/vega.js";
12
16
  function printHelp() {
13
17
  console.log(`kweaver
14
18
 
15
19
  Usage:
20
+ kweaver [--user <userId|username>] <command> [options]
16
21
  kweaver --version | -V
17
22
  kweaver --help | -h
18
23
 
19
- kweaver auth <platform-url> [--alias name] [-u user] [-p pass] [--playwright] [--insecure|-k]
24
+ kweaver auth <platform-url> [--alias name] [--no-auth] [-u user] [-p pass] [--playwright] [--insecure|-k]
20
25
  kweaver auth login <platform-url> (alias for auth <url>)
21
26
  kweaver auth login <url> --client-id ID --client-secret S --refresh-token T (run on host without browser)
22
27
  kweaver auth whoami [platform-url|alias] [--json]
@@ -24,8 +29,10 @@ Usage:
24
29
  kweaver auth status [platform-url|alias]
25
30
  kweaver auth list
26
31
  kweaver auth use <platform-url|alias>
27
- kweaver auth logout [platform-url|alias]
28
- kweaver auth delete <platform-url|alias>
32
+ kweaver auth users [platform-url|alias]
33
+ kweaver auth switch [platform-url|alias] --user <userId|username>
34
+ kweaver auth logout [platform-url|alias] [--user <userId>]
35
+ kweaver auth delete <platform-url|alias> [--user <userId>]
29
36
  kweaver token
30
37
 
31
38
  kweaver call <url> [-X METHOD] [-H "Name: value"] [-d BODY] [--data-raw BODY]
@@ -51,10 +58,15 @@ Usage:
51
58
  kweaver ds tables <id> [--keyword X] [--pretty]
52
59
  kweaver ds connect <db_type> <host> <port> <database> --account X --password Y [--schema S] [--name N]
53
60
 
61
+ kweaver dataflow list [-bd value]
62
+ kweaver dataflow run <dagId> (--file <path> | --url <remote-url> --name <filename>) [-bd value]
63
+ kweaver dataflow runs <dagId> [--since <date-like>] [-bd value]
64
+ kweaver dataflow logs <dagId> <instanceId> [--detail] [-bd value]
65
+
54
66
  kweaver dataview list [--datasource-id id] [--type atomic|custom] [--limit n] [-bd value] [--pretty]
55
67
  kweaver dataview find --name <name> [--exact] [--datasource-id id] [--wait] [--timeout ms] [-bd value] [--pretty]
56
68
  kweaver dataview get <id> [-bd value] [--pretty]
57
- kweaver dataview query <id> [--sql sql] [--limit n] [--offset n] [--need-total] [-bd value] [--pretty]
69
+ kweaver dataview query <id> [--sql sql] [--limit n] [--offset n] [--need-total] [--raw-sql] [-bd value] [--pretty]
58
70
  kweaver dataview delete <id> [-y] [-bd value]
59
71
 
60
72
  kweaver bkn list [options]
@@ -81,6 +93,12 @@ Usage:
81
93
  kweaver config list-bd
82
94
  kweaver config show
83
95
 
96
+ kweaver skill list|get|register|status|delete [options]
97
+ kweaver skill market [options]
98
+ kweaver skill content <skill-id> [--raw] [--output file]
99
+ kweaver skill read-file <skill-id> <rel-path> [--raw] [--output file]
100
+ kweaver skill download|install <skill-id> [path] [options]
101
+
84
102
  kweaver vega health|stats|inspect
85
103
  kweaver vega catalog list|get|health|test-connection|discover|resources [options]
86
104
  kweaver vega resource list|get|query [options]
@@ -95,23 +113,40 @@ Usage:
95
113
  kweaver context-loader query-object-instance|query-instance-subgraph|get-logic-properties|get-action-info ...
96
114
  (alias: kweaver context ...)
97
115
 
116
+ Global options:
117
+ --user <id|name> Use a specific user's credentials for this command (env: KWEAVER_USER)
118
+
98
119
  Commands:
99
120
  auth Login, list, inspect, and switch saved platform auth profiles
100
121
  token Print the current access token, refreshing it first if needed
101
122
  call (curl) Call an API with curl-style flags and auto-injected token headers
102
123
  agent Agent CRUD, chat, sessions, history, publish/unpublish
103
124
  ds Manage datasources (list, get, delete, tables, connect)
125
+ dataflow Dataflow document workflows (list, run, runs, logs)
104
126
  dataview|dv List, find, get, query (SQL), delete data views (atomic / custom)
105
127
  bkn Knowledge network (CRUD, build, validate, export, stats, push/pull,
106
128
  object-type, relation-type, subgraph, action-type, action-execution, action-log)
107
129
  config Per-platform configuration (business domain)
130
+ skill Skill registry and market (register, search, progressive read, download/install)
108
131
  vega Vega observability (catalog, resource, connector-type, health/stats/inspect)
109
132
  context-loader Context-loader MCP (config, tools, resources, prompts, kn-search, query-*, etc.)
110
133
  help Show this message`);
111
134
  }
112
135
  export async function run(argv) {
113
136
  applyTlsEnvFromSavedTokens();
114
- const [command, ...rest] = argv;
137
+ const noAuthEnv = process.env.KWEAVER_NO_AUTH;
138
+ if ((noAuthEnv === "1" || noAuthEnv === "true" || noAuthEnv === "yes") &&
139
+ !process.env.KWEAVER_TOKEN) {
140
+ process.env.KWEAVER_TOKEN = NO_AUTH_TOKEN;
141
+ }
142
+ // Global --user flag: override active user for this invocation
143
+ const userIdx = argv.indexOf("--user");
144
+ let filteredArgv = argv;
145
+ if (userIdx !== -1 && userIdx + 1 < argv.length) {
146
+ process.env.KWEAVER_USER = argv[userIdx + 1];
147
+ filteredArgv = [...argv.slice(0, userIdx), ...argv.slice(userIdx + 2)];
148
+ }
149
+ const [command, ...rest] = filteredArgv;
115
150
  if (command === "--version" || command === "-V" || command === "version") {
116
151
  const { createRequire } = await import("node:module");
117
152
  const require = createRequire(import.meta.url);
@@ -132,6 +167,9 @@ export async function run(argv) {
132
167
  if (command === "ds") {
133
168
  return runDsCommand(rest);
134
169
  }
170
+ if (command === "dataflow") {
171
+ return runDataflowCommand(rest);
172
+ }
135
173
  if (command === "dataview" || command === "dv") {
136
174
  return runDataviewCommand(rest);
137
175
  }
@@ -141,6 +179,9 @@ export async function run(argv) {
141
179
  if (command === "agent") {
142
180
  return runAgentCommand(rest);
143
181
  }
182
+ if (command === "explore") {
183
+ return runExploreCommand(rest);
184
+ }
144
185
  if (command === "bkn") {
145
186
  return runKnCommand(rest);
146
187
  }
@@ -150,6 +191,9 @@ export async function run(argv) {
150
191
  if (command === "config") {
151
192
  return runConfigCommand(rest);
152
193
  }
194
+ if (command === "skill") {
195
+ return runSkillCommand(rest);
196
+ }
153
197
  if (command === "context-loader" || command === "context") {
154
198
  return runContextLoaderCommand(rest);
155
199
  }
package/dist/client.d.ts CHANGED
@@ -6,6 +6,7 @@ import { DataSourcesResource } from "./resources/datasources.js";
6
6
  import { DataViewsResource } from "./resources/dataviews.js";
7
7
  import { KnowledgeNetworksResource } from "./resources/knowledge-networks.js";
8
8
  import { BknResource } from "./resources/bkn.js";
9
+ import { SkillsResource } from "./resources/skills.js";
9
10
  import { VegaResource } from "./resources/vega.js";
10
11
  /**
11
12
  * Shared credentials passed to every resource method.
@@ -39,8 +40,17 @@ export interface KWeaverClientOptions {
39
40
  * When true, read credentials exclusively from ~/.kweaver/ (saved by
40
41
  * `kweaver auth login`), ignoring KWEAVER_BASE_URL / KWEAVER_TOKEN env vars.
41
42
  * Useful when env vars hold stale tokens or are intended for other tooling.
43
+ * Incompatible with `auth: false` — the constructor throws if both are set.
42
44
  */
43
45
  config?: boolean;
46
+ /**
47
+ * When false, use no-auth mode: API requests omit Authorization / token headers.
48
+ * Requires a resolvable base URL: `baseUrl`, `KWEAVER_BASE_URL`, or the active
49
+ * platform from `kweaver auth login`. Incompatible with `config: true` — use
50
+ * saved `~/.kweaver/` credentials (including `__NO_AUTH__`) via `config: true`
51
+ * alone instead of passing `auth: false`.
52
+ */
53
+ auth?: boolean;
44
54
  }
45
55
  /**
46
56
  * Main entry point for the KWeaver TypeScript SDK.
@@ -90,6 +100,8 @@ export declare class KWeaverClient implements ClientContext {
90
100
  readonly dataviews: DataViewsResource;
91
101
  /** Vega observability platform (catalogs, resources, connector types). */
92
102
  readonly vega: VegaResource;
103
+ /** ADP/KWeaver skill registry, market, progressive read, and install helpers. */
104
+ readonly skills: SkillsResource;
93
105
  constructor(opts?: KWeaverClientOptions);
94
106
  /**
95
107
  * Async factory that auto-refreshes expired or revoked tokens.
package/dist/client.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { applyTlsEnvFromSavedTokens } from "./config/tls-env.js";
2
+ import { NO_AUTH_TOKEN, isNoAuth } from "./config/no-auth.js";
2
3
  import { getCurrentPlatform, loadTokenConfig, } from "./config/store.js";
4
+ import { buildHeaders } from "./api/headers.js";
3
5
  import { ensureValidToken } from "./auth/oauth.js";
4
6
  import { AgentsResource } from "./resources/agents.js";
5
7
  import { ConversationsResource } from "./resources/conversations.js";
@@ -9,6 +11,7 @@ import { DataSourcesResource } from "./resources/datasources.js";
9
11
  import { DataViewsResource } from "./resources/dataviews.js";
10
12
  import { KnowledgeNetworksResource } from "./resources/knowledge-networks.js";
11
13
  import { BknResource } from "./resources/bkn.js";
14
+ import { SkillsResource } from "./resources/skills.js";
12
15
  import { VegaResource } from "./resources/vega.js";
13
16
  // ── KWeaverClient ─────────────────────────────────────────────────────────────
14
17
  /**
@@ -59,10 +62,43 @@ export class KWeaverClient {
59
62
  dataviews;
60
63
  /** Vega observability platform (catalogs, resources, connector types). */
61
64
  vega;
65
+ /** ADP/KWeaver skill registry, market, progressive read, and install helpers. */
66
+ skills;
62
67
  constructor(opts = {}) {
63
68
  const envDomain = process.env.KWEAVER_BUSINESS_DOMAIN;
69
+ if (opts.auth === false && opts.config) {
70
+ throw new Error("KWeaverClient: auth: false is incompatible with config: true.");
71
+ }
64
72
  let baseUrl;
65
73
  let accessToken;
74
+ if (opts.auth === false) {
75
+ {
76
+ const envUrl = process.env.KWEAVER_BASE_URL;
77
+ baseUrl = opts.baseUrl ?? envUrl;
78
+ if (!baseUrl) {
79
+ const platform = getCurrentPlatform();
80
+ if (platform)
81
+ baseUrl = platform;
82
+ }
83
+ }
84
+ if (!baseUrl) {
85
+ throw new Error("KWeaverClient: baseUrl is required when auth is false. " +
86
+ "Pass it explicitly, set KWEAVER_BASE_URL, or run `kweaver auth login`.");
87
+ }
88
+ this._baseUrl = baseUrl.replace(/\/+$/, "");
89
+ this._accessToken = NO_AUTH_TOKEN;
90
+ this._businessDomain = opts.businessDomain ?? envDomain ?? "bd_public";
91
+ this.knowledgeNetworks = new KnowledgeNetworksResource(this);
92
+ this.agents = new AgentsResource(this);
93
+ this.bkn = new BknResource(this);
94
+ this.conversations = new ConversationsResource(this);
95
+ this.dataflows = new DataflowsResource(this);
96
+ this.datasources = new DataSourcesResource(this);
97
+ this.dataviews = new DataViewsResource(this);
98
+ this.vega = new VegaResource(this);
99
+ this.skills = new SkillsResource(this);
100
+ return;
101
+ }
66
102
  if (opts.config) {
67
103
  // config: true — read exclusively from ~/.kweaver/, ignore env vars
68
104
  const platform = getCurrentPlatform();
@@ -114,6 +150,7 @@ export class KWeaverClient {
114
150
  this.datasources = new DataSourcesResource(this);
115
151
  this.dataviews = new DataViewsResource(this);
116
152
  this.vega = new VegaResource(this);
153
+ this.skills = new SkillsResource(this);
117
154
  }
118
155
  /**
119
156
  * Async factory that auto-refreshes expired or revoked tokens.
@@ -136,15 +173,22 @@ export class KWeaverClient {
136
173
  accessToken: token.accessToken,
137
174
  ...opts,
138
175
  });
139
- // Quick probe — if the token was revoked server-side, force refresh
140
- try {
141
- const probe = await fetch(`${token.baseUrl.replace(/\/+$/, "")}/api/ontology-manager/v1/knowledge-networks?limit=1`, { headers: { authorization: `Bearer ${token.accessToken}`, token: token.accessToken } });
142
- if (probe.status === 401) {
143
- throw new Error("Access token revoked. Run `kweaver auth login` to re-authenticate.");
176
+ if (!isNoAuth(token.accessToken)) {
177
+ // Quick probe — if the token was revoked server-side, force refresh
178
+ try {
179
+ const bd = client.base().businessDomain;
180
+ const probe = await fetch(`${token.baseUrl.replace(/\/+$/, "")}/api/ontology-manager/v1/knowledge-networks?limit=1`, { headers: buildHeaders(token.accessToken, bd) });
181
+ if (probe.status === 401) {
182
+ throw new Error("Access token revoked. Run `kweaver auth login` to re-authenticate.");
183
+ }
184
+ }
185
+ catch (e) {
186
+ if (e instanceof Error &&
187
+ e.message.startsWith("Access token revoked")) {
188
+ throw e;
189
+ }
190
+ // Network error — return client as-is, let the caller deal with it
144
191
  }
145
- }
146
- catch {
147
- // Network error — return client as-is, let the caller deal with it
148
192
  }
149
193
  return client;
150
194
  }
@@ -9,7 +9,36 @@ export interface AgentListOptions {
9
9
  pretty: boolean;
10
10
  verbose: boolean;
11
11
  }
12
+ export interface AgentPersonalListOptions {
13
+ name: string;
14
+ pagination_marker_str: string;
15
+ publish_status: string;
16
+ publish_to_be: string;
17
+ size: number;
18
+ businessDomain: string;
19
+ pretty: boolean;
20
+ verbose: boolean;
21
+ }
22
+ export interface AgentTemplateListOptions {
23
+ category_id: string;
24
+ name: string;
25
+ pagination_marker_str: string;
26
+ size: number;
27
+ businessDomain: string;
28
+ pretty: boolean;
29
+ verbose: boolean;
30
+ }
31
+ export interface AgentTemplateGetOptions {
32
+ templateId: string;
33
+ businessDomain: string;
34
+ pretty: boolean;
35
+ verbose: boolean;
36
+ saveConfig: string | null;
37
+ }
12
38
  export declare function formatSimpleAgentList(text: string, pretty: boolean): string;
39
+ export declare function parseAgentTemplateGetArgs(args: string[]): AgentTemplateGetOptions;
40
+ export declare function parseAgentTemplateListArgs(args: string[]): AgentTemplateListOptions;
41
+ export declare function parseAgentPersonalListArgs(args: string[]): AgentPersonalListOptions;
13
42
  export declare function parseAgentListArgs(args: string[]): AgentListOptions;
14
43
  export interface AgentSessionsOptions {
15
44
  agentId: string;
@@ -19,13 +48,15 @@ export interface AgentSessionsOptions {
19
48
  }
20
49
  export declare function parseAgentSessionsArgs(args: string[]): AgentSessionsOptions;
21
50
  export interface AgentHistoryOptions {
51
+ agentId: string | undefined;
22
52
  conversationId: string;
23
53
  businessDomain: string;
24
- limit?: number;
25
54
  pretty: boolean;
55
+ limit?: number;
26
56
  }
27
57
  export declare function parseAgentHistoryArgs(args: string[]): AgentHistoryOptions;
28
58
  export interface AgentTraceOptions {
59
+ agentId: string;
29
60
  conversationId: string;
30
61
  pretty: boolean;
31
62
  }
@@ -36,5 +67,6 @@ export interface AgentGetOptions {
36
67
  businessDomain: string;
37
68
  pretty: boolean;
38
69
  verbose: boolean;
70
+ saveConfig: string | null;
39
71
  }
40
72
  export declare function parseAgentGetArgs(args: string[]): AgentGetOptions;