-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add adapter for related prompts (#1641)
- Loading branch information
1 parent
abc0d00
commit 8066983
Showing
20 changed files
with
139 additions
and
3 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
24 changes: 24 additions & 0 deletions
24
packages/x-adapter-platform/src/endpoint-adapters/related-prompts.endpoint-adapter.ts
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,24 @@ | ||
import { endpointAdapterFactory, interpolate } from '@empathyco/x-adapter'; | ||
import { RelatedPromptsRequest, RelatedPromptsResponse } from '@empathyco/x-types'; | ||
import { relatedPromptsRequestMapper } from '../mappers/requests/related-prompts-request.mapper'; | ||
import { relatedPromptsResponseMapper } from '../mappers/responses/related-prompts-response.mapper'; | ||
import { getSearchServiceUrl } from './utils'; | ||
|
||
/** | ||
* This endpoint does not support pagination in the request. | ||
*/ | ||
export const relatedPromptsEndpointAdapter = endpointAdapterFactory< | ||
RelatedPromptsRequest, | ||
RelatedPromptsResponse | ||
>({ | ||
endpoint: from => | ||
interpolate(`${getSearchServiceUrl(from)}/relatedprompts/{extraParams.instance}`, from), | ||
requestMapper: relatedPromptsRequestMapper, | ||
responseMapper: relatedPromptsResponseMapper, | ||
defaultRequestOptions: { | ||
id: 'related-prompts', | ||
parameters: { | ||
internal: true | ||
} | ||
} | ||
}); |
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
12 changes: 12 additions & 0 deletions
12
packages/x-adapter-platform/src/mappers/requests/related-prompts-request.mapper.ts
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,12 @@ | ||
import { schemaMapperFactory } from '@empathyco/x-adapter'; | ||
import { RelatedPromptsRequest } from '@empathyco/x-types'; | ||
import { PlatformRelatedPromptsRequest } from '../../types/requests/related-prompts-request.model'; | ||
import { relatedPromptsRequestSchema } from '../../schemas/requests/related-prompts-request.schema'; | ||
|
||
/** | ||
* Default implementation for the RelatedPromptsRequestMapper. | ||
*/ | ||
export const relatedPromptsRequestMapper = schemaMapperFactory< | ||
RelatedPromptsRequest, | ||
PlatformRelatedPromptsRequest | ||
>(relatedPromptsRequestSchema); |
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
14 changes: 14 additions & 0 deletions
14
packages/x-adapter-platform/src/mappers/responses/related-prompts-response.mapper.ts
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,14 @@ | ||
import { schemaMapperFactory } from '@empathyco/x-adapter'; | ||
import { RelatedPromptsResponse } from '@empathyco/x-types'; | ||
// eslint-disable-next-line max-len | ||
import { PlatformRelatedPromptsResponse } from '../../types/responses/related-prompts-response.model'; | ||
// eslint-disable-next-line max-len | ||
import { relatedPromptsResponseSchema } from '../../schemas/responses/related-prompts-response.schema'; | ||
|
||
/** | ||
* Default implementation for the RelatedPromptsResponseMapper. | ||
*/ | ||
export const relatedPromptsResponseMapper = schemaMapperFactory< | ||
PlatformRelatedPromptsResponse, | ||
RelatedPromptsResponse | ||
>(relatedPromptsResponseSchema); |
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
13 changes: 13 additions & 0 deletions
13
packages/x-adapter-platform/src/schemas/models/related-prompt.schema.ts
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,13 @@ | ||
import { createMutableSchema } from '@empathyco/x-adapter'; | ||
import { RelatedPrompt } from '@empathyco/x-types'; | ||
import { PlatformRelatedPrompt } from '../../types/models/related-prompt.model'; | ||
|
||
/** | ||
* Default implementation for the RelatedPromptSchema. | ||
*/ | ||
export const relatedPromptSchema = createMutableSchema<PlatformRelatedPrompt, RelatedPrompt>({ | ||
modelName: () => 'RelatedPrompt', | ||
nextQueries: 'nextQueries', | ||
suggestionText: 'suggestionText', | ||
type: 'type' | ||
}); |
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
14 changes: 14 additions & 0 deletions
14
packages/x-adapter-platform/src/schemas/requests/related-prompts-request.schema.ts
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,14 @@ | ||
import { createMutableSchema } from '@empathyco/x-adapter'; | ||
import { RelatedPromptsRequest } from '@empathyco/x-types'; | ||
import { PlatformRelatedPromptsRequest } from '../../types/requests/related-prompts-request.model'; | ||
|
||
/** | ||
* Default implementation for the RelatedPromptsRequestSchema. | ||
*/ | ||
export const relatedPromptsRequestSchema = createMutableSchema< | ||
RelatedPromptsRequest, | ||
PlatformRelatedPromptsRequest | ||
>({ | ||
query: 'query', | ||
extraParams: 'extraParams' | ||
}); |
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
18 changes: 18 additions & 0 deletions
18
packages/x-adapter-platform/src/schemas/responses/related-prompts-response.schema.ts
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,18 @@ | ||
import { createMutableSchema } from '@empathyco/x-adapter'; | ||
import { RelatedPromptsResponse } from '@empathyco/x-types'; | ||
// eslint-disable-next-line max-len | ||
import { PlatformRelatedPromptsResponse } from '../../types/responses/related-prompts-response.model'; | ||
import { relatedPromptSchema } from '../models/related-prompt.schema'; | ||
|
||
/** | ||
* Default implementation for the RelatedPromptsResponseSchema. | ||
*/ | ||
export const relatedPromptsResponseSchema = createMutableSchema< | ||
PlatformRelatedPromptsResponse, | ||
RelatedPromptsResponse | ||
>({ | ||
relatedPrompts: { | ||
$path: 'data.relatedprompts', | ||
$subSchema: relatedPromptSchema | ||
} | ||
}); |
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
8 changes: 8 additions & 0 deletions
8
packages/x-adapter-platform/src/types/models/related-prompt.model.ts
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,8 @@ | ||
/** | ||
* Related prompt model for the `platform` API. | ||
*/ | ||
export interface PlatformRelatedPrompt { | ||
nextQueries: string[]; | ||
suggestionText: string; | ||
type: 'SYNTHETIC' | 'CURATED'; | ||
} |
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
10 changes: 10 additions & 0 deletions
10
packages/x-adapter-platform/src/types/requests/related-prompts-request.model.ts
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,10 @@ | ||
import { PlatformExtraParamsRequest, PlatformQueryableRequest } from './request.types'; | ||
|
||
/** | ||
* Request for the `related prompts` endpoint with `extra params`. | ||
* | ||
* @public | ||
*/ | ||
export interface PlatformRelatedPromptsRequest | ||
extends PlatformQueryableRequest, | ||
PlatformExtraParamsRequest {} |
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
11 changes: 11 additions & 0 deletions
11
packages/x-adapter-platform/src/types/responses/related-prompts-response.model.ts
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,11 @@ | ||
import { PlatformRelatedPrompt } from '../models/related-prompt.model'; | ||
|
||
/** | ||
* Response for the `related prompts` endpoint. | ||
*/ | ||
export interface PlatformRelatedPromptsResponse { | ||
data: { | ||
relatedprompts: PlatformRelatedPrompt[]; | ||
}; | ||
status: number; | ||
} |