march-cli 0.1.13 → 0.1.15

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.
@@ -52,7 +52,7 @@ function normalizeModels(providerId, models, { api, baseUrl }) {
52
52
  api: normalizeApi(providerId, model.api ?? api),
53
53
  baseUrl: typeof model.baseUrl === "string" && model.baseUrl.trim() ? model.baseUrl : baseUrl,
54
54
  reasoning: typeof model.reasoning === "boolean" ? model.reasoning : false,
55
- input: normalizeInput(model.input),
55
+ input: normalizeInput(model.input, model.capabilities),
56
56
  cost: normalizeCost(model.cost),
57
57
  contextWindow: normalizePositiveNumber(model.contextWindow, 128000),
58
58
  maxTokens: normalizePositiveNumber(model.maxTokens, 4096),
@@ -75,9 +75,10 @@ function requireString(providerId, field, value) {
75
75
  return value;
76
76
  }
77
77
 
78
- function normalizeInput(input) {
79
- if (!Array.isArray(input) || input.length === 0) return ["text"];
80
- const normalized = input.filter((item) => item === "text" || item === "image");
78
+ function normalizeInput(input, capabilities = null) {
79
+ const normalized = Array.isArray(input) ? input.filter((item) => item === "text" || item === "image") : [];
80
+ if ((capabilities?.images === true || capabilities?.vision === true) && !normalized.includes("image")) normalized.push("image");
81
+ if (!normalized.includes("text")) normalized.unshift("text");
81
82
  return normalized.length > 0 ? normalized : ["text"];
82
83
  }
83
84
 
@@ -0,0 +1,79 @@
1
+ import { globalConfigJsonPath, readConfigJson } from "../config/config-json.mjs";
2
+ import { selectWithKeyboard } from "../cli/input/select-with-keyboard.mjs";
3
+ import { cloneProviderForShare, createProviderShareToken, hasApiKey } from "./share-payload.mjs";
4
+
5
+ export async function runProviderShareCommand({
6
+ homeDir,
7
+ providerId,
8
+ includeKey = false,
9
+ profileOnly = false,
10
+ input = process.stdin,
11
+ output = process.stdout,
12
+ select = selectWithKeyboard,
13
+ } = {}) {
14
+ if (includeKey && profileOnly) {
15
+ output.write("Choose either --include-key or --profile-only, not both.\n");
16
+ return 1;
17
+ }
18
+
19
+ const config = readConfigJson(globalConfigJsonPath(homeDir));
20
+ const providers = normalizeProviders(config.providers);
21
+ const selectedProviderId = providerId ?? await selectProvider({ providers, input, output, select });
22
+ if (!selectedProviderId) {
23
+ output.write(Object.keys(providers).length ? "Provider share cancelled.\n" : "No providers configured. Run: march provider --config\n");
24
+ return 1;
25
+ }
26
+
27
+ const provider = providers[selectedProviderId];
28
+ if (!provider) {
29
+ output.write(`Provider not found: ${selectedProviderId}\n`);
30
+ return 1;
31
+ }
32
+
33
+ const includeApiKey = includeKey || (!profileOnly && await selectShareMode({ input, output, select }));
34
+ const sharedProvider = cloneProviderForShare(provider, { includeApiKey });
35
+ const token = createProviderShareToken({
36
+ providerId: selectedProviderId,
37
+ provider: sharedProvider,
38
+ mode: includeApiKey ? "full" : "profile-only",
39
+ });
40
+
41
+ output.write(`Provider: ${selectedProviderId}\n`);
42
+ output.write(`Mode: ${includeApiKey ? "Full config, including API key" : "Profile only, without API key"}\n`);
43
+ output.write(`API key: ${hasApiKey(sharedProvider) ? "included" : "not included"}\n\n`);
44
+ output.write(`march provider accept ${token}\n`);
45
+ return 0;
46
+ }
47
+
48
+ function normalizeProviders(providers) {
49
+ return providers && typeof providers === "object" && !Array.isArray(providers) ? providers : {};
50
+ }
51
+
52
+ async function selectProvider({ providers, input, output, select }) {
53
+ const items = Object.entries(providers).map(([id, provider]) => ({
54
+ value: id,
55
+ label: formatProviderLabel(id, provider),
56
+ }));
57
+ return await select({ input, output, message: "Choose provider to share", items });
58
+ }
59
+
60
+ async function selectShareMode({ input, output, select }) {
61
+ const mode = await select({
62
+ input,
63
+ output,
64
+ message: "Choose share mode",
65
+ items: [
66
+ { label: "Full config, including API key", value: "full" },
67
+ { label: "Profile only, without API key", value: "profile-only" },
68
+ ],
69
+ });
70
+ return mode === "full";
71
+ }
72
+
73
+ function formatProviderLabel(id, provider) {
74
+ const name = typeof provider?.name === "string" && provider.name ? provider.name : "-";
75
+ const type = typeof provider?.type === "string" && provider.type ? provider.type : "unknown";
76
+ const modelCount = Array.isArray(provider?.models) ? `${provider.models.length} model${provider.models.length === 1 ? "" : "s"}` : "built-in";
77
+ const key = hasApiKey(provider) ? "API key configured" : "no API key";
78
+ return `${id} ${name} ${type} ${modelCount} ${key}`;
79
+ }
@@ -0,0 +1,52 @@
1
+ const KIND = "march.provider.share";
2
+ const VERSION = 1;
3
+ const PREFIX = "march-provider-v1.";
4
+
5
+ export function createProviderShareToken({ providerId, provider, mode }) {
6
+ const payload = {
7
+ kind: KIND,
8
+ version: VERSION,
9
+ mode,
10
+ containsApiKey: hasApiKey(provider),
11
+ providerId,
12
+ provider,
13
+ };
14
+ return `${PREFIX}${Buffer.from(JSON.stringify(payload), "utf8").toString("base64url")}`;
15
+ }
16
+
17
+ export function parseProviderShareToken(token) {
18
+ const text = String(token ?? "").trim();
19
+ if (!text.startsWith(PREFIX)) throw new Error(`Provider share token must start with ${PREFIX}`);
20
+ let payload;
21
+ try {
22
+ payload = JSON.parse(Buffer.from(text.slice(PREFIX.length), "base64url").toString("utf8"));
23
+ } catch {
24
+ throw new Error("Invalid provider share token");
25
+ }
26
+ validateProviderSharePayload(payload);
27
+ return payload;
28
+ }
29
+
30
+ export function cloneProviderForShare(provider, { includeApiKey }) {
31
+ const clone = structuredClone(provider);
32
+ if (!includeApiKey && clone.auth && typeof clone.auth === "object" && !Array.isArray(clone.auth)) {
33
+ delete clone.auth.apiKey;
34
+ }
35
+ return clone;
36
+ }
37
+
38
+ export function hasApiKey(provider) {
39
+ return typeof provider?.auth?.apiKey === "string" && provider.auth.apiKey.length > 0;
40
+ }
41
+
42
+ export function validateProviderSharePayload(payload) {
43
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) throw new Error("Invalid provider share payload");
44
+ if (payload.kind !== KIND || payload.version !== VERSION) throw new Error("Unsupported provider share token");
45
+ if (typeof payload.providerId !== "string" || !payload.providerId.trim()) throw new Error("Provider share token is missing providerId");
46
+ validateProviderProfile(payload.provider);
47
+ }
48
+
49
+ function validateProviderProfile(provider) {
50
+ if (!provider || typeof provider !== "object" || Array.isArray(provider)) throw new Error("Provider share token is missing provider config");
51
+ if (typeof provider.type !== "string" || !provider.type.trim()) throw new Error("Provider config is missing type");
52
+ }
@@ -13,14 +13,14 @@ export function createSuperGrokTool({ authStorage, projectMarchDir, resolveCrede
13
13
  name: "supergrok",
14
14
  label: "SuperGrok",
15
15
  description:
16
- "Use SuperGrok capabilities through xAI: realtime web search, X/Twitter search, and Grok image generation. " +
17
- "Default search behavior is broad and enables image/video understanding where supported. Requires SuperGrok OAuth or XAI_API_KEY.",
18
- promptSnippet: "supergrok(action, query, options?) - Use SuperGrok web_search, x_search, or image_generate",
16
+ "Use SuperGrok for complex research tasks that would otherwise require multiple searches or source comparison. " +
17
+ "It is backed by an agent team that can search repeatedly, verify across sources, and synthesize an answer.",
18
+ promptSnippet: "supergrok(action, query, options?) - Prefer SuperGrok for complex web/X research or Grok image generation",
19
19
  promptGuidelines: [
20
- "Use action=web_search for current web/news/documentation facts.",
21
- "Use action=x_search for current X/Twitter posts, reactions, profiles, and threads.",
20
+ "Prefer action=web_search for broad, ambiguous, current, or multi-step research.",
21
+ "Use action=x_search for targeted X/Twitter posts, reactions, profiles, and threads.",
22
22
  "Use action=image_generate when the user asks Grok/SuperGrok to create an image.",
23
- "Do not add domain, handle, or date filters unless the user asks for that narrower scope.",
23
+ "Use narrower tools instead for simple lookups, exact URL fetching, targeted X search, or non-Grok image generation.",
24
24
  ],
25
25
  parameters: Type.Object({
26
26
  action: Type.String({ enum: ACTIONS, description: "SuperGrok capability to invoke" }),