@andocorp/cli 0.3.1 → 0.5.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 +62 -146
- package/dist/cli.js +17053 -0
- package/package.json +24 -27
- package/LICENSE +0 -21
- package/dist/agent-commands.js +0 -297
- package/dist/api-command.js +0 -212
- package/dist/api-inputs.js +0 -223
- package/dist/api-operations.js +0 -344
- package/dist/args.js +0 -71
- package/dist/auth-commands.js +0 -362
- package/dist/cli-helpers.js +0 -67
- package/dist/cli-login-browser.js +0 -60
- package/dist/cli-login-errors.js +0 -10
- package/dist/cli-login-paths.js +0 -8
- package/dist/cli-login-revoke.js +0 -100
- package/dist/cli-login.js +0 -335
- package/dist/client.js +0 -104
- package/dist/commands.js +0 -155
- package/dist/config-credential-metadata.js +0 -68
- package/dist/config-keyring.js +0 -61
- package/dist/config-logout-credentials.js +0 -171
- package/dist/config-paths.js +0 -41
- package/dist/config-types.js +0 -1
- package/dist/config.js +0 -333
- package/dist/format.js +0 -297
- package/dist/help.js +0 -84
- package/dist/index.js +0 -101
- package/dist/output.js +0 -7
- package/dist/session.js +0 -58
- package/dist/timeouts.js +0 -1
- package/dist/types.js +0 -1
- package/dist/watch-commands.js +0 -121
- package/dist/webhook-commands.js +0 -360
package/dist/format.js
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
const LINK_START_MARKER = "\u0000";
|
|
2
|
-
const LINK_END_MARKER = "\u0001";
|
|
3
|
-
const LINK_SEPARATOR_MARKER = "\u0002";
|
|
4
|
-
const ANSI_RESET = "\u001b[0m";
|
|
5
|
-
const ANSI_LINK = "\u001b[34m";
|
|
6
|
-
const ANSI_CURRENT_MEMBER = "\u001b[38;2;0;224;224m";
|
|
7
|
-
const ANSI_ESCAPE_PATTERN = new RegExp(`${ANSI_RESET[0]}\\[[0-9;]*m`, "g");
|
|
8
|
-
const ANSI_ESCAPE_AT_START_PATTERN = new RegExp(`^${ANSI_RESET[0]}\\[[0-9;]*m`);
|
|
9
|
-
function pad(value) {
|
|
10
|
-
return value.toString().padStart(2, "0");
|
|
11
|
-
}
|
|
12
|
-
function stripLinkMarkers(text) {
|
|
13
|
-
let result = "";
|
|
14
|
-
let index = 0;
|
|
15
|
-
while (index < text.length) {
|
|
16
|
-
const character = text[index];
|
|
17
|
-
if (character == null) {
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
if (character === LINK_START_MARKER) {
|
|
21
|
-
index += 1;
|
|
22
|
-
while (index < text.length && text[index] !== LINK_SEPARATOR_MARKER) {
|
|
23
|
-
index += 1;
|
|
24
|
-
}
|
|
25
|
-
if (text[index] === LINK_SEPARATOR_MARKER) {
|
|
26
|
-
index += 1;
|
|
27
|
-
}
|
|
28
|
-
while (index < text.length && text[index] !== LINK_END_MARKER) {
|
|
29
|
-
const linkCharacter = text[index];
|
|
30
|
-
if (linkCharacter != null) {
|
|
31
|
-
result += linkCharacter;
|
|
32
|
-
}
|
|
33
|
-
index += 1;
|
|
34
|
-
}
|
|
35
|
-
if (text[index] === LINK_END_MARKER) {
|
|
36
|
-
index += 1;
|
|
37
|
-
}
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
if (character !== LINK_END_MARKER && character !== LINK_SEPARATOR_MARKER) {
|
|
41
|
-
result += character;
|
|
42
|
-
}
|
|
43
|
-
index += 1;
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
function stripAnsi(text) {
|
|
48
|
-
return text.replace(ANSI_ESCAPE_PATTERN, "");
|
|
49
|
-
}
|
|
50
|
-
export function getVisibleText(text) {
|
|
51
|
-
return stripAnsi(stripLinkMarkers(text));
|
|
52
|
-
}
|
|
53
|
-
export function getVisibleTextLength(text) {
|
|
54
|
-
return getVisibleText(text).length;
|
|
55
|
-
}
|
|
56
|
-
export function renderTerminalText(text) {
|
|
57
|
-
let rendered = "";
|
|
58
|
-
let index = 0;
|
|
59
|
-
while (index < text.length) {
|
|
60
|
-
const character = text[index];
|
|
61
|
-
if (character == null) {
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
if (character === LINK_START_MARKER) {
|
|
65
|
-
index += 1;
|
|
66
|
-
while (index < text.length && text[index] !== LINK_SEPARATOR_MARKER) {
|
|
67
|
-
index += 1;
|
|
68
|
-
}
|
|
69
|
-
if (text[index] === LINK_SEPARATOR_MARKER) {
|
|
70
|
-
index += 1;
|
|
71
|
-
}
|
|
72
|
-
rendered += ANSI_LINK;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
if (character === LINK_END_MARKER) {
|
|
76
|
-
rendered += ANSI_RESET;
|
|
77
|
-
index += 1;
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
if (character !== LINK_SEPARATOR_MARKER) {
|
|
81
|
-
rendered += character;
|
|
82
|
-
}
|
|
83
|
-
index += 1;
|
|
84
|
-
}
|
|
85
|
-
return rendered;
|
|
86
|
-
}
|
|
87
|
-
function formatLink(url, label) {
|
|
88
|
-
return `${LINK_START_MARKER}${url}${LINK_SEPARATOR_MARKER}${label}${LINK_END_MARKER}`;
|
|
89
|
-
}
|
|
90
|
-
function isUrlLikeText(text) {
|
|
91
|
-
try {
|
|
92
|
-
const url = new URL(text);
|
|
93
|
-
return url.protocol === "http:" || url.protocol === "https:";
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
function getLinkLabel(part) {
|
|
100
|
-
const childText = part.label.trim();
|
|
101
|
-
if (childText === "") {
|
|
102
|
-
return part.url;
|
|
103
|
-
}
|
|
104
|
-
if (childText === part.url || isUrlLikeText(childText)) {
|
|
105
|
-
return childText;
|
|
106
|
-
}
|
|
107
|
-
return childText;
|
|
108
|
-
}
|
|
109
|
-
function parseMarkdownParts(markdown) {
|
|
110
|
-
const parts = [];
|
|
111
|
-
const pattern = /(!?)\[([^\]]*)\]\(([^)]+)\)|\n/g;
|
|
112
|
-
let lastIndex = 0;
|
|
113
|
-
let match;
|
|
114
|
-
while ((match = pattern.exec(markdown)) != null) {
|
|
115
|
-
if (match.index > lastIndex) {
|
|
116
|
-
parts.push({
|
|
117
|
-
type: "text",
|
|
118
|
-
value: markdown.slice(lastIndex, match.index),
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
const raw = match[0];
|
|
122
|
-
if (raw === "\n") {
|
|
123
|
-
parts.push({ type: "linebreak" });
|
|
124
|
-
}
|
|
125
|
-
else if (match[1] === "!") {
|
|
126
|
-
parts.push({
|
|
127
|
-
type: "image",
|
|
128
|
-
alt: match[2] ?? "",
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
parts.push({
|
|
133
|
-
type: "link",
|
|
134
|
-
label: match[2] ?? "",
|
|
135
|
-
url: match[3] ?? "",
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
lastIndex = pattern.lastIndex;
|
|
139
|
-
}
|
|
140
|
-
if (lastIndex < markdown.length) {
|
|
141
|
-
parts.push({
|
|
142
|
-
type: "text",
|
|
143
|
-
value: markdown.slice(lastIndex),
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
return parts;
|
|
147
|
-
}
|
|
148
|
-
function getMessageBodyText(markdown) {
|
|
149
|
-
return parseMarkdownParts(markdown)
|
|
150
|
-
.map((part) => {
|
|
151
|
-
switch (part.type) {
|
|
152
|
-
case "text":
|
|
153
|
-
return part.value;
|
|
154
|
-
case "linebreak":
|
|
155
|
-
return "\n";
|
|
156
|
-
case "image":
|
|
157
|
-
return part.alt || "Image";
|
|
158
|
-
case "link":
|
|
159
|
-
return formatLink(part.url, getLinkLabel(part));
|
|
160
|
-
}
|
|
161
|
-
})
|
|
162
|
-
.join("");
|
|
163
|
-
}
|
|
164
|
-
function formatDateTime(value) {
|
|
165
|
-
if (value == null) {
|
|
166
|
-
return "";
|
|
167
|
-
}
|
|
168
|
-
const date = new Date(value);
|
|
169
|
-
if (Number.isNaN(date.getTime())) {
|
|
170
|
-
return "";
|
|
171
|
-
}
|
|
172
|
-
return `${pad(date.getDate())}/${pad(date.getMonth() + 1)} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
173
|
-
}
|
|
174
|
-
function truncate(text, width) {
|
|
175
|
-
if (width <= 0) {
|
|
176
|
-
return "";
|
|
177
|
-
}
|
|
178
|
-
const visibleText = getVisibleText(text);
|
|
179
|
-
if (visibleText.length <= width) {
|
|
180
|
-
return text;
|
|
181
|
-
}
|
|
182
|
-
if (width <= 1) {
|
|
183
|
-
return visibleText.slice(0, width);
|
|
184
|
-
}
|
|
185
|
-
let visibleCount = 0;
|
|
186
|
-
let result = "";
|
|
187
|
-
for (let index = 0; index < text.length; index += 1) {
|
|
188
|
-
const character = text[index];
|
|
189
|
-
if (character == null) {
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
if (character === "\u001b") {
|
|
193
|
-
const ansiMatch = ANSI_ESCAPE_AT_START_PATTERN.exec(text.slice(index));
|
|
194
|
-
if (ansiMatch != null) {
|
|
195
|
-
result += ansiMatch[0];
|
|
196
|
-
index += ansiMatch[0].length - 1;
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (character === LINK_START_MARKER || character === LINK_END_MARKER) {
|
|
201
|
-
result += character;
|
|
202
|
-
if (character === LINK_START_MARKER) {
|
|
203
|
-
index += 1;
|
|
204
|
-
while (index < text.length) {
|
|
205
|
-
const linkCharacter = text[index];
|
|
206
|
-
if (linkCharacter == null) {
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
result += linkCharacter;
|
|
210
|
-
if (linkCharacter === LINK_SEPARATOR_MARKER) {
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
index += 1;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
if (visibleCount >= width - 1) {
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
result += character;
|
|
222
|
-
visibleCount += 1;
|
|
223
|
-
}
|
|
224
|
-
return `${result}…`;
|
|
225
|
-
}
|
|
226
|
-
export function getMessageBody(message) {
|
|
227
|
-
const body = message.markdown_content?.trim();
|
|
228
|
-
if (body) {
|
|
229
|
-
return getMessageBodyText(body).replace(/\s+/g, " ").trim();
|
|
230
|
-
}
|
|
231
|
-
if (message.image_urls.length > 0) {
|
|
232
|
-
return `[${message.image_urls.length} image attachment${message.image_urls.length === 1 ? "" : "s"}]`;
|
|
233
|
-
}
|
|
234
|
-
if (message.files.length > 0) {
|
|
235
|
-
return `[${message.files.length} file attachment${message.files.length === 1 ? "" : "s"}]`;
|
|
236
|
-
}
|
|
237
|
-
if (message.call_id != null) {
|
|
238
|
-
return "[Jam started]";
|
|
239
|
-
}
|
|
240
|
-
return "[empty message]";
|
|
241
|
-
}
|
|
242
|
-
export function formatReactionSummary(message) {
|
|
243
|
-
const reactions = "message_reactions" in message ? message.message_reactions : message.reactions;
|
|
244
|
-
if (reactions.length === 0) {
|
|
245
|
-
return "";
|
|
246
|
-
}
|
|
247
|
-
const groupedEmojis = [];
|
|
248
|
-
let currentEmoji = "";
|
|
249
|
-
let currentCount = 0;
|
|
250
|
-
const pushCurrentEmoji = () => {
|
|
251
|
-
if (currentCount === 0) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
groupedEmojis.push(currentEmoji.repeat(currentCount));
|
|
255
|
-
};
|
|
256
|
-
for (const reaction of reactions) {
|
|
257
|
-
const count = "count" in reaction && typeof reaction.count === "number" ? reaction.count : 1;
|
|
258
|
-
if (reaction.emoji_text === currentEmoji) {
|
|
259
|
-
currentCount += count;
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
pushCurrentEmoji();
|
|
263
|
-
currentEmoji = reaction.emoji_text;
|
|
264
|
-
currentCount = count;
|
|
265
|
-
}
|
|
266
|
-
pushCurrentEmoji();
|
|
267
|
-
return groupedEmojis.join(" ");
|
|
268
|
-
}
|
|
269
|
-
function formatMessageFooter(message) {
|
|
270
|
-
const parts = [];
|
|
271
|
-
const reactions = formatReactionSummary(message);
|
|
272
|
-
if (message.replies_count > 0) {
|
|
273
|
-
parts.push(`[${message.replies_count} ${message.replies_count === 1 ? "reply" : "replies"}]`);
|
|
274
|
-
}
|
|
275
|
-
if (reactions !== "") {
|
|
276
|
-
parts.push(reactions);
|
|
277
|
-
}
|
|
278
|
-
return parts.join(" ");
|
|
279
|
-
}
|
|
280
|
-
function getMessageAuthorLabel(message) {
|
|
281
|
-
return (message.author.display_name ??
|
|
282
|
-
("email" in message.author ? message.author.email : null) ??
|
|
283
|
-
"Unknown");
|
|
284
|
-
}
|
|
285
|
-
export function formatMessageLine(message, options) {
|
|
286
|
-
const author = truncate(getMessageAuthorLabel(message), 20);
|
|
287
|
-
const parts = [
|
|
288
|
-
formatDateTime(message.created_at),
|
|
289
|
-
options?.currentMemberId != null && message.author.id === options.currentMemberId
|
|
290
|
-
? `${ANSI_CURRENT_MEMBER}${author}${ANSI_RESET}`
|
|
291
|
-
: author,
|
|
292
|
-
getMessageBody(message),
|
|
293
|
-
];
|
|
294
|
-
const footer = formatMessageFooter(message);
|
|
295
|
-
const footerSuffix = footer === "" ? "" : ` | ${footer}`;
|
|
296
|
-
return renderTerminalText(`${parts.filter(Boolean).join(" | ")}${footerSuffix}`);
|
|
297
|
-
}
|
package/dist/help.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { getConfigPath } from "./config.js";
|
|
2
|
-
export function buildHelpText() {
|
|
3
|
-
return `
|
|
4
|
-
ando
|
|
5
|
-
|
|
6
|
-
Usage:
|
|
7
|
-
ando help
|
|
8
|
-
ando login [--no-browser] [--base-url <url>] [--api-host <url>] [--realtime-host <host>]
|
|
9
|
-
ando login poll
|
|
10
|
-
ando login --api-key <key> [--base-url <url>] [--api-host <url>] [--realtime-host <host>]
|
|
11
|
-
ando logout
|
|
12
|
-
ando doctor [--json]
|
|
13
|
-
ando whoami [--json]
|
|
14
|
-
|
|
15
|
-
Agent-first commands:
|
|
16
|
-
ando api ls [--json]
|
|
17
|
-
ando api <path|operation-id> [--method|-X <method>] [--data|-d <json|->]
|
|
18
|
-
[name==value] [Header:Value] [field=value] [field:=json]
|
|
19
|
-
ando api <path|operation-id> --help
|
|
20
|
-
ando api <path|operation-id> --spec
|
|
21
|
-
ando messages (--channel <query> | --dm <query> | --conversation <id>) [--limit|-m <n>] [--before <cursor>] [--json]
|
|
22
|
-
ando search <query> [--type messages|members|conversations|clipboard|calls]
|
|
23
|
-
[--author <id>[,<id>]] [--conversation <id>[,<id>]] [--thread <id>]
|
|
24
|
-
[--after <iso>] [--before <iso>] [--mode full-text|semantic] [--json]
|
|
25
|
-
ando get message <message-id> [--json]
|
|
26
|
-
ando get member <member-id> [--json]
|
|
27
|
-
ando get clipboard <clipboard-id> [--json]
|
|
28
|
-
ando get call <call-id> [--json]
|
|
29
|
-
ando get transcript <call-id> [--limit <n>] [--cursor <cursor>] [--json]
|
|
30
|
-
ando thread <thread-root-message-id> [--limit <n>] [--after <cursor>] [--json]
|
|
31
|
-
ando thread -m <message-id> [--json]
|
|
32
|
-
ando watch messages [--delivery messages|mentions] [--limit|-n <n>] [--timeout <ms>] [--json]
|
|
33
|
-
ando webhooks endpoints list [--json]
|
|
34
|
-
ando webhooks endpoints create --url <url> --events <csv> [--name <name>] [--include-direct-messages] [--json]
|
|
35
|
-
ando webhooks endpoints get <endpoint-id> [--json]
|
|
36
|
-
ando webhooks endpoints update <endpoint-id> [--url <url>] [--events <csv>] [--name <name>] [--include-direct-messages|--exclude-direct-messages] [--json]
|
|
37
|
-
ando webhooks endpoints disable <endpoint-id> [--json]
|
|
38
|
-
ando webhooks endpoints rotate-secret <endpoint-id> [--previous-secret-ttl <seconds>] [--json]
|
|
39
|
-
ando webhooks endpoints test <endpoint-id> [--json]
|
|
40
|
-
ando webhooks endpoints test <endpoint-id> --watch-delivery [--timeout <ms>]
|
|
41
|
-
ando webhooks deliveries list [--endpoint <id>] [--event <id>] [--status <status>] [--limit|-n <n>] [--json]
|
|
42
|
-
ando webhooks deliveries replay <delivery-id> [--json]
|
|
43
|
-
|
|
44
|
-
Authentication:
|
|
45
|
-
login opens a browser authorization page, shows a verification code, and stores
|
|
46
|
-
the returned Ando API key in the system keyring by default. Non-secret config
|
|
47
|
-
metadata is stored in:
|
|
48
|
-
${getConfigPath()}
|
|
49
|
-
logout revokes browser-created CLI credentials before removing local auth
|
|
50
|
-
state. API keys supplied manually or through ANDO_API_KEY remain local-only.
|
|
51
|
-
Use --api-key or ANDO_API_KEY for headless scripts and CI. Set ANDO_KEYRING=0
|
|
52
|
-
to use file-based auth instead of the system keyring.
|
|
53
|
-
|
|
54
|
-
Environment:
|
|
55
|
-
ANDO_API_KEY API key for SDK and public API requests
|
|
56
|
-
ANDO_KEYRING Set to 0 to use file-based auth instead of keyring
|
|
57
|
-
ANDO_HOME Config and auth state directory
|
|
58
|
-
ANDO_BASE_URL Login and SDK REST base URL (default: https://api.ando.so)
|
|
59
|
-
ANDO_API_HOST Public API base URL for agent-first commands (default: https://api.ando.so/v1)
|
|
60
|
-
ANDO_REALTIME_HOST Realtime host for SDK subscriptions
|
|
61
|
-
|
|
62
|
-
Examples:
|
|
63
|
-
ando login
|
|
64
|
-
ando login --no-browser
|
|
65
|
-
ando login --api-key ando_sk_...
|
|
66
|
-
ando doctor
|
|
67
|
-
ando whoami
|
|
68
|
-
ando logout
|
|
69
|
-
ando api ls
|
|
70
|
-
ando api searchMessages q==incident mode==semantic
|
|
71
|
-
ando api getMember memberId=<member-id>
|
|
72
|
-
ando api /v1/search/messages q==incident mode==semantic
|
|
73
|
-
echo '{"markdown_content":"hello"}' | ando api /v1/conversations/<conversation-id>/messages --data -
|
|
74
|
-
ando messages -c engineering -m 20
|
|
75
|
-
ando search "incident" --type messages --mode semantic
|
|
76
|
-
ando get message <message-id>
|
|
77
|
-
ando thread <thread-root-message-id> --limit 50
|
|
78
|
-
ando watch messages --limit 1 --json
|
|
79
|
-
ando webhooks endpoints create --url https://example.com/ando/webhooks --events webhook.test,message.created --include-direct-messages
|
|
80
|
-
ando webhooks endpoints rotate-secret <endpoint-id> --previous-secret-ttl 3600
|
|
81
|
-
ando webhooks endpoints test <endpoint-id> --watch-delivery
|
|
82
|
-
ando webhooks deliveries list --endpoint <endpoint-id> --status failed
|
|
83
|
-
`.trim();
|
|
84
|
-
}
|
package/dist/index.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { AndoClient, resolveAndoPublicApiBaseUrl } from "@andocorp/sdk";
|
|
3
|
-
import { runAgentThreadCommand, runGetCommand, runMessagesCommand, runSearchCommand, } from "./agent-commands.js";
|
|
4
|
-
import { runApiCommand } from "./api-command.js";
|
|
5
|
-
import { hasFlag, parseArgs } from "./args.js";
|
|
6
|
-
import { runDoctor, runLogout, runWhoami } from "./auth-commands.js";
|
|
7
|
-
import { createAndoCliClient, createCliDiagnosticsSink } from "./client.js";
|
|
8
|
-
import { runLogin } from "./commands.js";
|
|
9
|
-
import { printHelp } from "./output.js";
|
|
10
|
-
import { ensureConfig, getConfiguredApiHost } from "./session.js";
|
|
11
|
-
import { DEFAULT_CLI_REQUEST_TIMEOUT_MS } from "./timeouts.js";
|
|
12
|
-
import { runWebhookCommand } from "./webhook-commands.js";
|
|
13
|
-
import { runWatchCommand } from "./watch-commands.js";
|
|
14
|
-
const cliCommandHandlers = new Map([
|
|
15
|
-
[
|
|
16
|
-
"watch",
|
|
17
|
-
async ({ client, parsedArgs }) => runWatchCommand({ apiClient: client, parsedArgs }),
|
|
18
|
-
],
|
|
19
|
-
]);
|
|
20
|
-
const apiCommandHandlers = new Map([
|
|
21
|
-
["get", runGetCommand],
|
|
22
|
-
[
|
|
23
|
-
"messages",
|
|
24
|
-
async ({ apiClient, client, parsedArgs }) => runMessagesCommand({ apiClient, cliClient: client, parsedArgs }),
|
|
25
|
-
],
|
|
26
|
-
[
|
|
27
|
-
"search",
|
|
28
|
-
async ({ apiClient, parsedArgs }) => runSearchCommand({ apiClient, parsedArgs }),
|
|
29
|
-
],
|
|
30
|
-
["thread", runAgentThreadCommand],
|
|
31
|
-
[
|
|
32
|
-
"webhooks",
|
|
33
|
-
async ({ apiClient, parsedArgs }) => runWebhookCommand({ apiClient, parsedArgs }),
|
|
34
|
-
],
|
|
35
|
-
]);
|
|
36
|
-
function createApiClient(config, parsedArgs) {
|
|
37
|
-
return new AndoClient({
|
|
38
|
-
auth: {
|
|
39
|
-
apiKey: config.apiKey,
|
|
40
|
-
},
|
|
41
|
-
baseUrl: resolveAndoPublicApiBaseUrl(getConfiguredApiHost(parsedArgs, config.apiHost)),
|
|
42
|
-
diagnostics: createCliDiagnosticsSink(),
|
|
43
|
-
requestTimeoutMs: DEFAULT_CLI_REQUEST_TIMEOUT_MS,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
async function runCommand() {
|
|
47
|
-
const parsedArgs = parseArgs(process.argv.slice(2));
|
|
48
|
-
const command = parsedArgs.positionals[0];
|
|
49
|
-
if (command === "help" || (command !== "api" && hasFlag(parsedArgs, "help", "h"))) {
|
|
50
|
-
printHelp();
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (command === "login") {
|
|
54
|
-
await runLogin(parsedArgs);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (command === "logout") {
|
|
58
|
-
await runLogout();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (command === "doctor") {
|
|
62
|
-
await runDoctor(parsedArgs);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (command === "whoami") {
|
|
66
|
-
await runWhoami(parsedArgs);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (command == null) {
|
|
70
|
-
printHelp();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (command === "api") {
|
|
74
|
-
await runApiCommand({
|
|
75
|
-
parsedArgs,
|
|
76
|
-
loadConfig: async () => ensureConfig({ command, parsedArgs }),
|
|
77
|
-
});
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const config = await ensureConfig({ command, parsedArgs });
|
|
81
|
-
const client = createAndoCliClient(config);
|
|
82
|
-
const cliHandler = cliCommandHandlers.get(command);
|
|
83
|
-
if (cliHandler != null) {
|
|
84
|
-
await cliHandler({ client, parsedArgs });
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const apiHandler = apiCommandHandlers.get(command);
|
|
88
|
-
if (apiHandler != null) {
|
|
89
|
-
await apiHandler({
|
|
90
|
-
apiClient: createApiClient(config, parsedArgs),
|
|
91
|
-
client,
|
|
92
|
-
parsedArgs,
|
|
93
|
-
});
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
throw new Error(`Unknown command: ${command}`);
|
|
97
|
-
}
|
|
98
|
-
void runCommand().catch((error) => {
|
|
99
|
-
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
100
|
-
process.exit(1);
|
|
101
|
-
});
|
package/dist/output.js
DELETED
package/dist/session.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_ANDO_PUBLIC_API_BASE_URL } from "@andocorp/sdk";
|
|
2
|
-
import { getStringFlag } from "./args.js";
|
|
3
|
-
import { readSavedConfig, readSavedConfigMetadata } from "./config.js";
|
|
4
|
-
const LOGIN_REQUIRED_ERROR = `API key is required. Run "ando login" or set ANDO_API_KEY.`;
|
|
5
|
-
function getOptionalStringFlag(parsedArgs, name) {
|
|
6
|
-
const value = getStringFlag(parsedArgs, name);
|
|
7
|
-
return value == null || value.trim() === "" ? null : value.trim();
|
|
8
|
-
}
|
|
9
|
-
function getOptionalStringEnv(name) {
|
|
10
|
-
const value = process.env[name];
|
|
11
|
-
return value == null || value.trim() === "" ? null : value.trim();
|
|
12
|
-
}
|
|
13
|
-
function getExplicitApiKey(parsedArgs) {
|
|
14
|
-
return (getOptionalStringFlag(parsedArgs, "api-key") ?? getOptionalStringEnv("ANDO_API_KEY"));
|
|
15
|
-
}
|
|
16
|
-
export function getConfiguredBaseUrl(parsedArgs, savedBaseUrl) {
|
|
17
|
-
return (getOptionalStringFlag(parsedArgs, "base-url") ??
|
|
18
|
-
getOptionalStringEnv("ANDO_BASE_URL") ??
|
|
19
|
-
savedBaseUrl ??
|
|
20
|
-
undefined);
|
|
21
|
-
}
|
|
22
|
-
export function getConfiguredRealtimeHost(parsedArgs, savedRealtimeHost) {
|
|
23
|
-
return (getOptionalStringFlag(parsedArgs, "realtime-host") ??
|
|
24
|
-
getOptionalStringEnv("ANDO_REALTIME_HOST") ??
|
|
25
|
-
savedRealtimeHost ??
|
|
26
|
-
undefined);
|
|
27
|
-
}
|
|
28
|
-
export function getConfiguredApiHost(parsedArgs, savedApiHost) {
|
|
29
|
-
return (getOptionalStringFlag(parsedArgs, "api-host") ??
|
|
30
|
-
getOptionalStringEnv("ANDO_API_HOST") ??
|
|
31
|
-
savedApiHost ??
|
|
32
|
-
DEFAULT_ANDO_PUBLIC_API_BASE_URL);
|
|
33
|
-
}
|
|
34
|
-
function buildConfig(parsedArgs, apiKey, savedConfig) {
|
|
35
|
-
if (apiKey == null) {
|
|
36
|
-
throw new Error(LOGIN_REQUIRED_ERROR);
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
apiKey,
|
|
40
|
-
baseUrl: getConfiguredBaseUrl(parsedArgs, savedConfig?.baseUrl ?? null),
|
|
41
|
-
apiHost: getConfiguredApiHost(parsedArgs, savedConfig?.apiHost ?? null),
|
|
42
|
-
realtimeHost: getConfiguredRealtimeHost(parsedArgs, savedConfig?.realtimeHost ?? null),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
async function loadConfig(parsedArgs) {
|
|
46
|
-
const explicitApiKey = getExplicitApiKey(parsedArgs);
|
|
47
|
-
if (explicitApiKey != null) {
|
|
48
|
-
return buildConfig(parsedArgs, explicitApiKey, await readSavedConfigMetadata());
|
|
49
|
-
}
|
|
50
|
-
const savedConfig = await readSavedConfig();
|
|
51
|
-
return buildConfig(parsedArgs, savedConfig?.apiKey ?? null, savedConfig);
|
|
52
|
-
}
|
|
53
|
-
export async function ensureConfig(params) {
|
|
54
|
-
if (params.command === "login") {
|
|
55
|
-
throw new Error("login configures API keys and must run before loading config.");
|
|
56
|
-
}
|
|
57
|
-
return await loadConfig(params.parsedArgs);
|
|
58
|
-
}
|
package/dist/timeouts.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_CLI_REQUEST_TIMEOUT_MS = 30_000;
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/watch-commands.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { getStringFlag, hasFlag } from "./args.js";
|
|
2
|
-
import { formatMessageLine, getMessageBody, getVisibleText } from "./format.js";
|
|
3
|
-
function getPositiveIntegerFlag(parsedArgs, longName, shortName) {
|
|
4
|
-
const value = getStringFlag(parsedArgs, longName, shortName);
|
|
5
|
-
if (value == null) {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
const parsed = Number.parseInt(value, 10);
|
|
9
|
-
if (!Number.isSafeInteger(parsed) || parsed <= 0 || String(parsed) !== value.trim()) {
|
|
10
|
-
throw new Error(`--${longName} must be a positive integer.`);
|
|
11
|
-
}
|
|
12
|
-
return parsed;
|
|
13
|
-
}
|
|
14
|
-
function getWatchDelivery(parsedArgs) {
|
|
15
|
-
const delivery = getStringFlag(parsedArgs, "delivery");
|
|
16
|
-
if (delivery == null) {
|
|
17
|
-
if (hasFlag(parsedArgs, "all")) {
|
|
18
|
-
throw new Error('Public realtime currently supports --delivery "messages" or "mentions".');
|
|
19
|
-
}
|
|
20
|
-
return "messages";
|
|
21
|
-
}
|
|
22
|
-
if (delivery !== "messages" && delivery !== "mentions") {
|
|
23
|
-
throw new Error('Unknown --delivery value. Expected "messages" or "mentions".');
|
|
24
|
-
}
|
|
25
|
-
return delivery;
|
|
26
|
-
}
|
|
27
|
-
function getWatchTarget(parsedArgs) {
|
|
28
|
-
const target = parsedArgs.positionals[1] ?? "messages";
|
|
29
|
-
if (target !== "messages") {
|
|
30
|
-
throw new Error(`Unknown watch target "${target}". Expected "messages".`);
|
|
31
|
-
}
|
|
32
|
-
return target;
|
|
33
|
-
}
|
|
34
|
-
function getConversationLabel(event) {
|
|
35
|
-
const prefix = event.isDirectMessage ? "@" : "#";
|
|
36
|
-
const rawName = event.conversation?.name ?? event.message.conversation_name;
|
|
37
|
-
const name = typeof rawName === "string" ? rawName.trim() : "";
|
|
38
|
-
if (name !== "") {
|
|
39
|
-
return `${prefix}${name}`;
|
|
40
|
-
}
|
|
41
|
-
return `${prefix}${event.message.conversation_id}`;
|
|
42
|
-
}
|
|
43
|
-
function writeWatchJsonEvent(event) {
|
|
44
|
-
process.stdout.write(`${JSON.stringify({
|
|
45
|
-
type: "message",
|
|
46
|
-
id: event.message.id,
|
|
47
|
-
conversationId: event.message.conversation_id,
|
|
48
|
-
conversationName: event.conversation?.name ?? event.message.conversation_name,
|
|
49
|
-
isDirectMessage: event.isDirectMessage,
|
|
50
|
-
authorId: event.message.author_id,
|
|
51
|
-
authorName: event.message.author.display_name ?? null,
|
|
52
|
-
content: getVisibleText(getMessageBody(event.message)),
|
|
53
|
-
markdownContent: event.message.markdown_content ?? null,
|
|
54
|
-
createdAt: event.message.created_at,
|
|
55
|
-
threadRootId: event.message.thread_root_id ?? null,
|
|
56
|
-
repliesCount: event.message.replies_count,
|
|
57
|
-
wasMentioned: event.wasMentioned ?? false,
|
|
58
|
-
context: event.context,
|
|
59
|
-
})}\n`);
|
|
60
|
-
}
|
|
61
|
-
function writeWatchPlainEvent(event) {
|
|
62
|
-
process.stdout.write(`${event.message.id}\t${getConversationLabel(event)}\t${formatMessageLine(event.message)}\n`);
|
|
63
|
-
}
|
|
64
|
-
export async function runWatchCommand({ apiClient, parsedArgs, isInteractive = Boolean(process.stdin.isTTY && process.stdout.isTTY), }) {
|
|
65
|
-
getWatchTarget(parsedArgs);
|
|
66
|
-
const jsonFlag = hasFlag(parsedArgs, "json");
|
|
67
|
-
const delivery = getWatchDelivery(parsedArgs);
|
|
68
|
-
const limit = getPositiveIntegerFlag(parsedArgs, "limit", "n");
|
|
69
|
-
const timeoutMs = getPositiveIntegerFlag(parsedArgs, "timeout");
|
|
70
|
-
if (!isInteractive && limit == null && timeoutMs == null) {
|
|
71
|
-
throw new Error("watch messages requires --limit or --timeout in non-interactive mode.");
|
|
72
|
-
}
|
|
73
|
-
const controller = new AbortController();
|
|
74
|
-
let messageCount = 0;
|
|
75
|
-
let timeout;
|
|
76
|
-
const stop = (reason) => {
|
|
77
|
-
if (!controller.signal.aborted) {
|
|
78
|
-
controller.abort(new Error(reason));
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const onInterrupt = () => stop("watch interrupted");
|
|
82
|
-
if (timeoutMs != null) {
|
|
83
|
-
timeout = setTimeout(() => stop("watch timeout reached"), timeoutMs);
|
|
84
|
-
}
|
|
85
|
-
process.once("SIGINT", onInterrupt);
|
|
86
|
-
let subscription = null;
|
|
87
|
-
try {
|
|
88
|
-
subscription = await apiClient.realtime.subscribeMember({
|
|
89
|
-
delivery,
|
|
90
|
-
signal: controller.signal,
|
|
91
|
-
onMessage(event) {
|
|
92
|
-
messageCount += 1;
|
|
93
|
-
if (jsonFlag) {
|
|
94
|
-
writeWatchJsonEvent(event);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
writeWatchPlainEvent(event);
|
|
98
|
-
}
|
|
99
|
-
if (limit != null && messageCount >= limit) {
|
|
100
|
-
stop("watch limit reached");
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
if (isInteractive) {
|
|
105
|
-
process.stderr.write("Watching messages via realtime. Press Ctrl-C to stop.\n");
|
|
106
|
-
}
|
|
107
|
-
await subscription.done();
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
if (!controller.signal.aborted) {
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
finally {
|
|
115
|
-
if (timeout != null) {
|
|
116
|
-
clearTimeout(timeout);
|
|
117
|
-
}
|
|
118
|
-
process.removeListener("SIGINT", onInterrupt);
|
|
119
|
-
await subscription?.close().catch(() => undefined);
|
|
120
|
-
}
|
|
121
|
-
}
|