@dxos/plugin-search 0.8.4-main.c1de068 → 0.8.4-main.f5c0578
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-FLW7KDC5.mjs → app-graph-builder-D2QQTIIR.mjs} +2 -2
- package/dist/lib/browser/{app-graph-builder-FLW7KDC5.mjs.map → app-graph-builder-D2QQTIIR.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-BXSF7IAU.mjs → chunk-VKV5ZDB4.mjs} +1 -1
- package/dist/lib/browser/{chunk-BXSF7IAU.mjs.map → chunk-VKV5ZDB4.mjs.map} +2 -2
- package/dist/lib/browser/index.mjs +5 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-JPBGEKFT.mjs → intent-resolver-NXFDPFHC.mjs} +2 -2
- package/dist/lib/browser/{intent-resolver-JPBGEKFT.mjs.map → intent-resolver-NXFDPFHC.mjs.map} +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-ETKK5YS3.mjs → react-surface-B2XYD6JN.mjs} +86 -266
- package/dist/lib/browser/react-surface-B2XYD6JN.mjs.map +7 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/components/Search.stories.d.ts.map +1 -1
- package/dist/types/src/components/SearchMain.d.ts.map +1 -1
- package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts.map +1 -1
- package/dist/types/src/components/Searchbar/Searchbar.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/search/exa.d.ts +0 -2
- package/dist/types/src/search/exa.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -30
- package/src/SearchPlugin.tsx +2 -2
- package/src/capabilities/app-graph-builder.ts +2 -2
- package/src/capabilities/intent-resolver.ts +1 -1
- package/src/capabilities/react-surface.tsx +1 -1
- package/src/components/Search.stories.tsx +4 -3
- package/src/components/SearchMain.tsx +4 -3
- package/src/components/SearchResults/SearchResults.stories.tsx +2 -1
- package/src/components/Searchbar/Searchbar.tsx +1 -1
- package/src/hooks/sync.test.ts +1 -1
- package/src/hooks/useGlobalSearch.tsx +3 -2
- package/src/hooks/useWebSearch.ts +1 -2
- package/src/search/exa.test.ts +2 -11
- package/src/search/exa.ts +127 -149
- package/dist/lib/browser/react-surface-ETKK5YS3.mjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-search",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.f5c0578",
|
|
4
4
|
"description": "Braneframe sketch plugin",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"source": "./src/index.ts",
|
|
13
14
|
"types": "./dist/types/src/index.d.ts",
|
|
14
15
|
"browser": "./dist/lib/browser/index.mjs"
|
|
15
16
|
}
|
|
@@ -26,41 +27,41 @@
|
|
|
26
27
|
"@preact-signals/safe-react": "^0.9.0",
|
|
27
28
|
"exa-js": "^1.5.12",
|
|
28
29
|
"main-thread-scheduling": "^14.1.1",
|
|
29
|
-
"@dxos/ai": "0.8.4-main.
|
|
30
|
-
"@dxos/app-framework": "0.8.4-main.
|
|
31
|
-
"@dxos/assistant": "0.8.4-main.
|
|
32
|
-
"@dxos/
|
|
33
|
-
"@dxos/
|
|
34
|
-
"@dxos/
|
|
35
|
-
"@dxos/echo": "0.8.4-main.
|
|
36
|
-
"@dxos/
|
|
37
|
-
"@dxos/effect": "0.8.4-main.
|
|
38
|
-
"@dxos/invariant": "0.8.4-main.
|
|
39
|
-
"@dxos/log": "0.8.4-main.
|
|
40
|
-
"@dxos/live-object": "0.8.4-main.
|
|
41
|
-
"@dxos/plugin-
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/plugin-
|
|
44
|
-
"@dxos/plugin-
|
|
45
|
-
"@dxos/react-ui-
|
|
46
|
-
"@dxos/react-
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/util": "0.8.4-main.
|
|
49
|
-
"@dxos/
|
|
30
|
+
"@dxos/ai": "0.8.4-main.f5c0578",
|
|
31
|
+
"@dxos/app-framework": "0.8.4-main.f5c0578",
|
|
32
|
+
"@dxos/assistant": "0.8.4-main.f5c0578",
|
|
33
|
+
"@dxos/echo": "0.8.4-main.f5c0578",
|
|
34
|
+
"@dxos/echo-protocol": "0.8.4-main.f5c0578",
|
|
35
|
+
"@dxos/debug": "0.8.4-main.f5c0578",
|
|
36
|
+
"@dxos/echo-schema": "0.8.4-main.f5c0578",
|
|
37
|
+
"@dxos/blueprints": "0.8.4-main.f5c0578",
|
|
38
|
+
"@dxos/effect": "0.8.4-main.f5c0578",
|
|
39
|
+
"@dxos/invariant": "0.8.4-main.f5c0578",
|
|
40
|
+
"@dxos/log": "0.8.4-main.f5c0578",
|
|
41
|
+
"@dxos/live-object": "0.8.4-main.f5c0578",
|
|
42
|
+
"@dxos/plugin-client": "0.8.4-main.f5c0578",
|
|
43
|
+
"@dxos/plugin-deck": "0.8.4-main.f5c0578",
|
|
44
|
+
"@dxos/plugin-graph": "0.8.4-main.f5c0578",
|
|
45
|
+
"@dxos/plugin-space": "0.8.4-main.f5c0578",
|
|
46
|
+
"@dxos/react-ui-stack": "0.8.4-main.f5c0578",
|
|
47
|
+
"@dxos/react-client": "0.8.4-main.f5c0578",
|
|
48
|
+
"@dxos/react-ui-searchlist": "0.8.4-main.f5c0578",
|
|
49
|
+
"@dxos/util": "0.8.4-main.f5c0578",
|
|
50
|
+
"@dxos/schema": "0.8.4-main.f5c0578"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@effect-rx/rx-react": "0.38.0",
|
|
53
|
-
"@effect/platform": "0.
|
|
54
|
+
"@effect/platform": "0.90.2",
|
|
54
55
|
"@types/react": "~18.2.0",
|
|
55
56
|
"@types/react-dom": "~18.2.0",
|
|
56
|
-
"effect": "3.17.
|
|
57
|
+
"effect": "3.17.7",
|
|
57
58
|
"react": "~18.2.0",
|
|
58
59
|
"react-dom": "~18.2.0",
|
|
59
60
|
"vite": "5.4.7",
|
|
60
|
-
"@dxos/random": "0.8.4-main.
|
|
61
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
61
|
+
"@dxos/random": "0.8.4-main.f5c0578",
|
|
62
|
+
"@dxos/react-ui": "0.8.4-main.f5c0578",
|
|
63
|
+
"@dxos/react-ui-theme": "0.8.4-main.f5c0578",
|
|
64
|
+
"@dxos/storybook-utils": "0.8.4-main.f5c0578"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
66
67
|
"@effect-rx/rx-react": "^0.34.1",
|
|
@@ -68,8 +69,8 @@
|
|
|
68
69
|
"effect": "^3.13.3",
|
|
69
70
|
"react": "~18.2.0",
|
|
70
71
|
"react-dom": "~18.2.0",
|
|
71
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
72
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
72
|
+
"@dxos/react-ui": "0.8.4-main.f5c0578",
|
|
73
|
+
"@dxos/react-ui-theme": "0.8.4-main.f5c0578"
|
|
73
74
|
},
|
|
74
75
|
"publishConfig": {
|
|
75
76
|
"access": "public"
|
package/src/SearchPlugin.tsx
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Capabilities, Events, contributes, defineModule, definePlugin } from '@dxos/app-framework';
|
|
6
6
|
|
|
7
7
|
import { AppGraphBuilder, IntentResolver, ReactSurface } from './capabilities';
|
|
8
|
-
import {
|
|
8
|
+
import { SEARCH_RESULT, meta } from './meta';
|
|
9
9
|
import { translations } from './translations';
|
|
10
10
|
import { type SearchResult } from './types';
|
|
11
11
|
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
import { Rx } from '@effect-rx/rx-react';
|
|
6
6
|
import { Option, pipe } from 'effect';
|
|
7
7
|
|
|
8
|
-
import { Capabilities, contributes, createIntent
|
|
8
|
+
import { Capabilities, type PluginContext, contributes, createIntent } from '@dxos/app-framework';
|
|
9
9
|
import { ClientCapabilities } from '@dxos/plugin-client';
|
|
10
10
|
import { ATTENDABLE_PATH_SEPARATOR, DECK_COMPANION_TYPE } from '@dxos/plugin-deck/types';
|
|
11
|
-
import {
|
|
11
|
+
import { ROOT_ID, createExtension, rxFromSignal } from '@dxos/plugin-graph';
|
|
12
12
|
import { parseId } from '@dxos/react-client/echo';
|
|
13
13
|
|
|
14
14
|
import { SEARCH_PLUGIN } from '../meta';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Capabilities, LayoutAction, contributes, createIntent, createResolver } from '@dxos/app-framework';
|
|
6
6
|
|
|
7
7
|
import { SearchAction } from '../types';
|
|
8
8
|
|
|
@@ -6,7 +6,7 @@ import React from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
8
8
|
import { useActiveSpace } from '@dxos/plugin-space';
|
|
9
|
-
import {
|
|
9
|
+
import { type Space, isSpace } from '@dxos/react-client/echo';
|
|
10
10
|
|
|
11
11
|
import { SEARCH_DIALOG, SearchDialog, type SearchDialogProps, SearchMain } from '../components';
|
|
12
12
|
import { SearchContextProvider } from '../hooks';
|
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type Decorator, type Meta, type StoryFn } from '@storybook/react-vite';
|
|
8
8
|
import React, { useState } from 'react';
|
|
9
9
|
|
|
10
10
|
import { faker } from '@dxos/random';
|
|
11
11
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
12
12
|
|
|
13
|
-
import { SearchResults } from './SearchResults';
|
|
14
|
-
import { Searchbar, type SearchbarProps } from './Searchbar';
|
|
15
13
|
import { SearchContextProvider, useGlobalSearch, useGlobalSearchResults } from '../hooks';
|
|
16
14
|
|
|
15
|
+
import { Searchbar, type SearchbarProps } from './Searchbar';
|
|
16
|
+
import { SearchResults } from './SearchResults';
|
|
17
|
+
|
|
17
18
|
faker.seed(1);
|
|
18
19
|
|
|
19
20
|
type StoryProps = SearchbarProps & {
|
|
@@ -6,16 +6,17 @@ import React, { type FC, useState } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { log } from '@dxos/log';
|
|
8
8
|
import { useClient } from '@dxos/react-client';
|
|
9
|
-
import { Filter,
|
|
9
|
+
import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
|
|
10
10
|
import { type ThemedClassName, useTranslation } from '@dxos/react-ui';
|
|
11
11
|
import { activeSurface, mx } from '@dxos/react-ui-theme';
|
|
12
12
|
|
|
13
|
-
import { SearchResults } from './SearchResults';
|
|
14
|
-
import { Searchbar } from './Searchbar';
|
|
15
13
|
import { useGlobalSearch, useGlobalSearchResults } from '../hooks';
|
|
16
14
|
import { useWebSearch } from '../hooks/useWebSearch';
|
|
17
15
|
import { SEARCH_PLUGIN } from '../meta';
|
|
18
16
|
|
|
17
|
+
import { Searchbar } from './Searchbar';
|
|
18
|
+
import { SearchResults } from './SearchResults';
|
|
19
|
+
|
|
19
20
|
export const SearchMain: FC<ThemedClassName<{ space: Space }>> = ({ classNames, space }) => {
|
|
20
21
|
const { t } = useTranslation(SEARCH_PLUGIN);
|
|
21
22
|
const client = useClient();
|
|
@@ -10,9 +10,10 @@ import React, { useState } from 'react';
|
|
|
10
10
|
import { faker } from '@dxos/random';
|
|
11
11
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
12
12
|
|
|
13
|
-
import { SearchResults, type SearchResultsProps } from './SearchResults';
|
|
14
13
|
import { filterObjectsSync } from '../../hooks';
|
|
15
14
|
|
|
15
|
+
import { SearchResults, type SearchResultsProps } from './SearchResults';
|
|
16
|
+
|
|
16
17
|
faker.seed(1);
|
|
17
18
|
|
|
18
19
|
const DefaultStory = (args: SearchResultsProps) => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type KeyboardEvent, useEffect, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import { Input, type TextInputProps
|
|
7
|
+
import { Icon, Input, type TextInputProps } from '@dxos/react-ui';
|
|
8
8
|
|
|
9
9
|
export type SearchbarProps = Pick<TextInputProps, 'variant' | 'placeholder'> & {
|
|
10
10
|
classes?: {
|
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';
|
|
@@ -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,6 @@
|
|
|
5
5
|
import { useState } from 'react';
|
|
6
6
|
|
|
7
7
|
import { EXA_API_KEY } from '@dxos/ai/testing';
|
|
8
|
-
import { todo } from '@dxos/debug';
|
|
9
8
|
import { Obj } from '@dxos/echo';
|
|
10
9
|
import { type DXN } from '@dxos/keys';
|
|
11
10
|
import { log } from '@dxos/log';
|
|
@@ -14,6 +13,7 @@ import { Testing } from '@dxos/schema/testing';
|
|
|
14
13
|
|
|
15
14
|
import { search } from '../search';
|
|
16
15
|
import { type SearchResult } from '../types';
|
|
16
|
+
|
|
17
17
|
import { getStringProperty } from './sync';
|
|
18
18
|
|
|
19
19
|
export const useWebSearch = ({ query, context }: { query?: string; context?: string }) => {
|
|
@@ -28,7 +28,6 @@ export const useWebSearch = ({ query, context }: { query?: string; context?: str
|
|
|
28
28
|
query,
|
|
29
29
|
context,
|
|
30
30
|
schema: [Testing.Project, Testing.Organization, Testing.Contact],
|
|
31
|
-
AiService: todo(),
|
|
32
31
|
exaApiKey: EXA_API_KEY,
|
|
33
32
|
});
|
|
34
33
|
|
package/src/search/exa.test.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
import { describe, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { EXA_API_KEY } from '@dxos/ai/testing';
|
|
8
|
-
import { todo } from '@dxos/debug';
|
|
9
8
|
import { log } from '@dxos/log';
|
|
10
9
|
import { Testing } from '@dxos/schema/testing';
|
|
10
|
+
import { trim } from '@dxos/util';
|
|
11
11
|
|
|
12
12
|
import { search } from './exa';
|
|
13
13
|
|
|
@@ -17,7 +17,6 @@ describe.skip('Search', () => {
|
|
|
17
17
|
const objects = await search({
|
|
18
18
|
query: 'top executives at google',
|
|
19
19
|
schema: [Testing.Contact],
|
|
20
|
-
AiService: null as any, // TODO: Implement AiService
|
|
21
20
|
exaApiKey: EXA_API_KEY,
|
|
22
21
|
});
|
|
23
22
|
|
|
@@ -28,7 +27,6 @@ describe.skip('Search', () => {
|
|
|
28
27
|
const objects = await search({
|
|
29
28
|
query: 'top executives at google',
|
|
30
29
|
schema: [Testing.Contact, Testing.Project, Testing.Organization],
|
|
31
|
-
AiService: todo(),
|
|
32
30
|
exaApiKey: EXA_API_KEY,
|
|
33
31
|
});
|
|
34
32
|
|
|
@@ -39,7 +37,6 @@ describe.skip('Search', () => {
|
|
|
39
37
|
const objects = await search({
|
|
40
38
|
query: 'a19z org, projects they invest in and team',
|
|
41
39
|
schema: [Testing.Project, Testing.Organization, Testing.Contact],
|
|
42
|
-
AiService: todo(),
|
|
43
40
|
exaApiKey: EXA_API_KEY,
|
|
44
41
|
});
|
|
45
42
|
|
|
@@ -50,7 +47,6 @@ describe.skip('Search', () => {
|
|
|
50
47
|
const objects = await search({
|
|
51
48
|
query: 'companies building CRDTs',
|
|
52
49
|
schema: [Testing.Project, Testing.Organization, Testing.Contact],
|
|
53
|
-
AiService: todo(),
|
|
54
50
|
exaApiKey: EXA_API_KEY,
|
|
55
51
|
});
|
|
56
52
|
|
|
@@ -63,7 +59,6 @@ describe.skip('Search', () => {
|
|
|
63
59
|
const objects = await search({
|
|
64
60
|
context: COMPOSER_DXOS_DOC,
|
|
65
61
|
schema: [Testing.Project, Testing.Organization, Testing.Contact],
|
|
66
|
-
AiService: todo(),
|
|
67
62
|
exaApiKey: EXA_API_KEY,
|
|
68
63
|
});
|
|
69
64
|
|
|
@@ -74,7 +69,6 @@ describe.skip('Search', () => {
|
|
|
74
69
|
const objects = await search({
|
|
75
70
|
context: EDGE_ARCHITECTURE_DOC,
|
|
76
71
|
schema: [Testing.Project, Testing.Organization, Testing.Contact],
|
|
77
|
-
AiService: todo(),
|
|
78
72
|
exaApiKey: EXA_API_KEY,
|
|
79
73
|
});
|
|
80
74
|
|
|
@@ -84,8 +78,7 @@ describe.skip('Search', () => {
|
|
|
84
78
|
});
|
|
85
79
|
|
|
86
80
|
// TODO(dmaretskyi): Import as txt.
|
|
87
|
-
const COMPOSER_DXOS_DOC = `
|
|
88
|
-
|
|
81
|
+
const COMPOSER_DXOS_DOC = trim`
|
|
89
82
|

|
|
90
83
|
# Welcome to Composer by DXOS
|
|
91
84
|
|
|
@@ -219,6 +212,4 @@ const EDGE_ARCHITECTURE_DOC = `
|
|
|
219
212
|
- 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
|
|
220
213
|
|
|
221
214
|
### Service Side
|
|
222
|
-
|
|
223
|
-
|
|
224
215
|
`;
|
package/src/search/exa.ts
CHANGED
|
@@ -2,30 +2,22 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// ISSUE(burdon): deprecated types: MixedStreamParser => effect
|
|
6
|
+
|
|
5
7
|
import { Option, Schema, SchemaAST } from 'effect';
|
|
6
|
-
import Exa from 'exa-js';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
-
import { Key, Obj, Type } from '@dxos/echo';
|
|
9
|
+
import { Key, Obj } from '@dxos/echo';
|
|
10
10
|
import { isEncodedReference } from '@dxos/echo-protocol';
|
|
11
11
|
import { ReferenceAnnotationId } from '@dxos/echo-schema';
|
|
12
12
|
import { mapAst } from '@dxos/effect';
|
|
13
|
-
import { assertArgument, failedInvariant } from '@dxos/invariant';
|
|
14
|
-
import { log } from '@dxos/log';
|
|
15
|
-
import { type ContentBlock, DataType } from '@dxos/schema';
|
|
16
13
|
import { deepMapValues, trim } from '@dxos/util';
|
|
17
14
|
|
|
18
15
|
export type SearchOptions<Schema extends Schema.Schema.AnyNoContext> = {
|
|
19
16
|
query?: string;
|
|
20
|
-
|
|
21
17
|
// TODO(dmaretskyi): How can we pass this through.
|
|
22
18
|
context?: string;
|
|
23
|
-
|
|
24
19
|
schema: Schema[];
|
|
25
|
-
|
|
26
|
-
AiService: AiServiceClient;
|
|
27
20
|
exaApiKey: string;
|
|
28
|
-
|
|
29
21
|
liveCrawl?: boolean;
|
|
30
22
|
};
|
|
31
23
|
|
|
@@ -40,91 +32,77 @@ export type SearchResult<T = unknown> = {
|
|
|
40
32
|
export const search = async <Schema extends Schema.Schema.AnyNoContext>(
|
|
41
33
|
options: SearchOptions<Schema>,
|
|
42
34
|
): Promise<SearchResult<Schema.Schema.Type<Schema>>> => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
let contextSearchTerms: readonly string[] = [];
|
|
46
|
-
if (options.context) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
schema: options.schema[i],
|
|
115
|
-
})) ?? []
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// log('verified objects', { entries });
|
|
120
|
-
|
|
121
|
-
return {
|
|
122
|
-
data: sanitizeObjects(entries),
|
|
123
|
-
metrics: {
|
|
124
|
-
sourceQueryTime,
|
|
125
|
-
dataExtractionTime,
|
|
126
|
-
},
|
|
127
|
-
};
|
|
35
|
+
throw new Error('Not implemented');
|
|
36
|
+
// assertArgument(options.query || options.context, 'query or context is required');
|
|
37
|
+
// let contextSearchTerms: readonly string[] = [];
|
|
38
|
+
// if (options.context) {
|
|
39
|
+
// contextSearchTerms = await getSearchTerms(options.AiService, options.context);
|
|
40
|
+
// log.info('context search terms', { additionalSearchTerms: contextSearchTerms });
|
|
41
|
+
// }
|
|
42
|
+
// const mappedSchema = options.schema.map(mapSchemaRefs);
|
|
43
|
+
// let startTime = performance.now();
|
|
44
|
+
// const exa = new Exa(options.exaApiKey);
|
|
45
|
+
// const context = await exa.searchAndContents(options.query + ' ' + contextSearchTerms.join(' '), {
|
|
46
|
+
// type: 'auto',
|
|
47
|
+
// text: { maxCharacters: 3_000 },
|
|
48
|
+
// livecrawl: options.liveCrawl ? 'always' : undefined,
|
|
49
|
+
// });
|
|
50
|
+
// log.info('context', { context });
|
|
51
|
+
// const sourceQueryTime = performance.now() - startTime;
|
|
52
|
+
// startTime = performance.now();
|
|
53
|
+
// let systemPrompt = DATA_EXTRACTION_INSTRUCTIONS;
|
|
54
|
+
// if (options.query) {
|
|
55
|
+
// systemPrompt += `\n<query>${options.query}</query>`;
|
|
56
|
+
// }
|
|
57
|
+
// if (options.context) {
|
|
58
|
+
// systemPrompt += `\n<search_context>${options.context}</search_context>`;
|
|
59
|
+
// }
|
|
60
|
+
// const result = await getStructuredOutput(options.AiService, {
|
|
61
|
+
// model: '@anthropic/claude-3-5-haiku-20241022',
|
|
62
|
+
// systemPrompt,
|
|
63
|
+
// history: [
|
|
64
|
+
// Obj.make(DataType.Message, {
|
|
65
|
+
// created: new Date().toISOString(),
|
|
66
|
+
// sender: { role: 'user' },
|
|
67
|
+
// blocks: context.results.map(
|
|
68
|
+
// (result): ContentBlock.Text => ({
|
|
69
|
+
// _tag: 'text',
|
|
70
|
+
// text: `# ${result.title}\n\n${result.text}`,
|
|
71
|
+
// }),
|
|
72
|
+
// ),
|
|
73
|
+
// }),
|
|
74
|
+
// ],
|
|
75
|
+
// schema: Schema.Struct({
|
|
76
|
+
// ...Object.fromEntries(
|
|
77
|
+
// mappedSchema.map((schema, index) => [
|
|
78
|
+
// `objects_${index}`,
|
|
79
|
+
// Schema.Array(schema).annotations({
|
|
80
|
+
// description: `The objects to answer the query of type ${Type.getTypename(schema) ?? SchemaAST.getIdentifierAnnotation(schema.ast).pipe(Option.getOrNull)}`,
|
|
81
|
+
// }),
|
|
82
|
+
// ]),
|
|
83
|
+
// ),
|
|
84
|
+
// }),
|
|
85
|
+
// });
|
|
86
|
+
// const dataExtractionTime = performance.now() - startTime;
|
|
87
|
+
// log.info('result', { result });
|
|
88
|
+
// const rawObjects = Object.values(result);
|
|
89
|
+
// // log('rawObjects', { rawObjects });
|
|
90
|
+
// const entries = mappedSchema.flatMap((schema, i) => {
|
|
91
|
+
// return (
|
|
92
|
+
// (rawObjects[i] as any[])?.map((object: any) => ({
|
|
93
|
+
// data: object,
|
|
94
|
+
// schema: options.schema[i],
|
|
95
|
+
// })) ?? []
|
|
96
|
+
// );
|
|
97
|
+
// });
|
|
98
|
+
// // log('verified objects', { entries });
|
|
99
|
+
// return {
|
|
100
|
+
// data: sanitizeObjects(entries),
|
|
101
|
+
// metrics: {
|
|
102
|
+
// sourceQueryTime,
|
|
103
|
+
// dataExtractionTime,
|
|
104
|
+
// },
|
|
105
|
+
// };
|
|
128
106
|
};
|
|
129
107
|
|
|
130
108
|
const DATA_EXTRACTION_INSTRUCTIONS = trim`
|
|
@@ -146,59 +124,59 @@ const DATA_EXTRACTION_INSTRUCTIONS = trim`
|
|
|
146
124
|
/**
|
|
147
125
|
* Runs the LLM to produce a structured output matching a schema
|
|
148
126
|
*/
|
|
149
|
-
const getStructuredOutput = async <S extends Schema.Schema.AnyNoContext>(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
): Promise<Schema.Schema.Type<S>> => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const getSearchTerms = async (AiService: AiServiceClient, context: string) => {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
};
|
|
127
|
+
// const getStructuredOutput = async <S extends Schema.Schema.AnyNoContext>(
|
|
128
|
+
// AiService: AiServiceClient,
|
|
129
|
+
// request: Omit<GenerateRequest, 'tools'> & { schema: S },
|
|
130
|
+
// ): Promise<Schema.Schema.Type<S>> => {
|
|
131
|
+
// const result = await new MixedStreamParser().parse(
|
|
132
|
+
// await AiService.execStream({
|
|
133
|
+
// ...request,
|
|
134
|
+
// systemPrompt:
|
|
135
|
+
// request.systemPrompt +
|
|
136
|
+
// '\nDo not output anything other then the tool call. Call the submit_result tool with the result.',
|
|
137
|
+
// tools: [
|
|
138
|
+
// createTool('submit_result', {
|
|
139
|
+
// name: 'submit_result',
|
|
140
|
+
// description: 'Submit the result',
|
|
141
|
+
// schema: request.schema,
|
|
142
|
+
// execute: async () => failedInvariant(),
|
|
143
|
+
// }),
|
|
144
|
+
// ],
|
|
145
|
+
// }),
|
|
146
|
+
// );
|
|
147
|
+
// return result[0].blocks.find((c) => c._tag === 'toolCall')?.input as any;
|
|
148
|
+
// };
|
|
149
|
+
|
|
150
|
+
// const getSearchTerms = async (AiService: AiServiceClient, context: string) => {
|
|
151
|
+
// const { terms } = await getStructuredOutput(AiService, {
|
|
152
|
+
// model: '@anthropic/claude-3-5-haiku-20241022',
|
|
153
|
+
// systemPrompt: trim`
|
|
154
|
+
// You are a search term extraction agent.
|
|
155
|
+
// Extract the relevant search terms from the context.
|
|
156
|
+
// Return the search terms as an array of strings.
|
|
157
|
+
// Prefer own names of people, companies, and projects, technologies, and other entities.
|
|
158
|
+
// `,
|
|
159
|
+
// history: [
|
|
160
|
+
// Obj.make(DataType.Message, {
|
|
161
|
+
// created: new Date().toISOString(),
|
|
162
|
+
// sender: { role: 'user' },
|
|
163
|
+
// blocks: [
|
|
164
|
+
// {
|
|
165
|
+
// _tag: 'text',
|
|
166
|
+
// text: `# Context to extract search terms from:\n\n${context}`,
|
|
167
|
+
// },
|
|
168
|
+
// ],
|
|
169
|
+
// }),
|
|
170
|
+
// ],
|
|
171
|
+
// schema: Schema.Struct({
|
|
172
|
+
// terms: Schema.Array(Schema.String).annotations({
|
|
173
|
+
// description: 'The search terms to use to find the objects. 0-10 terms.',
|
|
174
|
+
// }),
|
|
175
|
+
// }),
|
|
176
|
+
// });
|
|
177
|
+
|
|
178
|
+
// return terms;
|
|
179
|
+
// };
|
|
202
180
|
|
|
203
181
|
const sanitizeObjects = (entries: { data: any; schema: Schema.Schema.AnyNoContext }[]) => {
|
|
204
182
|
const idMap = new Map<string, string>();
|