diff --git a/docs/src/css/custom.css b/docs/src/css/custom.css index 85adb3538..20c91db1e 100644 --- a/docs/src/css/custom.css +++ b/docs/src/css/custom.css @@ -19,7 +19,8 @@ table tr:nth-child(even) { } /* changing the links to blue for accessibility */ -p a, .markdown a { +p a, +.markdown a { color: var(--slack-cloud-blue); } @@ -53,7 +54,7 @@ a:hover { /* removing ToC line */ .table-of-contents__left-border { border-left: none !important; -} +} /* increasing name of SDK in sidebar */ .sidebar-title { @@ -64,8 +65,8 @@ a:hover { /* removing sidebar line and adding space to match ToC */ .theme-doc-sidebar-container { - border-right: none !important; - margin-right: 2rem; + border-right: none !important; + margin-right: 2rem; } /* announcement bar up top */ @@ -112,17 +113,17 @@ html[data-theme="dark"] .navbar-github-link::before { /* Docs code bubbles */ [data-theme="light"] { - --code-link-background: #CFE9FE; - --code-link-text: rgb(21, 50, 59); + --code-link-background: #cfe9fe; + --code-link-text: rgb(21, 50, 59); - --method-link-background: #CDEFC4; + --method-link-background: #cdefc4; --method-link-text: rgb(0, 41, 0); - --scope-link-background: #FBF3E0; + --scope-link-background: #fbf3e0; --scope-link-text: rgb(63, 46, 0); - --event-link-background: #FDDDE3; - --event-link-text: rgb(74, 21, 75); + --event-link-background: #fddde3; + --event-link-text: rgb(74, 21, 75); } [data-theme="dark"] { @@ -130,28 +131,28 @@ html[data-theme="dark"] .navbar-github-link::before { --method-link-text: white; --scope-link-text: white; --event-link-text: white; - --code-link-background: #1AB9FF50; - --method-link-background: #41B65850; - --scope-link-background: #FCC00350; - --event-link-background: #E3066A50; + --code-link-background: #1ab9ff50; + --method-link-background: #41b65850; + --scope-link-background: #fcc00350; + --event-link-background: #e3066a50; } a code { background-color: var(--code-link-background); - color: var(--code-link-text); + color: var(--code-link-text); } a[href^="https://api.slack.com/methods"] > code { background-color: var(--method-link-background); - color: var(--method-link-text); + color: var(--method-link-text); } a[href^="https://api.slack.com/scopes"] > code { background-color: var(--scope-link-background); - color: var(--scope-link-text); + color: var(--scope-link-text); } a[href^="https://api.slack.com/events"] > code { background-color: var(--event-link-background); - color: var(--event-link-text); -} \ No newline at end of file + color: var(--event-link-text); +} diff --git a/src/Assistant.ts b/src/Assistant.ts index 14d817d19..687d481de 100644 --- a/src/Assistant.ts +++ b/src/Assistant.ts @@ -9,8 +9,6 @@ import { type AssistantThreadContext, type AssistantThreadContextStore, DefaultThreadContextStore, - type GetThreadContextFn, - type SaveThreadContextFn, } from './AssistantThreadContextStore'; import { AssistantInitializationError, AssistantMissingPropertyError } from './errors'; import processMiddleware from './middleware/process'; @@ -30,14 +28,16 @@ export interface AssistantConfig { * Callback utilities */ interface AssistantUtilityArgs { - getThreadContext: GetThreadContextFn; - saveThreadContext: SaveThreadContextFn; + getThreadContext: GetThreadContextUtilFn; + saveThreadContext: SaveThreadContextUtilFn; say: SayFn; setStatus: SetStatusFn; setSuggestedPrompts: SetSuggestedPromptsFn; setTitle: SetTitleFn; } +type GetThreadContextUtilFn = () => Promise; +type SaveThreadContextUtilFn = () => Promise; type SetStatusFn = (status: string) => Promise; type SetSuggestedPromptsFn = ( @@ -310,7 +310,7 @@ function createSay(args: AllAssistantMiddlewareArgs): SayFn { const { channelId: channel, threadTs: thread_ts, context } = extractThreadInfo(payload); return async (message: Parameters[0]) => { - const threadContext = context.channel_id ? context : await args.getThreadContext(args); + const threadContext = context.channel_id ? context : await args.getThreadContext(); const postMessageArgument: ChatPostMessageArguments = typeof message === 'string' ? { text: message, channel, thread_ts } : { ...message, channel, thread_ts }; diff --git a/test/types/assistant.test-d.ts b/test/types/assistant.test-d.ts new file mode 100644 index 000000000..1a1700056 --- /dev/null +++ b/test/types/assistant.test-d.ts @@ -0,0 +1,75 @@ +import { expectError, expectType } from 'tsd'; +import { type AllAssistantMiddlewareArgs, Assistant } from '../../src/Assistant'; +import type { AssistantThreadContext } from '../../src/AssistantThreadContextStore'; + +// Constructor tests +const asyncNoop = () => Promise.resolve(); + +// missing required properties `threadStarted` and `userMessage` +expectError(new Assistant({})); + +// missing required property `threadStarted` +expectError( + new Assistant({ + userMessage: asyncNoop, + }), +); + +// missing required property `userMessage` +expectError( + new Assistant({ + threadStarted: asyncNoop, + }), +); + +// happy construction +expectType( + new Assistant({ + threadStarted: asyncNoop, + userMessage: asyncNoop, + }), +); + +// threadStarted tests +new Assistant({ + userMessage: asyncNoop, + threadStarted: async ({ saveThreadContext }) => { + expectType(await saveThreadContext()); + return Promise.resolve(); + }, +}); + +// userMessage tests +new Assistant({ + userMessage: async ({ getThreadContext }) => { + expectType(await getThreadContext()); + return Promise.resolve(); + }, + threadStarted: asyncNoop, +}); + +// threadContextChanged tests +new Assistant({ + userMessage: asyncNoop, + threadStarted: asyncNoop, + threadContextChanged: async ({ event }) => { + expectType(event.assistant_thread.context); + return Promise.resolve(); + }, +}); + +// threadContextStore tests +new Assistant({ + threadContextStore: { + get: async (args) => { + expectType(args); + return Promise.resolve({}); + }, + save: async (args) => { + expectType(args); + return Promise.resolve(); + }, + }, + userMessage: asyncNoop, + threadStarted: asyncNoop, +});