-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#2319] Fix Assistant utility types #2325
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<AssistantThreadContext>; | ||
type SaveThreadContextUtilFn = () => Promise<void>; | ||
type SetStatusFn = (status: string) => Promise<AssistantThreadsSetStatusResponse>; | ||
|
||
type SetSuggestedPromptsFn = ( | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohhh nice catch. This took me a while to parse - I kept confusing the middleware arguments' |
||
const threadContext = context.channel_id ? context : await args.getThreadContext(); | ||
const postMessageArgument: ChatPostMessageArguments = | ||
typeof message === 'string' ? { text: message, channel, thread_ts } : { ...message, channel, thread_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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @filmaj Covered all class props, but let me know if I'm missing anything glaring or need to adjust the approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests look great, they cover all the utility functions mentioned in #2319 so I'm happy 👍 |
||
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, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite the ongoing issue with non-ack'd events, it appears to work as expected. This update corresponds to the enrich function. I believe I've gotten the pass-through correct:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me and this signature matches the assertion expectations in the matching tests 💯