fix(svelte): Respect cody ignore settings#63677
Conversation
2c58f8b to
012fa86
Compare
There was a problem hiding this comment.
There was a problem hiding this comment.
This commit adds support for cody ignore settings to the SvelteKit app. When cody is disabled on the instance or for the user, the cody button and sidebar are not shown anymore. Likewise if the repository is excluded from cody, the buttons and sidebar are not shown. The implementation was inspired by `useCodyIngore.ts`, but simplified for use in the SvelteKit app. It seems that the file exclusion logic is not actually used for the sidebar and thus was omitted. It also seems that for the sidebar itself we are only checking whether the current repository is excluded or not, which lets us simplify the whole setup and simply pass a boolean (store) from the data loader, indicating whether cody is enabled or not. Furthermore I introduced zod to validate that the value of `codyContextFilters.raw`, which is typed as `JSONValue`, has the expected shape. We've run into issues in the past where such values have just been cast to the expected Typescript type. zod adds runtime validation. Note that we use JSON schema base validation (with ajv) in some places, but that requires importing and sending the whole JSON schema to the client, which is something I'd like to avoid. The advantage JSON schema is that we also use it for generating Go code. We should find a way to use JSON schema but generate specific validators at build time. There are also other libraries that do runtime validation and are smaller but they don't necessarily allow asynchronous validation (which we want to do because we only want to import the `re2js` library when necessary).
3756701 to
14d33ca
Compare
vovakulikov
left a comment
There was a problem hiding this comment.
Very cool approach with zod validation.
| return | ||
| } | ||
|
|
||
| CodyContextFilters.safeParseAsync(filters).then(result => { |
There was a problem hiding this comment.
Very cool, maybe we could use the same approach from setting cascade later in other PRs
There was a problem hiding this comment.
Possibly... as I mentioned we use ajv in some places, which makes sense considering that the JSON schema can be shared between the client and the backend. But I also think that importing (i.e. sending) the whole schema to the client is wasteful. I'd like to find a solution where we can generate validation code at build time.
Then again, something like 'typing' the strings as re2 expressions and validating them is probably not possible with JSON schema alone.
Based on #63677 Closes srch-691 Closes srch-695 This adds the cody button to the repo "home page" so that cody can be opened from there. This commit also makes it so that the cody button is hidden when the sidebar opens (like in the React app) and it adds a fixed height to the various headers so that they align well with the sidebar header and don't change size when the cody button is hidden when the sidebar is open. ## Test plan Manual testing.
This commit adds support for cody ignore settings to the SvelteKit app. When cody is disabled on the instance or for the user, the cody button and sidebar are not shown anymore.
Likewise if the repository is excluded from cody, the buttons and sidebar are not shown.
The implementation was inspired by
useCodyIngore.ts, but simplified for use in the SvelteKit app. It seems that the file exclusion logic is not actually used for the sidebar and thus was omitted. It also seems that for the sidebar itself we are only checking whether the current repository is excluded or not, which lets us simplify the whole setup and simply pass a boolean (store) from the data loader, indicating whether cody is enabled or not.Furthermore I introduced zod to validate that the value of
codyContextFilters.raw, which is typed asJSONValue, has the expected shape. We've run into issues in the past where such values have just been cast to the expected Typescript type. zod adds runtime validation.Note that we use JSON schema base validation (with
ajv) in some places, but that requires importing and sending the whole JSON schema to the client, which is something I'd like to avoid. The advantage JSON schema is that we also use it for generating Go code. We should find a way to use JSON schema but generate specific validators at build time.There are also other libraries that do runtime validation and are smaller but they don't necessarily allow asynchronous validation (which we want to do because we only want to import the
re2jslibrary when necessary; of course we could organize the code differently but it's nice to be able to encapsulate this logic)Test plan
Manual testing and new integration tests.