moeba-claude-channel 0.0.4 → 0.0.6

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.
@@ -237,11 +237,47 @@ function connectSSE(c, mcp) {
237
237
  // Main — authenticate first, then connect MCP
238
238
  // ---------------------------------------------------------------------------
239
239
  async function main() {
240
- // 1. Load cached credentials never open browser automatically
241
- // User must run `npx moeba-claude-channel --login` to authenticate new projects
240
+ // 1. Authenticatethree modes:
241
+ // a. Cached credentials (fastest, no network)
242
+ // b. API key + email env vars (headless — SSH, CI, inviting others)
243
+ // c. Browser OAuth (--login flag)
242
244
  const loginMode = process.argv.includes('--login');
245
+ const envApiKey = process.env.MOEBA_API_KEY;
246
+ const envEmail = process.env.MOEBA_EMAIL;
243
247
  let creds = loadCredentials();
244
- if (!creds && loginMode) {
248
+ if (!creds && envApiKey && envEmail) {
249
+ // Mode B: headless auth via API key + email
250
+ console.error(`Authenticating as ${envEmail} via API key...`);
251
+ try {
252
+ const response = await fetch(`${MOEBA_API_URL}/channel/auth`, {
253
+ method: 'POST',
254
+ headers: { 'Content-Type': 'application/json' },
255
+ body: JSON.stringify({ apiKey: envApiKey, email: envEmail, projectName: PROJECT_NAME }),
256
+ });
257
+ if (!response.ok) {
258
+ const err = await response.text();
259
+ console.error(`API key auth failed: ${err}`);
260
+ }
261
+ else {
262
+ const data = (await response.json());
263
+ creds = {
264
+ token: data.token,
265
+ email: data.email,
266
+ businessId: data.businessId,
267
+ agentId: data.agentId,
268
+ connectionId: data.connectionId,
269
+ agentApiKey: data.agentApiKey,
270
+ projectName: PROJECT_NAME,
271
+ };
272
+ saveCredentials(creds);
273
+ }
274
+ }
275
+ catch (err) {
276
+ console.error(`API key auth error: ${err.message}`);
277
+ }
278
+ }
279
+ else if (!creds && loginMode) {
280
+ // Mode C: browser OAuth
245
281
  console.error('No Moeba credentials found — opening browser to sign in...');
246
282
  creds = await authenticate();
247
283
  }
@@ -249,7 +285,7 @@ async function main() {
249
285
  console.error(`Authenticated as ${creds.email} (project: ${PROJECT_NAME})`);
250
286
  }
251
287
  else {
252
- console.error(`Moeba channel: no credentials for project "${PROJECT_NAME}" — run with --login to authenticate`);
288
+ console.error(`Moeba channel: no credentials for project "${PROJECT_NAME}" — run with --login or set MOEBA_API_KEY + MOEBA_EMAIL`);
253
289
  }
254
290
  // 2. Create MCP channel server
255
291
  const mcp = new Server({ name: 'moeba', version: '0.0.1' }, {
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "moeba-claude-channel",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Claude Code channel for Moeba — chat with Claude Code from the Moeba app",
5
5
  "type": "module",
6
6
  "main": "dist/moeba-channel.js",
7
7
  "bin": {
8
- "moeba-channel": "dist/moeba-channel.js"
8
+ "moeba-claude-channel": "dist/moeba-channel.js"
9
9
  },
10
10
  "files": [
11
11
  "dist"
12
12
  ],
13
13
  "scripts": {
14
14
  "build": "tsc",
15
- "prepublishOnly": "npm run build"
15
+ "prepublishOnly": "npm run build && chmod +x dist/moeba-channel.js"
16
16
  },
17
17
  "keywords": [
18
18
  "claude-code",