@kweaver-ai/kweaver-sdk 0.4.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 (64) hide show
  1. package/bin/kweaver.js +9 -0
  2. package/dist/api/agent-chat.d.ts +69 -0
  3. package/dist/api/agent-chat.js +379 -0
  4. package/dist/api/agent-list.d.ts +12 -0
  5. package/dist/api/agent-list.js +33 -0
  6. package/dist/api/context-loader.d.ts +115 -0
  7. package/dist/api/context-loader.js +259 -0
  8. package/dist/api/conversations.d.ts +24 -0
  9. package/dist/api/conversations.js +64 -0
  10. package/dist/api/knowledge-networks.d.ts +57 -0
  11. package/dist/api/knowledge-networks.js +158 -0
  12. package/dist/api/ontology-query.d.ts +75 -0
  13. package/dist/api/ontology-query.js +238 -0
  14. package/dist/api/semantic-search.d.ts +12 -0
  15. package/dist/api/semantic-search.js +34 -0
  16. package/dist/auth/oauth.d.ts +75 -0
  17. package/dist/auth/oauth.js +417 -0
  18. package/dist/cli.d.ts +1 -0
  19. package/dist/cli.js +79 -0
  20. package/dist/client.d.ts +95 -0
  21. package/dist/client.js +104 -0
  22. package/dist/commands/agent-chat.d.ts +12 -0
  23. package/dist/commands/agent-chat.js +193 -0
  24. package/dist/commands/agent.d.ts +28 -0
  25. package/dist/commands/agent.js +431 -0
  26. package/dist/commands/auth.d.ts +9 -0
  27. package/dist/commands/auth.js +201 -0
  28. package/dist/commands/bkn.d.ts +70 -0
  29. package/dist/commands/bkn.js +1371 -0
  30. package/dist/commands/call.d.ts +14 -0
  31. package/dist/commands/call.js +151 -0
  32. package/dist/commands/context-loader.d.ts +1 -0
  33. package/dist/commands/context-loader.js +383 -0
  34. package/dist/commands/token.d.ts +2 -0
  35. package/dist/commands/token.js +24 -0
  36. package/dist/config/store.d.ts +77 -0
  37. package/dist/config/store.js +380 -0
  38. package/dist/index.d.ts +53 -0
  39. package/dist/index.js +44 -0
  40. package/dist/kweaver.d.ts +146 -0
  41. package/dist/kweaver.js +184 -0
  42. package/dist/resources/agents.d.ts +37 -0
  43. package/dist/resources/agents.js +60 -0
  44. package/dist/resources/bkn.d.ts +45 -0
  45. package/dist/resources/bkn.js +86 -0
  46. package/dist/resources/context-loader.d.ts +15 -0
  47. package/dist/resources/context-loader.js +32 -0
  48. package/dist/resources/conversations.d.ts +11 -0
  49. package/dist/resources/conversations.js +17 -0
  50. package/dist/resources/knowledge-networks.d.ts +65 -0
  51. package/dist/resources/knowledge-networks.js +167 -0
  52. package/dist/ui/ChatApp.d.ts +16 -0
  53. package/dist/ui/ChatApp.js +248 -0
  54. package/dist/ui/MarkdownBlock.d.ts +5 -0
  55. package/dist/ui/MarkdownBlock.js +137 -0
  56. package/dist/ui/display-text.d.ts +1 -0
  57. package/dist/ui/display-text.js +1 -0
  58. package/dist/utils/browser.d.ts +1 -0
  59. package/dist/utils/browser.js +20 -0
  60. package/dist/utils/display-text.d.ts +3 -0
  61. package/dist/utils/display-text.js +46 -0
  62. package/dist/utils/http.d.ts +17 -0
  63. package/dist/utils/http.js +72 -0
  64. package/package.json +62 -0
@@ -0,0 +1,201 @@
1
+ import { clearPlatformSession, deletePlatform, getConfigDir, getCurrentPlatform, getPlatformAlias, hasPlatform, listPlatforms, resolvePlatformIdentifier, setCurrentPlatform, setPlatformAlias, } from "../config/store.js";
2
+ import { callLogoutEndpoint, formatHttpError, getStoredAuthSummary, login, normalizeBaseUrl, } from "../auth/oauth.js";
3
+ export function getClientProvisioningMessage(created) {
4
+ return created ? "Registered a new OAuth client." : "Reusing existing OAuth client.";
5
+ }
6
+ export function formatAuthStatusSummary(input) {
7
+ const lines = [
8
+ `Config directory: ${getConfigDir()}`,
9
+ `Platform: ${input.client.baseUrl}`,
10
+ `Current platform: ${input.isCurrent ? "yes" : "no"}`,
11
+ `Client ID: ${input.client.clientId}`,
12
+ `Redirect URI: ${input.client.redirectUri}`,
13
+ `Token present: ${input.token ? "yes" : "no"}`,
14
+ `Callback recorded: ${input.callback ? "yes" : "no"}`,
15
+ ];
16
+ if (input.client.product) {
17
+ lines.push(`Product: ${input.client.product}`);
18
+ }
19
+ if (input.client.lang) {
20
+ lines.push(`Lang: ${input.client.lang}`);
21
+ }
22
+ if (input.token?.expiresAt) {
23
+ lines.push(`Token expires at: ${input.token.expiresAt}`);
24
+ }
25
+ if (input.callback?.receivedAt) {
26
+ lines.push(`Last callback at: ${input.callback.receivedAt}`);
27
+ }
28
+ if (input.callback?.scope) {
29
+ lines.push(`Last callback scope: ${input.callback.scope}`);
30
+ }
31
+ return lines;
32
+ }
33
+ export async function runAuthCommand(args) {
34
+ const target = args[0];
35
+ const rest = args.slice(1);
36
+ if (target === "login") {
37
+ const url = rest[0];
38
+ if (!url) {
39
+ console.error("Usage: kweaver auth login <platform-url>");
40
+ return 1;
41
+ }
42
+ return runAuthCommand([url, ...rest.slice(1)]);
43
+ }
44
+ if (target && target !== "status" && target !== "list" && target !== "use" && target !== "delete" && target !== "logout") {
45
+ try {
46
+ const normalizedTarget = normalizeBaseUrl(target);
47
+ const port = Number(readOption(args, "--port") ?? "9010");
48
+ const clientName = readOption(args, "--client-name") ?? "kweaver";
49
+ const alias = readOption(args, "--alias");
50
+ const host = readOption(args, "--host");
51
+ const redirectUriOverride = readOption(args, "--redirect-uri");
52
+ const forceRegister = args.includes("--force-register");
53
+ const open = !args.includes("--no-open");
54
+ const lang = readOption(args, "--lang") ?? "zh-cn";
55
+ const product = readOption(args, "--product") ?? "adp";
56
+ const xForwardedPrefix = readOption(args, "--x-forwarded-prefix") ?? "";
57
+ const result = await login({
58
+ baseUrl: normalizedTarget,
59
+ port,
60
+ clientName,
61
+ open,
62
+ forceRegister,
63
+ host,
64
+ redirectUriOverride,
65
+ lang,
66
+ product,
67
+ xForwardedPrefix,
68
+ });
69
+ if (alias) {
70
+ setPlatformAlias(normalizedTarget, alias);
71
+ }
72
+ console.log(`Config directory: ${getConfigDir()}`);
73
+ console.log(getClientProvisioningMessage(result.created));
74
+ console.log(`Client ID: ${result.client.clientId}`);
75
+ if (alias) {
76
+ console.log(`Alias: ${alias.toLowerCase()}`);
77
+ }
78
+ else {
79
+ const savedAlias = getPlatformAlias(result.client.baseUrl);
80
+ if (savedAlias) {
81
+ console.log(`Alias: ${savedAlias}`);
82
+ }
83
+ }
84
+ console.log(`Authorization URL: ${result.authorizationUrl}`);
85
+ console.log(`Callback received at: ${result.callback.receivedAt}`);
86
+ console.log(`Current platform: ${result.client.baseUrl}`);
87
+ console.log(`Access token saved: yes`);
88
+ return 0;
89
+ }
90
+ catch (error) {
91
+ console.error(formatHttpError(error));
92
+ return 1;
93
+ }
94
+ }
95
+ if (target === "status") {
96
+ const resolvedTarget = args[1] ? resolvePlatformIdentifier(args[1]) : undefined;
97
+ const statusTarget = resolvedTarget && /^https?:\/\//.test(resolvedTarget) ? normalizeBaseUrl(resolvedTarget) : resolvedTarget ?? undefined;
98
+ const { client, token, callback } = getStoredAuthSummary(statusTarget);
99
+ if (!client) {
100
+ console.error(statusTarget ? `No saved client config found for ${statusTarget}.` : "No saved client config found.");
101
+ return 1;
102
+ }
103
+ const currentPlatform = getCurrentPlatform();
104
+ for (const line of formatAuthStatusSummary({
105
+ client,
106
+ token,
107
+ callback,
108
+ isCurrent: currentPlatform === client.baseUrl,
109
+ })) {
110
+ console.log(line);
111
+ }
112
+ return 0;
113
+ }
114
+ if (target === "list") {
115
+ const currentPlatform = getCurrentPlatform();
116
+ const platforms = listPlatforms();
117
+ if (platforms.length === 0) {
118
+ console.error("No saved platforms found.");
119
+ return 1;
120
+ }
121
+ console.log(`Config directory: ${getConfigDir()}`);
122
+ for (const platform of platforms) {
123
+ const marker = platform.baseUrl === currentPlatform ? "*" : "-";
124
+ const aliasPart = platform.alias ? ` alias=${platform.alias}` : "";
125
+ console.log(`${marker} ${platform.baseUrl}${aliasPart} token=${platform.hasToken ? "yes" : "no"}`);
126
+ }
127
+ return 0;
128
+ }
129
+ if (target === "use") {
130
+ const resolvedTarget = args[1] ? resolvePlatformIdentifier(args[1]) : "";
131
+ const useTarget = resolvedTarget && /^https?:\/\//.test(resolvedTarget) ? normalizeBaseUrl(resolvedTarget) : resolvedTarget;
132
+ if (!useTarget) {
133
+ console.error("Usage: kweaver auth use <platform-url|alias>");
134
+ return 1;
135
+ }
136
+ if (!hasPlatform(useTarget)) {
137
+ console.error(`No saved client config found for ${useTarget}. Run \`kweaver auth ${useTarget}\` first.`);
138
+ return 1;
139
+ }
140
+ setCurrentPlatform(useTarget);
141
+ console.log(`Current platform: ${useTarget}`);
142
+ return 0;
143
+ }
144
+ if (target === "delete") {
145
+ const resolvedTarget = args[1] ? resolvePlatformIdentifier(args[1]) : "";
146
+ const deleteTarget = resolvedTarget && /^https?:\/\//.test(resolvedTarget) ? normalizeBaseUrl(resolvedTarget) : resolvedTarget;
147
+ if (!deleteTarget) {
148
+ console.error("Usage: kweaver auth delete <platform-url|alias>");
149
+ return 1;
150
+ }
151
+ if (!hasPlatform(deleteTarget)) {
152
+ console.error(`No saved client config found for ${deleteTarget}.`);
153
+ return 1;
154
+ }
155
+ const wasCurrent = getCurrentPlatform() === deleteTarget;
156
+ deletePlatform(deleteTarget);
157
+ console.log(`Deleted platform: ${deleteTarget}`);
158
+ if (wasCurrent) {
159
+ const nextCurrent = getCurrentPlatform();
160
+ console.log(`Current platform: ${nextCurrent ?? "none"}`);
161
+ }
162
+ return 0;
163
+ }
164
+ if (target === "logout") {
165
+ const resolvedTarget = args[1] ? resolvePlatformIdentifier(args[1]) : getCurrentPlatform();
166
+ const logoutTarget = resolvedTarget && /^https?:\/\//.test(resolvedTarget) ? normalizeBaseUrl(resolvedTarget) : resolvedTarget;
167
+ if (!logoutTarget) {
168
+ console.error("Usage: kweaver auth logout [platform-url|alias]");
169
+ console.error("No current platform. Specify a platform to logout, e.g. kweaver auth logout <platform-url|alias>");
170
+ return 1;
171
+ }
172
+ if (!hasPlatform(logoutTarget)) {
173
+ console.error(`No saved client config found for ${logoutTarget}.`);
174
+ return 1;
175
+ }
176
+ const { client, token } = getStoredAuthSummary(logoutTarget);
177
+ if (client) {
178
+ await callLogoutEndpoint(client, token);
179
+ }
180
+ clearPlatformSession(logoutTarget);
181
+ console.log(`Logged out: ${logoutTarget}`);
182
+ console.log(`Run \`kweaver auth ${logoutTarget}\` to sign in again (e.g. as a different user).`);
183
+ return 0;
184
+ }
185
+ console.error("Usage: kweaver auth <platform-url>");
186
+ console.error(" kweaver auth login <platform-url>");
187
+ console.error(" kweaver auth <platform-url> [--alias <name>] [--no-open] [--host <host>] [--redirect-uri <uri>]");
188
+ console.error(" kweaver auth status [platform-url|alias]");
189
+ console.error(" kweaver auth list");
190
+ console.error(" kweaver auth use <platform-url|alias>");
191
+ console.error(" kweaver auth logout [platform-url|alias]");
192
+ console.error(" kweaver auth delete <platform-url|alias>");
193
+ return 1;
194
+ }
195
+ function readOption(args, name) {
196
+ const index = args.findIndex((arg) => arg === name);
197
+ if (index === -1) {
198
+ return undefined;
199
+ }
200
+ return args[index + 1];
201
+ }
@@ -0,0 +1,70 @@
1
+ export interface KnListOptions {
2
+ offset: number;
3
+ limit: number;
4
+ sort: string;
5
+ direction: "asc" | "desc";
6
+ businessDomain: string;
7
+ detail: boolean;
8
+ pretty: boolean;
9
+ verbose: boolean;
10
+ name_pattern?: string;
11
+ tag?: string;
12
+ }
13
+ export declare function formatSimpleKnList(text: string, pretty: boolean, includeDetail?: boolean): string;
14
+ export declare function parseKnListArgs(args: string[]): KnListOptions;
15
+ export interface KnGetOptions {
16
+ knId: string;
17
+ stats: boolean;
18
+ export: boolean;
19
+ businessDomain: string;
20
+ pretty: boolean;
21
+ }
22
+ export declare function parseKnGetArgs(args: string[]): KnGetOptions;
23
+ export interface KnCreateOptions {
24
+ body: string;
25
+ import_mode?: "normal" | "ignore" | "overwrite";
26
+ validate_dependency?: boolean;
27
+ businessDomain: string;
28
+ pretty: boolean;
29
+ }
30
+ export declare function parseKnCreateArgs(args: string[]): KnCreateOptions;
31
+ export interface KnUpdateOptions {
32
+ knId: string;
33
+ body: string;
34
+ businessDomain: string;
35
+ pretty: boolean;
36
+ }
37
+ export declare function parseKnUpdateArgs(args: string[]): KnUpdateOptions;
38
+ export interface KnDeleteOptions {
39
+ knId: string;
40
+ businessDomain: string;
41
+ yes: boolean;
42
+ }
43
+ export declare function parseKnDeleteArgs(args: string[]): KnDeleteOptions;
44
+ export interface KnObjectTypeQueryOptions {
45
+ knId: string;
46
+ otId: string;
47
+ body: string;
48
+ pretty: boolean;
49
+ businessDomain: string;
50
+ }
51
+ export declare function parseKnObjectTypeQueryArgs(args: string[]): KnObjectTypeQueryOptions;
52
+ export declare function runKnCommand(args: string[]): Promise<number>;
53
+ export interface KnActionTypeExecuteOptions {
54
+ knId: string;
55
+ atId: string;
56
+ body: string;
57
+ pretty: boolean;
58
+ businessDomain: string;
59
+ wait: boolean;
60
+ timeout: number;
61
+ }
62
+ export declare function parseKnActionTypeExecuteArgs(args: string[]): KnActionTypeExecuteOptions;
63
+ export declare function parseKnSearchArgs(args: string[]): {
64
+ knId: string;
65
+ query: string;
66
+ maxConcepts: number;
67
+ mode: string;
68
+ pretty: boolean;
69
+ businessDomain: string;
70
+ };