@kweaver-ai/kweaver-sdk 0.6.2 → 0.6.3

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,7 +1,7 @@
1
1
  export type SkillStatus = "unpublish" | "published" | "offline";
2
2
  export type SkillFileType = "zip" | "content";
3
3
  export interface SkillSummary {
4
- skill_id: string;
4
+ id: string;
5
5
  name: string;
6
6
  description?: string;
7
7
  version?: string;
@@ -26,20 +26,20 @@ export interface SkillFileSummary {
26
26
  mime_type?: string;
27
27
  }
28
28
  export interface SkillContentIndex {
29
- skill_id: string;
29
+ id: string;
30
30
  url: string;
31
31
  files: SkillFileSummary[];
32
32
  status?: SkillStatus;
33
33
  }
34
34
  export interface SkillFileReadResult {
35
- skill_id: string;
35
+ id: string;
36
36
  rel_path: string;
37
37
  url: string;
38
38
  mime_type?: string;
39
39
  file_type?: string;
40
40
  }
41
41
  export interface RegisterSkillResult {
42
- skill_id: string;
42
+ id: string;
43
43
  name: string;
44
44
  description?: string;
45
45
  version?: string;
@@ -47,11 +47,11 @@ export interface RegisterSkillResult {
47
47
  files?: string[];
48
48
  }
49
49
  export interface DeleteSkillResult {
50
- skill_id: string;
50
+ id: string;
51
51
  deleted: boolean;
52
52
  }
53
53
  export interface UpdateSkillStatusResult {
54
- skill_id: string;
54
+ id: string;
55
55
  status: SkillStatus;
56
56
  }
57
57
  export interface SkillListResult {
@@ -18,6 +18,20 @@ function unwrapEnvelope(raw) {
18
18
  }
19
19
  return parsed;
20
20
  }
21
+ /** Rename `skill_id` → `id` for consistent output with other modules. */
22
+ function normalizeSkillId(obj) {
23
+ if (!obj || typeof obj !== "object")
24
+ return obj;
25
+ if (Array.isArray(obj))
26
+ return obj.map(normalizeSkillId);
27
+ const record = obj;
28
+ const out = {};
29
+ for (const [key, value] of Object.entries(record)) {
30
+ const newKey = key === "skill_id" ? "id" : key;
31
+ out[newKey] = typeof value === "object" ? normalizeSkillId(value) : value;
32
+ }
33
+ return out;
34
+ }
21
35
  function appendCommonListParams(url, opts) {
22
36
  if (opts.page !== undefined)
23
37
  url.searchParams.set("page", String(opts.page));
@@ -60,23 +74,23 @@ export async function listSkills(options) {
60
74
  if (options.createUser)
61
75
  url.searchParams.set("create_user", options.createUser);
62
76
  const { body } = await fetchTextOrThrow(url, { headers: baseHeaders(options) });
63
- return unwrapEnvelope(body);
77
+ return normalizeSkillId(unwrapEnvelope(body));
64
78
  }
65
79
  export async function listSkillMarket(options) {
66
80
  const url = new URL(buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/market`));
67
81
  appendCommonListParams(url, options);
68
82
  const { body } = await fetchTextOrThrow(url, { headers: baseHeaders(options) });
69
- return unwrapEnvelope(body);
83
+ return normalizeSkillId(unwrapEnvelope(body));
70
84
  }
71
85
  export async function getSkill(options) {
72
86
  const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/${encodeURIComponent(options.skillId)}`);
73
87
  const { body } = await fetchTextOrThrow(url, { headers: baseHeaders(options) });
74
- return unwrapEnvelope(body);
88
+ return normalizeSkillId(unwrapEnvelope(body));
75
89
  }
76
90
  export async function deleteSkill(options) {
77
91
  const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/${encodeURIComponent(options.skillId)}`);
78
92
  const { body } = await fetchTextOrThrow(url, { method: "DELETE", headers: baseHeaders(options) });
79
- return unwrapEnvelope(body);
93
+ return normalizeSkillId(unwrapEnvelope(body));
80
94
  }
81
95
  export async function updateSkillStatus(options) {
82
96
  const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/${encodeURIComponent(options.skillId)}/status`);
@@ -85,7 +99,7 @@ export async function updateSkillStatus(options) {
85
99
  headers: { ...baseHeaders(options), "content-type": "application/json" },
86
100
  body: JSON.stringify({ status: options.status }),
87
101
  });
88
- return unwrapEnvelope(body);
102
+ return normalizeSkillId(unwrapEnvelope(body));
89
103
  }
90
104
  export async function registerSkillContent(options) {
91
105
  const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills`);
@@ -102,7 +116,7 @@ export async function registerSkillContent(options) {
102
116
  headers: { ...baseHeaders(options), "content-type": "application/json" },
103
117
  body: JSON.stringify(payload),
104
118
  });
105
- return unwrapEnvelope(body);
119
+ return normalizeSkillId(unwrapEnvelope(body));
106
120
  }
107
121
  export async function registerSkillZip(options) {
108
122
  const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills`);
@@ -118,12 +132,12 @@ export async function registerSkillZip(options) {
118
132
  headers: baseHeaders(options),
119
133
  body: form,
120
134
  });
121
- return unwrapEnvelope(body);
135
+ return normalizeSkillId(unwrapEnvelope(body));
122
136
  }
123
137
  export async function getSkillContentIndex(options) {
124
138
  const url = buildUrl(options.baseUrl, `${SKILL_API_PREFIX}/skills/${encodeURIComponent(options.skillId)}/content`);
125
139
  const { body } = await fetchTextOrThrow(url, { headers: baseHeaders(options) });
126
- return unwrapEnvelope(body);
140
+ return normalizeSkillId(unwrapEnvelope(body));
127
141
  }
128
142
  export async function fetchSkillContent(options) {
129
143
  const index = await getSkillContentIndex(options);
@@ -137,7 +151,7 @@ export async function readSkillFile(options) {
137
151
  headers: { ...baseHeaders(options), "content-type": "application/json" },
138
152
  body: JSON.stringify({ rel_path: options.relPath }),
139
153
  });
140
- return unwrapEnvelope(body);
154
+ return normalizeSkillId(unwrapEnvelope(body));
141
155
  }
142
156
  export async function fetchSkillFile(options) {
143
157
  const file = await readSkillFile(options);
@@ -235,4 +235,6 @@ export interface ListAllVegaResourcesOptions {
235
235
  offset?: number;
236
236
  businessDomain?: string;
237
237
  }
238
+ /** List all Vega resources (no catalog filter). Uses GET /resources — not /resources/list, which
239
+ * conflicts with GET /resources/{id} on some gateways (path segment "list" is treated as an id). */
238
240
  export declare function listAllVegaResources(options: ListAllVegaResourcesOptions): Promise<string>;
package/dist/api/vega.js CHANGED
@@ -476,20 +476,15 @@ export async function vegaSQLQuery(options) {
476
476
  throw new HttpError(response.status, response.statusText, body);
477
477
  return body;
478
478
  }
479
+ /** List all Vega resources (no catalog filter). Uses GET /resources — not /resources/list, which
480
+ * conflicts with GET /resources/{id} on some gateways (path segment "list" is treated as an id). */
479
481
  export async function listAllVegaResources(options) {
480
482
  const { baseUrl, accessToken, limit, offset, businessDomain = "bd_public" } = options;
481
- const base = baseUrl.replace(/\/+$/, "");
482
- const url = new URL(`${base}${VEGA_BASE}/resources/list`);
483
- if (limit !== undefined)
484
- url.searchParams.set("limit", String(limit));
485
- if (offset !== undefined)
486
- url.searchParams.set("offset", String(offset));
487
- const response = await fetch(url.toString(), {
488
- method: "GET",
489
- headers: buildHeaders(accessToken, businessDomain),
483
+ return listVegaResources({
484
+ baseUrl,
485
+ accessToken,
486
+ limit,
487
+ offset,
488
+ businessDomain,
490
489
  });
491
- const body = await response.text();
492
- if (!response.ok)
493
- throw new HttpError(response.status, response.statusText, body);
494
- return body;
495
490
  }
@@ -84,7 +84,7 @@ export function parseChatArgs(args) {
84
84
  stream = false;
85
85
  continue;
86
86
  }
87
- if (arg === "--verbose" || arg === "-v") {
87
+ if (arg === "--verbose" || arg === "-v" || arg === "--debug") {
88
88
  verbose = true;
89
89
  continue;
90
90
  }
@@ -1,3 +1,12 @@
1
+ /** Build llm_config with valid defaults for fields that mf-model-api validates. */
2
+ export declare function buildLlmConfig(id: string, name: string, maxTokens: number): Record<string, unknown>;
3
+ /** Resolve LLM model name from mf-model-manager API by model ID. Falls back to llmId on failure. */
4
+ export declare function resolveLlmName(options: {
5
+ baseUrl: string;
6
+ accessToken: string;
7
+ llmId: string;
8
+ businessDomain?: string;
9
+ }): Promise<string>;
1
10
  export interface AgentListOptions {
2
11
  name: string;
3
12
  offset: number;
@@ -7,6 +7,44 @@ import { formatCallOutput } from "./call.js";
7
7
  import { resolveBusinessDomain } from "../config/store.js";
8
8
  import { promises as fs } from "fs";
9
9
  import { join, dirname, basename, extname } from "path";
10
+ import { buildHeaders } from "../api/headers.js";
11
+ /** Build llm_config with valid defaults for fields that mf-model-api validates. */
12
+ export function buildLlmConfig(id, name, maxTokens) {
13
+ return {
14
+ id,
15
+ name,
16
+ max_tokens: maxTokens,
17
+ temperature: 0.7,
18
+ top_p: 1,
19
+ top_k: 1,
20
+ };
21
+ }
22
+ /** Resolve LLM model name from mf-model-manager API by model ID. Falls back to llmId on failure. */
23
+ export async function resolveLlmName(options) {
24
+ const { baseUrl, accessToken, llmId, businessDomain = "bd_public" } = options;
25
+ const base = baseUrl.replace(/\/+$/, "");
26
+ const url = `${base}/api/mf-model-manager/v1/llm/list?page=1&size=50`;
27
+ try {
28
+ const response = await fetch(url, {
29
+ method: "GET",
30
+ headers: buildHeaders(accessToken, businessDomain),
31
+ });
32
+ if (!response.ok)
33
+ return llmId;
34
+ const body = (await response.json());
35
+ const items = (body.data ?? body.entries ?? []);
36
+ const match = items.find((m) => String(m.model_id ?? m.id) === llmId);
37
+ if (match) {
38
+ const name = match.model_name ?? match.name;
39
+ if (typeof name === "string" && name)
40
+ return name;
41
+ }
42
+ return llmId;
43
+ }
44
+ catch {
45
+ return llmId;
46
+ }
47
+ }
10
48
  /**
11
49
  * 生成带时间戳的文件路径
12
50
  * @param path 用户提供的路径
@@ -480,7 +518,7 @@ Subcommands:
480
518
  chat <agent_id> -m "message" Send a single message (non-interactive)
481
519
  sessions <agent_id> List all conversations for an agent
482
520
  history <agent_id> <conversation_id> Show message history for a conversation
483
- trace <conversation_id> Get trace data for a conversation`);
521
+ trace <agent_id> <conversation_id> Get trace data for a conversation`);
484
522
  return Promise.resolve(0);
485
523
  }
486
524
  const dispatch = async () => {
@@ -1144,9 +1182,6 @@ Optional:
1144
1182
  output: { default_format: "markdown" },
1145
1183
  system_prompt: systemPrompt,
1146
1184
  };
1147
- if (llmId) {
1148
- config.llms = [{ is_default: true, llm_config: { id: llmId, name: llmId, max_tokens: llmMaxTokens } }];
1149
- }
1150
1185
  }
1151
1186
  const payload = {
1152
1187
  name,
@@ -1161,6 +1196,11 @@ Optional:
1161
1196
  payload.key = key;
1162
1197
  try {
1163
1198
  const token = await ensureValidToken();
1199
+ // Resolve LLM model name from model-factory before creating agent
1200
+ if (llmId && !configStr) {
1201
+ const llmName = await resolveLlmName({ baseUrl: token.baseUrl, accessToken: token.accessToken, llmId, businessDomain });
1202
+ config.llms = [{ is_default: true, llm_config: buildLlmConfig(llmId, llmName, llmMaxTokens) }];
1203
+ }
1164
1204
  const body = await createAgent({
1165
1205
  baseUrl: token.baseUrl,
1166
1206
  accessToken: token.accessToken,
@@ -1185,8 +1185,13 @@ query/execute: Query or execute actions. execute has side effects - only use whe
1185
1185
  console.error("Usage: kweaver bkn action-type create <kn-id> '<json>'");
1186
1186
  return 1;
1187
1187
  }
1188
+ // Wrap in {"entries": [...]} if needed (ontology-manager expects this envelope)
1189
+ const entry = JSON.parse(bodyJson);
1190
+ const wrapped = entry && typeof entry === "object" && "entries" in entry
1191
+ ? bodyJson
1192
+ : JSON.stringify({ entries: Array.isArray(entry) ? entry : [entry] });
1188
1193
  const token = await ensureValidToken();
1189
- const result = await createActionTypes({ baseUrl: token.baseUrl, accessToken: token.accessToken, knId, body: bodyJson, businessDomain: parsed.businessDomain });
1194
+ const result = await createActionTypes({ baseUrl: token.baseUrl, accessToken: token.accessToken, knId, body: wrapped, businessDomain: parsed.businessDomain });
1190
1195
  console.log(formatCallOutput(result, parsed.pretty));
1191
1196
  return 0;
1192
1197
  }
@@ -6,6 +6,7 @@ import yargs from "yargs";
6
6
  import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
7
7
  import { resolveBusinessDomain } from "../config/store.js";
8
8
  import { getDataflowLogsPage, listDataflowRuns, listDataflows, runDataflowWithFile, runDataflowWithRemoteUrl, } from "../api/dataflow2.js";
9
+ import { createDataflow } from "../api/dataflow.js";
9
10
  function renderTable(rows) {
10
11
  if (rows.length === 0)
11
12
  return "";
@@ -101,16 +102,47 @@ export async function runDataflowCommand(args) {
101
102
  .fail((message, error) => {
102
103
  throw error ?? new Error(message);
103
104
  })
104
- .command("list", "List all dataflows", (command) => command.option("biz-domain", {
105
+ .command("create <json>", "Create a new dataflow (DAG) from a JSON definition", (command) => command
106
+ .positional("json", {
107
+ type: "string",
108
+ describe: "JSON body string or @file-path to read from file",
109
+ })
110
+ .option("biz-domain", { alias: "bd", type: "string" }), async (argv) => {
111
+ exitCode = await with401RefreshRetry(async () => {
112
+ const base = await requireTokenAndBusinessDomain(argv.bizDomain);
113
+ let raw = argv.json;
114
+ if (raw.startsWith("@")) {
115
+ const filePath = raw.slice(1);
116
+ await access(filePath, constants.R_OK);
117
+ raw = (await readFile(filePath, "utf8")).toString();
118
+ }
119
+ const body = JSON.parse(raw);
120
+ const dagId = await createDataflow({ ...base, body });
121
+ console.log(JSON.stringify({ id: dagId }, null, 2));
122
+ return 0;
123
+ });
124
+ })
125
+ .command("list", "List all dataflows", (command) => command
126
+ .option("biz-domain", {
105
127
  alias: "bd",
106
128
  type: "string",
129
+ })
130
+ .option("table", {
131
+ type: "boolean",
132
+ default: false,
133
+ describe: "Output as human-readable table instead of JSON",
107
134
  }), async (argv) => {
108
135
  exitCode = await with401RefreshRetry(async () => {
109
136
  const base = await requireTokenAndBusinessDomain(argv.bizDomain);
110
137
  const body = await listDataflows(base);
111
- const table = renderTable(buildListTableRows(body.dags));
112
- if (table) {
113
- console.log(table);
138
+ if (argv.table) {
139
+ const table = renderTable(buildListTableRows(body.dags));
140
+ if (table) {
141
+ console.log(table);
142
+ }
143
+ }
144
+ else {
145
+ console.log(JSON.stringify(body, null, 2));
114
146
  }
115
147
  return 0;
116
148
  });
@@ -160,6 +192,11 @@ export async function runDataflowCommand(args) {
160
192
  .command("runs <dagId>", "List run records for one dataflow", (command) => command
161
193
  .positional("dagId", { type: "string" })
162
194
  .option("since", { type: "string" })
195
+ .option("table", {
196
+ type: "boolean",
197
+ default: false,
198
+ describe: "Output as human-readable table instead of JSON",
199
+ })
163
200
  .option("biz-domain", { alias: "bd", type: "string" }), async (argv) => {
164
201
  exitCode = await with401RefreshRetry(async () => {
165
202
  const base = await requireTokenAndBusinessDomain(argv.bizDomain);
@@ -203,9 +240,14 @@ export async function runDataflowCommand(args) {
203
240
  results = results.concat(next.results);
204
241
  }
205
242
  }
206
- const table = renderTable(buildRunTableRows(results));
207
- if (table) {
208
- console.log(table);
243
+ if (argv.table) {
244
+ const table = renderTable(buildRunTableRows(results));
245
+ if (table) {
246
+ console.log(table);
247
+ }
248
+ }
249
+ else {
250
+ console.log(JSON.stringify(results, null, 2));
209
251
  }
210
252
  return 0;
211
253
  });
@@ -23,8 +23,8 @@ function printSkillHelp(subcommand) {
23
23
  [--source src] [--extend-info json] [-bd value] [--pretty|--compact]`);
24
24
  return;
25
25
  }
26
- if (subcommand === "status") {
27
- console.log("kweaver skill status <skill-id> <unpublish|published|offline> [-bd value] [--pretty|--compact]");
26
+ if (subcommand === "set-status" || subcommand === "status") {
27
+ console.log("kweaver skill set-status <skill-id> <unpublish|published|offline> [-bd value] [--pretty|--compact]");
28
28
  return;
29
29
  }
30
30
  if (subcommand === "delete") {
@@ -54,7 +54,7 @@ Subcommands:
54
54
  market [--name kw] [--source src] [--page N] [--page-size N] [-bd value]
55
55
  get <skill-id> [-bd value]
56
56
  register --content-file <path> | --zip-file <path> [--source src] [--extend-info json]
57
- status <skill-id> <unpublish|published|offline> [-bd value]
57
+ set-status <skill-id> <unpublish|published|offline> [-bd value]
58
58
  delete <skill-id> [-y] [-bd value]
59
59
  content <skill-id> [--raw] [--output file] [-bd value]
60
60
  read-file <skill-id> <rel-path> [--raw] [--output file] [-bd value]
@@ -419,7 +419,7 @@ export async function runSkillCommand(args) {
419
419
  return 0;
420
420
  }
421
421
  }
422
- if (subcommand === "status") {
422
+ if (subcommand === "set-status" || subcommand === "status") {
423
423
  const opts = parseStatusArgs(rest);
424
424
  const result = await updateSkillStatus({ ...token, ...opts });
425
425
  console.log(format(result, opts.pretty));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kweaver-ai/kweaver-sdk",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
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",
@@ -29,7 +29,6 @@
29
29
  "lint": "tsc --noEmit -p tsconfig.json",
30
30
  "test": "node --import tsx --test test/*.test.ts",
31
31
  "test:e2e": "node --import tsx --test test/e2e/*.test.ts",
32
- "test:e2e:live": "KWEAVER_BASE_URL=${KWEAVER_BASE_URL:-https://43.129.210.161} KWEAVER_NO_AUTH=1 KWEAVER_TLS_INSECURE=1 node --import tsx --test test/e2e/*.test.ts",
33
32
  "prepublishOnly": "npm run build"
34
33
  },
35
34
  "keywords": [