Skip to content

Commit

Permalink
feat: add types for related prompts (#1640)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorcg88 authored Oct 28, 2024
1 parent 7b90230 commit 9822c28
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/x-adapter-platform/src/platform.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const platformAdapter: PlatformAdapter = {
recommendations: recommendationsEndpointAdapter,
nextQueries: nextQueriesEndpointAdapter,
querySuggestions: querySuggestionsEndpointAdapter,
relatedPrompts: undefined,
relatedTags: relatedTagsEndpointAdapter,
identifierResults: identifierResultsEndpointAdapter,
tagging: taggingEndpointAdapter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface PlatformAdapter extends XComponentsAdapter {
nextQueries: ExtendableEndpointAdapter<NextQueriesRequest, NextQueriesResponse>;
recommendations: ExtendableEndpointAdapter<RecommendationsRequest, RecommendationsResponse>;
querySuggestions: ExtendableEndpointAdapter<QuerySuggestionsRequest, QuerySuggestionsResponse>;
relatedPrompts: any;
relatedTags: ExtendableEndpointAdapter<RelatedTagsRequest, RelatedTagsResponse>;
identifierResults: ExtendableEndpointAdapter<IdentifierResultsRequest, IdentifierResultsResponse>;
semanticQueries: ExtendableEndpointAdapter<SemanticQueriesRequest, SemanticQueriesResponse>;
Expand Down
1 change: 1 addition & 0 deletions packages/x-components/src/__tests__/adapter.dummy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const XComponentsAdapterDummy: XComponentsAdapter = {
popularSearches: jest.fn(),
querySuggestions: jest.fn(),
recommendations: jest.fn(),
relatedPrompts: jest.fn(),
relatedTags: jest.fn(),
search: jest.fn(),
semanticQueries: jest.fn(),
Expand Down
5 changes: 4 additions & 1 deletion packages/x-components/src/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
RelatedTagsResponse,
SearchResponse,
SemanticQueriesResponse,
ExperienceControlsResponse
ExperienceControlsResponse,
RelatedPromptsResponse
} from '@empathyco/x-types';
import { XPluginOptions } from '../plugins';
import { XPlugin } from '../plugins/x-plugin';
Expand Down Expand Up @@ -41,6 +42,7 @@ interface MockedAdapterFeatures {
popularSearches: PopularSearchesResponse;
querySuggestions: QuerySuggestionsResponse;
recommendations: RecommendationsResponse;
relatedPrompts: RelatedPromptsResponse;
relatedTags: RelatedTagsResponse;
search: SearchResponse;
semanticQueries: SemanticQueriesResponse;
Expand Down Expand Up @@ -156,6 +158,7 @@ export function getMockedAdapter(
popularSearches: getMockedAdapterFunction(responseFeatures?.popularSearches!),
querySuggestions: getMockedAdapterFunction(responseFeatures?.querySuggestions!),
recommendations: getMockedAdapterFunction(responseFeatures?.recommendations!),
relatedPrompts: getMockedAdapterFunction(responseFeatures?.relatedPrompts!),
relatedTags: getMockedAdapterFunction(responseFeatures?.relatedTags!),
search: getMockedAdapterFunction(responseFeatures?.search!),
semanticQueries: getMockedAdapterFunction(responseFeatures?.semanticQueries!),
Expand Down
1 change: 1 addition & 0 deletions packages/x-components/src/adapter/e2e-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const e2eAdapter: XComponentsAdapter = {
popularSearches: mockEndpointAdapter('popular-searches'),
querySuggestions: mockEndpointAdapter('query-suggestions'),
recommendations: mockEndpointAdapter('recommendations'),
relatedPrompts: mockEndpointAdapter('related-prompts'),
relatedTags: mockEndpointAdapter('related-tags'),
search: mockEndpointAdapter('search'),
semanticQueries: mockEndpointAdapter('semantic-queries'),
Expand Down
1 change: 1 addition & 0 deletions packages/x-types/src/query-signals/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './next-queries.model';
export * from './next-query.model';
export * from './related-prompt.model';
export * from './related-tag.model';
export * from './semantic-query.model';
13 changes: 13 additions & 0 deletions packages/x-types/src/query-signals/related-prompt.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NamedModel } from '../named-model.model';

/**
* Represents a related prompt.
*/
export interface RelatedPrompt extends NamedModel<'RelatedPrompt'> {
/** The next queries related to the prompt. */
nextQueries: string[];
/** The prompt. */
suggestionText: string;
/** The type of the prompt. */
type: string;
}
1 change: 1 addition & 0 deletions packages/x-types/src/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './next-queries-request.model';
export * from './popular-searches-request.model';
export * from './query-suggestions-request.model';
export * from './recommendations-request.model';
export * from './related-prompts-request.model';
export * from './related-tags-request.model';
export * from './request.model';
export * from './search-request.model';
Expand Down
6 changes: 6 additions & 0 deletions packages/x-types/src/request/related-prompts-request.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ExtraParamsRequest, QueryableRequest } from './request.model';

/**
* Request for Related Prompts endpoint.
*/
export interface RelatedPromptsRequest extends QueryableRequest, ExtraParamsRequest {}
1 change: 1 addition & 0 deletions packages/x-types/src/response/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './next-queries-response.model';
export * from './popular-searches-response.model';
export * from './query-suggestions-response.model';
export * from './recommendations-response.model';
export * from './related-prompts-response.model';
export * from './related-tags-response.model';
export * from './response.model';
export * from './search-response.model';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { RelatedPrompt } from '../query-signals/related-prompt.model';

/**
* Response for the related prompts endpoint.
*/
export interface RelatedPromptsResponse {
relatedPrompts: RelatedPrompt[];
}
11 changes: 11 additions & 0 deletions packages/x-types/src/schemas/related-prompt.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { RelatedPrompt } from '../query-signals';

/**
* Jest schema for validating Related Prompt entities.
*/
export const RelatedPromptSchema: RelatedPrompt = {
modelName: expect.any(String),
nextQueries: expect.any(Array),
suggestionText: expect.any(String),
type: expect.any(String)
};
5 changes: 4 additions & 1 deletion packages/x-types/src/x-components-adapter.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PopularSearchesRequest,
QuerySuggestionsRequest,
RecommendationsRequest,
RelatedPromptsRequest,
RelatedTagsRequest,
SearchRequest,
SemanticQueriesRequest,
Expand All @@ -20,7 +21,8 @@ import {
RelatedTagsResponse,
SearchResponse,
SemanticQueriesResponse,
ExperienceControlsResponse
ExperienceControlsResponse,
RelatedPromptsResponse
} from './response';

export interface XComponentsAdapter {
Expand All @@ -29,6 +31,7 @@ export interface XComponentsAdapter {
nextQueries: EndpointAdapter<NextQueriesRequest, NextQueriesResponse>;
recommendations: EndpointAdapter<RecommendationsRequest, RecommendationsResponse>;
querySuggestions: EndpointAdapter<QuerySuggestionsRequest, QuerySuggestionsResponse>;
relatedPrompts: EndpointAdapter<RelatedPromptsRequest, RelatedPromptsResponse>;
relatedTags: EndpointAdapter<RelatedTagsRequest, RelatedTagsResponse>;
identifierResults: EndpointAdapter<IdentifierResultsRequest, IdentifierResultsResponse>;
tagging: EndpointAdapter<TaggingRequest, void>;
Expand Down

0 comments on commit 9822c28

Please sign in to comment.