/** * Slack agents: reads and writes, now backed by agents (see `./agents`). * * The functions keep the shapes the Slack code was written against: `home` * is the Slack installation's own workspace (where its binding and channel * routes live) and `targetWorkspaceId` is the agent's home workspace, where * its chats run. Agent rows, revisions and Slack availability are written in * the agent's home. An agent may be in several installations; a record is the * agent as one installation sees it. * * Authorization (who may create, edit or use an agent) is decided by callers * from live grants. Nothing here grants anything. */ import { type SessionAvatar } from "@opengeni/contracts"; import { type SlackAgentProjection } from "./agents.js"; import { type Database } from "./database.js"; export type SlackAgentHome = { accountId: string; workspaceId: string; }; /** * An agent as one Slack installation sees it. Read from the agents tables * (see `./agents`); the shape is the one the Slack code was written against. */ export type SlackAgentRecord = SlackAgentProjection; /** * Every Slack-available agent in one organization, for the directory, once * per installation it is in. Ordered by name. */ export declare function listOrganizationSlackAgents(db: Database, input: { accountId: string; }): Promise; /** * The agents one installation answers to, ordered by name. An installation * with none is the common case and must stay one cheap indexed read. */ export declare function listSlackAgentsForConnection(db: Database, home: SlackAgentHome, input: { connectionId: string; }): Promise; /** * One Slack-available agent by id within an organization, or null: as * `connectionId`'s installation sees it, or else the installation it joined * first. */ export declare function getSlackAgent(db: Database, input: { accountId: string; agentId: string; connectionId?: string | null; }): Promise; export type SlackAgentWriteFields = { name: string; nameKey: string; description: string; avatar: SessionAvatar; instructions: string; }; /** * Create an agent available in one installation (`home` is the * installation's own workspace), with Memory on. `name_taken` when the * installation already has that name; nothing is created then. */ export declare function insertSlackAgent(db: Database, home: SlackAgentHome, input: SlackAgentWriteFields & { /** A fixed id makes a retried create find the agent it already made. */ id?: string; connectionId: string; slackTeamId: string; targetAccountId: string; targetWorkspaceId: string; createdBySubjectId: string; /** `slack` for the card a chat posted in Slack; `app` otherwise. */ origin?: "slack" | "app"; maxPerWorkspace?: number; }): Promise; /** * Change an agent's own fields at an expected version (the agent's). The * home workspace and installation never change. `home` is the installation's * own workspace; `connectionId` picks which installation's record is * returned (else the agent's first installation in `home`). `open` is the * agent's own "Anyone in the organization", in every installation. */ export declare function updateSlackAgent(db: Database, home: SlackAgentHome, input: { agentId: string; connectionId?: string | null; expectedVersion: number; patch: Partial & { knowledgeCollectionId?: string | null; open?: boolean; }; /** Who made the change, recorded on a new revision. */ actorSubjectId?: string | null; }): Promise; /** Remember the agent's Memory collection once it exists. Version-free and idempotent. */ export declare function setSlackAgentKnowledgeCollection(db: Database, home: SlackAgentHome, input: { agentId: string; knowledgeCollectionId: string; connectionId?: string | null; }): Promise; /** * Delete an agent through the Slack agents API: the agent itself, as that * API always did. A shared agent is in every linked Slack installation on its * own, so it can't leave only one. Its channel settings go with it; its chats * stay. `connectionId` only picks which installation's record to look up. */ export declare function deleteSlackAgent(db: Database, home: SlackAgentHome, input: { agentId: string; connectionId?: string | null; }): Promise; /** * Record that a person used an agent, and claim the one-time "next time" hint * for `hintInteractionId` when one is offered. * * Replay-stable: the stored claim is the source of truth, so a retried call for * the same interaction returns the same answer, and two interactions racing for * the hint elect exactly one. */ export declare function touchSlackAgentUserState(db: Database, home: SlackAgentHome, input: { connectionId: string; slackAgentId: string; slackUserId: string; hintInteractionId: string | null; }): Promise<{ showHint: boolean; }>; /** * Claim the one-time open-agent notice for a person and agent: true only for * the chat that claims it (and repairs of that chat), never again after. * Records first use too, like `touchSlackAgentUserState`. */ export declare function claimSlackAgentOpenNotice(db: Database, home: SlackAgentHome, input: { connectionId: string; slackAgentId: string; slackUserId: string; interactionId: string; }): Promise; /** The agents one Slack person has already used through this installation. */ export declare function listSlackAgentIdsUsedBy(db: Database, home: SlackAgentHome, input: { connectionId: string; slackUserId: string; }): Promise; /** * Which agent, if any, a chat was started with (`sessions.agent_id`, or an * older Slack chat's metadata), read from the workspace that owns the chat. * * `agentChat` stays true when the agent was deleted since, so the caller can * keep posting as plain Opengeni rather than falling back to the chat's own * title and avatar. */ export declare function getSlackAgentForSession(db: Database, input: { workspaceId: string; sessionId: string; }): Promise<{ agentChat: boolean; agent: { id: string; name: string; avatar: SessionAvatar; targetWorkspaceId: string; } | null; }>; export type SlackAgentChatSummary = { sessionId: string; title: string | null; /** Null for a chat started in the app. */ slackChannelId: string | null; slackThreadTs: string | null; initiatingSlackUserId: string | null; createdAt: Date; }; /** * Recent shared chats of one agent in its own workspace, newest first. Only * chats everyone in the workspace can open: an Only me chat (a Slack DM * included) belongs to the person who started it. */ export declare function listSlackAgentChats(db: Database, input: { accountId: string; workspaceId: string; slackAgentId: string; excludeSessionId?: string | null; limit: number; }): Promise; /** Mute or unmute occasional update messages for one Slack person. */ export declare function setSlackBotUserUpdatesMuted(db: Database, home: SlackAgentHome, input: { connectionId: string; slackUserId: string; muted: boolean; }): Promise; /** Record that an agent's intro was posted in a channel. Idempotent. */ export declare function recordSlackAgentIntroPost(db: Database, home: SlackAgentHome, input: { connectionId: string; slackAgentId: string; slackChannelId: string; postedBySubjectId: string; }): Promise; /** The channels an agent's intro was posted in (in one installation, given `connectionId`). */ export declare function listSlackAgentIntroChannelIds(db: Database, home: SlackAgentHome, input: { slackAgentId: string; connectionId?: string | null; }): Promise; export type SlackAgentSuggestionRecord = { id: string; connectionId: string; slackAgentId: string; interactionId: string; turnId: string; providerEventId: string; slackTeamId: string; slackUserId: string; slackChannelId: string; slackThreadTs: string; createdAt: Date; }; /** * Record a chat's suggestion to ask an agent, once per turn: the first * suggestion of a turn wins and a retried call returns it. */ export declare function recordSlackAgentSuggestion(db: Database, home: SlackAgentHome, input: Omit): Promise; /** A turn's suggestion, if its chat made one. */ export declare function getSlackAgentSuggestionForTurn(db: Database, home: SlackAgentHome, input: { interactionId: string; turnId: string; }): Promise; /** One suggestion by id, for its button. */ export declare function getSlackAgentSuggestion(db: Database, home: SlackAgentHome, input: { suggestionId: string; }): Promise;