@kweaver-ai/kweaver-sdk 0.4.1 → 0.4.2

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.
@@ -1,5 +1,76 @@
1
1
  import type { ChatResult, SendChatRequestStreamCallbacks } from "../api/agent-chat.js";
2
2
  import type { ClientContext } from "../client.js";
3
+ export interface AgentLlmConfig {
4
+ id?: string;
5
+ name: string;
6
+ model_type?: string;
7
+ temperature?: number;
8
+ top_p?: number;
9
+ top_k?: number;
10
+ frequency_penalty?: number;
11
+ presence_penalty?: number;
12
+ max_tokens: number;
13
+ }
14
+ export interface AgentLlmItem {
15
+ is_default: boolean;
16
+ llm_config: AgentLlmConfig;
17
+ }
18
+ export interface AgentInputField {
19
+ name: string;
20
+ type?: string;
21
+ desc?: string;
22
+ }
23
+ export interface AgentInput {
24
+ fields: AgentInputField[];
25
+ rewrite?: Record<string, unknown>;
26
+ augment?: Record<string, unknown>;
27
+ }
28
+ export interface AgentOutput {
29
+ variables?: Record<string, unknown>;
30
+ default_format?: string;
31
+ }
32
+ export interface AgentConfig {
33
+ input: AgentInput;
34
+ output: AgentOutput;
35
+ system_prompt?: string;
36
+ dolphin?: string;
37
+ is_dolphin_mode?: number;
38
+ data_source?: Record<string, unknown>;
39
+ skills?: Record<string, unknown>;
40
+ llms?: AgentLlmItem[];
41
+ opening_remark_config?: Record<string, unknown>;
42
+ preset_questions?: Array<{
43
+ question: string;
44
+ }>;
45
+ memory?: {
46
+ is_enabled: boolean;
47
+ };
48
+ related_question?: {
49
+ is_enabled: boolean;
50
+ };
51
+ plan_mode?: {
52
+ is_enabled: boolean;
53
+ };
54
+ conversation_history_config?: Record<string, unknown>;
55
+ [key: string]: unknown;
56
+ }
57
+ export interface CreateAgentBody {
58
+ name: string;
59
+ profile: string;
60
+ avatar_type?: number;
61
+ avatar?: string;
62
+ product_key?: string;
63
+ key?: string;
64
+ config: AgentConfig;
65
+ }
66
+ export interface UpdateAgentBody {
67
+ name: string;
68
+ profile: string;
69
+ avatar_type: number;
70
+ avatar: string;
71
+ product_key: string;
72
+ config: AgentConfig;
73
+ }
3
74
  export declare class AgentsResource {
4
75
  private readonly ctx;
5
76
  constructor(ctx: ClientContext);
@@ -9,26 +80,29 @@ export declare class AgentsResource {
9
80
  offset?: number;
10
81
  limit?: number;
11
82
  }): Promise<unknown[]>;
12
- /** Resolve agent key and version for a given agent id. */
83
+ get(agentId: string): Promise<unknown>;
84
+ getByKey(key: string): Promise<unknown>;
85
+ create(body: CreateAgentBody): Promise<{
86
+ id: string;
87
+ version: string;
88
+ }>;
89
+ update(agentId: string, body: UpdateAgentBody): Promise<void>;
90
+ delete(agentId: string): Promise<void>;
91
+ publish(agentId: string, opts?: {
92
+ business_domain_id?: string;
93
+ }): Promise<unknown>;
94
+ unpublish(agentId: string): Promise<void>;
13
95
  info(agentId: string, version?: string): Promise<{
14
96
  id: string;
15
97
  key: string;
16
98
  version: string;
17
99
  }>;
18
- /**
19
- * Send a single message and return the full response.
20
- * Automatically resolves the agent key/version before sending.
21
- */
22
100
  chat(agentId: string, message: string, opts?: {
23
101
  conversationId?: string;
24
102
  version?: string;
25
103
  stream?: boolean;
26
104
  verbose?: boolean;
27
105
  }): Promise<ChatResult>;
28
- /**
29
- * Send a message with streaming callbacks.
30
- * Automatically resolves the agent key/version before sending.
31
- */
32
106
  stream(agentId: string, message: string, callbacks: SendChatRequestStreamCallbacks, opts?: {
33
107
  conversationId?: string;
34
108
  version?: string;
@@ -1,10 +1,12 @@
1
- import { listAgents } from "../api/agent-list.js";
1
+ import { listAgents, getAgent, getAgentByKey, createAgent, updateAgent, deleteAgent, publishAgent, unpublishAgent, } from "../api/agent-list.js";
2
2
  import { fetchAgentInfo, sendChatRequest, sendChatRequestStream, } from "../api/agent-chat.js";
3
+ // ── AgentsResource ───────────────────────────────────────────────────────────
3
4
  export class AgentsResource {
4
5
  ctx;
5
6
  constructor(ctx) {
6
7
  this.ctx = ctx;
7
8
  }
9
+ // ── List (published agents) ──────────────────────────────────────────────
8
10
  async list(opts = {}) {
9
11
  const { keyword, ...rest } = opts;
10
12
  const raw = await listAgents({ ...this.ctx.base(), name: keyword, ...rest });
@@ -16,15 +18,52 @@ export class AgentsResource {
16
18
  : [];
17
19
  return items;
18
20
  }
19
- /** Resolve agent key and version for a given agent id. */
21
+ // ── Get by ID ────────────────────────────────────────────────────────────
22
+ async get(agentId) {
23
+ const raw = await getAgent({ ...this.ctx.base(), agentId });
24
+ return JSON.parse(raw);
25
+ }
26
+ // ── Get by key ───────────────────────────────────────────────────────────
27
+ async getByKey(key) {
28
+ const raw = await getAgentByKey({ ...this.ctx.base(), key });
29
+ return JSON.parse(raw);
30
+ }
31
+ // ── Create ───────────────────────────────────────────────────────────────
32
+ async create(body) {
33
+ // Apply defaults for required fields the user may omit
34
+ const payload = {
35
+ avatar_type: body.avatar_type ?? 1,
36
+ avatar: body.avatar ?? "icon-dip-agent-default",
37
+ product_key: body.product_key ?? "DIP",
38
+ ...body,
39
+ };
40
+ const raw = await createAgent({ ...this.ctx.base(), body: JSON.stringify(payload) });
41
+ return JSON.parse(raw);
42
+ }
43
+ // ── Update ───────────────────────────────────────────────────────────────
44
+ async update(agentId, body) {
45
+ await updateAgent({ ...this.ctx.base(), agentId, body: JSON.stringify(body) });
46
+ }
47
+ // ── Delete ───────────────────────────────────────────────────────────────
48
+ async delete(agentId) {
49
+ await deleteAgent({ ...this.ctx.base(), agentId });
50
+ }
51
+ // ── Publish ──────────────────────────────────────────────────────────────
52
+ async publish(agentId, opts = {}) {
53
+ const body = JSON.stringify({ agent_id: agentId, ...opts });
54
+ const raw = await publishAgent({ ...this.ctx.base(), agentId, body });
55
+ return JSON.parse(raw);
56
+ }
57
+ // ── Unpublish ────────────────────────────────────────────────────────────
58
+ async unpublish(agentId) {
59
+ await unpublishAgent({ ...this.ctx.base(), agentId });
60
+ }
61
+ // ── Agent info (resolve key/version) ─────────────────────────────────────
20
62
  async info(agentId, version = "v0") {
21
63
  const info = await fetchAgentInfo({ ...this.ctx.base(), agentId, version });
22
64
  return info;
23
65
  }
24
- /**
25
- * Send a single message and return the full response.
26
- * Automatically resolves the agent key/version before sending.
27
- */
66
+ // ── Chat (single-shot) ──────────────────────────────────────────────────
28
67
  async chat(agentId, message, opts = {}) {
29
68
  const { version = "v0", stream = false, conversationId, verbose } = opts;
30
69
  const info = await fetchAgentInfo({ ...this.ctx.base(), agentId, version });
@@ -39,10 +78,7 @@ export class AgentsResource {
39
78
  verbose,
40
79
  });
41
80
  }
42
- /**
43
- * Send a message with streaming callbacks.
44
- * Automatically resolves the agent key/version before sending.
45
- */
81
+ // ── Stream ──────────────────────────────────────────────────────────────
46
82
  async stream(agentId, message, callbacks, opts = {}) {
47
83
  const { version = "v0", conversationId, verbose } = opts;
48
84
  const info = await fetchAgentInfo({ ...this.ctx.base(), agentId, version });
@@ -8,9 +8,8 @@ export class KnowledgeNetworksResource {
8
8
  async list(opts = {}) {
9
9
  const raw = await listKnowledgeNetworks({ ...this.ctx.base(), ...opts });
10
10
  const parsed = JSON.parse(raw);
11
- const data = parsed && typeof parsed === "object" && "data" in parsed
12
- ? parsed.data
13
- : parsed;
11
+ // API returns { entries: [...] }
12
+ const data = parsed?.entries ?? parsed?.data ?? parsed;
14
13
  return Array.isArray(data) ? data : [];
15
14
  }
16
15
  async get(knId, opts = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kweaver-ai/kweaver-sdk",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "KWeaver TypeScript SDK — CLI tool and programmatic API for knowledge networks and Decision Agents.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -54,6 +54,7 @@
54
54
  "typescript": "^5.9.3"
55
55
  },
56
56
  "dependencies": {
57
+ "@kweaver-ai/bkn": "^0.1.0",
57
58
  "ink": "^6.8.0",
58
59
  "ink-spinner": "^5.0.0",
59
60
  "ink-text-input": "^6.0.0",