Skip to content

Commit 2ecccb1

Browse files
Dan JonesDan Jones
authored andcommitted
Add new QuerySort object to search responses
1 parent f5c2649 commit 2ecccb1

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/query/response/api-response.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ export type ApiAskModeResponse = {
1919
sources?: ApiSource[];
2020
};
2121

22+
export type ApiQuerySort = {
23+
property_name: string;
24+
order: "ascending" | "descending";
25+
tie_break?: ApiQuerySort;
26+
};
27+
2228
export type ApiSearch = {
2329
query?: string;
2430
filters?: ApiPropertyFilter | ApiFilterAndOr;
2531
collection: string;
32+
sort_property?: ApiQuerySort;
2633
};
2734

2835
export type ApiAggregation = {

src/query/response/response-mapping.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
AskModeResponse,
1717
Search,
1818
ModelUnitUsage,
19+
QuerySort,
1920
} from "./response.js";
2021

2122
import {
@@ -32,6 +33,7 @@ import {
3233
ApiAskModeResponse,
3334
ApiSearch,
3435
ApiModelUnitUsage,
36+
ApiQuerySort,
3537
} from "./api-response.js";
3638

3739
import { ServerSentEvent } from "./server-sent-events.js";
@@ -67,8 +69,17 @@ const mapSearches = (searches: ApiSearch[]): Search[] =>
6769
query: search.query,
6870
filters: search.filters ? mapFilter(search.filters) : undefined,
6971
collection: search.collection,
72+
sortProperty: search.sort_property
73+
? mapQuerySort(search.sort_property)
74+
: undefined,
7075
}));
7176

77+
const mapQuerySort = (sort: ApiQuerySort): QuerySort => ({
78+
propertyName: sort.property_name,
79+
order: sort.order,
80+
tieBreak: sort.tie_break ? mapQuerySort(sort.tie_break) : undefined,
81+
});
82+
7283
const mapUsage = (usage: ApiModelUnitUsage): ModelUnitUsage => ({
7384
modelUnits: usage.model_units,
7485
usageInPlan: usage.usage_in_plan,

src/query/response/response.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type Search = {
1717
query?: string;
1818
filters?: PropertyFilter | FilterAndOr;
1919
collection: string;
20+
sortProperty?: QuerySort;
2021
};
2122

2223
export type Aggregation = {
@@ -37,6 +38,12 @@ export type ModelUnitUsage = {
3738
remainingPlanRequests: number;
3839
};
3940

41+
export type QuerySort = {
42+
propertyName: string;
43+
order: "ascending" | "descending";
44+
tieBreak?: QuerySort;
45+
};
46+
4047
export type QueryAgentResponse = {
4148
outputType: "finalState";
4249
originalQuery: string;

0 commit comments

Comments
 (0)