@sideboard-ai/core 0.1.334 → 0.1.335
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/{abletime-SO2YHMEI.js → abletime-OGOHNRVB.js} +4 -4
- package/dist/{abletime-5FBKBO3R.js → abletime-TNONAVJG.js} +4 -4
- package/dist/{abletime-oauth-EUC5FFMD.js → abletime-oauth-DAZEUQJI.js} +3 -3
- package/dist/{abletime-oauth-I34WZZZL.js → abletime-oauth-TYDQ73GK.js} +3 -3
- package/dist/{abletime-rest-EI5ZJ72Z.js → abletime-rest-3FWZGTX6.js} +3 -3
- package/dist/{abletime-rest-HEQXSZAQ.js → abletime-rest-B4VI46MI.js} +3 -3
- package/dist/{agents-5NJ3FROS.js → agents-ISEAOZD5.js} +7 -7
- package/dist/{agents-SRM6OVML.js → agents-VTLFLMMT.js} +7 -7
- package/dist/{app-settings-JAEV53LB.js → app-settings-KOSVLMO5.js} +1 -1
- package/dist/{app-settings-SHZWNJBV.js → app-settings-YS5AUJTF.js} +1 -1
- package/dist/{chunk-EY5BJAPV.js → chunk-23KYDM2U.js} +23 -0
- package/dist/{chunk-F4OUZDIB.js → chunk-4BRO5LNX.js} +3 -3
- package/dist/{chunk-RJT6JPNX.js → chunk-4O7436ZH.js} +5 -5
- package/dist/{chunk-JJRTVB7D.js → chunk-4OVQGZEI.js} +3 -3
- package/dist/{chunk-SKPX66MO.js → chunk-4SP26Z6H.js} +5 -5
- package/dist/{chunk-WXOJSFGO.js → chunk-54GBJC6J.js} +8 -8
- package/dist/{chunk-QNKJCD7B.js → chunk-5FGQTB2Z.js} +2 -2
- package/dist/{chunk-25KXB7W6.js → chunk-5TVRPOVS.js} +1 -1
- package/dist/{chunk-EW5D53VB.js → chunk-AFSLMWQK.js} +1 -1
- package/dist/{chunk-ELDJBZ52.js → chunk-B6TPN624.js} +5 -5
- package/dist/{chunk-QVLDZWHZ.js → chunk-BDQFZAE6.js} +1 -1
- package/dist/{chunk-LEUAYFSG.js → chunk-CDRGQ6GX.js} +3 -3
- package/dist/{chunk-4J7R2BFU.js → chunk-EKI7D2AJ.js} +21 -21
- package/dist/{chunk-P7S3XGKL.js → chunk-ERCYQTJU.js} +3 -3
- package/dist/{chunk-UV33UCV6.js → chunk-FCBUDWP6.js} +2 -2
- package/dist/{chunk-YMV5O7KY.js → chunk-FEGRY7NL.js} +3 -3
- package/dist/{chunk-CS6LQUL6.js → chunk-HNW5KMGK.js} +2 -2
- package/dist/{chunk-277I5IBI.js → chunk-I2C5ZRVO.js} +1 -1
- package/dist/{chunk-ZT5YPYZE.js → chunk-KAIOL2M5.js} +1 -1
- package/dist/{chunk-BAIPCN34.js → chunk-LYJ5AVK4.js} +2 -2
- package/dist/{chunk-6RUSADA7.js → chunk-MGEUXR6E.js} +3 -3
- package/dist/{chunk-7BAS6DF7.js → chunk-N6TGSJVC.js} +22 -0
- package/dist/{chunk-TLL2K2MY.js → chunk-NB4U75TJ.js} +7 -7
- package/dist/{chunk-MXQ66CLO.js → chunk-OMKTX7ZW.js} +3 -3
- package/dist/{chunk-QKJC725N.js → chunk-PSXBOMXI.js} +20 -20
- package/dist/{chunk-7MPRTC6X.js → chunk-Q73I6I2K.js} +1 -1
- package/dist/{chunk-RCRDNOAT.js → chunk-QWFNKOGA.js} +2 -2
- package/dist/{chunk-NCFYUUSC.js → chunk-SYTTUNX6.js} +1 -1
- package/dist/{chunk-HJIA4X3L.js → chunk-W6J3ZWLJ.js} +2 -2
- package/dist/{chunk-D6V6F74A.js → chunk-WSZIJNAR.js} +5 -5
- package/dist/{conductor-XSP3SOS2.js → conductor-77L3QTZ2.js} +5 -5
- package/dist/{conductor-LUPB6RBH.js → conductor-JH26KU3W.js} +5 -5
- package/dist/{coordinator-prompt-O75QUEHP.js → coordinator-prompt-UKJJAMBG.js} +4 -4
- package/dist/{coordinator-prompt-EJJNJ5K7.js → coordinator-prompt-WVVC2TLP.js} +4 -4
- package/dist/{global-workspace-3IG44NAT.js → global-workspace-B5IHENCP.js} +4 -4
- package/dist/{global-workspace-Q4OURN7M.js → global-workspace-QDIPRW6G.js} +4 -4
- package/dist/index.cjs +1476 -568
- package/dist/index.d.cts +101 -15
- package/dist/index.d.ts +101 -15
- package/dist/index.js +1403 -531
- package/dist/{linear-FRJRK6KI.js → linear-5E2WI4QQ.js} +2 -2
- package/dist/{linear-7HSIGV5S.js → linear-P3LP455O.js} +2 -2
- package/dist/{linear-list-LDMBSKYI.js → linear-list-AXK62DPW.js} +1 -1
- package/dist/{linear-list-I6DNJC6V.js → linear-list-Y3INIBYH.js} +1 -1
- package/dist/mcp/run-stdio.cjs +29 -1
- package/dist/mcp/run-stdio.js +16 -16
- package/dist/{optional-cli-KWIII44P.js → optional-cli-6J6C4I3X.js} +3 -3
- package/dist/{optional-cli-XJE4BELL.js → optional-cli-X6I35UNI.js} +4 -4
- package/dist/{orchestrator-WHXHBNRS.js → orchestrator-BOLYQZO7.js} +10 -10
- package/dist/{orchestrator-IYXIWNB5.js → orchestrator-ZUIU667R.js} +10 -10
- package/dist/{thread-store-PCIMS6RA.js → thread-store-DCO5MZWJ.js} +2 -2
- package/dist/{thread-store-NVFWKJFH.js → thread-store-QGBPSZU2.js} +2 -2
- package/dist/{workspaces-ALUHOCWK.js → workspaces-VXE2MBKD.js} +4 -4
- package/dist/{workspaces-QGKSXA76.js → workspaces-WZZNNUJL.js} +4 -4
- package/dist/{worktree-6WWUWH4K.js → worktree-GWS77LWX.js} +3 -3
- package/dist/{worktree-N435EXSP.js → worktree-S4YOAYRA.js} +3 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1440,6 +1440,22 @@ var init_protocol = __esm({
|
|
|
1440
1440
|
}
|
|
1441
1441
|
});
|
|
1442
1442
|
|
|
1443
|
+
// src/slack/client-ids.ts
|
|
1444
|
+
function mergeSlackClientIds(ids) {
|
|
1445
|
+
const out = [];
|
|
1446
|
+
for (const raw of ids) {
|
|
1447
|
+
const id = raw?.trim() ?? "";
|
|
1448
|
+
if (!id || out.includes(id)) continue;
|
|
1449
|
+
out.push(id);
|
|
1450
|
+
}
|
|
1451
|
+
return out;
|
|
1452
|
+
}
|
|
1453
|
+
var init_client_ids = __esm({
|
|
1454
|
+
"src/slack/client-ids.ts"() {
|
|
1455
|
+
"use strict";
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
|
|
1443
1459
|
// src/store/private-file.ts
|
|
1444
1460
|
function writePrivateFile(path2, contents) {
|
|
1445
1461
|
(0, import_node_fs6.mkdirSync)((0, import_node_path8.dirname)(path2), { recursive: true });
|
|
@@ -2511,6 +2527,12 @@ function normalizeIntegrations(raw) {
|
|
|
2511
2527
|
const id = source.slackClientId.trim();
|
|
2512
2528
|
if (id) out.slackClientId = id;
|
|
2513
2529
|
}
|
|
2530
|
+
if (Array.isArray(source.slackClientIds)) {
|
|
2531
|
+
const ids = mergeSlackClientIds(
|
|
2532
|
+
source.slackClientIds.filter((id) => typeof id === "string")
|
|
2533
|
+
);
|
|
2534
|
+
if (ids.length > 0) out.slackClientIds = ids;
|
|
2535
|
+
}
|
|
2514
2536
|
if (typeof source.slackClientSecret === "string") {
|
|
2515
2537
|
const secret = source.slackClientSecret.trim();
|
|
2516
2538
|
if (secret) out.slackClientSecret = secret;
|
|
@@ -3089,6 +3111,11 @@ function updateIntegrationsSettings(patch) {
|
|
|
3089
3111
|
integrations.slackClientId = patch.slackClientId.trim();
|
|
3090
3112
|
}
|
|
3091
3113
|
}
|
|
3114
|
+
if ("slackClientIds" in patch) {
|
|
3115
|
+
const ids = mergeSlackClientIds(patch.slackClientIds ?? []);
|
|
3116
|
+
if (ids.length === 0) delete integrations.slackClientIds;
|
|
3117
|
+
else integrations.slackClientIds = ids;
|
|
3118
|
+
}
|
|
3092
3119
|
if ("slackClientSecret" in patch) {
|
|
3093
3120
|
if (patch.slackClientSecret == null || patch.slackClientSecret.trim() === "") {
|
|
3094
3121
|
delete integrations.slackClientSecret;
|
|
@@ -3879,6 +3906,7 @@ var init_app_settings = __esm({
|
|
|
3879
3906
|
init_nested_electron_env();
|
|
3880
3907
|
init_account_profile();
|
|
3881
3908
|
init_protocol();
|
|
3909
|
+
init_client_ids();
|
|
3882
3910
|
init_paths();
|
|
3883
3911
|
init_private_file();
|
|
3884
3912
|
init_secret_vault();
|
|
@@ -7354,9 +7382,9 @@ function parseOneQuestion(raw) {
|
|
|
7354
7382
|
if (!question) return null;
|
|
7355
7383
|
const options = parseOptions(o.options);
|
|
7356
7384
|
if (options.length < 1) return null;
|
|
7357
|
-
const
|
|
7385
|
+
const header2 = typeof o.header === "string" && o.header.trim() ? o.header.trim() : void 0;
|
|
7358
7386
|
const multiSelect = Boolean(o.multiSelect ?? o.multi_select);
|
|
7359
|
-
return { question, header, multiSelect, options };
|
|
7387
|
+
return { question, header: header2, multiSelect, options };
|
|
7360
7388
|
}
|
|
7361
7389
|
function parsePlanQuestionsInput(input) {
|
|
7362
7390
|
const root = asRecord2(input);
|
|
@@ -7470,12 +7498,12 @@ function formatPlanQuestionAnswers(questions2, answers) {
|
|
|
7470
7498
|
for (let i = 0; i < questions2.length; i++) {
|
|
7471
7499
|
const q = questions2[i];
|
|
7472
7500
|
const a = answers.find((x) => x.questionIndex === i);
|
|
7473
|
-
const
|
|
7501
|
+
const header2 = q.header ? `**${q.header}** \u2014 ` : "";
|
|
7474
7502
|
const parts = [];
|
|
7475
7503
|
if (a?.selected.length) parts.push(a.selected.join(", "));
|
|
7476
7504
|
if (a?.other?.trim()) parts.push(a.other.trim());
|
|
7477
7505
|
const body = parts.length ? parts.join(" \xB7 ") : "(no answer)";
|
|
7478
|
-
lines.push(`${i + 1}. ${
|
|
7506
|
+
lines.push(`${i + 1}. ${header2}${q.question} `);
|
|
7479
7507
|
lines.push(` \u2192 ${body}`);
|
|
7480
7508
|
}
|
|
7481
7509
|
return lines.join("\n");
|
|
@@ -7484,8 +7512,8 @@ function formatPlanQuestionsForChat(questions2) {
|
|
|
7484
7512
|
const lines = ["### Questions for you", ""];
|
|
7485
7513
|
for (let i = 0; i < questions2.length; i++) {
|
|
7486
7514
|
const q = questions2[i];
|
|
7487
|
-
const
|
|
7488
|
-
lines.push(`${i + 1}. ${
|
|
7515
|
+
const header2 = q.header ? `**${q.header}** \u2014 ` : "";
|
|
7516
|
+
lines.push(`${i + 1}. ${header2}${q.question}`);
|
|
7489
7517
|
for (let oi = 0; oi < q.options.length; oi++) {
|
|
7490
7518
|
const opt = q.options[oi];
|
|
7491
7519
|
const desc = opt.description?.trim();
|
|
@@ -9802,9 +9830,9 @@ async function ensureWorktreeSideboardIgnored(worktreePath) {
|
|
|
9802
9830
|
if (missing.length > 0) {
|
|
9803
9831
|
const prefix = body && !body.endsWith("\n") ? `${body}
|
|
9804
9832
|
` : body;
|
|
9805
|
-
const
|
|
9833
|
+
const header2 = body.includes(EXCLUDE_COMMENT) ? "" : `${EXCLUDE_COMMENT}
|
|
9806
9834
|
`;
|
|
9807
|
-
(0, import_node_fs21.writeFileSync)(excludePath, `${prefix}${
|
|
9835
|
+
(0, import_node_fs21.writeFileSync)(excludePath, `${prefix}${header2}${missing.join("\n")}
|
|
9808
9836
|
`, "utf8");
|
|
9809
9837
|
}
|
|
9810
9838
|
const listed = await git(["ls-files", "-z", "--", ".sideboard"], worktreePath, {
|
|
@@ -12086,16 +12114,16 @@ async function fetchOriginWithAuth(repoPath, args, timeoutMs) {
|
|
|
12086
12114
|
const token = await resolveGithubAgentToken(mode, repoPath);
|
|
12087
12115
|
if (!token) return false;
|
|
12088
12116
|
const remoteUrl2 = await originRemoteUrl(repoPath);
|
|
12089
|
-
const tryHttps = async (
|
|
12117
|
+
const tryHttps = async (header2) => git(args, repoPath, {
|
|
12090
12118
|
reject: false,
|
|
12091
12119
|
timeoutMs,
|
|
12092
12120
|
env: githubHttpsRetryEnv(remoteUrl2),
|
|
12093
12121
|
config: {
|
|
12094
|
-
"http.extraHeader":
|
|
12122
|
+
"http.extraHeader": header2
|
|
12095
12123
|
}
|
|
12096
12124
|
});
|
|
12097
|
-
const
|
|
12098
|
-
if (
|
|
12125
|
+
const bearer2 = await tryHttps(`AUTHORIZATION: bearer ${token}`);
|
|
12126
|
+
if (bearer2.exitCode === 0) return true;
|
|
12099
12127
|
const basic = Buffer.from(`x-access-token:${token}`, "utf8").toString("base64");
|
|
12100
12128
|
const basicFetch = await tryHttps(`Authorization: Basic ${basic}`);
|
|
12101
12129
|
return basicFetch.exitCode === 0;
|
|
@@ -12439,19 +12467,19 @@ async function pushBranch(worktreePath, branchName) {
|
|
|
12439
12467
|
);
|
|
12440
12468
|
}
|
|
12441
12469
|
const remoteUrl2 = await originRemoteUrl(worktreePath);
|
|
12442
|
-
const tryHttps = async (
|
|
12470
|
+
const tryHttps = async (header2) => git(["push", "-u", "origin", branchName], worktreePath, {
|
|
12443
12471
|
reject: false,
|
|
12444
12472
|
env: githubHttpsRetryEnv(remoteUrl2),
|
|
12445
12473
|
config: {
|
|
12446
|
-
"http.extraHeader":
|
|
12474
|
+
"http.extraHeader": header2
|
|
12447
12475
|
}
|
|
12448
12476
|
});
|
|
12449
|
-
const
|
|
12450
|
-
if (
|
|
12477
|
+
const bearer2 = await tryHttps(`AUTHORIZATION: bearer ${token}`);
|
|
12478
|
+
if (bearer2.exitCode === 0) return;
|
|
12451
12479
|
const basic = Buffer.from(`x-access-token:${token}`, "utf8").toString("base64");
|
|
12452
12480
|
const basicPush = await tryHttps(`Authorization: Basic ${basic}`);
|
|
12453
12481
|
if (basicPush.exitCode === 0) return;
|
|
12454
|
-
const httpsErr = (basicPush.stderr ||
|
|
12482
|
+
const httpsErr = (basicPush.stderr || bearer2.stderr || bearer2.stdout).trim();
|
|
12455
12483
|
throw new Error(httpsErr || sshErr || `git push origin ${branchName} failed`);
|
|
12456
12484
|
}
|
|
12457
12485
|
async function markCursorPrReady(cwd, slug, selector) {
|
|
@@ -12633,7 +12661,7 @@ var init_worktree = __esm({
|
|
|
12633
12661
|
init_workspace_scratch();
|
|
12634
12662
|
init_worktree_labels();
|
|
12635
12663
|
init_team_slugs();
|
|
12636
|
-
PR_INFO_JSON_FIELDS = "number,title,headRefName,url,isCrossRepository,author,isDraft,labels";
|
|
12664
|
+
PR_INFO_JSON_FIELDS = "number,title,headRefName,url,isCrossRepository,author,isDraft,labels,state";
|
|
12637
12665
|
PR_DETAILS_JSON_FIELDS = [
|
|
12638
12666
|
"number",
|
|
12639
12667
|
"title",
|
|
@@ -16461,8 +16489,8 @@ async function listenMcpUiProxy(opts) {
|
|
|
16461
16489
|
res.writeHead(404).end();
|
|
16462
16490
|
return;
|
|
16463
16491
|
}
|
|
16464
|
-
const
|
|
16465
|
-
const sid = typeof
|
|
16492
|
+
const header2 = req.headers["mcp-session-id"];
|
|
16493
|
+
const sid = typeof header2 === "string" ? header2 : "";
|
|
16466
16494
|
const sessionKey = `${target.server}:${target.dirsKey}`;
|
|
16467
16495
|
let transport = sid ? transports.get(`${sessionKey}:${sid}`) : void 0;
|
|
16468
16496
|
if (!transport) {
|
|
@@ -17239,9 +17267,9 @@ function filenameFromUrl(url, fallback = "attachment") {
|
|
|
17239
17267
|
}
|
|
17240
17268
|
return fallback;
|
|
17241
17269
|
}
|
|
17242
|
-
function filenameFromContentDisposition(
|
|
17243
|
-
if (!
|
|
17244
|
-
const star =
|
|
17270
|
+
function filenameFromContentDisposition(header2) {
|
|
17271
|
+
if (!header2) return void 0;
|
|
17272
|
+
const star = header2.match(/filename\*\s*=\s*(?:UTF-8''|utf-8'')([^;]+)/i);
|
|
17245
17273
|
if (star?.[1]) {
|
|
17246
17274
|
try {
|
|
17247
17275
|
return decodeURIComponent(star[1].trim().replace(/^["']|["']$/g, ""));
|
|
@@ -17249,7 +17277,7 @@ function filenameFromContentDisposition(header) {
|
|
|
17249
17277
|
return star[1].trim().replace(/^["']|["']$/g, "");
|
|
17250
17278
|
}
|
|
17251
17279
|
}
|
|
17252
|
-
const plain =
|
|
17280
|
+
const plain = header2.match(/filename\s*=\s*("(?:\\.|[^"])*"|[^;]+)/i);
|
|
17253
17281
|
if (!plain?.[1]) return void 0;
|
|
17254
17282
|
return plain[1].trim().replace(/^["']|["']$/g, "").replace(/\\"/g, '"');
|
|
17255
17283
|
}
|
|
@@ -29879,16 +29907,16 @@ function splitCombinedDiff(stdout) {
|
|
|
29879
29907
|
for (const part of parts) {
|
|
29880
29908
|
if (!part.trim()) continue;
|
|
29881
29909
|
const full = `diff --git ${part}`.replace(/\n$/, "");
|
|
29882
|
-
const
|
|
29883
|
-
if (!
|
|
29884
|
-
map.set(
|
|
29910
|
+
const header2 = full.match(/^diff --git a\/(.+?) b\/(.+?)(?:\n|$)/);
|
|
29911
|
+
if (!header2) continue;
|
|
29912
|
+
map.set(header2[2], full);
|
|
29885
29913
|
}
|
|
29886
29914
|
return map;
|
|
29887
29915
|
}
|
|
29888
29916
|
function syntheticAddPatch(path2, content, maxHunk) {
|
|
29889
29917
|
const lines = content.split("\n");
|
|
29890
29918
|
const body = lines.map((l) => `+${l}`).join("\n");
|
|
29891
|
-
const
|
|
29919
|
+
const header2 = `diff --git a/${path2} b/${path2}
|
|
29892
29920
|
new file mode 100644
|
|
29893
29921
|
--- /dev/null
|
|
29894
29922
|
+++ b/${path2}
|
|
@@ -29897,7 +29925,7 @@ new file mode 100644
|
|
|
29897
29925
|
return {
|
|
29898
29926
|
path: path2,
|
|
29899
29927
|
status: "A",
|
|
29900
|
-
patch: capPatch(`${
|
|
29928
|
+
patch: capPatch(`${header2}${body}`, maxHunk),
|
|
29901
29929
|
additions: lines.length,
|
|
29902
29930
|
deletions: 0
|
|
29903
29931
|
};
|
|
@@ -35809,6 +35837,7 @@ __export(index_exports, {
|
|
|
35809
35837
|
AbleTimeOAuthCancelledError: () => AbleTimeOAuthCancelledError,
|
|
35810
35838
|
BAKED_ABLETIME_OAUTH_CLIENT_ID: () => BAKED_ABLETIME_OAUTH_CLIENT_ID,
|
|
35811
35839
|
BAKED_REMOTE_RELAY_URL: () => BAKED_REMOTE_RELAY_URL,
|
|
35840
|
+
BAKED_SLACK_CLIENT_ID: () => BAKED_SLACK_CLIENT_ID,
|
|
35812
35841
|
BAKED_SLACK_RELAY_URL: () => BAKED_SLACK_RELAY_URL,
|
|
35813
35842
|
BASE_ALLOWED_TOOLS: () => BASE_ALLOWED_TOOLS,
|
|
35814
35843
|
BRIGHTSY_MCP_ALLOWED_TOOLS: () => BRIGHTSY_MCP_ALLOWED_TOOLS,
|
|
@@ -36113,6 +36142,7 @@ __export(index_exports, {
|
|
|
36113
36142
|
createOrUpdatePr: () => createOrUpdatePr,
|
|
36114
36143
|
createPrStack: () => createPrStack,
|
|
36115
36144
|
createSchedule: () => createSchedule,
|
|
36145
|
+
createSlackOrgApp: () => createSlackOrgApp,
|
|
36116
36146
|
createThread: () => createThread,
|
|
36117
36147
|
createThreadWorktree: () => createThreadWorktree,
|
|
36118
36148
|
currentBranch: () => currentBranch,
|
|
@@ -36536,6 +36566,7 @@ __export(index_exports, {
|
|
|
36536
36566
|
mergePrStack: () => mergePrStack,
|
|
36537
36567
|
mergeSetupOutput: () => mergeSetupOutput,
|
|
36538
36568
|
mergeSideboardIntoMcpServersJson: () => mergeSideboardIntoMcpServersJson,
|
|
36569
|
+
mergeSlackClientIds: () => mergeSlackClientIds,
|
|
36539
36570
|
mergeUsage: () => mergeUsage,
|
|
36540
36571
|
messagePartParentId: () => messagePartParentId,
|
|
36541
36572
|
messagesForCompactArchive: () => messagesForCompactArchive,
|
|
@@ -36743,6 +36774,7 @@ __export(index_exports, {
|
|
|
36743
36774
|
saveAppSettings: () => saveAppSettings,
|
|
36744
36775
|
saveLinearOAuth: () => saveLinearOAuth,
|
|
36745
36776
|
saveRemotePhoneToken: () => saveRemotePhoneToken,
|
|
36777
|
+
saveSlackOrgCredentials: () => saveSlackOrgCredentials,
|
|
36746
36778
|
saveWorktreeRunPorts: () => saveWorktreeRunPorts,
|
|
36747
36779
|
scheduleNeedsCaffeinate: () => scheduleNeedsCaffeinate,
|
|
36748
36780
|
schedulesPath: () => schedulesPath,
|
|
@@ -39209,8 +39241,8 @@ function dispatchPhoneWorkspace(cmd, emit, publishOpened) {
|
|
|
39209
39241
|
emit({ op: "error", chatId: cmd.chatId, message: "That agent is not on this Mac." });
|
|
39210
39242
|
return;
|
|
39211
39243
|
}
|
|
39212
|
-
void readPhoneHeader(thread).then((
|
|
39213
|
-
emit({ op: "header", chatId: cmd.chatId, ...
|
|
39244
|
+
void readPhoneHeader(thread).then((header2) => {
|
|
39245
|
+
emit({ op: "header", chatId: cmd.chatId, ...header2 });
|
|
39214
39246
|
});
|
|
39215
39247
|
return;
|
|
39216
39248
|
}
|
|
@@ -40067,12 +40099,52 @@ function sourceWarning(label, err) {
|
|
|
40067
40099
|
const message = err instanceof Error ? err.message : String(err);
|
|
40068
40100
|
return message ? `${label}: ${message}` : `${label} failed.`;
|
|
40069
40101
|
}
|
|
40102
|
+
function phonePrNumberQuery(query) {
|
|
40103
|
+
const match = query.trim().match(/^#?(\d+)$/);
|
|
40104
|
+
if (!match) return null;
|
|
40105
|
+
const n = Number(match[1]);
|
|
40106
|
+
if (!Number.isSafeInteger(n) || n <= 0) return null;
|
|
40107
|
+
return n;
|
|
40108
|
+
}
|
|
40109
|
+
function phonePrMatchesQuery(pr, query) {
|
|
40110
|
+
const raw = query.trim().toLowerCase();
|
|
40111
|
+
if (!raw) return true;
|
|
40112
|
+
const q = raw.replace(/^#/, "");
|
|
40113
|
+
if (!q) return pr.title.toLowerCase().includes(raw);
|
|
40114
|
+
return pr.title.toLowerCase().includes(q) || String(pr.number).includes(q);
|
|
40115
|
+
}
|
|
40116
|
+
function prIsListedOpen(pr) {
|
|
40117
|
+
const state = pr.state?.trim().toLowerCase();
|
|
40118
|
+
return state !== "closed" && state !== "merged";
|
|
40119
|
+
}
|
|
40120
|
+
function mergePrs(groups) {
|
|
40121
|
+
const out = [];
|
|
40122
|
+
const seen = /* @__PURE__ */ new Set();
|
|
40123
|
+
for (const group of groups) {
|
|
40124
|
+
for (const pr of group) {
|
|
40125
|
+
if (!pr || seen.has(pr.number) || !prIsListedOpen(pr)) continue;
|
|
40126
|
+
seen.add(pr.number);
|
|
40127
|
+
out.push(pr);
|
|
40128
|
+
}
|
|
40129
|
+
}
|
|
40130
|
+
return out;
|
|
40131
|
+
}
|
|
40132
|
+
async function loadPhonePrs(path2, query) {
|
|
40133
|
+
const number = phonePrNumberQuery(query);
|
|
40134
|
+
if (!query) return listPrs(path2, { state: "open", limit: 40 });
|
|
40135
|
+
const [searched, recent, exact] = await Promise.all([
|
|
40136
|
+
listPrs(path2, { state: "open", limit: 40, query: number == null ? query : String(number) }),
|
|
40137
|
+
listPrs(path2, { state: "open", limit: number == null ? 40 : 200 }),
|
|
40138
|
+
number == null ? Promise.resolve(null) : getPr(path2, number).catch(() => null)
|
|
40139
|
+
]);
|
|
40140
|
+
return mergePrs([exact ? [exact] : [], searched, recent]).filter((pr) => phonePrMatchesQuery(pr, query));
|
|
40141
|
+
}
|
|
40070
40142
|
async function listPhoneSources(repoPath, query) {
|
|
40071
40143
|
const path2 = assertKnownProject(repoPath);
|
|
40072
40144
|
const q = query?.trim() ?? "";
|
|
40073
40145
|
const warnings = [];
|
|
40074
40146
|
const [prs, branches, issues] = await Promise.all([
|
|
40075
|
-
|
|
40147
|
+
loadPhonePrs(path2, q).catch((err) => {
|
|
40076
40148
|
warnings.push(sourceWarning("Pull requests", err));
|
|
40077
40149
|
return [];
|
|
40078
40150
|
}),
|
|
@@ -41091,26 +41163,6 @@ function slackOAuthHtmlPage(title, body) {
|
|
|
41091
41163
|
<style>body{font-family:ui-sans-serif,system-ui,sans-serif;padding:48px 24px;max-width:36rem;margin:0 auto;color:#1a1a1a}
|
|
41092
41164
|
h1{font-size:1.25rem}p{line-height:1.5;color:#444}</style></head><body>${body}</body></html>`;
|
|
41093
41165
|
}
|
|
41094
|
-
function parseSlackOAuthCallbackUrl(reqUrl) {
|
|
41095
|
-
let url;
|
|
41096
|
-
try {
|
|
41097
|
-
url = new URL(reqUrl, SLACK_OAUTH_REDIRECT);
|
|
41098
|
-
} catch {
|
|
41099
|
-
return null;
|
|
41100
|
-
}
|
|
41101
|
-
if (url.pathname !== SLACK_OAUTH_CALLBACK_PATH) return null;
|
|
41102
|
-
return url;
|
|
41103
|
-
}
|
|
41104
|
-
function parseSlackOAuthResultUrl(reqUrl) {
|
|
41105
|
-
let url;
|
|
41106
|
-
try {
|
|
41107
|
-
url = new URL(reqUrl, SLACK_OAUTH_REDIRECT);
|
|
41108
|
-
} catch {
|
|
41109
|
-
return null;
|
|
41110
|
-
}
|
|
41111
|
-
if (url.pathname !== SLACK_OAUTH_RESULT_PATH) return null;
|
|
41112
|
-
return url;
|
|
41113
|
-
}
|
|
41114
41166
|
|
|
41115
41167
|
// src/slack/baked-app.ts
|
|
41116
41168
|
var BAKED_SLACK_CLIENT_ID = "7592788819232.11813536272562";
|
|
@@ -41192,11 +41244,15 @@ async function exchangeSlackOAuthCode(opts) {
|
|
|
41192
41244
|
team_name: data.team?.name?.trim() || teamId,
|
|
41193
41245
|
user_id: data.authed_user?.id?.trim() || void 0,
|
|
41194
41246
|
bot_token: data.access_token?.trim() || void 0,
|
|
41247
|
+
bot_user_id: data.bot_user_id?.trim() || void 0,
|
|
41195
41248
|
user_token: data.authed_user?.access_token?.trim() || void 0,
|
|
41196
41249
|
scopes: [data.scope, data.authed_user?.scope].filter(Boolean).join(",")
|
|
41197
41250
|
};
|
|
41198
41251
|
}
|
|
41199
41252
|
|
|
41253
|
+
// src/slack/events-api.ts
|
|
41254
|
+
var import_node_crypto23 = require("crypto");
|
|
41255
|
+
|
|
41200
41256
|
// src/slack/socket-mode.ts
|
|
41201
41257
|
var import_ws3 = require("ws");
|
|
41202
41258
|
|
|
@@ -41478,8 +41534,972 @@ function connectSession(ws, opts, log) {
|
|
|
41478
41534
|
});
|
|
41479
41535
|
}
|
|
41480
41536
|
|
|
41537
|
+
// src/slack/events-api.ts
|
|
41538
|
+
var MAX_SKEW_MS = 5 * 6e4;
|
|
41539
|
+
function verifySlackRequestSignature(opts) {
|
|
41540
|
+
const timestamp = opts.timestamp.trim();
|
|
41541
|
+
const signature = opts.signature.trim();
|
|
41542
|
+
const seconds = Number(timestamp);
|
|
41543
|
+
if (!timestamp || !signature || !Number.isFinite(seconds)) return false;
|
|
41544
|
+
const now = opts.nowMs ?? Date.now();
|
|
41545
|
+
if (Math.abs(now - seconds * 1e3) > MAX_SKEW_MS) return false;
|
|
41546
|
+
const hmac = (0, import_node_crypto23.createHmac)("sha256", opts.signingSecret).update(`v0:${timestamp}:${opts.rawBody}`).digest("hex");
|
|
41547
|
+
const expected = Buffer.from(`v0=${hmac}`);
|
|
41548
|
+
const presented = Buffer.from(signature);
|
|
41549
|
+
return expected.length === presented.length && (0, import_node_crypto23.timingSafeEqual)(expected, presented);
|
|
41550
|
+
}
|
|
41551
|
+
function parseSlackEventsBody(raw) {
|
|
41552
|
+
try {
|
|
41553
|
+
const parsed = JSON.parse(raw);
|
|
41554
|
+
if (!parsed || typeof parsed !== "object") return null;
|
|
41555
|
+
return parsed;
|
|
41556
|
+
} catch {
|
|
41557
|
+
return null;
|
|
41558
|
+
}
|
|
41559
|
+
}
|
|
41560
|
+
function asSocketFrame(body) {
|
|
41561
|
+
return {
|
|
41562
|
+
type: "events_api",
|
|
41563
|
+
payload: {
|
|
41564
|
+
team_id: typeof body.team_id === "string" ? body.team_id : void 0,
|
|
41565
|
+
event: body.event
|
|
41566
|
+
}
|
|
41567
|
+
};
|
|
41568
|
+
}
|
|
41569
|
+
function inboundFromEventsBody(body) {
|
|
41570
|
+
if (body.type !== "event_callback") return null;
|
|
41571
|
+
return inboundFromSocketFrame(asSocketFrame(body));
|
|
41572
|
+
}
|
|
41573
|
+
function lifecycleFromEventsBody(body) {
|
|
41574
|
+
if (body.type !== "event_callback") return null;
|
|
41575
|
+
return lifecycleFromSocketFrame(asSocketFrame(body));
|
|
41576
|
+
}
|
|
41577
|
+
var SlackEventDeduper = class {
|
|
41578
|
+
constructor(ttlMs = 10 * 6e4) {
|
|
41579
|
+
this.ttlMs = ttlMs;
|
|
41580
|
+
}
|
|
41581
|
+
ttlMs;
|
|
41582
|
+
seen = /* @__PURE__ */ new Map();
|
|
41583
|
+
duplicate(eventId, now = Date.now()) {
|
|
41584
|
+
const id = eventId.trim();
|
|
41585
|
+
if (!id) return false;
|
|
41586
|
+
for (const [key, expires] of this.seen) {
|
|
41587
|
+
if (expires <= now) this.seen.delete(key);
|
|
41588
|
+
}
|
|
41589
|
+
if (this.seen.has(id)) return true;
|
|
41590
|
+
this.seen.set(id, now + this.ttlMs);
|
|
41591
|
+
return false;
|
|
41592
|
+
}
|
|
41593
|
+
};
|
|
41594
|
+
|
|
41595
|
+
// src/slack/secret-box.ts
|
|
41596
|
+
var import_node_crypto24 = require("crypto");
|
|
41597
|
+
var VERSION = "v1";
|
|
41598
|
+
function parseSlackTokenKey(raw) {
|
|
41599
|
+
const text7 = raw.trim();
|
|
41600
|
+
if (!text7) throw new Error("SIDEBOARD_SLACK_TOKEN_KEY is empty");
|
|
41601
|
+
const buf = /^[0-9a-fA-F]{64}$/.test(text7) ? Buffer.from(text7, "hex") : Buffer.from(text7, "base64");
|
|
41602
|
+
if (buf.length !== 32) {
|
|
41603
|
+
throw new Error("SIDEBOARD_SLACK_TOKEN_KEY must be 32 bytes (base64 or 64 hex characters)");
|
|
41604
|
+
}
|
|
41605
|
+
return buf;
|
|
41606
|
+
}
|
|
41607
|
+
function sealSecret(key, plaintext) {
|
|
41608
|
+
const iv = (0, import_node_crypto24.randomBytes)(12);
|
|
41609
|
+
const cipher = (0, import_node_crypto24.createCipheriv)("aes-256-gcm", key, iv);
|
|
41610
|
+
const ciphertext = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
41611
|
+
const tag = cipher.getAuthTag();
|
|
41612
|
+
return [VERSION, iv.toString("base64url"), tag.toString("base64url"), ciphertext.toString("base64url")].join(
|
|
41613
|
+
"."
|
|
41614
|
+
);
|
|
41615
|
+
}
|
|
41616
|
+
function openSecret(key, sealed) {
|
|
41617
|
+
const [version, ivB64, tagB64, ctB64] = sealed.split(".");
|
|
41618
|
+
if (version !== VERSION || !ivB64 || !tagB64 || !ctB64 || sealed.split(".").length !== 4) {
|
|
41619
|
+
throw new Error("Slack secret ciphertext is not recognized");
|
|
41620
|
+
}
|
|
41621
|
+
const decipher = (0, import_node_crypto24.createDecipheriv)("aes-256-gcm", key, Buffer.from(ivB64, "base64url"));
|
|
41622
|
+
decipher.setAuthTag(Buffer.from(tagB64, "base64url"));
|
|
41623
|
+
return Buffer.concat([
|
|
41624
|
+
decipher.update(Buffer.from(ctB64, "base64url")),
|
|
41625
|
+
decipher.final()
|
|
41626
|
+
]).toString("utf8");
|
|
41627
|
+
}
|
|
41628
|
+
|
|
41629
|
+
// src/slack/oauth-state.ts
|
|
41630
|
+
var import_node_crypto25 = require("crypto");
|
|
41631
|
+
function slackOAuthState(clientId, bakedClientId) {
|
|
41632
|
+
const nonce = (0, import_node_crypto25.randomBytes)(16).toString("hex");
|
|
41633
|
+
const id = clientId.trim();
|
|
41634
|
+
if (!id || id === bakedClientId.trim()) return nonce;
|
|
41635
|
+
return `c.${Buffer.from(id, "utf8").toString("base64url")}.${nonce}`;
|
|
41636
|
+
}
|
|
41637
|
+
function clientIdFromOAuthState(state) {
|
|
41638
|
+
if (!state.startsWith("c.")) return null;
|
|
41639
|
+
const rest = state.slice(2);
|
|
41640
|
+
const dot = rest.lastIndexOf(".");
|
|
41641
|
+
if (dot <= 0) return null;
|
|
41642
|
+
if (!/^[0-9a-f]{32}$/.test(rest.slice(dot + 1))) return null;
|
|
41643
|
+
try {
|
|
41644
|
+
const id = Buffer.from(rest.slice(0, dot), "base64url").toString("utf8").trim();
|
|
41645
|
+
if (!id || id.includes("\0")) return null;
|
|
41646
|
+
return id;
|
|
41647
|
+
} catch {
|
|
41648
|
+
return null;
|
|
41649
|
+
}
|
|
41650
|
+
}
|
|
41651
|
+
|
|
41652
|
+
// src/slack/oauth.ts
|
|
41653
|
+
init_app_settings();
|
|
41654
|
+
|
|
41655
|
+
// src/slack/workspaces.ts
|
|
41656
|
+
var import_node_path71 = require("path");
|
|
41657
|
+
init_paths();
|
|
41658
|
+
init_secure_file();
|
|
41659
|
+
function storePath2() {
|
|
41660
|
+
return (0, import_node_path71.join)(appDataDir(), "slack-workspaces.json");
|
|
41661
|
+
}
|
|
41662
|
+
function readStore2() {
|
|
41663
|
+
try {
|
|
41664
|
+
const path2 = storePath2();
|
|
41665
|
+
const wasEncrypted = isSecureFileEncrypted(path2);
|
|
41666
|
+
const parsed = readSecureJson(path2);
|
|
41667
|
+
const workspaces = Array.isArray(parsed?.workspaces) ? parsed.workspaces : [];
|
|
41668
|
+
if (workspaces.length > 0 && !wasEncrypted && resolveVaultKey()) {
|
|
41669
|
+
writeSecureJson(path2, { workspaces });
|
|
41670
|
+
}
|
|
41671
|
+
return workspaces;
|
|
41672
|
+
} catch {
|
|
41673
|
+
return [];
|
|
41674
|
+
}
|
|
41675
|
+
}
|
|
41676
|
+
function writeStore2(workspaces) {
|
|
41677
|
+
writeSecureJson(storePath2(), { workspaces });
|
|
41678
|
+
return workspaces;
|
|
41679
|
+
}
|
|
41680
|
+
function toInfo(ws) {
|
|
41681
|
+
return {
|
|
41682
|
+
team_id: ws.team_id,
|
|
41683
|
+
team_name: ws.team_name,
|
|
41684
|
+
user_id: ws.user_id,
|
|
41685
|
+
has_bot_token: Boolean(ws.bot_token),
|
|
41686
|
+
has_user_token: Boolean(ws.user_token),
|
|
41687
|
+
connected_at: ws.connected_at
|
|
41688
|
+
};
|
|
41689
|
+
}
|
|
41690
|
+
function slackWorkspaceCanListen(ws) {
|
|
41691
|
+
return Boolean(
|
|
41692
|
+
ws.bot_token?.trim() && ws.user_id?.trim() && (ws.user_token?.trim() || ws.listen_grant?.trim())
|
|
41693
|
+
);
|
|
41694
|
+
}
|
|
41695
|
+
function listSlackWorkspaces() {
|
|
41696
|
+
return readStore2().map(toInfo).sort((a, b) => a.team_name.localeCompare(b.team_name));
|
|
41697
|
+
}
|
|
41698
|
+
function listSlackWorkspacesRaw() {
|
|
41699
|
+
return readStore2();
|
|
41700
|
+
}
|
|
41701
|
+
function getSlackWorkspace(teamId) {
|
|
41702
|
+
const id = teamId.trim();
|
|
41703
|
+
if (!id) return null;
|
|
41704
|
+
return readStore2().find(
|
|
41705
|
+
(ws) => ws.team_id === id || ws.team_name.toLowerCase() === id.toLowerCase()
|
|
41706
|
+
) ?? null;
|
|
41707
|
+
}
|
|
41708
|
+
function upsertSlackWorkspace(entry) {
|
|
41709
|
+
const workspaces = readStore2().filter((ws) => ws.team_id !== entry.team_id);
|
|
41710
|
+
workspaces.push(entry);
|
|
41711
|
+
writeStore2(workspaces);
|
|
41712
|
+
return toInfo(entry);
|
|
41713
|
+
}
|
|
41714
|
+
function disconnectSlackWorkspace(teamId) {
|
|
41715
|
+
const id = teamId.trim();
|
|
41716
|
+
writeStore2(readStore2().filter((ws) => ws.team_id !== id));
|
|
41717
|
+
return listSlackWorkspaces();
|
|
41718
|
+
}
|
|
41719
|
+
function tokenKind(token) {
|
|
41720
|
+
if (token.startsWith("xoxb-")) return "bot";
|
|
41721
|
+
if (token.startsWith("xoxp-") || token.startsWith("xoxe.xoxp-")) return "user";
|
|
41722
|
+
return "unknown";
|
|
41723
|
+
}
|
|
41724
|
+
async function connectSlackToken(rawToken) {
|
|
41725
|
+
const token = rawToken.trim();
|
|
41726
|
+
if (!token) throw new Error("Paste a Slack bot (xoxb-) or user (xoxp-) token");
|
|
41727
|
+
const auth = await slackAuthTest(token);
|
|
41728
|
+
const teamId = auth.team_id?.trim();
|
|
41729
|
+
if (!teamId) throw new Error("Slack auth.test did not return a team_id");
|
|
41730
|
+
const existing = getSlackWorkspace(teamId);
|
|
41731
|
+
const kind = tokenKind(token);
|
|
41732
|
+
const next = {
|
|
41733
|
+
team_id: teamId,
|
|
41734
|
+
team_name: auth.team?.trim() || existing?.team_name || teamId,
|
|
41735
|
+
user_id: auth.user_id?.trim() || existing?.user_id,
|
|
41736
|
+
bot_token: kind === "bot" ? token : existing?.bot_token,
|
|
41737
|
+
user_token: kind === "user" || kind === "unknown" ? token : existing?.user_token,
|
|
41738
|
+
scopes: existing?.scopes,
|
|
41739
|
+
connected_at: existing?.connected_at || (/* @__PURE__ */ new Date()).toISOString()
|
|
41740
|
+
};
|
|
41741
|
+
if (kind === "unknown" && auth.bot_id) {
|
|
41742
|
+
next.bot_token = token;
|
|
41743
|
+
next.user_token = existing?.user_token;
|
|
41744
|
+
}
|
|
41745
|
+
return upsertSlackWorkspace(next);
|
|
41746
|
+
}
|
|
41747
|
+
function slackTokenFor(ws, _kind = "read") {
|
|
41748
|
+
const token = (ws.bot_token || ws.user_token)?.trim();
|
|
41749
|
+
if (!token) {
|
|
41750
|
+
throw new Error(`Slack workspace ${ws.team_name} has no token`);
|
|
41751
|
+
}
|
|
41752
|
+
return token;
|
|
41753
|
+
}
|
|
41754
|
+
|
|
41755
|
+
// src/slack/oauth.ts
|
|
41756
|
+
var SLACK_BOT_SCOPES = [
|
|
41757
|
+
"app_mentions:read",
|
|
41758
|
+
"channels:history",
|
|
41759
|
+
"channels:read",
|
|
41760
|
+
"groups:history",
|
|
41761
|
+
"groups:read",
|
|
41762
|
+
"im:history",
|
|
41763
|
+
"im:read",
|
|
41764
|
+
"im:write",
|
|
41765
|
+
"mpim:history",
|
|
41766
|
+
"mpim:read",
|
|
41767
|
+
"chat:write",
|
|
41768
|
+
"chat:write.public",
|
|
41769
|
+
"reactions:write",
|
|
41770
|
+
"users:read",
|
|
41771
|
+
"users:read.email"
|
|
41772
|
+
].join(",");
|
|
41773
|
+
function slackOAuthCredentials() {
|
|
41774
|
+
const settings = loadAppSettings();
|
|
41775
|
+
const clientId = process.env.SIDEBOARD_SLACK_CLIENT_ID?.trim() || settings.integrations.slackClientId?.trim() || BAKED_SLACK_CLIENT_ID.trim();
|
|
41776
|
+
const clientSecret = process.env.SIDEBOARD_SLACK_CLIENT_SECRET?.trim() || settings.integrations.slackClientSecret?.trim() || "";
|
|
41777
|
+
if (!clientId) {
|
|
41778
|
+
throw new Error(
|
|
41779
|
+
"Slack browser sign-in needs a Slack app Client ID (Settings \u2192 Collaboration, or SIDEBOARD_SLACK_CLIENT_ID). You can still paste an xoxb- or xoxp- token."
|
|
41780
|
+
);
|
|
41781
|
+
}
|
|
41782
|
+
return { clientId, clientSecret: clientSecret || null };
|
|
41783
|
+
}
|
|
41784
|
+
var SLACK_OAUTH_CANCELLED = "Slack sign-in cancelled";
|
|
41785
|
+
var SlackOAuthCancelledError = class extends Error {
|
|
41786
|
+
constructor(message = SLACK_OAUTH_CANCELLED) {
|
|
41787
|
+
super(message);
|
|
41788
|
+
this.name = "SlackOAuthCancelledError";
|
|
41789
|
+
}
|
|
41790
|
+
};
|
|
41791
|
+
function isSlackOAuthCancelled(err) {
|
|
41792
|
+
if (err instanceof SlackOAuthCancelledError) return true;
|
|
41793
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
41794
|
+
if (message.includes(SLACK_OAUTH_CANCELLED)) return true;
|
|
41795
|
+
return err instanceof Error && err.name === "SlackOAuthCancelledError";
|
|
41796
|
+
}
|
|
41797
|
+
function slackOAuthAuthorizeUrl(clientId, state) {
|
|
41798
|
+
const params = new URLSearchParams({
|
|
41799
|
+
client_id: clientId,
|
|
41800
|
+
scope: SLACK_BOT_SCOPES,
|
|
41801
|
+
redirect_uri: slackOAuthRedirectUri(),
|
|
41802
|
+
state
|
|
41803
|
+
});
|
|
41804
|
+
return `https://slack.com/oauth/v2/authorize?${params.toString()}`;
|
|
41805
|
+
}
|
|
41806
|
+
function sleep(ms, signal) {
|
|
41807
|
+
return new Promise((resolve3, reject) => {
|
|
41808
|
+
if (signal?.aborted) {
|
|
41809
|
+
reject(new SlackOAuthCancelledError());
|
|
41810
|
+
return;
|
|
41811
|
+
}
|
|
41812
|
+
const timer = setTimeout(() => {
|
|
41813
|
+
signal?.removeEventListener("abort", onAbort);
|
|
41814
|
+
resolve3();
|
|
41815
|
+
}, ms);
|
|
41816
|
+
const onAbort = () => {
|
|
41817
|
+
clearTimeout(timer);
|
|
41818
|
+
reject(new SlackOAuthCancelledError());
|
|
41819
|
+
};
|
|
41820
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
41821
|
+
});
|
|
41822
|
+
}
|
|
41823
|
+
function upsertFromPayload(payload) {
|
|
41824
|
+
const existing = getSlackWorkspace(payload.team_id);
|
|
41825
|
+
return upsertSlackWorkspace({
|
|
41826
|
+
team_id: payload.team_id,
|
|
41827
|
+
team_name: payload.team_name || existing?.team_name || payload.team_id,
|
|
41828
|
+
user_id: payload.user_id || existing?.user_id,
|
|
41829
|
+
bot_token: payload.bot_token || existing?.bot_token,
|
|
41830
|
+
user_token: payload.user_token || existing?.user_token,
|
|
41831
|
+
listen_grant: payload.listen_grant || existing?.listen_grant,
|
|
41832
|
+
scopes: payload.scopes || existing?.scopes,
|
|
41833
|
+
connected_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
41834
|
+
});
|
|
41835
|
+
}
|
|
41836
|
+
async function startSlackOAuth(opts) {
|
|
41837
|
+
if (opts?.signal?.aborted) {
|
|
41838
|
+
throw new SlackOAuthCancelledError();
|
|
41839
|
+
}
|
|
41840
|
+
const clientId = opts?.clientId?.trim() || slackOAuthCredentials().clientId;
|
|
41841
|
+
const state = slackOAuthState(clientId, BAKED_SLACK_CLIENT_ID);
|
|
41842
|
+
const authorizeUrl = slackOAuthAuthorizeUrl(clientId, state);
|
|
41843
|
+
const timeoutMs = opts?.timeoutMs ?? 5 * 6e4;
|
|
41844
|
+
const pollIntervalMs = opts?.pollIntervalMs ?? 400;
|
|
41845
|
+
const fetchImpl = opts?.fetchImpl ?? fetch;
|
|
41846
|
+
const resultUrl = opts?.resultUrlForState?.(state) ?? slackOAuthResultUrl(state);
|
|
41847
|
+
await Promise.resolve(opts?.openUrl?.(authorizeUrl));
|
|
41848
|
+
if (opts?.signal?.aborted) {
|
|
41849
|
+
throw new SlackOAuthCancelledError();
|
|
41850
|
+
}
|
|
41851
|
+
const deadline = Date.now() + timeoutMs;
|
|
41852
|
+
while (Date.now() < deadline) {
|
|
41853
|
+
if (opts?.signal?.aborted) {
|
|
41854
|
+
throw new SlackOAuthCancelledError();
|
|
41855
|
+
}
|
|
41856
|
+
let res;
|
|
41857
|
+
try {
|
|
41858
|
+
res = await fetchImpl(resultUrl);
|
|
41859
|
+
} catch {
|
|
41860
|
+
if (opts?.signal?.aborted) throw new SlackOAuthCancelledError();
|
|
41861
|
+
await sleep(pollIntervalMs, opts?.signal);
|
|
41862
|
+
continue;
|
|
41863
|
+
}
|
|
41864
|
+
let data;
|
|
41865
|
+
try {
|
|
41866
|
+
data = await res.json();
|
|
41867
|
+
} catch {
|
|
41868
|
+
await sleep(pollIntervalMs, opts?.signal);
|
|
41869
|
+
continue;
|
|
41870
|
+
}
|
|
41871
|
+
if (data.ok && data.team_id?.trim()) {
|
|
41872
|
+
return upsertFromPayload({
|
|
41873
|
+
team_id: data.team_id.trim(),
|
|
41874
|
+
team_name: data.team_name?.trim() || data.team_id.trim(),
|
|
41875
|
+
user_id: data.user_id?.trim() || void 0,
|
|
41876
|
+
bot_token: data.bot_token?.trim() || void 0,
|
|
41877
|
+
user_token: data.user_token?.trim() || void 0,
|
|
41878
|
+
listen_grant: data.listen_grant?.trim() || void 0,
|
|
41879
|
+
scopes: data.scopes?.trim() || ""
|
|
41880
|
+
});
|
|
41881
|
+
}
|
|
41882
|
+
const err = data.error?.trim();
|
|
41883
|
+
if (err && err !== "pending") {
|
|
41884
|
+
if (/cancel/i.test(err) || /access_denied/i.test(err)) {
|
|
41885
|
+
throw new SlackOAuthCancelledError(`Slack OAuth: ${err}`);
|
|
41886
|
+
}
|
|
41887
|
+
throw new Error(err.startsWith("Slack") ? err : `Slack OAuth: ${err}`);
|
|
41888
|
+
}
|
|
41889
|
+
await sleep(pollIntervalMs, opts?.signal);
|
|
41890
|
+
}
|
|
41891
|
+
throw new Error("Slack sign-in timed out \u2014 try again");
|
|
41892
|
+
}
|
|
41893
|
+
|
|
41894
|
+
// src/slack/org-manifest.ts
|
|
41895
|
+
var BOT_EVENTS = [
|
|
41896
|
+
"app_home_opened",
|
|
41897
|
+
"app_mention",
|
|
41898
|
+
"app_uninstalled",
|
|
41899
|
+
"message.im",
|
|
41900
|
+
"message.mpim"
|
|
41901
|
+
];
|
|
41902
|
+
function yamlList(scopes, indent) {
|
|
41903
|
+
return scopes.split(",").map((scope) => scope.trim()).filter(Boolean).map((scope) => `${indent}- ${scope}`).join("\n");
|
|
41904
|
+
}
|
|
41905
|
+
function slackOrgManifest(opts) {
|
|
41906
|
+
const eventsUrl = opts.eventsUrl.trim();
|
|
41907
|
+
const redirectUrl = opts.redirectUrl.trim();
|
|
41908
|
+
return `display_information:
|
|
41909
|
+
name: Sideboard
|
|
41910
|
+
description: Drive Sideboard agents from Slack DMs and @mentions.
|
|
41911
|
+
background_color: "#111827"
|
|
41912
|
+
long_description: >-
|
|
41913
|
+
Sideboard sends DMs and @mentions to the orchestrator on a Mac in this
|
|
41914
|
+
workspace and posts replies back in thread. Agents can list, read, and
|
|
41915
|
+
post in Slack. Message text is not used to train models.
|
|
41916
|
+
|
|
41917
|
+
features:
|
|
41918
|
+
app_home:
|
|
41919
|
+
home_tab_enabled: true
|
|
41920
|
+
messages_tab_enabled: true
|
|
41921
|
+
messages_tab_read_only_enabled: false
|
|
41922
|
+
bot_user:
|
|
41923
|
+
display_name: Sideboard
|
|
41924
|
+
always_online: true
|
|
41925
|
+
|
|
41926
|
+
oauth_config:
|
|
41927
|
+
redirect_urls:
|
|
41928
|
+
- ${redirectUrl}
|
|
41929
|
+
scopes:
|
|
41930
|
+
bot:
|
|
41931
|
+
${yamlList(SLACK_BOT_SCOPES, " ")}
|
|
41932
|
+
|
|
41933
|
+
settings:
|
|
41934
|
+
org_deploy_enabled: false
|
|
41935
|
+
socket_mode_enabled: false
|
|
41936
|
+
token_rotation_enabled: false
|
|
41937
|
+
event_subscriptions:
|
|
41938
|
+
request_url: ${eventsUrl}
|
|
41939
|
+
bot_events:
|
|
41940
|
+
${BOT_EVENTS.map((event) => ` - ${event}`).join("\n")}
|
|
41941
|
+
`;
|
|
41942
|
+
}
|
|
41943
|
+
function slackEventsPath(registrationId) {
|
|
41944
|
+
return `/slack/events/${registrationId}`;
|
|
41945
|
+
}
|
|
41946
|
+
function slackEventsUrl(origin, registrationId) {
|
|
41947
|
+
return `${origin.replace(/\/$/, "")}${slackEventsPath(registrationId)}`;
|
|
41948
|
+
}
|
|
41949
|
+
|
|
41950
|
+
// src/relay/slack-http.ts
|
|
41951
|
+
var EVENTS_PREFIX = "/slack/events/";
|
|
41952
|
+
var APPS_PATH = "/slack/apps";
|
|
41953
|
+
var BODY_LIMIT = 262144;
|
|
41954
|
+
async function handleSlackHttp(ctx) {
|
|
41955
|
+
const url = parseUrl(ctx.reqUrl);
|
|
41956
|
+
if (!url) return false;
|
|
41957
|
+
const path2 = url.pathname;
|
|
41958
|
+
if (path2 === "/slack/callback") return handleCallback(ctx, url);
|
|
41959
|
+
if (path2 === "/slack/oauth/result") return handleResult(ctx, url);
|
|
41960
|
+
if (path2 === APPS_PATH && ctx.req.method === "POST") {
|
|
41961
|
+
await handleCreate(ctx);
|
|
41962
|
+
return true;
|
|
41963
|
+
}
|
|
41964
|
+
const creds = path2.match(/^\/slack\/apps\/([A-Za-z0-9_-]+)\/credentials$/);
|
|
41965
|
+
if (creds && ctx.req.method === "POST") {
|
|
41966
|
+
await handleCredentials(ctx, creds[1]);
|
|
41967
|
+
return true;
|
|
41968
|
+
}
|
|
41969
|
+
if (path2.startsWith(EVENTS_PREFIX) && ctx.req.method === "POST") {
|
|
41970
|
+
await handleEvents(ctx, decodeURIComponent(path2.slice(EVENTS_PREFIX.length)));
|
|
41971
|
+
return true;
|
|
41972
|
+
}
|
|
41973
|
+
return false;
|
|
41974
|
+
}
|
|
41975
|
+
function parseUrl(reqUrl) {
|
|
41976
|
+
try {
|
|
41977
|
+
return new URL(reqUrl, "http://127.0.0.1");
|
|
41978
|
+
} catch {
|
|
41979
|
+
return null;
|
|
41980
|
+
}
|
|
41981
|
+
}
|
|
41982
|
+
async function handleCreate(ctx) {
|
|
41983
|
+
if (!ctx.accounts || !ctx.apps) {
|
|
41984
|
+
sendJson(ctx.res, 503, {
|
|
41985
|
+
ok: false,
|
|
41986
|
+
error: "Per-company Slack apps need SIDEBOARD_SLACK_TOKEN_KEY and the relay account database"
|
|
41987
|
+
});
|
|
41988
|
+
return;
|
|
41989
|
+
}
|
|
41990
|
+
const accountId = ctx.accounts.verifyCredential(bearer(ctx.req));
|
|
41991
|
+
if (!accountId) {
|
|
41992
|
+
sendJson(ctx.res, 401, { ok: false, error: "Sign in to the relay before creating a Slack app" });
|
|
41993
|
+
return;
|
|
41994
|
+
}
|
|
41995
|
+
const created = ctx.apps.create(accountId);
|
|
41996
|
+
const eventsUrl = slackEventsUrl(ctx.publicOrigin, created.registrationId);
|
|
41997
|
+
sendJson(ctx.res, 200, {
|
|
41998
|
+
ok: true,
|
|
41999
|
+
registrationId: created.registrationId,
|
|
42000
|
+
writeToken: created.writeToken,
|
|
42001
|
+
eventsUrl,
|
|
42002
|
+
manifest: slackOrgManifest({ eventsUrl, redirectUrl: ctx.redirectUri })
|
|
42003
|
+
});
|
|
42004
|
+
}
|
|
42005
|
+
async function handleCredentials(ctx, registrationId) {
|
|
42006
|
+
if (!ctx.apps) {
|
|
42007
|
+
sendJson(ctx.res, 503, { ok: false, error: "Per-company Slack apps are off on this relay" });
|
|
42008
|
+
return;
|
|
42009
|
+
}
|
|
42010
|
+
const body = await readJson3(ctx.req);
|
|
42011
|
+
const writeToken = stringField(body, "writeToken");
|
|
42012
|
+
const clientId = stringField(body, "clientId");
|
|
42013
|
+
const clientSecret = stringField(body, "clientSecret");
|
|
42014
|
+
const signingSecret = stringField(body, "signingSecret");
|
|
42015
|
+
try {
|
|
42016
|
+
ctx.apps.saveCredentials(registrationId, writeToken, { clientId, clientSecret, signingSecret });
|
|
42017
|
+
} catch (err) {
|
|
42018
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
42019
|
+
sendJson(ctx.res, 400, { ok: false, error: message });
|
|
42020
|
+
return;
|
|
42021
|
+
}
|
|
42022
|
+
sendJson(ctx.res, 200, { ok: true });
|
|
42023
|
+
}
|
|
42024
|
+
async function handleEvents(ctx, registrationId) {
|
|
42025
|
+
if (!ctx.apps) {
|
|
42026
|
+
sendJson(ctx.res, 503, { ok: false, error: "Per-company Slack apps are off on this relay" });
|
|
42027
|
+
return;
|
|
42028
|
+
}
|
|
42029
|
+
const app = ctx.apps.getByRegistration(registrationId);
|
|
42030
|
+
if (!app) {
|
|
42031
|
+
sendJson(ctx.res, 404, { ok: false, error: "Unknown Slack app" });
|
|
42032
|
+
return;
|
|
42033
|
+
}
|
|
42034
|
+
const raw = await readBody(ctx.req);
|
|
42035
|
+
const body = parseSlackEventsBody(raw);
|
|
42036
|
+
if (!body) {
|
|
42037
|
+
sendJson(ctx.res, 400, { ok: false, error: "Invalid JSON" });
|
|
42038
|
+
return;
|
|
42039
|
+
}
|
|
42040
|
+
if (body.type === "url_verification") {
|
|
42041
|
+
if (app.signingSecret && !signed(ctx, app.signingSecret, raw)) {
|
|
42042
|
+
sendJson(ctx.res, 401, { ok: false, error: "Bad signature" });
|
|
42043
|
+
return;
|
|
42044
|
+
}
|
|
42045
|
+
const challenge = typeof body.challenge === "string" ? body.challenge : "";
|
|
42046
|
+
sendJson(ctx.res, 200, { challenge });
|
|
42047
|
+
return;
|
|
42048
|
+
}
|
|
42049
|
+
if (body.type !== "event_callback") {
|
|
42050
|
+
sendJson(ctx.res, 200, { ok: true });
|
|
42051
|
+
return;
|
|
42052
|
+
}
|
|
42053
|
+
if (!app.signingSecret || !signed(ctx, app.signingSecret, raw)) {
|
|
42054
|
+
sendJson(ctx.res, 401, { ok: false, error: "Bad signature" });
|
|
42055
|
+
return;
|
|
42056
|
+
}
|
|
42057
|
+
const teamId = typeof body.team_id === "string" ? body.team_id.trim() : "";
|
|
42058
|
+
if (app.teamId && teamId && teamId !== app.teamId) {
|
|
42059
|
+
sendJson(ctx.res, 401, { ok: false, error: "Slack team does not match this app" });
|
|
42060
|
+
return;
|
|
42061
|
+
}
|
|
42062
|
+
const eventId = typeof body.event_id === "string" ? body.event_id : "";
|
|
42063
|
+
if (ctx.dedupe.duplicate(eventId)) {
|
|
42064
|
+
sendJson(ctx.res, 200, { ok: true });
|
|
42065
|
+
return;
|
|
42066
|
+
}
|
|
42067
|
+
sendJson(ctx.res, 200, { ok: true });
|
|
42068
|
+
if (!app.teamId) {
|
|
42069
|
+
ctx.log(`slack event ${eventId || "?"} before install for ${registrationId}`);
|
|
42070
|
+
return;
|
|
42071
|
+
}
|
|
42072
|
+
const life = lifecycleFromEventsBody(body);
|
|
42073
|
+
if (life?.kind === "app_uninstalled") {
|
|
42074
|
+
ctx.apps.deleteByTeam(life.teamId);
|
|
42075
|
+
ctx.grants.revokeTeam(life.teamId);
|
|
42076
|
+
ctx.hub.uninstallTeam(life.teamId);
|
|
42077
|
+
return;
|
|
42078
|
+
}
|
|
42079
|
+
if (life?.kind === "app_home_opened") {
|
|
42080
|
+
void ctx.hub.handleAppHomeOpened(life.teamId, life.userId);
|
|
42081
|
+
return;
|
|
42082
|
+
}
|
|
42083
|
+
const inbound = inboundFromEventsBody(body);
|
|
42084
|
+
if (inbound) ctx.hub.routeEvent(inbound);
|
|
42085
|
+
}
|
|
42086
|
+
function signed(ctx, signingSecret, raw) {
|
|
42087
|
+
const timestamp = header(ctx.req, "x-slack-request-timestamp");
|
|
42088
|
+
const signature = header(ctx.req, "x-slack-signature");
|
|
42089
|
+
return verifySlackRequestSignature({ signingSecret, timestamp, rawBody: raw, signature });
|
|
42090
|
+
}
|
|
42091
|
+
async function handleCallback(ctx, url) {
|
|
42092
|
+
const error = url.searchParams.get("error")?.trim();
|
|
42093
|
+
const state = url.searchParams.get("state")?.trim() ?? "";
|
|
42094
|
+
const code = url.searchParams.get("code")?.trim() ?? "";
|
|
42095
|
+
if (error) {
|
|
42096
|
+
if (state) ctx.pending.put(state, { ok: false, error: `Slack OAuth: ${error}` });
|
|
42097
|
+
sendHtml(ctx.res, 400, "Slack", `<h1>Authorization cancelled</h1><p>${escapeHtml2(error)}</p>`);
|
|
42098
|
+
return true;
|
|
42099
|
+
}
|
|
42100
|
+
if (!state || !code) {
|
|
42101
|
+
sendHtml(ctx.res, 400, "Slack", "<h1>Invalid callback</h1><p>State or code missing.</p>");
|
|
42102
|
+
return true;
|
|
42103
|
+
}
|
|
42104
|
+
try {
|
|
42105
|
+
const creds = resolveOAuthClient(ctx, state);
|
|
42106
|
+
const payload = await exchangeSlackOAuthCode({
|
|
42107
|
+
clientId: creds.clientId,
|
|
42108
|
+
clientSecret: creds.clientSecret,
|
|
42109
|
+
code,
|
|
42110
|
+
redirectUri: ctx.redirectUri,
|
|
42111
|
+
fetchImpl: ctx.fetchImpl
|
|
42112
|
+
});
|
|
42113
|
+
if (ctx.apps && payload.bot_token) {
|
|
42114
|
+
ctx.apps.recordInstall({
|
|
42115
|
+
clientId: creds.clientId,
|
|
42116
|
+
teamId: payload.team_id,
|
|
42117
|
+
botToken: payload.bot_token,
|
|
42118
|
+
botUserId: payload.bot_user_id ?? ""
|
|
42119
|
+
});
|
|
42120
|
+
}
|
|
42121
|
+
const listenGrant = payload.user_id ? ctx.grants.issue(payload.team_id, payload.user_id) : null;
|
|
42122
|
+
ctx.pending.put(state, {
|
|
42123
|
+
ok: true,
|
|
42124
|
+
payload: publicPayload({
|
|
42125
|
+
...payload,
|
|
42126
|
+
...listenGrant ? { listen_grant: listenGrant } : {}
|
|
42127
|
+
})
|
|
42128
|
+
});
|
|
42129
|
+
if (payload.bot_token) {
|
|
42130
|
+
ctx.hub.rememberBot(payload.team_id, payload.bot_token);
|
|
42131
|
+
if (payload.user_id) void ctx.hub.handleAppHomeOpened(payload.team_id, payload.user_id);
|
|
42132
|
+
}
|
|
42133
|
+
sendHtml(
|
|
42134
|
+
ctx.res,
|
|
42135
|
+
200,
|
|
42136
|
+
"Slack connected",
|
|
42137
|
+
"<h1>Slack workspace connected</h1><p>Open <strong>Sideboard \u2192 Settings \u2192 Collaboration</strong>. Confirm Relay connected on Settings \u2192 Remote, name this Mac, then DM @Sideboard.</p>"
|
|
42138
|
+
);
|
|
42139
|
+
} catch (err) {
|
|
42140
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
42141
|
+
ctx.pending.put(state, { ok: false, error: message });
|
|
42142
|
+
sendHtml(ctx.res, 400, "Slack", `<h1>Could not connect Slack</h1><p>${escapeHtml2(message)}</p>`);
|
|
42143
|
+
}
|
|
42144
|
+
return true;
|
|
42145
|
+
}
|
|
42146
|
+
function resolveOAuthClient(ctx, state) {
|
|
42147
|
+
const fromState = clientIdFromOAuthState(state);
|
|
42148
|
+
if (!fromState) {
|
|
42149
|
+
if (!ctx.bakedClientSecret) throw new Error("Relay is missing SIDEBOARD_SLACK_CLIENT_SECRET");
|
|
42150
|
+
return { clientId: ctx.bakedClientId, clientSecret: ctx.bakedClientSecret };
|
|
42151
|
+
}
|
|
42152
|
+
const secret = ctx.apps?.clientSecretFor(fromState);
|
|
42153
|
+
if (!secret) throw new Error("This Slack app is not registered on the relay");
|
|
42154
|
+
return { clientId: fromState, clientSecret: secret };
|
|
42155
|
+
}
|
|
42156
|
+
function publicPayload(payload) {
|
|
42157
|
+
return {
|
|
42158
|
+
team_id: payload.team_id,
|
|
42159
|
+
team_name: payload.team_name,
|
|
42160
|
+
user_id: payload.user_id,
|
|
42161
|
+
bot_token: payload.bot_token,
|
|
42162
|
+
user_token: payload.user_token,
|
|
42163
|
+
listen_grant: payload.listen_grant,
|
|
42164
|
+
scopes: payload.scopes
|
|
42165
|
+
};
|
|
42166
|
+
}
|
|
42167
|
+
function handleResult(ctx, url) {
|
|
42168
|
+
const state = url.searchParams.get("state")?.trim() ?? "";
|
|
42169
|
+
const value = ctx.pending.take(state);
|
|
42170
|
+
if (!value) {
|
|
42171
|
+
sendJson(ctx.res, 404, { ok: false, error: "pending" });
|
|
42172
|
+
return true;
|
|
42173
|
+
}
|
|
42174
|
+
if (!value.ok) {
|
|
42175
|
+
sendJson(ctx.res, 400, { ok: false, error: value.error });
|
|
42176
|
+
return true;
|
|
42177
|
+
}
|
|
42178
|
+
sendJson(ctx.res, 200, { ok: true, ...value.payload });
|
|
42179
|
+
return true;
|
|
42180
|
+
}
|
|
42181
|
+
function bearer(req) {
|
|
42182
|
+
const value = header(req, "authorization");
|
|
42183
|
+
const match = /^Bearer\s+(\S+)/i.exec(value);
|
|
42184
|
+
return match?.[1]?.trim() ?? "";
|
|
42185
|
+
}
|
|
42186
|
+
function header(req, name) {
|
|
42187
|
+
const value = req.headers[name];
|
|
42188
|
+
return typeof value === "string" ? value.trim() : "";
|
|
42189
|
+
}
|
|
42190
|
+
function stringField(body, key) {
|
|
42191
|
+
const value = body?.[key];
|
|
42192
|
+
return typeof value === "string" ? value : "";
|
|
42193
|
+
}
|
|
42194
|
+
async function readJson3(req) {
|
|
42195
|
+
const raw = await readBody(req);
|
|
42196
|
+
if (!raw) return null;
|
|
42197
|
+
try {
|
|
42198
|
+
const parsed = JSON.parse(raw);
|
|
42199
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
42200
|
+
return parsed;
|
|
42201
|
+
} catch {
|
|
42202
|
+
return null;
|
|
42203
|
+
}
|
|
42204
|
+
}
|
|
42205
|
+
function readBody(req) {
|
|
42206
|
+
return new Promise((resolve3, reject) => {
|
|
42207
|
+
const chunks = [];
|
|
42208
|
+
let size = 0;
|
|
42209
|
+
req.on("data", (chunk) => {
|
|
42210
|
+
const buf = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
42211
|
+
size += buf.length;
|
|
42212
|
+
if (size > BODY_LIMIT) {
|
|
42213
|
+
reject(new Error("body too large"));
|
|
42214
|
+
req.destroy();
|
|
42215
|
+
return;
|
|
42216
|
+
}
|
|
42217
|
+
chunks.push(buf);
|
|
42218
|
+
});
|
|
42219
|
+
req.on("end", () => resolve3(Buffer.concat(chunks).toString("utf8")));
|
|
42220
|
+
req.on("error", reject);
|
|
42221
|
+
});
|
|
42222
|
+
}
|
|
42223
|
+
function sendHtml(res, status, title, body) {
|
|
42224
|
+
res.writeHead(status, { "Content-Type": "text/html; charset=utf-8" });
|
|
42225
|
+
res.end(slackOAuthHtmlPage(title, body));
|
|
42226
|
+
}
|
|
42227
|
+
function sendJson(res, status, body) {
|
|
42228
|
+
res.writeHead(status, { "Content-Type": "application/json; charset=utf-8" });
|
|
42229
|
+
res.end(JSON.stringify(body));
|
|
42230
|
+
}
|
|
42231
|
+
|
|
42232
|
+
// src/relay/slack-apps.ts
|
|
42233
|
+
var import_node_crypto26 = require("crypto");
|
|
42234
|
+
var import_node_fs72 = require("fs");
|
|
42235
|
+
var import_node_module7 = require("module");
|
|
42236
|
+
var import_node_path72 = require("path");
|
|
42237
|
+
var SlackAppStore = class {
|
|
42238
|
+
db;
|
|
42239
|
+
key;
|
|
42240
|
+
constructor(filePath, key) {
|
|
42241
|
+
if (key.length !== 32) throw new Error("Slack token key must be 32 bytes");
|
|
42242
|
+
(0, import_node_fs72.mkdirSync)((0, import_node_path72.dirname)(filePath), { recursive: true });
|
|
42243
|
+
this.key = key;
|
|
42244
|
+
this.db = openDatabase(filePath);
|
|
42245
|
+
this.db.exec(`
|
|
42246
|
+
CREATE TABLE IF NOT EXISTS slack_apps (
|
|
42247
|
+
registration_id TEXT PRIMARY KEY,
|
|
42248
|
+
account_id TEXT NOT NULL,
|
|
42249
|
+
write_token_hash TEXT NOT NULL,
|
|
42250
|
+
team_id TEXT,
|
|
42251
|
+
client_id TEXT,
|
|
42252
|
+
client_secret_enc TEXT,
|
|
42253
|
+
signing_secret_enc TEXT,
|
|
42254
|
+
bot_token_enc TEXT,
|
|
42255
|
+
bot_user_id TEXT,
|
|
42256
|
+
created_at INTEGER NOT NULL
|
|
42257
|
+
);
|
|
42258
|
+
CREATE UNIQUE INDEX IF NOT EXISTS slack_apps_client
|
|
42259
|
+
ON slack_apps(client_id) WHERE client_id IS NOT NULL;
|
|
42260
|
+
CREATE UNIQUE INDEX IF NOT EXISTS slack_apps_team
|
|
42261
|
+
ON slack_apps(team_id) WHERE team_id IS NOT NULL;
|
|
42262
|
+
`);
|
|
42263
|
+
}
|
|
42264
|
+
close() {
|
|
42265
|
+
this.db.close();
|
|
42266
|
+
}
|
|
42267
|
+
/** Mint a row. The write token is returned once and authorizes credential upload. */
|
|
42268
|
+
create(accountId) {
|
|
42269
|
+
const owner = accountId.trim();
|
|
42270
|
+
if (!owner) throw new Error("Slack app registration needs a Sideboard account");
|
|
42271
|
+
const registrationId = (0, import_node_crypto26.randomBytes)(16).toString("base64url");
|
|
42272
|
+
const writeToken = (0, import_node_crypto26.randomBytes)(32).toString("base64url");
|
|
42273
|
+
this.db.prepare(
|
|
42274
|
+
`INSERT INTO slack_apps (
|
|
42275
|
+
registration_id, account_id, write_token_hash, created_at
|
|
42276
|
+
) VALUES (?, ?, ?, ?)`
|
|
42277
|
+
).run(registrationId, owner, sha2562(writeToken), Date.now());
|
|
42278
|
+
return { registrationId, writeToken };
|
|
42279
|
+
}
|
|
42280
|
+
saveCredentials(registrationId, writeToken, creds) {
|
|
42281
|
+
const row2 = this.row(registrationId);
|
|
42282
|
+
if (!row2 || !sameHash(row2.write_token_hash, sha2562(writeToken.trim()))) {
|
|
42283
|
+
throw new Error("Slack app write token was rejected");
|
|
42284
|
+
}
|
|
42285
|
+
const clientId = creds.clientId.trim();
|
|
42286
|
+
const clientSecret = creds.clientSecret.trim();
|
|
42287
|
+
const signingSecret = creds.signingSecret.trim();
|
|
42288
|
+
if (!clientId || !clientSecret || !signingSecret) {
|
|
42289
|
+
throw new Error("Slack app credentials need a client id, client secret, and signing secret");
|
|
42290
|
+
}
|
|
42291
|
+
const taken = this.db.prepare(
|
|
42292
|
+
"SELECT registration_id FROM slack_apps WHERE client_id = ? AND registration_id != ?"
|
|
42293
|
+
).get(clientId, row2.registration_id);
|
|
42294
|
+
if (taken) throw new Error("That Slack client id is already registered");
|
|
42295
|
+
this.db.prepare(
|
|
42296
|
+
`UPDATE slack_apps
|
|
42297
|
+
SET client_id = ?, client_secret_enc = ?, signing_secret_enc = ?
|
|
42298
|
+
WHERE registration_id = ?`
|
|
42299
|
+
).run(clientId, sealSecret(this.key, clientSecret), sealSecret(this.key, signingSecret), row2.registration_id);
|
|
42300
|
+
}
|
|
42301
|
+
clientSecretFor(clientId) {
|
|
42302
|
+
const id = clientId.trim();
|
|
42303
|
+
if (!id) return null;
|
|
42304
|
+
const row2 = this.db.prepare("SELECT client_secret_enc FROM slack_apps WHERE client_id = ?").get(id);
|
|
42305
|
+
if (!row2?.client_secret_enc) return null;
|
|
42306
|
+
return openSecret(this.key, row2.client_secret_enc);
|
|
42307
|
+
}
|
|
42308
|
+
/**
|
|
42309
|
+
* OAuth finished for this client id. Rejects a different bot user than the
|
|
42310
|
+
* one already stored for the company.
|
|
42311
|
+
*/
|
|
42312
|
+
recordInstall(input) {
|
|
42313
|
+
const clientId = input.clientId.trim();
|
|
42314
|
+
const teamId = input.teamId.trim();
|
|
42315
|
+
const botToken = input.botToken.trim();
|
|
42316
|
+
const botUserId = input.botUserId.trim();
|
|
42317
|
+
if (!clientId || !teamId || !botToken) return false;
|
|
42318
|
+
const row2 = this.db.prepare("SELECT registration_id, team_id, bot_user_id FROM slack_apps WHERE client_id = ?").get(clientId);
|
|
42319
|
+
if (!row2) return false;
|
|
42320
|
+
if (row2.team_id && row2.team_id !== teamId) {
|
|
42321
|
+
throw new Error("This Slack app is already installed on another workspace");
|
|
42322
|
+
}
|
|
42323
|
+
if (botUserId && row2.bot_user_id && row2.bot_user_id !== botUserId) {
|
|
42324
|
+
throw new Error("This Slack app\u2019s bot user does not match the stored install");
|
|
42325
|
+
}
|
|
42326
|
+
this.db.prepare(
|
|
42327
|
+
`UPDATE slack_apps
|
|
42328
|
+
SET team_id = ?, bot_token_enc = ?, bot_user_id = COALESCE(?, bot_user_id)
|
|
42329
|
+
WHERE registration_id = ?`
|
|
42330
|
+
).run(teamId, sealSecret(this.key, botToken), botUserId || null, row2.registration_id);
|
|
42331
|
+
return true;
|
|
42332
|
+
}
|
|
42333
|
+
/** Error string when a desktop presents a different bot than the company app. */
|
|
42334
|
+
botUserMismatch(teamId, botUserId) {
|
|
42335
|
+
const row2 = this.teamRow(teamId);
|
|
42336
|
+
if (!row2?.bot_user_id) return null;
|
|
42337
|
+
if (row2.bot_user_id === botUserId.trim()) return null;
|
|
42338
|
+
return "This Mac\u2019s bot token is not the company\u2019s Sideboard Slack app";
|
|
42339
|
+
}
|
|
42340
|
+
/** Refresh the stored bot token after a desktop register for this team. */
|
|
42341
|
+
saveBot(teamId, botToken, botUserId) {
|
|
42342
|
+
const row2 = this.teamRow(teamId);
|
|
42343
|
+
const token = botToken.trim();
|
|
42344
|
+
const user = botUserId.trim();
|
|
42345
|
+
if (!row2 || !token || !user) return;
|
|
42346
|
+
if (row2.bot_user_id && row2.bot_user_id !== user) return;
|
|
42347
|
+
this.db.prepare("UPDATE slack_apps SET bot_token_enc = ?, bot_user_id = ? WHERE registration_id = ?").run(sealSecret(this.key, token), user, row2.registration_id);
|
|
42348
|
+
}
|
|
42349
|
+
getByRegistration(registrationId) {
|
|
42350
|
+
const row2 = this.row(registrationId);
|
|
42351
|
+
if (!row2) return null;
|
|
42352
|
+
return {
|
|
42353
|
+
registrationId: row2.registration_id,
|
|
42354
|
+
teamId: row2.team_id,
|
|
42355
|
+
signingSecret: row2.signing_secret_enc ? openSecret(this.key, row2.signing_secret_enc) : null
|
|
42356
|
+
};
|
|
42357
|
+
}
|
|
42358
|
+
listBots() {
|
|
42359
|
+
const rows = this.db.prepare(
|
|
42360
|
+
`SELECT team_id, bot_token_enc FROM slack_apps
|
|
42361
|
+
WHERE team_id IS NOT NULL AND bot_token_enc IS NOT NULL`
|
|
42362
|
+
).all();
|
|
42363
|
+
return rows.map((row2) => ({
|
|
42364
|
+
teamId: row2.team_id,
|
|
42365
|
+
botToken: openSecret(this.key, row2.bot_token_enc)
|
|
42366
|
+
}));
|
|
42367
|
+
}
|
|
42368
|
+
deleteByTeam(teamId) {
|
|
42369
|
+
const id = teamId.trim();
|
|
42370
|
+
if (!id) return;
|
|
42371
|
+
this.db.prepare("DELETE FROM slack_apps WHERE team_id = ?").run(id);
|
|
42372
|
+
}
|
|
42373
|
+
row(registrationId) {
|
|
42374
|
+
const id = registrationId.trim();
|
|
42375
|
+
if (!id) return null;
|
|
42376
|
+
return this.db.prepare("SELECT * FROM slack_apps WHERE registration_id = ?").get(id) ?? null;
|
|
42377
|
+
}
|
|
42378
|
+
teamRow(teamId) {
|
|
42379
|
+
const id = teamId.trim();
|
|
42380
|
+
if (!id) return null;
|
|
42381
|
+
return this.db.prepare("SELECT * FROM slack_apps WHERE team_id = ?").get(id) ?? null;
|
|
42382
|
+
}
|
|
42383
|
+
};
|
|
42384
|
+
function sha2562(value) {
|
|
42385
|
+
return (0, import_node_crypto26.createHash)("sha256").update(value).digest("hex");
|
|
42386
|
+
}
|
|
42387
|
+
function sameHash(stored, presented) {
|
|
42388
|
+
const left = Buffer.from(stored);
|
|
42389
|
+
const right = Buffer.from(presented);
|
|
42390
|
+
return left.length === right.length && (0, import_node_crypto26.timingSafeEqual)(left, right);
|
|
42391
|
+
}
|
|
42392
|
+
function thisModuleFile3() {
|
|
42393
|
+
const cjsFile = typeof __filename !== "undefined" ? __filename : "";
|
|
42394
|
+
return cjsFile || process.argv[1] || (0, import_node_path72.join)(process.cwd(), "package.json");
|
|
42395
|
+
}
|
|
42396
|
+
function openDatabase(filePath) {
|
|
42397
|
+
const req = (0, import_node_module7.createRequire)(thisModuleFile3());
|
|
42398
|
+
const { DatabaseSync: SqliteDatabase } = req("node:sqlite");
|
|
42399
|
+
const db = new SqliteDatabase(filePath);
|
|
42400
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
42401
|
+
return db;
|
|
42402
|
+
}
|
|
42403
|
+
|
|
42404
|
+
// src/relay/slack-grants.ts
|
|
42405
|
+
var import_node_crypto28 = require("crypto");
|
|
42406
|
+
var import_node_fs73 = require("fs");
|
|
42407
|
+
var import_node_module8 = require("module");
|
|
42408
|
+
var import_node_path73 = require("path");
|
|
42409
|
+
|
|
42410
|
+
// src/slack/listen-grant.ts
|
|
42411
|
+
var import_node_crypto27 = require("crypto");
|
|
42412
|
+
var MemorySlackListenGrants = class {
|
|
42413
|
+
rows = /* @__PURE__ */ new Map();
|
|
42414
|
+
issue(teamId, userId) {
|
|
42415
|
+
const team = teamId.trim();
|
|
42416
|
+
const user = userId.trim();
|
|
42417
|
+
if (!team || !user) return null;
|
|
42418
|
+
const grant = (0, import_node_crypto27.randomBytes)(32).toString("base64url");
|
|
42419
|
+
this.rows.set(hashListenGrant(grant), { teamId: team, userId: user });
|
|
42420
|
+
return grant;
|
|
42421
|
+
}
|
|
42422
|
+
verify(teamId, userId, grant) {
|
|
42423
|
+
const token = grant.trim();
|
|
42424
|
+
if (!token) return false;
|
|
42425
|
+
const row2 = this.rows.get(hashListenGrant(token));
|
|
42426
|
+
if (!row2) return false;
|
|
42427
|
+
return row2.teamId === teamId.trim() && row2.userId === userId.trim();
|
|
42428
|
+
}
|
|
42429
|
+
revokeTeam(teamId) {
|
|
42430
|
+
const team = teamId.trim();
|
|
42431
|
+
if (!team) return;
|
|
42432
|
+
for (const [hash, row2] of this.rows) {
|
|
42433
|
+
if (row2.teamId === team) this.rows.delete(hash);
|
|
42434
|
+
}
|
|
42435
|
+
}
|
|
42436
|
+
close() {
|
|
42437
|
+
this.rows.clear();
|
|
42438
|
+
}
|
|
42439
|
+
};
|
|
42440
|
+
function hashListenGrant(grant) {
|
|
42441
|
+
return (0, import_node_crypto27.createHash)("sha256").update(grant.trim()).digest("hex");
|
|
42442
|
+
}
|
|
42443
|
+
|
|
42444
|
+
// src/relay/slack-grants.ts
|
|
42445
|
+
var SlackListenGrantStore = class {
|
|
42446
|
+
db;
|
|
42447
|
+
constructor(filePath) {
|
|
42448
|
+
(0, import_node_fs73.mkdirSync)((0, import_node_path73.dirname)(filePath), { recursive: true });
|
|
42449
|
+
this.db = openDatabase2(filePath);
|
|
42450
|
+
this.db.exec(`
|
|
42451
|
+
CREATE TABLE IF NOT EXISTS slack_listen_grants (
|
|
42452
|
+
grant_hash TEXT PRIMARY KEY,
|
|
42453
|
+
team_id TEXT NOT NULL,
|
|
42454
|
+
user_id TEXT NOT NULL,
|
|
42455
|
+
created_at INTEGER NOT NULL
|
|
42456
|
+
);
|
|
42457
|
+
CREATE INDEX IF NOT EXISTS slack_listen_grants_team
|
|
42458
|
+
ON slack_listen_grants(team_id);
|
|
42459
|
+
`);
|
|
42460
|
+
}
|
|
42461
|
+
close() {
|
|
42462
|
+
this.db.close();
|
|
42463
|
+
}
|
|
42464
|
+
issue(teamId, userId) {
|
|
42465
|
+
const team = teamId.trim();
|
|
42466
|
+
const user = userId.trim();
|
|
42467
|
+
if (!team || !user) return null;
|
|
42468
|
+
const grant = (0, import_node_crypto28.randomBytes)(32).toString("base64url");
|
|
42469
|
+
this.db.prepare(
|
|
42470
|
+
`INSERT INTO slack_listen_grants (grant_hash, team_id, user_id, created_at)
|
|
42471
|
+
VALUES (?, ?, ?, ?)`
|
|
42472
|
+
).run(hashListenGrant(grant), team, user, Date.now());
|
|
42473
|
+
return grant;
|
|
42474
|
+
}
|
|
42475
|
+
verify(teamId, userId, grant) {
|
|
42476
|
+
const token = grant.trim();
|
|
42477
|
+
const team = teamId.trim();
|
|
42478
|
+
const user = userId.trim();
|
|
42479
|
+
if (!token || !team || !user) return false;
|
|
42480
|
+
const row2 = this.db.prepare("SELECT team_id, user_id FROM slack_listen_grants WHERE grant_hash = ?").get(hashListenGrant(token));
|
|
42481
|
+
return row2?.team_id === team && row2.user_id === user;
|
|
42482
|
+
}
|
|
42483
|
+
revokeTeam(teamId) {
|
|
42484
|
+
const team = teamId.trim();
|
|
42485
|
+
if (!team) return;
|
|
42486
|
+
this.db.prepare("DELETE FROM slack_listen_grants WHERE team_id = ?").run(team);
|
|
42487
|
+
}
|
|
42488
|
+
};
|
|
42489
|
+
function thisModuleFile4() {
|
|
42490
|
+
const cjsFile = typeof __filename !== "undefined" ? __filename : "";
|
|
42491
|
+
return cjsFile || process.argv[1] || (0, import_node_path73.join)(process.cwd(), "package.json");
|
|
42492
|
+
}
|
|
42493
|
+
function openDatabase2(filePath) {
|
|
42494
|
+
const req = (0, import_node_module8.createRequire)(thisModuleFile4());
|
|
42495
|
+
const { DatabaseSync: SqliteDatabase } = req("node:sqlite");
|
|
42496
|
+
const db = new SqliteDatabase(filePath);
|
|
42497
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
42498
|
+
return db;
|
|
42499
|
+
}
|
|
42500
|
+
|
|
41481
42501
|
// src/slack/relay-protocol.ts
|
|
41482
|
-
var
|
|
42502
|
+
var import_node_crypto29 = require("crypto");
|
|
41483
42503
|
var SLACK_RELAY_PING_INTERVAL_MS = 2e4;
|
|
41484
42504
|
var SLACK_RELAY_PONG_TIMEOUT_MS = 15e3;
|
|
41485
42505
|
function slackRelaySessionKey(teamId, userId, deviceId) {
|
|
@@ -41489,7 +42509,7 @@ function slackRelayUserKey(teamId, userId) {
|
|
|
41489
42509
|
return `${teamId.trim()}:${userId.trim()}`;
|
|
41490
42510
|
}
|
|
41491
42511
|
function newSlackRelayEventId() {
|
|
41492
|
-
return (0,
|
|
42512
|
+
return (0, import_node_crypto29.randomBytes)(12).toString("hex");
|
|
41493
42513
|
}
|
|
41494
42514
|
function parseSlackRelayClientMessage(raw) {
|
|
41495
42515
|
try {
|
|
@@ -41508,7 +42528,8 @@ function parseSlackRelayClientMessage(raw) {
|
|
|
41508
42528
|
const deviceLabel = typeof parsed.deviceLabel === "string" ? parsed.deviceLabel.trim() : void 0;
|
|
41509
42529
|
const botToken = typeof parsed.botToken === "string" ? parsed.botToken.trim() : "";
|
|
41510
42530
|
const userToken = typeof parsed.userToken === "string" ? parsed.userToken.trim() : "";
|
|
41511
|
-
|
|
42531
|
+
const listenGrant = typeof parsed.listenGrant === "string" ? parsed.listenGrant.trim() : "";
|
|
42532
|
+
if (!teamId || !userId || !deviceId || !botToken || !userToken && !listenGrant) return null;
|
|
41512
42533
|
return {
|
|
41513
42534
|
type: "register",
|
|
41514
42535
|
teamId,
|
|
@@ -41516,7 +42537,8 @@ function parseSlackRelayClientMessage(raw) {
|
|
|
41516
42537
|
deviceId,
|
|
41517
42538
|
deviceLabel: deviceLabel || void 0,
|
|
41518
42539
|
botToken,
|
|
41519
|
-
userToken
|
|
42540
|
+
...userToken ? { userToken } : {},
|
|
42541
|
+
...listenGrant ? { listenGrant } : {}
|
|
41520
42542
|
};
|
|
41521
42543
|
}
|
|
41522
42544
|
return null;
|
|
@@ -41567,10 +42589,10 @@ function parseSlackRelayServerMessage(raw) {
|
|
|
41567
42589
|
|
|
41568
42590
|
// src/slack/app-home.ts
|
|
41569
42591
|
var SLACK_APP_HOME_DOWNLOAD = "https://sideboard-downloads.t3.tigrisfiles.io/Sideboard-latest-arm64.dmg";
|
|
41570
|
-
var SLACK_APP_HOME_LANDING = "https://www.sideboard.
|
|
41571
|
-
var SLACK_APP_HOME_PRIVACY = "https://www.sideboard.
|
|
41572
|
-
var SLACK_APP_HOME_SUPPORT = "https://www.sideboard.
|
|
41573
|
-
var SLACK_APP_HOME_SUPPORT_EMAIL = "support@sideboard.
|
|
42592
|
+
var SLACK_APP_HOME_LANDING = "https://www.sideboard.build/slack/";
|
|
42593
|
+
var SLACK_APP_HOME_PRIVACY = "https://www.sideboard.build/privacy/";
|
|
42594
|
+
var SLACK_APP_HOME_SUPPORT = "https://www.sideboard.build/support/";
|
|
42595
|
+
var SLACK_APP_HOME_SUPPORT_EMAIL = "support@sideboard.build";
|
|
41574
42596
|
var SLACK_NO_MAC_ONLINE_REPLY = [
|
|
41575
42597
|
"No Sideboard Mac is online for your Slack user.",
|
|
41576
42598
|
"Open Sideboard \u2192 Settings \u2192 Remote and wait for Relay connected.",
|
|
@@ -41588,7 +42610,7 @@ function slackAppHomeView(opts) {
|
|
|
41588
42610
|
"",
|
|
41589
42611
|
"*First run*",
|
|
41590
42612
|
"1. Download Sideboard for Apple Silicon and keep it open.",
|
|
41591
|
-
"2. Settings \u2192
|
|
42613
|
+
"2. Settings \u2192 Collaboration \u2192 Add via browser. Name this Mac on Settings \u2192 Remote (`Work`, `Personal`, \u2026).",
|
|
41592
42614
|
"3. Wait until status shows Relay connected, then DM @Sideboard."
|
|
41593
42615
|
].join("\n");
|
|
41594
42616
|
return {
|
|
@@ -41662,11 +42684,26 @@ var SlackRelayHub = class {
|
|
|
41662
42684
|
fetchImpl;
|
|
41663
42685
|
authTest;
|
|
41664
42686
|
log;
|
|
42687
|
+
guardBotUser = null;
|
|
42688
|
+
onBotAccepted = null;
|
|
42689
|
+
verifyListenGrant = null;
|
|
41665
42690
|
constructor(opts = {}) {
|
|
41666
42691
|
this.fetchImpl = opts.fetchImpl;
|
|
41667
42692
|
this.log = opts.onLog ?? (() => void 0);
|
|
41668
42693
|
this.authTest = opts.authTest ?? (async (token) => slackApi(token, "auth.test", void 0, this.fetchImpl));
|
|
41669
42694
|
}
|
|
42695
|
+
/**
|
|
42696
|
+
* Company apps reject a bot user that is not the one stored for that team,
|
|
42697
|
+
* then persist a matching bot token. The baked app leaves both unset.
|
|
42698
|
+
*/
|
|
42699
|
+
setBotHooks(hooks2) {
|
|
42700
|
+
this.guardBotUser = hooks2.guardBotUser ?? null;
|
|
42701
|
+
this.onBotAccepted = hooks2.onBotAccepted ?? null;
|
|
42702
|
+
}
|
|
42703
|
+
/** Accept a relay listen grant in place of a Slack user token. */
|
|
42704
|
+
setListenGrantVerifier(verify2) {
|
|
42705
|
+
this.verifyListenGrant = verify2;
|
|
42706
|
+
}
|
|
41670
42707
|
sessionFor(teamId, userId, deviceId) {
|
|
41671
42708
|
return this.sessions.get(slackRelaySessionKey(teamId, userId, deviceId)) ?? null;
|
|
41672
42709
|
}
|
|
@@ -41705,43 +42742,61 @@ var SlackRelayHub = class {
|
|
|
41705
42742
|
msg.deviceId,
|
|
41706
42743
|
msg.deviceLabel,
|
|
41707
42744
|
msg.botToken,
|
|
41708
|
-
msg.userToken
|
|
42745
|
+
msg.userToken ?? "",
|
|
42746
|
+
msg.listenGrant
|
|
41709
42747
|
);
|
|
41710
42748
|
}
|
|
41711
42749
|
}
|
|
41712
|
-
async register(socket, teamId, userId, deviceId, deviceLabel, botToken, userToken) {
|
|
42750
|
+
async register(socket, teamId, userId, deviceId, deviceLabel, botToken, userToken, listenGrant) {
|
|
41713
42751
|
const claimedTeam = teamId.trim();
|
|
41714
42752
|
const claimedUser = userId.trim();
|
|
41715
42753
|
const claimedDevice = deviceId.trim();
|
|
41716
42754
|
const label = (deviceLabel?.trim() || claimedDevice).slice(0, 64);
|
|
41717
42755
|
const bot = botToken.trim();
|
|
41718
42756
|
const user = userToken.trim();
|
|
41719
|
-
|
|
42757
|
+
const grant = listenGrant?.trim() ?? "";
|
|
42758
|
+
let botUserId = "";
|
|
42759
|
+
if (!claimedTeam || !claimedUser || !claimedDevice || !bot || !user && !grant) {
|
|
41720
42760
|
this.send(socket, {
|
|
41721
42761
|
type: "error",
|
|
41722
|
-
message: "register needs teamId, userId, deviceId, botToken, and
|
|
42762
|
+
message: "register needs teamId, userId, deviceId, botToken, and a user token or listen grant"
|
|
41723
42763
|
});
|
|
41724
42764
|
return;
|
|
41725
42765
|
}
|
|
41726
42766
|
try {
|
|
41727
|
-
|
|
41728
|
-
|
|
41729
|
-
|
|
41730
|
-
|
|
41731
|
-
|
|
41732
|
-
|
|
41733
|
-
|
|
41734
|
-
|
|
41735
|
-
|
|
42767
|
+
let proved = false;
|
|
42768
|
+
if (user) {
|
|
42769
|
+
try {
|
|
42770
|
+
const userAuth = await this.authTest(user);
|
|
42771
|
+
const userTeam = userAuth.team_id?.trim();
|
|
42772
|
+
const userAuthId = userAuth.user_id?.trim();
|
|
42773
|
+
if (!userTeam || !userAuthId) {
|
|
42774
|
+
if (!grant) {
|
|
42775
|
+
this.send(socket, {
|
|
42776
|
+
type: "error",
|
|
42777
|
+
message: "user token auth.test did not return team_id/user_id"
|
|
42778
|
+
});
|
|
42779
|
+
return;
|
|
42780
|
+
}
|
|
42781
|
+
} else if (userTeam !== claimedTeam || userAuthId !== claimedUser) {
|
|
42782
|
+
this.send(socket, {
|
|
42783
|
+
type: "error",
|
|
42784
|
+
message: `User token identity ${userTeam}/${userAuthId} does not match claimed ${claimedTeam}/${claimedUser}`
|
|
42785
|
+
});
|
|
42786
|
+
this.log(
|
|
42787
|
+
`register rejected: claimed ${claimedTeam}/${claimedUser} user-token ${userTeam}/${userAuthId}`
|
|
42788
|
+
);
|
|
42789
|
+
return;
|
|
42790
|
+
} else {
|
|
42791
|
+
proved = true;
|
|
42792
|
+
}
|
|
42793
|
+
} catch (err) {
|
|
42794
|
+
if (!grant) throw err;
|
|
42795
|
+
}
|
|
41736
42796
|
}
|
|
41737
|
-
if (
|
|
41738
|
-
this.send(socket, {
|
|
41739
|
-
|
|
41740
|
-
message: `User token identity ${userTeam}/${userAuthId} does not match claimed ${claimedTeam}/${claimedUser}`
|
|
41741
|
-
});
|
|
41742
|
-
this.log(
|
|
41743
|
-
`register rejected: claimed ${claimedTeam}/${claimedUser} user-token ${userTeam}/${userAuthId}`
|
|
41744
|
-
);
|
|
42797
|
+
if (!proved && !this.verifyListenGrant?.(claimedTeam, claimedUser, grant)) {
|
|
42798
|
+
this.send(socket, { type: "error", message: "listen grant was rejected" });
|
|
42799
|
+
this.log(`register rejected: ${claimedTeam}/${claimedUser} listen grant`);
|
|
41745
42800
|
return;
|
|
41746
42801
|
}
|
|
41747
42802
|
const botAuth = await this.authTest(bot);
|
|
@@ -41761,6 +42816,22 @@ var SlackRelayHub = class {
|
|
|
41761
42816
|
this.log(`register rejected: claimed team ${claimedTeam} bot ${botTeam}`);
|
|
41762
42817
|
return;
|
|
41763
42818
|
}
|
|
42819
|
+
botUserId = botAuth.user_id?.trim() ?? "";
|
|
42820
|
+
if (this.guardBotUser) {
|
|
42821
|
+
if (!botUserId) {
|
|
42822
|
+
this.send(socket, {
|
|
42823
|
+
type: "error",
|
|
42824
|
+
message: "bot token auth.test did not return user_id"
|
|
42825
|
+
});
|
|
42826
|
+
return;
|
|
42827
|
+
}
|
|
42828
|
+
const guard = this.guardBotUser(claimedTeam, botUserId);
|
|
42829
|
+
if (guard) {
|
|
42830
|
+
this.send(socket, { type: "error", message: guard });
|
|
42831
|
+
this.log(`register rejected: ${claimedTeam} bot user ${botUserId}`);
|
|
42832
|
+
return;
|
|
42833
|
+
}
|
|
42834
|
+
}
|
|
41764
42835
|
} catch (err) {
|
|
41765
42836
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
41766
42837
|
this.send(socket, { type: "error", message: `auth.test failed: ${errMsg}` });
|
|
@@ -41788,6 +42859,7 @@ var SlackRelayHub = class {
|
|
|
41788
42859
|
this.sessions.set(key, session);
|
|
41789
42860
|
this.bySocket.set(socket, key);
|
|
41790
42861
|
this.rememberBot(claimedTeam, bot);
|
|
42862
|
+
if (botUserId) this.onBotAccepted?.(claimedTeam, bot, botUserId);
|
|
41791
42863
|
this.send(socket, {
|
|
41792
42864
|
type: "registered",
|
|
41793
42865
|
teamId: claimedTeam,
|
|
@@ -41942,9 +43014,9 @@ var SlackRelayHub = class {
|
|
|
41942
43014
|
};
|
|
41943
43015
|
|
|
41944
43016
|
// src/relay/static.ts
|
|
41945
|
-
var
|
|
43017
|
+
var import_node_fs74 = require("fs");
|
|
41946
43018
|
var import_promises = require("fs/promises");
|
|
41947
|
-
var
|
|
43019
|
+
var import_node_path74 = __toESM(require("path"), 1);
|
|
41948
43020
|
var TYPES = {
|
|
41949
43021
|
".css": "text/css; charset=utf-8",
|
|
41950
43022
|
".html": "text/html; charset=utf-8",
|
|
@@ -41957,6 +43029,7 @@ var TYPES = {
|
|
|
41957
43029
|
".svg": "image/svg+xml",
|
|
41958
43030
|
".txt": "text/plain; charset=utf-8",
|
|
41959
43031
|
".webp": "image/webp",
|
|
43032
|
+
".xml": "application/xml; charset=utf-8",
|
|
41960
43033
|
".woff2": "font/woff2"
|
|
41961
43034
|
};
|
|
41962
43035
|
function requestHostname(req) {
|
|
@@ -41967,6 +43040,45 @@ function hostnameAllowed(host, allowed) {
|
|
|
41967
43040
|
if (!allowed || allowed.length === 0) return true;
|
|
41968
43041
|
return allowed.includes(host);
|
|
41969
43042
|
}
|
|
43043
|
+
var CANONICAL_SITE_HOST = "www.sideboard.build";
|
|
43044
|
+
function isOAuthSitePath(pathname) {
|
|
43045
|
+
return pathname === "/oauth" || pathname.startsWith("/oauth/");
|
|
43046
|
+
}
|
|
43047
|
+
function marketingRedirectLocation(opts) {
|
|
43048
|
+
let pathname = "/";
|
|
43049
|
+
let search = "";
|
|
43050
|
+
try {
|
|
43051
|
+
const url = new URL(opts.requestUrl, "http://relay.local");
|
|
43052
|
+
pathname = url.pathname;
|
|
43053
|
+
search = url.search;
|
|
43054
|
+
} catch {
|
|
43055
|
+
return null;
|
|
43056
|
+
}
|
|
43057
|
+
const hostname2 = opts.hostname.toLowerCase();
|
|
43058
|
+
const canonical = opts.canonicalHost.toLowerCase();
|
|
43059
|
+
const staticHosts = opts.staticHosts ?? [];
|
|
43060
|
+
const listedSite = staticHosts.length > 0 && staticHosts.includes(hostname2);
|
|
43061
|
+
const listedRedirect = (opts.redirectHosts ?? []).includes(hostname2);
|
|
43062
|
+
const alias = hostname2 !== canonical && (listedSite || listedRedirect);
|
|
43063
|
+
if (alias && !isOAuthSitePath(pathname)) {
|
|
43064
|
+
return `https://${canonical}${pathname}${search}`;
|
|
43065
|
+
}
|
|
43066
|
+
return null;
|
|
43067
|
+
}
|
|
43068
|
+
async function directorySlashLocation(root, requestUrl) {
|
|
43069
|
+
let url;
|
|
43070
|
+
try {
|
|
43071
|
+
url = new URL(requestUrl, "http://relay.local");
|
|
43072
|
+
} catch {
|
|
43073
|
+
return null;
|
|
43074
|
+
}
|
|
43075
|
+
if (isOAuthSitePath(url.pathname) || url.pathname.endsWith("/")) return null;
|
|
43076
|
+
const candidate = resolveStaticPath(root, requestUrl);
|
|
43077
|
+
if (!candidate) return null;
|
|
43078
|
+
if (await fileSize(candidate) != null) return null;
|
|
43079
|
+
if (await fileSize(import_node_path74.default.join(candidate, "index.html")) == null) return null;
|
|
43080
|
+
return `${url.pathname}/${url.search}`;
|
|
43081
|
+
}
|
|
41970
43082
|
function resolveStaticPath(root, requestUrl) {
|
|
41971
43083
|
let pathname;
|
|
41972
43084
|
try {
|
|
@@ -41975,9 +43087,9 @@ function resolveStaticPath(root, requestUrl) {
|
|
|
41975
43087
|
return null;
|
|
41976
43088
|
}
|
|
41977
43089
|
if (!pathname.startsWith("/") || pathname.includes("\0")) return null;
|
|
41978
|
-
const rootResolved =
|
|
41979
|
-
const candidate =
|
|
41980
|
-
if (candidate !== rootResolved && !candidate.startsWith(rootResolved +
|
|
43090
|
+
const rootResolved = import_node_path74.default.resolve(root);
|
|
43091
|
+
const candidate = import_node_path74.default.resolve(rootResolved, `.${pathname}`);
|
|
43092
|
+
if (candidate !== rootResolved && !candidate.startsWith(rootResolved + import_node_path74.default.sep)) {
|
|
41981
43093
|
return null;
|
|
41982
43094
|
}
|
|
41983
43095
|
return candidate;
|
|
@@ -41991,7 +43103,7 @@ async function fileSize(file) {
|
|
|
41991
43103
|
}
|
|
41992
43104
|
}
|
|
41993
43105
|
function sendFile(req, res, file, size) {
|
|
41994
|
-
const ext =
|
|
43106
|
+
const ext = import_node_path74.default.extname(file).toLowerCase();
|
|
41995
43107
|
res.writeHead(200, {
|
|
41996
43108
|
"Content-Type": TYPES[ext] ?? "application/octet-stream",
|
|
41997
43109
|
"Content-Length": size,
|
|
@@ -42001,23 +43113,52 @@ function sendFile(req, res, file, size) {
|
|
|
42001
43113
|
res.end();
|
|
42002
43114
|
return true;
|
|
42003
43115
|
}
|
|
42004
|
-
(0,
|
|
43116
|
+
(0, import_node_fs74.createReadStream)(file).pipe(res);
|
|
42005
43117
|
return true;
|
|
42006
43118
|
}
|
|
43119
|
+
async function serveMarketingSite(req, res, opts) {
|
|
43120
|
+
const reqUrl = req.url || "/";
|
|
43121
|
+
const hostname2 = requestHostname(req);
|
|
43122
|
+
const canonical = opts.canonicalHost.toLowerCase();
|
|
43123
|
+
if (req.method === "GET" || req.method === "HEAD") {
|
|
43124
|
+
const location = marketingRedirectLocation({
|
|
43125
|
+
requestUrl: reqUrl,
|
|
43126
|
+
hostname: hostname2,
|
|
43127
|
+
canonicalHost: canonical,
|
|
43128
|
+
staticHosts: opts.staticHosts,
|
|
43129
|
+
redirectHosts: opts.redirectHosts
|
|
43130
|
+
});
|
|
43131
|
+
if (location) {
|
|
43132
|
+
res.writeHead(301, { Location: location });
|
|
43133
|
+
res.end();
|
|
43134
|
+
return true;
|
|
43135
|
+
}
|
|
43136
|
+
if (hostnameAllowed(hostname2, opts.staticHosts)) {
|
|
43137
|
+
const slash = await directorySlashLocation(opts.root, reqUrl);
|
|
43138
|
+
if (slash) {
|
|
43139
|
+
res.writeHead(301, { Location: slash });
|
|
43140
|
+
res.end();
|
|
43141
|
+
return true;
|
|
43142
|
+
}
|
|
43143
|
+
}
|
|
43144
|
+
}
|
|
43145
|
+
if (!hostnameAllowed(hostname2, opts.staticHosts)) return false;
|
|
43146
|
+
return tryServeStatic(req, res, opts.root);
|
|
43147
|
+
}
|
|
42007
43148
|
async function tryServeStatic(req, res, root) {
|
|
42008
43149
|
if (req.method !== "GET" && req.method !== "HEAD") return false;
|
|
42009
43150
|
const candidate = resolveStaticPath(root, req.url || "/");
|
|
42010
43151
|
if (!candidate) return false;
|
|
42011
43152
|
const direct = await fileSize(candidate);
|
|
42012
43153
|
if (direct != null) return sendFile(req, res, candidate, direct);
|
|
42013
|
-
const asIndex =
|
|
43154
|
+
const asIndex = import_node_path74.default.join(candidate, "index.html");
|
|
42014
43155
|
const indexSize = await fileSize(asIndex);
|
|
42015
43156
|
if (indexSize != null) return sendFile(req, res, asIndex, indexSize);
|
|
42016
43157
|
return false;
|
|
42017
43158
|
}
|
|
42018
43159
|
|
|
42019
43160
|
// src/remote/hub.ts
|
|
42020
|
-
var
|
|
43161
|
+
var import_node_crypto30 = require("crypto");
|
|
42021
43162
|
init_protocol();
|
|
42022
43163
|
var CODE_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
42023
43164
|
var CODE_TTL_MS = 10 * 60 * 1e3;
|
|
@@ -42028,7 +43169,7 @@ function send(socket, msg) {
|
|
|
42028
43169
|
}
|
|
42029
43170
|
}
|
|
42030
43171
|
function newCode() {
|
|
42031
|
-
const bytes = (0,
|
|
43172
|
+
const bytes = (0, import_node_crypto30.randomBytes)(6);
|
|
42032
43173
|
let code = "";
|
|
42033
43174
|
for (let i = 0; i < 6; i++) code += CODE_ALPHABET[bytes[i] % CODE_ALPHABET.length];
|
|
42034
43175
|
return code;
|
|
@@ -42299,7 +43440,7 @@ var RemoteHub = class {
|
|
|
42299
43440
|
host.phone = null;
|
|
42300
43441
|
}
|
|
42301
43442
|
const created = sessionToken == null;
|
|
42302
|
-
const token = sessionToken ?? (0,
|
|
43443
|
+
const token = sessionToken ?? (0, import_node_crypto30.randomBytes)(24).toString("hex");
|
|
42303
43444
|
if (host.sessionToken && host.sessionToken !== token) {
|
|
42304
43445
|
this.phonesByToken.delete(host.sessionToken);
|
|
42305
43446
|
}
|
|
@@ -42352,32 +43493,32 @@ var RemoteHub = class {
|
|
|
42352
43493
|
init_protocol();
|
|
42353
43494
|
|
|
42354
43495
|
// src/relay/accounts.ts
|
|
42355
|
-
var
|
|
42356
|
-
var
|
|
42357
|
-
var
|
|
42358
|
-
var
|
|
43496
|
+
var import_node_crypto31 = require("crypto");
|
|
43497
|
+
var import_node_fs75 = require("fs");
|
|
43498
|
+
var import_node_module9 = require("module");
|
|
43499
|
+
var import_node_path75 = require("path");
|
|
42359
43500
|
var GITHUB_ACCOUNT_ISSUER = "https://github.com";
|
|
42360
43501
|
var CURSOR_ACCOUNT_ISSUER = "https://api.cursor.com/v1/origin";
|
|
42361
43502
|
var RELAY_DEVICE_CAP = 3;
|
|
42362
|
-
function
|
|
43503
|
+
function thisModuleFile5() {
|
|
42363
43504
|
const cjsFile = typeof __filename !== "undefined" ? __filename : "";
|
|
42364
|
-
return cjsFile || process.argv[1] || (0,
|
|
43505
|
+
return cjsFile || process.argv[1] || (0, import_node_path75.join)(process.cwd(), "package.json");
|
|
42365
43506
|
}
|
|
42366
|
-
function
|
|
42367
|
-
const req = (0,
|
|
43507
|
+
function openDatabase3(filePath) {
|
|
43508
|
+
const req = (0, import_node_module9.createRequire)(thisModuleFile5());
|
|
42368
43509
|
const specifier = "node:sqlite";
|
|
42369
43510
|
const { DatabaseSync: SqliteDatabase } = req(specifier);
|
|
42370
43511
|
const db = new SqliteDatabase(filePath);
|
|
42371
43512
|
db.exec("PRAGMA journal_mode = WAL");
|
|
42372
43513
|
return db;
|
|
42373
43514
|
}
|
|
42374
|
-
function
|
|
42375
|
-
return (0,
|
|
43515
|
+
function sha2563(value) {
|
|
43516
|
+
return (0, import_node_crypto31.createHash)("sha256").update(value).digest("hex");
|
|
42376
43517
|
}
|
|
42377
|
-
function
|
|
43518
|
+
function sameHash2(a, b) {
|
|
42378
43519
|
const left = Buffer.from(a);
|
|
42379
43520
|
const right = Buffer.from(b);
|
|
42380
|
-
return left.length === right.length && (0,
|
|
43521
|
+
return left.length === right.length && (0, import_node_crypto31.timingSafeEqual)(left, right);
|
|
42381
43522
|
}
|
|
42382
43523
|
function normalizeEmail(email) {
|
|
42383
43524
|
const trimmed = email?.trim().toLowerCase() ?? "";
|
|
@@ -42398,8 +43539,8 @@ function assertRelayAccountsDurable(filePath) {
|
|
|
42398
43539
|
if (process.env.SIDEBOARD_RELAY_ACCOUNTS_EPHEMERAL === "1") return;
|
|
42399
43540
|
if (process.env.NODE_ENV !== "production") return;
|
|
42400
43541
|
if (process.platform !== "linux") return;
|
|
42401
|
-
const dir = (0,
|
|
42402
|
-
const mounts = (0,
|
|
43542
|
+
const dir = (0, import_node_fs75.realpathSync)((0, import_node_path75.dirname)(filePath));
|
|
43543
|
+
const mounts = (0, import_node_fs75.readFileSync)("/proc/mounts", "utf8");
|
|
42403
43544
|
const point = longestMountPoint(dir, mounts);
|
|
42404
43545
|
if (point === "/") {
|
|
42405
43546
|
throw new Error(
|
|
@@ -42410,8 +43551,8 @@ function assertRelayAccountsDurable(filePath) {
|
|
|
42410
43551
|
var RelayAccountStore = class {
|
|
42411
43552
|
db;
|
|
42412
43553
|
constructor(filePath) {
|
|
42413
|
-
(0,
|
|
42414
|
-
this.db =
|
|
43554
|
+
(0, import_node_fs75.mkdirSync)((0, import_node_path75.dirname)(filePath), { recursive: true });
|
|
43555
|
+
this.db = openDatabase3(filePath);
|
|
42415
43556
|
this.db.exec(`
|
|
42416
43557
|
CREATE TABLE IF NOT EXISTS accounts (
|
|
42417
43558
|
id TEXT PRIMARY KEY,
|
|
@@ -42482,7 +43623,7 @@ var RelayAccountStore = class {
|
|
|
42482
43623
|
this.insertIdentity(issuer, subject, accountId, email, verified);
|
|
42483
43624
|
} else {
|
|
42484
43625
|
const byEmail = verified ? this.accountIdForVerifiedEmail(email) : void 0;
|
|
42485
|
-
accountId = byEmail ?? (0,
|
|
43626
|
+
accountId = byEmail ?? (0, import_node_crypto31.randomUUID)();
|
|
42486
43627
|
if (!byEmail) {
|
|
42487
43628
|
this.db.prepare("INSERT INTO accounts (id, created_at, device_cap) VALUES (?, ?, ?)").run(accountId, Date.now(), RELAY_DEVICE_CAP);
|
|
42488
43629
|
}
|
|
@@ -42500,14 +43641,14 @@ var RelayAccountStore = class {
|
|
|
42500
43641
|
verifyCredential(token) {
|
|
42501
43642
|
const trimmed = token.trim();
|
|
42502
43643
|
if (!trimmed) return null;
|
|
42503
|
-
const row2 = this.db.prepare("SELECT account_id FROM credentials WHERE token_hash = ?").get(
|
|
43644
|
+
const row2 = this.db.prepare("SELECT account_id FROM credentials WHERE token_hash = ?").get(sha2563(trimmed));
|
|
42504
43645
|
return row2?.account_id ?? null;
|
|
42505
43646
|
}
|
|
42506
43647
|
/** Drop one Mac credential. The account and its other Macs stay. */
|
|
42507
43648
|
logout(token) {
|
|
42508
43649
|
const trimmed = token.trim();
|
|
42509
43650
|
if (!trimmed) return;
|
|
42510
|
-
this.db.prepare("DELETE FROM credentials WHERE token_hash = ?").run(
|
|
43651
|
+
this.db.prepare("DELETE FROM credentials WHERE token_hash = ?").run(sha2563(trimmed));
|
|
42511
43652
|
}
|
|
42512
43653
|
/** Delete the account and every identity, credential, and Mac bound to it. */
|
|
42513
43654
|
revokeAccount(accountId) {
|
|
@@ -42545,7 +43686,7 @@ var RelayAccountStore = class {
|
|
|
42545
43686
|
return { ok: false, message: "sign in required" };
|
|
42546
43687
|
}
|
|
42547
43688
|
const device = this.db.prepare("SELECT device_id, account_id, host_secret_hash FROM devices WHERE device_id = ?").get(deviceId);
|
|
42548
|
-
const secretHash =
|
|
43689
|
+
const secretHash = sha2563(hostSecret);
|
|
42549
43690
|
if (!device) {
|
|
42550
43691
|
const count = this.db.prepare("SELECT COUNT(*) AS n FROM devices WHERE account_id = ?").get(accountId);
|
|
42551
43692
|
if (count.n >= account.device_cap) {
|
|
@@ -42562,7 +43703,7 @@ var RelayAccountStore = class {
|
|
|
42562
43703
|
this.db.exec("ROLLBACK");
|
|
42563
43704
|
return { ok: false, message: "This Mac is registered to another account." };
|
|
42564
43705
|
}
|
|
42565
|
-
if (!
|
|
43706
|
+
if (!sameHash2(device.host_secret_hash, secretHash)) {
|
|
42566
43707
|
this.db.exec("ROLLBACK");
|
|
42567
43708
|
return { ok: false, message: "host secret rejected" };
|
|
42568
43709
|
}
|
|
@@ -42579,12 +43720,12 @@ var RelayAccountStore = class {
|
|
|
42579
43720
|
const id = deviceId.trim();
|
|
42580
43721
|
const token = sessionToken.trim();
|
|
42581
43722
|
if (!id || !token) return;
|
|
42582
|
-
this.db.prepare("UPDATE devices SET session_token_hash = ? WHERE device_id = ?").run(
|
|
43723
|
+
this.db.prepare("UPDATE devices SET session_token_hash = ? WHERE device_id = ?").run(sha2563(token), id);
|
|
42583
43724
|
}
|
|
42584
43725
|
findPhoneSession(sessionToken) {
|
|
42585
43726
|
const token = sessionToken.trim();
|
|
42586
43727
|
if (!token) return null;
|
|
42587
|
-
const row2 = this.db.prepare("SELECT device_id, device_label FROM devices WHERE session_token_hash = ?").get(
|
|
43728
|
+
const row2 = this.db.prepare("SELECT device_id, device_label FROM devices WHERE session_token_hash = ?").get(sha2563(token));
|
|
42588
43729
|
if (!row2) return null;
|
|
42589
43730
|
return { deviceId: row2.device_id, deviceLabel: row2.device_label };
|
|
42590
43731
|
}
|
|
@@ -42604,14 +43745,14 @@ var RelayAccountStore = class {
|
|
|
42604
43745
|
).run(issuer, subject, accountId, email, verified ? 1 : 0);
|
|
42605
43746
|
}
|
|
42606
43747
|
mintCredential(accountId) {
|
|
42607
|
-
const credential = (0,
|
|
42608
|
-
this.db.prepare("INSERT INTO credentials (token_hash, account_id, created_at) VALUES (?, ?, ?)").run(
|
|
43748
|
+
const credential = (0, import_node_crypto31.randomBytes)(32).toString("hex");
|
|
43749
|
+
this.db.prepare("INSERT INTO credentials (token_hash, account_id, created_at) VALUES (?, ?, ?)").run(sha2563(credential), accountId, Date.now());
|
|
42609
43750
|
return credential;
|
|
42610
43751
|
}
|
|
42611
43752
|
};
|
|
42612
43753
|
|
|
42613
43754
|
// src/relay/account-cursor.ts
|
|
42614
|
-
var
|
|
43755
|
+
var import_node_crypto32 = require("crypto");
|
|
42615
43756
|
var JWKS_URL = "https://api.cursor.com/v1/origin/keys";
|
|
42616
43757
|
var RECEIPT_TYP = "origin-user-confirmation-receipt+jwt";
|
|
42617
43758
|
var usedJti = /* @__PURE__ */ new Map();
|
|
@@ -42643,8 +43784,8 @@ async function cursorIdentityFromReceipt(receipt, expected, fetchImpl, nowMs = D
|
|
|
42643
43784
|
throw new Error("Cursor sign-in receipt was not a signed token.");
|
|
42644
43785
|
}
|
|
42645
43786
|
const [hSeg, pSeg, sSeg] = parts;
|
|
42646
|
-
const
|
|
42647
|
-
if (
|
|
43787
|
+
const header2 = b64urlJson(hSeg);
|
|
43788
|
+
if (header2.alg !== "EdDSA" || header2.typ !== RECEIPT_TYP || typeof header2.kid !== "string") {
|
|
42648
43789
|
throw new Error("Cursor sign-in receipt was not a user confirmation.");
|
|
42649
43790
|
}
|
|
42650
43791
|
const payload = b64urlJson(pSeg);
|
|
@@ -42662,11 +43803,11 @@ async function cursorIdentityFromReceipt(receipt, expected, fetchImpl, nowMs = D
|
|
|
42662
43803
|
const jwksRes = await fetchImpl(JWKS_URL);
|
|
42663
43804
|
const body = await jwksRes.json();
|
|
42664
43805
|
const jwk = (body.keys ?? []).find(
|
|
42665
|
-
(key2) => key2.kid ===
|
|
43806
|
+
(key2) => key2.kid === header2.kid && key2.kty === "OKP" && key2.crv === "Ed25519" && key2.x
|
|
42666
43807
|
);
|
|
42667
43808
|
if (!jwk?.x) throw new Error("Cursor did not publish the key that signed this receipt.");
|
|
42668
|
-
const key = (0,
|
|
42669
|
-
const ok = (0,
|
|
43809
|
+
const key = (0, import_node_crypto32.createPublicKey)({ key: { kty: "OKP", crv: "Ed25519", x: jwk.x }, format: "jwk" });
|
|
43810
|
+
const ok = (0, import_node_crypto32.verify)(null, Buffer.from(`${hSeg}.${pSeg}`), key, b64urlBuf(sSeg));
|
|
42670
43811
|
if (!ok) throw new Error("Cursor sign-in receipt signature did not verify.");
|
|
42671
43812
|
if (!rememberJti(jti, exp * 1e3, nowMs)) throw new Error("Cursor sign-in receipt was already used.");
|
|
42672
43813
|
const email = typeof payload.email === "string" && payload.email.trim() ? payload.email.trim() : null;
|
|
@@ -42692,7 +43833,7 @@ function cursorGitHostEntry() {
|
|
|
42692
43833
|
}
|
|
42693
43834
|
|
|
42694
43835
|
// src/relay/account-entire.ts
|
|
42695
|
-
var
|
|
43836
|
+
var import_node_crypto33 = require("crypto");
|
|
42696
43837
|
var ENTIRE_AUTHORIZE_ORIGIN = "https://auth.entire.io";
|
|
42697
43838
|
var ENTIRE_DEFAULT_ISSUER = "https://us.auth.entire.io";
|
|
42698
43839
|
var ISSUER_SUFFIX = ".auth.entire.io";
|
|
@@ -42715,10 +43856,10 @@ function entireAccountIssuer(value) {
|
|
|
42715
43856
|
return `https://${host}`;
|
|
42716
43857
|
}
|
|
42717
43858
|
function newEntireCodeVerifier() {
|
|
42718
|
-
return (0,
|
|
43859
|
+
return (0, import_node_crypto33.randomBytes)(32).toString("base64url");
|
|
42719
43860
|
}
|
|
42720
43861
|
function entireCodeChallenge(verifier) {
|
|
42721
|
-
return (0,
|
|
43862
|
+
return (0, import_node_crypto33.createHash)("sha256").update(verifier).digest("base64url");
|
|
42722
43863
|
}
|
|
42723
43864
|
function entireAuthorizeUrl(clientId, redirectUri, state, codeChallenge) {
|
|
42724
43865
|
const url = new URL("/authorize", ENTIRE_AUTHORIZE_ORIGIN);
|
|
@@ -42731,7 +43872,7 @@ function entireAuthorizeUrl(clientId, redirectUri, state, codeChallenge) {
|
|
|
42731
43872
|
url.searchParams.set("code_challenge_method", "S256");
|
|
42732
43873
|
return url.toString();
|
|
42733
43874
|
}
|
|
42734
|
-
async function
|
|
43875
|
+
async function readJson4(res) {
|
|
42735
43876
|
const text7 = await res.text();
|
|
42736
43877
|
if (!text7) return {};
|
|
42737
43878
|
try {
|
|
@@ -42775,13 +43916,13 @@ async function entireIdentityFromCode(client, code, redirectUri, ctx, fetchImpl)
|
|
|
42775
43916
|
headers,
|
|
42776
43917
|
body
|
|
42777
43918
|
});
|
|
42778
|
-
const token = accessToken(await
|
|
43919
|
+
const token = accessToken(await readJson4(tokenRes));
|
|
42779
43920
|
const userRes = await fetchImpl(`${issuer}/userinfo`, {
|
|
42780
43921
|
redirect: "error",
|
|
42781
43922
|
headers: { Accept: "application/json", Authorization: `Bearer ${token}` }
|
|
42782
43923
|
});
|
|
42783
43924
|
if (!userRes.ok) throw new Error("Entire did not return an account.");
|
|
42784
|
-
const user = await
|
|
43925
|
+
const user = await readJson4(userRes);
|
|
42785
43926
|
const subject = typeof user.sub === "string" ? user.sub.trim() : "";
|
|
42786
43927
|
if (!subject) throw new Error("Entire did not return an account id.");
|
|
42787
43928
|
const email = typeof user.email === "string" ? user.email.trim() : "";
|
|
@@ -42884,7 +44025,7 @@ function providerOf(value) {
|
|
|
42884
44025
|
function relayAuthorizeUrl(provider, client, redirectUri, state, ctx = EMPTY_AUTH) {
|
|
42885
44026
|
return GIT_HOST_AUTH[provider].authorizeUrl(client, redirectUri, state, ctx);
|
|
42886
44027
|
}
|
|
42887
|
-
async function
|
|
44028
|
+
async function readJson5(res) {
|
|
42888
44029
|
const text7 = await res.text();
|
|
42889
44030
|
if (!text7) return {};
|
|
42890
44031
|
try {
|
|
@@ -42915,17 +44056,17 @@ async function fetchGithubIdentity(client, code, redirectUri, state, fetchImpl,
|
|
|
42915
44056
|
redirect_uri: redirectUri
|
|
42916
44057
|
})
|
|
42917
44058
|
});
|
|
42918
|
-
const token = accessToken2(await
|
|
44059
|
+
const token = accessToken2(await readJson5(tokenRes));
|
|
42919
44060
|
const userRes = await fetchImpl("https://api.github.com/user", {
|
|
42920
44061
|
headers: { Authorization: `Bearer ${token}`, Accept: "application/vnd.github+json", "User-Agent": "sideboard-relay" }
|
|
42921
44062
|
});
|
|
42922
|
-
const user = await
|
|
44063
|
+
const user = await readJson5(userRes);
|
|
42923
44064
|
const subject = typeof user.id === "number" ? String(user.id) : "";
|
|
42924
44065
|
if (!subject) throw new Error("GitHub did not return an account id.");
|
|
42925
44066
|
const emailRes = await fetchImpl("https://api.github.com/user/emails", {
|
|
42926
44067
|
headers: { Authorization: `Bearer ${token}`, Accept: "application/vnd.github+json", "User-Agent": "sideboard-relay" }
|
|
42927
44068
|
});
|
|
42928
|
-
const emails = await
|
|
44069
|
+
const emails = await readJson5(emailRes);
|
|
42929
44070
|
const list = Array.isArray(emails) ? emails : [];
|
|
42930
44071
|
const primary = list.find((row2) => row2.primary === true && row2.verified === true);
|
|
42931
44072
|
const anyVerified = list.find((row2) => row2.verified === true);
|
|
@@ -42936,7 +44077,7 @@ async function fetchGithubIdentity(client, code, redirectUri, state, fetchImpl,
|
|
|
42936
44077
|
async function fetchRelayIdentity(provider, client, credential, redirectUri, state, fetchImpl, ctx = EMPTY_AUTH) {
|
|
42937
44078
|
return GIT_HOST_AUTH[provider].fetchIdentity(client, credential, redirectUri, state, fetchImpl, ctx);
|
|
42938
44079
|
}
|
|
42939
|
-
async function
|
|
44080
|
+
async function readBody2(req) {
|
|
42940
44081
|
const chunks = [];
|
|
42941
44082
|
let size = 0;
|
|
42942
44083
|
for await (const chunk of req) {
|
|
@@ -42949,7 +44090,7 @@ async function readBody(req) {
|
|
|
42949
44090
|
if (!text7) return {};
|
|
42950
44091
|
return JSON.parse(text7);
|
|
42951
44092
|
}
|
|
42952
|
-
function
|
|
44093
|
+
function sendJson2(res, status, body) {
|
|
42953
44094
|
res.writeHead(status, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
42954
44095
|
res.end(JSON.stringify(body));
|
|
42955
44096
|
}
|
|
@@ -43018,7 +44159,7 @@ function relayOAuthReturnPage(title, body) {
|
|
|
43018
44159
|
</body>
|
|
43019
44160
|
</html>`;
|
|
43020
44161
|
}
|
|
43021
|
-
function
|
|
44162
|
+
function sendHtml2(res, status, title, body) {
|
|
43022
44163
|
res.writeHead(status, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" });
|
|
43023
44164
|
res.end(relayOAuthReturnPage(title, body));
|
|
43024
44165
|
}
|
|
@@ -43032,21 +44173,21 @@ async function handleRelayAccountHttp(opts) {
|
|
|
43032
44173
|
if (method === "POST" && path2 === REMOTE_LOGIN_PATH) {
|
|
43033
44174
|
let body;
|
|
43034
44175
|
try {
|
|
43035
|
-
body = await
|
|
44176
|
+
body = await readBody2(opts.req);
|
|
43036
44177
|
} catch {
|
|
43037
|
-
|
|
44178
|
+
sendJson2(opts.res, 400, { ok: false, error: "invalid login request" });
|
|
43038
44179
|
return true;
|
|
43039
44180
|
}
|
|
43040
44181
|
const provider = providerOf(typeof body.provider === "string" ? body.provider : "");
|
|
43041
44182
|
const state = typeof body.state === "string" ? body.state.trim() : "";
|
|
43042
44183
|
if (!provider || !STATE_RE.test(state)) {
|
|
43043
|
-
|
|
44184
|
+
sendJson2(opts.res, 400, { ok: false, error: "invalid login request" });
|
|
43044
44185
|
return true;
|
|
43045
44186
|
}
|
|
43046
44187
|
const client = opts.oauth[provider];
|
|
43047
44188
|
const host = provider ? GIT_HOST_AUTH[provider] : null;
|
|
43048
44189
|
if (!client?.clientId || host?.requiresClientSecret && !client.clientSecret) {
|
|
43049
|
-
|
|
44190
|
+
sendJson2(opts.res, 503, {
|
|
43050
44191
|
ok: false,
|
|
43051
44192
|
error: `${GIT_HOST_AUTH[provider].label} sign-in is not configured on this relay.`
|
|
43052
44193
|
});
|
|
@@ -43057,14 +44198,14 @@ async function handleRelayAccountHttp(opts) {
|
|
|
43057
44198
|
if (linkToken) {
|
|
43058
44199
|
accountId = opts.store.verifyCredential(linkToken);
|
|
43059
44200
|
if (!accountId) {
|
|
43060
|
-
|
|
44201
|
+
sendJson2(opts.res, 401, { ok: false, error: "sign in required" });
|
|
43061
44202
|
return true;
|
|
43062
44203
|
}
|
|
43063
44204
|
}
|
|
43064
44205
|
const codeVerifier = provider === "entire" ? newEntireCodeVerifier() : null;
|
|
43065
44206
|
const auth = { codeVerifier, issuer: null };
|
|
43066
44207
|
opts.sessions.begin(state, provider, accountId, codeVerifier);
|
|
43067
|
-
|
|
44208
|
+
sendJson2(opts.res, 200, {
|
|
43068
44209
|
ok: true,
|
|
43069
44210
|
url: relayAuthorizeUrl(provider, client, redirectUri, state, auth)
|
|
43070
44211
|
});
|
|
@@ -43076,20 +44217,20 @@ async function handleRelayAccountHttp(opts) {
|
|
|
43076
44217
|
const providerError = url.searchParams.get("error")?.trim() ?? "";
|
|
43077
44218
|
const pending = STATE_RE.test(state) ? opts.sessions.takeLogin(state) : null;
|
|
43078
44219
|
if (!pending) {
|
|
43079
|
-
|
|
44220
|
+
sendHtml2(opts.res, 400, "Sideboard", "<h1>Sign-in expired</h1><p>Return to Sideboard and try again.</p>");
|
|
43080
44221
|
return true;
|
|
43081
44222
|
}
|
|
43082
44223
|
const credential = url.searchParams.get(GIT_HOST_AUTH[pending.provider].credentialParam)?.trim() ?? "";
|
|
43083
44224
|
if (providerError || !credential) {
|
|
43084
44225
|
const message = providerError || "Sign-in was cancelled.";
|
|
43085
44226
|
opts.sessions.putResult(state, { ok: false, error: message });
|
|
43086
|
-
|
|
44227
|
+
sendHtml2(opts.res, 400, "Sideboard", `<h1>Could not sign in</h1><p>${escapeHtml2(message)}</p>`);
|
|
43087
44228
|
return true;
|
|
43088
44229
|
}
|
|
43089
44230
|
const client = opts.oauth[pending.provider];
|
|
43090
44231
|
if (!client) {
|
|
43091
44232
|
opts.sessions.putResult(state, { ok: false, error: "Sign-in is not configured on this relay." });
|
|
43092
|
-
|
|
44233
|
+
sendHtml2(opts.res, 503, "Sideboard", "<h1>Sign-in is not configured</h1>");
|
|
43093
44234
|
return true;
|
|
43094
44235
|
}
|
|
43095
44236
|
try {
|
|
@@ -43102,14 +44243,14 @@ async function handleRelayAccountHttp(opts) {
|
|
|
43102
44243
|
fetchImpl,
|
|
43103
44244
|
{ codeVerifier: pending.codeVerifier, issuer: url.searchParams.get("iss") }
|
|
43104
44245
|
);
|
|
43105
|
-
const
|
|
44246
|
+
const signed2 = opts.store.signIn(identity, pending.accountId);
|
|
43106
44247
|
opts.sessions.putResult(state, {
|
|
43107
44248
|
ok: true,
|
|
43108
|
-
credential:
|
|
43109
|
-
email:
|
|
43110
|
-
accountId:
|
|
44249
|
+
credential: signed2.credential,
|
|
44250
|
+
email: signed2.email,
|
|
44251
|
+
accountId: signed2.accountId
|
|
43111
44252
|
});
|
|
43112
|
-
|
|
44253
|
+
sendHtml2(
|
|
43113
44254
|
opts.res,
|
|
43114
44255
|
200,
|
|
43115
44256
|
"Sideboard",
|
|
@@ -43118,7 +44259,7 @@ async function handleRelayAccountHttp(opts) {
|
|
|
43118
44259
|
} catch (err) {
|
|
43119
44260
|
const message = err instanceof Error ? err.message : String(err);
|
|
43120
44261
|
opts.sessions.putResult(state, { ok: false, error: message });
|
|
43121
|
-
|
|
44262
|
+
sendHtml2(opts.res, 400, "Sideboard", `<h1>Could not sign in</h1><p>${escapeHtml2(message)}</p>`);
|
|
43122
44263
|
}
|
|
43123
44264
|
return true;
|
|
43124
44265
|
}
|
|
@@ -43126,19 +44267,19 @@ async function handleRelayAccountHttp(opts) {
|
|
|
43126
44267
|
const url = new URL(reqUrl, origin);
|
|
43127
44268
|
const state = url.searchParams.get("state")?.trim() ?? "";
|
|
43128
44269
|
if (!STATE_RE.test(state)) {
|
|
43129
|
-
|
|
44270
|
+
sendJson2(opts.res, 400, { ok: false, error: "invalid login request" });
|
|
43130
44271
|
return true;
|
|
43131
44272
|
}
|
|
43132
44273
|
const result = opts.sessions.takeResult(state);
|
|
43133
44274
|
if (result === void 0 || result === null) {
|
|
43134
|
-
|
|
44275
|
+
sendJson2(opts.res, 404, { ok: false, error: "pending" });
|
|
43135
44276
|
return true;
|
|
43136
44277
|
}
|
|
43137
44278
|
if (!result.ok) {
|
|
43138
|
-
|
|
44279
|
+
sendJson2(opts.res, 400, { ok: false, error: result.error });
|
|
43139
44280
|
return true;
|
|
43140
44281
|
}
|
|
43141
|
-
|
|
44282
|
+
sendJson2(opts.res, 200, {
|
|
43142
44283
|
ok: true,
|
|
43143
44284
|
credential: result.credential,
|
|
43144
44285
|
email: result.email,
|
|
@@ -43149,14 +44290,14 @@ async function handleRelayAccountHttp(opts) {
|
|
|
43149
44290
|
if (method === "POST" && path2 === REMOTE_LOGOUT_PATH) {
|
|
43150
44291
|
let body;
|
|
43151
44292
|
try {
|
|
43152
|
-
body = await
|
|
44293
|
+
body = await readBody2(opts.req);
|
|
43153
44294
|
} catch {
|
|
43154
|
-
|
|
44295
|
+
sendJson2(opts.res, 400, { ok: false, error: "invalid logout request" });
|
|
43155
44296
|
return true;
|
|
43156
44297
|
}
|
|
43157
44298
|
const token = typeof body.accountToken === "string" ? body.accountToken : "";
|
|
43158
44299
|
opts.store.logout(token);
|
|
43159
|
-
|
|
44300
|
+
sendJson2(opts.res, 200, { ok: true });
|
|
43160
44301
|
return true;
|
|
43161
44302
|
}
|
|
43162
44303
|
return false;
|
|
@@ -43164,11 +44305,7 @@ async function handleRelayAccountHttp(opts) {
|
|
|
43164
44305
|
|
|
43165
44306
|
// src/relay/server.ts
|
|
43166
44307
|
init_abletime_oauth();
|
|
43167
|
-
function
|
|
43168
|
-
res.writeHead(status, { "Content-Type": "text/html; charset=utf-8" });
|
|
43169
|
-
res.end(slackOAuthHtmlPage(title, body));
|
|
43170
|
-
}
|
|
43171
|
-
function sendJson2(res, status, body) {
|
|
44308
|
+
function sendJson3(res, status, body) {
|
|
43172
44309
|
res.writeHead(status, { "Content-Type": "application/json" });
|
|
43173
44310
|
res.end(JSON.stringify(body));
|
|
43174
44311
|
}
|
|
@@ -43212,6 +44349,18 @@ async function startRelayServer(opts) {
|
|
|
43212
44349
|
const accountsPath = opts.accountsPath?.trim() ?? "";
|
|
43213
44350
|
if (accountsPath) assertRelayAccountsDurable(accountsPath);
|
|
43214
44351
|
const accountStore = accountsPath ? new RelayAccountStore(accountsPath) : null;
|
|
44352
|
+
const slackTokenKey = (opts.slackTokenKey ?? process.env.SIDEBOARD_SLACK_TOKEN_KEY ?? "").trim();
|
|
44353
|
+
const slackApps = accountsPath && slackTokenKey ? new SlackAppStore(accountsPath, parseSlackTokenKey(slackTokenKey)) : null;
|
|
44354
|
+
if (slackApps) {
|
|
44355
|
+
for (const row2 of slackApps.listBots()) hub.rememberBot(row2.teamId, row2.botToken);
|
|
44356
|
+
hub.setBotHooks({
|
|
44357
|
+
guardBotUser: (teamId, botUserId) => slackApps.botUserMismatch(teamId, botUserId),
|
|
44358
|
+
onBotAccepted: (teamId, botToken, botUserId) => slackApps.saveBot(teamId, botToken, botUserId)
|
|
44359
|
+
});
|
|
44360
|
+
}
|
|
44361
|
+
const listenGrants = accountsPath ? new SlackListenGrantStore(accountsPath) : new MemorySlackListenGrants();
|
|
44362
|
+
hub.setListenGrantVerifier((teamId, userId, grant) => listenGrants.verify(teamId, userId, grant));
|
|
44363
|
+
const slackDedupe = new SlackEventDeduper();
|
|
43215
44364
|
const accountSessions = new RelayLoginSessions();
|
|
43216
44365
|
const relayOAuth = opts.relayOAuth ?? {};
|
|
43217
44366
|
const authMarks = /* @__PURE__ */ new Map();
|
|
@@ -43228,83 +44377,7 @@ async function startRelayServer(opts) {
|
|
|
43228
44377
|
} : void 0,
|
|
43229
44378
|
onAuthorized: (socket) => authMarks.get(socket)?.()
|
|
43230
44379
|
});
|
|
43231
|
-
const
|
|
43232
|
-
const url2 = parseSlackOAuthCallbackUrl(reqUrl);
|
|
43233
|
-
if (!url2) return false;
|
|
43234
|
-
const error = url2.searchParams.get("error")?.trim();
|
|
43235
|
-
const state = url2.searchParams.get("state")?.trim() ?? "";
|
|
43236
|
-
const code = url2.searchParams.get("code")?.trim() ?? "";
|
|
43237
|
-
if (error) {
|
|
43238
|
-
if (state) pending.put(state, { ok: false, error: `Slack OAuth: ${error}` });
|
|
43239
|
-
sendHtml2(
|
|
43240
|
-
res,
|
|
43241
|
-
400,
|
|
43242
|
-
"Slack",
|
|
43243
|
-
`<h1>Authorization cancelled</h1><p>${escapeHtml2(error)}</p>`
|
|
43244
|
-
);
|
|
43245
|
-
return true;
|
|
43246
|
-
}
|
|
43247
|
-
if (!state || !code) {
|
|
43248
|
-
sendHtml2(res, 400, "Slack", "<h1>Invalid callback</h1><p>State or code missing.</p>");
|
|
43249
|
-
return true;
|
|
43250
|
-
}
|
|
43251
|
-
if (!clientSecret) {
|
|
43252
|
-
pending.put(state, {
|
|
43253
|
-
ok: false,
|
|
43254
|
-
error: "Relay is missing SIDEBOARD_SLACK_CLIENT_SECRET"
|
|
43255
|
-
});
|
|
43256
|
-
sendHtml2(
|
|
43257
|
-
res,
|
|
43258
|
-
500,
|
|
43259
|
-
"Slack",
|
|
43260
|
-
"<h1>Relay misconfigured</h1><p>OAuth client secret is not set on the relay.</p>"
|
|
43261
|
-
);
|
|
43262
|
-
return true;
|
|
43263
|
-
}
|
|
43264
|
-
try {
|
|
43265
|
-
const payload = await exchangeSlackOAuthCode({
|
|
43266
|
-
clientId,
|
|
43267
|
-
clientSecret,
|
|
43268
|
-
code,
|
|
43269
|
-
redirectUri,
|
|
43270
|
-
fetchImpl: opts.fetchImpl
|
|
43271
|
-
});
|
|
43272
|
-
pending.put(state, { ok: true, payload });
|
|
43273
|
-
if (payload.bot_token) {
|
|
43274
|
-
hub.rememberBot(payload.team_id, payload.bot_token);
|
|
43275
|
-
if (payload.user_id) {
|
|
43276
|
-
void hub.handleAppHomeOpened(payload.team_id, payload.user_id);
|
|
43277
|
-
}
|
|
43278
|
-
}
|
|
43279
|
-
sendHtml2(
|
|
43280
|
-
res,
|
|
43281
|
-
200,
|
|
43282
|
-
"Slack connected",
|
|
43283
|
-
'<h1>Slack workspace connected</h1><p>Open <strong>Sideboard \u2192 Settings \u2192 Remote \u2192 Slack</strong>. Confirm Relay connected, name this Mac, then DM @Sideboard.</p><p>Need the app? <a href="https://www.sideboard.cloud/slack/">Download Sideboard</a>.</p>'
|
|
43284
|
-
);
|
|
43285
|
-
} catch (err) {
|
|
43286
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
43287
|
-
pending.put(state, { ok: false, error: message });
|
|
43288
|
-
sendHtml2(res, 400, "Slack", `<h1>Could not connect Slack</h1><p>${escapeHtml2(message)}</p>`);
|
|
43289
|
-
}
|
|
43290
|
-
return true;
|
|
43291
|
-
};
|
|
43292
|
-
const handleResult = (reqUrl, res) => {
|
|
43293
|
-
const url2 = parseSlackOAuthResultUrl(reqUrl);
|
|
43294
|
-
if (!url2) return false;
|
|
43295
|
-
const state = url2.searchParams.get("state")?.trim() ?? "";
|
|
43296
|
-
const value = pending.take(state);
|
|
43297
|
-
if (!value) {
|
|
43298
|
-
sendJson2(res, 404, { ok: false, error: "pending" });
|
|
43299
|
-
return true;
|
|
43300
|
-
}
|
|
43301
|
-
if (!value.ok) {
|
|
43302
|
-
sendJson2(res, 400, { ok: false, error: value.error });
|
|
43303
|
-
return true;
|
|
43304
|
-
}
|
|
43305
|
-
sendJson2(res, 200, { ok: true, ...value.payload });
|
|
43306
|
-
return true;
|
|
43307
|
-
};
|
|
44380
|
+
const publicOrigin = () => opts.relayPublicOrigin?.trim() || process.env.SIDEBOARD_RELAY_PUBLIC_ORIGIN?.trim() || `http://127.0.0.1:${boundPort}`;
|
|
43308
44381
|
const httpServer = (0, import_node_http5.createServer)((req, res) => {
|
|
43309
44382
|
void (async () => {
|
|
43310
44383
|
const reqUrl = req.url || "/";
|
|
@@ -43314,13 +44387,30 @@ async function startRelayServer(opts) {
|
|
|
43314
44387
|
store: accountStore,
|
|
43315
44388
|
oauth: relayOAuth,
|
|
43316
44389
|
sessions: accountSessions,
|
|
43317
|
-
publicOrigin:
|
|
44390
|
+
publicOrigin: publicOrigin(),
|
|
43318
44391
|
fetchImpl: opts.fetchImpl
|
|
43319
44392
|
})) {
|
|
43320
44393
|
return;
|
|
43321
44394
|
}
|
|
43322
|
-
if (await
|
|
43323
|
-
|
|
44395
|
+
if (await handleSlackHttp({
|
|
44396
|
+
req,
|
|
44397
|
+
res,
|
|
44398
|
+
reqUrl,
|
|
44399
|
+
accounts: accountStore,
|
|
44400
|
+
apps: slackApps,
|
|
44401
|
+
hub,
|
|
44402
|
+
grants: listenGrants,
|
|
44403
|
+
pending,
|
|
44404
|
+
bakedClientId: clientId,
|
|
44405
|
+
bakedClientSecret: clientSecret,
|
|
44406
|
+
redirectUri,
|
|
44407
|
+
publicOrigin: publicOrigin(),
|
|
44408
|
+
fetchImpl: opts.fetchImpl,
|
|
44409
|
+
dedupe: slackDedupe,
|
|
44410
|
+
log
|
|
44411
|
+
})) {
|
|
44412
|
+
return;
|
|
44413
|
+
}
|
|
43324
44414
|
const ableTimeBounce = ableTimeOAuthLocalBounceUrl(reqUrl);
|
|
43325
44415
|
if (ableTimeBounce && (req.method === "GET" || req.method === "HEAD")) {
|
|
43326
44416
|
res.writeHead(200, {
|
|
@@ -43332,7 +44422,7 @@ async function startRelayServer(opts) {
|
|
|
43332
44422
|
return;
|
|
43333
44423
|
}
|
|
43334
44424
|
if (req.url === "/health") {
|
|
43335
|
-
|
|
44425
|
+
sendJson3(res, 200, {
|
|
43336
44426
|
ok: true,
|
|
43337
44427
|
service: "sideboard-relay",
|
|
43338
44428
|
sessions: hub.listSessions().length,
|
|
@@ -43340,20 +44430,16 @@ async function startRelayServer(opts) {
|
|
|
43340
44430
|
});
|
|
43341
44431
|
return;
|
|
43342
44432
|
}
|
|
43343
|
-
|
|
43344
|
-
|
|
43345
|
-
|
|
43346
|
-
|
|
43347
|
-
|
|
43348
|
-
|
|
43349
|
-
res.end();
|
|
43350
|
-
return;
|
|
43351
|
-
}
|
|
43352
|
-
if (opts.staticRoot && hostnameAllowed(hostname2, opts.staticHosts) && await tryServeStatic(req, res, opts.staticRoot)) {
|
|
44433
|
+
if (opts.staticRoot && await serveMarketingSite(req, res, {
|
|
44434
|
+
root: opts.staticRoot,
|
|
44435
|
+
canonicalHost: opts.canonicalSiteHost ?? CANONICAL_SITE_HOST,
|
|
44436
|
+
staticHosts: opts.staticHosts,
|
|
44437
|
+
redirectHosts: opts.redirectHosts
|
|
44438
|
+
})) {
|
|
43353
44439
|
return;
|
|
43354
44440
|
}
|
|
43355
44441
|
if (req.url === "/") {
|
|
43356
|
-
|
|
44442
|
+
sendJson3(res, 200, {
|
|
43357
44443
|
ok: true,
|
|
43358
44444
|
service: "sideboard-relay",
|
|
43359
44445
|
sessions: hub.listSessions().length,
|
|
@@ -43493,6 +44579,7 @@ async function startRelayServer(opts) {
|
|
|
43493
44579
|
void hub.handleAppHomeOpened(event.teamId, event.userId);
|
|
43494
44580
|
return;
|
|
43495
44581
|
}
|
|
44582
|
+
listenGrants.revokeTeam(event.teamId);
|
|
43496
44583
|
hub.uninstallTeam(event.teamId);
|
|
43497
44584
|
}
|
|
43498
44585
|
}).catch((err) => {
|
|
@@ -43517,6 +44604,8 @@ async function startRelayServer(opts) {
|
|
|
43517
44604
|
httpServer.close((err) => err ? reject(err) : resolve3());
|
|
43518
44605
|
});
|
|
43519
44606
|
await socketModeDone.catch(() => void 0);
|
|
44607
|
+
slackApps?.close();
|
|
44608
|
+
listenGrants.close();
|
|
43520
44609
|
accountStore?.close();
|
|
43521
44610
|
}
|
|
43522
44611
|
};
|
|
@@ -43881,7 +44970,7 @@ init_stage_files();
|
|
|
43881
44970
|
init_consume_attachments();
|
|
43882
44971
|
|
|
43883
44972
|
// src/composer/pasted-text.ts
|
|
43884
|
-
var
|
|
44973
|
+
var import_node_crypto34 = require("crypto");
|
|
43885
44974
|
var PASTE_ATTACH_MIN_CHARS = 1200;
|
|
43886
44975
|
var PASTE_ATTACH_MIN_LINES = 15;
|
|
43887
44976
|
var PASTED_NAME_RE = /^Pasted text #(\d+)\.txt$/i;
|
|
@@ -43908,7 +44997,7 @@ function nextPastedTextName(existing) {
|
|
|
43908
44997
|
}
|
|
43909
44998
|
function buildPastedTextAttachment(text7, opts) {
|
|
43910
44999
|
return {
|
|
43911
|
-
id: opts?.id ?? (0,
|
|
45000
|
+
id: opts?.id ?? (0, import_node_crypto34.randomUUID)(),
|
|
43912
45001
|
name: opts?.name ?? "Pasted text #1.txt",
|
|
43913
45002
|
kind: "file",
|
|
43914
45003
|
path: opts?.path,
|
|
@@ -43983,22 +45072,22 @@ init_error_detail();
|
|
|
43983
45072
|
init_cursor_stream_cutoff();
|
|
43984
45073
|
|
|
43985
45074
|
// src/agents/tool-result-clip.ts
|
|
43986
|
-
var
|
|
43987
|
-
var
|
|
45075
|
+
var import_node_fs76 = require("fs");
|
|
45076
|
+
var import_node_path76 = require("path");
|
|
43988
45077
|
init_workspace_scratch();
|
|
43989
45078
|
init_error_detail();
|
|
43990
45079
|
function spillPath(cwd, prefix) {
|
|
43991
45080
|
const stamp = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
43992
45081
|
const safe = prefix.replace(/[^a-zA-Z0-9_-]+/g, "-").slice(0, 40) || "tool";
|
|
43993
|
-
return (0,
|
|
45082
|
+
return (0, import_node_path76.join)(cwd, CLI_DIR, `${safe}-${stamp}.txt`);
|
|
43994
45083
|
}
|
|
43995
45084
|
function spillToolResultToCli(content, opts) {
|
|
43996
45085
|
const cwd = opts?.cwd?.trim();
|
|
43997
45086
|
if (!cwd || !content) return null;
|
|
43998
45087
|
const file = spillPath(cwd, opts?.prefix ?? "tool-result");
|
|
43999
45088
|
try {
|
|
44000
|
-
(0,
|
|
44001
|
-
(0,
|
|
45089
|
+
(0, import_node_fs76.mkdirSync)((0, import_node_path76.join)(cwd, CLI_DIR), { recursive: true });
|
|
45090
|
+
(0, import_node_fs76.writeFileSync)(file, content, "utf8");
|
|
44002
45091
|
return file;
|
|
44003
45092
|
} catch {
|
|
44004
45093
|
return null;
|
|
@@ -44084,8 +45173,8 @@ function createClippedMcpServer() {
|
|
|
44084
45173
|
|
|
44085
45174
|
// src/mcp/server.ts
|
|
44086
45175
|
var import_zod11 = require("zod");
|
|
44087
|
-
var
|
|
44088
|
-
var
|
|
45176
|
+
var import_node_crypto37 = require("crypto");
|
|
45177
|
+
var import_node_path80 = require("path");
|
|
44089
45178
|
init_orchestrator();
|
|
44090
45179
|
init_task_state();
|
|
44091
45180
|
init_worktree();
|
|
@@ -45766,8 +46855,8 @@ function registerScheduleTools(server) {
|
|
|
45766
46855
|
}
|
|
45767
46856
|
|
|
45768
46857
|
// src/agent-rpc/handlers.ts
|
|
45769
|
-
var
|
|
45770
|
-
var
|
|
46858
|
+
var import_node_crypto35 = require("crypto");
|
|
46859
|
+
var import_node_path77 = require("path");
|
|
45771
46860
|
init_wait_for_job();
|
|
45772
46861
|
init_wait_for_turn();
|
|
45773
46862
|
|
|
@@ -45849,7 +46938,7 @@ var handlePermissionAsk = async (params, _ctx) => {
|
|
|
45849
46938
|
// src/agent-rpc/handlers.ts
|
|
45850
46939
|
init_protocol2();
|
|
45851
46940
|
function presentArtifactResult(input) {
|
|
45852
|
-
const id = input.artifact_id?.trim() || `artifact_${Date.now().toString(36)}_${(0,
|
|
46941
|
+
const id = input.artifact_id?.trim() || `artifact_${Date.now().toString(36)}_${(0, import_node_crypto35.randomUUID)().slice(0, 8)}`;
|
|
45853
46942
|
return {
|
|
45854
46943
|
ok: true,
|
|
45855
46944
|
artifact_id: id,
|
|
@@ -45874,7 +46963,7 @@ function invalidParams2(message) {
|
|
|
45874
46963
|
function jobCwd(rec) {
|
|
45875
46964
|
const raw = str7(rec.cwd).trim();
|
|
45876
46965
|
if (!raw) throw invalidParams2("cwd is required");
|
|
45877
|
-
if (!(0,
|
|
46966
|
+
if (!(0, import_node_path77.isAbsolute)(raw)) throw invalidParams2("cwd must be an absolute path");
|
|
45878
46967
|
return raw;
|
|
45879
46968
|
}
|
|
45880
46969
|
async function handleRuntimePing(_params, _ctx) {
|
|
@@ -46007,36 +47096,36 @@ init_gh_errors();
|
|
|
46007
47096
|
init_git_auth_mode();
|
|
46008
47097
|
|
|
46009
47098
|
// src/board/load-home-board.ts
|
|
46010
|
-
var
|
|
46011
|
-
var
|
|
47099
|
+
var import_node_fs78 = require("fs");
|
|
47100
|
+
var import_node_path79 = require("path");
|
|
46012
47101
|
init_worktree();
|
|
46013
47102
|
init_paths();
|
|
46014
47103
|
|
|
46015
47104
|
// src/board/board-pins.ts
|
|
46016
|
-
var
|
|
46017
|
-
var
|
|
46018
|
-
var
|
|
47105
|
+
var import_node_crypto36 = require("crypto");
|
|
47106
|
+
var import_node_fs77 = require("fs");
|
|
47107
|
+
var import_node_path78 = require("path");
|
|
46019
47108
|
init_paths();
|
|
46020
47109
|
init_home_board();
|
|
46021
47110
|
var FILE = "home-board-pins.json";
|
|
46022
|
-
var
|
|
47111
|
+
var VERSION2 = 1;
|
|
46023
47112
|
function pinsFile() {
|
|
46024
|
-
return (0,
|
|
47113
|
+
return (0, import_node_path78.join)(appDataDir(), FILE);
|
|
46025
47114
|
}
|
|
46026
47115
|
function readDisk() {
|
|
46027
47116
|
const path2 = pinsFile();
|
|
46028
|
-
if (!(0,
|
|
47117
|
+
if (!(0, import_node_fs77.existsSync)(path2)) return [];
|
|
46029
47118
|
try {
|
|
46030
|
-
const raw = JSON.parse((0,
|
|
46031
|
-
if (raw?.version !==
|
|
47119
|
+
const raw = JSON.parse((0, import_node_fs77.readFileSync)(path2, "utf8"));
|
|
47120
|
+
if (raw?.version !== VERSION2 || !Array.isArray(raw.items)) return [];
|
|
46032
47121
|
return raw.items.filter((item) => item?.id && item.kind && item.ref);
|
|
46033
47122
|
} catch {
|
|
46034
47123
|
return [];
|
|
46035
47124
|
}
|
|
46036
47125
|
}
|
|
46037
47126
|
function writeDisk(items) {
|
|
46038
|
-
(0,
|
|
46039
|
-
(0,
|
|
47127
|
+
(0, import_node_fs77.mkdirSync)(appDataDir(), { recursive: true });
|
|
47128
|
+
(0, import_node_fs77.writeFileSync)(pinsFile(), JSON.stringify({ version: VERSION2, items }, null, 2), "utf8");
|
|
46040
47129
|
}
|
|
46041
47130
|
function listBoardPins() {
|
|
46042
47131
|
return readDisk();
|
|
@@ -46045,7 +47134,7 @@ function addBoardPin(input) {
|
|
|
46045
47134
|
const ref = input.ref.trim();
|
|
46046
47135
|
if (!ref) throw new Error("Board item needs a ref");
|
|
46047
47136
|
const pin = {
|
|
46048
|
-
id: (0,
|
|
47137
|
+
id: (0, import_node_crypto36.randomUUID)(),
|
|
46049
47138
|
kind: input.kind,
|
|
46050
47139
|
ref,
|
|
46051
47140
|
repoPath: input.repoPath.trim(),
|
|
@@ -46088,7 +47177,7 @@ function replaceBoardPins(items) {
|
|
|
46088
47177
|
}
|
|
46089
47178
|
function clearBoardPins() {
|
|
46090
47179
|
try {
|
|
46091
|
-
(0,
|
|
47180
|
+
(0, import_node_fs77.unlinkSync)(pinsFile());
|
|
46092
47181
|
} catch {
|
|
46093
47182
|
}
|
|
46094
47183
|
}
|
|
@@ -46105,7 +47194,7 @@ function homeBoardWorkspaceKey(workspaces) {
|
|
|
46105
47194
|
return workspaces.map((w) => w.path).filter(Boolean).sort().join("\n");
|
|
46106
47195
|
}
|
|
46107
47196
|
function cacheFile() {
|
|
46108
|
-
return (0,
|
|
47197
|
+
return (0, import_node_path79.join)(appDataDir(), "home-board-cache.json");
|
|
46109
47198
|
}
|
|
46110
47199
|
function emptyInputs() {
|
|
46111
47200
|
return {
|
|
@@ -46131,9 +47220,9 @@ function shouldCacheHomeBoardInputs(inputs) {
|
|
|
46131
47220
|
}
|
|
46132
47221
|
function readDiskCache() {
|
|
46133
47222
|
const path2 = cacheFile();
|
|
46134
|
-
if (!(0,
|
|
47223
|
+
if (!(0, import_node_fs78.existsSync)(path2)) return null;
|
|
46135
47224
|
try {
|
|
46136
|
-
const raw = JSON.parse((0,
|
|
47225
|
+
const raw = JSON.parse((0, import_node_fs78.readFileSync)(path2, "utf8"));
|
|
46137
47226
|
if (raw?.version !== CACHE_VERSION || typeof raw.fetchedAt !== "number") {
|
|
46138
47227
|
return null;
|
|
46139
47228
|
}
|
|
@@ -46147,14 +47236,14 @@ function readDiskCache() {
|
|
|
46147
47236
|
}
|
|
46148
47237
|
function writeDiskCache(entry) {
|
|
46149
47238
|
try {
|
|
46150
|
-
(0,
|
|
46151
|
-
(0,
|
|
47239
|
+
(0, import_node_fs78.mkdirSync)(appDataDir(), { recursive: true });
|
|
47240
|
+
(0, import_node_fs78.writeFileSync)(cacheFile(), JSON.stringify(entry), "utf8");
|
|
46152
47241
|
} catch {
|
|
46153
47242
|
}
|
|
46154
47243
|
}
|
|
46155
47244
|
function deleteDiskCache() {
|
|
46156
47245
|
try {
|
|
46157
|
-
(0,
|
|
47246
|
+
(0, import_node_fs78.unlinkSync)(cacheFile());
|
|
46158
47247
|
} catch {
|
|
46159
47248
|
}
|
|
46160
47249
|
}
|
|
@@ -46370,7 +47459,7 @@ async function startMcpServer() {
|
|
|
46370
47459
|
async () => {
|
|
46371
47460
|
const threads = orch.getThreads();
|
|
46372
47461
|
const lines = threads.map((t) => {
|
|
46373
|
-
const repo = t.repoPath === GLOBAL_WORKSPACE_ID2 ? "Orchestration" : (0,
|
|
47462
|
+
const repo = t.repoPath === GLOBAL_WORKSPACE_ID2 ? "Orchestration" : (0, import_node_path80.basename)(t.repoPath) || t.repoPath;
|
|
46374
47463
|
const live = orch.threadLooksLive(t) ? readTurnLive(t.id) : null;
|
|
46375
47464
|
const parent = t.parentThreadId ? ` parent:${t.parentThreadId.slice(0, 8)}` : "";
|
|
46376
47465
|
const preview = lastMessagePreview(t.messages, 80);
|
|
@@ -46978,7 +48067,7 @@ async function startMcpServer() {
|
|
|
46978
48067
|
const ident = issue?.identifier ?? ref.trim();
|
|
46979
48068
|
const attachments = issue ? [
|
|
46980
48069
|
{
|
|
46981
|
-
id: (0,
|
|
48070
|
+
id: (0, import_node_crypto37.randomUUID)(),
|
|
46982
48071
|
name: issue.identifier,
|
|
46983
48072
|
kind: "issue",
|
|
46984
48073
|
content: [
|
|
@@ -47540,7 +48629,7 @@ init_protocol2();
|
|
|
47540
48629
|
init_metadata();
|
|
47541
48630
|
|
|
47542
48631
|
// src/agent-rpc/server.ts
|
|
47543
|
-
var
|
|
48632
|
+
var import_node_crypto38 = require("crypto");
|
|
47544
48633
|
var import_node_http6 = require("http");
|
|
47545
48634
|
var import_ws5 = require("ws");
|
|
47546
48635
|
init_protocol2();
|
|
@@ -47549,7 +48638,7 @@ function tokensEqual(a, b) {
|
|
|
47549
48638
|
const left = Buffer.from(a);
|
|
47550
48639
|
const right = Buffer.from(b);
|
|
47551
48640
|
if (left.length !== right.length) return false;
|
|
47552
|
-
return (0,
|
|
48641
|
+
return (0, import_node_crypto38.timingSafeEqual)(left, right);
|
|
47553
48642
|
}
|
|
47554
48643
|
function authTokenFromUpgrade(req) {
|
|
47555
48644
|
try {
|
|
@@ -47559,7 +48648,7 @@ function authTokenFromUpgrade(req) {
|
|
|
47559
48648
|
return "";
|
|
47560
48649
|
}
|
|
47561
48650
|
}
|
|
47562
|
-
function
|
|
48651
|
+
function sendJson4(ws, value) {
|
|
47563
48652
|
if (ws.readyState !== ws.OPEN) return;
|
|
47564
48653
|
ws.send(JSON.stringify(value));
|
|
47565
48654
|
}
|
|
@@ -47582,9 +48671,9 @@ var AgentRpcServer = class {
|
|
|
47582
48671
|
async listen(opts = {}) {
|
|
47583
48672
|
const host = opts.host ?? "127.0.0.1";
|
|
47584
48673
|
const port = opts.port ?? 0;
|
|
47585
|
-
const authToken = (0,
|
|
48674
|
+
const authToken = (0, import_node_crypto38.randomBytes)(24).toString("base64url");
|
|
47586
48675
|
this.meta = {
|
|
47587
|
-
runtimeId: (0,
|
|
48676
|
+
runtimeId: (0, import_node_crypto38.randomUUID)(),
|
|
47588
48677
|
pid: process.pid,
|
|
47589
48678
|
protocolVersion: AGENT_RPC_PROTOCOL_VERSION,
|
|
47590
48679
|
authToken,
|
|
@@ -47644,36 +48733,36 @@ var AgentRpcServer = class {
|
|
|
47644
48733
|
async onMessage(ws, raw) {
|
|
47645
48734
|
const parsed = parseRpcFrame(raw);
|
|
47646
48735
|
if (parsed === void 0) {
|
|
47647
|
-
|
|
48736
|
+
sendJson4(ws, rpcError(null, RPC_PARSE_ERROR, "Parse error"));
|
|
47648
48737
|
return;
|
|
47649
48738
|
}
|
|
47650
48739
|
if (!isJsonRpcRequest(parsed)) {
|
|
47651
|
-
|
|
48740
|
+
sendJson4(ws, rpcError(null, RPC_INVALID_REQUEST, "Invalid request"));
|
|
47652
48741
|
return;
|
|
47653
48742
|
}
|
|
47654
48743
|
const id = parsed.id;
|
|
47655
48744
|
const expected = this.meta?.authToken ?? "";
|
|
47656
48745
|
const got = typeof parsed.authToken === "string" ? parsed.authToken : "";
|
|
47657
48746
|
if (!expected || !got || !tokensEqual(got, expected)) {
|
|
47658
|
-
|
|
48747
|
+
sendJson4(ws, rpcError(id, RPC_UNAUTHORIZED, "Unauthorized"));
|
|
47659
48748
|
return;
|
|
47660
48749
|
}
|
|
47661
48750
|
const handler = this.handlers[parsed.method];
|
|
47662
48751
|
if (!handler) {
|
|
47663
|
-
|
|
48752
|
+
sendJson4(ws, rpcError(id, RPC_METHOD_NOT_FOUND, `Method not found: ${parsed.method}`));
|
|
47664
48753
|
return;
|
|
47665
48754
|
}
|
|
47666
48755
|
const ctx = {
|
|
47667
48756
|
cwd: this.cwd(),
|
|
47668
|
-
notify: (method, params) =>
|
|
48757
|
+
notify: (method, params) => sendJson4(ws, rpcNotify(method, params))
|
|
47669
48758
|
};
|
|
47670
48759
|
try {
|
|
47671
48760
|
const result = await handler(parsed.params, ctx);
|
|
47672
|
-
|
|
48761
|
+
sendJson4(ws, rpcResult(id, result));
|
|
47673
48762
|
} catch (err) {
|
|
47674
48763
|
const message = err instanceof Error ? err.message : String(err);
|
|
47675
48764
|
const code = err && typeof err === "object" && "rpcCode" in err && typeof err.rpcCode === "number" ? err.rpcCode : RPC_INTERNAL_ERROR;
|
|
47676
|
-
|
|
48765
|
+
sendJson4(ws, rpcError(id, code, message));
|
|
47677
48766
|
}
|
|
47678
48767
|
}
|
|
47679
48768
|
async close() {
|
|
@@ -48383,248 +49472,59 @@ init_host();
|
|
|
48383
49472
|
init_model_context();
|
|
48384
49473
|
init_meta();
|
|
48385
49474
|
|
|
48386
|
-
// src/slack/
|
|
48387
|
-
|
|
48388
|
-
|
|
48389
|
-
init_secure_file();
|
|
48390
|
-
function storePath2() {
|
|
48391
|
-
return (0, import_node_path78.join)(appDataDir(), "slack-workspaces.json");
|
|
49475
|
+
// src/slack/org-app-client.ts
|
|
49476
|
+
function originOf(relayWsUrl) {
|
|
49477
|
+
return slackRelayHttpOrigin(relayWsUrl ?? slackRelayUrl());
|
|
48392
49478
|
}
|
|
48393
|
-
function
|
|
49479
|
+
async function readError(res) {
|
|
48394
49480
|
try {
|
|
48395
|
-
const
|
|
48396
|
-
|
|
48397
|
-
const parsed = readSecureJson(path2);
|
|
48398
|
-
const workspaces = Array.isArray(parsed?.workspaces) ? parsed.workspaces : [];
|
|
48399
|
-
if (workspaces.length > 0 && !wasEncrypted && resolveVaultKey()) {
|
|
48400
|
-
writeSecureJson(path2, { workspaces });
|
|
48401
|
-
}
|
|
48402
|
-
return workspaces;
|
|
49481
|
+
const body = await res.json();
|
|
49482
|
+
if (body.error?.trim()) return body.error.trim();
|
|
48403
49483
|
} catch {
|
|
48404
|
-
return [];
|
|
48405
49484
|
}
|
|
49485
|
+
return `Relay returned ${res.status}`;
|
|
48406
49486
|
}
|
|
48407
|
-
function
|
|
48408
|
-
|
|
48409
|
-
|
|
48410
|
-
|
|
48411
|
-
|
|
49487
|
+
async function createSlackOrgApp(opts) {
|
|
49488
|
+
const token = opts.accountToken.trim();
|
|
49489
|
+
if (!token) throw new Error("Sign in on Settings \u2192 Remote before creating a Slack app");
|
|
49490
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
49491
|
+
const res = await fetchImpl(`${originOf(opts.relayWsUrl)}/slack/apps`, {
|
|
49492
|
+
method: "POST",
|
|
49493
|
+
headers: { Authorization: `Bearer ${token}` }
|
|
49494
|
+
});
|
|
49495
|
+
if (!res.ok) throw new Error(await readError(res));
|
|
49496
|
+
const body = await res.json();
|
|
49497
|
+
if (!body.registrationId || !body.writeToken || !body.manifest || !body.eventsUrl) {
|
|
49498
|
+
throw new Error("Relay did not return a Slack app registration");
|
|
49499
|
+
}
|
|
48412
49500
|
return {
|
|
48413
|
-
|
|
48414
|
-
|
|
48415
|
-
|
|
48416
|
-
|
|
48417
|
-
has_user_token: Boolean(ws.user_token),
|
|
48418
|
-
connected_at: ws.connected_at
|
|
49501
|
+
registrationId: body.registrationId,
|
|
49502
|
+
writeToken: body.writeToken,
|
|
49503
|
+
eventsUrl: body.eventsUrl,
|
|
49504
|
+
manifest: body.manifest
|
|
48419
49505
|
};
|
|
48420
49506
|
}
|
|
48421
|
-
function
|
|
48422
|
-
|
|
48423
|
-
|
|
48424
|
-
|
|
48425
|
-
|
|
48426
|
-
|
|
48427
|
-
|
|
48428
|
-
|
|
48429
|
-
|
|
48430
|
-
|
|
48431
|
-
|
|
48432
|
-
|
|
48433
|
-
}
|
|
48434
|
-
function upsertSlackWorkspace(entry) {
|
|
48435
|
-
const workspaces = readStore2().filter((ws) => ws.team_id !== entry.team_id);
|
|
48436
|
-
workspaces.push(entry);
|
|
48437
|
-
writeStore2(workspaces);
|
|
48438
|
-
return toInfo(entry);
|
|
48439
|
-
}
|
|
48440
|
-
function disconnectSlackWorkspace(teamId) {
|
|
48441
|
-
const id = teamId.trim();
|
|
48442
|
-
writeStore2(readStore2().filter((ws) => ws.team_id !== id));
|
|
48443
|
-
return listSlackWorkspaces();
|
|
48444
|
-
}
|
|
48445
|
-
function tokenKind(token) {
|
|
48446
|
-
if (token.startsWith("xoxb-")) return "bot";
|
|
48447
|
-
if (token.startsWith("xoxp-") || token.startsWith("xoxe.xoxp-")) return "user";
|
|
48448
|
-
return "unknown";
|
|
48449
|
-
}
|
|
48450
|
-
async function connectSlackToken(rawToken) {
|
|
48451
|
-
const token = rawToken.trim();
|
|
48452
|
-
if (!token) throw new Error("Paste a Slack bot (xoxb-) or user (xoxp-) token");
|
|
48453
|
-
const auth = await slackAuthTest(token);
|
|
48454
|
-
const teamId = auth.team_id?.trim();
|
|
48455
|
-
if (!teamId) throw new Error("Slack auth.test did not return a team_id");
|
|
48456
|
-
const existing = getSlackWorkspace(teamId);
|
|
48457
|
-
const kind = tokenKind(token);
|
|
48458
|
-
const next = {
|
|
48459
|
-
team_id: teamId,
|
|
48460
|
-
team_name: auth.team?.trim() || existing?.team_name || teamId,
|
|
48461
|
-
user_id: auth.user_id?.trim() || existing?.user_id,
|
|
48462
|
-
bot_token: kind === "bot" ? token : existing?.bot_token,
|
|
48463
|
-
user_token: kind === "user" || kind === "unknown" ? token : existing?.user_token,
|
|
48464
|
-
scopes: existing?.scopes,
|
|
48465
|
-
connected_at: existing?.connected_at || (/* @__PURE__ */ new Date()).toISOString()
|
|
48466
|
-
};
|
|
48467
|
-
if (kind === "unknown" && auth.bot_id) {
|
|
48468
|
-
next.bot_token = token;
|
|
48469
|
-
next.user_token = existing?.user_token;
|
|
48470
|
-
}
|
|
48471
|
-
return upsertSlackWorkspace(next);
|
|
48472
|
-
}
|
|
48473
|
-
function slackTokenFor(ws, kind = "read") {
|
|
48474
|
-
const token = (kind === "write" ? ws.bot_token || ws.user_token : ws.user_token || ws.bot_token)?.trim();
|
|
48475
|
-
if (!token) {
|
|
48476
|
-
throw new Error(`Slack workspace ${ws.team_name} has no token`);
|
|
48477
|
-
}
|
|
48478
|
-
return token;
|
|
48479
|
-
}
|
|
48480
|
-
|
|
48481
|
-
// src/slack/oauth.ts
|
|
48482
|
-
var import_node_crypto33 = require("crypto");
|
|
48483
|
-
init_app_settings();
|
|
48484
|
-
var SLACK_BOT_SCOPES = [
|
|
48485
|
-
"app_mentions:read",
|
|
48486
|
-
"channels:history",
|
|
48487
|
-
"channels:read",
|
|
48488
|
-
"groups:history",
|
|
48489
|
-
"groups:read",
|
|
48490
|
-
"im:history",
|
|
48491
|
-
"im:read",
|
|
48492
|
-
"im:write",
|
|
48493
|
-
"mpim:history",
|
|
48494
|
-
"mpim:read",
|
|
48495
|
-
"chat:write",
|
|
48496
|
-
"chat:write.public",
|
|
48497
|
-
"reactions:write",
|
|
48498
|
-
"users:read",
|
|
48499
|
-
"users:read.email"
|
|
48500
|
-
].join(",");
|
|
48501
|
-
var SLACK_USER_SCOPES = [
|
|
48502
|
-
"channels:history",
|
|
48503
|
-
"channels:read",
|
|
48504
|
-
"groups:history",
|
|
48505
|
-
"im:history",
|
|
48506
|
-
"mpim:history",
|
|
48507
|
-
"users:read"
|
|
48508
|
-
].join(",");
|
|
48509
|
-
function slackOAuthCredentials() {
|
|
48510
|
-
const settings = loadAppSettings();
|
|
48511
|
-
const clientId = process.env.SIDEBOARD_SLACK_CLIENT_ID?.trim() || settings.integrations.slackClientId?.trim() || BAKED_SLACK_CLIENT_ID.trim();
|
|
48512
|
-
const clientSecret = process.env.SIDEBOARD_SLACK_CLIENT_SECRET?.trim() || settings.integrations.slackClientSecret?.trim() || "";
|
|
48513
|
-
if (!clientId) {
|
|
48514
|
-
throw new Error(
|
|
48515
|
-
"Slack browser sign-in needs a Slack app Client ID (Settings \u2192 Remote \u2192 Slack, or SIDEBOARD_SLACK_CLIENT_ID). You can still paste an xoxb- or xoxp- token."
|
|
48516
|
-
);
|
|
48517
|
-
}
|
|
48518
|
-
return { clientId, clientSecret: clientSecret || null };
|
|
48519
|
-
}
|
|
48520
|
-
var SLACK_OAUTH_CANCELLED = "Slack sign-in cancelled";
|
|
48521
|
-
var SlackOAuthCancelledError = class extends Error {
|
|
48522
|
-
constructor(message = SLACK_OAUTH_CANCELLED) {
|
|
48523
|
-
super(message);
|
|
48524
|
-
this.name = "SlackOAuthCancelledError";
|
|
48525
|
-
}
|
|
48526
|
-
};
|
|
48527
|
-
function isSlackOAuthCancelled(err) {
|
|
48528
|
-
if (err instanceof SlackOAuthCancelledError) return true;
|
|
48529
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
48530
|
-
if (message.includes(SLACK_OAUTH_CANCELLED)) return true;
|
|
48531
|
-
return err instanceof Error && err.name === "SlackOAuthCancelledError";
|
|
48532
|
-
}
|
|
48533
|
-
function slackOAuthAuthorizeUrl(clientId, state) {
|
|
48534
|
-
const params = new URLSearchParams({
|
|
48535
|
-
client_id: clientId,
|
|
48536
|
-
scope: SLACK_BOT_SCOPES,
|
|
48537
|
-
user_scope: SLACK_USER_SCOPES,
|
|
48538
|
-
redirect_uri: slackOAuthRedirectUri(),
|
|
48539
|
-
state
|
|
48540
|
-
});
|
|
48541
|
-
return `https://slack.com/oauth/v2/authorize?${params.toString()}`;
|
|
48542
|
-
}
|
|
48543
|
-
function sleep(ms, signal) {
|
|
48544
|
-
return new Promise((resolve3, reject) => {
|
|
48545
|
-
if (signal?.aborted) {
|
|
48546
|
-
reject(new SlackOAuthCancelledError());
|
|
48547
|
-
return;
|
|
48548
|
-
}
|
|
48549
|
-
const timer = setTimeout(() => {
|
|
48550
|
-
signal?.removeEventListener("abort", onAbort);
|
|
48551
|
-
resolve3();
|
|
48552
|
-
}, ms);
|
|
48553
|
-
const onAbort = () => {
|
|
48554
|
-
clearTimeout(timer);
|
|
48555
|
-
reject(new SlackOAuthCancelledError());
|
|
48556
|
-
};
|
|
48557
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
48558
|
-
});
|
|
48559
|
-
}
|
|
48560
|
-
function upsertFromPayload(payload) {
|
|
48561
|
-
return upsertSlackWorkspace({
|
|
48562
|
-
team_id: payload.team_id,
|
|
48563
|
-
team_name: payload.team_name,
|
|
48564
|
-
user_id: payload.user_id,
|
|
48565
|
-
bot_token: payload.bot_token,
|
|
48566
|
-
user_token: payload.user_token,
|
|
48567
|
-
scopes: payload.scopes,
|
|
48568
|
-
connected_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
48569
|
-
});
|
|
48570
|
-
}
|
|
48571
|
-
async function startSlackOAuth(opts) {
|
|
48572
|
-
if (opts?.signal?.aborted) {
|
|
48573
|
-
throw new SlackOAuthCancelledError();
|
|
48574
|
-
}
|
|
48575
|
-
const { clientId } = slackOAuthCredentials();
|
|
48576
|
-
const state = (0, import_node_crypto33.randomBytes)(16).toString("hex");
|
|
48577
|
-
const authorizeUrl = slackOAuthAuthorizeUrl(clientId, state);
|
|
48578
|
-
const timeoutMs = opts?.timeoutMs ?? 5 * 6e4;
|
|
48579
|
-
const pollIntervalMs = opts?.pollIntervalMs ?? 400;
|
|
48580
|
-
const fetchImpl = opts?.fetchImpl ?? fetch;
|
|
48581
|
-
const resultUrl = opts?.resultUrlForState?.(state) ?? slackOAuthResultUrl(state);
|
|
48582
|
-
await Promise.resolve(opts?.openUrl?.(authorizeUrl));
|
|
48583
|
-
if (opts?.signal?.aborted) {
|
|
48584
|
-
throw new SlackOAuthCancelledError();
|
|
48585
|
-
}
|
|
48586
|
-
const deadline = Date.now() + timeoutMs;
|
|
48587
|
-
while (Date.now() < deadline) {
|
|
48588
|
-
if (opts?.signal?.aborted) {
|
|
48589
|
-
throw new SlackOAuthCancelledError();
|
|
48590
|
-
}
|
|
48591
|
-
let res;
|
|
48592
|
-
try {
|
|
48593
|
-
res = await fetchImpl(resultUrl);
|
|
48594
|
-
} catch {
|
|
48595
|
-
if (opts?.signal?.aborted) throw new SlackOAuthCancelledError();
|
|
48596
|
-
await sleep(pollIntervalMs, opts?.signal);
|
|
48597
|
-
continue;
|
|
48598
|
-
}
|
|
48599
|
-
let data;
|
|
48600
|
-
try {
|
|
48601
|
-
data = await res.json();
|
|
48602
|
-
} catch {
|
|
48603
|
-
await sleep(pollIntervalMs, opts?.signal);
|
|
48604
|
-
continue;
|
|
48605
|
-
}
|
|
48606
|
-
if (data.ok && data.team_id?.trim()) {
|
|
48607
|
-
return upsertFromPayload({
|
|
48608
|
-
team_id: data.team_id.trim(),
|
|
48609
|
-
team_name: data.team_name?.trim() || data.team_id.trim(),
|
|
48610
|
-
user_id: data.user_id?.trim() || void 0,
|
|
48611
|
-
bot_token: data.bot_token?.trim() || void 0,
|
|
48612
|
-
user_token: data.user_token?.trim() || void 0,
|
|
48613
|
-
scopes: data.scopes?.trim() || ""
|
|
48614
|
-
});
|
|
48615
|
-
}
|
|
48616
|
-
const err = data.error?.trim();
|
|
48617
|
-
if (err && err !== "pending") {
|
|
48618
|
-
if (/cancel/i.test(err) || /access_denied/i.test(err)) {
|
|
48619
|
-
throw new SlackOAuthCancelledError(`Slack OAuth: ${err}`);
|
|
48620
|
-
}
|
|
48621
|
-
throw new Error(err.startsWith("Slack") ? err : `Slack OAuth: ${err}`);
|
|
49507
|
+
async function saveSlackOrgCredentials(opts) {
|
|
49508
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
49509
|
+
const res = await fetchImpl(
|
|
49510
|
+
`${originOf(opts.relayWsUrl)}/slack/apps/${encodeURIComponent(opts.registrationId)}/credentials`,
|
|
49511
|
+
{
|
|
49512
|
+
method: "POST",
|
|
49513
|
+
headers: { "Content-Type": "application/json" },
|
|
49514
|
+
body: JSON.stringify({
|
|
49515
|
+
writeToken: opts.writeToken,
|
|
49516
|
+
clientId: opts.clientId,
|
|
49517
|
+
clientSecret: opts.clientSecret,
|
|
49518
|
+
signingSecret: opts.signingSecret
|
|
49519
|
+
})
|
|
48622
49520
|
}
|
|
48623
|
-
|
|
48624
|
-
|
|
48625
|
-
throw new Error("Slack sign-in timed out \u2014 try again");
|
|
49521
|
+
);
|
|
49522
|
+
if (!res.ok) throw new Error(await readError(res));
|
|
48626
49523
|
}
|
|
48627
49524
|
|
|
49525
|
+
// src/index.ts
|
|
49526
|
+
init_client_ids();
|
|
49527
|
+
|
|
48628
49528
|
// src/slack/listen.ts
|
|
48629
49529
|
init_orchestrator_capable();
|
|
48630
49530
|
init_orchestrator();
|
|
@@ -48635,19 +49535,19 @@ init_turn_live();
|
|
|
48635
49535
|
init_thread_store();
|
|
48636
49536
|
|
|
48637
49537
|
// src/slack/reply-target.ts
|
|
48638
|
-
var
|
|
48639
|
-
var
|
|
49538
|
+
var import_node_fs79 = require("fs");
|
|
49539
|
+
var import_node_path81 = require("path");
|
|
48640
49540
|
init_paths();
|
|
48641
49541
|
init_private_file();
|
|
48642
49542
|
init_secure_file();
|
|
48643
49543
|
function storePath3() {
|
|
48644
|
-
return (0,
|
|
49544
|
+
return (0, import_node_path81.join)(appDataDir(), "slack-reply-to.json");
|
|
48645
49545
|
}
|
|
48646
49546
|
function readStore3() {
|
|
48647
49547
|
const path2 = storePath3();
|
|
48648
|
-
if (!(0,
|
|
49548
|
+
if (!(0, import_node_fs79.existsSync)(path2)) return {};
|
|
48649
49549
|
try {
|
|
48650
|
-
const parsed = isSecureFileEncrypted(path2) ? readSecureJson(path2) : JSON.parse((0,
|
|
49550
|
+
const parsed = isSecureFileEncrypted(path2) ? readSecureJson(path2) : JSON.parse((0, import_node_fs79.readFileSync)(path2, "utf8"));
|
|
48651
49551
|
return parsed?.targets && typeof parsed.targets === "object" ? parsed.targets : {};
|
|
48652
49552
|
} catch {
|
|
48653
49553
|
return {};
|
|
@@ -48703,9 +49603,11 @@ async function runSlackRelayClient(opts) {
|
|
|
48703
49603
|
const deviceId = opts.deviceId.trim();
|
|
48704
49604
|
if (!url) throw new Error("Relay URL is empty");
|
|
48705
49605
|
if (!deviceId) throw new Error("Relay needs a deviceId for this Mac");
|
|
48706
|
-
if (opts.workspaces.length === 0
|
|
49606
|
+
if (opts.workspaces.length === 0 || opts.workspaces.some(
|
|
49607
|
+
(ws) => !ws.botToken.trim() || !ws.userId.trim() || !ws.userToken?.trim() && !ws.listenGrant?.trim()
|
|
49608
|
+
)) {
|
|
48707
49609
|
throw new Error(
|
|
48708
|
-
"Relay needs
|
|
49610
|
+
"Relay needs Add via browser so this Mac can prove which Slack user it is."
|
|
48709
49611
|
);
|
|
48710
49612
|
}
|
|
48711
49613
|
let backoff = BACKOFF_START_MS3;
|
|
@@ -48811,7 +49713,8 @@ function connectSession2(ws, opts, log) {
|
|
|
48811
49713
|
deviceId: opts.deviceId.trim(),
|
|
48812
49714
|
deviceLabel: opts.deviceLabel?.trim() || void 0,
|
|
48813
49715
|
botToken: wsInfo.botToken,
|
|
48814
|
-
userToken: wsInfo.userToken
|
|
49716
|
+
...wsInfo.userToken?.trim() ? { userToken: wsInfo.userToken.trim() } : {},
|
|
49717
|
+
...wsInfo.listenGrant?.trim() ? { listenGrant: wsInfo.listenGrant.trim() } : {}
|
|
48815
49718
|
});
|
|
48816
49719
|
}
|
|
48817
49720
|
pingOnce();
|
|
@@ -49181,8 +50084,8 @@ function startSlackTurnProgress(msg, threadId, opts) {
|
|
|
49181
50084
|
finishWith: (text7) => {
|
|
49182
50085
|
stop();
|
|
49183
50086
|
return run2(async () => {
|
|
49184
|
-
const
|
|
49185
|
-
if (!
|
|
50087
|
+
const signed2 = signForThisMac(text7.trim());
|
|
50088
|
+
if (!signed2) {
|
|
49186
50089
|
if (!postedTs) return;
|
|
49187
50090
|
const ts = postedTs;
|
|
49188
50091
|
postedTs = null;
|
|
@@ -49196,14 +50099,14 @@ function startSlackTurnProgress(msg, threadId, opts) {
|
|
|
49196
50099
|
}
|
|
49197
50100
|
if (postedTs) {
|
|
49198
50101
|
try {
|
|
49199
|
-
await updateSlackText(target, postedTs,
|
|
50102
|
+
await updateSlackText(target, postedTs, signed2, opts);
|
|
49200
50103
|
return;
|
|
49201
50104
|
} catch (err) {
|
|
49202
50105
|
const errMsg = err instanceof Error ? err.message : String(err);
|
|
49203
50106
|
log(`progress update error: ${errMsg}`);
|
|
49204
50107
|
}
|
|
49205
50108
|
}
|
|
49206
|
-
await postSlackText(target,
|
|
50109
|
+
await postSlackText(target, signed2, opts);
|
|
49207
50110
|
});
|
|
49208
50111
|
}
|
|
49209
50112
|
};
|
|
@@ -49436,12 +50339,10 @@ async function runSlackListen(opts = {}) {
|
|
|
49436
50339
|
if (!relay) {
|
|
49437
50340
|
throw new Error("Slack Listen needs the hosted relay URL.");
|
|
49438
50341
|
}
|
|
49439
|
-
const withIdentity = connected.filter(
|
|
49440
|
-
(w) => w.bot_token?.trim() && w.user_token?.trim() && w.user_id?.trim()
|
|
49441
|
-
);
|
|
50342
|
+
const withIdentity = connected.filter(slackWorkspaceCanListen);
|
|
49442
50343
|
if (withIdentity.length === 0) {
|
|
49443
50344
|
throw new Error(
|
|
49444
|
-
"Slack Listen needs Add via browser
|
|
50345
|
+
"Slack Listen needs Add via browser so this Mac can prove which Slack user it is. A pasted bot token cannot."
|
|
49445
50346
|
);
|
|
49446
50347
|
}
|
|
49447
50348
|
const device = ensureSlackDeviceIdentity();
|
|
@@ -49453,12 +50354,17 @@ async function runSlackListen(opts = {}) {
|
|
|
49453
50354
|
WebSocketImpl: opts.WebSocketImpl,
|
|
49454
50355
|
deviceId: device.deviceId,
|
|
49455
50356
|
deviceLabel: device.deviceLabel,
|
|
49456
|
-
workspaces: withIdentity.map((w) =>
|
|
49457
|
-
|
|
49458
|
-
|
|
49459
|
-
|
|
49460
|
-
|
|
49461
|
-
|
|
50357
|
+
workspaces: withIdentity.map((w) => {
|
|
50358
|
+
const userToken = w.user_token?.trim();
|
|
50359
|
+
const listenGrant = w.listen_grant?.trim();
|
|
50360
|
+
return {
|
|
50361
|
+
teamId: w.team_id,
|
|
50362
|
+
userId: w.user_id.trim(),
|
|
50363
|
+
botToken: w.bot_token.trim(),
|
|
50364
|
+
...userToken ? { userToken } : {},
|
|
50365
|
+
...listenGrant ? { listenGrant } : {}
|
|
50366
|
+
};
|
|
50367
|
+
}),
|
|
49462
50368
|
onEvent: onInbound,
|
|
49463
50369
|
onUninstalled: (teamId) => {
|
|
49464
50370
|
disconnectSlackWorkspace(teamId);
|
|
@@ -49471,9 +50377,7 @@ async function runSlackListen(opts = {}) {
|
|
|
49471
50377
|
}
|
|
49472
50378
|
function resolveSlackListenMode(opts) {
|
|
49473
50379
|
const relay = (opts?.relayUrl ?? slackRelayUrl()).trim();
|
|
49474
|
-
const count =
|
|
49475
|
-
(w) => w.bot_token?.trim() && w.user_token?.trim() && w.user_id?.trim()
|
|
49476
|
-
).length;
|
|
50380
|
+
const count = listSlackWorkspacesRaw().filter(slackWorkspaceCanListen).length;
|
|
49477
50381
|
if (relay && count > 0) return "relay";
|
|
49478
50382
|
return null;
|
|
49479
50383
|
}
|
|
@@ -49482,7 +50386,7 @@ function resolveSlackListenMode(opts) {
|
|
|
49482
50386
|
init_protocol();
|
|
49483
50387
|
|
|
49484
50388
|
// src/relay/account-login.ts
|
|
49485
|
-
var
|
|
50389
|
+
var import_node_crypto39 = require("crypto");
|
|
49486
50390
|
init_fetch();
|
|
49487
50391
|
init_protocol();
|
|
49488
50392
|
var RemoteAccountLoginCancelled = class extends Error {
|
|
@@ -49537,7 +50441,7 @@ async function relayFetch(fetchImpl, url, init) {
|
|
|
49537
50441
|
throw relayFetchError(err, url);
|
|
49538
50442
|
}
|
|
49539
50443
|
}
|
|
49540
|
-
async function
|
|
50444
|
+
async function readJson6(res, url) {
|
|
49541
50445
|
try {
|
|
49542
50446
|
return await res.json();
|
|
49543
50447
|
} catch {
|
|
@@ -49550,7 +50454,7 @@ async function readJson5(res, url) {
|
|
|
49550
50454
|
async function startRemoteAccountLogin(opts) {
|
|
49551
50455
|
if (opts.signal?.aborted) throw new RemoteAccountLoginCancelled();
|
|
49552
50456
|
const origin = (opts.origin ?? remoteAccountHttpOrigin()).replace(/\/+$/, "");
|
|
49553
|
-
const state = (0,
|
|
50457
|
+
const state = (0, import_node_crypto39.randomBytes)(16).toString("hex");
|
|
49554
50458
|
const timeoutMs = opts.timeoutMs ?? 5 * 6e4;
|
|
49555
50459
|
const pollIntervalMs = opts.pollIntervalMs ?? 400;
|
|
49556
50460
|
const linkToken = opts.linkToken?.trim() ?? "";
|
|
@@ -49564,7 +50468,7 @@ async function startRemoteAccountLogin(opts) {
|
|
|
49564
50468
|
...linkToken ? { accountToken: linkToken } : {}
|
|
49565
50469
|
})
|
|
49566
50470
|
});
|
|
49567
|
-
const startBody = await
|
|
50471
|
+
const startBody = await readJson6(started, startUrl);
|
|
49568
50472
|
if (!started.ok || !startBody.url) {
|
|
49569
50473
|
throw new Error(startBody.error || `Could not start sign-in (HTTP ${started.status}).`);
|
|
49570
50474
|
}
|
|
@@ -49612,8 +50516,8 @@ async function disconnectRemoteAccount(opts) {
|
|
|
49612
50516
|
}
|
|
49613
50517
|
|
|
49614
50518
|
// src/slack/outbound-watch.ts
|
|
49615
|
-
var
|
|
49616
|
-
var
|
|
50519
|
+
var import_node_fs80 = require("fs");
|
|
50520
|
+
var import_node_path82 = require("path");
|
|
49617
50521
|
init_paths();
|
|
49618
50522
|
init_private_file();
|
|
49619
50523
|
init_secure_file();
|
|
@@ -49626,7 +50530,7 @@ var POLL_INTERVAL_MS = 12e3;
|
|
|
49626
50530
|
var lastPollMs = 0;
|
|
49627
50531
|
var nameCache = /* @__PURE__ */ new Map();
|
|
49628
50532
|
function storePath4() {
|
|
49629
|
-
return (0,
|
|
50533
|
+
return (0, import_node_path82.join)(appDataDir(), "slack-outbound-watch.json");
|
|
49630
50534
|
}
|
|
49631
50535
|
function watchId(teamId, channelId, ts) {
|
|
49632
50536
|
return `${teamId}:${channelId}:${ts}`;
|
|
@@ -49639,9 +50543,9 @@ function tsNewer(a, b) {
|
|
|
49639
50543
|
}
|
|
49640
50544
|
function readStore4() {
|
|
49641
50545
|
const path2 = storePath4();
|
|
49642
|
-
if (!(0,
|
|
50546
|
+
if (!(0, import_node_fs80.existsSync)(path2)) return [];
|
|
49643
50547
|
try {
|
|
49644
|
-
const parsed = isSecureFileEncrypted(path2) ? readSecureJson(path2) : JSON.parse((0,
|
|
50548
|
+
const parsed = isSecureFileEncrypted(path2) ? readSecureJson(path2) : JSON.parse((0, import_node_fs80.readFileSync)(path2, "utf8"));
|
|
49645
50549
|
return Array.isArray(parsed?.watches) ? parsed.watches : [];
|
|
49646
50550
|
} catch {
|
|
49647
50551
|
return [];
|
|
@@ -49976,6 +50880,7 @@ async function pollSlackOutboundWatches(opts) {
|
|
|
49976
50880
|
AbleTimeOAuthCancelledError,
|
|
49977
50881
|
BAKED_ABLETIME_OAUTH_CLIENT_ID,
|
|
49978
50882
|
BAKED_REMOTE_RELAY_URL,
|
|
50883
|
+
BAKED_SLACK_CLIENT_ID,
|
|
49979
50884
|
BAKED_SLACK_RELAY_URL,
|
|
49980
50885
|
BASE_ALLOWED_TOOLS,
|
|
49981
50886
|
BRIGHTSY_MCP_ALLOWED_TOOLS,
|
|
@@ -50280,6 +51185,7 @@ async function pollSlackOutboundWatches(opts) {
|
|
|
50280
51185
|
createOrUpdatePr,
|
|
50281
51186
|
createPrStack,
|
|
50282
51187
|
createSchedule,
|
|
51188
|
+
createSlackOrgApp,
|
|
50283
51189
|
createThread,
|
|
50284
51190
|
createThreadWorktree,
|
|
50285
51191
|
currentBranch,
|
|
@@ -50703,6 +51609,7 @@ async function pollSlackOutboundWatches(opts) {
|
|
|
50703
51609
|
mergePrStack,
|
|
50704
51610
|
mergeSetupOutput,
|
|
50705
51611
|
mergeSideboardIntoMcpServersJson,
|
|
51612
|
+
mergeSlackClientIds,
|
|
50706
51613
|
mergeUsage,
|
|
50707
51614
|
messagePartParentId,
|
|
50708
51615
|
messagesForCompactArchive,
|
|
@@ -50910,6 +51817,7 @@ async function pollSlackOutboundWatches(opts) {
|
|
|
50910
51817
|
saveAppSettings,
|
|
50911
51818
|
saveLinearOAuth,
|
|
50912
51819
|
saveRemotePhoneToken,
|
|
51820
|
+
saveSlackOrgCredentials,
|
|
50913
51821
|
saveWorktreeRunPorts,
|
|
50914
51822
|
scheduleNeedsCaffeinate,
|
|
50915
51823
|
schedulesPath,
|