@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
package/dist/db/index.d.ts
CHANGED
package/dist/db/index.js
CHANGED
package/dist/db/runDbClient.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _inkeep_agents_core0 from "@inkeep/agents-core";
|
|
2
2
|
|
|
3
3
|
//#region src/db/runDbClient.d.ts
|
|
4
|
-
declare const runDbClient:
|
|
4
|
+
declare const runDbClient: _inkeep_agents_core0.AgentsRunDatabaseClient;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { runDbClient as default };
|
package/dist/env.d.ts
CHANGED
|
@@ -14,14 +14,13 @@ declare const envSchema: z.ZodObject<{
|
|
|
14
14
|
pentest: "pentest";
|
|
15
15
|
}>>;
|
|
16
16
|
LOG_LEVEL: z.ZodDefault<z.ZodEnum<{
|
|
17
|
-
error: "error";
|
|
18
17
|
trace: "trace";
|
|
19
18
|
debug: "debug";
|
|
20
19
|
info: "info";
|
|
21
20
|
warn: "warn";
|
|
21
|
+
error: "error";
|
|
22
22
|
}>>;
|
|
23
23
|
INKEEP_AGENTS_RUN_DATABASE_URL: z.ZodString;
|
|
24
|
-
INKEEP_AGENTS_MANAGE_DATABASE_URL: z.ZodOptional<z.ZodString>;
|
|
25
24
|
INKEEP_AGENTS_MANAGE_UI_URL: z.ZodOptional<z.ZodString>;
|
|
26
25
|
GITHUB_APP_ID: z.ZodOptional<z.ZodString>;
|
|
27
26
|
GITHUB_APP_PRIVATE_KEY: z.ZodOptional<z.ZodString>;
|
|
@@ -29,23 +28,12 @@ declare const envSchema: z.ZodObject<{
|
|
|
29
28
|
GITHUB_STATE_SIGNING_SECRET: z.ZodOptional<z.ZodString>;
|
|
30
29
|
GITHUB_APP_NAME: z.ZodOptional<z.ZodString>;
|
|
31
30
|
GITHUB_MCP_API_KEY: z.ZodOptional<z.ZodString>;
|
|
32
|
-
SLACK_CLIENT_ID: z.ZodOptional<z.ZodString>;
|
|
33
|
-
SLACK_CLIENT_SECRET: z.ZodOptional<z.ZodString>;
|
|
34
|
-
SLACK_SIGNING_SECRET: z.ZodOptional<z.ZodString>;
|
|
35
|
-
SLACK_BOT_TOKEN: z.ZodOptional<z.ZodString>;
|
|
36
|
-
SLACK_APP_URL: z.ZodOptional<z.ZodString>;
|
|
37
|
-
NANGO_SECRET_KEY: z.ZodOptional<z.ZodString>;
|
|
38
|
-
NANGO_SLACK_SECRET_KEY: z.ZodOptional<z.ZodString>;
|
|
39
|
-
NANGO_SLACK_INTEGRATION_ID: z.ZodOptional<z.ZodString>;
|
|
40
|
-
NANGO_SERVER_URL: z.ZodOptional<z.ZodString>;
|
|
41
|
-
INKEEP_AGENTS_API_URL: z.ZodOptional<z.ZodString>;
|
|
42
31
|
}, z.core.$strip>;
|
|
43
32
|
declare const env: {
|
|
44
33
|
NODE_ENV: "development" | "production" | "test";
|
|
45
34
|
ENVIRONMENT: "development" | "production" | "test" | "pentest";
|
|
46
|
-
LOG_LEVEL: "
|
|
35
|
+
LOG_LEVEL: "trace" | "debug" | "info" | "warn" | "error";
|
|
47
36
|
INKEEP_AGENTS_RUN_DATABASE_URL: string;
|
|
48
|
-
INKEEP_AGENTS_MANAGE_DATABASE_URL?: string | undefined;
|
|
49
37
|
INKEEP_AGENTS_MANAGE_UI_URL?: string | undefined;
|
|
50
38
|
GITHUB_APP_ID?: string | undefined;
|
|
51
39
|
GITHUB_APP_PRIVATE_KEY?: string | undefined;
|
|
@@ -53,16 +41,6 @@ declare const env: {
|
|
|
53
41
|
GITHUB_STATE_SIGNING_SECRET?: string | undefined;
|
|
54
42
|
GITHUB_APP_NAME?: string | undefined;
|
|
55
43
|
GITHUB_MCP_API_KEY?: string | undefined;
|
|
56
|
-
SLACK_CLIENT_ID?: string | undefined;
|
|
57
|
-
SLACK_CLIENT_SECRET?: string | undefined;
|
|
58
|
-
SLACK_SIGNING_SECRET?: string | undefined;
|
|
59
|
-
SLACK_BOT_TOKEN?: string | undefined;
|
|
60
|
-
SLACK_APP_URL?: string | undefined;
|
|
61
|
-
NANGO_SECRET_KEY?: string | undefined;
|
|
62
|
-
NANGO_SLACK_SECRET_KEY?: string | undefined;
|
|
63
|
-
NANGO_SLACK_INTEGRATION_ID?: string | undefined;
|
|
64
|
-
NANGO_SERVER_URL?: string | undefined;
|
|
65
|
-
INKEEP_AGENTS_API_URL?: string | undefined;
|
|
66
44
|
};
|
|
67
45
|
type Env = z.infer<typeof envSchema>;
|
|
68
46
|
//#endregion
|
package/dist/env.js
CHANGED
|
@@ -23,24 +23,13 @@ const envSchema = z.object({
|
|
|
23
23
|
"error"
|
|
24
24
|
]).default("info").describe("Logging verbosity level"),
|
|
25
25
|
INKEEP_AGENTS_RUN_DATABASE_URL: z.string().describe("PostgreSQL connection URL for the runtime database (Doltgres with Git version control)"),
|
|
26
|
-
INKEEP_AGENTS_MANAGE_DATABASE_URL: z.string().optional().describe("PostgreSQL connection URL for the management database"),
|
|
27
26
|
INKEEP_AGENTS_MANAGE_UI_URL: z.string().optional().describe("URL where the management UI is hosted"),
|
|
28
27
|
GITHUB_APP_ID: z.string().optional().describe("GitHub App ID for GitHub integration"),
|
|
29
28
|
GITHUB_APP_PRIVATE_KEY: z.string().optional().describe("GitHub App private key for authentication"),
|
|
30
29
|
GITHUB_WEBHOOK_SECRET: z.string().optional().describe("Secret for validating GitHub webhook payloads"),
|
|
31
30
|
GITHUB_STATE_SIGNING_SECRET: z.string().min(32, "GITHUB_STATE_SIGNING_SECRET must be at least 32 characters").optional().describe("Secret for signing GitHub OAuth state (minimum 32 characters)"),
|
|
32
31
|
GITHUB_APP_NAME: z.string().optional().describe("Name of the GitHub App"),
|
|
33
|
-
GITHUB_MCP_API_KEY: z.string().optional().describe("API key for the GitHub MCP")
|
|
34
|
-
SLACK_CLIENT_ID: z.string().optional().describe("Slack App Client ID"),
|
|
35
|
-
SLACK_CLIENT_SECRET: z.string().optional().describe("Slack App Client Secret"),
|
|
36
|
-
SLACK_SIGNING_SECRET: z.string().optional().describe("Slack App Signing Secret"),
|
|
37
|
-
SLACK_BOT_TOKEN: z.string().optional().describe("Slack Bot Token (for testing)"),
|
|
38
|
-
SLACK_APP_URL: z.string().optional().describe("Slack App Install URL"),
|
|
39
|
-
NANGO_SECRET_KEY: z.string().optional().describe("Nango Secret Key"),
|
|
40
|
-
NANGO_SLACK_SECRET_KEY: z.string().optional().describe("Nango Slack-specific Secret Key"),
|
|
41
|
-
NANGO_SLACK_INTEGRATION_ID: z.string().optional().describe("Nango Slack Integration ID"),
|
|
42
|
-
NANGO_SERVER_URL: z.string().optional().describe("Nango Server URL"),
|
|
43
|
-
INKEEP_AGENTS_API_URL: z.string().optional().describe("Inkeep Agents API URL")
|
|
32
|
+
GITHUB_MCP_API_KEY: z.string().optional().describe("API key for the GitHub MCP")
|
|
44
33
|
});
|
|
45
34
|
const parseEnv = () => {
|
|
46
35
|
try {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
|
-
import * as
|
|
2
|
+
import * as hono_types6 from "hono/types";
|
|
3
3
|
|
|
4
4
|
//#region src/github/routes/setup.d.ts
|
|
5
|
-
declare const app: Hono<
|
|
5
|
+
declare const app: Hono<hono_types6.BlankEnv, hono_types6.BlankSchema, "/">;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { app as default };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
|
-
import * as
|
|
2
|
+
import * as hono_types4 from "hono/types";
|
|
3
3
|
|
|
4
4
|
//#region src/github/routes/tokenExchange.d.ts
|
|
5
|
-
declare const app: Hono<
|
|
5
|
+
declare const app: Hono<hono_types4.BlankEnv, hono_types4.BlankSchema, "/">;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { app as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-work-apps",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20260204210021",
|
|
4
4
|
"description": "First party integrations for Inkeep Agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -13,26 +13,18 @@
|
|
|
13
13
|
"./github": {
|
|
14
14
|
"types": "./dist/github/index.d.ts",
|
|
15
15
|
"import": "./dist/github/index.js"
|
|
16
|
-
},
|
|
17
|
-
"./slack": {
|
|
18
|
-
"types": "./dist/slack/index.d.ts",
|
|
19
|
-
"import": "./dist/slack/index.js"
|
|
20
16
|
}
|
|
21
17
|
},
|
|
22
18
|
"dependencies": {
|
|
23
19
|
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
24
|
-
"@nangohq/node": "^0.48.1",
|
|
25
20
|
"@octokit/auth-app": "^8.1.2",
|
|
26
21
|
"@octokit/rest": "^22.0.1",
|
|
27
|
-
"@slack/types": "^2.18.0",
|
|
28
|
-
"@slack/web-api": "^7.9.1",
|
|
29
|
-
"slack-block-builder": "^2.8.0",
|
|
30
22
|
"drizzle-orm": "^0.44.7",
|
|
31
23
|
"fetch-to-node": "^2.1.0",
|
|
32
24
|
"hono": "^4.10.4",
|
|
33
25
|
"jose": "^6.1.0",
|
|
34
26
|
"minimatch": "^10.1.1",
|
|
35
|
-
"@inkeep/agents-core": "0.0.0-dev-
|
|
27
|
+
"@inkeep/agents-core": "0.0.0-dev-20260204210021"
|
|
36
28
|
},
|
|
37
29
|
"peerDependencies": {
|
|
38
30
|
"@hono/zod-openapi": "^1.1.5",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import * as _inkeep_agents_core0 from "@inkeep/agents-core";
|
|
2
|
-
|
|
3
|
-
//#region src/db/manageDbClient.d.ts
|
|
4
|
-
declare function getManageDbClient(): _inkeep_agents_core0.AgentsManageDatabaseClient;
|
|
5
|
-
declare const _default: _inkeep_agents_core0.AgentsManageDatabaseClient;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { _default as default, getManageDbClient };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { createAgentsManageDatabaseClient } from "@inkeep/agents-core";
|
|
2
|
-
|
|
3
|
-
//#region src/db/manageDbClient.ts
|
|
4
|
-
let manageDbClient = null;
|
|
5
|
-
function getManageDbClient() {
|
|
6
|
-
if (!manageDbClient) {
|
|
7
|
-
const connectionString = process.env.INKEEP_AGENTS_MANAGE_DATABASE_URL;
|
|
8
|
-
if (!connectionString) throw new Error("INKEEP_AGENTS_MANAGE_DATABASE_URL environment variable is required");
|
|
9
|
-
manageDbClient = createAgentsManageDatabaseClient({ connectionString });
|
|
10
|
-
}
|
|
11
|
-
return manageDbClient;
|
|
12
|
-
}
|
|
13
|
-
var manageDbClient_default = getManageDbClient();
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { manageDbClient_default as default, getManageDbClient };
|
package/dist/slack/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ManageAppVariables, WorkAppsVariables } from "./types.js";
|
|
2
|
-
import { DefaultAgentConfig, SlackWorkspaceConnection, WorkspaceInstallData, computeWorkspaceConnectionId, createConnectSession, deleteWorkspaceInstallation, findWorkspaceConnectionByTeamId, getConnectionAccessToken, getSlackIntegrationId, getSlackNango, getWorkspaceDefaultAgentFromNango, listWorkspaceInstallations, setWorkspaceDefaultAgent, storeWorkspaceInstallation, updateConnectionMetadata } from "./services/nango.js";
|
|
3
|
-
import { getChannelAgentConfig, getWorkspaceDefaultAgent } from "./services/events/utils.js";
|
|
4
|
-
import "./services/events/index.js";
|
|
5
|
-
import { getBotTokenForTeam, setBotTokenForTeam } from "./services/workspace-tokens.js";
|
|
6
|
-
import "./routes/oauth.js";
|
|
7
|
-
import { pendingSessionTokens } from "./routes/users.js";
|
|
8
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
9
|
-
|
|
10
|
-
//#region src/slack/index.d.ts
|
|
11
|
-
|
|
12
|
-
declare function createSlackRoutes(): OpenAPIHono<{
|
|
13
|
-
Variables: WorkAppsVariables;
|
|
14
|
-
}, {}, "/">;
|
|
15
|
-
declare const slackRoutes: OpenAPIHono<{
|
|
16
|
-
Variables: WorkAppsVariables;
|
|
17
|
-
}, {}, "/">;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { DefaultAgentConfig, ManageAppVariables, SlackWorkspaceConnection, WorkAppsVariables, WorkspaceInstallData, computeWorkspaceConnectionId, createConnectSession, createSlackRoutes, deleteWorkspaceInstallation, findWorkspaceConnectionByTeamId, getBotTokenForTeam, getChannelAgentConfig, getConnectionAccessToken, getSlackIntegrationId, getSlackNango, getWorkspaceDefaultAgent, getWorkspaceDefaultAgentFromNango, listWorkspaceInstallations, pendingSessionTokens, setBotTokenForTeam, setWorkspaceDefaultAgent, slackRoutes, storeWorkspaceInstallation, updateConnectionMetadata };
|
package/dist/slack/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { computeWorkspaceConnectionId, createConnectSession, deleteWorkspaceInstallation, findWorkspaceConnectionByTeamId, getConnectionAccessToken, getSlackIntegrationId, getSlackNango, getWorkspaceDefaultAgentFromNango, listWorkspaceInstallations, setWorkspaceDefaultAgent, storeWorkspaceInstallation, updateConnectionMetadata } from "./services/nango.js";
|
|
2
|
-
import { getBotTokenForTeam, setBotTokenForTeam } from "./services/workspace-tokens.js";
|
|
3
|
-
import { getChannelAgentConfig, getWorkspaceDefaultAgent } from "./services/events/utils.js";
|
|
4
|
-
import "./services/events/index.js";
|
|
5
|
-
import "./routes/oauth.js";
|
|
6
|
-
import { pendingSessionTokens } from "./routes/users.js";
|
|
7
|
-
import routes_default from "./routes.js";
|
|
8
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
9
|
-
|
|
10
|
-
//#region src/slack/index.ts
|
|
11
|
-
/**
|
|
12
|
-
* Slack Work App
|
|
13
|
-
*
|
|
14
|
-
* Provides Slack integration for Inkeep Agents including:
|
|
15
|
-
* - OAuth-based workspace installation
|
|
16
|
-
* - User account linking via JWT tokens
|
|
17
|
-
* - Slash commands for agent interaction
|
|
18
|
-
* - @mention support for workspace-wide agent access
|
|
19
|
-
* - Channel-specific agent configuration
|
|
20
|
-
*/
|
|
21
|
-
function createSlackRoutes() {
|
|
22
|
-
const app = new OpenAPIHono();
|
|
23
|
-
app.route("/", routes_default);
|
|
24
|
-
return app;
|
|
25
|
-
}
|
|
26
|
-
const slackRoutes = createSlackRoutes();
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
export { computeWorkspaceConnectionId, createConnectSession, createSlackRoutes, deleteWorkspaceInstallation, findWorkspaceConnectionByTeamId, getBotTokenForTeam, getChannelAgentConfig, getConnectionAccessToken, getSlackIntegrationId, getSlackNango, getWorkspaceDefaultAgent, getWorkspaceDefaultAgentFromNango, listWorkspaceInstallations, pendingSessionTokens, setBotTokenForTeam, setWorkspaceDefaultAgent, slackRoutes, storeWorkspaceInstallation, updateConnectionMetadata };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ManageAppVariables } from "../types.js";
|
|
2
|
-
import * as hono0 from "hono";
|
|
3
|
-
|
|
4
|
-
//#region src/slack/middleware/permissions.d.ts
|
|
5
|
-
declare const requireWorkspaceAdmin: <Env extends {
|
|
6
|
-
Variables: ManageAppVariables;
|
|
7
|
-
} = {
|
|
8
|
-
Variables: ManageAppVariables;
|
|
9
|
-
}>() => hono0.MiddlewareHandler<Env, string, {}, Response>;
|
|
10
|
-
declare const requireAuthenticatedUser: <Env extends {
|
|
11
|
-
Variables: ManageAppVariables;
|
|
12
|
-
} = {
|
|
13
|
-
Variables: ManageAppVariables;
|
|
14
|
-
}>() => hono0.MiddlewareHandler<Env, string, {}, Response>;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { requireAuthenticatedUser, requireWorkspaceAdmin };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { OrgRoles, createApiError } from "@inkeep/agents-core";
|
|
2
|
-
import { createMiddleware } from "hono/factory";
|
|
3
|
-
|
|
4
|
-
//#region src/slack/middleware/permissions.ts
|
|
5
|
-
const requireWorkspaceAdmin = () => createMiddleware(async (c, next) => {
|
|
6
|
-
if (process.env.ENVIRONMENT === "test") {
|
|
7
|
-
await next();
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const userId = c.get("userId");
|
|
11
|
-
const tenantId = c.get("tenantId");
|
|
12
|
-
const tenantRole = c.get("tenantRole");
|
|
13
|
-
if (!userId || !tenantId) throw createApiError({
|
|
14
|
-
code: "unauthorized",
|
|
15
|
-
message: "User or organization context not found",
|
|
16
|
-
instance: c.req.path
|
|
17
|
-
});
|
|
18
|
-
if (userId === "system" || userId.startsWith("apikey:")) {
|
|
19
|
-
await next();
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (!(tenantRole === OrgRoles.OWNER || tenantRole === OrgRoles.ADMIN)) throw createApiError({
|
|
23
|
-
code: "forbidden",
|
|
24
|
-
message: "Only workspace administrators can modify workspace and channel configurations",
|
|
25
|
-
instance: c.req.path,
|
|
26
|
-
extensions: {
|
|
27
|
-
requiredRole: "admin or owner",
|
|
28
|
-
currentRole: tenantRole
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
await next();
|
|
32
|
-
});
|
|
33
|
-
const requireAuthenticatedUser = () => createMiddleware(async (c, next) => {
|
|
34
|
-
if (process.env.ENVIRONMENT === "test") {
|
|
35
|
-
await next();
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const userId = c.get("userId");
|
|
39
|
-
const tenantId = c.get("tenantId");
|
|
40
|
-
if (!userId || !tenantId) throw createApiError({
|
|
41
|
-
code: "unauthorized",
|
|
42
|
-
message: "Authentication required",
|
|
43
|
-
instance: c.req.path
|
|
44
|
-
});
|
|
45
|
-
await next();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
export { requireAuthenticatedUser, requireWorkspaceAdmin };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { WorkAppsVariables } from "../types.js";
|
|
2
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
3
|
-
|
|
4
|
-
//#region src/slack/routes/events.d.ts
|
|
5
|
-
|
|
6
|
-
declare const app: OpenAPIHono<{
|
|
7
|
-
Variables: WorkAppsVariables;
|
|
8
|
-
}, {}, "/">;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { app as default };
|
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import { env } from "../../env.js";
|
|
2
|
-
import { getLogger } from "../../logger.js";
|
|
3
|
-
import runDbClient_default from "../../db/runDbClient.js";
|
|
4
|
-
import { findWorkspaceConnectionByTeamId, getSlackIntegrationId, getSlackNango, updateConnectionMetadata } from "../services/nango.js";
|
|
5
|
-
import { getSlackClient, getSlackUserInfo } from "../services/client.js";
|
|
6
|
-
import { handleCommand } from "../services/commands/index.js";
|
|
7
|
-
import { sendResponseUrlMessage } from "../services/events/utils.js";
|
|
8
|
-
import { handleAppMention } from "../services/events/app-mention.js";
|
|
9
|
-
import { handleOpenAgentSelectorModal, handleShareToChannel, handleShareToThread } from "../services/events/block-actions.js";
|
|
10
|
-
import { handleModalSubmission } from "../services/events/modal-submission.js";
|
|
11
|
-
import "../services/events/index.js";
|
|
12
|
-
import { parseSlackCommandBody, parseSlackEventBody, verifySlackRequest } from "../services/security.js";
|
|
13
|
-
import "../services/index.js";
|
|
14
|
-
import { pendingSessionTokens } from "./users.js";
|
|
15
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
16
|
-
import { deleteAllWorkAppSlackChannelAgentConfigsByTeam, deleteAllWorkAppSlackUserMappingsByTeam, deleteWorkAppSlackWorkspaceByNangoConnectionId } from "@inkeep/agents-core";
|
|
17
|
-
|
|
18
|
-
//#region src/slack/routes/events.ts
|
|
19
|
-
/**
|
|
20
|
-
* Slack Events Routes
|
|
21
|
-
*
|
|
22
|
-
* Endpoints for handling Slack events, commands, and webhooks:
|
|
23
|
-
* - POST /commands - Handle /inkeep slash commands
|
|
24
|
-
* - POST /events - Handle Slack events & interactivity
|
|
25
|
-
* - POST /nango-webhook - Handle Nango auth webhooks
|
|
26
|
-
*/
|
|
27
|
-
const logger = getLogger("slack-events");
|
|
28
|
-
const app = new OpenAPIHono();
|
|
29
|
-
app.post("/commands", async (c) => {
|
|
30
|
-
const body = await c.req.text();
|
|
31
|
-
const timestamp = c.req.header("x-slack-request-timestamp") || "";
|
|
32
|
-
const signature = c.req.header("x-slack-signature") || "";
|
|
33
|
-
if (!env.SLACK_SIGNING_SECRET) {
|
|
34
|
-
logger.error({}, "SLACK_SIGNING_SECRET not configured - rejecting request");
|
|
35
|
-
return c.json({
|
|
36
|
-
response_type: "ephemeral",
|
|
37
|
-
text: "Server configuration error"
|
|
38
|
-
}, 500);
|
|
39
|
-
}
|
|
40
|
-
if (!verifySlackRequest(env.SLACK_SIGNING_SECRET, body, timestamp, signature)) {
|
|
41
|
-
logger.error({}, "Invalid Slack request signature");
|
|
42
|
-
return c.json({
|
|
43
|
-
response_type: "ephemeral",
|
|
44
|
-
text: "Invalid request signature"
|
|
45
|
-
}, 401);
|
|
46
|
-
}
|
|
47
|
-
const params = parseSlackCommandBody(body);
|
|
48
|
-
const response = await handleCommand({
|
|
49
|
-
command: params.command || "",
|
|
50
|
-
text: params.text || "",
|
|
51
|
-
userId: params.user_id || "",
|
|
52
|
-
userName: params.user_name || "",
|
|
53
|
-
teamId: params.team_id || "",
|
|
54
|
-
teamDomain: params.team_domain || "",
|
|
55
|
-
enterpriseId: params.enterprise_id,
|
|
56
|
-
channelId: params.channel_id || "",
|
|
57
|
-
channelName: params.channel_name || "",
|
|
58
|
-
responseUrl: params.response_url || "",
|
|
59
|
-
triggerId: params.trigger_id || ""
|
|
60
|
-
});
|
|
61
|
-
if (Object.keys(response).length === 0) return c.body(null, 200);
|
|
62
|
-
return c.json(response);
|
|
63
|
-
});
|
|
64
|
-
app.post("/events", async (c) => {
|
|
65
|
-
const contentType = c.req.header("content-type") || "";
|
|
66
|
-
const body = await c.req.text();
|
|
67
|
-
const timestamp = c.req.header("x-slack-request-timestamp") || "";
|
|
68
|
-
const signature = c.req.header("x-slack-signature") || "";
|
|
69
|
-
let eventBody;
|
|
70
|
-
try {
|
|
71
|
-
eventBody = parseSlackEventBody(body, contentType);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
logger.error({
|
|
74
|
-
error,
|
|
75
|
-
contentType,
|
|
76
|
-
bodyPreview: body.slice(0, 200)
|
|
77
|
-
}, "Failed to parse Slack event body");
|
|
78
|
-
return c.json({ error: "Invalid payload" }, 400);
|
|
79
|
-
}
|
|
80
|
-
logger.debug({ eventType: eventBody.type }, "Slack event received");
|
|
81
|
-
const eventType = eventBody.type;
|
|
82
|
-
if (eventType === "url_verification") {
|
|
83
|
-
logger.info({}, "Responding to Slack URL verification challenge");
|
|
84
|
-
return c.text(String(eventBody.challenge));
|
|
85
|
-
}
|
|
86
|
-
if (!env.SLACK_SIGNING_SECRET) {
|
|
87
|
-
logger.error({}, "SLACK_SIGNING_SECRET not configured - rejecting request");
|
|
88
|
-
return c.json({ error: "Server configuration error" }, 500);
|
|
89
|
-
}
|
|
90
|
-
if (!verifySlackRequest(env.SLACK_SIGNING_SECRET, body, timestamp, signature)) {
|
|
91
|
-
logger.error({}, "Invalid Slack request signature");
|
|
92
|
-
return c.json({ error: "Invalid request signature" }, 401);
|
|
93
|
-
}
|
|
94
|
-
if (eventType === "event_callback") {
|
|
95
|
-
const teamId = eventBody.team_id;
|
|
96
|
-
const event = eventBody.event;
|
|
97
|
-
if (event?.bot_id || event?.subtype === "bot_message") {
|
|
98
|
-
logger.debug({ botId: event.bot_id }, "Ignoring bot message");
|
|
99
|
-
return c.json({ ok: true });
|
|
100
|
-
}
|
|
101
|
-
logger.debug({
|
|
102
|
-
eventType: event?.type,
|
|
103
|
-
teamId
|
|
104
|
-
}, "Slack event callback");
|
|
105
|
-
if (event?.type === "app_mention" && event.channel && event.user && teamId) {
|
|
106
|
-
const question = (event.text || "").replace(/<@[A-Z0-9]+>/g, "").trim();
|
|
107
|
-
logger.info({
|
|
108
|
-
userId: event.user,
|
|
109
|
-
channel: event.channel,
|
|
110
|
-
teamId
|
|
111
|
-
}, "Bot was mentioned");
|
|
112
|
-
handleAppMention({
|
|
113
|
-
slackUserId: event.user,
|
|
114
|
-
channel: event.channel,
|
|
115
|
-
text: question,
|
|
116
|
-
threadTs: event.thread_ts || event.ts || "",
|
|
117
|
-
messageTs: event.ts || "",
|
|
118
|
-
teamId
|
|
119
|
-
}).catch((err) => {
|
|
120
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
121
|
-
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
122
|
-
logger.error({
|
|
123
|
-
errorMessage,
|
|
124
|
-
errorStack
|
|
125
|
-
}, "Failed to handle app mention (outer catch)");
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (eventType === "block_actions" || eventType === "interactive_message") {
|
|
130
|
-
logger.debug({ eventType }, "Slack interactive event received");
|
|
131
|
-
const actions = eventBody.actions;
|
|
132
|
-
const teamId = eventBody.team?.id;
|
|
133
|
-
const channelId = eventBody.channel?.id;
|
|
134
|
-
const userId = eventBody.user?.id;
|
|
135
|
-
const responseUrl = eventBody.response_url;
|
|
136
|
-
const triggerId = eventBody.trigger_id;
|
|
137
|
-
if (actions && teamId) for (const action of actions) {
|
|
138
|
-
if (action.action_id === "share_to_channel" && action.value) handleShareToChannel({
|
|
139
|
-
teamId,
|
|
140
|
-
channelId: channelId || "",
|
|
141
|
-
userId: userId || "",
|
|
142
|
-
actionValue: action.value,
|
|
143
|
-
responseUrl: responseUrl || ""
|
|
144
|
-
}).catch(async (err) => {
|
|
145
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
146
|
-
logger.error({
|
|
147
|
-
errorMessage,
|
|
148
|
-
actionId: action.action_id
|
|
149
|
-
}, "Failed to handle share_to_channel");
|
|
150
|
-
if (responseUrl) await sendResponseUrlMessage(responseUrl, {
|
|
151
|
-
text: "Sorry, something went wrong while sharing to channel. Please try again.",
|
|
152
|
-
response_type: "ephemeral"
|
|
153
|
-
}).catch(() => {});
|
|
154
|
-
});
|
|
155
|
-
if (action.action_id === "share_to_thread" && action.value) handleShareToThread({
|
|
156
|
-
teamId,
|
|
157
|
-
channelId: channelId || "",
|
|
158
|
-
userId: userId || "",
|
|
159
|
-
actionValue: action.value,
|
|
160
|
-
responseUrl: responseUrl || ""
|
|
161
|
-
}).catch(async (err) => {
|
|
162
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
163
|
-
logger.error({
|
|
164
|
-
errorMessage,
|
|
165
|
-
actionId: action.action_id
|
|
166
|
-
}, "Failed to handle share_to_thread");
|
|
167
|
-
if (responseUrl) await sendResponseUrlMessage(responseUrl, {
|
|
168
|
-
text: "Sorry, something went wrong while sharing to thread. Please try again.",
|
|
169
|
-
response_type: "ephemeral"
|
|
170
|
-
}).catch(() => {});
|
|
171
|
-
});
|
|
172
|
-
if (action.action_id === "open_agent_selector_modal" && action.value && triggerId) handleOpenAgentSelectorModal({
|
|
173
|
-
triggerId,
|
|
174
|
-
actionValue: action.value,
|
|
175
|
-
teamId,
|
|
176
|
-
responseUrl: responseUrl || ""
|
|
177
|
-
}).catch(async (err) => {
|
|
178
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
179
|
-
logger.error({
|
|
180
|
-
errorMessage,
|
|
181
|
-
actionId: action.action_id
|
|
182
|
-
}, "Failed to open agent selector modal");
|
|
183
|
-
if (responseUrl) await sendResponseUrlMessage(responseUrl, {
|
|
184
|
-
text: "Sorry, something went wrong while opening the agent selector. Please try again.",
|
|
185
|
-
response_type: "ephemeral"
|
|
186
|
-
}).catch(() => {});
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
if (eventType === "view_submission") {
|
|
191
|
-
const callbackId = eventBody.view?.callback_id;
|
|
192
|
-
if (callbackId === "agent_selector_modal") {
|
|
193
|
-
const view = eventBody.view;
|
|
194
|
-
handleModalSubmission(view).catch((err) => {
|
|
195
|
-
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
196
|
-
logger.error({
|
|
197
|
-
errorMessage,
|
|
198
|
-
callbackId
|
|
199
|
-
}, "Failed to handle modal submission");
|
|
200
|
-
});
|
|
201
|
-
return new Response(null, { status: 200 });
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return c.json({ ok: true });
|
|
205
|
-
});
|
|
206
|
-
app.post("/nango-webhook", async (c) => {
|
|
207
|
-
const body = await c.req.text();
|
|
208
|
-
let payload;
|
|
209
|
-
try {
|
|
210
|
-
payload = JSON.parse(body);
|
|
211
|
-
} catch (error) {
|
|
212
|
-
logger.error({
|
|
213
|
-
error,
|
|
214
|
-
bodyPreview: body.slice(0, 200)
|
|
215
|
-
}, "Failed to parse Nango webhook JSON");
|
|
216
|
-
return c.json({ error: "Invalid JSON" }, 400);
|
|
217
|
-
}
|
|
218
|
-
logger.debug({ payload }, "Nango webhook received");
|
|
219
|
-
if (payload.type === "connection_deleted" && payload.connectionId && payload.providerConfigKey) {
|
|
220
|
-
const { connectionId, providerConfigKey } = payload;
|
|
221
|
-
if (providerConfigKey === getSlackIntegrationId()) try {
|
|
222
|
-
const teamMatch = connectionId.match(/T:([A-Z0-9]+)/);
|
|
223
|
-
if (teamMatch) {
|
|
224
|
-
const teamId = teamMatch[1];
|
|
225
|
-
const tenantId = (await findWorkspaceConnectionByTeamId(teamId))?.tenantId || "default";
|
|
226
|
-
if (await deleteWorkAppSlackWorkspaceByNangoConnectionId(runDbClient_default)(connectionId)) logger.info({ connectionId }, "Deleted workspace from database via Nango webhook");
|
|
227
|
-
const deletedMappings = await deleteAllWorkAppSlackUserMappingsByTeam(runDbClient_default)(tenantId, teamId);
|
|
228
|
-
if (deletedMappings > 0) logger.info({
|
|
229
|
-
teamId,
|
|
230
|
-
deletedMappings
|
|
231
|
-
}, "Deleted user mappings via Nango webhook");
|
|
232
|
-
const deletedChannelConfigs = await deleteAllWorkAppSlackChannelAgentConfigsByTeam(runDbClient_default)(tenantId, teamId);
|
|
233
|
-
if (deletedChannelConfigs > 0) logger.info({
|
|
234
|
-
teamId,
|
|
235
|
-
deletedChannelConfigs
|
|
236
|
-
}, "Deleted channel configs via Nango webhook");
|
|
237
|
-
logger.info({
|
|
238
|
-
connectionId,
|
|
239
|
-
teamId
|
|
240
|
-
}, "Processed Nango connection deletion webhook");
|
|
241
|
-
}
|
|
242
|
-
} catch (error) {
|
|
243
|
-
logger.error({
|
|
244
|
-
error,
|
|
245
|
-
connectionId
|
|
246
|
-
}, "Failed to process Nango deletion webhook");
|
|
247
|
-
}
|
|
248
|
-
return c.json({ received: true });
|
|
249
|
-
}
|
|
250
|
-
if (payload.type === "auth" && payload.success && payload.endUser && payload.connectionId) {
|
|
251
|
-
const { endUser, connectionId } = payload;
|
|
252
|
-
const integrationId = getSlackIntegrationId();
|
|
253
|
-
try {
|
|
254
|
-
const rawResponse = (await getSlackNango().getConnection(integrationId, connectionId)).credentials?.raw;
|
|
255
|
-
logger.debug({ teamId: rawResponse?.team?.id }, "Retrieved Nango connection info");
|
|
256
|
-
if (rawResponse?.ok && rawResponse.access_token) {
|
|
257
|
-
const slackUserId = rawResponse.authed_user?.id || "";
|
|
258
|
-
const slackTeamId = rawResponse.team?.id || "";
|
|
259
|
-
const accessToken = rawResponse.access_token;
|
|
260
|
-
let slackUsername = "";
|
|
261
|
-
let slackDisplayName = "";
|
|
262
|
-
let slackEmail = "";
|
|
263
|
-
let isSlackAdmin = false;
|
|
264
|
-
let isSlackOwner = false;
|
|
265
|
-
if (slackUserId && accessToken) {
|
|
266
|
-
const userInfo = await getSlackUserInfo(getSlackClient(accessToken), slackUserId);
|
|
267
|
-
if (userInfo) {
|
|
268
|
-
slackUsername = userInfo.name || "";
|
|
269
|
-
slackDisplayName = userInfo.displayName || userInfo.realName || "";
|
|
270
|
-
slackEmail = userInfo.email || "";
|
|
271
|
-
isSlackAdmin = userInfo.isAdmin || false;
|
|
272
|
-
isSlackOwner = userInfo.isOwner || false;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
const tenantId = payload.organization?.id || "default";
|
|
276
|
-
const pendingSession = pendingSessionTokens.get(endUser.endUserId);
|
|
277
|
-
if (pendingSession) {
|
|
278
|
-
pendingSessionTokens.delete(endUser.endUserId);
|
|
279
|
-
logger.info({ userId: endUser.endUserId }, "Retrieved pending session token");
|
|
280
|
-
}
|
|
281
|
-
await updateConnectionMetadata(connectionId, {
|
|
282
|
-
linked_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
283
|
-
app_user_id: endUser.endUserId,
|
|
284
|
-
app_user_email: endUser.endUserEmail || "",
|
|
285
|
-
tenant_id: tenantId,
|
|
286
|
-
slack_user_id: slackUserId,
|
|
287
|
-
slack_team_id: slackTeamId,
|
|
288
|
-
slack_team_name: rawResponse.team?.name || "",
|
|
289
|
-
slack_username: slackUsername,
|
|
290
|
-
slack_display_name: slackDisplayName,
|
|
291
|
-
slack_email: slackEmail,
|
|
292
|
-
is_slack_admin: String(isSlackAdmin),
|
|
293
|
-
is_slack_owner: String(isSlackOwner),
|
|
294
|
-
enterprise_id: rawResponse.enterprise?.id || "",
|
|
295
|
-
enterprise_name: rawResponse.enterprise?.name || "",
|
|
296
|
-
...pendingSession ? {
|
|
297
|
-
inkeep_session_token: pendingSession.token,
|
|
298
|
-
inkeep_session_expires_at: pendingSession.expiresAt
|
|
299
|
-
} : {}
|
|
300
|
-
});
|
|
301
|
-
logger.info({
|
|
302
|
-
appUserId: endUser.endUserId,
|
|
303
|
-
slackUserId,
|
|
304
|
-
slackEmail
|
|
305
|
-
}, "User linked to Slack with enriched metadata");
|
|
306
|
-
}
|
|
307
|
-
} catch (error) {
|
|
308
|
-
logger.error({
|
|
309
|
-
error,
|
|
310
|
-
connectionId
|
|
311
|
-
}, "Failed to process Nango webhook");
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return c.json({ received: true });
|
|
315
|
-
});
|
|
316
|
-
var events_default = app;
|
|
317
|
-
|
|
318
|
-
//#endregion
|
|
319
|
-
export { events_default as default };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { WorkAppsVariables } from "../types.js";
|
|
2
|
-
import { pendingSessionTokens } from "./users.js";
|
|
3
|
-
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
4
|
-
|
|
5
|
-
//#region src/slack/routes/index.d.ts
|
|
6
|
-
|
|
7
|
-
declare const app: OpenAPIHono<{
|
|
8
|
-
Variables: WorkAppsVariables;
|
|
9
|
-
}, {}, "/">;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { app as default, pendingSessionTokens };
|