Skip to content

Commit bc37dfc

Browse files
committed
feat(search): add Search class inside Hyper
1 parent d7d3d59 commit bc37dfc

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/search/@types/index.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
export type MethodParamsOptions = {
2+
contextId: string;
3+
};
4+
5+
type MetaDataType =
6+
| { type: 'airtable'; source: string; name: string }
7+
| { type: 'slack'; source: string; channel: string; name: string }
8+
| { type: 'notion'; source: string; page_id: string; name: string }
9+
| {
10+
type: 'google-doc';
11+
name: string;
12+
when: string;
13+
title: string;
14+
source: { doc_id: string; file_id: string };
15+
}
16+
| {
17+
type: 'document';
18+
file_name: string;
19+
name: string;
20+
page_label: string;
21+
source: string;
22+
}
23+
| {
24+
type: 'web';
25+
name: string;
26+
source: string;
27+
}
28+
| {
29+
type: 'text-snippet';
30+
name: string;
31+
source: string;
32+
}
33+
| {
34+
type: 'Slack Message';
35+
name: string;
36+
source: string;
37+
};
38+
39+
export type SearchResultData = {
40+
page_content: string;
41+
type: 'Document';
42+
metadata: MetaDataType;
43+
};

src/search/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { Search } from './search';

src/search/search.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Hyper } from '../hyper';
2+
import { MethodParamsOptions, SearchResultData } from './@types';
3+
4+
export class Search {
5+
constructor(private readonly hyper: Hyper) {}
6+
7+
async execute(query: string, options?: MethodParamsOptions) {
8+
const payload = options?.contextId
9+
? { query, context_id: options.contextId }
10+
: { query };
11+
12+
const res = await this.hyper.post<SearchResultData[]>({
13+
endpoint: '/search',
14+
body: payload,
15+
});
16+
17+
return res;
18+
}
19+
}

0 commit comments

Comments
 (0)