@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.
- package/bin/kweaver.js +9 -0
- package/dist/api/agent-chat.d.ts +69 -0
- package/dist/api/agent-chat.js +379 -0
- package/dist/api/agent-list.d.ts +12 -0
- package/dist/api/agent-list.js +33 -0
- package/dist/api/context-loader.d.ts +115 -0
- package/dist/api/context-loader.js +259 -0
- package/dist/api/conversations.d.ts +24 -0
- package/dist/api/conversations.js +64 -0
- package/dist/api/knowledge-networks.d.ts +57 -0
- package/dist/api/knowledge-networks.js +158 -0
- package/dist/api/ontology-query.d.ts +75 -0
- package/dist/api/ontology-query.js +238 -0
- package/dist/api/semantic-search.d.ts +12 -0
- package/dist/api/semantic-search.js +34 -0
- package/dist/auth/oauth.d.ts +75 -0
- package/dist/auth/oauth.js +417 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +79 -0
- package/dist/client.d.ts +95 -0
- package/dist/client.js +104 -0
- package/dist/commands/agent-chat.d.ts +12 -0
- package/dist/commands/agent-chat.js +193 -0
- package/dist/commands/agent.d.ts +28 -0
- package/dist/commands/agent.js +431 -0
- package/dist/commands/auth.d.ts +9 -0
- package/dist/commands/auth.js +201 -0
- package/dist/commands/bkn.d.ts +70 -0
- package/dist/commands/bkn.js +1371 -0
- package/dist/commands/call.d.ts +14 -0
- package/dist/commands/call.js +151 -0
- package/dist/commands/context-loader.d.ts +1 -0
- package/dist/commands/context-loader.js +383 -0
- package/dist/commands/token.d.ts +2 -0
- package/dist/commands/token.js +24 -0
- package/dist/config/store.d.ts +77 -0
- package/dist/config/store.js +380 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +44 -0
- package/dist/kweaver.d.ts +146 -0
- package/dist/kweaver.js +184 -0
- package/dist/resources/agents.d.ts +37 -0
- package/dist/resources/agents.js +60 -0
- package/dist/resources/bkn.d.ts +45 -0
- package/dist/resources/bkn.js +86 -0
- package/dist/resources/context-loader.d.ts +15 -0
- package/dist/resources/context-loader.js +32 -0
- package/dist/resources/conversations.d.ts +11 -0
- package/dist/resources/conversations.js +17 -0
- package/dist/resources/knowledge-networks.d.ts +65 -0
- package/dist/resources/knowledge-networks.js +167 -0
- package/dist/ui/ChatApp.d.ts +16 -0
- package/dist/ui/ChatApp.js +248 -0
- package/dist/ui/MarkdownBlock.d.ts +5 -0
- package/dist/ui/MarkdownBlock.js +137 -0
- package/dist/ui/display-text.d.ts +1 -0
- package/dist/ui/display-text.js +1 -0
- package/dist/utils/browser.d.ts +1 -0
- package/dist/utils/browser.js +20 -0
- package/dist/utils/display-text.d.ts +3 -0
- package/dist/utils/display-text.js +46 -0
- package/dist/utils/http.d.ts +17 -0
- package/dist/utils/http.js +72 -0
- package/package.json +62 -0
package/dist/kweaver.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module-level simple API — cognee-style usage without instantiating KWeaverClient.
|
|
3
|
+
*
|
|
4
|
+
* @example Read-only (search + chat, no weaver needed)
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import kweaver from "kweaver-sdk/kweaver";
|
|
7
|
+
*
|
|
8
|
+
* kweaver.configure({ config: true, bknId: "your-bkn-id", agentId: "your-agent-id" });
|
|
9
|
+
*
|
|
10
|
+
* const results = await kweaver.search("供应链有哪些风险?");
|
|
11
|
+
* const reply = await kweaver.chat("总结前三大风险");
|
|
12
|
+
* console.log(reply.text);
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example Write then build
|
|
16
|
+
* ```typescript
|
|
17
|
+
* kweaver.configure({ baseUrl: "https://...", accessToken: "token", bknId: "abc" });
|
|
18
|
+
* // ... add datasource, object types via kweaver.client ...
|
|
19
|
+
* await kweaver.weaver({ wait: true });
|
|
20
|
+
* const results = await kweaver.search("新接入的数据");
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import { KWeaverClient } from "./client.js";
|
|
24
|
+
import { getCurrentPlatform, loadTokenConfig, } from "./config/store.js";
|
|
25
|
+
// ── Global state ──────────────────────────────────────────────────────────────
|
|
26
|
+
let _client = null;
|
|
27
|
+
let _defaultBknId = null;
|
|
28
|
+
let _defaultAgentId = null;
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the default KWeaver client.
|
|
31
|
+
* Must be called before any other kweaver.* function.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* kweaver.configure({ config: true, bknId: "abc", agentId: "ag1" });
|
|
36
|
+
* kweaver.configure({ baseUrl: "https://...", accessToken: "token", bknId: "abc" });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function configure(opts) {
|
|
40
|
+
// Reset all state first so a failed re-configure never leaves a stale client.
|
|
41
|
+
_client = null;
|
|
42
|
+
_defaultBknId = null;
|
|
43
|
+
_defaultAgentId = null;
|
|
44
|
+
const { bknId, agentId, businessDomain, config, baseUrl, accessToken } = opts;
|
|
45
|
+
if (config) {
|
|
46
|
+
// Use saved credentials — do NOT pass baseUrl to avoid cross-env leaks
|
|
47
|
+
const platform = getCurrentPlatform();
|
|
48
|
+
if (!platform) {
|
|
49
|
+
throw new Error("No active platform. Run `kweaver auth login` first.");
|
|
50
|
+
}
|
|
51
|
+
const stored = loadTokenConfig(platform);
|
|
52
|
+
if (!stored?.accessToken) {
|
|
53
|
+
throw new Error(`No token for ${platform}. Run \`kweaver auth login\` first.`);
|
|
54
|
+
}
|
|
55
|
+
_client = new KWeaverClient({
|
|
56
|
+
baseUrl: platform,
|
|
57
|
+
accessToken: stored.accessToken,
|
|
58
|
+
businessDomain,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
if (!baseUrl && !process.env.KWEAVER_BASE_URL) {
|
|
63
|
+
throw new Error("Provide baseUrl=, config=true, or set KWEAVER_BASE_URL.");
|
|
64
|
+
}
|
|
65
|
+
if (!accessToken && !process.env.KWEAVER_TOKEN) {
|
|
66
|
+
throw new Error("Provide accessToken=, config=true, or set KWEAVER_TOKEN.");
|
|
67
|
+
}
|
|
68
|
+
_client = new KWeaverClient({ baseUrl, accessToken, businessDomain });
|
|
69
|
+
}
|
|
70
|
+
_defaultBknId = bknId ?? null;
|
|
71
|
+
_defaultAgentId = agentId ?? null;
|
|
72
|
+
}
|
|
73
|
+
function requireClient() {
|
|
74
|
+
if (!_client) {
|
|
75
|
+
throw new Error("No KWeaver client configured. Call kweaver.configure() first.");
|
|
76
|
+
}
|
|
77
|
+
return _client;
|
|
78
|
+
}
|
|
79
|
+
function requireBknId(bknId) {
|
|
80
|
+
const id = bknId ?? _defaultBknId;
|
|
81
|
+
if (!id) {
|
|
82
|
+
throw new Error("No bknId provided. Pass bknId or set it in kweaver.configure().");
|
|
83
|
+
}
|
|
84
|
+
return id;
|
|
85
|
+
}
|
|
86
|
+
function requireAgentId(agentId) {
|
|
87
|
+
const id = agentId ?? _defaultAgentId;
|
|
88
|
+
if (!id) {
|
|
89
|
+
throw new Error("No agentId provided. Pass agentId or set it in kweaver.configure().");
|
|
90
|
+
}
|
|
91
|
+
return id;
|
|
92
|
+
}
|
|
93
|
+
// ── Top-level API ─────────────────────────────────────────────────────────────
|
|
94
|
+
/**
|
|
95
|
+
* Semantic search over a BKN.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const results = await kweaver.search("供应链风险");
|
|
100
|
+
* for (const c of results.concepts) console.log(c.concept_name);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export async function search(query, opts = {}) {
|
|
104
|
+
const client = requireClient();
|
|
105
|
+
const bknId = requireBknId(opts.bknId);
|
|
106
|
+
return client.bkn.semanticSearch(bknId, query, opts);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* List published agents.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const list = await kweaver.agents({ keyword: "supply" });
|
|
114
|
+
* list.forEach(a => console.log(a));
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export async function agents(opts = {}) {
|
|
118
|
+
return requireClient().agents.list(opts);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Send a message to an agent.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const reply = await kweaver.chat("分析供应链风险");
|
|
126
|
+
* console.log(reply.text);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export async function chat(message, opts = {}) {
|
|
130
|
+
const client = requireClient();
|
|
131
|
+
const agentId = requireAgentId(opts.agentId);
|
|
132
|
+
return client.agents.chat(agentId, message, {
|
|
133
|
+
conversationId: opts.conversationId,
|
|
134
|
+
stream: false,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* List BKNs (Business Knowledge Networks).
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const list = await kweaver.bkns();
|
|
143
|
+
* list.forEach(b => console.log(b));
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export async function bkns(opts = {}) {
|
|
147
|
+
return requireClient().knowledgeNetworks.list(opts);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Trigger a full build (index rebuild) of a BKN.
|
|
151
|
+
*
|
|
152
|
+
* Only needed after write-side changes (added datasource, modified object/relation
|
|
153
|
+
* types). Pure read-only usage (search, chat) does not require weaver().
|
|
154
|
+
*
|
|
155
|
+
* @param opts.wait If true, poll until completed and return the final BuildStatus.
|
|
156
|
+
* @param opts.timeout Max wait time in **milliseconds** (default 300_000 = 5 min).
|
|
157
|
+
* Note: Python SDK uses seconds; multiply by 1000 when porting.
|
|
158
|
+
* @param opts.interval Poll interval in **milliseconds** (default 2_000).
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* await kweaver.weaver({ wait: true }); // block until done
|
|
163
|
+
* await kweaver.weaver({ wait: true, timeout: 60_000 }); // 60-second timeout
|
|
164
|
+
* await kweaver.weaver(); // fire-and-forget (returns void)
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export async function weaver(opts = {}) {
|
|
168
|
+
const client = requireClient();
|
|
169
|
+
const bknId = requireBknId(opts.bknId);
|
|
170
|
+
if (opts.wait) {
|
|
171
|
+
return client.knowledgeNetworks.buildAndWait(bknId, {
|
|
172
|
+
timeout: opts.timeout,
|
|
173
|
+
interval: opts.interval,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
await client.knowledgeNetworks.build(bknId);
|
|
177
|
+
}
|
|
178
|
+
// ── Expose underlying client ──────────────────────────────────────────────────
|
|
179
|
+
/** Access the underlying KWeaverClient for advanced operations. */
|
|
180
|
+
export function getClient() {
|
|
181
|
+
return requireClient();
|
|
182
|
+
}
|
|
183
|
+
// ── Default export ────────────────────────────────────────────────────────────
|
|
184
|
+
export default { configure, search, agents, chat, bkns, weaver, getClient };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ChatResult, SendChatRequestStreamCallbacks } from "../api/agent-chat.js";
|
|
2
|
+
import type { ClientContext } from "../client.js";
|
|
3
|
+
export declare class AgentsResource {
|
|
4
|
+
private readonly ctx;
|
|
5
|
+
constructor(ctx: ClientContext);
|
|
6
|
+
list(opts?: {
|
|
7
|
+
name?: string;
|
|
8
|
+
keyword?: string;
|
|
9
|
+
offset?: number;
|
|
10
|
+
limit?: number;
|
|
11
|
+
}): Promise<unknown[]>;
|
|
12
|
+
/** Resolve agent key and version for a given agent id. */
|
|
13
|
+
info(agentId: string, version?: string): Promise<{
|
|
14
|
+
id: string;
|
|
15
|
+
key: string;
|
|
16
|
+
version: string;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Send a single message and return the full response.
|
|
20
|
+
* Automatically resolves the agent key/version before sending.
|
|
21
|
+
*/
|
|
22
|
+
chat(agentId: string, message: string, opts?: {
|
|
23
|
+
conversationId?: string;
|
|
24
|
+
version?: string;
|
|
25
|
+
stream?: boolean;
|
|
26
|
+
verbose?: boolean;
|
|
27
|
+
}): Promise<ChatResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Send a message with streaming callbacks.
|
|
30
|
+
* Automatically resolves the agent key/version before sending.
|
|
31
|
+
*/
|
|
32
|
+
stream(agentId: string, message: string, callbacks: SendChatRequestStreamCallbacks, opts?: {
|
|
33
|
+
conversationId?: string;
|
|
34
|
+
version?: string;
|
|
35
|
+
verbose?: boolean;
|
|
36
|
+
}): Promise<ChatResult>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { listAgents } from "../api/agent-list.js";
|
|
2
|
+
import { fetchAgentInfo, sendChatRequest, sendChatRequestStream, } from "../api/agent-chat.js";
|
|
3
|
+
export class AgentsResource {
|
|
4
|
+
ctx;
|
|
5
|
+
constructor(ctx) {
|
|
6
|
+
this.ctx = ctx;
|
|
7
|
+
}
|
|
8
|
+
async list(opts = {}) {
|
|
9
|
+
const { keyword, ...rest } = opts;
|
|
10
|
+
const raw = await listAgents({ ...this.ctx.base(), name: keyword, ...rest });
|
|
11
|
+
const parsed = JSON.parse(raw);
|
|
12
|
+
const items = parsed && typeof parsed === "object" && "data" in parsed
|
|
13
|
+
? parsed.data?.records ?? []
|
|
14
|
+
: Array.isArray(parsed)
|
|
15
|
+
? parsed
|
|
16
|
+
: [];
|
|
17
|
+
return items;
|
|
18
|
+
}
|
|
19
|
+
/** Resolve agent key and version for a given agent id. */
|
|
20
|
+
async info(agentId, version = "v0") {
|
|
21
|
+
const info = await fetchAgentInfo({ ...this.ctx.base(), agentId, version });
|
|
22
|
+
return info;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Send a single message and return the full response.
|
|
26
|
+
* Automatically resolves the agent key/version before sending.
|
|
27
|
+
*/
|
|
28
|
+
async chat(agentId, message, opts = {}) {
|
|
29
|
+
const { version = "v0", stream = false, conversationId, verbose } = opts;
|
|
30
|
+
const info = await fetchAgentInfo({ ...this.ctx.base(), agentId, version });
|
|
31
|
+
return sendChatRequest({
|
|
32
|
+
...this.ctx.base(),
|
|
33
|
+
agentId: info.id,
|
|
34
|
+
agentKey: info.key,
|
|
35
|
+
agentVersion: info.version,
|
|
36
|
+
query: message,
|
|
37
|
+
conversationId,
|
|
38
|
+
stream,
|
|
39
|
+
verbose,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Send a message with streaming callbacks.
|
|
44
|
+
* Automatically resolves the agent key/version before sending.
|
|
45
|
+
*/
|
|
46
|
+
async stream(agentId, message, callbacks, opts = {}) {
|
|
47
|
+
const { version = "v0", conversationId, verbose } = opts;
|
|
48
|
+
const info = await fetchAgentInfo({ ...this.ctx.base(), agentId, version });
|
|
49
|
+
return sendChatRequestStream({
|
|
50
|
+
...this.ctx.base(),
|
|
51
|
+
agentId: info.id,
|
|
52
|
+
agentKey: info.key,
|
|
53
|
+
agentVersion: info.version,
|
|
54
|
+
query: message,
|
|
55
|
+
conversationId,
|
|
56
|
+
stream: true,
|
|
57
|
+
verbose,
|
|
58
|
+
}, callbacks);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ClientContext } from "../client.js";
|
|
2
|
+
export interface SemanticSearchResult {
|
|
3
|
+
concepts: Array<{
|
|
4
|
+
concept_type: string;
|
|
5
|
+
concept_id: string;
|
|
6
|
+
concept_name: string;
|
|
7
|
+
intent_score: number;
|
|
8
|
+
match_score: number;
|
|
9
|
+
rerank_score: number;
|
|
10
|
+
concept_detail?: Record<string, unknown>;
|
|
11
|
+
samples?: unknown[];
|
|
12
|
+
}>;
|
|
13
|
+
hits_total: number;
|
|
14
|
+
query_understanding?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
/** BKN engine resource — instance queries, subgraph, action execution and logs. */
|
|
17
|
+
export declare class BknResource {
|
|
18
|
+
private readonly ctx;
|
|
19
|
+
constructor(ctx: ClientContext);
|
|
20
|
+
/**
|
|
21
|
+
* Semantic search over a BKN (Business Knowledge Network).
|
|
22
|
+
*
|
|
23
|
+
* @param bknId BKN ID to search against.
|
|
24
|
+
* @param query Natural-language query string.
|
|
25
|
+
* @param opts Optional retrieval mode and max concepts.
|
|
26
|
+
*/
|
|
27
|
+
semanticSearch(bknId: string, query: string, opts?: {
|
|
28
|
+
mode?: string;
|
|
29
|
+
maxConcepts?: number;
|
|
30
|
+
}): Promise<SemanticSearchResult>;
|
|
31
|
+
queryInstances(knId: string, otId: string, body: Record<string, unknown>): Promise<unknown>;
|
|
32
|
+
queryProperties(knId: string, otId: string, body: Record<string, unknown>): Promise<unknown>;
|
|
33
|
+
querySubgraph(knId: string, body: Record<string, unknown>): Promise<unknown>;
|
|
34
|
+
queryAction(knId: string, atId: string, body: Record<string, unknown>): Promise<unknown>;
|
|
35
|
+
executeAction(knId: string, atId: string, body: Record<string, unknown>): Promise<unknown>;
|
|
36
|
+
getExecution(knId: string, executionId: string): Promise<unknown>;
|
|
37
|
+
listActionLogs(knId: string, opts?: {
|
|
38
|
+
offset?: number;
|
|
39
|
+
limit?: number;
|
|
40
|
+
atId?: string;
|
|
41
|
+
status?: string;
|
|
42
|
+
}): Promise<unknown[]>;
|
|
43
|
+
getActionLog(knId: string, logId: string): Promise<unknown>;
|
|
44
|
+
cancelActionLog(knId: string, logId: string): Promise<unknown>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { objectTypeQuery, objectTypeProperties, subgraph, actionTypeQuery, actionTypeExecute, actionExecutionGet, actionLogsList, actionLogGet, actionLogCancel, } from "../api/ontology-query.js";
|
|
2
|
+
import { fetchTextOrThrow } from "../utils/http.js";
|
|
3
|
+
/** BKN engine resource — instance queries, subgraph, action execution and logs. */
|
|
4
|
+
export class BknResource {
|
|
5
|
+
ctx;
|
|
6
|
+
constructor(ctx) {
|
|
7
|
+
this.ctx = ctx;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Semantic search over a BKN (Business Knowledge Network).
|
|
11
|
+
*
|
|
12
|
+
* @param bknId BKN ID to search against.
|
|
13
|
+
* @param query Natural-language query string.
|
|
14
|
+
* @param opts Optional retrieval mode and max concepts.
|
|
15
|
+
*/
|
|
16
|
+
async semanticSearch(bknId, query, opts = {}) {
|
|
17
|
+
const { baseUrl, accessToken, businessDomain } = this.ctx.base();
|
|
18
|
+
const { mode = "keyword_vector_retrieval", maxConcepts = 10 } = opts;
|
|
19
|
+
const url = `${baseUrl}/api/agent-retrieval/v1/kn/semantic-search`;
|
|
20
|
+
const { body } = await fetchTextOrThrow(url, {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
"content-type": "application/json",
|
|
24
|
+
authorization: `Bearer ${accessToken}`,
|
|
25
|
+
token: accessToken,
|
|
26
|
+
"x-business-domain": businessDomain,
|
|
27
|
+
},
|
|
28
|
+
body: JSON.stringify({
|
|
29
|
+
kn_id: bknId,
|
|
30
|
+
query,
|
|
31
|
+
mode,
|
|
32
|
+
rerank_action: "default",
|
|
33
|
+
max_concepts: maxConcepts,
|
|
34
|
+
return_query_understanding: false,
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
const data = JSON.parse(body);
|
|
38
|
+
return {
|
|
39
|
+
concepts: data.concepts ?? [],
|
|
40
|
+
hits_total: data.hits_total ?? 0,
|
|
41
|
+
query_understanding: data.query_understanding,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async queryInstances(knId, otId, body) {
|
|
45
|
+
const raw = await objectTypeQuery({ ...this.ctx.base(), knId, otId, body: JSON.stringify(body) });
|
|
46
|
+
return JSON.parse(raw);
|
|
47
|
+
}
|
|
48
|
+
async queryProperties(knId, otId, body) {
|
|
49
|
+
const raw = await objectTypeProperties({ ...this.ctx.base(), knId, otId, body: JSON.stringify(body) });
|
|
50
|
+
return JSON.parse(raw);
|
|
51
|
+
}
|
|
52
|
+
async querySubgraph(knId, body) {
|
|
53
|
+
const raw = await subgraph({ ...this.ctx.base(), knId, body: JSON.stringify(body) });
|
|
54
|
+
return JSON.parse(raw);
|
|
55
|
+
}
|
|
56
|
+
async queryAction(knId, atId, body) {
|
|
57
|
+
const raw = await actionTypeQuery({ ...this.ctx.base(), knId, atId, body: JSON.stringify(body) });
|
|
58
|
+
return JSON.parse(raw);
|
|
59
|
+
}
|
|
60
|
+
async executeAction(knId, atId, body) {
|
|
61
|
+
const raw = await actionTypeExecute({ ...this.ctx.base(), knId, atId, body: JSON.stringify(body) });
|
|
62
|
+
return JSON.parse(raw);
|
|
63
|
+
}
|
|
64
|
+
async getExecution(knId, executionId) {
|
|
65
|
+
const raw = await actionExecutionGet({ ...this.ctx.base(), knId, executionId });
|
|
66
|
+
return JSON.parse(raw);
|
|
67
|
+
}
|
|
68
|
+
async listActionLogs(knId, opts = {}) {
|
|
69
|
+
const raw = await actionLogsList({ ...this.ctx.base(), knId, ...opts });
|
|
70
|
+
const parsed = JSON.parse(raw);
|
|
71
|
+
const items = parsed && typeof parsed === "object" && "data" in parsed
|
|
72
|
+
? (parsed.data?.records ?? [])
|
|
73
|
+
: Array.isArray(parsed)
|
|
74
|
+
? parsed
|
|
75
|
+
: [];
|
|
76
|
+
return items;
|
|
77
|
+
}
|
|
78
|
+
async getActionLog(knId, logId) {
|
|
79
|
+
const raw = await actionLogGet({ ...this.ctx.base(), knId, logId });
|
|
80
|
+
return JSON.parse(raw);
|
|
81
|
+
}
|
|
82
|
+
async cancelActionLog(knId, logId) {
|
|
83
|
+
const raw = await actionLogCancel({ ...this.ctx.base(), knId, logId });
|
|
84
|
+
return JSON.parse(raw);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { KnSearchArgs, KnSchemaSearchArgs, QueryObjectInstanceArgs, QueryInstanceSubgraphArgs, GetLogicPropertiesValuesArgs, GetActionInfoArgs } from "../api/context-loader.js";
|
|
2
|
+
import type { ClientContext } from "../client.js";
|
|
3
|
+
export declare class ContextLoaderResource {
|
|
4
|
+
private readonly ctx;
|
|
5
|
+
private readonly mcpUrl;
|
|
6
|
+
private readonly knId;
|
|
7
|
+
constructor(ctx: ClientContext, mcpUrl: string, knId: string);
|
|
8
|
+
private opts;
|
|
9
|
+
search(args: KnSearchArgs): Promise<unknown>;
|
|
10
|
+
schemaSearch(args: KnSchemaSearchArgs): Promise<unknown>;
|
|
11
|
+
queryInstances(args: QueryObjectInstanceArgs): Promise<unknown>;
|
|
12
|
+
querySubgraph(args: QueryInstanceSubgraphArgs): Promise<unknown>;
|
|
13
|
+
getLogicProperties(args: GetLogicPropertiesValuesArgs): Promise<unknown>;
|
|
14
|
+
getActionInfo(args: GetActionInfoArgs): Promise<unknown>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { knSearch, knSchemaSearch, queryObjectInstance, queryInstanceSubgraph, getLogicPropertiesValues, getActionInfo, } from "../api/context-loader.js";
|
|
2
|
+
export class ContextLoaderResource {
|
|
3
|
+
ctx;
|
|
4
|
+
mcpUrl;
|
|
5
|
+
knId;
|
|
6
|
+
constructor(ctx, mcpUrl, knId) {
|
|
7
|
+
this.ctx = ctx;
|
|
8
|
+
this.mcpUrl = mcpUrl;
|
|
9
|
+
this.knId = knId;
|
|
10
|
+
}
|
|
11
|
+
opts() {
|
|
12
|
+
return { mcpUrl: this.mcpUrl, knId: this.knId, accessToken: this.ctx.base().accessToken };
|
|
13
|
+
}
|
|
14
|
+
async search(args) {
|
|
15
|
+
return knSearch(this.opts(), args);
|
|
16
|
+
}
|
|
17
|
+
async schemaSearch(args) {
|
|
18
|
+
return knSchemaSearch(this.opts(), args);
|
|
19
|
+
}
|
|
20
|
+
async queryInstances(args) {
|
|
21
|
+
return queryObjectInstance(this.opts(), args);
|
|
22
|
+
}
|
|
23
|
+
async querySubgraph(args) {
|
|
24
|
+
return queryInstanceSubgraph(this.opts(), args);
|
|
25
|
+
}
|
|
26
|
+
async getLogicProperties(args) {
|
|
27
|
+
return getLogicPropertiesValues(this.opts(), args);
|
|
28
|
+
}
|
|
29
|
+
async getActionInfo(args) {
|
|
30
|
+
return getActionInfo(this.opts(), args);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ClientContext } from "../client.js";
|
|
2
|
+
export declare class ConversationsResource {
|
|
3
|
+
private readonly ctx;
|
|
4
|
+
constructor(ctx: ClientContext);
|
|
5
|
+
list(agentId: string, opts?: {
|
|
6
|
+
limit?: number;
|
|
7
|
+
}): Promise<unknown[]>;
|
|
8
|
+
listMessages(conversationId: string, opts?: {
|
|
9
|
+
limit?: number;
|
|
10
|
+
}): Promise<unknown[]>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { listConversations, listMessages } from "../api/conversations.js";
|
|
2
|
+
export class ConversationsResource {
|
|
3
|
+
ctx;
|
|
4
|
+
constructor(ctx) {
|
|
5
|
+
this.ctx = ctx;
|
|
6
|
+
}
|
|
7
|
+
async list(agentId, opts = {}) {
|
|
8
|
+
const raw = await listConversations({ ...this.ctx.base(), agentId, ...opts });
|
|
9
|
+
const parsed = JSON.parse(raw);
|
|
10
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
11
|
+
}
|
|
12
|
+
async listMessages(conversationId, opts = {}) {
|
|
13
|
+
const raw = await listMessages({ ...this.ctx.base(), conversationId, ...opts });
|
|
14
|
+
const parsed = JSON.parse(raw);
|
|
15
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ClientContext } from "../client.js";
|
|
2
|
+
export interface BuildStatus {
|
|
3
|
+
state: "running" | "completed" | "failed" | string;
|
|
4
|
+
state_detail?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class KnowledgeNetworksResource {
|
|
7
|
+
private readonly ctx;
|
|
8
|
+
constructor(ctx: ClientContext);
|
|
9
|
+
list(opts?: {
|
|
10
|
+
offset?: number;
|
|
11
|
+
limit?: number;
|
|
12
|
+
name_pattern?: string;
|
|
13
|
+
tag?: string;
|
|
14
|
+
}): Promise<unknown[]>;
|
|
15
|
+
get(knId: string, opts?: {
|
|
16
|
+
mode?: "export" | "";
|
|
17
|
+
include_statistics?: boolean;
|
|
18
|
+
}): Promise<unknown>;
|
|
19
|
+
create(opts: {
|
|
20
|
+
name: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
tags?: string[];
|
|
23
|
+
}): Promise<unknown>;
|
|
24
|
+
update(knId: string, opts: {
|
|
25
|
+
name: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
tags?: string[];
|
|
28
|
+
}): Promise<unknown>;
|
|
29
|
+
delete(knId: string): Promise<void>;
|
|
30
|
+
listObjectTypes(knId: string, opts?: {
|
|
31
|
+
branch?: string;
|
|
32
|
+
limit?: number;
|
|
33
|
+
}): Promise<unknown[]>;
|
|
34
|
+
listRelationTypes(knId: string, opts?: {
|
|
35
|
+
branch?: string;
|
|
36
|
+
limit?: number;
|
|
37
|
+
}): Promise<unknown[]>;
|
|
38
|
+
listActionTypes(knId: string, opts?: {
|
|
39
|
+
branch?: string;
|
|
40
|
+
limit?: number;
|
|
41
|
+
}): Promise<unknown[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Trigger a full build (index rebuild) of a BKN.
|
|
44
|
+
* Call this after adding datasources or modifying object/relation types.
|
|
45
|
+
*
|
|
46
|
+
* @param bknId BKN ID to build.
|
|
47
|
+
* @returns A promise that resolves immediately after the build is triggered.
|
|
48
|
+
* Use `buildAndWait` to block until completion.
|
|
49
|
+
*/
|
|
50
|
+
build(bknId: string): Promise<void>;
|
|
51
|
+
/** Poll build status for a BKN. */
|
|
52
|
+
buildStatus(bknId: string): Promise<BuildStatus>;
|
|
53
|
+
/**
|
|
54
|
+
* Trigger a full BKN build and wait for it to complete.
|
|
55
|
+
*
|
|
56
|
+
* @param bknId BKN ID to build.
|
|
57
|
+
* @param timeout Max wait time in milliseconds (default 300_000 = 5 min).
|
|
58
|
+
* @param interval Poll interval in milliseconds (default 2_000).
|
|
59
|
+
* @throws Error if the build fails or times out.
|
|
60
|
+
*/
|
|
61
|
+
buildAndWait(bknId: string, { timeout, interval }?: {
|
|
62
|
+
timeout?: number;
|
|
63
|
+
interval?: number;
|
|
64
|
+
}): Promise<BuildStatus>;
|
|
65
|
+
}
|