@kweaver-ai/kweaver-sdk 0.7.3 → 0.7.4

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 (43) hide show
  1. package/README.md +29 -0
  2. package/README.zh.md +26 -0
  3. package/bin/kweaver.js +12 -11
  4. package/dist/api/bkn-backend.d.ts +1 -0
  5. package/dist/api/bkn-backend.js +1 -1
  6. package/dist/api/bkn-metrics.d.ts +59 -0
  7. package/dist/api/bkn-metrics.js +129 -0
  8. package/dist/api/conversations.d.ts +47 -2
  9. package/dist/api/conversations.js +113 -17
  10. package/dist/api/datasources.js +43 -6
  11. package/dist/api/model-invocation.d.ts +58 -0
  12. package/dist/api/model-invocation.js +203 -0
  13. package/dist/api/models.d.ts +79 -0
  14. package/dist/api/models.js +183 -0
  15. package/dist/api/ontology-query-metrics.d.ts +14 -0
  16. package/dist/api/ontology-query-metrics.js +30 -0
  17. package/dist/bundled-model-templates.d.ts +17 -0
  18. package/dist/bundled-model-templates.js +24 -0
  19. package/dist/cli.js +10 -0
  20. package/dist/client.d.ts +3 -0
  21. package/dist/client.js +5 -0
  22. package/dist/commands/agent.d.ts +7 -1
  23. package/dist/commands/agent.js +75 -21
  24. package/dist/commands/bkn-metric.d.ts +1 -0
  25. package/dist/commands/bkn-metric.js +406 -0
  26. package/dist/commands/bkn-ops.js +17 -11
  27. package/dist/commands/bkn-utils.d.ts +29 -0
  28. package/dist/commands/bkn-utils.js +37 -0
  29. package/dist/commands/bkn.js +4 -0
  30. package/dist/commands/ds.js +7 -1
  31. package/dist/commands/explore-chat.js +2 -2
  32. package/dist/commands/model.d.ts +72 -0
  33. package/dist/commands/model.js +1315 -0
  34. package/dist/index.d.ts +9 -0
  35. package/dist/index.js +5 -0
  36. package/dist/resources/models.d.ts +40 -0
  37. package/dist/resources/models.js +88 -0
  38. package/dist/templates/model/llm-basic.json +13 -0
  39. package/dist/templates/model/manifest.json +16 -0
  40. package/dist/templates/model/small-basic.json +6 -0
  41. package/dist/utils/trace-views.d.ts +44 -0
  42. package/dist/utils/trace-views.js +425 -0
  43. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -29,6 +29,10 @@ export type { ListKnowledgeNetworksOptions, GetKnowledgeNetworkOptions, CreateKn
29
29
  export { listKnowledgeNetworks, getKnowledgeNetwork, createKnowledgeNetwork, updateKnowledgeNetwork, deleteKnowledgeNetwork, listObjectTypes, listRelationTypes, listActionTypes, } from "./api/knowledge-networks.js";
30
30
  export type { OntologyQueryBaseOptions, ObjectTypeQueryOptions, ObjectTypePropertiesOptions, SubgraphOptions, ActionTypeQueryOptions, ActionTypeExecuteOptions, ActionExecutionGetOptions, ActionLogsListOptions, ActionLogGetOptions, ActionLogCancelOptions, } from "./api/ontology-query.js";
31
31
  export { objectTypeQuery, objectTypeProperties, subgraph, actionTypeQuery, actionTypeExecute, actionExecutionGet, actionLogsList, actionLogGet, actionLogCancel, } from "./api/ontology-query.js";
32
+ export type { MetricQueryDataOptions, MetricDryRunOptions } from "./api/ontology-query-metrics.js";
33
+ export { metricQueryData, metricDryRun } from "./api/ontology-query-metrics.js";
34
+ export type { ListMetricsOptions, CreateMetricsOptions, SearchMetricsOptions, ValidateMetricsOptions, GetMetricOptions, UpdateMetricOptions, DeleteMetricOptions, GetMetricsByIdsOptions, DeleteMetricsByIdsOptions, } from "./api/bkn-metrics.js";
35
+ export { listMetrics, createMetrics, searchMetrics, validateMetrics, getMetric, updateMetric, deleteMetric, getMetrics, deleteMetrics, } from "./api/bkn-metrics.js";
32
36
  export type { SendChatRequestOptions, SendChatRequestStreamCallbacks, ChatResult, ProgressItem, AgentInfo, } from "./api/agent-chat.js";
33
37
  export { sendChatRequest, sendChatRequestStream, fetchAgentInfo, buildChatUrl, buildAgentInfoUrl, extractText, } from "./api/agent-chat.js";
34
38
  export type { ListAgentsOptions, GetAgentOptions, GetAgentByKeyOptions, CreateAgentOptions, UpdateAgentOptions, DeleteAgentOptions, PublishAgentOptions, UnpublishAgentOptions, } from "./api/agent-list.js";
@@ -52,11 +56,16 @@ export { ContextLoaderResource } from "./resources/context-loader.js";
52
56
  export { SkillsResource } from "./resources/skills.js";
53
57
  export { ToolboxesResource } from "./resources/toolboxes.js";
54
58
  export type { InvokeToolArgs } from "./resources/toolboxes.js";
59
+ export { ModelsResource, LlmModelsSubresource, SmallModelsSubresource, ModelInvocationSubresource, } from "./resources/models.js";
55
60
  export type { SkillStatus, SkillSummary, SkillInfo, SkillFileSummary, SkillContentIndex, SkillFileReadResult, RegisterSkillResult, DeleteSkillResult, UpdateSkillStatusResult, SkillListResult, ListSkillsOptions, ListSkillMarketOptions, GetSkillOptions, RegisterSkillContentOptions, RegisterSkillZipOptions, UpdateSkillStatusOptions, ReadSkillFileOptions, DownloadSkillOptions, DownloadedSkillArchive, } from "./api/skills.js";
56
61
  export { listSkills, listSkillMarket, getSkill, deleteSkill, updateSkillStatus, registerSkillContent, registerSkillZip, getSkillContentIndex, fetchSkillContent, readSkillFile, fetchSkillFile, downloadSkill, installSkillArchive, } from "./api/skills.js";
57
62
  export type { ViewField, DataView, CreateDataViewOptions, GetDataViewOptions, ListDataViewsOptions, DeleteDataViewOptions, FindDataViewOptions, QueryDataViewOptions, DataViewQueryResult, } from "./api/dataviews.js";
58
63
  export { parseDataView, createDataView, getDataView, listDataViews, deleteDataView, findDataView, queryDataView, } from "./api/dataviews.js";
59
64
  export { DataViewsResource } from "./resources/dataviews.js";
65
+ export type { MfManagerBaseOptions, ListLlmModelsOptions, GetLlmModelOptions, AddLlmModelOptions, EditLlmModelOptions, DeleteLlmModelsOptions, TestLlmModelOptions, ListSmallModelsOptions, GetSmallModelOptions, AddSmallModelOptions, EditSmallModelOptions, DeleteSmallModelsOptions, TestSmallModelOptions, } from "./api/models.js";
66
+ export { MF_MODEL_MANAGER_PATH_PREFIX, assertSmallModelConfigAdapterExclusive, assertSmallModelEditBody, listLlmModels, getLlmModel, addLlmModel, editLlmModel, deleteLlmModels, testLlmModel, listSmallModels, getSmallModel, addSmallModel, editSmallModel, deleteSmallModels, testSmallModel, } from "./api/models.js";
67
+ export type { MfApiBaseOptions, ChatMessage, ModelChatCompletionsOptions, ModelChatResult, ModelEmbeddingOptions, ModelRerankOptions, } from "./api/model-invocation.js";
68
+ export { MF_MODEL_API_PATH_PREFIX, consumeOpenAiSseText, modelChatCompletions, modelEmbedding, modelEmbeddings, modelRerank, } from "./api/model-invocation.js";
60
69
  export type { BusinessDomain, ListBusinessDomainsOptions } from "./api/business-domains.js";
61
70
  export { listBusinessDomains } from "./api/business-domains.js";
62
71
  export type { CreateToolboxOptions, DeleteToolboxOptions, SetToolboxStatusOptions, UploadToolOptions, SetToolStatusesOptions, ListToolboxesOptions, ListToolsOptions, InvokeToolOptions, } from "./api/toolboxes.js";
package/dist/index.js CHANGED
@@ -27,6 +27,8 @@
27
27
  */
28
28
  export { listKnowledgeNetworks, getKnowledgeNetwork, createKnowledgeNetwork, updateKnowledgeNetwork, deleteKnowledgeNetwork, listObjectTypes, listRelationTypes, listActionTypes, } from "./api/knowledge-networks.js";
29
29
  export { objectTypeQuery, objectTypeProperties, subgraph, actionTypeQuery, actionTypeExecute, actionExecutionGet, actionLogsList, actionLogGet, actionLogCancel, } from "./api/ontology-query.js";
30
+ export { metricQueryData, metricDryRun } from "./api/ontology-query-metrics.js";
31
+ export { listMetrics, createMetrics, searchMetrics, validateMetrics, getMetric, updateMetric, deleteMetric, getMetrics, deleteMetrics, } from "./api/bkn-metrics.js";
30
32
  export { sendChatRequest, sendChatRequestStream, fetchAgentInfo, buildChatUrl, buildAgentInfoUrl, extractText, } from "./api/agent-chat.js";
31
33
  export { listAgents, getAgent, getAgentByKey, createAgent, updateAgent, deleteAgent, publishAgent, unpublishAgent, } from "./api/agent-list.js";
32
34
  export { listConversations, listMessages } from "./api/conversations.js";
@@ -41,9 +43,12 @@ export { ConversationsResource } from "./resources/conversations.js";
41
43
  export { ContextLoaderResource } from "./resources/context-loader.js";
42
44
  export { SkillsResource } from "./resources/skills.js";
43
45
  export { ToolboxesResource } from "./resources/toolboxes.js";
46
+ export { ModelsResource, LlmModelsSubresource, SmallModelsSubresource, ModelInvocationSubresource, } from "./resources/models.js";
44
47
  export { listSkills, listSkillMarket, getSkill, deleteSkill, updateSkillStatus, registerSkillContent, registerSkillZip, getSkillContentIndex, fetchSkillContent, readSkillFile, fetchSkillFile, downloadSkill, installSkillArchive, } from "./api/skills.js";
45
48
  export { parseDataView, createDataView, getDataView, listDataViews, deleteDataView, findDataView, queryDataView, } from "./api/dataviews.js";
46
49
  export { DataViewsResource } from "./resources/dataviews.js";
50
+ export { MF_MODEL_MANAGER_PATH_PREFIX, assertSmallModelConfigAdapterExclusive, assertSmallModelEditBody, listLlmModels, getLlmModel, addLlmModel, editLlmModel, deleteLlmModels, testLlmModel, listSmallModels, getSmallModel, addSmallModel, editSmallModel, deleteSmallModels, testSmallModel, } from "./api/models.js";
51
+ export { MF_MODEL_API_PATH_PREFIX, consumeOpenAiSseText, modelChatCompletions, modelEmbedding, modelEmbeddings, modelRerank, } from "./api/model-invocation.js";
47
52
  export { listBusinessDomains } from "./api/business-domains.js";
48
53
  export { createToolbox, deleteToolbox, setToolboxStatus, uploadTool, setToolStatuses, listToolboxes, listTools, executeTool, debugTool, } from "./api/toolboxes.js";
49
54
  // ── HTTP utilities ────────────────────────────────────────────────────────────
@@ -0,0 +1,40 @@
1
+ import type { ClientContext } from "../client.js";
2
+ import { type ListLlmModelsOptions, type ListSmallModelsOptions, type MfManagerBaseOptions } from "../api/models.js";
3
+ import { type MfApiBaseOptions, type ModelChatCompletionsOptions, type ModelEmbeddingOptions, type ModelRerankOptions } from "../api/model-invocation.js";
4
+ type Base = MfManagerBaseOptions;
5
+ export declare class LlmModelsSubresource {
6
+ private readonly ctx;
7
+ constructor(ctx: ClientContext);
8
+ list(opts: Omit<ListLlmModelsOptions, keyof Base> & Partial<MfManagerBaseOptions>): Promise<unknown>;
9
+ get(modelId: string, opts?: Partial<Pick<MfManagerBaseOptions, "mfManagerBaseUrl" | "businessDomain">>): Promise<unknown>;
10
+ add(body: Record<string, unknown>, opts?: Partial<Pick<MfManagerBaseOptions, "mfManagerBaseUrl" | "businessDomain">>): Promise<unknown>;
11
+ edit(body: Record<string, unknown>, opts?: Partial<Pick<MfManagerBaseOptions, "mfManagerBaseUrl" | "businessDomain">>): Promise<unknown>;
12
+ delete(modelIds: string[], opts?: Partial<Pick<MfManagerBaseOptions, "mfManagerBaseUrl" | "businessDomain">>): Promise<unknown>;
13
+ test(body: Record<string, unknown>, opts?: Partial<Pick<MfManagerBaseOptions, "mfManagerBaseUrl" | "businessDomain">>): Promise<unknown>;
14
+ }
15
+ export declare class SmallModelsSubresource {
16
+ private readonly ctx;
17
+ constructor(ctx: ClientContext);
18
+ list(opts: Omit<ListSmallModelsOptions, keyof Base> & Partial<MfManagerBaseOptions>): Promise<unknown>;
19
+ get(modelId: string, opts?: Partial<Pick<MfManagerBaseOptions, "mfManagerBaseUrl" | "businessDomain">>): Promise<unknown>;
20
+ add(body: Record<string, unknown>, opts?: Partial<Pick<MfManagerBaseOptions, "mfManagerBaseUrl" | "businessDomain">>): Promise<unknown>;
21
+ edit(body: Record<string, unknown>, opts?: Partial<Pick<MfManagerBaseOptions, "mfManagerBaseUrl" | "businessDomain">>): Promise<unknown>;
22
+ delete(modelIds: string[], opts?: Partial<Pick<MfManagerBaseOptions, "mfManagerBaseUrl" | "businessDomain">>): Promise<unknown>;
23
+ test(body: Record<string, unknown>, opts?: Partial<Pick<MfManagerBaseOptions, "mfManagerBaseUrl" | "businessDomain">>): Promise<unknown>;
24
+ }
25
+ export declare class ModelInvocationSubresource {
26
+ private readonly ctx;
27
+ constructor(ctx: ClientContext);
28
+ chat(opts: Omit<ModelChatCompletionsOptions, "baseUrl" | "accessToken" | "businessDomain"> & Partial<Pick<MfApiBaseOptions, "mfApiBaseUrl" | "businessDomain">>): Promise<import("../api/model-invocation.js").ModelChatResult>;
29
+ embedding(opts: Omit<ModelEmbeddingOptions, "baseUrl" | "accessToken" | "businessDomain"> & Partial<Pick<MfApiBaseOptions, "mfApiBaseUrl" | "businessDomain">>): Promise<unknown>;
30
+ embeddings(opts: Omit<ModelEmbeddingOptions, "baseUrl" | "accessToken" | "businessDomain"> & Partial<Pick<MfApiBaseOptions, "mfApiBaseUrl" | "businessDomain">>): Promise<unknown>;
31
+ rerank(opts: Omit<ModelRerankOptions, "baseUrl" | "accessToken" | "businessDomain"> & Partial<Pick<MfApiBaseOptions, "mfApiBaseUrl" | "businessDomain">>): Promise<unknown>;
32
+ }
33
+ /** Model factory: mf-model-manager (CRUD) + mf-model-api (invoke chat / embedding / rerank). */
34
+ export declare class ModelsResource {
35
+ readonly llm: LlmModelsSubresource;
36
+ readonly small: SmallModelsSubresource;
37
+ readonly invocation: ModelInvocationSubresource;
38
+ constructor(ctx: ClientContext);
39
+ }
40
+ export {};
@@ -0,0 +1,88 @@
1
+ import { addLlmModel, addSmallModel, deleteLlmModels, deleteSmallModels, editLlmModel, editSmallModel, getLlmModel, getSmallModel, listLlmModels, listSmallModels, testLlmModel, testSmallModel, } from "../api/models.js";
2
+ import { modelChatCompletions, modelEmbedding, modelEmbeddings, modelRerank, } from "../api/model-invocation.js";
3
+ export class LlmModelsSubresource {
4
+ ctx;
5
+ constructor(ctx) {
6
+ this.ctx = ctx;
7
+ }
8
+ list(opts) {
9
+ return listLlmModels({ ...this.ctx.base(), ...opts });
10
+ }
11
+ get(modelId, opts = {}) {
12
+ return getLlmModel({ ...this.ctx.base(), modelId, ...opts });
13
+ }
14
+ add(body, opts = {}) {
15
+ return addLlmModel({ ...this.ctx.base(), body, ...opts });
16
+ }
17
+ edit(body, opts = {}) {
18
+ return editLlmModel({ ...this.ctx.base(), body, ...opts });
19
+ }
20
+ delete(modelIds, opts = {}) {
21
+ return deleteLlmModels({ ...this.ctx.base(), modelIds, ...opts });
22
+ }
23
+ test(body, opts = {}) {
24
+ return testLlmModel({ ...this.ctx.base(), body, ...opts });
25
+ }
26
+ }
27
+ export class SmallModelsSubresource {
28
+ ctx;
29
+ constructor(ctx) {
30
+ this.ctx = ctx;
31
+ }
32
+ list(opts) {
33
+ return listSmallModels({ ...this.ctx.base(), ...opts });
34
+ }
35
+ get(modelId, opts = {}) {
36
+ return getSmallModel({ ...this.ctx.base(), modelId, ...opts });
37
+ }
38
+ add(body, opts = {}) {
39
+ return addSmallModel({ ...this.ctx.base(), body, ...opts });
40
+ }
41
+ edit(body, opts = {}) {
42
+ return editSmallModel({ ...this.ctx.base(), body, ...opts });
43
+ }
44
+ delete(modelIds, opts = {}) {
45
+ return deleteSmallModels({ ...this.ctx.base(), modelIds, ...opts });
46
+ }
47
+ test(body, opts = {}) {
48
+ return testSmallModel({ ...this.ctx.base(), body, ...opts });
49
+ }
50
+ }
51
+ export class ModelInvocationSubresource {
52
+ ctx;
53
+ constructor(ctx) {
54
+ this.ctx = ctx;
55
+ }
56
+ chat(opts) {
57
+ const { baseUrl, accessToken, businessDomain } = this.ctx.base();
58
+ return modelChatCompletions({
59
+ baseUrl,
60
+ accessToken,
61
+ businessDomain,
62
+ ...opts,
63
+ });
64
+ }
65
+ embedding(opts) {
66
+ const { baseUrl, accessToken, businessDomain } = this.ctx.base();
67
+ return modelEmbedding({ baseUrl, accessToken, businessDomain, ...opts });
68
+ }
69
+ embeddings(opts) {
70
+ const { baseUrl, accessToken, businessDomain } = this.ctx.base();
71
+ return modelEmbeddings({ baseUrl, accessToken, businessDomain, ...opts });
72
+ }
73
+ rerank(opts) {
74
+ const { baseUrl, accessToken, businessDomain } = this.ctx.base();
75
+ return modelRerank({ baseUrl, accessToken, businessDomain, ...opts });
76
+ }
77
+ }
78
+ /** Model factory: mf-model-manager (CRUD) + mf-model-api (invoke chat / embedding / rerank). */
79
+ export class ModelsResource {
80
+ llm;
81
+ small;
82
+ invocation;
83
+ constructor(ctx) {
84
+ this.llm = new LlmModelsSubresource(ctx);
85
+ this.small = new SmallModelsSubresource(ctx);
86
+ this.invocation = new ModelInvocationSubresource(ctx);
87
+ }
88
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "__template_note": "Shape aligned with mf-model-manager POST /llm/add: nested model_config (required). model_series must be one of: tome, qwen, openai, internlm, deepseek, qianxun, claude, chatglm, llama, others, baidu, baidu_tianchen. model_type: llm | rlm | vu. Optional: model_parameters (int>0), quota (bool). openai series: api_key required by backend validation. baidu/baidu_tianchen need extra keys inside model_config per vendor.",
3
+ "model_name": "example-llm",
4
+ "model_series": "others",
5
+ "model_type": "llm",
6
+ "max_model_len": 8192,
7
+ "model_config": {
8
+ "api_url": "https://example.com/v1/chat/completions",
9
+ "api_model": "example-deployment",
10
+ "api_key": ""
11
+ },
12
+ "quota": false
13
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "llm": [
3
+ {
4
+ "id": "basic",
5
+ "file": "llm-basic.json",
6
+ "summary": "Minimal POST /llm/add body — model_config nested + model_series / max_model_len / model_type"
7
+ }
8
+ ],
9
+ "small": [
10
+ {
11
+ "id": "basic",
12
+ "file": "small-basic.json",
13
+ "summary": "Minimal model_config stub for embedding/reranker registration — extend or merge with CLI flags"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "__template_note": "Fragment for small-model model_config only (POST /small-model/add). Backend requires api_url + api_model inside model_config. Root fields model_name, model_type (embedding|reranker), batch_size, and for embedding also max_tokens + embedding_dim are supplied via CLI flags or separate JSON root — not repeated here.",
3
+ "api_url": "https://example.com/v1/embeddings",
4
+ "api_model": "example-embedding-model",
5
+ "api_key": ""
6
+ }
@@ -0,0 +1,44 @@
1
+ import type { TraceSpan, TracesByConversationResult } from "../api/conversations.js";
2
+ export interface SpanNode {
3
+ span: TraceSpan;
4
+ children: SpanNode[];
5
+ }
6
+ /**
7
+ * Build a parent-child forest from a flat span array.
8
+ *
9
+ * Spans whose parentSpanId is missing or points to a span that is not in the set
10
+ * are treated as roots. Multiple traceIds in one conversation produce multiple roots.
11
+ * Children are sorted by startTime ascending.
12
+ */
13
+ export declare function buildSpanTree(spans: TraceSpan[]): SpanNode[];
14
+ /**
15
+ * Tree view: indented call topology with duration, status, service, and inline metadata.
16
+ */
17
+ export declare function formatTreeView(spans: TraceSpan[]): string;
18
+ /**
19
+ * Perf view: aggregated duration and call count per category.
20
+ */
21
+ export declare function formatPerfView(spans: TraceSpan[]): string;
22
+ /**
23
+ * Evidence view: ordered chain of execute_tool spans with arguments, hit count, and score.
24
+ */
25
+ export declare function formatEvidenceView(spans: TraceSpan[]): string;
26
+ export interface ReasoningOptions {
27
+ /** When true, print every message at full length. Default truncates large bodies. */
28
+ full?: boolean;
29
+ }
30
+ /**
31
+ * Reasoning view: walks the LLM's chat history (input messages of the chat span +
32
+ * the assistant's final output) so the user can read the agent's actual thought
33
+ * process — system / user / assistant / tool_call / tool result / final answer.
34
+ */
35
+ export declare function formatReasoningView(spans: TraceSpan[], opts?: ReasoningOptions): string;
36
+ export type TraceView = "tree" | "perf" | "evidence" | "reasoning" | "all";
37
+ export interface FormatOptions {
38
+ /** Pass through to formatReasoningView — disables per-message truncation. */
39
+ full?: boolean;
40
+ }
41
+ /**
42
+ * Render one or more views over a trace result. Returns concatenated text suitable for stdout.
43
+ */
44
+ export declare function formatTraceResult(result: TracesByConversationResult, view: TraceView, opts?: FormatOptions): string;