Skip to content

Commit

Permalink
[#2319] Fix Assistant utility types (#2325)
Browse files Browse the repository at this point in the history
  • Loading branch information
misscoded authored Nov 12, 2024
1 parent 6dedf1d commit 2f25b21
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 24 deletions.
39 changes: 20 additions & 19 deletions docs/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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 */
Expand Down Expand Up @@ -112,46 +113,46 @@ 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"] {
--code-link-text: white;
--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);
}
color: var(--event-link-text);
}
10 changes: 5 additions & 5 deletions src/Assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<AssistantThreadContext>;
type SaveThreadContextUtilFn = () => Promise<void>;
type SetStatusFn = (status: string) => Promise<AssistantThreadsSetStatusResponse>;

type SetSuggestedPromptsFn = (
Expand Down Expand Up @@ -310,7 +310,7 @@ function createSay(args: AllAssistantMiddlewareArgs): SayFn {
const { channelId: channel, threadTs: thread_ts, context } = extractThreadInfo(payload);

return async (message: Parameters<SayFn>[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 };

Expand Down
75 changes: 75 additions & 0 deletions test/types/assistant.test-d.ts
Original file line number Diff line number Diff line change
@@ -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<Assistant>(
new Assistant({
threadStarted: asyncNoop,
userMessage: asyncNoop,
}),
);

// threadStarted tests
new Assistant({
userMessage: asyncNoop,
threadStarted: async ({ saveThreadContext }) => {
expectType<void>(await saveThreadContext());
return Promise.resolve();
},
});

// userMessage tests
new Assistant({
userMessage: async ({ getThreadContext }) => {
expectType<AssistantThreadContext>(await getThreadContext());
return Promise.resolve();
},
threadStarted: asyncNoop,
});

// threadContextChanged tests
new Assistant({
userMessage: asyncNoop,
threadStarted: asyncNoop,
threadContextChanged: async ({ event }) => {
expectType<AssistantThreadContext>(event.assistant_thread.context);
return Promise.resolve();
},
});

// threadContextStore tests
new Assistant({
threadContextStore: {
get: async (args) => {
expectType<AllAssistantMiddlewareArgs>(args);
return Promise.resolve({});
},
save: async (args) => {
expectType<AllAssistantMiddlewareArgs>(args);
return Promise.resolve();
},
},
userMessage: asyncNoop,
threadStarted: asyncNoop,
});

0 comments on commit 2f25b21

Please sign in to comment.