@octen.ai/cli 0.13.1 → 0.15.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/README.md CHANGED
@@ -10,7 +10,7 @@ Command-line tool for Octen — web search, extract, chat, embeddings, and one-c
10
10
  npm i -g @octen.ai/cli
11
11
  ```
12
12
 
13
- Or run without installing: `npx @octen.ai/cli <command>`. Requires Node.js 18+.
13
+ Or run without installing: `npx @octen.ai/cli <command>`. Requires Node.js 20+.
14
14
  Uninstall: `npm uninstall -g @octen.ai/cli`.
15
15
 
16
16
  ### Without Node.js — Homebrew (macOS/Linux)
@@ -553,6 +553,43 @@ Options: `-n` (result count 1–10), `--time-range` (day|week|month|year or d|w|
553
553
 
554
554
  ---
555
555
 
556
+ ### `octen monitor`
557
+
558
+ Watch a topic (new results for a search query) or up to 10 pages (changes to their content) on a schedule, and get told only when a change meets a plain-language condition — by webhook, by email, or by reading the events.
559
+
560
+ ```sh
561
+ octen monitor create --topic "solid-state battery breakthroughs" --condition "a carmaker announces a mass production date" --interval 1d
562
+ octen monitor create --page https://example.com/pricing --field "price:number:Monthly price in USD" --condition "price drops more than 10%"
563
+ octen monitor list --status active
564
+ octen monitor events mon_123 --limit 20
565
+ octen monitor pause mon_123
566
+ octen monitor delete mon_123
567
+ ```
568
+
569
+ | Subcommand | What it does |
570
+ |---|---|
571
+ | `create` | Create a monitor; its first run starts right away |
572
+ | `list` | List monitors (`--status`, `--name`, `--limit`, `--cursor` or `--page-no`) |
573
+ | `get <id>` | Show a monitor, including why it is paused |
574
+ | `update <id>` | Change a monitor; sends only the options given |
575
+ | `pause <id>` / `resume <id>` | Stop or restart scheduled runs |
576
+ | `delete <id>` | Delete a monitor; asks first unless `--yes` |
577
+ | `trigger <id>` | Run it now, outside the schedule |
578
+ | `runs <id>` / `run <id> <run_id>` | List runs, or show one with its items |
579
+ | `events <id>` | What it found (`--run`, `--order-by`, `--limit` 1–20, `--cursor`) |
580
+
581
+ Options of `create` and `update`: `--topic` or `--page` (repeatable), `--field name:type[:description]` (type `string`, `number` or `boolean`, repeatable), `--include-domains` / `--exclude-domains` (topic monitors), `--name`, `--condition`, `--interval` (`5m`–`59m`, `1h`–`100h` or `1d`–`30d`; the API runs it hourly when unset) or `--cron` with `--timezone`, `--webhook`, `--email` (repeatable), `--metadata key=value` (repeatable), and `--params '<json>'` or `--params @file.json` for any other request field. `update` also takes `--status`, `--clear condition,webhook,email,metadata` and `--rotate-secret`; its `--email` replaces all existing recipients and its `--metadata` all existing pairs, so pass every value you want to keep.
582
+
583
+ **Deleting asks first.** In a terminal, `delete` shows the monitor and waits for `y`. In a script or pipe it refuses (exit 2) unless you pass `--yes`.
584
+
585
+ **Webhook secret.** Adding a webhook or `--rotate-secret` returns the signing secret once; the terminal view highlights it, and `--json` includes it. Verify deliveries with the webhook verification function of the Octen SDKs.
586
+
587
+ **Writes are not retried after they may have been sent**, because the API has no idempotency key. The only case where a write is retried is HTTP 429 (up to three retries, the SDK's default), which the API returns without applying the request. If `create`, `update`, `pause`, `resume`, `delete` or `trigger` times out or gets a server error, the request may already have taken effect: check with `octen monitor list` or `get` before trying again (for `trigger`, look for a new manual run with `octen monitor runs <id>`: the monitor's last run only changes once the run finishes). Error messages carry the API code, with a hint for the common ones (for example `409103`: the monitor is paused).
588
+
589
+ Pricing: a topic monitor costs $2 per 1,000 runs and a page monitor $3 per 1,000 runs per URL; skipped and failed runs are free. An account can have up to 30 monitors. See [Monitor](https://docs.octen.ai/capabilities/monitor).
590
+
591
+ ---
592
+
556
593
  ### `octen configure-mcp`
557
594
 
558
595
  Configure the Octen MCP server in AI clients (merges into existing config, does not clobber).
@@ -568,11 +605,11 @@ octen configure-mcp --claude-code --cursor
568
605
  octen configure-mcp --all --pin 0.2.1
569
606
  ```
570
607
 
571
- Supported clients: Claude Code, Claude Desktop, Cursor, Windsurf, VS Code, Codex.
608
+ Supported clients: Claude Code, Claude Desktop, Cursor, Windsurf, VS Code, Codex, Devin (Devin CLI and Devin Desktop).
572
609
 
573
610
  Only clients detected as installed are configured; `--all` skips the rest, and an explicitly-named client that isn't detected is skipped unless you pass `--force`.
574
611
 
575
- Options: `--all`, `--claude-code`, `--cursor`, `--claude-desktop`, `--windsurf`, `--vscode`, `--codex`, `--scope` (user|project), `--pin <version>`, `--force` (configure even if the client is not detected).
612
+ Options: `--all`, `--claude-code`, `--cursor`, `--claude-desktop`, `--windsurf`, `--vscode`, `--codex`, `--devin`, `--scope` (user|project), `--pin <version>`, `--force` (configure even if the client is not detected).
576
613
 
577
614
  Run without flags to print current status for each client.
578
615
 
@@ -586,6 +623,7 @@ than a silent fall back to `user`:
586
623
  | Codex | `$HOME/.codex/config.toml` | `<project>/.codex/config.toml` |
587
624
  | Cursor | `$HOME/.cursor/mcp.json` | `<project>/.cursor/mcp.json` |
588
625
  | VS Code | `<project>/.vscode/mcp.json` | `<project>/.vscode/mcp.json` |
626
+ | Devin | `$HOME/.config/devin/mcp_config.json` (`$XDG_CONFIG_HOME/devin/` when set; Windows: `%APPDATA%\devin\`) | `<project>/.devin/mcp_config.local.json` |
589
627
  | Claude Code, Claude Desktop, Windsurf | user config only | same as user |
590
628
 
591
629
  Codex reads a project-level `.codex/config.toml` only in a repository it has
@@ -593,6 +631,18 @@ been told to trust, so a project-scoped entry stays inert until you trust the
593
631
  directory in Codex. `--scope status` and `reset --scope project` read and remove
594
632
  from the same project file.
595
633
 
634
+ Devin CLI and Devin Local in Devin Desktop read the same files; Devin CLI v3000.3
635
+ (Devin Local 3.6) or later is required, since earlier versions read MCP servers
636
+ from `config.json` instead. For Devin the
637
+ entry points at the hosted server (`https://mcp.octen.ai/mcp` with an `x-api-key`
638
+ header), so it needs no local Node.js, and `--pin` does not apply. Without a key
639
+ it writes `${env:OCTEN_API_KEY}`, which Devin reads from its environment. The
640
+ project scope writes Devin's personal `.devin/mcp_config.local.json` rather than
641
+ the shared `.devin/mcp_config.json`, and always with `${env:OCTEN_API_KEY}` instead
642
+ of the key, because the file can be committed until Devin has excluded it from
643
+ git; export `OCTEN_API_KEY` in the shell you start Devin from. For Devin Cloud,
644
+ add the server in the web app instead (Customize → MCPs).
645
+
596
646
  #### Codex cold start
597
647
 
598
648
  On a machine that has never run `octen-mcp`, `npx -y octen-mcp` has to fetch
@@ -683,7 +733,7 @@ octen reset --skills --claude-code
683
733
  octen reset --credentials
684
734
  ```
685
735
 
686
- Options: `--all` (both surfaces, all clients), `--mcp`, `--skills`, `--credentials`, plus per-client flags: `--claude-code`, `--cursor`, `--claude-desktop`, `--windsurf`, `--vscode`, `--codex`, `--openclaw`, `--hermes`, `--scope` (user|project).
736
+ Options: `--all` (both surfaces, all clients), `--mcp`, `--skills`, `--credentials`, plus per-client flags: `--claude-code`, `--cursor`, `--claude-desktop`, `--windsurf`, `--vscode`, `--codex`, `--devin`, `--openclaw`, `--hermes`, `--scope` (user|project).
687
737
 
688
738
  `--credentials` is **not** included in `--all` — `--all`'s existing meaning is "both
689
739
  surfaces (MCP + skills) across all clients", and folding in the login credential would mean
@@ -26,6 +26,10 @@ export declare class OctenNetworkError extends OctenError {
26
26
  /** A stream that was malformed, truncated, or carried a typed error event. */
27
27
  export declare class OctenStreamError extends OctenError {
28
28
  }
29
+ /** The user answered no to a confirmation prompt; nothing was sent. */
30
+ export declare class OctenCancelledError extends OctenError {
31
+ constructor(message?: string);
32
+ }
29
33
  export declare class OctenAPIError extends OctenError {
30
34
  status: number;
31
35
  body?: unknown | undefined;
@@ -1,3 +1,4 @@
1
+ import { OctenAuthenticationError as SdkAuthenticationError, OctenValidationError as SdkValidationError, } from "@octen.ai/sdk";
1
2
  export class OctenError extends Error {
2
3
  }
3
4
  export class OctenAuthError extends OctenError {
@@ -26,6 +27,10 @@ export class OctenNetworkError extends OctenError {
26
27
  /** A stream that was malformed, truncated, or carried a typed error event. */
27
28
  export class OctenStreamError extends OctenError {
28
29
  }
30
+ /** The user answered no to a confirmation prompt; nothing was sent. */
31
+ export class OctenCancelledError extends OctenError {
32
+ constructor(message = "Cancelled.") { super(message); }
33
+ }
29
34
  export class OctenAPIError extends OctenError {
30
35
  status;
31
36
  body;
@@ -72,5 +77,8 @@ export function errorMessage(payload, fallback) {
72
77
  export function exitCodeFor(err) {
73
78
  if (err instanceof OctenAuthError || err instanceof OctenValidationError)
74
79
  return 2;
80
+ // The monitor commands throw the SDK's own classes, which are not these.
81
+ if (err instanceof SdkValidationError || err instanceof SdkAuthenticationError)
82
+ return 2;
75
83
  return 1;
76
84
  }
package/dist/cli.js CHANGED
@@ -18,6 +18,7 @@ import { registerVlEmbed } from "./commands/vlEmbed.js";
18
18
  import { registerImageSearch } from "./commands/imageSearch.js";
19
19
  import { registerDesignSearch } from "./commands/designSearch.js";
20
20
  import { registerVideoSearch } from "./commands/videoSearch.js";
21
+ import { registerMonitor } from "./commands/monitor/index.js";
21
22
  import { registerConfigureMcp } from "./commands/configureMcp.js";
22
23
  import { registerConfigureSkills } from "./commands/configureSkills.js";
23
24
  import { registerReset } from "./commands/reset.js";
@@ -58,6 +59,7 @@ registerVlEmbed(program);
58
59
  registerImageSearch(program);
59
60
  registerDesignSearch(program);
60
61
  registerVideoSearch(program);
62
+ registerMonitor(program);
61
63
  registerLogin(program);
62
64
  registerLogout(program);
63
65
  registerWhoami(program);
@@ -20,33 +20,79 @@ function buildModel(program) {
20
20
  const subcommands = program.commands.map((c) => c.name());
21
21
  const globalFlags = flagsFor(program.options);
22
22
  const subFlags = {};
23
+ const groups = {};
23
24
  for (const cmd of program.commands) {
24
25
  subFlags[cmd.name()] = flagsFor(cmd.options);
26
+ if (cmd.commands.length) {
27
+ const inner = {};
28
+ for (const c of cmd.commands)
29
+ inner[c.name()] = flagsFor(c.options);
30
+ groups[cmd.name()] = { subcommands: cmd.commands.map((c) => c.name()), subFlags: inner };
31
+ }
25
32
  }
26
- return { subcommands, globalFlags, subFlags };
33
+ const globalValueFlags = flagsFor(program.options.filter((o) => o.required || o.optional));
34
+ return { subcommands, globalFlags, globalValueFlags, subFlags, groups };
35
+ }
36
+ // `case` branches shared by the bash function and the native zsh file. A group nests a
37
+ // second `case` on the next word: its subcommands until one is typed, then that one's flags.
38
+ function caseBranches(model, sub2) {
39
+ return model.subcommands
40
+ .map((sub) => {
41
+ const group = model.groups[sub];
42
+ if (!group) {
43
+ const flags = [...(model.subFlags[sub] ?? []), ...model.globalFlags].join(" ");
44
+ return ` ${sub})\n opts="${flags}"\n ;;`;
45
+ }
46
+ const first = [...group.subcommands, ...(model.subFlags[sub] ?? []), ...model.globalFlags].join(" ");
47
+ const inner = group.subcommands
48
+ .map((c) => ` ${c}) opts="${[...(group.subFlags[c] ?? []), ...model.globalFlags].join(" ")}" ;;`)
49
+ .join("\n");
50
+ return ` ${sub})\n case ${sub2} in\n "") opts="${first}" ;;\n${inner}\n *) opts="${model.globalFlags.join(" ")}" ;;\n esac\n ;;`;
51
+ })
52
+ .join("\n");
27
53
  }
28
54
  /**
29
55
  * The shared bash `_octen` completion function, reused verbatim by the zsh
30
56
  * script (via bashcompinit). Returns the full function plus `complete` line.
31
57
  */
32
- function bashFunction(model) {
58
+ // `lineScan` is bash only: COMP_WORDS there also splits at = and :, and the zsh eval
59
+ // script reuses this function, where neither the substring nor `read -a` works.
60
+ function bashFunction(model, lineScan = true) {
33
61
  const subs = model.subcommands.join(" ");
34
62
  const globals = model.globalFlags.join(" ");
35
63
  // Build the case branches for per-subcommand flag completion.
36
- const branches = model.subcommands
37
- .map((sub) => {
38
- const flags = [...(model.subFlags[sub] ?? []), ...model.globalFlags].join(" ");
39
- return ` ${sub})\n opts="${flags}"\n ;;`;
40
- })
41
- .join("\n");
42
- return `_octen() {
43
- local cur sub i opts
64
+ const branches = caseBranches(model, '"$sub2"');
65
+ const valueFlags = model.globalValueFlags.length ? ` ${model.globalValueFlags.join("|")}) skip=1 ;;\n` : "";
66
+ const scan = lineScan
67
+ ? ` local cur sub sub2 i opts skip line n
68
+ local -a words
69
+ cur="\${COMP_WORDS[COMP_CWORD]}"
70
+ sub=""
71
+ sub2=""
72
+ skip=0
73
+ # COMP_WORDS also splits at = and :, so find the commands in the line split at spaces only.
74
+ cur="\${cur//\\\\$'\\n'/}"
75
+ line="\${COMP_LINE:0:COMP_POINT}"
76
+ line="\${line//\\\\$'\\n'/ }"
77
+ line="\${line//$'\\n'/ }"
78
+ IFS=$' \\t' read -ra words <<< "$line"
79
+ n=\${#words[@]}
80
+ [[ -z "$line" || "$line" == *[[:space:]] ]] && n=$((n+1))
81
+ for (( i=1; i < n-1; i++ )); do`
82
+ : ` local cur sub sub2 i opts skip
83
+ local -a words
44
84
  cur="\${COMP_WORDS[COMP_CWORD]}"
45
85
  sub=""
46
- for (( i=1; i < COMP_CWORD; i++ )); do
47
- case "\${COMP_WORDS[i]}" in
48
- -*) ;;
49
- *) sub="\${COMP_WORDS[i]}"; break ;;
86
+ sub2=""
87
+ skip=0
88
+ words=("\${COMP_WORDS[@]}")
89
+ for (( i=1; i < COMP_CWORD; i++ )); do`;
90
+ return `_octen() {
91
+ ${scan}
92
+ if [ "$skip" = 1 ]; then skip=0; continue; fi
93
+ case "\${words[i]}" in
94
+ ${valueFlags} -*) ;;
95
+ *) if [ -z "$sub" ]; then sub="\${words[i]}"; elif [ -z "$sub2" ]; then sub2="\${words[i]}"; fi ;;
50
96
  esac
51
97
  done
52
98
  if [ -z "$sub" ]; then
@@ -80,7 +126,7 @@ function zshScript(model) {
80
126
  "fi",
81
127
  "autoload -Uz bashcompinit && bashcompinit",
82
128
  ].join("\n");
83
- return `${preamble}\n${bashFunction(model)}\n`;
129
+ return `${preamble}\n${bashFunction(model, false)}\n`;
84
130
  }
85
131
  /** Strip leading dashes for fish's `-l`/`-s` which want bare names. */
86
132
  function fishFlagArgs(flags) {
@@ -107,6 +153,16 @@ function fishScript(model) {
107
153
  if (flagArgs) {
108
154
  lines.push(`complete -c octen -n '__fish_seen_subcommand_from ${sub}' ${flagArgs}`);
109
155
  }
156
+ const group = model.groups[sub];
157
+ if (!group)
158
+ continue;
159
+ const names = group.subcommands.join(" ");
160
+ lines.push(`complete -c octen -f -n '__fish_seen_subcommand_from ${sub}; and not __fish_seen_subcommand_from ${names}' -a '${names}'`);
161
+ for (const c of group.subcommands) {
162
+ const args = fishFlagArgs(group.subFlags[c] ?? []);
163
+ if (args)
164
+ lines.push(`complete -c octen -n '__fish_seen_subcommand_from ${sub}; and __fish_seen_subcommand_from ${c}' ${args}`);
165
+ }
110
166
  }
111
167
  const globalArgs = fishFlagArgs(model.globalFlags);
112
168
  if (globalArgs) {
@@ -124,23 +180,22 @@ function fishScript(model) {
124
180
  function zshCompletionFile(model) {
125
181
  const subs = model.subcommands.join(" ");
126
182
  const globals = model.globalFlags.join(" ");
127
- const branches = model.subcommands
128
- .map((sub) => {
129
- const flags = [...(model.subFlags[sub] ?? []), ...model.globalFlags].join(" ");
130
- return ` ${sub})\n opts="${flags}"\n ;;`;
131
- })
132
- .join("\n");
183
+ const branches = caseBranches(model, "$sub2");
184
+ const valueFlags = model.globalValueFlags.length ? ` ${model.globalValueFlags.join("|")}) skip=1 ;;\n` : "";
133
185
  return `#compdef octen
134
186
  # octen zsh completion (native, fpath-autoloaded). Do not edit by hand;
135
187
  # regenerate with: octen completion zsh --install
136
188
  _octen() {
137
- local cur sub i opts
189
+ local cur sub sub2 i opts skip
138
190
  cur=\${words[CURRENT]}
139
191
  sub=""
192
+ sub2=""
193
+ skip=0
140
194
  for (( i = 2; i < CURRENT; i++ )); do
195
+ if [[ $skip == 1 ]]; then skip=0; continue; fi
141
196
  case \${words[i]} in
142
- -*) ;;
143
- *) sub=\${words[i]}; break ;;
197
+ ${valueFlags} -*) ;;
198
+ *) if [[ -z $sub ]]; then sub=\${words[i]}; elif [[ -z $sub2 ]]; then sub2=\${words[i]}; fi ;;
144
199
  esac
145
200
  done
146
201
  if [[ -z $sub ]]; then
@@ -1,6 +1,6 @@
1
1
  import os from "node:os";
2
2
  import pc from "picocolors";
3
- import { MCP_CLIENTS } from "../mcp/clients.js";
3
+ import { HOSTED_MCP_URL, MCP_CLIENTS } from "../mcp/clients.js";
4
4
  import { installMcp } from "../mcp/install.js";
5
5
  import { mcpStatus } from "../mcp/detect.js";
6
6
  import { resolveApiKey } from "../config/resolve.js";
@@ -20,6 +20,7 @@ export function registerConfigureMcp(program, internal = {}) {
20
20
  .option("--windsurf", "configure Windsurf")
21
21
  .option("--vscode", "configure VS Code")
22
22
  .option("--codex", "configure Codex")
23
+ .option("--devin", "configure Devin (CLI and Devin Desktop)")
23
24
  .option("--scope <s>", "config scope: user | project (default: user)", parseScopeOpt("--scope"), "user")
24
25
  .option("--pin <ver>", "pin octen-mcp to a specific version, e.g. 0.2.1")
25
26
  .option("--force", "configure even if the client is not detected")
@@ -45,6 +46,7 @@ export function registerConfigureMcp(program, internal = {}) {
45
46
  windsurf: "windsurf",
46
47
  vscode: "vscode",
47
48
  codex: "codex",
49
+ devin: "devin",
48
50
  };
49
51
  const anySelected = opts.all ||
50
52
  opts.claudeCode ||
@@ -52,7 +54,8 @@ export function registerConfigureMcp(program, internal = {}) {
52
54
  opts.claudeDesktop ||
53
55
  opts.windsurf ||
54
56
  opts.vscode ||
55
- opts.codex;
57
+ opts.codex ||
58
+ opts.devin;
56
59
  if (!anySelected) {
57
60
  // STATUS MODE: print status for each client
58
61
  for (const client of MCP_CLIENTS) {
@@ -89,6 +92,12 @@ export function registerConfigureMcp(program, internal = {}) {
89
92
  args: ["-y", pin ? `octen-mcp@${pin}` : "octen-mcp"],
90
93
  env: { OCTEN_API_KEY: key },
91
94
  };
95
+ // Hosted clients reach mcp.octen.ai directly. Devin expands ${env:VAR}, not ${VAR}, in headers.
96
+ // A project file can be committed, so it never gets the key itself.
97
+ const envRef = (c) => c.hosted && (keyMissing || scope === "project");
98
+ const entryFor = (c) => c.hosted
99
+ ? { url: HOSTED_MCP_URL, headers: { "x-api-key": envRef(c) ? "${env:OCTEN_API_KEY}" : key } }
100
+ : entry;
92
101
  // Determine which clients to act on, gated by detection.
93
102
  let selected;
94
103
  if (opts.all) {
@@ -121,10 +130,13 @@ export function registerConfigureMcp(program, internal = {}) {
121
130
  process.stdout.write("no installed clients to configure\n");
122
131
  return;
123
132
  }
133
+ if (pin && selected.some((c) => c.hosted)) {
134
+ process.stderr.write(`note: --pin does not apply to ${selected.filter((c) => c.hosted).map((c) => c.label).join(", ")}, which use the hosted server\n`);
135
+ }
124
136
  let anyFailed = false;
125
137
  for (const client of selected) {
126
138
  try {
127
- const result = installMcp(client, scope, entry, home, cwd, installOpts);
139
+ const result = installMcp(client, scope, entryFor(client), home, cwd, installOpts);
128
140
  if (result.method === "claude-cli") {
129
141
  process.stdout.write(`${client.label}: configured via claude CLI\n`);
130
142
  }
@@ -144,5 +156,8 @@ export function registerConfigureMcp(program, internal = {}) {
144
156
  if (keyMissing) {
145
157
  process.stderr.write("warning: no API key found — set OCTEN_API_KEY in each client's environment\n");
146
158
  }
159
+ else if (scope === "project" && selected.some((c) => c.hosted)) {
160
+ process.stderr.write(`note: ${selected.filter((c) => c.hosted).map((c) => c.label).join(", ")} project config references \${env:OCTEN_API_KEY} instead of the key; export OCTEN_API_KEY in the shell you start it from\n`);
161
+ }
147
162
  });
148
163
  }
@@ -0,0 +1,6 @@
1
+ import Octen from "@octen.ai/sdk";
2
+ /** SDK client for the monitor commands; the SDK owns retries and request checks. */
3
+ export declare function makeMonitorClient(g: {
4
+ apiKey?: string;
5
+ baseUrl?: string;
6
+ }): Octen;
@@ -0,0 +1,9 @@
1
+ import Octen from "@octen.ai/sdk";
2
+ import { resolveApiKey, resolveBaseUrl } from "../../config/resolve.js";
3
+ /** SDK client for the monitor commands; the SDK owns retries and request checks. */
4
+ export function makeMonitorClient(g) {
5
+ return new Octen({
6
+ apiKey: resolveApiKey(g.apiKey, process.env),
7
+ baseURL: resolveBaseUrl(g.baseUrl, process.env),
8
+ });
9
+ }
@@ -0,0 +1,5 @@
1
+ /** Ask a yes/no question; only "y" or "yes" counts as yes, and input that ends unanswered (Ctrl-D) is no. */
2
+ export declare function confirm(question: string, io?: {
3
+ input: NodeJS.ReadableStream;
4
+ output: NodeJS.WritableStream;
5
+ }): Promise<boolean>;
@@ -0,0 +1,19 @@
1
+ import { createInterface } from "node:readline";
2
+ /** Ask a yes/no question; only "y" or "yes" counts as yes, and input that ends unanswered (Ctrl-D) is no. */
3
+ export function confirm(question, io = { input: process.stdin, output: process.stderr }) {
4
+ // The prompt goes to stderr so stdout stays clean for output.
5
+ const rl = createInterface({ input: io.input, output: io.output });
6
+ return new Promise((resolve) => {
7
+ let answered = false;
8
+ rl.on("close", () => {
9
+ if (!answered)
10
+ resolve(false);
11
+ });
12
+ rl.question(question, (answer) => {
13
+ answered = true;
14
+ rl.close();
15
+ const a = answer.trim().toLowerCase();
16
+ resolve(a === "y" || a === "yes");
17
+ });
18
+ });
19
+ }
@@ -0,0 +1,5 @@
1
+ /** What to do when a write may or may not have been applied: check before retrying. */
2
+ export declare const mayHaveApplied: (check: string) => string;
3
+ export declare function annotateMonitorError(err: unknown, write: boolean, advice?: string): unknown;
4
+ /** A write answered "success" without the field it must return: it may or may not have been applied. */
5
+ export declare function incompleteReply(field: string, advice?: string): Error;
@@ -0,0 +1,38 @@
1
+ import { OctenAPIError as CliAPIError } from "../../api/errors.js";
2
+ import { OctenAPIError, OctenConnectionError, OctenError, OctenServerError, OctenTimeoutError, } from "@octen.ai/sdk";
3
+ const HINTS = {
4
+ 409103: "The monitor is paused; resume it first with `octen monitor resume <id>`.",
5
+ 409101: "A run is still in progress; wait for it to finish before triggering again.",
6
+ 429101: "Less than 3 seconds since the last manual trigger; wait a few seconds.",
7
+ 404101: "The monitor does not exist; check the id with `octen monitor list`.",
8
+ 409102: "A concurrent update conflicted; get the monitor again and redo your change on its current settings before retrying (--email and --metadata replace whole values).",
9
+ 400101: "The account already has 30 monitors (deleted ones don't count); delete the ones you no longer need.",
10
+ };
11
+ /** What to do when a write may or may not have been applied: check before retrying. */
12
+ export const mayHaveApplied = (check) => `The request may already have taken effect; check with ${check} before retrying.`;
13
+ const DEFAULT_ADVICE = mayHaveApplied("`octen monitor list` or `octen monitor get`");
14
+ // Adds the server code and a hint to an SDK error in place, so its class (and exit code) is kept.
15
+ // `write` marks calls the SDK does not retry once sent (create, update, pause, resume, delete, trigger).
16
+ export function annotateMonitorError(err, write, advice = DEFAULT_ADVICE) {
17
+ if (!(err instanceof OctenError))
18
+ return err;
19
+ const lines = [err.message];
20
+ if (err instanceof OctenAPIError && err.code !== null) {
21
+ lines[0] = `${err.message} (code ${err.code})`;
22
+ if (HINTS[err.code])
23
+ lines.push(HINTS[err.code]);
24
+ }
25
+ // A connection error does not say whether the request was sent, and an unreadable 2xx means it was applied.
26
+ const unreadableSuccess = err instanceof OctenAPIError && err.status >= 200 && err.status < 300 && err.code === null;
27
+ // The SDK reports a 408 as a plain API error, but the request may have been applied.
28
+ const timedOut = err instanceof OctenAPIError && err.status === 408;
29
+ if (write && (err instanceof OctenTimeoutError || err instanceof OctenConnectionError || err instanceof OctenServerError || unreadableSuccess || timedOut)) {
30
+ lines.push(advice);
31
+ }
32
+ err.message = lines.join("\n");
33
+ return err;
34
+ }
35
+ /** A write answered "success" without the field it must return: it may or may not have been applied. */
36
+ export function incompleteReply(field, advice = DEFAULT_ADVICE) {
37
+ return new CliAPIError(`The API reported success but returned no ${field}.\n${advice}`, 200);
38
+ }
@@ -0,0 +1,13 @@
1
+ import type { Command } from "commander";
2
+ type Globals = {
3
+ apiKey?: string;
4
+ baseUrl?: string;
5
+ json?: boolean;
6
+ pretty?: boolean;
7
+ };
8
+ export declare function globalsOf(command: Command): Globals;
9
+ export declare function output(g: Globals, res: unknown, render: (d: any) => string): void;
10
+ /** Run one SDK call; `write` marks calls the SDK does not retry once sent. */
11
+ export declare function call<T>(write: boolean, fn: () => Promise<T>, advice?: string): Promise<T>;
12
+ export declare function registerMonitor(program: Command): void;
13
+ export {};