@dxos/assistant 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae
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/README.md +1 -0
- package/dist/lib/neutral/chunk-BE6SRJ4N.mjs +193 -0
- package/dist/lib/neutral/chunk-BE6SRJ4N.mjs.map +7 -0
- package/dist/lib/neutral/extraction/index.mjs +223 -0
- package/dist/lib/neutral/extraction/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1328 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/testing/index.mjs +38 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/conversation/context.d.ts +109 -60
- package/dist/types/src/conversation/context.d.ts.map +1 -1
- package/dist/types/src/conversation/context.test.d.ts +2 -0
- package/dist/types/src/conversation/context.test.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.d.ts +41 -16
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/conversation.test.d.ts +2 -0
- package/dist/types/src/conversation/conversation.test.d.ts.map +1 -0
- package/dist/types/src/diff.d.ts +3 -1
- package/dist/types/src/diff.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +22 -30
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/execution-graph.d.ts +5 -2
- package/dist/types/src/execution-graph.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-llm-function/extraction-llm-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts +282 -268
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +348 -303
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/extraction/quotes.d.ts +2 -2
- package/dist/types/src/extraction/quotes.d.ts.map +1 -1
- package/dist/types/src/functions/services.d.ts +6 -6
- package/dist/types/src/functions/services.d.ts.map +1 -1
- package/dist/types/src/functions.test.d.ts +2 -0
- package/dist/types/src/functions.test.d.ts.map +1 -0
- package/dist/types/src/session/artifact-diff.d.ts +1 -1
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -1
- package/dist/types/src/session/format.d.ts +4 -176
- package/dist/types/src/session/format.d.ts.map +1 -1
- package/dist/types/src/session/index.d.ts +1 -0
- package/dist/types/src/session/index.d.ts.map +1 -1
- package/dist/types/src/session/observer.d.ts +6 -5
- package/dist/types/src/session/observer.d.ts.map +1 -1
- package/dist/types/src/session/session.d.ts +25 -15
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/toolkit.d.ts +9 -6
- package/dist/types/src/session/toolkit.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +3 -3
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/layer.d.ts +22 -0
- package/dist/types/src/testing/layer.d.ts.map +1 -0
- package/dist/types/src/types/artifact.d.ts +28 -0
- package/dist/types/src/types/artifact.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +41 -31
- package/src/conversation/context.test.ts +46 -0
- package/src/conversation/context.ts +223 -49
- package/src/conversation/conversation.test.ts +65 -0
- package/src/conversation/conversation.ts +179 -53
- package/src/diff.test.ts +37 -6
- package/src/diff.ts +18 -4
- package/src/errors.ts +2 -2
- package/src/execution-graph.test.ts +46 -44
- package/src/execution-graph.ts +25 -16
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +2 -2
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +44 -54
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +15 -14
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +36 -44
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +10 -5
- package/src/extraction/extraction.ts +9 -8
- package/src/extraction/quotes.ts +4 -5
- package/src/functions/services.ts +88 -37
- package/src/functions.conversations.json +1 -0
- package/src/functions.test.ts +74 -0
- package/src/session/artifact-diff.ts +1 -1
- package/src/session/format.test.ts +103 -39
- package/src/session/format.ts +17 -16
- package/src/session/index.ts +1 -0
- package/src/session/observer.ts +6 -3
- package/src/session/session.conversations.json +1 -1
- package/src/session/session.test.ts +60 -18
- package/src/session/session.ts +99 -60
- package/src/session/toolkit.ts +21 -25
- package/src/session/version-pin.ts +6 -6
- package/src/templates/{format.tpl → instructions/format.tpl} +1 -4
- package/src/templates/system.ts +2 -2
- package/src/testing/index.ts +5 -0
- package/src/testing/layer.ts +85 -0
- package/src/{types.ts → types/artifact.ts} +43 -6
- package/src/types/index.ts +5 -0
- package/dist/lib/browser/chunk-CWGVG235.mjs +0 -380
- package/dist/lib/browser/chunk-CWGVG235.mjs.map +0 -7
- package/dist/lib/browser/chunk-UB26N5UF.mjs +0 -89
- package/dist/lib/browser/chunk-UB26N5UF.mjs.map +0 -7
- package/dist/lib/browser/extraction/index.mjs +0 -272
- package/dist/lib/browser/extraction/index.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -869
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs +0 -13
- package/dist/lib/browser/named-entity-recognition-QPYHML66.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs +0 -91
- package/dist/lib/node-esm/chunk-BCFXTNSK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OV5PMQPB.mjs +0 -382
- package/dist/lib/node-esm/chunk-OV5PMQPB.mjs.map +0 -7
- package/dist/lib/node-esm/extraction/index.mjs +0 -273
- package/dist/lib/node-esm/extraction/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -870
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs +0 -14
- package/dist/lib/node-esm/named-entity-recognition-2HDF46YX.mjs.map +0 -7
- package/dist/types/src/summarization/summarization.test.d.ts +0 -2
- package/dist/types/src/summarization/summarization.test.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -16
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/summarization/summarization.test.ts +0 -202
- /package/src/extraction/extraction-llm-function/{instructions.tpl → transcription-instructions.tpl} +0 -0
- /package/src/templates/{system.tpl → instructions/system.tpl} +0 -0
|
@@ -2,59 +2,123 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { describe, expect, it } from '@effect/vitest';
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
7
8
|
|
|
8
9
|
import { Blueprint, Template } from '@dxos/blueprints';
|
|
9
|
-
import { Obj } from '@dxos/echo';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { Database, Obj, Query } from '@dxos/echo';
|
|
11
|
+
import { TestHelpers } from '@dxos/effect/testing';
|
|
12
|
+
import { defineFunction } from '@dxos/functions';
|
|
13
|
+
import { Text } from '@dxos/schema';
|
|
14
|
+
import { Organization } from '@dxos/types';
|
|
13
15
|
import { trim } from '@dxos/util';
|
|
14
16
|
|
|
15
17
|
import { createSystemPrompt } from '../templates/system';
|
|
18
|
+
import { AssistantTestLayer } from '../testing';
|
|
16
19
|
|
|
17
20
|
import { formatSystemPrompt } from './format';
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const organizationListFunction = defineFunction({
|
|
23
|
+
key: 'dxos.org/function/organization-list',
|
|
24
|
+
name: 'Organization List',
|
|
25
|
+
description: 'List organizations',
|
|
26
|
+
inputSchema: Schema.Struct({}),
|
|
27
|
+
outputSchema: Schema.Array(Schema.String),
|
|
28
|
+
handler: Effect.fnUntraced(function* () {
|
|
29
|
+
const organizations = yield* Database.runQuery(Query.type(Organization.Organization));
|
|
30
|
+
return organizations.map((organization) => organization.name);
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const TestLayer = AssistantTestLayer({
|
|
35
|
+
types: [Text.Text, Organization.Organization, Blueprint.Blueprint],
|
|
36
|
+
functions: [organizationListFunction],
|
|
37
|
+
});
|
|
27
38
|
|
|
39
|
+
describe('format', () => {
|
|
28
40
|
it.effect(
|
|
29
41
|
'should format',
|
|
30
|
-
Effect.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
Effect.fnUntraced(
|
|
43
|
+
function* (_) {
|
|
44
|
+
const { db } = yield* Database.Service;
|
|
45
|
+
const object = db.add(
|
|
46
|
+
Obj.make(Organization.Organization, {
|
|
47
|
+
name: 'Test',
|
|
48
|
+
website: 'https://www.test.com',
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const blueprint = db.add(
|
|
53
|
+
Blueprint.make({
|
|
54
|
+
key: 'example.com/blueprint/test',
|
|
55
|
+
name: 'Test',
|
|
56
|
+
instructions: Template.make({
|
|
57
|
+
source: trim`
|
|
58
|
+
Test
|
|
59
|
+
This is the test blueprint.
|
|
60
|
+
`,
|
|
61
|
+
}),
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const output = yield* formatSystemPrompt({
|
|
66
|
+
system: createSystemPrompt({}),
|
|
67
|
+
blueprints: [blueprint],
|
|
68
|
+
objects: [object],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
console.log(output);
|
|
72
|
+
},
|
|
73
|
+
Effect.provide(TestLayer),
|
|
74
|
+
TestHelpers.provideTestContext,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
it.effect(
|
|
79
|
+
'should format with function input',
|
|
80
|
+
Effect.fnUntraced(
|
|
81
|
+
function* (_) {
|
|
82
|
+
const { db } = yield* Database.Service;
|
|
83
|
+
const object = db.add(
|
|
84
|
+
Obj.make(Organization.Organization, {
|
|
85
|
+
name: 'Test Org',
|
|
86
|
+
website: 'https://www.test.com',
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const blueprint = db.add(
|
|
91
|
+
Blueprint.make({
|
|
92
|
+
key: 'example.com/blueprint/test',
|
|
93
|
+
name: 'Test',
|
|
94
|
+
instructions: Template.make({
|
|
95
|
+
source: trim`
|
|
96
|
+
Organization List:
|
|
97
|
+
{{#each organizations}}
|
|
98
|
+
- {{this}}
|
|
99
|
+
{{/each}}
|
|
100
|
+
`,
|
|
101
|
+
inputs: [
|
|
102
|
+
{
|
|
103
|
+
name: 'organizations',
|
|
104
|
+
kind: 'function',
|
|
105
|
+
function: organizationListFunction.key,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
}),
|
|
47
109
|
}),
|
|
48
|
-
|
|
49
|
-
);
|
|
110
|
+
);
|
|
50
111
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
112
|
+
const output = yield* formatSystemPrompt({
|
|
113
|
+
system: createSystemPrompt({}),
|
|
114
|
+
blueprints: [blueprint],
|
|
115
|
+
objects: [object],
|
|
116
|
+
});
|
|
56
117
|
|
|
57
|
-
|
|
58
|
-
|
|
118
|
+
expect(output).to.include('Test Org');
|
|
119
|
+
},
|
|
120
|
+
Effect.provide(TestLayer),
|
|
121
|
+
TestHelpers.provideTestContext,
|
|
122
|
+
),
|
|
59
123
|
);
|
|
60
124
|
});
|
package/src/session/format.ts
CHANGED
|
@@ -2,24 +2,22 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import * as Array from 'effect/Array';
|
|
6
5
|
import * as Effect from 'effect/Effect';
|
|
7
6
|
import * as Function from 'effect/Function';
|
|
8
7
|
import * as Option from 'effect/Option';
|
|
9
8
|
|
|
10
9
|
import { Template } from '@dxos/blueprints';
|
|
11
10
|
import { Obj } from '@dxos/echo';
|
|
12
|
-
import { type ObjectId } from '@dxos/echo/internal';
|
|
13
11
|
import { ObjectVersion } from '@dxos/echo-db';
|
|
14
|
-
import {
|
|
12
|
+
import { type ObjectId } from '@dxos/keys';
|
|
15
13
|
import { log } from '@dxos/log';
|
|
16
|
-
import { type ContentBlock,
|
|
14
|
+
import { type ContentBlock, Message } from '@dxos/types';
|
|
17
15
|
import { trim } from '@dxos/util';
|
|
18
16
|
|
|
19
17
|
import { AiAssistantError } from '../errors';
|
|
20
18
|
|
|
21
19
|
import { ArtifactDiffResolver } from './artifact-diff';
|
|
22
|
-
import { type
|
|
20
|
+
import { type AiSessionRunError, type AiSessionRunProps } from './session';
|
|
23
21
|
|
|
24
22
|
/**
|
|
25
23
|
* Formats the system prompt.
|
|
@@ -29,20 +27,20 @@ export const formatSystemPrompt = ({
|
|
|
29
27
|
system,
|
|
30
28
|
blueprints = [],
|
|
31
29
|
objects = [],
|
|
32
|
-
}: Pick<
|
|
30
|
+
}: Pick<AiSessionRunProps<any>, 'system' | 'blueprints' | 'objects'>) =>
|
|
33
31
|
Effect.gen(function* () {
|
|
34
32
|
const blueprintDefs = yield* Function.pipe(
|
|
35
33
|
blueprints,
|
|
36
34
|
Effect.forEach((blueprint) => Effect.succeed(blueprint.instructions)),
|
|
37
|
-
Effect.flatMap(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
(template) => trim`
|
|
35
|
+
Effect.flatMap(
|
|
36
|
+
Effect.forEach((template) =>
|
|
37
|
+
Effect.gen(function* () {
|
|
38
|
+
return trim`
|
|
42
39
|
<blueprint>
|
|
43
|
-
${Template.
|
|
40
|
+
${yield* Template.processTemplate(template)}
|
|
44
41
|
</blueprint>
|
|
45
|
-
|
|
42
|
+
`;
|
|
43
|
+
}),
|
|
46
44
|
),
|
|
47
45
|
),
|
|
48
46
|
Effect.map((blueprints) =>
|
|
@@ -74,7 +72,10 @@ export const formatSystemPrompt = ({
|
|
|
74
72
|
*/
|
|
75
73
|
// TODO(burdon): Move to AiPreprocessor.
|
|
76
74
|
// TODO(burdon): Convert util below to `Effect.fn` (to preserve stack info)
|
|
77
|
-
export const formatUserPrompt = ({
|
|
75
|
+
export const formatUserPrompt = ({
|
|
76
|
+
prompt,
|
|
77
|
+
history = [],
|
|
78
|
+
}: Pick<AiSessionRunProps<any>, 'prompt' | 'history'>): Effect.Effect<Message.Message, AiSessionRunError> =>
|
|
78
79
|
Effect.gen(function* () {
|
|
79
80
|
const blocks: ContentBlock.Any[] = [];
|
|
80
81
|
|
|
@@ -105,14 +106,14 @@ export const formatUserPrompt = ({ prompt, history = [] }: Pick<AiSessionRunPara
|
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
return Obj.make(
|
|
109
|
+
return Obj.make(Message.Message, {
|
|
109
110
|
created: new Date().toISOString(),
|
|
110
111
|
sender: { role: 'user' },
|
|
111
112
|
blocks: [...blocks, { _tag: 'text', text: prompt }],
|
|
112
113
|
});
|
|
113
114
|
});
|
|
114
115
|
|
|
115
|
-
const gatherObjectVersions = (messages:
|
|
116
|
+
const gatherObjectVersions = (messages: Message.Message[]): Map<ObjectId, ObjectVersion> => {
|
|
116
117
|
const artifactIds = new Map<ObjectId, ObjectVersion>();
|
|
117
118
|
for (const message of messages) {
|
|
118
119
|
for (const block of message.blocks) {
|
package/src/session/index.ts
CHANGED
package/src/session/observer.ts
CHANGED
|
@@ -2,21 +2,24 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import type * as Tool from '@effect/ai/Tool';
|
|
5
6
|
import * as Effect from 'effect/Effect';
|
|
6
7
|
import * as Function from 'effect/Function';
|
|
7
8
|
|
|
8
9
|
import { type AiParser, type ConsolePrinter } from '@dxos/ai';
|
|
9
|
-
import { type
|
|
10
|
+
import { type Message } from '@dxos/types';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Live observer of the generation process.
|
|
13
14
|
*/
|
|
14
|
-
export interface GenerationObserver
|
|
15
|
+
export interface GenerationObserver<
|
|
16
|
+
Tools extends Record<string, Tool.Any> = any,
|
|
17
|
+
> extends AiParser.ParseResponseCallbacks<Tools> {
|
|
15
18
|
/**
|
|
16
19
|
* Complete messages fired during the session, both from the model and from the user.
|
|
17
20
|
* This message will contain all message blocks emitted through the `onBlock` callback.
|
|
18
21
|
*/
|
|
19
|
-
onMessage: (message:
|
|
22
|
+
onMessage: (message: Message.Message) => Effect.Effect<void>;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
export const GenerationObserver = Object.freeze({
|