UNPKG

@hank.chat/types

Version:
188 lines (187 loc) 8.61 kB
import { ChatCommandInput } from "./io/chat_command_input"; import { ChatCommandOutput } from "./io/chat_command_output"; import { ChatMessageInput } from "./io/chat_message_input"; import { ChatMessageOutput } from "./io/chat_message_output"; import { CronInput } from "./io/cron_input"; import { CronOutput } from "./io/cron_output"; import { DatetimeInput } from "./io/datetime_input"; import { DatetimeOutput } from "./io/datetime_output"; import { DbQueryInput } from "./io/db_query_input"; import { DbQueryOutput } from "./io/db_query_output"; import { GetMetadataInput } from "./io/get_metadata_input"; import { GetMetadataOutput } from "./io/get_metadata_output"; import { InitializeInput } from "./io/initialize_input"; import { InitializeOutput } from "./io/initialize_output"; import { InstallInput } from "./io/install_input"; import { InstallOutput } from "./io/install_output"; import { InstructPluginInput } from "./io/instruct_plugin_input"; import { InstructPluginOutput } from "./io/instruct_plugin_output"; import { LoadPluginInput } from "./io/load_plugin_input"; import { LoadPluginOutput } from "./io/load_plugin_output"; import { OneShotInput } from "./io/one_shot_input"; import { OneShotOutput } from "./io/one_shot_output"; import { ReactInput } from "./io/react_input"; import { ReactOutput } from "./io/react_output"; import { ReloadPluginInput } from "./io/reload_plugin_input"; import { ReloadPluginOutput } from "./io/reload_plugin_output"; import { ScheduledJobInput } from "./io/scheduled_job_input"; import { ScheduledJobOutput } from "./io/scheduled_job_output"; import { SendMessageInput } from "./io/send_message_input"; import { SendMessageOutput } from "./io/send_message_output"; import { ShutdownInput } from "./io/shutdown_input"; import { ShutdownOutput } from "./io/shutdown_output"; import { UnloadPluginInput } from "./io/unload_plugin_input"; import { UnloadPluginOutput } from "./io/unload_plugin_output"; /** [Internal] The underlying core Hank service. Should only be used by internal code. */ export interface Hank { /** [Internal] Send a chat message to Hank. */ send_message(request: SendMessageInput): Promise<SendMessageOutput>; /** [Internal] Send a reaction to Hank. */ react(request: ReactInput): Promise<ReactOutput>; /** [Internal] Send a database query to hank. */ db_query(request: DbQueryInput): Promise<DbQueryOutput>; /** [Internal] Send a cron job to hank. */ cron(request: CronInput): Promise<CronOutput>; /** [Internal] Send a one shot job to hank. */ one_shot(request: OneShotInput): Promise<OneShotOutput>; /** [Internal] Get the current local datetime from hank. */ datetime(request: DatetimeInput): Promise<DatetimeOutput>; /** * [Internal] Send a reload plugin request to hank. * * Requires EscalatedPrivilege::RELOAD_PLUGIN */ reload_plugin(request: ReloadPluginInput): Promise<ReloadPluginOutput>; /** * [Internal] Send a load plugin request to hank. * * Requires EscalatedPrivilege::LOAD_PLUGIN */ load_plugin(request: LoadPluginInput): Promise<LoadPluginOutput>; /** * [Internal] Send an unload plugin request to hank. * * Requires EscalatedPrivilege::UNLOAD_PLUGIN */ unload_plugin(request: UnloadPluginInput): Promise<UnloadPluginOutput>; /** * [Internal] Send an instruct plugin request to hank. * * Requires EscalatedPrivilege::INSTRUCT_PLUGIN */ instruct_plugin(request: InstructPluginInput): Promise<InstructPluginOutput>; } export declare const HankServiceName = "hank.Hank"; export declare class HankClientImpl implements Hank { private readonly rpc; private readonly service; constructor(rpc: Rpc, opts?: { service?: string; }); send_message(request: SendMessageInput): Promise<SendMessageOutput>; react(request: ReactInput): Promise<ReactOutput>; db_query(request: DbQueryInput): Promise<DbQueryOutput>; cron(request: CronInput): Promise<CronOutput>; one_shot(request: OneShotInput): Promise<OneShotOutput>; datetime(request: DatetimeInput): Promise<DatetimeOutput>; reload_plugin(request: ReloadPluginInput): Promise<ReloadPluginOutput>; load_plugin(request: LoadPluginInput): Promise<LoadPluginOutput>; unload_plugin(request: UnloadPluginInput): Promise<UnloadPluginOutput>; instruct_plugin(request: InstructPluginInput): Promise<InstructPluginOutput>; } /** The underlying interface for a Hank plugin. */ export interface Plugin { /** * [Internal] Handle InstructionKind::GetMetadata * * This is the first function called after the entry point to retrieve the * plugins metadata. */ handle_get_metadata(request: GetMetadataInput): Promise<GetMetadataOutput>; /** * [Internal] Handle InstructionKind::Install * * If the plugin registers an install handler, the plugin service will call * out to it. * * The install function is only called a single time when the plugin is * installed. * * The install function registered by the plugin should be used to create * database tables and other tasks that may only need to happen a single time * in a plugins lifetime. */ handle_install(request: InstallInput): Promise<InstallOutput>; /** * [Internal] Handle InstructionKind::Initialize * * If the plugin registers an initialize handler, the plugin service will * call out to it. * * The initialize function registered by the plugin should be used to execute * any functionality that should be run every time the plugin is loaded by * hank, e.g. scheduling jobs, sending a message to a channel, etc. */ handle_initialize(request: InitializeInput): Promise<InitializeOutput>; /** * [Internal] Handle InstructionKind::Shutdown * * If the plugin registers a shutdown handler, the plugin service will call * out to it. * * The shutdown function registered by the plugin should be used to execute * any functions necessary to gracefully shut down the plugin. */ handle_shutdown(request: ShutdownInput): Promise<ShutdownOutput>; /** * [Internal] Handle InstructionKind::ChatMessage * * If the plugin registers a chat message handler, the plugin service will * call out to it. * * The message handler function registered by the plugin should be used to * execute functionality that functions on general chat messages. Plugins * should prefer registering chat commands in their metadata and using the * chat command handler over custom command parsing implementations. */ handle_chat_message(request: ChatMessageInput): Promise<ChatMessageOutput>; /** * [Internal] Handle InstructionKind::ChatCommand * * If the plugin registers a chat command handler, the plugin service will * call out to it. * * The chat command handler function registered by the plugin should be used * to execute custom plugin commands. Plugins can register their commands in * the plugin metadata. See hank.plugin.Metadata for more information. */ handle_chat_command(request: ChatCommandInput): Promise<ChatCommandOutput>; /** * [Internal] Handle InstructionKind::ScheduledJob * * If the plugin registers cron or one shot jobs, the plugin service will * receive instruction from hank to execute the scheduled job. * * See your PDK documentation for information on registering cron and one * shot jobs. */ handle_scheduled_job(request: ScheduledJobInput): Promise<ScheduledJobOutput>; } export declare const PluginServiceName = "hank.Plugin"; export declare class PluginClientImpl implements Plugin { private readonly rpc; private readonly service; constructor(rpc: Rpc, opts?: { service?: string; }); handle_get_metadata(request: GetMetadataInput): Promise<GetMetadataOutput>; handle_install(request: InstallInput): Promise<InstallOutput>; handle_initialize(request: InitializeInput): Promise<InitializeOutput>; handle_shutdown(request: ShutdownInput): Promise<ShutdownOutput>; handle_chat_message(request: ChatMessageInput): Promise<ChatMessageOutput>; handle_chat_command(request: ChatCommandInput): Promise<ChatCommandOutput>; handle_scheduled_job(request: ScheduledJobInput): Promise<ScheduledJobOutput>; } export interface Rpc { request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>; }