-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
100 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |