@dxos/plugin-search 0.8.4-main.f9ba587 → 0.8.4-main.fffef41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{app-graph-builder-V667YGDS.mjs → app-graph-builder-HQR6P4C7.mjs} +17 -16
- package/dist/lib/browser/app-graph-builder-HQR6P4C7.mjs.map +7 -0
- package/dist/lib/browser/chunk-GN2FSWTM.mjs +22 -0
- package/dist/lib/browser/chunk-GN2FSWTM.mjs.map +7 -0
- package/dist/lib/browser/{chunk-2QKDUXCH.mjs → chunk-TCVYYI44.mjs} +5 -5
- package/dist/lib/browser/chunk-TCVYYI44.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-L7BUHKLC.mjs → browser/chunk-ZEP4O5SU.mjs} +111 -12
- package/dist/lib/browser/chunk-ZEP4O5SU.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +12 -12
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/intent-resolver-UYQA6UUQ.mjs +22 -0
- package/dist/lib/browser/{intent-resolver-SPX5JVY7.mjs.map → intent-resolver-UYQA6UUQ.mjs.map} +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-LV7ZVI2K.mjs +293 -0
- package/dist/lib/browser/react-surface-LV7ZVI2K.mjs.map +7 -0
- package/dist/types/src/SearchPlugin.d.ts +1 -1
- package/dist/types/src/SearchPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +3 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/Search.stories.d.ts +13 -12
- package/dist/types/src/components/Search.stories.d.ts.map +1 -1
- package/dist/types/src/components/SearchDialog.d.ts +1 -1
- package/dist/types/src/components/SearchDialog.d.ts.map +1 -1
- package/dist/types/src/components/SearchMain.d.ts +4 -5
- package/dist/types/src/components/SearchMain.d.ts.map +1 -1
- package/dist/types/src/components/SearchResults/SearchResults.d.ts +9 -9
- package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +1 -1
- package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts +12 -8
- package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts.map +1 -1
- package/dist/types/src/components/Searchbar/Searchbar.d.ts +5 -9
- package/dist/types/src/components/Searchbar/Searchbar.d.ts.map +1 -1
- package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts +10 -8
- package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/sync.d.ts.map +1 -1
- package/dist/types/src/hooks/useGlobalSearch.d.ts.map +1 -1
- package/dist/types/src/hooks/useWebSearch.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/search/exa.d.ts +1 -3
- package/dist/types/src/search/exa.d.ts.map +1 -1
- package/dist/types/src/types/action.d.ts +3 -3
- package/dist/types/src/types/action.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +40 -41
- package/src/SearchPlugin.tsx +43 -44
- package/src/capabilities/app-graph-builder.ts +15 -14
- package/src/capabilities/intent-resolver.ts +1 -1
- package/src/capabilities/react-surface.tsx +1 -4
- package/src/components/Search.stories.tsx +14 -16
- package/src/components/SearchDialog.tsx +23 -11
- package/src/components/SearchMain.tsx +20 -28
- package/src/components/SearchResults/SearchResults.stories.tsx +20 -18
- package/src/components/SearchResults/SearchResults.tsx +46 -49
- package/src/components/Searchbar/Searchbar.stories.tsx +8 -8
- package/src/components/Searchbar/Searchbar.tsx +26 -47
- package/src/hooks/index.ts +2 -0
- package/src/hooks/sync.test.ts +1 -1
- package/src/hooks/sync.ts +6 -5
- package/src/hooks/useGlobalSearch.tsx +3 -2
- package/src/hooks/useSearchResults.ts +4 -4
- package/src/hooks/useWebSearch.ts +4 -9
- package/src/meta.ts +8 -5
- package/src/search/exa.test.ts +8 -31
- package/src/search/exa.ts +136 -165
- package/src/types/action.tsx +3 -3
- package/src/types/index.ts +1 -1
- package/dist/lib/browser/app-graph-builder-V667YGDS.mjs.map +0 -7
- package/dist/lib/browser/chunk-2QKDUXCH.mjs.map +0 -7
- package/dist/lib/browser/chunk-KNS62YL2.mjs +0 -20
- package/dist/lib/browser/chunk-KNS62YL2.mjs.map +0 -7
- package/dist/lib/browser/chunk-LPB2XRYL.mjs +0 -190
- package/dist/lib/browser/chunk-LPB2XRYL.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-SPX5JVY7.mjs +0 -22
- package/dist/lib/browser/react-surface-HMXHJSLE.mjs +0 -642
- package/dist/lib/browser/react-surface-HMXHJSLE.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-IZHM72QQ.mjs +0 -78
- package/dist/lib/node-esm/app-graph-builder-IZHM72QQ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-L7BUHKLC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-N5SNYFMK.mjs +0 -22
- package/dist/lib/node-esm/chunk-N5SNYFMK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-Y7BGRQH5.mjs +0 -22
- package/dist/lib/node-esm/chunk-Y7BGRQH5.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -113
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-MFPFD3XC.mjs +0 -23
- package/dist/lib/node-esm/intent-resolver-MFPFD3XC.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/react-surface-WHU5EEAQ.mjs +0 -643
- package/dist/lib/node-esm/react-surface-WHU5EEAQ.mjs.map +0 -7
|
@@ -4,12 +4,57 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type FC, forwardRef } from 'react';
|
|
6
6
|
|
|
7
|
+
import { Surface } from '@dxos/app-framework/react';
|
|
8
|
+
import { Obj } from '@dxos/echo';
|
|
7
9
|
import { Card } from '@dxos/react-ui-stack';
|
|
8
10
|
import { ghostHover } from '@dxos/react-ui-theme';
|
|
9
11
|
|
|
10
|
-
import { SEARCH_RESULT } from '../../meta';
|
|
11
12
|
import { type SearchResult } from '../../types';
|
|
12
13
|
|
|
14
|
+
export type SearchResultsProps = {
|
|
15
|
+
items: SearchResult[];
|
|
16
|
+
match?: RegExp;
|
|
17
|
+
selected?: string;
|
|
18
|
+
onSelect?: (id: string) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// TODO(burdon): Key cursor up/down.
|
|
22
|
+
// TODO(burdon): Use stack (should be virtualized).
|
|
23
|
+
export const SearchResults = ({ items }: SearchResultsProps) => {
|
|
24
|
+
return (
|
|
25
|
+
<div className='overflow-y-auto'>
|
|
26
|
+
<div className='flex flex-col'>
|
|
27
|
+
{items
|
|
28
|
+
// TODO(burdon): Hack to reduce noise from system objects.
|
|
29
|
+
.filter((item) => Obj.getLabel(item.object))
|
|
30
|
+
.map((item) => (
|
|
31
|
+
<div key={item.id} role='none' className='pli-2 first:pbs-2 pbe-2'>
|
|
32
|
+
<Surface role='card' data={{ subject: item.object }} limit={1} />
|
|
33
|
+
</div>
|
|
34
|
+
))}
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type SearchItemProps = SearchResult & { selected: boolean } & Pick<SearchResultsProps, 'onSelect'>;
|
|
41
|
+
|
|
42
|
+
export const SearchItem = forwardRef<HTMLDivElement, SearchItemProps>((item, forwardRef) => {
|
|
43
|
+
const { id, objectType, label, snippet, match, selected, onSelect } = item;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Card.StaticRoot
|
|
47
|
+
ref={forwardRef}
|
|
48
|
+
classNames={['mx-2 mt-2 cursor-pointer', selected && '!bg-activeSurface', ghostHover]}
|
|
49
|
+
onClick={() => onSelect?.(id)}
|
|
50
|
+
>
|
|
51
|
+
{objectType && <div className='text-xs text-neutral-400 ml-4'>{objectType}</div>}
|
|
52
|
+
<Card.Heading>{label ?? 'Untitled'}</Card.Heading>
|
|
53
|
+
{snippet && <Snippet text={snippet} match={match} />}
|
|
54
|
+
</Card.StaticRoot>
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
13
58
|
export const Snippet: FC<{ text: string; match?: RegExp }> = ({ text, match }) => {
|
|
14
59
|
let content = <>{text}</>;
|
|
15
60
|
if (match) {
|
|
@@ -36,51 +81,3 @@ export const Snippet: FC<{ text: string; match?: RegExp }> = ({ text, match }) =
|
|
|
36
81
|
|
|
37
82
|
return <span className='text-xs mb-1 line-clamp-3 text-neutral-300'>{content}</span>;
|
|
38
83
|
};
|
|
39
|
-
|
|
40
|
-
export type SearchItemProps = SearchResult & { selected: boolean } & Pick<SearchResultsProps, 'onSelect'>;
|
|
41
|
-
|
|
42
|
-
export const SearchItem = forwardRef<HTMLDivElement, SearchItemProps>((item, forwardRef) => {
|
|
43
|
-
const { id, objectType, label, snippet, match, selected, onSelect } = item;
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<Card.StaticRoot
|
|
47
|
-
ref={forwardRef}
|
|
48
|
-
classNames={['mx-2 mt-2 cursor-pointer', selected && '!bg-activeSurface', ghostHover]}
|
|
49
|
-
onClick={() => onSelect?.(id)}
|
|
50
|
-
>
|
|
51
|
-
{objectType && (
|
|
52
|
-
<>
|
|
53
|
-
<div className='text-xs text-neutral-400 ml-4'>{objectType}</div>
|
|
54
|
-
</>
|
|
55
|
-
)}
|
|
56
|
-
<Card.Heading>{label ?? 'Untitled'}</Card.Heading>
|
|
57
|
-
{snippet && <Snippet text={snippet} match={match} />}
|
|
58
|
-
</Card.StaticRoot>
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export type SearchResultsProps = {
|
|
63
|
-
match?: RegExp;
|
|
64
|
-
items: SearchResult[];
|
|
65
|
-
selected?: string;
|
|
66
|
-
onSelect?: (id: string) => void;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// TODO(burdon): Key cursor up/down.
|
|
70
|
-
export const SearchResults = ({ items, selected, onSelect }: SearchResultsProps) => {
|
|
71
|
-
return (
|
|
72
|
-
<div className='flex flex-col grow overflow-y-auto'>
|
|
73
|
-
<div className='flex flex-col'>
|
|
74
|
-
{items.map((item) => (
|
|
75
|
-
<SearchItem
|
|
76
|
-
key={item.id}
|
|
77
|
-
type={SEARCH_RESULT}
|
|
78
|
-
{...item}
|
|
79
|
-
onSelect={onSelect}
|
|
80
|
-
selected={selected === item.id}
|
|
81
|
-
/>
|
|
82
|
-
))}
|
|
83
|
-
</div>
|
|
84
|
-
</div>
|
|
85
|
-
);
|
|
86
|
-
};
|
|
@@ -2,26 +2,26 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { Searchbar } from './Searchbar';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const meta: Meta<SearchbarProps> = {
|
|
11
|
+
const meta = {
|
|
14
12
|
title: 'plugins/plugin-search/Searchbar',
|
|
15
13
|
component: Searchbar,
|
|
16
14
|
decorators: [withTheme],
|
|
17
15
|
parameters: {
|
|
18
16
|
layout: 'centered',
|
|
19
17
|
},
|
|
20
|
-
}
|
|
18
|
+
} satisfies Meta<typeof Searchbar>;
|
|
21
19
|
|
|
22
20
|
export default meta;
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
type Story = StoryObj<typeof meta>;
|
|
23
|
+
|
|
24
|
+
export const Default: Story = {
|
|
25
25
|
args: {
|
|
26
26
|
placeholder: 'Search...',
|
|
27
27
|
},
|
|
@@ -2,68 +2,47 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import React, { type KeyboardEvent, useEffect, useRef, useState } from 'react';
|
|
5
|
+
import React, { type KeyboardEvent, useCallback, useRef } from 'react';
|
|
7
6
|
|
|
8
|
-
import { Input, type TextInputProps } from '@dxos/react-ui';
|
|
9
|
-
import { getSize, mx } from '@dxos/react-ui-theme';
|
|
7
|
+
import { Input, type TextInputProps, type ThemedClassName, Toolbar, useControlledState } from '@dxos/react-ui';
|
|
10
8
|
|
|
11
|
-
export type SearchbarProps =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
delay?: number;
|
|
20
|
-
};
|
|
9
|
+
export type SearchbarProps = ThemedClassName<
|
|
10
|
+
Pick<TextInputProps, 'variant' | 'placeholder'> & {
|
|
11
|
+
delay?: number;
|
|
12
|
+
value?: string;
|
|
13
|
+
onChange?: (text?: string) => void;
|
|
14
|
+
onSubmit?: (text?: string) => void;
|
|
15
|
+
}
|
|
16
|
+
>;
|
|
21
17
|
|
|
22
|
-
export const Searchbar = ({
|
|
18
|
+
export const Searchbar = ({ classNames, variant, placeholder, value, onChange, onSubmit }: SearchbarProps) => {
|
|
19
|
+
const [text, setText] = useControlledState(value, onChange);
|
|
23
20
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
24
|
-
const [text, setText] = useState(value);
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
setText(value);
|
|
27
|
-
}, [value]);
|
|
28
|
-
const handleChange = (text?: string) => {
|
|
29
|
-
setText(text);
|
|
30
|
-
onChange?.(text);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const handleReset = () => {
|
|
34
|
-
handleChange(undefined);
|
|
35
|
-
inputRef.current?.focus();
|
|
36
|
-
};
|
|
37
21
|
|
|
38
|
-
const handleKeyDown = (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
22
|
+
const handleKeyDown = useCallback(
|
|
23
|
+
(event: KeyboardEvent<HTMLInputElement>) => {
|
|
24
|
+
switch (event.key) {
|
|
25
|
+
case 'Enter':
|
|
26
|
+
onSubmit?.(text);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
[text, onSubmit],
|
|
31
|
+
);
|
|
48
32
|
|
|
49
33
|
return (
|
|
50
|
-
<
|
|
34
|
+
<Toolbar.Root classNames={classNames}>
|
|
51
35
|
<Input.Root>
|
|
52
36
|
<Input.TextInput
|
|
53
37
|
ref={inputRef}
|
|
54
38
|
placeholder={placeholder}
|
|
39
|
+
autoFocus
|
|
55
40
|
variant={variant}
|
|
56
41
|
value={text ?? ''}
|
|
57
|
-
|
|
58
|
-
onChange={({ target }) => handleChange(target.value)}
|
|
42
|
+
onChange={({ target }) => setText(target.value)}
|
|
59
43
|
onKeyDown={handleKeyDown}
|
|
60
44
|
/>
|
|
61
|
-
|
|
62
|
-
{/* TODO(burdon): Margin should be density specific. */}
|
|
63
|
-
<div role='button' className='-ml-7 p-0 cursor-pointer' onClick={handleReset}>
|
|
64
|
-
<MagnifyingGlass className={getSize(5)} />
|
|
65
|
-
</div>
|
|
66
45
|
</Input.Root>
|
|
67
|
-
</
|
|
46
|
+
</Toolbar.Root>
|
|
68
47
|
);
|
|
69
48
|
};
|
package/src/hooks/index.ts
CHANGED
package/src/hooks/sync.test.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Client } from '@dxos/client';
|
|
8
|
-
import {
|
|
8
|
+
import { Filter, Obj, Type } from '@dxos/echo';
|
|
9
9
|
import { faker } from '@dxos/random';
|
|
10
10
|
|
|
11
11
|
import { filterObjectsSync } from './sync';
|
package/src/hooks/sync.ts
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
6
7
|
|
|
7
8
|
import { Obj } from '@dxos/echo';
|
|
8
|
-
import {
|
|
9
|
+
import { Text } from '@dxos/schema';
|
|
9
10
|
|
|
10
11
|
import { type SearchResult } from '../types';
|
|
11
12
|
|
|
@@ -45,7 +46,7 @@ export const filterObjectsSync = <T extends Record<string, any>>(objects: T[], m
|
|
|
45
46
|
|
|
46
47
|
return objects.reduce<SearchResult[]>((results, object) => {
|
|
47
48
|
// TODO(burdon): Hack to ignore Text objects.
|
|
48
|
-
if (object instanceof
|
|
49
|
+
if (object instanceof Text.Text) {
|
|
49
50
|
return results;
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -63,7 +64,7 @@ export const filterObjectsSync = <T extends Record<string, any>>(objects: T[], m
|
|
|
63
64
|
match,
|
|
64
65
|
// TODO(burdon): Truncate.
|
|
65
66
|
// TODO(burdon): Issue with sketch documents.
|
|
66
|
-
snippet: value !== label ? value : fields.content ?? fields.description ?? undefined,
|
|
67
|
+
snippet: value !== label ? value : (fields.content ?? fields.description ?? undefined),
|
|
67
68
|
object,
|
|
68
69
|
});
|
|
69
70
|
|
|
@@ -111,7 +112,7 @@ const getKeys = (object: Record<string, unknown>): string[] => {
|
|
|
111
112
|
export const mapObjectToTextFields = <T extends Record<string, unknown>>(object: T): TextFields => {
|
|
112
113
|
return getKeys(object).reduce<TextFields>((fields, key) => {
|
|
113
114
|
const value = object[key] as any;
|
|
114
|
-
if (typeof value === 'string' || value instanceof
|
|
115
|
+
if (typeof value === 'string' || value instanceof Text.Text) {
|
|
115
116
|
try {
|
|
116
117
|
fields[key] = String(value);
|
|
117
118
|
} catch (err) {
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, {
|
|
5
|
+
import React, { type PropsWithChildren, createContext, useContext, useMemo, useState } from 'react';
|
|
6
6
|
|
|
7
7
|
import { raise } from '@dxos/debug';
|
|
8
8
|
|
|
9
|
-
import { filterObjectsSync, queryStringToMatch } from './sync';
|
|
10
9
|
import { type SearchResult } from '../types';
|
|
11
10
|
|
|
11
|
+
import { filterObjectsSync, queryStringToMatch } from './sync';
|
|
12
|
+
|
|
12
13
|
type SearchContextType = {
|
|
13
14
|
match?: RegExp;
|
|
14
15
|
setMatch?: (text?: string) => void;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { yieldOrContinue } from 'main-thread-scheduling';
|
|
6
6
|
import { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Text } from '@dxos/schema';
|
|
9
9
|
|
|
10
10
|
// TODO(thure): Deprecate search-sync, move still-relevant utilities elsewhere (here, probably).
|
|
11
11
|
import { mapObjectToTextFields, queryStringToMatch } from './sync';
|
|
@@ -20,7 +20,7 @@ export const filterObjects = async <T extends Record<string, any>>(
|
|
|
20
20
|
}
|
|
21
21
|
await Promise.all(
|
|
22
22
|
objects
|
|
23
|
-
.filter((object) => !(object instanceof
|
|
23
|
+
.filter((object) => !(object instanceof Text.Text))
|
|
24
24
|
.map(async (object) => {
|
|
25
25
|
await yieldOrContinue('interactive');
|
|
26
26
|
const fields = mapObjectToTextFields<T>(object);
|
|
@@ -47,14 +47,14 @@ export const useSearchResults = <T extends Record<string, any>>(
|
|
|
47
47
|
|
|
48
48
|
useEffect(() => {
|
|
49
49
|
setPending(!!(objects && queryString));
|
|
50
|
-
const
|
|
50
|
+
const timeout = setTimeout(async () => {
|
|
51
51
|
const nextResults =
|
|
52
52
|
objects && queryString ? await filterObjects(objects, queryStringToMatch(queryString)) : new Map();
|
|
53
53
|
setResults(nextResults);
|
|
54
54
|
setPending(false);
|
|
55
55
|
}, delay);
|
|
56
56
|
|
|
57
|
-
return () => clearTimeout(
|
|
57
|
+
return () => clearTimeout(timeout);
|
|
58
58
|
}, [queryString, objects]);
|
|
59
59
|
|
|
60
60
|
return [pending, results];
|
|
@@ -4,23 +4,19 @@
|
|
|
4
4
|
|
|
5
5
|
import { useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { AI_SERVICE_ENDPOINT, EXA_API_KEY } from '@dxos/ai/testing';
|
|
7
|
+
import { EXA_API_KEY } from '@dxos/ai/testing';
|
|
9
8
|
import { Obj } from '@dxos/echo';
|
|
10
9
|
import { type DXN } from '@dxos/keys';
|
|
11
10
|
import { log } from '@dxos/log';
|
|
12
11
|
import { getIconAnnotation } from '@dxos/schema';
|
|
13
12
|
import { Testing } from '@dxos/schema/testing';
|
|
14
13
|
|
|
15
|
-
import { getStringProperty } from './sync';
|
|
16
14
|
import { search } from '../search';
|
|
17
15
|
import { type SearchResult } from '../types';
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
const AiService = new EdgeAiServiceClient({
|
|
21
|
-
endpoint: AI_SERVICE_ENDPOINT.REMOTE,
|
|
22
|
-
});
|
|
17
|
+
import { getStringProperty } from './sync';
|
|
23
18
|
|
|
19
|
+
export const useWebSearch = ({ query, context }: { query?: string; context?: string }) => {
|
|
24
20
|
const [results, setResults] = useState<SearchResult[]>([]);
|
|
25
21
|
const [isLoading, setIsLoading] = useState(false);
|
|
26
22
|
|
|
@@ -31,8 +27,7 @@ export const useWebSearch = ({ query, context }: { query?: string; context?: str
|
|
|
31
27
|
const results = await search({
|
|
32
28
|
query,
|
|
33
29
|
context,
|
|
34
|
-
schema: [Testing.Project, Testing.Organization, Testing.
|
|
35
|
-
AiService,
|
|
30
|
+
schema: [Testing.Project, Testing.Organization, Testing.Person],
|
|
36
31
|
exaApiKey: EXA_API_KEY,
|
|
37
32
|
});
|
|
38
33
|
|
package/src/meta.ts
CHANGED
|
@@ -3,15 +3,18 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type PluginMeta } from '@dxos/app-framework';
|
|
6
|
-
|
|
7
|
-
export const SEARCH_PLUGIN = 'dxos.org/plugin/search';
|
|
8
|
-
export const SEARCH_RESULT = `${SEARCH_PLUGIN}/result`;
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
9
7
|
|
|
10
8
|
export const meta: PluginMeta = {
|
|
11
|
-
id:
|
|
9
|
+
id: 'dxos.org/plugin/search',
|
|
12
10
|
name: 'Search',
|
|
13
|
-
description:
|
|
11
|
+
description: trim`
|
|
12
|
+
Full-text search engine for finding content across all spaces and object types.
|
|
13
|
+
Quickly locate documents, tables, and other objects with instant results and relevance ranking.
|
|
14
|
+
`,
|
|
14
15
|
icon: 'ph--magnifying-glass--regular',
|
|
15
16
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-search',
|
|
16
17
|
tags: ['labs'],
|
|
17
18
|
};
|
|
19
|
+
|
|
20
|
+
export const SEARCH_RESULT = `${meta.id}/result`;
|
package/src/search/exa.test.ts
CHANGED
|
@@ -4,32 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { AI_SERVICE_ENDPOINT, EXA_API_KEY } from '@dxos/ai/testing';
|
|
7
|
+
import { EXA_API_KEY } from '@dxos/ai/testing';
|
|
9
8
|
import { log } from '@dxos/log';
|
|
10
9
|
import { Testing } from '@dxos/schema/testing';
|
|
11
10
|
|
|
12
11
|
import { search } from './exa';
|
|
13
12
|
|
|
14
|
-
const REMOTE_AI = true;
|
|
15
|
-
|
|
16
|
-
const AiService = REMOTE_AI
|
|
17
|
-
? new EdgeAiServiceClient({
|
|
18
|
-
endpoint: AI_SERVICE_ENDPOINT.REMOTE,
|
|
19
|
-
})
|
|
20
|
-
: new OllamaAiServiceClient({
|
|
21
|
-
overrides: {
|
|
22
|
-
model: 'llama3.1:8b',
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
13
|
describe.skip('Search', () => {
|
|
27
14
|
describe('Query-based', () => {
|
|
28
15
|
test.skip('contacts', { timeout: 60_000 }, async () => {
|
|
29
16
|
const objects = await search({
|
|
30
17
|
query: 'top executives at google',
|
|
31
|
-
schema: [Testing.
|
|
32
|
-
AiService,
|
|
18
|
+
schema: [Testing.Person],
|
|
33
19
|
exaApiKey: EXA_API_KEY,
|
|
34
20
|
});
|
|
35
21
|
|
|
@@ -39,8 +25,7 @@ describe.skip('Search', () => {
|
|
|
39
25
|
test.skip('contacts projects and orgs', { timeout: 60_000 }, async () => {
|
|
40
26
|
const objects = await search({
|
|
41
27
|
query: 'top executives at google',
|
|
42
|
-
schema: [Testing.
|
|
43
|
-
AiService,
|
|
28
|
+
schema: [Testing.Person, Testing.Project, Testing.Organization],
|
|
44
29
|
exaApiKey: EXA_API_KEY,
|
|
45
30
|
});
|
|
46
31
|
|
|
@@ -50,8 +35,7 @@ describe.skip('Search', () => {
|
|
|
50
35
|
test('a19z org, projects they invest in and team', { timeout: 60_000 }, async () => {
|
|
51
36
|
const objects = await search({
|
|
52
37
|
query: 'a19z org, projects they invest in and team',
|
|
53
|
-
schema: [Testing.Project, Testing.Organization, Testing.
|
|
54
|
-
AiService,
|
|
38
|
+
schema: [Testing.Project, Testing.Organization, Testing.Person],
|
|
55
39
|
exaApiKey: EXA_API_KEY,
|
|
56
40
|
});
|
|
57
41
|
|
|
@@ -61,8 +45,7 @@ describe.skip('Search', () => {
|
|
|
61
45
|
test('companies building CRDTs', { timeout: 60_000 }, async () => {
|
|
62
46
|
const objects = await search({
|
|
63
47
|
query: 'companies building CRDTs',
|
|
64
|
-
schema: [Testing.Project, Testing.Organization, Testing.
|
|
65
|
-
AiService,
|
|
48
|
+
schema: [Testing.Project, Testing.Organization, Testing.Person],
|
|
66
49
|
exaApiKey: EXA_API_KEY,
|
|
67
50
|
});
|
|
68
51
|
|
|
@@ -74,8 +57,7 @@ describe.skip('Search', () => {
|
|
|
74
57
|
test('composer context-based search', { timeout: 60_000 }, async () => {
|
|
75
58
|
const objects = await search({
|
|
76
59
|
context: COMPOSER_DXOS_DOC,
|
|
77
|
-
schema: [Testing.Project, Testing.Organization, Testing.
|
|
78
|
-
AiService,
|
|
60
|
+
schema: [Testing.Project, Testing.Organization, Testing.Person],
|
|
79
61
|
exaApiKey: EXA_API_KEY,
|
|
80
62
|
});
|
|
81
63
|
|
|
@@ -85,8 +67,7 @@ describe.skip('Search', () => {
|
|
|
85
67
|
test.only('edge architecture', { timeout: 60_000 }, async () => {
|
|
86
68
|
const objects = await search({
|
|
87
69
|
context: EDGE_ARCHITECTURE_DOC,
|
|
88
|
-
schema: [Testing.Project, Testing.Organization, Testing.
|
|
89
|
-
AiService,
|
|
70
|
+
schema: [Testing.Project, Testing.Organization, Testing.Person],
|
|
90
71
|
exaApiKey: EXA_API_KEY,
|
|
91
72
|
});
|
|
92
73
|
|
|
@@ -95,9 +76,7 @@ describe.skip('Search', () => {
|
|
|
95
76
|
});
|
|
96
77
|
});
|
|
97
78
|
|
|
98
|
-
// TODO(dmaretskyi): Import as txt.
|
|
99
79
|
const COMPOSER_DXOS_DOC = `
|
|
100
|
-
|
|
101
80
|

|
|
102
81
|
# Welcome to Composer by DXOS
|
|
103
82
|
|
|
@@ -105,7 +84,7 @@ const COMPOSER_DXOS_DOC = `
|
|
|
105
84
|
|
|
106
85
|
Composer is an extensible application that includes familiar components such as documents, diagrams, and tables. It leverages DXOS — a full stack framework for building collaborative local-first applications.
|
|
107
86
|
|
|
108
|
-
With our
|
|
87
|
+
With our SDK, you'll be able to build custom plugins, leverage external APIs and integrate with LLMs. All inside of a private collaborative workspace.
|
|
109
88
|
|
|
110
89
|
## Disclaimer
|
|
111
90
|
|
|
@@ -231,6 +210,4 @@ const EDGE_ARCHITECTURE_DOC = `
|
|
|
231
210
|
- given the fq id of the deployment object, anyone in the space should be able to invoke the function even if they don't have access to the object itself
|
|
232
211
|
|
|
233
212
|
### Service Side
|
|
234
|
-
|
|
235
|
-
|
|
236
213
|
`;
|