@dxos/assistant 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.
Files changed (177) hide show
  1. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  2. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  3. package/dist/lib/browser/extraction/index.mjs +225 -0
  4. package/dist/lib/browser/extraction/index.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +1114 -1843
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  9. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  10. package/dist/lib/node-esm/extraction/index.mjs +226 -0
  11. package/dist/lib/node-esm/extraction/index.mjs.map +7 -0
  12. package/dist/lib/node-esm/index.mjs +1114 -1844
  13. package/dist/lib/node-esm/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/types/src/conversation/context.d.ts +103 -0
  16. package/dist/types/src/conversation/context.d.ts.map +1 -0
  17. package/dist/types/src/conversation/conversation.d.ts +29 -32
  18. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  19. package/dist/types/src/conversation/index.d.ts +1 -0
  20. package/dist/types/src/conversation/index.d.ts.map +1 -1
  21. package/dist/types/src/diff.d.ts +15 -0
  22. package/dist/types/src/diff.d.ts.map +1 -0
  23. package/dist/types/src/diff.test.d.ts +2 -0
  24. package/dist/types/src/diff.test.d.ts.map +1 -0
  25. package/dist/types/src/errors.d.ts +71 -0
  26. package/dist/types/src/errors.d.ts.map +1 -0
  27. package/dist/types/src/execution-graph.d.ts +85 -0
  28. package/dist/types/src/execution-graph.d.ts.map +1 -0
  29. package/dist/types/src/execution-graph.test.d.ts +2 -0
  30. package/dist/types/src/execution-graph.test.d.ts.map +1 -0
  31. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +1 -1
  32. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
  33. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +195 -58
  34. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
  35. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
  36. package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
  37. package/dist/types/src/extraction/extraction.d.ts +264 -165
  38. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  39. package/dist/types/src/extraction/quotes.d.ts +1 -1
  40. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  41. package/dist/types/src/functions/index.d.ts +2 -0
  42. package/dist/types/src/functions/index.d.ts.map +1 -0
  43. package/dist/types/src/functions/services.d.ts +20 -0
  44. package/dist/types/src/functions/services.d.ts.map +1 -0
  45. package/dist/types/src/index.d.ts +5 -5
  46. package/dist/types/src/index.d.ts.map +1 -1
  47. package/dist/types/src/session/GenericToolkit.d.ts +84 -0
  48. package/dist/types/src/session/GenericToolkit.d.ts.map +1 -0
  49. package/dist/types/src/session/artifact-diff.d.ts +27 -0
  50. package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
  51. package/dist/types/src/session/error-handling.d.ts +4 -0
  52. package/dist/types/src/session/error-handling.d.ts.map +1 -0
  53. package/dist/types/src/session/format.d.ts +12 -0
  54. package/dist/types/src/session/format.d.ts.map +1 -0
  55. package/dist/types/src/session/format.test.d.ts +2 -0
  56. package/dist/types/src/session/format.test.d.ts.map +1 -0
  57. package/dist/types/src/session/index.d.ts +4 -0
  58. package/dist/types/src/session/index.d.ts.map +1 -1
  59. package/dist/types/src/session/observer.d.ts +22 -0
  60. package/dist/types/src/session/observer.d.ts.map +1 -0
  61. package/dist/types/src/session/session.d.ts +36 -268
  62. package/dist/types/src/session/session.d.ts.map +1 -1
  63. package/dist/types/src/session/toolkit.d.ts +15 -0
  64. package/dist/types/src/session/toolkit.d.ts.map +1 -0
  65. package/dist/types/src/session/version-pin.d.ts +5 -5
  66. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  67. package/dist/types/src/templates/index.d.ts +2 -0
  68. package/dist/types/src/templates/index.d.ts.map +1 -0
  69. package/dist/types/src/templates/system.d.ts +18 -0
  70. package/dist/types/src/templates/system.d.ts.map +1 -0
  71. package/dist/types/src/types/artifact.d.ts +20 -0
  72. package/dist/types/src/types/artifact.d.ts.map +1 -0
  73. package/dist/types/src/types/index.d.ts +2 -0
  74. package/dist/types/src/types/index.d.ts.map +1 -0
  75. package/dist/types/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +48 -26
  77. package/src/conversation/context.ts +186 -0
  78. package/src/conversation/conversation.ts +101 -76
  79. package/src/conversation/index.ts +1 -0
  80. package/src/diff.test.ts +43 -0
  81. package/src/diff.ts +84 -0
  82. package/src/errors.ts +15 -0
  83. package/src/execution-graph.test.ts +740 -0
  84. package/src/execution-graph.ts +509 -0
  85. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +14 -25
  86. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +48 -52
  87. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +18 -17
  88. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +43 -41
  89. package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +12 -6
  90. package/src/extraction/extraction-ner-function/named-entity-recognition.ts +3 -1
  91. package/src/extraction/extraction.ts +7 -6
  92. package/src/extraction/quotes.test.ts +3 -3
  93. package/src/extraction/quotes.ts +4 -4
  94. package/src/functions/index.ts +5 -0
  95. package/src/functions/services.ts +162 -0
  96. package/src/index.ts +5 -5
  97. package/src/session/GenericToolkit.ts +130 -0
  98. package/src/session/artifact-diff.ts +41 -0
  99. package/src/session/error-handling.ts +41 -0
  100. package/src/session/format.test.ts +61 -0
  101. package/src/session/format.ts +144 -0
  102. package/src/session/index.ts +5 -0
  103. package/src/session/observer.ts +59 -0
  104. package/src/session/session.conversations.json +1 -0
  105. package/src/session/session.test.ts +88 -214
  106. package/src/session/session.ts +170 -539
  107. package/src/session/toolkit.ts +48 -0
  108. package/src/session/version-pin.ts +11 -12
  109. package/src/templates/index.ts +5 -0
  110. package/src/templates/instructions/format.tpl +61 -0
  111. package/src/templates/instructions/system.tpl +48 -0
  112. package/src/templates/system.ts +41 -0
  113. package/src/types/artifact.ts +71 -0
  114. package/src/types/index.ts +5 -0
  115. package/src/typings.d.ts +5 -0
  116. package/dist/types/bin/chat.d.ts +0 -2
  117. package/dist/types/bin/chat.d.ts.map +0 -1
  118. package/dist/types/src/blueprint/blueprint.d.ts +0 -41
  119. package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
  120. package/dist/types/src/blueprint/index.d.ts +0 -3
  121. package/dist/types/src/blueprint/index.d.ts.map +0 -1
  122. package/dist/types/src/blueprint/registry.d.ts +0 -7
  123. package/dist/types/src/blueprint/registry.d.ts.map +0 -1
  124. package/dist/types/src/context/binder.d.ts +0 -34
  125. package/dist/types/src/context/binder.d.ts.map +0 -1
  126. package/dist/types/src/context/binding.d.ts +0 -38
  127. package/dist/types/src/context/binding.d.ts.map +0 -1
  128. package/dist/types/src/context/index.d.ts +0 -3
  129. package/dist/types/src/context/index.d.ts.map +0 -1
  130. package/dist/types/src/research/exa.d.ts +0 -7
  131. package/dist/types/src/research/exa.d.ts.map +0 -1
  132. package/dist/types/src/research/graph.d.ts +0 -41
  133. package/dist/types/src/research/graph.d.ts.map +0 -1
  134. package/dist/types/src/research/graph.test.d.ts +0 -2
  135. package/dist/types/src/research/graph.test.d.ts.map +0 -1
  136. package/dist/types/src/research/index.d.ts +0 -4
  137. package/dist/types/src/research/index.d.ts.map +0 -1
  138. package/dist/types/src/research/research.d.ts +0 -10
  139. package/dist/types/src/research/research.d.ts.map +0 -1
  140. package/dist/types/src/research/research.test.d.ts +0 -2
  141. package/dist/types/src/research/research.test.d.ts.map +0 -1
  142. package/dist/types/src/session/version-pin.test.d.ts +0 -2
  143. package/dist/types/src/session/version-pin.test.d.ts.map +0 -1
  144. package/dist/types/src/summarization/summarization.test.d.ts +0 -2
  145. package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
  146. package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
  147. package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
  148. package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
  149. package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
  150. package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
  151. package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
  152. package/dist/types/src/testing/index.d.ts +0 -3
  153. package/dist/types/src/testing/index.d.ts.map +0 -1
  154. package/dist/types/src/types.d.ts +0 -3
  155. package/dist/types/src/types.d.ts.map +0 -1
  156. package/src/blueprint/blueprint.ts +0 -75
  157. package/src/blueprint/index.ts +0 -6
  158. package/src/blueprint/registry.ts +0 -15
  159. package/src/context/binder.ts +0 -101
  160. package/src/context/binding.ts +0 -31
  161. package/src/context/index.ts +0 -6
  162. package/src/research/exa.ts +0 -100
  163. package/src/research/graph.test.ts +0 -15
  164. package/src/research/graph.ts +0 -337
  165. package/src/research/index.ts +0 -7
  166. package/src/research/instructions-research.tpl +0 -97
  167. package/src/research/research.test.ts +0 -190
  168. package/src/research/research.ts +0 -90
  169. package/src/session/version-pin.test.ts +0 -26
  170. package/src/summarization/summarization.test.ts +0 -221
  171. package/src/testing/exa-search-1748337321991.ts +0 -131
  172. package/src/testing/exa-search-1748337331526.ts +0 -144
  173. package/src/testing/exa-search-1748337344119.ts +0 -133
  174. package/src/testing/index.ts +0 -11
  175. package/src/typedefs.d.ts +0 -8
  176. package/src/types.ts +0 -8
  177. /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
@@ -1,38 +0,0 @@
1
- declare const _default: {
2
- requestId: string;
3
- autopromptString: string;
4
- autoDate: string;
5
- resolvedSearchType: string;
6
- results: ({
7
- id: string;
8
- title: string;
9
- url: string;
10
- publishedDate: string;
11
- author: string;
12
- score: number;
13
- text: string;
14
- image?: undefined;
15
- favicon?: undefined;
16
- } | {
17
- id: string;
18
- title: string;
19
- url: string;
20
- publishedDate: string;
21
- author: string;
22
- score: number;
23
- text: string;
24
- image: string;
25
- favicon: string;
26
- })[];
27
- costDollars: {
28
- total: number;
29
- search: {
30
- neural: number;
31
- };
32
- contents: {
33
- text: number;
34
- };
35
- };
36
- };
37
- export default _default;
38
- //# sourceMappingURL=exa-search-1748337321991.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exa-search-1748337321991.d.ts","sourceRoot":"","sources":["../../../../src/testing/exa-search-1748337321991.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBA8HE"}
@@ -1,37 +0,0 @@
1
- declare const _default: {
2
- requestId: string;
3
- autopromptString: string;
4
- resolvedSearchType: string;
5
- results: ({
6
- id: string;
7
- title: string;
8
- url: string;
9
- publishedDate: string;
10
- author: string;
11
- score: number;
12
- text: string;
13
- image: string;
14
- favicon: string;
15
- } | {
16
- id: string;
17
- title: string;
18
- url: string;
19
- publishedDate: string;
20
- author: string;
21
- text: string;
22
- image: string;
23
- favicon: string;
24
- score?: undefined;
25
- })[];
26
- costDollars: {
27
- total: number;
28
- search: {
29
- neural: number;
30
- };
31
- contents: {
32
- text: number;
33
- };
34
- };
35
- };
36
- export default _default;
37
- //# sourceMappingURL=exa-search-1748337331526.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exa-search-1748337331526.d.ts","sourceRoot":"","sources":["../../../../src/testing/exa-search-1748337331526.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBA2IE"}
@@ -1,58 +0,0 @@
1
- declare const _default: {
2
- requestId: string;
3
- autopromptString: string;
4
- autoDate: string;
5
- resolvedSearchType: string;
6
- results: ({
7
- id: string;
8
- title: string;
9
- url: string;
10
- publishedDate: string;
11
- author: string;
12
- score: number;
13
- text: string;
14
- favicon: string;
15
- image?: undefined;
16
- } | {
17
- id: string;
18
- title: string;
19
- url: string;
20
- publishedDate: string;
21
- author: string;
22
- score: number;
23
- text: string;
24
- favicon?: undefined;
25
- image?: undefined;
26
- } | {
27
- id: string;
28
- title: string;
29
- url: string;
30
- publishedDate: string;
31
- author: string;
32
- score: number;
33
- text: string;
34
- image: string;
35
- favicon: string;
36
- } | {
37
- id: string;
38
- title: string;
39
- url: string;
40
- author: string;
41
- text: string;
42
- image: string;
43
- favicon: string;
44
- publishedDate?: undefined;
45
- score?: undefined;
46
- })[];
47
- costDollars: {
48
- total: number;
49
- search: {
50
- neural: number;
51
- };
52
- contents: {
53
- text: number;
54
- };
55
- };
56
- };
57
- export default _default;
58
- //# sourceMappingURL=exa-search-1748337344119.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exa-search-1748337344119.d.ts","sourceRoot":"","sources":["../../../../src/testing/exa-search-1748337344119.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBAgIE"}
@@ -1,3 +0,0 @@
1
- import type { SearchResponse } from 'exa-js';
2
- export declare const SEARCH_RESULTS: SearchResponse<any>[];
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAM7C,eAAO,MAAM,cAAc,EAAE,cAAc,CAAC,GAAG,CAAC,EAAgC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { type ObjectId } from '@dxos/echo-schema';
2
- export declare const createArtifactElement: (id: ObjectId) => string;
3
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlD,eAAO,MAAM,qBAAqB,GAAI,IAAI,QAAQ,WAA4B,CAAC"}
@@ -1,75 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import { ToolId } from '@dxos/ai';
8
- import { Type } from '@dxos/echo';
9
- import { LabelAnnotation } from '@dxos/echo-schema';
10
-
11
- /**
12
- * Blueprint schema defines the structure for AI assistant blueprints.
13
- * Blueprints contain instructions, tools, and artifacts that guide the AI's behavior.
14
- */
15
- export const Blueprint = Schema.Struct({
16
- /**
17
- * Global registry ID.
18
- * NOTE: Once a blueprint has been cloned from the registry, its stored definition may converge,
19
- * but the `key` property refers to the original registry entry.
20
- */
21
- // TODO(burdon): Create Format type.
22
- key: Schema.String.annotations({
23
- description: 'Unique registration key for the blueprint',
24
- }),
25
-
26
- /**
27
- * Human-readable name of the blueprint.
28
- */
29
- name: Schema.String.annotations({
30
- description: 'Human-readable name of the blueprint',
31
- }),
32
-
33
- /**
34
- * Description of the blueprint's purpose and functionality.
35
- */
36
- description: Schema.optional(Schema.String).annotations({
37
- description: "Description of the blueprint's purpose and functionality",
38
- }),
39
-
40
- /**
41
- * Instructions that guide the AI assistant's behavior and responses.
42
- * These are system prompts or guidelines that the AI should follow.
43
- */
44
- instructions: Schema.String.annotations({
45
- description: "Instructions that guide the AI assistant's behavior and responses",
46
- }),
47
-
48
- /**
49
- * Array of tools that the AI assistant can use when this blueprint is active.
50
- */
51
- tools: Schema.Array(ToolId).annotations({
52
- description: 'Array of tools that the AI assistant can use when this blueprint is active',
53
- }),
54
-
55
- /**
56
- * Array of artifacts that the AI assistant can create or modify.
57
- */
58
- artifacts: Schema.Array(Schema.String).annotations({
59
- description: 'Ids of artifact definitions that should be pulled into the blueprint',
60
- }),
61
- }).pipe(
62
- Type.Obj({
63
- // TODO(burdon): Is this a DXN? Need to create a Format type for these IDs.
64
- typename: 'dxos.org/type/Blueprint',
65
- version: '0.1.0',
66
- }),
67
-
68
- // TODO(burdon): Move to main API.
69
- LabelAnnotation.set(['name']),
70
- );
71
-
72
- /**
73
- * TypeScript type for Blueprint.
74
- */
75
- export interface Blueprint extends Schema.Schema.Type<typeof Blueprint> {}
@@ -1,6 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- export * from './blueprint';
6
- export * from './registry';
@@ -1,15 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type Blueprint } from './blueprint';
6
-
7
- export class BlueprintRegistry {
8
- constructor(private readonly _blueprints: Blueprint[]) {
9
- this._blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));
10
- }
11
-
12
- query(): Blueprint[] {
13
- return this._blueprints;
14
- }
15
- }
@@ -1,101 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { computed, type ReadonlySignal } from '@preact/signals-core';
6
- import { Array, pipe } from 'effect';
7
-
8
- import { Obj, type Type, type Ref, type Relation } from '@dxos/echo';
9
- import { type Queue } from '@dxos/echo-db';
10
- import { ComplexSet } from '@dxos/util';
11
-
12
- import { ContextBinding } from './binding';
13
- import { type Blueprint } from '../blueprint';
14
-
15
- /**
16
- * Manages bindings of blueprints and objects to a conversation.
17
- */
18
- export class ContextBinder {
19
- constructor(private readonly _queue: Queue) {}
20
-
21
- /**
22
- * Reactive query of all bindings.
23
- */
24
- // TODO(burdon): Cache value?
25
- readonly bindings: ReadonlySignal<Bindings> = computed(() => this._reduce(this._queue.objects));
26
-
27
- // TODO(burdon): load refs?
28
- readonly blueprints: ReadonlySignal<Ref.Ref<Blueprint>[]> = computed(() => [...this.bindings.value.blueprints]);
29
- readonly objects: ReadonlySignal<Ref.Ref<Type.Expando>[]> = computed(() => [...this.bindings.value.objects]);
30
-
31
- /**
32
- * Asynchronous query of all bindings.
33
- */
34
- async query(): Promise<Bindings> {
35
- const queueItems = await this._queue.queryObjects();
36
- return this._reduce(queueItems);
37
- }
38
-
39
- // TODO(burdon): Pass in Blueprint obj (from registry?) and create reference.
40
- async bind(props: BindingProps): Promise<void> {
41
- if (!props.blueprints?.length && !props.objects?.length) {
42
- return;
43
- }
44
-
45
- await this._queue.append([
46
- Obj.make(ContextBinding, {
47
- blueprints: {
48
- added: props.blueprints ?? [],
49
- removed: [],
50
- },
51
- objects: {
52
- added: props.objects ?? [],
53
- removed: [],
54
- },
55
- }),
56
- ]);
57
- }
58
-
59
- async unbind(props: BindingProps): Promise<void> {
60
- if (!props.blueprints?.length && !props.objects?.length) {
61
- return;
62
- }
63
-
64
- await this._queue.append([
65
- Obj.make(ContextBinding, {
66
- blueprints: {
67
- added: [],
68
- removed: props.blueprints ?? [],
69
- },
70
- objects: {
71
- added: [],
72
- removed: props.objects ?? [],
73
- },
74
- }),
75
- ]);
76
- }
77
-
78
- private _reduce(items: (Obj.Any | Relation.Any)[]): Bindings {
79
- return pipe(
80
- items,
81
- Array.filter(Obj.instanceOf(ContextBinding)),
82
- Array.reduce(new Bindings(), (context, item) => {
83
- item.blueprints.removed.forEach((item) => context.blueprints.delete(item));
84
- item.blueprints.added.forEach((item) => context.blueprints.add(item));
85
- item.objects.removed.forEach((item) => context.objects.delete(item));
86
- item.objects.added.forEach((item) => context.objects.add(item));
87
- return context;
88
- }),
89
- );
90
- }
91
- }
92
-
93
- export type BindingProps = Partial<{
94
- blueprints: Ref.Ref<Blueprint>[];
95
- objects: Ref.Ref<Type.Expando>[];
96
- }>;
97
-
98
- export class Bindings {
99
- blueprints = new ComplexSet<Ref.Ref<Blueprint>>((ref) => ref.dxn.toString());
100
- objects = new ComplexSet<Ref.Ref<Type.Expando>>((ref) => ref.dxn.toString());
101
- }
@@ -1,31 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import { Type } from '@dxos/echo';
8
-
9
- import { Blueprint } from '../blueprint';
10
- /**
11
- * Thread message that binds or unbinds contextual objects to a conversation.
12
- */
13
- export const ContextBinding = Schema.Struct({
14
- blueprints: Schema.Struct({
15
- added: Schema.Array(Type.Ref(Blueprint)),
16
- removed: Schema.Array(Type.Ref(Blueprint)),
17
- }),
18
-
19
- // TODO(burdon): Type.Expando => Type.Obj (or Obj.Any?)
20
- objects: Schema.Struct({
21
- added: Schema.Array(Type.Ref(Type.Expando)),
22
- removed: Schema.Array(Type.Ref(Type.Expando)),
23
- }),
24
- }).pipe(
25
- Type.Obj({
26
- typename: 'dxos.org/type/ContextBinding',
27
- version: '0.1.0',
28
- }),
29
- );
30
-
31
- export interface ContextBinding extends Schema.Schema.Type<typeof ContextBinding> {}
@@ -1,6 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- export * from './binder';
6
- export * from './binding';
@@ -1,100 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
- import Exa from 'exa-js';
7
-
8
- import { createTool, ToolResult } from '@dxos/ai';
9
- import { log } from '@dxos/log';
10
-
11
- import { SEARCH_RESULTS } from '../testing';
12
-
13
- type CreateExaToolOptions = {
14
- apiKey: string;
15
- };
16
-
17
- export const createExaTool = ({ apiKey }: CreateExaToolOptions) => {
18
- const exa = new Exa(apiKey);
19
-
20
- return createTool('search', {
21
- name: 'web_search',
22
- description: 'Search the web for information',
23
- schema: Schema.Struct({
24
- query: Schema.String.annotations({ description: 'The query to search for' }),
25
- }),
26
- execute: async ({ query }) => {
27
- const context = await exa.searchAndContents(query, {
28
- type: 'auto',
29
- text: {
30
- maxCharacters: 3_000,
31
- },
32
- livecrawl: 'always',
33
- });
34
-
35
- log.info('exa search', { query, costDollars: context.costDollars });
36
-
37
- return ToolResult.Success(context);
38
- },
39
- });
40
- };
41
-
42
- export const createMockExaTool = () => {
43
- return createTool('search', {
44
- name: 'web_search',
45
- description: 'Search the web for information',
46
- schema: Schema.Struct({
47
- query: Schema.String.annotations({ description: 'The query to search for' }),
48
- }),
49
- execute: async ({ query }) => {
50
- // Find result with closest matching autoprompt using weighted Levenshtein distance
51
- const result = SEARCH_RESULTS.reduce(
52
- (closest, current) => {
53
- if (!current.autopromptString) {
54
- return closest;
55
- }
56
- if (!closest) {
57
- return current;
58
- }
59
-
60
- // Calculate Levenshtein distance
61
- const dist1 = levenshteinDistance(query, current.autopromptString);
62
- const dist2 = levenshteinDistance(query, closest.autopromptString || '');
63
-
64
- // Weight by length of the longer string to normalize
65
- const weight1 = dist1 / Math.max(query.length, current.autopromptString.length);
66
- const weight2 = dist2 / Math.max(query.length, closest.autopromptString?.length || 0);
67
-
68
- return weight1 < weight2 ? current : closest;
69
- },
70
- null as (typeof SEARCH_RESULTS)[0] | null,
71
- );
72
-
73
- return ToolResult.Success(result);
74
- },
75
- });
76
- };
77
-
78
- const levenshteinDistance = (str1: string, str2: string): number => {
79
- const m = str1.length;
80
- const n = str2.length;
81
- const dp: number[][] = Array(m + 1)
82
- .fill(null)
83
- .map(() => Array(n + 1).fill(0));
84
-
85
- for (let i = 0; i <= m; i++) {
86
- dp[i][0] = i;
87
- }
88
- for (let j = 0; j <= n; j++) {
89
- dp[0][j] = j;
90
- }
91
-
92
- for (let i = 1; i <= m; i++) {
93
- for (let j = 1; j <= n; j++) {
94
- dp[i][j] =
95
- str1[i - 1] === str2[j - 1] ? dp[i - 1][j - 1] : Math.min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1;
96
- }
97
- }
98
-
99
- return dp[m][n];
100
- };
@@ -1,15 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { describe } from 'vitest';
6
-
7
- // import { type EchoTestBuilder } from '@dxos/echo-db/testing';
8
-
9
- describe('graph', () => {
10
- // let builder: EchoTestBuilder;
11
- // test('findRelatedSchema', async () => {
12
- // const db = await createEchoDatabase();
13
- // const relatedSchemas = await findRelatedSchema(db, Schema.Struct({}));
14
- // });
15
- });