feat(slack): add gated managed setup alongside customer-owned apps

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-09 10:03:53 -05:00
1 parent 835a022936
commit 785ae16699
46 files changed
+4629 -783

No files matched your search

+28 -1
View File
@@ -22,7 +22,7 @@ export function buildSlackAppManifest(input: {
redirectUri?: string;
}) {
return {
display_information: { name: input.app.appName },
display_information: { name: input.app.appName, description: `Talk to ${input.agentName} and manage work in Paperclip.`.slice(0, 140) },
features: {
app_home: { home_tab_enabled: false, messages_tab_enabled: true, messages_tab_read_only_enabled: false },
agent_view: { agent_description: "Work with a Paperclip agent in a task-backed conversation." },
@@ -60,6 +60,7 @@ export const slackRegistrationStateSchema = z.object({
status: slackRegistrationStatusSchema,
appId: z.string().nullable().optional(),
managementUrl: z.string().url().nullable().optional(),
managerGrantId: z.string().uuid().nullable().optional(),
errorCode: z.string().nullable().optional(),
}).strict();
export type SlackRegistrationState = z.infer<typeof slackRegistrationStateSchema>;
@@ -79,11 +80,18 @@ export const slackAccountStateSchema = z.object({
}).strict();
export type SlackAccountState = z.infer<typeof slackAccountStateSchema>;
export const slackInstallAuthorizationSchema = z.object({ authorizationUrl: z.string().url(), expiresAt: z.string().datetime() });
export const slackManagerAuthorizationSchema = slackInstallAuthorizationSchema.extend({ handoff: z.object({ kind: z.literal("paperclip_cloud"), session: z.string().min(16).max(512) }).optional() });
export type SlackManagerAuthorization = z.infer<typeof slackManagerAuthorizationSchema>;
export type SlackInstallAuthorization = z.infer<typeof slackInstallAuthorizationSchema>;
export const slackSetupActionSchema = z.object({}).strict();
export function slackRegistrationErrorMessage(code: string): string {
const messages: Record<string, string> = {
slack_managed_unavailable: "Managed Slack setup is unavailable. Try again later or use your own app before creation starts.",
slack_manager_reauthorize: "Reconnect your Slack workspace to continue setting up this agent.",
slack_approval_pending: "Slack is waiting for your workspace administrator to approve this app.",
slack_approval_required: "Your Slack workspace requires approval. Continue in Slack to request it.",
slack_approval_denied: "Your Slack administrator declined this installation. Contact them to continue.",
slack_configuration_token_invalid: "Slack rejected the app configuration access token. Generate a new access token and try again.",
slack_manifest_invalid: "Slack rejected this app configuration. Check the app details or use manual setup.",
slack_manifest_update_pending: "Your Slack app is saved, but its event settings still need to be applied. Enter an app configuration access token to retry configuring the same app.",
@@ -102,3 +110,22 @@ export function slackRegistrationErrorMessage(code: string): string {
};
return messages[code] ?? "Slack setup could not be completed. Resume setup and try again.";
}
/** Persisted legacy values keep their original meaning. Missing means manual. */
export type SlackSetupMethod = "managed" | "automatic" | "manual" | "existing";
export function isProvisionedSlackSetup(method: string | undefined): boolean {
return method === "automatic" || method === "managed";
}
export const SLACK_MANAGER_SCOPES = ["app_configurations:read", "app_configurations:write", "managed_apps:install"] as const;
export const slackSetupOptionsSchema = z.object({
managedAvailable: z.boolean(),
defaultMethod: z.enum(["managed", "automatic"]),
workspaces: z.array(z.object({ grantId: z.string().uuid(), workspaceId: z.string(), workspaceName: z.string(), userId: z.string() })),
});
export type SlackSetupOptions = z.infer<typeof slackSetupOptionsSchema>;
export const slackManagedProvisionSchema = z.object({
requestId: z.string().uuid(), grantId: z.string().uuid(), confirmedNoAppCreated: z.boolean().optional(),
}).strict();
export type SlackManagedProvisionInput = z.infer<typeof slackManagedProvisionSchema>;
export const slackManagedResultSchema = z.object({ authorization: slackInstallAuthorizationSchema.optional() });
export type SlackManagedResult = z.infer<typeof slackManagedResultSchema>;
+4 -2
View File
@@ -188,7 +188,8 @@ export interface SlackAppConfiguration {
}
export interface ChatEndpointSetupState {
slackSetupMethod?: "automatic" | "manual" | "existing";
slackSetupMethod?: "managed" | "automatic" | "manual" | "existing";
slackManagerError?: string;
slackRegistration?: import("../slack-app-manifest.js").SlackRegistrationState;
/** Provider-confirmed app icon outcome; configuration tokens are never retained. */
slackAvatar?: import("../slack-app-manifest.js").SlackAvatarState;
@@ -486,10 +487,11 @@ export interface CreateChatEndpointInput {
applicationId?: string;
name?: string;
slackApp?: SlackAppConfiguration;
slackSetupMethod?: "managed" | "automatic" | "manual" | "existing";
}
export interface UpdateChatEndpointInput {
slackSetupMethod?: "automatic" | "manual" | "existing";
slackSetupMethod?: "managed" | "automatic" | "manual" | "existing";
slackApp?: SlackAppConfiguration;
communicationInstructions?: string;
allowDirectMessages?: boolean;
@@ -80,9 +80,10 @@ export const createChatEndpointSchema = z
applicationId: z.string().uuid().optional(),
name: z.string().trim().min(1).max(160).optional(),
slackApp: slackAppConfigurationSchema.optional(),
slackSetupMethod: z.enum(["managed", "automatic", "manual", "existing"]).optional(),
})
.strict()
.refine(value => !value.slackApp || value.provider === "slack", {
.refine(value => (!value.slackApp && !value.slackSetupMethod) || value.provider === "slack", {
message: "Slack app details only apply to Slack connections", path: ["slackApp"],
});
@@ -90,7 +91,7 @@ export const updateChatEndpointSchema = z
.object({
communicationInstructions: multilineTextSchema.pipe(z.string().trim().max(4000)).optional(),
slackApp: slackAppConfigurationSchema.optional(),
slackSetupMethod: z.enum(["automatic", "manual", "existing"]).optional(),
slackSetupMethod: z.enum(["managed", "automatic", "manual", "existing"]).optional(),
allowDirectMessages: z.boolean().optional(),
allowGroupChats: z.boolean().optional(),
allowUnlinkedPeople: z.boolean().optional(),