@kweaver-ai/kweaver-sdk 0.7.2 → 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 (69) hide show
  1. package/README.md +35 -1
  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.d.ts +7 -0
  11. package/dist/api/datasources.js +51 -6
  12. package/dist/api/model-invocation.d.ts +58 -0
  13. package/dist/api/model-invocation.js +203 -0
  14. package/dist/api/models.d.ts +79 -0
  15. package/dist/api/models.js +183 -0
  16. package/dist/api/ontology-query-metrics.d.ts +14 -0
  17. package/dist/api/ontology-query-metrics.js +30 -0
  18. package/dist/api/toolboxes.d.ts +2 -0
  19. package/dist/api/toolboxes.js +2 -1
  20. package/dist/bundled-model-templates.d.ts +17 -0
  21. package/dist/bundled-model-templates.js +24 -0
  22. package/dist/cli.js +28 -2
  23. package/dist/client.d.ts +3 -0
  24. package/dist/client.js +5 -0
  25. package/dist/commands/agent.d.ts +7 -1
  26. package/dist/commands/agent.js +75 -21
  27. package/dist/commands/auth.js +42 -7
  28. package/dist/commands/bkn-metric.d.ts +1 -0
  29. package/dist/commands/bkn-metric.js +406 -0
  30. package/dist/commands/bkn-ops.d.ts +2 -1
  31. package/dist/commands/bkn-ops.js +75 -34
  32. package/dist/commands/bkn-utils.d.ts +55 -2
  33. package/dist/commands/bkn-utils.js +103 -9
  34. package/dist/commands/bkn.js +4 -0
  35. package/dist/commands/dataflow.js +194 -20
  36. package/dist/commands/ds.d.ts +0 -1
  37. package/dist/commands/ds.js +26 -10
  38. package/dist/commands/explore-chat.js +2 -2
  39. package/dist/commands/import-csv.d.ts +0 -2
  40. package/dist/commands/import-csv.js +2 -4
  41. package/dist/commands/model.d.ts +72 -0
  42. package/dist/commands/model.js +1315 -0
  43. package/dist/commands/tool.d.ts +1 -0
  44. package/dist/commands/tool.js +12 -0
  45. package/dist/config/store.d.ts +1 -0
  46. package/dist/config/store.js +17 -0
  47. package/dist/index.d.ts +9 -0
  48. package/dist/index.js +5 -0
  49. package/dist/resources/models.d.ts +40 -0
  50. package/dist/resources/models.js +88 -0
  51. package/dist/resources/toolboxes.d.ts +2 -0
  52. package/dist/templates/bkn/document/manifest.json +12 -0
  53. package/dist/templates/bkn/document/template.json +757 -0
  54. package/dist/templates/dataflow/unstructured/manifest.json +11 -0
  55. package/dist/templates/dataflow/unstructured/template.json +63 -0
  56. package/dist/templates/dataset/document/manifest.json +10 -0
  57. package/dist/templates/dataset/document/template.json +23 -0
  58. package/dist/templates/dataset/document-content/manifest.json +10 -0
  59. package/dist/templates/dataset/document-content/template.json +29 -0
  60. package/dist/templates/dataset/document-element/manifest.json +10 -0
  61. package/dist/templates/dataset/document-element/template.json +21 -0
  62. package/dist/templates/model/llm-basic.json +13 -0
  63. package/dist/templates/model/manifest.json +16 -0
  64. package/dist/templates/model/small-basic.json +6 -0
  65. package/dist/utils/template-loader.d.ts +40 -0
  66. package/dist/utils/template-loader.js +129 -0
  67. package/dist/utils/trace-views.d.ts +44 -0
  68. package/dist/utils/trace-views.js +425 -0
  69. package/package.json +3 -3
package/dist/cli.js CHANGED
@@ -10,6 +10,7 @@ import { runDataflowCommand } from "./commands/dataflow.js";
10
10
  import { runDsCommand } from "./commands/ds.js";
11
11
  import { runExploreCommand } from "./commands/explore.js";
12
12
  import { runDataviewCommand } from "./commands/dataview.js";
13
+ import { runModelCommand } from "./commands/model.js";
13
14
  import { runSkillCommand } from "./commands/skill.js";
14
15
  import { runTokenCommand } from "./commands/token.js";
15
16
  import { runToolboxCommand } from "./commands/toolbox.js";
@@ -62,11 +63,19 @@ Usage:
62
63
  kweaver ds connect <db_type> <host> <port> <database> --account X --password Y [--schema S] [--name N]
63
64
  [--reuse-existing|--force-new]
64
65
 
66
+ kweaver dataflow templates [--json]
67
+ kweaver dataflow create-dataset --template <name> --set "key=value" [--json] [-bd value]
68
+ kweaver dataflow create-bkn --template <name> --set "key=value" [--json] [-bd value]
69
+ kweaver dataflow create (--template <name> --set "key=value" | <json>) [-bd value]
65
70
  kweaver dataflow list [-bd value]
66
71
  kweaver dataflow run <dagId> (--file <path> | --url <remote-url> --name <filename>) [-bd value]
67
72
  kweaver dataflow runs <dagId> [--since <date-like>] [-bd value]
68
73
  kweaver dataflow logs <dagId> <instanceId> [--detail] [-bd value]
69
74
 
75
+ kweaver model llm list|get|add|edit|delete|test|chat|--template ... (mf-model-manager + mf-model-api)
76
+ kweaver model small list|get|add|edit|delete|test|embeddings|rerank|--template ...
77
+ kweaver model --help
78
+
70
79
  kweaver dataview list [--datasource-id id] [--type atomic|custom] [--limit n] [-bd value]
71
80
  kweaver dataview find --name <name> [--exact] [--datasource-id id] [--wait] [--timeout ms] [-bd value]
72
81
  kweaver dataview get <id> [-bd value]
@@ -87,6 +96,7 @@ Usage:
87
96
  kweaver bkn push <directory> [--branch main] [-bd value] [--detect-encoding|--no-detect-encoding] [--source-encoding name]
88
97
  kweaver bkn pull <kn-id> [directory] [--branch main] [-bd value]
89
98
  kweaver bkn object-type list|get|create|update|delete|query|properties <kn-id> ...
99
+ kweaver bkn metric list|get|create|search|validate|update|delete|query|dry-run <kn-id> ...
90
100
  kweaver bkn relation-type list|get|create|update|delete <kn-id> ...
91
101
  kweaver bkn subgraph <kn-id> <body-json>
92
102
  kweaver bkn action-type list|query|inputs|execute <kn-id> ... [--wait] [--no-wait] [--timeout N]
@@ -116,7 +126,7 @@ Usage:
116
126
  kweaver tool enable|disable --toolbox <box-id> <tool-id>... [-bd value]
117
127
  kweaver tool execute|debug --toolbox <box-id> <tool-id>
118
128
  [--body '<json>'|--body-file <path>]
119
- [--header '<json>'] [--query '<json>'] [--timeout <s>]
129
+ [--header '<json>'] [--query '<json>'] [--path '<json>'] [--timeout <s>]
120
130
 
121
131
  kweaver vega health|stats|inspect
122
132
  kweaver vega catalog list|get|health|test-connection|discover|resources [options]
@@ -139,7 +149,19 @@ Usage:
139
149
  Global options:
140
150
  --base-url <url> Override platform base URL for this command (env: KWEAVER_BASE_URL)
141
151
  --token <value> Override access token for this command (env: KWEAVER_TOKEN; disables write-to-disk commands)
142
- --user <id|name> Use a specific user's credentials for this command (env: KWEAVER_USER)
152
+ --user <id|name> Use a specific user's credentials for this command, transient (env: KWEAVER_USER)
153
+
154
+ Multi-shell account isolation:
155
+ KWEAVER_PROFILE=<name> Scope state.json (active platform / active user) to a named
156
+ profile. Tokens under platforms/ are still shared, so each
157
+ profile reuses logins. Required for \`auth switch\` and
158
+ \`auth use\` (use --global to override). Name must match
159
+ [A-Za-z0-9_-]{1,64}.
160
+ KWEAVERC_CONFIG_DIR=<dir> Override the entire config root (~/.kweaver by default).
161
+ Use this for hard isolation (separate token store per shell).
162
+
163
+ For agents / multi-terminal scripts: prefer \`--user <id>\` (transient, no persistence)
164
+ over \`auth switch\` (persistent, requires KWEAVER_PROFILE).
143
165
  --pretty / --compact
144
166
  Toggle pretty-printed JSON output. Supported by every
145
167
  command that prints a JSON payload (default: pretty).
@@ -151,6 +173,7 @@ Commands:
151
173
  agent Agent CRUD, chat, sessions, history, publish/unpublish
152
174
  ds Manage datasources (list, get, delete, tables, connect)
153
175
  dataflow Dataflow document workflows (list, run, runs, logs)
176
+ model Model factory: LLM/small-model CRUD (manager) and llm chat (OpenAI-compatible API)
154
177
  dataview|dv List, find, get, query (SQL), delete data views (atomic / custom)
155
178
  bkn Knowledge network (CRUD, build, validate, export, stats, push/pull,
156
179
  object-type, relation-type, subgraph, action-type, action-execution, action-log)
@@ -228,6 +251,9 @@ export async function run(argv) {
228
251
  if (command === "dataflow") {
229
252
  return runDataflowCommand(rest);
230
253
  }
254
+ if (command === "model") {
255
+ return runModelCommand(rest);
256
+ }
231
257
  if (command === "dataview" || command === "dv") {
232
258
  return runDataviewCommand(rest);
233
259
  }
package/dist/client.d.ts CHANGED
@@ -9,6 +9,7 @@ import { BknResource } from "./resources/bkn.js";
9
9
  import { SkillsResource } from "./resources/skills.js";
10
10
  import { ToolboxesResource } from "./resources/toolboxes.js";
11
11
  import { VegaResource } from "./resources/vega.js";
12
+ import { ModelsResource } from "./resources/models.js";
12
13
  /**
13
14
  * Shared credentials passed to every resource method.
14
15
  * Internal — use KWeaverClient.
@@ -105,6 +106,8 @@ export declare class KWeaverClient implements ClientContext {
105
106
  readonly skills: SkillsResource;
106
107
  /** Toolbox / tool management plus execute & debug invocation. */
107
108
  readonly toolboxes: ToolboxesResource;
109
+ /** Model factory (mf-model-manager CRUD + mf-model-api chat / embedding / rerank). */
110
+ readonly models: ModelsResource;
108
111
  constructor(opts?: KWeaverClientOptions);
109
112
  /**
110
113
  * Async factory that auto-refreshes expired or revoked tokens.
package/dist/client.js CHANGED
@@ -14,6 +14,7 @@ import { BknResource } from "./resources/bkn.js";
14
14
  import { SkillsResource } from "./resources/skills.js";
15
15
  import { ToolboxesResource } from "./resources/toolboxes.js";
16
16
  import { VegaResource } from "./resources/vega.js";
17
+ import { ModelsResource } from "./resources/models.js";
17
18
  // ── KWeaverClient ─────────────────────────────────────────────────────────────
18
19
  /**
19
20
  * Main entry point for the KWeaver TypeScript SDK.
@@ -67,6 +68,8 @@ export class KWeaverClient {
67
68
  skills;
68
69
  /** Toolbox / tool management plus execute & debug invocation. */
69
70
  toolboxes;
71
+ /** Model factory (mf-model-manager CRUD + mf-model-api chat / embedding / rerank). */
72
+ models;
70
73
  constructor(opts = {}) {
71
74
  const envDomain = process.env.KWEAVER_BUSINESS_DOMAIN;
72
75
  if (opts.auth === false && opts.config) {
@@ -101,6 +104,7 @@ export class KWeaverClient {
101
104
  this.vega = new VegaResource(this);
102
105
  this.skills = new SkillsResource(this);
103
106
  this.toolboxes = new ToolboxesResource(this);
107
+ this.models = new ModelsResource(this);
104
108
  return;
105
109
  }
106
110
  if (opts.config) {
@@ -156,6 +160,7 @@ export class KWeaverClient {
156
160
  this.vega = new VegaResource(this);
157
161
  this.skills = new SkillsResource(this);
158
162
  this.toolboxes = new ToolboxesResource(this);
163
+ this.models = new ModelsResource(this);
159
164
  }
160
165
  /**
161
166
  * Async factory that auto-refreshes expired or revoked tokens.
@@ -65,8 +65,14 @@ export interface AgentHistoryOptions {
65
65
  }
66
66
  export declare function parseAgentHistoryArgs(args: string[]): AgentHistoryOptions;
67
67
  export interface AgentTraceOptions {
68
- agentId: string;
68
+ /** Optional. Retained as positional arg for backward compatibility; trace-ai keys by conversation_id only. */
69
+ agentId?: string;
69
70
  conversationId: string;
71
+ view: "tree" | "perf" | "evidence" | "reasoning" | "all";
72
+ /** When true, emit raw JSON of the TracesByConversationResult instead of a rendered view. */
73
+ json: boolean;
74
+ /** Disable per-message truncation in the reasoning view. */
75
+ full: boolean;
70
76
  pretty: boolean;
71
77
  }
72
78
  export declare function parseAgentTraceArgs(args: string[]): AgentTraceOptions;
@@ -468,21 +468,43 @@ export function parseAgentHistoryArgs(args) {
468
468
  const finalConversationId = optionStartIndex === 2 ? args[1] : args[0];
469
469
  return { agentId: finalAgentId, conversationId: finalConversationId, businessDomain, pretty, limit };
470
470
  }
471
+ const TRACE_VIEWS = new Set(["tree", "perf", "evidence", "reasoning", "all"]);
471
472
  export function parseAgentTraceArgs(args) {
472
- const agentId = args[0];
473
- if (!agentId || agentId.startsWith("-")) {
474
- throw new Error("Missing agent_id");
475
- }
476
- const conversationId = args[1];
477
- if (!conversationId || conversationId.startsWith("-")) {
478
- throw new Error("Missing conversation_id");
479
- }
473
+ const positional = [];
474
+ let view = "tree";
475
+ let json = false;
476
+ let full = false;
480
477
  let pretty = true;
481
- for (let i = 2; i < args.length; i += 1) {
478
+ for (let i = 0; i < args.length; i += 1) {
482
479
  const arg = args[i];
483
480
  if (arg === "--help" || arg === "-h") {
484
481
  throw new Error("help");
485
482
  }
483
+ if (arg === "--view") {
484
+ const next = args[i + 1];
485
+ if (!next || !TRACE_VIEWS.has(next)) {
486
+ throw new Error(`--view requires one of: tree, perf, evidence, reasoning, all`);
487
+ }
488
+ view = next;
489
+ i += 1;
490
+ continue;
491
+ }
492
+ if (arg.startsWith("--view=")) {
493
+ const value = arg.slice("--view=".length);
494
+ if (!TRACE_VIEWS.has(value)) {
495
+ throw new Error(`--view requires one of: tree, perf, evidence, reasoning, all`);
496
+ }
497
+ view = value;
498
+ continue;
499
+ }
500
+ if (arg === "--json") {
501
+ json = true;
502
+ continue;
503
+ }
504
+ if (arg === "--full") {
505
+ full = true;
506
+ continue;
507
+ }
486
508
  if (arg === "--pretty") {
487
509
  pretty = true;
488
510
  continue;
@@ -491,9 +513,26 @@ export function parseAgentTraceArgs(args) {
491
513
  pretty = false;
492
514
  continue;
493
515
  }
494
- throw new Error(`Unsupported agent trace argument: ${arg}`);
516
+ if (arg.startsWith("-")) {
517
+ throw new Error(`Unsupported agent trace argument: ${arg}`);
518
+ }
519
+ positional.push(arg);
520
+ }
521
+ // Backward-compat: legacy form is `trace <agent_id> <conversation_id>`.
522
+ // New form: `trace <conversation_id>`. We disambiguate by argument count.
523
+ let agentId;
524
+ let conversationId;
525
+ if (positional.length === 0) {
526
+ throw new Error("Missing conversation_id");
527
+ }
528
+ else if (positional.length === 1) {
529
+ conversationId = positional[0];
495
530
  }
496
- return { agentId, conversationId, pretty };
531
+ else {
532
+ agentId = positional[0];
533
+ conversationId = positional[1];
534
+ }
535
+ return { agentId, conversationId, view, json, full, pretty };
497
536
  }
498
537
  export async function runAgentCommand(args) {
499
538
  const [subcommand, ...rest] = args;
@@ -520,7 +559,8 @@ Subcommands:
520
559
  skill <verb> ... Manage skills attached to an agent (add/remove/list)
521
560
  sessions <agent_id> List all conversations for an agent
522
561
  history <agent_id> <conversation_id> Show message history for a conversation
523
- trace <agent_id> <conversation_id> Get trace data for a conversation`);
562
+ trace <conversation_id> [--view tree|perf|evidence|reasoning|all] [--json]
563
+ Get trace data for a conversation`);
524
564
  return Promise.resolve(0);
525
565
  }
526
566
  const dispatch = async () => {
@@ -724,13 +764,16 @@ Options:
724
764
  }
725
765
  if (subcommand === "trace") {
726
766
  if (rest.length === 1 && (rest[0] === "--help" || rest[0] === "-h")) {
727
- console.log(`kweaver agent trace <agent_id> <conversation_id> [options]
767
+ console.log(`kweaver agent trace <conversation_id> [options]
768
+ kweaver agent trace <agent_id> <conversation_id> [options] (legacy)
728
769
 
729
770
  Get trace data for a conversation.
730
771
 
731
772
  Options:
732
- --pretty Pretty-print JSON output (default)
733
- --compact Compact JSON output`);
773
+ --view tree|perf|evidence|reasoning|all Render style (default: tree)
774
+ --json Emit raw TracesByConversationResult JSON
775
+ --pretty Pretty-print JSON output (default)
776
+ --compact Compact JSON output`);
734
777
  return 0;
735
778
  }
736
779
  }
@@ -1031,13 +1074,18 @@ async function runAgentTraceCommand(args) {
1031
1074
  }
1032
1075
  catch (error) {
1033
1076
  if (error instanceof Error && error.message === "help") {
1034
- console.log(`kweaver agent trace <agent_id> <conversation_id> [options]
1077
+ console.log(`kweaver agent trace <conversation_id> [options]
1078
+ kweaver agent trace <agent_id> <conversation_id> [options] (legacy)
1035
1079
 
1036
- Get trace data for a conversation.
1080
+ Get trace data for a conversation. Spans are fetched from trace-ai via a 2-jump
1081
+ lookup that recovers pipeline spans (HTTP entry, internal RPCs, prompt-build)
1082
+ which the simpler /by-conversation endpoint omits.
1037
1083
 
1038
1084
  Options:
1039
- --pretty Pretty-print JSON output (default)
1040
- --compact Compact JSON output`);
1085
+ --view tree|perf|evidence|reasoning|all Render style (default: tree)
1086
+ --json Emit raw TracesByConversationResult JSON
1087
+ --pretty Pretty-print JSON output (default)
1088
+ --compact Compact JSON output`);
1041
1089
  return 0;
1042
1090
  }
1043
1091
  console.error(formatHttpError(error));
@@ -1045,13 +1093,19 @@ Options:
1045
1093
  }
1046
1094
  try {
1047
1095
  const token = await ensureValidToken();
1048
- const body = await getTracesByConversation({
1096
+ const result = await getTracesByConversation({
1049
1097
  baseUrl: token.baseUrl,
1050
1098
  accessToken: token.accessToken,
1051
1099
  agentId: options.agentId,
1052
1100
  conversationId: options.conversationId,
1053
1101
  });
1054
- console.log(formatCallOutput(body, options.pretty));
1102
+ if (options.json) {
1103
+ console.log(formatCallOutput(JSON.stringify(result), options.pretty));
1104
+ }
1105
+ else {
1106
+ const { formatTraceResult } = await import("../utils/trace-views.js");
1107
+ console.log(formatTraceResult(result, options.view, { full: options.full }));
1108
+ }
1055
1109
  return 0;
1056
1110
  }
1057
1111
  catch (error) {
@@ -1,9 +1,31 @@
1
1
  import { isNoAuth } from "../config/no-auth.js";
2
2
  import { assertNotStatelessForWrite } from "../config/stateless.js";
3
- import { autoSelectBusinessDomain, clearPlatformSession, deletePlatform, deleteUser, getActiveUser, getConfigDir, getCurrentPlatform, getPlatformAlias, hasPlatform, listPlatforms, listUserProfiles, loadClientConfig, loadTokenConfig, loadUserTokenConfig, resolveBusinessDomain, resolvePlatformIdentifier, resolveUserId, saveNoAuthPlatform, setActiveUser, setCurrentPlatform, setPlatformAlias, } from "../config/store.js";
3
+ import { autoSelectBusinessDomain, clearPlatformSession, deletePlatform, deleteUser, getActiveUser, getConfigDir, getCurrentPlatform, getPlatformAlias, getProfileName, hasPlatform, listPlatforms, listUserProfiles, loadClientConfig, loadTokenConfig, loadUserTokenConfig, resolveBusinessDomain, resolvePlatformIdentifier, resolveUserId, saveNoAuthPlatform, setActiveUser, setCurrentPlatform, setPlatformAlias, } from "../config/store.js";
4
4
  import { decodeJwtPayload } from "../config/jwt.js";
5
5
  import { eacpModifyPassword } from "../auth/eacp-modify-password.js";
6
6
  import { buildCopyCommand, fetchEacpUserInfo, formatHttpError, InitialPasswordChangeRequiredError, normalizeBaseUrl, oauth2Login, oauth2PasswordSigninLogin, promptForUsername, promptForPassword, refreshTokenLogin, resolveActivePlatform, } from "../auth/oauth.js";
7
+ function consumeGlobalFlag(args) {
8
+ const idx = args.indexOf("--global");
9
+ if (idx === -1)
10
+ return { args, isGlobal: false };
11
+ return { args: [...args.slice(0, idx), ...args.slice(idx + 1)], isGlobal: true };
12
+ }
13
+ function requireProfileOrGlobal(command, isGlobal) {
14
+ if (isGlobal)
15
+ return null;
16
+ try {
17
+ if (getProfileName())
18
+ return null;
19
+ }
20
+ catch (err) {
21
+ return err instanceof Error ? err.message : String(err);
22
+ }
23
+ return (`kweaver auth ${command} mutates the active account globally and would affect every shell using ~/.kweaver.\n` +
24
+ `Pick one:\n` +
25
+ ` - Transient: prepend \`--user <id|name>\` (or \`KWEAVER_USER=<id>\`) to the command you actually want to run; no persistent switch.\n` +
26
+ ` - Persistent (this shell only): \`export KWEAVER_PROFILE=<name>\`, then re-run.\n` +
27
+ ` - Intentionally global (CI / single-user setup): re-run with \`--global\`.`);
28
+ }
7
29
  export async function runAuthCommand(args) {
8
30
  const target = args[0];
9
31
  const rest = args.slice(1);
@@ -357,10 +379,16 @@ Login options:
357
379
  return 0;
358
380
  }
359
381
  if (target === "use") {
360
- const resolvedTarget = args[1] ? resolvePlatformIdentifier(args[1]) : "";
382
+ const { args: useArgs, isGlobal } = consumeGlobalFlag(args);
383
+ const refusal = requireProfileOrGlobal("use", isGlobal);
384
+ if (refusal !== null) {
385
+ console.error(refusal);
386
+ return 1;
387
+ }
388
+ const resolvedTarget = useArgs[1] ? resolvePlatformIdentifier(useArgs[1]) : "";
361
389
  const useTarget = resolvedTarget && /^https?:\/\//.test(resolvedTarget) ? normalizeBaseUrl(resolvedTarget) : resolvedTarget;
362
390
  if (!useTarget) {
363
- console.error("Usage: kweaver auth use <platform-url|alias>");
391
+ console.error("Usage: kweaver auth use [--global] <platform-url|alias>");
364
392
  return 1;
365
393
  }
366
394
  if (!hasPlatform(useTarget)) {
@@ -490,18 +518,25 @@ You can use either userId or username with --user in switch/logout/delete.`);
490
518
  }
491
519
  function runAuthSwitchCommand(args) {
492
520
  if (args[0] === "--help" || args[0] === "-h") {
493
- console.log(`kweaver auth switch [platform-url|alias] --user <userId|username>
521
+ console.log(`kweaver auth switch [--global] [platform-url|alias] --user <userId|username>
494
522
 
495
523
  Switch the active user for a platform.
496
524
  You can specify either the userId (sub claim) or the username (preferred_username from id_token).`);
497
525
  return 0;
498
526
  }
499
- const userArg = readOption(args, "--user");
527
+ const { args: switchArgs, isGlobal } = consumeGlobalFlag(args);
528
+ const refusal = requireProfileOrGlobal("switch", isGlobal);
529
+ if (refusal !== null) {
530
+ console.error(refusal);
531
+ return 1;
532
+ }
533
+ const cleanedArgs = switchArgs;
534
+ const userArg = readOption(cleanedArgs, "--user") ?? process.env.KWEAVER_USER;
500
535
  if (!userArg) {
501
- console.error("Usage: kweaver auth switch [platform-url|alias] --user <userId|username>");
536
+ console.error("Usage: kweaver auth switch [--global] [platform-url|alias] --user <userId|username>");
502
537
  return 1;
503
538
  }
504
- const filteredArgs = args.filter((a) => a !== "--user" && a !== userArg);
539
+ const filteredArgs = cleanedArgs.filter((a) => a !== "--user" && a !== userArg);
505
540
  const platform = resolvePlatformArg(filteredArgs);
506
541
  if (!platform) {
507
542
  console.error("No active platform. Run `kweaver auth login <platform-url>` first.");
@@ -0,0 +1 @@
1
+ export declare function runKnMetricCommand(args: string[]): Promise<number>;