@octen.ai/cli 0.1.0
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/LICENSE +21 -0
- package/README.md +184 -0
- package/dist/api/chat.d.ts +33 -0
- package/dist/api/chat.js +23 -0
- package/dist/api/client.d.ts +19 -0
- package/dist/api/client.js +111 -0
- package/dist/api/constants.d.ts +38 -0
- package/dist/api/constants.js +32 -0
- package/dist/api/embedding.d.ts +18 -0
- package/dist/api/embedding.js +27 -0
- package/dist/api/errors.d.ts +14 -0
- package/dist/api/errors.js +22 -0
- package/dist/api/extract.d.ts +34 -0
- package/dist/api/extract.js +26 -0
- package/dist/api/search.d.ts +33 -0
- package/dist/api/search.js +34 -0
- package/dist/api/sse.d.ts +6 -0
- package/dist/api/sse.js +53 -0
- package/dist/api/vlEmbedding.d.ts +39 -0
- package/dist/api/vlEmbedding.js +68 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +39 -0
- package/dist/commands/chat.d.ts +2 -0
- package/dist/commands/chat.js +122 -0
- package/dist/commands/configureMcp.d.ts +11 -0
- package/dist/commands/configureMcp.js +101 -0
- package/dist/commands/configureSkills.d.ts +11 -0
- package/dist/commands/configureSkills.js +118 -0
- package/dist/commands/embed.d.ts +2 -0
- package/dist/commands/embed.js +69 -0
- package/dist/commands/fetch.d.ts +2 -0
- package/dist/commands/fetch.js +26 -0
- package/dist/commands/reset.d.ts +11 -0
- package/dist/commands/reset.js +112 -0
- package/dist/commands/search.d.ts +2 -0
- package/dist/commands/search.js +31 -0
- package/dist/commands/utils.d.ts +10 -0
- package/dist/commands/utils.js +24 -0
- package/dist/commands/vlEmbed.d.ts +2 -0
- package/dist/commands/vlEmbed.js +98 -0
- package/dist/config/resolve.d.ts +2 -0
- package/dist/config/resolve.js +12 -0
- package/dist/mcp/clients.d.ts +9 -0
- package/dist/mcp/clients.js +58 -0
- package/dist/mcp/detect.d.ts +2 -0
- package/dist/mcp/detect.js +35 -0
- package/dist/mcp/install.d.ts +20 -0
- package/dist/mcp/install.js +56 -0
- package/dist/mcp/write.d.ts +3 -0
- package/dist/mcp/write.js +104 -0
- package/dist/output/pretty/chat.d.ts +2 -0
- package/dist/output/pretty/chat.js +9 -0
- package/dist/output/pretty/embedding.d.ts +11 -0
- package/dist/output/pretty/embedding.js +43 -0
- package/dist/output/pretty/extract.d.ts +2 -0
- package/dist/output/pretty/extract.js +41 -0
- package/dist/output/pretty/search.d.ts +2 -0
- package/dist/output/pretty/search.js +28 -0
- package/dist/output/pretty/vlEmbedding.d.ts +13 -0
- package/dist/output/pretty/vlEmbedding.js +47 -0
- package/dist/output/render.d.ts +6 -0
- package/dist/output/render.js +13 -0
- package/dist/skills/clients.d.ts +7 -0
- package/dist/skills/clients.js +47 -0
- package/dist/skills/install.d.ts +18 -0
- package/dist/skills/install.js +77 -0
- package/dist/skills/source.d.ts +12 -0
- package/dist/skills/source.js +56 -0
- package/dist/util/preflightColor.d.ts +1 -0
- package/dist/util/preflightColor.js +7 -0
- package/package.json +44 -0
- package/skills/manifest.json +8 -0
- package/skills/octen-design/SKILL.md +218 -0
- package/skills/octen-design/scripts/search.py +304 -0
- package/skills/octen-search/SKILL.md +199 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { ENDPOINTS } from "../api/constants.js";
|
|
3
|
+
import { buildEmbeddingRequest } from "../api/embedding.js";
|
|
4
|
+
import { OctenValidationError } from "../api/errors.js";
|
|
5
|
+
import { chooseMode, emit } from "../output/render.js";
|
|
6
|
+
import { renderEmbedding } from "../output/pretty/embedding.js";
|
|
7
|
+
import { makeClient, parseIntOpt } from "./utils.js";
|
|
8
|
+
export function registerEmbed(program) {
|
|
9
|
+
program
|
|
10
|
+
.command("embed")
|
|
11
|
+
.argument("[text...]", "text to embed (or use --file / stdin)")
|
|
12
|
+
.description("Create text embeddings")
|
|
13
|
+
.option("-m, --model <id>", "model: 0.6b | 4b | 8b or full id")
|
|
14
|
+
.option("--dimension <n>", "output vector dimension", parseIntOpt("--dimension"))
|
|
15
|
+
.option("--input-type <t>", "query | document")
|
|
16
|
+
.option("--file <path>", "read texts from file (one per line)")
|
|
17
|
+
// Truncation tri-state:
|
|
18
|
+
// --truncation sets opts.truncation = true
|
|
19
|
+
// --no-truncation sets opts.truncation = false
|
|
20
|
+
// Neither flag → opts.truncation = undefined (not passed to API)
|
|
21
|
+
// We use getOptionValueSource("truncation") === "cli" to detect explicit CLI use.
|
|
22
|
+
// Commander's --no-* mechanism: defining "--truncation" alone yields a tri-state when
|
|
23
|
+
// getOptionValueSource is checked; "--no-truncation" negates it. No default is set, so
|
|
24
|
+
// if neither is passed, the value stays undefined.
|
|
25
|
+
.option("--truncation", "enable input truncation")
|
|
26
|
+
.option("--no-truncation", "disable input truncation")
|
|
27
|
+
.action(async (textArgs, opts, command) => {
|
|
28
|
+
const g = command.optsWithGlobals();
|
|
29
|
+
// --- Input resolution (precedence: args > --file > stdin) ---
|
|
30
|
+
let input;
|
|
31
|
+
if (textArgs.length > 0) {
|
|
32
|
+
// Single arg → string; multiple → array
|
|
33
|
+
input = textArgs.length === 1 ? textArgs[0] : textArgs;
|
|
34
|
+
}
|
|
35
|
+
else if (opts.file) {
|
|
36
|
+
if (!existsSync(opts.file))
|
|
37
|
+
throw new OctenValidationError(`file not found: ${opts.file}`);
|
|
38
|
+
const raw = readFileSync(opts.file, "utf8");
|
|
39
|
+
const lines = raw.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
40
|
+
input = lines.length === 1 ? lines[0] : lines;
|
|
41
|
+
}
|
|
42
|
+
else if (!process.stdin.isTTY) {
|
|
43
|
+
// Read all of stdin and split into non-empty lines
|
|
44
|
+
const chunks = [];
|
|
45
|
+
for await (const chunk of process.stdin)
|
|
46
|
+
chunks.push(chunk);
|
|
47
|
+
const raw = Buffer.concat(chunks).toString("utf8");
|
|
48
|
+
const lines = raw.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
49
|
+
input = lines.length === 1 ? lines[0] : lines;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new OctenValidationError("no input: provide text args, --file, or stdin");
|
|
53
|
+
}
|
|
54
|
+
// --- Truncation tri-state ---
|
|
55
|
+
// If the user explicitly passed --truncation or --no-truncation, forward it.
|
|
56
|
+
// Otherwise leave undefined so the API uses its own default.
|
|
57
|
+
const truncationSource = command.getOptionValueSource("truncation");
|
|
58
|
+
const truncation = truncationSource === "cli" ? opts.truncation : undefined;
|
|
59
|
+
const client = makeClient(g);
|
|
60
|
+
const req = buildEmbeddingRequest(input, {
|
|
61
|
+
model: opts.model,
|
|
62
|
+
dimension: opts.dimension,
|
|
63
|
+
inputType: opts.inputType,
|
|
64
|
+
truncation,
|
|
65
|
+
});
|
|
66
|
+
const res = await client.request(ENDPOINTS.embedding, req);
|
|
67
|
+
emit(res, chooseMode(g, process.stdout.isTTY ?? false), renderEmbedding);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ENDPOINTS } from "../api/constants.js";
|
|
2
|
+
import { buildExtractRequest } from "../api/extract.js";
|
|
3
|
+
import { chooseMode, emit } from "../output/render.js";
|
|
4
|
+
import { renderExtract } from "../output/pretty/extract.js";
|
|
5
|
+
import { makeClient, parseIntOpt } from "./utils.js";
|
|
6
|
+
export function registerFetch(program) {
|
|
7
|
+
program
|
|
8
|
+
.command("fetch")
|
|
9
|
+
.argument("<urls...>", "one or more URLs (1-20)")
|
|
10
|
+
.description("Extract content from URLs")
|
|
11
|
+
.option("--query <q>", "optional search query for relevance")
|
|
12
|
+
.option("--max-age <sec>", "max cache age in seconds", parseIntOpt("--max-age"))
|
|
13
|
+
.option("--format <f>", "markdown|text")
|
|
14
|
+
.option("--fetch-timeout <sec>", "per-URL fetch timeout (1-60)", parseIntOpt("--fetch-timeout"))
|
|
15
|
+
.option("--images", "include images")
|
|
16
|
+
.option("--videos", "include videos")
|
|
17
|
+
.option("--audio", "include audio")
|
|
18
|
+
.option("--favicon", "include favicon")
|
|
19
|
+
.action(async (urls, opts, command) => {
|
|
20
|
+
const g = command.optsWithGlobals();
|
|
21
|
+
const client = makeClient(g);
|
|
22
|
+
const req = buildExtractRequest(urls, opts);
|
|
23
|
+
const res = await client.request(ENDPOINTS.extract, req);
|
|
24
|
+
emit(res, chooseMode(g, process.stdout.isTTY ?? false), renderExtract);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
interface ResetInternalOpts {
|
|
3
|
+
/** Injected home dir (for testing); defaults to os.homedir() */
|
|
4
|
+
home?: string;
|
|
5
|
+
/** Injected cwd (for testing); defaults to process.cwd() */
|
|
6
|
+
cwd?: string;
|
|
7
|
+
/** Override claude CLI detection (for testing) */
|
|
8
|
+
hasClaudeCli?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function registerReset(program: Command, internal?: ResetInternalOpts): void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
import { MCP_CLIENTS } from "../mcp/clients.js";
|
|
4
|
+
import { SKILL_CLIENTS } from "../skills/clients.js";
|
|
5
|
+
import { removeMcp } from "../mcp/install.js";
|
|
6
|
+
import { removeSkills } from "../skills/install.js";
|
|
7
|
+
// Maps CLI flag name → client id (shared across both registries)
|
|
8
|
+
const CLIENT_FLAG_MAP = {
|
|
9
|
+
claudeCode: "claude-code",
|
|
10
|
+
cursor: "cursor",
|
|
11
|
+
claudeDesktop: "claude-desktop",
|
|
12
|
+
windsurf: "windsurf",
|
|
13
|
+
vscode: "vscode",
|
|
14
|
+
codex: "codex",
|
|
15
|
+
openclaw: "openclaw",
|
|
16
|
+
hermes: "hermes",
|
|
17
|
+
};
|
|
18
|
+
export function registerReset(program, internal = {}) {
|
|
19
|
+
program
|
|
20
|
+
.command("reset")
|
|
21
|
+
.description("Remove Octen MCP server and/or skills from AI clients")
|
|
22
|
+
.option("--mcp", "remove MCP entries")
|
|
23
|
+
.option("--skills", "remove skills")
|
|
24
|
+
.option("--all", "remove from both surfaces across all clients")
|
|
25
|
+
.option("--claude-code", "target Claude Code")
|
|
26
|
+
.option("--cursor", "target Cursor")
|
|
27
|
+
.option("--claude-desktop", "target Claude Desktop")
|
|
28
|
+
.option("--windsurf", "target Windsurf")
|
|
29
|
+
.option("--vscode", "target VS Code")
|
|
30
|
+
.option("--codex", "target Codex")
|
|
31
|
+
.option("--openclaw", "target OpenClaw")
|
|
32
|
+
.option("--hermes", "target Hermes")
|
|
33
|
+
.option("--scope <s>", "config scope: user | project (default: user)", "user")
|
|
34
|
+
.action((_opts, command) => {
|
|
35
|
+
const opts = command.opts();
|
|
36
|
+
const home = internal.home ?? os.homedir();
|
|
37
|
+
const cwd = internal.cwd ?? process.cwd();
|
|
38
|
+
const scope = (opts.scope === "project" ? "project" : "user");
|
|
39
|
+
const installOpts = { hasClaudeCli: internal.hasClaudeCli };
|
|
40
|
+
// Surface selection
|
|
41
|
+
const doMcp = opts.all ? true : !!opts.mcp;
|
|
42
|
+
const doSkills = opts.all ? true : !!opts.skills;
|
|
43
|
+
if (!doMcp && !doSkills) {
|
|
44
|
+
process.stdout.write("specify --mcp, --skills, or --all to select what to remove\n");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// Determine which client ids were explicitly requested via per-client flags
|
|
48
|
+
const requestedIds = new Set();
|
|
49
|
+
const anyPerClientFlag = Object.entries(CLIENT_FLAG_MAP).some(([flagName]) => !!opts[flagName]);
|
|
50
|
+
if (anyPerClientFlag) {
|
|
51
|
+
for (const [flagName, clientId] of Object.entries(CLIENT_FLAG_MAP)) {
|
|
52
|
+
if (opts[flagName]) {
|
|
53
|
+
requestedIds.add(clientId);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Helper: select clients from a registry based on --all / per-client flags
|
|
58
|
+
function selectClients(registry) {
|
|
59
|
+
if (opts.all || !anyPerClientFlag) {
|
|
60
|
+
// No per-client filter: use all clients in this registry
|
|
61
|
+
return registry;
|
|
62
|
+
}
|
|
63
|
+
// Filter: only those whose id was explicitly requested
|
|
64
|
+
return registry.filter((c) => requestedIds.has(c.id));
|
|
65
|
+
}
|
|
66
|
+
let anyFailed = false;
|
|
67
|
+
// --- MCP surface ---
|
|
68
|
+
if (doMcp) {
|
|
69
|
+
const selectedMcpClients = selectClients(MCP_CLIENTS);
|
|
70
|
+
for (const client of selectedMcpClients) {
|
|
71
|
+
try {
|
|
72
|
+
const result = removeMcp(client, scope, home, cwd, installOpts);
|
|
73
|
+
if (result.removed) {
|
|
74
|
+
process.stdout.write(`removed octen from ${client.label} (${result.path})\n`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
process.stdout.write(`octen not present in ${client.label}\n`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
82
|
+
process.stderr.write(pc.red(`warning: failed to remove MCP from ${client.label}: ${msg}`) + "\n");
|
|
83
|
+
anyFailed = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// --- Skills surface ---
|
|
88
|
+
if (doSkills) {
|
|
89
|
+
const selectedSkillClients = selectClients(SKILL_CLIENTS);
|
|
90
|
+
for (const client of selectedSkillClients) {
|
|
91
|
+
try {
|
|
92
|
+
const skillsDir = client.dirFor(scope, home, cwd);
|
|
93
|
+
const removed = removeSkills(skillsDir);
|
|
94
|
+
if (removed.length > 0) {
|
|
95
|
+
process.stdout.write(`removed [${removed.join(", ")}] from ${client.label} (${skillsDir})\n`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
process.stdout.write(`no octen skills in ${client.label}\n`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
103
|
+
process.stderr.write(pc.red(`warning: failed to remove skills from ${client.label}: ${msg}`) + "\n");
|
|
104
|
+
anyFailed = true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (anyFailed) {
|
|
109
|
+
process.exitCode = 1;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ENDPOINTS } from "../api/constants.js";
|
|
2
|
+
import { buildSearchRequest } from "../api/search.js";
|
|
3
|
+
import { chooseMode, emit } from "../output/render.js";
|
|
4
|
+
import { renderSearch } from "../output/pretty/search.js";
|
|
5
|
+
import { makeClient, parseIntOpt } from "./utils.js";
|
|
6
|
+
export function registerSearch(program, fixedTopic) {
|
|
7
|
+
const cmd = program.command(fixedTopic ?? "search")
|
|
8
|
+
.argument("<query>", "search query")
|
|
9
|
+
.description(fixedTopic ? "News-focused web search" : "Search the live web")
|
|
10
|
+
.option("-n, --count <n>", "results 1-100", parseIntOpt("--count"))
|
|
11
|
+
.option("--include-domains <list>", "comma list", (v) => v.split(","))
|
|
12
|
+
.option("--exclude-domains <list>", "comma list", (v) => v.split(","))
|
|
13
|
+
.option("--include-text <list>", "comma list", (v) => v.split(","))
|
|
14
|
+
.option("--exclude-text <list>", "comma list", (v) => v.split(","))
|
|
15
|
+
.option("--time-basis <b>").option("--time-range <r>")
|
|
16
|
+
.option("--start-time <iso>").option("--end-time <iso>")
|
|
17
|
+
.option("--format <f>", "text|markdown").option("--safesearch <s>", "off|strict")
|
|
18
|
+
.option("--highlight").option("--highlight-max-tokens <n>", "max tokens per highlight", parseIntOpt("--highlight-max-tokens"))
|
|
19
|
+
.option("--full-content").option("--full-content-max-tokens <n>", "max tokens per result", parseIntOpt("--full-content-max-tokens"))
|
|
20
|
+
.option("--images").option("--videos");
|
|
21
|
+
if (!fixedTopic)
|
|
22
|
+
cmd.option("--topic <t>", "general|news");
|
|
23
|
+
cmd.action(async (query, opts, command) => {
|
|
24
|
+
const g = command.optsWithGlobals();
|
|
25
|
+
const client = makeClient(g);
|
|
26
|
+
const searchOpts = { ...opts, topic: fixedTopic ?? opts.topic };
|
|
27
|
+
const req = buildSearchRequest(query, searchOpts);
|
|
28
|
+
const res = await client.request(ENDPOINTS.search, req);
|
|
29
|
+
emit(res, chooseMode(g, process.stdout.isTTY ?? false), renderSearch);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OctenClient } from "../api/client.js";
|
|
2
|
+
/** Build an OctenClient from resolved global options (flag > env). */
|
|
3
|
+
export declare function makeClient(g: {
|
|
4
|
+
apiKey?: string;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
}): OctenClient;
|
|
7
|
+
/** Commander option parser for integer flags that errors clearly on non-integers. */
|
|
8
|
+
export declare const parseIntOpt: (name: string) => (v: string) => number;
|
|
9
|
+
/** Commander option parser for float flags that errors clearly on non-numbers. */
|
|
10
|
+
export declare const parseFloatOpt: (name: string) => (v: string) => number;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { OctenClient } from "../api/client.js";
|
|
2
|
+
import { OctenValidationError } from "../api/errors.js";
|
|
3
|
+
import { resolveApiKey, resolveBaseUrl } from "../config/resolve.js";
|
|
4
|
+
/** Build an OctenClient from resolved global options (flag > env). */
|
|
5
|
+
export function makeClient(g) {
|
|
6
|
+
return new OctenClient({
|
|
7
|
+
apiKey: resolveApiKey(g.apiKey, process.env),
|
|
8
|
+
baseUrl: resolveBaseUrl(g.baseUrl, process.env),
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
/** Commander option parser for integer flags that errors clearly on non-integers. */
|
|
12
|
+
export const parseIntOpt = (name) => (v) => {
|
|
13
|
+
const n = parseInt(v, 10);
|
|
14
|
+
if (Number.isNaN(n))
|
|
15
|
+
throw new OctenValidationError(`${name} must be an integer`);
|
|
16
|
+
return n;
|
|
17
|
+
};
|
|
18
|
+
/** Commander option parser for float flags that errors clearly on non-numbers. */
|
|
19
|
+
export const parseFloatOpt = (name) => (v) => {
|
|
20
|
+
const n = parseFloat(v);
|
|
21
|
+
if (Number.isNaN(n))
|
|
22
|
+
throw new OctenValidationError(`${name} must be a number`);
|
|
23
|
+
return n;
|
|
24
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { readFileSync, existsSync, statSync } from "node:fs";
|
|
2
|
+
import { extname } from "node:path";
|
|
3
|
+
import { ENDPOINTS } from "../api/constants.js";
|
|
4
|
+
import { OctenValidationError } from "../api/errors.js";
|
|
5
|
+
import { parseContentTokens, buildVlEmbeddingRequest } from "../api/vlEmbedding.js";
|
|
6
|
+
import { chooseMode, emit } from "../output/render.js";
|
|
7
|
+
import { renderVlEmbedding } from "../output/pretty/vlEmbedding.js";
|
|
8
|
+
import { makeClient, parseIntOpt, parseFloatOpt } from "./utils.js";
|
|
9
|
+
/** Map common file extensions to MIME types for base64 data URIs. */
|
|
10
|
+
function mimeForExtension(ext) {
|
|
11
|
+
switch (ext.toLowerCase()) {
|
|
12
|
+
case ".png": return "image/png";
|
|
13
|
+
case ".jpg":
|
|
14
|
+
case ".jpeg": return "image/jpeg";
|
|
15
|
+
case ".gif": return "image/gif";
|
|
16
|
+
case ".webp": return "image/webp";
|
|
17
|
+
case ".mp4": return "video/mp4";
|
|
18
|
+
case ".webm": return "video/webm";
|
|
19
|
+
default: return "application/octet-stream";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a single image or video content item:
|
|
24
|
+
* - If the value looks like a URL (http://, https://) or data URI, return as-is.
|
|
25
|
+
* - Otherwise treat it as a local file path, read and convert to a base64 data URI.
|
|
26
|
+
*
|
|
27
|
+
* NOTE: It is currently unconfirmed whether the Octen /vl-embedding API accepts
|
|
28
|
+
* base64 data URIs or only HTTPS URLs. The local-file path is implemented here
|
|
29
|
+
* for ergonomics but should be validated against the API once confirmed.
|
|
30
|
+
*/
|
|
31
|
+
function resolveContentValue(value) {
|
|
32
|
+
if (value.startsWith("http://") ||
|
|
33
|
+
value.startsWith("https://") ||
|
|
34
|
+
value.startsWith("data:")) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
// Local file path — read and encode as base64 data URI.
|
|
38
|
+
if (!existsSync(value)) {
|
|
39
|
+
throw new OctenValidationError(`file not found: ${value}`);
|
|
40
|
+
}
|
|
41
|
+
const MAX_INLINE_BYTES = 10 * 1024 * 1024; // 10 MB
|
|
42
|
+
const { size } = statSync(value);
|
|
43
|
+
if (size > MAX_INLINE_BYTES) {
|
|
44
|
+
throw new OctenValidationError(`file ${value} is ${(size / 1048576).toFixed(1)}MB; max 10MB for inline embedding — pass an https URL instead`);
|
|
45
|
+
}
|
|
46
|
+
const buf = readFileSync(value);
|
|
47
|
+
const ext = extname(value);
|
|
48
|
+
const mime = mimeForExtension(ext);
|
|
49
|
+
return `data:${mime};base64,${buf.toString("base64")}`;
|
|
50
|
+
}
|
|
51
|
+
/** Resolve local file paths for image and video contents. */
|
|
52
|
+
function resolveLocalFiles(contents) {
|
|
53
|
+
return contents.map((c) => {
|
|
54
|
+
if ("image" in c) {
|
|
55
|
+
return { image: resolveContentValue(c.image) };
|
|
56
|
+
}
|
|
57
|
+
if ("video" in c) {
|
|
58
|
+
return { video: resolveContentValue(c.video) };
|
|
59
|
+
}
|
|
60
|
+
return c; // text items pass through
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export function registerVlEmbed(program) {
|
|
64
|
+
program
|
|
65
|
+
.command("vl-embed")
|
|
66
|
+
.argument("<content...>", "ordered content tokens: text:... image:... video:...")
|
|
67
|
+
.description("Create multimodal embeddings")
|
|
68
|
+
.option("-m, --model <id>", "model: base | large | full id")
|
|
69
|
+
.option("--dimension <n>", "output vector dimension", parseIntOpt("--dimension"))
|
|
70
|
+
.option("--fps <n>", "video frames per second to sample", parseFloatOpt("--fps"))
|
|
71
|
+
.option("--instruct <s>", "task instruction for embedding")
|
|
72
|
+
// Fusion tri-state (same pattern as embed's --truncation):
|
|
73
|
+
// --fusion → opts.fusion = true
|
|
74
|
+
// --no-fusion → opts.fusion = false
|
|
75
|
+
// Neither → opts.fusion = undefined (omit enable_fusion from API body)
|
|
76
|
+
.option("--fusion", "enable fusion embedding")
|
|
77
|
+
.option("--no-fusion", "disable fusion embedding")
|
|
78
|
+
.action(async (contentArgs, opts, command) => {
|
|
79
|
+
const g = command.optsWithGlobals();
|
|
80
|
+
// Parse content tokens
|
|
81
|
+
const rawContents = parseContentTokens(contentArgs);
|
|
82
|
+
// Resolve local files to base64 data URIs
|
|
83
|
+
const contents = resolveLocalFiles(rawContents);
|
|
84
|
+
// Fusion tri-state: only forward if explicitly set via CLI
|
|
85
|
+
const fusionSource = command.getOptionValueSource("fusion");
|
|
86
|
+
const fusion = fusionSource === "cli" ? opts.fusion : undefined;
|
|
87
|
+
const client = makeClient(g);
|
|
88
|
+
const req = buildVlEmbeddingRequest(contents, {
|
|
89
|
+
model: opts.model,
|
|
90
|
+
fusion,
|
|
91
|
+
dimension: opts.dimension,
|
|
92
|
+
fps: opts.fps,
|
|
93
|
+
instruct: opts.instruct,
|
|
94
|
+
});
|
|
95
|
+
const res = await client.request(ENDPOINTS.vlEmbedding, req);
|
|
96
|
+
emit(res, chooseMode(g, process.stdout.isTTY ?? false), renderVlEmbedding);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DEFAULT_BASE_URL } from "../api/constants.js";
|
|
2
|
+
import { OctenAuthError } from "../api/errors.js";
|
|
3
|
+
export function resolveApiKey(flag, env) {
|
|
4
|
+
const key = flag || env.OCTEN_API_KEY;
|
|
5
|
+
if (!key) {
|
|
6
|
+
throw new OctenAuthError("No API key. Pass --api-key or set OCTEN_API_KEY. Get one at https://octen.ai");
|
|
7
|
+
}
|
|
8
|
+
return key;
|
|
9
|
+
}
|
|
10
|
+
export function resolveBaseUrl(flag, env) {
|
|
11
|
+
return flag || env.OCTEN_API_URL || DEFAULT_BASE_URL;
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type McpFormat = "json-mcpServers" | "json-servers" | "toml" | "claude-code";
|
|
2
|
+
export interface McpClient {
|
|
3
|
+
id: "claude-code" | "claude-desktop" | "cursor" | "windsurf" | "vscode" | "codex";
|
|
4
|
+
label: string;
|
|
5
|
+
format: McpFormat;
|
|
6
|
+
supportsProject: boolean;
|
|
7
|
+
pathFor(scope: "user" | "project", home: string, cwd: string): string;
|
|
8
|
+
}
|
|
9
|
+
export declare const MCP_CLIENTS: McpClient[];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
export const MCP_CLIENTS = [
|
|
3
|
+
{
|
|
4
|
+
id: "claude-code",
|
|
5
|
+
label: "Claude Code",
|
|
6
|
+
format: "claude-code",
|
|
7
|
+
supportsProject: false,
|
|
8
|
+
pathFor(_scope, home, _cwd) {
|
|
9
|
+
return join(home, ".claude.json");
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: "claude-desktop",
|
|
14
|
+
label: "Claude Desktop",
|
|
15
|
+
format: "json-mcpServers",
|
|
16
|
+
supportsProject: false,
|
|
17
|
+
pathFor(_scope, home, _cwd) {
|
|
18
|
+
return join(home, "Library/Application Support/Claude/claude_desktop_config.json");
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "cursor",
|
|
23
|
+
label: "Cursor",
|
|
24
|
+
format: "json-mcpServers",
|
|
25
|
+
supportsProject: true,
|
|
26
|
+
pathFor(scope, home, cwd) {
|
|
27
|
+
return scope === "project" ? join(cwd, ".cursor/mcp.json") : join(home, ".cursor/mcp.json");
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "windsurf",
|
|
32
|
+
label: "Windsurf",
|
|
33
|
+
format: "json-mcpServers",
|
|
34
|
+
supportsProject: false,
|
|
35
|
+
pathFor(_scope, home, _cwd) {
|
|
36
|
+
return join(home, ".codeium/windsurf/mcp_config.json");
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "vscode",
|
|
41
|
+
label: "VS Code",
|
|
42
|
+
format: "json-servers",
|
|
43
|
+
supportsProject: true,
|
|
44
|
+
// v1: project-scoped only; user scope also returns the project path
|
|
45
|
+
pathFor(_scope, _home, cwd) {
|
|
46
|
+
return join(cwd, ".vscode/mcp.json");
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "codex",
|
|
51
|
+
label: "Codex",
|
|
52
|
+
format: "toml",
|
|
53
|
+
supportsProject: false,
|
|
54
|
+
pathFor(_scope, home, _cwd) {
|
|
55
|
+
return join(home, ".codex/config.toml");
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { parse as tomlParse } from "smol-toml";
|
|
3
|
+
export function mcpStatus(client, scope, home, cwd) {
|
|
4
|
+
const filePath = client.pathFor(scope, home, cwd);
|
|
5
|
+
if (!existsSync(filePath))
|
|
6
|
+
return "absent";
|
|
7
|
+
const raw = readFileSync(filePath, "utf8").trim();
|
|
8
|
+
if (!raw)
|
|
9
|
+
return "absent";
|
|
10
|
+
try {
|
|
11
|
+
if (client.format === "toml") {
|
|
12
|
+
const obj = tomlParse(raw);
|
|
13
|
+
const servers = obj.mcp_servers;
|
|
14
|
+
if (servers && typeof servers === "object" && "octen" in servers) {
|
|
15
|
+
return "configured";
|
|
16
|
+
}
|
|
17
|
+
return "absent";
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// JSON formats
|
|
21
|
+
const obj = JSON.parse(raw);
|
|
22
|
+
// claude-code, json-mcpServers → check mcpServers
|
|
23
|
+
// json-servers → check servers
|
|
24
|
+
const container = client.format === "json-servers" ? obj.servers : obj.mcpServers;
|
|
25
|
+
if (container && typeof container === "object" && "octen" in container) {
|
|
26
|
+
return "configured";
|
|
27
|
+
}
|
|
28
|
+
return "absent";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
process.stderr.write(`warning: could not parse ${filePath}: ${e.message}\n`);
|
|
33
|
+
return "absent";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { McpClient } from "./clients.js";
|
|
2
|
+
export interface InstallOpts {
|
|
3
|
+
/** Override claude-CLI availability detection for testing */
|
|
4
|
+
hasClaudeCli?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface InstallResult {
|
|
7
|
+
path: string;
|
|
8
|
+
method: "claude-cli" | "file";
|
|
9
|
+
}
|
|
10
|
+
export interface RemoveResult {
|
|
11
|
+
path: string;
|
|
12
|
+
removed: boolean;
|
|
13
|
+
method: "claude-cli" | "file";
|
|
14
|
+
}
|
|
15
|
+
export declare function installMcp(client: McpClient, scope: "user" | "project", entry: {
|
|
16
|
+
command: string;
|
|
17
|
+
args: string[];
|
|
18
|
+
env: Record<string, string>;
|
|
19
|
+
}, home: string, cwd: string, opts?: InstallOpts): InstallResult;
|
|
20
|
+
export declare function removeMcp(client: McpClient, scope: "user" | "project", home: string, cwd: string, opts?: InstallOpts): RemoveResult;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { upsertMcpServer, removeMcpServer } from "./write.js";
|
|
3
|
+
function claudeAvailable(override) {
|
|
4
|
+
if (override !== undefined)
|
|
5
|
+
return override;
|
|
6
|
+
try {
|
|
7
|
+
execFileSync("which", ["claude"], { stdio: "ignore" });
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function installMcp(client, scope, entry, home, cwd, opts = {}) {
|
|
15
|
+
if (client.id === "claude-code") {
|
|
16
|
+
if (claudeAvailable(opts.hasClaudeCli)) {
|
|
17
|
+
// Use claude CLI: build args safely, no string concatenation
|
|
18
|
+
const apiKey = entry.env["OCTEN_API_KEY"] ?? "";
|
|
19
|
+
execFileSync("claude", [
|
|
20
|
+
"mcp",
|
|
21
|
+
"add",
|
|
22
|
+
"--scope",
|
|
23
|
+
scope,
|
|
24
|
+
"octen",
|
|
25
|
+
"-e",
|
|
26
|
+
`OCTEN_API_KEY=${apiKey}`,
|
|
27
|
+
"--",
|
|
28
|
+
entry.command,
|
|
29
|
+
...entry.args,
|
|
30
|
+
], { stdio: "inherit" });
|
|
31
|
+
return { path: client.pathFor(scope, home, cwd), method: "claude-cli" };
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// Fall back to writing ~/.claude.json mcpServers directly
|
|
35
|
+
const filePath = client.pathFor(scope, home, cwd);
|
|
36
|
+
upsertMcpServer(filePath, client.format, entry);
|
|
37
|
+
return { path: filePath, method: "file" };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// All other clients: write via file
|
|
41
|
+
const filePath = client.pathFor(scope, home, cwd);
|
|
42
|
+
upsertMcpServer(filePath, client.format, entry);
|
|
43
|
+
return { path: filePath, method: "file" };
|
|
44
|
+
}
|
|
45
|
+
export function removeMcp(client, scope, home, cwd, opts = {}) {
|
|
46
|
+
if (client.id === "claude-code") {
|
|
47
|
+
if (claudeAvailable(opts.hasClaudeCli)) {
|
|
48
|
+
execFileSync("claude", ["mcp", "remove", "--scope", scope, "octen"], { stdio: "inherit" });
|
|
49
|
+
return { path: client.pathFor(scope, home, cwd), removed: true, method: "claude-cli" };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// All other clients (and claude-code without CLI): write via file
|
|
53
|
+
const filePath = client.pathFor(scope, home, cwd);
|
|
54
|
+
const removed = removeMcpServer(filePath, client.format);
|
|
55
|
+
return { path: filePath, removed, method: "file" };
|
|
56
|
+
}
|