@meetstream/cli 0.2.0 → 0.6.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.
@@ -0,0 +1,292 @@
1
+ // `meetstream logins teams|google ...` - manage the accounts signed-in bots use.
2
+ // Teams accounts use an email + password (write-only). Google accounts use an SSO
3
+ // private key + certificate (PEM files). Secrets are never CLI args and never printed.
4
+ import { readFileSync } from 'node:fs';
5
+ import { printJson, ok, kv, bold, dim, cyan, green, yellow, handleError } from '../output.js';
6
+ import { resolvePassword, confirm, PASSWORD_ENV } from '../secrets.js';
7
+
8
+ function usageError(message) {
9
+ return Object.assign(new Error(message), { exitCode: 2 });
10
+ }
11
+
12
+ async function confirmOrAbort(question, opts) {
13
+ if (opts.yes) return;
14
+ if (!process.stdin.isTTY) throw usageError(`${question} Refusing without --yes in a non-interactive shell.`);
15
+ if (!(await confirm(question))) throw Object.assign(new Error('Aborted'), { exitCode: 1 });
16
+ }
17
+
18
+ function readPem(path, flag) {
19
+ try { return readFileSync(path, 'utf8'); } catch (e) {
20
+ throw usageError(`${flag}: cannot read ${path} (${e.code || e.message})`);
21
+ }
22
+ }
23
+
24
+ const activeLabel = (v) => (v === false ? yellow('inactive') : green('active'));
25
+
26
+ const PLATFORMS = {
27
+ teams: {
28
+ label: 'Microsoft Teams',
29
+ docs: 'https://docs.meetstream.ai/guides/app-integrations/teams-signed-in-bots',
30
+ domainKey: 'domain',
31
+ m: {
32
+ domains: 'teamsDomainsList', domain: 'teamsDomainGet', addDomain: 'teamsDomainCreate',
33
+ updateDomain: 'teamsDomainUpdate', removeDomain: 'teamsDomainDelete',
34
+ list: 'teamsLoginsList', add: 'teamsLoginCreate', update: 'teamsLoginUpdate', remove: 'teamsLoginDelete',
35
+ },
36
+ loginLine: (l) => `${cyan(l.login_id)} ${l.email} ${activeLabel(l.is_active)} ${dim(`lease: ${l.lease_status ?? '-'} last: ${l.last_session_result ?? '-'}`)}`,
37
+ },
38
+ google: {
39
+ label: 'Google Meet',
40
+ docs: 'https://docs.meetstream.ai/guides/app-integrations/google-signed-in-bots',
41
+ domainKey: 'sso_workspace_domain',
42
+ m: {
43
+ domains: 'googleDomainsList', domain: 'googleDomainGet', addDomain: 'googleDomainCreate',
44
+ updateDomain: 'googleDomainUpdate', removeDomain: 'googleDomainDelete',
45
+ list: 'googleLoginsList', add: 'googleLoginCreate', update: 'googleLoginUpdate', remove: 'googleLoginDelete',
46
+ },
47
+ loginLine: (l) => `${cyan(l.login_id)} ${l.email} ${activeLabel(l.is_active)} ${dim(`sessions: ${l.active_sessions ?? 0} last test: ${l.last_test_status ?? '-'}`)}`,
48
+ },
49
+ };
50
+
51
+ function registerPlatform(logins, key, getClient) {
52
+ const p = PLATFORMS[key];
53
+ const isTeams = key === 'teams';
54
+ const cmd = logins
55
+ .command(key)
56
+ .description(`${p.label} signed-in bot domains and accounts (guide: ${p.docs})`);
57
+
58
+ // ── Domains ──────────────────────────────────────────────────────────
59
+ cmd
60
+ .command('domains')
61
+ .description('List registered login domains')
62
+ .option('--json', 'JSON output')
63
+ .action(async (opts) => {
64
+ try {
65
+ const { data } = await getClient()[p.m.domains]();
66
+ if (opts.json) return printJson(data);
67
+ const domains = data?.domains || [];
68
+ if (!domains.length) return console.log(dim(`No ${p.label} login domains yet. Register one: meetstream logins ${key} add-domain <domain>`));
69
+ for (const d of domains) {
70
+ const extra = isTeams ? '' : ` ${dim(`max/login: ${d.max_concurrent_per_login ?? '-'}`)}`;
71
+ console.log(`${cyan(d[p.domainKey])} ${d.name ?? ''} ${dim(d.login_mode ?? '')} ${d.active_login_count ?? 0}/${d.login_count ?? 0} active logins${extra}`);
72
+ }
73
+ } catch (e) { handleError(e, opts); }
74
+ });
75
+
76
+ cmd
77
+ .command('domain')
78
+ .description('Show one domain and its accounts')
79
+ .argument('<domain>')
80
+ .option('--json', 'JSON output')
81
+ .action(async (domain, opts) => {
82
+ try {
83
+ const { data } = await getClient()[p.m.domain](domain);
84
+ if (opts.json) return printJson(data);
85
+ kv({ domain: bold(data?.[p.domainKey] ?? domain), name: data?.name, login_mode: data?.login_mode, max_concurrent_per_login: data?.max_concurrent_per_login, created_at: data?.created_at });
86
+ const list = data?.logins || [];
87
+ console.log(list.length ? '' : dim('\n No accounts yet.'));
88
+ for (const l of list) console.log(` ${p.loginLine(l)}`);
89
+ } catch (e) { handleError(e, opts); }
90
+ });
91
+
92
+ const addDomain = cmd
93
+ .command('add-domain')
94
+ .description(isTeams
95
+ ? 'Register a Microsoft 365 bot tenant domain (login_mode is always "always" for Teams)'
96
+ : 'Register a Google Workspace domain (set up SSO in Google Admin first, see the guide)')
97
+ .argument('<domain>')
98
+ .option('--name <name>', 'friendly name');
99
+ if (!isTeams) addDomain.option('--login-mode <mode>', 'always | if_required', 'always');
100
+ addDomain
101
+ .option('--json', 'JSON output')
102
+ .action(async (domain, opts) => {
103
+ try {
104
+ const { data } = await getClient()[p.m.addDomain]({ domain, name: opts.name, loginMode: opts.loginMode });
105
+ if (opts.json) return printJson(data);
106
+ ok(`Domain ${bold(domain)} registered`);
107
+ console.log(dim(isTeams
108
+ ? `\n Next: meetstream logins teams add --domain ${domain} --email <bot@${domain}>`
109
+ : `\n Next: meetstream logins google add --domain ${domain} --email <bot@${domain}> --key key.pem --cert cert.pem`));
110
+ } catch (e) { handleError(e, opts); }
111
+ });
112
+
113
+ const updateDomain = cmd
114
+ .command('update-domain')
115
+ .description('Rename a domain' + (isTeams ? '' : ' or change its login mode'))
116
+ .argument('<domain>')
117
+ .option('--name <name>', 'new friendly name');
118
+ if (!isTeams) updateDomain.option('--login-mode <mode>', 'always | if_required');
119
+ updateDomain
120
+ .option('--json', 'JSON output')
121
+ .action(async (domain, opts) => {
122
+ try {
123
+ if (!opts.name && !opts.loginMode) throw usageError('Nothing to update: pass --name' + (isTeams ? '' : ' and/or --login-mode'));
124
+ const { data } = await getClient()[p.m.updateDomain](domain, { name: opts.name, loginMode: opts.loginMode });
125
+ if (opts.json) return printJson(data);
126
+ ok(`Domain ${bold(domain)} updated`);
127
+ } catch (e) { handleError(e, opts); }
128
+ });
129
+
130
+ cmd
131
+ .command('remove-domain')
132
+ .description(isTeams
133
+ ? 'Delete a domain AND all of its accounts'
134
+ : 'Delete a domain and its accounts (the API refuses while any account is active; disable them first)')
135
+ .argument('<domain>')
136
+ .option('--yes', 'skip confirmation')
137
+ .option('--json', 'JSON output')
138
+ .action(async (domain, opts) => {
139
+ try {
140
+ await confirmOrAbort(`Delete ${p.label} domain ${domain} and every account registered under it?`, opts);
141
+ const { data } = await getClient()[p.m.removeDomain](domain);
142
+ if (opts.json) return printJson(data);
143
+ ok(`Domain ${bold(domain)} deleted`);
144
+ } catch (e) { handleError(e, opts); }
145
+ });
146
+
147
+ // ── Accounts ─────────────────────────────────────────────────────────
148
+ cmd
149
+ .command('list')
150
+ .description('List accounts in a domain')
151
+ .requiredOption('--domain <domain>', 'registered domain')
152
+ .option('--json', 'JSON output')
153
+ .action(async (opts) => {
154
+ try {
155
+ const { data } = await getClient()[p.m.list](opts.domain);
156
+ if (opts.json) return printJson(data);
157
+ const list = data?.logins || [];
158
+ if (!list.length) return console.log(dim(`No accounts in ${opts.domain} yet.`));
159
+ for (const l of list) console.log(p.loginLine(l));
160
+ } catch (e) { handleError(e, opts); }
161
+ });
162
+
163
+ if (isTeams) {
164
+ cmd
165
+ .command('get')
166
+ .description('Show one account')
167
+ .argument('<login-id>')
168
+ .option('--json', 'JSON output')
169
+ .action(async (loginId, opts) => {
170
+ try {
171
+ const { data } = await getClient().teamsLoginGet(loginId);
172
+ if (opts.json) return printJson(data);
173
+ kv({ login_id: bold(data.login_id), domain: data.domain, email: data.email, is_active: String(data.is_active), lease_status: data.lease_status, last_session_result: data.last_session_result, last_login_error: data.last_login_error, updated_at: data.updated_at });
174
+ } catch (e) { handleError(e, opts); }
175
+ });
176
+
177
+ cmd
178
+ .command('add')
179
+ .description(`Register a bot account. Password from --password-stdin, $${PASSWORD_ENV}, or a hidden prompt (never a CLI argument)`)
180
+ .requiredOption('--domain <domain>', 'registered domain')
181
+ .requiredOption('--email <email>', 'account email, e.g. bot1@bots.example.com')
182
+ .option('--password-stdin', 'read the password from stdin')
183
+ .option('--inactive', 'register the account disabled')
184
+ .option('--json', 'JSON output')
185
+ .action(async (opts) => {
186
+ try {
187
+ const password = await resolvePassword({ passwordStdin: opts.passwordStdin });
188
+ const { data } = await getClient().teamsLoginCreate({ domain: opts.domain, email: opts.email, password, isActive: opts.inactive ? false : undefined });
189
+ if (opts.json) return printJson(data);
190
+ ok(`Account ${bold(opts.email)} registered (login_id ${cyan(data?.login_id)})`);
191
+ console.log(dim(' Teams allows ONE concurrent bot per account: register N accounts for N concurrent signed-in bots.'));
192
+ } catch (e) { handleError(e, opts); }
193
+ });
194
+
195
+ cmd
196
+ .command('set-password')
197
+ .description(`Rotate an account password (also reactivates a deactivated account). Same password sources as add`)
198
+ .argument('<login-id>')
199
+ .option('--password-stdin', 'read the password from stdin')
200
+ .option('--json', 'JSON output')
201
+ .action(async (loginId, opts) => {
202
+ try {
203
+ const password = await resolvePassword({ passwordStdin: opts.passwordStdin });
204
+ const { data } = await getClient().teamsLoginUpdate(loginId, { password });
205
+ if (opts.json) return printJson(data);
206
+ ok(`Password updated for ${bold(loginId)}`);
207
+ } catch (e) { handleError(e, opts); }
208
+ });
209
+ } else {
210
+ cmd
211
+ .command('add')
212
+ .description('Register a Google Workspace account with the SSO key + certificate from the setup guide')
213
+ .requiredOption('--domain <domain>', 'registered Workspace domain')
214
+ .requiredOption('--email <email>', 'account email')
215
+ .requiredOption('--key <path>', 'path to the SSO private key PEM (key.pem)')
216
+ .requiredOption('--cert <path>', 'path to the SSO certificate PEM (cert.pem)')
217
+ .option('--inactive', 'register the account disabled')
218
+ .option('--json', 'JSON output')
219
+ .action(async (opts) => {
220
+ try {
221
+ const privateKeyPem = readPem(opts.key, '--key');
222
+ const certPem = readPem(opts.cert, '--cert');
223
+ const { data } = await getClient().googleLoginCreate({ domain: opts.domain, email: opts.email, privateKeyPem, certPem, isActive: opts.inactive ? false : undefined });
224
+ if (opts.json) return printJson(data);
225
+ ok(`Account ${bold(opts.email)} registered (login_id ${cyan(data?.login_id)})`);
226
+ } catch (e) { handleError(e, opts); }
227
+ });
228
+
229
+ cmd
230
+ .command('set-cert')
231
+ .description('Replace an account\'s SSO key + certificate (refused while the account has active sessions)')
232
+ .argument('<login-id>')
233
+ .requiredOption('--domain <domain>', 'the account\'s domain')
234
+ .requiredOption('--key <path>', 'path to the SSO private key PEM')
235
+ .requiredOption('--cert <path>', 'path to the SSO certificate PEM')
236
+ .option('--json', 'JSON output')
237
+ .action(async (loginId, opts) => {
238
+ try {
239
+ const { data } = await getClient().googleLoginUpdate(loginId, {
240
+ domain: opts.domain, privateKeyPem: readPem(opts.key, '--key'), certPem: readPem(opts.cert, '--cert'),
241
+ });
242
+ if (opts.json) return printJson(data);
243
+ ok(`Credentials updated for ${bold(loginId)}`);
244
+ } catch (e) { handleError(e, opts); }
245
+ });
246
+ }
247
+
248
+ for (const [name, active] of [['disable', false], ['enable', true]]) {
249
+ const c = cmd
250
+ .command(name)
251
+ .description(active ? 'Re-enable an account' : 'Disable an account (bots stop using it)')
252
+ .argument('<login-id>');
253
+ if (!isTeams) c.requiredOption('--domain <domain>', 'the account\'s domain');
254
+ c.option('--json', 'JSON output')
255
+ .action(async (loginId, opts) => {
256
+ try {
257
+ const { data } = await getClient()[p.m.update](loginId, isTeams ? { isActive: active } : { domain: opts.domain, isActive: active });
258
+ if (opts.json) return printJson(data);
259
+ ok(`Account ${bold(loginId)} ${active ? 'enabled' : 'disabled'}`);
260
+ } catch (e) { handleError(e, opts); }
261
+ });
262
+ }
263
+
264
+ const rm = cmd
265
+ .command('remove')
266
+ .description('Delete an account')
267
+ .argument('<login-id>');
268
+ if (!isTeams) rm.requiredOption('--domain <domain>', 'the account\'s domain');
269
+ rm.option('--yes', 'skip confirmation')
270
+ .option('--json', 'JSON output')
271
+ .action(async (loginId, opts) => {
272
+ try {
273
+ await confirmOrAbort(`Delete ${p.label} account ${loginId}?`, opts);
274
+ const { data } = isTeams
275
+ ? await getClient().teamsLoginDelete(loginId)
276
+ : await getClient().googleLoginDelete(loginId, opts.domain);
277
+ if (opts.json) return printJson(data);
278
+ ok(`Account ${bold(loginId)} deleted`);
279
+ } catch (e) { handleError(e, opts); }
280
+ });
281
+
282
+ return cmd;
283
+ }
284
+
285
+ export function registerLoginsCommands(program, getClient) {
286
+ const logins = program
287
+ .command('logins')
288
+ .description('Accounts for signed-in bots (Microsoft Teams, Google Meet). Use them with bot create --teams-login-domain / --google-login-domain');
289
+ registerPlatform(logins, 'teams', getClient);
290
+ registerPlatform(logins, 'google', getClient);
291
+ return logins;
292
+ }
@@ -1,5 +1,5 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import { printJson, ok, kv, dim, handleError } from '../output.js';
2
+ import { printJson, ok, kv, dim, warn, handleError } from '../output.js';
3
3
  import { saveConfig, resolveApiKey, CONFIG_PATH, BASE_URL } from '../config.js';
4
4
 
5
5
  export function registerAuthCommands(program, getClient) {
@@ -78,24 +78,110 @@ export function registerCalendarCommands(program, getClient) {
78
78
  });
79
79
  }
80
80
 
81
+ function readJsonFile(path) {
82
+ try {
83
+ return JSON.parse(readFileSync(path, 'utf8'));
84
+ } catch (e) {
85
+ throw Object.assign(new Error(`Could not read JSON from ${path}: ${e.message}`), { exitCode: 2 });
86
+ }
87
+ }
88
+
81
89
  export function registerMiaCommands(program, getClient) {
82
- const mia = program.command('mia').description('MIA conversational AI agents');
83
- mia.command('list').description('List agent configs').action(async (opts) => {
90
+ const mia = program
91
+ .command('mia')
92
+ .alias('agents')
93
+ .description('Agents API: voice agent (MIA) configs. Attach one to a bot with: bot create <link> --agent-config <id>');
94
+
95
+ mia.command('list').description('List agent configs').option('--json', 'JSON output').action(async (opts) => {
84
96
  try { printJson((await getClient().miaList()).data); } catch (e) { handleError(e, opts); }
85
97
  });
98
+
99
+ mia.command('get').description('Show one agent config (secrets come back masked)').argument('<agent-config-id>')
100
+ .option('--json', 'JSON output')
101
+ .action(async (id, opts) => {
102
+ try { printJson((await getClient().miaGet(id)).data); } catch (e) { handleError(e, opts); }
103
+ });
104
+
86
105
  mia
87
106
  .command('create')
88
- .description('Create an agent config from a JSON file (agent_name, mode, model, voice, transcriber, …)')
107
+ .description('Create an agent config from a JSON file (agent_name, mode, model, voice, transcriber, agent, ...)')
89
108
  .requiredOption('-f, --file <path>', 'JSON config file')
109
+ .option('--json', 'JSON output')
90
110
  .action(async (opts) => {
91
111
  try {
92
- const cfg = JSON.parse(readFileSync(opts.file, 'utf8'));
93
- const { data } = await getClient().miaCreate(cfg);
112
+ const { data } = await getClient().miaCreate(readJsonFile(opts.file));
113
+ if (opts.json) return printJson(data);
94
114
  ok('Agent config created'); printJson(data);
95
- console.log(dim('Attach it to a bot: meetstream bot create <link> --agent-config-id <id> --socket-ws <wss> --live-audio-ws <wss>'));
115
+ const id = data?.agent_config_id || '<agent-config-id>';
116
+ console.log(dim(`Attach it to a bot (nothing else is needed): meetstream bot create <meeting-link> --agent-config ${id}`));
96
117
  } catch (e) { handleError(e, opts); }
97
118
  });
98
- mia.command('delete').description('Delete an agent config').argument('<agent-config-id>').action(async (id, opts) => {
99
- try { printJson((await getClient().miaDelete(id)).data); ok('Deleted'); } catch (e) { handleError(e, opts); }
100
- });
119
+
120
+ mia
121
+ .command('update')
122
+ .description('Update an agent config from a JSON file (PUT: each block you send replaces the saved block, so send whole blocks)')
123
+ .argument('<agent-config-id>')
124
+ .requiredOption('-f, --file <path>', 'JSON file with the blocks to replace')
125
+ .option('--json', 'JSON output')
126
+ .action(async (id, opts) => {
127
+ try {
128
+ const body = { ...readJsonFile(opts.file), agent_config_id: id };
129
+ const { data } = await getClient().miaUpdate(body);
130
+ if (opts.json) return printJson(data);
131
+ ok('Agent config updated'); printJson(data);
132
+ } catch (e) { handleError(e, opts); }
133
+ });
134
+
135
+ mia.command('delete').description('Delete an agent config').argument('<agent-config-id>').option('--json', 'JSON output')
136
+ .action(async (id, opts) => {
137
+ try {
138
+ const { data } = await getClient().miaDelete(id);
139
+ if (opts.json) return printJson(data);
140
+ printJson(data); ok('Deleted');
141
+ } catch (e) { handleError(e, opts); }
142
+ });
143
+
144
+ mia
145
+ .command('check')
146
+ .description('Test the connection to your local agent bridge (model.provider "local_agent"; needs the local agent feature on for your account)')
147
+ .argument('<agent-config-id>')
148
+ .option('--json', 'JSON output')
149
+ .action(async (id, opts) => {
150
+ try {
151
+ const { data } = await getClient().miaCheckLocalAgent(id);
152
+ if (opts.json) return printJson(data);
153
+ const status = data?.local_agent?.status;
154
+ if (status === 'ok') ok(`Local agent bridge is reachable (${data.local_agent.latency_ms ?? '?'} ms)`);
155
+ else warn(`Local agent bridge status: ${status ?? 'unknown'}`);
156
+ printJson(data);
157
+ if (status && status !== 'ok') process.exit(3);
158
+ } catch (e) { handleError(e, opts); }
159
+ });
160
+ }
161
+
162
+ export function registerBalanceCommand(program, getClient) {
163
+ program
164
+ .command('balance')
165
+ .description('Show your prepaid balance (read only; available when the balance endpoint is on for your account)')
166
+ .option('--json', 'JSON output')
167
+ .action(async (opts) => {
168
+ try {
169
+ const { data } = await getClient().balance();
170
+ if (opts.json) return printJson(data);
171
+ if (data?.balance_usd == null) {
172
+ kv({ customer_type: data?.customer_type, balance: 'no prepaid balance (billed by invoice)' });
173
+ } else {
174
+ kv({ customer_type: data?.customer_type, balance: `${data.balance_usd} ${data.currency || 'USD'}` });
175
+ }
176
+ console.log(dim(' Top up: https://app.meetstream.ai/billing'));
177
+ } catch (e) {
178
+ if (e.status === 404) {
179
+ const msg = 'The balance endpoint is not available for this account yet. See your balance at https://app.meetstream.ai/billing';
180
+ if (opts.json) printJson({ error: 'balance_unavailable', status: 404, message: msg, billing_url: 'https://app.meetstream.ai/billing' });
181
+ else warn(msg);
182
+ process.exit(3);
183
+ }
184
+ handleError(e, opts);
185
+ }
186
+ });
101
187
  }
@@ -41,7 +41,7 @@ export function registerTranscriptCommands(program, getClient) {
41
41
  .command('transcribe')
42
42
  .description('Run (or re-run) transcription on a bot\'s recorded audio')
43
43
  .argument('<bot-id>')
44
- .option('-p, --provider <name>', 'deepgram | assemblyai | sarvam | meetstream | jigsawstack', 'deepgram')
44
+ .option('-p, --provider <name>', 'deepgram | assemblyai | sarvam | meetstream | jigsawstack | smallest (needs your Smallest AI key saved in the dashboard)', 'deepgram')
45
45
  .option('-l, --language <lang>', 'language (provider-specific format)')
46
46
  .option('-c, --callback <url>', 'webhook to notify when done')
47
47
  .option('--json', 'JSON output')
@@ -54,6 +54,7 @@ export function registerTranscriptCommands(program, getClient) {
54
54
  else if (p === 'sarvam') provider.sarvam = { model: 'saarika:v2', language_code: opts.language || 'en-IN', mode: 'batch' };
55
55
  else if (p === 'meetstream') provider.meetstream = { language: opts.language || 'auto', translate: false };
56
56
  else if (p === 'jigsawstack') provider.jigsawstack = { language: opts.language || 'auto', translate: false };
57
+ else if (p === 'smallest') provider.smallest = { model: 'pulse', language: opts.language || 'en' };
57
58
  else provider[p] = {};
58
59
  const { data } = await getClient().transcribe(botId, provider, opts.callback);
59
60
  if (opts.json) return printJson(data);
package/src/output.js CHANGED
@@ -1,4 +1,4 @@
1
- // Terminal output helpers — zero-dependency colors + consistent JSON mode.
1
+ // Terminal output helpers - zero-dependency colors + consistent JSON mode.
2
2
  const tty = process.stdout.isTTY;
3
3
  const c = (code) => (s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : String(s));
4
4
  export const bold = c('1');
@@ -14,6 +14,8 @@ export function printJson(obj) {
14
14
 
15
15
  export function ok(msg) { console.log(green('✓ ') + msg); }
16
16
  export function warn(msg) { console.log(yellow('⚠ ') + msg); }
17
+ /** Warning on stderr, so --json output on stdout stays parseable. */
18
+ export function warnErr(msg) { console.error(yellow('⚠ ') + msg); }
17
19
  export function fail(msg) { console.error(red('✗ ') + msg); }
18
20
 
19
21
  export function kv(pairs) {
@@ -33,12 +35,43 @@ export function transcriptToText(segments) {
33
35
  .join('\n');
34
36
  }
35
37
 
38
+ const FAILED_TRANSCRIPT_EXIT = 4;
39
+
40
+ /** For a failed transcript (422 with transcript_status): { reason, transcript_status, transcript_id }, else null. */
41
+ export function failedTranscript(err) {
42
+ if (err?.status !== 422 || typeof err?.body?.transcript_status !== 'string') return null;
43
+ const msg = typeof err.body.message === 'string' ? err.body.message : '';
44
+ return {
45
+ reason: msg.replace(/^Transcript processing failed:?\s*/i, '') || msg || 'no reason given',
46
+ transcript_status: err.body.transcript_status,
47
+ transcript_id: err.body.transcript_id,
48
+ };
49
+ }
50
+
36
51
  export function handleError(err, { json = false } = {}) {
52
+ const failed = failedTranscript(err);
53
+ if (failed) {
54
+ if (json) {
55
+ printJson({ error: 'transcript_failed', status: 422, ...failed });
56
+ } else {
57
+ fail(`Transcript failed: ${failed.reason}`);
58
+ console.error(dim(` transcript_id ${failed.transcript_id ?? '(unknown)'}, status ${failed.transcript_status}. It will not become ready, so do not retry.`));
59
+ console.error(dim(' Fix the cause (for example the provider API key or its usage limit), then run: meetstream transcribe <bot-id>'));
60
+ }
61
+ process.exit(FAILED_TRANSCRIPT_EXIT);
62
+ }
37
63
  if (json) {
38
- printJson({ error: err.message, status: err.status, body: err.body });
64
+ printJson({ error: err.message, status: err.status, body: err.body, ...(err.retryAfter !== undefined ? { retry_after: err.retryAfter } : {}) });
39
65
  } else {
40
66
  fail(err.message);
67
+ if (/MeetStream-managed keys are not available/i.test(err.message || '')) {
68
+ console.error(dim(' MeetStream\'s inbuilt keys are not on for your account yet. Use your own provider key for that section'));
69
+ console.error(dim(' ("key_source": "user", key saved under Integrations), then run the command again.'));
70
+ }
41
71
  if (err.status === 401) console.error(dim(' Check your API key: https://app.meetstream.ai/api-keys'));
72
+ if (err.status === 429 && err.retryAfter !== undefined) {
73
+ console.error(dim(` Rate limited. Wait ${err.retryAfter} s, then run the command again (reuse the same --idempotency-key).`));
74
+ }
42
75
  }
43
76
  process.exit(err.exitCode || 1);
44
77
  }
package/src/secrets.js ADDED
@@ -0,0 +1,61 @@
1
+ // Secret input for signed-in bot accounts. A password is NEVER accepted as a CLI
2
+ // argument (it would land in shell history and `ps`), and is never printed or logged.
3
+ import readline from 'node:readline';
4
+ import { Writable } from 'node:stream';
5
+
6
+ export const PASSWORD_ENV = 'MEETSTREAM_LOGIN_PASSWORD';
7
+
8
+ function usageError(message) {
9
+ return Object.assign(new Error(message), { exitCode: 2 });
10
+ }
11
+
12
+ /** Read all of stdin and strip one trailing newline (so `echo "$PW" | ...` works). */
13
+ export async function readStdin(stream = process.stdin) {
14
+ const chunks = [];
15
+ for await (const chunk of stream) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
16
+ return Buffer.concat(chunks).toString('utf8').replace(/\r?\n$/, '');
17
+ }
18
+
19
+ /** Prompt on stderr without echoing what is typed. */
20
+ export function promptHidden(question, { input = process.stdin, output = process.stderr } = {}) {
21
+ return new Promise((resolve, reject) => {
22
+ let muted = false;
23
+ const sink = new Writable({
24
+ write(chunk, encoding, cb) { if (!muted) output.write(chunk, encoding); cb(); },
25
+ });
26
+ const rl = readline.createInterface({ input, output: sink, terminal: true });
27
+ rl.on('SIGINT', () => { rl.close(); output.write('\n'); reject(usageError('Cancelled')); });
28
+ rl.question(question, (answer) => { rl.close(); output.write('\n'); resolve(answer); });
29
+ muted = true;
30
+ });
31
+ }
32
+
33
+ /** Ask a yes/no question on stderr. Resolves true only for y / yes. */
34
+ export function confirm(question, { input = process.stdin, output = process.stderr } = {}) {
35
+ return new Promise((resolve) => {
36
+ const rl = readline.createInterface({ input, output });
37
+ rl.question(`${question} [y/N] `, (answer) => { rl.close(); resolve(/^y(es)?$/i.test(answer.trim())); });
38
+ });
39
+ }
40
+
41
+ /**
42
+ * Resolve a login password. Order: --password-stdin, then $MEETSTREAM_LOGIN_PASSWORD,
43
+ * then an interactive hidden prompt (TTY only). Dependencies are injectable for tests.
44
+ */
45
+ export async function resolvePassword({
46
+ passwordStdin = false,
47
+ env = process.env,
48
+ isTTY = Boolean(process.stdin.isTTY),
49
+ read = readStdin,
50
+ prompt = promptHidden,
51
+ } = {}) {
52
+ let password;
53
+ if (passwordStdin) password = await read();
54
+ else if (env[PASSWORD_ENV]) password = env[PASSWORD_ENV];
55
+ else if (isTTY) password = await prompt('Account password (input hidden): ');
56
+ else {
57
+ throw usageError(`No password provided. Pipe it with --password-stdin or set ${PASSWORD_ENV}. Passwords are never accepted as command-line arguments.`);
58
+ }
59
+ if (!password) throw usageError('Password is empty.');
60
+ return password;
61
+ }
package/src/telemetry.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Anonymous, opt-out usage telemetry (PostHog).
3
- * Captures ONLY command names + counts — never API keys, meeting URLs, transcripts,
3
+ * Captures ONLY command names + counts - never API keys, meeting URLs, transcripts,
4
4
  * or any content. Disable with DO_NOT_TRACK=1 or MEETSTREAM_TELEMETRY=0.
5
5
  * The project key is a PostHog *public* key.
6
6
  */