@dxos/plugin-search 0.8.2-main.f11618f → 0.8.2-staging.42af850
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-NZN3MIDZ.mjs +77 -0
- package/dist/lib/browser/app-graph-builder-NZN3MIDZ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-J6YWSQTW.mjs → chunk-ARZYMSFF.mjs} +3 -3
- package/dist/lib/browser/{chunk-J6YWSQTW.mjs.map → chunk-ARZYMSFF.mjs.map} +1 -1
- package/dist/lib/browser/{chunk-QNZWTMYF.mjs → chunk-CKQAVN5U.mjs} +23 -16
- package/dist/lib/browser/chunk-CKQAVN5U.mjs.map +7 -0
- package/dist/lib/browser/{chunk-LXHJVTYG.mjs → chunk-VMEXQBHE.mjs} +7 -7
- package/dist/lib/browser/chunk-VMEXQBHE.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +6 -6
- package/dist/lib/browser/{intent-resolver-G76A35DX.mjs → intent-resolver-RWC63UGI.mjs} +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-O56YMWJT.mjs → react-surface-UJOSZGP5.mjs} +288 -253
- package/dist/lib/browser/react-surface-UJOSZGP5.mjs.map +7 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts +2 -179
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +1 -177
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/SearchDialog.d.ts.map +1 -1
- package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +1 -1
- package/dist/types/src/components/Searchbar/Searchbar.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/useSearchResults.d.ts.map +1 -1
- package/dist/types/src/hooks/useWebSearch.d.ts +1 -1
- package/dist/types/src/hooks/useWebSearch.d.ts.map +1 -1
- package/dist/types/src/search/exa.d.ts +4 -4
- package/dist/types/src/search/exa.d.ts.map +1 -1
- package/dist/types/src/types/action.d.ts +5 -5
- package/dist/types/src/types/action.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +35 -27
- package/src/capabilities/app-graph-builder.ts +59 -41
- package/src/capabilities/react-surface.tsx +4 -7
- package/src/components/SearchDialog.tsx +8 -7
- package/src/components/SearchMain.tsx +4 -4
- package/src/components/SearchResults/SearchResults.tsx +1 -1
- package/src/hooks/sync.test.ts +2 -2
- package/src/hooks/sync.ts +8 -6
- package/src/hooks/useSearchResults.ts +2 -2
- package/src/hooks/useWebSearch.ts +5 -7
- package/src/meta.ts +2 -2
- package/src/search/exa.test.ts +2 -3
- package/src/search/exa.ts +28 -22
- package/src/types/action.tsx +4 -4
- package/dist/lib/browser/app-graph-builder-RHZORTY2.mjs +0 -76
- package/dist/lib/browser/app-graph-builder-RHZORTY2.mjs.map +0 -7
- package/dist/lib/browser/chunk-LXHJVTYG.mjs.map +0 -7
- package/dist/lib/browser/chunk-QNZWTMYF.mjs.map +0 -7
- package/dist/lib/browser/react-surface-O56YMWJT.mjs.map +0 -7
- /package/dist/lib/browser/{intent-resolver-G76A35DX.mjs.map → intent-resolver-RWC63UGI.mjs.map} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-search",
|
|
3
|
-
"version": "0.8.2-
|
|
3
|
+
"version": "0.8.2-staging.42af850",
|
|
4
4
|
"description": "Braneframe sketch plugin",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -23,47 +23,55 @@
|
|
|
23
23
|
"src"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"
|
|
26
|
+
"@preact-signals/safe-react": "^0.9.0",
|
|
27
27
|
"exa-js": "^1.5.12",
|
|
28
28
|
"main-thread-scheduling": "^14.1.1",
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/plugin-
|
|
42
|
-
"@dxos/plugin-
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/react-
|
|
29
|
+
"@dxos/artifact": "0.8.2-staging.42af850",
|
|
30
|
+
"@dxos/app-framework": "0.8.2-staging.42af850",
|
|
31
|
+
"@dxos/debug": "0.8.2-staging.42af850",
|
|
32
|
+
"@dxos/ai": "0.8.2-staging.42af850",
|
|
33
|
+
"@dxos/echo": "0.8.2-staging.42af850",
|
|
34
|
+
"@dxos/assistant": "0.8.2-staging.42af850",
|
|
35
|
+
"@dxos/echo-schema": "0.8.2-staging.42af850",
|
|
36
|
+
"@dxos/echo-protocol": "0.8.2-staging.42af850",
|
|
37
|
+
"@dxos/effect": "0.8.2-staging.42af850",
|
|
38
|
+
"@dxos/invariant": "0.8.2-staging.42af850",
|
|
39
|
+
"@dxos/live-object": "0.8.2-staging.42af850",
|
|
40
|
+
"@dxos/log": "0.8.2-staging.42af850",
|
|
41
|
+
"@dxos/plugin-deck": "0.8.2-staging.42af850",
|
|
42
|
+
"@dxos/plugin-client": "0.8.2-staging.42af850",
|
|
43
|
+
"@dxos/plugin-graph": "0.8.2-staging.42af850",
|
|
44
|
+
"@dxos/react-client": "0.8.2-staging.42af850",
|
|
45
|
+
"@dxos/plugin-space": "0.8.2-staging.42af850",
|
|
46
|
+
"@dxos/react-ui-card": "0.8.2-staging.42af850",
|
|
47
|
+
"@dxos/react-ui-searchlist": "0.8.2-staging.42af850",
|
|
48
|
+
"@dxos/schema": "0.8.2-staging.42af850",
|
|
49
|
+
"@dxos/util": "0.8.2-staging.42af850"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
52
|
+
"@effect-rx/rx-react": "^0.34.1",
|
|
53
|
+
"@effect/platform": "0.80.12",
|
|
50
54
|
"@phosphor-icons/react": "^2.1.5",
|
|
51
55
|
"@types/react": "~18.2.0",
|
|
52
56
|
"@types/react-dom": "~18.2.0",
|
|
57
|
+
"effect": "3.14.21",
|
|
53
58
|
"react": "~18.2.0",
|
|
54
59
|
"react-dom": "~18.2.0",
|
|
55
60
|
"vite": "5.4.7",
|
|
56
|
-
"@dxos/random": "0.8.2-
|
|
57
|
-
"@dxos/react-ui": "0.8.2-
|
|
58
|
-
"@dxos/react-ui-theme": "0.8.2-
|
|
59
|
-
"@dxos/storybook-utils": "0.8.2-
|
|
61
|
+
"@dxos/random": "0.8.2-staging.42af850",
|
|
62
|
+
"@dxos/react-ui": "0.8.2-staging.42af850",
|
|
63
|
+
"@dxos/react-ui-theme": "0.8.2-staging.42af850",
|
|
64
|
+
"@dxos/storybook-utils": "0.8.2-staging.42af850"
|
|
60
65
|
},
|
|
61
66
|
"peerDependencies": {
|
|
67
|
+
"@effect-rx/rx-react": "^0.34.1",
|
|
68
|
+
"@effect/platform": "0.80.12",
|
|
62
69
|
"@phosphor-icons/react": "^2.1.5",
|
|
70
|
+
"effect": "^3.13.3",
|
|
63
71
|
"react": "~18.2.0",
|
|
64
72
|
"react-dom": "~18.2.0",
|
|
65
|
-
"@dxos/react-ui": "0.8.2-
|
|
66
|
-
"@dxos/react-ui-theme": "0.8.2-
|
|
73
|
+
"@dxos/react-ui": "0.8.2-staging.42af850",
|
|
74
|
+
"@dxos/react-ui-theme": "0.8.2-staging.42af850"
|
|
67
75
|
},
|
|
68
76
|
"publishConfig": {
|
|
69
77
|
"access": "public"
|
|
@@ -2,60 +2,78 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Rx } from '@effect-rx/rx-react';
|
|
6
|
+
import { Option, pipe } from 'effect';
|
|
7
|
+
|
|
8
|
+
import { Capabilities, contributes, createIntent, type PluginContext } from '@dxos/app-framework';
|
|
6
9
|
import { ClientCapabilities } from '@dxos/plugin-client';
|
|
7
10
|
import { ATTENDABLE_PATH_SEPARATOR, DECK_COMPANION_TYPE } from '@dxos/plugin-deck/types';
|
|
8
|
-
import { createExtension,
|
|
11
|
+
import { createExtension, ROOT_ID, rxFromSignal } from '@dxos/plugin-graph';
|
|
9
12
|
import { parseId } from '@dxos/react-client/echo';
|
|
10
13
|
|
|
11
14
|
import { SEARCH_PLUGIN } from '../meta';
|
|
12
15
|
import { SearchAction } from '../types';
|
|
13
16
|
|
|
14
|
-
export default (context:
|
|
17
|
+
export default (context: PluginContext) =>
|
|
15
18
|
contributes(Capabilities.AppGraphBuilder, [
|
|
16
19
|
createExtension({
|
|
17
20
|
id: `${SEARCH_PLUGIN}/space-search`,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
connector: (node) =>
|
|
22
|
+
Rx.make((get) =>
|
|
23
|
+
pipe(
|
|
24
|
+
get(node),
|
|
25
|
+
Option.flatMap((node) => (node.id === ROOT_ID ? Option.some(node) : Option.none())),
|
|
26
|
+
Option.map((node) => {
|
|
27
|
+
const workspace = get(rxFromSignal(() => context.getCapability(Capabilities.Layout).workspace));
|
|
28
|
+
const client = context.getCapability(ClientCapabilities.Client);
|
|
29
|
+
const { spaceId } = parseId(workspace);
|
|
30
|
+
const space = spaceId ? client.spaces.get(spaceId) : null;
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
id: [node.id, 'search'].join(ATTENDABLE_PATH_SEPARATOR),
|
|
35
|
+
type: DECK_COMPANION_TYPE,
|
|
36
|
+
data: space,
|
|
37
|
+
properties: {
|
|
38
|
+
label: ['search label', { ns: SEARCH_PLUGIN }],
|
|
39
|
+
icon: 'ph--magnifying-glass--regular',
|
|
40
|
+
disposition: 'hidden',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
}),
|
|
45
|
+
Option.getOrElse(() => []),
|
|
46
|
+
),
|
|
47
|
+
),
|
|
38
48
|
}),
|
|
39
49
|
createExtension({
|
|
40
50
|
id: SEARCH_PLUGIN,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
actions: (node) =>
|
|
52
|
+
Rx.make((get) =>
|
|
53
|
+
pipe(
|
|
54
|
+
get(node),
|
|
55
|
+
Option.flatMap((node) => (node.id === ROOT_ID ? Option.some(node) : Option.none())),
|
|
56
|
+
Option.map(() => {
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
id: SearchAction.OpenSearch._tag,
|
|
60
|
+
data: async () => {
|
|
61
|
+
const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);
|
|
62
|
+
await dispatch(createIntent(SearchAction.OpenSearch));
|
|
63
|
+
},
|
|
64
|
+
properties: {
|
|
65
|
+
label: ['search action label', { ns: SEARCH_PLUGIN }],
|
|
66
|
+
icon: 'ph--magnifying-glass--regular',
|
|
67
|
+
keyBinding: {
|
|
68
|
+
macos: 'shift+meta+f',
|
|
69
|
+
windows: 'shift+alt+f',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
}),
|
|
75
|
+
Option.getOrElse(() => []),
|
|
76
|
+
),
|
|
77
|
+
),
|
|
60
78
|
}),
|
|
61
79
|
]);
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import { Capabilities, contributes, createSurface
|
|
8
|
-
import {
|
|
7
|
+
import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
8
|
+
import { useActiveSpace } from '@dxos/plugin-space';
|
|
9
9
|
import { isSpace, type Space } from '@dxos/react-client/echo';
|
|
10
10
|
|
|
11
11
|
import { SEARCH_DIALOG, SearchDialog, type SearchDialogProps, SearchMain } from '../components';
|
|
@@ -24,13 +24,10 @@ export default () =>
|
|
|
24
24
|
),
|
|
25
25
|
}),
|
|
26
26
|
createSurface({
|
|
27
|
-
|
|
28
|
-
id: 'search-input',
|
|
27
|
+
id: `${SEARCH_DIALOG}/search-input`,
|
|
29
28
|
role: 'search-input',
|
|
30
29
|
component: () => {
|
|
31
|
-
const
|
|
32
|
-
const { graph } = useAppGraph();
|
|
33
|
-
const space = graph ? getActiveSpace(graph, layout.active[0]) : undefined;
|
|
30
|
+
const space = useActiveSpace();
|
|
34
31
|
if (!space) {
|
|
35
32
|
return null;
|
|
36
33
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Option } from 'effect';
|
|
5
6
|
import React, { forwardRef, useCallback, useState } from 'react';
|
|
6
7
|
|
|
7
8
|
import { LayoutAction, createIntent, useAppGraph, useIntentDispatcher, useLayout } from '@dxos/app-framework';
|
|
@@ -47,11 +48,11 @@ export const SearchDialog = ({ pivotId }: SearchDialogProps) => {
|
|
|
47
48
|
const { graph } = useAppGraph();
|
|
48
49
|
const layout = useLayout();
|
|
49
50
|
const closed = (Array.isArray(layout.inactive) ? layout.inactive : [layout.inactive])
|
|
50
|
-
.map((id) => graph?.
|
|
51
|
+
.map((id) => graph?.getNode(id))
|
|
51
52
|
.filter(Boolean);
|
|
52
53
|
const [queryString, setQueryString] = useState('');
|
|
53
54
|
const client = useClient();
|
|
54
|
-
const dangerouslyLoadAllObjects = useQuery(client.spaces, Filter.
|
|
55
|
+
const dangerouslyLoadAllObjects = useQuery(client.spaces, Filter.everything());
|
|
55
56
|
const [pending, results] = useSearchResults(queryString, dangerouslyLoadAllObjects);
|
|
56
57
|
const resultObjects = Array.from(results.keys());
|
|
57
58
|
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
@@ -96,17 +97,17 @@ export const SearchDialog = ({ pivotId }: SearchDialogProps) => {
|
|
|
96
97
|
{queryString.length > 0 ? (
|
|
97
98
|
resultObjects.length > 0 ? (
|
|
98
99
|
resultObjects
|
|
99
|
-
.map((object) => graph
|
|
100
|
-
.filter(
|
|
101
|
-
.map((node) => <SearchListResult key={node
|
|
100
|
+
.map((object) => graph.getNode(fullyQualifiedId(object)))
|
|
101
|
+
.filter(Option.isSome)
|
|
102
|
+
.map((node) => <SearchListResult key={node.value.id} node={node.value} onSelect={handleSelect} />)
|
|
102
103
|
) : (
|
|
103
104
|
<p className='pli-1'>{t(pending ? 'pending results message' : 'empty results message')}</p>
|
|
104
105
|
)
|
|
105
106
|
) : (
|
|
106
107
|
<>
|
|
107
108
|
{closed.length > 0 && <h2 className={mx('mlb-1', descriptionText)}>{t('recently closed heading')}</h2>}
|
|
108
|
-
{closed.map((node) => (
|
|
109
|
-
<SearchListResult key={node
|
|
109
|
+
{closed.filter(Option.isSome).map((node) => (
|
|
110
|
+
<SearchListResult key={node.value.id} node={node.value} onSelect={handleSelect} />
|
|
110
111
|
))}
|
|
111
112
|
</>
|
|
112
113
|
)}
|
|
@@ -8,7 +8,7 @@ import { log } from '@dxos/log';
|
|
|
8
8
|
import { useClient } from '@dxos/react-client';
|
|
9
9
|
import { Filter, useQuery, type Space } from '@dxos/react-client/echo';
|
|
10
10
|
import { type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
11
|
-
import {
|
|
11
|
+
import { activeSurface, mx } from '@dxos/react-ui-theme';
|
|
12
12
|
|
|
13
13
|
import { SearchResults } from './SearchResults';
|
|
14
14
|
import { Searchbar } from './Searchbar';
|
|
@@ -25,7 +25,7 @@ export const SearchMain: FC<ThemedClassName<{ space: Space }>> = ({ classNames,
|
|
|
25
25
|
const allSpaces = false;
|
|
26
26
|
|
|
27
27
|
// TODO(burdon): Returns ALL objects (e.g., incl. Text objects that are fields of parent objects).
|
|
28
|
-
const objects = useQuery(allSpaces ? client.spaces : space, Filter.
|
|
28
|
+
const objects = useQuery(allSpaces ? client.spaces : space, Filter.everything());
|
|
29
29
|
const results = useGlobalSearchResults(objects);
|
|
30
30
|
|
|
31
31
|
const {
|
|
@@ -56,9 +56,9 @@ export const SearchMain: FC<ThemedClassName<{ space: Space }>> = ({ classNames,
|
|
|
56
56
|
}}
|
|
57
57
|
onSubmit={runSearch}
|
|
58
58
|
/>
|
|
59
|
-
{isLoading && <div className={mx('flex flex-col grow overflow-hidden',
|
|
59
|
+
{isLoading && <div className={mx('flex flex-col grow overflow-hidden', activeSurface)}>Loading...</div>}
|
|
60
60
|
{allResults.length > 0 && (
|
|
61
|
-
<div className={mx('flex flex-col grow overflow-hidden',
|
|
61
|
+
<div className={mx('flex flex-col grow overflow-hidden', activeSurface)}>
|
|
62
62
|
<SearchResults items={allResults} selected={selected} onSelect={handleSelect} />
|
|
63
63
|
</div>
|
|
64
64
|
)}
|
|
@@ -49,7 +49,7 @@ export const SearchItem = forwardRef<HTMLDivElement, SearchItemProps>((item, for
|
|
|
49
49
|
return (
|
|
50
50
|
<Card.Root
|
|
51
51
|
ref={forwardRef}
|
|
52
|
-
classNames={mx('mx-2 mt-2 cursor-pointer', selected && '!bg-
|
|
52
|
+
classNames={mx('mx-2 mt-2 cursor-pointer', selected && '!bg-activeSurface', ghostHover)}
|
|
53
53
|
onClick={() => onSelect?.(id)}
|
|
54
54
|
>
|
|
55
55
|
{objectType && (
|
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 { Expando } from '@dxos/echo-schema';
|
|
8
|
+
import { Expando, Filter } from '@dxos/echo-schema';
|
|
9
9
|
import { live } from '@dxos/live-object';
|
|
10
10
|
import { faker } from '@dxos/random';
|
|
11
11
|
|
|
@@ -29,7 +29,7 @@ describe('Search', () => {
|
|
|
29
29
|
return space.db.add(live(Expando, { title: faker.lorem.sentence(), content }));
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
const { objects } = await space.db.query().run();
|
|
32
|
+
const { objects } = await space.db.query(Filter.everything()).run();
|
|
33
33
|
const results = filterObjectsSync(objects, new RegExp(match, 'i'));
|
|
34
34
|
expect(results).to.have.length(1);
|
|
35
35
|
});
|
package/src/hooks/sync.ts
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { type Schema, SchemaAST } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { getSchema } from '@dxos/echo-schema';
|
|
8
|
+
import { DataType } from '@dxos/schema';
|
|
7
9
|
|
|
8
10
|
import { type SearchResult } from '../types';
|
|
9
11
|
|
|
@@ -13,8 +15,8 @@ export const queryStringToMatch = (queryString?: string): RegExp | undefined =>
|
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
// TODO(burdon): Type name registry linked to schema?
|
|
16
|
-
const getIcon = (schema:
|
|
17
|
-
if (!(schema &&
|
|
18
|
+
const getIcon = (schema: Schema.Schema.AnyNoContext | undefined): string | undefined => {
|
|
19
|
+
if (!(schema && SchemaAST.isTypeLiteral(schema.ast))) {
|
|
18
20
|
return undefined;
|
|
19
21
|
}
|
|
20
22
|
const keys = schema.ast.propertySignatures.map((p) => p.name);
|
|
@@ -43,7 +45,7 @@ export const filterObjectsSync = <T extends Record<string, any>>(objects: T[], m
|
|
|
43
45
|
|
|
44
46
|
return objects.reduce<SearchResult[]>((results, object) => {
|
|
45
47
|
// TODO(burdon): Hack to ignore Text objects.
|
|
46
|
-
if (object instanceof
|
|
48
|
+
if (object instanceof DataType.Text) {
|
|
47
49
|
return results;
|
|
48
50
|
}
|
|
49
51
|
|
|
@@ -109,7 +111,7 @@ const getKeys = (object: Record<string, unknown>): string[] => {
|
|
|
109
111
|
export const mapObjectToTextFields = <T extends Record<string, unknown>>(object: T): TextFields => {
|
|
110
112
|
return getKeys(object).reduce<TextFields>((fields, key) => {
|
|
111
113
|
const value = object[key] as any;
|
|
112
|
-
if (typeof value === 'string' || value instanceof
|
|
114
|
+
if (typeof value === 'string' || value instanceof DataType.Text) {
|
|
113
115
|
try {
|
|
114
116
|
fields[key] = String(value);
|
|
115
117
|
} catch (err) {
|
|
@@ -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 { DataType } 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 DataType.Text))
|
|
24
24
|
.map(async (object) => {
|
|
25
25
|
await yieldOrContinue('interactive');
|
|
26
26
|
const fields = mapObjectToTextFields<T>(object);
|
|
@@ -4,20 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import { useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import { AIServiceEdgeClient } from '@dxos/
|
|
8
|
-
import { AI_SERVICE_ENDPOINT } from '@dxos/
|
|
7
|
+
import { AIServiceEdgeClient } from '@dxos/ai';
|
|
8
|
+
import { AI_SERVICE_ENDPOINT, EXA_API_KEY } from '@dxos/ai/testing';
|
|
9
9
|
import { getSchema, getTypename } from '@dxos/echo-schema';
|
|
10
|
-
import type
|
|
10
|
+
import { type DXN } from '@dxos/keys';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
import { getIconAnnotation } from '@dxos/schema';
|
|
13
13
|
import { Testing } from '@dxos/schema/testing';
|
|
14
14
|
|
|
15
15
|
import { getStringProperty } from './sync';
|
|
16
16
|
import { search } from '../search';
|
|
17
|
-
import type
|
|
18
|
-
|
|
19
|
-
// TODO(dmaretskyi): Get from config/credentials
|
|
20
|
-
const EXA_API_KEY = '9c7e17ff-0c85-4cd5-827a-8b489f139e03';
|
|
17
|
+
import { type SearchResult } from '../types';
|
|
21
18
|
|
|
22
19
|
export const useWebSearch = ({ query, context }: { query?: string; context?: string }) => {
|
|
23
20
|
const aiService = new AIServiceEdgeClient({
|
|
@@ -56,5 +53,6 @@ export const useWebSearch = ({ query, context }: { query?: string; context?: str
|
|
|
56
53
|
setIsLoading(false);
|
|
57
54
|
}
|
|
58
55
|
};
|
|
56
|
+
|
|
59
57
|
return { runSearch, results, isLoading };
|
|
60
58
|
};
|
package/src/meta.ts
CHANGED
|
@@ -12,6 +12,6 @@ export const meta: PluginMeta = {
|
|
|
12
12
|
name: 'Search',
|
|
13
13
|
description: 'Search ECHO spaces for content.',
|
|
14
14
|
icon: 'ph--magnifying-glass--regular',
|
|
15
|
-
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/
|
|
16
|
-
tags: ['
|
|
15
|
+
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-search',
|
|
16
|
+
tags: ['labs'],
|
|
17
17
|
};
|
package/src/search/exa.test.ts
CHANGED
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import { AIServiceEdgeClient, OllamaClient } from '@dxos/
|
|
8
|
-
import { AI_SERVICE_ENDPOINT } from '@dxos/
|
|
7
|
+
import { AIServiceEdgeClient, OllamaClient } from '@dxos/ai';
|
|
8
|
+
import { AI_SERVICE_ENDPOINT, EXA_API_KEY } from '@dxos/ai/testing';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { Testing } from '@dxos/schema/testing';
|
|
11
11
|
|
|
12
12
|
import { search } from './exa';
|
|
13
13
|
|
|
14
|
-
const EXA_API_KEY = '9c7e17ff-0c85-4cd5-827a-8b489f139e03';
|
|
15
14
|
const REMOTE_AI = true;
|
|
16
15
|
|
|
17
16
|
const aiService = REMOTE_AI
|
package/src/search/exa.ts
CHANGED
|
@@ -2,19 +2,25 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Option, SchemaAST
|
|
5
|
+
import { Option, Schema, SchemaAST } from 'effect';
|
|
6
6
|
import Exa from 'exa-js';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
type AIServiceClient,
|
|
10
|
+
type GenerateRequest,
|
|
11
|
+
Message,
|
|
12
|
+
MixedStreamParser,
|
|
13
|
+
type TextContentBlock,
|
|
14
|
+
createTool,
|
|
15
|
+
} from '@dxos/ai';
|
|
10
16
|
import { isEncodedReference } from '@dxos/echo-protocol';
|
|
11
|
-
import { create, getTypeAnnotation, ObjectId, ReferenceAnnotationId
|
|
17
|
+
import { create, getTypeAnnotation, ObjectId, ReferenceAnnotationId } from '@dxos/echo-schema';
|
|
12
18
|
import { mapAst } from '@dxos/effect';
|
|
13
19
|
import { assertArgument, failedInvariant } from '@dxos/invariant';
|
|
14
20
|
import { log } from '@dxos/log';
|
|
15
21
|
import { deepMapValues } from '@dxos/util';
|
|
16
22
|
|
|
17
|
-
export type SearchOptions<Schema extends
|
|
23
|
+
export type SearchOptions<Schema extends Schema.Schema.AnyNoContext> = {
|
|
18
24
|
query?: string;
|
|
19
25
|
|
|
20
26
|
// TODO(dmaretskyi): How can we pass this through.
|
|
@@ -36,9 +42,9 @@ export type SearchResult<T = unknown> = {
|
|
|
36
42
|
};
|
|
37
43
|
};
|
|
38
44
|
|
|
39
|
-
export const search = async <Schema extends
|
|
45
|
+
export const search = async <Schema extends Schema.Schema.AnyNoContext>(
|
|
40
46
|
options: SearchOptions<Schema>,
|
|
41
|
-
): Promise<SearchResult<
|
|
47
|
+
): Promise<SearchResult<Schema.Schema.Type<Schema>>> => {
|
|
42
48
|
assertArgument(options.query || options.context, 'query or context is required');
|
|
43
49
|
|
|
44
50
|
let contextSearchTerms: readonly string[] = [];
|
|
@@ -90,12 +96,12 @@ export const search = async <Schema extends S.Schema.AnyNoContext>(
|
|
|
90
96
|
}),
|
|
91
97
|
],
|
|
92
98
|
|
|
93
|
-
schema:
|
|
99
|
+
schema: Schema.Struct({
|
|
94
100
|
...Object.fromEntries(
|
|
95
101
|
mappedSchema.map((schema, index) => [
|
|
96
102
|
`objects_${index}`,
|
|
97
|
-
|
|
98
|
-
description: `The objects to answer the query of type ${getTypeAnnotation(schema)?.typename ??
|
|
103
|
+
Schema.Array(schema).annotations({
|
|
104
|
+
description: `The objects to answer the query of type ${getTypeAnnotation(schema)?.typename ?? SchemaAST.getIdentifierAnnotation(schema.ast).pipe(Option.getOrNull)}`,
|
|
99
105
|
}),
|
|
100
106
|
]),
|
|
101
107
|
),
|
|
@@ -149,10 +155,10 @@ const DATA_EXTRACTION_INSTRUCTIONS = `
|
|
|
149
155
|
/**
|
|
150
156
|
* Runs the LLM to produce a structured output matching a schema
|
|
151
157
|
*/
|
|
152
|
-
const getStructuredOutput = async <S extends
|
|
158
|
+
const getStructuredOutput = async <S extends Schema.Schema.AnyNoContext>(
|
|
153
159
|
aiService: AIServiceClient,
|
|
154
160
|
request: Omit<GenerateRequest, 'tools'> & { schema: S },
|
|
155
|
-
): Promise<
|
|
161
|
+
): Promise<Schema.Schema.Type<S>> => {
|
|
156
162
|
const result = await new MixedStreamParser().parse(
|
|
157
163
|
await aiService.execStream({
|
|
158
164
|
...request,
|
|
@@ -160,7 +166,7 @@ const getStructuredOutput = async <S extends S.Schema.AnyNoContext>(
|
|
|
160
166
|
request.systemPrompt +
|
|
161
167
|
'\nDo not output anything other then the tool call. Call the submit_result tool with the result.',
|
|
162
168
|
tools: [
|
|
163
|
-
|
|
169
|
+
createTool('submit_result', {
|
|
164
170
|
name: 'submit_result',
|
|
165
171
|
description: 'Submit the result',
|
|
166
172
|
schema: request.schema,
|
|
@@ -192,8 +198,8 @@ const getSearchTerms = async (aiService: AIServiceClient, context: string) => {
|
|
|
192
198
|
],
|
|
193
199
|
}),
|
|
194
200
|
],
|
|
195
|
-
schema:
|
|
196
|
-
terms:
|
|
201
|
+
schema: Schema.Struct({
|
|
202
|
+
terms: Schema.Array(Schema.String).annotations({
|
|
197
203
|
description: 'The search terms to use to find the objects. 0-10 terms.',
|
|
198
204
|
}),
|
|
199
205
|
}),
|
|
@@ -202,7 +208,7 @@ const getSearchTerms = async (aiService: AIServiceClient, context: string) => {
|
|
|
202
208
|
return terms;
|
|
203
209
|
};
|
|
204
210
|
|
|
205
|
-
const sanitizeObjects = (entries: { data: any; schema:
|
|
211
|
+
const sanitizeObjects = (entries: { data: any; schema: Schema.Schema.AnyNoContext }[]) => {
|
|
206
212
|
const idMap = new Map<string, string>();
|
|
207
213
|
|
|
208
214
|
return entries
|
|
@@ -231,20 +237,20 @@ const sanitizeObjects = (entries: { data: any; schema: S.Schema.AnyNoContext }[]
|
|
|
231
237
|
});
|
|
232
238
|
};
|
|
233
239
|
|
|
234
|
-
const SoftRef =
|
|
235
|
-
'/':
|
|
240
|
+
const SoftRef = Schema.Struct({
|
|
241
|
+
'/': Schema.String,
|
|
236
242
|
}).annotations({
|
|
237
243
|
description: 'Reference to another object.',
|
|
238
244
|
});
|
|
239
245
|
|
|
240
|
-
const mapSchemaRefs = (schema:
|
|
241
|
-
const go = (ast:
|
|
242
|
-
if (
|
|
246
|
+
const mapSchemaRefs = (schema: Schema.Schema.AnyNoContext) => {
|
|
247
|
+
const go = (ast: SchemaAST.AST): SchemaAST.AST => {
|
|
248
|
+
if (SchemaAST.getAnnotation(ast, ReferenceAnnotationId).pipe(Option.isSome)) {
|
|
243
249
|
return SoftRef.ast;
|
|
244
250
|
}
|
|
245
251
|
|
|
246
252
|
return mapAst(ast, go);
|
|
247
253
|
};
|
|
248
254
|
|
|
249
|
-
return
|
|
255
|
+
return Schema.make(mapAst(schema.ast, go));
|
|
250
256
|
};
|
package/src/types/action.tsx
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
7
|
import { SEARCH_PLUGIN } from '../meta';
|
|
8
8
|
|
|
9
9
|
export namespace SearchAction {
|
|
10
10
|
const SEARCH_ACTION = `${SEARCH_PLUGIN}/action`;
|
|
11
11
|
|
|
12
|
-
export class OpenSearch extends
|
|
13
|
-
input:
|
|
14
|
-
output:
|
|
12
|
+
export class OpenSearch extends Schema.TaggedClass<OpenSearch>()(`${SEARCH_ACTION}/open-search`, {
|
|
13
|
+
input: Schema.Void,
|
|
14
|
+
output: Schema.Void,
|
|
15
15
|
}) {}
|
|
16
16
|
}
|