@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,34 @@
|
|
|
1
|
+
import { LIMITS } from "./constants.js";
|
|
2
|
+
import { OctenValidationError } from "./errors.js";
|
|
3
|
+
export function buildSearchRequest(query, o) {
|
|
4
|
+
if (!query)
|
|
5
|
+
throw new OctenValidationError("query is required");
|
|
6
|
+
if (o.count != null && (o.count < LIMITS.searchCount.min || o.count > LIMITS.searchCount.max))
|
|
7
|
+
throw new OctenValidationError(`count must be ${LIMITS.searchCount.min}-${LIMITS.searchCount.max}`);
|
|
8
|
+
if (o.includeText && o.includeText.length > LIMITS.includeText)
|
|
9
|
+
throw new OctenValidationError(`include-text max ${LIMITS.includeText}`);
|
|
10
|
+
if (o.excludeText && o.excludeText.length > LIMITS.excludeText)
|
|
11
|
+
throw new OctenValidationError(`exclude-text max ${LIMITS.excludeText}`);
|
|
12
|
+
const req = { query };
|
|
13
|
+
const put = (k, v) => { if (v != null)
|
|
14
|
+
req[k] = v; };
|
|
15
|
+
put("topic", o.topic);
|
|
16
|
+
put("count", o.count);
|
|
17
|
+
put("include_domains", o.includeDomains);
|
|
18
|
+
put("exclude_domains", o.excludeDomains);
|
|
19
|
+
put("include_text", o.includeText);
|
|
20
|
+
put("exclude_text", o.excludeText);
|
|
21
|
+
put("time_basis", o.timeBasis);
|
|
22
|
+
put("time_range", o.timeRange);
|
|
23
|
+
put("start_time", o.startTime);
|
|
24
|
+
put("end_time", o.endTime);
|
|
25
|
+
put("format", o.format);
|
|
26
|
+
put("safesearch", o.safesearch);
|
|
27
|
+
put("include_images", o.images);
|
|
28
|
+
put("include_videos", o.videos);
|
|
29
|
+
if (o.highlight)
|
|
30
|
+
req.highlight = { enable: true, ...(o.highlightMaxTokens ? { max_tokens: o.highlightMaxTokens } : {}) };
|
|
31
|
+
if (o.fullContent)
|
|
32
|
+
req.full_content = { enable: true, ...(o.fullContentMaxTokens ? { max_tokens: o.fullContentMaxTokens } : {}) };
|
|
33
|
+
return req;
|
|
34
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a Server-Sent Events (SSE) stream from a fetch Response.
|
|
3
|
+
* Yields parsed JSON objects from `data:` lines, stops at `data: [DONE]`.
|
|
4
|
+
* Tolerates non-JSON keepalive/comment lines by skipping them.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseSSE(res: Response): AsyncGenerator<unknown>;
|
package/dist/api/sse.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a Server-Sent Events (SSE) stream from a fetch Response.
|
|
3
|
+
* Yields parsed JSON objects from `data:` lines, stops at `data: [DONE]`.
|
|
4
|
+
* Tolerates non-JSON keepalive/comment lines by skipping them.
|
|
5
|
+
*/
|
|
6
|
+
export async function* parseSSE(res) {
|
|
7
|
+
const reader = res.body.getReader();
|
|
8
|
+
const decoder = new TextDecoder();
|
|
9
|
+
let buffer = "";
|
|
10
|
+
while (true) {
|
|
11
|
+
const { done, value } = await reader.read();
|
|
12
|
+
if (done)
|
|
13
|
+
break;
|
|
14
|
+
buffer += decoder.decode(value, { stream: true });
|
|
15
|
+
// SSE events are separated by double newlines
|
|
16
|
+
const events = buffer.split("\n\n");
|
|
17
|
+
// Keep the last (possibly incomplete) segment in the buffer
|
|
18
|
+
buffer = events.pop() ?? "";
|
|
19
|
+
for (const event of events) {
|
|
20
|
+
// Gather data lines from the event block
|
|
21
|
+
for (const line of event.split("\n")) {
|
|
22
|
+
if (!line.startsWith("data:"))
|
|
23
|
+
continue;
|
|
24
|
+
const payload = line.slice("data:".length).trim();
|
|
25
|
+
if (payload === "[DONE]")
|
|
26
|
+
return;
|
|
27
|
+
try {
|
|
28
|
+
yield JSON.parse(payload);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Skip non-JSON keepalive or malformed lines
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Flush any remaining buffer content
|
|
37
|
+
if (buffer.trim()) {
|
|
38
|
+
for (const line of buffer.split("\n")) {
|
|
39
|
+
if (!line.startsWith("data:"))
|
|
40
|
+
continue;
|
|
41
|
+
const payload = line.slice("data:".length).trim();
|
|
42
|
+
if (payload === "[DONE]")
|
|
43
|
+
return;
|
|
44
|
+
try {
|
|
45
|
+
yield JSON.parse(payload);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Skip non-JSON keepalive or malformed lines
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// A stream ending without [DONE] is treated as a normal end; the chat command owns user-facing truncation messaging.
|
|
53
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type VLContent = {
|
|
2
|
+
text: string;
|
|
3
|
+
} | {
|
|
4
|
+
image: string;
|
|
5
|
+
} | {
|
|
6
|
+
video: string;
|
|
7
|
+
};
|
|
8
|
+
/** A single VL embedding item. All fields optional — the server is untyped. */
|
|
9
|
+
export interface VLEmbeddingItem {
|
|
10
|
+
embedding?: number[];
|
|
11
|
+
vector?: number[];
|
|
12
|
+
type?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Response shape for the /vl-embedding endpoint. */
|
|
15
|
+
export interface VLEmbeddingResponse {
|
|
16
|
+
model?: string;
|
|
17
|
+
data?: (number[] | VLEmbeddingItem)[];
|
|
18
|
+
embeddings?: (number[] | VLEmbeddingItem)[];
|
|
19
|
+
items?: (number[] | VLEmbeddingItem)[];
|
|
20
|
+
}
|
|
21
|
+
export interface VLEmbeddingOpts {
|
|
22
|
+
model?: string;
|
|
23
|
+
/** tri-state: true/false = explicit enable_fusion; undefined = omit from request */
|
|
24
|
+
fusion?: boolean;
|
|
25
|
+
dimension?: number;
|
|
26
|
+
fps?: number;
|
|
27
|
+
instruct?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parse ordered content tokens into VLContent objects.
|
|
31
|
+
* Each token has the form "type:value" where the split occurs at the FIRST colon.
|
|
32
|
+
* This means URLs (e.g. "image:https://x.com/a.png") are parsed correctly.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseContentTokens(tokens: string[]): VLContent[];
|
|
35
|
+
/**
|
|
36
|
+
* Build the request body for POST /vl-embedding.
|
|
37
|
+
* Enforces content limits and resolves model aliases.
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildVlEmbeddingRequest(contents: VLContent[], o: VLEmbeddingOpts): Record<string, unknown>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { LIMITS, VL_EMBEDDING_MODELS } from "./constants.js";
|
|
2
|
+
import { OctenValidationError } from "./errors.js";
|
|
3
|
+
const ALLOWED_PREFIXES = new Set(["text", "image", "video"]);
|
|
4
|
+
/**
|
|
5
|
+
* Parse ordered content tokens into VLContent objects.
|
|
6
|
+
* Each token has the form "type:value" where the split occurs at the FIRST colon.
|
|
7
|
+
* This means URLs (e.g. "image:https://x.com/a.png") are parsed correctly.
|
|
8
|
+
*/
|
|
9
|
+
export function parseContentTokens(tokens) {
|
|
10
|
+
return tokens.map((tok) => {
|
|
11
|
+
const colonIdx = tok.indexOf(":");
|
|
12
|
+
if (colonIdx === -1) {
|
|
13
|
+
throw new OctenValidationError(`invalid content token "${tok}": must start with text:, image:, or video:`);
|
|
14
|
+
}
|
|
15
|
+
const prefix = tok.slice(0, colonIdx);
|
|
16
|
+
const value = tok.slice(colonIdx + 1);
|
|
17
|
+
if (!ALLOWED_PREFIXES.has(prefix)) {
|
|
18
|
+
throw new OctenValidationError(`invalid content token "${tok}": must start with text:, image:, or video:`);
|
|
19
|
+
}
|
|
20
|
+
if (!value) {
|
|
21
|
+
throw new OctenValidationError(`invalid content token "${tok}": must start with text:, image:, or video:`);
|
|
22
|
+
}
|
|
23
|
+
return { [prefix]: value };
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build the request body for POST /vl-embedding.
|
|
28
|
+
* Enforces content limits and resolves model aliases.
|
|
29
|
+
*/
|
|
30
|
+
export function buildVlEmbeddingRequest(contents, o) {
|
|
31
|
+
// --- Validate content limits ---
|
|
32
|
+
if (contents.length === 0) {
|
|
33
|
+
throw new OctenValidationError("contents must not be empty");
|
|
34
|
+
}
|
|
35
|
+
if (contents.length > LIMITS.vlContents) {
|
|
36
|
+
throw new OctenValidationError("contents must not exceed 20 items total");
|
|
37
|
+
}
|
|
38
|
+
const imageCount = contents.filter((c) => "image" in c).length;
|
|
39
|
+
if (imageCount > LIMITS.vlImages) {
|
|
40
|
+
throw new OctenValidationError("contents must not include more than 5 images");
|
|
41
|
+
}
|
|
42
|
+
const videoCount = contents.filter((c) => "video" in c).length;
|
|
43
|
+
if (videoCount > LIMITS.vlVideos) {
|
|
44
|
+
throw new OctenValidationError("contents must not include more than 1 video");
|
|
45
|
+
}
|
|
46
|
+
// --- Resolve model ---
|
|
47
|
+
if (o.model === undefined || o.model === null) {
|
|
48
|
+
throw new OctenValidationError("model is required (pass --model base|large)");
|
|
49
|
+
}
|
|
50
|
+
const model = VL_EMBEDDING_MODELS[o.model] ?? o.model;
|
|
51
|
+
// --- Build body ---
|
|
52
|
+
const req = {
|
|
53
|
+
model,
|
|
54
|
+
input: { contents },
|
|
55
|
+
};
|
|
56
|
+
const put = (k, v) => {
|
|
57
|
+
if (v != null)
|
|
58
|
+
req[k] = v;
|
|
59
|
+
};
|
|
60
|
+
// enable_fusion tri-state: only include when explicitly set (not undefined)
|
|
61
|
+
if (o.fusion !== undefined) {
|
|
62
|
+
req["enable_fusion"] = o.fusion;
|
|
63
|
+
}
|
|
64
|
+
put("dimension", o.dimension);
|
|
65
|
+
put("fps", o.fps);
|
|
66
|
+
put("instruct", o.instruct);
|
|
67
|
+
return req;
|
|
68
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "./util/preflightColor.js";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
import { exitCodeFor } from "./api/errors.js";
|
|
8
|
+
import { registerSearch } from "./commands/search.js";
|
|
9
|
+
import { registerFetch } from "./commands/fetch.js";
|
|
10
|
+
import { registerChat } from "./commands/chat.js";
|
|
11
|
+
import { registerEmbed } from "./commands/embed.js";
|
|
12
|
+
import { registerVlEmbed } from "./commands/vlEmbed.js";
|
|
13
|
+
import { registerConfigureMcp } from "./commands/configureMcp.js";
|
|
14
|
+
import { registerConfigureSkills } from "./commands/configureSkills.js";
|
|
15
|
+
import { registerReset } from "./commands/reset.js";
|
|
16
|
+
const pkg = JSON.parse(readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf8"));
|
|
17
|
+
const program = new Command();
|
|
18
|
+
program
|
|
19
|
+
.name("octen")
|
|
20
|
+
.description("Octen CLI — search, extract, chat, embeddings, and MCP/Skills setup")
|
|
21
|
+
.version(pkg.version)
|
|
22
|
+
.option("--api-key <key>", "Octen API key")
|
|
23
|
+
.option("--base-url <url>", "API base URL")
|
|
24
|
+
.option("--json", "raw JSON output")
|
|
25
|
+
.option("--pretty", "human-readable output")
|
|
26
|
+
.option("--no-color", "disable color");
|
|
27
|
+
registerReset(program);
|
|
28
|
+
registerConfigureMcp(program);
|
|
29
|
+
registerConfigureSkills(program);
|
|
30
|
+
registerSearch(program);
|
|
31
|
+
registerSearch(program, "news");
|
|
32
|
+
registerFetch(program);
|
|
33
|
+
registerChat(program);
|
|
34
|
+
registerEmbed(program);
|
|
35
|
+
registerVlEmbed(program);
|
|
36
|
+
program.parseAsync().catch((err) => {
|
|
37
|
+
process.stderr.write(pc.red(`error: ${err.message}\n`));
|
|
38
|
+
process.exit(exitCodeFor(err));
|
|
39
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
import { ENDPOINTS } from "../api/constants.js";
|
|
3
|
+
import { buildChatRequest } from "../api/chat.js";
|
|
4
|
+
import { parseSSE } from "../api/sse.js";
|
|
5
|
+
import { OctenValidationError } from "../api/errors.js";
|
|
6
|
+
import { chooseMode, emit } from "../output/render.js";
|
|
7
|
+
import { renderChat } from "../output/pretty/chat.js";
|
|
8
|
+
import { makeClient, parseIntOpt, parseFloatOpt } from "./utils.js";
|
|
9
|
+
export function registerChat(program) {
|
|
10
|
+
program
|
|
11
|
+
.command("chat")
|
|
12
|
+
.argument("[prompt]", "prompt (or read stdin / use -i)")
|
|
13
|
+
.description("Chat completion")
|
|
14
|
+
.option("-m, --model <id>", "model ID")
|
|
15
|
+
.option("--system <s>", "system message")
|
|
16
|
+
.option("--web-search <onoff>", "on|off")
|
|
17
|
+
.option("--temperature <n>", "sampling temperature", parseFloatOpt("--temperature"))
|
|
18
|
+
.option("--top-p <n>", "nucleus sampling top-p", parseFloatOpt("--top-p"))
|
|
19
|
+
.option("--frequency-penalty <n>", "frequency penalty", parseFloatOpt("--frequency-penalty"))
|
|
20
|
+
.option("--presence-penalty <n>", "presence penalty", parseFloatOpt("--presence-penalty"))
|
|
21
|
+
.option("--max-tokens <n>", "max output tokens", parseIntOpt("--max-tokens"))
|
|
22
|
+
.option("--reasoning-effort <e>", "low|medium|high")
|
|
23
|
+
.option("--stop <list>", "comma-separated stop sequences", (v) => v.split(","))
|
|
24
|
+
.option("--seed <n>", "random seed", parseIntOpt("--seed"))
|
|
25
|
+
.option("--no-stream", "disable streaming (use request/response)")
|
|
26
|
+
.option("-i, --interactive", "REPL mode")
|
|
27
|
+
.action(async (promptArg, opts, command) => {
|
|
28
|
+
const g = command.optsWithGlobals();
|
|
29
|
+
const client = makeClient(g);
|
|
30
|
+
const mode = chooseMode(g, process.stdout.isTTY ?? false);
|
|
31
|
+
const model = opts.model ?? process.env.OCTEN_CHAT_MODEL;
|
|
32
|
+
const chatOpts = {
|
|
33
|
+
webSearch: opts.webSearch,
|
|
34
|
+
maxTokens: opts.maxTokens,
|
|
35
|
+
temperature: opts.temperature,
|
|
36
|
+
topP: opts.topP,
|
|
37
|
+
frequencyPenalty: opts.frequencyPenalty,
|
|
38
|
+
presencePenalty: opts.presencePenalty,
|
|
39
|
+
stop: opts.stop,
|
|
40
|
+
seed: opts.seed,
|
|
41
|
+
reasoningEffort: opts.reasoningEffort,
|
|
42
|
+
};
|
|
43
|
+
// ── REPL mode ──────────────────────────────────────────────────────────
|
|
44
|
+
if (opts.interactive) {
|
|
45
|
+
const history = [];
|
|
46
|
+
if (opts.system)
|
|
47
|
+
history.push({ role: "system", content: opts.system });
|
|
48
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr, prompt: "> " });
|
|
49
|
+
rl.prompt();
|
|
50
|
+
rl.on("line", async (line) => {
|
|
51
|
+
const trimmed = line.trim();
|
|
52
|
+
if (trimmed === "/exit" || trimmed === "/quit") {
|
|
53
|
+
rl.close();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (trimmed === "/reset") {
|
|
57
|
+
history.length = 0;
|
|
58
|
+
if (opts.system)
|
|
59
|
+
history.push({ role: "system", content: opts.system });
|
|
60
|
+
process.stderr.write("(conversation reset)\n");
|
|
61
|
+
rl.prompt();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (!trimmed) {
|
|
65
|
+
rl.prompt();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
history.push({ role: "user", content: trimmed });
|
|
69
|
+
rl.pause();
|
|
70
|
+
try {
|
|
71
|
+
const req = buildChatRequest(history, model, chatOpts);
|
|
72
|
+
const res = await client.request(ENDPOINTS.chat, req);
|
|
73
|
+
const reply = res?.choices?.[0]?.message?.content ?? "";
|
|
74
|
+
history.push({ role: "assistant", content: reply });
|
|
75
|
+
process.stdout.write(reply + "\n");
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
process.stderr.write(`error: ${err.message}\n`);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
rl.resume();
|
|
82
|
+
rl.prompt();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
await new Promise((resolve) => rl.on("close", resolve));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// ── Single-turn mode ───────────────────────────────────────────────────
|
|
89
|
+
let prompt = promptArg;
|
|
90
|
+
// Read from stdin if no positional arg and stdin is not a TTY
|
|
91
|
+
if (!prompt && !process.stdin.isTTY) {
|
|
92
|
+
const chunks = [];
|
|
93
|
+
for await (const chunk of process.stdin) {
|
|
94
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
95
|
+
}
|
|
96
|
+
prompt = Buffer.concat(chunks).toString("utf8").trim();
|
|
97
|
+
}
|
|
98
|
+
if (!prompt) {
|
|
99
|
+
throw new OctenValidationError("no prompt provided");
|
|
100
|
+
}
|
|
101
|
+
const messages = [];
|
|
102
|
+
if (opts.system)
|
|
103
|
+
messages.push({ role: "system", content: opts.system });
|
|
104
|
+
messages.push({ role: "user", content: prompt });
|
|
105
|
+
const req = buildChatRequest(messages, model, chatOpts);
|
|
106
|
+
// --json forces the non-stream path: we emit one JSON object, not a token stream.
|
|
107
|
+
if (mode === "json" || opts.stream === false) {
|
|
108
|
+
const res = await client.request(ENDPOINTS.chat, req);
|
|
109
|
+
emit(res, mode, renderChat);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// Streaming pretty mode
|
|
113
|
+
const httpRes = await client.stream(ENDPOINTS.chat, req);
|
|
114
|
+
for await (const ev of parseSSE(httpRes)) {
|
|
115
|
+
const e = ev;
|
|
116
|
+
const piece = e.choices?.[0]?.delta?.content;
|
|
117
|
+
if (piece)
|
|
118
|
+
process.stdout.write(piece);
|
|
119
|
+
}
|
|
120
|
+
process.stdout.write("\n");
|
|
121
|
+
});
|
|
122
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
interface ConfigureMcpInternalOpts {
|
|
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 registerConfigureMcp(program: Command, internal?: ConfigureMcpInternalOpts): void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
import { MCP_CLIENTS } from "../mcp/clients.js";
|
|
4
|
+
import { installMcp } from "../mcp/install.js";
|
|
5
|
+
import { mcpStatus } from "../mcp/detect.js";
|
|
6
|
+
import { resolveApiKey } from "../config/resolve.js";
|
|
7
|
+
// Exported so tests can call with injected dirs
|
|
8
|
+
export function registerConfigureMcp(program, internal = {}) {
|
|
9
|
+
program
|
|
10
|
+
.command("configure-mcp")
|
|
11
|
+
.description("Configure the Octen MCP server in AI clients")
|
|
12
|
+
.option("--all", "configure all supported clients")
|
|
13
|
+
.option("--claude-code", "configure Claude Code")
|
|
14
|
+
.option("--cursor", "configure Cursor")
|
|
15
|
+
.option("--claude-desktop", "configure Claude Desktop")
|
|
16
|
+
.option("--windsurf", "configure Windsurf")
|
|
17
|
+
.option("--vscode", "configure VS Code")
|
|
18
|
+
.option("--codex", "configure Codex")
|
|
19
|
+
.option("--scope <s>", "config scope: user | project (default: user)", "user")
|
|
20
|
+
.option("--pin <ver>", "pin octen-mcp to a specific version, e.g. 0.2.1")
|
|
21
|
+
.action(async (_opts, command) => {
|
|
22
|
+
const g = command.optsWithGlobals();
|
|
23
|
+
const opts = command.opts();
|
|
24
|
+
const scope = (opts.scope === "project" ? "project" : "user");
|
|
25
|
+
const pin = opts.pin;
|
|
26
|
+
// Resolve API key — tolerate missing
|
|
27
|
+
let key;
|
|
28
|
+
let keyMissing = false;
|
|
29
|
+
try {
|
|
30
|
+
key = resolveApiKey(g.apiKey, process.env);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
key = "${OCTEN_API_KEY}";
|
|
34
|
+
keyMissing = true;
|
|
35
|
+
}
|
|
36
|
+
// Build the MCP server entry
|
|
37
|
+
const entry = {
|
|
38
|
+
command: "npx",
|
|
39
|
+
args: ["-y", pin ? `octen-mcp@${pin}` : "octen-mcp"],
|
|
40
|
+
env: { OCTEN_API_KEY: key },
|
|
41
|
+
};
|
|
42
|
+
// Determine the effective home/cwd
|
|
43
|
+
const home = internal.home ?? os.homedir();
|
|
44
|
+
const cwd = internal.cwd ?? process.cwd();
|
|
45
|
+
const installOpts = { hasClaudeCli: internal.hasClaudeCli };
|
|
46
|
+
// Determine selected clients
|
|
47
|
+
const clientFlagMap = {
|
|
48
|
+
"claude-code": "claudeCode",
|
|
49
|
+
"claude-desktop": "claudeDesktop",
|
|
50
|
+
cursor: "cursor",
|
|
51
|
+
windsurf: "windsurf",
|
|
52
|
+
vscode: "vscode",
|
|
53
|
+
codex: "codex",
|
|
54
|
+
};
|
|
55
|
+
const anySelected = opts.all ||
|
|
56
|
+
opts.claudeCode ||
|
|
57
|
+
opts.cursor ||
|
|
58
|
+
opts.claudeDesktop ||
|
|
59
|
+
opts.windsurf ||
|
|
60
|
+
opts.vscode ||
|
|
61
|
+
opts.codex;
|
|
62
|
+
if (!anySelected) {
|
|
63
|
+
// STATUS MODE: print status for each client
|
|
64
|
+
for (const client of MCP_CLIENTS) {
|
|
65
|
+
const status = mcpStatus(client, scope, home, cwd);
|
|
66
|
+
process.stdout.write(`${client.label}: ${status}\n`);
|
|
67
|
+
}
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// INSTALL MODE
|
|
71
|
+
const selected = opts.all
|
|
72
|
+
? MCP_CLIENTS
|
|
73
|
+
: MCP_CLIENTS.filter((c) => {
|
|
74
|
+
const flagName = clientFlagMap[c.id];
|
|
75
|
+
return flagName ? Boolean(opts[flagName]) : false;
|
|
76
|
+
});
|
|
77
|
+
let anyFailed = false;
|
|
78
|
+
for (const client of selected) {
|
|
79
|
+
try {
|
|
80
|
+
const result = installMcp(client, scope, entry, home, cwd, installOpts);
|
|
81
|
+
if (result.method === "claude-cli") {
|
|
82
|
+
process.stdout.write(`${client.label}: configured via claude CLI\n`);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
process.stdout.write(`${client.label}: configured → ${result.path}\n`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
90
|
+
process.stderr.write(pc.red(`error configuring ${client.label}: ${msg}`) + "\n");
|
|
91
|
+
anyFailed = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (anyFailed) {
|
|
95
|
+
process.exitCode = 1;
|
|
96
|
+
}
|
|
97
|
+
if (keyMissing) {
|
|
98
|
+
process.stderr.write("warning: no API key found — set OCTEN_API_KEY in each client's environment\n");
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
interface ConfigureSkillsInternalOpts {
|
|
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
|
+
/** Injected fetch implementation (for testing); defaults to global fetch */
|
|
8
|
+
fetchImpl?: typeof fetch;
|
|
9
|
+
}
|
|
10
|
+
export declare function registerConfigureSkills(program: Command, internal?: ConfigureSkillsInternalOpts): void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import pc from "picocolors";
|
|
5
|
+
import { SKILL_CLIENTS } from "../skills/clients.js";
|
|
6
|
+
import { resolveSkillsDir } from "../skills/source.js";
|
|
7
|
+
import { installSkills, skillStatus } from "../skills/install.js";
|
|
8
|
+
// Exported so tests can call with injected dirs
|
|
9
|
+
export function registerConfigureSkills(program, internal = {}) {
|
|
10
|
+
program
|
|
11
|
+
.command("configure-skills")
|
|
12
|
+
.description("Install Octen Agent Skills into AI clients")
|
|
13
|
+
.option("--all", "install into all supported clients")
|
|
14
|
+
.option("--claude-code", "install into Claude Code")
|
|
15
|
+
.option("--cursor", "install into Cursor")
|
|
16
|
+
.option("--codex", "install into Codex")
|
|
17
|
+
.option("--openclaw", "install into OpenClaw")
|
|
18
|
+
.option("--hermes", "install into Hermes")
|
|
19
|
+
.option("--skills-dir <path>", "use a custom skills source directory")
|
|
20
|
+
.option("--scope <s>", "config scope: user | project (default: user)", "user")
|
|
21
|
+
.option("--only <names>", "comma-separated list of skill names to install (e.g. octen-search,octen-design)")
|
|
22
|
+
.option("--ref <ref>", "upstream git ref to fetch skills from", "main")
|
|
23
|
+
.option("--bundled", "force use of bundled (vendored) skills — no network")
|
|
24
|
+
.option("--offline", "alias for --bundled")
|
|
25
|
+
.action(async (_opts, command) => {
|
|
26
|
+
const opts = command.opts();
|
|
27
|
+
const scope = (opts.scope === "project" ? "project" : "user");
|
|
28
|
+
const ref = opts.ref;
|
|
29
|
+
const offline = !!(opts.bundled || opts.offline);
|
|
30
|
+
const only = opts.only
|
|
31
|
+
? opts.only.split(",").map((s) => s.trim()).filter(Boolean)
|
|
32
|
+
: undefined;
|
|
33
|
+
const home = internal.home ?? os.homedir();
|
|
34
|
+
const cwd = internal.cwd ?? process.cwd();
|
|
35
|
+
// Both dist/commands/ (published) and src/commands/ (tsx tests) are two levels below the
|
|
36
|
+
// package root, so ../../skills resolves to the package-root skills/ dir in both.
|
|
37
|
+
const bundledDir = fileURLToPath(new URL("../../skills", import.meta.url));
|
|
38
|
+
const cacheDir = join(home, ".cache/octen-cli/skills");
|
|
39
|
+
// Determine selected clients
|
|
40
|
+
const clientFlagMap = {
|
|
41
|
+
"claude-code": "claudeCode",
|
|
42
|
+
cursor: "cursor",
|
|
43
|
+
codex: "codex",
|
|
44
|
+
openclaw: "openclaw",
|
|
45
|
+
hermes: "hermes",
|
|
46
|
+
};
|
|
47
|
+
const anySelected = opts.all ||
|
|
48
|
+
opts.claudeCode ||
|
|
49
|
+
opts.cursor ||
|
|
50
|
+
opts.codex ||
|
|
51
|
+
opts.openclaw ||
|
|
52
|
+
opts.hermes;
|
|
53
|
+
if (!anySelected) {
|
|
54
|
+
// STATUS MODE: show installed octen-* skills per client
|
|
55
|
+
for (const client of SKILL_CLIENTS) {
|
|
56
|
+
const skillsDir = client.dirFor(scope, home, cwd);
|
|
57
|
+
const status = skillStatus(skillsDir);
|
|
58
|
+
const names = Object.keys(status);
|
|
59
|
+
if (names.length === 0) {
|
|
60
|
+
process.stdout.write(`${client.label}: no octen skills installed\n`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const detail = names
|
|
64
|
+
.map((n) => `${n}@${status[n] ?? "unknown"}`)
|
|
65
|
+
.join(", ");
|
|
66
|
+
process.stdout.write(`${client.label}: ${detail}\n`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// INSTALL MODE
|
|
72
|
+
const selected = opts.all
|
|
73
|
+
? SKILL_CLIENTS
|
|
74
|
+
: SKILL_CLIENTS.filter((c) => {
|
|
75
|
+
const flagName = clientFlagMap[c.id];
|
|
76
|
+
return flagName
|
|
77
|
+
? Boolean(opts[flagName])
|
|
78
|
+
: false;
|
|
79
|
+
});
|
|
80
|
+
// Resolve skills source (custom dir, or remote/bundled)
|
|
81
|
+
let srcDir;
|
|
82
|
+
let source;
|
|
83
|
+
if (opts.skillsDir) {
|
|
84
|
+
srcDir = opts.skillsDir;
|
|
85
|
+
source = "custom";
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const resolved = await resolveSkillsDir({
|
|
89
|
+
ref,
|
|
90
|
+
offline,
|
|
91
|
+
cacheDir,
|
|
92
|
+
bundledDir,
|
|
93
|
+
fetchImpl: internal.fetchImpl,
|
|
94
|
+
});
|
|
95
|
+
srcDir = resolved.dir;
|
|
96
|
+
source = resolved.source;
|
|
97
|
+
}
|
|
98
|
+
let anyFailed = false;
|
|
99
|
+
for (const client of selected) {
|
|
100
|
+
const targetDir = client.dirFor(scope, home, cwd);
|
|
101
|
+
try {
|
|
102
|
+
const installed = installSkills(srcDir, targetDir, ref, only);
|
|
103
|
+
const skillList = installed.length > 0 ? installed.join(", ") : "(none)";
|
|
104
|
+
process.stdout.write(`${client.label}: installed [${skillList}] → ${targetDir} (source: ${source})\n`);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
108
|
+
process.stderr.write(pc.red(`error installing skills for ${client.label}: ${msg}`) + "\n");
|
|
109
|
+
anyFailed = true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (anyFailed) {
|
|
113
|
+
process.exitCode = 1;
|
|
114
|
+
}
|
|
115
|
+
// Print API key setup reminder
|
|
116
|
+
process.stdout.write("\nSet OCTEN_API_KEY in each client's environment — see https://octen.ai\n");
|
|
117
|
+
});
|
|
118
|
+
}
|