@inkeep/agents-work-apps 0.0.0-dev-20260204182014 → 0.0.0-dev-20260204210021
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/db/index.d.ts +1 -2
- package/dist/db/index.js +1 -2
- package/dist/db/runDbClient.d.ts +2 -2
- package/dist/env.d.ts +2 -24
- package/dist/env.js +1 -12
- package/dist/github/routes/setup.d.ts +2 -2
- package/dist/github/routes/tokenExchange.d.ts +2 -2
- package/package.json +2 -10
- package/dist/db/manageDbClient.d.ts +0 -7
- package/dist/db/manageDbClient.js +0 -16
- package/dist/slack/index.d.ts +0 -19
- package/dist/slack/index.js +0 -29
- package/dist/slack/middleware/permissions.d.ts +0 -16
- package/dist/slack/middleware/permissions.js +0 -49
- package/dist/slack/routes/events.d.ts +0 -10
- package/dist/slack/routes/events.js +0 -319
- package/dist/slack/routes/index.d.ts +0 -11
- package/dist/slack/routes/index.js +0 -64
- package/dist/slack/routes/internal.d.ts +0 -10
- package/dist/slack/routes/internal.js +0 -107
- package/dist/slack/routes/oauth.d.ts +0 -12
- package/dist/slack/routes/oauth.js +0 -218
- package/dist/slack/routes/resources.d.ts +0 -10
- package/dist/slack/routes/resources.js +0 -163
- package/dist/slack/routes/users.d.ts +0 -15
- package/dist/slack/routes/users.js +0 -430
- package/dist/slack/routes/workspaces.d.ts +0 -10
- package/dist/slack/routes/workspaces.js +0 -828
- package/dist/slack/routes.d.ts +0 -7
- package/dist/slack/routes.js +0 -12
- package/dist/slack/services/agent-resolution.d.ts +0 -49
- package/dist/slack/services/agent-resolution.js +0 -135
- package/dist/slack/services/api-client.d.ts +0 -161
- package/dist/slack/services/api-client.js +0 -248
- package/dist/slack/services/auth/index.d.ts +0 -61
- package/dist/slack/services/auth/index.js +0 -164
- package/dist/slack/services/blocks/index.d.ts +0 -60
- package/dist/slack/services/blocks/index.js +0 -143
- package/dist/slack/services/client.d.ts +0 -78
- package/dist/slack/services/client.js +0 -152
- package/dist/slack/services/commands/index.d.ts +0 -15
- package/dist/slack/services/commands/index.js +0 -556
- package/dist/slack/services/events/app-mention.d.ts +0 -41
- package/dist/slack/services/events/app-mention.js +0 -212
- package/dist/slack/services/events/block-actions.d.ts +0 -47
- package/dist/slack/services/events/block-actions.js +0 -287
- package/dist/slack/services/events/index.d.ts +0 -6
- package/dist/slack/services/events/index.js +0 -7
- package/dist/slack/services/events/modal-submission.d.ts +0 -12
- package/dist/slack/services/events/modal-submission.js +0 -279
- package/dist/slack/services/events/streaming.d.ts +0 -27
- package/dist/slack/services/events/streaming.js +0 -285
- package/dist/slack/services/events/utils.d.ts +0 -129
- package/dist/slack/services/events/utils.js +0 -315
- package/dist/slack/services/index.d.ts +0 -18
- package/dist/slack/services/index.js +0 -18
- package/dist/slack/services/modals.d.ts +0 -67
- package/dist/slack/services/modals.js +0 -203
- package/dist/slack/services/nango.d.ts +0 -82
- package/dist/slack/services/nango.js +0 -326
- package/dist/slack/services/security.d.ts +0 -35
- package/dist/slack/services/security.js +0 -65
- package/dist/slack/services/types.d.ts +0 -26
- package/dist/slack/services/types.js +0 -1
- package/dist/slack/services/workspace-tokens.d.ts +0 -37
- package/dist/slack/services/workspace-tokens.js +0 -39
- package/dist/slack/types.d.ts +0 -10
- package/dist/slack/types.js +0 -1
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import oauth_default from "./oauth.js";
|
|
2
|
-
import users_default, { pendingSessionTokens } from "./users.js";
|
|
3
|
-
import events_default from "./events.js";
|
|
4
|
-
import internal_default from "./internal.js";
|
|
5
|
-
import resources_default from "./resources.js";
|
|
6
|
-
import workspaces_default from "./workspaces.js";
|
|
7
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
8
|
-
|
|
9
|
-
//#region src/slack/routes/index.ts
|
|
10
|
-
/**
|
|
11
|
-
* Slack Work App Routes - Main Router
|
|
12
|
-
*
|
|
13
|
-
* Modular RESTful API structure:
|
|
14
|
-
*
|
|
15
|
-
* OAuth & Installation (oauth.ts):
|
|
16
|
-
* GET /install - Redirect to Slack OAuth
|
|
17
|
-
* GET /oauth_redirect - OAuth callback
|
|
18
|
-
*
|
|
19
|
-
* Workspaces (workspaces.ts):
|
|
20
|
-
* GET /workspaces - List all workspaces
|
|
21
|
-
* GET /workspaces/:teamId - Get workspace details
|
|
22
|
-
* GET /workspaces/:teamId/settings - Get workspace settings
|
|
23
|
-
* PUT /workspaces/:teamId/settings - Update workspace settings [ADMIN]
|
|
24
|
-
* DELETE /workspaces/:teamId - Uninstall workspace [ADMIN]
|
|
25
|
-
* GET /workspaces/:teamId/channels - List channels
|
|
26
|
-
* GET/PUT/DELETE /workspaces/:teamId/channels/:channelId/settings - Channel config
|
|
27
|
-
* GET /workspaces/:teamId/users - List linked users
|
|
28
|
-
*
|
|
29
|
-
* Users (users.ts):
|
|
30
|
-
* GET /users/me/settings - Get user's personal settings
|
|
31
|
-
* PUT /users/me/settings - Update user's personal settings
|
|
32
|
-
* GET /users/link-status - Check link status
|
|
33
|
-
* POST /users/link/verify-token - Verify JWT link token (primary linking method)
|
|
34
|
-
* POST /users/connect - Create Nango session
|
|
35
|
-
* POST /users/disconnect - Disconnect/unlink user
|
|
36
|
-
* GET /users/status - Get user connection status
|
|
37
|
-
* POST /users/refresh-session - Refresh session token
|
|
38
|
-
*
|
|
39
|
-
* Resources (resources.ts):
|
|
40
|
-
* GET /projects - List projects
|
|
41
|
-
* GET /projects/:projectId/agents - List agents in project
|
|
42
|
-
* GET /agents - List all agents
|
|
43
|
-
*
|
|
44
|
-
* Events & Commands (events.ts):
|
|
45
|
-
* POST /commands - Handle slash commands
|
|
46
|
-
* POST /events - Handle Slack events
|
|
47
|
-
* POST /nango-webhook - Handle Nango webhooks
|
|
48
|
-
*
|
|
49
|
-
* Internal/Debug (internal.ts):
|
|
50
|
-
* POST /register-workspace - Register workspace (memory cache)
|
|
51
|
-
* GET /workspace-info - Get workspace info
|
|
52
|
-
* POST /debug/generate-token - Generate test tokens (dev only)
|
|
53
|
-
*/
|
|
54
|
-
const app = new OpenAPIHono();
|
|
55
|
-
app.route("/workspaces", workspaces_default);
|
|
56
|
-
app.route("/users", users_default);
|
|
57
|
-
app.route("/", oauth_default);
|
|
58
|
-
app.route("/", events_default);
|
|
59
|
-
app.route("/", internal_default);
|
|
60
|
-
app.route("/", resources_default);
|
|
61
|
-
var routes_default = app;
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
export { routes_default as default, pendingSessionTokens };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { WorkAppsVariables } from "../types.js";
|
|
2
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
3
|
-
|
|
4
|
-
//#region src/slack/routes/internal.d.ts
|
|
5
|
-
|
|
6
|
-
declare const app: OpenAPIHono<{
|
|
7
|
-
Variables: WorkAppsVariables;
|
|
8
|
-
}, {}, "/">;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { app as default };
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { env } from "../../env.js";
|
|
2
|
-
import { getLogger } from "../../logger.js";
|
|
3
|
-
import { getConnectionAccessToken } from "../services/nango.js";
|
|
4
|
-
import { getSlackChannels, getSlackClient, getSlackTeamInfo } from "../services/client.js";
|
|
5
|
-
import { setBotTokenForTeam } from "../services/workspace-tokens.js";
|
|
6
|
-
import "../services/index.js";
|
|
7
|
-
import "./oauth.js";
|
|
8
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
9
|
-
|
|
10
|
-
//#region src/slack/routes/internal.ts
|
|
11
|
-
/**
|
|
12
|
-
* Slack Internal/Debug Routes
|
|
13
|
-
*
|
|
14
|
-
* Endpoints for internal operations and debugging:
|
|
15
|
-
* - POST /register-workspace - Register workspace bot token (memory cache)
|
|
16
|
-
* - POST /debug/generate-token - Generate test tokens (dev only)
|
|
17
|
-
* - GET /workspace-info - Get workspace info from Nango
|
|
18
|
-
*/
|
|
19
|
-
const logger = getLogger("slack-internal");
|
|
20
|
-
const app = new OpenAPIHono();
|
|
21
|
-
app.post("/register-workspace", async (c) => {
|
|
22
|
-
const { teamId, teamName, botToken } = await c.req.json();
|
|
23
|
-
if (!teamId) return c.json({ error: "teamId is required" }, 400);
|
|
24
|
-
if (!botToken) return c.json({ error: "botToken is required" }, 400);
|
|
25
|
-
setBotTokenForTeam(teamId, {
|
|
26
|
-
botToken,
|
|
27
|
-
teamName: teamName || "",
|
|
28
|
-
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
29
|
-
});
|
|
30
|
-
logger.info({
|
|
31
|
-
teamId,
|
|
32
|
-
teamName
|
|
33
|
-
}, "Registered workspace bot token");
|
|
34
|
-
return c.json({
|
|
35
|
-
success: true,
|
|
36
|
-
teamId
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
app.get("/workspace-info", async (c) => {
|
|
40
|
-
const connectionId = c.req.query("connectionId");
|
|
41
|
-
if (!connectionId) return c.json({ error: "connectionId is required" }, 400);
|
|
42
|
-
try {
|
|
43
|
-
const accessToken = await getConnectionAccessToken(connectionId);
|
|
44
|
-
if (!accessToken) return c.json({ error: "No access token found" }, 404);
|
|
45
|
-
const client = getSlackClient(accessToken);
|
|
46
|
-
const [team, channels] = await Promise.all([getSlackTeamInfo(client), getSlackChannels(client, 20)]);
|
|
47
|
-
logger.debug({
|
|
48
|
-
hasTeam: !!team,
|
|
49
|
-
channelCount: channels.length
|
|
50
|
-
}, "Retrieved Slack workspace info");
|
|
51
|
-
return c.json({
|
|
52
|
-
team,
|
|
53
|
-
channels
|
|
54
|
-
});
|
|
55
|
-
} catch (error) {
|
|
56
|
-
logger.error({
|
|
57
|
-
error,
|
|
58
|
-
connectionId
|
|
59
|
-
}, "Failed to fetch Slack workspace info");
|
|
60
|
-
return c.json({ error: "Failed to fetch workspace info" }, 500);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
app.post("/debug/generate-token", async (c) => {
|
|
64
|
-
if (env.ENVIRONMENT === "production") return c.json({ error: "This endpoint is not available in production" }, 403);
|
|
65
|
-
const { userId, tenantId, slackUserId, slackTeamId, slackEnterpriseId } = await c.req.json();
|
|
66
|
-
if (!userId) return c.json({ error: "userId is required" }, 400);
|
|
67
|
-
if (!slackUserId) return c.json({ error: "slackUserId is required" }, 400);
|
|
68
|
-
if (!slackTeamId) return c.json({ error: "slackTeamId is required" }, 400);
|
|
69
|
-
try {
|
|
70
|
-
const { signSlackUserToken } = await import("@inkeep/agents-core");
|
|
71
|
-
const token = await signSlackUserToken({
|
|
72
|
-
inkeepUserId: userId,
|
|
73
|
-
tenantId: tenantId || "default",
|
|
74
|
-
slackTeamId,
|
|
75
|
-
slackUserId,
|
|
76
|
-
slackEnterpriseId
|
|
77
|
-
});
|
|
78
|
-
logger.info({
|
|
79
|
-
userId,
|
|
80
|
-
tenantId: tenantId || "default",
|
|
81
|
-
slackTeamId,
|
|
82
|
-
slackUserId
|
|
83
|
-
}, "Generated Slack user token for debugging");
|
|
84
|
-
return c.json({
|
|
85
|
-
token,
|
|
86
|
-
expiresIn: "5m",
|
|
87
|
-
tokenType: "slackUser",
|
|
88
|
-
payload: {
|
|
89
|
-
sub: userId,
|
|
90
|
-
tenantId: tenantId || "default",
|
|
91
|
-
slack: {
|
|
92
|
-
teamId: slackTeamId,
|
|
93
|
-
userId: slackUserId,
|
|
94
|
-
enterpriseId: slackEnterpriseId
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
} catch (error) {
|
|
99
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
100
|
-
logger.error({ error: errorMessage }, "Failed to generate Slack user token");
|
|
101
|
-
return c.json({ error: `Failed to generate token: ${errorMessage}` }, 500);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
var internal_default = app;
|
|
105
|
-
|
|
106
|
-
//#endregion
|
|
107
|
-
export { internal_default as default };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { WorkAppsVariables } from "../types.js";
|
|
2
|
-
import { getBotTokenForTeam, setBotTokenForTeam } from "../services/workspace-tokens.js";
|
|
3
|
-
import "../services/index.js";
|
|
4
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
5
|
-
|
|
6
|
-
//#region src/slack/routes/oauth.d.ts
|
|
7
|
-
|
|
8
|
-
declare const app: OpenAPIHono<{
|
|
9
|
-
Variables: WorkAppsVariables;
|
|
10
|
-
}, {}, "/">;
|
|
11
|
-
//#endregion
|
|
12
|
-
export { app as default, getBotTokenForTeam, setBotTokenForTeam };
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { env } from "../../env.js";
|
|
2
|
-
import { getLogger } from "../../logger.js";
|
|
3
|
-
import runDbClient_default from "../../db/runDbClient.js";
|
|
4
|
-
import { computeWorkspaceConnectionId, storeWorkspaceInstallation } from "../services/nango.js";
|
|
5
|
-
import { getSlackClient, getSlackTeamInfo, getSlackUserInfo } from "../services/client.js";
|
|
6
|
-
import { getBotTokenForTeam, setBotTokenForTeam } from "../services/workspace-tokens.js";
|
|
7
|
-
import "../services/index.js";
|
|
8
|
-
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
9
|
-
import { createWorkAppSlackWorkspace } from "@inkeep/agents-core";
|
|
10
|
-
|
|
11
|
-
//#region src/slack/routes/oauth.ts
|
|
12
|
-
/**
|
|
13
|
-
* Slack OAuth Routes
|
|
14
|
-
*
|
|
15
|
-
* Endpoints for Slack workspace installation via OAuth:
|
|
16
|
-
* - GET /install - Redirect to Slack OAuth page
|
|
17
|
-
* - GET /oauth_redirect - Handle OAuth callback
|
|
18
|
-
*/
|
|
19
|
-
const logger = getLogger("slack-oauth");
|
|
20
|
-
const app = new OpenAPIHono();
|
|
21
|
-
app.openapi(createRoute({
|
|
22
|
-
method: "get",
|
|
23
|
-
path: "/install",
|
|
24
|
-
summary: "Install Slack App",
|
|
25
|
-
description: "Redirects to Slack OAuth page for workspace installation",
|
|
26
|
-
operationId: "slack-install",
|
|
27
|
-
tags: [
|
|
28
|
-
"Work Apps",
|
|
29
|
-
"Slack",
|
|
30
|
-
"OAuth"
|
|
31
|
-
],
|
|
32
|
-
responses: { 302: { description: "Redirect to Slack OAuth" } }
|
|
33
|
-
}), (c) => {
|
|
34
|
-
const clientId = env.SLACK_CLIENT_ID;
|
|
35
|
-
const redirectUri = `${env.SLACK_APP_URL}/work-apps/slack/oauth_redirect`;
|
|
36
|
-
const botScopes = [
|
|
37
|
-
"app_mentions:read",
|
|
38
|
-
"channels:history",
|
|
39
|
-
"channels:read",
|
|
40
|
-
"chat:write",
|
|
41
|
-
"chat:write.public",
|
|
42
|
-
"commands",
|
|
43
|
-
"groups:history",
|
|
44
|
-
"groups:read",
|
|
45
|
-
"im:history",
|
|
46
|
-
"im:read",
|
|
47
|
-
"im:write",
|
|
48
|
-
"team:read",
|
|
49
|
-
"users:read",
|
|
50
|
-
"users:read.email"
|
|
51
|
-
].join(",");
|
|
52
|
-
const slackAuthUrl = new URL("https://slack.com/oauth/v2/authorize");
|
|
53
|
-
slackAuthUrl.searchParams.set("client_id", clientId || "");
|
|
54
|
-
slackAuthUrl.searchParams.set("scope", botScopes);
|
|
55
|
-
slackAuthUrl.searchParams.set("redirect_uri", redirectUri);
|
|
56
|
-
logger.info({ redirectUri }, "Redirecting to Slack OAuth");
|
|
57
|
-
return c.redirect(slackAuthUrl.toString());
|
|
58
|
-
});
|
|
59
|
-
app.openapi(createRoute({
|
|
60
|
-
method: "get",
|
|
61
|
-
path: "/oauth_redirect",
|
|
62
|
-
summary: "Slack OAuth Callback",
|
|
63
|
-
description: "Handles the OAuth callback from Slack after workspace installation",
|
|
64
|
-
operationId: "slack-oauth-redirect",
|
|
65
|
-
tags: [
|
|
66
|
-
"Work Apps",
|
|
67
|
-
"Slack",
|
|
68
|
-
"OAuth"
|
|
69
|
-
],
|
|
70
|
-
request: { query: z.object({
|
|
71
|
-
code: z.string().optional(),
|
|
72
|
-
error: z.string().optional()
|
|
73
|
-
}) },
|
|
74
|
-
responses: { 302: { description: "Redirect to dashboard with workspace data" } }
|
|
75
|
-
}), async (c) => {
|
|
76
|
-
const { code, error } = c.req.valid("query");
|
|
77
|
-
const dashboardUrl = `${env.INKEEP_AGENTS_MANAGE_UI_URL || "http://localhost:3000"}/default/work-apps/slack`;
|
|
78
|
-
if (error) {
|
|
79
|
-
logger.error({ error }, "Slack OAuth error");
|
|
80
|
-
return c.redirect(`${dashboardUrl}?error=${encodeURIComponent(error)}`);
|
|
81
|
-
}
|
|
82
|
-
if (!code) {
|
|
83
|
-
logger.error({}, "No code provided in OAuth callback");
|
|
84
|
-
return c.redirect(`${dashboardUrl}?error=no_code`);
|
|
85
|
-
}
|
|
86
|
-
try {
|
|
87
|
-
const tokenData = await (await fetch("https://slack.com/api/oauth.v2.access", {
|
|
88
|
-
method: "POST",
|
|
89
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
90
|
-
body: new URLSearchParams({
|
|
91
|
-
client_id: env.SLACK_CLIENT_ID || "",
|
|
92
|
-
client_secret: env.SLACK_CLIENT_SECRET || "",
|
|
93
|
-
code,
|
|
94
|
-
redirect_uri: `${env.SLACK_APP_URL}/work-apps/slack/oauth_redirect`
|
|
95
|
-
})
|
|
96
|
-
})).json();
|
|
97
|
-
if (!tokenData.ok) {
|
|
98
|
-
logger.error({ error: tokenData.error }, "Slack token exchange failed");
|
|
99
|
-
return c.redirect(`${dashboardUrl}?error=${encodeURIComponent(tokenData.error || "token_exchange_failed")}`);
|
|
100
|
-
}
|
|
101
|
-
const client = getSlackClient(tokenData.access_token);
|
|
102
|
-
const teamInfo = await getSlackTeamInfo(client);
|
|
103
|
-
logger.debug({ teamInfo }, "Retrieved Slack team info");
|
|
104
|
-
const installerUserId = tokenData.authed_user?.id;
|
|
105
|
-
let installerUserName;
|
|
106
|
-
if (installerUserId) try {
|
|
107
|
-
const userInfo = await getSlackUserInfo(client, installerUserId);
|
|
108
|
-
installerUserName = userInfo?.realName || userInfo?.name;
|
|
109
|
-
} catch {
|
|
110
|
-
logger.warn({ installerUserId }, "Could not fetch installer user info");
|
|
111
|
-
}
|
|
112
|
-
const workspaceData = {
|
|
113
|
-
ok: true,
|
|
114
|
-
teamId: tokenData.team?.id,
|
|
115
|
-
teamName: tokenData.team?.name,
|
|
116
|
-
teamDomain: teamInfo?.domain,
|
|
117
|
-
workspaceUrl: teamInfo?.url,
|
|
118
|
-
workspaceIconUrl: teamInfo?.icon,
|
|
119
|
-
enterpriseId: tokenData.enterprise?.id,
|
|
120
|
-
enterpriseName: tokenData.enterprise?.name,
|
|
121
|
-
isEnterpriseInstall: tokenData.is_enterprise_install || false,
|
|
122
|
-
botUserId: tokenData.bot_user_id,
|
|
123
|
-
botToken: tokenData.access_token,
|
|
124
|
-
botScopes: tokenData.scope,
|
|
125
|
-
installerUserId,
|
|
126
|
-
installerUserName,
|
|
127
|
-
appId: tokenData.app_id,
|
|
128
|
-
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
129
|
-
};
|
|
130
|
-
if (workspaceData.teamId && workspaceData.botToken) {
|
|
131
|
-
const tenantId = "default";
|
|
132
|
-
const nangoResult = await storeWorkspaceInstallation({
|
|
133
|
-
teamId: workspaceData.teamId,
|
|
134
|
-
teamName: workspaceData.teamName,
|
|
135
|
-
teamDomain: workspaceData.teamDomain,
|
|
136
|
-
workspaceUrl: workspaceData.workspaceUrl,
|
|
137
|
-
workspaceIconUrl: workspaceData.workspaceIconUrl,
|
|
138
|
-
enterpriseId: workspaceData.enterpriseId,
|
|
139
|
-
enterpriseName: workspaceData.enterpriseName,
|
|
140
|
-
botUserId: workspaceData.botUserId,
|
|
141
|
-
botToken: workspaceData.botToken,
|
|
142
|
-
botScopes: workspaceData.botScopes,
|
|
143
|
-
installerUserId: workspaceData.installerUserId,
|
|
144
|
-
installerUserName: workspaceData.installerUserName,
|
|
145
|
-
isEnterpriseInstall: workspaceData.isEnterpriseInstall,
|
|
146
|
-
appId: workspaceData.appId,
|
|
147
|
-
tenantId,
|
|
148
|
-
installationSource: "dashboard"
|
|
149
|
-
});
|
|
150
|
-
if (nangoResult.success && nangoResult.connectionId) {
|
|
151
|
-
logger.info({
|
|
152
|
-
teamId: workspaceData.teamId,
|
|
153
|
-
connectionId: nangoResult.connectionId
|
|
154
|
-
}, "Stored workspace installation in Nango");
|
|
155
|
-
try {
|
|
156
|
-
await createWorkAppSlackWorkspace(runDbClient_default)({
|
|
157
|
-
tenantId,
|
|
158
|
-
slackTeamId: workspaceData.teamId,
|
|
159
|
-
slackEnterpriseId: workspaceData.enterpriseId,
|
|
160
|
-
slackAppId: workspaceData.appId,
|
|
161
|
-
slackTeamName: workspaceData.teamName,
|
|
162
|
-
nangoConnectionId: nangoResult.connectionId,
|
|
163
|
-
status: "active"
|
|
164
|
-
});
|
|
165
|
-
logger.info({
|
|
166
|
-
teamId: workspaceData.teamId,
|
|
167
|
-
tenantId
|
|
168
|
-
}, "Persisted workspace installation to database");
|
|
169
|
-
} catch (dbError) {
|
|
170
|
-
const dbErrorMessage = dbError instanceof Error ? dbError.message : String(dbError);
|
|
171
|
-
if (dbErrorMessage.includes("duplicate key") || dbErrorMessage.includes("unique constraint")) logger.info({
|
|
172
|
-
teamId: workspaceData.teamId,
|
|
173
|
-
tenantId
|
|
174
|
-
}, "Workspace already exists in database");
|
|
175
|
-
else logger.error({
|
|
176
|
-
error: dbErrorMessage,
|
|
177
|
-
teamId: workspaceData.teamId
|
|
178
|
-
}, "Failed to persist workspace to database");
|
|
179
|
-
}
|
|
180
|
-
} else logger.warn({ teamId: workspaceData.teamId }, "Failed to store in Nango, falling back to memory");
|
|
181
|
-
setBotTokenForTeam(workspaceData.teamId, {
|
|
182
|
-
botToken: workspaceData.botToken,
|
|
183
|
-
teamName: workspaceData.teamName || "",
|
|
184
|
-
installedAt: workspaceData.installedAt
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
logger.info({
|
|
188
|
-
teamId: workspaceData.teamId,
|
|
189
|
-
teamName: workspaceData.teamName
|
|
190
|
-
}, "Slack workspace installation successful");
|
|
191
|
-
const safeWorkspaceData = {
|
|
192
|
-
ok: workspaceData.ok,
|
|
193
|
-
teamId: workspaceData.teamId,
|
|
194
|
-
teamName: workspaceData.teamName,
|
|
195
|
-
teamDomain: workspaceData.teamDomain,
|
|
196
|
-
enterpriseId: workspaceData.enterpriseId,
|
|
197
|
-
enterpriseName: workspaceData.enterpriseName,
|
|
198
|
-
isEnterpriseInstall: workspaceData.isEnterpriseInstall,
|
|
199
|
-
botUserId: workspaceData.botUserId,
|
|
200
|
-
botScopes: workspaceData.botScopes,
|
|
201
|
-
installerUserId: workspaceData.installerUserId,
|
|
202
|
-
installedAt: workspaceData.installedAt,
|
|
203
|
-
connectionId: workspaceData.teamId ? computeWorkspaceConnectionId({
|
|
204
|
-
teamId: workspaceData.teamId,
|
|
205
|
-
enterpriseId: workspaceData.enterpriseId
|
|
206
|
-
}) : void 0
|
|
207
|
-
};
|
|
208
|
-
const encodedData = encodeURIComponent(JSON.stringify(safeWorkspaceData));
|
|
209
|
-
return c.redirect(`${dashboardUrl}?success=true&workspace=${encodedData}`);
|
|
210
|
-
} catch (err) {
|
|
211
|
-
logger.error({ error: err }, "Slack OAuth callback error");
|
|
212
|
-
return c.redirect(`${dashboardUrl}?error=callback_error`);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
var oauth_default = app;
|
|
216
|
-
|
|
217
|
-
//#endregion
|
|
218
|
-
export { oauth_default as default, getBotTokenForTeam, setBotTokenForTeam };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { WorkAppsVariables } from "../types.js";
|
|
2
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
3
|
-
|
|
4
|
-
//#region src/slack/routes/resources.d.ts
|
|
5
|
-
|
|
6
|
-
declare const app: OpenAPIHono<{
|
|
7
|
-
Variables: WorkAppsVariables;
|
|
8
|
-
}, {}, "/">;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { app as default };
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { getLogger } from "../../logger.js";
|
|
2
|
-
import manageDbClient_default from "../../db/manageDbClient.js";
|
|
3
|
-
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
4
|
-
import { listAgents, listProjectsPaginated } from "@inkeep/agents-core";
|
|
5
|
-
|
|
6
|
-
//#region src/slack/routes/resources.ts
|
|
7
|
-
/**
|
|
8
|
-
* Slack Resources Routes
|
|
9
|
-
*
|
|
10
|
-
* Endpoints for listing projects and agents:
|
|
11
|
-
* - GET /projects - List projects for tenant
|
|
12
|
-
* - GET /projects/:projectId/agents - List agents in project
|
|
13
|
-
* - GET /agents - List all agents (flat view)
|
|
14
|
-
*/
|
|
15
|
-
const logger = getLogger("slack-resources");
|
|
16
|
-
const app = new OpenAPIHono();
|
|
17
|
-
const ProjectSchema = z.object({
|
|
18
|
-
id: z.string(),
|
|
19
|
-
name: z.string().nullable(),
|
|
20
|
-
description: z.string().nullable().optional()
|
|
21
|
-
});
|
|
22
|
-
const AgentSchema = z.object({
|
|
23
|
-
id: z.string(),
|
|
24
|
-
name: z.string().nullable(),
|
|
25
|
-
projectId: z.string(),
|
|
26
|
-
projectName: z.string().nullable().optional()
|
|
27
|
-
});
|
|
28
|
-
app.openapi(createRoute({
|
|
29
|
-
method: "get",
|
|
30
|
-
path: "/projects",
|
|
31
|
-
summary: "List Projects",
|
|
32
|
-
description: "List all projects for the tenant",
|
|
33
|
-
operationId: "slack-list-projects",
|
|
34
|
-
tags: [
|
|
35
|
-
"Work Apps",
|
|
36
|
-
"Slack",
|
|
37
|
-
"Resources"
|
|
38
|
-
],
|
|
39
|
-
request: { query: z.object({
|
|
40
|
-
tenantId: z.string().optional().default("default"),
|
|
41
|
-
limit: z.coerce.number().optional().default(100)
|
|
42
|
-
}) },
|
|
43
|
-
responses: { 200: {
|
|
44
|
-
description: "List of projects",
|
|
45
|
-
content: { "application/json": { schema: z.object({ projects: z.array(ProjectSchema) }) } }
|
|
46
|
-
} }
|
|
47
|
-
}), async (c) => {
|
|
48
|
-
const { tenantId, limit } = c.req.valid("query");
|
|
49
|
-
try {
|
|
50
|
-
const result = await listProjectsPaginated(manageDbClient_default)({
|
|
51
|
-
tenantId,
|
|
52
|
-
pagination: { limit }
|
|
53
|
-
});
|
|
54
|
-
return c.json({ projects: result.data.map((p) => ({
|
|
55
|
-
id: p.id,
|
|
56
|
-
name: p.name,
|
|
57
|
-
description: p.description
|
|
58
|
-
})) });
|
|
59
|
-
} catch (error) {
|
|
60
|
-
logger.error({
|
|
61
|
-
error,
|
|
62
|
-
tenantId
|
|
63
|
-
}, "Failed to list projects");
|
|
64
|
-
return c.json({ projects: [] });
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
app.openapi(createRoute({
|
|
68
|
-
method: "get",
|
|
69
|
-
path: "/projects/:projectId/agents",
|
|
70
|
-
summary: "List Agents in Project",
|
|
71
|
-
description: "List all agents within a specific project",
|
|
72
|
-
operationId: "slack-list-project-agents",
|
|
73
|
-
tags: [
|
|
74
|
-
"Work Apps",
|
|
75
|
-
"Slack",
|
|
76
|
-
"Resources"
|
|
77
|
-
],
|
|
78
|
-
request: {
|
|
79
|
-
params: z.object({ projectId: z.string() }),
|
|
80
|
-
query: z.object({ tenantId: z.string().optional().default("default") })
|
|
81
|
-
},
|
|
82
|
-
responses: { 200: {
|
|
83
|
-
description: "List of agents",
|
|
84
|
-
content: { "application/json": { schema: z.object({ agents: z.array(AgentSchema) }) } }
|
|
85
|
-
} }
|
|
86
|
-
}), async (c) => {
|
|
87
|
-
const { projectId } = c.req.valid("param");
|
|
88
|
-
const { tenantId } = c.req.valid("query");
|
|
89
|
-
try {
|
|
90
|
-
const agents = await listAgents(manageDbClient_default)({ scopes: {
|
|
91
|
-
tenantId,
|
|
92
|
-
projectId
|
|
93
|
-
} });
|
|
94
|
-
return c.json({ agents: agents.map((a) => ({
|
|
95
|
-
id: a.id,
|
|
96
|
-
name: a.name,
|
|
97
|
-
projectId,
|
|
98
|
-
projectName: void 0
|
|
99
|
-
})) });
|
|
100
|
-
} catch (error) {
|
|
101
|
-
logger.error({
|
|
102
|
-
error,
|
|
103
|
-
tenantId,
|
|
104
|
-
projectId
|
|
105
|
-
}, "Failed to list agents");
|
|
106
|
-
return c.json({ agents: [] });
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
app.openapi(createRoute({
|
|
110
|
-
method: "get",
|
|
111
|
-
path: "/agents",
|
|
112
|
-
summary: "List All Agents",
|
|
113
|
-
description: "List all agents across all projects (flat view)",
|
|
114
|
-
operationId: "slack-list-all-agents",
|
|
115
|
-
tags: [
|
|
116
|
-
"Work Apps",
|
|
117
|
-
"Slack",
|
|
118
|
-
"Resources"
|
|
119
|
-
],
|
|
120
|
-
request: { query: z.object({ tenantId: z.string().optional().default("default") }) },
|
|
121
|
-
responses: { 200: {
|
|
122
|
-
description: "List of agents",
|
|
123
|
-
content: { "application/json": { schema: z.object({ agents: z.array(AgentSchema) }) } }
|
|
124
|
-
} }
|
|
125
|
-
}), async (c) => {
|
|
126
|
-
const { tenantId } = c.req.valid("query");
|
|
127
|
-
try {
|
|
128
|
-
const projectsResult = await listProjectsPaginated(manageDbClient_default)({
|
|
129
|
-
tenantId,
|
|
130
|
-
pagination: { limit: 100 }
|
|
131
|
-
});
|
|
132
|
-
const allAgents = (await Promise.all((projectsResult.data || []).map(async (project) => {
|
|
133
|
-
try {
|
|
134
|
-
return (await listAgents(manageDbClient_default)({ scopes: {
|
|
135
|
-
tenantId,
|
|
136
|
-
projectId: project.id
|
|
137
|
-
} })).map((agent) => ({
|
|
138
|
-
id: agent.id,
|
|
139
|
-
name: agent.name,
|
|
140
|
-
projectId: project.id,
|
|
141
|
-
projectName: project.name
|
|
142
|
-
}));
|
|
143
|
-
} catch (error) {
|
|
144
|
-
logger.warn({
|
|
145
|
-
projectId: project.id,
|
|
146
|
-
error
|
|
147
|
-
}, "Failed to fetch agents for project");
|
|
148
|
-
return [];
|
|
149
|
-
}
|
|
150
|
-
}))).flat();
|
|
151
|
-
return c.json({ agents: allAgents });
|
|
152
|
-
} catch (error) {
|
|
153
|
-
logger.error({
|
|
154
|
-
error,
|
|
155
|
-
tenantId
|
|
156
|
-
}, "Failed to list agents");
|
|
157
|
-
return c.json({ agents: [] });
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
var resources_default = app;
|
|
161
|
-
|
|
162
|
-
//#endregion
|
|
163
|
-
export { resources_default as default };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { WorkAppsVariables } from "../types.js";
|
|
2
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
3
|
-
|
|
4
|
-
//#region src/slack/routes/users.d.ts
|
|
5
|
-
|
|
6
|
-
declare const app: OpenAPIHono<{
|
|
7
|
-
Variables: WorkAppsVariables;
|
|
8
|
-
}, {}, "/">;
|
|
9
|
-
declare const pendingSessionTokens: Map<string, {
|
|
10
|
-
token: string;
|
|
11
|
-
expiresAt: string;
|
|
12
|
-
createdAt: number;
|
|
13
|
-
}>;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { app as default, pendingSessionTokens };
|