@dxos/assistant 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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 (142) hide show
  1. package/README.md +1 -0
  2. package/dist/lib/neutral/chunk-UAWIXKF6.mjs +1875 -0
  3. package/dist/lib/neutral/chunk-UAWIXKF6.mjs.map +7 -0
  4. package/dist/lib/{browser → neutral}/extraction/index.mjs +29 -35
  5. package/dist/lib/neutral/extraction/index.mjs.map +7 -0
  6. package/dist/lib/neutral/index.mjs +551 -0
  7. package/dist/lib/neutral/index.mjs.map +7 -0
  8. package/dist/lib/neutral/meta.json +1 -0
  9. package/dist/lib/neutral/testing/index.mjs +114 -0
  10. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  11. package/dist/types/src/conversation/context.d.ts +116 -64
  12. package/dist/types/src/conversation/context.d.ts.map +1 -1
  13. package/dist/types/src/conversation/context.test.d.ts +2 -0
  14. package/dist/types/src/conversation/context.test.d.ts.map +1 -0
  15. package/dist/types/src/conversation/conversation.d.ts +45 -18
  16. package/dist/types/src/conversation/conversation.d.ts.map +1 -1
  17. package/dist/types/src/conversation/conversation.test.d.ts +2 -0
  18. package/dist/types/src/conversation/conversation.test.d.ts.map +1 -0
  19. package/dist/types/src/diff.d.ts +3 -1
  20. package/dist/types/src/diff.d.ts.map +1 -1
  21. package/dist/types/src/errors.d.ts +12 -16
  22. package/dist/types/src/errors.d.ts.map +1 -1
  23. package/dist/types/src/execution-graph.d.ts +2 -2
  24. package/dist/types/src/execution-graph.d.ts.map +1 -1
  25. package/dist/types/src/extraction/extraction-ner-function/index.d.ts +0 -1
  26. package/dist/types/src/extraction/extraction-ner-function/index.d.ts.map +1 -1
  27. package/dist/types/src/extraction/extraction.d.ts +1059 -313
  28. package/dist/types/src/extraction/extraction.d.ts.map +1 -1
  29. package/dist/types/src/extraction/index.d.ts +0 -1
  30. package/dist/types/src/extraction/index.d.ts.map +1 -1
  31. package/dist/types/src/extraction/quotes.d.ts +2 -2
  32. package/dist/types/src/extraction/quotes.d.ts.map +1 -1
  33. package/dist/types/src/functions/services.d.ts +28 -9
  34. package/dist/types/src/functions/services.d.ts.map +1 -1
  35. package/dist/types/src/functions.test.d.ts +2 -0
  36. package/dist/types/src/functions.test.d.ts.map +1 -0
  37. package/dist/types/src/index.d.ts +2 -0
  38. package/dist/types/src/index.d.ts.map +1 -1
  39. package/dist/types/src/service/AgentService.d.ts +61 -0
  40. package/dist/types/src/service/AgentService.d.ts.map +1 -0
  41. package/dist/types/src/service/AgentService.test.d.ts +2 -0
  42. package/dist/types/src/service/AgentService.test.d.ts.map +1 -0
  43. package/dist/types/src/service/agent-process.d.ts +17 -0
  44. package/dist/types/src/service/agent-process.d.ts.map +1 -0
  45. package/dist/types/src/service/index.d.ts +3 -0
  46. package/dist/types/src/service/index.d.ts.map +1 -0
  47. package/dist/types/src/session/artifact-diff.d.ts +1 -1
  48. package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
  49. package/dist/types/src/session/format.d.ts +3 -3
  50. package/dist/types/src/session/format.d.ts.map +1 -1
  51. package/dist/types/src/session/index.d.ts +1 -1
  52. package/dist/types/src/session/index.d.ts.map +1 -1
  53. package/dist/types/src/session/observer.d.ts +4 -3
  54. package/dist/types/src/session/observer.d.ts.map +1 -1
  55. package/dist/types/src/session/session.d.ts +72 -11
  56. package/dist/types/src/session/session.d.ts.map +1 -1
  57. package/dist/types/src/session/toolkit.d.ts +9 -6
  58. package/dist/types/src/session/toolkit.d.ts.map +1 -1
  59. package/dist/types/src/session/version-pin.d.ts +2 -2
  60. package/dist/types/src/session/version-pin.d.ts.map +1 -1
  61. package/dist/types/src/templates/system.d.ts +0 -1
  62. package/dist/types/src/templates/system.d.ts.map +1 -1
  63. package/dist/types/src/testing/index.d.ts +2 -0
  64. package/dist/types/src/testing/index.d.ts.map +1 -0
  65. package/dist/types/src/testing/layer.d.ts +35 -0
  66. package/dist/types/src/testing/layer.d.ts.map +1 -0
  67. package/dist/types/src/tracing.d.ts +264 -0
  68. package/dist/types/src/tracing.d.ts.map +1 -0
  69. package/dist/types/src/types/artifact.d.ts +13 -5
  70. package/dist/types/src/types/artifact.d.ts.map +1 -1
  71. package/dist/types/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +42 -33
  73. package/src/conversation/context.test.ts +52 -0
  74. package/src/conversation/context.ts +307 -90
  75. package/src/conversation/conversation.test.ts +58 -0
  76. package/src/conversation/conversation.ts +209 -62
  77. package/src/diff.test.ts +36 -5
  78. package/src/diff.ts +13 -4
  79. package/src/errors.ts +2 -2
  80. package/src/execution-graph.test.ts +3 -3
  81. package/src/execution-graph.ts +6 -6
  82. package/src/extraction/extraction-ner-function/index.ts +0 -1
  83. package/src/extraction/extraction.ts +40 -12
  84. package/src/extraction/index.ts +0 -1
  85. package/src/extraction/quotes.ts +4 -5
  86. package/src/functions/services.ts +217 -50
  87. package/src/functions.conversations.json +1 -0
  88. package/src/functions.test.ts +82 -0
  89. package/src/index.ts +2 -0
  90. package/src/service/AgentService.conversations.json +1 -0
  91. package/src/service/AgentService.test.ts +169 -0
  92. package/src/service/AgentService.ts +165 -0
  93. package/src/service/agent-process.ts +359 -0
  94. package/src/service/index.ts +6 -0
  95. package/src/session/artifact-diff.ts +1 -1
  96. package/src/session/format.test.ts +110 -39
  97. package/src/session/format.ts +12 -14
  98. package/src/session/index.ts +1 -2
  99. package/src/session/observer.ts +4 -1
  100. package/src/session/session.conversations.json +1 -1
  101. package/src/session/session.test.ts +58 -17
  102. package/src/session/session.ts +249 -113
  103. package/src/session/toolkit.ts +21 -25
  104. package/src/session/version-pin.ts +4 -3
  105. package/src/templates/instructions/format.tpl +0 -4
  106. package/src/templates/instructions/system.tpl +11 -2
  107. package/src/templates/system.ts +6 -5
  108. package/src/testing/index.ts +5 -0
  109. package/src/testing/layer.ts +258 -0
  110. package/src/tracing.ts +113 -0
  111. package/src/types/artifact.ts +31 -13
  112. package/dist/lib/browser/extraction/index.mjs.map +0 -7
  113. package/dist/lib/browser/index.mjs +0 -1290
  114. package/dist/lib/browser/index.mjs.map +0 -7
  115. package/dist/lib/browser/meta.json +0 -1
  116. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
  117. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
  118. package/dist/lib/node-esm/extraction/index.mjs +0 -226
  119. package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
  120. package/dist/lib/node-esm/index.mjs +0 -1291
  121. package/dist/lib/node-esm/index.mjs.map +0 -7
  122. package/dist/lib/node-esm/meta.json +0 -1
  123. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts +0 -4
  124. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +0 -1
  125. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts +0 -2
  126. package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.test.d.ts.map +0 -1
  127. package/dist/types/src/extraction/extraction-llm-function/index.d.ts +0 -2
  128. package/dist/types/src/extraction/extraction-llm-function/index.d.ts.map +0 -1
  129. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +0 -345
  130. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +0 -1
  131. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts +0 -2
  132. package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.test.d.ts.map +0 -1
  133. package/dist/types/src/session/GenericToolkit.d.ts +0 -84
  134. package/dist/types/src/session/GenericToolkit.d.ts.map +0 -1
  135. package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +0 -84
  136. package/src/extraction/extraction-llm-function/extraction-llm-function.ts +0 -62
  137. package/src/extraction/extraction-llm-function/index.ts +0 -5
  138. package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +0 -116
  139. package/src/extraction/extraction-ner-function/extraction-ner-function.ts +0 -56
  140. package/src/session/GenericToolkit.ts +0 -130
  141. /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
  142. /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs.map +0 -0
@@ -1,116 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { beforeAll, describe, test } from 'vitest';
6
-
7
- import { type EchoDatabase } from '@dxos/echo-db';
8
- import { EchoTestBuilder } from '@dxos/echo-db/testing';
9
- import { FunctionExecutor, ServiceContainer } from '@dxos/functions-runtime';
10
- import { log } from '@dxos/log';
11
- import { Testing } from '@dxos/schema/testing';
12
- import { type Message, Organization, Person } from '@dxos/types';
13
- import { createTestData } from '@dxos/types/testing';
14
- import { range } from '@dxos/util';
15
-
16
- import { processTranscriptMessage } from '../extraction';
17
-
18
- import { extractionNerFunction } from './extraction-ner-function';
19
-
20
- describe.skip('NER EntityExtraction', () => {
21
- let builder: EchoTestBuilder;
22
- let db: EchoDatabase;
23
- let executor: FunctionExecutor;
24
- let testData: {
25
- transcriptJosiah: Message.Message[];
26
- transcriptWoflram: Message.Message[];
27
- transcriptMessages: Message.Message[];
28
- documents: Testing.DocumentType[];
29
- contacts: Record<string, Person.Person>;
30
- organizations: Record<string, Organization.Organization>;
31
- };
32
-
33
- const TYPES = [Organization.Organization, Person.Person, Testing.Person, Testing.DocumentType];
34
-
35
- beforeAll(async () => {
36
- // TODO(dmaretskyi): Helper to scaffold this from a config.
37
- builder = await new EchoTestBuilder().open();
38
- const { db: db1 } = await builder.createDatabase({ indexing: { vector: true } });
39
- db = db1;
40
- db.graph.schemaRegistry.addSchema(TYPES);
41
- const data = createTestData();
42
- testData = {
43
- transcriptJosiah: data.transcriptJosiah,
44
- transcriptWoflram: data.transcriptWoflram,
45
- transcriptMessages: data.transcriptMessages,
46
- documents: data.documents.map((document) => db.add(document)),
47
- contacts: Object.fromEntries(Object.entries(data.contacts).map(([key, value]) => [key, db.add(value)])),
48
- organizations: Object.fromEntries(Object.entries(data.organizations).map(([key, value]) => [key, db.add(value)])),
49
- };
50
-
51
- await db.flush();
52
- executor = new FunctionExecutor(
53
- new ServiceContainer().setServices({
54
- database: { db },
55
- }),
56
- );
57
- }, 30_000);
58
-
59
- test('should process a transcript block', async () => {
60
- const { transcriptMessages, documents, contacts } = testData;
61
- log.info('context', { documents, contacts });
62
-
63
- for (const message of transcriptMessages) {
64
- log.info('input', message);
65
- const { message: enhancedMessage } = await processTranscriptMessage({
66
- input: {
67
- message,
68
- objects: [...documents, ...Object.values(contacts)],
69
- },
70
- function: extractionNerFunction,
71
- executor,
72
- });
73
- log.info('output', enhancedMessage);
74
- }
75
- });
76
-
77
- test('computational irreducibility', async () => {
78
- const { transcriptWoflram, documents, contacts } = testData;
79
- log.info('context', { documents, contacts });
80
- const message = transcriptWoflram[0];
81
- log.info('input', message);
82
-
83
- await Promise.all(
84
- range(10).map(async () => {
85
- const { message: enhancedMessage, timeElapsed } = await processTranscriptMessage({
86
- input: {
87
- message,
88
- objects: [...documents, ...Object.values(contacts)],
89
- },
90
- function: extractionNerFunction,
91
- executor,
92
- });
93
- log.info('output', { message: enhancedMessage.blocks[0], timeElapsed });
94
- }),
95
- );
96
- });
97
-
98
- test('org and document linking', async () => {
99
- const { transcriptJosiah, documents, contacts, organizations } = testData;
100
- log.info('context', { contacts, organizations, documents });
101
-
102
- for (const message of transcriptJosiah) {
103
- log.info('input', message);
104
-
105
- const { message: enhancedMessage } = await processTranscriptMessage({
106
- input: {
107
- message,
108
- objects: [...documents, ...Object.values(contacts), ...Object.values(organizations)],
109
- },
110
- function: extractionNerFunction,
111
- executor,
112
- });
113
- log.info('output', enhancedMessage);
114
- }
115
- });
116
- });
@@ -1,56 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { defineFunction } from '@dxos/functions';
6
-
7
- import { ExtractionInput, ExtractionOutput } from '../extraction';
8
-
9
- /**
10
- * Named Entity Recognition model
11
- */
12
- // TODO(mykola): Make it use vector index to query objects and not pass objects as input.
13
- export const extractionNerFunction = defineFunction({
14
- key: 'dxos.org/function/extraction/extract-entities',
15
- name: 'Extract Entities',
16
- description: 'Extracts named entities from a text',
17
- inputSchema: ExtractionInput,
18
- outputSchema: ExtractionOutput,
19
- handler: async ({ data: { message, options }, context }) => {
20
- throw new Error('not implemented');
21
- // log.info('input', { message, options });
22
- // const startTime = performance.now();
23
- // const { db } = context.getService(DatabaseService);
24
- // const { extractFullEntities } = await import('./named-entity-recognition');
25
-
26
- // const entitiesPromise = Promise.all(
27
- // message.blocks.map(async (block) => {
28
- // invariant(block._tag === 'transcript' || block._tag === 'text');
29
- // return extractFullEntities(block.text);
30
- // }),
31
- // ).then((entities) => entities.flat());
32
- // const entities = options?.timeout ? await asyncTimeout(entitiesPromise, options.timeout) : await entitiesPromise;
33
-
34
- // log.info('entities', { entities });
35
- // const quoteReferences = await findQuotes(
36
- // entities.map((entity) => entity.word),
37
- // db,
38
- // );
39
-
40
- // const blocksWithReferences = message.blocks.map((block) => {
41
- // invariant(block._tag === 'transcript' || block._tag === 'text');
42
- // return { ...block, text: insertReferences(block._tag, quoteReferences) };
43
- // });
44
-
45
- // const messageWithReferences = create(Message.Message, {
46
- // ...message,
47
- // blocks: blocksWithReferences,
48
- // });
49
-
50
- // log.info('output', { messageWithReferences });
51
- // return {
52
- // message: messageWithReferences,
53
- // timeElapsed: performance.now() - startTime,
54
- // };
55
- },
56
- });
@@ -1,130 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import type * as Tool from '@effect/ai/Tool';
6
- import * as Toolkit from '@effect/ai/Toolkit';
7
- import * as Effect from 'effect/Effect';
8
- import * as Layer from 'effect/Layer';
9
- import * as Pipeable from 'effect/Pipeable';
10
- import type * as Schema from 'effect/Schema';
11
- import type * as SchemaAST from 'effect/SchemaAST';
12
-
13
- /**
14
- * Unique identifier for generic toolkit instances.
15
- */
16
- export const TypeId = '~@dxos/assistant/GenericToolkit';
17
-
18
- /**
19
- * Type-level representation of the generic toolkit identifier.
20
- */
21
- export type TypeId = typeof TypeId;
22
-
23
- /**
24
- * Type-safe way to define toolkits where we don't know specific types of tools,
25
- * and we want to bundle definition and handlers together.
26
- *
27
- * Usefull for plugin-based systems, where tools are dynamically added.
28
- *
29
- * @param TR requirements type to the tool invocation.
30
- * @param E failure type to the handlers layer.
31
- * @param R requirements type to the handlers layer.
32
- */
33
- export interface GenericToolkit<TR = never, E = never, R = never> extends Pipeable.Pipeable {
34
- readonly [TypeId]: TypeId;
35
-
36
- /**
37
- * Toolkit definition.
38
- */
39
- readonly toolkit: Toolkit.Toolkit<GenericTools<TR>>;
40
-
41
- /**
42
- * Handlers layer.
43
- */
44
- readonly layer: Layer.Layer<unknown, E, R>;
45
-
46
- /**
47
- * Handlers effect.
48
- */
49
- readonly handlers: Effect.Effect<Toolkit.WithHandler<GenericTools<TR>>, E, R>;
50
- }
51
-
52
- /**
53
- * Generic constraint.
54
- *
55
- * NOTE: Only use in place of `T extends PortableToolkit.Any`. Not suitable for standalone use.
56
- */
57
- export interface Any {
58
- readonly [TypeId]: TypeId;
59
- readonly toolkit: Toolkit.Toolkit<any>;
60
- readonly layer: Layer.Layer<unknown, any, any>;
61
- }
62
-
63
- export type InvocationRequirements<T extends Any> = T extends GenericToolkit<infer TR, infer _E, infer _R> ? TR : never;
64
- export type Failure<T extends Any> = T extends GenericToolkit<infer _TR, infer E, infer _R> ? E : never;
65
- export type Requirements<T extends Any> = T extends GenericToolkit<infer _TR, infer _E, infer R> ? R : never;
66
-
67
- /**
68
- * Creates a portable toolkit from toolkit definition and handlers layer.
69
- */
70
- export const make = <Tools extends Record<string, Tool.Any>, E, R>(
71
- toolkit: Toolkit.Toolkit<Tools>,
72
- layer: Layer.Layer<Tool.HandlersFor<Tools>, E, R>,
73
- ): GenericToolkit<E, R> => {
74
- return {
75
- [TypeId]: TypeId,
76
- toolkit: toolkit as any,
77
- layer: layer as any,
78
- handlers: toolkit.pipe(Effect.provide(layer)) as any,
79
- pipe() {
80
- // eslint-disable-next-line prefer-rest-params
81
- return Pipeable.pipeArguments(this, arguments);
82
- },
83
- };
84
- };
85
-
86
- /**
87
- * Merges multiple portable toolkits into a single portable toolkit.
88
- */
89
- export const merge = <const Toolkits extends ReadonlyArray<Any>>(
90
- /**
91
- * The toolkits to merge together.
92
- */
93
- ...toolkits: Toolkits
94
- ): GenericToolkit<
95
- InvocationRequirements<Toolkits[number]>,
96
- Failure<Toolkits[number]>,
97
- Requirements<Toolkits[number]>
98
- > => {
99
- return make(
100
- Toolkit.merge(...toolkits.map((t) => t.toolkit)),
101
- Layer.mergeAll(...(toolkits.map((t) => t.layer) as any)),
102
- ) as any;
103
- };
104
-
105
- /**
106
- * Generic tools type where we cannot statically enumerate individual tools.
107
- */
108
- export type GenericTools<R = never> = Record<
109
- string,
110
- Tool.Tool<
111
- string,
112
- {
113
- readonly parameters: AnyStructSchemaNoContext;
114
- readonly success: Schema.Schema.AnyNoContext;
115
- readonly failure: typeof Schema.Never;
116
- },
117
- R
118
- >
119
- >;
120
-
121
- export interface AnyStructSchemaNoContext extends Pipeable.Pipeable {
122
- readonly [Schema.TypeId]: any;
123
- readonly make: any;
124
- readonly Type: any;
125
- readonly Encoded: any;
126
- readonly Context: never;
127
- readonly ast: SchemaAST.AST;
128
- readonly fields: Schema.Struct.Fields;
129
- readonly annotations: any;
130
- }