@kweaver-ai/kweaver-sdk 0.7.3 → 0.8.1
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/README.md +49 -0
- package/README.zh.md +44 -0
- package/bin/kweaver.js +12 -11
- package/dist/api/agent-observability.d.ts +51 -0
- package/dist/api/agent-observability.js +108 -0
- package/dist/api/bkn-backend.d.ts +1 -0
- package/dist/api/bkn-backend.js +1 -1
- package/dist/api/bkn-metrics.d.ts +59 -0
- package/dist/api/bkn-metrics.js +129 -0
- package/dist/api/conversations.d.ts +43 -2
- package/dist/api/conversations.js +77 -23
- package/dist/api/datasources.d.ts +2 -20
- package/dist/api/datasources.js +7 -86
- package/dist/api/model-invocation.d.ts +58 -0
- package/dist/api/model-invocation.js +203 -0
- package/dist/api/models.d.ts +79 -0
- package/dist/api/models.js +183 -0
- package/dist/api/ontology-query-metrics.d.ts +14 -0
- package/dist/api/ontology-query-metrics.js +30 -0
- package/dist/api/trace.d.ts +44 -0
- package/dist/api/trace.js +81 -0
- package/dist/api/vega.d.ts +53 -0
- package/dist/api/vega.js +144 -0
- package/dist/bundled-model-templates.d.ts +17 -0
- package/dist/bundled-model-templates.js +24 -0
- package/dist/cli.js +15 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.js +5 -0
- package/dist/commands/agent.d.ts +7 -1
- package/dist/commands/agent.js +75 -21
- package/dist/commands/bkn-metric.d.ts +1 -0
- package/dist/commands/bkn-metric.js +406 -0
- package/dist/commands/bkn-ops.js +28 -16
- package/dist/commands/bkn-utils.d.ts +38 -0
- package/dist/commands/bkn-utils.js +54 -0
- package/dist/commands/bkn.js +4 -0
- package/dist/commands/ds.js +14 -3
- package/dist/commands/explore-chat.js +2 -2
- package/dist/commands/model.d.ts +72 -0
- package/dist/commands/model.js +1315 -0
- package/dist/commands/trace.d.ts +14 -0
- package/dist/commands/trace.js +168 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +5 -0
- package/dist/resources/datasources.js +2 -1
- package/dist/resources/models.d.ts +40 -0
- package/dist/resources/models.js +88 -0
- package/dist/templates/model/llm-basic.json +13 -0
- package/dist/templates/model/manifest.json +16 -0
- package/dist/templates/model/small-basic.json +6 -0
- package/dist/trace-core/diagnose/builtin-rules/excessive-tool-calls-per-turn.d.ts +2 -0
- package/dist/trace-core/diagnose/builtin-rules/excessive-tool-calls-per-turn.js +15 -0
- package/dist/trace-core/diagnose/builtin-rules/excessive-tool-calls-per-turn.yaml +16 -0
- package/dist/trace-core/diagnose/builtin-rules/llm-response-truncated-no-continue.d.ts +2 -0
- package/dist/trace-core/diagnose/builtin-rules/llm-response-truncated-no-continue.js +44 -0
- package/dist/trace-core/diagnose/builtin-rules/llm-response-truncated-no-continue.yaml +15 -0
- package/dist/trace-core/diagnose/builtin-rules/register.d.ts +1 -0
- package/dist/trace-core/diagnose/builtin-rules/register.js +11 -0
- package/dist/trace-core/diagnose/builtin-rules/retrieval-empty-no-fallback.d.ts +2 -0
- package/dist/trace-core/diagnose/builtin-rules/retrieval-empty-no-fallback.js +29 -0
- package/dist/trace-core/diagnose/builtin-rules/retrieval-empty-no-fallback.yaml +15 -0
- package/dist/trace-core/diagnose/builtin-rules/tool-error-swallowed.d.ts +2 -0
- package/dist/trace-core/diagnose/builtin-rules/tool-error-swallowed.js +45 -0
- package/dist/trace-core/diagnose/builtin-rules/tool-error-swallowed.yaml +15 -0
- package/dist/trace-core/diagnose/builtin-rules/tool-loop-no-state-change.d.ts +2 -0
- package/dist/trace-core/diagnose/builtin-rules/tool-loop-no-state-change.js +38 -0
- package/dist/trace-core/diagnose/builtin-rules/tool-loop-no-state-change.yaml +16 -0
- package/dist/trace-core/diagnose/index.d.ts +9 -0
- package/dist/trace-core/diagnose/index.js +104 -0
- package/dist/trace-core/diagnose/predicate-registry.d.ts +7 -0
- package/dist/trace-core/diagnose/predicate-registry.js +30 -0
- package/dist/trace-core/diagnose/report-assembler.d.ts +12 -0
- package/dist/trace-core/diagnose/report-assembler.js +90 -0
- package/dist/trace-core/diagnose/rule-loader.d.ts +11 -0
- package/dist/trace-core/diagnose/rule-loader.js +86 -0
- package/dist/trace-core/diagnose/schemas.d.ts +109 -0
- package/dist/trace-core/diagnose/schemas.js +94 -0
- package/dist/trace-core/diagnose/signal-probe.d.ts +5 -0
- package/dist/trace-core/diagnose/signal-probe.js +21 -0
- package/dist/trace-core/diagnose/synthesizer-template.d.ts +2 -0
- package/dist/trace-core/diagnose/synthesizer-template.js +49 -0
- package/dist/trace-core/diagnose/trace-shaper.d.ts +3 -0
- package/dist/trace-core/diagnose/trace-shaper.js +72 -0
- package/dist/trace-core/diagnose/types.d.ts +124 -0
- package/dist/trace-core/diagnose/types.js +1 -0
- package/dist/utils/trace-views.d.ts +44 -0
- package/dist/utils/trace-views.js +425 -0
- package/package.json +15 -5
package/dist/commands/bkn-ops.js
CHANGED
|
@@ -5,7 +5,7 @@ import { loadNetwork, allObjects, allRelations, allActions, generateChecksum, va
|
|
|
5
5
|
import { prepareBknDirectoryForImport, stripBknEncodingCliArgs, } from "../utils/bkn-encoding.js";
|
|
6
6
|
import { ensureValidToken, formatHttpError } from "../auth/oauth.js";
|
|
7
7
|
import { createKnowledgeNetwork, createObjectTypes, deleteKnowledgeNetwork, buildKnowledgeNetwork, getBuildStatus, } from "../api/knowledge-networks.js";
|
|
8
|
-
import { listTablesWithColumns, scanDatasourceMetadata } from "../api/
|
|
8
|
+
import { listTablesWithColumns, scanDatasourceMetadata } from "../api/vega.js";
|
|
9
9
|
import { createDataView, findDataView } from "../api/dataviews.js";
|
|
10
10
|
import { resolveFiles } from "./ds.js";
|
|
11
11
|
import { buildTableName } from "./import-csv.js";
|
|
@@ -13,7 +13,7 @@ import { downloadBkn, uploadBkn, listActionSchedules, getActionSchedule, createA
|
|
|
13
13
|
import { formatCallOutput } from "./call.js";
|
|
14
14
|
import { resolveBusinessDomain } from "../config/store.js";
|
|
15
15
|
import { runDsImportCsv } from "./ds.js";
|
|
16
|
-
import { pollWithBackoff,
|
|
16
|
+
import { pollWithBackoff, detectDisplayKey, formatPkDetectionError, parsePkMap, resolvePrimaryKey, confirmYes, assertVegaCatalogId, } from "./bkn-utils.js";
|
|
17
17
|
// ── BKN object name validation ──────────────────────────────────────────────
|
|
18
18
|
// Mirrors bkn-backend OBJECT_NAME_MAX_LENGTH (interfaces/common.go:28) and
|
|
19
19
|
// validateObjectName (driveradapters/validate.go:85). 40 utf-8 codepoints,
|
|
@@ -473,9 +473,11 @@ export async function runKnPullCommand(args) {
|
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
// ── Create from datasource ──────────────────────────────────────────────────
|
|
476
|
-
const KN_CREATE_FROM_DS_HELP = `kweaver bkn create-from-ds <
|
|
476
|
+
const KN_CREATE_FROM_DS_HELP = `kweaver bkn create-from-ds <vega-catalog-id> --name X [options]
|
|
477
477
|
|
|
478
|
-
Create a knowledge network from a datasource (dataviews + object types + optional build).
|
|
478
|
+
Create a knowledge network from a vega catalog datasource (dataviews + object types + optional build).
|
|
479
|
+
<vega-catalog-id> is a vega catalog id (use \`kweaver vega catalog list\` to find one;
|
|
480
|
+
legacy data-connection datasource UUIDs are no longer accepted).
|
|
479
481
|
|
|
480
482
|
Options:
|
|
481
483
|
--name <s> Knowledge network name (required)
|
|
@@ -548,6 +550,7 @@ export function parseKnCreateFromDsArgs(args) {
|
|
|
548
550
|
if (!dsId || !name) {
|
|
549
551
|
throw new Error("Usage: kweaver bkn create-from-ds <ds-id> --name X [options]");
|
|
550
552
|
}
|
|
553
|
+
assertVegaCatalogId(dsId);
|
|
551
554
|
const pkMap = pkMapStr ? parsePkMap(pkMapStr) : {};
|
|
552
555
|
if (!businessDomain)
|
|
553
556
|
businessDomain = resolveBusinessDomain();
|
|
@@ -644,19 +647,25 @@ export async function runKnCreateFromDsCommand(args, sampleRows) {
|
|
|
644
647
|
}
|
|
645
648
|
for (const t of targetTables) {
|
|
646
649
|
const override = options.pkMap[t.name];
|
|
647
|
-
if (override) {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
650
|
+
if (override && !t.columns.some((c) => c.name === override)) {
|
|
651
|
+
throw new Error(`--pk-map specifies '${override}' for table '${t.name}', but no such column. ` +
|
|
652
|
+
`Columns: ${t.columns.map((c) => c.name).join(", ")}`);
|
|
653
|
+
}
|
|
654
|
+
const resolution = resolvePrimaryKey(t, sampleRows?.[t.name], override);
|
|
655
|
+
if (resolution.pk) {
|
|
656
|
+
tablePks[t.name] = resolution.pk;
|
|
653
657
|
continue;
|
|
654
658
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
throw new Error(
|
|
659
|
+
if (resolution.source === "ambiguous") {
|
|
660
|
+
const cols = (resolution.ambiguous ?? []).join(", ");
|
|
661
|
+
throw new Error(`Table '${t.name}' has a composite PRIMARY KEY (${cols}). ` +
|
|
662
|
+
`BKN object types take a single primary key — pick one with --pk-map ${t.name}:<column>.`);
|
|
658
663
|
}
|
|
659
|
-
|
|
664
|
+
throw new Error(formatPkDetectionError(t.name, {
|
|
665
|
+
pk: null,
|
|
666
|
+
candidates: resolution.candidates ?? [],
|
|
667
|
+
sampleSize: resolution.sampleSize ?? 0,
|
|
668
|
+
}));
|
|
660
669
|
}
|
|
661
670
|
// Phase 1: Create DataViews for each table. findDataView is idempotent;
|
|
662
671
|
// not tracked for rollback so a retry can reuse what's already there.
|
|
@@ -797,9 +806,11 @@ export async function runKnCreateFromDsCommand(args, sampleRows) {
|
|
|
797
806
|
}
|
|
798
807
|
}
|
|
799
808
|
// ── Create from CSV ─────────────────────────────────────────────────────────
|
|
800
|
-
const KN_CREATE_FROM_CSV_HELP = `kweaver bkn create-from-csv <
|
|
809
|
+
const KN_CREATE_FROM_CSV_HELP = `kweaver bkn create-from-csv <vega-catalog-id> --files <glob> --name X [options]
|
|
801
810
|
|
|
802
|
-
Import CSV files into datasource, then create a knowledge network.
|
|
811
|
+
Import CSV files into a vega catalog datasource, then create a knowledge network.
|
|
812
|
+
<vega-catalog-id> is a vega catalog id (use \`kweaver vega catalog list\` to find one;
|
|
813
|
+
legacy data-connection datasource UUIDs are no longer accepted).
|
|
803
814
|
|
|
804
815
|
Options:
|
|
805
816
|
--files <s> CSV file paths (comma-separated or glob, required)
|
|
@@ -885,6 +896,7 @@ export function parseKnCreateFromCsvArgs(args) {
|
|
|
885
896
|
if (!dsId || !files || !name) {
|
|
886
897
|
throw new Error("Usage: kweaver bkn create-from-csv <ds-id> --files <glob> --name X [options]");
|
|
887
898
|
}
|
|
899
|
+
assertVegaCatalogId(dsId);
|
|
888
900
|
const pkMap = pkMapStr ? parsePkMap(pkMapStr) : {};
|
|
889
901
|
if (!businessDomain)
|
|
890
902
|
businessDomain = resolveBusinessDomain();
|
|
@@ -43,6 +43,35 @@ export declare function detectPrimaryKey(table: {
|
|
|
43
43
|
type: string;
|
|
44
44
|
}>;
|
|
45
45
|
}, rows?: Array<Record<string, string | null>>): PkDetectionResult;
|
|
46
|
+
export interface PkResolution {
|
|
47
|
+
/** Resolved PK column name, or null when caller must fail-fast. */
|
|
48
|
+
pk: string | null;
|
|
49
|
+
/** Origin of the resolution — used by callers for messaging and warnings. */
|
|
50
|
+
source: "override" | "schema" | "sample" | "ambiguous";
|
|
51
|
+
/** For 'sample' source: cardinality candidates from `detectPrimaryKey`. */
|
|
52
|
+
candidates?: PkCandidate[];
|
|
53
|
+
/** For 'sample' source: rows seen, propagated for error formatting. */
|
|
54
|
+
sampleSize?: number;
|
|
55
|
+
/** For 'ambiguous' source: schema-declared composite PK columns. */
|
|
56
|
+
ambiguous?: string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolve a single PK for a BKN object type, in priority order:
|
|
60
|
+
* 1. caller-provided override (e.g. --pk-map)
|
|
61
|
+
* 2. schema-declared single PK from datasource metadata
|
|
62
|
+
* 3. sample-based detection (CSV / schemaless sources)
|
|
63
|
+
* Composite SQL PKs intentionally surface as `source: "ambiguous"` — BKN
|
|
64
|
+
* object types take a single PK, so the caller must pick via --pk-map.
|
|
65
|
+
*/
|
|
66
|
+
export declare function resolvePrimaryKey(table: {
|
|
67
|
+
name: string;
|
|
68
|
+
columns: Array<{
|
|
69
|
+
name: string;
|
|
70
|
+
type: string;
|
|
71
|
+
isPrimaryKey?: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
primaryKeys?: string[];
|
|
74
|
+
}, sampleRows?: Array<Record<string, string | null>>, override?: string | null): PkResolution;
|
|
46
75
|
/** Format a user-facing error message when PK auto-detection fails. */
|
|
47
76
|
export declare function formatPkDetectionError(tableName: string, result: PkDetectionResult): string;
|
|
48
77
|
/**
|
|
@@ -57,4 +86,13 @@ export declare function detectDisplayKey(table: {
|
|
|
57
86
|
type: string;
|
|
58
87
|
}>;
|
|
59
88
|
}, primaryKey: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Reject legacy data-connection datasource UUIDs.
|
|
91
|
+
*
|
|
92
|
+
* Since the SDK migration to vega-backend (#114), commands that call
|
|
93
|
+
* `listTablesWithColumns` / `scanMetadata` expect a vega catalog id (a short
|
|
94
|
+
* slug like `d7nicrcjto2s73d9g67g`), not the UUID-shaped id stored in
|
|
95
|
+
* data-connection.
|
|
96
|
+
*/
|
|
97
|
+
export declare function assertVegaCatalogId(id: string): void;
|
|
60
98
|
export declare function confirmYes(prompt: string): Promise<boolean>;
|
|
@@ -98,6 +98,43 @@ export function detectPrimaryKey(table, rows) {
|
|
|
98
98
|
sampleSize: rows.length,
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Resolve a single PK for a BKN object type, in priority order:
|
|
103
|
+
* 1. caller-provided override (e.g. --pk-map)
|
|
104
|
+
* 2. schema-declared single PK from datasource metadata
|
|
105
|
+
* 3. sample-based detection (CSV / schemaless sources)
|
|
106
|
+
* Composite SQL PKs intentionally surface as `source: "ambiguous"` — BKN
|
|
107
|
+
* object types take a single PK, so the caller must pick via --pk-map.
|
|
108
|
+
*/
|
|
109
|
+
export function resolvePrimaryKey(table, sampleRows, override) {
|
|
110
|
+
if (override) {
|
|
111
|
+
return { pk: override, source: "override" };
|
|
112
|
+
}
|
|
113
|
+
const schemaPks = collectSchemaPks(table);
|
|
114
|
+
if (schemaPks.length === 1) {
|
|
115
|
+
return { pk: schemaPks[0], source: "schema" };
|
|
116
|
+
}
|
|
117
|
+
if (schemaPks.length > 1) {
|
|
118
|
+
return { pk: null, source: "ambiguous", ambiguous: schemaPks };
|
|
119
|
+
}
|
|
120
|
+
const sample = detectPrimaryKey(table, sampleRows);
|
|
121
|
+
return {
|
|
122
|
+
pk: sample.pk,
|
|
123
|
+
source: "sample",
|
|
124
|
+
candidates: sample.candidates,
|
|
125
|
+
sampleSize: sample.sampleSize,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function collectSchemaPks(table) {
|
|
129
|
+
// Filter against the actual column list — schema metadata can drift (stale
|
|
130
|
+
// catalog, post-rename) and an unusable PK should fall through cleanly to
|
|
131
|
+
// sample/fail rather than poison downstream object-type creation.
|
|
132
|
+
const colNames = new Set(table.columns.map((c) => c.name));
|
|
133
|
+
if (Array.isArray(table.primaryKeys) && table.primaryKeys.length > 0) {
|
|
134
|
+
return table.primaryKeys.filter((n) => colNames.has(n));
|
|
135
|
+
}
|
|
136
|
+
return table.columns.filter((c) => c.isPrimaryKey === true).map((c) => c.name);
|
|
137
|
+
}
|
|
101
138
|
/** Format a user-facing error message when PK auto-detection fails. */
|
|
102
139
|
export function formatPkDetectionError(tableName, result) {
|
|
103
140
|
const lines = [`Cannot auto-detect primary key for table '${tableName}'.`];
|
|
@@ -146,6 +183,23 @@ export function detectDisplayKey(table, primaryKey) {
|
|
|
146
183
|
}
|
|
147
184
|
return primaryKey;
|
|
148
185
|
}
|
|
186
|
+
// ── Vega catalog id guard ────────────────────────────────────────────────────
|
|
187
|
+
const UUID_V4_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
188
|
+
/**
|
|
189
|
+
* Reject legacy data-connection datasource UUIDs.
|
|
190
|
+
*
|
|
191
|
+
* Since the SDK migration to vega-backend (#114), commands that call
|
|
192
|
+
* `listTablesWithColumns` / `scanMetadata` expect a vega catalog id (a short
|
|
193
|
+
* slug like `d7nicrcjto2s73d9g67g`), not the UUID-shaped id stored in
|
|
194
|
+
* data-connection.
|
|
195
|
+
*/
|
|
196
|
+
export function assertVegaCatalogId(id) {
|
|
197
|
+
if (UUID_V4_RE.test(id)) {
|
|
198
|
+
throw new Error(`expected a vega catalog id, got UUID '${id}'. ` +
|
|
199
|
+
`This looks like a legacy data-connection datasource UUID. ` +
|
|
200
|
+
`Run \`kweaver vega catalog list --keyword <name>\` to find the corresponding catalog id.`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
149
203
|
// ── Interactive confirmation ─────────────────────────────────────────────────
|
|
150
204
|
export function confirmYes(prompt) {
|
|
151
205
|
return new Promise((resolve) => {
|
package/dist/commands/bkn.js
CHANGED
|
@@ -7,6 +7,7 @@ import { resolveBusinessDomain } from "../config/store.js";
|
|
|
7
7
|
import { runKnObjectTypeCommand, runKnRelationTypeCommand, runKnActionTypeCommand, runKnConceptGroupCommand, } from "./bkn-schema.js";
|
|
8
8
|
import { runKnSubgraphCommand, runKnActionExecutionCommand, runKnActionLogCommand, runKnSearchCommand, runKnRelationTypePathsCommand, runKnResourcesCommand, } from "./bkn-query.js";
|
|
9
9
|
import { runKnBuildCommand, runKnValidateCommand, runKnPushCommand, runKnPullCommand, runKnCreateFromDsCommand, runKnCreateFromCsvCommand, runKnActionScheduleCommand, runKnJobCommand, } from "./bkn-ops.js";
|
|
10
|
+
import { runKnMetricCommand } from "./bkn-metric.js";
|
|
10
11
|
// Re-export shared utils for backward compatibility (tests import from bkn.js)
|
|
11
12
|
export { pollWithBackoff, parseOntologyQueryFlags, parseJsonObject, parseSearchAfterArray, confirmYes, DISPLAY_HINTS, detectPrimaryKey, detectDisplayKey, } from "./bkn-utils.js";
|
|
12
13
|
// Re-export schema types and parse functions for backward compatibility
|
|
@@ -404,6 +405,7 @@ Subcommands:
|
|
|
404
405
|
job list|get|tasks|delete <kn-id> ...
|
|
405
406
|
relation-type-paths <kn-id> '<json>' Query relation type paths between OTs
|
|
406
407
|
resources List available resources
|
|
408
|
+
metric list|get|create|search|validate|update|delete|query|dry-run <kn-id> ... BKN metrics (definitions + data)
|
|
407
409
|
|
|
408
410
|
Use 'kweaver bkn <subcommand> --help' for subcommand options.`;
|
|
409
411
|
export async function runKnCommand(args) {
|
|
@@ -463,6 +465,8 @@ export async function runKnCommand(args) {
|
|
|
463
465
|
return runKnRelationTypePathsCommand(rest);
|
|
464
466
|
if (subcommand === "resources")
|
|
465
467
|
return runKnResourcesCommand(rest);
|
|
468
|
+
if (subcommand === "metric")
|
|
469
|
+
return runKnMetricCommand(rest);
|
|
466
470
|
return Promise.resolve(-1);
|
|
467
471
|
};
|
|
468
472
|
try {
|
package/dist/commands/ds.js
CHANGED
|
@@ -3,9 +3,11 @@ import { statSync } from "node:fs";
|
|
|
3
3
|
import { glob } from "node:fs/promises";
|
|
4
4
|
import { resolve as resolvePath } from "node:path";
|
|
5
5
|
import { ensureValidToken, formatHttpError, with401RefreshRetry } from "../auth/oauth.js";
|
|
6
|
-
import { testDatasource, createDatasource, listDatasources, getDatasource, deleteDatasource,
|
|
6
|
+
import { testDatasource, createDatasource, listDatasources, getDatasource, deleteDatasource, } from "../api/datasources.js";
|
|
7
|
+
import { listTablesWithColumns, scanMetadata } from "../api/vega.js";
|
|
7
8
|
import { formatCallOutput } from "./call.js";
|
|
8
9
|
import { resolveBusinessDomain } from "../config/store.js";
|
|
10
|
+
import { assertVegaCatalogId } from "./bkn-utils.js";
|
|
9
11
|
import { parseCsvFile, buildTableName, splitBatches, buildFieldMappings, buildDagBody, } from "./import-csv.js";
|
|
10
12
|
import { executeDataflow } from "../api/dataflow.js";
|
|
11
13
|
function confirmYes(prompt) {
|
|
@@ -196,9 +198,12 @@ async function runDsTablesCommand(args) {
|
|
|
196
198
|
id = arg;
|
|
197
199
|
}
|
|
198
200
|
if (!id) {
|
|
199
|
-
console.error("Usage: kweaver ds tables <id> [--keyword X]"
|
|
201
|
+
console.error("Usage: kweaver ds tables <vega-catalog-id> [--keyword X]\n" +
|
|
202
|
+
" <vega-catalog-id> is a vega catalog id (use `kweaver vega catalog list` to find one;\n" +
|
|
203
|
+
" legacy data-connection datasource UUIDs are no longer accepted).");
|
|
200
204
|
return 1;
|
|
201
205
|
}
|
|
206
|
+
assertVegaCatalogId(id);
|
|
202
207
|
const token = await ensureValidToken();
|
|
203
208
|
const body = await listTablesWithColumns({
|
|
204
209
|
baseUrl: token.baseUrl,
|
|
@@ -389,7 +394,13 @@ async function printDsConnectOutput(base, dsId) {
|
|
|
389
394
|
datasource_id: dsId,
|
|
390
395
|
tables: tables.map((t) => ({
|
|
391
396
|
name: t.name,
|
|
392
|
-
|
|
397
|
+
...(t.primaryKeys && t.primaryKeys.length > 0 ? { primary_keys: t.primaryKeys } : {}),
|
|
398
|
+
columns: t.columns.map((c) => ({
|
|
399
|
+
name: c.name,
|
|
400
|
+
type: c.type,
|
|
401
|
+
comment: c.comment,
|
|
402
|
+
...(c.isPrimaryKey ? { is_primary_key: true } : {}),
|
|
403
|
+
})),
|
|
393
404
|
})),
|
|
394
405
|
};
|
|
395
406
|
console.log(JSON.stringify(output, null, 2));
|
|
@@ -175,7 +175,7 @@ export function registerChatRoutes(getToken, businessDomain) {
|
|
|
175
175
|
return;
|
|
176
176
|
}
|
|
177
177
|
const t = await getToken();
|
|
178
|
-
const
|
|
178
|
+
const result = await getTracesByConversation({
|
|
179
179
|
baseUrl: t.baseUrl,
|
|
180
180
|
accessToken: t.accessToken,
|
|
181
181
|
agentId,
|
|
@@ -183,7 +183,7 @@ export function registerChatRoutes(getToken, businessDomain) {
|
|
|
183
183
|
businessDomain,
|
|
184
184
|
});
|
|
185
185
|
res.writeHead(200, { "Content-Type": "application/json; charset=utf-8" });
|
|
186
|
-
res.end(
|
|
186
|
+
res.end(JSON.stringify(result));
|
|
187
187
|
}
|
|
188
188
|
catch (error) {
|
|
189
189
|
handleApiError(res, error);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export interface ModelGlobalParse {
|
|
2
|
+
rest: string[];
|
|
3
|
+
businessDomain: string;
|
|
4
|
+
mfManagerBaseUrl?: string;
|
|
5
|
+
mfApiBaseUrl?: string;
|
|
6
|
+
pretty: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Strip global flags; fill default business domain. */
|
|
9
|
+
export declare function parseModelGlobalFlags(args: string[]): ModelGlobalParse;
|
|
10
|
+
/** Sparse flags for model llm edit (after leading model_id). Exported for unit tests. */
|
|
11
|
+
export interface ParsedLlmSparseEditFlags {
|
|
12
|
+
name?: string;
|
|
13
|
+
modelSeries?: string;
|
|
14
|
+
modelType?: string;
|
|
15
|
+
maxModelLen?: number;
|
|
16
|
+
quota?: boolean;
|
|
17
|
+
modelConfigFile?: string;
|
|
18
|
+
upstreamUrl?: string;
|
|
19
|
+
apiModel?: string;
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
apiKeyFile?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Exported for unit tests. */
|
|
24
|
+
export declare function parsedLlmSparseEditHasUpdates(p: ParsedLlmSparseEditFlags): boolean;
|
|
25
|
+
/** Exported for unit tests. */
|
|
26
|
+
export declare function parseLlmSparseEditFlags(tail: string[]): ParsedLlmSparseEditFlags;
|
|
27
|
+
/**
|
|
28
|
+
* Normalize GET /llm/get JSON into a body suitable for POST /llm/edit.
|
|
29
|
+
* Exported for unit tests.
|
|
30
|
+
*/
|
|
31
|
+
export declare function llmModelGetToEditBase(raw: unknown): Record<string, unknown>;
|
|
32
|
+
/** Apply sparse llm edit flags onto a normalized record from GET. Exported for unit tests. */
|
|
33
|
+
export declare function mergeLlmEditOntoExistingBase(base: Record<string, unknown>, p: ParsedLlmSparseEditFlags): Promise<Record<string, unknown>>;
|
|
34
|
+
/**
|
|
35
|
+
* Returns registry **model_name** from ``GET /llm/get`` JSON when present. Exported for unit tests.
|
|
36
|
+
*/
|
|
37
|
+
export declare function llmGetRecordModelName(raw: unknown): string;
|
|
38
|
+
/** Registry **model_name** from ``GET /small-model/get``. Exported for unit tests. */
|
|
39
|
+
export declare function smallGetRecordModelName(raw: unknown): string;
|
|
40
|
+
export interface ParsedSmallAddFlags {
|
|
41
|
+
name?: string;
|
|
42
|
+
modelType?: "embedding" | "reranker";
|
|
43
|
+
batchSize?: number;
|
|
44
|
+
maxTokens?: number;
|
|
45
|
+
embeddingDim?: number;
|
|
46
|
+
modelConfigFile?: string;
|
|
47
|
+
adapter?: boolean;
|
|
48
|
+
adapterCodeFile?: string;
|
|
49
|
+
bodyFile?: string;
|
|
50
|
+
/** Outbound HTTP API base or full path (stored in model_config.api_url). */
|
|
51
|
+
upstreamUrl?: string;
|
|
52
|
+
/** Third-party model id / deployment name (model_config.api_model). */
|
|
53
|
+
apiModel?: string;
|
|
54
|
+
/** Inline API secret — prefer --api-key-file (shell history risk). */
|
|
55
|
+
apiKey?: string;
|
|
56
|
+
apiKeyFile?: string;
|
|
57
|
+
}
|
|
58
|
+
/** True when sparse CLI flags should perform an edit (excluding --body-file). Exported for unit tests. */
|
|
59
|
+
export declare function parsedSmallFlagsHasEditUpdates(p: ParsedSmallAddFlags): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Normalize GET /small-model/get JSON into a body suitable for POST /small-model/edit.
|
|
62
|
+
* Exported for unit tests.
|
|
63
|
+
*/
|
|
64
|
+
export declare function smallModelGetToEditBase(raw: unknown): Record<string, unknown>;
|
|
65
|
+
/**
|
|
66
|
+
* Apply sparse edit flags onto a normalized small-model record (from GET). Exported for unit tests.
|
|
67
|
+
*/
|
|
68
|
+
export declare function mergeSmallEditOntoExistingBase(base: Record<string, unknown>, p: ParsedSmallAddFlags): Promise<Record<string, unknown>>;
|
|
69
|
+
/** Parse small-model add/edit flags from argv tail (after action). Exported for unit tests. */
|
|
70
|
+
export declare function parseSmallAddFlags(tail: string[]): ParsedSmallAddFlags;
|
|
71
|
+
export declare function buildSmallBodyFromFlags(p: ParsedSmallAddFlags, modelId?: string): Promise<Record<string, unknown>>;
|
|
72
|
+
export declare function runModelCommand(args: string[]): Promise<number>;
|