nworks 0.7.0 → 1.0.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 +163 -141
- package/dist/index.js +79 -24
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +46 -18
- package/dist/mcp.js.map +1 -1
- package/package.json +8 -5
package/dist/mcp.js
CHANGED
|
@@ -13811,20 +13811,15 @@ async function ensureConfigDir() {
|
|
|
13811
13811
|
function getCredentialsFromEnv() {
|
|
13812
13812
|
const clientId = process.env["NWORKS_CLIENT_ID"];
|
|
13813
13813
|
const clientSecret = process.env["NWORKS_CLIENT_SECRET"];
|
|
13814
|
-
|
|
13815
|
-
|
|
13816
|
-
|
|
13817
|
-
|
|
13818
|
-
|
|
13819
|
-
|
|
13820
|
-
|
|
13821
|
-
|
|
13822
|
-
|
|
13823
|
-
botId,
|
|
13824
|
-
domainId: process.env["NWORKS_DOMAIN_ID"]
|
|
13825
|
-
};
|
|
13826
|
-
}
|
|
13827
|
-
return null;
|
|
13814
|
+
if (!clientId || !clientSecret) return null;
|
|
13815
|
+
return {
|
|
13816
|
+
clientId,
|
|
13817
|
+
clientSecret,
|
|
13818
|
+
serviceAccount: process.env["NWORKS_SERVICE_ACCOUNT"],
|
|
13819
|
+
privateKeyPath: process.env["NWORKS_PRIVATE_KEY_PATH"],
|
|
13820
|
+
botId: process.env["NWORKS_BOT_ID"],
|
|
13821
|
+
domainId: process.env["NWORKS_DOMAIN_ID"]
|
|
13822
|
+
};
|
|
13828
13823
|
}
|
|
13829
13824
|
async function loadCredentials(profile = "default") {
|
|
13830
13825
|
const envCreds = getCredentialsFromEnv();
|
|
@@ -13891,6 +13886,11 @@ async function saveUserToken(token, profile = "default") {
|
|
|
13891
13886
|
import { readFile as readFile2 } from "fs/promises";
|
|
13892
13887
|
import jwt2 from "jsonwebtoken";
|
|
13893
13888
|
async function createJWT(creds) {
|
|
13889
|
+
if (!creds.serviceAccount || !creds.privateKeyPath) {
|
|
13890
|
+
throw new AuthError(
|
|
13891
|
+
"Service Account credentials required for bot authentication.\nRun `nworks login` with --service-account and --private-key flags."
|
|
13892
|
+
);
|
|
13893
|
+
}
|
|
13894
13894
|
const privateKey = await readFile2(creds.privateKeyPath, "utf-8");
|
|
13895
13895
|
const now = Math.floor(Date.now() / 1e3);
|
|
13896
13896
|
const payload = {
|
|
@@ -14018,6 +14018,11 @@ function buildContent(opts) {
|
|
|
14018
14018
|
async function send(opts) {
|
|
14019
14019
|
const profile = opts.profile ?? "default";
|
|
14020
14020
|
const creds = await loadCredentials(profile);
|
|
14021
|
+
if (!creds.botId) {
|
|
14022
|
+
throw new Error(
|
|
14023
|
+
"Bot ID is required for sending messages.\nRun `nworks login` with --bot-id flag to set up bot credentials."
|
|
14024
|
+
);
|
|
14025
|
+
}
|
|
14021
14026
|
const content = buildContent(opts);
|
|
14022
14027
|
const body = { content };
|
|
14023
14028
|
if (opts.to) {
|
|
@@ -14042,6 +14047,11 @@ async function send(opts) {
|
|
|
14042
14047
|
}
|
|
14043
14048
|
async function listMembers(channelId, profile = "default") {
|
|
14044
14049
|
const creds = await loadCredentials(profile);
|
|
14050
|
+
if (!creds.botId) {
|
|
14051
|
+
throw new Error(
|
|
14052
|
+
"Bot ID is required for listing channel members.\nRun `nworks login` with --bot-id flag to set up bot credentials."
|
|
14053
|
+
);
|
|
14054
|
+
}
|
|
14045
14055
|
const result = await request({
|
|
14046
14056
|
method: "GET",
|
|
14047
14057
|
path: `/bots/${creds.botId}/channels/${channelId}/members`,
|
|
@@ -14211,7 +14221,9 @@ async function getEvent(eventId, userId = "me", profile = "default") {
|
|
|
14211
14221
|
const res = await authedFetch(url2, { method: "GET" }, profile);
|
|
14212
14222
|
if (!res.ok) return handleError(res);
|
|
14213
14223
|
const data = await res.json();
|
|
14214
|
-
|
|
14224
|
+
const event = data.eventComponents[0];
|
|
14225
|
+
if (!event) throw new ApiError("NOT_FOUND", "Event not found", 404);
|
|
14226
|
+
return event;
|
|
14215
14227
|
}
|
|
14216
14228
|
async function updateEvent(opts) {
|
|
14217
14229
|
const userId = opts.userId ?? "me";
|
|
@@ -15509,9 +15521,9 @@ function registerTools(server) {
|
|
|
15509
15521
|
const token = await loadToken();
|
|
15510
15522
|
const isValid = token ? token.expiresAt > Date.now() / 1e3 : false;
|
|
15511
15523
|
const info = {
|
|
15512
|
-
serviceAccount: creds.serviceAccount,
|
|
15524
|
+
serviceAccount: creds.serviceAccount ?? null,
|
|
15513
15525
|
clientId: creds.clientId,
|
|
15514
|
-
botId: creds.botId,
|
|
15526
|
+
botId: creds.botId ?? null,
|
|
15515
15527
|
tokenValid: isValid
|
|
15516
15528
|
};
|
|
15517
15529
|
return {
|
|
@@ -15530,9 +15542,25 @@ function registerTools(server) {
|
|
|
15530
15542
|
|
|
15531
15543
|
// src/mcp/server.ts
|
|
15532
15544
|
async function startMcpServer() {
|
|
15545
|
+
try {
|
|
15546
|
+
await loadCredentials();
|
|
15547
|
+
} catch {
|
|
15548
|
+
console.error(
|
|
15549
|
+
"[nworks] Authentication required. Run: nworks login"
|
|
15550
|
+
);
|
|
15551
|
+
}
|
|
15552
|
+
try {
|
|
15553
|
+
const userToken = await loadUserToken();
|
|
15554
|
+
if (!userToken) {
|
|
15555
|
+
console.error(
|
|
15556
|
+
"[nworks] User OAuth not configured. Run: nworks login --user"
|
|
15557
|
+
);
|
|
15558
|
+
}
|
|
15559
|
+
} catch {
|
|
15560
|
+
}
|
|
15533
15561
|
const server = new McpServer({
|
|
15534
15562
|
name: "nworks",
|
|
15535
|
-
version: "0.
|
|
15563
|
+
version: "1.0.0"
|
|
15536
15564
|
});
|
|
15537
15565
|
registerTools(server);
|
|
15538
15566
|
const transport = new StdioServerTransport();
|