moeba-claude-channel 0.0.5 → 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.
- package/dist/moeba-channel.js +40 -4
- package/package.json +1 -1
package/dist/moeba-channel.js
CHANGED
|
@@ -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.
|
|
241
|
-
//
|
|
240
|
+
// 1. Authenticate — three 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 &&
|
|
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
|
|
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' }, {
|