@dxos/assistant 0.8.4-main.f9ba587 → 0.8.4-main.fd6878d
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/chunk-6WRGDEMH.mjs +89 -0
- package/dist/lib/browser/chunk-6WRGDEMH.mjs.map +7 -0
- package/dist/lib/browser/chunk-NZGGCEF3.mjs +341 -0
- package/dist/lib/browser/chunk-NZGGCEF3.mjs.map +7 -0
- package/dist/lib/browser/extraction/index.mjs +269 -0
- package/dist/lib/browser/extraction/index.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +240 -1905
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs +13 -0
- package/dist/lib/browser/named-entity-recognition-O46UTCLR.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-3UU5V4FS.mjs +91 -0
- package/dist/lib/node-esm/chunk-3UU5V4FS.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-XOOPGSGW.mjs +343 -0
- package/dist/lib/node-esm/chunk-XOOPGSGW.mjs.map +7 -0
- package/dist/lib/node-esm/extraction/index.mjs +270 -0
- package/dist/lib/node-esm/extraction/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +240 -1906
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs +14 -0
- package/dist/lib/node-esm/named-entity-recognition-W4VMRCH6.mjs.map +7 -0
- package/dist/types/src/conversation/context.d.ts +90 -0
- package/dist/types/src/conversation/context.d.ts.map +1 -0
- package/dist/types/src/conversation/conversation.d.ts +31 -25
- package/dist/types/src/conversation/conversation.d.ts.map +1 -1
- package/dist/types/src/conversation/index.d.ts +1 -0
- package/dist/types/src/conversation/index.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +39 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- 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 +143 -45
- package/dist/types/src/extraction/extraction-ner-function/extraction-ner-function.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts +1 -1
- package/dist/types/src/extraction/extraction-ner-function/named-entity-recognition.d.ts.map +1 -1
- package/dist/types/src/extraction/extraction.d.ts +106 -44
- package/dist/types/src/extraction/extraction.d.ts.map +1 -1
- package/dist/types/src/functions/index.d.ts +2 -0
- package/dist/types/src/functions/index.d.ts.map +1 -0
- package/dist/types/src/functions/services.d.ts +7 -0
- package/dist/types/src/functions/services.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/session/artifact-diff.d.ts +27 -0
- package/dist/types/src/session/artifact-diff.d.ts.map +1 -0
- package/dist/types/src/session/format.d.ts +168 -0
- package/dist/types/src/session/format.d.ts.map +1 -0
- package/dist/types/src/session/format.test.d.ts +2 -0
- package/dist/types/src/session/format.test.d.ts.map +1 -0
- 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/session.d.ts +123 -239
- package/dist/types/src/session/session.d.ts.map +1 -1
- package/dist/types/src/session/version-pin.d.ts +4 -4
- package/dist/types/src/session/version-pin.d.ts.map +1 -1
- package/dist/types/src/templates/index.d.ts +2 -0
- package/dist/types/src/templates/index.d.ts.map +1 -0
- package/dist/types/src/templates/system.d.ts +22 -0
- package/dist/types/src/templates/system.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +13 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +46 -22
- package/src/{context/binder.ts → conversation/context.ts} +51 -19
- package/src/conversation/conversation.ts +90 -68
- package/src/conversation/index.ts +1 -0
- package/src/errors.ts +10 -0
- package/src/extraction/extraction-llm-function/extraction-llm-function.test.ts +7 -18
- package/src/extraction/extraction-llm-function/extraction-llm-function.ts +22 -17
- package/src/extraction/extraction-ner-function/extraction-ner-function.test.ts +4 -3
- package/src/extraction/extraction-ner-function/extraction-ner-function.ts +7 -4
- package/src/extraction/extraction-ner-function/named-entity-recognition.test.ts +2 -2
- package/src/extraction/extraction-ner-function/named-entity-recognition.ts +1 -1
- package/src/extraction/quotes.test.ts +1 -1
- package/src/extraction/quotes.ts +1 -1
- package/src/functions/index.ts +5 -0
- package/src/functions/services.ts +114 -0
- package/src/index.ts +3 -5
- package/src/session/__snapshots__/session.test.ts.snap +32 -0
- package/src/session/artifact-diff.ts +37 -0
- package/src/session/format.test.ts +60 -0
- package/src/session/format.ts +139 -0
- package/src/session/index.ts +1 -0
- package/src/session/session.test.ts +87 -57
- package/src/session/session.ts +220 -523
- package/src/session/version-pin.test.ts +2 -21
- package/src/session/version-pin.ts +9 -9
- package/src/summarization/summarization.test.ts +82 -106
- package/src/templates/format.tpl +55 -0
- package/src/templates/index.ts +5 -0
- package/src/templates/system.tpl +47 -0
- package/src/templates/system.ts +32 -0
- package/src/types.ts +45 -1
- package/src/typings.d.ts +5 -0
- package/dist/types/bin/chat.d.ts +0 -2
- package/dist/types/bin/chat.d.ts.map +0 -1
- package/dist/types/src/blueprint/blueprint.d.ts +0 -41
- package/dist/types/src/blueprint/blueprint.d.ts.map +0 -1
- package/dist/types/src/blueprint/index.d.ts +0 -3
- package/dist/types/src/blueprint/index.d.ts.map +0 -1
- package/dist/types/src/blueprint/registry.d.ts +0 -7
- package/dist/types/src/blueprint/registry.d.ts.map +0 -1
- package/dist/types/src/context/binder.d.ts +0 -34
- package/dist/types/src/context/binder.d.ts.map +0 -1
- package/dist/types/src/context/binding.d.ts +0 -38
- package/dist/types/src/context/binding.d.ts.map +0 -1
- package/dist/types/src/context/index.d.ts +0 -3
- package/dist/types/src/context/index.d.ts.map +0 -1
- package/dist/types/src/research/exa.d.ts +0 -7
- package/dist/types/src/research/exa.d.ts.map +0 -1
- package/dist/types/src/research/graph.d.ts +0 -41
- package/dist/types/src/research/graph.d.ts.map +0 -1
- package/dist/types/src/research/graph.test.d.ts +0 -2
- package/dist/types/src/research/graph.test.d.ts.map +0 -1
- package/dist/types/src/research/index.d.ts +0 -4
- package/dist/types/src/research/index.d.ts.map +0 -1
- package/dist/types/src/research/research.d.ts +0 -10
- package/dist/types/src/research/research.d.ts.map +0 -1
- package/dist/types/src/research/research.test.d.ts +0 -2
- package/dist/types/src/research/research.test.d.ts.map +0 -1
- package/dist/types/src/testing/exa-search-1748337321991.d.ts +0 -38
- package/dist/types/src/testing/exa-search-1748337321991.d.ts.map +0 -1
- package/dist/types/src/testing/exa-search-1748337331526.d.ts +0 -37
- package/dist/types/src/testing/exa-search-1748337331526.d.ts.map +0 -1
- package/dist/types/src/testing/exa-search-1748337344119.d.ts +0 -58
- package/dist/types/src/testing/exa-search-1748337344119.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/src/blueprint/blueprint.ts +0 -75
- package/src/blueprint/index.ts +0 -6
- package/src/blueprint/registry.ts +0 -15
- package/src/context/binding.ts +0 -31
- package/src/context/index.ts +0 -6
- package/src/research/exa.ts +0 -100
- package/src/research/graph.test.ts +0 -15
- package/src/research/graph.ts +0 -337
- package/src/research/index.ts +0 -7
- package/src/research/instructions-research.tpl +0 -97
- package/src/research/research.test.ts +0 -190
- package/src/research/research.ts +0 -90
- package/src/testing/exa-search-1748337321991.ts +0 -131
- package/src/testing/exa-search-1748337331526.ts +0 -144
- package/src/testing/exa-search-1748337344119.ts +0 -133
- package/src/testing/index.ts +0 -11
- package/src/typedefs.d.ts +0 -8
|
@@ -2,25 +2,6 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { describe, expect, test } from 'vitest';
|
|
5
|
+
import { describe } from 'vitest';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
import { invariant } from '@dxos/invariant';
|
|
10
|
-
import { live } from '@dxos/live-object';
|
|
11
|
-
|
|
12
|
-
import { VersionPin } from './version-pin';
|
|
13
|
-
|
|
14
|
-
describe('VersionPin', () => {
|
|
15
|
-
test('serialization', () => {
|
|
16
|
-
const obj = live(Expando, {
|
|
17
|
-
name: 'John Doe',
|
|
18
|
-
});
|
|
19
|
-
const block = VersionPin.createBlock(VersionPin.make({ objectId: obj.id, version: obj.version }));
|
|
20
|
-
invariant(block.type === 'json' && block.disposition === VersionPin.DISPOSITION);
|
|
21
|
-
const pin = pipe(JSON.parse(block.json), VersionPin.pipe(Schema.decodeSync));
|
|
22
|
-
expect(pin).toBeDefined();
|
|
23
|
-
expect(pin?.objectId).toBe(obj.id);
|
|
24
|
-
expect(pin?.version).toBe(obj.version);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
7
|
+
describe('VersionPin', () => {});
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
|
-
import { type MessageContentBlock } from '@dxos/ai';
|
|
8
7
|
import { type ObjectVersion } from '@dxos/echo-db';
|
|
9
8
|
import { getVersion } from '@dxos/echo-db';
|
|
10
|
-
import {
|
|
9
|
+
import { type AnyEchoObject, ObjectId } from '@dxos/echo-schema';
|
|
10
|
+
import { type ContentBlock } from '@dxos/schema';
|
|
11
11
|
|
|
12
12
|
// TODO(dmaretskyi): Extract.
|
|
13
13
|
const ObjectVersionSchema = Schema.Unknown as Schema.Schema<ObjectVersion>;
|
|
@@ -15,7 +15,7 @@ const ObjectVersionSchema = Schema.Unknown as Schema.Schema<ObjectVersion>;
|
|
|
15
15
|
const VersionPinSchema = Schema.Struct({
|
|
16
16
|
// TODO(dmaretskyi): Use Ref when those support encoding.
|
|
17
17
|
objectId: ObjectId,
|
|
18
|
-
// TODO(dmaretskyi): Could be opaque
|
|
18
|
+
// TODO(dmaretskyi): Could be opaque.
|
|
19
19
|
version: ObjectVersionSchema,
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -27,22 +27,22 @@ export interface VersionPin extends Schema.Schema.Type<typeof VersionPinSchema>
|
|
|
27
27
|
|
|
28
28
|
export const VersionPin: typeof VersionPinSchema & {
|
|
29
29
|
DISPOSITION: 'version-pin';
|
|
30
|
-
fromObject: (object:
|
|
31
|
-
createBlock: (pin: VersionPin) =>
|
|
30
|
+
fromObject: (object: AnyEchoObject) => VersionPin;
|
|
31
|
+
createBlock: (pin: VersionPin) => ContentBlock.Any;
|
|
32
32
|
} = class extends VersionPinSchema {
|
|
33
33
|
static readonly DISPOSITION = 'version-pin';
|
|
34
|
-
static fromObject(object:
|
|
34
|
+
static fromObject(object: AnyEchoObject): VersionPin {
|
|
35
35
|
return VersionPin.make({
|
|
36
36
|
objectId: object.id,
|
|
37
37
|
version: getVersion(object),
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
static createBlock(pin: VersionPin):
|
|
41
|
+
static createBlock(pin: VersionPin): ContentBlock.Any {
|
|
42
42
|
return {
|
|
43
|
-
|
|
43
|
+
_tag: 'json',
|
|
44
44
|
disposition: VersionPin.DISPOSITION,
|
|
45
|
-
|
|
45
|
+
data: JSON.stringify(pin),
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
};
|
|
@@ -2,25 +2,20 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// ISSUE(burdon): defineFunction
|
|
6
|
+
// @ts-nocheck
|
|
7
|
+
|
|
8
|
+
import { Schema, pipe } from 'effect';
|
|
6
9
|
import { beforeAll, describe, test } from 'vitest';
|
|
7
10
|
|
|
8
|
-
import {
|
|
9
|
-
EdgeAiServiceClient,
|
|
10
|
-
Message,
|
|
11
|
-
MixedStreamParser,
|
|
12
|
-
OllamaAiServiceClient,
|
|
13
|
-
type TextContentBlock,
|
|
14
|
-
} from '@dxos/ai';
|
|
15
|
-
import { AI_SERVICE_ENDPOINT } from '@dxos/ai/testing';
|
|
11
|
+
import { AiService, MixedStreamParser } from '@dxos/ai';
|
|
16
12
|
import { Obj } from '@dxos/echo';
|
|
17
|
-
import type
|
|
13
|
+
import { type EchoDatabase } from '@dxos/echo-db';
|
|
18
14
|
import { EchoTestBuilder } from '@dxos/echo-db/testing';
|
|
19
|
-
import {
|
|
20
|
-
import { DataType } from '@dxos/schema';
|
|
15
|
+
import { FunctionExecutor, ServiceContainer, defineFunction } from '@dxos/functions';
|
|
16
|
+
import { type ContentBlock, DataType } from '@dxos/schema';
|
|
21
17
|
import { createTestData } from '@dxos/schema/testing';
|
|
22
|
-
|
|
23
|
-
const REMOTE_AI = true;
|
|
18
|
+
import { trim } from '@dxos/util';
|
|
24
19
|
|
|
25
20
|
const summarizationFn = defineFunction({
|
|
26
21
|
description: 'Summarize a document',
|
|
@@ -30,49 +25,50 @@ const summarizationFn = defineFunction({
|
|
|
30
25
|
}),
|
|
31
26
|
outputSchema: DataType.Text,
|
|
32
27
|
handler: async ({ data: { document, transcript }, context }) => {
|
|
33
|
-
const ai = context.getService(AiService);
|
|
28
|
+
const ai = context.getService(AiService.AiService);
|
|
34
29
|
const result = await new MixedStreamParser().parse(
|
|
35
30
|
await ai.client.execStream({
|
|
36
31
|
model: '@anthropic/claude-3-5-haiku-20241022',
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
32
|
+
// TODO(burdon): Factor out and test prompts.
|
|
33
|
+
systemPrompt: trim`
|
|
34
|
+
Your job is to summarize a meeting transcript.
|
|
35
|
+
Transcript Summarizer updates an existing summary within <summary> tags with a new transcript that is placed in <transcript> tags.
|
|
36
|
+
Transcript Summarizer updates only the relevant parts of the summary.
|
|
37
|
+
If there's no summary, create a new one.
|
|
38
|
+
Transcript Summarizer outputs only the summary texts and nothing else.
|
|
39
|
+
Transcript Summarizer keeps the original summary structure.
|
|
40
|
+
Transcript Summarizer keeps the unrelated parts of the summary untouched.
|
|
41
|
+
The Transcript Summarizer errs on the side of being too verbose.
|
|
42
|
+
The Transcript Summarizer outputs the entire update summary.
|
|
43
|
+
The summary is formatted as hierarchical markdown bullet points with no headings.
|
|
44
|
+
The hierarchical structure is deeply nested.
|
|
45
|
+
The Transcript Summarizer formats the bullets with "-" symbol as prefix and two spaces indentation.
|
|
46
|
+
The Transcript Summarizer knows that the content of transcript will be updated solely by its output.
|
|
47
|
+
The Transcript Summarizer outputs only the summary text.
|
|
48
|
+
`,
|
|
54
49
|
history: [
|
|
55
|
-
Obj.make(Message, {
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
Obj.make(DataType.Message, {
|
|
51
|
+
created: new Date().toISOString(),
|
|
52
|
+
sender: { role: 'user' },
|
|
53
|
+
blocks: [
|
|
58
54
|
{
|
|
59
|
-
|
|
60
|
-
text: `
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
_tag: 'text',
|
|
56
|
+
text: trim`
|
|
57
|
+
<transcript>
|
|
58
|
+
${JSON.stringify(transcript, null, 2)}
|
|
59
|
+
</transcript>
|
|
60
|
+
`,
|
|
65
61
|
},
|
|
66
62
|
...(document != null && document.content.length > 0
|
|
67
63
|
? [
|
|
68
64
|
{
|
|
69
|
-
|
|
70
|
-
text: `
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
} satisfies
|
|
65
|
+
_tag: 'text',
|
|
66
|
+
text: trim`
|
|
67
|
+
<summary>
|
|
68
|
+
${document.content}
|
|
69
|
+
</summary>
|
|
70
|
+
`,
|
|
71
|
+
} satisfies ContentBlock.Text,
|
|
76
72
|
]
|
|
77
73
|
: []),
|
|
78
74
|
],
|
|
@@ -80,9 +76,8 @@ const summarizationFn = defineFunction({
|
|
|
80
76
|
],
|
|
81
77
|
}),
|
|
82
78
|
);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
79
|
+
|
|
80
|
+
return DataType.makeText(pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : '')));
|
|
86
81
|
},
|
|
87
82
|
});
|
|
88
83
|
|
|
@@ -95,49 +90,49 @@ const refinementFn = defineFunction({
|
|
|
95
90
|
summary: DataType.Text,
|
|
96
91
|
}),
|
|
97
92
|
handler: async ({ data: { summaries }, context }) => {
|
|
98
|
-
const ai = context.getService(AiService);
|
|
93
|
+
const ai = context.getService(AiService.AiService);
|
|
99
94
|
const result = await new MixedStreamParser().parse(
|
|
100
95
|
await ai.client.execStream({
|
|
101
96
|
model: '@anthropic/claude-3-5-haiku-20241022',
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
97
|
+
// TODO(burdon): Factor out and test prompts.
|
|
98
|
+
systemPrompt: trim`
|
|
99
|
+
You are a Transcript Summary Refiner.
|
|
100
|
+
Transcript Summary Refiner works on a history of evolving summaries that were generated based on the transcript.
|
|
101
|
+
The summaries are presented starting from the oldest to the newest.
|
|
102
|
+
Each iteration of the summary contains a new part of the transcript.
|
|
103
|
+
The Transcript Summary Refiner refines the summary based on the history of summaries.
|
|
104
|
+
The Transcript Summary Refiner identifies any potential data lost between the iterations and adds its back to the output.
|
|
105
|
+
The Transcript Summary Refiner updates the summary to be more structured.
|
|
106
|
+
The Transcript Summary Refiner errs on the side of being too verbose.
|
|
107
|
+
The Transcript Summary Refiner errs on keeping the original summary structure.
|
|
108
|
+
The Transcript Summary Refiner outputs the entire update summary.
|
|
109
|
+
The Transcript Summary is formatted as hierarchical markdown bullet points with no headings.
|
|
110
|
+
The hierarchical structure is deeply nested.
|
|
111
|
+
The Transcript Summary Refiner formats the bullets with "-" symbol as prefix and two spaces indentation.
|
|
112
|
+
The Transcript Summary Refiner knows that the content of transcript will be updated solely by its output.
|
|
113
|
+
The Transcript Summary Refiner outputs only the summary text.
|
|
114
|
+
`,
|
|
119
115
|
history: [
|
|
120
|
-
Obj.make(Message, {
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
Obj.make(DataType.Message, {
|
|
117
|
+
created: new Date().toISOString(),
|
|
118
|
+
sender: { role: 'user' },
|
|
119
|
+
blocks: summaries.map(
|
|
123
120
|
(summary) =>
|
|
124
121
|
({
|
|
125
|
-
|
|
126
|
-
text: `
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}) satisfies
|
|
122
|
+
_tag: 'text',
|
|
123
|
+
text: trim`
|
|
124
|
+
<summary>
|
|
125
|
+
${summary.content}
|
|
126
|
+
</summary>
|
|
127
|
+
`,
|
|
128
|
+
}) satisfies ContentBlock.Text,
|
|
132
129
|
),
|
|
133
130
|
}),
|
|
134
131
|
],
|
|
135
132
|
}),
|
|
136
133
|
);
|
|
137
134
|
return {
|
|
138
|
-
summary:
|
|
139
|
-
content: pipe(result[0]?.content[0], (c) => (c?.type === 'text' ? c.text : '')),
|
|
140
|
-
}),
|
|
135
|
+
summary: DataType.makeText(pipe(result[0]?.blocks[0], (c) => (c?._tag === 'text' ? c.text : ''))),
|
|
141
136
|
};
|
|
142
137
|
},
|
|
143
138
|
});
|
|
@@ -147,6 +142,7 @@ describe.skip('Summarization', () => {
|
|
|
147
142
|
let db: EchoDatabase;
|
|
148
143
|
let executor: FunctionExecutor;
|
|
149
144
|
|
|
145
|
+
// TODO(burdon): Rewrite test.
|
|
150
146
|
beforeAll(async () => {
|
|
151
147
|
// TODO(dmaretskyi): Helper to scaffold this from a config.
|
|
152
148
|
builder = await new EchoTestBuilder().open();
|
|
@@ -154,21 +150,7 @@ describe.skip('Summarization', () => {
|
|
|
154
150
|
db = db1;
|
|
155
151
|
executor = new FunctionExecutor(
|
|
156
152
|
new ServiceContainer().setServices({
|
|
157
|
-
ai:
|
|
158
|
-
client: REMOTE_AI
|
|
159
|
-
? new EdgeAiServiceClient({
|
|
160
|
-
endpoint: AI_SERVICE_ENDPOINT.REMOTE,
|
|
161
|
-
defaultGenerationOptions: {
|
|
162
|
-
// model: '@anthropic/claude-sonnet-4-20250514',
|
|
163
|
-
model: '@anthropic/claude-3-5-sonnet-20241022',
|
|
164
|
-
},
|
|
165
|
-
})
|
|
166
|
-
: new OllamaAiServiceClient({
|
|
167
|
-
overrides: {
|
|
168
|
-
model: 'llama3.1:8b',
|
|
169
|
-
},
|
|
170
|
-
}),
|
|
171
|
-
},
|
|
153
|
+
ai: todo(),
|
|
172
154
|
database: {
|
|
173
155
|
db,
|
|
174
156
|
},
|
|
@@ -179,9 +161,7 @@ describe.skip('Summarization', () => {
|
|
|
179
161
|
test('keeps transcript outline', { timeout: 1000_000 }, async () => {
|
|
180
162
|
const { transcriptMessages } = createTestData();
|
|
181
163
|
|
|
182
|
-
const summary =
|
|
183
|
-
content: '',
|
|
184
|
-
});
|
|
164
|
+
const summary = DataType.makeText();
|
|
185
165
|
|
|
186
166
|
const summaries = [];
|
|
187
167
|
|
|
@@ -192,12 +172,10 @@ describe.skip('Summarization', () => {
|
|
|
192
172
|
transcript: blocks,
|
|
193
173
|
});
|
|
194
174
|
summary.content = result.content;
|
|
195
|
-
summaries.push(
|
|
175
|
+
summaries.push(DataType.makeText(result.content));
|
|
196
176
|
|
|
197
177
|
console.log(blocks.at(-1));
|
|
198
178
|
console.log();
|
|
199
|
-
console.log('--------------------------------');
|
|
200
|
-
console.log();
|
|
201
179
|
console.log(summary.content);
|
|
202
180
|
console.log();
|
|
203
181
|
|
|
@@ -207,12 +185,10 @@ describe.skip('Summarization', () => {
|
|
|
207
185
|
summaries: history,
|
|
208
186
|
});
|
|
209
187
|
summary.content = result.summary.content;
|
|
210
|
-
summaries.push(
|
|
188
|
+
summaries.push(DataType.makeText(result.summary.content));
|
|
211
189
|
|
|
212
190
|
console.log('REFINED');
|
|
213
191
|
console.log();
|
|
214
|
-
console.log('--------------------------------');
|
|
215
|
-
console.log();
|
|
216
192
|
console.log(summary.content);
|
|
217
193
|
console.log();
|
|
218
194
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{{! System Core }}
|
|
2
|
+
|
|
3
|
+
## Input Formats
|
|
4
|
+
|
|
5
|
+
### Blueprints
|
|
6
|
+
|
|
7
|
+
You may be provided with Blueprint definitions that include specific instructions and tools for a given set of tasks.
|
|
8
|
+
Blue print instructions will be enclosed in a <blueprint> tag.
|
|
9
|
+
|
|
10
|
+
### Context objects
|
|
11
|
+
|
|
12
|
+
You may be provided with references to objects that are relevant to the current prompt.
|
|
13
|
+
Objects will be in the form of a <object> tag with a <dxn> element that is the unique key of the object required by many tools.
|
|
14
|
+
The <typename> element is the type of the object.
|
|
15
|
+
|
|
16
|
+
<object>
|
|
17
|
+
<dxn>object-id</dxn>
|
|
18
|
+
<typename>example.com/type/TypeName</typename>
|
|
19
|
+
</object>
|
|
20
|
+
|
|
21
|
+
## Response Formats
|
|
22
|
+
|
|
23
|
+
It is very important to respond in the correct format.
|
|
24
|
+
You response must be valid Markdown.
|
|
25
|
+
In some cases you should respond with well-formed XML tags along with the content.
|
|
26
|
+
|
|
27
|
+
{{#if cot}}
|
|
28
|
+
Before responding, explain your reasoning and include your detailed chain-of-thought enclosed in a <cot> tag.
|
|
29
|
+
The <cot> tag should be the first thing in your response.
|
|
30
|
+
{{/if}}
|
|
31
|
+
|
|
32
|
+
## Block references
|
|
33
|
+
|
|
34
|
+
You can reply with a block reference for objects if you have the DXN. For example:
|
|
35
|
+
|
|
36
|
+
<object>
|
|
37
|
+
<dxn>dxn:queue:data:B6INSIBY3CBEF4M5VZRYBCMAHQMPYK5AJ:01K24XMVHSZHS97SG1VTVQDM5Z:01K24XPK464FSCKVQJAB2H662M</dxn>
|
|
38
|
+
</object>
|
|
39
|
+
<object>
|
|
40
|
+
<dxn>dxn:echo:@:01K24XPK464FSCKVQJAB2H662M</dxn>
|
|
41
|
+
</object>
|
|
42
|
+
|
|
43
|
+
### Suggestions
|
|
44
|
+
|
|
45
|
+
Each suggestion must in the form of a proposed action enclosed in a <suggest> tag.
|
|
46
|
+
Example: <suggest>Show on a map</suggest>
|
|
47
|
+
|
|
48
|
+
### Multiple choice questions
|
|
49
|
+
|
|
50
|
+
You may ask multiple choice questions by wrapping consise options inside <option> tags inside a well formed <select> tag.
|
|
51
|
+
Example: <select><option>Yes</option><option>No</option></select>
|
|
52
|
+
|
|
53
|
+
## Toolkit
|
|
54
|
+
|
|
55
|
+
If the user asks for a list of tools, then just emit a single self-closing <toolkit/> tag instead of listing the tools.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{{! System Prompt }}
|
|
2
|
+
|
|
3
|
+
You are a helpful assistant called Kai.
|
|
4
|
+
Your name is Kai and you are powered by different language models.
|
|
5
|
+
You were created by DXOS and operate in Composer and on the DXOS EDGE network.
|
|
6
|
+
In your initial greeting state your name and make some suggestions based on the current context objects.
|
|
7
|
+
|
|
8
|
+
You are an advanced AI assistant capable of creating and managing artifacts from provided data and tools.
|
|
9
|
+
Your task is to process user commands and questions and decide how best to respond.
|
|
10
|
+
In general be concise and direct.
|
|
11
|
+
|
|
12
|
+
Follow these guidelines carefully:
|
|
13
|
+
|
|
14
|
+
Include the following steps:
|
|
15
|
+
|
|
16
|
+
- Analyze the structure and type of the content in the user's message.
|
|
17
|
+
- Determine if you complete the task using the available blueprint definitions?
|
|
18
|
+
- If you can't complete the task using the available blueprint definitions, query the list of available blueprint definitions using the appropriate tool.
|
|
19
|
+
- Identify which blueprint definitions are relevant to the user's request.
|
|
20
|
+
- Evaluate the potential benefits of creating an artifact vs. normal processing for each identified element.
|
|
21
|
+
- Make a final decision on whether to create an artifact and explain your reasoning.
|
|
22
|
+
- Are the required blueprint definitions already available?
|
|
23
|
+
- If not, select which blueprint definition(s) will be the most relevant and require them using the require_artifact_definitions tool.
|
|
24
|
+
- The require'd artifact tools will be available for use after require.
|
|
25
|
+
- If creating an artifact, outline how you will structure it within the response.
|
|
26
|
+
- Decide if the artifact needs to be shown to the user.
|
|
27
|
+
- Call the show tool to show the artifact to the user.
|
|
28
|
+
- Your reasoning must include: whether to use artifacts or not, to create one or query, whether to show the artifact to the user, and how to structure the response.
|
|
29
|
+
|
|
30
|
+
# Blueprints
|
|
31
|
+
|
|
32
|
+
- Determine if the interaction involves an artifact. Prefer artifacts for tables, lists, spreadsheets, kanbans, games, images, and other structured data.
|
|
33
|
+
- Determine if the user is explicitly talking about creating a new artifact, or wants to use an existing artifact.
|
|
34
|
+
- If it is ambiguous, query for existing artifacts first and then decide.
|
|
35
|
+
- If you decide to create an artifact, call the associated tool to create the artifact.
|
|
36
|
+
- Artifacts are stored in the database. Tools are used to create and query artifacts.
|
|
37
|
+
- If you are unsure about creating an artifact ask the user for clarification.
|
|
38
|
+
|
|
39
|
+
- Artifacts are mutable objects that can change over the course of the conversation.
|
|
40
|
+
- Always re-query the artifact using the tool (like query or inspect) to get the latest state of the artifact before answering the user.
|
|
41
|
+
- You must never generate the id of the artifact; only recall the ids that are already in the history.
|
|
42
|
+
- Artifacts are created by requiring the specific artifact using the require_artifact tool and creating it by calling the associated tool.
|
|
43
|
+
|
|
44
|
+
- You can add suggested actions at the end of your response.
|
|
45
|
+
- Suggested actions should be very concise and start with a verb and be phrased as a command to an agent -- not a question to the user.
|
|
46
|
+
- Suggested actions must be in the form of a user instruction that you can follow.
|
|
47
|
+
- Suggested actions could include actions that create artifacts.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Template } from '@dxos/blueprints';
|
|
6
|
+
|
|
7
|
+
import FORMAT from './format.tpl?raw';
|
|
8
|
+
import SYSTEM from './system.tpl?raw';
|
|
9
|
+
|
|
10
|
+
type PromptOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* Emit chain-of-thought inside <cot> tag.
|
|
13
|
+
* Should be `false` for models with built-in reasoning: Claude, deepseek, o1.
|
|
14
|
+
*/
|
|
15
|
+
cot?: boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Whether to include suggestions in the prompt.
|
|
19
|
+
*/
|
|
20
|
+
suggestions?: boolean;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Base system prompt.
|
|
25
|
+
* NOTE: This contains protocol instructions that can not be dynamically edited.
|
|
26
|
+
*/
|
|
27
|
+
export const createSystemPrompt = (options: PromptOptions) => Template.process<PromptOptions>(FORMAT, options);
|
|
28
|
+
|
|
29
|
+
export const templates = {
|
|
30
|
+
// Editable system prompt.
|
|
31
|
+
system: Template.make({ source: SYSTEM }),
|
|
32
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -2,7 +2,51 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
5
7
|
import { type ObjectId } from '@dxos/echo-schema';
|
|
8
|
+
import { DXN, LOCAL_SPACE_TAG, type SpaceId } from '@dxos/keys';
|
|
9
|
+
import { trim } from '@dxos/util';
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
8
14
|
export const createArtifactElement = (id: ObjectId) => `<artifact id=${id} />`;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A model-friendly way to reference an object.
|
|
18
|
+
* Supports vairous formats that will be normalized to a DXN.
|
|
19
|
+
*/
|
|
20
|
+
// TODO(burdon): Rename ObjectReference?
|
|
21
|
+
export const ArtifactId: Schema.Schema<string> & {
|
|
22
|
+
toDXN: (reference: ArtifactId, owningSpaceId?: SpaceId) => DXN;
|
|
23
|
+
} = class extends Schema.String.annotations({
|
|
24
|
+
description: trim`
|
|
25
|
+
The ID of the referenced object. Formats accepted:
|
|
26
|
+
- DXN (dxn:echo:@:XXXXX). DXNs can be prepended with an @ symbol for compatibility with in-text references.
|
|
27
|
+
- space ID, object ID tuple (spaceID:objectID)
|
|
28
|
+
- Only object ID that is assumed to be in the current space (XXXXX)
|
|
29
|
+
`,
|
|
30
|
+
examples: ['dxn:echo:@:XXXXX', '@dxn:echo:@:XXXXX', 'spaceID:objectID', 'XXXXX'],
|
|
31
|
+
}) {
|
|
32
|
+
static toDXN(reference: ArtifactId, owningSpaceId?: SpaceId): DXN {
|
|
33
|
+
// Allow @dxn: prefix for compatibility with in-text references.
|
|
34
|
+
if (reference.startsWith('@dxn:')) {
|
|
35
|
+
return DXN.parse(reference.slice(1));
|
|
36
|
+
} else if (reference.startsWith('dxn:')) {
|
|
37
|
+
return DXN.parse(reference);
|
|
38
|
+
} else if (/^[A-Z0-9]+:[A-Z0-9]+$/.test(reference)) {
|
|
39
|
+
const [spaceId, objectId] = reference.split(':');
|
|
40
|
+
// This is a workaround because the current Filter API doesn't work with fully qualified Echo DXNs.
|
|
41
|
+
// We check if the space ID is the same as the owning space and then use LOCAL_SPACE_TAG for local references.
|
|
42
|
+
// TODO(dmaretskyi): Fix this in the Echo and Filter API to properly handle fully qualified DXNs.
|
|
43
|
+
return new DXN(DXN.kind.ECHO, [spaceId === owningSpaceId ? LOCAL_SPACE_TAG : spaceId, objectId]);
|
|
44
|
+
} else if (/^[A-Z0-9]+$/.test(reference)) {
|
|
45
|
+
return DXN.fromLocalObjectId(reference);
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error(`Unable to parse object reference: ${reference}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type ArtifactId = Schema.Schema.Type<typeof ArtifactId>;
|
package/src/typings.d.ts
CHANGED
package/dist/types/bin/chat.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../../bin/chat.ts"],"names":[],"mappings":""}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Schema } from 'effect';
|
|
2
|
-
import { Type } from '@dxos/echo';
|
|
3
|
-
/**
|
|
4
|
-
* Blueprint schema defines the structure for AI assistant blueprints.
|
|
5
|
-
* Blueprints contain instructions, tools, and artifacts that guide the AI's behavior.
|
|
6
|
-
*/
|
|
7
|
-
export declare const Blueprint: Type.obj<Schema.Struct<{
|
|
8
|
-
/**
|
|
9
|
-
* Global registry ID.
|
|
10
|
-
* NOTE: Once a blueprint has been cloned from the registry, its stored definition may converge,
|
|
11
|
-
* but the `key` property refers to the original registry entry.
|
|
12
|
-
*/
|
|
13
|
-
key: Schema.SchemaClass<string, string, never>;
|
|
14
|
-
/**
|
|
15
|
-
* Human-readable name of the blueprint.
|
|
16
|
-
*/
|
|
17
|
-
name: Schema.SchemaClass<string, string, never>;
|
|
18
|
-
/**
|
|
19
|
-
* Description of the blueprint's purpose and functionality.
|
|
20
|
-
*/
|
|
21
|
-
description: Schema.optional<typeof Schema.String>;
|
|
22
|
-
/**
|
|
23
|
-
* Instructions that guide the AI assistant's behavior and responses.
|
|
24
|
-
* These are system prompts or guidelines that the AI should follow.
|
|
25
|
-
*/
|
|
26
|
-
instructions: Schema.SchemaClass<string, string, never>;
|
|
27
|
-
/**
|
|
28
|
-
* Array of tools that the AI assistant can use when this blueprint is active.
|
|
29
|
-
*/
|
|
30
|
-
tools: Schema.Array$<Schema.SchemaClass<string, string, never>>;
|
|
31
|
-
/**
|
|
32
|
-
* Array of artifacts that the AI assistant can create or modify.
|
|
33
|
-
*/
|
|
34
|
-
artifacts: Schema.Array$<typeof Schema.String>;
|
|
35
|
-
}>>;
|
|
36
|
-
/**
|
|
37
|
-
* TypeScript type for Blueprint.
|
|
38
|
-
*/
|
|
39
|
-
export interface Blueprint extends Schema.Schema.Type<typeof Blueprint> {
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=blueprint.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blueprint.d.ts","sourceRoot":"","sources":["../../../../src/blueprint/blueprint.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGlC;;;GAGG;AACH,eAAO,MAAM,SAAS;IACpB;;;;OAIG;;IAMH;;OAEG;;IAKH;;OAEG;;IAKH;;;OAGG;;IAKH;;OAEG;;IAKH;;OAEG;;GAaJ,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC;CAAG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/blueprint/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../../src/blueprint/registry.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,SAAS,EAAE;IAIrD,KAAK,IAAI,SAAS,EAAE;CAGrB"}
|